grm-shared-library 1.1.192 → 1.1.193

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.
Files changed (36) hide show
  1. package/dist/cjs/index.js +1 -0
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/modules/system-user/constants/system-user.const.js +31 -0
  4. package/dist/cjs/modules/system-user/constants/system-user.const.js.map +1 -0
  5. package/dist/cjs/modules/system-user/index.js +27 -0
  6. package/dist/cjs/modules/system-user/index.js.map +1 -0
  7. package/dist/cjs/modules/system-user/interfaces/system-user-env-source.js +3 -0
  8. package/dist/cjs/modules/system-user/interfaces/system-user-env-source.js.map +1 -0
  9. package/dist/cjs/modules/system-user/services/system-user.service.js +60 -0
  10. package/dist/cjs/modules/system-user/services/system-user.service.js.map +1 -0
  11. package/dist/cjs/modules/system-user/system-user.module.js +33 -0
  12. package/dist/cjs/modules/system-user/system-user.module.js.map +1 -0
  13. package/dist/cjs/modules/system-user/utils/system-user.util.js +57 -0
  14. package/dist/cjs/modules/system-user/utils/system-user.util.js.map +1 -0
  15. package/dist/esm/index.js +1 -0
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/modules/system-user/constants/system-user.const.js +28 -0
  18. package/dist/esm/modules/system-user/constants/system-user.const.js.map +1 -0
  19. package/dist/esm/modules/system-user/index.js +11 -0
  20. package/dist/esm/modules/system-user/index.js.map +1 -0
  21. package/dist/esm/modules/system-user/interfaces/system-user-env-source.js +2 -0
  22. package/dist/esm/modules/system-user/interfaces/system-user-env-source.js.map +1 -0
  23. package/dist/esm/modules/system-user/services/system-user.service.js +57 -0
  24. package/dist/esm/modules/system-user/services/system-user.service.js.map +1 -0
  25. package/dist/esm/modules/system-user/system-user.module.js +30 -0
  26. package/dist/esm/modules/system-user/system-user.module.js.map +1 -0
  27. package/dist/esm/modules/system-user/utils/system-user.util.js +53 -0
  28. package/dist/esm/modules/system-user/utils/system-user.util.js.map +1 -0
  29. package/dist/types/index.d.ts +1 -0
  30. package/dist/types/modules/system-user/constants/system-user.const.d.ts +24 -0
  31. package/dist/types/modules/system-user/index.d.ts +5 -0
  32. package/dist/types/modules/system-user/interfaces/system-user-env-source.d.ts +10 -0
  33. package/dist/types/modules/system-user/services/system-user.service.d.ts +26 -0
  34. package/dist/types/modules/system-user/system-user.module.d.ts +13 -0
  35. package/dist/types/modules/system-user/utils/system-user.util.d.ts +41 -0
  36. package/package.json +5 -3
package/dist/cjs/index.js CHANGED
@@ -37,6 +37,7 @@ __exportStar(require("./modules/country/index"), exports);
37
37
  __exportStar(require("./modules/phone/index"), exports);
38
38
  __exportStar(require("./modules/tracking/index"), exports);
39
39
  __exportStar(require("./modules/entitlement/index"), exports);
40
+ __exportStar(require("./modules/system-user/index"), exports);
40
41
  // Interfaces
41
42
  __exportStar(require("./interfaces/server-message"), exports);
42
43
  __exportStar(require("./interfaces/i-request-with-user"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,UAAU;AACV,uDAAqC;AACrC,+DAA6C;AAC7C,yDAAuC;AACvC,6DAA2C;AAC3C,uDAAqC;AACrC,uDAAqC;AACrC,iEAA+C;AAC/C,wDAAsC;AACtC,gEAA8C;AAC9C,2DAAyC;AACzC,2DAAyC;AACzC,sDAAoC;AACpC,sDAAoC;AACpC,sDAAoC;AACpC,yDAAuC;AACvC,mEAAiD;AACjD,+DAA6C;AAC7C,uDAAqC;AACrC,0DAAwC;AACxC,wDAAsC;AACtC,2DAAyC;AACzC,8DAA4C;AAE5C,aAAa;AACb,8DAA4C;AAC5C,mEAAiD;AACjD,8DAA4C;AAC5C,2DAAyC;AACzC,0DAAwC;AAExC,YAAY;AACZ,2DAAyC;AAEzC,QAAQ;AACR,gDAA8B;AAE9B,YAAY;AACZ,+DAA6C;AAC7C,wFAAsE;AAEtE,aAAa;AACb,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,UAAU;AACV,uDAAqC;AACrC,+DAA6C;AAC7C,yDAAuC;AACvC,6DAA2C;AAC3C,uDAAqC;AACrC,uDAAqC;AACrC,iEAA+C;AAC/C,wDAAsC;AACtC,gEAA8C;AAC9C,2DAAyC;AACzC,2DAAyC;AACzC,sDAAoC;AACpC,sDAAoC;AACpC,sDAAoC;AACpC,yDAAuC;AACvC,mEAAiD;AACjD,+DAA6C;AAC7C,uDAAqC;AACrC,0DAAwC;AACxC,wDAAsC;AACtC,2DAAyC;AACzC,8DAA4C;AAC5C,8DAA4C;AAE5C,aAAa;AACb,8DAA4C;AAC5C,mEAAiD;AACjD,8DAA4C;AAC5C,2DAAyC;AACzC,0DAAwC;AAExC,YAAY;AACZ,2DAAyC;AAEzC,QAAQ;AACR,gDAA8B;AAE9B,YAAY;AACZ,+DAA6C;AAC7C,wFAAsE;AAEtE,aAAa;AACb,qDAAmC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LEGACY_SYSTEM_USER_ID_ENV_KEYS = exports.SYSTEM_USER_ID_ENV_KEY = void 0;
4
+ /**
5
+ * Canonical environment variable that carries the platform "system user" id.
6
+ *
7
+ * The system user is a real row in the clarion-authentication `users` table
8
+ * that services stamp on records they create or mutate on their own behalf —
9
+ * i.e. when there is no authenticated human in the request (auto-assignment,
10
+ * automated status changes, service-to-service document uploads).
11
+ *
12
+ * It is deliberately NOT a compile-time constant: it is an environment-specific
13
+ * database row id, so dev / staging / production each carry their own value.
14
+ * The library owns the *contract* (key name, parsing, validation, fallback
15
+ * policy); the deployment owns the *value* (see clarion-deployment configmap).
16
+ */
17
+ exports.SYSTEM_USER_ID_ENV_KEY = 'SYSTEM_USER_ID';
18
+ /**
19
+ * Per-service keys that predate {@link SYSTEM_USER_ID_ENV_KEY}.
20
+ *
21
+ * Still read — in order — when the canonical key is absent, so that a rollback
22
+ * to an older ConfigMap does not take a service down. Remove once every
23
+ * environment has been migrated to the canonical key.
24
+ *
25
+ * @deprecated Set {@link SYSTEM_USER_ID_ENV_KEY} instead.
26
+ */
27
+ exports.LEGACY_SYSTEM_USER_ID_ENV_KEYS = [
28
+ 'BILLING_DMS_SERVICE_USER_ID',
29
+ 'NEWSFEED_DMS_SERVICE_USER_ID',
30
+ ];
31
+ //# sourceMappingURL=system-user.const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user.const.js","sourceRoot":"","sources":["../../../../../src/modules/system-user/constants/system-user.const.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACU,QAAA,sBAAsB,GAAG,gBAAgB,CAAC;AAEvD;;;;;;;;GAQG;AACU,QAAA,8BAA8B,GAAsB;IAC7D,6BAA6B;IAC7B,8BAA8B;CACjC,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Constants
18
+ __exportStar(require("./constants/system-user.const"), exports);
19
+ // Interfaces
20
+ __exportStar(require("./interfaces/system-user-env-source"), exports);
21
+ // Utilities
22
+ __exportStar(require("./utils/system-user.util"), exports);
23
+ // Services
24
+ __exportStar(require("./services/system-user.service"), exports);
25
+ // Module
26
+ __exportStar(require("./system-user.module"), exports);
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/system-user/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,YAAY;AACZ,gEAA8C;AAE9C,aAAa;AACb,sEAAoD;AAEpD,YAAY;AACZ,2DAAyC;AAEzC,WAAW;AACX,iEAA+C;AAE/C,SAAS;AACT,uDAAqC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=system-user-env-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user-env-source.js","sourceRoot":"","sources":["../../../../../src/modules/system-user/interfaces/system-user-env-source.ts"],"names":[],"mappings":""}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var SystemUserService_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.SystemUserService = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const config_1 = require("@nestjs/config");
16
+ const system_user_const_1 = require("../constants/system-user.const");
17
+ const system_user_util_1 = require("../utils/system-user.util");
18
+ /**
19
+ * Single source of truth for the platform system user id inside a service.
20
+ *
21
+ * Resolution happens once, on module init, so a mis-set `SYSTEM_USER_ID`
22
+ * fails the pod's startup probe instead of surfacing later as records stamped
23
+ * with a user id that clarion-authentication cannot resolve.
24
+ *
25
+ * @example
26
+ * constructor(private readonly systemUser: SystemUserService) {}
27
+ * ...
28
+ * const actorId = userContext?.userId ?? this.systemUser.id;
29
+ */
30
+ let SystemUserService = SystemUserService_1 = class SystemUserService {
31
+ constructor(configService) {
32
+ this.configService = configService;
33
+ this.logger = new common_1.Logger(SystemUserService_1.name);
34
+ this.resolvedId = null;
35
+ }
36
+ onModuleInit() {
37
+ this.resolvedId = (0, system_user_util_1.resolveSystemUserId)(this.configService, {
38
+ onLegacyKeyUsed: (key) => this.logger.warn(`Resolved the system user id from deprecated env key "${key}". ` +
39
+ `Set ${system_user_const_1.SYSTEM_USER_ID_ENV_KEY} instead — legacy keys will be removed.`),
40
+ });
41
+ this.logger.log(`System user id resolved to ${this.resolvedId}`);
42
+ }
43
+ /**
44
+ * The system user id. Throws if read before module init completed, which
45
+ * only happens if a provider resolves it inside its own constructor.
46
+ */
47
+ get id() {
48
+ if (this.resolvedId === null) {
49
+ // Resolve on demand so constructor-time reads still work.
50
+ this.resolvedId = (0, system_user_util_1.resolveSystemUserId)(this.configService);
51
+ }
52
+ return this.resolvedId;
53
+ }
54
+ };
55
+ exports.SystemUserService = SystemUserService;
56
+ exports.SystemUserService = SystemUserService = SystemUserService_1 = __decorate([
57
+ (0, common_1.Injectable)(),
58
+ __metadata("design:paramtypes", [config_1.ConfigService])
59
+ ], SystemUserService);
60
+ //# sourceMappingURL=system-user.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user.service.js","sourceRoot":"","sources":["../../../../../src/modules/system-user/services/system-user.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkE;AAClE,2CAA+C;AAC/C,sEAAwE;AACxE,gEAAgE;AAEhE;;;;;;;;;;;GAWG;AAEI,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAI1B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAHxC,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;QACrD,eAAU,GAAkB,IAAI,CAAC;IAEoB,CAAC;IAE9D,YAAY;QACR,IAAI,CAAC,UAAU,GAAG,IAAA,sCAAmB,EAAC,IAAI,CAAC,aAAa,EAAE;YACtD,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE,CACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ,wDAAwD,GAAG,KAAK;gBAChE,OAAO,0CAAsB,yCAAyC,CACzE;SACR,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,8BAA8B,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACH,IAAI,EAAE;QACF,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC3B,0DAA0D;YAC1D,IAAI,CAAC,UAAU,GAAG,IAAA,sCAAmB,EAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ,CAAA;AA5BY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAKmC,sBAAa;GAJhD,iBAAiB,CA4B7B"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SystemUserModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const system_user_service_1 = require("./services/system-user.service");
12
+ /**
13
+ * Global module exposing {@link SystemUserService} to every provider in the
14
+ * host application. Import once in the service's root `AppModule`:
15
+ *
16
+ * @example
17
+ * @Module({ imports: [ConfigModule.forRoot({ ... }), SystemUserModule] })
18
+ * export class AppModule {}
19
+ *
20
+ * Requires `ConfigModule` to be global (the convention across clarion
21
+ * services) or otherwise available where this module is imported.
22
+ */
23
+ let SystemUserModule = class SystemUserModule {
24
+ };
25
+ exports.SystemUserModule = SystemUserModule;
26
+ exports.SystemUserModule = SystemUserModule = __decorate([
27
+ (0, common_1.Global)(),
28
+ (0, common_1.Module)({
29
+ providers: [system_user_service_1.SystemUserService],
30
+ exports: [system_user_service_1.SystemUserService],
31
+ })
32
+ ], SystemUserModule);
33
+ //# sourceMappingURL=system-user.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user.module.js","sourceRoot":"","sources":["../../../../src/modules/system-user/system-user.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,wEAAmE;AAEnE;;;;;;;;;;GAUG;AAMI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAI,CAAA;AAApB,4CAAgB;2BAAhB,gBAAgB;IAL5B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACJ,SAAS,EAAE,CAAC,uCAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,uCAAiB,CAAC;KAC/B,CAAC;GACW,gBAAgB,CAAI"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSystemUserId = parseSystemUserId;
4
+ exports.resolveSystemUserId = resolveSystemUserId;
5
+ const system_user_const_1 = require("../constants/system-user.const");
6
+ /**
7
+ * Parses a raw environment value into a usable user id.
8
+ *
9
+ * Returns `null` for anything that is not a positive integer — including
10
+ * `'0'`, `'-1'`, `'abc'` and the empty string — so that a typo'd ConfigMap
11
+ * entry surfaces as a clear failure rather than silently stamping user `0`
12
+ * onto production records.
13
+ */
14
+ function parseSystemUserId(raw) {
15
+ if (raw === null || raw === undefined) {
16
+ return null;
17
+ }
18
+ const text = String(raw).trim();
19
+ if (!text || !/^\d+$/.test(text)) {
20
+ return null;
21
+ }
22
+ const parsed = Number(text);
23
+ return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
24
+ }
25
+ /**
26
+ * Resolves the platform system user id from the environment.
27
+ *
28
+ * Precedence: {@link SYSTEM_USER_ID_ENV_KEY} → each legacy key in order →
29
+ * `options.fallback`. Throws when nothing resolves and no fallback is given,
30
+ * which is the intended behaviour at startup: a service that stamps records
31
+ * with the system user should refuse to boot rather than write a wrong id.
32
+ *
33
+ * @example
34
+ * // In a Nest provider that already injects ConfigService:
35
+ * this.systemUserId = resolveSystemUserId(this.configService);
36
+ */
37
+ function resolveSystemUserId(source, options = {}) {
38
+ const { legacyKeys = system_user_const_1.LEGACY_SYSTEM_USER_ID_ENV_KEYS, fallback, onLegacyKeyUsed } = options;
39
+ const canonical = parseSystemUserId(source.get(system_user_const_1.SYSTEM_USER_ID_ENV_KEY));
40
+ if (canonical !== null) {
41
+ return canonical;
42
+ }
43
+ for (const key of legacyKeys) {
44
+ const legacy = parseSystemUserId(source.get(key));
45
+ if (legacy !== null) {
46
+ onLegacyKeyUsed === null || onLegacyKeyUsed === void 0 ? void 0 : onLegacyKeyUsed(key);
47
+ return legacy;
48
+ }
49
+ }
50
+ if (fallback !== undefined) {
51
+ return fallback;
52
+ }
53
+ throw new Error(`${system_user_const_1.SYSTEM_USER_ID_ENV_KEY} is not set to a positive integer. ` +
54
+ `Set it to the id of the platform system user in clarion-authentication ` +
55
+ `(checked legacy keys: ${legacyKeys.length ? legacyKeys.join(', ') : 'none'}).`);
56
+ }
57
+ //# sourceMappingURL=system-user.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user.util.js","sourceRoot":"","sources":["../../../../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CAAC;IACL,CAAC;IAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,MAAM,IAAI,KAAK,CACX,GAAG,0CAAsB,qCAAqC;QAC9D,yEAAyE;QACzE,yBAAyB,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAClF,CAAC;AACN,CAAC"}
package/dist/esm/index.js CHANGED
@@ -21,6 +21,7 @@ export * from './modules/country/index';
21
21
  export * from './modules/phone/index';
22
22
  export * from './modules/tracking/index';
23
23
  export * from './modules/entitlement/index';
24
+ export * from './modules/system-user/index';
24
25
  // Interfaces
25
26
  export * from './interfaces/server-message';
26
27
  export * from './interfaces/i-request-with-user';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAE5C,aAAa;AACb,cAAc,6BAA6B,CAAC;AAC5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,CAAC;AAC7C,cAAc,uDAAuD,CAAC;AAEtE,aAAa;AACb,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Canonical environment variable that carries the platform "system user" id.
3
+ *
4
+ * The system user is a real row in the clarion-authentication `users` table
5
+ * that services stamp on records they create or mutate on their own behalf —
6
+ * i.e. when there is no authenticated human in the request (auto-assignment,
7
+ * automated status changes, service-to-service document uploads).
8
+ *
9
+ * It is deliberately NOT a compile-time constant: it is an environment-specific
10
+ * database row id, so dev / staging / production each carry their own value.
11
+ * The library owns the *contract* (key name, parsing, validation, fallback
12
+ * policy); the deployment owns the *value* (see clarion-deployment configmap).
13
+ */
14
+ export const SYSTEM_USER_ID_ENV_KEY = 'SYSTEM_USER_ID';
15
+ /**
16
+ * Per-service keys that predate {@link SYSTEM_USER_ID_ENV_KEY}.
17
+ *
18
+ * Still read — in order — when the canonical key is absent, so that a rollback
19
+ * to an older ConfigMap does not take a service down. Remove once every
20
+ * environment has been migrated to the canonical key.
21
+ *
22
+ * @deprecated Set {@link SYSTEM_USER_ID_ENV_KEY} instead.
23
+ */
24
+ export const LEGACY_SYSTEM_USER_ID_ENV_KEYS = [
25
+ 'BILLING_DMS_SERVICE_USER_ID',
26
+ 'NEWSFEED_DMS_SERVICE_USER_ID',
27
+ ];
28
+ //# sourceMappingURL=system-user.const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user.const.js","sourceRoot":"","sources":["../../../../../src/modules/system-user/constants/system-user.const.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAsB;IAC7D,6BAA6B;IAC7B,8BAA8B;CACjC,CAAC"}
@@ -0,0 +1,11 @@
1
+ // Constants
2
+ export * from './constants/system-user.const';
3
+ // Interfaces
4
+ export * from './interfaces/system-user-env-source';
5
+ // Utilities
6
+ export * from './utils/system-user.util';
7
+ // Services
8
+ export * from './services/system-user.service';
9
+ // Module
10
+ export * from './system-user.module';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/system-user/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,cAAc,+BAA+B,CAAC;AAE9C,aAAa;AACb,cAAc,qCAAqC,CAAC;AAEpD,YAAY;AACZ,cAAc,0BAA0B,CAAC;AAEzC,WAAW;AACX,cAAc,gCAAgC,CAAC;AAE/C,SAAS;AACT,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=system-user-env-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user-env-source.js","sourceRoot":"","sources":["../../../../../src/modules/system-user/interfaces/system-user-env-source.ts"],"names":[],"mappings":""}
@@ -0,0 +1,57 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var SystemUserService_1;
11
+ import { Injectable, Logger } from '@nestjs/common';
12
+ import { ConfigService } from '@nestjs/config';
13
+ import { SYSTEM_USER_ID_ENV_KEY } from '../constants/system-user.const';
14
+ import { resolveSystemUserId } from '../utils/system-user.util';
15
+ /**
16
+ * Single source of truth for the platform system user id inside a service.
17
+ *
18
+ * Resolution happens once, on module init, so a mis-set `SYSTEM_USER_ID`
19
+ * fails the pod's startup probe instead of surfacing later as records stamped
20
+ * with a user id that clarion-authentication cannot resolve.
21
+ *
22
+ * @example
23
+ * constructor(private readonly systemUser: SystemUserService) {}
24
+ * ...
25
+ * const actorId = userContext?.userId ?? this.systemUser.id;
26
+ */
27
+ let SystemUserService = SystemUserService_1 = class SystemUserService {
28
+ constructor(configService) {
29
+ this.configService = configService;
30
+ this.logger = new Logger(SystemUserService_1.name);
31
+ this.resolvedId = null;
32
+ }
33
+ onModuleInit() {
34
+ this.resolvedId = resolveSystemUserId(this.configService, {
35
+ onLegacyKeyUsed: (key) => this.logger.warn(`Resolved the system user id from deprecated env key "${key}". ` +
36
+ `Set ${SYSTEM_USER_ID_ENV_KEY} instead — legacy keys will be removed.`),
37
+ });
38
+ this.logger.log(`System user id resolved to ${this.resolvedId}`);
39
+ }
40
+ /**
41
+ * The system user id. Throws if read before module init completed, which
42
+ * only happens if a provider resolves it inside its own constructor.
43
+ */
44
+ get id() {
45
+ if (this.resolvedId === null) {
46
+ // Resolve on demand so constructor-time reads still work.
47
+ this.resolvedId = resolveSystemUserId(this.configService);
48
+ }
49
+ return this.resolvedId;
50
+ }
51
+ };
52
+ SystemUserService = SystemUserService_1 = __decorate([
53
+ Injectable(),
54
+ __metadata("design:paramtypes", [ConfigService])
55
+ ], SystemUserService);
56
+ export { SystemUserService };
57
+ //# sourceMappingURL=system-user.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user.service.js","sourceRoot":"","sources":["../../../../../src/modules/system-user/services/system-user.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAgB,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;;;;;;;;GAWG;AAEI,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAI1B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAHxC,WAAM,GAAG,IAAI,MAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;QACrD,eAAU,GAAkB,IAAI,CAAC;IAEoB,CAAC;IAE9D,YAAY;QACR,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC,aAAa,EAAE;YACtD,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE,CACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ,wDAAwD,GAAG,KAAK;gBAChE,OAAO,sBAAsB,yCAAyC,CACzE;SACR,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,8BAA8B,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACH,IAAI,EAAE;QACF,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC3B,0DAA0D;YAC1D,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ,CAAA;AA5BY,iBAAiB;IAD7B,UAAU,EAAE;qCAKmC,aAAa;GAJhD,iBAAiB,CA4B7B"}
@@ -0,0 +1,30 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Global, Module } from '@nestjs/common';
8
+ import { SystemUserService } from './services/system-user.service';
9
+ /**
10
+ * Global module exposing {@link SystemUserService} to every provider in the
11
+ * host application. Import once in the service's root `AppModule`:
12
+ *
13
+ * @example
14
+ * @Module({ imports: [ConfigModule.forRoot({ ... }), SystemUserModule] })
15
+ * export class AppModule {}
16
+ *
17
+ * Requires `ConfigModule` to be global (the convention across clarion
18
+ * services) or otherwise available where this module is imported.
19
+ */
20
+ let SystemUserModule = class SystemUserModule {
21
+ };
22
+ SystemUserModule = __decorate([
23
+ Global(),
24
+ Module({
25
+ providers: [SystemUserService],
26
+ exports: [SystemUserService],
27
+ })
28
+ ], SystemUserModule);
29
+ export { SystemUserModule };
30
+ //# sourceMappingURL=system-user.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user.module.js","sourceRoot":"","sources":["../../../../src/modules/system-user/system-user.module.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;;;;;;;;;GAUG;AAMI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAI,CAAA;AAApB,gBAAgB;IAL5B,MAAM,EAAE;IACR,MAAM,CAAC;QACJ,SAAS,EAAE,CAAC,iBAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,iBAAiB,CAAC;KAC/B,CAAC;GACW,gBAAgB,CAAI"}
@@ -0,0 +1,53 @@
1
+ import { LEGACY_SYSTEM_USER_ID_ENV_KEYS, SYSTEM_USER_ID_ENV_KEY } from '../constants/system-user.const';
2
+ /**
3
+ * Parses a raw environment value into a usable user id.
4
+ *
5
+ * Returns `null` for anything that is not a positive integer — including
6
+ * `'0'`, `'-1'`, `'abc'` and the empty string — so that a typo'd ConfigMap
7
+ * entry surfaces as a clear failure rather than silently stamping user `0`
8
+ * onto production records.
9
+ */
10
+ export function parseSystemUserId(raw) {
11
+ if (raw === null || raw === undefined) {
12
+ return null;
13
+ }
14
+ const text = String(raw).trim();
15
+ if (!text || !/^\d+$/.test(text)) {
16
+ return null;
17
+ }
18
+ const parsed = Number(text);
19
+ return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
20
+ }
21
+ /**
22
+ * Resolves the platform system user id from the environment.
23
+ *
24
+ * Precedence: {@link SYSTEM_USER_ID_ENV_KEY} → each legacy key in order →
25
+ * `options.fallback`. Throws when nothing resolves and no fallback is given,
26
+ * which is the intended behaviour at startup: a service that stamps records
27
+ * with the system user should refuse to boot rather than write a wrong id.
28
+ *
29
+ * @example
30
+ * // In a Nest provider that already injects ConfigService:
31
+ * this.systemUserId = resolveSystemUserId(this.configService);
32
+ */
33
+ export function resolveSystemUserId(source, options = {}) {
34
+ const { legacyKeys = LEGACY_SYSTEM_USER_ID_ENV_KEYS, fallback, onLegacyKeyUsed } = options;
35
+ const canonical = parseSystemUserId(source.get(SYSTEM_USER_ID_ENV_KEY));
36
+ if (canonical !== null) {
37
+ return canonical;
38
+ }
39
+ for (const key of legacyKeys) {
40
+ const legacy = parseSystemUserId(source.get(key));
41
+ if (legacy !== null) {
42
+ onLegacyKeyUsed === null || onLegacyKeyUsed === void 0 ? void 0 : onLegacyKeyUsed(key);
43
+ return legacy;
44
+ }
45
+ }
46
+ if (fallback !== undefined) {
47
+ return fallback;
48
+ }
49
+ throw new Error(`${SYSTEM_USER_ID_ENV_KEY} is not set to a positive integer. ` +
50
+ `Set it to the id of the platform system user in clarion-authentication ` +
51
+ `(checked legacy keys: ${legacyKeys.length ? legacyKeys.join(', ') : 'none'}).`);
52
+ }
53
+ //# sourceMappingURL=system-user.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-user.util.js","sourceRoot":"","sources":["../../../../../src/modules/system-user/utils/system-user.util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CA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AQ,CAAC;IACpB,CAAC;IAED,MAAM,IAAI,KAAK,CACX,GAAG,sBAAsB,qCAAqC;QAC9D,yEAAyE;QACzE,yBAAyB,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAClF,CAAC;AACN,CAAC"}
@@ -20,6 +20,7 @@ export * from './modules/country/index';
20
20
  export * from './modules/phone/index';
21
21
  export * from './modules/tracking/index';
22
22
  export * from './modules/entitlement/index';
23
+ export * from './modules/system-user/index';
23
24
  export * from './interfaces/server-message';
24
25
  export * from './interfaces/i-request-with-user';
25
26
  export * from './interfaces/validated-user';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Canonical environment variable that carries the platform "system user" id.
3
+ *
4
+ * The system user is a real row in the clarion-authentication `users` table
5
+ * that services stamp on records they create or mutate on their own behalf —
6
+ * i.e. when there is no authenticated human in the request (auto-assignment,
7
+ * automated status changes, service-to-service document uploads).
8
+ *
9
+ * It is deliberately NOT a compile-time constant: it is an environment-specific
10
+ * database row id, so dev / staging / production each carry their own value.
11
+ * The library owns the *contract* (key name, parsing, validation, fallback
12
+ * policy); the deployment owns the *value* (see clarion-deployment configmap).
13
+ */
14
+ export declare const SYSTEM_USER_ID_ENV_KEY = "SYSTEM_USER_ID";
15
+ /**
16
+ * Per-service keys that predate {@link SYSTEM_USER_ID_ENV_KEY}.
17
+ *
18
+ * Still read — in order — when the canonical key is absent, so that a rollback
19
+ * to an older ConfigMap does not take a service down. Remove once every
20
+ * environment has been migrated to the canonical key.
21
+ *
22
+ * @deprecated Set {@link SYSTEM_USER_ID_ENV_KEY} instead.
23
+ */
24
+ export declare const LEGACY_SYSTEM_USER_ID_ENV_KEYS: readonly string[];
@@ -0,0 +1,5 @@
1
+ export * from './constants/system-user.const';
2
+ export * from './interfaces/system-user-env-source';
3
+ export * from './utils/system-user.util';
4
+ export * from './services/system-user.service';
5
+ export * from './system-user.module';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Minimal read surface needed to resolve the system user id.
3
+ *
4
+ * Structurally satisfied by `ConfigService` from `@nestjs/config`, so callers
5
+ * can pass their existing config service straight through without the shared
6
+ * library taking a hard dependency on it.
7
+ */
8
+ export interface SystemUserEnvSource {
9
+ get<T = string>(key: string): T | undefined;
10
+ }
@@ -0,0 +1,26 @@
1
+ import { OnModuleInit } from '@nestjs/common';
2
+ import { ConfigService } from '@nestjs/config';
3
+ /**
4
+ * Single source of truth for the platform system user id inside a service.
5
+ *
6
+ * Resolution happens once, on module init, so a mis-set `SYSTEM_USER_ID`
7
+ * fails the pod's startup probe instead of surfacing later as records stamped
8
+ * with a user id that clarion-authentication cannot resolve.
9
+ *
10
+ * @example
11
+ * constructor(private readonly systemUser: SystemUserService) {}
12
+ * ...
13
+ * const actorId = userContext?.userId ?? this.systemUser.id;
14
+ */
15
+ export declare class SystemUserService implements OnModuleInit {
16
+ private readonly configService;
17
+ private readonly logger;
18
+ private resolvedId;
19
+ constructor(configService: ConfigService);
20
+ onModuleInit(): void;
21
+ /**
22
+ * The system user id. Throws if read before module init completed, which
23
+ * only happens if a provider resolves it inside its own constructor.
24
+ */
25
+ get id(): number;
26
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Global module exposing {@link SystemUserService} to every provider in the
3
+ * host application. Import once in the service's root `AppModule`:
4
+ *
5
+ * @example
6
+ * @Module({ imports: [ConfigModule.forRoot({ ... }), SystemUserModule] })
7
+ * export class AppModule {}
8
+ *
9
+ * Requires `ConfigModule` to be global (the convention across clarion
10
+ * services) or otherwise available where this module is imported.
11
+ */
12
+ export declare class SystemUserModule {
13
+ }
@@ -0,0 +1,41 @@
1
+ import { SystemUserEnvSource } from '../interfaces/system-user-env-source';
2
+ export interface ResolveSystemUserIdOptions {
3
+ /**
4
+ * Deprecated keys to fall back to, in order, when the canonical key is
5
+ * unset. Defaults to {@link LEGACY_SYSTEM_USER_ID_ENV_KEYS}; pass `[]` to
6
+ * disable legacy support entirely.
7
+ */
8
+ legacyKeys?: readonly string[];
9
+ /**
10
+ * Value to return when nothing resolves, instead of throwing. Use only
11
+ * where a missing system user must not stop the process from booting.
12
+ */
13
+ fallback?: number;
14
+ /**
15
+ * Invoked once per legacy-key hit so the service can surface the
16
+ * deprecation in its own logger.
17
+ */
18
+ onLegacyKeyUsed?: (key: string) => void;
19
+ }
20
+ /**
21
+ * Parses a raw environment value into a usable user id.
22
+ *
23
+ * Returns `null` for anything that is not a positive integer — including
24
+ * `'0'`, `'-1'`, `'abc'` and the empty string — so that a typo'd ConfigMap
25
+ * entry surfaces as a clear failure rather than silently stamping user `0`
26
+ * onto production records.
27
+ */
28
+ export declare function parseSystemUserId(raw: unknown): number | null;
29
+ /**
30
+ * Resolves the platform system user id from the environment.
31
+ *
32
+ * Precedence: {@link SYSTEM_USER_ID_ENV_KEY} → each legacy key in order →
33
+ * `options.fallback`. Throws when nothing resolves and no fallback is given,
34
+ * which is the intended behaviour at startup: a service that stamps records
35
+ * with the system user should refuse to boot rather than write a wrong id.
36
+ *
37
+ * @example
38
+ * // In a Nest provider that already injects ConfigService:
39
+ * this.systemUserId = resolveSystemUserId(this.configService);
40
+ */
41
+ export declare function resolveSystemUserId(source: SystemUserEnvSource, options?: ResolveSystemUserIdOptions): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grm-shared-library",
3
- "version": "1.1.192",
3
+ "version": "1.1.193",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -57,7 +57,8 @@
57
57
  "grm-shared-library": "^1.1.101",
58
58
  "libphonenumber-js": "^1.13.8",
59
59
  "rxjs": "^7.8.2",
60
- "swagger-ui-express": "^5.0.1"
60
+ "swagger-ui-express": "^5.0.1",
61
+ "@nestjs/config": "^4.0.0"
61
62
  },
62
63
  "peerDependencies": {
63
64
  "@nestjs/common": "^11.0.0",
@@ -65,6 +66,7 @@
65
66
  "@nestjs/microservices": "^11.0.0",
66
67
  "@sentry/node": "^8.0.0",
67
68
  "class-transformer": "^0.5.0",
68
- "class-validator": "^0.14.0"
69
+ "class-validator": "^0.14.0",
70
+ "@nestjs/config": "^4.0.0"
69
71
  }
70
72
  }