@ductape/sdk 0.0.4-v2 → 0.0.4-v21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/api/services/appApi.service.d.ts +2 -2
  2. package/dist/api/services/appApi.service.js +1 -2
  3. package/dist/api/services/appApi.service.js.map +1 -1
  4. package/dist/api/services/pricingApi.service.d.ts +10 -0
  5. package/dist/api/services/pricingApi.service.js +34 -0
  6. package/dist/api/services/pricingApi.service.js.map +1 -0
  7. package/dist/api/services/processorApi.service.d.ts +12 -2
  8. package/dist/api/services/processorApi.service.js +12 -2
  9. package/dist/api/services/processorApi.service.js.map +1 -1
  10. package/dist/api/services/productsApi.service.d.ts +7 -1
  11. package/dist/api/services/productsApi.service.js +33 -0
  12. package/dist/api/services/productsApi.service.js.map +1 -1
  13. package/dist/api/services/userApi.service.js +1 -0
  14. package/dist/api/services/userApi.service.js.map +1 -1
  15. package/dist/api/services/workspaceApi.service.js +1 -0
  16. package/dist/api/services/workspaceApi.service.js.map +1 -1
  17. package/dist/api/urls.d.ts +7 -1
  18. package/dist/api/urls.js +13 -2
  19. package/dist/api/urls.js.map +1 -1
  20. package/dist/api/utils/strings.utils.d.ts +2 -0
  21. package/dist/api/utils/strings.utils.js +14 -0
  22. package/dist/api/utils/strings.utils.js.map +1 -1
  23. package/dist/apps/services/app.service.js +7 -5
  24. package/dist/apps/services/app.service.js.map +1 -1
  25. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
  26. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
  27. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
  28. package/dist/clients/apps.client.js +1 -1
  29. package/dist/clients/apps.client.js.map +1 -1
  30. package/dist/clients/pricing.client.d.ts +3 -0
  31. package/dist/clients/pricing.client.js +33 -0
  32. package/dist/clients/pricing.client.js.map +1 -0
  33. package/dist/imports/imports.service.d.ts +3 -3
  34. package/dist/imports/imports.service.js +7 -7
  35. package/dist/imports/imports.service.js.map +1 -1
  36. package/dist/imports/imports.types.d.ts +8 -0
  37. package/dist/imports/repos/openApi.repo.d.ts +1 -2
  38. package/dist/imports/repos/openApi.repo.js +43 -71
  39. package/dist/imports/repos/openApi.repo.js.map +1 -1
  40. package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
  41. package/dist/imports/repos/postmanV21.repo.js +29 -2
  42. package/dist/imports/repos/postmanV21.repo.js.map +1 -1
  43. package/dist/index.d.ts +953 -46
  44. package/dist/index.js +918 -81
  45. package/dist/index.js.map +1 -1
  46. package/dist/inputs/inputs.service.js +2 -2
  47. package/dist/inputs/inputs.service.js.map +1 -1
  48. package/dist/inputs/utils/inputs.utils.create.js +1 -1
  49. package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
  50. package/dist/logs/logs.service.js +1 -0
  51. package/dist/logs/logs.service.js.map +1 -1
  52. package/dist/logs/logs.types.d.ts +5 -0
  53. package/dist/logs/logs.types.js.map +1 -1
  54. package/dist/parsers/index.d.ts +3 -0
  55. package/dist/parsers/index.js +27 -0
  56. package/dist/parsers/index.js.map +1 -0
  57. package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
  58. package/dist/parsers/pipelines/postman.pipelines.js +103 -0
  59. package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
  60. package/dist/parsers/types/postman.types.d.ts +200 -0
  61. package/dist/parsers/types/postman.types.js +3 -0
  62. package/dist/parsers/types/postman.types.js.map +1 -0
  63. package/dist/parsers/utils/postman.utils.d.ts +12 -0
  64. package/dist/parsers/utils/postman.utils.js +116 -0
  65. package/dist/parsers/utils/postman.utils.js.map +1 -0
  66. package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
  67. package/dist/parsers/validators/postman-auth.validators.js +127 -0
  68. package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
  69. package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
  70. package/dist/parsers/validators/postman-request.validators.js +139 -0
  71. package/dist/parsers/validators/postman-request.validators.js.map +1 -0
  72. package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
  73. package/dist/parsers/validators/postman-response.validators.js +150 -0
  74. package/dist/parsers/validators/postman-response.validators.js.map +1 -0
  75. package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
  76. package/dist/parsers/validators/postman-variable.validators.js +163 -0
  77. package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
  78. package/dist/pricing/pricing.repo.d.ts +0 -0
  79. package/dist/pricing/pricing.repo.js +1 -0
  80. package/dist/pricing/pricing.repo.js.map +1 -0
  81. package/dist/pricing/pricing.service.d.ts +24 -0
  82. package/dist/pricing/pricing.service.js +51 -0
  83. package/dist/pricing/pricing.service.js.map +1 -0
  84. package/dist/pricing/pricing.types.d.ts +76 -0
  85. package/dist/pricing/pricing.types.js +21 -0
  86. package/dist/pricing/pricing.types.js.map +1 -0
  87. package/dist/pricing/utils/string.utils.d.ts +1 -0
  88. package/dist/pricing/utils/string.utils.js +9 -0
  89. package/dist/pricing/utils/string.utils.js.map +1 -0
  90. package/dist/processor/repos/sms.repo.d.ts +4 -4
  91. package/dist/processor/repos/sms.repo.js +23 -10
  92. package/dist/processor/repos/sms.repo.js.map +1 -1
  93. package/dist/processor/services/processor.service.d.ts +36 -5
  94. package/dist/processor/services/processor.service.js +556 -201
  95. package/dist/processor/services/processor.service.js.map +1 -1
  96. package/dist/processor/services/request.service.d.ts +36 -0
  97. package/dist/processor/services/request.service.js +304 -0
  98. package/dist/processor/services/request.service.js.map +1 -0
  99. package/dist/processor/types/request.types.d.ts +14 -0
  100. package/dist/processor/types/request.types.js +3 -0
  101. package/dist/processor/types/request.types.js.map +1 -0
  102. package/dist/processor/utils/processor.utils.d.ts +3 -0
  103. package/dist/processor/utils/processor.utils.js +88 -5
  104. package/dist/processor/utils/processor.utils.js.map +1 -1
  105. package/dist/processor/utils/request.utils.d.ts +20 -0
  106. package/dist/processor/utils/request.utils.js +113 -0
  107. package/dist/processor/utils/request.utils.js.map +1 -0
  108. package/dist/processor/utils/storage.util.js +54 -40
  109. package/dist/processor/utils/storage.util.js.map +1 -1
  110. package/dist/products/services/products.service.d.ts +21 -6
  111. package/dist/products/services/products.service.js +286 -44
  112. package/dist/products/services/products.service.js.map +1 -1
  113. package/dist/products/utils/string.utils.d.ts +1 -1
  114. package/dist/products/utils/string.utils.js +14 -2
  115. package/dist/products/utils/string.utils.js.map +1 -1
  116. package/dist/products/validators/index.d.ts +2 -1
  117. package/dist/products/validators/index.js +3 -1
  118. package/dist/products/validators/index.js.map +1 -1
  119. package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
  120. package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
  121. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
  122. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
  123. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
  124. package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
  125. package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
  126. package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
  127. package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
  128. package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
  129. package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
  130. package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
  131. package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
  132. package/dist/test/test.health.d.ts +1 -0
  133. package/dist/test/test.health.js +49 -0
  134. package/dist/test/test.health.js.map +1 -0
  135. package/dist/test/test.import.js +51 -4
  136. package/dist/test/test.import.js.map +1 -1
  137. package/dist/test/test.imports.js +22 -7
  138. package/dist/test/test.imports.js.map +1 -1
  139. package/dist/test/test.processor.js +32 -115
  140. package/dist/test/test.processor.js.map +1 -1
  141. package/dist/test/test.products.d.ts +1 -0
  142. package/dist/test/test.products.js +49 -0
  143. package/dist/test/test.products.js.map +1 -0
  144. package/dist/types/appBuilder.types.d.ts +1 -11
  145. package/dist/types/enums.d.ts +3 -1
  146. package/dist/types/enums.js +2 -0
  147. package/dist/types/enums.js.map +1 -1
  148. package/dist/types/index.types.d.ts +4 -0
  149. package/dist/types/pricing.types.d.ts +4 -0
  150. package/dist/types/pricing.types.js +3 -0
  151. package/dist/types/pricing.types.js.map +1 -0
  152. package/dist/types/processor.types.d.ts +68 -9
  153. package/dist/types/processor.types.js.map +1 -1
  154. package/dist/types/productsBuilder.types.d.ts +59 -3
  155. package/dist/types/productsBuilder.types.js +9 -1
  156. package/dist/types/productsBuilder.types.js.map +1 -1
  157. package/dist/types/request-tracker.interface.d.ts +0 -0
  158. package/dist/types/request-tracker.interface.js +1 -0
  159. package/dist/types/request-tracker.interface.js.map +1 -0
  160. package/dist/utils/constants.d.ts +1 -0
  161. package/dist/utils/constants.js +5 -0
  162. package/dist/utils/constants.js.map +1 -0
  163. package/package.json +13 -1
@@ -42,7 +42,7 @@ const functions_utils_1 = require("../utils/functions.utils");
42
42
  const objects_utils_2 = require("../../apps/utils/objects.utils");
43
43
  const webhooksApi_service_1 = require("../../api/services/webhooksApi.service");
44
44
  class ProductsBuilderService {
45
- constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
45
+ constructor({ workspace_id, public_key, user_id, token, env_type, redis_client, queues }) {
46
46
  this.workspace_id = workspace_id;
47
47
  this.public_key = public_key;
48
48
  this.user_id = user_id;
@@ -54,6 +54,137 @@ class ProductsBuilderService {
54
54
  this.appApi = new appApi_service_1.AppApiService(env_type, redis_client);
55
55
  this.inputsService = new inputs_service_1.default();
56
56
  this.thirdPartyApps = [];
57
+ if (redis_client) {
58
+ this.redisClient = redis_client;
59
+ // Start healthcheck workers automatically
60
+ //this.startHealthcheckWorkers();
61
+ }
62
+ if (queues) {
63
+ this.queues = queues;
64
+ }
65
+ }
66
+ async createHealthcheck(data) {
67
+ try {
68
+ await validators_1.CreateProductHealthcheckSchema.validateAsync(data);
69
+ if (!data.tag) {
70
+ throw new Error('tag field is required');
71
+ }
72
+ const exists = this.fetchHealthcheck(data.app, data.tag);
73
+ if (!exists) {
74
+ const { app: access_tag, event: action } = data;
75
+ const app = await this.fetchThirdPartyAppByAccessTag(access_tag);
76
+ const version = app.versions.find((data) => data.tag === app.version);
77
+ if (!version) {
78
+ throw new Error(`Version ${app.version} not found`);
79
+ }
80
+ const event = version.actions.find((act) => act.tag === action);
81
+ data.envs = await Promise.all(data.envs.map(async (env) => {
82
+ const exists = this.fetchEnv(env.slug);
83
+ if (!exists) {
84
+ throw new Error(`Env ${env.slug} does not exist`);
85
+ }
86
+ await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
87
+ env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.fetchProduct().private_key);
88
+ console.log("INPUT", env);
89
+ return env;
90
+ }));
91
+ const envs = this.fetchEnvs();
92
+ console.log("ENVS ===>>>>", envs);
93
+ console.log("DBENVS ====>>>>", data.envs);
94
+ envs.map((env) => {
95
+ const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
96
+ if (exists === -1) {
97
+ throw new Error(`Product env ${env.slug} is not defined, please provide details`);
98
+ }
99
+ });
100
+ console.log("UPDATING VALUE", data);
101
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { action: enums_1.RequestAction.CREATE, component: enums_1.ProductComponents.HEALTHCHECK }), this.getUserAccess());
102
+ await this.initializeProduct(this.product_id);
103
+ data.envs.map(async (env) => {
104
+ const payload = {
105
+ app: data.app,
106
+ event: data.event,
107
+ input: env.input,
108
+ env: env.slug,
109
+ product: this.product.tag,
110
+ retries: data.retries,
111
+ };
112
+ const jobId = `healthcheck-${data.tag}`;
113
+ const job = await this.queues.health.getJob(jobId);
114
+ if (job) {
115
+ await job.remove();
116
+ }
117
+ await this.queues.health.add(jobId, payload, { jobId, repeat: { every: data.interval } });
118
+ });
119
+ }
120
+ }
121
+ catch (e) {
122
+ console.log(e);
123
+ throw e;
124
+ }
125
+ }
126
+ async updateHealthcheck(tag, data) {
127
+ try {
128
+ // 1. Fetch the existing healthcheck
129
+ const healthcheck = this.fetchHealthcheck(data.app, tag);
130
+ if (!healthcheck) {
131
+ throw new Error(`Healthcheck with tag: ${tag} not found`);
132
+ }
133
+ // 2. Validate the incoming data
134
+ await validators_1.CreateProductHealthcheckSchema.validateAsync(data); // No Update schema, use Create
135
+ // 3. Check for tag conflicts
136
+ if (data.tag && data.tag !== tag && this.fetchHealthcheck(data.app, data.tag)) {
137
+ throw new Error(`Healthcheck with tag ${data.tag} already exists`);
138
+ }
139
+ // 4. Validate and process envs
140
+ if (data.envs) {
141
+ data.envs = await Promise.all(data.envs.map(async (env) => {
142
+ const exists = this.fetchEnv(env.slug);
143
+ if (!exists) {
144
+ throw new Error(`Env ${env.slug} does not exist`);
145
+ }
146
+ // Validate input if present
147
+ if (env.input) {
148
+ const app = await this.fetchThirdPartyAppByAccessTag(data.app);
149
+ const version = app.versions.find((v) => v.tag === app.version);
150
+ if (!version) {
151
+ throw new Error(`Version ${app.version} not found`);
152
+ }
153
+ const event = version.actions.find((act) => act.tag === data.event);
154
+ await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
155
+ env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.fetchProduct().private_key);
156
+ }
157
+ return env;
158
+ }));
159
+ }
160
+ // 5. Ensure all product envs are covered
161
+ const envs = this.fetchEnvs();
162
+ envs.map((env) => {
163
+ var _a;
164
+ const exists = (_a = data.envs) === null || _a === void 0 ? void 0 : _a.findIndex((dbEnv) => dbEnv.slug === env.slug);
165
+ if (exists === -1) {
166
+ throw new Error(`Product env ${env.slug} is not defined, please provide details`);
167
+ }
168
+ });
169
+ // 6. Update the healthcheck
170
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, healthcheck), data), { tag, component: enums_1.ProductComponents.HEALTHCHECK, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
171
+ await this.initializeProduct(this.product_id);
172
+ }
173
+ catch (e) {
174
+ throw e;
175
+ }
176
+ }
177
+ fetchHealthcheck(access_tag, tag, throwError = false) {
178
+ const health = this.product.healthchecks.find((data) => data.tag === tag && data.app === access_tag);
179
+ if (!health && throwError)
180
+ throw new Error(`Healthcheck ${tag} not found`);
181
+ return health;
182
+ }
183
+ fetchHealthchecks(access_tag, throwError = false) {
184
+ const health = this.product.healthchecks.filter((data) => data.app === access_tag);
185
+ if (!health && throwError)
186
+ throw new Error(`Access tag ${access_tag} not found`);
187
+ return health;
57
188
  }
58
189
  async updateDataValidation(selector, update) {
59
190
  if (!selector.startsWith('$Data{') && !selector.startsWith('$Filter')) {
@@ -68,8 +199,8 @@ class ProductsBuilderService {
68
199
  if (stages.length < 3) {
69
200
  throw new Error(`Invalid selector ${selector}`);
70
201
  }
71
- const tag = stages[0];
72
- const type = stages[1];
202
+ const tag = String(stages[0]);
203
+ const type = String(stages[1]);
73
204
  let size = 2;
74
205
  let data;
75
206
  switch (type) {
@@ -81,13 +212,14 @@ class ProductsBuilderService {
81
212
  break;
82
213
  case productsBuilder_types_1.FeatureEventTypes.NOTIFICATION:
83
214
  size = 3;
84
- if (!stages[3] || (stages[3] !== 'push' && stages[3] !== 'callback' && stages[3] !== 'email')) {
85
- throw new Error(`Invalid value ${stages[3]} in ${selector}, expected to be "push", "callback" or "email" in notification`);
215
+ const stage3Str = String(stages[3]);
216
+ if (!stages[3] || (stage3Str !== 'push' && stage3Str !== 'callback' && stage3Str !== 'email')) {
217
+ throw new Error(`Invalid value ${stage3Str} in ${selector}, expected to be "push", "callback" or "email" in notification`);
86
218
  }
87
219
  const notification = this.fetchNotificationMessage(tag);
88
220
  if (!notification)
89
221
  throw new Error(`Notification ${tag} not found`);
90
- if (stages[3] === 'push') {
222
+ if (stage3Str === 'push') {
91
223
  data = notification.push_notification_data;
92
224
  }
93
225
  if (stages[3] === 'callback') {
@@ -157,6 +289,9 @@ class ProductsBuilderService {
157
289
  async initializeProductByTag(tag) {
158
290
  try {
159
291
  this.product = await this.productApi.fetchProductByTag(tag, this.getUserAccess());
292
+ if (!this.product) {
293
+ throw new Error(`Product with tag "${tag}" not found or failed to fetch`);
294
+ }
160
295
  this.product_id = this.product._id;
161
296
  }
162
297
  catch (e) {
@@ -192,19 +327,45 @@ class ProductsBuilderService {
192
327
  }
193
328
  return this.product;
194
329
  }
195
- async createSession(data) {
330
+ async createSession(data, throwErrorIfExists = false) {
196
331
  try {
197
- // TODO: figure out a way to check if this has run before, halt if it has
198
- if (!this.fetchSession(data.tag)) {
199
- await validators_1.CreateProductSessionSchema.validateAsync(data);
200
- data.schema_data = (await this.inputsService.parseJson({
332
+ await validators_1.CreateProductSessionSchema.validateAsync(data);
333
+ if (!data.tag) {
334
+ throw new Error('tag field is required');
335
+ }
336
+ const exists = this.fetchSession(data.tag);
337
+ if (!exists) {
338
+ if (!data.selector.startsWith('$Session{')) {
339
+ throw new Error('Selector should be in the format $Session{...}{key}');
340
+ }
341
+ const stages = (0, string_utils_1.extractStages)(data.selector);
342
+ let current = data.schema;
343
+ for (const stage of stages) {
344
+ if (current && typeof current === 'object' && stage in current) {
345
+ current = current[stage];
346
+ }
347
+ else {
348
+ throw new Error(`${data.selector} not found in event sample`);
349
+ }
350
+ }
351
+ if (current === null ||
352
+ typeof current === "undefined" ||
353
+ typeof current === "object") {
354
+ throw new Error("Selector value is not allowed to be an object|array|null|undefined");
355
+ }
356
+ data.schema_data = await this.inputsService.parseJson({
201
357
  data: data.schema,
202
- expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
203
- category: enums_1.Categories.DATA,
204
- }));
205
- await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
358
+ expected: inputs_types_1.ExpectedValues.PARSESAMPLE
359
+ });
360
+ data.selectorValue = current;
361
+ const payload = Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE });
362
+ await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
206
363
  await this.initializeProduct(this.product_id);
207
364
  }
365
+ else {
366
+ if (throwErrorIfExists)
367
+ throw new Error(`Session ${data.tag} already exists`);
368
+ }
208
369
  }
209
370
  catch (e) {
210
371
  throw e;
@@ -212,13 +373,13 @@ class ProductsBuilderService {
212
373
  }
213
374
  async updateSession(tag, data) {
214
375
  try {
215
- const auth = this.fetchSession(tag);
216
- if (!auth) {
217
- throw new Error(`Session ${tag} not found`);
376
+ const session = this.fetchSession(tag);
377
+ if (!session) {
378
+ throw new Error(`Session with tag: ${tag} not found`);
218
379
  }
219
380
  //const { _id } = auth;
220
381
  await validators_1.UpdateProductSessionSchema.validateAsync(data); // Change to update;
221
- if (data.tag && this.fetchEnv(data.tag) && data.tag !== tag) {
382
+ if (data.tag && this.fetchSession(data.tag) && data.tag !== tag) {
222
383
  throw new Error(`tag ${data.tag} is in use`); // TODO: also check on the backend
223
384
  }
224
385
  if (!data.tag) {
@@ -230,8 +391,28 @@ class ProductsBuilderService {
230
391
  expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
231
392
  category: enums_1.Categories.DATA,
232
393
  }));
394
+ if (!data.selector) {
395
+ throw new Error('Selector is expected when updating schema');
396
+ }
233
397
  }
234
- await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, auth), data)), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
398
+ if (data.selector) {
399
+ const stages = (0, string_utils_1.extractStages)(data.selector);
400
+ let current = data.schema;
401
+ for (const stage of stages) {
402
+ if (current && typeof current === 'object' && stage in current) {
403
+ current = current[stage];
404
+ }
405
+ else {
406
+ throw new Error(`${data.selector} not found in event sample`);
407
+ }
408
+ }
409
+ if (current === null ||
410
+ typeof current === "undefined" ||
411
+ typeof current === "object") {
412
+ throw new Error("Selector value is not allowed to be an object|array|null|undefined");
413
+ }
414
+ }
415
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, session), data)), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
235
416
  await this.initializeProduct(this.product_id);
236
417
  }
237
418
  catch (e) {
@@ -862,11 +1043,43 @@ class ProductsBuilderService {
862
1043
  return messageBroker;
863
1044
  }
864
1045
  fetchMessageBrokers() {
865
- console.log("PROD!", this.product);
866
1046
  return this.product.messageBrokers.map((broker) => {
867
1047
  return this.fetchMessageBroker(broker.tag);
868
1048
  });
869
1049
  }
1050
+ async fetchStorageFiles(filter) {
1051
+ try {
1052
+ const result = await this.productApi.fetchProductStorageFiles(Object.assign(Object.assign({}, filter), { product: this.product.tag }), this.getUserAccess());
1053
+ if (!result)
1054
+ return [];
1055
+ return result.map((res) => {
1056
+ delete res._id;
1057
+ delete res.workspace_id;
1058
+ delete res.__v;
1059
+ res.url = (0, processor_utils_1.decrypt)(res.url, this.product.private_key);
1060
+ return res;
1061
+ });
1062
+ }
1063
+ catch (e) {
1064
+ throw (e);
1065
+ }
1066
+ }
1067
+ async fetchSessionUsers(filter) {
1068
+ try {
1069
+ const result = await this.productApi.fetchProductSessionUsers(Object.assign(Object.assign({}, filter), { product: this.product.tag }), this.getUserAccess());
1070
+ if (!result)
1071
+ return [];
1072
+ return result.map((res) => {
1073
+ delete res._id;
1074
+ delete res.workspace_id;
1075
+ delete res.__v;
1076
+ return res;
1077
+ });
1078
+ }
1079
+ catch (e) {
1080
+ throw (e);
1081
+ }
1082
+ }
870
1083
  async createStorage(data, throwErrorIfExists = false) {
871
1084
  if (!this.fetchStorage(data.tag, false)) {
872
1085
  await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
@@ -999,6 +1212,9 @@ class ProductsBuilderService {
999
1212
  }
1000
1213
  }
1001
1214
  validateVariablesValues(variables, appVariables) {
1215
+ if (!variables) {
1216
+ variables = [];
1217
+ }
1002
1218
  if (appVariables && appVariables.length) {
1003
1219
  appVariables.map((data) => {
1004
1220
  const find = variables.find((value) => value.key === data.key);
@@ -1141,7 +1357,10 @@ class ProductsBuilderService {
1141
1357
  throw new Error(`App ${app.access_tag} not found`);
1142
1358
  }
1143
1359
  const cleanedAppData = await this.validateAppData(appData, app);
1144
- await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, cleanedAppData), { component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1360
+ if (!cleanedAppData.pricing_tag) {
1361
+ cleanedAppData.pricing_tag = `${appData.tag}:${productsBuilder_types_1.PricingTag.FREE}`;
1362
+ }
1363
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, cleanedAppData), { app_tag: appData.tag, component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1145
1364
  await this.initializeProduct(this.product_id);
1146
1365
  }
1147
1366
  else {
@@ -1160,7 +1379,7 @@ class ProductsBuilderService {
1160
1379
  throw new Error(`App with access tag ${access_tag} not found`);
1161
1380
  }
1162
1381
  const version = app.versions.find((version) => version.tag === app.version);
1163
- const status = await this.webhooksApi.fetchWebhooks({ access_tag, app_tag: app.tag, version: app.version }, this.getUserAccess());
1382
+ //const status = await this.webhooksApi.fetchWebhooks({access_tag, app_tag: app.tag, version: app.version}, this.getUserAccess())
1164
1383
  console.log(status);
1165
1384
  if (!version) {
1166
1385
  throw new Error(`Required app version not found`);
@@ -1199,7 +1418,7 @@ class ProductsBuilderService {
1199
1418
  return this.product.apps;
1200
1419
  }
1201
1420
  fetchApp(tag, throwErrorIfExists = false) {
1202
- const app = this.product.apps.find((data) => data.access_tag === tag);
1421
+ const app = this.product.apps.find((data) => data.app_tag === tag || data.access_tag === tag);
1203
1422
  if (!app && throwErrorIfExists)
1204
1423
  throw new Error(`App ${tag} not found`);
1205
1424
  return app;
@@ -1940,7 +2159,7 @@ class ProductsBuilderService {
1940
2159
  });
1941
2160
  }
1942
2161
  async validateActionInputData(data, skipSample = false, option = false, optionIndex = 0) {
1943
- var _a;
2162
+ var _a, _b;
1944
2163
  const { obj } = data, base_data = __rest(data, ["obj"]);
1945
2164
  if (!data.sample && Object.keys(obj).length === 0) {
1946
2165
  return;
@@ -1948,8 +2167,8 @@ class ProductsBuilderService {
1948
2167
  if (!data.sample) {
1949
2168
  throw new Error('Something unexpected happened in validating action input');
1950
2169
  }
1951
- const sequence = data.feature.sequence[data.sequence_index];
1952
- if (obj === undefined || obj === null) {
2170
+ const sequence = data.feature.sequence ? (_a = data.feature) === null || _a === void 0 ? void 0 : _a.sequence[data.sequence_index] : null;
2171
+ if ((obj === undefined || obj === null) && sequence) {
1953
2172
  if (!option) {
1954
2173
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be ${obj}`);
1955
2174
  }
@@ -1957,7 +2176,7 @@ class ProductsBuilderService {
1957
2176
  throw new Error(`option event index ${optionIndex}, ${data.type} should not be ${obj}`);
1958
2177
  }
1959
2178
  }
1960
- if (Object.values(obj).length > 0 && ((_a = data.sample.data) === null || _a === void 0 ? void 0 : _a.length) === 0) {
2179
+ if (sequence && (Object.values(obj).length > 0 && ((_b = data.sample.data) === null || _b === void 0 ? void 0 : _b.length) === 0)) {
1961
2180
  if (!option) {
1962
2181
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should be an empty object`);
1963
2182
  }
@@ -1968,7 +2187,7 @@ class ProductsBuilderService {
1968
2187
  if (Object.values(obj).length === 0 && data.sample.data.length === 0 /*data.sample?.data?.length === 0*/) {
1969
2188
  return;
1970
2189
  }
1971
- if (Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
2190
+ if (sequence && Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
1972
2191
  //console.log("validity err: ",obj, data.sample)
1973
2192
  if (!option) {
1974
2193
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be an empty object`);
@@ -2144,7 +2363,9 @@ class ProductsBuilderService {
2144
2363
  let current_input = input;
2145
2364
  for (let i = 0; i < stages.length; i++) {
2146
2365
  let stage = stages[i];
2147
- const matches = stage.match(/^\[(\d+)\]$/);
2366
+ // Convert to string for .match() call
2367
+ const stageStr = String(stage);
2368
+ const matches = stageStr.match(/^\[(\d+)\]$/);
2148
2369
  if (matches && matches.length === 2) {
2149
2370
  const number = parseInt(matches[1], 10);
2150
2371
  if (!isNaN(number)) {
@@ -2207,7 +2428,9 @@ class ProductsBuilderService {
2207
2428
  throw new Error(`Auth ${stages[0]} does not exist on env ${env.product_env_slug} on app ${access_tag}`);
2208
2429
  }
2209
2430
  const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.fetchProduct().private_key));
2210
- const check = (0, objects_utils_1.findFaultyKeys)(stages.slice(1), decrypted);
2431
+ // Convert stages to string[] for findFaultyKeys
2432
+ const stringStages = stages.slice(1).map(stage => String(stage));
2433
+ const check = (0, objects_utils_1.findFaultyKeys)(stringStages, decrypted);
2211
2434
  if (check.faultyKeys) {
2212
2435
  throw new Error(`Auth Key(s) ${check.faultyKeys.join(', ')} is/are invalid, they do not exist in authorization for ${env.product_env_slug} on app ${access_tag}`);
2213
2436
  }
@@ -2223,7 +2446,9 @@ class ProductsBuilderService {
2223
2446
  let i = 1;
2224
2447
  while (i < stages.length) {
2225
2448
  let stage = stages[i];
2226
- const matches = stage.match(/^\[(\d+)\]$/);
2449
+ // Convert to string for .match() call
2450
+ const stageStr = String(stage);
2451
+ const matches = stageStr.match(/^\[(\d+)\]$/);
2227
2452
  if (matches && matches.length === 2) {
2228
2453
  const number = parseInt(matches[1], 10);
2229
2454
  if (!isNaN(number)) {
@@ -2297,11 +2522,15 @@ class ProductsBuilderService {
2297
2522
  // let current_data;
2298
2523
  if (i === 0) {
2299
2524
  // find sequence by tag, see if it exists and its before current sequence
2300
- this.validateSequenceInputParents(stage, meta.sequence_index, meta.feature.sequence);
2301
- sequence = this.fetchPriorSequence(meta, stage);
2525
+ // Convert stage to string for function calls
2526
+ const stageStr = String(stage);
2527
+ this.validateSequenceInputParents(stageStr, meta.sequence_index, meta.feature.sequence);
2528
+ sequence = this.fetchPriorSequence(meta, stageStr);
2302
2529
  }
2303
2530
  if (i === 1 && sequence) {
2304
- event = this.fetchSequenceEvent(sequence, stage);
2531
+ // Convert stage to string for function calls
2532
+ const stageStr = String(stage);
2533
+ event = this.fetchSequenceEvent(sequence, stageStr);
2305
2534
  if (!event) {
2306
2535
  throw new Error(`event ${stage} not found in sequence ${sequence.tag}`);
2307
2536
  }
@@ -2330,7 +2559,9 @@ class ProductsBuilderService {
2330
2559
  if (i > 1 && response) {
2331
2560
  let parent_index = 0;
2332
2561
  let increment = false;
2333
- const matches = stage.match(/^\[(\d+)\]$/);
2562
+ // Convert to string for .match() call
2563
+ const stageStr = String(stage);
2564
+ const matches = stageStr.match(/^\[(\d+)\]$/);
2334
2565
  if (matches && matches.length === 2) {
2335
2566
  const number = parseInt(matches[1], 10);
2336
2567
  if (!isNaN(number)) {
@@ -2388,7 +2619,7 @@ class ProductsBuilderService {
2388
2619
  if (stages.length > 2) {
2389
2620
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}, has invalid varibale definition ${value}, only two keys is required`);
2390
2621
  }
2391
- const app = this.fetchApp(stages[0]);
2622
+ const app = this.fetchApp(String(stages[0]));
2392
2623
  if (!app) {
2393
2624
  throw new Error(`App ${stages[0]} not found in sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}, has invalid varibale definition ${value}. `);
2394
2625
  }
@@ -2405,8 +2636,8 @@ class ProductsBuilderService {
2405
2636
  if (stages.length !== 2) {
2406
2637
  throw new Error(`When using constants you need to specify the constant in the format $Constant{app_tag}{key} instead of ${value}`);
2407
2638
  }
2408
- const app_tag = stages[0];
2409
- const key = stages[1];
2639
+ const app_tag = String(stages[0]);
2640
+ const key = String(stages[1]);
2410
2641
  const _c = await this.fetchThirdPartyAppByAccessTag(app_tag), { version } = _c, app = __rest(_c, ["version"]);
2411
2642
  if (!app) {
2412
2643
  throw new Error(`App ${app_tag} not found in constant ${value}`);
@@ -2496,9 +2727,10 @@ class ProductsBuilderService {
2496
2727
  return found;
2497
2728
  }
2498
2729
  validateActionKeyPlacement(data) {
2730
+ var _a;
2499
2731
  const actionData = data.sample.data;
2500
2732
  const { indexes } = data;
2501
- const sequence = data.feature.sequence[data.sequence_index];
2733
+ const sequence = data.feature.sequence ? (_a = data.feature) === null || _a === void 0 ? void 0 : _a.sequence[data.sequence_index] : null;
2502
2734
  const datapoint = actionData.find((item) => {
2503
2735
  return (item.parent_key === indexes.parent_key && item.key === data.key && item.level === indexes.level //&&
2504
2736
  //indexes.index === item.index
@@ -2506,7 +2738,12 @@ class ProductsBuilderService {
2506
2738
  });
2507
2739
  if (!datapoint) {
2508
2740
  console.log('VALIDATE', data.key, data.value, actionData, indexes);
2509
- throw new Error(`Key ${data.key} not found for ${data.type} for sequence ${sequence.tag} event ${sequence.events[data.event_index].event}`);
2741
+ if (sequence) {
2742
+ throw new Error(`Key ${data.key} not found for ${data.type} for sequence ${sequence.tag} event ${sequence.events[data.event_index].event}`);
2743
+ }
2744
+ else {
2745
+ throw new Error(`Key ${data.key} not found`);
2746
+ }
2510
2747
  }
2511
2748
  return datapoint;
2512
2749
  }
@@ -2674,11 +2911,13 @@ class ProductsBuilderService {
2674
2911
  }
2675
2912
  fetchDatabase(tag, throwErrorIfExists = false) {
2676
2913
  const database = this.product.databases.find((data) => data.tag === tag);
2677
- database.envs.map((env) => {
2678
- env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.fetchProduct().private_key);
2679
- });
2680
2914
  if (!database && throwErrorIfExists)
2681
2915
  throw new Error(`Database ${tag} not found`);
2916
+ if (database && database.envs.length > 0) {
2917
+ database.envs.map((env) => {
2918
+ env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.fetchProduct().private_key);
2919
+ });
2920
+ }
2682
2921
  return database;
2683
2922
  }
2684
2923
  fetchDatabases() {
@@ -2980,6 +3219,9 @@ class ProductsBuilderService {
2980
3219
  public_key: this.public_key,
2981
3220
  };
2982
3221
  }
3222
+ async fetchSessionUser(ductape_user_id) {
3223
+ return await this.productApi.fetchProductSessionUser(ductape_user_id, this.getUserAccess());
3224
+ }
2983
3225
  }
2984
3226
  exports.default = ProductsBuilderService;
2985
3227
  //# sourceMappingURL=products.service.js.map