@flowerforce/flowerbase 1.1.2-beta.6 → 1.1.2-beta.8
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 +13 -41
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +0 -8
- package/package.json +1 -1
- package/src/features/functions/controller.ts +20 -69
- package/src/services/mongodb-atlas/index.ts +0 -10
|
@@ -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,kBAmGjC,CAAA"}
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.functionsController = void 0;
|
|
13
13
|
const bson_1 = require("bson");
|
|
14
|
+
const constants_1 = require("../../constants");
|
|
14
15
|
const services_1 = require("../../services");
|
|
15
16
|
const state_1 = require("../../state");
|
|
16
17
|
const context_1 = require("../../utils/context");
|
|
@@ -24,38 +25,8 @@ const utils_1 = require("./utils");
|
|
|
24
25
|
const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0, function* (app, { functionsList, rules }) {
|
|
25
26
|
app.addHook('preHandler', app.jwtAuthentication);
|
|
26
27
|
app.post('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
const { user
|
|
28
|
+
const { user } = req;
|
|
28
29
|
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
|
-
}
|
|
59
30
|
if ('service' in req.body) {
|
|
60
31
|
const serviceFn = services_1.services[req.body.service];
|
|
61
32
|
if (req.body.service)
|
|
@@ -100,10 +71,19 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
100
71
|
const { query, user } = req;
|
|
101
72
|
const { baas_request, stitch_request } = query;
|
|
102
73
|
const config = JSON.parse(Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'));
|
|
103
|
-
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);
|
|
104
74
|
const [{ database, collection }] = config.arguments;
|
|
105
75
|
const app = state_1.StateManager.select('app');
|
|
106
76
|
const services = state_1.StateManager.select('services');
|
|
77
|
+
const headers = {
|
|
78
|
+
'Content-Type': 'text/event-stream',
|
|
79
|
+
'Cache-Control': 'no-cache',
|
|
80
|
+
'Connection': 'keep-alive',
|
|
81
|
+
"access-control-allow-credentials": "true",
|
|
82
|
+
"access-control-allow-origin": `${constants_1.DEFAULT_CONFIG.HTTPS_SCHEMA}://${req.headers.host}`,
|
|
83
|
+
"access-control-allow-headers": "X-Stitch-Location, X-Baas-Location, Location",
|
|
84
|
+
};
|
|
85
|
+
res.raw.writeHead(200, headers);
|
|
86
|
+
res.raw.flushHeaders();
|
|
107
87
|
const changeStream = yield services['mongodb-atlas'](app, {
|
|
108
88
|
user,
|
|
109
89
|
rules
|
|
@@ -111,19 +91,11 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
111
91
|
.db(database)
|
|
112
92
|
.collection(collection)
|
|
113
93
|
.watch([], { fullDocument: 'whenAvailable' });
|
|
114
|
-
console.log("🚀 ~ functionsController ~ changeStream:", changeStream);
|
|
115
|
-
res.header('Content-Type', 'text/event-stream');
|
|
116
|
-
res.header('Cache-Control', 'no-cache');
|
|
117
|
-
res.header("content-encoding", "gzip");
|
|
118
|
-
res.header('Connection', 'keep-alive');
|
|
119
|
-
res.header("access-control-allow-credentials", true);
|
|
120
|
-
res.header("access-control-allow-origin", "*");
|
|
121
|
-
res.header("access-control-allow-headers", "X-Stitch-Location, X-Baas-Location, Location");
|
|
122
|
-
res.raw.flushHeaders();
|
|
123
94
|
changeStream.on('change', (change) => {
|
|
124
95
|
res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
|
|
125
96
|
});
|
|
126
97
|
req.raw.on('close', () => {
|
|
98
|
+
console.log("change stream closed");
|
|
127
99
|
changeStream.close();
|
|
128
100
|
});
|
|
129
101
|
}));
|
|
@@ -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;AAqpBrF,QAAA,MAAM,YAAY,EAAE,oBAmBlB,CAAA;AAEF,eAAe,YAAY,CAAA"}
|
|
@@ -292,7 +292,6 @@ 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);
|
|
296
295
|
const firstStep = formattedQuery.length ? {
|
|
297
296
|
$match: {
|
|
298
297
|
$and: formattedQuery
|
|
@@ -302,11 +301,8 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
302
301
|
firstStep,
|
|
303
302
|
...pipeline
|
|
304
303
|
].filter(Boolean);
|
|
305
|
-
console.log("🚀 ~ getOperators ~ formattedPipeline:", formattedPipeline);
|
|
306
304
|
const result = collection.watch(formattedPipeline, options);
|
|
307
|
-
console.log("🚀 ~ getOperators ~ result:", result);
|
|
308
305
|
const originalOn = result.on.bind(result);
|
|
309
|
-
console.log("🚀 ~ getOperators ~ originalOn:", originalOn);
|
|
310
306
|
/**
|
|
311
307
|
* Validates a change event against the user's roles.
|
|
312
308
|
*
|
|
@@ -335,18 +331,14 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
335
331
|
});
|
|
336
332
|
// Override the .on() method to apply validation before emitting events
|
|
337
333
|
result.on = (eventType, listener) => {
|
|
338
|
-
console.log("🚀 ~ getOperators ~ eventType:", eventType);
|
|
339
334
|
return originalOn(eventType, (change) => __awaiter(void 0, void 0, void 0, function* () {
|
|
340
|
-
console.log("🚀 ~ getOperators ~ change:", change);
|
|
341
335
|
const { status, document, updatedFieldsStatus, updatedFields } = yield isValidChange(change);
|
|
342
336
|
if (!status)
|
|
343
337
|
return;
|
|
344
338
|
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);
|
|
346
339
|
listener(filteredChange);
|
|
347
340
|
}));
|
|
348
341
|
};
|
|
349
|
-
console.log("result", result, options);
|
|
350
342
|
return result;
|
|
351
343
|
}
|
|
352
344
|
// System mode: no filtering applied
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ObjectId } from 'bson'
|
|
2
|
-
|
|
2
|
+
import { DEFAULT_CONFIG } from '../../constants'
|
|
3
3
|
import { services } from '../../services'
|
|
4
4
|
import { StateManager } from '../../state'
|
|
5
5
|
import { GenerateContext } from '../../utils/context'
|
|
@@ -19,54 +19,9 @@ export const functionsController: FunctionController = async (
|
|
|
19
19
|
) => {
|
|
20
20
|
app.addHook('preHandler', app.jwtAuthentication)
|
|
21
21
|
|
|
22
|
-
app.post<{ Body: FunctionCallDto
|
|
23
|
-
const { user
|
|
22
|
+
app.post<{ Body: FunctionCallDto }>('/call', async (req, res) => {
|
|
23
|
+
const { user } = 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
|
-
|
|
70
25
|
|
|
71
26
|
if ('service' in req.body) {
|
|
72
27
|
const serviceFn = services[req.body.service]
|
|
@@ -124,17 +79,22 @@ export const functionsController: FunctionController = async (
|
|
|
124
79
|
Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8')
|
|
125
80
|
)
|
|
126
81
|
|
|
127
|
-
console.log("🚀 ~ functionsController ~ baas_request:",
|
|
128
|
-
baas_request,
|
|
129
|
-
query,
|
|
130
|
-
Buffer.from(baas_request || stitch_request || '', 'base64'),
|
|
131
|
-
Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'),
|
|
132
|
-
config
|
|
133
|
-
)
|
|
134
82
|
const [{ database, collection }] = config.arguments
|
|
135
83
|
const app = StateManager.select('app')
|
|
136
84
|
const services = StateManager.select('services')
|
|
137
85
|
|
|
86
|
+
const headers = {
|
|
87
|
+
'Content-Type': 'text/event-stream',
|
|
88
|
+
'Cache-Control': 'no-cache',
|
|
89
|
+
'Connection': 'keep-alive',
|
|
90
|
+
"access-control-allow-credentials": "true",
|
|
91
|
+
"access-control-allow-origin": `${DEFAULT_CONFIG.HTTPS_SCHEMA}://${req.headers.host}`,
|
|
92
|
+
"access-control-allow-headers": "X-Stitch-Location, X-Baas-Location, Location",
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
res.raw.writeHead(200, headers)
|
|
96
|
+
res.raw.flushHeaders();
|
|
97
|
+
|
|
138
98
|
const changeStream = await services['mongodb-atlas'](app, {
|
|
139
99
|
user,
|
|
140
100
|
rules
|
|
@@ -142,23 +102,14 @@ export const functionsController: FunctionController = async (
|
|
|
142
102
|
.db(database)
|
|
143
103
|
.collection(collection)
|
|
144
104
|
.watch([], { fullDocument: 'whenAvailable' })
|
|
145
|
-
console.log("🚀 ~ functionsController ~ changeStream:", changeStream)
|
|
146
|
-
|
|
147
|
-
res.header('Content-Type', 'text/event-stream')
|
|
148
|
-
res.header('Cache-Control', 'no-cache')
|
|
149
|
-
res.header("content-encoding", "gzip")
|
|
150
|
-
res.header('Connection', 'keep-alive')
|
|
151
|
-
res.header("access-control-allow-credentials", true)
|
|
152
|
-
res.header("access-control-allow-origin", "*")
|
|
153
|
-
res.header("access-control-allow-headers", "X-Stitch-Location, X-Baas-Location, Location")
|
|
154
|
-
res.raw.flushHeaders()
|
|
155
105
|
|
|
156
106
|
changeStream.on('change', (change) => {
|
|
157
|
-
res.raw.write(`data: ${JSON.stringify(change)}\n\n`)
|
|
158
|
-
})
|
|
107
|
+
res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
|
|
108
|
+
});
|
|
159
109
|
|
|
160
110
|
req.raw.on('close', () => {
|
|
161
|
-
|
|
162
|
-
|
|
111
|
+
console.log("change stream closed")
|
|
112
|
+
changeStream.close();
|
|
113
|
+
});
|
|
163
114
|
})
|
|
164
115
|
}
|
|
@@ -342,7 +342,6 @@ 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)
|
|
346
345
|
|
|
347
346
|
const firstStep = formattedQuery.length ? {
|
|
348
347
|
$match: {
|
|
@@ -354,12 +353,9 @@ const getOperators: GetOperatorsFunction = (
|
|
|
354
353
|
firstStep,
|
|
355
354
|
...pipeline
|
|
356
355
|
].filter(Boolean) as Document[]
|
|
357
|
-
console.log("🚀 ~ getOperators ~ formattedPipeline:", formattedPipeline)
|
|
358
356
|
|
|
359
357
|
const result = collection.watch(formattedPipeline, options)
|
|
360
|
-
console.log("🚀 ~ getOperators ~ result:", result)
|
|
361
358
|
const originalOn = result.on.bind(result)
|
|
362
|
-
console.log("🚀 ~ getOperators ~ originalOn:", originalOn)
|
|
363
359
|
|
|
364
360
|
/**
|
|
365
361
|
* Validates a change event against the user's roles.
|
|
@@ -404,9 +400,7 @@ const getOperators: GetOperatorsFunction = (
|
|
|
404
400
|
eventType: EventKey,
|
|
405
401
|
listener: EventsDescription[EventKey]
|
|
406
402
|
) => {
|
|
407
|
-
console.log("🚀 ~ getOperators ~ eventType:", eventType)
|
|
408
403
|
return originalOn(eventType, async (change: Document) => {
|
|
409
|
-
console.log("🚀 ~ getOperators ~ change:", change)
|
|
410
404
|
const { status, document, updatedFieldsStatus, updatedFields } =
|
|
411
405
|
await isValidChange(change)
|
|
412
406
|
if (!status) return
|
|
@@ -419,14 +413,10 @@ const getOperators: GetOperatorsFunction = (
|
|
|
419
413
|
updatedFields: updatedFieldsStatus ? updatedFields : {}
|
|
420
414
|
}
|
|
421
415
|
}
|
|
422
|
-
console.log("🚀 ~ getOperators ~ filteredChange:", filteredChange)
|
|
423
416
|
|
|
424
417
|
listener(filteredChange)
|
|
425
418
|
})
|
|
426
419
|
}
|
|
427
|
-
|
|
428
|
-
console.log("result", result, options)
|
|
429
|
-
|
|
430
420
|
return result
|
|
431
421
|
}
|
|
432
422
|
|