@trayio/commons 4.54.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/file/File.d.ts +2 -30
- package/dist/file/File.d.ts.map +1 -1
- package/dist/file/File.js +4 -65
- package/dist/http/Http.d.ts +1 -11
- package/dist/http/Http.d.ts.map +1 -1
- package/dist/http/Http.js +0 -10
- 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 +3 -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
|
+
});
|
package/dist/file/File.d.ts
CHANGED
|
@@ -4,42 +4,14 @@ import { TaskEither } from 'fp-ts/TaskEither';
|
|
|
4
4
|
import * as t from 'io-ts';
|
|
5
5
|
import { Option } from 'fp-ts/lib/Option';
|
|
6
6
|
import { DynamicObject } from '../dynamictype/DynamicType';
|
|
7
|
-
export declare enum FileContentType {
|
|
8
|
-
Text = "text/plain",
|
|
9
|
-
Html = "text/html",
|
|
10
|
-
Css = "text/css",
|
|
11
|
-
Javascript = "application/javascript",
|
|
12
|
-
Xml = "application/xml",
|
|
13
|
-
Pdf = "application/pdf",
|
|
14
|
-
Zip = "application/zip",
|
|
15
|
-
Gif = "image/gif",
|
|
16
|
-
Jpeg = "image/jpeg",
|
|
17
|
-
Jpg = "image/jpg",
|
|
18
|
-
Png = "image/png",
|
|
19
|
-
Svg = "image/svg+xml",
|
|
20
|
-
Bmp = "image/bmp",
|
|
21
|
-
Webp = "image/webp",
|
|
22
|
-
Ico = "image/x-icon",
|
|
23
|
-
Tiff = "image/tiff",
|
|
24
|
-
Heic = "image/heic",
|
|
25
|
-
Heif = "image/heif",
|
|
26
|
-
AudioMidi = "audio/midi",
|
|
27
|
-
AudioMpeg = "audio/mpeg",
|
|
28
|
-
AudioWebm = "audio/webm",
|
|
29
|
-
AudioOgg = "audio/ogg",
|
|
30
|
-
AudioWav = "audio/wav",
|
|
31
|
-
VideoWebm = "video/webm",
|
|
32
|
-
VideoOgg = "video/ogg",
|
|
33
|
-
VideoMp4 = "video/mp4"
|
|
34
|
-
}
|
|
35
7
|
export interface FileContentTypeCheckerInterface {
|
|
36
|
-
isFileContentType(value: unknown): value is
|
|
8
|
+
isFileContentType(value: unknown): value is string;
|
|
37
9
|
}
|
|
38
10
|
export declare const FileContentTypeChecker: FileContentTypeCheckerInterface;
|
|
39
11
|
export type FileMetadata = {
|
|
40
12
|
name: string;
|
|
41
13
|
size?: number;
|
|
42
|
-
contentType?:
|
|
14
|
+
contentType?: string;
|
|
43
15
|
};
|
|
44
16
|
export declare const fileMetadataDescriptor: t.Type<FileMetadata, unknown>;
|
|
45
17
|
export declare const fileDescriptorDescriptor: t.Type<FileDescriptor, unknown>;
|
package/dist/file/File.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../src/file/File.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../src/file/File.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,WAAW,+BAA+B;IAC/C,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC;CACnD;AAED,eAAO,MAAM,sBAAsB,EAAE,+BAQpC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,OAA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importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.FileDescriptor = exports.fileDescriptorDescriptor = exports.fileMetadataDescriptor = exports.FileContentTypeChecker =
|
|
26
|
+
exports.FileDescriptor = exports.fileDescriptorDescriptor = exports.fileMetadataDescriptor = exports.FileContentTypeChecker = void 0;
|
|
27
27
|
const t = __importStar(require("io-ts"));
|
|
28
|
-
|
|
29
|
-
(function (FileContentType) {
|
|
30
|
-
FileContentType["Text"] = "text/plain";
|
|
31
|
-
FileContentType["Html"] = "text/html";
|
|
32
|
-
FileContentType["Css"] = "text/css";
|
|
33
|
-
FileContentType["Javascript"] = "application/javascript";
|
|
34
|
-
FileContentType["Xml"] = "application/xml";
|
|
35
|
-
FileContentType["Pdf"] = "application/pdf";
|
|
36
|
-
FileContentType["Zip"] = "application/zip";
|
|
37
|
-
// Image types
|
|
38
|
-
FileContentType["Gif"] = "image/gif";
|
|
39
|
-
FileContentType["Jpeg"] = "image/jpeg";
|
|
40
|
-
FileContentType["Jpg"] = "image/jpg";
|
|
41
|
-
FileContentType["Png"] = "image/png";
|
|
42
|
-
FileContentType["Svg"] = "image/svg+xml";
|
|
43
|
-
FileContentType["Bmp"] = "image/bmp";
|
|
44
|
-
FileContentType["Webp"] = "image/webp";
|
|
45
|
-
FileContentType["Ico"] = "image/x-icon";
|
|
46
|
-
FileContentType["Tiff"] = "image/tiff";
|
|
47
|
-
FileContentType["Heic"] = "image/heic";
|
|
48
|
-
FileContentType["Heif"] = "image/heif";
|
|
49
|
-
// Audio types
|
|
50
|
-
FileContentType["AudioMidi"] = "audio/midi";
|
|
51
|
-
FileContentType["AudioMpeg"] = "audio/mpeg";
|
|
52
|
-
FileContentType["AudioWebm"] = "audio/webm";
|
|
53
|
-
FileContentType["AudioOgg"] = "audio/ogg";
|
|
54
|
-
FileContentType["AudioWav"] = "audio/wav";
|
|
55
|
-
// Video types
|
|
56
|
-
FileContentType["VideoWebm"] = "video/webm";
|
|
57
|
-
FileContentType["VideoOgg"] = "video/ogg";
|
|
58
|
-
FileContentType["VideoMp4"] = "video/mp4";
|
|
59
|
-
})(FileContentType || (exports.FileContentType = FileContentType = {}));
|
|
28
|
+
const mime = __importStar(require("mime-types"));
|
|
60
29
|
exports.FileContentTypeChecker = {
|
|
61
30
|
isFileContentType(value) {
|
|
62
31
|
if (typeof value !== 'string') {
|
|
63
32
|
return false;
|
|
64
33
|
}
|
|
65
34
|
const lowerCaseValue = value.toLowerCase();
|
|
66
|
-
return
|
|
67
|
-
.map((contentType) => contentType.toLowerCase())
|
|
68
|
-
.includes(lowerCaseValue);
|
|
35
|
+
return mime.contentType(lowerCaseValue) !== false;
|
|
69
36
|
},
|
|
70
37
|
};
|
|
71
|
-
const contentTypeDescriptor = t.union([
|
|
72
|
-
t.literal(FileContentType.Text),
|
|
73
|
-
t.literal(FileContentType.Html),
|
|
74
|
-
t.literal(FileContentType.Css),
|
|
75
|
-
t.literal(FileContentType.Javascript),
|
|
76
|
-
t.literal(FileContentType.Xml),
|
|
77
|
-
t.literal(FileContentType.Gif),
|
|
78
|
-
t.literal(FileContentType.Jpeg),
|
|
79
|
-
t.literal(FileContentType.Jpg),
|
|
80
|
-
t.literal(FileContentType.Png),
|
|
81
|
-
t.literal(FileContentType.Svg),
|
|
82
|
-
t.literal(FileContentType.Pdf),
|
|
83
|
-
t.literal(FileContentType.Zip),
|
|
84
|
-
t.literal(FileContentType.Bmp),
|
|
85
|
-
t.literal(FileContentType.Webp),
|
|
86
|
-
t.literal(FileContentType.Ico),
|
|
87
|
-
t.literal(FileContentType.Tiff),
|
|
88
|
-
t.literal(FileContentType.Heic),
|
|
89
|
-
t.literal(FileContentType.Heif),
|
|
90
|
-
t.literal(FileContentType.AudioMidi),
|
|
91
|
-
t.literal(FileContentType.AudioMpeg),
|
|
92
|
-
t.literal(FileContentType.AudioWebm),
|
|
93
|
-
t.literal(FileContentType.AudioOgg),
|
|
94
|
-
t.literal(FileContentType.AudioWav),
|
|
95
|
-
t.literal(FileContentType.VideoWebm),
|
|
96
|
-
t.literal(FileContentType.VideoOgg),
|
|
97
|
-
t.literal(FileContentType.VideoMp4),
|
|
98
|
-
]);
|
|
99
38
|
exports.fileMetadataDescriptor = t.intersection([
|
|
100
39
|
t.type({
|
|
101
40
|
name: t.string,
|
|
102
41
|
}),
|
|
103
42
|
t.partial({
|
|
104
43
|
size: t.number,
|
|
105
|
-
contentType:
|
|
44
|
+
contentType: t.string,
|
|
106
45
|
}),
|
|
107
46
|
]);
|
|
108
47
|
exports.fileDescriptorDescriptor = t.type({
|
package/dist/http/Http.d.ts
CHANGED
|
@@ -55,17 +55,7 @@ export declare enum HttpContentType {
|
|
|
55
55
|
OctetStream = "application/octet-stream",
|
|
56
56
|
FormUrlEncoded = "application/x-www-form-urlencoded",
|
|
57
57
|
MultipartRequestBody = "multipart/form-data",
|
|
58
|
-
Text = "text/plain"
|
|
59
|
-
Html = "text/html",
|
|
60
|
-
Css = "text/css",
|
|
61
|
-
Javascript = "application/javascript",
|
|
62
|
-
Xml = "application/xml",
|
|
63
|
-
Gif = "image/gif",
|
|
64
|
-
Jpeg = "image/jpeg",
|
|
65
|
-
Png = "image/png",
|
|
66
|
-
Svg = "image/svg+xml",
|
|
67
|
-
Pdf = "application/pdf",
|
|
68
|
-
Zip = "application/zip"
|
|
58
|
+
Text = "text/plain"
|
|
69
59
|
}
|
|
70
60
|
export declare enum HttpHeader {
|
|
71
61
|
Authorization = "Authorization",
|
package/dist/http/Http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../src/http/Http.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC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AE,oBASzB,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACvE,kBAAkB,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/D,iBAAiB,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,WAAW,CAAC;IAC3D,eAAe,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,aAAa,CAAC;CACzD;AAED,eAAO,MAAM,WAAW,EAAE,oBAyIzB,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACxD,mBAAmB,EACnB,eAAe,CAIf,CAAC;AAEF,eAAO,MAAM,eAAe,SACrB,eAAe,qCAEkC,CAAC"}
|
package/dist/http/Http.js
CHANGED
|
@@ -82,16 +82,6 @@ var HttpContentType;
|
|
|
82
82
|
HttpContentType["FormUrlEncoded"] = "application/x-www-form-urlencoded";
|
|
83
83
|
HttpContentType["MultipartRequestBody"] = "multipart/form-data";
|
|
84
84
|
HttpContentType["Text"] = "text/plain";
|
|
85
|
-
HttpContentType["Html"] = "text/html";
|
|
86
|
-
HttpContentType["Css"] = "text/css";
|
|
87
|
-
HttpContentType["Javascript"] = "application/javascript";
|
|
88
|
-
HttpContentType["Xml"] = "application/xml";
|
|
89
|
-
HttpContentType["Gif"] = "image/gif";
|
|
90
|
-
HttpContentType["Jpeg"] = "image/jpeg";
|
|
91
|
-
HttpContentType["Png"] = "image/png";
|
|
92
|
-
HttpContentType["Svg"] = "image/svg+xml";
|
|
93
|
-
HttpContentType["Pdf"] = "application/pdf";
|
|
94
|
-
HttpContentType["Zip"] = "application/zip";
|
|
95
85
|
})(HttpContentType || (exports.HttpContentType = HttpContentType = {}));
|
|
96
86
|
var HttpHeader;
|
|
97
87
|
(function (HttpHeader) {
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/commons",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.56.0",
|
|
4
4
|
"description": "Extensions to the standard/core libraries and basic features",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@types/formidable": "3.4.5",
|
|
18
|
+
"@types/mime-types": "^2.1.4",
|
|
18
19
|
"@types/node": "18.11.9",
|
|
19
20
|
"@types/uuid": "9.0.2",
|
|
20
21
|
"ajv": "^8.12.0",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"io-ts-reporters": "2.0.1",
|
|
29
30
|
"io-ts-types": "0.5.19",
|
|
30
31
|
"lodash": "4.17.21",
|
|
32
|
+
"mime-types": "^2.1.35",
|
|
31
33
|
"monocle-ts": "2.3.13",
|
|
32
34
|
"newtype-ts": "0.3.5",
|
|
33
35
|
"uuid": "9.0.0",
|
|
@@ -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
|
-
});
|