@flowerforce/flowerbase 1.7.5 → 1.7.6-beta.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/auth/controller.d.ts.map +1 -1
- package/dist/auth/controller.js +11 -10
- package/dist/auth/plugins/jwt.js +1 -1
- package/dist/auth/providers/anon-user/controller.js +1 -1
- package/dist/auth/providers/custom-function/controller.d.ts.map +1 -1
- package/dist/auth/providers/custom-function/controller.js +36 -10
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +15 -14
- package/dist/auth/utils.d.ts +1 -0
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -3
- package/dist/features/triggers/index.js +1 -1
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +38 -30
- package/dist/monitoring/routes/users.d.ts.map +1 -1
- package/dist/monitoring/routes/users.js +7 -6
- package/dist/monitoring/utils.d.ts.map +1 -1
- package/dist/monitoring/utils.js +5 -4
- package/dist/services/api/index.d.ts +4 -0
- package/dist/services/api/index.d.ts.map +1 -1
- package/dist/services/api/utils.d.ts +1 -0
- package/dist/services/api/utils.d.ts.map +1 -1
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/shared/handleUserDeletion.js +1 -1
- package/dist/shared/handleUserRegistration.js +2 -2
- package/dist/utils/context/helpers.d.ts +12 -0
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/dist/utils/initializer/exposeRoutes.js +1 -1
- package/dist/utils/rules-matcher/interface.d.ts +5 -1
- package/dist/utils/rules-matcher/interface.d.ts.map +1 -1
- package/dist/utils/rules-matcher/interface.js +2 -0
- package/dist/utils/rules-matcher/utils.d.ts.map +1 -1
- package/dist/utils/rules-matcher/utils.js +51 -16
- package/package.json +1 -1
- package/src/auth/__tests__/controller.test.ts +1 -0
- package/src/auth/controller.ts +12 -11
- package/src/auth/plugins/jwt.ts +2 -2
- package/src/auth/providers/anon-user/__tests__/controller.test.ts +1 -0
- package/src/auth/providers/anon-user/controller.ts +2 -2
- package/src/auth/providers/custom-function/controller.ts +39 -12
- package/src/auth/providers/local-userpass/controller.ts +16 -15
- package/src/auth/utils.ts +1 -0
- package/src/constants.ts +3 -2
- package/src/features/triggers/__tests__/index.test.ts +1 -0
- package/src/features/triggers/index.ts +2 -2
- package/src/features/triggers/utils.ts +42 -31
- package/src/monitoring/routes/users.ts +8 -7
- package/src/monitoring/ui.css +5 -1
- package/src/monitoring/ui.events.js +2 -2
- package/src/monitoring/ui.shared.js +2 -1
- package/src/monitoring/utils.ts +6 -5
- package/src/shared/handleUserDeletion.ts +2 -2
- package/src/shared/handleUserRegistration.ts +3 -3
- package/src/utils/__tests__/operators.test.ts +24 -0
- package/src/utils/__tests__/rule.test.ts +39 -0
- package/src/utils/__tests__/rulesMatcherInterfaces.test.ts +2 -0
- package/src/utils/initializer/exposeRoutes.ts +2 -2
- package/src/utils/rules-matcher/interface.ts +5 -1
- package/src/utils/rules-matcher/utils.ts +78 -32
package/dist/monitoring/utils.js
CHANGED
|
@@ -332,7 +332,8 @@ const resolveUserContext = (app, userId, userPayload) => __awaiter(void 0, void
|
|
|
332
332
|
if (!userId)
|
|
333
333
|
return undefined;
|
|
334
334
|
const normalizedUserId = userId.trim();
|
|
335
|
-
const
|
|
335
|
+
const authDb = app.mongo.client.db(constants_1.AUTH_DB_NAME);
|
|
336
|
+
const customDb = app.mongo.client.db(constants_1.DB_NAME);
|
|
336
337
|
const authCollection = (_a = constants_1.AUTH_CONFIG.authCollection) !== null && _a !== void 0 ? _a : 'auth_users';
|
|
337
338
|
const userCollection = constants_1.AUTH_CONFIG.userCollection;
|
|
338
339
|
const userIdField = (_b = constants_1.AUTH_CONFIG.user_id_field) !== null && _b !== void 0 ? _b : 'id';
|
|
@@ -340,13 +341,13 @@ const resolveUserContext = (app, userId, userPayload) => __awaiter(void 0, void
|
|
|
340
341
|
const authSelector = isObjectId
|
|
341
342
|
? { _id: new mongodb_1.ObjectId(normalizedUserId) }
|
|
342
343
|
: { id: normalizedUserId };
|
|
343
|
-
const authUser = yield
|
|
344
|
+
const authUser = yield authDb.collection(authCollection).findOne(authSelector);
|
|
344
345
|
let customUser = null;
|
|
345
346
|
if (userCollection) {
|
|
346
347
|
const customSelector = { [userIdField]: normalizedUserId };
|
|
347
|
-
customUser = yield
|
|
348
|
+
customUser = yield customDb.collection(userCollection).findOne(customSelector);
|
|
348
349
|
if (!customUser && isObjectId) {
|
|
349
|
-
customUser = yield
|
|
350
|
+
customUser = yield customDb.collection(userCollection).findOne({ _id: new mongodb_1.ObjectId(normalizedUserId) });
|
|
350
351
|
}
|
|
351
352
|
}
|
|
352
353
|
const id = authUser && typeof authUser._id !== 'undefined'
|
|
@@ -30,6 +30,7 @@ declare const Api: (_app?: unknown, opt?: {
|
|
|
30
30
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
31
31
|
};
|
|
32
32
|
statusCode: number;
|
|
33
|
+
statusText: string;
|
|
33
34
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
34
35
|
trailers: Record<string, string>;
|
|
35
36
|
opaque: T;
|
|
@@ -58,6 +59,7 @@ declare const Api: (_app?: unknown, opt?: {
|
|
|
58
59
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
59
60
|
};
|
|
60
61
|
statusCode: number;
|
|
62
|
+
statusText: string;
|
|
61
63
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
62
64
|
trailers: Record<string, string>;
|
|
63
65
|
opaque: T;
|
|
@@ -86,6 +88,7 @@ declare const Api: (_app?: unknown, opt?: {
|
|
|
86
88
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
87
89
|
};
|
|
88
90
|
statusCode: number;
|
|
91
|
+
statusText: string;
|
|
89
92
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
90
93
|
trailers: Record<string, string>;
|
|
91
94
|
opaque: T;
|
|
@@ -114,6 +117,7 @@ declare const Api: (_app?: unknown, opt?: {
|
|
|
114
117
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
115
118
|
};
|
|
116
119
|
statusCode: number;
|
|
120
|
+
statusText: string;
|
|
117
121
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
118
122
|
trailers: Record<string, string>;
|
|
119
123
|
opaque: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/api/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGxE;;GAEG;AACH,QAAA,MAAM,GAAG,GAAI,OAAO,OAAO,EAAE,MAAM;IAAE,UAAU,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE;UAG5D,CAAC,wCAAoD,SAAS
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/api/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGxE;;GAEG;AACH,QAAA,MAAM,GAAG,GAAI,OAAO,OAAO,EAAE,MAAM;IAAE,UAAU,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE;UAG5D,CAAC,wCAAoD,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAuB7D,CAAC,gGASX,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+BD,CAAC,gGASV,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA+BG,CAAC,wEAOb,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBlB,CAAA;AAED,eAAe,GAAG,CAAA"}
|
|
@@ -29,6 +29,7 @@ export declare const makeRequest: <T = null>({ method, url, headers, body, resol
|
|
|
29
29
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
30
30
|
};
|
|
31
31
|
statusCode: number;
|
|
32
|
+
statusText: string;
|
|
32
33
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
33
34
|
trailers: Record<string, string>;
|
|
34
35
|
opaque: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/api/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAgBlD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAU,CAAC,GAAG,IAAI,EAAE,6CAMzC,iBAAiB
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/api/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAgBlD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAU,CAAC,GAAG,IAAI,EAAE,6CAMzC,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBnB,CAAA"}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare const services: {
|
|
|
27
27
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
28
28
|
};
|
|
29
29
|
statusCode: number;
|
|
30
|
+
statusText: string;
|
|
30
31
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
31
32
|
trailers: Record<string, string>;
|
|
32
33
|
opaque: T;
|
|
@@ -55,6 +56,7 @@ export declare const services: {
|
|
|
55
56
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
56
57
|
};
|
|
57
58
|
statusCode: number;
|
|
59
|
+
statusText: string;
|
|
58
60
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
59
61
|
trailers: Record<string, string>;
|
|
60
62
|
opaque: T;
|
|
@@ -83,6 +85,7 @@ export declare const services: {
|
|
|
83
85
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
84
86
|
};
|
|
85
87
|
statusCode: number;
|
|
88
|
+
statusText: string;
|
|
86
89
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
87
90
|
trailers: Record<string, string>;
|
|
88
91
|
opaque: T;
|
|
@@ -111,6 +114,7 @@ export declare const services: {
|
|
|
111
114
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
112
115
|
};
|
|
113
116
|
statusCode: number;
|
|
117
|
+
statusText: string;
|
|
114
118
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
115
119
|
trailers: Record<string, string>;
|
|
116
120
|
opaque: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;;kBAMoG,CAAC;uBAAe,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;;kBAMoG,CAAC;uBAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAA2hB,CAAC;uBAAe,CAAC;;;;;;;;;;;;;;;;sBAA0/F,CAAC;yBAAa,CAAC;;;;;;;;;;;CAD9rH,CAAA"}
|
|
@@ -40,7 +40,7 @@ const handleUserDeletion = (app, opt) => (_a) => __awaiter(void 0, [_a], void 0,
|
|
|
40
40
|
}
|
|
41
41
|
const { authCollection } = constants_1.AUTH_CONFIG;
|
|
42
42
|
const mongo = app === null || app === void 0 ? void 0 : app.mongo;
|
|
43
|
-
const db = mongo.client.db(constants_1.
|
|
43
|
+
const db = mongo.client.db(constants_1.AUTH_DB_NAME);
|
|
44
44
|
const collection = db.collection(authCollection);
|
|
45
45
|
let query;
|
|
46
46
|
if (id) {
|
|
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const constants_1 = require("../constants");
|
|
13
|
+
const monitoring_1 = require("../services/monitoring");
|
|
13
14
|
const state_1 = require("../state");
|
|
14
15
|
const context_1 = require("../utils/context");
|
|
15
16
|
const crypto_1 = require("../utils/crypto");
|
|
16
|
-
const monitoring_1 = require("../services/monitoring");
|
|
17
17
|
/**
|
|
18
18
|
* Register user
|
|
19
19
|
*
|
|
@@ -43,7 +43,7 @@ const handleUserRegistration = (app, opt) => (_a) => __awaiter(void 0, [_a], voi
|
|
|
43
43
|
const runConfirmationFunction = (localUserpassConfig === null || localUserpassConfig === void 0 ? void 0 : localUserpassConfig.runConfirmationFunction) === true;
|
|
44
44
|
const confirmationFunctionName = localUserpassConfig === null || localUserpassConfig === void 0 ? void 0 : localUserpassConfig.confirmationFunctionName;
|
|
45
45
|
const mongo = app === null || app === void 0 ? void 0 : app.mongo;
|
|
46
|
-
const db = mongo.client.db(constants_1.
|
|
46
|
+
const db = mongo.client.db(constants_1.AUTH_DB_NAME);
|
|
47
47
|
const hashedPassword = yield (0, crypto_1.hashPassword)(password);
|
|
48
48
|
const existingUser = yield (db === null || db === void 0 ? void 0 : db.collection(authCollection).findOne({ email }));
|
|
49
49
|
if (existingUser && !skipUserCheck) {
|
|
@@ -82,6 +82,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
82
82
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
83
83
|
};
|
|
84
84
|
statusCode: number;
|
|
85
|
+
statusText: string;
|
|
85
86
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
86
87
|
trailers: Record<string, string>;
|
|
87
88
|
opaque: T;
|
|
@@ -110,6 +111,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
110
111
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
111
112
|
};
|
|
112
113
|
statusCode: number;
|
|
114
|
+
statusText: string;
|
|
113
115
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
114
116
|
trailers: Record<string, string>;
|
|
115
117
|
opaque: T;
|
|
@@ -138,6 +140,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
138
140
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
139
141
|
};
|
|
140
142
|
statusCode: number;
|
|
143
|
+
statusText: string;
|
|
141
144
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
142
145
|
trailers: Record<string, string>;
|
|
143
146
|
opaque: T;
|
|
@@ -166,6 +169,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
166
169
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
167
170
|
};
|
|
168
171
|
statusCode: number;
|
|
172
|
+
statusText: string;
|
|
169
173
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
170
174
|
trailers: Record<string, string>;
|
|
171
175
|
opaque: T;
|
|
@@ -230,6 +234,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
230
234
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
231
235
|
};
|
|
232
236
|
statusCode: number;
|
|
237
|
+
statusText: string;
|
|
233
238
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
234
239
|
trailers: Record<string, string>;
|
|
235
240
|
opaque: T;
|
|
@@ -258,6 +263,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
258
263
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
259
264
|
};
|
|
260
265
|
statusCode: number;
|
|
266
|
+
statusText: string;
|
|
261
267
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
262
268
|
trailers: Record<string, string>;
|
|
263
269
|
opaque: T;
|
|
@@ -286,6 +292,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
286
292
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
287
293
|
};
|
|
288
294
|
statusCode: number;
|
|
295
|
+
statusText: string;
|
|
289
296
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
290
297
|
trailers: Record<string, string>;
|
|
291
298
|
opaque: T;
|
|
@@ -314,6 +321,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
314
321
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
315
322
|
};
|
|
316
323
|
statusCode: number;
|
|
324
|
+
statusText: string;
|
|
317
325
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
318
326
|
trailers: Record<string, string>;
|
|
319
327
|
opaque: T;
|
|
@@ -377,6 +385,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
377
385
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
378
386
|
};
|
|
379
387
|
statusCode: number;
|
|
388
|
+
statusText: string;
|
|
380
389
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
381
390
|
trailers: Record<string, string>;
|
|
382
391
|
opaque: T;
|
|
@@ -405,6 +414,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
405
414
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
406
415
|
};
|
|
407
416
|
statusCode: number;
|
|
417
|
+
statusText: string;
|
|
408
418
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
409
419
|
trailers: Record<string, string>;
|
|
410
420
|
opaque: T;
|
|
@@ -433,6 +443,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
433
443
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
434
444
|
};
|
|
435
445
|
statusCode: number;
|
|
446
|
+
statusText: string;
|
|
436
447
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
437
448
|
trailers: Record<string, string>;
|
|
438
449
|
opaque: T;
|
|
@@ -461,6 +472,7 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
461
472
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
462
473
|
};
|
|
463
474
|
statusCode: number;
|
|
475
|
+
statusText: string;
|
|
464
476
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
465
477
|
trailers: Record<string, string>;
|
|
466
478
|
opaque: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAG1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,CACN,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzC,MAAM,CAAA;IACX,MAAM,EAAE,CACN,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,YAAY,CAAC,EAAE,OAAO,EACtB,sBAAsB,CAAC,EAAE,MAAM,EAAE,KAC9B,OAAO,CAAA;CACb,CAAA;AAgFD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,4GAUjC,yBAAyB;;;;;;;;;;;;;uBA4DP,SAAS;yBAGP,SAAS;;;;;;;;;;;;;;;;;;uBAcb,MAAM;;;;;;+BA5CU,MAAM,OAAO,QAAQ;;;;sCA1HrC,CAAC
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAG1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE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;;;;;;;;;4BAyEF,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAiBrE,CAAA"}
|
|
@@ -56,7 +56,7 @@ const exposeRoutes = (fastify) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
56
56
|
}, function (req, res) {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
58
|
const { authCollection } = constants_1.AUTH_CONFIG;
|
|
59
|
-
const db = fastify.mongo.client.db(constants_1.
|
|
59
|
+
const db = fastify.mongo.client.db(constants_1.AUTH_DB_NAME);
|
|
60
60
|
const { email, password } = req.body;
|
|
61
61
|
const hashedPassword = yield (0, crypto_1.hashPassword)(password);
|
|
62
62
|
const now = new Date();
|
|
@@ -311,6 +311,8 @@ export type Operators = {
|
|
|
311
311
|
* @returns
|
|
312
312
|
*/
|
|
313
313
|
$regex: OperatorsFunction;
|
|
314
|
+
'%stringToOid': OperatorsFunction;
|
|
315
|
+
'%oidToString': OperatorsFunction;
|
|
314
316
|
};
|
|
315
317
|
export declare enum RulesOperators {
|
|
316
318
|
$exists = "$exists",
|
|
@@ -328,7 +330,9 @@ export declare enum RulesOperators {
|
|
|
328
330
|
$nin = "$nin",
|
|
329
331
|
$all = "$all",
|
|
330
332
|
$size = "$size",
|
|
331
|
-
$regex = "$regex"
|
|
333
|
+
$regex = "$regex",
|
|
334
|
+
'%stringToOid' = "%stringToOid",
|
|
335
|
+
'%oidToString' = "%oidToString"
|
|
332
336
|
}
|
|
333
337
|
export type RulesOperatorsInArray<T> = Partial<{
|
|
334
338
|
[KEY in keyof T]: Partial<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/utils/rules-matcher/interface.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,CAAA;AAE7C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,SAAS,CAAA;IACnB,KA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AAC;CAC3C,GACD,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAA"}
|
|
@@ -19,6 +19,8 @@ var RulesOperators;
|
|
|
19
19
|
RulesOperators["$all"] = "$all";
|
|
20
20
|
RulesOperators["$size"] = "$size";
|
|
21
21
|
RulesOperators["$regex"] = "$regex";
|
|
22
|
+
RulesOperators["%stringToOid"] = "%stringToOid";
|
|
23
|
+
RulesOperators["%oidToString"] = "%oidToString";
|
|
22
24
|
})(RulesOperators || (exports.RulesOperators = RulesOperators = {}));
|
|
23
25
|
var RulesModes;
|
|
24
26
|
(function (RulesModes) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils/rules-matcher/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAe,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils/rules-matcher/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAe,MAAM,aAAa,CAAA;AAsDvE;;GAEG;AACH,QAAA,MAAM,iBAAiB,EAAE,iBAsNxB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,SAoDvB,CAAA;AAID,eAAe,iBAAiB,CAAA"}
|
|
@@ -4,10 +4,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.operators = void 0;
|
|
7
|
+
const bson_1 = require("bson");
|
|
7
8
|
const get_1 = __importDefault(require("lodash/get"));
|
|
8
|
-
const intersection_1 = __importDefault(require("lodash/intersection"));
|
|
9
9
|
const trimStart_1 = __importDefault(require("lodash/trimStart"));
|
|
10
10
|
const EMPTY_STRING_REGEXP = /^\s*$/;
|
|
11
|
+
const HEX_24_REGEXP = /^[a-fA-F0-9]{24}$/;
|
|
12
|
+
const toObjectIdHex = (value) => {
|
|
13
|
+
if (value instanceof bson_1.ObjectId) {
|
|
14
|
+
return value.toHexString();
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
if (!HEX_24_REGEXP.test(value) || !bson_1.ObjectId.isValid(value)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return new bson_1.ObjectId(value).toHexString();
|
|
21
|
+
}
|
|
22
|
+
if (!value || typeof value !== 'object') {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const maybeObjectId = value;
|
|
26
|
+
if (maybeObjectId._bsontype === 'ObjectId' && typeof maybeObjectId.toHexString === 'function') {
|
|
27
|
+
const hex = maybeObjectId.toHexString();
|
|
28
|
+
return HEX_24_REGEXP.test(hex) ? hex.toLowerCase() : null;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
const areSemanticallyEqual = (left, right) => {
|
|
33
|
+
const leftOid = toObjectIdHex(left);
|
|
34
|
+
const rightOid = toObjectIdHex(right);
|
|
35
|
+
if (leftOid || rightOid) {
|
|
36
|
+
return leftOid !== null && rightOid !== null && leftOid === rightOid;
|
|
37
|
+
}
|
|
38
|
+
return left === right;
|
|
39
|
+
};
|
|
40
|
+
const includesWithSemanticEquality = (value, candidate) => rulesMatcherUtils
|
|
41
|
+
.forceArray(candidate)
|
|
42
|
+
.some((item) => rulesMatcherUtils
|
|
43
|
+
.forceArray(value)
|
|
44
|
+
.some((sourceItem) => rulesMatcherUtils.forceArray(item).some((candidateItem) => areSemanticallyEqual(sourceItem, candidateItem))));
|
|
11
45
|
/**
|
|
12
46
|
* Defines a utility object named rulesMatcherUtils, which contains various helper functions used for processing rules and data in a rule-matching context.
|
|
13
47
|
*/
|
|
@@ -187,8 +221,8 @@ const rulesMatcherUtils = {
|
|
|
187
221
|
*/
|
|
188
222
|
exports.operators = {
|
|
189
223
|
$exists: (a, b) => !rulesMatcherUtils.isEmpty(a) === b,
|
|
190
|
-
$eq: (a, b) => a
|
|
191
|
-
$ne: (a, b) => a
|
|
224
|
+
$eq: (a, b) => areSemanticallyEqual(a, b),
|
|
225
|
+
$ne: (a, b) => !areSemanticallyEqual(a, b),
|
|
192
226
|
$gt: (a, b) => rulesMatcherUtils.forceNumber(a) > parseFloat(b),
|
|
193
227
|
$gte: (a, b) => rulesMatcherUtils.forceNumber(a) >= parseFloat(b),
|
|
194
228
|
$lt: (a, b) => rulesMatcherUtils.forceNumber(a) < parseFloat(b),
|
|
@@ -197,22 +231,23 @@ exports.operators = {
|
|
|
197
231
|
$strGte: (a, b) => String(a || '').length >= parseFloat(b),
|
|
198
232
|
$strLt: (a, b) => String(a || '').length < parseFloat(b),
|
|
199
233
|
$strLte: (a, b) => String(a || '').length <= parseFloat(b),
|
|
200
|
-
$in: (a, b) =>
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
.
|
|
204
|
-
|
|
205
|
-
.forceArray(b)
|
|
206
|
-
.some((c) => (0, intersection_1.default)(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c))
|
|
207
|
-
.length),
|
|
208
|
-
$all: (a, b) => rulesMatcherUtils
|
|
209
|
-
.forceArray(b)
|
|
210
|
-
.every((c) => (0, intersection_1.default)(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c))
|
|
211
|
-
.length),
|
|
234
|
+
$in: (a, b) => includesWithSemanticEquality(a, b),
|
|
235
|
+
$nin: (a, b) => !includesWithSemanticEquality(a, b),
|
|
236
|
+
$all: (a, b) => rulesMatcherUtils.forceArray(b).every((candidate) => rulesMatcherUtils
|
|
237
|
+
.forceArray(a)
|
|
238
|
+
.some((value) => rulesMatcherUtils.forceArray(candidate).some((item) => areSemanticallyEqual(value, item)))),
|
|
212
239
|
$size: (a, b) => Array.isArray(a) && a.length === parseFloat(b),
|
|
213
240
|
$regex: (a, b, opt) => rulesMatcherUtils
|
|
214
241
|
.forceArray(b)
|
|
215
|
-
.some((c) => (c instanceof RegExp ? c.test(a) : new RegExp(c, opt).test(a)))
|
|
242
|
+
.some((c) => (c instanceof RegExp ? c.test(a) : new RegExp(c, opt).test(a))),
|
|
243
|
+
'%stringToOid': (a, b) => {
|
|
244
|
+
const converted = toObjectIdHex(b);
|
|
245
|
+
return converted !== null && areSemanticallyEqual(a, converted);
|
|
246
|
+
},
|
|
247
|
+
'%oidToString': (a, b) => {
|
|
248
|
+
const converted = toObjectIdHex(b);
|
|
249
|
+
return converted !== null && areSemanticallyEqual(a, converted);
|
|
250
|
+
}
|
|
216
251
|
};
|
|
217
252
|
// export default operators
|
|
218
253
|
exports.default = rulesMatcherUtils;
|
package/package.json
CHANGED
package/src/auth/controller.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ObjectId } from 'bson'
|
|
2
2
|
import { FastifyInstance } from 'fastify'
|
|
3
|
-
import { AUTH_CONFIG, DB_NAME, DEFAULT_CONFIG } from '../constants'
|
|
3
|
+
import { AUTH_CONFIG, AUTH_DB_NAME, DB_NAME, DEFAULT_CONFIG } from '../constants'
|
|
4
4
|
import { StateManager } from '../state'
|
|
5
5
|
import { hashToken } from '../utils/crypto'
|
|
6
6
|
import { SessionCreatedDto } from './dtos'
|
|
@@ -23,11 +23,12 @@ type UnauthorizedSessionReply = typeof unauthorizedSessionError
|
|
|
23
23
|
export async function authController(app: FastifyInstance) {
|
|
24
24
|
const { authCollection, userCollection, refreshTokensCollection } = AUTH_CONFIG
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const authDb = app.mongo.client.db(AUTH_DB_NAME)
|
|
27
|
+
const customUserDb = app.mongo.client.db(DB_NAME)
|
|
27
28
|
const refreshTokenTtlMs = DEFAULT_CONFIG.REFRESH_TOKEN_TTL_DAYS * 24 * 60 * 60 * 1000
|
|
28
29
|
|
|
29
30
|
try {
|
|
30
|
-
await
|
|
31
|
+
await authDb.collection(refreshTokensCollection).createIndex(
|
|
31
32
|
{ expiresAt: 1 },
|
|
32
33
|
{ expireAfterSeconds: 0 }
|
|
33
34
|
)
|
|
@@ -36,7 +37,7 @@ export async function authController(app: FastifyInstance) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
try {
|
|
39
|
-
await
|
|
40
|
+
await authDb.collection(authCollection).createIndex(
|
|
40
41
|
{ email: 1 },
|
|
41
42
|
{
|
|
42
43
|
unique: true
|
|
@@ -63,12 +64,12 @@ export async function authController(app: FastifyInstance) {
|
|
|
63
64
|
if (req.user.typ !== 'access') {
|
|
64
65
|
throw new Error('Access token required')
|
|
65
66
|
}
|
|
66
|
-
const authUser = await
|
|
67
|
+
const authUser = await authDb
|
|
67
68
|
.collection<Record<string, unknown>>(authCollection)
|
|
68
69
|
.findOne({ _id: ObjectId.createFromHexString(req.user.id) })
|
|
69
70
|
|
|
70
71
|
const customData = userCollection && AUTH_CONFIG.user_id_field
|
|
71
|
-
? await
|
|
72
|
+
? await customUserDb
|
|
72
73
|
.collection<Record<string, unknown>>(userCollection)
|
|
73
74
|
.findOne({ [AUTH_CONFIG.user_id_field]: req.user.id })
|
|
74
75
|
: null
|
|
@@ -117,7 +118,7 @@ export async function authController(app: FastifyInstance) {
|
|
|
117
118
|
}
|
|
118
119
|
const refreshToken = authHeader.slice('Bearer '.length).trim()
|
|
119
120
|
const refreshTokenHash = hashToken(refreshToken)
|
|
120
|
-
const storedToken = await
|
|
121
|
+
const storedToken = await authDb.collection(refreshTokensCollection).findOne({
|
|
121
122
|
tokenHash: refreshTokenHash,
|
|
122
123
|
revokedAt: null,
|
|
123
124
|
expiresAt: { $gt: new Date() }
|
|
@@ -127,7 +128,7 @@ export async function authController(app: FastifyInstance) {
|
|
|
127
128
|
return
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
const auth_user = await
|
|
131
|
+
const auth_user = await authDb
|
|
131
132
|
?.collection(authCollection)
|
|
132
133
|
.findOne({ _id: new this.mongo.ObjectId(req.user.sub) })
|
|
133
134
|
|
|
@@ -137,7 +138,7 @@ export async function authController(app: FastifyInstance) {
|
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
const user = userCollection && AUTH_CONFIG.user_id_field
|
|
140
|
-
? (await
|
|
141
|
+
? (await customUserDb.collection(userCollection).findOne({ [AUTH_CONFIG.user_id_field]: req.user.sub }))
|
|
141
142
|
: {}
|
|
142
143
|
|
|
143
144
|
res.status(201)
|
|
@@ -175,7 +176,7 @@ export async function authController(app: FastifyInstance) {
|
|
|
175
176
|
const refreshTokenHash = hashToken(refreshToken)
|
|
176
177
|
const now = new Date()
|
|
177
178
|
const expiresAt = new Date(Date.now() + refreshTokenTtlMs)
|
|
178
|
-
const updateResult = await
|
|
179
|
+
const updateResult = await authDb.collection(refreshTokensCollection).findOneAndUpdate(
|
|
179
180
|
{ tokenHash: refreshTokenHash },
|
|
180
181
|
{
|
|
181
182
|
$set: {
|
|
@@ -197,7 +198,7 @@ export async function authController(app: FastifyInstance) {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
if (userId && authCollection) {
|
|
200
|
-
await
|
|
201
|
+
await authDb.collection(authCollection).updateOne(
|
|
201
202
|
{ _id: userId },
|
|
202
203
|
{ $set: { lastLogoutAt: now } }
|
|
203
204
|
)
|
package/src/auth/plugins/jwt.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fastifyJwt from '@fastify/jwt'
|
|
2
2
|
import fp from 'fastify-plugin'
|
|
3
3
|
import { Document, ObjectId, WithId } from 'mongodb'
|
|
4
|
-
import { AUTH_CONFIG,
|
|
4
|
+
import { AUTH_CONFIG, AUTH_DB_NAME, DEFAULT_CONFIG } from '../../constants'
|
|
5
5
|
|
|
6
6
|
type Options = {
|
|
7
7
|
secret: string
|
|
@@ -51,7 +51,7 @@ export default fp(async function (fastify, opts: Options) {
|
|
|
51
51
|
return
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const db = fastify.mongo?.client?.db(
|
|
54
|
+
const db = fastify.mongo?.client?.db(AUTH_DB_NAME)
|
|
55
55
|
if (!db) {
|
|
56
56
|
fastify.log.warn('Mongo client unavailable while checking logout state')
|
|
57
57
|
return
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ObjectId } from 'bson'
|
|
2
2
|
import { FastifyInstance } from 'fastify'
|
|
3
|
-
import { AUTH_CONFIG,
|
|
3
|
+
import { AUTH_CONFIG, AUTH_DB_NAME, DEFAULT_CONFIG } from '../../../constants'
|
|
4
4
|
import { PROVIDER } from '../../../shared/models/handleUserRegistration.model'
|
|
5
5
|
import { hashToken } from '../../../utils/crypto'
|
|
6
6
|
import { AUTH_ENDPOINTS } from '../../utils'
|
|
@@ -12,7 +12,7 @@ import { LoginDto } from './dtos'
|
|
|
12
12
|
* @param {FastifyInstance} app - The Fastify instance.
|
|
13
13
|
*/
|
|
14
14
|
export async function anonUserController(app: FastifyInstance) {
|
|
15
|
-
const db = app.mongo.client.db(
|
|
15
|
+
const db = app.mongo.client.db(AUTH_DB_NAME)
|
|
16
16
|
const { authCollection, refreshTokensCollection } = AUTH_CONFIG
|
|
17
17
|
const refreshTokenTtlMs = DEFAULT_CONFIG.REFRESH_TOKEN_TTL_DAYS * 24 * 60 * 60 * 1000
|
|
18
18
|
const anonUserTtlSeconds = DEFAULT_CONFIG.ANON_USER_TTL_SECONDS
|