@ductape/sdk 0.0.4-v33 → 0.0.4-v34

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.
@@ -139,9 +139,8 @@ class ProcessorService {
139
139
  // Fetch all products (or the current product if context is single-tenant)
140
140
  // For demo, we use the current product only
141
141
  await this.productBuilderService.initializeProductByTag(this.productTag);
142
- const product = this.productBuilderService.fetchProduct();
143
- const healthchecks = product.healthchecks || [];
144
- const privateKey = product.private_key;
142
+ const healthchecks = await this.productBuilderService.fetchProductHealthchecks();
143
+ const privateKey = this.productBuilderService.fetchPrivateKey();
145
144
  for (const healthcheck of healthchecks) {
146
145
  for (const env of healthcheck.envs) {
147
146
  // Each env gets its own worker (setInterval)
@@ -156,7 +155,7 @@ class ProcessorService {
156
155
  // Prepare action input
157
156
  const actionInput = {
158
157
  env: env.slug,
159
- product: product.tag,
158
+ product: this.productTag,
160
159
  app: healthcheck.app,
161
160
  input: decryptedInput,
162
161
  event: healthcheck.event,
@@ -179,9 +178,8 @@ class ProcessorService {
179
178
  */
180
179
  async processAllHealthchecksForProduct(productTag) {
181
180
  await this.productBuilderService.initializeProductByTag(productTag);
182
- const product = this.productBuilderService.fetchProduct();
183
- const healthchecks = product.healthchecks || [];
184
- const privateKey = product.private_key;
181
+ const healthchecks = await this.productBuilderService.fetchProductHealthchecks();
182
+ const privateKey = this.productBuilderService.fetchPrivateKey();
185
183
  for (const healthcheck of healthchecks) {
186
184
  for (const env of healthcheck.envs) {
187
185
  try {
@@ -191,7 +189,7 @@ class ProcessorService {
191
189
  }
192
190
  const actionInput = {
193
191
  env: env.slug,
194
- product: product.tag,
192
+ product: productTag,
195
193
  app: healthcheck.app,
196
194
  input: decryptedInput,
197
195
  event: healthcheck.event,
@@ -214,12 +212,12 @@ class ProcessorService {
214
212
  expected: types_1.ExpectedValues.PARSEINPUT,
215
213
  });
216
214
  await this.productBuilderService.initializeProductByTag(product_tag);
217
- // const product = this.productBuilderService.fetchProduct();
218
- const session = this.productBuilderService.fetchSession(tag);
215
+ const privateKey = this.productBuilderService.fetchPrivateKey();
216
+ const session = await this.productBuilderService.fetchSession(tag);
219
217
  if (!session) {
220
218
  throw new Error(`Session with tag ${tag} does not exist`);
221
219
  }
222
- const env = this.productBuilderService.fetchEnv(slug);
220
+ const env = await this.productBuilderService.fetchEnv(slug);
223
221
  if (!env) {
224
222
  throw new Error(`Env with slug ${slug} does not exist`);
225
223
  }
@@ -233,15 +231,15 @@ class ProcessorService {
233
231
  const JWT = await loadJWT();
234
232
  if (JWT) {
235
233
  const session_id = (0, uuid_1.v4)();
236
- const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, this.productBuilderService.fetchProduct().private_key, { expiresIn: expiry });
237
- const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.productBuilderService.fetchProduct().private_key);
234
+ const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, privateKey, { expiresIn: expiry });
235
+ const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), privateKey);
238
236
  // WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
239
237
  const details = {
240
238
  identifier: user,
241
239
  start_at: Date.now(),
242
240
  end_at,
243
241
  session_tag: tag,
244
- data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), this.productBuilderService.fetchProduct().private_key),
242
+ data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), privateKey),
245
243
  session_id
246
244
  };
247
245
  await this.processorApiService.createSessionInfo(Object.assign({ product_tag, env: slug, refreshToken }, details), this.getUserAccess());
@@ -260,11 +258,12 @@ class ProcessorService {
260
258
  }
261
259
  async refreshSession(payload) {
262
260
  await this.productBuilderService.initializeProductByTag(payload.product);
261
+ const privateKey = this.productBuilderService.fetchPrivateKey();
263
262
  // validate token validity
264
263
  const { refreshToken } = payload, payloadData = __rest(payload, ["refreshToken"]);
265
264
  const valid = await this.processorApiService.validateRefreshToken({ refreshToken, product: payload.product, env: payload.env }, this.getUserAccess());
266
265
  if (valid) {
267
- const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, this.productBuilderService.fetchProduct().private_key));
266
+ const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, privateKey));
268
267
  return await this.generateSession(Object.assign(Object.assign({}, payloadData), { data }));
269
268
  }
270
269
  else {
@@ -273,12 +272,13 @@ class ProcessorService {
273
272
  }
274
273
  async decryptSession(data) {
275
274
  await this.productBuilderService.initializeProductByTag(data.product);
275
+ const privateKey = this.productBuilderService.fetchPrivateKey();
276
276
  const JWT = await loadJWT();
277
277
  if (!JWT) {
278
278
  throw new Error(`Running in browser, token service not loaded.`);
279
279
  }
280
280
  try {
281
- const res = await JWT.verify(data.token, this.productBuilderService.fetchProduct().private_key);
281
+ const res = await JWT.verify(data.token, privateKey);
282
282
  if (res.session !== data.tag) {
283
283
  throw new Error(`Invalid token for session ${data.tag}`);
284
284
  }
@@ -295,8 +295,7 @@ class ProcessorService {
295
295
  async registerWebhook(data) {
296
296
  const { product: product_tag, access_tag, webhook_tag, envs } = data;
297
297
  await this.productBuilderService.initializeProductByTag(product_tag);
298
- const product = this.productBuilderService.fetchProduct();
299
- const { version, envs: appEnvs } = this.productBuilderService.fetchApp(access_tag);
298
+ const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
300
299
  const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
301
300
  const { webhooks } = app.versions.find((data) => data.tag === version);
302
301
  if (!webhooks) {
@@ -307,7 +306,7 @@ class ProcessorService {
307
306
  if (!webhook) {
308
307
  throw new Error(`Webhook tag ${webhook_tag} not found`);
309
308
  }
310
- const productEnvs = this.productBuilderService.fetchEnvs();
309
+ const productEnvs = await this.productBuilderService.fetchEnvs();
311
310
  productEnvs.map((env) => {
312
311
  const exists = envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
313
312
  if (exists === -1) {
@@ -351,7 +350,7 @@ class ProcessorService {
351
350
  if (replacedUrl && replacedUrl !== env.url && replacedUrl) {
352
351
  throw new Error(`Ductape expects the url ${replacedUrl} in request body to match inputted url ${env.url}`);
353
352
  }
354
- const exists = this.fetchEnv(env.slug, {});
353
+ const exists = await this.fetchEnv(env.slug, {});
355
354
  if (!exists) {
356
355
  throw new Error(`Env ${env.slug} does not exist`);
357
356
  }
@@ -373,7 +372,7 @@ class ProcessorService {
373
372
  webhook_tag,
374
373
  version,
375
374
  sender_workspace_id: app.workspace_id,
376
- receiver_workspace_id: product.workspace_id,
375
+ receiver_workspace_id: this.getUserAccess().workspace_id,
377
376
  app_tag: app.tag,
378
377
  product_tag,
379
378
  active,
@@ -384,8 +383,7 @@ class ProcessorService {
384
383
  async generateWebhookLink(data) {
385
384
  const { product: product_tag, access_tag, webhook_tag, env: product_env, url, method } = data;
386
385
  await this.productBuilderService.initializeProductByTag(product_tag);
387
- const product = this.productBuilderService.fetchProduct();
388
- const { version, envs: appEnvs } = this.productBuilderService.fetchApp(access_tag);
386
+ const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
389
387
  const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
390
388
  const { webhooks } = app.versions.find((data) => data.tag === version);
391
389
  if (!webhooks) {
@@ -406,7 +404,7 @@ class ProcessorService {
406
404
  webhook_tag,
407
405
  version,
408
406
  sender_workspace_id: app.workspace_id,
409
- receiver_workspace_id: product.workspace_id,
407
+ receiver_workspace_id: this.getUserAccess().workspace_id,
410
408
  app_tag: app.tag,
411
409
  product_tag,
412
410
  active: false,
@@ -436,12 +434,12 @@ class ProcessorService {
436
434
  process_id,
437
435
  data: input,
438
436
  };
439
- this.quota = this.fetchQuota(quota_tag, additional_logs);
437
+ this.quota = await this.fetchQuota(quota_tag, additional_logs);
440
438
  if (!this.quota) {
441
439
  throw new Error(`Quota ${quota_tag} not found`);
442
440
  }
443
441
  this.logService.setFeatureId(this.quota._id);
444
- this.processEnv = this.fetchEnv(env, additional_logs);
442
+ this.processEnv = await this.fetchEnv(env, additional_logs);
445
443
  if (!this.processEnv.active) {
446
444
  throw new Error(`Environment ${data.env} is not active`);
447
445
  }
@@ -567,12 +565,12 @@ class ProcessorService {
567
565
  process_id,
568
566
  data: input,
569
567
  };
570
- this.fallback = this.fetchFallback(fallback_tag, additional_logs);
568
+ this.fallback = await this.fetchFallback(fallback_tag, additional_logs);
571
569
  if (!this.fallback) {
572
570
  throw new Error(`Fallback "${fallback_tag}" not found`);
573
571
  }
574
572
  this.logService.setFeatureId(this.fallback._id);
575
- this.processEnv = this.fetchEnv(env, additional_logs);
573
+ this.processEnv = await this.fetchEnv(env, additional_logs);
576
574
  if (!this.processEnv.active) {
577
575
  throw new Error(`Environment ${data.env} is not active`);
578
576
  }
@@ -605,7 +603,7 @@ class ProcessorService {
605
603
  this.component = types_1.LogEventTypes.FEATURE;
606
604
  const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
607
605
  this.process_id = process_id;
608
- this.feature = this.fetchFeature(feature_tag, additional_logs);
606
+ this.feature = await this.fetchFeature(feature_tag, additional_logs);
609
607
  if (!this.feature) {
610
608
  throw new Error(`Feature "${feature_tag}" not found`);
611
609
  }
@@ -621,7 +619,7 @@ class ProcessorService {
621
619
  feature_id: this.feature._id,
622
620
  };
623
621
  this.logService.setFeatureId(this.feature._id);
624
- this.processEnv = this.fetchEnv(env, additional_logs);
622
+ this.processEnv = await this.fetchEnv(env, additional_logs);
625
623
  if (!this.processEnv.active) {
626
624
  throw new Error(`Environment ${data.env} is not active`);
627
625
  }
@@ -669,8 +667,8 @@ class ProcessorService {
669
667
  else {
670
668
  await this.productBuilderService.initializeProduct(this.productId);
671
669
  }
672
- const { _id: product_id, workspace_id } = this.productBuilderService.fetchProduct();
673
- this.productId = product_id;
670
+ this.productId = this.productBuilderService.fetchProductId();
671
+ const workspace_id = this.productBuilderService.fetchWorkspaceId();
674
672
  if (workspace_id !== this.workspace_id) {
675
673
  throw new Error('Access Denied');
676
674
  }
@@ -694,7 +692,7 @@ class ProcessorService {
694
692
  }
695
693
  try {
696
694
  console.log(`Initializing pricing for access tag: ${access_tag}`);
697
- const product_app = this.productBuilderService.fetchApp(access_tag); // validate app exists
695
+ const product_app = await this.productBuilderService.fetchApp(access_tag); // validate app exists
698
696
  console.log(`Found product app: ${JSON.stringify(product_app)}`);
699
697
  const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(product_app.access_tag);
700
698
  await this.pricingService.initializePricingByTag(product_app.pricing_tag, app._id);
@@ -707,9 +705,9 @@ class ProcessorService {
707
705
  throw e;
708
706
  }
709
707
  }
710
- fetchFeature(tag, additional_logs) {
708
+ async fetchFeature(tag, additional_logs) {
711
709
  try {
712
- const feature = this.productBuilderService.fetchFeature(tag); // validate feature exists
710
+ const feature = await this.productBuilderService.fetchFeature(tag); // validate feature exists
713
711
  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 }));
714
712
  return feature;
715
713
  }
@@ -718,9 +716,9 @@ class ProcessorService {
718
716
  throw e;
719
717
  }
720
718
  }
721
- fetchQuota(tag, additional_logs) {
719
+ async fetchQuota(tag, additional_logs) {
722
720
  try {
723
- const quota = this.productBuilderService.fetchQuota(tag); // validate feature exists
721
+ const quota = await this.productBuilderService.fetchQuota(tag); // validate feature exists
724
722
  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 }));
725
723
  return quota;
726
724
  }
@@ -729,9 +727,9 @@ class ProcessorService {
729
727
  throw e;
730
728
  }
731
729
  }
732
- fetchFallback(tag, additional_logs) {
730
+ async fetchFallback(tag, additional_logs) {
733
731
  try {
734
- const fallback = this.productBuilderService.fetchFallback(tag); // validate feature exists
732
+ const fallback = await this.productBuilderService.fetchFallback(tag); // validate feature exists
735
733
  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 }));
736
734
  return fallback;
737
735
  }
@@ -740,9 +738,9 @@ class ProcessorService {
740
738
  throw e;
741
739
  }
742
740
  }
743
- fetchEnv(env, additional_logs) {
741
+ async fetchEnv(env, additional_logs) {
744
742
  try {
745
- const product_env = this.productBuilderService.fetchEnv(env); // validate env exists
743
+ const product_env = await this.productBuilderService.fetchEnv(env); // validate env exists
746
744
  if (!product_env) {
747
745
  throw new Error(`Env ${env} not found`);
748
746
  }
@@ -1547,7 +1545,7 @@ class ProcessorService {
1547
1545
  }
1548
1546
  async generateVariableValue(stages) {
1549
1547
  try {
1550
- const app = this.productBuilderService.fetchApp(stages[0]);
1548
+ const app = await this.productBuilderService.fetchApp(stages[0]);
1551
1549
  const env = app.envs.find((items) => items.product_env_slug === this.processEnv.slug);
1552
1550
  if (!env) {
1553
1551
  throw new Error(`App ${stages[0]} variables needs to have a definition for env: ${this.processEnv.slug}`);
@@ -1609,7 +1607,7 @@ class ProcessorService {
1609
1607
  }
1610
1608
  async fetchAuthData(app_tag, additional_logs) {
1611
1609
  try {
1612
- const app = this.productBuilderService.fetchApp(app_tag);
1610
+ const app = await this.productBuilderService.fetchApp(app_tag);
1613
1611
  if (!app) {
1614
1612
  throw new Error(`App ${app_tag} not found in $Auth value`);
1615
1613
  }
@@ -1631,7 +1629,7 @@ class ProcessorService {
1631
1629
  console.log("REFRESH DATA", env, app_tag);
1632
1630
  values = await this.getAndStoreAuth(env, app_tag);
1633
1631
  }
1634
- const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchProduct().private_key);
1632
+ const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchPrivateKey());
1635
1633
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch auth data - success', data: { auth: (0, processor_utils_1.anonymizeValue)(decrypted) }, status: types_1.LogEventStatus.SUCCESS }));
1636
1634
  return JSON.parse(decrypted);
1637
1635
  }
@@ -1788,8 +1786,8 @@ class ProcessorService {
1788
1786
  throw new Error(`Invalid process id ${process_id}`);
1789
1787
  }
1790
1788
  await this.productBuilderService.initializeProduct(result.product_id);
1791
- result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchProduct().private_key));
1792
- result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchProduct().private_key));
1789
+ result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchPrivateKey()));
1790
+ result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchPrivateKey()));
1793
1791
  return result;
1794
1792
  }
1795
1793
  async generateOutput(process_id) {
@@ -1853,7 +1851,7 @@ class ProcessorService {
1853
1851
  if (result.component === types_1.LogEventTypes.FEATURE) {
1854
1852
  this.feature = await this.fetchFeature(result.input.tag, additional_logs);
1855
1853
  const { input: featureInput, sequence, output } = this.feature;
1856
- this.processEnv = this.fetchEnv(result.env, additional_logs);
1854
+ this.processEnv = await this.fetchEnv(result.env, additional_logs);
1857
1855
  if (!this.processEnv.active) {
1858
1856
  throw new Error(`Environment ${result.env} is not active`);
1859
1857
  }
@@ -1895,7 +1893,7 @@ class ProcessorService {
1895
1893
  //await this.processWaitingEvents(additional_logs);
1896
1894
  this.feature = await this.fetchFeature(result.input.tag, additional_logs);
1897
1895
  const { input: featureInput, sequence, output } = this.feature;
1898
- this.processEnv = this.fetchEnv(result.env, additional_logs);
1896
+ this.processEnv = await this.fetchEnv(result.env, additional_logs);
1899
1897
  if (!this.processEnv.active) {
1900
1898
  throw new Error(`Environment ${result.env} is not active`);
1901
1899
  }
@@ -1910,7 +1908,7 @@ class ProcessorService {
1910
1908
  ((_b = result.result.success[0]) === null || _b === void 0 ? void 0 : _b.event) ||
1911
1909
  ((_c = result.result.skipped[0]) === null || _c === void 0 ? void 0 : _c.event) ||
1912
1910
  result.result.waiting[0].event;
1913
- this.processEnv = this.fetchEnv(result.env, additional_logs);
1911
+ this.processEnv = await this.fetchEnv(result.env, additional_logs);
1914
1912
  this.start = Date.now();
1915
1913
  await this.processEvent(event);
1916
1914
  this.end = Date.now();
@@ -1937,8 +1935,8 @@ class ProcessorService {
1937
1935
  }
1938
1936
  async getAndStoreAuth(appEnv, access_tag) {
1939
1937
  try {
1940
- // const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.fetchProduct().private_key));
1941
- const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.fetchProduct().private_key));
1938
+ // const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.fetchPrivateKey()));
1939
+ const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.fetchPrivateKey()));
1942
1940
  let app = await this.fetchThirdPartyApp(access_tag);
1943
1941
  const auth = app.auths.find((item) => item.tag === appEnv.auth.auth_tag);
1944
1942
  console.log("JAMESY", auth);
@@ -1964,8 +1962,8 @@ class ProcessorService {
1964
1962
  }
1965
1963
  console.log("payloadabi!!!!", payload);
1966
1964
  const results = await this.sendActionRequest(request_base_url, url, payload, method, appEnv.app_env_slug);
1967
- const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchProduct().private_key);
1968
- const productApp = this.productBuilderService.fetchApp(access_tag);
1965
+ const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchPrivateKey());
1966
+ const productApp = await this.productBuilderService.fetchApp(access_tag);
1969
1967
  for (let i = 0; i < productApp.envs.length; i++) {
1970
1968
  if (productApp.envs[i].app_env_slug === env.slug) {
1971
1969
  productApp.envs[i].auth.values = values; // write new values
@@ -2076,7 +2074,7 @@ class ProcessorService {
2076
2074
  }
2077
2075
  let app = await this.fetchThirdPartyApp(access_tag);
2078
2076
  const { actions, envs: appEnvs, retries, workspace_id: recipient_workspace_id, active } = app;
2079
- const productApp = this.productBuilderService.fetchApp(access_tag);
2077
+ const productApp = await this.productBuilderService.fetchApp(access_tag);
2080
2078
  const { envs: productEnvs, version } = productApp;
2081
2079
  const { app_env_slug } = productEnvs.find((item) => item.product_env_slug === this.processEnv.slug);
2082
2080
  additional_logs.app_env = app_env_slug;
@@ -2111,9 +2109,9 @@ class ProcessorService {
2111
2109
  };
2112
2110
  let payloads;
2113
2111
  let result;
2114
- const product = this.productBuilderService.fetchProduct();
2112
+ //const product = this.productBuilderService.fetchProduct();
2115
2113
  if (cache_tag && this.redisClient) {
2116
- const productCache = this.productBuilderService.fetchCache(cache_tag);
2114
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
2117
2115
  if (!productCache) {
2118
2116
  throw new Error('Invalid cache tag ');
2119
2117
  }
@@ -2121,7 +2119,7 @@ class ProcessorService {
2121
2119
  const check = await this.fetchFromCache({
2122
2120
  cache_tag,
2123
2121
  input: inputString,
2124
- privateKey: product.private_key,
2122
+ privateKey: this.productBuilderService.fetchPrivateKey(),
2125
2123
  expiry: productCache.expiry,
2126
2124
  }, additional_logs);
2127
2125
  if (check) {
@@ -2151,14 +2149,14 @@ class ProcessorService {
2151
2149
  }
2152
2150
  }
2153
2151
  if (cache_tag && this.redisClient && result) {
2154
- const productCache = this.productBuilderService.fetchCache(cache_tag);
2152
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
2155
2153
  if (!productCache) {
2156
2154
  throw new Error('Invalid cache tag ');
2157
2155
  }
2158
2156
  const inputString = JSON.stringify(event.input);
2159
2157
  await this.addToCache({
2160
2158
  input: inputString,
2161
- privateKey: product.private_key,
2159
+ privateKey: this.productBuilderService.fetchPrivateKey(),
2162
2160
  data: JSON.stringify(result),
2163
2161
  cache_tag,
2164
2162
  timestamp: Date.now(),
@@ -2487,7 +2485,7 @@ class ProcessorService {
2487
2485
  process_id, data: this.clone }, additional_logs);
2488
2486
  await this.intializeProduct(additional_logs);
2489
2487
  this.process_id = process_id;
2490
- const productEnv = this.fetchEnv(env, additional_logs);
2488
+ const productEnv = await this.fetchEnv(env, additional_logs);
2491
2489
  this.processEnv = productEnv;
2492
2490
  if (!productEnv.active) {
2493
2491
  throw new Error(`Environment ${env} is not active`);
@@ -2536,7 +2534,7 @@ class ProcessorService {
2536
2534
  await this.intializeProduct(additional_logs);
2537
2535
  this.baseLogs.product_id = this.productId;
2538
2536
  this.process_id = process_id;
2539
- const productEnv = this.fetchEnv(data.env, additional_logs);
2537
+ const productEnv = await this.fetchEnv(data.env, additional_logs);
2540
2538
  this.processEnv = productEnv;
2541
2539
  if (!productEnv.active) {
2542
2540
  throw new Error(`Environment ${data.env} is not active`);
@@ -2588,7 +2586,7 @@ class ProcessorService {
2588
2586
  await this.intializeProduct(additional_logs);
2589
2587
  this.baseLogs.product_id = this.productId;
2590
2588
  this.process_id = process_id;
2591
- const productEnv = this.fetchEnv(data.env, additional_logs);
2589
+ const productEnv = await this.fetchEnv(data.env, additional_logs);
2592
2590
  this.processEnv = productEnv;
2593
2591
  if (!productEnv.active) {
2594
2592
  throw new Error(`Environment ${data.env} is not active`);
@@ -2618,7 +2616,7 @@ class ProcessorService {
2618
2616
  }
2619
2617
  async processJob(job, additional_logs = {}) {
2620
2618
  var _a;
2621
- const productJob = this.productBuilderService.fetchJob(job.event);
2619
+ const productJob = await this.productBuilderService.fetchJob(job.event);
2622
2620
  if (!productJob) {
2623
2621
  throw new Error(`Job ${job.event} not found`);
2624
2622
  }
@@ -2782,8 +2780,8 @@ class ProcessorService {
2782
2780
  const input = notification.input;
2783
2781
  try {
2784
2782
  //await this.intializeProduct(additional_logs);
2785
- const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
2786
- const message = this.productBuilderService.fetchNotificationMessage(event);
2783
+ const notificationEvent = await this.productBuilderService.fetchNotification(event.split(":")[0]);
2784
+ const message = await this.productBuilderService.fetchNotificationMessage(event);
2787
2785
  if (!message) {
2788
2786
  throw new Error(`Message ${event} not found`);
2789
2787
  }
@@ -2911,14 +2909,14 @@ class ProcessorService {
2911
2909
  name: 'Run Migration',
2912
2910
  };
2913
2911
  await this.intializeProduct(additional_logs);
2914
- const db = this.productBuilderService.fetchDatabase(dbTag);
2912
+ const db = await this.productBuilderService.fetchDatabase(dbTag);
2915
2913
  if (!db) {
2916
2914
  throw new Error('Database not found');
2917
2915
  }
2918
2916
  if (db.type === types_1.DatabaseTypes.MONGODB) {
2919
2917
  throw new Error(`${db.type} does not support migrations`);
2920
2918
  }
2921
- const migration = this.productBuilderService.fetchDatabaseMigration(tag);
2919
+ const migration = await this.productBuilderService.fetchDatabaseMigration(tag);
2922
2920
  if (!migration) {
2923
2921
  throw new Error('Database migration not found');
2924
2922
  }
@@ -2926,12 +2924,11 @@ class ProcessorService {
2926
2924
  if (!dbEnv) {
2927
2925
  throw new Error(`Environment ${env} not found`);
2928
2926
  }
2929
- const productEnv = this.fetchEnv(env, additional_logs);
2927
+ const productEnv = await this.fetchEnv(env, additional_logs);
2930
2928
  if (!productEnv.active) {
2931
2929
  throw new Error(`Environment ${env} is not active`);
2932
2930
  }
2933
- const product = this.productBuilderService.fetchProduct();
2934
- const migrations = this.productBuilderService.fetchDatabaseMigrations(dbTag);
2931
+ const migrations = await this.productBuilderService.fetchDatabaseMigrations(dbTag);
2935
2932
  //this.processEnv = productEnv;
2936
2933
  /* const check = migration.envs.find((migrationEnv) => migrationEnv.slug === env);
2937
2934
  if (!check) {
@@ -2943,7 +2940,7 @@ class ProcessorService {
2943
2940
  const migrationsToRun = (0, processor_utils_1.getMigrationsToRun)((0, processor_utils_1.structuredClone)(migrations), type, migrationTag, env);
2944
2941
  if (db.type === types_1.DatabaseTypes.POSTGRES) {
2945
2942
  const PostgresDBHandler = await (0, postgres_repo_1.loadPostgresHandler)();
2946
- const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(dbEnv.connection_url, product.private_key));
2943
+ const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(dbEnv.connection_url, this.productBuilderService.fetchPrivateKey()));
2947
2944
  for (const migrationToRun of migrationsToRun) {
2948
2945
  const envS = migration.envs.find((envT) => envT.slug === env && type === envT.type);
2949
2946
  if (envS && envS.status === types_1.MigrationStatus.PROCESSED) {
@@ -3012,7 +3009,7 @@ class ProcessorService {
3012
3009
  status: LogEventStatus.PROCESSING,
3013
3010
  });
3014
3011
 
3015
- const cloudFunction = this.productBuilderService.fetchFunction(data.event);
3012
+ const cloudFunction = await this.productBuilderService.fetchFunction(data.event);
3016
3013
 
3017
3014
  this.logService.add({
3018
3015
  ...this.baseLogs,
@@ -3079,10 +3076,9 @@ class ProcessorService {
3079
3076
  throw new Error(`Storage env for ${env.slug} not found`);
3080
3077
  }
3081
3078
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch storage details - success', data: { storage }, status: types_1.LogEventStatus.SUCCESS }));
3082
- const product = this.productBuilderService.fetchProduct();
3083
3079
  let result;
3084
3080
  if (cache_tag && this.redisClient) {
3085
- const productCache = this.productBuilderService.fetchCache(cache_tag);
3081
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
3086
3082
  if (!productCache) {
3087
3083
  throw new Error('Invalid cache tag ');
3088
3084
  }
@@ -3090,7 +3086,7 @@ class ProcessorService {
3090
3086
  const check = await this.fetchFromCache({
3091
3087
  cache_tag,
3092
3088
  input: inputString,
3093
- privateKey: product.private_key,
3089
+ privateKey: this.productBuilderService.fetchPrivateKey(),
3094
3090
  expiry: productCache.expiry,
3095
3091
  }, additional_logs);
3096
3092
  if (check) {
@@ -3104,14 +3100,14 @@ class ProcessorService {
3104
3100
  input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
3105
3101
  result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
3106
3102
  if (cache_tag && this.redisClient) {
3107
- const productCache = this.productBuilderService.fetchCache(cache_tag);
3103
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
3108
3104
  if (!productCache) {
3109
3105
  throw new Error('Invalid cache tag ');
3110
3106
  }
3111
3107
  const inputString = JSON.stringify(input);
3112
3108
  await this.addToCache({
3113
3109
  input: inputString,
3114
- privateKey: product.private_key,
3110
+ privateKey: this.productBuilderService.fetchPrivateKey(),
3115
3111
  data: JSON.stringify(result),
3116
3112
  cache_tag,
3117
3113
  timestamp: Date.now(),
@@ -3132,7 +3128,6 @@ class ProcessorService {
3132
3128
  try {
3133
3129
  //await this.intializeProduct(additional_logs);
3134
3130
  const [database_tag, action_tag] = event.split(':');
3135
- const product = this.productBuilderService.fetchProduct();
3136
3131
  const database = await this.productBuilderService.fetchDatabase(database_tag);
3137
3132
  const databaseAction = await this.productBuilderService.fetchDatabaseAction(event);
3138
3133
  const databaseEnv = database.envs.find((el) => el.slug === env.slug);
@@ -3172,7 +3167,7 @@ class ProcessorService {
3172
3167
  }
3173
3168
  let result;
3174
3169
  if (cache_tag && this.redisClient) {
3175
- const productCache = this.productBuilderService.fetchCache(cache_tag);
3170
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
3176
3171
  if (!productCache) {
3177
3172
  throw new Error('Invalid cache tag ');
3178
3173
  }
@@ -3180,7 +3175,7 @@ class ProcessorService {
3180
3175
  const check = await this.fetchFromCache({
3181
3176
  cache_tag,
3182
3177
  input: inputString,
3183
- privateKey: product.private_key,
3178
+ privateKey: this.productBuilderService.fetchPrivateKey(),
3184
3179
  expiry: productCache.expiry,
3185
3180
  }, additional_logs);
3186
3181
  if (check) {
@@ -3211,7 +3206,7 @@ class ProcessorService {
3211
3206
  if (!PostgresDBHandler) {
3212
3207
  throw new Error(`Running in browser, postgres handler not loaded.`);
3213
3208
  }
3214
- const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchProduct().private_key));
3209
+ const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchPrivateKey()));
3215
3210
  if (databaseAction.type !== types_1.DatabaseActionTypes.AGGREGATE) {
3216
3211
  result = await pgHandler[databaseAction.type](databaseAction.data, template, input.data);
3217
3212
  }
@@ -3220,14 +3215,14 @@ class ProcessorService {
3220
3215
  // const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
3221
3216
  await this.addToSuccessOutput(db_action, result, additional_logs);
3222
3217
  if (cache_tag && this.redisClient) {
3223
- const productCache = this.productBuilderService.fetchCache(cache_tag);
3218
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
3224
3219
  if (!productCache) {
3225
3220
  throw new Error('Invalid cache tag ');
3226
3221
  }
3227
3222
  const inputString = JSON.stringify(input);
3228
3223
  await this.addToCache({
3229
3224
  input: inputString,
3230
- privateKey: product.private_key,
3225
+ privateKey: this.productBuilderService.fetchPrivateKey(),
3231
3226
  data: JSON.stringify(result),
3232
3227
  cache_tag,
3233
3228
  timestamp: Date.now(),
@@ -3250,7 +3245,7 @@ class ProcessorService {
3250
3245
  try {
3251
3246
  await this.intializeProduct(additional_logs);
3252
3247
  const [brokerTag, topicTag] = event.split(':');
3253
- const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
3248
+ const broker = await this.productBuilderService.fetchMessageBroker(brokerTag);
3254
3249
  if (!broker) {
3255
3250
  throw new Error(`Message Broker ${brokerTag} not found`);
3256
3251
  }
@@ -3258,7 +3253,7 @@ class ProcessorService {
3258
3253
  if (!brokerEnv) {
3259
3254
  throw new Error(`Broker env for ${env.slug} not found`);
3260
3255
  }
3261
- const topic = this.productBuilderService.fetchMessageBrokerTopic(event);
3256
+ const topic = await this.productBuilderService.fetchMessageBrokerTopic(event);
3262
3257
  if (!topic) {
3263
3258
  throw new Error(`Topic ${topicTag} not found in broker ${brokerTag}`);
3264
3259
  }
@@ -3299,7 +3294,7 @@ class ProcessorService {
3299
3294
  try {
3300
3295
  await this.intializeProduct(additional_logs);
3301
3296
  const [brokerTag, topicTag] = event.split(':');
3302
- const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
3297
+ const broker = await this.productBuilderService.fetchMessageBroker(brokerTag);
3303
3298
  if (!broker) {
3304
3299
  throw new Error(`Message Broker ${brokerTag} not found`);
3305
3300
  }
@@ -3307,7 +3302,7 @@ class ProcessorService {
3307
3302
  if (!brokerEnv) {
3308
3303
  throw new Error(`Broker env for ${env.slug} not found`);
3309
3304
  }
3310
- const topic = this.productBuilderService.fetchMessageBrokerTopic(event);
3305
+ const topic = await this.productBuilderService.fetchMessageBrokerTopic(event);
3311
3306
  if (!topic) {
3312
3307
  throw new Error(`Topic ${topicTag} not found in broker ${brokerTag}`);
3313
3308
  }
@@ -3371,7 +3366,7 @@ class ProcessorService {
3371
3366
  const result = { url: await (0, storage_util_1.uploadBlobToCloud)({ data: input.buffer, destinationPath: input.fileName, config }) };
3372
3367
  try {
3373
3368
  await this.processorApiService.saveFileURL({
3374
- url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchProduct().private_key),
3369
+ url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchPrivateKey()),
3375
3370
  provider: storageEnv.type,
3376
3371
  product: this.productTag,
3377
3372
  process_id: this.process_id,
@@ -3432,12 +3427,12 @@ class ProcessorService {
3432
3427
  start: this.start,
3433
3428
  end: this.end,
3434
3429
  retryable,
3435
- result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchProduct().private_key),
3430
+ result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchPrivateKey()),
3436
3431
  process_id: this.process_id,
3437
3432
  feature_id: this.feature ? this.feature._id : null,
3438
3433
  product_id: this.productId,
3439
3434
  env: this.processEnv.slug,
3440
- input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchProduct().private_key),
3435
+ input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchPrivateKey()),
3441
3436
  }, this.getUserAccess());
3442
3437
  }
3443
3438
  async validateActionDataMappingInput(input, type) {
@@ -3486,7 +3481,7 @@ class ProcessorService {
3486
3481
  await this.initializePricing(additional_logs, app);
3487
3482
  this.process_id = process_id;
3488
3483
  this.baseLogs.product_id = this.productId;
3489
- const productEnv = this.fetchEnv(env, additional_logs);
3484
+ const productEnv = await this.fetchEnv(env, additional_logs);
3490
3485
  this.processEnv = productEnv;
3491
3486
  if (!productEnv.active) {
3492
3487
  throw new Error(`Environment ${env} is not active`);
@@ -3541,7 +3536,7 @@ class ProcessorService {
3541
3536
  await this.intializeProduct(additional_logs);
3542
3537
  this.baseLogs.product_id = this.productId;
3543
3538
  this.process_id = process_id;
3544
- const productEnv = this.fetchEnv(env, additional_logs);
3539
+ const productEnv = await this.fetchEnv(env, additional_logs);
3545
3540
  this.processEnv = productEnv;
3546
3541
  if (!productEnv.active) {
3547
3542
  throw new Error(`Environment ${env} is not active`);
@@ -3595,7 +3590,7 @@ class ProcessorService {
3595
3590
  await this.intializeProduct(additional_logs);
3596
3591
  this.process_id = process_id;
3597
3592
  this.baseLogs.product_id = this.productId;
3598
- const productEnv = this.fetchEnv(env, additional_logs);
3593
+ const productEnv = await this.fetchEnv(env, additional_logs);
3599
3594
  this.processEnv = productEnv;
3600
3595
  if (!productEnv.active) {
3601
3596
  throw new Error(`Environment ${env} is not active`);
@@ -3627,7 +3622,7 @@ class ProcessorService {
3627
3622
  try {
3628
3623
  const data = await this.processorApiService.fetchRemoteCaches(payload, this.getUserAccess());
3629
3624
  return data.map((data) => {
3630
- data.value = (0, processor_utils_1.decrypt)(data.value, this.productBuilderService.fetchProduct().private_key);
3625
+ data.value = (0, processor_utils_1.decrypt)(data.value, this.productBuilderService.fetchPrivateKey());
3631
3626
  return data;
3632
3627
  });
3633
3628
  }