@flowerforce/flowerbase 1.1.2-beta.5 → 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.
|
@@ -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");
|
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')
|