@flowerforce/flowerbase 1.4.0 → 1.4.1-beta.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.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAA;AAqC9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;AA0OD,eAAO,MAAM,gBAAgB;0EAtN1B,aAAa;yEAiKb,aAAa;+EA5Ib,aAAa;CAqMf,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAA;AAqC9D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,gBAAuB,KAAG,OAAO,CAAC,QAAQ,CAkB5E,CAAA;AA8PD,eAAO,MAAM,gBAAgB;0EA1O1B,aAAa;yEAqLb,aAAa;+EA1Jb,aAAa;CAmNf,CAAA"}
@@ -117,6 +117,11 @@ const handleCronTrigger = (_a) => __awaiter(void 0, [_a], void 0, function* ({ c
117
117
  }));
118
118
  registerOnClose(app, () => task.stop(), 'Scheduled trigger');
119
119
  });
120
+ const mapOp = {
121
+ insert: 'CREATE',
122
+ update: 'UPDATE',
123
+ replace: 'REPLACE'
124
+ };
120
125
  const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, function* ({ config, triggerHandler, functionsList, services, app }) {
121
126
  var _b;
122
127
  const { database, isAutoTrigger } = config;
@@ -130,7 +135,10 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
130
135
  }
131
136
  ];
132
137
  const changeStream = collection.watch(pipeline, {
133
- fullDocument: 'whenAvailable'
138
+ fullDocument: 'whenAvailable',
139
+ fullDocumentBeforeChange: config.full_document_before_change
140
+ ? 'whenAvailable'
141
+ : undefined
134
142
  });
135
143
  changeStream.on('error', (error) => {
136
144
  if (shouldIgnoreStreamError(error))
@@ -143,6 +151,7 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
143
151
  const operationType = change['operationType'];
144
152
  const documentKey = change['documentKey'];
145
153
  const fullDocument = change['fullDocument'];
154
+ const fullDocumentBeforeChange = change['fullDocumentBeforeChange'];
146
155
  if (!(documentKey === null || documentKey === void 0 ? void 0 : documentKey._id)) {
147
156
  return;
148
157
  }
@@ -190,10 +199,16 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
190
199
  _id: currentUser._id.toString(),
191
200
  email: currentUser.email
192
201
  } });
193
- // TODO change va ripulito
202
+ const op = {
203
+ operationType: mapOp[operationType],
204
+ fullDocument,
205
+ fullDocumentBeforeChange,
206
+ documentKey,
207
+ updateDescription
208
+ };
194
209
  try {
195
210
  yield (0, context_1.GenerateContext)({
196
- args: isAutoTrigger ? [userData] : [{ user: userData /*, ...change */ }],
211
+ args: isAutoTrigger ? [userData] : [Object.assign({ user: userData }, op)],
197
212
  app,
198
213
  rules: state_1.StateManager.select("rules"),
199
214
  user: {}, // TODO from currentUser ??
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.4.0",
3
+ "version": "1.4.1-beta.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -103,6 +103,12 @@ const handleCronTrigger = async ({
103
103
  registerOnClose(app, () => task.stop(), 'Scheduled trigger')
104
104
  }
105
105
 
106
+ const mapOp = {
107
+ insert: 'CREATE',
108
+ update: 'UPDATE',
109
+ replace: 'REPLACE'
110
+ }
111
+
106
112
  const handleAuthenticationTrigger = async ({
107
113
  config,
108
114
  triggerHandler,
@@ -121,20 +127,26 @@ const handleAuthenticationTrigger = async ({
121
127
  }
122
128
  ]
123
129
  const changeStream = collection.watch(pipeline, {
124
- fullDocument: 'whenAvailable'
130
+ fullDocument: 'whenAvailable',
131
+ fullDocumentBeforeChange: config.full_document_before_change
132
+ ? 'whenAvailable'
133
+ : undefined
125
134
  })
126
135
  changeStream.on('error', (error) => {
127
136
  if (shouldIgnoreStreamError(error)) return
128
137
  console.error('Authentication trigger change stream error', error)
129
138
  })
130
139
  changeStream.on('change', async function (change) {
131
- const operationType = change['operationType' as keyof typeof change] as string | undefined
140
+ const operationType = change['operationType' as keyof typeof change] as 'insert' | 'update' | 'replace'
132
141
  const documentKey = change['documentKey' as keyof typeof change] as
133
142
  | { _id?: unknown }
134
143
  | undefined
135
144
  const fullDocument = change['fullDocument' as keyof typeof change] as
136
145
  | Record<string, unknown>
137
146
  | null
147
+ const fullDocumentBeforeChange = change['fullDocumentBeforeChange' as keyof typeof change] as
148
+ | Record<string, unknown>
149
+ | null
138
150
  if (!documentKey?._id) {
139
151
  return
140
152
  }
@@ -200,10 +212,18 @@ const handleAuthenticationTrigger = async ({
200
212
  email: (currentUser as { email?: string }).email
201
213
  }
202
214
  }
203
- // TODO change va ripulito
215
+
216
+ const op = {
217
+ operationType: mapOp[operationType],
218
+ fullDocument,
219
+ fullDocumentBeforeChange,
220
+ documentKey,
221
+ updateDescription
222
+ }
223
+
204
224
  try {
205
225
  await GenerateContext({
206
- args: isAutoTrigger ? [userData] : [{ user: userData /*, ...change */ }],
226
+ args: isAutoTrigger ? [userData] : [{ user: userData, ...op }],
207
227
  app,
208
228
  rules: StateManager.select("rules"),
209
229
  user: {}, // TODO from currentUser ??