@loomcore/common 0.0.40 → 0.0.41

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.
@@ -21,10 +21,12 @@ export const PublicUserContextSchema = Type.Object({
21
21
  organization: OrganizationSpec.fullSchema
22
22
  });
23
23
  export const PublicUserContextSpec = entityUtils.getModelSpec(PublicUserContextSchema);
24
+ import { getSystemUserId } from '../validation/index.js';
24
25
  export function initializeSystemUserContext(systemEmail, metaOrg) {
26
+ const systemId = getSystemUserId();
25
27
  _systemUserContext = {
26
28
  user: {
27
- _id: 'system',
29
+ _id: systemId,
28
30
  _orgId: metaOrg?._id,
29
31
  email: systemEmail,
30
32
  firstName: 'System',
@@ -32,9 +34,9 @@ export function initializeSystemUserContext(systemEmail, metaOrg) {
32
34
  displayName: 'System User',
33
35
  password: 'systemPassword',
34
36
  _created: new Date(),
35
- _createdBy: 'system',
37
+ _createdBy: systemId,
36
38
  _updated: new Date(),
37
- _updatedBy: 'system',
39
+ _updatedBy: systemId,
38
40
  },
39
41
  authorizations: [{
40
42
  _id: 'system-authorization',
@@ -1,6 +1,8 @@
1
1
  import { Kind, TSchema, NumberOptions } from '@sinclair/typebox';
2
+ import { AppId } from '../types/app.types.js';
2
3
  export declare const setIdSchema: (schema: TSchema) => void;
3
4
  export declare const getIdSchema: () => TSchema;
5
+ export declare const getSystemUserId: () => AppId;
4
6
  export declare function TypeboxIsoDate(options?: object): import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
5
7
  export declare function TypeboxDate(options?: object): import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
6
8
  export declare function TypeboxObjectId(options?: object): import("@sinclair/typebox").TString;
@@ -3,6 +3,7 @@ import { TypeRegistry } from '@sinclair/typebox';
3
3
  import { Decimal as _Decimal } from 'decimal.js';
4
4
  import { Value } from '@sinclair/typebox/value';
5
5
  let idSchemaInstance;
6
+ let systemUserId;
6
7
  export const setIdSchema = (schema) => {
7
8
  if (idSchemaInstance) {
8
9
  throw new Error('IdSchema has already been initialized and cannot be set again.');
@@ -11,6 +12,15 @@ export const setIdSchema = (schema) => {
11
12
  throw new Error('Schema cannot be null or undefined.');
12
13
  }
13
14
  idSchemaInstance = schema;
15
+ if (schema.type === 'string') {
16
+ systemUserId = 'system';
17
+ }
18
+ else if (schema.type === 'number') {
19
+ systemUserId = 0;
20
+ }
21
+ else {
22
+ systemUserId = 'system';
23
+ }
14
24
  };
15
25
  export const getIdSchema = () => {
16
26
  if (!idSchemaInstance) {
@@ -18,6 +28,12 @@ export const getIdSchema = () => {
18
28
  }
19
29
  return idSchemaInstance;
20
30
  };
31
+ export const getSystemUserId = () => {
32
+ if (!systemUserId) {
33
+ throw new Error('SystemUser ID has not been initialized. Please call setIdSchema() at application startup.');
34
+ }
35
+ return systemUserId;
36
+ };
21
37
  export function TypeboxIsoDate(options = {}) {
22
38
  const dateTransform = Type.Transform(Type.String({ format: 'date-time', ...options }))
23
39
  .Decode(value => new Date(value))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/common",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "private": false,
5
5
  "description": "Loom Core Models- common models, interfaces, types, and utils for Loom Core. All things common to both api and client apps.",
6
6
  "scripts": {