@flowerforce/flowerbase 1.1.2-beta.7 → 1.1.2-beta.9

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,kBAuGjC,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;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");
@@ -70,10 +71,19 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
70
71
  const { query, user } = req;
71
72
  const { baas_request, stitch_request } = query;
72
73
  const config = JSON.parse(Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'));
73
- 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);
74
74
  const [{ database, collection }] = config.arguments;
75
75
  const app = state_1.StateManager.select('app');
76
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();
77
87
  const changeStream = yield services['mongodb-atlas'](app, {
78
88
  user,
79
89
  rules
@@ -81,19 +91,11 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
81
91
  .db(database)
82
92
  .collection(collection)
83
93
  .watch([], { fullDocument: 'whenAvailable' });
84
- console.log("🚀 ~ functionsController ~ changeStream:", changeStream);
85
- res.header('Content-Type', 'text/event-stream');
86
- res.header('Cache-Control', 'no-cache');
87
- res.header("content-encoding", "gzip");
88
- res.header('Connection', 'keep-alive');
89
- res.header("access-control-allow-credentials", true);
90
- res.header("access-control-allow-origin", "*");
91
- res.header("access-control-allow-headers", "X-Stitch-Location, X-Baas-Location, Location");
92
- res.raw.flushHeaders();
93
94
  changeStream.on('change', (change) => {
94
95
  res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
95
96
  });
96
97
  req.raw.on('close', () => {
98
+ console.log("change stream closed");
97
99
  changeStream.close();
98
100
  });
99
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;AA+pBrF,QAAA,MAAM,YAAY,EAAE,oBAmBlB,CAAA;AAEF,eAAe,YAAY,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,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.1.2-beta.7",
3
+ "version": "1.1.2-beta.9",
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
-
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'
@@ -79,17 +79,22 @@ export const functionsController: FunctionController = async (
79
79
  Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8')
80
80
  )
81
81
 
82
- console.log("🚀 ~ functionsController ~ baas_request:",
83
- baas_request,
84
- query,
85
- Buffer.from(baas_request || stitch_request || '', 'base64'),
86
- Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'),
87
- config
88
- )
89
82
  const [{ database, collection }] = config.arguments
90
83
  const app = StateManager.select('app')
91
84
  const services = StateManager.select('services')
92
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
+
93
98
  const changeStream = await services['mongodb-atlas'](app, {
94
99
  user,
95
100
  rules
@@ -97,23 +102,14 @@ export const functionsController: FunctionController = async (
97
102
  .db(database)
98
103
  .collection(collection)
99
104
  .watch([], { fullDocument: 'whenAvailable' })
100
- console.log("🚀 ~ functionsController ~ changeStream:", changeStream)
101
-
102
- res.header('Content-Type', 'text/event-stream')
103
- res.header('Cache-Control', 'no-cache')
104
- res.header("content-encoding", "gzip")
105
- res.header('Connection', 'keep-alive')
106
- res.header("access-control-allow-credentials", true)
107
- res.header("access-control-allow-origin", "*")
108
- res.header("access-control-allow-headers", "X-Stitch-Location, X-Baas-Location, Location")
109
- res.raw.flushHeaders()
110
105
 
111
106
  changeStream.on('change', (change) => {
112
- res.raw.write(`data: ${JSON.stringify(change)}\n\n`)
113
- })
107
+ res.raw.write(`data: ${JSON.stringify(change)}\n\n`);
108
+ });
114
109
 
115
110
  req.raw.on('close', () => {
116
- changeStream.close()
117
- })
111
+ console.log("change stream closed")
112
+ changeStream.close();
113
+ });
118
114
  })
119
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