@trayio/commons 4.31.0 → 4.32.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.
- package/dist/codec/RedactValuesCodec.d.ts +12 -0
- package/dist/codec/RedactValuesCodec.d.ts.map +1 -0
- package/dist/codec/RedactValuesCodec.js +77 -0
- package/dist/codec/RedactValuesCodec.unit.test.d.ts +2 -0
- package/dist/codec/RedactValuesCodec.unit.test.d.ts.map +1 -0
- package/dist/codec/RedactValuesCodec.unit.test.js +70 -0
- package/dist/sensitive/Sensitive.d.ts +13 -0
- package/dist/sensitive/Sensitive.d.ts.map +1 -0
- package/dist/sensitive/Sensitive.js +38 -0
- package/dist/sensitive/Sensitive.unit.test.d.ts +8 -0
- package/dist/sensitive/Sensitive.unit.test.d.ts.map +1 -0
- package/dist/sensitive/Sensitive.unit.test.js +62 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as E from 'fp-ts/lib/Either';
|
|
2
|
+
import { Codec } from './Codec';
|
|
3
|
+
export declare class RedactValuesCodec implements Codec<unknown> {
|
|
4
|
+
static instance: Codec<unknown>;
|
|
5
|
+
encode(value: unknown): unknown;
|
|
6
|
+
decode(value: unknown): E.Either<Error, unknown>;
|
|
7
|
+
private isObject;
|
|
8
|
+
private redactSensitiveValues;
|
|
9
|
+
private redactValuesFromArrayIfPresent;
|
|
10
|
+
private redactValuesFromObjectIfPresent;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=RedactValuesCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedactValuesCodec.d.ts","sourceRoot":"","sources":["../../src/codec/RedactValuesCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,qBAAa,iBAAkB,YAAW,KAAK,CAAC,OAAO,CAAC;IACvD,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAA2B;IAE1D,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,qBAAqB;IAa7B,OAAO,CAAC,8BAA8B;IAStC,OAAO,CAAC,+BAA+B;CAiBvC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.RedactValuesCodec = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/lib/Either"));
|
|
28
|
+
const Sensitive_1 = require("../sensitive/Sensitive");
|
|
29
|
+
class RedactValuesCodec {
|
|
30
|
+
static instance = new RedactValuesCodec();
|
|
31
|
+
encode(value) {
|
|
32
|
+
return this.redactSensitiveValues(value);
|
|
33
|
+
}
|
|
34
|
+
decode(value) {
|
|
35
|
+
return E.right(this.redactSensitiveValues(value));
|
|
36
|
+
}
|
|
37
|
+
isObject(value) {
|
|
38
|
+
return typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
39
|
+
}
|
|
40
|
+
redactSensitiveValues(value) {
|
|
41
|
+
if (value === null) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
if (this.isObject(value)) {
|
|
45
|
+
return this.redactValuesFromObjectIfPresent(value);
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
return this.redactValuesFromArrayIfPresent(value);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
redactValuesFromArrayIfPresent(value) {
|
|
53
|
+
return value.reduce((acc, propertyValue) => {
|
|
54
|
+
if (propertyValue == null) {
|
|
55
|
+
return acc;
|
|
56
|
+
}
|
|
57
|
+
return [...acc, this.redactSensitiveValues(propertyValue)];
|
|
58
|
+
}, []);
|
|
59
|
+
}
|
|
60
|
+
redactValuesFromObjectIfPresent(value) {
|
|
61
|
+
return Object.entries(value).reduce((acc, [key, propertyValue]) => {
|
|
62
|
+
if (this.isObject(propertyValue)) {
|
|
63
|
+
if (propertyValue._tag === 'Sensitive') {
|
|
64
|
+
return { ...acc, [key]: Sensitive_1.Sensitive.fromValue('<REDACTED>') };
|
|
65
|
+
}
|
|
66
|
+
const nestedObject = this.redactValuesFromObjectIfPresent(propertyValue);
|
|
67
|
+
return { ...acc, [key]: nestedObject };
|
|
68
|
+
}
|
|
69
|
+
if (Array.isArray(propertyValue)) {
|
|
70
|
+
const nestedArray = this.redactValuesFromArrayIfPresent(propertyValue);
|
|
71
|
+
return { ...acc, [key]: nestedArray };
|
|
72
|
+
}
|
|
73
|
+
return { ...acc, [key]: propertyValue };
|
|
74
|
+
}, {});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.RedactValuesCodec = RedactValuesCodec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedactValuesCodec.unit.test.d.ts","sourceRoot":"","sources":["../../src/codec/RedactValuesCodec.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Sensitive_1 = require("../sensitive/Sensitive");
|
|
4
|
+
const Sensitive_unit_test_1 = require("../sensitive/Sensitive.unit.test");
|
|
5
|
+
const CompositeCodec_1 = require("./CompositeCodec");
|
|
6
|
+
const RedactValuesCodec_1 = require("./RedactValuesCodec");
|
|
7
|
+
describe('redactValue Codec', () => {
|
|
8
|
+
it('should redact sensitive typed data', () => {
|
|
9
|
+
const value = {
|
|
10
|
+
password: Sensitive_1.Sensitive.fromValue('password'),
|
|
11
|
+
username: 'username',
|
|
12
|
+
address: {
|
|
13
|
+
city: 'city',
|
|
14
|
+
street: 'street',
|
|
15
|
+
number: 123,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const actualValue = RedactValuesCodec_1.RedactValuesCodec.instance.encode(value);
|
|
19
|
+
const expectedValue = {
|
|
20
|
+
password: Sensitive_1.Sensitive.fromValue('<REDACTED>'),
|
|
21
|
+
username: 'username',
|
|
22
|
+
address: {
|
|
23
|
+
city: 'city',
|
|
24
|
+
street: 'street',
|
|
25
|
+
number: 123,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
29
|
+
});
|
|
30
|
+
it('should redact sensitive typed data in nested arrays', () => {
|
|
31
|
+
const value = {
|
|
32
|
+
users: [
|
|
33
|
+
{ password: Sensitive_1.Sensitive.fromValue('password'), username: 'username' },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
const actualValue = RedactValuesCodec_1.RedactValuesCodec.instance.encode(value);
|
|
37
|
+
const expectedValue = {
|
|
38
|
+
users: [
|
|
39
|
+
{ password: Sensitive_1.Sensitive.fromValue('<REDACTED>'), username: 'username' },
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
43
|
+
});
|
|
44
|
+
it('should redact sensitive typed data in nested objects', () => {
|
|
45
|
+
const value = {
|
|
46
|
+
user: { password: Sensitive_1.Sensitive.fromValue('password'), username: 'username' },
|
|
47
|
+
};
|
|
48
|
+
const actualValue = RedactValuesCodec_1.RedactValuesCodec.instance.encode(value);
|
|
49
|
+
const expectedValue = {
|
|
50
|
+
user: {
|
|
51
|
+
password: Sensitive_1.Sensitive.fromValue('<REDACTED>'),
|
|
52
|
+
username: 'username',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
56
|
+
});
|
|
57
|
+
it('should redact sensitive typed data and type encode the value', () => {
|
|
58
|
+
const testValueEncoded = {
|
|
59
|
+
strField: 'str',
|
|
60
|
+
intField: Sensitive_1.Sensitive.fromValue(123),
|
|
61
|
+
};
|
|
62
|
+
const redactAndTypeDecode = CompositeCodec_1.CompositeCodec.fromCodecs(RedactValuesCodec_1.RedactValuesCodec.instance, Sensitive_unit_test_1.testTypeSensitiveCodec);
|
|
63
|
+
const result = redactAndTypeDecode.encode(testValueEncoded);
|
|
64
|
+
const expected = {
|
|
65
|
+
strField: 'str',
|
|
66
|
+
intField: '<REDACTED>',
|
|
67
|
+
};
|
|
68
|
+
expect(result).toStrictEqual(expected);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as t from 'io-ts';
|
|
2
|
+
import { Codec } from '../codec/Codec';
|
|
3
|
+
export type Sensitive<T> = {
|
|
4
|
+
value: T;
|
|
5
|
+
readonly _tag: 'Sensitive';
|
|
6
|
+
};
|
|
7
|
+
export interface SensitiveInterface {
|
|
8
|
+
fromValue: <T>(value: T) => Sensitive<T>;
|
|
9
|
+
typeCodec: Codec<Sensitive<unknown>>;
|
|
10
|
+
typeDescriptor: <T>(descriptor: t.Type<T, unknown>) => t.Type<Sensitive<T>, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export declare const Sensitive: SensitiveInterface;
|
|
13
|
+
//# sourceMappingURL=Sensitive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sensitive.d.ts","sourceRoot":"","sources":["../../src/sensitive/Sensitive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAC1B,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,kBAAkB;IAClC,SAAS,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC;IACzC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACrC,cAAc,EAAE,CAAC,CAAC,EACjB,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,KAC1B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;CACnC;AAeD,eAAO,MAAM,SAAS,EAAE,kBAQvB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Sensitive = void 0;
|
|
27
|
+
const t = __importStar(require("io-ts"));
|
|
28
|
+
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
29
|
+
const sensitiveTypeDescriptor = () => new t.Type('Sensitive', (u) => u instanceof Object && '_tag' in u && u._tag === 'Sensitive', (u, c) => t.success(exports.Sensitive.fromValue(u)), (a) => a.value);
|
|
30
|
+
const sensitiveTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(sensitiveTypeDescriptor());
|
|
31
|
+
exports.Sensitive = {
|
|
32
|
+
fromValue: (value) => ({
|
|
33
|
+
value,
|
|
34
|
+
_tag: 'Sensitive',
|
|
35
|
+
}),
|
|
36
|
+
typeCodec: sensitiveTypeCodec,
|
|
37
|
+
typeDescriptor: (descriptor) => descriptor.pipe(sensitiveTypeDescriptor()),
|
|
38
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Codec } from '../codec/Codec';
|
|
2
|
+
import { Sensitive } from './Sensitive';
|
|
3
|
+
export type TestTypeSensitive = {
|
|
4
|
+
strField: string;
|
|
5
|
+
intField: Sensitive<number>;
|
|
6
|
+
};
|
|
7
|
+
export declare const testTypeSensitiveCodec: Codec<TestTypeSensitive>;
|
|
8
|
+
//# sourceMappingURL=Sensitive.unit.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sensitive.unit.test.d.ts","sourceRoot":"","sources":["../../src/sensitive/Sensitive.unit.test.ts"],"names":[],"mappings":"AAEA,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,MAAM,CAAC,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,iBAAiB,CAM1D,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.testTypeSensitiveCodec = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
const t = __importStar(require("io-ts"));
|
|
29
|
+
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
30
|
+
const Sensitive_1 = require("./Sensitive");
|
|
31
|
+
exports.testTypeSensitiveCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
32
|
+
strField: t.string,
|
|
33
|
+
intField: Sensitive_1.Sensitive.typeDescriptor(t.number),
|
|
34
|
+
}));
|
|
35
|
+
describe('Sensitive', () => {
|
|
36
|
+
describe('encode/decode sensitive values', () => {
|
|
37
|
+
it('should encode sensitive typed data without the extra layer', () => {
|
|
38
|
+
const testValueEncoded = {
|
|
39
|
+
strField: 'str',
|
|
40
|
+
intField: Sensitive_1.Sensitive.fromValue(123),
|
|
41
|
+
};
|
|
42
|
+
const result = exports.testTypeSensitiveCodec.encode(testValueEncoded);
|
|
43
|
+
const expected = {
|
|
44
|
+
strField: 'str',
|
|
45
|
+
intField: 123,
|
|
46
|
+
};
|
|
47
|
+
expect(result).toStrictEqual(expected);
|
|
48
|
+
});
|
|
49
|
+
it('should decode sensitive typed data without the extra layer', () => {
|
|
50
|
+
const testValueEncoded = {
|
|
51
|
+
strField: 'str',
|
|
52
|
+
intField: 123,
|
|
53
|
+
};
|
|
54
|
+
const result = exports.testTypeSensitiveCodec.decode(testValueEncoded);
|
|
55
|
+
const expected = E.right({
|
|
56
|
+
strField: 'str',
|
|
57
|
+
intField: Sensitive_1.Sensitive.fromValue(123),
|
|
58
|
+
});
|
|
59
|
+
expect(result).toStrictEqual(expected);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|