@frontegg/entitlements-javascript-commons 1.0.0-alpha.12 → 1.0.0-alpha.13
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/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 +7 -0
- package/package.json +1 -5
- 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,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,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AAC;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,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-alpha.12...v-1.0.0-alpha.13) (2023-10-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **dep:** remove flat dependency ([e8a2daf](https://github.com/frontegg/entitlements-javascript-commons/commit/e8a2dafde0612ebfacc8e2d7e346d189276e5f72))
|
|
7
|
+
|
|
1
8
|
# [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
9
|
|
|
3
10
|
|
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.13",
|
|
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,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 = {
|