@flowerforce/flowerbase 1.2.1-beta.12 → 1.2.1-beta.13

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":"index.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAG/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,0CAIpC,sBAAsB,kBA+DxB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAG/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,0CAIpC,sBAAsB,kBAgExB,CAAA"}
@@ -48,6 +48,7 @@ const activateTriggers = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fa
48
48
  type: 'AUTHENTICATION',
49
49
  disabled: false,
50
50
  config: {
51
+ isAutoTrigger: true,
51
52
  collection: (_e = constants_1.AUTH_CONFIG.authCollection) !== null && _e !== void 0 ? _e : 'auth_users',
52
53
  database: constants_1.DB_NAME,
53
54
  full_document: true,
@@ -19,6 +19,7 @@ type Config = {
19
19
  database: string;
20
20
  full_document: boolean;
21
21
  full_document_before_change: boolean;
22
+ isAutoTrigger?: boolean;
22
23
  match: Record<string, unknown>;
23
24
  operation_types: string[];
24
25
  project: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE5D,MAAM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AA;IAClB,aAAa,EAAE,SAAS,CAAA;CACzB,CAAA"}
@@ -119,7 +119,7 @@ const handleCronTrigger = (_a) => __awaiter(void 0, [_a], void 0, function* ({ c
119
119
  });
120
120
  const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, function* ({ config, triggerHandler, functionsList, services, app }) {
121
121
  var _b;
122
- const { database } = config;
122
+ const { database, isAutoTrigger } = config;
123
123
  const authCollection = (_b = constants_1.AUTH_CONFIG.authCollection) !== null && _b !== void 0 ? _b : 'auth_users';
124
124
  const collection = app.mongo.client.db(database || constants_1.DB_NAME).collection(authCollection);
125
125
  const pipeline = [
@@ -186,13 +186,12 @@ const handleAuthenticationTrigger = (_a) => __awaiter(void 0, [_a], void 0, func
186
186
  delete document.password;
187
187
  const currentUser = Object.assign({}, document);
188
188
  delete currentUser.password;
189
+ const userData = Object.assign(Object.assign({}, currentUser), { id: currentUser._id.toString(), data: {
190
+ _id: currentUser._id.toString(),
191
+ email: currentUser.email
192
+ } });
189
193
  yield (0, context_1.GenerateContext)({
190
- args: [{
191
- user: Object.assign(Object.assign({}, currentUser), { id: currentUser._id.toString(), data: {
192
- _id: currentUser._id.toString(),
193
- email: currentUser.email
194
- } })
195
- }],
194
+ args: isAutoTrigger ? [userData] : [Object.assign({ user: userData }, change)],
196
195
  app,
197
196
  rules: state_1.StateManager.select("rules"),
198
197
  user: {}, // TODO from currentUser ??
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.2.1-beta.12",
3
+ "version": "1.2.1-beta.13",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@ export const activateTriggers = async ({
24
24
  (trigger) =>
25
25
  trigger.content.type === 'AUTHENTICATION' &&
26
26
  trigger.content.event_processors?.FUNCTION?.config?.function_name ===
27
- AUTH_CONFIG.on_user_creation_function_name
27
+ AUTH_CONFIG.on_user_creation_function_name
28
28
  )
29
29
  if (!alreadyDeclared) {
30
30
  triggersToActivate.push({
@@ -34,6 +34,7 @@ export const activateTriggers = async ({
34
34
  type: 'AUTHENTICATION',
35
35
  disabled: false,
36
36
  config: {
37
+ isAutoTrigger: true,
37
38
  collection: AUTH_CONFIG.authCollection ?? 'auth_users',
38
39
  database: DB_NAME,
39
40
  full_document: true,
@@ -21,6 +21,7 @@ type Config = {
21
21
  database: string
22
22
  full_document: boolean
23
23
  full_document_before_change: boolean
24
+ isAutoTrigger?: boolean
24
25
  match: Record<string, unknown>
25
26
  operation_types: string[]
26
27
  project: Record<string, unknown>
@@ -110,7 +110,7 @@ const handleAuthenticationTrigger = async ({
110
110
  services,
111
111
  app
112
112
  }: HandlerParams) => {
113
- const { database } = config
113
+ const { database, isAutoTrigger } = config
114
114
  const authCollection = AUTH_CONFIG.authCollection ?? 'auth_users'
115
115
  const collection = app.mongo.client.db(database || DB_NAME).collection(authCollection)
116
116
  const pipeline = [
@@ -191,17 +191,17 @@ const handleAuthenticationTrigger = async ({
191
191
 
192
192
  const currentUser = { ...document }
193
193
  delete (currentUser as { password?: unknown }).password
194
+
195
+ const userData = {
196
+ ...currentUser,
197
+ id: (currentUser as { _id: { toString: () => string } })._id.toString(),
198
+ data: {
199
+ _id: (currentUser as { _id: { toString: () => string } })._id.toString(),
200
+ email: (currentUser as { email?: string }).email
201
+ }
202
+ }
194
203
  await GenerateContext({
195
- args: [{
196
- user: {
197
- ...currentUser,
198
- id: (currentUser as { _id: { toString: () => string } })._id.toString(),
199
- data: {
200
- _id: (currentUser as { _id: { toString: () => string } })._id.toString(),
201
- email: (currentUser as { email?: string }).email
202
- }
203
- }
204
- }],
204
+ args: isAutoTrigger ? [userData] : [{ user: userData, ...change }],
205
205
  app,
206
206
  rules: StateManager.select("rules"),
207
207
  user: {}, // TODO from currentUser ??