@alanszp/jwt 15.0.0 → 15.0.4
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/JWTUser.d.ts +15 -1
- package/dist/JWTUser.js +24 -6
- package/dist/JWTUser.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
package/dist/JWTUser.d.ts
CHANGED
|
@@ -8,7 +8,14 @@ export declare class JWTUser implements IJWTUser {
|
|
|
8
8
|
originalOrganizationReference: string | null;
|
|
9
9
|
originalId: string | null;
|
|
10
10
|
originalEmployeeReference: string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Old role codes to maintain backwards compatibility
|
|
13
|
+
*/
|
|
11
14
|
roles: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Role ids
|
|
17
|
+
*/
|
|
18
|
+
roleReferences: string[];
|
|
12
19
|
permissions: string;
|
|
13
20
|
segmentReference: string | null;
|
|
14
21
|
expirationTime?: number;
|
|
@@ -20,7 +27,7 @@ export declare class JWTUser implements IJWTUser {
|
|
|
20
27
|
* @throws {PermissionServiceNotInstantiated}
|
|
21
28
|
*/
|
|
22
29
|
static getPermissionService(): IPermissionService;
|
|
23
|
-
constructor({ id, employeeReference, organizationReference, roles, permissions, segmentReference, originalOrganizationReference, originalId, originalEmployeeReference, expirationTime, }: IJWTUser);
|
|
30
|
+
constructor({ id, employeeReference, organizationReference, roles, roleReferences, permissions, segmentReference, originalOrganizationReference, originalId, originalEmployeeReference, expirationTime, }: IJWTUser);
|
|
24
31
|
static fromPayload(payload: JWTPayload): JWTUser;
|
|
25
32
|
toTokenPayload(): JWTPayload;
|
|
26
33
|
/**
|
|
@@ -34,6 +41,12 @@ export declare class JWTUser implements IJWTUser {
|
|
|
34
41
|
* Will be replaced by permission checks
|
|
35
42
|
*/
|
|
36
43
|
hasRoles(validateRoles: string | string[]): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Get current role reference
|
|
46
|
+
* (only the first role is returned for now, as we are not using multiple roles yet)
|
|
47
|
+
* @returns role reference
|
|
48
|
+
*/
|
|
49
|
+
getRoleReference(): string;
|
|
37
50
|
/**
|
|
38
51
|
* Check if user has permission to perform an action
|
|
39
52
|
* @param permissionCode - permission code to check
|
|
@@ -88,4 +101,5 @@ export declare class JWTUser implements IJWTUser {
|
|
|
88
101
|
*/
|
|
89
102
|
private getPermissionDefinition;
|
|
90
103
|
isImpersonating(): boolean;
|
|
104
|
+
isServiceAccount(): boolean;
|
|
91
105
|
}
|
package/dist/JWTUser.js
CHANGED
|
@@ -27,10 +27,11 @@ const PermissionNotFound_1 = require("./errors/PermissionNotFound");
|
|
|
27
27
|
const PermissionServiceNotInstantiated_1 = require("./errors/PermissionServiceNotInstantiated");
|
|
28
28
|
const NoPermissionError_1 = require("./errors/NoPermissionError");
|
|
29
29
|
class JWTUser {
|
|
30
|
-
constructor({ id, employeeReference, organizationReference, roles, permissions, segmentReference, originalOrganizationReference, originalId, originalEmployeeReference, expirationTime, }) {
|
|
30
|
+
constructor({ id, employeeReference, organizationReference, roles, roleReferences, permissions, segmentReference, originalOrganizationReference, originalId, originalEmployeeReference, expirationTime, }) {
|
|
31
31
|
this.id = id;
|
|
32
32
|
this.employeeReference = employeeReference;
|
|
33
33
|
this.organizationReference = organizationReference;
|
|
34
|
+
this.roleReferences = roleReferences;
|
|
34
35
|
this.roles = roles;
|
|
35
36
|
this.permissions = permissions;
|
|
36
37
|
this.segmentReference = segmentReference;
|
|
@@ -57,16 +58,18 @@ class JWTUser {
|
|
|
57
58
|
return __classPrivateFieldGet(JWTUser, _a, "f", _JWTUser_permissionService);
|
|
58
59
|
}
|
|
59
60
|
static fromPayload(payload) {
|
|
61
|
+
var _b, _c, _d;
|
|
60
62
|
return new JWTUser({
|
|
61
63
|
id: payload.sub,
|
|
62
64
|
employeeReference: payload.ref,
|
|
63
65
|
organizationReference: payload.org,
|
|
64
66
|
roles: payload.rls,
|
|
67
|
+
roleReferences: payload.rl,
|
|
65
68
|
permissions: payload.prms,
|
|
66
69
|
segmentReference: payload.seg || null,
|
|
67
|
-
originalOrganizationReference: payload.oorg,
|
|
68
|
-
originalId: payload.osub,
|
|
69
|
-
originalEmployeeReference: payload.oref,
|
|
70
|
+
originalOrganizationReference: (_b = payload.oorg) !== null && _b !== void 0 ? _b : payload.org,
|
|
71
|
+
originalId: (_c = payload.osub) !== null && _c !== void 0 ? _c : payload.sub,
|
|
72
|
+
originalEmployeeReference: (_d = payload.oref) !== null && _d !== void 0 ? _d : payload.ref,
|
|
70
73
|
expirationTime: payload.exp,
|
|
71
74
|
});
|
|
72
75
|
}
|
|
@@ -76,6 +79,7 @@ class JWTUser {
|
|
|
76
79
|
ref: this.employeeReference,
|
|
77
80
|
org: this.organizationReference,
|
|
78
81
|
rls: this.roles,
|
|
82
|
+
rl: this.roleReferences,
|
|
79
83
|
prms: this.permissions,
|
|
80
84
|
seg: this.segmentReference,
|
|
81
85
|
oorg: this.originalOrganizationReference,
|
|
@@ -101,6 +105,14 @@ class JWTUser {
|
|
|
101
105
|
}
|
|
102
106
|
return validateRoles.some((role) => this.hasRole(role));
|
|
103
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Get current role reference
|
|
110
|
+
* (only the first role is returned for now, as we are not using multiple roles yet)
|
|
111
|
+
* @returns role reference
|
|
112
|
+
*/
|
|
113
|
+
getRoleReference() {
|
|
114
|
+
return this.roleReferences[0];
|
|
115
|
+
}
|
|
104
116
|
/**
|
|
105
117
|
* Check if user has permission to perform an action
|
|
106
118
|
* @param permissionCode - permission code to check
|
|
@@ -219,8 +231,14 @@ class JWTUser {
|
|
|
219
231
|
});
|
|
220
232
|
}
|
|
221
233
|
isImpersonating() {
|
|
222
|
-
return
|
|
223
|
-
|
|
234
|
+
return this.id !== this.originalId;
|
|
235
|
+
}
|
|
236
|
+
// To check if it's not impersonating and is Lara Service Account. This should be change to check the
|
|
237
|
+
// JWT type instead.
|
|
238
|
+
isServiceAccount() {
|
|
239
|
+
return (!this.isImpersonating() &&
|
|
240
|
+
this.originalEmployeeReference === "0" &&
|
|
241
|
+
this.originalOrganizationReference === "lara");
|
|
224
242
|
}
|
|
225
243
|
}
|
|
226
244
|
exports.JWTUser = JWTUser;
|
package/dist/JWTUser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JWTUser.js","sourceRoot":"","sources":["../src/JWTUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA8C;AAE9C,oEAA2E;AAC3E,gGAA6F;AAE7F,kEAA+D;AAE/D,MAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"JWTUser.js","sourceRoot":"","sources":["../src/JWTUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA8C;AAE9C,oEAA2E;AAC3E,gGAA6F;AAE7F,kEAA+D;AAE/D,MAAa,OAAO;IAqDlB,YAAY,EACV,EAAE,EACF,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,EACL,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,6BAA6B,EAC7B,UAAU,EACV,yBAAyB,EACzB,cAAc,GACL;QACT,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,6BAA6B;YAChC,6BAA6B,aAA7B,6BAA6B,cAA7B,6BAA6B,GAAI,qBAAqB,CAAC;QACzD,IAAI,CAAC,UAAU,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,CAAC;QACnC,IAAI,CAAC,yBAAyB;YAC5B,yBAAy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,CAAC;YACxE,IAAI,CAAC,iBAAiB,EAAE;gBACtB,MAAM,IAAI,qCAAiB,CAAC,eAAe,CAAC,CAAC;aAC9C;QACH,CAAC;KAAA;IAED;;;OAGG;IACW,uBAAuB,CACnC,cAAsB;;YAEtB,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,oBAAoB,EAAE,CAAC,cAAc,EAAE,CAAC;YAC1E,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;YAC1E,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,IAAI,iDAA4B,CAAC,cAAc,CAAC,CAAC;aACxD;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC;IACrC,CAAC;IAED,qGAAqG;IACrG,oBAAoB;IACb,gBAAgB;QACrB,OAAO,CACL,CAAC,IAAI,CAAC,eAAe,EAAE;YACvB,IAAI,CAAC,yBAAyB,KAAK,GAAG;YACtC,IAAI,CAAC,6BAA6B,KAAK,MAAM,CAC9C,CAAC;IACJ,CAAC;;AA7QH,0BA8QC;;AAjPC;;;;GAIG;AACH,sCAAuD,IAAI,EAAC,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface JWTPayload extends LibPayload {
|
|
|
4
4
|
ref: string | null;
|
|
5
5
|
org: string;
|
|
6
6
|
rls: string[];
|
|
7
|
+
rl: string[];
|
|
7
8
|
prms: string;
|
|
8
9
|
oorg: string | null;
|
|
9
10
|
osub: string | null;
|
|
@@ -14,6 +15,7 @@ export interface IJWTUser {
|
|
|
14
15
|
id: string;
|
|
15
16
|
employeeReference: string | null;
|
|
16
17
|
organizationReference: string;
|
|
18
|
+
roleReferences: string[];
|
|
17
19
|
roles: string[];
|
|
18
20
|
permissions: string;
|
|
19
21
|
segmentReference: string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/jwt",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.0.4",
|
|
4
4
|
"description": "Alan's jwt validator & signer.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"typescript": "^4.3.4"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@alanszp/axios-node": "^15.0.
|
|
31
|
+
"@alanszp/axios-node": "^15.0.4",
|
|
32
32
|
"@alanszp/core": "^15.0.0",
|
|
33
33
|
"@alanszp/errors": "^15.0.0",
|
|
34
34
|
"@alanszp/logger": "^15.0.0",
|
|
35
35
|
"jose": "^5.2.2"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "21554c6285f8c1f6d4aea93d4f9253033d7bf385"
|
|
38
38
|
}
|