@ductape/sdk 0.0.4-v4 → 0.0.4-v5

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.
@@ -301,7 +301,6 @@ class ProcessorService {
301
301
  throw new Error(`Quota ${quota_tag} not found`);
302
302
  }
303
303
  this.logService.setFeatureId(this.quota._id);
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 }));
305
304
  this.processEnv = this.fetchEnv(env, additional_logs);
306
305
  if (!this.processEnv.active) {
307
306
  throw new Error(`Environment ${data.env} is not active`);
@@ -311,6 +310,7 @@ class ProcessorService {
311
310
  this.validateJSONFeatureInput(input, quotaInput, additional_logs);
312
311
  // split processes
313
312
  //this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
313
+ await this.logService.publish();
314
314
  return await this.runQuotaOptions(options, input, additional_logs);
315
315
  }
316
316
  catch (e) {
@@ -320,17 +320,25 @@ class ProcessorService {
320
320
  }
321
321
  }
322
322
  async runQuotaOptions(options, input, additional_logs) {
323
- const quotaManager = new quota_service_1.default(options, this.redisClient);
324
- const getNextProvider = quotaManager.getNextProvider();
325
- const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
326
- return await this.processEvent({
327
- app: getNextProvider.app,
328
- type: getNextProvider.type,
329
- event: getNextProvider.event,
330
- input: quotaInput,
331
- retries: getNextProvider.retries,
332
- allow_fail: false
333
- });
323
+ try {
324
+ const quotaManager = new quota_service_1.default(options, this.redisClient);
325
+ const getNextProvider = quotaManager.getNextProvider();
326
+ const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
327
+ const result = await this.processEvent({
328
+ app: getNextProvider.app,
329
+ type: getNextProvider.type,
330
+ event: getNextProvider.event,
331
+ input: quotaInput,
332
+ retries: getNextProvider.retries,
333
+ allow_fail: false
334
+ });
335
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota successful', successful_execution: true, data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.PROCESSING }));
336
+ return result;
337
+ }
338
+ catch (e) {
339
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota failed', failed_execution: true, data: { e }, status: types_1.LogEventStatus.PROCESSING }));
340
+ throw e;
341
+ }
334
342
  }
335
343
  async mapQuotaFallbackInput(providerInput, quotaInput, app) {
336
344
  if (Array.isArray(providerInput)) {
@@ -420,7 +428,6 @@ class ProcessorService {
420
428
  throw new Error(`Fallback "${fallback_tag}" not found`);
421
429
  }
422
430
  this.logService.setFeatureId(this.fallback._id);
423
- 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 }));
424
431
  this.processEnv = this.fetchEnv(env, additional_logs);
425
432
  if (!this.processEnv.active) {
426
433
  throw new Error(`Environment ${data.env} is not active`);
@@ -470,7 +477,6 @@ class ProcessorService {
470
477
  feature_id: this.feature._id,
471
478
  };
472
479
  this.logService.setFeatureId(this.feature._id);
473
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process feature initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
474
480
  this.processEnv = this.fetchEnv(env, additional_logs);
475
481
  if (!this.processEnv.active) {
476
482
  throw new Error(`Environment ${data.env} is not active`);
@@ -502,13 +508,7 @@ class ProcessorService {
502
508
  }
503
509
  }
504
510
  async intializeProduct(additional_logs) {
505
- try {
506
- if (this.productTag) {
507
- await this.productBuilderService.initializeProductByTag(this.productTag); // validate product_exists
508
- }
509
- else {
510
- await this.productBuilderService.initializeProduct(this.productId);
511
- }
511
+ if (!this.logService) {
512
512
  this.logService = new logs_service_1.default({
513
513
  product_id: this.productId,
514
514
  workspace_id: this.workspace_id,
@@ -517,6 +517,14 @@ class ProcessorService {
517
517
  token: this.token,
518
518
  env_type: this.environment,
519
519
  });
520
+ }
521
+ try {
522
+ if (this.productTag) {
523
+ await this.productBuilderService.initializeProductByTag(this.productTag); // validate product_exists
524
+ }
525
+ else {
526
+ await this.productBuilderService.initializeProduct(this.productId);
527
+ }
520
528
  const { _id: product_id, workspace_id } = this.productBuilderService.fetchProduct();
521
529
  this.productId = product_id;
522
530
  if (workspace_id !== this.workspace_id) {
@@ -531,7 +539,6 @@ class ProcessorService {
531
539
  }
532
540
  fetchFeature(tag, additional_logs) {
533
541
  try {
534
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch feature - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
535
542
  const feature = this.productBuilderService.fetchFeature(tag); // validate feature exists
536
543
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch feature - success', data: { tag, feature }, status: types_1.LogEventStatus.SUCCESS }));
537
544
  return feature;
@@ -543,7 +550,6 @@ class ProcessorService {
543
550
  }
544
551
  fetchQuota(tag, additional_logs) {
545
552
  try {
546
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch quota - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
547
553
  const quota = this.productBuilderService.fetchQuota(tag); // validate feature exists
548
554
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch quota - success', data: { tag, quota }, status: types_1.LogEventStatus.SUCCESS }));
549
555
  return quota;
@@ -555,7 +561,6 @@ class ProcessorService {
555
561
  }
556
562
  fetchFallback(tag, additional_logs) {
557
563
  try {
558
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch fallback - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
559
564
  const fallback = this.productBuilderService.fetchFallback(tag); // validate feature exists
560
565
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch fallback - success', data: { tag, fallback }, status: types_1.LogEventStatus.SUCCESS }));
561
566
  return fallback;
@@ -567,7 +572,6 @@ class ProcessorService {
567
572
  }
568
573
  fetchEnv(env, additional_logs) {
569
574
  try {
570
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch environment - initiated', data: { slug: env }, status: types_1.LogEventStatus.PROCESSING }));
571
575
  const product_env = this.productBuilderService.fetchEnv(env); // validate env exists
572
576
  if (!product_env) {
573
577
  throw new Error(`Env ${env} not found`);
@@ -582,7 +586,6 @@ class ProcessorService {
582
586
  }
583
587
  validateJSONFeatureInput(input, feature_input, additional_logs) {
584
588
  try {
585
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - initiated', data: { input: (0, processor_utils_1.anonymizeObject)(input), feature_input }, status: types_1.LogEventStatus.PROCESSING }));
586
589
  (0, processor_utils_1.validateFeatureJSONInput)(input, feature_input);
587
590
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
588
591
  }
@@ -593,7 +596,6 @@ class ProcessorService {
593
596
  }
594
597
  async splitSequenceIntoLevels(data, additional_logs) {
595
598
  try {
596
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
597
599
  const levels = {};
598
600
  const tagMap = new Map(data.map((seq) => [seq.tag, seq]));
599
601
  const assignedLevels = new Map();
@@ -630,7 +632,6 @@ class ProcessorService {
630
632
  }
631
633
  async processSequenceLevels(additional_logs) {
632
634
  try {
633
- 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 }));
634
635
  const levelEvents = {};
635
636
  Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
636
637
  levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
@@ -658,7 +659,6 @@ class ProcessorService {
658
659
  successful_feature_execution = true;
659
660
  }
660
661
  else if (this.processingFailure) {
661
- console.log("PROCESSING FAILURE", this.processingFailure);
662
662
  message = 'Process feature - processing';
663
663
  status = types_1.LogEventStatus.PROCESSING;
664
664
  successful_feature_execution = false;
@@ -674,7 +674,7 @@ class ProcessorService {
674
674
  return true;
675
675
  }
676
676
  catch (e) {
677
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process levels - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
677
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process sequence levels - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
678
678
  throw e;
679
679
  }
680
680
  }
@@ -702,7 +702,6 @@ class ProcessorService {
702
702
  const { failure } = this.processingOutput;
703
703
  const promises = failure.map((failed) => {
704
704
  if (failed.retries_left > 0 && new Date().getTime() > failed.retry_at) {
705
- 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 }));
706
705
  return this.processEvent(failed.event); // process events should also take care of this.processingOutput
707
706
  }
708
707
  if (failed.retries_left === 0 && !failed.allow_fail) {
@@ -747,7 +746,6 @@ class ProcessorService {
747
746
  }
748
747
  fetchActionRequestDependents(input, additional_logs) {
749
748
  try {
750
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch request dependencies - initialized', data: input, status: types_1.LogEventStatus.PROCESSING }));
751
749
  const dependents = [];
752
750
  if (input.query) {
753
751
  dependents.push(...this.fetchDependents(input.query, additional_logs));
@@ -779,7 +777,6 @@ class ProcessorService {
779
777
  }
780
778
  fetchDependents(obj, additional_logs) {
781
779
  try {
782
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch dependents - initiated', data: obj, status: types_1.LogEventStatus.PROCESSING }));
783
780
  const dependants = [];
784
781
  for (const key in obj) {
785
782
  const value = obj[key];
@@ -821,7 +818,6 @@ class ProcessorService {
821
818
  return dependants;
822
819
  }
823
820
  catch (e) {
824
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch dependents - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
825
821
  throw e;
826
822
  }
827
823
  }
@@ -855,7 +851,6 @@ class ProcessorService {
855
851
  }
856
852
  async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
857
853
  try {
858
- 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 }));
859
854
  const payload = {};
860
855
  const { body: actionBody, query: actionQuery, headers: actionHeaders, params: actionParams } = object;
861
856
  if (actionBody) {
@@ -912,7 +907,6 @@ class ProcessorService {
912
907
  }
913
908
  async generatePayload(obj, event, additional_logs, sample = [], index = {}, loopIndex = null) {
914
909
  try {
915
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate payload - initiated', data: { obj, event, sample }, status: types_1.LogEventStatus.PROCESSING }));
916
910
  const payload = {};
917
911
  const keys = Object.keys(obj);
918
912
  for (let i = 0; i < keys.length; i++) {
@@ -1432,7 +1426,6 @@ class ProcessorService {
1432
1426
  }
1433
1427
  async fetchAuthData(app_tag, additional_logs) {
1434
1428
  try {
1435
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching auth data - initiated', data: { app_tag, env: this.processEnv.slug }, status: types_1.LogEventStatus.PROCESSING }));
1436
1429
  const app = this.productBuilderService.fetchApp(app_tag);
1437
1430
  if (!app) {
1438
1431
  throw new Error(`App ${app_tag} not found in $Auth value`);
@@ -1591,12 +1584,19 @@ class ProcessorService {
1591
1584
  throw new Error('Method not implemented.');
1592
1585
  }
1593
1586
  async processFailedAndWaiting() { }
1594
- async generateOutput(process_id) {
1595
- var _a, _b, _c, _d;
1587
+ async fetchResult(process_id) {
1596
1588
  const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
1597
1589
  if (!result) {
1598
1590
  throw new Error(`Invalid process id ${process_id}`);
1599
1591
  }
1592
+ await this.productBuilderService.initializeProduct(result.product_id);
1593
+ result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchProduct().private_key));
1594
+ result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchProduct().private_key));
1595
+ return result;
1596
+ }
1597
+ async generateOutput(process_id) {
1598
+ var _a, _b, _c, _d;
1599
+ const result = await this.fetchResult(process_id);
1600
1600
  if (result.component === types_1.LogEventTypes.FEATURE) {
1601
1601
  const additional_logs = {
1602
1602
  parent_tag: result.input.tag,
@@ -1635,7 +1635,7 @@ class ProcessorService {
1635
1635
  }
1636
1636
  }
1637
1637
  async resumeProcess(process_id) {
1638
- const result = (await this.processorApiService.fetchResult(process_id, this.getUserAccess()));
1638
+ const result = await this.fetchResult(process_id);
1639
1639
  if (!result) {
1640
1640
  throw new Error(`Invalid process id ${process_id}`);
1641
1641
  }
@@ -1677,7 +1677,7 @@ class ProcessorService {
1677
1677
  }
1678
1678
  async replayProcess(process_id) {
1679
1679
  var _a, _b, _c;
1680
- const result = (await this.processorApiService.fetchResult(process_id, this.getUserAccess()));
1680
+ const result = await this.fetchResult(process_id);
1681
1681
  if (!result) {
1682
1682
  throw new Error(`Invalid process id ${process_id}`);
1683
1683
  }
@@ -1805,7 +1805,6 @@ class ProcessorService {
1805
1805
  }
1806
1806
  async processConditionalCheck(event, additional_logs = {}) {
1807
1807
  const parts = (0, string_utils_1.extractConditionalParts)(event.condition.check);
1808
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Check conditional - initiated', data: { condition: event.condition, parts }, status: types_1.LogEventStatus.PROCESSING, action: event.event }));
1809
1808
  const [, initiator, operator, value] = parts;
1810
1809
  const initiatorValue = await this.generateStringValues(initiator, event.app, additional_logs);
1811
1810
  let valueValue;
@@ -1817,7 +1816,6 @@ class ProcessorService {
1817
1816
  else {
1818
1817
  valueValue = value;
1819
1818
  }
1820
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate check conditional - initiated', data: { condition: { initiatorValue, operator, valueValue } }, status: types_1.LogEventStatus.PROCESSING, action: event.event }));
1821
1819
  const pass = (0, processor_utils_1.compareValues)(initiatorValue, operator, valueValue);
1822
1820
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate check condition - success', data: { condition: { initiatorValue, operator, valueValue }, pass }, status: types_1.LogEventStatus.SUCCESS, action: event.event }));
1823
1821
  if (!pass) {
@@ -1842,7 +1840,6 @@ class ProcessorService {
1842
1840
  }
1843
1841
  async extractLoopIndexes(event, additional_logs = {}) {
1844
1842
  const parts = (0, string_utils_1.extractConditionalParts)(event.condition.check);
1845
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Loop conditional - initiated', data: { condition: event.condition, parts }, status: types_1.LogEventStatus.PROCESSING, action: event.event }));
1846
1843
  const [, initiator, operator, value] = parts;
1847
1844
  let valueValue;
1848
1845
  if (!(0, string_utils_1.isNumeric)(value)) {
@@ -1913,10 +1910,10 @@ class ProcessorService {
1913
1910
  input: inputString,
1914
1911
  privateKey: product.private_key,
1915
1912
  expiry: productCache.expiry,
1916
- });
1913
+ }, additional_logs);
1917
1914
  if (check) {
1918
1915
  result = JSON.parse(check);
1919
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run action - return from cache', data: { result }, status: types_1.LogEventStatus.PROCESSING }));
1916
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run action - response from cache', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS, cache_tag, action: event.event }));
1920
1917
  if (returnValue) {
1921
1918
  return result;
1922
1919
  }
@@ -1955,18 +1952,17 @@ class ProcessorService {
1955
1952
  component_tag: action_tag,
1956
1953
  component_type: types_1.ProductComponents.ACTION,
1957
1954
  product_tag: this.productTag,
1958
- });
1955
+ }, additional_logs);
1959
1956
  }
1960
1957
  return result;
1961
1958
  }
1962
1959
  catch (e) {
1963
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Run Action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
1960
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run Action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
1964
1961
  throw e;
1965
1962
  }
1966
1963
  }
1967
1964
  async processRequest(payload, event, retries, additional_logs, returnValue = false) {
1968
1965
  const { request_base_url, resource, payloads, method, env, app_id } = payload;
1969
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - initiated', data: { request: (0, processor_utils_1.anonymizeObject)(payload) }, status: types_1.LogEventStatus.PROCESSING, app_id, action: event.event }));
1970
1966
  const start = Date.now();
1971
1967
  try {
1972
1968
  let results = (0, processor_utils_1.generateMockData)(resource, env.slug, payloads);
@@ -1988,11 +1984,16 @@ class ProcessorService {
1988
1984
  }
1989
1985
  catch (e) {
1990
1986
  const end = Date.now();
1987
+ let error = e;
1988
+ if (e.response.data) {
1989
+ error = e.response.data;
1990
+ }
1991
1991
  this.requestTime += end - start;
1992
1992
  this.totalRequests += 1;
1993
- 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,
1993
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - failed', failed_execution: true, data: { e: error, input: (0, processor_utils_1.anonymizeObject)(payloads) }, status: types_1.LogEventStatus.FAIL, app_id, action: event.event, start,
1994
1994
  end }));
1995
1995
  try {
1996
+ console.log(e);
1996
1997
  const value = await this.addToFailureOutput(e, event, {
1997
1998
  request_base_url,
1998
1999
  resource,
@@ -2022,6 +2023,9 @@ class ProcessorService {
2022
2023
  this.processingOutput.failure = this.processingOutput.failure.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
2023
2024
  this.processingOutput.skipped = this.processingOutput.skipped.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
2024
2025
  this.processingOutput.waiting = this.processingOutput.waiting.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
2026
+ if (event.type === types_1.FeatureEventTypes.STORAGE) {
2027
+ event = (0, processor_utils_1.cleanBlob)(event);
2028
+ }
2025
2029
  this.processingOutput.success.push({ event, output });
2026
2030
  await this.processWaitingEvents(additional_logs);
2027
2031
  if (this.checkIsSuccessful() && this.doneWithProcessing) {
@@ -2076,6 +2080,12 @@ class ProcessorService {
2076
2080
  max = metrices.max;
2077
2081
  }
2078
2082
  const { allow_fail, retries } = event;
2083
+ let retryable = true;
2084
+ if (event.type === types_1.FeatureEventTypes.STORAGE) {
2085
+ event = (0, processor_utils_1.cleanBlob)(event);
2086
+ if (!this.feature || (this.feature && !event.allow_fail))
2087
+ retryable = false;
2088
+ }
2079
2089
  let retries_left = retries || max;
2080
2090
  if (exists > -1) {
2081
2091
  retries_left = this.processingOutput.failure[exists].retries_left - 1;
@@ -2122,7 +2132,7 @@ class ProcessorService {
2122
2132
  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 }));
2123
2133
  //throw new Error("Run out of retries")
2124
2134
  this.end = Date.now();
2125
- await this.writeResult(types_1.LogEventStatus.FAIL);
2135
+ await this.writeResult(types_1.LogEventStatus.FAIL, retryable);
2126
2136
  await this.logService.publish();
2127
2137
  //throw new Error("Terminate Process")
2128
2138
  }
@@ -2239,7 +2249,6 @@ class ProcessorService {
2239
2249
  if (!productEnv.active) {
2240
2250
  throw new Error(`Environment ${env} is not active`);
2241
2251
  }
2242
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - initiated', status: types_1.LogEventStatus.PROCESSING, storage: new Blob([action.input.buffer]).size }));
2243
2252
  const payload = {
2244
2253
  type: types_1.FeatureEventTypes.STORAGE,
2245
2254
  event,
@@ -2254,7 +2263,7 @@ class ProcessorService {
2254
2263
  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 }));
2255
2264
  await this.writeResult(types_1.LogEventStatus.SUCCESS);
2256
2265
  await this.logService.publish();
2257
- return result;
2266
+ return Object.assign(Object.assign({}, result), { process_id: this.process_id });
2258
2267
  }
2259
2268
  catch (e) {
2260
2269
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
@@ -2341,7 +2350,6 @@ class ProcessorService {
2341
2350
  if (!productEnv.active) {
2342
2351
  throw new Error(`Environment ${data.env} is not active`);
2343
2352
  }
2344
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to topic - initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
2345
2353
  const payload = {
2346
2354
  type: types_1.FeatureEventTypes.PUBLISH,
2347
2355
  event: data.event,
@@ -2404,24 +2412,18 @@ class ProcessorService {
2404
2412
  }
2405
2413
  }
2406
2414
  async ProcessExpoNotification(notification, template, payload, additional_logs) {
2407
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate notification payload - initiated', data: { notification, payload: (0, processor_utils_1.anonymizeObject)(payload) }, status: types_1.LogEventStatus.PROCESSING }));
2408
2415
  (0, processor_utils_1.validateNotification)(template, payload);
2409
2416
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate notification payload - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2410
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate notification template - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2411
2417
  const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
2412
2418
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate notification template - success', data: { title, body, data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
2413
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Expo notification - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2414
2419
  await this.sendExpoNotification({ title, body, data }, payload.device_tokens);
2415
2420
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Expo notification - success', data: { title, body, data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
2416
2421
  }
2417
2422
  async ProcessFirebaseNotification(notification, template, payload, additional_logs) {
2418
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate Firebase notification payload - initiated', data: { notification, payload: (0, processor_utils_1.anonymizeObject)(payload) }, status: types_1.LogEventStatus.PROCESSING }));
2419
2423
  (0, processor_utils_1.validateNotification)(template, payload);
2420
2424
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate Firebase notification payload - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2421
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate Firebase notification template - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2422
2425
  const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
2423
2426
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate Firebase notification template - success', data: { title, body: (0, processor_utils_1.anonymizeObject)(data), data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
2424
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Firebase notification - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2425
2427
  await this.sendFirebaseNotification({ title, body, data }, payload.device_tokens, notification.credentials);
2426
2428
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Firebase notification - success', data: { title, body: (0, processor_utils_1.anonymizeObject)(data), data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
2427
2429
  }
@@ -2431,8 +2433,6 @@ class ProcessorService {
2431
2433
  const input = notification.input;
2432
2434
  try {
2433
2435
  //await this.intializeProduct(additional_logs);
2434
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempting notification', data: { notification }, status: types_1.LogEventStatus.PROCESSING }));
2435
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching notification details', data: { notification }, status: types_1.LogEventStatus.PROCESSING }));
2436
2436
  const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
2437
2437
  const message = this.productBuilderService.fetchNotificationMessage(event);
2438
2438
  if (!message) {
@@ -2452,15 +2452,23 @@ class ProcessorService {
2452
2452
  expected: types_1.ExpectedValues.PARSEINPUT,
2453
2453
  }));
2454
2454
  //await this.inputService.validateInput(validationPayload, message.push_notification_data, "Push Notifications");
2455
- if (push && notifications.type === types_1.Notifiers.FIREBASE) {
2456
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Processing Expo notification - initiated', data: { notification, input: (0, processor_utils_1.anonymizeObject)(input.push_notification) }, status: types_1.LogEventStatus.PROCESSING }));
2457
- await this.ProcessExpoNotification(notifications, message, input.push_notification, additional_logs);
2458
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Processing Expo notification - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2459
- }
2460
2455
  if (push && notifications.type === types_1.Notifiers.EXPO) {
2461
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Processing Firebase notification - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2462
- await this.ProcessFirebaseNotification(notifications, message, input.push_notification, additional_logs);
2463
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Processing Firebase notification - success', data: { notification, input: (0, processor_utils_1.anonymizeObject)(input.push_notification) }, status: types_1.LogEventStatus.SUCCESS }));
2456
+ try {
2457
+ await this.ProcessExpoNotification(notifications, message, input.push_notification, additional_logs);
2458
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Processing Expo notification - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2459
+ }
2460
+ catch (e) {
2461
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Processing Expo notification - failed', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2462
+ }
2463
+ }
2464
+ if (push && notifications.type === types_1.Notifiers.FIREBASE) {
2465
+ try {
2466
+ await this.ProcessFirebaseNotification(notifications, message, input.push_notification, additional_logs);
2467
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Processing Firebase notification - success', data: { notification, input: (0, processor_utils_1.anonymizeObject)(input.push_notification) }, status: types_1.LogEventStatus.SUCCESS }));
2468
+ }
2469
+ catch (e) {
2470
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Processing Firebase notification - failed', data: { notification, input: (0, processor_utils_1.anonymizeObject)(input.push_notification) }, status: types_1.LogEventStatus.FAIL }));
2471
+ }
2464
2472
  }
2465
2473
  if (email && emails) {
2466
2474
  input.email.subject = await this.generatePayload(input.email.subject, notification, additional_logs, message.email_data.filter((data) => data.parent_key === 'subject'));
@@ -2472,37 +2480,28 @@ class ProcessorService {
2472
2480
  }));
2473
2481
  //await this.inputService.validateInput(validationPayload, message.email_data);
2474
2482
  input.email.recipients.map((email) => this.inputService.validateEmailString({ key: 'to', value: email }));
2475
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process email - initiated', data: { email: (0, processor_utils_1.anonymizeObject)(email), input: (0, processor_utils_1.anonymizeObject)(input.email) }, status: types_1.LogEventStatus.PROCESSING }));
2476
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt email auth fetch - initiated', data: { emails: (0, processor_utils_1.anonymizeObject)(emails) }, status: types_1.LogEventStatus.PROCESSING }));
2477
2483
  const { sender_email: from } = emails, auth = __rest(emails, ["sender_email"]);
2478
2484
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt email auth fetch - success', data: { from: (0, processor_utils_1.anonymizeValue)(from), host: (0, processor_utils_1.anonymizeValue)(auth.host), port: (0, processor_utils_1.anonymizeValue)(auth.port) }, status: types_1.LogEventStatus.SUCCESS }));
2479
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - initiated', data: {
2480
- template: (0, processor_utils_1.anonymizeValue)(email.template),
2481
- subject: (0, processor_utils_1.anonymizeValue)(email.subject),
2482
- input: (0, processor_utils_1.anonymizeObject)(input.email),
2483
- }, status: types_1.LogEventStatus.PROCESSING }));
2484
2485
  const templateMaker = (0, handlebars_1.compile)(email.template);
2485
2486
  const template = templateMaker(input.email.template);
2486
2487
  const subject = (0, processor_utils_1.replacePlaceholderString)(email.subject, input.email.subject || {});
2487
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - success', data: { template: (0, processor_utils_1.anonymizeValue)(template), subject: (0, processor_utils_1.anonymizeValue)(subject) }, status: types_1.LogEventStatus.SUCCESS }));
2488
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - success', data: { template: (0, processor_utils_1.anonymizeValue)(template), subject: (0, processor_utils_1.anonymizeValue)(subject), input: (0, processor_utils_1.anonymizeObject)(input.email), }, status: types_1.LogEventStatus.SUCCESS }));
2488
2489
  const mailOptions = {
2489
2490
  from,
2490
2491
  to: input.email.recipients,
2491
2492
  subject,
2492
2493
  template,
2493
2494
  };
2494
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - initiated', data: { template: (0, processor_utils_1.anonymizeValue)(template), subject: (0, processor_utils_1.anonymizeValue)(subject), to: input.email.recipients.map((data) => (0, processor_utils_1.anonymizeValue)(data)) }, status: types_1.LogEventStatus.PROCESSING }));
2495
2495
  try {
2496
2496
  const transporter = await (0, processor_utils_1.mailerClient)(auth);
2497
2497
  const response = await transporter.sendMail(mailOptions);
2498
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - success', data: { response }, status: types_1.LogEventStatus.SUCCESS }));
2498
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - success', successful_execution: true, data: { response }, status: types_1.LogEventStatus.SUCCESS }));
2499
2499
  }
2500
2500
  catch (e) {
2501
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2501
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Send email - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2502
2502
  }
2503
2503
  }
2504
2504
  if (callback && callbacks) {
2505
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process callback - initiated', data: Object.assign(Object.assign({}, callbacks), { data: (0, processor_utils_1.anonymizeObject)(callback) }), status: types_1.LogEventStatus.PROCESSING }));
2506
2505
  const payload = {
2507
2506
  query: Object.assign(Object.assign({}, (_a = input.callback) === null || _a === void 0 ? void 0 : _a.query), (_b = callbacks.auth) === null || _b === void 0 ? void 0 : _b.query),
2508
2507
  headers: Object.assign(Object.assign({}, (_c = input.callback) === null || _c === void 0 ? void 0 : _c.headers), (_d = callbacks.auth) === null || _d === void 0 ? void 0 : _d.headers),
@@ -2518,32 +2517,29 @@ class ProcessorService {
2518
2517
  expected: types_1.ExpectedValues.PARSEINPUT,
2519
2518
  }));
2520
2519
  //this.inputService.validateInput(validationPayload, message.callback_data);
2521
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate callback payload - initiated', data: Object.assign(Object.assign({}, callbacks), { data: (0, processor_utils_1.anonymizeObject)(payload) }), status: types_1.LogEventStatus.PROCESSING }));
2522
2520
  const url = new URL(callbacks.url);
2523
2521
  try {
2524
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send callback - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2525
2522
  await this.sendActionRequest(url.origin, url.pathname, payload, callbacks.method, '');
2526
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send callback - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2523
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, name: 'Send callback - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2527
2524
  }
2528
2525
  catch (e) {
2529
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send callback - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2526
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Send callback - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2530
2527
  }
2531
2528
  }
2532
2529
  if (sms && smses) {
2533
2530
  try {
2534
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process sms - initiated', data: { data: sms, config: (0, processor_utils_1.anonymizeObject)(smses) }, status: types_1.LogEventStatus.PROCESSING }));
2535
2531
  input.sms.body = await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body);
2536
2532
  const SmsClient = await (0, sms_repo_1.loadSMSClient)();
2537
2533
  const smsClient = new SmsClient(smses);
2538
2534
  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 }));
2539
2535
  const res = await smsClient.sendMessage(input.sms.body, input.sms.recipients);
2540
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - success', data: res, status: types_1.LogEventStatus.SUCCESS }));
2536
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - success', successful_execution: true, data: res, status: types_1.LogEventStatus.SUCCESS }));
2541
2537
  }
2542
2538
  catch (e) {
2543
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process sms - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2539
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Process sms - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
2544
2540
  }
2545
2541
  }
2546
- 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 }));
2542
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt notification - success', data: notification, status: types_1.LogEventStatus.SUCCESS }));
2547
2543
  }
2548
2544
  catch (e) {
2549
2545
  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 }));
@@ -2728,8 +2724,6 @@ class ProcessorService {
2728
2724
  const input = data.input;
2729
2725
  try {
2730
2726
  await this.intializeProduct(additional_logs);
2731
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt storage - initiated', data: this.clone, status: types_1.LogEventStatus.PROCESSING }));
2732
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch storage details - initiated', data: this.clone, status: types_1.LogEventStatus.PROCESSING }));
2733
2727
  const storage = await this.productBuilderService.fetchStorage(event);
2734
2728
  const storageEnv = storage.envs.find((el) => el.slug === env.slug);
2735
2729
  if (!storageEnv) {
@@ -2749,19 +2743,17 @@ class ProcessorService {
2749
2743
  input: inputString,
2750
2744
  privateKey: product.private_key,
2751
2745
  expiry: productCache.expiry,
2752
- });
2746
+ }, additional_logs);
2753
2747
  if (check) {
2754
2748
  result = JSON.parse(check);
2755
2749
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Store file - return from cache', data: { result }, status: types_1.LogEventStatus.PROCESSING }));
2756
2750
  return result;
2757
2751
  }
2758
2752
  }
2759
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Store file - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2760
2753
  input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
2761
2754
  input.fileName = input.fileName ? await this.generateStringValues(input.fileName, '', additional_logs, []) : undefined;
2762
2755
  input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
2763
2756
  result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
2764
- 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 }));
2765
2757
  if (cache_tag && this.redisClient) {
2766
2758
  const productCache = this.productBuilderService.fetchCache(cache_tag);
2767
2759
  if (!productCache) {
@@ -2777,12 +2769,11 @@ class ProcessorService {
2777
2769
  component_tag: event,
2778
2770
  component_type: types_1.ProductComponents.STORAGE,
2779
2771
  product_tag: this.productTag,
2780
- });
2772
+ }, additional_logs);
2781
2773
  }
2782
2774
  return result;
2783
2775
  }
2784
2776
  catch (e) {
2785
- 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 }));
2786
2777
  throw e;
2787
2778
  }
2788
2779
  }
@@ -2791,8 +2782,6 @@ class ProcessorService {
2791
2782
  const input = db_action.input;
2792
2783
  try {
2793
2784
  //await this.intializeProduct(additional_logs);
2794
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt database action - initiated', data: db_action, status: types_1.LogEventStatus.PROCESSING }));
2795
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch database action - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2796
2785
  const [database_tag, action_tag] = event.split(':');
2797
2786
  const product = this.productBuilderService.fetchProduct();
2798
2787
  const database = await this.productBuilderService.fetchDatabase(database_tag);
@@ -2802,7 +2791,6 @@ class ProcessorService {
2802
2791
  throw new Error(`Database env for ${env.slug} not found`);
2803
2792
  }
2804
2793
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch database action - success', data: databaseAction, status: types_1.LogEventStatus.SUCCESS }));
2805
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database action payload - initiated', data: { payload: (0, processor_utils_1.anonymizeObject)(input.data) }, status: types_1.LogEventStatus.PROCESSING }));
2806
2794
  input.data = await this.generatePayload(input.data, db_action, additional_logs, databaseAction.data);
2807
2795
  if (Array.isArray(input.data)) {
2808
2796
  await Promise.all(input.data.map(async (d) => {
@@ -2830,11 +2818,9 @@ class ProcessorService {
2830
2818
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database action payload - success', data: { db_action, payload: (0, processor_utils_1.anonymizeObject)(input.data) }, status: types_1.LogEventStatus.SUCCESS }));
2831
2819
  if (database.type === types_1.DatabaseTypes.MONGODB) {
2832
2820
  if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
2833
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database update action filter - initiated', data: { filter: (0, processor_utils_1.anonymizeObject)(input.filter) }, status: types_1.LogEventStatus.PROCESSING }));
2834
2821
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database update action filter - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
2835
2822
  }
2836
2823
  }
2837
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run database action query - initiated', data: { payload: (0, processor_utils_1.anonymizeObject)(input) }, status: types_1.LogEventStatus.PROCESSING }));
2838
2824
  let result;
2839
2825
  if (cache_tag && this.redisClient) {
2840
2826
  const productCache = this.productBuilderService.fetchCache(cache_tag);
@@ -2847,7 +2833,7 @@ class ProcessorService {
2847
2833
  input: inputString,
2848
2834
  privateKey: product.private_key,
2849
2835
  expiry: productCache.expiry,
2850
- });
2836
+ }, additional_logs);
2851
2837
  if (check) {
2852
2838
  result = JSON.parse(check);
2853
2839
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run database action query - return from cache', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
@@ -2883,7 +2869,6 @@ class ProcessorService {
2883
2869
  }
2884
2870
  //await this.logService.publish();
2885
2871
  // const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
2886
- 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 }));
2887
2872
  await this.addToSuccessOutput(db_action, result, additional_logs);
2888
2873
  if (cache_tag && this.redisClient) {
2889
2874
  const productCache = this.productBuilderService.fetchCache(cache_tag);
@@ -2900,8 +2885,9 @@ class ProcessorService {
2900
2885
  product_tag: this.productTag,
2901
2886
  component_tag: database_tag,
2902
2887
  component_type: types_1.ProductComponents.DATABASE_ACTION,
2903
- });
2888
+ }, additional_logs);
2904
2889
  }
2890
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Attempt database action - successful', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
2905
2891
  return result;
2906
2892
  }
2907
2893
  catch (e) {
@@ -2914,8 +2900,6 @@ class ProcessorService {
2914
2900
  const input = data.input;
2915
2901
  try {
2916
2902
  await this.intializeProduct(additional_logs);
2917
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt broker topic subscription - initiated', data: { event }, status: types_1.LogEventStatus.PROCESSING }));
2918
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch broker details - initiated', data: { event }, status: types_1.LogEventStatus.PROCESSING }));
2919
2903
  const [brokerTag, topicTag] = event.split(':');
2920
2904
  const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
2921
2905
  if (!broker) {
@@ -2941,12 +2925,13 @@ class ProcessorService {
2941
2925
  url = queueUrl.url;
2942
2926
  }
2943
2927
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch broker details - success', data: { event, broker }, status: types_1.LogEventStatus.SUCCESS }));
2944
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Subscribe to broker topic - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2945
2928
  const createBrokerService = await loadBrokerService();
2946
2929
  if (createBrokerService) {
2947
2930
  const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
2948
2931
  await brokerService.subscribe(url, input.callback);
2949
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Subscribe to broker topic - success', data: { event }, status: types_1.LogEventStatus.SUCCESS }));
2932
+ if (this.feature) {
2933
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Subscribe to broker topic - success', data: { event }, status: types_1.LogEventStatus.SUCCESS }));
2934
+ }
2950
2935
  return;
2951
2936
  }
2952
2937
  else {
@@ -2964,8 +2949,6 @@ class ProcessorService {
2964
2949
  const input = data.input;
2965
2950
  try {
2966
2951
  await this.intializeProduct(additional_logs);
2967
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt publish to broker topic - initiated', data: { event }, status: types_1.LogEventStatus.PROCESSING }));
2968
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch broker details - initiated', data: { event }, status: types_1.LogEventStatus.PROCESSING }));
2969
2952
  const [brokerTag, topicTag] = event.split(':');
2970
2953
  const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
2971
2954
  if (!broker) {
@@ -2991,12 +2974,13 @@ class ProcessorService {
2991
2974
  url = queueUrl.url;
2992
2975
  }
2993
2976
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch broker details - success', data: { event, broker }, status: types_1.LogEventStatus.SUCCESS }));
2994
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to broker topic initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
2995
2977
  const createBrokerService = await loadBrokerService();
2996
2978
  if (createBrokerService) {
2997
2979
  const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
2998
2980
  await brokerService.publish(url, input.message);
2999
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to broker topic - success', successful_execution: true, data: { event }, status: types_1.LogEventStatus.SUCCESS }));
2981
+ if (this.feature) {
2982
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to broker topic - success', successful_execution: true, data: { event }, status: types_1.LogEventStatus.SUCCESS }));
2983
+ }
3000
2984
  return;
3001
2985
  }
3002
2986
  else {
@@ -3041,6 +3025,7 @@ class ProcessorService {
3041
3025
  url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchProduct().private_key),
3042
3026
  provider: storageEnv.type,
3043
3027
  product: this.productTag,
3028
+ process_id: this.process_id,
3044
3029
  workspace_id: this.workspace_id,
3045
3030
  type: input.mimeType,
3046
3031
  event: data.event,
@@ -3091,18 +3076,19 @@ class ProcessorService {
3091
3076
  return value;
3092
3077
  }
3093
3078
  }
3094
- async writeResult(status) {
3079
+ async writeResult(status, retryable = true) {
3095
3080
  this.processorApiService.saveResult({
3096
3081
  status,
3097
3082
  component: this.component,
3098
3083
  start: this.start,
3099
3084
  end: this.end,
3100
- result: this.processingOutput,
3085
+ retryable,
3086
+ result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchProduct().private_key),
3101
3087
  process_id: this.process_id,
3102
3088
  feature_id: this.feature ? this.feature._id : null,
3103
3089
  product_id: this.productId,
3104
3090
  env: this.processEnv.slug,
3105
- input: this.input,
3091
+ input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchProduct().private_key),
3106
3092
  }, this.getUserAccess());
3107
3093
  }
3108
3094
  async validateActionDataMappingInput(input, type) {
@@ -3155,7 +3141,6 @@ class ProcessorService {
3155
3141
  if (!productEnv.active) {
3156
3142
  throw new Error(`Environment ${env} is not active`);
3157
3143
  }
3158
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action initiated', status: types_1.LogEventStatus.PROCESSING }));
3159
3144
  const result = await this.runAction({
3160
3145
  type: types_1.FeatureEventTypes.ACTION,
3161
3146
  event,
@@ -3210,7 +3195,6 @@ class ProcessorService {
3210
3195
  if (!productEnv.active) {
3211
3196
  throw new Error(`Environment ${env} is not active`);
3212
3197
  }
3213
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { action: (0, processor_utils_1.anonymizeObject)(action) }, status: types_1.LogEventStatus.PROCESSING }));
3214
3198
  const payload = {
3215
3199
  type: types_1.FeatureEventTypes.DB_ACTION,
3216
3200
  event,
@@ -3265,7 +3249,6 @@ class ProcessorService {
3265
3249
  if (!productEnv.active) {
3266
3250
  throw new Error(`Environment ${env} is not active`);
3267
3251
  }
3268
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send notification - initiated', data: { action: (0, processor_utils_1.anonymizeObject)(action) }, status: types_1.LogEventStatus.PROCESSING }));
3269
3252
  const payload = {
3270
3253
  type: types_1.FeatureEventTypes.NOTIFICATION,
3271
3254
  event,
@@ -3309,7 +3292,7 @@ class ProcessorService {
3309
3292
  public_key: this.public_key,
3310
3293
  };
3311
3294
  }
3312
- async addToCache(payload) {
3295
+ async addToCache(payload, additional_logs) {
3313
3296
  if (!this.redisClient) {
3314
3297
  throw 'redis client not setup';
3315
3298
  }
@@ -3325,13 +3308,15 @@ class ProcessorService {
3325
3308
  product_tag,
3326
3309
  component_tag,
3327
3310
  component_type }), this.getUserAccess());
3311
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Renewing expired Cache Value', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
3328
3312
  await this.redisClient.hSet(key, 'data', encryptedData);
3329
3313
  await this.redisClient.hSet(key, 'lastUpdated', timestamp);
3330
3314
  }
3331
- async fetchFromCache(payload) {
3315
+ async fetchFromCache(payload, additional_logs) {
3332
3316
  var _a;
3333
3317
  const { input, privateKey, cache_tag, expiry } = payload;
3334
3318
  const key = `${cache_tag}-${CryptoJS.SHA512(input)}`;
3319
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching from Cache', data: { key }, status: types_1.LogEventStatus.PROCESSING, cache_tag }));
3335
3320
  if (!this.redisClient) {
3336
3321
  return null;
3337
3322
  }
@@ -3339,8 +3324,10 @@ class ProcessorService {
3339
3324
  if (!record || !record.data || !record.lastUpdated) {
3340
3325
  const checkRemote = await this.processorApiService.fetchRemoteCacheByKey(key, this.getUserAccess());
3341
3326
  if (!checkRemote) {
3327
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Remote Cache Not Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.FAIL, cache_tag }));
3342
3328
  return null;
3343
3329
  }
3330
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Remote Cache Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
3344
3331
  record = { data: checkRemote.value, expiresAt: (_a = checkRemote.expiry) === null || _a === void 0 ? void 0 : _a.getTime().toString() };
3345
3332
  }
3346
3333
  if (record.lastUpdated) {
@@ -3348,11 +3335,13 @@ class ProcessorService {
3348
3335
  if (expiry) {
3349
3336
  const expiryTime = lastUpdated + expiry;
3350
3337
  if (Date.now() > expiryTime) {
3338
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Deleting expired Cache Value', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
3351
3339
  await this.redisClient.del(key);
3352
3340
  return null;
3353
3341
  }
3354
3342
  }
3355
3343
  }
3344
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Cache Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
3356
3345
  return (0, processor_utils_1.decrypt)(record.data, privateKey);
3357
3346
  }
3358
3347
  }