@alanszp/jwt 20.4.3 → 20.5.0
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 +6 -1
- package/dist/JWTUser.js +12 -9
- package/dist/JWTUser.js.map +1 -1
- package/dist/JWTUser.test.js +39 -0
- package/dist/JWTUser.test.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +7 -6
- package/dist/BitmaskUtils.d.ts +0 -63
- package/dist/BitmaskUtils.js +0 -85
- package/dist/BitmaskUtils.js.map +0 -1
- package/dist/BitmaskUtils.test.js +0 -152
- package/dist/BitmaskUtils.test.js.map +0 -1
- /package/dist/{BitmaskUtils.test.d.ts → JWTUser.test.d.ts} +0 -0
package/dist/JWTUser.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ import { IJWTUser, JWTPayload, Permission } from "./types";
|
|
|
3
3
|
export declare class JWTUser implements IJWTUser {
|
|
4
4
|
#private;
|
|
5
5
|
jwtId: string | null;
|
|
6
|
+
/**
|
|
7
|
+
* OAuth client id the token was issued to (registered MCP client).
|
|
8
|
+
* Null for non-OAuth tokens (web session, partial login, etc.).
|
|
9
|
+
*/
|
|
10
|
+
clientId: string | null;
|
|
6
11
|
id: string;
|
|
7
12
|
employeeReference: string | null;
|
|
8
13
|
organizationReference: string;
|
|
@@ -33,7 +38,7 @@ export declare class JWTUser implements IJWTUser {
|
|
|
33
38
|
* @throws {PermissionServiceNotInstantiated}
|
|
34
39
|
*/
|
|
35
40
|
static getPermissionDefinition(permissionCode: string): Promise<Permission>;
|
|
36
|
-
constructor({ jwtId, id, employeeReference, organizationReference, roles, roleReferences, permissions, segmentReference, originalOrganizationReference, originalId, originalEmployeeReference, expirationTime, }: IJWTUser);
|
|
41
|
+
constructor({ jwtId, clientId, id, employeeReference, organizationReference, roles, roleReferences, permissions, segmentReference, originalOrganizationReference, originalId, originalEmployeeReference, expirationTime, }: IJWTUser);
|
|
37
42
|
/**
|
|
38
43
|
* Set the raw token from the original request
|
|
39
44
|
* @description Do not include the Bearer prefix
|
package/dist/JWTUser.js
CHANGED
|
@@ -22,7 +22,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
22
22
|
var _a, _JWTUser_rawToken, _JWTUser_permissionService;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.JWTUser = void 0;
|
|
25
|
-
const
|
|
25
|
+
const bitmask_1 = require("@alanszp/bitmask");
|
|
26
26
|
const PermissionNotFound_1 = require("./errors/PermissionNotFound");
|
|
27
27
|
const PermissionServiceNotInstantiated_1 = require("./errors/PermissionServiceNotInstantiated");
|
|
28
28
|
const NoPermissionError_1 = require("./errors/NoPermissionError");
|
|
@@ -55,9 +55,10 @@ class JWTUser {
|
|
|
55
55
|
return definition;
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
constructor({ jwtId, id, employeeReference, organizationReference, roles, roleReferences, permissions, segmentReference, originalOrganizationReference, originalId, originalEmployeeReference, expirationTime, }) {
|
|
58
|
+
constructor({ jwtId, clientId, id, employeeReference, organizationReference, roles, roleReferences, permissions, segmentReference, originalOrganizationReference, originalId, originalEmployeeReference, expirationTime, }) {
|
|
59
59
|
_JWTUser_rawToken.set(this, void 0);
|
|
60
60
|
this.jwtId = jwtId !== null && jwtId !== void 0 ? jwtId : null;
|
|
61
|
+
this.clientId = clientId !== null && clientId !== void 0 ? clientId : null;
|
|
61
62
|
this.id = id;
|
|
62
63
|
this.employeeReference = employeeReference;
|
|
63
64
|
this.organizationReference = organizationReference;
|
|
@@ -88,9 +89,10 @@ class JWTUser {
|
|
|
88
89
|
return __classPrivateFieldGet(this, _JWTUser_rawToken, "f") ? `Bearer ${__classPrivateFieldGet(this, _JWTUser_rawToken, "f")}` : undefined;
|
|
89
90
|
}
|
|
90
91
|
static fromPayload(payload) {
|
|
91
|
-
var _b, _c, _d, _e;
|
|
92
|
+
var _b, _c, _d, _e, _f;
|
|
92
93
|
return new _a({
|
|
93
94
|
jwtId: (_b = payload.jti) !== null && _b !== void 0 ? _b : null,
|
|
95
|
+
clientId: (_c = payload.cid) !== null && _c !== void 0 ? _c : null,
|
|
94
96
|
id: payload.sub,
|
|
95
97
|
employeeReference: payload.ref,
|
|
96
98
|
organizationReference: payload.org,
|
|
@@ -98,9 +100,9 @@ class JWTUser {
|
|
|
98
100
|
roleReferences: payload.rl,
|
|
99
101
|
permissions: payload.prms,
|
|
100
102
|
segmentReference: payload.seg || null,
|
|
101
|
-
originalOrganizationReference: (
|
|
102
|
-
originalId: (
|
|
103
|
-
originalEmployeeReference: (
|
|
103
|
+
originalOrganizationReference: (_d = payload.oorg) !== null && _d !== void 0 ? _d : payload.org,
|
|
104
|
+
originalId: (_e = payload.osub) !== null && _e !== void 0 ? _e : payload.sub,
|
|
105
|
+
originalEmployeeReference: (_f = payload.oref) !== null && _f !== void 0 ? _f : payload.ref,
|
|
104
106
|
expirationTime: payload.exp,
|
|
105
107
|
});
|
|
106
108
|
}
|
|
@@ -116,6 +118,7 @@ class JWTUser {
|
|
|
116
118
|
oorg: this.originalOrganizationReference,
|
|
117
119
|
osub: this.originalId,
|
|
118
120
|
oref: this.originalEmployeeReference,
|
|
121
|
+
cid: this.clientId,
|
|
119
122
|
};
|
|
120
123
|
}
|
|
121
124
|
/**
|
|
@@ -154,9 +157,9 @@ class JWTUser {
|
|
|
154
157
|
hasPermission(permissionCode) {
|
|
155
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
159
|
const definition = yield _a.getPermissionDefinition(permissionCode);
|
|
157
|
-
const checkBitmask =
|
|
158
|
-
const permissionsBitmask =
|
|
159
|
-
return
|
|
160
|
+
const checkBitmask = bitmask_1.BitmaskUtils.encodeFromPosition(definition.position);
|
|
161
|
+
const permissionsBitmask = bitmask_1.BitmaskUtils.decodeFromBase64(this.permissions);
|
|
162
|
+
return bitmask_1.BitmaskUtils.checkBitmask(permissionsBitmask, checkBitmask);
|
|
160
163
|
});
|
|
161
164
|
}
|
|
162
165
|
/**
|
package/dist/JWTUser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JWTUser.js","sourceRoot":"","sources":["../src/JWTUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"JWTUser.js","sourceRoot":"","sources":["../src/JWTUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAgD;AAEhD,oEAA2E;AAC3E,gGAA6F;AAE7F,kEAA+D;AAE/D,MAAa,OAAO;IA8ClB;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,OAA2B;QACrD,uBAAA,EAAO,MAAsB,OAAO,kCAAA,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB;QACzB,IAAI,CAAC,uBAAA,EAAO,sCAAmB,EAAE,CAAC;YAChC,MAAM,IAAI,mEAAgC,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,uBAAA,EAAO,sCAAmB,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAO,uBAAuB,CAClC,cAAsB;;YAEtB,MAAM,UAAU,GAAG,MAAM,EAAO,CAAC,oBAAoB,EAAE,CAAC,aAAa,CACnE,cAAc,CACf,CAAC;YACF,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,IAAI,iDAA4B,CAAC,cAAc,CAAC,CAAC;YACzD,CAAC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED,YAAY,EACV,KAAK,EACL,QAAQ,EACR,EAAE,EACF,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,EACL,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,6BAA6B,EAC7B,UAAU,EACV,yBAAyB,EACzB,cAAc,GACL;QAxDX,oCAAmB;QAyDjB,IAAI,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,CAAC,6BAA6B,KAAK,MAAM,CAC9C,CAAC;IACJ,CAAC;;AAhTH,0BAiTC;;AA1QC;;;;GAIG;AACI,sCAAgD,IAAI,EAAlC,CAAmC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const JWTUser_1 = require("./JWTUser");
|
|
4
|
+
const baseUser = {
|
|
5
|
+
id: "user-1",
|
|
6
|
+
employeeReference: "emp-1",
|
|
7
|
+
organizationReference: "org-1",
|
|
8
|
+
roles: [],
|
|
9
|
+
roleReferences: [],
|
|
10
|
+
permissions: "",
|
|
11
|
+
segmentReference: null,
|
|
12
|
+
};
|
|
13
|
+
describe("JWTUser - clientId / cid claim", () => {
|
|
14
|
+
it("defaults clientId to null when not provided (non-OAuth tokens)", () => {
|
|
15
|
+
const user = new JWTUser_1.JWTUser(baseUser);
|
|
16
|
+
expect(user.clientId).toBeNull();
|
|
17
|
+
expect(user.toTokenPayload().cid).toBeNull();
|
|
18
|
+
});
|
|
19
|
+
it("always emits the cid claim in the payload (uniform shape across token types)", () => {
|
|
20
|
+
const payload = new JWTUser_1.JWTUser(baseUser).toTokenPayload();
|
|
21
|
+
expect(payload).toHaveProperty("cid");
|
|
22
|
+
});
|
|
23
|
+
it("carries the OAuth client id through the cid claim", () => {
|
|
24
|
+
const user = new JWTUser_1.JWTUser(Object.assign(Object.assign({}, baseUser), { clientId: "client-123" }));
|
|
25
|
+
expect(user.clientId).toBe("client-123");
|
|
26
|
+
expect(user.toTokenPayload().cid).toBe("client-123");
|
|
27
|
+
});
|
|
28
|
+
it("round-trips clientId through toTokenPayload/fromPayload", () => {
|
|
29
|
+
const original = new JWTUser_1.JWTUser(Object.assign(Object.assign({}, baseUser), { clientId: "client-123" }));
|
|
30
|
+
const restored = JWTUser_1.JWTUser.fromPayload(Object.assign(Object.assign({}, original.toTokenPayload()), { sub: original.id }));
|
|
31
|
+
expect(restored.clientId).toBe("client-123");
|
|
32
|
+
});
|
|
33
|
+
it("reads clientId as null from a legacy payload without cid", () => {
|
|
34
|
+
const payload = new JWTUser_1.JWTUser(baseUser).toTokenPayload();
|
|
35
|
+
delete payload.cid;
|
|
36
|
+
expect(JWTUser_1.JWTUser.fromPayload(payload).clientId).toBeNull();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=JWTUser.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JWTUser.test.js","sourceRoot":"","sources":["../src/JWTUser.test.ts"],"names":[],"mappings":";;AAAA,uCAAoC;AAGpC,MAAM,QAAQ,GAAa;IACzB,EAAE,EAAE,QAAQ;IACZ,iBAAiB,EAAE,OAAO;IAC1B,qBAAqB,EAAE,OAAO;IAC9B,KAAK,EAAE,EAAE;IACT,cAAc,EAAE,EAAE;IAClB,WAAW,EAAE,EAAE;IACf,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEF,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;QACxE,MAAM,IAAI,GAAG,IAAI,iBAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,GAAG,EAAE;QACtF,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,QAAQ,CAAC,CAAC,cAAc,EAAE,CAAC;QACvD,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,IAAI,GAAG,IAAI,iBAAO,iCAAM,QAAQ,KAAE,QAAQ,EAAE,YAAY,IAAG,CAAC;QAClE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACzC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,QAAQ,GAAG,IAAI,iBAAO,iCAAM,QAAQ,KAAE,QAAQ,EAAE,YAAY,IAAG,CAAC;QACtE,MAAM,QAAQ,GAAG,iBAAO,CAAC,WAAW,iCAC/B,QAAQ,CAAC,cAAc,EAAE,KAC5B,GAAG,EAAE,QAAQ,CAAC,EAAE,IAChB,CAAC;QACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,QAAQ,CAAC,CAAC,cAAc,EAAE,CAAC;QACvD,OAAQ,OAAmC,CAAC,GAAG,CAAC;QAChD,MAAM,CAAC,iBAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from "./types";
|
|
|
2
2
|
export * from "./JWTUser";
|
|
3
3
|
export * from "./jwt";
|
|
4
4
|
export * from "./PermissionService";
|
|
5
|
-
export * from "
|
|
5
|
+
export * from "@alanszp/bitmask";
|
|
6
6
|
export * from "./errors/NoPermissionError";
|
|
7
7
|
export * from "./errors/PermissionNotFound";
|
|
8
8
|
export * from "./errors/PermissionServiceNotInstantiated";
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ __exportStar(require("./types"), exports);
|
|
|
18
18
|
__exportStar(require("./JWTUser"), exports);
|
|
19
19
|
__exportStar(require("./jwt"), exports);
|
|
20
20
|
__exportStar(require("./PermissionService"), exports);
|
|
21
|
-
__exportStar(require("
|
|
21
|
+
__exportStar(require("@alanszp/bitmask"), exports);
|
|
22
22
|
__exportStar(require("./errors/NoPermissionError"), exports);
|
|
23
23
|
__exportStar(require("./errors/PermissionNotFound"), exports);
|
|
24
24
|
__exportStar(require("./errors/PermissionServiceNotInstantiated"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,wCAAsB;AACtB,sDAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,wCAAsB;AACtB,sDAAoC;AACpC,mDAAiC;AACjC,6DAA2C;AAC3C,8DAA4C;AAC5C,4EAA0D;AAC1D,yEAAuD;AACvD,sEAAoD"}
|
package/dist/types.d.ts
CHANGED
|
@@ -10,9 +10,11 @@ export interface JWTPayload extends LibPayload {
|
|
|
10
10
|
osub: string | null;
|
|
11
11
|
oref: string | null;
|
|
12
12
|
seg: string | null;
|
|
13
|
+
cid?: string | null;
|
|
13
14
|
}
|
|
14
15
|
export interface IJWTUser {
|
|
15
16
|
jwtId?: string | null;
|
|
17
|
+
clientId?: string | null;
|
|
16
18
|
id: string;
|
|
17
19
|
employeeReference: string | null;
|
|
18
20
|
organizationReference: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/jwt",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.5.0",
|
|
4
4
|
"description": "Alan's jwt validator & signer.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
"typescript": "^5.7.3"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@alanszp/axios-node": "^20.
|
|
32
|
-
"@alanszp/
|
|
33
|
-
"@alanszp/
|
|
34
|
-
"@alanszp/
|
|
31
|
+
"@alanszp/axios-node": "^20.5.0",
|
|
32
|
+
"@alanszp/bitmask": "^20.5.0",
|
|
33
|
+
"@alanszp/core": "^20.5.0",
|
|
34
|
+
"@alanszp/errors": "^20.5.0",
|
|
35
|
+
"@alanszp/logger": "^20.5.0",
|
|
35
36
|
"jose": "^5.2.2",
|
|
36
37
|
"uuid": "^11.1.1"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "db82dba6b9d0976f56b256be6d552131b44217f6"
|
|
39
40
|
}
|
package/dist/BitmaskUtils.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Permission } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Bitmask utility class
|
|
4
|
-
* - Use to handle binary numbers
|
|
5
|
-
* - Support binary numbers larger than 32 bits (Node.js uses 32-bit numbers)
|
|
6
|
-
*/
|
|
7
|
-
export declare class BitmaskUtils {
|
|
8
|
-
/**
|
|
9
|
-
* Encode a position into a binary number
|
|
10
|
-
* @example Bitmask.encodeFromPosition(0) // 1 or 0b1
|
|
11
|
-
* @example Bitmask.encodeFromPosition(1) // 2 or 0b10
|
|
12
|
-
* @example Bitmask.encodeFromPosition(2) // 4 or 0b100
|
|
13
|
-
* @example Bitmask.encodeFromPosition(3) // 8 or 0b1000
|
|
14
|
-
*/
|
|
15
|
-
static encodeFromPosition(position: number): bigint;
|
|
16
|
-
/**
|
|
17
|
-
* Check if a bitmask has a specific bit set
|
|
18
|
-
* @param bitmask - the bitmask to check
|
|
19
|
-
* @param check - the bit to check (also a bitmask with only one bit set)
|
|
20
|
-
* @example Bitmask.checkBitmask(0b1010, 0b1000) // true
|
|
21
|
-
* @example Bitmask.checkBitmask(0b1010, 0b0100) // false
|
|
22
|
-
*/
|
|
23
|
-
static checkBitmask(bitmask: bigint, check: bigint): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Combine multiple bitmasks into one
|
|
26
|
-
* Uses the bitwise OR operator to combine the bitmasks
|
|
27
|
-
* @param bitmasks - An array of bitmasks
|
|
28
|
-
* @returns The combined bitmask
|
|
29
|
-
* @example Bitmask.combineBitmasks([0b1000, 0b0100]) // 0b1100
|
|
30
|
-
* @example Bitmask.combineBitmasks([0b1000, 0b0100, 0b0010]) // 0b1110
|
|
31
|
-
*/
|
|
32
|
-
static combineBitmasks(bitmasks: bigint[]): bigint;
|
|
33
|
-
/**
|
|
34
|
-
* Decode a base64 encoded string into a binary number
|
|
35
|
-
* @param base64 Base64 encoded bitmask (valid utf-8 string of a number)
|
|
36
|
-
* @returns The decoded bitmask
|
|
37
|
-
* @example Bitmask.decodeFromBase64("AQ==") // 1 or 0b1
|
|
38
|
-
* @example Bitmask.decodeFromBase64("Ag==") // 2 or 0b10
|
|
39
|
-
*/
|
|
40
|
-
static decodeFromBase64(base64: string): bigint;
|
|
41
|
-
/**
|
|
42
|
-
* Encode a binary number into a base64 string
|
|
43
|
-
* @param bitmask The bitmask to encode
|
|
44
|
-
* @returns The base64 encoded bitmask
|
|
45
|
-
* @example Bitmask.encodeToBase64(1) // "AQ=="
|
|
46
|
-
* @example Bitmask.encodeToBase64(2) // "Ag=="
|
|
47
|
-
*/
|
|
48
|
-
static encodeToBase64(bitmask: bigint): string;
|
|
49
|
-
/**
|
|
50
|
-
* Similar to #encodeFromPosition but takes a Permission object and encodes it to
|
|
51
|
-
* a binary number, based on the Permission.position property.
|
|
52
|
-
*/
|
|
53
|
-
static encodePermission(permission: Permission): bigint;
|
|
54
|
-
/**
|
|
55
|
-
* Converts an array of Permissions to a binary number. Will combine all the permissions
|
|
56
|
-
* bitmasks into one.
|
|
57
|
-
*/
|
|
58
|
-
static encodePermissions(permissions: Permission[]): bigint;
|
|
59
|
-
/**
|
|
60
|
-
* Converts an array of Permissions to an encoded string ready to use in JWTUser.permission
|
|
61
|
-
*/
|
|
62
|
-
static encodePermissionsToBase64(permissions: Permission[]): string;
|
|
63
|
-
}
|
package/dist/BitmaskUtils.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BitmaskUtils = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Bitmask utility class
|
|
6
|
-
* - Use to handle binary numbers
|
|
7
|
-
* - Support binary numbers larger than 32 bits (Node.js uses 32-bit numbers)
|
|
8
|
-
*/
|
|
9
|
-
class BitmaskUtils {
|
|
10
|
-
/**
|
|
11
|
-
* Encode a position into a binary number
|
|
12
|
-
* @example Bitmask.encodeFromPosition(0) // 1 or 0b1
|
|
13
|
-
* @example Bitmask.encodeFromPosition(1) // 2 or 0b10
|
|
14
|
-
* @example Bitmask.encodeFromPosition(2) // 4 or 0b100
|
|
15
|
-
* @example Bitmask.encodeFromPosition(3) // 8 or 0b1000
|
|
16
|
-
*/
|
|
17
|
-
static encodeFromPosition(position) {
|
|
18
|
-
return BigInt(1) << BigInt(position);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Check if a bitmask has a specific bit set
|
|
22
|
-
* @param bitmask - the bitmask to check
|
|
23
|
-
* @param check - the bit to check (also a bitmask with only one bit set)
|
|
24
|
-
* @example Bitmask.checkBitmask(0b1010, 0b1000) // true
|
|
25
|
-
* @example Bitmask.checkBitmask(0b1010, 0b0100) // false
|
|
26
|
-
*/
|
|
27
|
-
static checkBitmask(bitmask, check) {
|
|
28
|
-
return (bitmask & check) === check;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Combine multiple bitmasks into one
|
|
32
|
-
* Uses the bitwise OR operator to combine the bitmasks
|
|
33
|
-
* @param bitmasks - An array of bitmasks
|
|
34
|
-
* @returns The combined bitmask
|
|
35
|
-
* @example Bitmask.combineBitmasks([0b1000, 0b0100]) // 0b1100
|
|
36
|
-
* @example Bitmask.combineBitmasks([0b1000, 0b0100, 0b0010]) // 0b1110
|
|
37
|
-
*/
|
|
38
|
-
static combineBitmasks(bitmasks) {
|
|
39
|
-
return bitmasks.reduce((acc, bitmask) => acc | bitmask, BigInt(0));
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Decode a base64 encoded string into a binary number
|
|
43
|
-
* @param base64 Base64 encoded bitmask (valid utf-8 string of a number)
|
|
44
|
-
* @returns The decoded bitmask
|
|
45
|
-
* @example Bitmask.decodeFromBase64("AQ==") // 1 or 0b1
|
|
46
|
-
* @example Bitmask.decodeFromBase64("Ag==") // 2 or 0b10
|
|
47
|
-
*/
|
|
48
|
-
static decodeFromBase64(base64) {
|
|
49
|
-
const string = Buffer.from(base64, "base64").toString("utf-8");
|
|
50
|
-
return BigInt(string);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Encode a binary number into a base64 string
|
|
54
|
-
* @param bitmask The bitmask to encode
|
|
55
|
-
* @returns The base64 encoded bitmask
|
|
56
|
-
* @example Bitmask.encodeToBase64(1) // "AQ=="
|
|
57
|
-
* @example Bitmask.encodeToBase64(2) // "Ag=="
|
|
58
|
-
*/
|
|
59
|
-
static encodeToBase64(bitmask) {
|
|
60
|
-
return Buffer.from(bitmask.toString()).toString("base64");
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Similar to #encodeFromPosition but takes a Permission object and encodes it to
|
|
64
|
-
* a binary number, based on the Permission.position property.
|
|
65
|
-
*/
|
|
66
|
-
static encodePermission(permission) {
|
|
67
|
-
return BitmaskUtils.encodeFromPosition(permission.position);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Converts an array of Permissions to a binary number. Will combine all the permissions
|
|
71
|
-
* bitmasks into one.
|
|
72
|
-
*/
|
|
73
|
-
static encodePermissions(permissions) {
|
|
74
|
-
const bitmasks = permissions.map((p) => BitmaskUtils.encodePermission(p));
|
|
75
|
-
return BitmaskUtils.combineBitmasks(bitmasks);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Converts an array of Permissions to an encoded string ready to use in JWTUser.permission
|
|
79
|
-
*/
|
|
80
|
-
static encodePermissionsToBase64(permissions) {
|
|
81
|
-
return BitmaskUtils.encodeToBase64(this.encodePermissions(permissions));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.BitmaskUtils = BitmaskUtils;
|
|
85
|
-
//# sourceMappingURL=BitmaskUtils.js.map
|
package/dist/BitmaskUtils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BitmaskUtils.js","sourceRoot":"","sources":["../src/BitmaskUtils.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,MAAa,YAAY;IACvB;;;;;;OAMG;IACI,MAAM,CAAC,kBAAkB,CAAC,QAAgB;QAC/C,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,YAAY,CAAC,OAAe,EAAE,KAAa;QACvD,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,KAAK,CAAC;IACrC,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,eAAe,CAAC,QAAkB;QAC9C,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,gBAAgB,CAAC,MAAc;QAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC/D,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,cAAc,CAAC,OAAe;QAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,gBAAgB,CAAC,UAAsB;QACnD,OAAO,YAAY,CAAC,kBAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,iBAAiB,CAAC,WAAyB;QACvD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1E,OAAO,YAAY,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,yBAAyB,CAAC,WAAyB;QAC/D,OAAO,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1E,CAAC;CACF;AAjFD,oCAiFC"}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const BitmaskUtils_1 = require("./BitmaskUtils");
|
|
4
|
-
describe("BitmaskUtils", () => {
|
|
5
|
-
describe("encodeFromPosition", () => {
|
|
6
|
-
it.each([
|
|
7
|
-
{ position: 0, expected: BigInt(0b1) },
|
|
8
|
-
{ position: 1, expected: BigInt(0b10) },
|
|
9
|
-
{ position: 5, expected: BigInt(0b100000) },
|
|
10
|
-
{ position: 10, expected: BigInt(0b10000000000) },
|
|
11
|
-
{ position: 15, expected: BigInt(0b1000000000000000) },
|
|
12
|
-
{ position: 30, expected: BigInt(0b1000000000000000000000000000000) },
|
|
13
|
-
{
|
|
14
|
-
position: 31,
|
|
15
|
-
expected: BigInt(0b10000000000000000000000000000000),
|
|
16
|
-
},
|
|
17
|
-
// 32 is the maximum position for a 32-bit number - Node.js uses 32-bit numbers (when using unsigned ints), we should support more than 32 bits
|
|
18
|
-
{
|
|
19
|
-
position: 32,
|
|
20
|
-
expected: BigInt("0b100000000000000000000000000000000"),
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
position: 50,
|
|
24
|
-
expected: BigInt("0b100000000000000000000000000000000000000000000000000"),
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
position: 100,
|
|
28
|
-
expected: BigInt("0b10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
|
29
|
-
},
|
|
30
|
-
])("Should encode a numeric position $position to a binary number", ({ position, expected }) => {
|
|
31
|
-
const result = BitmaskUtils_1.BitmaskUtils.encodeFromPosition(position);
|
|
32
|
-
expect(result).toStrictEqual(expected);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe("checkBitmask", () => {
|
|
36
|
-
it.each([
|
|
37
|
-
{
|
|
38
|
-
bitmask: BigInt(0b1010),
|
|
39
|
-
position: 3,
|
|
40
|
-
expected: true,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
bitmask: BigInt(0b1010),
|
|
44
|
-
position: 2,
|
|
45
|
-
expected: false,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
bitmask: BigInt(0b1010),
|
|
49
|
-
position: 1,
|
|
50
|
-
expected: true,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
bitmask: BigInt(0b1010),
|
|
54
|
-
position: 0,
|
|
55
|
-
expected: false,
|
|
56
|
-
},
|
|
57
|
-
])("Should check if a bitmask has a specific bit set in position $position", ({ bitmask, position, expected }) => {
|
|
58
|
-
const check = BitmaskUtils_1.BitmaskUtils.encodeFromPosition(position);
|
|
59
|
-
const result = BitmaskUtils_1.BitmaskUtils.checkBitmask(bitmask, check);
|
|
60
|
-
expect(result).toStrictEqual(expected);
|
|
61
|
-
});
|
|
62
|
-
it("Should check if a bitmask has a specific bit set with big numbers", () => {
|
|
63
|
-
const bitmask = BitmaskUtils_1.BitmaskUtils.encodeFromPosition(100);
|
|
64
|
-
const result = BitmaskUtils_1.BitmaskUtils.checkBitmask(bitmask, bitmask);
|
|
65
|
-
expect(result).toStrictEqual(true);
|
|
66
|
-
});
|
|
67
|
-
it("Should check if a bitmask has a specific bit set with enormous numbers", () => {
|
|
68
|
-
const bitmask = BitmaskUtils_1.BitmaskUtils.encodeFromPosition(500);
|
|
69
|
-
const result = BitmaskUtils_1.BitmaskUtils.checkBitmask(bitmask, bitmask);
|
|
70
|
-
expect(result).toStrictEqual(true);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe("combineBitmasks", () => {
|
|
74
|
-
it.each([
|
|
75
|
-
{
|
|
76
|
-
bitmasks: [BigInt(0b1000), BigInt(0b0100)],
|
|
77
|
-
expected: BigInt(0b1100),
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
bitmasks: [BigInt(0b1000), BigInt(0b0100), BigInt(0b0010)],
|
|
81
|
-
expected: BigInt(0b1110),
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
bitmasks: [
|
|
85
|
-
BigInt(0b1000),
|
|
86
|
-
BigInt(0b0100),
|
|
87
|
-
BigInt(0b0010),
|
|
88
|
-
BigInt(0b0001),
|
|
89
|
-
],
|
|
90
|
-
expected: BigInt(0b1111),
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
bitmasks: [
|
|
94
|
-
BitmaskUtils_1.BitmaskUtils.encodeFromPosition(100),
|
|
95
|
-
BitmaskUtils_1.BitmaskUtils.encodeFromPosition(200),
|
|
96
|
-
BitmaskUtils_1.BitmaskUtils.encodeFromPosition(300),
|
|
97
|
-
BitmaskUtils_1.BitmaskUtils.encodeFromPosition(400),
|
|
98
|
-
],
|
|
99
|
-
expected: BitmaskUtils_1.BitmaskUtils.encodeFromPosition(100) |
|
|
100
|
-
BitmaskUtils_1.BitmaskUtils.encodeFromPosition(200) |
|
|
101
|
-
BitmaskUtils_1.BitmaskUtils.encodeFromPosition(300) |
|
|
102
|
-
BitmaskUtils_1.BitmaskUtils.encodeFromPosition(400),
|
|
103
|
-
},
|
|
104
|
-
])("Should combine multiple bitmasks into one", ({ bitmasks, expected }) => {
|
|
105
|
-
const result = BitmaskUtils_1.BitmaskUtils.combineBitmasks(bitmasks);
|
|
106
|
-
expect(result).toStrictEqual(expected);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe("decodeFromBase64", () => {
|
|
110
|
-
it.each([
|
|
111
|
-
{ base64: "MA==", expected: BigInt(0b0) },
|
|
112
|
-
{ base64: "MQ==", expected: BigInt(0b1) },
|
|
113
|
-
{ base64: "Mg==", expected: BigInt(0b10) },
|
|
114
|
-
{ base64: "NjY3", expected: BigInt(0b1010011011) },
|
|
115
|
-
{
|
|
116
|
-
base64: "MTI2NzY1MDYwMDIyODIyOTQwMTQ5NjcwMzIwNTM3Ng==",
|
|
117
|
-
expected: BitmaskUtils_1.BitmaskUtils.encodeFromPosition(100),
|
|
118
|
-
},
|
|
119
|
-
])("Should decode a base64 encoded bitmask for $base64", ({ base64, expected }) => {
|
|
120
|
-
const result = BitmaskUtils_1.BitmaskUtils.decodeFromBase64(base64);
|
|
121
|
-
expect(result).toStrictEqual(expected);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
describe("encodeToBase64", () => {
|
|
125
|
-
it.each([
|
|
126
|
-
{ bitmask: BigInt(0b0), expected: "MA==" },
|
|
127
|
-
{ bitmask: BigInt(0b1), expected: "MQ==" },
|
|
128
|
-
{ bitmask: BigInt(0b10), expected: "Mg==" },
|
|
129
|
-
{ bitmask: BigInt(0b1010011011), expected: "NjY3" },
|
|
130
|
-
{
|
|
131
|
-
bitmask: BitmaskUtils_1.BitmaskUtils.encodeFromPosition(100),
|
|
132
|
-
expected: "MTI2NzY1MDYwMDIyODIyOTQwMTQ5NjcwMzIwNTM3Ng==",
|
|
133
|
-
},
|
|
134
|
-
])("Should encode a bitmask to a base64 string for $bitmask", ({ bitmask, expected }) => {
|
|
135
|
-
const result = BitmaskUtils_1.BitmaskUtils.encodeToBase64(bitmask);
|
|
136
|
-
expect(result).toStrictEqual(expected);
|
|
137
|
-
});
|
|
138
|
-
it("Should encode and decode a bitmask from and to a base64 string", () => {
|
|
139
|
-
const bitmask = BigInt(0b1010011011);
|
|
140
|
-
const base64 = BitmaskUtils_1.BitmaskUtils.encodeToBase64(bitmask);
|
|
141
|
-
const result = BitmaskUtils_1.BitmaskUtils.decodeFromBase64(base64);
|
|
142
|
-
expect(result).toStrictEqual(bitmask);
|
|
143
|
-
});
|
|
144
|
-
it("Should encode and decode a bitmask from and to a base64 string with enormous numbers", () => {
|
|
145
|
-
const bitmask = BitmaskUtils_1.BitmaskUtils.encodeFromPosition(500);
|
|
146
|
-
const base64 = BitmaskUtils_1.BitmaskUtils.encodeToBase64(bitmask);
|
|
147
|
-
const result = BitmaskUtils_1.BitmaskUtils.decodeFromBase64(base64);
|
|
148
|
-
expect(result).toStrictEqual(bitmask);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
//# sourceMappingURL=BitmaskUtils.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BitmaskUtils.test.js","sourceRoot":"","sources":["../src/BitmaskUtils.test.ts"],"names":[],"mappings":";;AAAA,iDAA8C;AAE9C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,EAAE,CAAC,IAAI,CAAC;YACN,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,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