@autofleet/zehut 3.1.2-beta.5 → 3.1.2-beta.7
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/lib/user/ApiUser.js +3 -3
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +32 -1
- package/package.json +2 -3
package/lib/user/ApiUser.js
CHANGED
|
@@ -7,10 +7,10 @@ exports.CONTEXTS_IDS_HEADER = exports.ELEVATED_PERMISSIONS_HEADER = void 0;
|
|
|
7
7
|
/* eslint-disable consistent-return */
|
|
8
8
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
9
|
const object_hash_1 = __importDefault(require("object-hash"));
|
|
10
|
-
const merge_deep_1 = __importDefault(require("merge-deep"));
|
|
11
10
|
const uuid_1 = require("uuid");
|
|
12
11
|
const outbreak_1 = require("@autofleet/outbreak");
|
|
13
12
|
const services_1 = require("../services");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
14
|
exports.ELEVATED_PERMISSIONS_HEADER = 'x-af-elevated-permissions';
|
|
15
15
|
exports.CONTEXTS_IDS_HEADER = 'x-af-context-ids';
|
|
16
16
|
const userCache = new node_cache_1.default({ stdTTL: 10 });
|
|
@@ -88,7 +88,7 @@ class ApiUser {
|
|
|
88
88
|
demandSources: {},
|
|
89
89
|
};
|
|
90
90
|
[...this.privateElevatedPermissionsHash.values()].forEach((p) => {
|
|
91
|
-
permissions = (0,
|
|
91
|
+
permissions = (0, utils_1.mergeDeep)(permissions, p);
|
|
92
92
|
});
|
|
93
93
|
return permissions;
|
|
94
94
|
}
|
|
@@ -96,7 +96,7 @@ class ApiUser {
|
|
|
96
96
|
if (!this.privatePermissions) {
|
|
97
97
|
throw new Error('Cannot get permissions without calling (async) getUserPermissions before');
|
|
98
98
|
}
|
|
99
|
-
const permissions = (0,
|
|
99
|
+
const permissions = (0, utils_1.mergeDeep)(this.privatePermissions, this.elevatedPermissions);
|
|
100
100
|
return permissions;
|
|
101
101
|
}
|
|
102
102
|
elevatePermissions(addedPermissions) {
|
package/lib/utils.d.ts
CHANGED
|
@@ -3,3 +3,11 @@ export declare const decodeBearer: (bearer: string, appSecret?: string) => any;
|
|
|
3
3
|
export declare const parsePermissions: (contextId: any, decodedToken: any) => any;
|
|
4
4
|
export declare const getEntitiesFromContext: (contextId: string, decodedToken: any) => any;
|
|
5
5
|
export declare const getContextAttributes: (contextId: string, decodedToken: any) => any;
|
|
6
|
+
/**
|
|
7
|
+
* Custom deep merge function that merges `source` into `target`.
|
|
8
|
+
*
|
|
9
|
+
* @param target - The object to receive merged properties.
|
|
10
|
+
* @param source - The object whose properties are merged into the target.
|
|
11
|
+
* @returns The modified `target` object.
|
|
12
|
+
*/
|
|
13
|
+
export declare const mergeDeep: <T extends object>(target: T, source: Partial<T>) => T;
|
package/lib/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getContextAttributes = exports.getEntitiesFromContext = exports.parsePermissions = exports.decodeBearer = exports.getAuthFromBearer = void 0;
|
|
26
|
+
exports.mergeDeep = exports.getContextAttributes = exports.getEntitiesFromContext = exports.parsePermissions = exports.decodeBearer = exports.getAuthFromBearer = void 0;
|
|
27
27
|
/* eslint-disable prefer-destructuring */
|
|
28
28
|
const jwt = __importStar(require("jsonwebtoken"));
|
|
29
29
|
const secret_getter_1 = require("./secret-getter");
|
|
@@ -97,3 +97,34 @@ const getContextAttributes = (contextId, decodedToken) => {
|
|
|
97
97
|
return attributes;
|
|
98
98
|
};
|
|
99
99
|
exports.getContextAttributes = getContextAttributes;
|
|
100
|
+
/**
|
|
101
|
+
* A simple helper to check if a value is a plain object.
|
|
102
|
+
*/
|
|
103
|
+
const isObject = (value) => (typeof value === 'object'
|
|
104
|
+
&& value !== null
|
|
105
|
+
&& !Array.isArray(value));
|
|
106
|
+
/**
|
|
107
|
+
* Custom deep merge function that merges `source` into `target`.
|
|
108
|
+
*
|
|
109
|
+
* @param target - The object to receive merged properties.
|
|
110
|
+
* @param source - The object whose properties are merged into the target.
|
|
111
|
+
* @returns The modified `target` object.
|
|
112
|
+
*/
|
|
113
|
+
const mergeDeep = (target, source) => {
|
|
114
|
+
if (!isObject(target) || !isObject(source)) {
|
|
115
|
+
throw new Error('Both arguments must be objects to merge');
|
|
116
|
+
}
|
|
117
|
+
Object.keys(source).forEach((key) => {
|
|
118
|
+
const sourceValue = source[key];
|
|
119
|
+
const targetValue = target[key];
|
|
120
|
+
if (isObject(sourceValue) && isObject(targetValue)) {
|
|
121
|
+
(0, exports.mergeDeep)(targetValue, sourceValue);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// eslint-disable-next-line no-param-reassign
|
|
125
|
+
target[key] = sourceValue;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return target;
|
|
129
|
+
};
|
|
130
|
+
exports.mergeDeep = mergeDeep;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/zehut",
|
|
3
|
-
"version": "3.1.2-beta.
|
|
3
|
+
"version": "3.1.2-beta.7",
|
|
4
4
|
"description": "manage user's identity",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"axios": "^0.27.2",
|
|
29
29
|
"express": "^4.18.1",
|
|
30
30
|
"jsonwebtoken": "^8.5.1",
|
|
31
|
-
"merge-deep": "^3.0.3",
|
|
32
31
|
"methods": "^1.1.2",
|
|
33
32
|
"moment": "^2.29.1",
|
|
34
33
|
"nock": "^13.2.9",
|
|
@@ -50,7 +49,7 @@
|
|
|
50
49
|
"typescript": "^4.9.5"
|
|
51
50
|
},
|
|
52
51
|
"peerDependencies": {
|
|
53
|
-
"@autofleet/shtinker": "1.2.
|
|
52
|
+
"@autofleet/shtinker": "^1.2.0"
|
|
54
53
|
},
|
|
55
54
|
"peerDependenciesMeta": {
|
|
56
55
|
"@autofleet/shtinker": {
|