Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/sdk/@sfmc-sdk/src/module-loader/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ export class ModuleRegistry {
cleanups.set(id, []);
}
booted.delete(id);
// 清身份避免禁用后仍带旧 token 调用(Demeter:只清本模块上下文)
clearDbModuleContext();
clearConfigModuleContext();
clearServiceModuleContext();
// 清身份避免禁用后仍带旧 token 调用(Demeter:只清本模块上下文,勿误清其他模块桶)
clearDbModuleContext(id);
clearConfigModuleContext(id);
clearServiceModuleContext(id);
}

static teardown(): void {
Expand Down
19 changes: 16 additions & 3 deletions modules/sdk/@sfmc-sdk/src/sapi/config/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,22 @@ export function setConfigModuleContext(moduleId: string, configKey: string, toke
_activeConfigKey = configKey;
}

export function clearConfigModuleContext(): void {
_buckets.clear();
_activeConfigKey = "";
/**
* 清理配置上下文。
* - 传入 moduleId:只删该模块的桶(Demeter/OCP:禁用 A 不误清 B 的缓存)
* - 省略 moduleId:全清(进程级 teardown)
*/
export function clearConfigModuleContext(moduleId?: string): void {
if (!moduleId) {
_buckets.clear();
_activeConfigKey = "";
return;
}
for (const [key, bucket] of [..._buckets.entries()]) {
if (bucket.moduleId !== moduleId) continue;
_buckets.delete(key);
if (_activeConfigKey === key) _activeConfigKey = "";
}
}

function activeBucket(): ConfigBucket {
Expand Down
8 changes: 7 additions & 1 deletion modules/sdk/@sfmc-sdk/src/sapi/db/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ export function setDbModuleContext(moduleId: string, token: string): void {
_authToken = token;
}

export function clearDbModuleContext(): void {
/**
* 清理 db 模块身份。
* - 传入 moduleId:仅当当前身份匹配时清空(Demeter:禁用 A 不误清 B)
* - 省略 moduleId:强制清空
*/
export function clearDbModuleContext(moduleId?: string): void {
if (moduleId && _moduleId !== moduleId) return;
_moduleId = "";
_authToken = "";
_currentTxId = null;
Expand Down
8 changes: 7 additions & 1 deletion modules/sdk/@sfmc-sdk/src/sapi/service/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ export function setServiceModuleContext(moduleId: string, token: string, inTx: (
_isInTx = inTx;
}

export function clearServiceModuleContext(): void {
/**
* 清理 service 模块身份。
* - 传入 moduleId:仅当当前身份匹配时清空(Demeter:禁用 A 不误清 B)
* - 省略 moduleId:强制清空
*/
export function clearServiceModuleContext(moduleId?: string): void {
if (moduleId && _moduleId !== moduleId) return;
_moduleId = "";
_authToken = "";
_isInTx = () => false;
Expand Down
Loading