@flowerforce/flowerbase 1.7.5-beta.6 → 1.7.5
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/CHANGELOG.md +21 -0
- package/dist/auth/providers/custom-function/controller.d.ts.map +1 -1
- package/dist/auth/providers/custom-function/controller.js +6 -31
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +28 -36
- package/dist/services/api/index.d.ts +0 -4
- package/dist/services/api/index.d.ts.map +1 -1
- package/dist/services/api/utils.d.ts +0 -1
- package/dist/services/api/utils.d.ts.map +1 -1
- package/dist/services/index.d.ts +0 -4
- package/dist/services/index.d.ts.map +1 -1
- package/dist/utils/context/helpers.d.ts +0 -12
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auth/providers/custom-function/controller.ts +8 -35
- package/src/features/triggers/utils.ts +28 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## 1.7.5 (2026-03-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🩹 Fixes
|
|
5
|
+
|
|
6
|
+
- _id in user_data ([#21](https://github.com/flowerforce/flowerbase/pull/21))
|
|
7
|
+
|
|
8
|
+
- refresh token ([#25](https://github.com/flowerforce/flowerbase/pull/25))
|
|
9
|
+
|
|
10
|
+
- trigger disable ([61b6676](https://github.com/flowerforce/flowerbase/commit/61b6676))
|
|
11
|
+
|
|
12
|
+
- cursor functions ([da6d590](https://github.com/flowerforce/flowerbase/commit/da6d590))
|
|
13
|
+
|
|
14
|
+
- WIP roles ([35e93b4](https://github.com/flowerforce/flowerbase/commit/35e93b4))
|
|
15
|
+
|
|
16
|
+
- roles ([f7a3b13](https://github.com/flowerforce/flowerbase/commit/f7a3b13))
|
|
17
|
+
|
|
18
|
+
- roles read & write ([45ded56](https://github.com/flowerforce/flowerbase/commit/45ded56))
|
|
19
|
+
|
|
20
|
+
- **monitoring:** keep function editor line numbers synced while scrolling ([#30](https://github.com/flowerforce/flowerbase/pull/30))
|
|
21
|
+
|
|
1
22
|
## 1.7.4 (2026-02-19)
|
|
2
23
|
|
|
3
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/custom-function/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/custom-function/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AASzC;;;;GAIG;AACH,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,eAAe,iBAiHlE"}
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.customFunctionController = customFunctionController;
|
|
13
|
-
const mongodb_1 = require("mongodb");
|
|
14
13
|
const constants_1 = require("../../../constants");
|
|
15
14
|
const state_1 = require("../../../state");
|
|
16
15
|
const context_1 = require("../../../utils/context");
|
|
@@ -37,10 +36,7 @@ function customFunctionController(app) {
|
|
|
37
36
|
* @returns {Promise<Object>} A promise resolving with access and refresh tokens.
|
|
38
37
|
*/
|
|
39
38
|
app.post(utils_1.AUTH_ENDPOINTS.LOGIN, {
|
|
40
|
-
schema: schema_1.LOGIN_SCHEMA
|
|
41
|
-
errorHandler: (_error, _request, reply) => {
|
|
42
|
-
reply.code(500).send({ message: 'Internal Server Error' });
|
|
43
|
-
}
|
|
39
|
+
schema: schema_1.LOGIN_SCHEMA
|
|
44
40
|
}, function (req, reply) {
|
|
45
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
42
|
var _a, _b;
|
|
@@ -79,29 +75,10 @@ function customFunctionController(app) {
|
|
|
79
75
|
reply.code(401).send({ message: 'Unauthorized' });
|
|
80
76
|
return;
|
|
81
77
|
}
|
|
82
|
-
const
|
|
83
|
-
let authUser = yield db.collection(authCollection).findOne({ email });
|
|
78
|
+
const authUser = yield db.collection(authCollection).findOne({ email: authResult.id });
|
|
84
79
|
if (!authUser) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
_id: authUserId,
|
|
88
|
-
email,
|
|
89
|
-
status: 'confirmed',
|
|
90
|
-
createdAt: new Date(),
|
|
91
|
-
custom_data: {},
|
|
92
|
-
identities: [
|
|
93
|
-
{
|
|
94
|
-
id: authResult.id.toString(),
|
|
95
|
-
provider_id: authResult.id.toString(),
|
|
96
|
-
provider_type: 'custom-function',
|
|
97
|
-
provider_data: { email }
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
});
|
|
101
|
-
authUser = {
|
|
102
|
-
_id: authUserId,
|
|
103
|
-
email
|
|
104
|
-
};
|
|
80
|
+
reply.code(401).send({ message: 'Unauthorized' });
|
|
81
|
+
return;
|
|
105
82
|
}
|
|
106
83
|
const user = user_id_field && userCollection
|
|
107
84
|
? yield db
|
|
@@ -122,14 +99,12 @@ function customFunctionController(app) {
|
|
|
122
99
|
expiresAt: new Date(Date.now() + refreshTokenTtlMs),
|
|
123
100
|
revokedAt: null
|
|
124
101
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
access_token: accessToken,
|
|
102
|
+
return {
|
|
103
|
+
access_token: this.createAccessToken(currentUserData),
|
|
128
104
|
refresh_token: refreshToken,
|
|
129
105
|
device_id: '',
|
|
130
106
|
user_id: authUser._id.toString()
|
|
131
107
|
};
|
|
132
|
-
reply.code(200).send(responsePayload);
|
|
133
108
|
});
|
|
134
109
|
});
|
|
135
110
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAA;AA0E9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAA;AA0E9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;AA+mBD,eAAO,MAAM,gBAAgB;kHAxlB1B,aAAa;iHAggBb,aAAa;uHA/Yb,aAAa;CA2ef,CAAA"}
|
|
@@ -252,14 +252,6 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
252
252
|
if (shouldIgnoreStreamError(error))
|
|
253
253
|
return;
|
|
254
254
|
console.error('Authentication trigger change stream error', error);
|
|
255
|
-
emitTriggerEvent({
|
|
256
|
-
status: 'error',
|
|
257
|
-
triggerName,
|
|
258
|
-
triggerType,
|
|
259
|
-
functionName,
|
|
260
|
-
meta: Object.assign(Object.assign({}, baseMeta), { event: 'CHANGE_STREAM' }),
|
|
261
|
-
error
|
|
262
|
-
});
|
|
263
255
|
});
|
|
264
256
|
changeStream.on('change', function (change) {
|
|
265
257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -329,6 +321,13 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
329
321
|
updateDescription
|
|
330
322
|
};
|
|
331
323
|
try {
|
|
324
|
+
emitTriggerEvent({
|
|
325
|
+
status: 'fired',
|
|
326
|
+
triggerName,
|
|
327
|
+
triggerType,
|
|
328
|
+
functionName,
|
|
329
|
+
meta: Object.assign(Object.assign({}, baseMeta), { event: 'LOGOUT' })
|
|
330
|
+
});
|
|
332
331
|
yield (0, context_1.GenerateContext)({
|
|
333
332
|
args: [Object.assign({ user: userData }, op)],
|
|
334
333
|
app,
|
|
@@ -340,13 +339,6 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
340
339
|
services,
|
|
341
340
|
runAsSystem: true
|
|
342
341
|
});
|
|
343
|
-
emitTriggerEvent({
|
|
344
|
-
status: 'fired',
|
|
345
|
-
triggerName,
|
|
346
|
-
triggerType,
|
|
347
|
-
functionName,
|
|
348
|
-
meta: Object.assign(Object.assign({}, baseMeta), { event: 'LOGOUT' })
|
|
349
|
-
});
|
|
350
342
|
}
|
|
351
343
|
catch (error) {
|
|
352
344
|
emitTriggerEvent({
|
|
@@ -381,6 +373,13 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
381
373
|
updateDescription
|
|
382
374
|
};
|
|
383
375
|
try {
|
|
376
|
+
emitTriggerEvent({
|
|
377
|
+
status: 'fired',
|
|
378
|
+
triggerName,
|
|
379
|
+
triggerType,
|
|
380
|
+
functionName,
|
|
381
|
+
meta: Object.assign(Object.assign({}, baseMeta), { event: 'DELETE' })
|
|
382
|
+
});
|
|
384
383
|
yield (0, context_1.GenerateContext)({
|
|
385
384
|
args: isAutoTrigger ? [userData] : [Object.assign({ user: userData }, op)],
|
|
386
385
|
app,
|
|
@@ -392,13 +391,6 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
392
391
|
services,
|
|
393
392
|
runAsSystem: true
|
|
394
393
|
});
|
|
395
|
-
emitTriggerEvent({
|
|
396
|
-
status: 'fired',
|
|
397
|
-
triggerName,
|
|
398
|
-
triggerType,
|
|
399
|
-
functionName,
|
|
400
|
-
meta: Object.assign(Object.assign({}, baseMeta), { event: 'DELETE' })
|
|
401
|
-
});
|
|
402
394
|
}
|
|
403
395
|
catch (error) {
|
|
404
396
|
emitTriggerEvent({
|
|
@@ -435,6 +427,13 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
435
427
|
updateDescription
|
|
436
428
|
};
|
|
437
429
|
try {
|
|
430
|
+
emitTriggerEvent({
|
|
431
|
+
status: 'fired',
|
|
432
|
+
triggerName,
|
|
433
|
+
triggerType,
|
|
434
|
+
functionName,
|
|
435
|
+
meta: Object.assign(Object.assign({}, baseMeta), { event: 'UPDATE' })
|
|
436
|
+
});
|
|
438
437
|
yield (0, context_1.GenerateContext)({
|
|
439
438
|
args: isAutoTrigger ? [userData] : [Object.assign({ user: userData }, op)],
|
|
440
439
|
app,
|
|
@@ -446,13 +445,6 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
446
445
|
services,
|
|
447
446
|
runAsSystem: true
|
|
448
447
|
});
|
|
449
|
-
emitTriggerEvent({
|
|
450
|
-
status: 'fired',
|
|
451
|
-
triggerName,
|
|
452
|
-
triggerType,
|
|
453
|
-
functionName,
|
|
454
|
-
meta: Object.assign(Object.assign({}, baseMeta), { event: 'UPDATE' })
|
|
455
|
-
});
|
|
456
448
|
}
|
|
457
449
|
catch (error) {
|
|
458
450
|
emitTriggerEvent({
|
|
@@ -526,6 +518,13 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
526
518
|
updateDescription
|
|
527
519
|
};
|
|
528
520
|
try {
|
|
521
|
+
emitTriggerEvent({
|
|
522
|
+
status: 'fired',
|
|
523
|
+
triggerName,
|
|
524
|
+
triggerType,
|
|
525
|
+
functionName,
|
|
526
|
+
meta: Object.assign(Object.assign({}, baseMeta), { event: 'CREATE' })
|
|
527
|
+
});
|
|
529
528
|
yield (0, context_1.GenerateContext)({
|
|
530
529
|
args: isAutoTrigger ? [userData] : [Object.assign({ user: userData }, op)],
|
|
531
530
|
app,
|
|
@@ -537,13 +536,6 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
|
|
|
537
536
|
services,
|
|
538
537
|
runAsSystem: true
|
|
539
538
|
});
|
|
540
|
-
emitTriggerEvent({
|
|
541
|
-
status: 'fired',
|
|
542
|
-
triggerName,
|
|
543
|
-
triggerType,
|
|
544
|
-
functionName,
|
|
545
|
-
meta: Object.assign(Object.assign({}, baseMeta), { event: 'CREATE' })
|
|
546
|
-
});
|
|
547
539
|
}
|
|
548
540
|
catch (error) {
|
|
549
541
|
emitTriggerEvent({
|
|
@@ -30,7 +30,6 @@ declare const Api: (_app?: unknown, opt?: {
|
|
|
30
30
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
31
31
|
};
|
|
32
32
|
statusCode: number;
|
|
33
|
-
statusText: string;
|
|
34
33
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
35
34
|
trailers: Record<string, string>;
|
|
36
35
|
opaque: T;
|
|
@@ -59,7 +58,6 @@ declare const Api: (_app?: unknown, opt?: {
|
|
|
59
58
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
60
59
|
};
|
|
61
60
|
statusCode: number;
|
|
62
|
-
statusText: string;
|
|
63
61
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
64
62
|
trailers: Record<string, string>;
|
|
65
63
|
opaque: T;
|
|
@@ -88,7 +86,6 @@ declare const Api: (_app?: unknown, opt?: {
|
|
|
88
86
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
89
87
|
};
|
|
90
88
|
statusCode: number;
|
|
91
|
-
statusText: string;
|
|
92
89
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
93
90
|
trailers: Record<string, string>;
|
|
94
91
|
opaque: T;
|
|
@@ -117,7 +114,6 @@ declare const Api: (_app?: unknown, opt?: {
|
|
|
117
114
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
118
115
|
};
|
|
119
116
|
statusCode: number;
|
|
120
|
-
statusText: string;
|
|
121
117
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
122
118
|
trailers: Record<string, string>;
|
|
123
119
|
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,7 +29,6 @@ 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;
|
|
33
32
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
34
33
|
trailers: Record<string, string>;
|
|
35
34
|
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,7 +27,6 @@ export declare const services: {
|
|
|
27
27
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
28
28
|
};
|
|
29
29
|
statusCode: number;
|
|
30
|
-
statusText: string;
|
|
31
30
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
32
31
|
trailers: Record<string, string>;
|
|
33
32
|
opaque: T;
|
|
@@ -56,7 +55,6 @@ export declare const services: {
|
|
|
56
55
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
57
56
|
};
|
|
58
57
|
statusCode: number;
|
|
59
|
-
statusText: string;
|
|
60
58
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
61
59
|
trailers: Record<string, string>;
|
|
62
60
|
opaque: T;
|
|
@@ -85,7 +83,6 @@ export declare const services: {
|
|
|
85
83
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
86
84
|
};
|
|
87
85
|
statusCode: number;
|
|
88
|
-
statusText: string;
|
|
89
86
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
90
87
|
trailers: Record<string, string>;
|
|
91
88
|
opaque: T;
|
|
@@ -114,7 +111,6 @@ export declare const services: {
|
|
|
114
111
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
115
112
|
};
|
|
116
113
|
statusCode: number;
|
|
117
|
-
statusText: string;
|
|
118
114
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
119
115
|
trailers: Record<string, string>;
|
|
120
116
|
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"}
|
|
@@ -82,7 +82,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
82
82
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
83
83
|
};
|
|
84
84
|
statusCode: number;
|
|
85
|
-
statusText: string;
|
|
86
85
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
87
86
|
trailers: Record<string, string>;
|
|
88
87
|
opaque: T;
|
|
@@ -111,7 +110,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
111
110
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
112
111
|
};
|
|
113
112
|
statusCode: number;
|
|
114
|
-
statusText: string;
|
|
115
113
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
116
114
|
trailers: Record<string, string>;
|
|
117
115
|
opaque: T;
|
|
@@ -140,7 +138,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
140
138
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
141
139
|
};
|
|
142
140
|
statusCode: number;
|
|
143
|
-
statusText: string;
|
|
144
141
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
145
142
|
trailers: Record<string, string>;
|
|
146
143
|
opaque: T;
|
|
@@ -169,7 +166,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
169
166
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
170
167
|
};
|
|
171
168
|
statusCode: number;
|
|
172
|
-
statusText: string;
|
|
173
169
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
174
170
|
trailers: Record<string, string>;
|
|
175
171
|
opaque: T;
|
|
@@ -234,7 +230,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
234
230
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
235
231
|
};
|
|
236
232
|
statusCode: number;
|
|
237
|
-
statusText: string;
|
|
238
233
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
239
234
|
trailers: Record<string, string>;
|
|
240
235
|
opaque: T;
|
|
@@ -263,7 +258,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
263
258
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
264
259
|
};
|
|
265
260
|
statusCode: number;
|
|
266
|
-
statusText: string;
|
|
267
261
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
268
262
|
trailers: Record<string, string>;
|
|
269
263
|
opaque: T;
|
|
@@ -292,7 +286,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
292
286
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
293
287
|
};
|
|
294
288
|
statusCode: number;
|
|
295
|
-
statusText: string;
|
|
296
289
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
297
290
|
trailers: Record<string, string>;
|
|
298
291
|
opaque: T;
|
|
@@ -321,7 +314,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
321
314
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
322
315
|
};
|
|
323
316
|
statusCode: number;
|
|
324
|
-
statusText: string;
|
|
325
317
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
326
318
|
trailers: Record<string, string>;
|
|
327
319
|
opaque: T;
|
|
@@ -385,7 +377,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
385
377
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
386
378
|
};
|
|
387
379
|
statusCode: number;
|
|
388
|
-
statusText: string;
|
|
389
380
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
390
381
|
trailers: Record<string, string>;
|
|
391
382
|
opaque: T;
|
|
@@ -414,7 +405,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
414
405
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
415
406
|
};
|
|
416
407
|
statusCode: number;
|
|
417
|
-
statusText: string;
|
|
418
408
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
419
409
|
trailers: Record<string, string>;
|
|
420
410
|
opaque: T;
|
|
@@ -443,7 +433,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
443
433
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
444
434
|
};
|
|
445
435
|
statusCode: number;
|
|
446
|
-
statusText: string;
|
|
447
436
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
448
437
|
trailers: Record<string, string>;
|
|
449
438
|
opaque: T;
|
|
@@ -472,7 +461,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
472
461
|
bytes: () => Uint8Array<ArrayBuffer>;
|
|
473
462
|
};
|
|
474
463
|
statusCode: number;
|
|
475
|
-
statusText: string;
|
|
476
464
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
477
465
|
trailers: Record<string, string>;
|
|
478
466
|
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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAsGT,CAAC;iCAAa,CAAC;;;;;;;;;;;;;;;;;;;kCAtGP,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAsGT,CAAC;6BAAa,CAAC;;;;;;;;;;;;;;;;;;kCAtGP,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAsGT,CAAC;6BAAa,CAAC;;;;;;;;;;;;;;;4BAyEF,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAiBrE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify'
|
|
2
|
-
import { ObjectId } from 'mongodb'
|
|
3
2
|
import { AUTH_CONFIG, DB_NAME, DEFAULT_CONFIG } from '../../../constants'
|
|
4
3
|
import { StateManager } from '../../../state'
|
|
5
4
|
import { GenerateContext } from '../../../utils/context'
|
|
@@ -31,10 +30,7 @@ export async function customFunctionController(app: FastifyInstance) {
|
|
|
31
30
|
app.post<LoginDto>(
|
|
32
31
|
AUTH_ENDPOINTS.LOGIN,
|
|
33
32
|
{
|
|
34
|
-
schema: LOGIN_SCHEMA
|
|
35
|
-
errorHandler: (_error, _request, reply) => {
|
|
36
|
-
reply.code(500).send({ message: 'Internal Server Error' })
|
|
37
|
-
}
|
|
33
|
+
schema: LOGIN_SCHEMA
|
|
38
34
|
},
|
|
39
35
|
async function (req, reply) {
|
|
40
36
|
const customFunctionProvider = AUTH_CONFIG.authProviders?.['custom-function']
|
|
@@ -58,7 +54,7 @@ export async function customFunctionController(app: FastifyInstance) {
|
|
|
58
54
|
id
|
|
59
55
|
} = req
|
|
60
56
|
|
|
61
|
-
type CustomFunctionAuthResult = { id?: string
|
|
57
|
+
type CustomFunctionAuthResult = { id?: string }
|
|
62
58
|
const authResult = await GenerateContext({
|
|
63
59
|
args: [
|
|
64
60
|
req.body
|
|
@@ -81,35 +77,16 @@ export async function customFunctionController(app: FastifyInstance) {
|
|
|
81
77
|
}
|
|
82
78
|
}) as CustomFunctionAuthResult
|
|
83
79
|
|
|
80
|
+
|
|
84
81
|
if (!authResult.id) {
|
|
85
82
|
reply.code(401).send({ message: 'Unauthorized' })
|
|
86
83
|
return
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
const
|
|
90
|
-
let authUser = await db.collection(authCollection!).findOne({ email })
|
|
91
|
-
|
|
86
|
+
const authUser = await db.collection(authCollection!).findOne({ email: authResult.id })
|
|
92
87
|
if (!authUser) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_id: authUserId,
|
|
96
|
-
email,
|
|
97
|
-
status: 'confirmed',
|
|
98
|
-
createdAt: new Date(),
|
|
99
|
-
custom_data: {},
|
|
100
|
-
identities: [
|
|
101
|
-
{
|
|
102
|
-
id: authResult.id.toString(),
|
|
103
|
-
provider_id: authResult.id.toString(),
|
|
104
|
-
provider_type: 'custom-function',
|
|
105
|
-
provider_data: { email }
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
})
|
|
109
|
-
authUser = {
|
|
110
|
-
_id: authUserId,
|
|
111
|
-
email
|
|
112
|
-
}
|
|
88
|
+
reply.code(401).send({ message: 'Unauthorized' })
|
|
89
|
+
return
|
|
113
90
|
}
|
|
114
91
|
|
|
115
92
|
const user =
|
|
@@ -130,7 +107,6 @@ export async function customFunctionController(app: FastifyInstance) {
|
|
|
130
107
|
...(user || {})
|
|
131
108
|
}
|
|
132
109
|
}
|
|
133
|
-
|
|
134
110
|
const refreshToken = this.createRefreshToken(currentUserData)
|
|
135
111
|
const refreshTokenHash = hashToken(refreshToken)
|
|
136
112
|
await db.collection(refreshTokensCollection).insertOne({
|
|
@@ -140,15 +116,12 @@ export async function customFunctionController(app: FastifyInstance) {
|
|
|
140
116
|
expiresAt: new Date(Date.now() + refreshTokenTtlMs),
|
|
141
117
|
revokedAt: null
|
|
142
118
|
})
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const responsePayload = {
|
|
146
|
-
access_token: accessToken,
|
|
119
|
+
return {
|
|
120
|
+
access_token: this.createAccessToken(currentUserData),
|
|
147
121
|
refresh_token: refreshToken,
|
|
148
122
|
device_id: '',
|
|
149
123
|
user_id: authUser._id.toString()
|
|
150
124
|
}
|
|
151
|
-
reply.code(200).send(responsePayload)
|
|
152
125
|
}
|
|
153
126
|
)
|
|
154
127
|
|
|
@@ -277,17 +277,6 @@ const handleAuthenticationTrigger = async ({
|
|
|
277
277
|
changeStream.on('error', (error) => {
|
|
278
278
|
if (shouldIgnoreStreamError(error)) return
|
|
279
279
|
console.error('Authentication trigger change stream error', error)
|
|
280
|
-
emitTriggerEvent({
|
|
281
|
-
status: 'error',
|
|
282
|
-
triggerName,
|
|
283
|
-
triggerType,
|
|
284
|
-
functionName,
|
|
285
|
-
meta: {
|
|
286
|
-
...baseMeta,
|
|
287
|
-
event: 'CHANGE_STREAM'
|
|
288
|
-
},
|
|
289
|
-
error
|
|
290
|
-
})
|
|
291
280
|
})
|
|
292
281
|
changeStream.on('change', async function (change) {
|
|
293
282
|
const operationType = change['operationType' as keyof typeof change] as
|
|
@@ -376,6 +365,13 @@ const handleAuthenticationTrigger = async ({
|
|
|
376
365
|
updateDescription
|
|
377
366
|
}
|
|
378
367
|
try {
|
|
368
|
+
emitTriggerEvent({
|
|
369
|
+
status: 'fired',
|
|
370
|
+
triggerName,
|
|
371
|
+
triggerType,
|
|
372
|
+
functionName,
|
|
373
|
+
meta: { ...baseMeta, event: 'LOGOUT' }
|
|
374
|
+
})
|
|
379
375
|
await GenerateContext({
|
|
380
376
|
args: [{ user: userData, ...op }],
|
|
381
377
|
app,
|
|
@@ -387,13 +383,6 @@ const handleAuthenticationTrigger = async ({
|
|
|
387
383
|
services,
|
|
388
384
|
runAsSystem: true
|
|
389
385
|
})
|
|
390
|
-
emitTriggerEvent({
|
|
391
|
-
status: 'fired',
|
|
392
|
-
triggerName,
|
|
393
|
-
triggerType,
|
|
394
|
-
functionName,
|
|
395
|
-
meta: { ...baseMeta, event: 'LOGOUT' }
|
|
396
|
-
})
|
|
397
386
|
} catch (error) {
|
|
398
387
|
emitTriggerEvent({
|
|
399
388
|
status: 'error',
|
|
@@ -428,6 +417,13 @@ const handleAuthenticationTrigger = async ({
|
|
|
428
417
|
updateDescription
|
|
429
418
|
}
|
|
430
419
|
try {
|
|
420
|
+
emitTriggerEvent({
|
|
421
|
+
status: 'fired',
|
|
422
|
+
triggerName,
|
|
423
|
+
triggerType,
|
|
424
|
+
functionName,
|
|
425
|
+
meta: { ...baseMeta, event: 'DELETE' }
|
|
426
|
+
})
|
|
431
427
|
await GenerateContext({
|
|
432
428
|
args: isAutoTrigger ? [userData] : [{ user: userData, ...op }],
|
|
433
429
|
app,
|
|
@@ -439,13 +435,6 @@ const handleAuthenticationTrigger = async ({
|
|
|
439
435
|
services,
|
|
440
436
|
runAsSystem: true
|
|
441
437
|
})
|
|
442
|
-
emitTriggerEvent({
|
|
443
|
-
status: 'fired',
|
|
444
|
-
triggerName,
|
|
445
|
-
triggerType,
|
|
446
|
-
functionName,
|
|
447
|
-
meta: { ...baseMeta, event: 'DELETE' }
|
|
448
|
-
})
|
|
449
438
|
} catch (error) {
|
|
450
439
|
emitTriggerEvent({
|
|
451
440
|
status: 'error',
|
|
@@ -482,6 +471,13 @@ const handleAuthenticationTrigger = async ({
|
|
|
482
471
|
updateDescription
|
|
483
472
|
}
|
|
484
473
|
try {
|
|
474
|
+
emitTriggerEvent({
|
|
475
|
+
status: 'fired',
|
|
476
|
+
triggerName,
|
|
477
|
+
triggerType,
|
|
478
|
+
functionName,
|
|
479
|
+
meta: { ...baseMeta, event: 'UPDATE' }
|
|
480
|
+
})
|
|
485
481
|
await GenerateContext({
|
|
486
482
|
args: isAutoTrigger ? [userData] : [{ user: userData, ...op }],
|
|
487
483
|
app,
|
|
@@ -493,13 +489,6 @@ const handleAuthenticationTrigger = async ({
|
|
|
493
489
|
services,
|
|
494
490
|
runAsSystem: true
|
|
495
491
|
})
|
|
496
|
-
emitTriggerEvent({
|
|
497
|
-
status: 'fired',
|
|
498
|
-
triggerName,
|
|
499
|
-
triggerType,
|
|
500
|
-
functionName,
|
|
501
|
-
meta: { ...baseMeta, event: 'UPDATE' }
|
|
502
|
-
})
|
|
503
492
|
} catch (error) {
|
|
504
493
|
emitTriggerEvent({
|
|
505
494
|
status: 'error',
|
|
@@ -586,6 +575,13 @@ const handleAuthenticationTrigger = async ({
|
|
|
586
575
|
}
|
|
587
576
|
|
|
588
577
|
try {
|
|
578
|
+
emitTriggerEvent({
|
|
579
|
+
status: 'fired',
|
|
580
|
+
triggerName,
|
|
581
|
+
triggerType,
|
|
582
|
+
functionName,
|
|
583
|
+
meta: { ...baseMeta, event: 'CREATE' }
|
|
584
|
+
})
|
|
589
585
|
await GenerateContext({
|
|
590
586
|
args: isAutoTrigger ? [userData] : [{ user: userData, ...op }],
|
|
591
587
|
app,
|
|
@@ -597,13 +593,6 @@ const handleAuthenticationTrigger = async ({
|
|
|
597
593
|
services,
|
|
598
594
|
runAsSystem: true
|
|
599
595
|
})
|
|
600
|
-
emitTriggerEvent({
|
|
601
|
-
status: 'fired',
|
|
602
|
-
triggerName,
|
|
603
|
-
triggerType,
|
|
604
|
-
functionName,
|
|
605
|
-
meta: { ...baseMeta, event: 'CREATE' }
|
|
606
|
-
})
|
|
607
596
|
} catch (error) {
|
|
608
597
|
emitTriggerEvent({
|
|
609
598
|
status: 'error',
|