@trayio/commons 4.56.0 → 4.58.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SensitiveRemoveTagAndRedactCodec.d.ts","sourceRoot":"","sources":["../../src/codec/SensitiveRemoveTagAndRedactCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,gCAAiC,YAAW,KAAK,CAAC,OAAO,CAAC;IAC1D,OAAO,CAAC,YAAY;gBAAZ,YAAY,GAAE,OAAe;IAEjD,MAAM,CAAC,QAAQ,CAAC,YAAY,UAAQ,GAAG,KAAK,CAAC,OAAO,CAAC;IAIrD,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI/B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;IAIhD,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,8BAA8B;IAStC,OAAO,CAAC,+BAA+B;CAyCvC"}
1
+ {"version":3,"file":"SensitiveRemoveTagAndRedactCodec.d.ts","sourceRoot":"","sources":["../../src/codec/SensitiveRemoveTagAndRedactCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,gCAAiC,YAAW,KAAK,CAAC,OAAO,CAAC;IAC1D,OAAO,CAAC,YAAY;gBAAZ,YAAY,GAAE,OAAe;IAEjD,MAAM,CAAC,QAAQ,CAAC,YAAY,UAAQ,GAAG,KAAK,CAAC,OAAO,CAAC;IAIrD,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI/B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;IAIhD,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,8BAA8B;IAStC,OAAO,CAAC,+BAA+B;CAyCvC"}
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.SensitiveRemoveTagAndRedactCodec = void 0;
27
27
  const E = __importStar(require("fp-ts/lib/Either"));
28
+ const lodash_1 = require("lodash");
28
29
  class SensitiveRemoveTagAndRedactCodec {
29
30
  redactValues;
30
31
  constructor(redactValues = false) {
@@ -37,10 +38,10 @@ class SensitiveRemoveTagAndRedactCodec {
37
38
  return this.stripTagAndRedactValue(value);
38
39
  }
39
40
  decode(value) {
40
- return E.right(this.stripTagAndRedactValue(value));
41
+ return E.right(value);
41
42
  }
42
43
  isObject(value) {
43
- return typeof value === 'object' && !Array.isArray(value) && value !== null;
44
+ return (0, lodash_1.isPlainObject)(value);
44
45
  }
45
46
  stripTagAndRedactValue(value) {
46
47
  if (value === null) {
@@ -98,11 +98,15 @@ describe('SensitiveRemoveTagAndRedactCodec', () => {
98
98
  };
99
99
  expect(actualValue).toStrictEqual(expectedValue);
100
100
  });
101
- it('should redact sensitive typed data in nested optional objects', () => {
101
+ it('should redact sensitive typed data in nested optional objects when redact values is true', () => {
102
+ const dob = new Date();
103
+ const creationDate = new Date();
102
104
  const value = {
103
105
  user: {
104
106
  password: Sensitive_1.Sensitive.fromValue(O.some('test')),
105
107
  username: 'username',
108
+ dob: Sensitive_1.Sensitive.fromValue(dob),
109
+ creationDate,
106
110
  },
107
111
  };
108
112
  const actualValue = SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(true).encode(value);
@@ -110,15 +114,21 @@ describe('SensitiveRemoveTagAndRedactCodec', () => {
110
114
  user: {
111
115
  password: '<REDACTED>',
112
116
  username: 'username',
117
+ dob: '<REDACTED>',
118
+ creationDate,
113
119
  },
114
120
  };
115
121
  expect(actualValue).toStrictEqual(expectedValue);
116
122
  });
117
123
  it('should not redact sensitive typed data in nested optional objects when redact values is false', () => {
124
+ const dob = new Date();
125
+ const creationDate = new Date();
118
126
  const value = {
119
127
  user: {
120
128
  password: Sensitive_1.Sensitive.fromValue(O.some('test')),
121
129
  username: 'username',
130
+ dob: Sensitive_1.Sensitive.fromValue(dob),
131
+ creationDate,
122
132
  },
123
133
  };
124
134
  const actualValue = SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(false).encode(value);
@@ -126,6 +136,8 @@ describe('SensitiveRemoveTagAndRedactCodec', () => {
126
136
  user: {
127
137
  password: O.some('test'),
128
138
  username: 'username',
139
+ dob,
140
+ creationDate,
129
141
  },
130
142
  };
131
143
  expect(actualValue).toStrictEqual(expectedValue);
@@ -148,7 +160,7 @@ describe('SensitiveRemoveTagAndRedactCodec', () => {
148
160
  })),
149
161
  }),
150
162
  };
151
- const redactAndTypeDecode = CompositeCodec_1.CompositeCodec.fromCodecs(Sensitive_unit_test_1.testTypeSensitiveCodec, SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(true));
163
+ const redactAndTypeDecode = Sensitive_unit_test_1.testTypeSensitiveRedactionCodec;
152
164
  const result = redactAndTypeDecode.encode(testValueEncoded);
153
165
  const expected = {
154
166
  strField: 'str',
@@ -2,7 +2,7 @@ import * as E from 'fp-ts/lib/Either';
2
2
  import * as t from 'io-ts';
3
3
  import { Codec } from './Codec';
4
4
  export declare class TypeCodec<T> implements Codec<T> {
5
- static fromDescriptor<T>(descriptor: t.Type<T, unknown>): Codec<T>;
5
+ static fromDescriptor<T>(descriptor: t.Type<T, unknown>, redactValues?: boolean): Codec<T>;
6
6
  static undefined: Codec<undefined>;
7
7
  static unknown: Codec<unknown>;
8
8
  static emptyRecord: Codec<{}>;
@@ -1 +1 @@
1
- {"version":3,"file":"TypeCodec.d.ts","sourceRoot":"","sources":["../../src/codec/TypeCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAK3B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,SAAS,CAAC,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IAC5C,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IAIlE,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAEhC;IAEF,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAgD;IAC9E,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,CAA4C;IACzE,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAElB;IAIhC,MAAM,CAAC,aAAa,oHAGoB;IAExC,OAAO,CAAC,UAAU,CAAqB;IAEvC,OAAO;IAIP,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO;IAIzB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;CAQ1C"}
1
+ {"version":3,"file":"TypeCodec.d.ts","sourceRoot":"","sources":["../../src/codec/TypeCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAK3B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAIhC,qBAAa,SAAS,CAAC,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IAC5C,MAAM,CAAC,cAAc,CAAC,CAAC,EACtB,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,EAC9B,YAAY,GAAE,OAAe,GAC3B,KAAK,CAAC,CAAC,CAAC;IAOX,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAEhC;IAEF,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAgD;IAC9E,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,CAA4C;IACzE,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAElB;IAIhC,MAAM,CAAC,aAAa,oHAGoB;IAExC,OAAO,CAAC,UAAU,CAAqB;IAEvC,OAAO;IAIP,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO;IAIzB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;CAQ1C"}
@@ -32,9 +32,11 @@ const t = __importStar(require("io-ts"));
32
32
  const io_ts_reporters_1 = __importDefault(require("io-ts-reporters"));
33
33
  const Record_1 = require("fp-ts/Record");
34
34
  const function_1 = require("fp-ts/function");
35
+ const CompositeCodec_1 = require("./CompositeCodec");
36
+ const SensitiveRemoveTagAndRedactCodec_1 = require("./SensitiveRemoveTagAndRedactCodec");
35
37
  class TypeCodec {
36
- static fromDescriptor(descriptor) {
37
- return new TypeCodec(descriptor);
38
+ static fromDescriptor(descriptor, redactValues = false) {
39
+ return CompositeCodec_1.CompositeCodec.fromCodecs(new TypeCodec(descriptor), SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(redactValues));
38
40
  }
39
41
  static undefined = TypeCodec.fromDescriptor(t.undefined);
40
42
  static unknown = TypeCodec.fromDescriptor(t.unknown);
@@ -14,5 +14,6 @@ export type TestTypeSensitive = {
14
14
  }>>;
15
15
  }>;
16
16
  };
17
+ export declare const testTypeSensitiveRedactionCodec: Codec<TestTypeSensitive>;
17
18
  export declare const testTypeSensitiveCodec: Codec<TestTypeSensitive>;
18
19
  //# sourceMappingURL=Sensitive.unit.test.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Sensitive.unit.test.d.ts","sourceRoot":"","sources":["../../src/sensitive/Sensitive.unit.test.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACtC,WAAW,EAAE,SAAS,CAAC;QACtB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,EAAE,SAAS,CACrB,CAAC,CAAC,MAAM,CAAC;YACR,IAAI,EAAE,MAAM,CAAC;YACb,KAAK,EAAE,MAAM,CAAC;YACd,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACzC,CAAC,CACF,CAAC;KACF,CAAC,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,iBAAiB,CAuB1D,CAAC"}
1
+ {"version":3,"file":"Sensitive.unit.test.d.ts","sourceRoot":"","sources":["../../src/sensitive/Sensitive.unit.test.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACtC,WAAW,EAAE,SAAS,CAAC;QACtB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,EAAE,SAAS,CACrB,CAAC,CAAC,MAAM,CAAC;YACR,IAAI,EAAE,MAAM,CAAC;YACb,KAAK,EAAE,MAAM,CAAC;YACd,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACzC,CAAC,CACF,CAAC;KACF,CAAC,CAAC;CACH,CAAC;AAwBF,eAAO,MAAM,+BAA+B,EAAE,KAAK,CAAC,iBAAiB,CAInE,CAAC;AAEH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,iBAAiB,CACiB,CAAC"}
@@ -23,14 +23,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.testTypeSensitiveCodec = void 0;
26
+ exports.testTypeSensitiveCodec = exports.testTypeSensitiveRedactionCodec = void 0;
27
27
  const E = __importStar(require("fp-ts/Either"));
28
28
  const t = __importStar(require("io-ts"));
29
29
  const O = __importStar(require("fp-ts/Option"));
30
30
  const td = __importStar(require("io-ts-types"));
31
31
  const TypeCodec_1 = require("../codec/TypeCodec");
32
32
  const Sensitive_1 = require("./Sensitive");
33
- exports.testTypeSensitiveCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
33
+ const testTypeSensitiveTypeDescriptor = t.type({
34
34
  strField: t.string,
35
35
  intField: Sensitive_1.Sensitive.typeDescriptor(td.optionFromNullable(t.number)),
36
36
  objectField: Sensitive_1.Sensitive.typeDescriptor(t.type({
@@ -42,7 +42,9 @@ exports.testTypeSensitiveCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
42
42
  testArray: Sensitive_1.Sensitive.typeDescriptor(t.array(td.optionFromNullable(t.string))),
43
43
  }))),
44
44
  })),
45
- }));
45
+ });
46
+ exports.testTypeSensitiveRedactionCodec = TypeCodec_1.TypeCodec.fromDescriptor(testTypeSensitiveTypeDescriptor, true);
47
+ exports.testTypeSensitiveCodec = TypeCodec_1.TypeCodec.fromDescriptor(testTypeSensitiveTypeDescriptor);
46
48
  describe('Sensitive', () => {
47
49
  describe('encode/decode sensitive values', () => {
48
50
  it('should encode sensitive typed data without the extra layer', () => {
@@ -62,16 +64,16 @@ describe('Sensitive', () => {
62
64
  const result = exports.testTypeSensitiveCodec.encode(testValueEncoded);
63
65
  const expected = {
64
66
  strField: 'str',
65
- intField: Sensitive_1.Sensitive.fromValue(123),
66
- objectField: Sensitive_1.Sensitive.fromValue({
67
+ intField: 123,
68
+ objectField: {
67
69
  int: 123,
68
70
  str: 'test',
69
- optionalObj: Sensitive_1.Sensitive.fromValue({
71
+ optionalObj: {
70
72
  test: 'test',
71
73
  test1: 'test1',
72
- testArray: Sensitive_1.Sensitive.fromValue(['test']),
73
- }),
74
- }),
74
+ testArray: ['test'],
75
+ },
76
+ },
75
77
  };
76
78
  expect(result).toStrictEqual(expected);
77
79
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/commons",
3
- "version": "4.56.0",
3
+ "version": "4.58.0",
4
4
  "description": "Extensions to the standard/core libraries and basic features",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"