@ductape/sdk 0.0.4-v3 → 0.0.4-v30
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.
- package/dist/api/services/appApi.service.d.ts +2 -2
- package/dist/api/services/appApi.service.js +1 -2
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/pricingApi.service.d.ts +10 -0
- package/dist/api/services/pricingApi.service.js +34 -0
- package/dist/api/services/pricingApi.service.js.map +1 -0
- package/dist/api/services/processorApi.service.d.ts +12 -2
- package/dist/api/services/processorApi.service.js +12 -2
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +5 -1
- package/dist/api/services/productsApi.service.js +22 -0
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/userApi.service.js +1 -0
- package/dist/api/services/userApi.service.js.map +1 -1
- package/dist/api/services/workspaceApi.service.js +1 -0
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +6 -1
- package/dist/api/urls.js +12 -2
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/strings.utils.d.ts +2 -0
- package/dist/api/utils/strings.utils.js +14 -0
- package/dist/api/utils/strings.utils.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +8 -1
- package/dist/apps/services/app.service.js +174 -25
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js +21 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
- package/dist/clients/apps.client.js +1 -1
- package/dist/clients/apps.client.js.map +1 -1
- package/dist/clients/pricing.client.d.ts +3 -0
- package/dist/clients/pricing.client.js +33 -0
- package/dist/clients/pricing.client.js.map +1 -0
- package/dist/imports/imports.service.d.ts +3 -3
- package/dist/imports/imports.service.js +7 -7
- package/dist/imports/imports.service.js.map +1 -1
- package/dist/imports/imports.types.d.ts +8 -0
- package/dist/imports/repos/openApi.repo.d.ts +1 -2
- package/dist/imports/repos/openApi.repo.js +43 -71
- package/dist/imports/repos/openApi.repo.js.map +1 -1
- package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
- package/dist/imports/repos/postmanV21.repo.js +29 -2
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +965 -47
- package/dist/index.js +924 -81
- package/dist/index.js.map +1 -1
- package/dist/inputs/inputs.service.js +2 -2
- package/dist/inputs/inputs.service.js.map +1 -1
- package/dist/inputs/utils/inputs.utils.create.js +1 -1
- package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
- package/dist/logs/logs.service.js +1 -0
- package/dist/logs/logs.service.js.map +1 -1
- package/dist/logs/logs.types.d.ts +5 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/parsers/index.d.ts +3 -0
- package/dist/parsers/index.js +27 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
- package/dist/parsers/pipelines/postman.pipelines.js +103 -0
- package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
- package/dist/parsers/types/postman.types.d.ts +200 -0
- package/dist/parsers/types/postman.types.js +3 -0
- package/dist/parsers/types/postman.types.js.map +1 -0
- package/dist/parsers/utils/postman.utils.d.ts +12 -0
- package/dist/parsers/utils/postman.utils.js +116 -0
- package/dist/parsers/utils/postman.utils.js.map +1 -0
- package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
- package/dist/parsers/validators/postman-auth.validators.js +127 -0
- package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
- package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-request.validators.js +139 -0
- package/dist/parsers/validators/postman-request.validators.js.map +1 -0
- package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-response.validators.js +150 -0
- package/dist/parsers/validators/postman-response.validators.js.map +1 -0
- package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
- package/dist/parsers/validators/postman-variable.validators.js +163 -0
- package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
- package/dist/pricing/pricing.repo.d.ts +0 -0
- package/dist/pricing/pricing.repo.js +1 -0
- package/dist/pricing/pricing.repo.js.map +1 -0
- package/dist/pricing/pricing.service.d.ts +24 -0
- package/dist/pricing/pricing.service.js +51 -0
- package/dist/pricing/pricing.service.js.map +1 -0
- package/dist/pricing/pricing.types.d.ts +76 -0
- package/dist/pricing/pricing.types.js +21 -0
- package/dist/pricing/pricing.types.js.map +1 -0
- package/dist/pricing/utils/string.utils.d.ts +1 -0
- package/dist/pricing/utils/string.utils.js +9 -0
- package/dist/pricing/utils/string.utils.js.map +1 -0
- package/dist/processor/repos/sms.repo.d.ts +4 -4
- package/dist/processor/repos/sms.repo.js +23 -10
- package/dist/processor/repos/sms.repo.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +36 -5
- package/dist/processor/services/processor.service.js +568 -201
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/request.service.d.ts +36 -0
- package/dist/processor/services/request.service.js +304 -0
- package/dist/processor/services/request.service.js.map +1 -0
- package/dist/processor/types/request.types.d.ts +14 -0
- package/dist/processor/types/request.types.js +3 -0
- package/dist/processor/types/request.types.js.map +1 -0
- package/dist/processor/utils/processor.utils.d.ts +3 -0
- package/dist/processor/utils/processor.utils.js +88 -5
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/request.utils.d.ts +20 -0
- package/dist/processor/utils/request.utils.js +113 -0
- package/dist/processor/utils/request.utils.js.map +1 -0
- package/dist/processor/utils/storage.util.js +54 -40
- package/dist/processor/utils/storage.util.js.map +1 -1
- package/dist/products/services/products.service.d.ts +20 -7
- package/dist/products/services/products.service.js +269 -43
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/utils/string.utils.d.ts +1 -1
- package/dist/products/utils/string.utils.js +14 -2
- package/dist/products/utils/string.utils.js.map +1 -1
- package/dist/products/validators/index.d.ts +2 -1
- package/dist/products/validators/index.js +3 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
- package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
- package/dist/test/test.health.d.ts +1 -0
- package/dist/test/test.health.js +49 -0
- package/dist/test/test.health.js.map +1 -0
- package/dist/test/test.import.js +51 -4
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.imports.js +22 -7
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.processor.js +32 -115
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.products.d.ts +1 -0
- package/dist/test/test.products.js +49 -0
- package/dist/test/test.products.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +4 -11
- package/dist/types/enums.d.ts +3 -1
- package/dist/types/enums.js +2 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/index.types.d.ts +4 -0
- package/dist/types/pricing.types.d.ts +4 -0
- package/dist/types/pricing.types.js +3 -0
- package/dist/types/pricing.types.js.map +1 -0
- package/dist/types/processor.types.d.ts +66 -9
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +52 -5
- package/dist/types/productsBuilder.types.js +9 -1
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/types/request-tracker.interface.d.ts +0 -0
- package/dist/types/request-tracker.interface.js +1 -0
- package/dist/types/request-tracker.interface.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/package.json +14 -3
|
@@ -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
|
-
|
|
85
|
-
|
|
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 (
|
|
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
|
-
|
|
198
|
-
if (!
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
|
216
|
-
if (!
|
|
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.
|
|
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
|
+
}
|
|
397
|
+
}
|
|
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
|
+
}
|
|
233
414
|
}
|
|
234
|
-
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({},
|
|
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) {
|
|
@@ -883,6 +1064,22 @@ class ProductsBuilderService {
|
|
|
883
1064
|
throw (e);
|
|
884
1065
|
}
|
|
885
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
|
+
}
|
|
886
1083
|
async createStorage(data, throwErrorIfExists = false) {
|
|
887
1084
|
if (!this.fetchStorage(data.tag, false)) {
|
|
888
1085
|
await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
|
|
@@ -1015,6 +1212,9 @@ class ProductsBuilderService {
|
|
|
1015
1212
|
}
|
|
1016
1213
|
}
|
|
1017
1214
|
validateVariablesValues(variables, appVariables) {
|
|
1215
|
+
if (!variables) {
|
|
1216
|
+
variables = [];
|
|
1217
|
+
}
|
|
1018
1218
|
if (appVariables && appVariables.length) {
|
|
1019
1219
|
appVariables.map((data) => {
|
|
1020
1220
|
const find = variables.find((value) => value.key === data.key);
|
|
@@ -1157,7 +1357,10 @@ class ProductsBuilderService {
|
|
|
1157
1357
|
throw new Error(`App ${app.access_tag} not found`);
|
|
1158
1358
|
}
|
|
1159
1359
|
const cleanedAppData = await this.validateAppData(appData, app);
|
|
1160
|
-
|
|
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());
|
|
1161
1364
|
await this.initializeProduct(this.product_id);
|
|
1162
1365
|
}
|
|
1163
1366
|
else {
|
|
@@ -1176,7 +1379,7 @@ class ProductsBuilderService {
|
|
|
1176
1379
|
throw new Error(`App with access tag ${access_tag} not found`);
|
|
1177
1380
|
}
|
|
1178
1381
|
const version = app.versions.find((version) => version.tag === app.version);
|
|
1179
|
-
const status = await this.webhooksApi.fetchWebhooks({
|
|
1382
|
+
//const status = await this.webhooksApi.fetchWebhooks({access_tag, app_tag: app.tag, version: app.version}, this.getUserAccess())
|
|
1180
1383
|
console.log(status);
|
|
1181
1384
|
if (!version) {
|
|
1182
1385
|
throw new Error(`Required app version not found`);
|
|
@@ -1215,7 +1418,7 @@ class ProductsBuilderService {
|
|
|
1215
1418
|
return this.product.apps;
|
|
1216
1419
|
}
|
|
1217
1420
|
fetchApp(tag, throwErrorIfExists = false) {
|
|
1218
|
-
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);
|
|
1219
1422
|
if (!app && throwErrorIfExists)
|
|
1220
1423
|
throw new Error(`App ${tag} not found`);
|
|
1221
1424
|
return app;
|
|
@@ -1956,7 +2159,7 @@ class ProductsBuilderService {
|
|
|
1956
2159
|
});
|
|
1957
2160
|
}
|
|
1958
2161
|
async validateActionInputData(data, skipSample = false, option = false, optionIndex = 0) {
|
|
1959
|
-
var _a;
|
|
2162
|
+
var _a, _b;
|
|
1960
2163
|
const { obj } = data, base_data = __rest(data, ["obj"]);
|
|
1961
2164
|
if (!data.sample && Object.keys(obj).length === 0) {
|
|
1962
2165
|
return;
|
|
@@ -1964,8 +2167,8 @@ class ProductsBuilderService {
|
|
|
1964
2167
|
if (!data.sample) {
|
|
1965
2168
|
throw new Error('Something unexpected happened in validating action input');
|
|
1966
2169
|
}
|
|
1967
|
-
const sequence = data.feature.sequence[data.sequence_index];
|
|
1968
|
-
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) {
|
|
1969
2172
|
if (!option) {
|
|
1970
2173
|
throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be ${obj}`);
|
|
1971
2174
|
}
|
|
@@ -1973,7 +2176,7 @@ class ProductsBuilderService {
|
|
|
1973
2176
|
throw new Error(`option event index ${optionIndex}, ${data.type} should not be ${obj}`);
|
|
1974
2177
|
}
|
|
1975
2178
|
}
|
|
1976
|
-
if (Object.values(obj).length > 0 && ((
|
|
2179
|
+
if (sequence && (Object.values(obj).length > 0 && ((_b = data.sample.data) === null || _b === void 0 ? void 0 : _b.length) === 0)) {
|
|
1977
2180
|
if (!option) {
|
|
1978
2181
|
throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should be an empty object`);
|
|
1979
2182
|
}
|
|
@@ -1984,7 +2187,7 @@ class ProductsBuilderService {
|
|
|
1984
2187
|
if (Object.values(obj).length === 0 && data.sample.data.length === 0 /*data.sample?.data?.length === 0*/) {
|
|
1985
2188
|
return;
|
|
1986
2189
|
}
|
|
1987
|
-
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) {
|
|
1988
2191
|
//console.log("validity err: ",obj, data.sample)
|
|
1989
2192
|
if (!option) {
|
|
1990
2193
|
throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be an empty object`);
|
|
@@ -2160,7 +2363,9 @@ class ProductsBuilderService {
|
|
|
2160
2363
|
let current_input = input;
|
|
2161
2364
|
for (let i = 0; i < stages.length; i++) {
|
|
2162
2365
|
let stage = stages[i];
|
|
2163
|
-
|
|
2366
|
+
// Convert to string for .match() call
|
|
2367
|
+
const stageStr = String(stage);
|
|
2368
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2164
2369
|
if (matches && matches.length === 2) {
|
|
2165
2370
|
const number = parseInt(matches[1], 10);
|
|
2166
2371
|
if (!isNaN(number)) {
|
|
@@ -2223,7 +2428,9 @@ class ProductsBuilderService {
|
|
|
2223
2428
|
throw new Error(`Auth ${stages[0]} does not exist on env ${env.product_env_slug} on app ${access_tag}`);
|
|
2224
2429
|
}
|
|
2225
2430
|
const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.fetchProduct().private_key));
|
|
2226
|
-
|
|
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);
|
|
2227
2434
|
if (check.faultyKeys) {
|
|
2228
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}`);
|
|
2229
2436
|
}
|
|
@@ -2239,7 +2446,9 @@ class ProductsBuilderService {
|
|
|
2239
2446
|
let i = 1;
|
|
2240
2447
|
while (i < stages.length) {
|
|
2241
2448
|
let stage = stages[i];
|
|
2242
|
-
|
|
2449
|
+
// Convert to string for .match() call
|
|
2450
|
+
const stageStr = String(stage);
|
|
2451
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2243
2452
|
if (matches && matches.length === 2) {
|
|
2244
2453
|
const number = parseInt(matches[1], 10);
|
|
2245
2454
|
if (!isNaN(number)) {
|
|
@@ -2313,11 +2522,15 @@ class ProductsBuilderService {
|
|
|
2313
2522
|
// let current_data;
|
|
2314
2523
|
if (i === 0) {
|
|
2315
2524
|
// find sequence by tag, see if it exists and its before current sequence
|
|
2316
|
-
|
|
2317
|
-
|
|
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);
|
|
2318
2529
|
}
|
|
2319
2530
|
if (i === 1 && sequence) {
|
|
2320
|
-
|
|
2531
|
+
// Convert stage to string for function calls
|
|
2532
|
+
const stageStr = String(stage);
|
|
2533
|
+
event = this.fetchSequenceEvent(sequence, stageStr);
|
|
2321
2534
|
if (!event) {
|
|
2322
2535
|
throw new Error(`event ${stage} not found in sequence ${sequence.tag}`);
|
|
2323
2536
|
}
|
|
@@ -2346,7 +2559,9 @@ class ProductsBuilderService {
|
|
|
2346
2559
|
if (i > 1 && response) {
|
|
2347
2560
|
let parent_index = 0;
|
|
2348
2561
|
let increment = false;
|
|
2349
|
-
|
|
2562
|
+
// Convert to string for .match() call
|
|
2563
|
+
const stageStr = String(stage);
|
|
2564
|
+
const matches = stageStr.match(/^\[(\d+)\]$/);
|
|
2350
2565
|
if (matches && matches.length === 2) {
|
|
2351
2566
|
const number = parseInt(matches[1], 10);
|
|
2352
2567
|
if (!isNaN(number)) {
|
|
@@ -2404,7 +2619,7 @@ class ProductsBuilderService {
|
|
|
2404
2619
|
if (stages.length > 2) {
|
|
2405
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`);
|
|
2406
2621
|
}
|
|
2407
|
-
const app = this.fetchApp(stages[0]);
|
|
2622
|
+
const app = this.fetchApp(String(stages[0]));
|
|
2408
2623
|
if (!app) {
|
|
2409
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}. `);
|
|
2410
2625
|
}
|
|
@@ -2421,8 +2636,8 @@ class ProductsBuilderService {
|
|
|
2421
2636
|
if (stages.length !== 2) {
|
|
2422
2637
|
throw new Error(`When using constants you need to specify the constant in the format $Constant{app_tag}{key} instead of ${value}`);
|
|
2423
2638
|
}
|
|
2424
|
-
const app_tag = stages[0];
|
|
2425
|
-
const key = stages[1];
|
|
2639
|
+
const app_tag = String(stages[0]);
|
|
2640
|
+
const key = String(stages[1]);
|
|
2426
2641
|
const _c = await this.fetchThirdPartyAppByAccessTag(app_tag), { version } = _c, app = __rest(_c, ["version"]);
|
|
2427
2642
|
if (!app) {
|
|
2428
2643
|
throw new Error(`App ${app_tag} not found in constant ${value}`);
|
|
@@ -2512,9 +2727,10 @@ class ProductsBuilderService {
|
|
|
2512
2727
|
return found;
|
|
2513
2728
|
}
|
|
2514
2729
|
validateActionKeyPlacement(data) {
|
|
2730
|
+
var _a;
|
|
2515
2731
|
const actionData = data.sample.data;
|
|
2516
2732
|
const { indexes } = data;
|
|
2517
|
-
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;
|
|
2518
2734
|
const datapoint = actionData.find((item) => {
|
|
2519
2735
|
return (item.parent_key === indexes.parent_key && item.key === data.key && item.level === indexes.level //&&
|
|
2520
2736
|
//indexes.index === item.index
|
|
@@ -2522,7 +2738,12 @@ class ProductsBuilderService {
|
|
|
2522
2738
|
});
|
|
2523
2739
|
if (!datapoint) {
|
|
2524
2740
|
console.log('VALIDATE', data.key, data.value, actionData, indexes);
|
|
2525
|
-
|
|
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
|
+
}
|
|
2526
2747
|
}
|
|
2527
2748
|
return datapoint;
|
|
2528
2749
|
}
|
|
@@ -2690,11 +2911,13 @@ class ProductsBuilderService {
|
|
|
2690
2911
|
}
|
|
2691
2912
|
fetchDatabase(tag, throwErrorIfExists = false) {
|
|
2692
2913
|
const database = this.product.databases.find((data) => data.tag === tag);
|
|
2693
|
-
database.envs.map((env) => {
|
|
2694
|
-
env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.fetchProduct().private_key);
|
|
2695
|
-
});
|
|
2696
2914
|
if (!database && throwErrorIfExists)
|
|
2697
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
|
+
}
|
|
2698
2921
|
return database;
|
|
2699
2922
|
}
|
|
2700
2923
|
fetchDatabases() {
|
|
@@ -2996,6 +3219,9 @@ class ProductsBuilderService {
|
|
|
2996
3219
|
public_key: this.public_key,
|
|
2997
3220
|
};
|
|
2998
3221
|
}
|
|
3222
|
+
async fetchSessionUser(ductape_user_id) {
|
|
3223
|
+
return await this.productApi.fetchProductSessionUser(ductape_user_id, this.getUserAccess());
|
|
3224
|
+
}
|
|
2999
3225
|
}
|
|
3000
3226
|
exports.default = ProductsBuilderService;
|
|
3001
3227
|
//# sourceMappingURL=products.service.js.map
|