@ductape/sdk 0.0.3-beta11 → 0.0.3-beta13

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.
Files changed (68) hide show
  1. package/dist/api/services/appApi.service.d.ts +3 -1
  2. package/dist/api/services/appApi.service.js +41 -1
  3. package/dist/api/services/appApi.service.js.map +1 -1
  4. package/dist/api/services/productsApi.service.d.ts +2 -1
  5. package/dist/api/services/productsApi.service.js +1 -1
  6. package/dist/api/services/productsApi.service.js.map +1 -1
  7. package/dist/api/services/userApi.service.d.ts +2 -1
  8. package/dist/api/services/userApi.service.js +1 -1
  9. package/dist/api/services/userApi.service.js.map +1 -1
  10. package/dist/api/services/workspaceApi.service.d.ts +2 -1
  11. package/dist/api/services/workspaceApi.service.js +1 -1
  12. package/dist/api/services/workspaceApi.service.js.map +1 -1
  13. package/dist/api/utils/cache.utils.d.ts +3 -0
  14. package/dist/api/utils/cache.utils.js +18 -0
  15. package/dist/api/utils/cache.utils.js.map +1 -0
  16. package/dist/apps/services/app.service.js +69 -25
  17. package/dist/apps/services/app.service.js.map +1 -1
  18. package/dist/apps/utils/objects.utils.d.ts +1 -1
  19. package/dist/apps/utils/objects.utils.js +5 -3
  20. package/dist/apps/utils/objects.utils.js.map +1 -1
  21. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +1 -1
  22. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
  23. package/dist/apps/validators/joi-validators/create.appWebhookEvent.validator.js +1 -0
  24. package/dist/apps/validators/joi-validators/create.appWebhookEvent.validator.js.map +1 -1
  25. package/dist/apps/validators/joi-validators/update.appWebhookEvent.validator.js +2 -0
  26. package/dist/apps/validators/joi-validators/update.appWebhookEvent.validator.js.map +1 -1
  27. package/dist/index.d.ts +14 -5
  28. package/dist/index.js +35 -4
  29. package/dist/index.js.map +1 -1
  30. package/dist/logs/logs.service.d.ts +1 -1
  31. package/dist/logs/logs.service.js +0 -1
  32. package/dist/logs/logs.service.js.map +1 -1
  33. package/dist/logs/logs.types.d.ts +2 -0
  34. package/dist/logs/logs.types.js.map +1 -1
  35. package/dist/processor/services/fallback.service.d.ts +1 -2
  36. package/dist/processor/services/fallback.service.js +0 -17
  37. package/dist/processor/services/fallback.service.js.map +1 -1
  38. package/dist/processor/services/processor.service.d.ts +17 -10
  39. package/dist/processor/services/processor.service.js +280 -132
  40. package/dist/processor/services/processor.service.js.map +1 -1
  41. package/dist/processor/services/quota.service.d.ts +3 -1
  42. package/dist/processor/services/quota.service.js +1 -1
  43. package/dist/processor/services/quota.service.js.map +1 -1
  44. package/dist/processor/utils/processor.utils.d.ts +1 -0
  45. package/dist/processor/utils/processor.utils.js +5 -2
  46. package/dist/processor/utils/processor.utils.js.map +1 -1
  47. package/dist/processor/utils/storage.util.js +0 -1
  48. package/dist/processor/utils/storage.util.js.map +1 -1
  49. package/dist/products/services/products.service.d.ts +12 -5
  50. package/dist/products/services/products.service.js +174 -50
  51. package/dist/products/services/products.service.js.map +1 -1
  52. package/dist/products/utils/functions.utils.d.ts +1 -0
  53. package/dist/products/utils/functions.utils.js +11 -0
  54. package/dist/products/utils/functions.utils.js.map +1 -1
  55. package/dist/products/validators/joi-validators/create.productFallback.validator.js +7 -1
  56. package/dist/products/validators/joi-validators/create.productFallback.validator.js.map +1 -1
  57. package/dist/products/validators/joi-validators/create.productQuota.validator.js +8 -2
  58. package/dist/products/validators/joi-validators/create.productQuota.validator.js.map +1 -1
  59. package/dist/products/validators/joi-validators/update.productFallback.validator.js +7 -2
  60. package/dist/products/validators/joi-validators/update.productFallback.validator.js.map +1 -1
  61. package/dist/products/validators/joi-validators/update.productQuota.validator.js +5 -1
  62. package/dist/products/validators/joi-validators/update.productQuota.validator.js.map +1 -1
  63. package/dist/types/appBuilder.types.d.ts +3 -1
  64. package/dist/types/enums.d.ts +1 -0
  65. package/dist/types/enums.js +1 -0
  66. package/dist/types/enums.js.map +1 -1
  67. package/dist/types/productsBuilder.types.d.ts +6 -6
  68. package/package.json +1 -1
@@ -52,10 +52,11 @@ const types_1 = require("../../types");
52
52
  const logs_service_1 = __importDefault(require("../../logs/logs.service"));
53
53
  const inputs_service_1 = __importDefault(require("../../inputs/inputs.service"));
54
54
  const processor_utils_1 = require("../utils/processor.utils");
55
- const http_client_1 = __importDefault(require("../../clients/http.client"));
55
+ const axios_1 = __importDefault(require("axios"));
56
56
  const processorApi_service_1 = require("../../api/services/processorApi.service");
57
57
  const expo_client_1 = __importDefault(require("../../clients/expo.client"));
58
58
  const handlebars_1 = require("handlebars");
59
+ const functions_utils_1 = require("../../products/utils/functions.utils");
59
60
  const string_utils_1 = require("../../products/utils/string.utils");
60
61
  const create_productFeature_validator_1 = require("../../products/validators/joi-validators/create.productFeature.validator");
61
62
  const validators_1 = require("../../products/validators");
@@ -68,8 +69,6 @@ const postgres_repo_1 = require("../repos/postgres.repo");
68
69
  const storage_util_1 = require("../utils/storage.util");
69
70
  const sms_repo_1 = require("../repos/sms.repo");
70
71
  const quota_service_1 = __importDefault(require("./quota.service"));
71
- const fallback_service_1 = __importDefault(require("./fallback.service"));
72
- const productsApi_service_1 = require("../../api/services/productsApi.service");
73
72
  async function loadBrokerService() {
74
73
  if (typeof window === 'undefined') {
75
74
  const { createBrokerService } = await Promise.resolve().then(() => __importStar(require('./messagebrokers')));
@@ -90,14 +89,18 @@ class ProcessorService {
90
89
  this.public_key = public_key;
91
90
  this.user_id = user_id;
92
91
  this.token = token;
92
+ this.published = false;
93
93
  this.productBuilderService = new products_service_1.default({
94
94
  workspace_id,
95
95
  public_key,
96
96
  user_id,
97
97
  token,
98
98
  env_type,
99
+ redis_client
99
100
  });
100
101
  this.inputService = new inputs_service_1.default();
102
+ this.requestTime = 0;
103
+ this.totalRequests = 0;
101
104
  this.processingOutput = {
102
105
  success: [],
103
106
  failure: [],
@@ -110,7 +113,6 @@ class ProcessorService {
110
113
  if (redis_client) {
111
114
  this.redisClient = redis_client;
112
115
  }
113
- this.productApi = new productsApi_service_1.ProductsApiService(env_type);
114
116
  }
115
117
  async generateSession(payload) {
116
118
  try {
@@ -274,7 +276,6 @@ class ProcessorService {
274
276
  }
275
277
  async processQuota(data) {
276
278
  this.start = Date.now();
277
- this.input = data;
278
279
  const { product: product_tag, env, input, tag: quota_tag } = data;
279
280
  try {
280
281
  this.productTag = product_tag;
@@ -296,6 +297,9 @@ class ProcessorService {
296
297
  data: input,
297
298
  };
298
299
  this.quota = this.fetchQuota(quota_tag, additional_logs);
300
+ if (!this.quota) {
301
+ throw new Error(`Quota ${quota_tag} not found`);
302
+ }
299
303
  this.logService.setFeatureId(this.quota._id);
300
304
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
301
305
  this.processEnv = this.fetchEnv(env, additional_logs);
@@ -307,32 +311,91 @@ class ProcessorService {
307
311
  this.validateJSONFeatureInput(input, quotaInput, additional_logs);
308
312
  // split processes
309
313
  //this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
310
- return await this.runQuotaOptions(options, additional_logs);
314
+ return await this.runQuotaOptions(options, input, additional_logs);
311
315
  }
312
316
  catch (e) {
313
317
  this.end = Date.now();
314
- this.logService.publish();
318
+ await this.logService.publish();
315
319
  throw e;
316
320
  }
317
321
  }
318
- async runQuotaOptions(options, additional_logs) {
319
- const quotaManager = new quota_service_1.default(options);
322
+ async runQuotaOptions(options, input, additional_logs) {
323
+ const quotaManager = new quota_service_1.default(options, this.redisClient);
320
324
  const getNextProvider = quotaManager.getNextProvider();
321
- await this.processEvent({
325
+ const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
326
+ return await this.processEvent({
327
+ app: getNextProvider.app,
322
328
  type: getNextProvider.type,
323
329
  event: getNextProvider.event,
324
- input: getNextProvider.input,
330
+ input: quotaInput,
325
331
  retries: getNextProvider.retries,
326
332
  allow_fail: false
327
333
  });
328
334
  }
329
- async runFallbackOptions(options, additional_logs) {
330
- const fallbackManager = new fallback_service_1.default(options);
331
- await fallbackManager.executeActionWithFallback(this.processEvent);
335
+ async mapQuotaFallbackInput(providerInput, quotaInput, app) {
336
+ if (Array.isArray(providerInput)) {
337
+ return providerInput.map(async (item) => await this.mapQuotaFallbackInput(item, quotaInput, app));
338
+ }
339
+ else if (providerInput && typeof providerInput === 'object') {
340
+ const result = {};
341
+ for (const key in providerInput) {
342
+ result[key] = await this.mapQuotaFallbackInput(providerInput[key], quotaInput, app);
343
+ }
344
+ return result;
345
+ }
346
+ else {
347
+ // Base case: primitive value
348
+ return await this.overrideQuotaFallbackInput(providerInput, quotaInput, app);
349
+ }
350
+ }
351
+ async overrideQuotaFallbackInput(value, quotaInput, app) {
352
+ if (value.startsWith('$Input{')) {
353
+ return quotaInput[(0, string_utils_1.extractStages)(value)[0]];
354
+ }
355
+ else if (value.startsWith('$Auth')) {
356
+ return await this.generateAuthValue((0, string_utils_1.extractStages)(value), app, [], {});
357
+ }
358
+ else if (value.startsWith('$')) {
359
+ this.input = Object.assign(Object.assign({}, this.input), { input: quotaInput });
360
+ return await this.generateOperatorValues(value, '', {});
361
+ }
362
+ else {
363
+ return value;
364
+ }
365
+ }
366
+ async runFallbackOptions(options, input, additional_logs) {
367
+ return await this.executeActionWithFallback(options, input);
368
+ }
369
+ async executeActionWithFallback(providers, input) {
370
+ let index = 0;
371
+ for (const provider of providers) {
372
+ try {
373
+ const payload = {
374
+ app: provider.app,
375
+ type: provider.type,
376
+ event: provider.event,
377
+ input: await this.mapQuotaFallbackInput(provider.input, input, provider.app),
378
+ retries: provider.retries,
379
+ allow_fail: false
380
+ };
381
+ const result = await this.processEvent(payload);
382
+ if (result.status === types_1.LogEventStatus.FAIL) {
383
+ throw new Error(result.errors);
384
+ }
385
+ index++;
386
+ }
387
+ catch (error) {
388
+ console.log(error);
389
+ if (index > 0) {
390
+ throw error;
391
+ }
392
+ console.warn(`${provider.app || provider.event} failed: ${error}`);
393
+ }
394
+ }
395
+ //throw new Error("All providers failed.");
332
396
  }
333
397
  async processFallback(data) {
334
398
  this.start = Date.now();
335
- this.input = data;
336
399
  const { product: product_tag, env, input, tag: fallback_tag } = data;
337
400
  try {
338
401
  this.productTag = product_tag;
@@ -349,12 +412,15 @@ class ProcessorService {
349
412
  product_id: this.productId,
350
413
  workspace_id: this.workspace_id,
351
414
  env,
352
- type: types_1.LogEventTypes.QUOTA,
415
+ type: types_1.LogEventTypes.FALLBACK,
353
416
  process_id,
354
417
  data: input,
355
418
  };
356
419
  this.fallback = this.fetchFallback(fallback_tag, additional_logs);
357
- this.logService.setFeatureId(this.quota._id);
420
+ if (!this.fallback) {
421
+ throw new Error(`Fallback "${fallback_tag}" not found`);
422
+ }
423
+ this.logService.setFeatureId(this.fallback._id);
358
424
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process fallback initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
359
425
  this.processEnv = this.fetchEnv(env, additional_logs);
360
426
  if (!this.processEnv.active) {
@@ -365,15 +431,15 @@ class ProcessorService {
365
431
  this.validateJSONFeatureInput(input, fallbackInput, additional_logs);
366
432
  // split processes
367
433
  //this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
368
- return await this.runFallbackOptions(options, additional_logs);
434
+ return await this.runFallbackOptions(options, input, additional_logs);
369
435
  }
370
436
  catch (e) {
371
437
  this.end = Date.now();
372
- this.logService.publish();
438
+ await this.logService.publish();
373
439
  throw e;
374
440
  }
375
441
  }
376
- async processFeature(data) {
442
+ async processFeature(data, awaitResolution = false) {
377
443
  this.start = Date.now();
378
444
  this.input = data;
379
445
  const { product: product_tag, env, input, tag: feature_tag } = data;
@@ -385,12 +451,14 @@ class ProcessorService {
385
451
  name: 'Process feature',
386
452
  type: types_1.LogEventTypes.FEATURE,
387
453
  };
388
- console.log(additional_logs);
389
454
  await this.intializeProduct(additional_logs);
390
455
  this.component = types_1.LogEventTypes.FEATURE;
391
456
  const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
392
457
  this.process_id = process_id;
393
458
  this.feature = this.fetchFeature(feature_tag, additional_logs);
459
+ if (!this.feature) {
460
+ throw new Error(`Feature "${feature_tag}" not found`);
461
+ }
394
462
  this.baseLogs = {
395
463
  product_tag: this.productTag,
396
464
  product_id: this.productId,
@@ -412,7 +480,7 @@ class ProcessorService {
412
480
  // validate feature input and log failure
413
481
  this.validateJSONFeatureInput(input, featureInput, additional_logs);
414
482
  // split processes
415
- this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
483
+ this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
416
484
  await this.processSequenceLevels(additional_logs);
417
485
  return { process_id };
418
486
  //return this.generateOutput(output as unknown as Record<string, IFeatureOutput>);
@@ -421,7 +489,7 @@ class ProcessorService {
421
489
  this.end = Date.now();
422
490
  if (this.logService) {
423
491
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process feature - failed', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
424
- this.logService.publish();
492
+ await this.logService.publish();
425
493
  if (passedValidation) {
426
494
  return { process_id: this.process_id };
427
495
  }
@@ -525,7 +593,7 @@ class ProcessorService {
525
593
  throw e;
526
594
  }
527
595
  }
528
- splitSequenceIntoLevels(data, additional_logs) {
596
+ async splitSequenceIntoLevels(data, additional_logs) {
529
597
  try {
530
598
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
531
599
  const levels = {};
@@ -567,7 +635,7 @@ class ProcessorService {
567
635
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process levels - initiated', data: { levels: this.sequenceLevels }, status: types_1.LogEventStatus.PROCESSING }));
568
636
  const levelEvents = {};
569
637
  Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
570
- levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences);
638
+ levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
571
639
  });
572
640
  let previousLevelComplete = true;
573
641
  for (const level of Object.keys(levelEvents)
@@ -580,8 +648,9 @@ class ProcessorService {
580
648
  break;
581
649
  }
582
650
  }
583
- if (previousLevelComplete) {
584
- this.logService.publish();
651
+ if (previousLevelComplete && !this.published) {
652
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_feature_execution: true, message: 'Process feature - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
653
+ await this.logService.publish();
585
654
  this.end = Date.now();
586
655
  this.writeResult(types_1.LogEventStatus.SUCCESS);
587
656
  }
@@ -592,46 +661,62 @@ class ProcessorService {
592
661
  }
593
662
  }
594
663
  async processLevelEvents(events, additional_logs) {
595
- const promises = events.map((event) => {
596
- const dependants = this.fetchActionRequestDependents(event.input, additional_logs);
597
- if (this.checkDependentsSuccess(dependants)) {
598
- // TODO: comparison to see if all depending events are in success || dependants is empty
599
- return this.processEvent(event);
600
- }
601
- else {
602
- this.addToWaitingOutput(event, dependants);
603
- }
604
- });
605
- return Promise.all(promises);
664
+ try {
665
+ const promises = events.map((event) => {
666
+ const dependants = this.fetchActionRequestDependents(event.input, additional_logs);
667
+ const passed = this.checkDependentsSuccess(dependants);
668
+ if (passed) {
669
+ // TODO: comparison to see if all depending events are in success || dependants is empty
670
+ return this.processEvent(event);
671
+ }
672
+ else {
673
+ this.addToWaitingOutput(event, dependants);
674
+ }
675
+ });
676
+ return Promise.all(promises);
677
+ }
678
+ catch (e) {
679
+ throw e;
680
+ }
606
681
  }
607
682
  async processFailedEvents(additional_logs) {
608
- const { failure } = this.processingOutput;
609
- const promises = failure.map((failed) => {
610
- if (failed.retries_left > 0 && new Date().getTime() > failed.retry_at) {
611
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess failed events - initiated', data: Object.assign({}, failed), status: types_1.LogEventStatus.PROCESSING }));
612
- return this.processEvent(failed.event); // process events should also take care of this.processingOutput
613
- }
614
- if (failed.retries_left === 0 && !failed.allow_fail) {
615
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess failed events - failed', data: Object.assign(Object.assign({}, failed), { reason: 'Ran out of Retries' }), status: types_1.LogEventStatus.FAIL }));
616
- throw new Error(`Event ${failed.event.event} failed in sequence ${failed.event.sequence_tag}, ran out of retries and the feature cannot run without it succeeding`);
617
- }
618
- });
619
- Promise.all(promises);
683
+ try {
684
+ const { failure } = this.processingOutput;
685
+ const promises = failure.map((failed) => {
686
+ if (failed.retries_left > 0 && new Date().getTime() > failed.retry_at) {
687
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess failed events - initiated', data: Object.assign({}, failed), status: types_1.LogEventStatus.PROCESSING }));
688
+ return this.processEvent(failed.event); // process events should also take care of this.processingOutput
689
+ }
690
+ if (failed.retries_left === 0 && !failed.allow_fail) {
691
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess failed events - failed', data: Object.assign(Object.assign({}, failed), { reason: 'Ran out of Retries' }), status: types_1.LogEventStatus.FAIL }));
692
+ throw new Error(`Event ${failed.event.event} failed in sequence ${failed.event.sequence_tag}, ran out of retries and the feature cannot run without it succeeding`);
693
+ }
694
+ });
695
+ Promise.all(promises);
696
+ }
697
+ catch (e) {
698
+ throw e;
699
+ }
620
700
  }
621
701
  async processWaitingEvents(additional_logs) {
622
- const { waiting } = this.processingOutput;
623
- const promises = waiting.map((waiting) => {
624
- const { dependants } = waiting;
625
- if (this.checkDependentsSuccess(dependants)) {
626
- // TODO: comparison to see if all depending events are in success || dependants is empty
627
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess waiting events - initiated', data: Object.assign({}, waiting), status: types_1.LogEventStatus.PROCESSING }));
628
- return this.processEvent(waiting.event);
629
- }
630
- else {
631
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess waiting events - waiting', data: Object.assign({}, waiting), status: types_1.LogEventStatus.WAITING }));
632
- }
633
- });
634
- return Promise.all(promises);
702
+ try {
703
+ const { waiting } = this.processingOutput;
704
+ const promises = waiting.map((waiting) => {
705
+ const { dependants } = waiting;
706
+ if (this.checkDependentsSuccess(dependants)) {
707
+ // TODO: comparison to see if all depending events are in success || dependants is empty
708
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess waiting events - initiated', data: Object.assign({}, waiting), status: types_1.LogEventStatus.PROCESSING }));
709
+ return this.processEvent(waiting.event);
710
+ }
711
+ else {
712
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess waiting events - waiting', data: Object.assign({}, waiting), status: types_1.LogEventStatus.WAITING }));
713
+ }
714
+ });
715
+ return Promise.all(promises);
716
+ }
717
+ catch (e) {
718
+ throw e;
719
+ }
635
720
  }
636
721
  checkDependentsSuccess(dependants) {
637
722
  let pass = true;
@@ -661,6 +746,12 @@ class ProcessorService {
661
746
  if (input.data) {
662
747
  dependents.push(...this.fetchDependents(input.data, additional_logs));
663
748
  }
749
+ if (input.fileName) {
750
+ dependents.push(...this.valueStringDepsCheck(input.fileName));
751
+ }
752
+ if (input.buffer) {
753
+ dependents.push(...this.valueStringDepsCheck(input.buffer));
754
+ }
664
755
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch request dependencies - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), dependents }, status: types_1.LogEventStatus.SUCCESS }));
665
756
  return dependents;
666
757
  }
@@ -685,6 +776,20 @@ class ProcessorService {
685
776
  event_tag: stages[1],
686
777
  });
687
778
  }
779
+ else if (values[i].startsWith('$')) {
780
+ const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(values[i]);
781
+ if (funcArgs.args.length) {
782
+ funcArgs.args.map((arg) => {
783
+ if (arg.startsWith('$Sequence')) {
784
+ const stages = this.productBuilderService.extractStages(arg);
785
+ dependants.push({
786
+ sequence_tag: stages[0],
787
+ event_tag: stages[1],
788
+ });
789
+ }
790
+ });
791
+ }
792
+ }
688
793
  }
689
794
  }
690
795
  else {
@@ -692,10 +797,7 @@ class ProcessorService {
692
797
  }
693
798
  }
694
799
  else if (typeof value === 'string') {
695
- if (value.startsWith('$Sequence')) {
696
- const stages = this.productBuilderService.extractStages(value);
697
- dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
698
- }
800
+ dependants.push(...this.valueStringDepsCheck(value.trim()));
699
801
  }
700
802
  }
701
803
  return dependants;
@@ -705,6 +807,34 @@ class ProcessorService {
705
807
  throw e;
706
808
  }
707
809
  }
810
+ valueStringDepsCheck(value) {
811
+ const dependants = [];
812
+ if (value.startsWith('$Sequence')) {
813
+ const stages = this.productBuilderService.extractStages(value);
814
+ dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
815
+ }
816
+ else if (value.startsWith('$')) {
817
+ const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(value);
818
+ if (funcArgs && funcArgs.args.length) {
819
+ funcArgs.args.map((arg) => {
820
+ if (arg.startsWith('$Sequence')) {
821
+ const stages = this.productBuilderService.extractStages(arg);
822
+ dependants.push({
823
+ sequence_tag: stages[0],
824
+ event_tag: stages[1],
825
+ });
826
+ }
827
+ else {
828
+ const args = arg.split(',');
829
+ args.map((arg) => {
830
+ dependants.push(...this.valueStringDepsCheck(arg.trim()));
831
+ });
832
+ }
833
+ });
834
+ }
835
+ }
836
+ return dependants;
837
+ }
708
838
  async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
709
839
  try {
710
840
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Construct JSON payloads - initiated', data: { object, samples }, status: types_1.LogEventStatus.PROCESSING }));
@@ -861,7 +991,7 @@ class ProcessorService {
861
991
  return await this.sumValues(value, app, additional_logs, sample, index, key, loopIndex);
862
992
  }
863
993
  else if (value.startsWith('$Substract(') && value.endsWith(')')) {
864
- return await this.sumValues(value, app, additional_logs, sample, index, key, loopIndex);
994
+ return await this.subtractValues(value, app, additional_logs, sample, index, key, loopIndex);
865
995
  }
866
996
  else if (value.startsWith('$Pick(') && value.endsWith(')')) {
867
997
  return await this.pickValue(value, app, additional_logs, sample, index, key, loopIndex);
@@ -1253,7 +1383,7 @@ class ProcessorService {
1253
1383
  }
1254
1384
  }
1255
1385
  decorateValue(value, sample) {
1256
- if (sample.decorator) {
1386
+ if (sample && sample.decorator) {
1257
1387
  if (sample.decoratorPosition &&
1258
1388
  sample.decoratorPosition == types_1.DecoratorPostions.APPEND &&
1259
1389
  !value.endsWith(sample.decorator)) {
@@ -1349,12 +1479,14 @@ class ProcessorService {
1349
1479
  return this.runFallback(event as unknown as IFallbackEvent);
1350
1480
  }*/
1351
1481
  if (event.type === types_1.FeatureEventTypes.ACTION) {
1482
+ console.log("APP AND EVENT!!!!", event.app);
1352
1483
  const additional_logs = {
1353
- parent_tag: (0, string_utils_1.extractOriginAndTag)(event.app),
1484
+ parent_tag: event.app,
1354
1485
  child_tag: event.event,
1355
1486
  type: types_1.LogEventTypes.ACTION,
1356
1487
  name: 'Process feature action',
1357
1488
  };
1489
+ console.log("EVENTER!!!!!!===>>>>>>", event);
1358
1490
  return this.runAction(event, additional_logs);
1359
1491
  }
1360
1492
  if (event.type === types_1.FeatureEventTypes.DB_ACTION) {
@@ -1378,8 +1510,12 @@ class ProcessorService {
1378
1510
  return this.runStorage(event, additional_logs);
1379
1511
  }
1380
1512
  if (event.type === types_1.FeatureEventTypes.FEATURE) {
1381
- // this.processFeature({})
1382
- // this.processFeature TODO: do some processing to get this to reuse this.processFeature from abov
1513
+ const additional_logs = {
1514
+ parent_tag: event.event,
1515
+ type: types_1.LogEventTypes.FEATURE,
1516
+ name: 'Process sub-feature',
1517
+ };
1518
+ return this.runFeature(event, additional_logs);
1383
1519
  }
1384
1520
  if (event.type === types_1.FeatureEventTypes.NOTIFICATION) {
1385
1521
  const [parent_tag, child_tag] = event.event.split(':');
@@ -1400,11 +1536,9 @@ class ProcessorService {
1400
1536
  name: 'Process feature broker event',
1401
1537
  };
1402
1538
  try {
1403
- console.log("GRENADYE ALASOOOO!");
1404
1539
  return this.runBrokerPublish(event, additional_logs);
1405
1540
  }
1406
1541
  catch (e) {
1407
- console.log("GRENADYE ALASOOOO!!!!");
1408
1542
  }
1409
1543
  }
1410
1544
  if (event.type === types_1.FeatureEventTypes.JOB) {
@@ -1420,13 +1554,30 @@ class ProcessorService {
1420
1554
  throw e;
1421
1555
  }
1422
1556
  }
1557
+ async runFeature(event, additional_logs) {
1558
+ const freshInstance = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
1559
+ const result = await freshInstance.processFeature({
1560
+ product: this.productTag,
1561
+ tag: event.event,
1562
+ env: this.processEnv.slug,
1563
+ input: event.input,
1564
+ }, true);
1565
+ const output = await freshInstance.generateOutput(result.process_id);
1566
+ if (output.status === types_1.LogEventStatus.FAIL) {
1567
+ await this.addToFailureOutput(output.errors, event, { process_id: result.process_id }, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
1568
+ }
1569
+ else if (output.status === types_1.LogEventStatus.SUCCESS) {
1570
+ await this.addToSuccessOutput(event, output.data, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
1571
+ }
1572
+ return output;
1573
+ }
1423
1574
  runJob(event, additional_logs) {
1424
1575
  throw new Error('Method not implemented.');
1425
1576
  }
1426
1577
  async processFailedAndWaiting() { }
1427
1578
  async generateOutput(process_id) {
1428
1579
  var _a, _b, _c, _d;
1429
- const result = (await this.processorApiService.fetchResult(process_id, this.getUserAccess()));
1580
+ const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
1430
1581
  if (!result) {
1431
1582
  throw new Error(`Invalid process id ${process_id}`);
1432
1583
  }
@@ -1452,7 +1603,7 @@ class ProcessorService {
1452
1603
  return { process_id, status: result.status, errors };
1453
1604
  }
1454
1605
  }
1455
- else {
1606
+ else if (result) {
1456
1607
  if ((_a = result.result.success[0]) === null || _a === void 0 ? void 0 : _a.output) {
1457
1608
  return { process_id, status: result.status, data: (_b = result.result.success[0]) === null || _b === void 0 ? void 0 : _b.output };
1458
1609
  }
@@ -1492,7 +1643,7 @@ class ProcessorService {
1492
1643
  // validate feature input and log failure
1493
1644
  this.validateJSONFeatureInput(result.input.input, featureInput, additional_logs);
1494
1645
  // split processes
1495
- this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
1646
+ this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
1496
1647
  await this.processSequenceLevels(additional_logs);
1497
1648
  }
1498
1649
  else {
@@ -1534,7 +1685,7 @@ class ProcessorService {
1534
1685
  // validate feature input and log failure
1535
1686
  this.validateJSONFeatureInput(result.input.input, featureInput, additional_logs);
1536
1687
  // split processes
1537
- this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
1688
+ this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
1538
1689
  await this.processSequenceLevels(additional_logs);
1539
1690
  }
1540
1691
  else {
@@ -1547,19 +1698,19 @@ class ProcessorService {
1547
1698
  await this.processEvent(event);
1548
1699
  this.end = Date.now();
1549
1700
  this.writeResult(types_1.LogEventStatus.SUCCESS);
1550
- this.logService.publish();
1701
+ await this.logService.publish();
1551
1702
  }
1552
1703
  return { process_id };
1553
1704
  }
1554
- fetchLevelEvents(level) {
1705
+ fetchLevelEvents(sequence, level) {
1555
1706
  const events = [];
1556
- for (let i = 0; i < level.length; i++) {
1557
- events.push(...this.appendSequenceDataToLevelEvents(level[i]));
1707
+ for (let i = 0; i < sequence.length; i++) {
1708
+ events.push(...this.appendSequenceDataToLevelEvents(sequence[i], level));
1558
1709
  }
1559
1710
  return events;
1560
1711
  }
1561
- appendSequenceDataToLevelEvents(sequence) {
1562
- const { events, level, tag } = sequence;
1712
+ appendSequenceDataToLevelEvents(sequence, level) {
1713
+ const { events, tag } = sequence;
1563
1714
  for (let i = 0; i < events.length; i++) {
1564
1715
  events[i].sequence_level = level;
1565
1716
  events[i].sequence_tag = tag;
@@ -1688,15 +1839,13 @@ class ProcessorService {
1688
1839
  // generate indexes
1689
1840
  return (0, processor_utils_1.generateIndexes)(operator, iter, init, valueValue);
1690
1841
  }
1691
- async runAction(event, additional_logs, returnValue = false) {
1842
+ async runAction(event, additional_logs, returnValue = true) {
1692
1843
  try {
1693
- console.log("RUNNING ACTION!!!!!");
1694
1844
  const { event: action_tag, app: access_tag, condition, cache: cache_tag } = event;
1695
1845
  let indexes = [];
1696
1846
  if (condition &&
1697
1847
  condition.type === types_1.Conditions.CHECK &&
1698
1848
  (await this.processConditionalCheck(event, additional_logs))) {
1699
- console.log("RUNNING ACTION SKIPPED!!!!!");
1700
1849
  // if it fails, it would add to skipped queue
1701
1850
  return;
1702
1851
  }
@@ -1704,6 +1853,7 @@ class ProcessorService {
1704
1853
  indexes = await this.extractLoopIndexes(event, additional_logs);
1705
1854
  }
1706
1855
  let app = await this.fetchThirdPartyApp(access_tag);
1856
+ console.log("RUNNING ACTION APP ====>>>>", app.envs, access_tag);
1707
1857
  const { actions, envs: appEnvs, retries, workspace_id: recipient_workspace_id, active } = app;
1708
1858
  const productApp = this.productBuilderService.fetchApp(access_tag);
1709
1859
  const { envs: productEnvs, version } = productApp;
@@ -1721,6 +1871,7 @@ class ProcessorService {
1721
1871
  throw new Error(`Action ${action_tag} not found in ${access_tag}`);
1722
1872
  }
1723
1873
  const { query, headers, body, params, request_type, method, base_url, resource } = action;
1874
+ console.log("BASE URLS!!!!!!", base_url, env.base_url);
1724
1875
  let request_base_url = base_url;
1725
1876
  if (env.base_url) {
1726
1877
  request_base_url = env.base_url;
@@ -1754,9 +1905,12 @@ class ProcessorService {
1754
1905
  }
1755
1906
  }
1756
1907
  }
1757
- if (request_type === types_1.DataFormats.JSON || !request_type) {
1908
+ if (request_type === types_1.DataFormats.JSON || request_type === types_1.DataFormats.URLENCODED || !request_type) {
1758
1909
  if (indexes.length == 0) {
1759
1910
  payloads = await this.constructJSONDataPayloads(event.input, additional_logs, samples, event);
1911
+ if (request_type === types_1.DataFormats.URLENCODED) {
1912
+ payloads.body = (0, processor_utils_1.toFormUrlEncoded)(payloads.body);
1913
+ }
1760
1914
  additional_logs.recipient_workspace_id = recipient_workspace_id;
1761
1915
  result = await this.processRequest({ request_base_url, resource, method, env, payloads, app_id: app._id }, event, retries, additional_logs, returnValue);
1762
1916
  }
@@ -1802,6 +1956,8 @@ class ProcessorService {
1802
1956
  try {
1803
1957
  const results = await this.sendActionRequest(request_base_url, resource, payloads, method, env.slug);
1804
1958
  const end = Date.now();
1959
+ this.requestTime += end - start;
1960
+ this.totalRequests += 1;
1805
1961
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - success', successful_execution: true, data: { response: (0, processor_utils_1.anonymizeObject)(results) }, status: types_1.LogEventStatus.SUCCESS, app_id, action: event.event, start,
1806
1962
  end }));
1807
1963
  await this.addToSuccessOutput(event, results, additional_logs);
@@ -1814,10 +1970,12 @@ class ProcessorService {
1814
1970
  }
1815
1971
  catch (e) {
1816
1972
  const end = Date.now();
1973
+ this.requestTime += end - start;
1974
+ this.totalRequests += 1;
1817
1975
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - failed', failed_execution: true, data: { e }, status: types_1.LogEventStatus.FAIL, app_id, action: event.event, start,
1818
1976
  end }));
1819
1977
  try {
1820
- const value = this.addToFailureOutput(e, event, {
1978
+ const value = await this.addToFailureOutput(e, event, {
1821
1979
  request_base_url,
1822
1980
  resource,
1823
1981
  method,
@@ -1858,7 +2016,7 @@ class ProcessorService {
1858
2016
  }
1859
2017
  // addToSkippedOutput()
1860
2018
  }
1861
- addToFailureOutput(e, event, payload, additional_logs, policy = {}) {
2019
+ async addToFailureOutput(e, event, payload, additional_logs, policy = {}) {
1862
2020
  try {
1863
2021
  const exists = this.processingOutput.failure.findIndex((item) => {
1864
2022
  if (item.event.sequence_tag) {
@@ -1917,11 +2075,16 @@ class ProcessorService {
1917
2075
  }, retry_at);
1918
2076
  }
1919
2077
  if (allow_fail === false && retries_left === 0) {
2078
+ if (this.feature) {
2079
+ additional_logs.failed_feature_execution = true;
2080
+ }
1920
2081
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Ran out of retries - failed', data: Object.assign(Object.assign({}, output), { payload: (0, processor_utils_1.anonymizeObject)(output.payload) }), status: types_1.LogEventStatus.FAIL }));
1921
2082
  //throw new Error("Run out of retries")
1922
2083
  this.end = Date.now();
1923
2084
  this.writeResult(types_1.LogEventStatus.FAIL);
1924
- this.logService.publish();
2085
+ await this.logService.publish();
2086
+ this.published = true;
2087
+ //throw new Error("Terminate Process")
1925
2088
  }
1926
2089
  return output;
1927
2090
  }
@@ -1988,20 +2151,24 @@ class ProcessorService {
1988
2151
  }
1989
2152
  }
1990
2153
  const authHeaders = headers;
2154
+ if (!base_url.endsWith('/') && !resource.startsWith('/')) {
2155
+ base_url = base_url + '/';
2156
+ }
1991
2157
  const request = {
1992
2158
  url: resource,
1993
2159
  method,
2160
+ baseURL: base_url,
1994
2161
  data: body,
1995
2162
  params: query,
1996
2163
  headers: authHeaders,
2164
+ timeout: 15000,
2165
+ withCredentials: false
1997
2166
  };
1998
- if (!base_url.endsWith('/') && !resource.startsWith('/')) {
1999
- base_url = base_url + '/';
2000
- }
2001
- const response = await (0, http_client_1.default)(base_url).request(request);
2167
+ const response = await axios_1.default.request(request);
2002
2168
  return response.data;
2003
2169
  }
2004
2170
  catch (e) {
2171
+ console.error("LOG ERROR", e);
2005
2172
  throw e;
2006
2173
  }
2007
2174
  }
@@ -2046,13 +2213,13 @@ class ProcessorService {
2046
2213
  this.end = Date.now();
2047
2214
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - success', data: { input: this.clone, result }, status: types_1.LogEventStatus.SUCCESS }));
2048
2215
  this.writeResult(types_1.LogEventStatus.SUCCESS);
2049
- this.logService.publish();
2216
+ await this.logService.publish();
2050
2217
  return result;
2051
2218
  }
2052
2219
  catch (e) {
2053
2220
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2054
2221
  this.end = Date.now();
2055
- this.logService.publish();
2222
+ await this.logService.publish();
2056
2223
  return { process_id: this.process_id };
2057
2224
  }
2058
2225
  }
@@ -2095,13 +2262,13 @@ class ProcessorService {
2095
2262
  this.end = Date.now();
2096
2263
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Subscribe to topic - success', data: { input: this.clone, result }, status: types_1.LogEventStatus.SUCCESS }));
2097
2264
  this.writeResult(types_1.LogEventStatus.SUCCESS);
2098
- this.logService.publish();
2265
+ await this.logService.publish();
2099
2266
  return result;
2100
2267
  }
2101
2268
  catch (e) {
2102
2269
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Subscribe to topic - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2103
2270
  this.end = Date.now();
2104
- this.logService.publish();
2271
+ await this.logService.publish();
2105
2272
  return { process_id: this.process_id };
2106
2273
  }
2107
2274
  }
@@ -2118,7 +2285,6 @@ class ProcessorService {
2118
2285
  };
2119
2286
  try {
2120
2287
  this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
2121
- console.log("JAPANESE MIRRORS", data.input);
2122
2288
  this.start = Date.now();
2123
2289
  // clone
2124
2290
  this.clone = (0, processor_utils_1.structuredClone)(data.input);
@@ -2132,7 +2298,6 @@ class ProcessorService {
2132
2298
  this.process_id = process_id;
2133
2299
  const productEnv = this.fetchEnv(data.env, additional_logs);
2134
2300
  this.processEnv = productEnv;
2135
- console.log("JAPANESE MIRRORS 2", productEnv);
2136
2301
  if (!productEnv.active) {
2137
2302
  throw new Error(`Environment ${data.env} is not active`);
2138
2303
  }
@@ -2150,14 +2315,13 @@ class ProcessorService {
2150
2315
  this.end = Date.now();
2151
2316
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publishing to topic - success', data: { input: (0, processor_utils_1.anonymizeObject)(this.clone), result }, status: types_1.LogEventStatus.SUCCESS }));
2152
2317
  this.writeResult(types_1.LogEventStatus.SUCCESS);
2153
- this.logService.publish();
2318
+ await this.logService.publish();
2154
2319
  return result;
2155
2320
  }
2156
2321
  catch (e) {
2157
- console.log(e);
2158
2322
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publishing to topic - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2159
2323
  this.end = Date.now();
2160
- this.logService.publish();
2324
+ await this.logService.publish();
2161
2325
  return { process_id: this.process_id };
2162
2326
  }
2163
2327
  }
@@ -2170,7 +2334,6 @@ class ProcessorService {
2170
2334
  body: payload.body,
2171
2335
  data: (0, processor_utils_1.convertStringToObject)(payload.data),
2172
2336
  };
2173
- console.log("MESSAGE!!!", message);
2174
2337
  try {
2175
2338
  await (0, expo_client_1.default)().post('', message, (0, processor_utils_1.generateAxiosConfig)());
2176
2339
  }
@@ -2189,7 +2352,6 @@ class ProcessorService {
2189
2352
  try {
2190
2353
  const admin = require('firebase-admin');
2191
2354
  const serviceAccount = credentials;
2192
- console.log("MESSAGE", message);
2193
2355
  admin.initializeApp({
2194
2356
  credential: admin.credential.cert(serviceAccount),
2195
2357
  });
@@ -2320,11 +2482,6 @@ class ProcessorService {
2320
2482
  const url = new URL(callbacks.url);
2321
2483
  try {
2322
2484
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send callback - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2323
- console.log("CALLBACK!!!!", {
2324
- url,
2325
- payload,
2326
- method: callbacks.method
2327
- });
2328
2485
  await this.sendActionRequest(url.origin, url.pathname, payload, callbacks.method, '');
2329
2486
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send callback - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2330
2487
  }
@@ -2339,7 +2496,6 @@ class ProcessorService {
2339
2496
  const SmsClient = await (0, sms_repo_1.loadSMSClient)();
2340
2497
  const smsClient = new SmsClient(smses);
2341
2498
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - initiated', data: { message: input.sms.body, config: (0, processor_utils_1.anonymizeObject)(smses) }, status: types_1.LogEventStatus.SUCCESS }));
2342
- console.log("SMS!!!!", input.sms, smses);
2343
2499
  const res = await smsClient.sendMessage(input.sms.body, input.sms.recipients);
2344
2500
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - success', data: res, status: types_1.LogEventStatus.SUCCESS }));
2345
2501
  }
@@ -2350,9 +2506,8 @@ class ProcessorService {
2350
2506
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Attempt notification - success', data: notification, status: types_1.LogEventStatus.SUCCESS }));
2351
2507
  }
2352
2508
  catch (e) {
2353
- console.log(e);
2354
2509
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt notification - failed', data: { e: e.toString() }, status: types_1.LogEventStatus.FAIL }));
2355
- //this.logService.publish();
2510
+ //await this.logService.publish();
2356
2511
  throw e;
2357
2512
  }
2358
2513
  }
@@ -2431,9 +2586,8 @@ class ProcessorService {
2431
2586
  }
2432
2587
  }
2433
2588
  catch (e) {
2434
- console.log(e);
2435
2589
  this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { failed_execution: true, message: 'Attempt migration - failed', data: e, status: types_1.LogEventStatus.FAIL }));
2436
- this.logService.publish();
2590
+ await this.logService.publish();
2437
2591
  }
2438
2592
  }
2439
2593
  /*async runFunction(data: IFeatureEvent, additional_logs: Partial<ILogData>): Promise<any> {
@@ -2526,7 +2680,7 @@ class ProcessorService {
2526
2680
  data: e,
2527
2681
  status: LogEventStatus.FAIL,
2528
2682
  });
2529
- this.logService.publish();
2683
+ await this.logService.publish();
2530
2684
  }
2531
2685
  }*/
2532
2686
  async runStorage(data, additional_logs = {}) {
@@ -2566,7 +2720,6 @@ class ProcessorService {
2566
2720
  input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
2567
2721
  input.fileName = input.fileName ? await this.generateStringValues(input.fileName, '', additional_logs, []) : undefined;
2568
2722
  input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
2569
- console.log("CHINYERE", input.buffer, input.fileName);
2570
2723
  result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
2571
2724
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Store file - success', data: { result }, status: types_1.LogEventStatus.PROCESSING }));
2572
2725
  if (cache_tag && this.redisClient) {
@@ -2589,7 +2742,6 @@ class ProcessorService {
2589
2742
  return result;
2590
2743
  }
2591
2744
  catch (e) {
2592
- console.log(e);
2593
2745
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt storage - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2594
2746
  throw e;
2595
2747
  }
@@ -2668,8 +2820,6 @@ class ProcessorService {
2668
2820
  if (!MongoDBHandler) {
2669
2821
  throw new Error(`Running in browser, mongo handler not loaded.`);
2670
2822
  }
2671
- console.log("PRIVATE KEY!!!", this.productBuilderService.fetchProduct().private_key);
2672
- console.log("AMAZONS", (0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchProduct().private_key));
2673
2823
  const mongoHandler = new MongoDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchProduct().private_key));
2674
2824
  if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
2675
2825
  const filterTemplate = typeof databaseAction.filterTemplate === 'string'
@@ -2691,7 +2841,7 @@ class ProcessorService {
2691
2841
  result = await pgHandler[databaseAction.type](databaseAction.data, template, input.data);
2692
2842
  }
2693
2843
  }
2694
- //this.logService.publish();
2844
+ //await this.logService.publish();
2695
2845
  // const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
2696
2846
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Run database action query - success', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
2697
2847
  await this.addToSuccessOutput(db_action, result, additional_logs);
@@ -2817,7 +2967,6 @@ class ProcessorService {
2817
2967
  }
2818
2968
  catch (e) {
2819
2969
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt publish to broker topic - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2820
- console.log("JERMOOOOO!!!");
2821
2970
  throw e;
2822
2971
  }
2823
2972
  }
@@ -2854,7 +3003,7 @@ class ProcessorService {
2854
3003
  }
2855
3004
  catch (e) {
2856
3005
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Run storage request - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2857
- const value = this.addToFailureOutput(e, data, { storageEnv }, additional_logs);
3006
+ const value = await this.addToFailureOutput(e, data, { storageEnv }, additional_logs);
2858
3007
  throw e;
2859
3008
  }
2860
3009
  }
@@ -2877,7 +3026,7 @@ class ProcessorService {
2877
3026
  }
2878
3027
  catch (e) {
2879
3028
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Running database query - failed', data: { payload: (0, processor_utils_1.anonymizeObject)(input), e }, status: types_1.LogEventStatus.FAIL }));
2880
- const value = this.addToFailureOutput(e, db_action, {
3029
+ const value = await this.addToFailureOutput(e, db_action, {
2881
3030
  db_action,
2882
3031
  input,
2883
3032
  database_tag,
@@ -2962,18 +3111,17 @@ class ProcessorService {
2962
3111
  retries: retries || 0,
2963
3112
  allow_fail: false,
2964
3113
  }, additional_logs, true);
2965
- console.log("RESULT ===>>>>", result);
2966
3114
  this.end = Date.now();
2967
3115
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
2968
3116
  this.writeResult(types_1.LogEventStatus.SUCCESS);
2969
- this.logService.publish();
3117
+ await this.logService.publish();
2970
3118
  return result;
2971
3119
  }
2972
3120
  catch (e) {
2973
3121
  console.log(e);
2974
3122
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2975
3123
  this.end = Date.now();
2976
- this.logService.publish();
3124
+ await this.logService.publish();
2977
3125
  return { process_id: this.process_id };
2978
3126
  }
2979
3127
  }
@@ -3021,13 +3169,13 @@ class ProcessorService {
3021
3169
  this.end = Date.now();
3022
3170
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
3023
3171
  this.writeResult(types_1.LogEventStatus.SUCCESS);
3024
- this.logService.publish();
3172
+ await this.logService.publish();
3025
3173
  return result;
3026
3174
  }
3027
3175
  catch (e) {
3028
3176
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { e }, status: types_1.LogEventStatus.FAIL }));
3029
3177
  this.end = Date.now();
3030
- this.logService.publish();
3178
+ await this.logService.publish();
3031
3179
  return { process_id: this.process_id };
3032
3180
  }
3033
3181
  }
@@ -3076,13 +3224,13 @@ class ProcessorService {
3076
3224
  this.end = Date.now();
3077
3225
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send notification - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
3078
3226
  this.writeResult(types_1.LogEventStatus.SUCCESS);
3079
- this.logService.publish();
3227
+ await this.logService.publish();
3080
3228
  return { process_id };
3081
3229
  }
3082
3230
  catch (e) {
3083
3231
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send notification - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
3084
3232
  this.end = Date.now();
3085
- this.logService.publish();
3233
+ await this.logService.publish();
3086
3234
  return { process_id: this.process_id };
3087
3235
  }
3088
3236
  }