@ductape/sdk 0.0.4-v2 → 0.0.4-v20

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 (154) 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/urls.d.ts +7 -1
  16. package/dist/api/urls.js +13 -2
  17. package/dist/api/urls.js.map +1 -1
  18. package/dist/api/utils/strings.utils.d.ts +2 -0
  19. package/dist/api/utils/strings.utils.js +14 -0
  20. package/dist/api/utils/strings.utils.js.map +1 -1
  21. package/dist/apps/services/app.service.js +1 -1
  22. package/dist/apps/services/app.service.js.map +1 -1
  23. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
  24. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
  25. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
  26. package/dist/clients/apps.client.js +1 -1
  27. package/dist/clients/apps.client.js.map +1 -1
  28. package/dist/clients/pricing.client.d.ts +3 -0
  29. package/dist/clients/pricing.client.js +33 -0
  30. package/dist/clients/pricing.client.js.map +1 -0
  31. package/dist/imports/imports.service.d.ts +3 -3
  32. package/dist/imports/imports.service.js +7 -7
  33. package/dist/imports/imports.service.js.map +1 -1
  34. package/dist/imports/imports.types.d.ts +8 -0
  35. package/dist/imports/repos/openApi.repo.d.ts +1 -2
  36. package/dist/imports/repos/openApi.repo.js +43 -71
  37. package/dist/imports/repos/openApi.repo.js.map +1 -1
  38. package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
  39. package/dist/imports/repos/postmanV21.repo.js +29 -2
  40. package/dist/imports/repos/postmanV21.repo.js.map +1 -1
  41. package/dist/index.d.ts +953 -46
  42. package/dist/index.js +918 -81
  43. package/dist/index.js.map +1 -1
  44. package/dist/inputs/inputs.service.js +2 -2
  45. package/dist/inputs/inputs.service.js.map +1 -1
  46. package/dist/inputs/utils/inputs.utils.create.js +1 -1
  47. package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
  48. package/dist/logs/logs.service.js +1 -0
  49. package/dist/logs/logs.service.js.map +1 -1
  50. package/dist/logs/logs.types.d.ts +5 -0
  51. package/dist/logs/logs.types.js.map +1 -1
  52. package/dist/parsers/index.d.ts +3 -0
  53. package/dist/parsers/index.js +27 -0
  54. package/dist/parsers/index.js.map +1 -0
  55. package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
  56. package/dist/parsers/pipelines/postman.pipelines.js +103 -0
  57. package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
  58. package/dist/parsers/types/postman.types.d.ts +200 -0
  59. package/dist/parsers/types/postman.types.js +3 -0
  60. package/dist/parsers/types/postman.types.js.map +1 -0
  61. package/dist/parsers/utils/postman.utils.d.ts +12 -0
  62. package/dist/parsers/utils/postman.utils.js +116 -0
  63. package/dist/parsers/utils/postman.utils.js.map +1 -0
  64. package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
  65. package/dist/parsers/validators/postman-auth.validators.js +127 -0
  66. package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
  67. package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
  68. package/dist/parsers/validators/postman-request.validators.js +139 -0
  69. package/dist/parsers/validators/postman-request.validators.js.map +1 -0
  70. package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
  71. package/dist/parsers/validators/postman-response.validators.js +150 -0
  72. package/dist/parsers/validators/postman-response.validators.js.map +1 -0
  73. package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
  74. package/dist/parsers/validators/postman-variable.validators.js +163 -0
  75. package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
  76. package/dist/pricing/pricing.repo.d.ts +0 -0
  77. package/dist/pricing/pricing.repo.js +1 -0
  78. package/dist/pricing/pricing.repo.js.map +1 -0
  79. package/dist/pricing/pricing.service.d.ts +24 -0
  80. package/dist/pricing/pricing.service.js +51 -0
  81. package/dist/pricing/pricing.service.js.map +1 -0
  82. package/dist/pricing/pricing.types.d.ts +76 -0
  83. package/dist/pricing/pricing.types.js +21 -0
  84. package/dist/pricing/pricing.types.js.map +1 -0
  85. package/dist/pricing/utils/string.utils.d.ts +1 -0
  86. package/dist/pricing/utils/string.utils.js +9 -0
  87. package/dist/pricing/utils/string.utils.js.map +1 -0
  88. package/dist/processor/repos/sms.repo.d.ts +4 -4
  89. package/dist/processor/repos/sms.repo.js +23 -10
  90. package/dist/processor/repos/sms.repo.js.map +1 -1
  91. package/dist/processor/services/processor.service.d.ts +36 -5
  92. package/dist/processor/services/processor.service.js +526 -187
  93. package/dist/processor/services/processor.service.js.map +1 -1
  94. package/dist/processor/services/request.service.d.ts +36 -0
  95. package/dist/processor/services/request.service.js +304 -0
  96. package/dist/processor/services/request.service.js.map +1 -0
  97. package/dist/processor/types/request.types.d.ts +14 -0
  98. package/dist/processor/types/request.types.js +3 -0
  99. package/dist/processor/types/request.types.js.map +1 -0
  100. package/dist/processor/utils/processor.utils.d.ts +3 -0
  101. package/dist/processor/utils/processor.utils.js +88 -5
  102. package/dist/processor/utils/processor.utils.js.map +1 -1
  103. package/dist/processor/utils/request.utils.d.ts +20 -0
  104. package/dist/processor/utils/request.utils.js +113 -0
  105. package/dist/processor/utils/request.utils.js.map +1 -0
  106. package/dist/processor/utils/storage.util.js +54 -40
  107. package/dist/processor/utils/storage.util.js.map +1 -1
  108. package/dist/products/services/products.service.d.ts +19 -4
  109. package/dist/products/services/products.service.js +256 -29
  110. package/dist/products/services/products.service.js.map +1 -1
  111. package/dist/products/validators/index.d.ts +2 -1
  112. package/dist/products/validators/index.js +3 -1
  113. package/dist/products/validators/index.js.map +1 -1
  114. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
  115. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
  116. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
  117. package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
  118. package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
  119. package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
  120. package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
  121. package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
  122. package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
  123. package/dist/test/test.health.d.ts +1 -0
  124. package/dist/test/test.health.js +49 -0
  125. package/dist/test/test.health.js.map +1 -0
  126. package/dist/test/test.import.js +51 -4
  127. package/dist/test/test.import.js.map +1 -1
  128. package/dist/test/test.imports.js +22 -7
  129. package/dist/test/test.imports.js.map +1 -1
  130. package/dist/test/test.processor.js +32 -115
  131. package/dist/test/test.processor.js.map +1 -1
  132. package/dist/test/test.products.d.ts +1 -0
  133. package/dist/test/test.products.js +49 -0
  134. package/dist/test/test.products.js.map +1 -0
  135. package/dist/types/appBuilder.types.d.ts +1 -11
  136. package/dist/types/enums.d.ts +3 -1
  137. package/dist/types/enums.js +2 -0
  138. package/dist/types/enums.js.map +1 -1
  139. package/dist/types/index.types.d.ts +4 -0
  140. package/dist/types/pricing.types.d.ts +4 -0
  141. package/dist/types/pricing.types.js +3 -0
  142. package/dist/types/pricing.types.js.map +1 -0
  143. package/dist/types/processor.types.d.ts +68 -9
  144. package/dist/types/processor.types.js.map +1 -1
  145. package/dist/types/productsBuilder.types.d.ts +58 -2
  146. package/dist/types/productsBuilder.types.js +9 -1
  147. package/dist/types/productsBuilder.types.js.map +1 -1
  148. package/dist/types/request-tracker.interface.d.ts +0 -0
  149. package/dist/types/request-tracker.interface.js +1 -0
  150. package/dist/types/request-tracker.interface.js.map +1 -0
  151. package/dist/utils/constants.d.ts +1 -0
  152. package/dist/utils/constants.js +5 -0
  153. package/dist/utils/constants.js.map +1 -0
  154. 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')) {
@@ -157,6 +288,7 @@ class ProductsBuilderService {
157
288
  async initializeProductByTag(tag) {
158
289
  try {
159
290
  this.product = await this.productApi.fetchProductByTag(tag, this.getUserAccess());
291
+ console.error(this.product, tag);
160
292
  this.product_id = this.product._id;
161
293
  }
162
294
  catch (e) {
@@ -192,19 +324,45 @@ class ProductsBuilderService {
192
324
  }
193
325
  return this.product;
194
326
  }
195
- async createSession(data) {
327
+ async createSession(data, throwErrorIfExists = false) {
196
328
  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({
329
+ await validators_1.CreateProductSessionSchema.validateAsync(data);
330
+ if (!data.tag) {
331
+ throw new Error('tag field is required');
332
+ }
333
+ const exists = this.fetchSession(data.tag);
334
+ if (!exists) {
335
+ if (!data.selector.startsWith('$Session{')) {
336
+ throw new Error('Selector should be in the format $Session{...}{key}');
337
+ }
338
+ const stages = (0, string_utils_1.extractStages)(data.selector);
339
+ let current = data.schema;
340
+ for (const stage of stages) {
341
+ if (current && typeof current === 'object' && stage in current) {
342
+ current = current[stage];
343
+ }
344
+ else {
345
+ throw new Error(`${data.selector} not found in event sample`);
346
+ }
347
+ }
348
+ if (current === null ||
349
+ typeof current === "undefined" ||
350
+ typeof current === "object") {
351
+ throw new Error("Selector value is not allowed to be an object|array|null|undefined");
352
+ }
353
+ data.schema_data = await this.inputsService.parseJson({
201
354
  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());
355
+ expected: inputs_types_1.ExpectedValues.PARSESAMPLE
356
+ });
357
+ data.selectorValue = current;
358
+ const payload = Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE });
359
+ await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
206
360
  await this.initializeProduct(this.product_id);
207
361
  }
362
+ else {
363
+ if (throwErrorIfExists)
364
+ throw new Error(`Session ${data.tag} already exists`);
365
+ }
208
366
  }
209
367
  catch (e) {
210
368
  throw e;
@@ -212,13 +370,13 @@ class ProductsBuilderService {
212
370
  }
213
371
  async updateSession(tag, data) {
214
372
  try {
215
- const auth = this.fetchSession(tag);
216
- if (!auth) {
217
- throw new Error(`Session ${tag} not found`);
373
+ const session = this.fetchSession(tag);
374
+ if (!session) {
375
+ throw new Error(`Session with tag: ${tag} not found`);
218
376
  }
219
377
  //const { _id } = auth;
220
378
  await validators_1.UpdateProductSessionSchema.validateAsync(data); // Change to update;
221
- if (data.tag && this.fetchEnv(data.tag) && data.tag !== tag) {
379
+ if (data.tag && this.fetchSession(data.tag) && data.tag !== tag) {
222
380
  throw new Error(`tag ${data.tag} is in use`); // TODO: also check on the backend
223
381
  }
224
382
  if (!data.tag) {
@@ -230,8 +388,28 @@ class ProductsBuilderService {
230
388
  expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
231
389
  category: enums_1.Categories.DATA,
232
390
  }));
391
+ if (!data.selector) {
392
+ throw new Error('Selector is expected when updating schema');
393
+ }
233
394
  }
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());
395
+ if (data.selector) {
396
+ const stages = (0, string_utils_1.extractStages)(data.selector);
397
+ let current = data.schema;
398
+ for (const stage of stages) {
399
+ if (current && typeof current === 'object' && stage in current) {
400
+ current = current[stage];
401
+ }
402
+ else {
403
+ throw new Error(`${data.selector} not found in event sample`);
404
+ }
405
+ }
406
+ if (current === null ||
407
+ typeof current === "undefined" ||
408
+ typeof current === "object") {
409
+ throw new Error("Selector value is not allowed to be an object|array|null|undefined");
410
+ }
411
+ }
412
+ 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
413
  await this.initializeProduct(this.product_id);
236
414
  }
237
415
  catch (e) {
@@ -862,11 +1040,43 @@ class ProductsBuilderService {
862
1040
  return messageBroker;
863
1041
  }
864
1042
  fetchMessageBrokers() {
865
- console.log("PROD!", this.product);
866
1043
  return this.product.messageBrokers.map((broker) => {
867
1044
  return this.fetchMessageBroker(broker.tag);
868
1045
  });
869
1046
  }
1047
+ async fetchStorageFiles(filter) {
1048
+ try {
1049
+ const result = await this.productApi.fetchProductStorageFiles(Object.assign(Object.assign({}, filter), { product: this.product.tag }), this.getUserAccess());
1050
+ if (!result)
1051
+ return [];
1052
+ return result.map((res) => {
1053
+ delete res._id;
1054
+ delete res.workspace_id;
1055
+ delete res.__v;
1056
+ res.url = (0, processor_utils_1.decrypt)(res.url, this.product.private_key);
1057
+ return res;
1058
+ });
1059
+ }
1060
+ catch (e) {
1061
+ throw (e);
1062
+ }
1063
+ }
1064
+ async fetchSessionUsers(filter) {
1065
+ try {
1066
+ const result = await this.productApi.fetchProductSessionUsers(Object.assign(Object.assign({}, filter), { product: this.product.tag }), this.getUserAccess());
1067
+ if (!result)
1068
+ return [];
1069
+ return result.map((res) => {
1070
+ delete res._id;
1071
+ delete res.workspace_id;
1072
+ delete res.__v;
1073
+ return res;
1074
+ });
1075
+ }
1076
+ catch (e) {
1077
+ throw (e);
1078
+ }
1079
+ }
870
1080
  async createStorage(data, throwErrorIfExists = false) {
871
1081
  if (!this.fetchStorage(data.tag, false)) {
872
1082
  await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
@@ -999,6 +1209,9 @@ class ProductsBuilderService {
999
1209
  }
1000
1210
  }
1001
1211
  validateVariablesValues(variables, appVariables) {
1212
+ if (!variables) {
1213
+ variables = [];
1214
+ }
1002
1215
  if (appVariables && appVariables.length) {
1003
1216
  appVariables.map((data) => {
1004
1217
  const find = variables.find((value) => value.key === data.key);
@@ -1141,7 +1354,10 @@ class ProductsBuilderService {
1141
1354
  throw new Error(`App ${app.access_tag} not found`);
1142
1355
  }
1143
1356
  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());
1357
+ if (!cleanedAppData.pricing_tag) {
1358
+ cleanedAppData.pricing_tag = `${appData.tag}:${productsBuilder_types_1.PricingTag.FREE}`;
1359
+ }
1360
+ 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
1361
  await this.initializeProduct(this.product_id);
1146
1362
  }
1147
1363
  else {
@@ -1160,7 +1376,7 @@ class ProductsBuilderService {
1160
1376
  throw new Error(`App with access tag ${access_tag} not found`);
1161
1377
  }
1162
1378
  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());
1379
+ //const status = await this.webhooksApi.fetchWebhooks({access_tag, app_tag: app.tag, version: app.version}, this.getUserAccess())
1164
1380
  console.log(status);
1165
1381
  if (!version) {
1166
1382
  throw new Error(`Required app version not found`);
@@ -1199,7 +1415,7 @@ class ProductsBuilderService {
1199
1415
  return this.product.apps;
1200
1416
  }
1201
1417
  fetchApp(tag, throwErrorIfExists = false) {
1202
- const app = this.product.apps.find((data) => data.access_tag === tag);
1418
+ const app = this.product.apps.find((data) => data.app_tag === tag || data.access_tag === tag);
1203
1419
  if (!app && throwErrorIfExists)
1204
1420
  throw new Error(`App ${tag} not found`);
1205
1421
  return app;
@@ -1940,7 +2156,7 @@ class ProductsBuilderService {
1940
2156
  });
1941
2157
  }
1942
2158
  async validateActionInputData(data, skipSample = false, option = false, optionIndex = 0) {
1943
- var _a;
2159
+ var _a, _b;
1944
2160
  const { obj } = data, base_data = __rest(data, ["obj"]);
1945
2161
  if (!data.sample && Object.keys(obj).length === 0) {
1946
2162
  return;
@@ -1948,8 +2164,8 @@ class ProductsBuilderService {
1948
2164
  if (!data.sample) {
1949
2165
  throw new Error('Something unexpected happened in validating action input');
1950
2166
  }
1951
- const sequence = data.feature.sequence[data.sequence_index];
1952
- if (obj === undefined || obj === null) {
2167
+ const sequence = data.feature.sequence ? (_a = data.feature) === null || _a === void 0 ? void 0 : _a.sequence[data.sequence_index] : null;
2168
+ if ((obj === undefined || obj === null) && sequence) {
1953
2169
  if (!option) {
1954
2170
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be ${obj}`);
1955
2171
  }
@@ -1957,7 +2173,7 @@ class ProductsBuilderService {
1957
2173
  throw new Error(`option event index ${optionIndex}, ${data.type} should not be ${obj}`);
1958
2174
  }
1959
2175
  }
1960
- if (Object.values(obj).length > 0 && ((_a = data.sample.data) === null || _a === void 0 ? void 0 : _a.length) === 0) {
2176
+ if (sequence && (Object.values(obj).length > 0 && ((_b = data.sample.data) === null || _b === void 0 ? void 0 : _b.length) === 0)) {
1961
2177
  if (!option) {
1962
2178
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should be an empty object`);
1963
2179
  }
@@ -1968,7 +2184,7 @@ class ProductsBuilderService {
1968
2184
  if (Object.values(obj).length === 0 && data.sample.data.length === 0 /*data.sample?.data?.length === 0*/) {
1969
2185
  return;
1970
2186
  }
1971
- if (Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
2187
+ if (sequence && Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
1972
2188
  //console.log("validity err: ",obj, data.sample)
1973
2189
  if (!option) {
1974
2190
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be an empty object`);
@@ -2496,9 +2712,10 @@ class ProductsBuilderService {
2496
2712
  return found;
2497
2713
  }
2498
2714
  validateActionKeyPlacement(data) {
2715
+ var _a;
2499
2716
  const actionData = data.sample.data;
2500
2717
  const { indexes } = data;
2501
- const sequence = data.feature.sequence[data.sequence_index];
2718
+ const sequence = data.feature.sequence ? (_a = data.feature) === null || _a === void 0 ? void 0 : _a.sequence[data.sequence_index] : null;
2502
2719
  const datapoint = actionData.find((item) => {
2503
2720
  return (item.parent_key === indexes.parent_key && item.key === data.key && item.level === indexes.level //&&
2504
2721
  //indexes.index === item.index
@@ -2506,7 +2723,12 @@ class ProductsBuilderService {
2506
2723
  });
2507
2724
  if (!datapoint) {
2508
2725
  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}`);
2726
+ if (sequence) {
2727
+ throw new Error(`Key ${data.key} not found for ${data.type} for sequence ${sequence.tag} event ${sequence.events[data.event_index].event}`);
2728
+ }
2729
+ else {
2730
+ throw new Error(`Key ${data.key} not found`);
2731
+ }
2510
2732
  }
2511
2733
  return datapoint;
2512
2734
  }
@@ -2674,11 +2896,13 @@ class ProductsBuilderService {
2674
2896
  }
2675
2897
  fetchDatabase(tag, throwErrorIfExists = false) {
2676
2898
  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
2899
  if (!database && throwErrorIfExists)
2681
2900
  throw new Error(`Database ${tag} not found`);
2901
+ if (database && database.envs.length > 0) {
2902
+ database.envs.map((env) => {
2903
+ env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.fetchProduct().private_key);
2904
+ });
2905
+ }
2682
2906
  return database;
2683
2907
  }
2684
2908
  fetchDatabases() {
@@ -2980,6 +3204,9 @@ class ProductsBuilderService {
2980
3204
  public_key: this.public_key,
2981
3205
  };
2982
3206
  }
3207
+ async fetchSessionUser(ductape_user_id) {
3208
+ return await this.productApi.fetchProductSessionUser(ductape_user_id, this.getUserAccess());
3209
+ }
2983
3210
  }
2984
3211
  exports.default = ProductsBuilderService;
2985
3212
  //# sourceMappingURL=products.service.js.map