@autofleet/zehut 1.7.1 → 1.7.2
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/index.d.ts +3 -0
- package/lib/user/index.d.ts +3 -0
- package/lib/user/index.js +14 -2
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -16,6 +16,9 @@ declare const _default: {
|
|
|
16
16
|
middlewareWithDecode: (options?: {
|
|
17
17
|
eagerLoadUserPermissions?: boolean;
|
|
18
18
|
eagerLoadUserPermissionsLegacy?: boolean;
|
|
19
|
+
appId?: string;
|
|
20
|
+
clientSecret?: string;
|
|
21
|
+
returnErrorIfNoToken?: boolean;
|
|
19
22
|
}) => (req: any, res: any, next: any) => Promise<void>;
|
|
20
23
|
eagerLoadPermissionsMiddleware: (req: any, res: any, next: any) => Promise<any>;
|
|
21
24
|
getCurrentPayload: () => any;
|
package/lib/user/index.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export declare const middleware: (options?: {
|
|
|
9
9
|
export declare const middlewareWithDecode: (options?: {
|
|
10
10
|
eagerLoadUserPermissions?: boolean;
|
|
11
11
|
eagerLoadUserPermissionsLegacy?: boolean;
|
|
12
|
+
appId?: string;
|
|
13
|
+
clientSecret?: string;
|
|
14
|
+
returnErrorIfNoToken?: boolean;
|
|
12
15
|
}) => (req: any, res: any, next: any) => Promise<void>;
|
|
13
16
|
export declare const eagerLoadPermissionsMiddleware: (req: any, res: any, next: any) => Promise<any>;
|
|
14
17
|
export declare const getDecodedBearer: (req: any) => any;
|
package/lib/user/index.js
CHANGED
|
@@ -49,6 +49,7 @@ exports.middleware = (options = {}) => (req, res, next) => __awaiter(void 0, voi
|
|
|
49
49
|
});
|
|
50
50
|
exports.middlewareWithDecode = (options = {}) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
51
|
var _a;
|
|
52
|
+
const { eagerLoadUserPermissions, eagerLoadUserPermissionsLegacy, appId, clientSecret, returnErrorIfNoToken, } = options;
|
|
52
53
|
const trace = tracer_1.newTrace('userPayload');
|
|
53
54
|
let decoded;
|
|
54
55
|
if (req.headers.authorization) {
|
|
@@ -81,17 +82,28 @@ exports.middlewareWithDecode = (options = {}) => (req, res, next) => __awaiter(v
|
|
|
81
82
|
req.headers['X-AF-USER-ID'] = userId;
|
|
82
83
|
}
|
|
83
84
|
const userObject = new ApiUser_1.default(userId);
|
|
84
|
-
if (
|
|
85
|
+
if (eagerLoadUserPermissions) {
|
|
85
86
|
yield userObject.getUserPermissions();
|
|
86
87
|
}
|
|
87
|
-
if (
|
|
88
|
+
if (eagerLoadUserPermissionsLegacy) {
|
|
88
89
|
yield userObject.getUserPermissionsLegacy();
|
|
89
90
|
}
|
|
91
|
+
if (appId && clientSecret) {
|
|
92
|
+
req.headers['x-autofleet-apps-secret'] = clientSecret;
|
|
93
|
+
yield userObject.getUserAppPermissions(appId);
|
|
94
|
+
}
|
|
90
95
|
req.user = userObject;
|
|
91
96
|
trace.context.set('userObject', userObject);
|
|
92
97
|
// Added in order to support outbreak.
|
|
93
98
|
req.headers['x-af-user-permissions'] = userObject;
|
|
94
99
|
}
|
|
100
|
+
else if (returnErrorIfNoToken) {
|
|
101
|
+
res.status(401);
|
|
102
|
+
// eslint-disable-next-line consistent-return
|
|
103
|
+
return res.json({
|
|
104
|
+
errors: ['No token provided'],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
95
107
|
trace.context.set('userObject', {});
|
|
96
108
|
// eslint-disable-next-line consistent-return
|
|
97
109
|
return next();
|