@loomcore/common 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,3 +9,7 @@ export declare const UserContextSchema: import("@sinclair/typebox").TObject<{
|
|
|
9
9
|
_orgId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
10
10
|
}>;
|
|
11
11
|
export declare const UserContextSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
|
|
12
|
+
export declare function initializeSystemUserContext(systemEmail: string, metaOrgId: string | undefined): IUserContext;
|
|
13
|
+
export declare function getSystemUserContext(): IUserContext;
|
|
14
|
+
export declare function isSystemUserContextInitialized(): boolean;
|
|
15
|
+
export declare function resetSystemUserContext(): void;
|
|
@@ -5,8 +5,37 @@ export const EmptyUserContext = {
|
|
|
5
5
|
user: {},
|
|
6
6
|
_orgId: undefined
|
|
7
7
|
};
|
|
8
|
+
let _systemUserContext = null;
|
|
8
9
|
export const UserContextSchema = Type.Object({
|
|
9
10
|
user: PublicUserSchema,
|
|
10
11
|
_orgId: Type.Optional(Type.String())
|
|
11
12
|
});
|
|
12
13
|
export const UserContextSpec = entityUtils.getModelSpec(UserContextSchema);
|
|
14
|
+
export function initializeSystemUserContext(systemEmail, metaOrgId) {
|
|
15
|
+
_systemUserContext = {
|
|
16
|
+
user: {
|
|
17
|
+
_id: 'system',
|
|
18
|
+
email: systemEmail,
|
|
19
|
+
password: '',
|
|
20
|
+
_created: new Date(),
|
|
21
|
+
_createdBy: 'system',
|
|
22
|
+
_updated: new Date(),
|
|
23
|
+
_updatedBy: 'system',
|
|
24
|
+
},
|
|
25
|
+
_orgId: metaOrgId,
|
|
26
|
+
};
|
|
27
|
+
console.log('SystemUserContext initialized successfully');
|
|
28
|
+
return _systemUserContext;
|
|
29
|
+
}
|
|
30
|
+
export function getSystemUserContext() {
|
|
31
|
+
if (!_systemUserContext) {
|
|
32
|
+
throw new Error('SystemUserContext has not been initialized. Call initializeSystemUserContext() first.');
|
|
33
|
+
}
|
|
34
|
+
return _systemUserContext;
|
|
35
|
+
}
|
|
36
|
+
export function isSystemUserContextInitialized() {
|
|
37
|
+
return _systemUserContext !== null;
|
|
38
|
+
}
|
|
39
|
+
export function resetSystemUserContext() {
|
|
40
|
+
_systemUserContext = null;
|
|
41
|
+
}
|
package/package.json
CHANGED