@frontegg/entitlements-javascript-commons 1.0.0-alpha.12 → 1.0.0-alpha.14
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/operations/date/sanitizers.d.ts +2 -0
- package/dist/operations/date/sanitizers.js +9 -2
- package/dist/operations/date/sanitizers.js.map +1 -1
- package/dist/operations/numeric/sanitizers.js +2 -2
- package/dist/user-entitlements/attributes.utils.js +2 -2
- package/dist/user-entitlements/attributes.utils.js.map +1 -1
- package/dist/user-entitlements/flatten.utils.d.ts +8 -0
- package/dist/user-entitlements/flatten.utils.js +39 -0
- package/dist/user-entitlements/flatten.utils.js.map +1 -0
- package/docs/CHANGELOG.md +14 -0
- package/package.json +1 -5
- package/src/operations/date/sanitizers.ts +11 -1
- package/src/operations/date/tests/sanitizers.spec.ts +18 -1
- package/src/operations/numeric/sanitizers.ts +2 -2
- package/src/user-entitlements/attributes.utils.ts +1 -2
- package/src/user-entitlements/flatten.utils.ts +52 -0
- package/src/user-entitlements/tests/attributes.utils.spec.ts +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Sanitizer, SanitizersMapper } from '../types';
|
|
2
2
|
import { BetweenDateOperationPayload, DateOperationPayload, SingleDateOperationPayload } from './types';
|
|
3
|
+
export declare const sanitizeDateValue: (value: Date | string | number) => Date;
|
|
4
|
+
export declare const isValidDate: (value: unknown) => boolean;
|
|
3
5
|
export declare const sanitizeSingleDate: Sanitizer<SingleDateOperationPayload>;
|
|
4
6
|
export declare const sanitizeDateRange: Sanitizer<BetweenDateOperationPayload>;
|
|
5
7
|
export declare const DateSanitizersMapper: SanitizersMapper<DateOperationPayload>;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DateSanitizersMapper = exports.sanitizeDateRange = exports.sanitizeSingleDate = void 0;
|
|
3
|
+
exports.DateSanitizersMapper = exports.sanitizeDateRange = exports.sanitizeSingleDate = exports.isValidDate = exports.sanitizeDateValue = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
+
const sanitizeDateValue = (value) => {
|
|
6
|
+
return new Date(value);
|
|
7
|
+
};
|
|
8
|
+
exports.sanitizeDateValue = sanitizeDateValue;
|
|
9
|
+
const isValidDate = (value) => value instanceof Date && !isNaN(value);
|
|
10
|
+
exports.isValidDate = isValidDate;
|
|
5
11
|
const sanitizeSingleDate = (value) => {
|
|
6
|
-
const
|
|
12
|
+
const sanitizedDateValue = value.date ? (0, exports.sanitizeDateValue)(value.date) : undefined;
|
|
13
|
+
const sanitizedValue = sanitizedDateValue && (0, exports.isValidDate)(sanitizedDateValue) ? { date: sanitizedDateValue } : undefined;
|
|
7
14
|
return {
|
|
8
15
|
isSanitized: !!sanitizedValue,
|
|
9
16
|
sanitizedValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizers.js","sourceRoot":"","sources":["../../../src/operations/date/sanitizers.ts"],"names":[],"mappings":";;;AAAA,oCAAsE;
|
|
1
|
+
{"version":3,"file":"sanitizers.js","sourceRoot":"","sources":["../../../src/operations/date/sanitizers.ts"],"names":[],"mappings":";;;AAAA,oCAAsE;AAK/D,MAAM,iBAAiB,GAAG,CAAC,KAA6B,EAAQ,EAAE;IACvE,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,WAAW,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,KAAK,YAAY,IAAI,IAAI,CAAC,KAAK,CAAC,KAA0B,CAAC,CAAC;AAAvG,QAAA,WAAW,eAA4F;AAE7G,MAAM,kBAAkB,GAA0C,CAAC,KAAK,EAAE,EAAE;IACjF,MAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,yBAAiB,EAAC,KAAK,CAAC,IAAoB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClG,MAAM,cAAc,GAClB,kBAAkB,IAAI,IAAA,mBAAW,EAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnG,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B;AAEK,MAAM,iBAAiB,GAA2C,CAAC,KAAK,EAAE,EAAE;IACjF,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAa,EAAE,GAAG,EAAE,KAAK,CAAC,GAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAErH,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,iBAAiB,qBAO5B;AAEW,QAAA,oBAAoB,GAA2C;IAC1E,CAAC,qBAAa,CAAC,EAAE,CAAC,EAAE,0BAAkB;IACtC,CAAC,qBAAa,CAAC,SAAS,CAAC,EAAE,yBAAiB;IAC5C,CAAC,qBAAa,CAAC,UAAU,CAAC,EAAE,0BAAkB;IAC9C,CAAC,qBAAa,CAAC,WAAW,CAAC,EAAE,0BAAkB;CAChD,CAAC"}
|
|
@@ -23,10 +23,10 @@ const sanitizeNumericRange = (value) => {
|
|
|
23
23
|
exports.sanitizeNumericRange = sanitizeNumericRange;
|
|
24
24
|
exports.NumericSanitizersMapper = {
|
|
25
25
|
[types_1.OperationEnum.Equal]: exports.sanitizeSingleNumber,
|
|
26
|
-
[types_1.OperationEnum.GreaterThan]: exports.
|
|
26
|
+
[types_1.OperationEnum.GreaterThan]: exports.sanitizeSingleNumber,
|
|
27
27
|
[types_1.OperationEnum.GreaterThanEqual]: exports.sanitizeSingleNumber,
|
|
28
28
|
[types_1.OperationEnum.LesserThan]: exports.sanitizeSingleNumber,
|
|
29
|
-
[types_1.OperationEnum.LesserThanEqual]: exports.
|
|
29
|
+
[types_1.OperationEnum.LesserThanEqual]: exports.sanitizeSingleNumber,
|
|
30
30
|
[types_1.OperationEnum.BetweenNumeric]: exports.sanitizeNumericRange,
|
|
31
31
|
};
|
|
32
32
|
//# sourceMappingURL=sanitizers.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.modifyObjectKeysWithPrefix = exports.defaultFronteggAttributesMapper = exports.prepareAttributes = void 0;
|
|
4
|
-
const
|
|
4
|
+
const flatten_utils_1 = require("./flatten.utils");
|
|
5
5
|
/**
|
|
6
6
|
* Merges both `custom` and `jwt` records, map Frontegg attributes and modifies record keys with corrisponding prefixes
|
|
7
7
|
*
|
|
@@ -11,7 +11,7 @@ const flat_1 = require("flat");
|
|
|
11
11
|
*/
|
|
12
12
|
function prepareAttributes(attributes = {}, customFronteggAttributesMapper) {
|
|
13
13
|
const { custom = {}, jwt = {} } = attributes;
|
|
14
|
-
const flatJwtAttributes = (0,
|
|
14
|
+
const flatJwtAttributes = (0, flatten_utils_1.flatten)(jwt);
|
|
15
15
|
const fronteggAttributes = customFronteggAttributesMapper
|
|
16
16
|
? customFronteggAttributesMapper(jwt)
|
|
17
17
|
: defaultFronteggAttributesMapper(jwt);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.utils.js","sourceRoot":"","sources":["../../src/user-entitlements/attributes.utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"attributes.utils.js","sourceRoot":"","sources":["../../src/user-entitlements/attributes.utils.ts"],"names":[],"mappings":";;;AACA,mDAA0C;AAC1C;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,aAAyB,EAAE,EAC3B,8BAAqF;IAErF,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC;IAC7C,MAAM,iBAAiB,GAAG,IAAA,uBAAO,EAA+B,GAAG,CAAC,CAAC;IACrE,MAAM,kBAAkB,GAAG,8BAA8B;QACvD,CAAC,CAAC,8BAA8B,CAAC,GAAG,CAAC;QACrC,CAAC,CAAC,+BAA+B,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,wBAAwB,GAAG,WAAW,CAAC;IAC7C,MAAM,mBAAmB,GAAG,MAAM,CAAC;IAEnC,OAAO;QACL,GAAG,MAAM;QACT,GAAG,0BAA0B,CAAC,kBAAkB,EAAE,wBAAwB,CAAC;QAC3E,GAAG,0BAA0B,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;KACtE,CAAC;AACJ,CAAC;AAjBD,8CAiBC;AAED,SAAgB,+BAA+B,CAAC,GAAkB;IAChE,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,KAAe;QAC1B,aAAa,EAAE,GAAG,CAAC,cAAyB;QAC5C,QAAQ,EAAE,GAAG,CAAC,QAAkB;QAChC,MAAM,EAAE,GAAG,CAAC,MAAgB;KAC7B,CAAC;AACJ,CAAC;AAPD,0EAOC;AAED,SAAgB,0BAA0B,CAAC,MAA+B,EAAE,MAAc;IACxF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,UAAU,EAAE,EAAE;QAC/D,cAAc,CAAC,GAAG,MAAM,GAAG,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QAC9D,OAAO,cAAc,CAAC;IACxB,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AALD,gEAKC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** DISCLAIMER - THIS CODE BELONGS TO https://github.com/hughsk/flat */
|
|
2
|
+
export interface FlattenOptions {
|
|
3
|
+
delimiter?: string;
|
|
4
|
+
maxDepth?: number;
|
|
5
|
+
safe?: boolean;
|
|
6
|
+
transformKey?: (key: string) => string;
|
|
7
|
+
}
|
|
8
|
+
export declare function flatten<TTraget, TResult>(target: TTraget, opts?: FlattenOptions): TResult;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flatten = void 0;
|
|
4
|
+
function flatten(target, opts) {
|
|
5
|
+
opts = opts || {};
|
|
6
|
+
const delimiter = (opts === null || opts === void 0 ? void 0 : opts.delimiter) || '.';
|
|
7
|
+
const maxDepth = opts === null || opts === void 0 ? void 0 : opts.maxDepth;
|
|
8
|
+
const transformKey = (opts === null || opts === void 0 ? void 0 : opts.transformKey) || keyIdentity;
|
|
9
|
+
const output = {};
|
|
10
|
+
function step(object, prev, currentDepth) {
|
|
11
|
+
currentDepth = currentDepth || 1;
|
|
12
|
+
Object.keys(object).forEach(function (key) {
|
|
13
|
+
const value = object[key];
|
|
14
|
+
const isarray = (opts === null || opts === void 0 ? void 0 : opts.safe) && Array.isArray(value);
|
|
15
|
+
const type = Object.prototype.toString.call(value);
|
|
16
|
+
const isbuffer = isBuffer(value);
|
|
17
|
+
const isobject = type === '[object Object]' || type === '[object Array]';
|
|
18
|
+
const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
|
|
19
|
+
if (!isarray &&
|
|
20
|
+
!isbuffer &&
|
|
21
|
+
isobject &&
|
|
22
|
+
Object.keys(value).length &&
|
|
23
|
+
(!(opts === null || opts === void 0 ? void 0 : opts.maxDepth) || (maxDepth && currentDepth < maxDepth))) {
|
|
24
|
+
return step(value, newKey, currentDepth + 1);
|
|
25
|
+
}
|
|
26
|
+
output[newKey] = value;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
step(target);
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
exports.flatten = flatten;
|
|
33
|
+
function isBuffer(obj) {
|
|
34
|
+
return obj && obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
|
|
35
|
+
}
|
|
36
|
+
function keyIdentity(key) {
|
|
37
|
+
return key;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=flatten.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten.utils.js","sourceRoot":"","sources":["../../src/user-entitlements/flatten.utils.ts"],"names":[],"mappings":";;;AAQA,SAAgB,OAAO,CAAmB,MAAe,EAAE,IAAqB;IAC9E,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAElB,MAAM,SAAS,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,KAAI,GAAG,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC;IAChC,MAAM,YAAY,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,KAAI,WAAW,CAAC;IACvD,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,SAAS,IAAI,CAAC,MAAM,EAAE,IAAK,EAAE,YAAa;QACxC,YAAY,GAAG,YAAY,IAAI,CAAC,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,GAAG;YACvC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,OAAO,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,KAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACnD,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnD,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,IAAI,KAAK,iBAAiB,IAAI,IAAI,KAAK,gBAAgB,CAAC;YAEzE,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAC/E,IACE,CAAC,OAAO;gBACR,CAAC,QAAQ;gBACT,QAAQ;gBACR,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM;gBACzB,CAAC,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAA,IAAI,CAAC,QAAQ,IAAI,YAAY,GAAG,QAAQ,CAAC,CAAC,EAC1D;gBACA,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;aAC9C;YAED,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,CAAC;IAEb,OAAO,MAAiB,CAAC;AAC3B,CAAC;AAnCD,0BAmCC;AAED,SAAS,QAAQ,CAAC,GAAG;IACnB,OAAO,GAAG,IAAI,GAAG,CAAC,WAAW,IAAI,OAAO,GAAG,CAAC,WAAW,CAAC,QAAQ,KAAK,UAAU,IAAI,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACnH,CAAC;AAED,SAAS,WAAW,CAAC,GAAG;IACtB,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.0.0-alpha.14](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.0-alpha.13...v-1.0.0-alpha.14) (2023-10-24)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **sanitizers:** fix numeric and date sanitizers ([#24](https://github.com/frontegg/entitlements-javascript-commons/issues/24)) ([8f5717a](https://github.com/frontegg/entitlements-javascript-commons/commit/8f5717acdcc0a1eccae84b272c7a02e315131a01))
|
|
7
|
+
|
|
8
|
+
# [1.0.0-alpha.13](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.0-alpha.12...v-1.0.0-alpha.13) (2023-10-22)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **dep:** remove flat dependency ([e8a2daf](https://github.com/frontegg/entitlements-javascript-commons/commit/e8a2dafde0612ebfacc8e2d7e346d189276e5f72))
|
|
14
|
+
|
|
1
15
|
# [1.0.0-alpha.12](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.0-alpha.11...v-1.0.0-alpha.12) (2023-10-18)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/entitlements-javascript-commons",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"@fast-check/jest": "^1.7.3",
|
|
26
26
|
"@semantic-release/changelog": "^6.0.1",
|
|
27
27
|
"@semantic-release/git": "^10.0.1",
|
|
28
|
-
"@types/flat": "^5.0.3",
|
|
29
28
|
"@types/jest": "^29.2.0",
|
|
30
29
|
"@types/sinon": "^10.0.15",
|
|
31
30
|
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
|
@@ -40,8 +39,5 @@
|
|
|
40
39
|
"sinon": "^15.2.0",
|
|
41
40
|
"ts-jest": "^28.0.8",
|
|
42
41
|
"typescript": "^4.8.4"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"flat": "^5.0.2"
|
|
46
42
|
}
|
|
47
43
|
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { OperationEnum, Sanitizer, SanitizersMapper } from '../types';
|
|
2
2
|
import { BetweenDateOperationPayload, DateOperationPayload, SingleDateOperationPayload } from './types';
|
|
3
3
|
|
|
4
|
+
type RawDateValue = Date | string | number;
|
|
5
|
+
|
|
6
|
+
export const sanitizeDateValue = (value: Date | string | number): Date => {
|
|
7
|
+
return new Date(value);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const isValidDate = (value: unknown): boolean => value instanceof Date && !isNaN(value as unknown as number);
|
|
11
|
+
|
|
4
12
|
export const sanitizeSingleDate: Sanitizer<SingleDateOperationPayload> = (value) => {
|
|
5
|
-
const
|
|
13
|
+
const sanitizedDateValue = value.date ? sanitizeDateValue(value.date as RawDateValue) : undefined;
|
|
14
|
+
const sanitizedValue =
|
|
15
|
+
sanitizedDateValue && isValidDate(sanitizedDateValue) ? { date: sanitizedDateValue } : undefined;
|
|
6
16
|
|
|
7
17
|
return {
|
|
8
18
|
isSanitized: !!sanitizedValue,
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { fc, test } from '@fast-check/jest';
|
|
2
|
-
import { sanitizeDateRange, sanitizeSingleDate } from '../sanitizers';
|
|
2
|
+
import { isValidDate, sanitizeDateRange, sanitizeDateValue, sanitizeSingleDate } from '../sanitizers';
|
|
3
3
|
|
|
4
4
|
describe('Date sanitizers', () => {
|
|
5
|
+
it.each([['2021-01-01'], ['2023-10-23T12:09:17.502Z'], [123432443], [new Date()]])(
|
|
6
|
+
'should return sanitized date when value is a string',
|
|
7
|
+
(value) => {
|
|
8
|
+
const sanitizationResult = sanitizeDateValue(value);
|
|
9
|
+
|
|
10
|
+
expect(sanitizationResult).toBeDefined();
|
|
11
|
+
expect(sanitizationResult).toEqual(new Date(value));
|
|
12
|
+
},
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
it.each([['not a date'], [], {}, [undefined]])('should return invalid date when value is not a date', (value) => {
|
|
16
|
+
const sanitizationResult = sanitizeDateValue(value as any);
|
|
17
|
+
|
|
18
|
+
expect(sanitizationResult).toBeDefined();
|
|
19
|
+
expect(isValidDate(sanitizationResult)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
5
22
|
test.prop([fc.record({ date: fc.date() })], { verbose: true })(
|
|
6
23
|
'should return sanitized when date value exists',
|
|
7
24
|
(value) => {
|
|
@@ -26,9 +26,9 @@ export const sanitizeNumericRange: Sanitizer<BetweenNumericOperationPayload> = (
|
|
|
26
26
|
|
|
27
27
|
export const NumericSanitizersMapper: SanitizersMapper<NumericOperationPayload> = {
|
|
28
28
|
[OperationEnum.Equal]: sanitizeSingleNumber,
|
|
29
|
-
[OperationEnum.GreaterThan]:
|
|
29
|
+
[OperationEnum.GreaterThan]: sanitizeSingleNumber,
|
|
30
30
|
[OperationEnum.GreaterThanEqual]: sanitizeSingleNumber,
|
|
31
31
|
[OperationEnum.LesserThan]: sanitizeSingleNumber,
|
|
32
|
-
[OperationEnum.LesserThanEqual]:
|
|
32
|
+
[OperationEnum.LesserThanEqual]: sanitizeSingleNumber,
|
|
33
33
|
[OperationEnum.BetweenNumeric]: sanitizeNumericRange,
|
|
34
34
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { flatten } from 'flat';
|
|
2
1
|
import { Attributes, JwtAttributes, FronteggAttributes } from './types';
|
|
3
|
-
|
|
2
|
+
import { flatten } from './flatten.utils';
|
|
4
3
|
/**
|
|
5
4
|
* Merges both `custom` and `jwt` records, map Frontegg attributes and modifies record keys with corrisponding prefixes
|
|
6
5
|
*
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** DISCLAIMER - THIS CODE BELONGS TO https://github.com/hughsk/flat */
|
|
2
|
+
export interface FlattenOptions {
|
|
3
|
+
delimiter?: string;
|
|
4
|
+
maxDepth?: number;
|
|
5
|
+
safe?: boolean;
|
|
6
|
+
transformKey?: (key: string) => string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function flatten<TTraget, TResult>(target: TTraget, opts?: FlattenOptions): TResult {
|
|
10
|
+
opts = opts || {};
|
|
11
|
+
|
|
12
|
+
const delimiter = opts?.delimiter || '.';
|
|
13
|
+
const maxDepth = opts?.maxDepth;
|
|
14
|
+
const transformKey = opts?.transformKey || keyIdentity;
|
|
15
|
+
const output = {};
|
|
16
|
+
|
|
17
|
+
function step(object, prev?, currentDepth?) {
|
|
18
|
+
currentDepth = currentDepth || 1;
|
|
19
|
+
Object.keys(object).forEach(function (key) {
|
|
20
|
+
const value = object[key];
|
|
21
|
+
const isarray = opts?.safe && Array.isArray(value);
|
|
22
|
+
const type = Object.prototype.toString.call(value);
|
|
23
|
+
const isbuffer = isBuffer(value);
|
|
24
|
+
const isobject = type === '[object Object]' || type === '[object Array]';
|
|
25
|
+
|
|
26
|
+
const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
|
|
27
|
+
if (
|
|
28
|
+
!isarray &&
|
|
29
|
+
!isbuffer &&
|
|
30
|
+
isobject &&
|
|
31
|
+
Object.keys(value).length &&
|
|
32
|
+
(!opts?.maxDepth || (maxDepth && currentDepth < maxDepth))
|
|
33
|
+
) {
|
|
34
|
+
return step(value, newKey, currentDepth + 1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
output[newKey] = value;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
step(target);
|
|
42
|
+
|
|
43
|
+
return output as TResult;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isBuffer(obj) {
|
|
47
|
+
return obj && obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function keyIdentity(key) {
|
|
51
|
+
return key;
|
|
52
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as AttributesUtils from '../attributes.utils';
|
|
2
2
|
import { Attributes, FronteggAttributes, JwtAttributes } from '../types';
|
|
3
|
-
import { flatten } from 'flat';
|
|
4
3
|
describe('prepareAttributes', () => {
|
|
5
4
|
test('given custom & jwt attributes, expected is merged & flatten attributes record', () => {
|
|
6
5
|
const attributes: Attributes = {
|