@flowerforce/flowerbase 1.7.2-beta.0 → 1.7.2

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,18 @@
1
+ ## 1.7.2 (2026-02-12)
2
+
3
+
4
+ ### 🩹 Fixes
5
+
6
+ - monit endpoint event ([e696efc](https://github.com/flowerforce/flowerbase/commit/e696efc))
7
+
8
+ - name trigger for monit ([f428fc2](https://github.com/flowerforce/flowerbase/commit/f428fc2))
9
+
10
+ - add mongo method countDocuments ([7a7d872](https://github.com/flowerforce/flowerbase/commit/7a7d872))
11
+
12
+ - add operator $size ([adbc749](https://github.com/flowerforce/flowerbase/commit/adbc749))
13
+
14
+ - add EJSON to context function ([2332c3c](https://github.com/flowerforce/flowerbase/commit/2332c3c))
15
+
1
16
  ## 1.7.1 (2026-02-04)
2
17
 
3
18
 
@@ -1 +1 @@
1
- {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../../src/monitoring/routes/users.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,EAAiB,YAAY,EAAY,MAAM,UAAU,CAAA;AAEhE,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;CACxC,CAAA;AAYD,eAAO,MAAM,kBAAkB,GAAI,KAAK,eAAe,EAAE,MAAM,cAAc,SAoP5E,CAAA"}
1
+ {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../../src/monitoring/routes/users.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,EAAiB,YAAY,EAAY,MAAM,UAAU,CAAA;AAEhE,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;CACxC,CAAA;AAYD,eAAO,MAAM,kBAAkB,GAAI,KAAK,eAAe,EAAE,MAAM,cAAc,SAsP5E,CAAA"}
@@ -122,7 +122,7 @@ const registerUserRoutes = (app, deps) => {
122
122
  };
123
123
  }));
124
124
  app.post(`${prefix}/api/users`, (req, reply) => __awaiter(void 0, void 0, void 0, function* () {
125
- var _a, _b, _c;
125
+ var _a, _b;
126
126
  const body = req.body;
127
127
  const email = (_a = body === null || body === void 0 ? void 0 : body.email) === null || _a === void 0 ? void 0 : _a.toLowerCase();
128
128
  const password = body === null || body === void 0 ? void 0 : body.password;
@@ -140,13 +140,22 @@ const registerUserRoutes = (app, deps) => {
140
140
  provider: handleUserRegistration_model_1.PROVIDER.LOCAL_USERPASS
141
141
  })({ email, password });
142
142
  const userId = (_b = result === null || result === void 0 ? void 0 : result.insertedId) === null || _b === void 0 ? void 0 : _b.toString();
143
- if (userId && constants_1.AUTH_CONFIG.userCollection && constants_1.AUTH_CONFIG.user_id_field) {
144
- const db = app.mongo.client.db(constants_1.DB_NAME);
145
- const customData = (_c = body === null || body === void 0 ? void 0 : body.customData) !== null && _c !== void 0 ? _c : {};
146
- yield db.collection(constants_1.AUTH_CONFIG.userCollection).updateOne({ [constants_1.AUTH_CONFIG.user_id_field]: userId }, {
147
- $set: Object.assign(Object.assign({}, customData), { [constants_1.AUTH_CONFIG.user_id_field]: userId })
148
- }, { upsert: true });
149
- }
143
+ /*
144
+ non deve essere fatto, solo i trigger creano gli users
145
+ if (userId && AUTH_CONFIG.userCollection && AUTH_CONFIG.user_id_field) {
146
+ const db = app.mongo.client.db(DB_NAME)
147
+ const customData = body?.customData ?? {}
148
+ await db.collection(AUTH_CONFIG.userCollection).updateOne(
149
+ { [AUTH_CONFIG.user_id_field]: userId },
150
+ {
151
+ $set: {
152
+ ...customData,
153
+ [AUTH_CONFIG.user_id_field]: userId
154
+ }
155
+ },
156
+ { upsert: true }
157
+ )
158
+ } */
150
159
  addEvent({
151
160
  id: (0, utils_2.createEventId)(),
152
161
  ts: Date.now(),
@@ -17,6 +17,12 @@ type JwtUtils = {
17
17
  */
18
18
  export declare const generateContextData: ({ user, services, app, rules, currentFunction, functionName, functionsList, GenerateContext, request }: GenerateContextDataParams) => {
19
19
  BSON: typeof mongodb.BSON;
20
+ EJSON: {
21
+ parse: (text: string, options?: mongodb.BSON.EJSONOptions) => any;
22
+ stringify: (value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | mongodb.BSON.EJSONOptions, space?: string | number, options?: mongodb.BSON.EJSONOptions) => string;
23
+ serialize: (value: any, options?: mongodb.BSON.EJSONOptions) => mongodb.BSON.Document;
24
+ deserialize: (ejson: mongodb.BSON.Document, options?: mongodb.BSON.EJSONOptions) => any;
25
+ };
20
26
  Buffer: BufferConstructor;
21
27
  utils: {
22
28
  jwt: JwtUtils;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,CACN,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzC,MAAM,CAAA;IACX,MAAM,EAAE,CACN,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,YAAY,CAAC,EAAE,OAAO,EACtB,sBAAsB,CAAC,EAAE,MAAM,EAAE,KAC9B,OAAO,CAAA;CACb,CAAA;AAgFD;;;;;;;;;GASG;AACH,eAAO,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,CAAA;IACX,MAAM,EAAE,CACN,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,YAAY,CAAC,EAAE,OAAO,EACtB,sBAAsB,CAAC,EAAE,MAAM,EAAE,KAC9B,OAAO,CAAA;CACb,CAAA;AAgFD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,wGAUjC,yBAAyB;;;;;;;;;;;;;uBA4DP,SAAS;yBAGP,SAAS;;;;;;;;;;;;;;;;;;uBAcb,MAAM;;;;;;+BA5CU,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BApBzC,CAAC;iCAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAf,CAAC;6BAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAf,CAAC;6BAAa,CAAC;;;;;;;;;;;;;;;4BAyEN,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAgBrE,CAAA"}
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generateContextData = void 0;
37
37
  const mongodb_1 = require("@fastify/mongodb");
38
38
  const jwt = __importStar(require("jsonwebtoken"));
39
+ const bson_1 = require("bson");
39
40
  const normalizePayload = (payload) => {
40
41
  if (typeof payload !== 'string')
41
42
  return payload;
@@ -147,6 +148,7 @@ const generateContextData = ({ user, services, app, rules, currentFunction, func
147
148
  };
148
149
  return {
149
150
  BSON,
151
+ EJSON: bson_1.EJSON,
150
152
  Buffer,
151
153
  utils,
152
154
  console: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.7.2-beta.0",
3
+ "version": "1.7.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -149,20 +149,22 @@ export const registerUserRoutes = (app: FastifyInstance, deps: UserRoutesDeps) =
149
149
 
150
150
  const userId = result?.insertedId?.toString()
151
151
 
152
+ /*
153
+ non deve essere fatto, solo i trigger creano gli users
152
154
  if (userId && AUTH_CONFIG.userCollection && AUTH_CONFIG.user_id_field) {
153
- const db = app.mongo.client.db(DB_NAME)
154
- const customData = body?.customData ?? {}
155
- await db.collection(AUTH_CONFIG.userCollection).updateOne(
156
- { [AUTH_CONFIG.user_id_field]: userId },
157
- {
158
- $set: {
159
- ...customData,
160
- [AUTH_CONFIG.user_id_field]: userId
161
- }
162
- },
163
- { upsert: true }
164
- )
165
- }
155
+ const db = app.mongo.client.db(DB_NAME)
156
+ const customData = body?.customData ?? {}
157
+ await db.collection(AUTH_CONFIG.userCollection).updateOne(
158
+ { [AUTH_CONFIG.user_id_field]: userId },
159
+ {
160
+ $set: {
161
+ ...customData,
162
+ [AUTH_CONFIG.user_id_field]: userId
163
+ }
164
+ },
165
+ { upsert: true }
166
+ )
167
+ } */
166
168
 
167
169
  addEvent({
168
170
  id: createEventId(),
@@ -0,0 +1,52 @@
1
+ import { EJSON } from 'bson'
2
+ import { ObjectId } from 'mongodb'
3
+ import { Function, Functions } from '../../features/functions/interface'
4
+ import { FunctionsQueue } from '../../features/functions/queue'
5
+ import { StateManager } from '../../state'
6
+ import { Services } from '../../services/interface'
7
+ import { GenerateContext } from '../context'
8
+
9
+ describe('GenerateContext with function using EJSON', () => {
10
+ beforeEach(() => {
11
+ StateManager.setData('functionsQueue', new FunctionsQueue())
12
+ })
13
+
14
+ it('runs a function that uses EJSON in the sandbox', async () => {
15
+ const objectId = new ObjectId('65b7f1c5e1c6d44f8a1b2c3d')
16
+ const createdAt = new Date('2025-01-01T00:00:00.000Z')
17
+
18
+ const currentFunction: Function = {
19
+ code: `
20
+ module.exports = (doc) => {
21
+ return EJSON.serialize({ _id: doc._id, createdAt: doc.createdAt })
22
+ }
23
+ `
24
+ }
25
+
26
+ const functionsList: Functions = {
27
+ usesEjson: currentFunction
28
+ }
29
+
30
+ const services: Services = {
31
+ api: jest.fn().mockReturnValue({}),
32
+ aws: jest.fn().mockReturnValue({}),
33
+ auth: jest.fn().mockReturnValue({}),
34
+ 'mongodb-atlas': jest.fn().mockReturnValue({})
35
+ } as unknown as Services
36
+
37
+ const result = await GenerateContext({
38
+ args: [EJSON.serialize({ _id: objectId, createdAt })],
39
+ app: {} as any,
40
+ rules: {},
41
+ user: {},
42
+ currentFunction,
43
+ functionsList,
44
+ services
45
+ })
46
+
47
+ expect(result).toEqual({
48
+ _id: { $oid: objectId.toHexString() },
49
+ createdAt: { $date: '2025-01-01T00:00:00Z' }
50
+ })
51
+ })
52
+ })
@@ -3,6 +3,7 @@ import * as jwt from 'jsonwebtoken'
3
3
  import { Arguments } from '../../auth/dtos'
4
4
  import { Function } from '../../features/functions/interface'
5
5
  import { GenerateContextDataParams } from './interface'
6
+ import { EJSON } from 'bson'
6
7
 
7
8
  type JwtUtils = {
8
9
  encode: (
@@ -121,10 +122,10 @@ export const generateContextData = ({
121
122
  const BSON = mongodb.BSON
122
123
  const Binary = BSON?.Binary as
123
124
  | (typeof mongodb.BSON.Binary & {
124
- fromBase64?: (base64: string, subType?: number) => mongodb.BSON.Binary | Uint8Array
125
- fromBase64Binary?: (base64: string, subType?: number) => mongodb.BSON.Binary
126
- __fb_fromBase64Wrapped?: boolean
127
- })
125
+ fromBase64?: (base64: string, subType?: number) => mongodb.BSON.Binary | Uint8Array
126
+ fromBase64Binary?: (base64: string, subType?: number) => mongodb.BSON.Binary
127
+ __fb_fromBase64Wrapped?: boolean
128
+ })
128
129
  | undefined
129
130
 
130
131
  if (Binary && typeof Binary.fromBase64 !== 'function') {
@@ -173,6 +174,7 @@ export const generateContextData = ({
173
174
 
174
175
  return {
175
176
  BSON,
177
+ EJSON,
176
178
  Buffer,
177
179
  utils,
178
180
  console: {