@trayio/commons 4.55.0 → 4.56.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/SensitiveRemoveTagAndRedactCodec.d.ts +14 -0
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts.map +1 -0
- package/dist/codec/{RedactValuesCodec.js → SensitiveRemoveTagAndRedactCodec.js} +34 -10
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.d.ts +2 -0
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.d.ts.map +1 -0
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.js +196 -0
- package/dist/sensitive/Sensitive.d.ts +2 -2
- package/dist/sensitive/Sensitive.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.js +10 -3
- package/dist/sensitive/Sensitive.unit.test.d.ts +11 -1
- package/dist/sensitive/Sensitive.unit.test.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.unit.test.js +54 -7
- package/package.json +1 -1
- package/dist/codec/RedactValuesCodec.d.ts +0 -12
- package/dist/codec/RedactValuesCodec.d.ts.map +0 -1
- package/dist/codec/RedactValuesCodec.unit.test.d.ts +0 -2
- package/dist/codec/RedactValuesCodec.unit.test.d.ts.map +0 -1
- package/dist/codec/RedactValuesCodec.unit.test.js +0 -70
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as E from 'fp-ts/lib/Either';
|
|
2
|
+
import { Codec } from './Codec';
|
|
3
|
+
export declare class SensitiveRemoveTagAndRedactCodec implements Codec<unknown> {
|
|
4
|
+
private redactValues;
|
|
5
|
+
constructor(redactValues?: boolean);
|
|
6
|
+
static instance(redactValues?: boolean): Codec<unknown>;
|
|
7
|
+
encode(value: unknown): unknown;
|
|
8
|
+
decode(value: unknown): E.Either<Error, unknown>;
|
|
9
|
+
private isObject;
|
|
10
|
+
private stripTagAndRedactValue;
|
|
11
|
+
private redactValuesFromArrayIfPresent;
|
|
12
|
+
private redactValuesFromObjectIfPresent;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=SensitiveRemoveTagAndRedactCodec.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -23,21 +23,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.SensitiveRemoveTagAndRedactCodec = void 0;
|
|
27
27
|
const E = __importStar(require("fp-ts/lib/Either"));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
class SensitiveRemoveTagAndRedactCodec {
|
|
29
|
+
redactValues;
|
|
30
|
+
constructor(redactValues = false) {
|
|
31
|
+
this.redactValues = redactValues;
|
|
32
|
+
}
|
|
33
|
+
static instance(redactValues = false) {
|
|
34
|
+
return new SensitiveRemoveTagAndRedactCodec(redactValues);
|
|
35
|
+
}
|
|
31
36
|
encode(value) {
|
|
32
|
-
return this.
|
|
37
|
+
return this.stripTagAndRedactValue(value);
|
|
33
38
|
}
|
|
34
39
|
decode(value) {
|
|
35
|
-
return E.right(this.
|
|
40
|
+
return E.right(this.stripTagAndRedactValue(value));
|
|
36
41
|
}
|
|
37
42
|
isObject(value) {
|
|
38
43
|
return typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
39
44
|
}
|
|
40
|
-
|
|
45
|
+
stripTagAndRedactValue(value) {
|
|
41
46
|
if (value === null) {
|
|
42
47
|
return value;
|
|
43
48
|
}
|
|
@@ -54,14 +59,33 @@ class RedactValuesCodec {
|
|
|
54
59
|
if (propertyValue == null) {
|
|
55
60
|
return acc;
|
|
56
61
|
}
|
|
57
|
-
return [...acc, this.
|
|
62
|
+
return [...acc, this.stripTagAndRedactValue(propertyValue)];
|
|
58
63
|
}, []);
|
|
59
64
|
}
|
|
60
65
|
redactValuesFromObjectIfPresent(value) {
|
|
61
66
|
return Object.entries(value).reduce((acc, [key, propertyValue]) => {
|
|
62
67
|
if (this.isObject(propertyValue)) {
|
|
63
68
|
if (propertyValue._tag === 'Sensitive') {
|
|
64
|
-
|
|
69
|
+
const { _tag, value: sensitiveValue } = propertyValue;
|
|
70
|
+
if (this.redactValues) {
|
|
71
|
+
return {
|
|
72
|
+
...acc,
|
|
73
|
+
[key]: '<REDACTED>',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (this.isObject(sensitiveValue)) {
|
|
77
|
+
return {
|
|
78
|
+
...acc,
|
|
79
|
+
[key]: this.redactValuesFromObjectIfPresent(sensitiveValue),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (Array.isArray(sensitiveValue)) {
|
|
83
|
+
return {
|
|
84
|
+
...acc,
|
|
85
|
+
[key]: this.redactValuesFromArrayIfPresent(sensitiveValue),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return { ...acc, [key]: sensitiveValue };
|
|
65
89
|
}
|
|
66
90
|
const nestedObject = this.redactValuesFromObjectIfPresent(propertyValue);
|
|
67
91
|
return { ...acc, [key]: nestedObject };
|
|
@@ -74,4 +98,4 @@ class RedactValuesCodec {
|
|
|
74
98
|
}, {});
|
|
75
99
|
}
|
|
76
100
|
}
|
|
77
|
-
exports.
|
|
101
|
+
exports.SensitiveRemoveTagAndRedactCodec = SensitiveRemoveTagAndRedactCodec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SensitiveRemoveTagAndRedactCodec.unit.test.d.ts","sourceRoot":"","sources":["../../src/codec/SensitiveRemoveTagAndRedactCodec.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
27
|
+
const Sensitive_1 = require("../sensitive/Sensitive");
|
|
28
|
+
const Sensitive_unit_test_1 = require("../sensitive/Sensitive.unit.test");
|
|
29
|
+
const CompositeCodec_1 = require("./CompositeCodec");
|
|
30
|
+
const SensitiveRemoveTagAndRedactCodec_1 = require("./SensitiveRemoveTagAndRedactCodec");
|
|
31
|
+
describe('SensitiveRemoveTagAndRedactCodec', () => {
|
|
32
|
+
it('should redact sensitive typed data', () => {
|
|
33
|
+
const value = {
|
|
34
|
+
password: Sensitive_1.Sensitive.fromValue('password'),
|
|
35
|
+
username: 'username',
|
|
36
|
+
address: {
|
|
37
|
+
city: 'city',
|
|
38
|
+
street: 'street',
|
|
39
|
+
number: 123,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const actualValue = SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(true).encode(value);
|
|
43
|
+
const expectedValue = {
|
|
44
|
+
password: '<REDACTED>',
|
|
45
|
+
username: 'username',
|
|
46
|
+
address: {
|
|
47
|
+
city: 'city',
|
|
48
|
+
street: 'street',
|
|
49
|
+
number: 123,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
53
|
+
});
|
|
54
|
+
it('should remove sensitive wrapper and not redact values when redactValues is false', () => {
|
|
55
|
+
const value = {
|
|
56
|
+
password: Sensitive_1.Sensitive.fromValue('password'),
|
|
57
|
+
username: 'username',
|
|
58
|
+
address: {
|
|
59
|
+
city: 'city',
|
|
60
|
+
street: 'street',
|
|
61
|
+
number: 123,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const actualValue = SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(false).encode(value);
|
|
65
|
+
const expectedValue = {
|
|
66
|
+
password: 'password',
|
|
67
|
+
username: 'username',
|
|
68
|
+
address: {
|
|
69
|
+
city: 'city',
|
|
70
|
+
street: 'street',
|
|
71
|
+
number: 123,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
75
|
+
});
|
|
76
|
+
it('should redact sensitive typed data in nested arrays', () => {
|
|
77
|
+
const value = {
|
|
78
|
+
users: [
|
|
79
|
+
{ password: Sensitive_1.Sensitive.fromValue('password'), username: 'username' },
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
const actualValue = SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(true).encode(value);
|
|
83
|
+
const expectedValue = {
|
|
84
|
+
users: [{ password: '<REDACTED>', username: 'username' }],
|
|
85
|
+
};
|
|
86
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
87
|
+
});
|
|
88
|
+
it('should redact sensitive typed data in nested objects', () => {
|
|
89
|
+
const value = {
|
|
90
|
+
user: { password: Sensitive_1.Sensitive.fromValue('password'), username: 'username' },
|
|
91
|
+
};
|
|
92
|
+
const actualValue = SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(true).encode(value);
|
|
93
|
+
const expectedValue = {
|
|
94
|
+
user: {
|
|
95
|
+
password: '<REDACTED>',
|
|
96
|
+
username: 'username',
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
100
|
+
});
|
|
101
|
+
it('should redact sensitive typed data in nested optional objects', () => {
|
|
102
|
+
const value = {
|
|
103
|
+
user: {
|
|
104
|
+
password: Sensitive_1.Sensitive.fromValue(O.some('test')),
|
|
105
|
+
username: 'username',
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const actualValue = SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(true).encode(value);
|
|
109
|
+
const expectedValue = {
|
|
110
|
+
user: {
|
|
111
|
+
password: '<REDACTED>',
|
|
112
|
+
username: 'username',
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
116
|
+
});
|
|
117
|
+
it('should not redact sensitive typed data in nested optional objects when redact values is false', () => {
|
|
118
|
+
const value = {
|
|
119
|
+
user: {
|
|
120
|
+
password: Sensitive_1.Sensitive.fromValue(O.some('test')),
|
|
121
|
+
username: 'username',
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const actualValue = SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(false).encode(value);
|
|
125
|
+
const expectedValue = {
|
|
126
|
+
user: {
|
|
127
|
+
password: O.some('test'),
|
|
128
|
+
username: 'username',
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
expect(actualValue).toStrictEqual(expectedValue);
|
|
132
|
+
});
|
|
133
|
+
it('should redact sensitive typed data and type encode the value', () => {
|
|
134
|
+
const testValueEncoded = {
|
|
135
|
+
strField: 'str',
|
|
136
|
+
intField: Sensitive_1.Sensitive.fromValue(O.some(123)),
|
|
137
|
+
objectField: Sensitive_1.Sensitive.fromValue({
|
|
138
|
+
str: 'test',
|
|
139
|
+
int: 123,
|
|
140
|
+
optionalObj: Sensitive_1.Sensitive.fromValue(O.some({
|
|
141
|
+
test: 'test',
|
|
142
|
+
test1: 'test1',
|
|
143
|
+
testArray: Sensitive_1.Sensitive.fromValue([
|
|
144
|
+
O.some('test1'),
|
|
145
|
+
O.some('test2'),
|
|
146
|
+
O.some('test3'),
|
|
147
|
+
]),
|
|
148
|
+
})),
|
|
149
|
+
}),
|
|
150
|
+
};
|
|
151
|
+
const redactAndTypeDecode = CompositeCodec_1.CompositeCodec.fromCodecs(Sensitive_unit_test_1.testTypeSensitiveCodec, SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(true));
|
|
152
|
+
const result = redactAndTypeDecode.encode(testValueEncoded);
|
|
153
|
+
const expected = {
|
|
154
|
+
strField: 'str',
|
|
155
|
+
intField: '<REDACTED>',
|
|
156
|
+
objectField: '<REDACTED>',
|
|
157
|
+
};
|
|
158
|
+
expect(result).toStrictEqual(expected);
|
|
159
|
+
});
|
|
160
|
+
it('should not redact sensitive typed data and type encode the value', () => {
|
|
161
|
+
const testValueEncoded = {
|
|
162
|
+
strField: 'str',
|
|
163
|
+
intField: Sensitive_1.Sensitive.fromValue(O.some(123)),
|
|
164
|
+
objectField: Sensitive_1.Sensitive.fromValue({
|
|
165
|
+
str: 'test',
|
|
166
|
+
int: 123,
|
|
167
|
+
optionalObj: Sensitive_1.Sensitive.fromValue(O.some({
|
|
168
|
+
test: 'test',
|
|
169
|
+
test1: 'test1',
|
|
170
|
+
testArray: Sensitive_1.Sensitive.fromValue([
|
|
171
|
+
O.some('test'),
|
|
172
|
+
O.some('test1'),
|
|
173
|
+
O.some('test2'),
|
|
174
|
+
O.some('test3'),
|
|
175
|
+
]),
|
|
176
|
+
})),
|
|
177
|
+
}),
|
|
178
|
+
};
|
|
179
|
+
const redactAndTypeDecode = CompositeCodec_1.CompositeCodec.fromCodecs(Sensitive_unit_test_1.testTypeSensitiveCodec, SensitiveRemoveTagAndRedactCodec_1.SensitiveRemoveTagAndRedactCodec.instance(false));
|
|
180
|
+
const result = redactAndTypeDecode.encode(testValueEncoded);
|
|
181
|
+
const expected = {
|
|
182
|
+
strField: 'str',
|
|
183
|
+
intField: 123,
|
|
184
|
+
objectField: {
|
|
185
|
+
int: 123,
|
|
186
|
+
str: 'test',
|
|
187
|
+
optionalObj: {
|
|
188
|
+
test: 'test',
|
|
189
|
+
test1: 'test1',
|
|
190
|
+
testArray: ['test', 'test1', 'test2', 'test3'],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
expect(result).toStrictEqual(expected);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -6,8 +6,8 @@ export type Sensitive<T> = {
|
|
|
6
6
|
};
|
|
7
7
|
export interface SensitiveInterface {
|
|
8
8
|
fromValue: <T>(value: T) => Sensitive<T>;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
typeDescriptor: <T>(descriptor: t.Type<T, unknown>) => t.Type<Sensitive<T>, Sensitive<unknown>>;
|
|
10
|
+
typeCodec: <T>(descriptor: t.Type<T, unknown>) => Codec<Sensitive<T>>;
|
|
11
11
|
}
|
|
12
12
|
export declare const Sensitive: SensitiveInterface;
|
|
13
13
|
//# sourceMappingURL=Sensitive.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sensitive.d.ts","sourceRoot":"","sources":["../../src/sensitive/Sensitive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Sensitive.d.ts","sourceRoot":"","sources":["../../src/sensitive/Sensitive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,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,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,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9C,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CACtE;AAyBD,eAAO,MAAM,SAAS,EAAE,kBAQvB,CAAC"}
|
|
@@ -25,14 +25,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.Sensitive = void 0;
|
|
27
27
|
const t = __importStar(require("io-ts"));
|
|
28
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
29
|
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) =>
|
|
30
|
-
const
|
|
30
|
+
const sensitiveTypeDescriptor = (descriptor) => new t.Type('Sensitive', (u) => u instanceof Object && '_tag' in u && u._tag === 'Sensitive', (u, c) => {
|
|
31
|
+
const validation = descriptor.validate(u, c);
|
|
32
|
+
if (E.isLeft(validation)) {
|
|
33
|
+
return t.failure(u, c, validation.left.map((e) => e.message).join('\n'));
|
|
34
|
+
}
|
|
35
|
+
return t.success(exports.Sensitive.fromValue(validation.right));
|
|
36
|
+
}, (a) => exports.Sensitive.fromValue(descriptor.encode(a.value)));
|
|
37
|
+
const sensitiveTypeCodec = (descriptor) => TypeCodec_1.TypeCodec.fromDescriptor(sensitiveTypeDescriptor(descriptor));
|
|
31
38
|
exports.Sensitive = {
|
|
32
39
|
fromValue: (value) => ({
|
|
33
40
|
value,
|
|
34
41
|
_tag: 'Sensitive',
|
|
35
42
|
}),
|
|
43
|
+
typeDescriptor: (descriptor) => sensitiveTypeDescriptor(descriptor),
|
|
36
44
|
typeCodec: sensitiveTypeCodec,
|
|
37
|
-
typeDescriptor: (descriptor) => descriptor.pipe(sensitiveTypeDescriptor()),
|
|
38
45
|
};
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import * as O from 'fp-ts/Option';
|
|
1
2
|
import { Codec } from '../codec/Codec';
|
|
2
3
|
import { Sensitive } from './Sensitive';
|
|
3
4
|
export type TestTypeSensitive = {
|
|
4
5
|
strField: string;
|
|
5
|
-
intField: Sensitive<number
|
|
6
|
+
intField: Sensitive<O.Option<number>>;
|
|
7
|
+
objectField: Sensitive<{
|
|
8
|
+
int: number;
|
|
9
|
+
str: string;
|
|
10
|
+
optionalObj: Sensitive<O.Option<{
|
|
11
|
+
test: string;
|
|
12
|
+
test1: string;
|
|
13
|
+
testArray: Sensitive<O.Option<string>[]>;
|
|
14
|
+
}>>;
|
|
15
|
+
}>;
|
|
6
16
|
};
|
|
7
17
|
export declare const testTypeSensitiveCodec: Codec<TestTypeSensitive>;
|
|
8
18
|
//# 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,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;
|
|
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"}
|
|
@@ -26,35 +26,82 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.testTypeSensitiveCodec = void 0;
|
|
27
27
|
const E = __importStar(require("fp-ts/Either"));
|
|
28
28
|
const t = __importStar(require("io-ts"));
|
|
29
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
30
|
+
const td = __importStar(require("io-ts-types"));
|
|
29
31
|
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
30
32
|
const Sensitive_1 = require("./Sensitive");
|
|
31
33
|
exports.testTypeSensitiveCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
32
34
|
strField: t.string,
|
|
33
|
-
intField: Sensitive_1.Sensitive.typeDescriptor(t.number),
|
|
35
|
+
intField: Sensitive_1.Sensitive.typeDescriptor(td.optionFromNullable(t.number)),
|
|
36
|
+
objectField: Sensitive_1.Sensitive.typeDescriptor(t.type({
|
|
37
|
+
int: t.number,
|
|
38
|
+
str: t.string,
|
|
39
|
+
optionalObj: Sensitive_1.Sensitive.typeDescriptor(td.optionFromNullable(t.type({
|
|
40
|
+
test: t.string,
|
|
41
|
+
test1: t.string,
|
|
42
|
+
testArray: Sensitive_1.Sensitive.typeDescriptor(t.array(td.optionFromNullable(t.string))),
|
|
43
|
+
}))),
|
|
44
|
+
})),
|
|
34
45
|
}));
|
|
35
46
|
describe('Sensitive', () => {
|
|
36
47
|
describe('encode/decode sensitive values', () => {
|
|
37
48
|
it('should encode sensitive typed data without the extra layer', () => {
|
|
38
49
|
const testValueEncoded = {
|
|
39
50
|
strField: 'str',
|
|
40
|
-
intField: Sensitive_1.Sensitive.fromValue(123),
|
|
51
|
+
intField: Sensitive_1.Sensitive.fromValue(O.some(123)),
|
|
52
|
+
objectField: Sensitive_1.Sensitive.fromValue({
|
|
53
|
+
str: 'test',
|
|
54
|
+
int: 123,
|
|
55
|
+
optionalObj: Sensitive_1.Sensitive.fromValue(O.some({
|
|
56
|
+
test: 'test',
|
|
57
|
+
test1: 'test1',
|
|
58
|
+
testArray: Sensitive_1.Sensitive.fromValue([O.some('test')]),
|
|
59
|
+
})),
|
|
60
|
+
}),
|
|
41
61
|
};
|
|
42
62
|
const result = exports.testTypeSensitiveCodec.encode(testValueEncoded);
|
|
43
63
|
const expected = {
|
|
44
64
|
strField: 'str',
|
|
45
|
-
intField: 123,
|
|
65
|
+
intField: Sensitive_1.Sensitive.fromValue(123),
|
|
66
|
+
objectField: Sensitive_1.Sensitive.fromValue({
|
|
67
|
+
int: 123,
|
|
68
|
+
str: 'test',
|
|
69
|
+
optionalObj: Sensitive_1.Sensitive.fromValue({
|
|
70
|
+
test: 'test',
|
|
71
|
+
test1: 'test1',
|
|
72
|
+
testArray: Sensitive_1.Sensitive.fromValue(['test']),
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
46
75
|
};
|
|
47
76
|
expect(result).toStrictEqual(expected);
|
|
48
77
|
});
|
|
49
78
|
it('should decode sensitive typed data without the extra layer', () => {
|
|
50
|
-
const
|
|
79
|
+
const testValueDecoded = {
|
|
51
80
|
strField: 'str',
|
|
52
|
-
intField:
|
|
81
|
+
intField: undefined,
|
|
82
|
+
objectField: {
|
|
83
|
+
int: 123,
|
|
84
|
+
str: 'test',
|
|
85
|
+
optionalObj: {
|
|
86
|
+
test: 'test',
|
|
87
|
+
test1: 'test1',
|
|
88
|
+
testArray: [],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
53
91
|
};
|
|
54
|
-
const result = exports.testTypeSensitiveCodec.decode(
|
|
92
|
+
const result = exports.testTypeSensitiveCodec.decode(testValueDecoded);
|
|
55
93
|
const expected = E.right({
|
|
56
94
|
strField: 'str',
|
|
57
|
-
intField: Sensitive_1.Sensitive.fromValue(
|
|
95
|
+
intField: Sensitive_1.Sensitive.fromValue(O.none),
|
|
96
|
+
objectField: Sensitive_1.Sensitive.fromValue({
|
|
97
|
+
str: 'test',
|
|
98
|
+
int: 123,
|
|
99
|
+
optionalObj: Sensitive_1.Sensitive.fromValue(O.some({
|
|
100
|
+
test: 'test',
|
|
101
|
+
test1: 'test1',
|
|
102
|
+
testArray: Sensitive_1.Sensitive.fromValue([]),
|
|
103
|
+
})),
|
|
104
|
+
}),
|
|
58
105
|
});
|
|
59
106
|
expect(result).toStrictEqual(expected);
|
|
60
107
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RedactValuesCodec.unit.test.d.ts","sourceRoot":"","sources":["../../src/codec/RedactValuesCodec.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
});
|