@flowerforce/flowerbase 1.1.2-beta.8 → 1.2.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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 1.2.0 (2025-10-14)
2
+
3
+
4
+ ### 🚀 Features
5
+
6
+ - add users exporter ([9e40926](https://github.com/flowerforce/flowerbase/commit/9e40926))
7
+
8
+
9
+ ### 🩹 Fixes
10
+
11
+ - isClient as last parameter ([7b0aa7b](https://github.com/flowerforce/flowerbase/commit/7b0aa7b))
12
+
1
13
  ## 1.1.1 (2025-09-12)
2
14
 
3
15
 
@@ -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,kBAmGjC,CAAA"}
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAKhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAoHjC,CAAA"}
@@ -11,7 +11,6 @@ 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");
15
14
  const services_1 = require("../../services");
16
15
  const state_1 = require("../../state");
17
16
  const context_1 = require("../../utils/context");
@@ -24,6 +23,7 @@ const utils_1 = require("./utils");
24
23
  */
25
24
  const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0, function* (app, { functionsList, rules }) {
26
25
  app.addHook('preHandler', app.jwtAuthentication);
26
+ const streams = {};
27
27
  app.post('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
28
28
  const { user } = req;
29
29
  const { name: method, arguments: args } = req.body;
@@ -79,25 +79,37 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
79
79
  'Cache-Control': 'no-cache',
80
80
  'Connection': 'keep-alive',
81
81
  "access-control-allow-credentials": "true",
82
- "access-control-allow-origin": `${constants_1.DEFAULT_CONFIG.HTTPS_SCHEMA}://${req.headers.host}`,
82
+ "access-control-allow-origin": '*',
83
83
  "access-control-allow-headers": "X-Stitch-Location, X-Baas-Location, Location",
84
84
  };
85
85
  res.raw.writeHead(200, headers);
86
86
  res.raw.flushHeaders();
87
- const changeStream = yield services['mongodb-atlas'](app, {
87
+ const requestKey = baas_request || stitch_request;
88
+ if (!requestKey)
89
+ return;
90
+ const changeStream = streams[requestKey];
91
+ if (changeStream) {
92
+ changeStream.on('change', (change) => {
93
+ res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
94
+ });
95
+ req.raw.on('close', () => {
96
+ var _a;
97
+ console.log("change stream closed");
98
+ (_a = changeStream === null || changeStream === void 0 ? void 0 : changeStream.close) === null || _a === void 0 ? void 0 : _a.call(changeStream);
99
+ delete streams[requestKey];
100
+ });
101
+ return;
102
+ }
103
+ streams[requestKey] = yield services['mongodb-atlas'](app, {
88
104
  user,
89
105
  rules
90
106
  })
91
107
  .db(database)
92
108
  .collection(collection)
93
109
  .watch([], { fullDocument: 'whenAvailable' });
94
- changeStream.on('change', (change) => {
110
+ streams[requestKey].on('change', (change) => {
95
111
  res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
96
112
  });
97
- req.raw.on('close', () => {
98
- console.log("change stream closed");
99
- changeStream.close();
100
- });
101
113
  }));
102
114
  });
103
115
  exports.functionsController = functionsController;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.1.2-beta.8",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { ObjectId } from 'bson'
2
- import { DEFAULT_CONFIG } from '../../constants'
2
+ import { ChangeStream, Document } from 'mongodb';
3
3
  import { services } from '../../services'
4
4
  import { StateManager } from '../../state'
5
5
  import { GenerateContext } from '../../utils/context'
@@ -7,6 +7,8 @@ import { Base64Function, FunctionCallBase64Dto, FunctionCallDto } from './dtos'
7
7
  import { FunctionController } from './interface'
8
8
  import { executeQuery } from './utils'
9
9
 
10
+
11
+
10
12
  /**
11
13
  * > Creates a pre handler for every query
12
14
  * @param app -> the fastify instance
@@ -19,6 +21,8 @@ export const functionsController: FunctionController = async (
19
21
  ) => {
20
22
  app.addHook('preHandler', app.jwtAuthentication)
21
23
 
24
+ const streams = {} as Record<string, ChangeStream<Document, Document>>
25
+
22
26
  app.post<{ Body: FunctionCallDto }>('/call', async (req, res) => {
23
27
  const { user } = req
24
28
  const { name: method, arguments: args } = req.body
@@ -88,28 +92,43 @@ export const functionsController: FunctionController = async (
88
92
  'Cache-Control': 'no-cache',
89
93
  'Connection': 'keep-alive',
90
94
  "access-control-allow-credentials": "true",
91
- "access-control-allow-origin": `${DEFAULT_CONFIG.HTTPS_SCHEMA}://${req.headers.host}`,
95
+ "access-control-allow-origin": '*',
92
96
  "access-control-allow-headers": "X-Stitch-Location, X-Baas-Location, Location",
93
- }
97
+ };
94
98
 
95
99
  res.raw.writeHead(200, headers)
96
100
  res.raw.flushHeaders();
97
101
 
98
- const changeStream = await services['mongodb-atlas'](app, {
102
+ const requestKey = baas_request || stitch_request
103
+
104
+ if (!requestKey) return
105
+
106
+ const changeStream = streams[requestKey]
107
+
108
+ if (changeStream) {
109
+ changeStream.on('change', (change) => {
110
+ res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
111
+ });
112
+
113
+ req.raw.on('close', () => {
114
+ console.log("change stream closed");
115
+ changeStream?.close?.();
116
+ delete streams[requestKey]
117
+ });
118
+ return
119
+ }
120
+
121
+ streams[requestKey] = await services['mongodb-atlas'](app, {
99
122
  user,
100
123
  rules
101
124
  })
102
125
  .db(database)
103
126
  .collection(collection)
104
- .watch([], { fullDocument: 'whenAvailable' })
127
+ .watch([], { fullDocument: 'whenAvailable' });
105
128
 
106
- changeStream.on('change', (change) => {
107
- res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
108
- });
109
129
 
110
- req.raw.on('close', () => {
111
- console.log("change stream closed")
112
- changeStream.close();
130
+ streams[requestKey].on('change', (change) => {
131
+ res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
113
132
  });
114
133
  })
115
134
  }