@cocreate/lazy-loader 1.19.2 → 1.19.4

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,17 @@
1
+ ## [1.19.4](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.19.3...v1.19.4) (2024-05-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * removed environment handling variables as it is database specific ([d63921c](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/d63921cb039c284ab452bf47f0802fc56a66eeb3))
7
+
8
+ ## [1.19.3](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.19.2...v1.19.3) (2024-05-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * processOperators and processOperator functions ([984f19c](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/984f19cdad55bfb74b9599f910950ef91f174f00))
14
+
1
15
  ## [1.19.2](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.19.1...v1.19.2) (2024-04-29)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/lazy-loader",
3
- "version": "1.19.2",
3
+ "version": "1.19.4",
4
4
  "description": "A simple lazy-loader component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "lazy-loader",
package/src/server.js CHANGED
@@ -156,14 +156,8 @@ class CoCreateLazyLoader {
156
156
  const name = methodPath.shift()
157
157
 
158
158
  const apis = await this.getApiKey(data, name)
159
- let environment = 'production';
160
159
 
161
- if (data.environment)
162
- environment = data.environment
163
- else if (data.host.startsWith('dev.') || data.host.startsWith('test.'))
164
- environment = 'test'
165
-
166
- const key = apis[environment].key;
160
+ const key = apis.key;
167
161
  if (!key)
168
162
  throw new Error(`Missing ${name} key in organization apis object`);
169
163
 
@@ -205,29 +199,25 @@ class CoCreateLazyLoader {
205
199
  async webhooks(config, data, name) {
206
200
  try {
207
201
  const apis = await this.getApiKey(data, name)
208
- if (data.environment)
209
- environment = data.environment
210
- else if (data.host.startsWith('dev.') || data.host.startsWith('test.'))
211
- environment = 'test'
212
202
 
213
- const key = apis[environment].key;
203
+ const key = apis.key;
214
204
  if (!key)
215
205
  throw new Error(`Missing ${name} key in organization apis object`);
216
206
 
217
207
  let webhookName = data.req.url.split('/');
218
208
  webhookName = webhookName[webhookName.length - 1]
219
209
 
220
- const webhook = apis[environment].webhooks[webhookName];
210
+ const webhook = apis.webhooks[webhookName];
221
211
  if (!webhook)
222
212
  throw new Error(`Webhook ${name} ${webhookName} is not defined`);
223
213
 
224
214
  // eventDataKey is used to access the event data
225
- let eventDataKey = webhook.eventDataKey || apis[environment].eventDataKey
215
+ let eventDataKey = webhook.eventDataKey || apis.eventDataKey
226
216
  if (!eventDataKey)
227
217
  throw new Error(`Webhook ${name} eventKey is not defined`);
228
218
 
229
219
  // eventNameKey is used to access the event the event name
230
- let eventNameKey = webhook.eventNameKey || apis[environment].eventNameKey
220
+ let eventNameKey = webhook.eventNameKey || apis.eventNameKey
231
221
  if (!eventNameKey)
232
222
  throw new Error(`Webhook ${name} eventNameKey is not defined`);
233
223
 
@@ -252,15 +242,15 @@ class CoCreateLazyLoader {
252
242
 
253
243
  if (webhook.authenticate && webhook.authenticate.method) {
254
244
  method = webhook.authenticate.method
255
- } else if (apis[environment].authenticate && apis[environment].authenticate.method) {
256
- method = apis[environment].authenticate.method
245
+ } else if (apis.authenticate && apis.authenticate.method) {
246
+ method = apis.authenticate.method
257
247
  } else
258
248
  throw new Error(`Webhook ${name} authenticate method is not defined`);
259
249
 
260
250
  if (webhook.authenticate && webhook.authenticate.parameters) {
261
251
  parameters = webhook.authenticate.parameters
262
- } else if (apis[environment].authenticate && apis[environment].authenticate.parameters) {
263
- parameters = apis[environment].authenticate.parameters
252
+ } else if (apis.authenticate && apis.authenticate.parameters) {
253
+ parameters = apis.authenticate.parameters
264
254
  } else
265
255
  throw new Error(`Webhook ${name} authenticate parameters is not defined`);
266
256
 
@@ -311,32 +301,34 @@ class CoCreateLazyLoader {
311
301
  }
312
302
  }
313
303
 
314
- async processOperators(data, event, execute, parent = null, parentKey = null) {
304
+ async processOperators(data, event, execute) {
315
305
  if (Array.isArray(execute)) {
316
306
  for (let index = 0; index < execute.length; index++) {
317
- execute[index] = await this.processOperators(data, event, execute[index], execute, index);
307
+ execute[index] = await this.processOperators(data, event, execute[index]);
318
308
  }
319
309
  } else if (typeof execute === 'object' && execute !== null) {
320
310
  for (let key of Object.keys(execute)) {
321
- if (key.startsWith('$')) {
322
- const operatorResult = await this.processOperator(data, event, key, execute[key]);
323
- if (parent && operatorResult !== null && parentKey !== null) {
324
- parent[parentKey] = operatorResult;
325
- await this.processOperators(data, event, parent[parentKey], parent, parentKey);
326
- }
327
- } else {
328
- execute[key] = await this.processOperators(data, event, execute[key], execute, key);
311
+ if (key.startsWith('$') && !['$storage', '$database', '$array', '$filter'].includes(key)) {
312
+ execute[key] = await this.processOperator(data, event, key, execute[key]);
313
+ } else if (typeof execute[key] === 'string' && execute[key].startsWith('$') && !['$storage', '$database', '$array', '$filter'].includes(execute[key])) {
314
+ execute[key] = await this.processOperator(data, event, execute[key]);
315
+ } else if (Array.isArray(execute[key])) {
316
+ execute[key] = await this.processOperators(data, event, execute[key]);
317
+ } else if (typeof execute[key] === 'object' && execute[key] !== null) {
318
+ execute[key] = await this.processOperators(data, event, execute[key]);
329
319
  }
330
320
  }
331
- } else {
332
- return await this.processOperator(data, event, execute);
321
+ } else if (typeof execute === 'string' && execute.startsWith('$') && !['$storage', '$database', '$array', '$filter'].includes(execute)) {
322
+ execute = await this.processOperator(data, event, execute);
333
323
  }
324
+
334
325
  return execute;
335
326
  }
336
327
 
337
328
  async processOperator(data, event, operator, context) {
338
329
  let result
339
330
  if (operator.startsWith('$data.')) {
331
+ result = getValueFromObject(data, operator.substring(6))
340
332
  return getValueFromObject(data, operator.substring(6))
341
333
  } else if (operator.startsWith('$req')) {
342
334
  return getValueFromObject(data, operator.substring(1))
@@ -385,36 +377,6 @@ class CoCreateLazyLoader {
385
377
 
386
378
  }
387
379
 
388
-
389
- // async function processOperators(data, event, execute, parent = null, parentKey = null) {
390
- // if (Array.isArray(execute)) {
391
- // execute.forEach(async (item, index) => await processOperators(data, event, item, execute, index));
392
- // } else if (typeof execute === 'object' && execute !== null) {
393
- // for (let key of Object.keys(execute)) {
394
- // // Check if key is an operator
395
- // if (key.startsWith('$')) {
396
- // const operatorResult = await processOperator(data, event, key, execute[key]);
397
- // if (parent && operatorResult !== null) {
398
- // if (parentKey !== null) {
399
- // parent[parentKey] = operatorResult;
400
- // await processOperators(data, event, parent[parentKey], parent, parentKey);
401
- // }
402
- // // else {
403
- // // // Scenario 2: Replace the key (more complex, might require re-structuring the executable object)
404
- // // delete parent[key]; // Remove the original key
405
- // // parent[operatorResult] = execute[key]; // Assign the value to the new key
406
- // // // Continue processing the new key if necessary
407
- // // }
408
- // }
409
- // } else {
410
- // await processOperators(data, event, execute[key], execute, key);
411
- // }
412
- // }
413
- // } else {
414
- // return await processOperator(data, event, execute);
415
- // }
416
- // }
417
-
418
380
  async function executeMethod(method, methodPath, instance, params) {
419
381
  try {
420
382
  switch (methodPath.length) {