@flowerforce/flowerbase 1.1.2-beta.4 → 1.1.2-beta.6
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/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +32 -1
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +8 -0
- package/package.json +1 -1
- package/src/features/functions/controller.ts +48 -2
- package/src/services/mongodb-atlas/index.ts +9 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAoJjC,CAAA"}
|
|
@@ -24,8 +24,38 @@ const utils_1 = require("./utils");
|
|
|
24
24
|
const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0, function* (app, { functionsList, rules }) {
|
|
25
25
|
app.addHook('preHandler', app.jwtAuthentication);
|
|
26
26
|
app.post('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
const { user } = req;
|
|
27
|
+
const { user, query } = req;
|
|
28
28
|
const { name: method, arguments: args } = req.body;
|
|
29
|
+
if (query) {
|
|
30
|
+
const { baas_request, stitch_request } = query;
|
|
31
|
+
const config = JSON.parse(Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'));
|
|
32
|
+
console.log("🚀 ~ functionsController ~ baas_request:", baas_request, query, Buffer.from(baas_request || stitch_request || '', 'base64'), Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'), config);
|
|
33
|
+
const [{ database, collection }] = config.arguments;
|
|
34
|
+
const app = state_1.StateManager.select('app');
|
|
35
|
+
const services = state_1.StateManager.select('services');
|
|
36
|
+
const changeStream = yield services['mongodb-atlas'](app, {
|
|
37
|
+
user,
|
|
38
|
+
rules
|
|
39
|
+
})
|
|
40
|
+
.db(database)
|
|
41
|
+
.collection(collection)
|
|
42
|
+
.watch([], { fullDocument: 'whenAvailable' });
|
|
43
|
+
console.log("🚀 ~ functionsController ~ changeStream:", changeStream);
|
|
44
|
+
res.header('Content-Type', 'text/event-stream');
|
|
45
|
+
res.header('Cache-Control', 'no-cache');
|
|
46
|
+
res.header("content-encoding", "gzip");
|
|
47
|
+
res.header('Connection', 'keep-alive');
|
|
48
|
+
res.header("access-control-allow-credentials", true);
|
|
49
|
+
res.header("access-control-allow-origin", "*");
|
|
50
|
+
res.header("access-control-allow-headers", "X-Stitch-Location, X-Baas-Location, Location");
|
|
51
|
+
res.raw.flushHeaders();
|
|
52
|
+
changeStream.on('change', (change) => {
|
|
53
|
+
res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
|
|
54
|
+
});
|
|
55
|
+
req.raw.on('close', () => {
|
|
56
|
+
changeStream.close();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
29
59
|
if ('service' in req.body) {
|
|
30
60
|
const serviceFn = services_1.services[req.body.service];
|
|
31
61
|
if (req.body.service)
|
|
@@ -81,6 +111,7 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
81
111
|
.db(database)
|
|
82
112
|
.collection(collection)
|
|
83
113
|
.watch([], { fullDocument: 'whenAvailable' });
|
|
114
|
+
console.log("🚀 ~ functionsController ~ changeStream:", changeStream);
|
|
84
115
|
res.header('Content-Type', 'text/event-stream');
|
|
85
116
|
res.header('Cache-Control', 'no-cache');
|
|
86
117
|
res.header("content-encoding", "gzip");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyC,oBAAoB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyC,oBAAoB,EAAE,MAAM,SAAS,CAAA;AA+pBrF,QAAA,MAAM,YAAY,EAAE,oBAmBlB,CAAA;AAEF,eAAe,YAAY,CAAA"}
|
|
@@ -292,6 +292,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
292
292
|
const { filters, roles } = rules[collName] || {};
|
|
293
293
|
// Apply access filters to initial change stream pipeline
|
|
294
294
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, {}, user);
|
|
295
|
+
console.log("🚀 ~ getOperators ~ formattedQuery:", formattedQuery);
|
|
295
296
|
const firstStep = formattedQuery.length ? {
|
|
296
297
|
$match: {
|
|
297
298
|
$and: formattedQuery
|
|
@@ -301,8 +302,11 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
301
302
|
firstStep,
|
|
302
303
|
...pipeline
|
|
303
304
|
].filter(Boolean);
|
|
305
|
+
console.log("🚀 ~ getOperators ~ formattedPipeline:", formattedPipeline);
|
|
304
306
|
const result = collection.watch(formattedPipeline, options);
|
|
307
|
+
console.log("🚀 ~ getOperators ~ result:", result);
|
|
305
308
|
const originalOn = result.on.bind(result);
|
|
309
|
+
console.log("🚀 ~ getOperators ~ originalOn:", originalOn);
|
|
306
310
|
/**
|
|
307
311
|
* Validates a change event against the user's roles.
|
|
308
312
|
*
|
|
@@ -331,14 +335,18 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
331
335
|
});
|
|
332
336
|
// Override the .on() method to apply validation before emitting events
|
|
333
337
|
result.on = (eventType, listener) => {
|
|
338
|
+
console.log("🚀 ~ getOperators ~ eventType:", eventType);
|
|
334
339
|
return originalOn(eventType, (change) => __awaiter(void 0, void 0, void 0, function* () {
|
|
340
|
+
console.log("🚀 ~ getOperators ~ change:", change);
|
|
335
341
|
const { status, document, updatedFieldsStatus, updatedFields } = yield isValidChange(change);
|
|
336
342
|
if (!status)
|
|
337
343
|
return;
|
|
338
344
|
const filteredChange = Object.assign(Object.assign({}, change), { fullDocument: document, updateDescription: Object.assign(Object.assign({}, change.updateDescription), { updatedFields: updatedFieldsStatus ? updatedFields : {} }) });
|
|
345
|
+
console.log("🚀 ~ getOperators ~ filteredChange:", filteredChange);
|
|
339
346
|
listener(filteredChange);
|
|
340
347
|
}));
|
|
341
348
|
};
|
|
349
|
+
console.log("result", result, options);
|
|
342
350
|
return result;
|
|
343
351
|
}
|
|
344
352
|
// System mode: no filtering applied
|
package/package.json
CHANGED
|
@@ -19,9 +19,54 @@ export const functionsController: FunctionController = async (
|
|
|
19
19
|
) => {
|
|
20
20
|
app.addHook('preHandler', app.jwtAuthentication)
|
|
21
21
|
|
|
22
|
-
app.post<{ Body: FunctionCallDto }>('/call', async (req, res) => {
|
|
23
|
-
const { user } = req
|
|
22
|
+
app.post<{ Body: FunctionCallDto, Querystring?: FunctionCallBase64Dto }>('/call', async (req, res) => {
|
|
23
|
+
const { user, query } = req
|
|
24
24
|
const { name: method, arguments: args } = req.body
|
|
25
|
+
if (query) {
|
|
26
|
+
const { baas_request, stitch_request } = query
|
|
27
|
+
|
|
28
|
+
const config: Base64Function = JSON.parse(
|
|
29
|
+
Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8')
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
console.log("🚀 ~ functionsController ~ baas_request:",
|
|
33
|
+
baas_request,
|
|
34
|
+
query,
|
|
35
|
+
Buffer.from(baas_request || stitch_request || '', 'base64'),
|
|
36
|
+
Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'),
|
|
37
|
+
config
|
|
38
|
+
)
|
|
39
|
+
const [{ database, collection }] = config.arguments
|
|
40
|
+
const app = StateManager.select('app')
|
|
41
|
+
const services = StateManager.select('services')
|
|
42
|
+
|
|
43
|
+
const changeStream = await services['mongodb-atlas'](app, {
|
|
44
|
+
user,
|
|
45
|
+
rules
|
|
46
|
+
})
|
|
47
|
+
.db(database)
|
|
48
|
+
.collection(collection)
|
|
49
|
+
.watch([], { fullDocument: 'whenAvailable' })
|
|
50
|
+
console.log("🚀 ~ functionsController ~ changeStream:", changeStream)
|
|
51
|
+
|
|
52
|
+
res.header('Content-Type', 'text/event-stream')
|
|
53
|
+
res.header('Cache-Control', 'no-cache')
|
|
54
|
+
res.header("content-encoding", "gzip")
|
|
55
|
+
res.header('Connection', 'keep-alive')
|
|
56
|
+
res.header("access-control-allow-credentials", true)
|
|
57
|
+
res.header("access-control-allow-origin", "*")
|
|
58
|
+
res.header("access-control-allow-headers", "X-Stitch-Location, X-Baas-Location, Location")
|
|
59
|
+
res.raw.flushHeaders()
|
|
60
|
+
|
|
61
|
+
changeStream.on('change', (change) => {
|
|
62
|
+
res.raw.write(`data: ${JSON.stringify(change)}\n\n`)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
req.raw.on('close', () => {
|
|
66
|
+
changeStream.close()
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
25
70
|
|
|
26
71
|
if ('service' in req.body) {
|
|
27
72
|
const serviceFn = services[req.body.service]
|
|
@@ -97,6 +142,7 @@ export const functionsController: FunctionController = async (
|
|
|
97
142
|
.db(database)
|
|
98
143
|
.collection(collection)
|
|
99
144
|
.watch([], { fullDocument: 'whenAvailable' })
|
|
145
|
+
console.log("🚀 ~ functionsController ~ changeStream:", changeStream)
|
|
100
146
|
|
|
101
147
|
res.header('Content-Type', 'text/event-stream')
|
|
102
148
|
res.header('Cache-Control', 'no-cache')
|
|
@@ -342,6 +342,7 @@ const getOperators: GetOperatorsFunction = (
|
|
|
342
342
|
|
|
343
343
|
// Apply access filters to initial change stream pipeline
|
|
344
344
|
const formattedQuery = getFormattedQuery(filters, {}, user)
|
|
345
|
+
console.log("🚀 ~ getOperators ~ formattedQuery:", formattedQuery)
|
|
345
346
|
|
|
346
347
|
const firstStep = formattedQuery.length ? {
|
|
347
348
|
$match: {
|
|
@@ -353,9 +354,12 @@ const getOperators: GetOperatorsFunction = (
|
|
|
353
354
|
firstStep,
|
|
354
355
|
...pipeline
|
|
355
356
|
].filter(Boolean) as Document[]
|
|
357
|
+
console.log("🚀 ~ getOperators ~ formattedPipeline:", formattedPipeline)
|
|
356
358
|
|
|
357
359
|
const result = collection.watch(formattedPipeline, options)
|
|
360
|
+
console.log("🚀 ~ getOperators ~ result:", result)
|
|
358
361
|
const originalOn = result.on.bind(result)
|
|
362
|
+
console.log("🚀 ~ getOperators ~ originalOn:", originalOn)
|
|
359
363
|
|
|
360
364
|
/**
|
|
361
365
|
* Validates a change event against the user's roles.
|
|
@@ -400,7 +404,9 @@ const getOperators: GetOperatorsFunction = (
|
|
|
400
404
|
eventType: EventKey,
|
|
401
405
|
listener: EventsDescription[EventKey]
|
|
402
406
|
) => {
|
|
407
|
+
console.log("🚀 ~ getOperators ~ eventType:", eventType)
|
|
403
408
|
return originalOn(eventType, async (change: Document) => {
|
|
409
|
+
console.log("🚀 ~ getOperators ~ change:", change)
|
|
404
410
|
const { status, document, updatedFieldsStatus, updatedFields } =
|
|
405
411
|
await isValidChange(change)
|
|
406
412
|
if (!status) return
|
|
@@ -413,11 +419,14 @@ const getOperators: GetOperatorsFunction = (
|
|
|
413
419
|
updatedFields: updatedFieldsStatus ? updatedFields : {}
|
|
414
420
|
}
|
|
415
421
|
}
|
|
422
|
+
console.log("🚀 ~ getOperators ~ filteredChange:", filteredChange)
|
|
416
423
|
|
|
417
424
|
listener(filteredChange)
|
|
418
425
|
})
|
|
419
426
|
}
|
|
420
427
|
|
|
428
|
+
console.log("result", result, options)
|
|
429
|
+
|
|
421
430
|
return result
|
|
422
431
|
}
|
|
423
432
|
|