@coast/service-common 2.0.65 → 2.0.67

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.
@@ -4,4 +4,5 @@ export declare class HmacUtils {
4
4
  private static algorithm;
5
5
  private static encoding;
6
6
  static sign(data: string, secret: HmacSecretKey): HmacSignature;
7
+ static generateSecret(): HmacSecretKey;
7
8
  }
@@ -5,12 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HmacUtils = void 0;
7
7
  const node_crypto_1 = __importDefault(require("node:crypto"));
8
+ const HmacSecretKey_1 = require("./HmacSecretKey");
8
9
  const HmacSignature_1 = require("./HmacSignature");
9
10
  class HmacUtils {
10
11
  static sign(data, secret) {
11
12
  const hmac = node_crypto_1.default.createHmac(HmacUtils.algorithm, secret);
12
13
  return (0, HmacSignature_1.HmacSignature)(hmac.update(data).digest().toString(HmacUtils.encoding));
13
14
  }
15
+ static generateSecret() {
16
+ return (0, HmacSecretKey_1.HmacSecretKey)(node_crypto_1.default.randomBytes(32).toString('hex'));
17
+ }
14
18
  }
15
19
  exports.HmacUtils = HmacUtils;
16
20
  HmacUtils.algorithm = 'sha256';
@@ -1 +1 @@
1
- {"version":3,"file":"HmacUtils.js","sourceRoot":"","sources":["../../lib/crypto/HmacUtils.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAGjC,mDAAgD;AAEhD,MAAa,SAAS;IAIX,MAAM,CAAC,IAAI,CAAC,IAAY,EAAE,MAAqB;QAClD,MAAM,IAAI,GAAG,qBAAM,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE5D,OAAO,IAAA,6BAAa,EAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClF,CAAC;;AARL,8BASC;AARkB,mBAAS,GAAG,QAAQ,CAAC;AACrB,kBAAQ,GAAmB,QAAQ,CAAC"}
1
+ {"version":3,"file":"HmacUtils.js","sourceRoot":"","sources":["../../lib/crypto/HmacUtils.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAEjC,mDAAgD;AAChD,mDAAgD;AAEhD,MAAa,SAAS;IAIX,MAAM,CAAC,IAAI,CAAC,IAAY,EAAE,MAAqB;QAClD,MAAM,IAAI,GAAG,qBAAM,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE5D,OAAO,IAAA,6BAAa,EAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClF,CAAC;IAEM,MAAM,CAAC,cAAc;QACxB,OAAO,IAAA,6BAAa,EAAC,qBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACjE,CAAC;;AAZL,8BAaC;AAZkB,mBAAS,GAAG,QAAQ,CAAC;AACrB,kBAAQ,GAAmB,QAAQ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export interface PathRedaction<T = object> {
2
+ keys?: Array<keyof T>;
3
+ fieldNames?: string[];
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=PathRedaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PathRedaction.js","sourceRoot":"","sources":["../../../lib/logger/redaction/PathRedaction.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export type Redactable = Record<string, any>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Redactable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Redactable.js","sourceRoot":"","sources":["../../../lib/logger/redaction/Redactable.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import type { PathRedaction } from './PathRedaction';
2
+ import type { Redactable } from './Redactable';
3
+ export declare class RedactionUtils {
4
+ static redactKey(_k: unknown): string;
5
+ static redact<T extends Redactable = Redactable>(k: T | null | undefined, options?: PathRedaction<T>): T | null | undefined;
6
+ private static shouldRedact;
7
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedactionUtils = void 0;
4
+ class RedactionUtils {
5
+ static redactKey(_k) {
6
+ return '<redacted>';
7
+ }
8
+ static redact(k, options = { fieldNames: [] }) {
9
+ if (k === undefined || k === null) {
10
+ return k;
11
+ }
12
+ if (typeof k === 'object') {
13
+ return Object.keys(k).reduce((acc, key) => {
14
+ if (RedactionUtils.shouldRedact(key, options)) {
15
+ acc[key] = RedactionUtils.redactKey(k[key]);
16
+ }
17
+ else {
18
+ acc[key] = RedactionUtils.redact(k[key], { fieldNames: options.fieldNames });
19
+ }
20
+ return acc;
21
+ }, {});
22
+ }
23
+ return k;
24
+ }
25
+ static shouldRedact(key, redaction) {
26
+ const allRedactionFieldNames = new Set([...(redaction.keys ?? []), ...(redaction.fieldNames ?? [])].map((i) => i.toString().toLowerCase().replace('_', '')));
27
+ return allRedactionFieldNames.has(key.toLowerCase().replace('_', ''));
28
+ }
29
+ }
30
+ exports.RedactionUtils = RedactionUtils;
31
+ //# sourceMappingURL=RedactionUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RedactionUtils.js","sourceRoot":"","sources":["../../../lib/logger/redaction/RedactionUtils.ts"],"names":[],"mappings":";;;AAGA,MAAa,cAAc;IACvB,MAAM,CAAC,SAAS,CAAC,EAAW;QACxB,OAAO,YAAY,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,MAAM,CACT,CAAuB,EACvB,UAA4B,EAAE,UAAU,EAAE,EAAE,EAAE;QAE9C,IAAI,CAAC,K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import 'reflect-metadata';
2
+ import type { PathRedaction } from './PathRedaction';
3
+ export declare function Sensitive<T extends object = object>(redaction?: PathRedaction<T>): (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sensitive = Sensitive;
4
+ require("reflect-metadata");
5
+ const SensitiveSymbol_1 = require("./SensitiveSymbol");
6
+ function Sensitive(redaction) {
7
+ return (target, propertyKey, parameterIndex) => {
8
+ const existingRequiredParameters = Reflect.getOwnMetadata(SensitiveSymbol_1.SENSITIVE, target, propertyKey) || {
9
+ keys: [],
10
+ };
11
+ existingRequiredParameters.keys.push({ index: parameterIndex, redaction: redaction ?? true });
12
+ Reflect.defineMetadata(SensitiveSymbol_1.SENSITIVE, existingRequiredParameters, target, propertyKey);
13
+ };
14
+ }
15
+ //# sourceMappingURL=Sensitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sensitive.js","sourceRoot":"","sources":["../../../lib/logger/redaction/Sensitive.ts"],"names":[],"mappings":";;AAaA,8BAUC;AAvBD,4BAA0B;AAK1B,uDAA8C;AAQ9C,SAAgB,SAAS,CAA4B,SAA4B;IAC7E,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,cAAsB,EAAE,EAAE;QAC5E,MAAM,0BAA0B,GAAyB,OAAO,CAAC,cAAc,CAAC,2BAAS,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI;YAC/G,IAAI,EAAE,EAAE;SACX,CAAC;QAEF,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,IAAI,IAAI,EAAE,CAAC,CAAC;QAE9F,OAAO,CAAC,cAAc,CAAC,2BAAS,EAAE,0BAA0B,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACvF,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { PathRedaction } from './PathRedaction';
2
+ export interface SensitiveMetadata<T extends object = object> {
3
+ keys: Array<{
4
+ index: number;
5
+ redaction: boolean | PathRedaction<T> | undefined;
6
+ }>;
7
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=SensitiveMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SensitiveMetadata.js","sourceRoot":"","sources":["../../../lib/logger/redaction/SensitiveMetadata.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare const SENSITIVE: unique symbol;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SENSITIVE = void 0;
4
+ exports.SENSITIVE = Symbol('Sensitive');
5
+ //# sourceMappingURL=SensitiveSymbol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SensitiveSymbol.js","sourceRoot":"","sources":["../../../lib/logger/redaction/SensitiveSymbol.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coast/service-common",
3
- "version": "2.0.65",
3
+ "version": "2.0.67",
4
4
  "description": "Common service package",
5
5
  "engines": {
6
6
  "node": ">=20.0.0"
@@ -38,6 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "pino": "^9.6.0",
41
+ "reflect-metadata": "^0.2.2",
41
42
  "uuid": "^11.0.5"
42
43
  },
43
44
  "devDependencies": {
@@ -46,6 +47,7 @@
46
47
  "@types/jest": "^29.5.14",
47
48
  "@types/node": "^22.13.4",
48
49
  "@types/pino": "^7.0.5",
50
+ "fast-check": "^4.5.3",
49
51
  "jest": "^29.7.0",
50
52
  "pino-test": "^1.1.0",
51
53
  "ts-jest": "^29.2.5",