@ductape/sdk 0.0.4-v33 → 0.0.4-v35
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 +46 -0
- package/dist/api/services/appApi.service.js +100 -0
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +34 -0
- package/dist/api/services/productsApi.service.js +54 -0
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/utils/cache.utils.d.ts +1 -1
- package/dist/api/utils/cache.utils.js +2 -2
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +32 -32
- package/dist/apps/services/app.service.js +132 -102
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/index.d.ts +44 -44
- package/dist/index.js +45 -45
- package/dist/index.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +4 -4
- package/dist/processor/services/processor.service.js +89 -94
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/products/services/products.service.d.ts +82 -74
- package/dist/products/services/products.service.js +266 -318
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productNotification.validator.js +5 -2
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/test/test.notifiers.d.ts +1 -0
- package/dist/test/test.notifiers.js +85 -0
- package/dist/test/test.notifiers.js.map +1 -0
- package/package.json +2 -1
|
@@ -63,13 +63,22 @@ class ProductsBuilderService {
|
|
|
63
63
|
this.queues = queues;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
fetchPrivateKey() {
|
|
67
|
+
return this.product.private_key;
|
|
68
|
+
}
|
|
69
|
+
fetchWorkspaceId() {
|
|
70
|
+
return this.product.workspace_id;
|
|
71
|
+
}
|
|
72
|
+
fetchProductId() {
|
|
73
|
+
return this.product._id;
|
|
74
|
+
}
|
|
66
75
|
async createHealthcheck(data) {
|
|
67
76
|
try {
|
|
68
77
|
await validators_1.CreateProductHealthcheckSchema.validateAsync(data);
|
|
69
78
|
if (!data.tag) {
|
|
70
79
|
throw new Error('tag field is required');
|
|
71
80
|
}
|
|
72
|
-
const exists = this.fetchHealthcheck(data.app, data.tag);
|
|
81
|
+
const exists = await this.fetchHealthcheck(data.app, data.tag);
|
|
73
82
|
if (!exists) {
|
|
74
83
|
const { app: access_tag, event: action } = data;
|
|
75
84
|
const app = await this.fetchThirdPartyAppByAccessTag(access_tag);
|
|
@@ -79,16 +88,16 @@ class ProductsBuilderService {
|
|
|
79
88
|
}
|
|
80
89
|
const event = version.actions.find((act) => act.tag === action);
|
|
81
90
|
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
82
|
-
const exists = this.fetchEnv(env.slug);
|
|
91
|
+
const exists = await this.fetchEnv(env.slug);
|
|
83
92
|
if (!exists) {
|
|
84
93
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
85
94
|
}
|
|
86
95
|
await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
|
|
87
|
-
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.
|
|
96
|
+
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.product.private_key);
|
|
88
97
|
console.log("INPUT", env);
|
|
89
98
|
return env;
|
|
90
99
|
}));
|
|
91
|
-
const envs = this.fetchEnvs();
|
|
100
|
+
const envs = await this.fetchEnvs();
|
|
92
101
|
console.log("ENVS ===>>>>", envs);
|
|
93
102
|
console.log("DBENVS ====>>>>", data.envs);
|
|
94
103
|
envs.map((env) => {
|
|
@@ -99,7 +108,6 @@ class ProductsBuilderService {
|
|
|
99
108
|
});
|
|
100
109
|
console.log("UPDATING VALUE", data);
|
|
101
110
|
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
111
|
data.envs.map(async (env) => {
|
|
104
112
|
const payload = {
|
|
105
113
|
app: data.app,
|
|
@@ -126,20 +134,20 @@ class ProductsBuilderService {
|
|
|
126
134
|
async updateHealthcheck(tag, data) {
|
|
127
135
|
try {
|
|
128
136
|
// 1. Fetch the existing healthcheck
|
|
129
|
-
const healthcheck = this.fetchHealthcheck(data.app, tag);
|
|
137
|
+
const healthcheck = await this.fetchHealthcheck(data.app, tag);
|
|
130
138
|
if (!healthcheck) {
|
|
131
139
|
throw new Error(`Healthcheck with tag: ${tag} not found`);
|
|
132
140
|
}
|
|
133
141
|
// 2. Validate the incoming data
|
|
134
142
|
await validators_1.CreateProductHealthcheckSchema.validateAsync(data); // No Update schema, use Create
|
|
135
143
|
// 3. Check for tag conflicts
|
|
136
|
-
if (data.tag && data.tag !== tag && this.fetchHealthcheck(data.app, data.tag)) {
|
|
144
|
+
if (data.tag && data.tag !== tag && await this.fetchHealthcheck(data.app, data.tag)) {
|
|
137
145
|
throw new Error(`Healthcheck with tag ${data.tag} already exists`);
|
|
138
146
|
}
|
|
139
147
|
// 4. Validate and process envs
|
|
140
148
|
if (data.envs) {
|
|
141
149
|
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
142
|
-
const exists = this.fetchEnv(env.slug);
|
|
150
|
+
const exists = await this.fetchEnv(env.slug);
|
|
143
151
|
if (!exists) {
|
|
144
152
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
145
153
|
}
|
|
@@ -152,13 +160,13 @@ class ProductsBuilderService {
|
|
|
152
160
|
}
|
|
153
161
|
const event = version.actions.find((act) => act.tag === data.event);
|
|
154
162
|
await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
|
|
155
|
-
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.
|
|
163
|
+
env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.product.private_key);
|
|
156
164
|
}
|
|
157
165
|
return env;
|
|
158
166
|
}));
|
|
159
167
|
}
|
|
160
168
|
// 5. Ensure all product envs are covered
|
|
161
|
-
const envs = this.fetchEnvs();
|
|
169
|
+
const envs = await this.fetchEnvs();
|
|
162
170
|
envs.map((env) => {
|
|
163
171
|
var _a;
|
|
164
172
|
const exists = (_a = data.envs) === null || _a === void 0 ? void 0 : _a.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
@@ -168,24 +176,29 @@ class ProductsBuilderService {
|
|
|
168
176
|
});
|
|
169
177
|
// 6. Update the healthcheck
|
|
170
178
|
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
179
|
}
|
|
173
180
|
catch (e) {
|
|
174
181
|
throw e;
|
|
175
182
|
}
|
|
176
183
|
}
|
|
177
|
-
fetchHealthcheck(access_tag, tag, throwError = false) {
|
|
178
|
-
const
|
|
184
|
+
async fetchHealthcheck(access_tag, tag, throwError = false) {
|
|
185
|
+
const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
|
|
186
|
+
const health = healthchecks.find((data) => data.tag === tag && data.app === access_tag);
|
|
179
187
|
if (!health && throwError)
|
|
180
188
|
throw new Error(`Healthcheck ${tag} not found`);
|
|
181
|
-
return health;
|
|
189
|
+
return health || null;
|
|
182
190
|
}
|
|
183
|
-
fetchHealthchecks(access_tag, throwError = false) {
|
|
184
|
-
const
|
|
191
|
+
async fetchHealthchecks(access_tag, throwError = false) {
|
|
192
|
+
const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
|
|
193
|
+
const health = healthchecks.filter((data) => data.app === access_tag);
|
|
185
194
|
if (!health && throwError)
|
|
186
195
|
throw new Error(`Access tag ${access_tag} not found`);
|
|
187
196
|
return health;
|
|
188
197
|
}
|
|
198
|
+
async fetchProductHealthchecks() {
|
|
199
|
+
const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
|
|
200
|
+
return healthchecks;
|
|
201
|
+
}
|
|
189
202
|
async updateDataValidation(selector, update) {
|
|
190
203
|
if (!selector.startsWith('$Data{') && !selector.startsWith('$Filter')) {
|
|
191
204
|
throw new Error(`selector ${selector} is expected to start with $Data or $Filter`);
|
|
@@ -205,7 +218,7 @@ class ProductsBuilderService {
|
|
|
205
218
|
let data;
|
|
206
219
|
switch (type) {
|
|
207
220
|
case productsBuilder_types_1.FeatureEventTypes.DB_ACTION:
|
|
208
|
-
const action = this.fetchDatabaseAction(tag);
|
|
221
|
+
const action = await this.fetchDatabaseAction(tag);
|
|
209
222
|
if (!action)
|
|
210
223
|
throw new Error(`DB Action ${tag} not found`);
|
|
211
224
|
data = useData ? action.data : action.filterData;
|
|
@@ -216,7 +229,7 @@ class ProductsBuilderService {
|
|
|
216
229
|
if (!stages[3] || (stage3Str !== 'push' && stage3Str !== 'callback' && stage3Str !== 'email')) {
|
|
217
230
|
throw new Error(`Invalid value ${stage3Str} in ${selector}, expected to be "push", "callback" or "email" in notification`);
|
|
218
231
|
}
|
|
219
|
-
const notification = this.fetchNotificationMessage(tag);
|
|
232
|
+
const notification = await this.fetchNotificationMessage(tag);
|
|
220
233
|
if (!notification)
|
|
221
234
|
throw new Error(`Notification ${tag} not found`);
|
|
222
235
|
if (stage3Str === 'push') {
|
|
@@ -261,11 +274,11 @@ class ProductsBuilderService {
|
|
|
261
274
|
await validators_1.CreateProductBuilderSchema.validateAsync(data);
|
|
262
275
|
const exists = await this.checkIfProductExists(data.name);
|
|
263
276
|
if (exists && (exists === null || exists === void 0 ? void 0 : exists._id)) {
|
|
264
|
-
await this.initializeProduct(exists
|
|
277
|
+
// await this.initializeProduct(exists?._id);
|
|
265
278
|
}
|
|
266
279
|
else {
|
|
267
280
|
const product = await this.createNewProduct(data);
|
|
268
|
-
await this.initializeProduct(product._id);
|
|
281
|
+
// await this.initializeProduct(product._id);
|
|
269
282
|
}
|
|
270
283
|
}
|
|
271
284
|
catch (e) {
|
|
@@ -279,7 +292,7 @@ class ProductsBuilderService {
|
|
|
279
292
|
}
|
|
280
293
|
async initializeProduct(product_id) {
|
|
281
294
|
try {
|
|
282
|
-
this.product = await this.productApi.
|
|
295
|
+
this.product = await this.productApi.initProduct(product_id, this.getUserAccess());
|
|
283
296
|
this.product_id = product_id;
|
|
284
297
|
}
|
|
285
298
|
catch (e) {
|
|
@@ -288,7 +301,7 @@ class ProductsBuilderService {
|
|
|
288
301
|
}
|
|
289
302
|
async initializeProductByTag(tag) {
|
|
290
303
|
try {
|
|
291
|
-
this.product = await this.productApi.
|
|
304
|
+
this.product = await this.productApi.initProduct(tag, this.getUserAccess());
|
|
292
305
|
if (!this.product) {
|
|
293
306
|
throw new Error(`Product with tag "${tag}" not found or failed to fetch`);
|
|
294
307
|
}
|
|
@@ -304,7 +317,6 @@ class ProductsBuilderService {
|
|
|
304
317
|
throw new Error('Product not initialized');
|
|
305
318
|
await validators_1.CreateProductBuilderSchema.validateAsync(data);
|
|
306
319
|
await this.productApi.updateProduct(this.product_id, Object.assign({}, data), this.getUserAccess());
|
|
307
|
-
await this.initializeProduct(this.product_id);
|
|
308
320
|
}
|
|
309
321
|
catch (e) {
|
|
310
322
|
throw e;
|
|
@@ -321,11 +333,11 @@ class ProductsBuilderService {
|
|
|
321
333
|
return false;
|
|
322
334
|
}
|
|
323
335
|
}
|
|
324
|
-
fetchProduct() {
|
|
336
|
+
async fetchProduct() {
|
|
325
337
|
if (!this.product) {
|
|
326
338
|
throw new Error('Product not yet initiated');
|
|
327
339
|
}
|
|
328
|
-
return this.product;
|
|
340
|
+
return await this.productApi.fetchProductByTag(this.product.tag, this.getUserAccess());
|
|
329
341
|
}
|
|
330
342
|
async createSession(data, throwErrorIfExists = false) {
|
|
331
343
|
try {
|
|
@@ -333,7 +345,7 @@ class ProductsBuilderService {
|
|
|
333
345
|
if (!data.tag) {
|
|
334
346
|
throw new Error('tag field is required');
|
|
335
347
|
}
|
|
336
|
-
const exists = this.fetchSession(data.tag);
|
|
348
|
+
const exists = await this.fetchSession(data.tag);
|
|
337
349
|
if (!exists) {
|
|
338
350
|
if (!data.selector.startsWith('$Session{')) {
|
|
339
351
|
throw new Error('Selector should be in the format $Session{...}{key}');
|
|
@@ -360,7 +372,6 @@ class ProductsBuilderService {
|
|
|
360
372
|
data.selectorValue = current;
|
|
361
373
|
const payload = Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE });
|
|
362
374
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
363
|
-
await this.initializeProduct(this.product_id);
|
|
364
375
|
}
|
|
365
376
|
else {
|
|
366
377
|
if (throwErrorIfExists)
|
|
@@ -373,7 +384,7 @@ class ProductsBuilderService {
|
|
|
373
384
|
}
|
|
374
385
|
async updateSession(tag, data) {
|
|
375
386
|
try {
|
|
376
|
-
const session = this.fetchSession(tag);
|
|
387
|
+
const session = await this.fetchSession(tag);
|
|
377
388
|
if (!session) {
|
|
378
389
|
throw new Error(`Session with tag: ${tag} not found`);
|
|
379
390
|
}
|
|
@@ -413,18 +424,18 @@ class ProductsBuilderService {
|
|
|
413
424
|
}
|
|
414
425
|
}
|
|
415
426
|
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());
|
|
416
|
-
await this.initializeProduct(this.product_id);
|
|
417
427
|
}
|
|
418
428
|
catch (e) {
|
|
419
429
|
throw e;
|
|
420
430
|
}
|
|
421
431
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return
|
|
432
|
+
async fetchSessions(version) {
|
|
433
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'session', this.getUserAccess());
|
|
434
|
+
return components;
|
|
425
435
|
}
|
|
426
|
-
|
|
427
|
-
|
|
436
|
+
async fetchSession(tag) {
|
|
437
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'session', tag, this.getUserAccess());
|
|
438
|
+
return component;
|
|
428
439
|
}
|
|
429
440
|
async createMessageBrokerTopic(data, throwErrorIfExists = false) {
|
|
430
441
|
try {
|
|
@@ -438,16 +449,17 @@ class ProductsBuilderService {
|
|
|
438
449
|
if (data.sample)
|
|
439
450
|
data.sample = JSON.stringify(data.sample);
|
|
440
451
|
await create_productMessageBrokerTopic_validator_1.default.validateAsync(data);
|
|
441
|
-
const exists = this.fetchMessageBrokerTopic(data.tag);
|
|
442
|
-
const broker = this.fetchMessageBroker(messageBrokerTag);
|
|
443
|
-
|
|
452
|
+
const exists = await this.fetchMessageBrokerTopic(data.tag);
|
|
453
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
454
|
+
if (broker) {
|
|
455
|
+
(0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
|
|
456
|
+
}
|
|
444
457
|
data.tag = tag;
|
|
445
458
|
if (!exists) {
|
|
446
459
|
if (data.sample) {
|
|
447
460
|
data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
|
|
448
461
|
}
|
|
449
462
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_TOPIC, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
450
|
-
await this.initializeProduct(this.product_id);
|
|
451
463
|
}
|
|
452
464
|
else {
|
|
453
465
|
if (throwErrorIfExists)
|
|
@@ -470,12 +482,12 @@ class ProductsBuilderService {
|
|
|
470
482
|
if (!messageBrokerTag || !tag) {
|
|
471
483
|
throw new Error(`tag is expected to be defined as "messageBrokr_tag:topic_tag"`);
|
|
472
484
|
}
|
|
473
|
-
const exists = this.fetchMessageBrokerTopic(data.tag);
|
|
485
|
+
const exists = await this.fetchMessageBrokerTopic(data.tag);
|
|
474
486
|
if (!exists) {
|
|
475
487
|
throw new Error(`Topic ${data.tag} not found`);
|
|
476
488
|
}
|
|
477
|
-
const broker = this.fetchMessageBroker(messageBrokerTag);
|
|
478
|
-
if (data.queueUrls) {
|
|
489
|
+
const broker = await this.fetchMessageBroker(messageBrokerTag);
|
|
490
|
+
if (data.queueUrls && broker) {
|
|
479
491
|
(0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
|
|
480
492
|
}
|
|
481
493
|
data.tag = tag;
|
|
@@ -484,7 +496,6 @@ class ProductsBuilderService {
|
|
|
484
496
|
data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
|
|
485
497
|
}
|
|
486
498
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_TOPIC, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
487
|
-
await this.initializeProduct(this.product_id);
|
|
488
499
|
}
|
|
489
500
|
else {
|
|
490
501
|
throw new Error(`Message Broker Topic ${data.tag} not found`);
|
|
@@ -494,7 +505,7 @@ class ProductsBuilderService {
|
|
|
494
505
|
throw e;
|
|
495
506
|
}
|
|
496
507
|
}
|
|
497
|
-
fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
|
|
508
|
+
async fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
|
|
498
509
|
const [messageBrokerTag, topicTag] = tag.split(':');
|
|
499
510
|
if (!messageBrokerTag || !topicTag) {
|
|
500
511
|
throw new Error(`tag is expected to be defined as "messageBroker_tag:topic_tag"`);
|
|
@@ -507,7 +518,7 @@ class ProductsBuilderService {
|
|
|
507
518
|
throw new Error(`MessageBroker topic ${tag} not found`);
|
|
508
519
|
return topic;
|
|
509
520
|
}
|
|
510
|
-
fetchMessageBrokerTopics(messageBrokerTag) {
|
|
521
|
+
async fetchMessageBrokerTopics(messageBrokerTag) {
|
|
511
522
|
const messageBroker = this.product.messageBrokers.find((data) => data.tag === messageBrokerTag);
|
|
512
523
|
if (!messageBroker)
|
|
513
524
|
throw new Error(`Message Broker ${messageBrokerTag} not found`);
|
|
@@ -545,7 +556,7 @@ class ProductsBuilderService {
|
|
|
545
556
|
this.checkActionQuotaFallbackInput(action.body, option.input.body, input, 'body');
|
|
546
557
|
}
|
|
547
558
|
else {
|
|
548
|
-
const feature = this.fetchFeature(option.event);
|
|
559
|
+
const feature = await this.fetchFeature(option.event);
|
|
549
560
|
if (!feature) {
|
|
550
561
|
throw new Error(`Feature ${option.event} not found`);
|
|
551
562
|
}
|
|
@@ -635,7 +646,7 @@ class ProductsBuilderService {
|
|
|
635
646
|
}
|
|
636
647
|
else {
|
|
637
648
|
// fetch feature
|
|
638
|
-
const feature = this.fetchFeature(option.event);
|
|
649
|
+
const feature = await this.fetchFeature(option.event);
|
|
639
650
|
if (!feature) {
|
|
640
651
|
throw new Error(`Feature ${option.event} not found`);
|
|
641
652
|
}
|
|
@@ -703,7 +714,7 @@ class ProductsBuilderService {
|
|
|
703
714
|
if (!data.tag) {
|
|
704
715
|
throw new Error('tag field is required');
|
|
705
716
|
}
|
|
706
|
-
if (!this.fetchQuota(data.tag)) {
|
|
717
|
+
if (!(await this.fetchQuota(data.tag))) {
|
|
707
718
|
await validators_1.CreateProductQuotaSchema.validateAsync(data);
|
|
708
719
|
await this.validateQuotaFallbackInputAndOutput(data, 'quota');
|
|
709
720
|
data.total_quota = 0;
|
|
@@ -746,7 +757,7 @@ class ProductsBuilderService {
|
|
|
746
757
|
}
|
|
747
758
|
async updateQuota(tag, data) {
|
|
748
759
|
try {
|
|
749
|
-
const quota = this.fetchQuota(tag);
|
|
760
|
+
const quota = await this.fetchQuota(tag);
|
|
750
761
|
if (quota) {
|
|
751
762
|
await validators_1.UpdateProductQuotaSchema.validateAsync(data);
|
|
752
763
|
if (data.options) {
|
|
@@ -794,18 +805,20 @@ class ProductsBuilderService {
|
|
|
794
805
|
throw e;
|
|
795
806
|
}
|
|
796
807
|
}
|
|
797
|
-
|
|
798
|
-
|
|
808
|
+
async fetchQuotas(version) {
|
|
809
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'quota', this.getUserAccess());
|
|
810
|
+
return components;
|
|
799
811
|
}
|
|
800
|
-
|
|
801
|
-
|
|
812
|
+
async fetchQuota(tag, version) {
|
|
813
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'quota', tag, this.getUserAccess());
|
|
814
|
+
return component;
|
|
802
815
|
}
|
|
803
816
|
async createFallback(data) {
|
|
804
817
|
try {
|
|
805
818
|
if (!data.tag) {
|
|
806
819
|
throw new Error('tag field is required');
|
|
807
820
|
}
|
|
808
|
-
if (!this.fetchFallback(data.tag)) {
|
|
821
|
+
if (!(await this.fetchFallback(data.tag))) {
|
|
809
822
|
await validators_1.CreateProductFallbackSchema.validateAsync(data);
|
|
810
823
|
await this.validateQuotaFallbackInputAndOutput(data, 'fallback');
|
|
811
824
|
await Promise.all(data.options.map(async (d) => {
|
|
@@ -845,7 +858,7 @@ class ProductsBuilderService {
|
|
|
845
858
|
}
|
|
846
859
|
async updateFallback(tag, data) {
|
|
847
860
|
try {
|
|
848
|
-
const fallback = this.fetchFallback(tag);
|
|
861
|
+
const fallback = await this.fetchFallback(tag);
|
|
849
862
|
if (fallback) {
|
|
850
863
|
await validators_1.UpdateProductFallbackSchema.validateAsync(data);
|
|
851
864
|
if (data.options) {
|
|
@@ -890,19 +903,20 @@ class ProductsBuilderService {
|
|
|
890
903
|
throw e;
|
|
891
904
|
}
|
|
892
905
|
}
|
|
893
|
-
|
|
894
|
-
|
|
906
|
+
async fetchFallbacks(version) {
|
|
907
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'fallback', this.getUserAccess());
|
|
908
|
+
return components;
|
|
895
909
|
}
|
|
896
|
-
|
|
897
|
-
|
|
910
|
+
async fetchFallback(tag, version) {
|
|
911
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'fallback', tag, this.getUserAccess());
|
|
912
|
+
return component;
|
|
898
913
|
}
|
|
899
914
|
async createEnv(data, throwErrorIfExists = false) {
|
|
900
915
|
try {
|
|
901
916
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
902
|
-
if (!this.fetchEnv(data.slug)) {
|
|
917
|
+
if (!(await this.fetchEnv(data.slug))) {
|
|
903
918
|
await validators_1.CreateProductEnvSchema.validateAsync(data);
|
|
904
919
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.ENV, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
905
|
-
await this.initializeProduct(this.product_id);
|
|
906
920
|
}
|
|
907
921
|
else {
|
|
908
922
|
if (throwErrorIfExists)
|
|
@@ -915,54 +929,53 @@ class ProductsBuilderService {
|
|
|
915
929
|
}
|
|
916
930
|
async updateEnv(slug, data) {
|
|
917
931
|
try {
|
|
918
|
-
const env = this.fetchEnv(slug
|
|
932
|
+
const env = await this.fetchEnv(slug);
|
|
919
933
|
if (!env) {
|
|
920
934
|
throw new Error(`Env ${slug} not found`);
|
|
921
935
|
}
|
|
922
936
|
const { _id } = env;
|
|
923
937
|
await validators_1.UpdateProductEnvSchema.validateAsync(data); // Change to update;
|
|
924
|
-
if (data.slug && this.fetchEnv(data.slug)) {
|
|
938
|
+
if (data.slug && (await this.fetchEnv(data.slug))) {
|
|
925
939
|
throw new Error(`slug ${slug} is in use`); // TODO: also check on the backend
|
|
926
940
|
}
|
|
927
941
|
if (!data.slug) {
|
|
928
942
|
data.slug = slug;
|
|
929
943
|
}
|
|
930
944
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, env), data)), { component: enums_1.ProductComponents.ENV, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
931
|
-
await this.initializeProduct(this.product_id);
|
|
932
945
|
}
|
|
933
946
|
catch (e) {
|
|
934
947
|
throw e;
|
|
935
948
|
}
|
|
936
949
|
}
|
|
937
|
-
fetchEnvs() {
|
|
938
|
-
|
|
950
|
+
async fetchEnvs(version) {
|
|
951
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'env', this.getUserAccess());
|
|
952
|
+
return components;
|
|
939
953
|
}
|
|
940
|
-
fetchEnv(slug
|
|
941
|
-
const
|
|
942
|
-
|
|
943
|
-
throw new Error(`Env ${slug} not found`);
|
|
944
|
-
return env;
|
|
954
|
+
async fetchEnv(slug) {
|
|
955
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'env', slug, this.getUserAccess());
|
|
956
|
+
return component;
|
|
945
957
|
}
|
|
946
958
|
async createMessageBroker(data, throwErrorIfExists = false) {
|
|
947
|
-
if (!this.fetchMessageBroker(data.tag
|
|
959
|
+
if (!(await this.fetchMessageBroker(data.tag))) {
|
|
948
960
|
await validators_1.CreateMessageBrokerSchema.validateAsync(data);
|
|
949
|
-
|
|
950
|
-
|
|
961
|
+
const processedEnvs = [];
|
|
962
|
+
for (const env of data.envs) {
|
|
963
|
+
const exists = await this.fetchEnv(env.slug);
|
|
951
964
|
if (!exists) {
|
|
952
965
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
953
966
|
}
|
|
954
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.
|
|
955
|
-
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
envs.
|
|
967
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
968
|
+
processedEnvs.push(env);
|
|
969
|
+
}
|
|
970
|
+
data.envs = processedEnvs;
|
|
971
|
+
const envs = await this.fetchEnvs();
|
|
972
|
+
for (const env of envs) {
|
|
959
973
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
960
974
|
if (exists === -1) {
|
|
961
975
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
962
976
|
}
|
|
963
|
-
}
|
|
977
|
+
}
|
|
964
978
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.MESSAGEBROKER, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
965
|
-
await this.initializeProduct(this.product_id);
|
|
966
979
|
}
|
|
967
980
|
else {
|
|
968
981
|
if (throwErrorIfExists)
|
|
@@ -971,30 +984,32 @@ class ProductsBuilderService {
|
|
|
971
984
|
}
|
|
972
985
|
async updateMessageBroker(tag, data) {
|
|
973
986
|
try {
|
|
974
|
-
const messageBroker = this.fetchMessageBroker(tag);
|
|
987
|
+
const messageBroker = await this.fetchMessageBroker(tag);
|
|
975
988
|
if (!messageBroker) {
|
|
976
989
|
throw new Error(`Broker ${tag} not found`);
|
|
977
990
|
}
|
|
978
991
|
const { _id, envs } = messageBroker;
|
|
979
992
|
await validators_1.UpdateMessageBrokerSchema.validateAsync(data); // Change to update;
|
|
980
|
-
if (data.tag && this.fetchMessageBroker(data.tag)) {
|
|
993
|
+
if (data.tag && (await this.fetchMessageBroker(data.tag))) {
|
|
981
994
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
982
995
|
}
|
|
983
996
|
console.log('2', data.envs);
|
|
984
|
-
|
|
985
|
-
|
|
997
|
+
const processedEnvs = [];
|
|
998
|
+
for (const env of data.envs) {
|
|
999
|
+
const exists = await this.fetchEnv(env.slug);
|
|
986
1000
|
if (!exists) {
|
|
987
1001
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
988
1002
|
}
|
|
989
1003
|
if (env.config)
|
|
990
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.
|
|
991
|
-
|
|
992
|
-
}
|
|
1004
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1005
|
+
processedEnvs.push(env);
|
|
1006
|
+
}
|
|
1007
|
+
data.envs = processedEnvs;
|
|
993
1008
|
const overwrite = [];
|
|
994
1009
|
const newEnvs = [];
|
|
995
|
-
data.envs
|
|
1010
|
+
for (const dataEnv of data.envs) {
|
|
996
1011
|
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
997
|
-
if (!this.fetchEnv(dataEnv.slug)) {
|
|
1012
|
+
if (!(await this.fetchEnv(dataEnv.slug))) {
|
|
998
1013
|
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
999
1014
|
}
|
|
1000
1015
|
if (exists === -1) {
|
|
@@ -1005,47 +1020,36 @@ class ProductsBuilderService {
|
|
|
1005
1020
|
}
|
|
1006
1021
|
else {
|
|
1007
1022
|
if (envs[exists].config) {
|
|
1008
|
-
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.
|
|
1023
|
+
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.product.private_key);
|
|
1009
1024
|
}
|
|
1010
1025
|
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1011
1026
|
}
|
|
1012
|
-
}
|
|
1027
|
+
}
|
|
1013
1028
|
const unchanged = [];
|
|
1014
|
-
|
|
1029
|
+
for (const env of envs) {
|
|
1015
1030
|
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1016
1031
|
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1017
1032
|
if (!newEnv && !overwriteEnv) {
|
|
1018
1033
|
if (env.config) {
|
|
1019
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.
|
|
1034
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1020
1035
|
}
|
|
1021
1036
|
unchanged.push(env);
|
|
1022
1037
|
}
|
|
1023
|
-
}
|
|
1038
|
+
}
|
|
1024
1039
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1025
1040
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, messageBroker), data), { component: enums_1.ProductComponents.MESSAGEBROKER, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1026
|
-
await this.initializeProduct(this.product_id);
|
|
1027
1041
|
}
|
|
1028
1042
|
catch (e) {
|
|
1029
1043
|
throw e;
|
|
1030
1044
|
}
|
|
1031
1045
|
}
|
|
1032
|
-
|
|
1033
|
-
const
|
|
1034
|
-
|
|
1035
|
-
throw new Error(`Message Broker ${tag} not found`);
|
|
1036
|
-
if (messageBroker) {
|
|
1037
|
-
messageBroker.envs.map((broker) => {
|
|
1038
|
-
if (typeof broker.config === 'string') {
|
|
1039
|
-
broker.config = JSON.parse((0, processor_utils_1.decrypt)(String(broker.config), this.fetchProduct().private_key));
|
|
1040
|
-
}
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
return messageBroker;
|
|
1046
|
+
async fetchMessageBrokers(version) {
|
|
1047
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'message_broker', this.getUserAccess());
|
|
1048
|
+
return components;
|
|
1044
1049
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
});
|
|
1050
|
+
async fetchMessageBroker(tag, version) {
|
|
1051
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'message_broker', tag, this.getUserAccess());
|
|
1052
|
+
return component;
|
|
1049
1053
|
}
|
|
1050
1054
|
async fetchStorageFiles(filter) {
|
|
1051
1055
|
try {
|
|
@@ -1081,10 +1085,11 @@ class ProductsBuilderService {
|
|
|
1081
1085
|
}
|
|
1082
1086
|
}
|
|
1083
1087
|
async createStorage(data, throwErrorIfExists = false) {
|
|
1084
|
-
if (!this.fetchStorage(data.tag
|
|
1088
|
+
if (!(await this.fetchStorage(data.tag))) {
|
|
1085
1089
|
await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
|
|
1086
|
-
|
|
1087
|
-
|
|
1090
|
+
const processedEnvs = [];
|
|
1091
|
+
for (const env of data.envs) {
|
|
1092
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1088
1093
|
if (!exists) {
|
|
1089
1094
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
1090
1095
|
}
|
|
@@ -1092,18 +1097,18 @@ class ProductsBuilderService {
|
|
|
1092
1097
|
// @ts-ignore
|
|
1093
1098
|
//env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
|
|
1094
1099
|
}
|
|
1095
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.
|
|
1096
|
-
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
envs.
|
|
1100
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1101
|
+
processedEnvs.push(env);
|
|
1102
|
+
}
|
|
1103
|
+
data.envs = processedEnvs;
|
|
1104
|
+
const envs = await this.fetchEnvs();
|
|
1105
|
+
for (const env of envs) {
|
|
1100
1106
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
1101
1107
|
if (exists === -1) {
|
|
1102
1108
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
1103
1109
|
}
|
|
1104
|
-
}
|
|
1110
|
+
}
|
|
1105
1111
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1106
|
-
await this.initializeProduct(this.product_id);
|
|
1107
1112
|
}
|
|
1108
1113
|
else {
|
|
1109
1114
|
if (throwErrorIfExists)
|
|
@@ -1112,7 +1117,7 @@ class ProductsBuilderService {
|
|
|
1112
1117
|
}
|
|
1113
1118
|
async updateStorage(tag, data) {
|
|
1114
1119
|
try {
|
|
1115
|
-
const storage = this.fetchStorage(tag);
|
|
1120
|
+
const storage = await this.fetchStorage(tag);
|
|
1116
1121
|
if (!storage) {
|
|
1117
1122
|
throw new Error(`Storage ${tag} not found`);
|
|
1118
1123
|
}
|
|
@@ -1121,8 +1126,8 @@ class ProductsBuilderService {
|
|
|
1121
1126
|
if (data.tag && this.fetchStorage(data.tag)) {
|
|
1122
1127
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1123
1128
|
}
|
|
1124
|
-
data.envs = data.envs.map((env) => {
|
|
1125
|
-
const exists = this.fetchEnv(env.slug);
|
|
1129
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
1130
|
+
const exists = await this.fetchEnv(env.slug);
|
|
1126
1131
|
if (!exists) {
|
|
1127
1132
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
1128
1133
|
}
|
|
@@ -1131,9 +1136,9 @@ class ProductsBuilderService {
|
|
|
1131
1136
|
//env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
|
|
1132
1137
|
}
|
|
1133
1138
|
if (env.config)
|
|
1134
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.
|
|
1139
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1135
1140
|
return env;
|
|
1136
|
-
});
|
|
1141
|
+
}));
|
|
1137
1142
|
const overwrite = [];
|
|
1138
1143
|
const newEnvs = [];
|
|
1139
1144
|
data.envs.map((dataEnv) => {
|
|
@@ -1149,7 +1154,7 @@ class ProductsBuilderService {
|
|
|
1149
1154
|
}
|
|
1150
1155
|
else {
|
|
1151
1156
|
if (envs[exists].config) {
|
|
1152
|
-
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.
|
|
1157
|
+
envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.product.private_key);
|
|
1153
1158
|
}
|
|
1154
1159
|
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1155
1160
|
}
|
|
@@ -1160,36 +1165,25 @@ class ProductsBuilderService {
|
|
|
1160
1165
|
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1161
1166
|
if (!newEnv && !overwriteEnv) {
|
|
1162
1167
|
if (env.config) {
|
|
1163
|
-
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.
|
|
1168
|
+
env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
|
|
1164
1169
|
}
|
|
1165
1170
|
unchanged.push(env);
|
|
1166
1171
|
}
|
|
1167
1172
|
});
|
|
1168
1173
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1169
1174
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, storage), data), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1170
|
-
await this.initializeProduct(this.product_id);
|
|
1171
1175
|
}
|
|
1172
1176
|
catch (e) {
|
|
1173
1177
|
throw e;
|
|
1174
1178
|
}
|
|
1175
1179
|
}
|
|
1176
|
-
|
|
1177
|
-
const
|
|
1178
|
-
|
|
1179
|
-
throw new Error(`Storage ${tag} not found`);
|
|
1180
|
-
if (storage) {
|
|
1181
|
-
storage.envs.map((store) => {
|
|
1182
|
-
if (typeof store.config === 'string') {
|
|
1183
|
-
store.config = JSON.parse((0, processor_utils_1.decrypt)(String(store.config), this.fetchProduct().private_key));
|
|
1184
|
-
}
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
return storage;
|
|
1180
|
+
async fetchStorages(version) {
|
|
1181
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'storage', this.getUserAccess());
|
|
1182
|
+
return components;
|
|
1188
1183
|
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
});
|
|
1184
|
+
async fetchStorage(tag, version) {
|
|
1185
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'storage', tag, this.getUserAccess());
|
|
1186
|
+
return component;
|
|
1193
1187
|
}
|
|
1194
1188
|
async validateAppData(appData, app) {
|
|
1195
1189
|
// TODO:
|
|
@@ -1231,7 +1225,7 @@ class ProductsBuilderService {
|
|
|
1231
1225
|
const { envs: appEnvs } = version;
|
|
1232
1226
|
return envs.map((env) => {
|
|
1233
1227
|
const { auth } = env;
|
|
1234
|
-
this.fetchEnv(env.product_env_slug
|
|
1228
|
+
this.fetchEnv(env.product_env_slug);
|
|
1235
1229
|
const appEnv = appEnvs.find((appEnv) => appEnv.slug === env.app_env_slug);
|
|
1236
1230
|
if (!appEnv) {
|
|
1237
1231
|
throw new Error(`app_slug ${env.app_env_slug} not found`);
|
|
@@ -1321,10 +1315,10 @@ class ProductsBuilderService {
|
|
|
1321
1315
|
});
|
|
1322
1316
|
(0, inputs_utils_create_1.validateInputSchema)(queryValues, querySchema);
|
|
1323
1317
|
}
|
|
1324
|
-
const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.
|
|
1318
|
+
const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.product.private_key);
|
|
1325
1319
|
let updateValues = null;
|
|
1326
1320
|
if (exists.setup_type === enums_1.AuthTypes.TOKEN) {
|
|
1327
|
-
updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.
|
|
1321
|
+
updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.product.private_key);
|
|
1328
1322
|
}
|
|
1329
1323
|
return { data: updateData, values: updateValues };
|
|
1330
1324
|
}
|
|
@@ -1361,7 +1355,6 @@ class ProductsBuilderService {
|
|
|
1361
1355
|
cleanedAppData.pricing_tag = `${appData.tag}:${productsBuilder_types_1.PricingTag.FREE}`;
|
|
1362
1356
|
}
|
|
1363
1357
|
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());
|
|
1364
|
-
await this.initializeProduct(this.product_id);
|
|
1365
1358
|
}
|
|
1366
1359
|
else {
|
|
1367
1360
|
if (throwErrorIfExists)
|
|
@@ -1392,7 +1385,7 @@ class ProductsBuilderService {
|
|
|
1392
1385
|
}
|
|
1393
1386
|
async updateApp(access_tag, data) {
|
|
1394
1387
|
try {
|
|
1395
|
-
const app = this.fetchApp(access_tag);
|
|
1388
|
+
const app = await this.fetchApp(access_tag);
|
|
1396
1389
|
if (!app) {
|
|
1397
1390
|
throw new Error(`App ${access_tag} not found`);
|
|
1398
1391
|
}
|
|
@@ -1408,16 +1401,15 @@ class ProductsBuilderService {
|
|
|
1408
1401
|
throw new Error(`access_tag ${access_tag} is in use`); // TODO: also check on the backend
|
|
1409
1402
|
}*/
|
|
1410
1403
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { access_tag, component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1411
|
-
await this.initializeProduct(this.product_id);
|
|
1412
1404
|
}
|
|
1413
1405
|
catch (e) {
|
|
1414
1406
|
throw e;
|
|
1415
1407
|
}
|
|
1416
1408
|
}
|
|
1417
|
-
fetchApps() {
|
|
1409
|
+
async fetchApps() {
|
|
1418
1410
|
return this.product.apps;
|
|
1419
1411
|
}
|
|
1420
|
-
fetchApp(tag, throwErrorIfExists = false) {
|
|
1412
|
+
async fetchApp(tag, throwErrorIfExists = false) {
|
|
1421
1413
|
const app = this.product.apps.find((data) => data.app_tag === tag || data.access_tag === tag);
|
|
1422
1414
|
if (!app && throwErrorIfExists)
|
|
1423
1415
|
throw new Error(`App ${tag} not found`);
|
|
@@ -1426,10 +1418,10 @@ class ProductsBuilderService {
|
|
|
1426
1418
|
async createFunction(data, throwErrorIfExists = false) {
|
|
1427
1419
|
try {
|
|
1428
1420
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1429
|
-
if (!this.fetchFunction(data.tag)) {
|
|
1421
|
+
if (!(await this.fetchFunction(data.tag))) {
|
|
1430
1422
|
await validators_1.CreateProductFunctionSchema.validateAsync(data);
|
|
1431
1423
|
data.envs.map((env) => {
|
|
1432
|
-
env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.
|
|
1424
|
+
env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.product.private_key);
|
|
1433
1425
|
});
|
|
1434
1426
|
data.sample_data = (await this.inputsService.parseJson({
|
|
1435
1427
|
data: data.sample,
|
|
@@ -1442,7 +1434,6 @@ class ProductsBuilderService {
|
|
|
1442
1434
|
category: enums_1.Categories.DATA,
|
|
1443
1435
|
}));
|
|
1444
1436
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FUNCTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1445
|
-
await this.initializeProduct(this.product_id);
|
|
1446
1437
|
}
|
|
1447
1438
|
else {
|
|
1448
1439
|
if (throwErrorIfExists)
|
|
@@ -1455,37 +1446,35 @@ class ProductsBuilderService {
|
|
|
1455
1446
|
}
|
|
1456
1447
|
async updateFunction(tag, data) {
|
|
1457
1448
|
try {
|
|
1458
|
-
const func = this.fetchFunction(tag);
|
|
1449
|
+
const func = await this.fetchFunction(tag);
|
|
1459
1450
|
if (!func) {
|
|
1460
1451
|
throw new Error(`Function ${tag} not found`);
|
|
1461
1452
|
}
|
|
1462
1453
|
const { _id } = func;
|
|
1463
1454
|
await validators_1.UpdateProductFunctionSchema.validateAsync(data); // Change to update;
|
|
1464
|
-
if (data.tag && this.fetchFunction(data.tag)) {
|
|
1455
|
+
if (data.tag && await this.fetchFunction(data.tag)) {
|
|
1465
1456
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1466
1457
|
}
|
|
1467
1458
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, func), data), { component: enums_1.ProductComponents.FUNCTION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1468
|
-
await this.initializeProduct(this.product_id);
|
|
1469
1459
|
}
|
|
1470
1460
|
catch (e) {
|
|
1471
1461
|
throw e;
|
|
1472
1462
|
}
|
|
1473
1463
|
}
|
|
1474
|
-
fetchFunctions() {
|
|
1475
|
-
|
|
1464
|
+
async fetchFunctions(version) {
|
|
1465
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'function', this.getUserAccess());
|
|
1466
|
+
return components;
|
|
1476
1467
|
}
|
|
1477
|
-
fetchFunction(tag) {
|
|
1478
|
-
const
|
|
1479
|
-
|
|
1480
|
-
return func;
|
|
1468
|
+
async fetchFunction(tag, version) {
|
|
1469
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'function', tag, this.getUserAccess());
|
|
1470
|
+
return component;
|
|
1481
1471
|
}
|
|
1482
1472
|
async createCache(data, throwErrorIfExists = false) {
|
|
1483
1473
|
try {
|
|
1484
1474
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1485
|
-
if (!this.fetchCache(data.tag)) {
|
|
1475
|
+
if (!(await this.fetchCache(data.tag))) {
|
|
1486
1476
|
await validators_1.CreateProductCacheSchema.validateAsync(data);
|
|
1487
1477
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.CACHE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1488
|
-
await this.initializeProduct(this.product_id);
|
|
1489
1478
|
}
|
|
1490
1479
|
else {
|
|
1491
1480
|
if (throwErrorIfExists)
|
|
@@ -1498,62 +1487,59 @@ class ProductsBuilderService {
|
|
|
1498
1487
|
}
|
|
1499
1488
|
async updateCache(tag, data) {
|
|
1500
1489
|
try {
|
|
1501
|
-
const cache = this.fetchCache(tag);
|
|
1490
|
+
const cache = await this.fetchCache(tag);
|
|
1502
1491
|
if (!cache) {
|
|
1503
1492
|
throw new Error(`Cache ${tag} not found`);
|
|
1504
1493
|
}
|
|
1505
1494
|
const { _id } = cache;
|
|
1506
1495
|
await validators_1.UpdateProductCacheSchema.validateAsync(data); // Change to update;
|
|
1507
|
-
if (data.tag && this.fetchCache(data.tag)) {
|
|
1496
|
+
if (data.tag && await this.fetchCache(data.tag)) {
|
|
1508
1497
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1509
1498
|
}
|
|
1510
1499
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { component: enums_1.ProductComponents.CACHE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1511
|
-
await this.initializeProduct(this.product_id);
|
|
1512
1500
|
}
|
|
1513
1501
|
catch (e) {
|
|
1514
1502
|
throw e;
|
|
1515
1503
|
}
|
|
1516
1504
|
}
|
|
1517
|
-
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
throw new Error(`Cache ${tag} not found`);
|
|
1521
|
-
return cache;
|
|
1505
|
+
async fetchCaches(version) {
|
|
1506
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'cache', this.getUserAccess());
|
|
1507
|
+
return components;
|
|
1522
1508
|
}
|
|
1523
|
-
|
|
1524
|
-
|
|
1509
|
+
async fetchCache(tag, version) {
|
|
1510
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'cache', tag, this.getUserAccess());
|
|
1511
|
+
return component;
|
|
1525
1512
|
}
|
|
1526
1513
|
async createNotification(data, throwErrorIfExists = false) {
|
|
1527
1514
|
try {
|
|
1528
1515
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
1529
|
-
if (!this.fetchNotification(data.tag)) {
|
|
1516
|
+
if (!(await this.fetchNotification(data.tag))) {
|
|
1530
1517
|
await validators_1.CreateProductNotificationSchema.validateAsync(data);
|
|
1531
|
-
const envs = this.fetchEnvs();
|
|
1532
|
-
|
|
1518
|
+
const envs = await this.fetchEnvs();
|
|
1519
|
+
for (const env of envs) {
|
|
1533
1520
|
const exists = data.envs.findIndex((nEnv) => nEnv.slug === env.slug);
|
|
1534
1521
|
if (exists === -1) {
|
|
1535
1522
|
throw new Error(`Notification for environment ${env.slug} is not defined, please provide the environment details`);
|
|
1536
1523
|
}
|
|
1537
|
-
}
|
|
1524
|
+
}
|
|
1538
1525
|
for (let i = 0; i < data.envs.length; i++) {
|
|
1539
1526
|
const updates = {
|
|
1540
1527
|
push_notifications: data.envs[i].push_notifications
|
|
1541
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].push_notifications), this.
|
|
1528
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].push_notifications), this.product.private_key)
|
|
1542
1529
|
: undefined,
|
|
1543
1530
|
emails: data.envs[i].emails
|
|
1544
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].emails), this.
|
|
1531
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].emails), this.product.private_key)
|
|
1545
1532
|
: undefined,
|
|
1546
1533
|
callbacks: data.envs[i].callbacks
|
|
1547
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].callbacks), this.
|
|
1534
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].callbacks), this.product.private_key)
|
|
1548
1535
|
: undefined,
|
|
1549
1536
|
sms: data.envs[i].sms
|
|
1550
|
-
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].sms), this.
|
|
1537
|
+
? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].sms), this.product.private_key)
|
|
1551
1538
|
: undefined,
|
|
1552
1539
|
};
|
|
1553
1540
|
data.envs[i] = Object.assign(Object.assign({}, data.envs[i]), updates);
|
|
1554
1541
|
}
|
|
1555
1542
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1556
|
-
await this.initializeProduct(this.product_id);
|
|
1557
1543
|
}
|
|
1558
1544
|
else {
|
|
1559
1545
|
if (throwErrorIfExists)
|
|
@@ -1574,7 +1560,7 @@ class ProductsBuilderService {
|
|
|
1574
1560
|
if (!notificationTag || !tag) {
|
|
1575
1561
|
throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
|
|
1576
1562
|
}
|
|
1577
|
-
const exists = this.fetchNotificationMessage(data.tag);
|
|
1563
|
+
const exists = await this.fetchNotificationMessage(data.tag);
|
|
1578
1564
|
data.tag = tag;
|
|
1579
1565
|
if (!exists) {
|
|
1580
1566
|
if (!data.email && !data.push_notification && !data.callback) {
|
|
@@ -1611,7 +1597,6 @@ class ProductsBuilderService {
|
|
|
1611
1597
|
data.sms_data = (0, string_utils_1.extractPlaceholders)(data.sms, '');
|
|
1612
1598
|
}
|
|
1613
1599
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { notificationTag, component: enums_1.ProductComponents.NOTIFICATION_MESSAGE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
1614
|
-
await this.initializeProduct(this.product_id);
|
|
1615
1600
|
}
|
|
1616
1601
|
else {
|
|
1617
1602
|
if (throwErrorIfExists)
|
|
@@ -1622,12 +1607,12 @@ class ProductsBuilderService {
|
|
|
1622
1607
|
throw e;
|
|
1623
1608
|
}
|
|
1624
1609
|
}
|
|
1625
|
-
fetchNotificationMessage(tag, throwErrorIfExists = false) {
|
|
1610
|
+
async fetchNotificationMessage(tag, throwErrorIfExists = false) {
|
|
1626
1611
|
const [notificationTag, messageTag] = tag.split(':');
|
|
1627
1612
|
if (!notificationTag || !messageTag) {
|
|
1628
1613
|
throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
|
|
1629
1614
|
}
|
|
1630
|
-
const notification = this.fetchNotification(notificationTag);
|
|
1615
|
+
const notification = await this.fetchNotification(notificationTag);
|
|
1631
1616
|
if (!notification)
|
|
1632
1617
|
throw new Error(`Notification ${notificationTag} not found`);
|
|
1633
1618
|
const message = notification.messages.find((data) => data.tag === messageTag);
|
|
@@ -1635,7 +1620,7 @@ class ProductsBuilderService {
|
|
|
1635
1620
|
throw new Error(`Notification message ${tag} not found`);
|
|
1636
1621
|
return message;
|
|
1637
1622
|
}
|
|
1638
|
-
fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
|
|
1623
|
+
async fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
|
|
1639
1624
|
const notification = this.product.notifications.find((data) => data.tag === notificationTag);
|
|
1640
1625
|
if (!notification)
|
|
1641
1626
|
throw new Error(`Notification ${notificationTag} not found`);
|
|
@@ -1689,7 +1674,6 @@ class ProductsBuilderService {
|
|
|
1689
1674
|
const payload = Object.assign(Object.assign(Object.assign({}, message), data), { notificationTag, component: enums_1.ProductComponents.NOTIFICATION_MESSAGE, action: enums_1.RequestAction.UPDATE });
|
|
1690
1675
|
// Update product and reinitialize
|
|
1691
1676
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
1692
|
-
await this.initializeProduct(this.product_id);
|
|
1693
1677
|
}
|
|
1694
1678
|
catch (error) {
|
|
1695
1679
|
throw error;
|
|
@@ -1697,21 +1681,25 @@ class ProductsBuilderService {
|
|
|
1697
1681
|
}
|
|
1698
1682
|
async updateNotification(tag, data) {
|
|
1699
1683
|
try {
|
|
1700
|
-
const
|
|
1701
|
-
if (
|
|
1684
|
+
const notificationResult = await this.fetchNotification(tag);
|
|
1685
|
+
if (!notificationResult) {
|
|
1686
|
+
throw new Error(`Notification with tag ${tag} not found`);
|
|
1687
|
+
}
|
|
1688
|
+
const { _id, envs } = notificationResult;
|
|
1689
|
+
if (data.tag && tag !== data.tag && (await this.fetchNotification(data.tag))) {
|
|
1702
1690
|
throw new Error(`Notification of tag ${data.tag} already exists`);
|
|
1703
1691
|
}
|
|
1704
1692
|
await validators_1.UpdateProductNotificationSchema.validateAsync(data); // Change to update;
|
|
1705
|
-
let notification = this.fetchNotification(tag);
|
|
1693
|
+
let notification = await this.fetchNotification(tag);
|
|
1706
1694
|
if (!notification) {
|
|
1707
1695
|
throw new Error(`Notification with tag ${tag} not found`);
|
|
1708
1696
|
}
|
|
1709
1697
|
if (data.envs) {
|
|
1710
1698
|
const overwrite = [];
|
|
1711
1699
|
const newEnvs = [];
|
|
1712
|
-
data.envs
|
|
1700
|
+
for (const dataEnv of data.envs) {
|
|
1713
1701
|
const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
1714
|
-
if (!this.fetchEnv(dataEnv.slug)) {
|
|
1702
|
+
if (!(await this.fetchEnv(dataEnv.slug))) {
|
|
1715
1703
|
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
1716
1704
|
}
|
|
1717
1705
|
if (exists === -1) {
|
|
@@ -1721,70 +1709,42 @@ class ProductsBuilderService {
|
|
|
1721
1709
|
else {
|
|
1722
1710
|
overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
|
|
1723
1711
|
}
|
|
1724
|
-
}
|
|
1712
|
+
}
|
|
1725
1713
|
const unchanged = [];
|
|
1726
|
-
|
|
1714
|
+
for (const env of envs) {
|
|
1727
1715
|
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1728
1716
|
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
1729
1717
|
if (!newEnv && !overwriteEnv) {
|
|
1730
1718
|
unchanged.push(env);
|
|
1731
1719
|
}
|
|
1732
|
-
}
|
|
1720
|
+
}
|
|
1733
1721
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
1734
1722
|
}
|
|
1735
1723
|
const update = Object.assign(Object.assign({}, notification), data);
|
|
1736
|
-
update.envs
|
|
1724
|
+
for (const env of update.envs) {
|
|
1737
1725
|
if (env.emails)
|
|
1738
|
-
env.emails = (0, processor_utils_1.encrypt)(JSON.stringify(env.emails), this.
|
|
1726
|
+
env.emails = (0, processor_utils_1.encrypt)(JSON.stringify(env.emails), this.product.private_key);
|
|
1739
1727
|
if (env.push_notifications)
|
|
1740
|
-
env.push_notifications = (0, processor_utils_1.encrypt)(JSON.stringify(env.push_notifications), this.
|
|
1728
|
+
env.push_notifications = (0, processor_utils_1.encrypt)(JSON.stringify(env.push_notifications), this.product.private_key);
|
|
1741
1729
|
if (env.callbacks)
|
|
1742
|
-
env.callbacks = (0, processor_utils_1.encrypt)(JSON.stringify(env.callbacks), this.
|
|
1730
|
+
env.callbacks = (0, processor_utils_1.encrypt)(JSON.stringify(env.callbacks), this.product.private_key);
|
|
1743
1731
|
if (env.sms)
|
|
1744
|
-
env.sms = (0, processor_utils_1.encrypt)(JSON.stringify(env.sms), this.
|
|
1745
|
-
|
|
1746
|
-
});
|
|
1732
|
+
env.sms = (0, processor_utils_1.encrypt)(JSON.stringify(env.sms), this.product.private_key);
|
|
1733
|
+
}
|
|
1747
1734
|
const payload = Object.assign(Object.assign({ _id }, update), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.UPDATE });
|
|
1748
1735
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
1749
|
-
await this.initializeProduct(this.product_id);
|
|
1750
1736
|
}
|
|
1751
1737
|
catch (e) {
|
|
1752
1738
|
throw e;
|
|
1753
1739
|
}
|
|
1754
1740
|
}
|
|
1755
|
-
|
|
1756
|
-
const
|
|
1757
|
-
|
|
1758
|
-
throw new Error(`Notification ${tag} is in use`);
|
|
1759
|
-
/*if (notification_slug) {
|
|
1760
|
-
const { notifications, emails, callbacks } = notification.envs.find(
|
|
1761
|
-
(data: INotificationEnv) => (data.slug = notification_slug),
|
|
1762
|
-
);
|
|
1763
|
-
return { notifications, emails, callbacks };
|
|
1764
|
-
}*/
|
|
1765
|
-
if (notification) {
|
|
1766
|
-
notification.envs.map((data) => {
|
|
1767
|
-
if (data.callbacks && typeof data.callbacks == 'string') {
|
|
1768
|
-
data.callbacks = JSON.parse((0, processor_utils_1.decrypt)(String(data.callbacks), this.fetchProduct().private_key));
|
|
1769
|
-
}
|
|
1770
|
-
if (data.push_notifications && typeof data.push_notifications == 'string') {
|
|
1771
|
-
data.push_notifications = JSON.parse((0, processor_utils_1.decrypt)(String(data.push_notifications), this.fetchProduct().private_key));
|
|
1772
|
-
}
|
|
1773
|
-
if (data.emails && typeof data.emails == 'string') {
|
|
1774
|
-
data.emails = JSON.parse((0, processor_utils_1.decrypt)(String(data.emails), this.fetchProduct().private_key));
|
|
1775
|
-
}
|
|
1776
|
-
if (data.sms && typeof data.sms == 'string') {
|
|
1777
|
-
data.sms = JSON.parse((0, processor_utils_1.decrypt)(String(data.sms), this.fetchProduct().private_key));
|
|
1778
|
-
}
|
|
1779
|
-
return data;
|
|
1780
|
-
});
|
|
1781
|
-
}
|
|
1782
|
-
return notification;
|
|
1741
|
+
async fetchNotifications(version) {
|
|
1742
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'notification', this.getUserAccess());
|
|
1743
|
+
return components;
|
|
1783
1744
|
}
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
});
|
|
1745
|
+
async fetchNotification(tag, version) {
|
|
1746
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'notification', tag, this.getUserAccess());
|
|
1747
|
+
return component;
|
|
1788
1748
|
}
|
|
1789
1749
|
validateFeatureSequence(array) {
|
|
1790
1750
|
// Validate uniqueness of sequence_tag
|
|
@@ -1884,24 +1844,27 @@ class ProductsBuilderService {
|
|
|
1884
1844
|
await this.validateActionDataInput(data, action, event.input, event_index, sequence_index);
|
|
1885
1845
|
}
|
|
1886
1846
|
async checkAndValidateFunctionDataInput(data, sequence_index, event, event_index) {
|
|
1887
|
-
const func = this.fetchFunction(event.event);
|
|
1847
|
+
const func = await this.fetchFunction(event.event);
|
|
1888
1848
|
await this.validateActionDataInput(data, func, event.input, event_index, sequence_index);
|
|
1889
1849
|
}
|
|
1890
1850
|
async checkAndValidateDBActionDataInput(data, sequence_index, event, event_index) {
|
|
1891
1851
|
console.log('EVENTY', event.event);
|
|
1892
|
-
const { filterData, data: dbData, filterTemplate, template } = this.fetchDatabaseAction(event.event);
|
|
1852
|
+
const { filterData, data: dbData, filterTemplate, template } = await this.fetchDatabaseAction(event.event);
|
|
1893
1853
|
await this.validateDBActionDataInput(data, { filterData, data: dbData, template, filter: filterTemplate }, event.input, event_index, sequence_index);
|
|
1894
1854
|
}
|
|
1895
1855
|
async checkAndValidateFeatureDataInput(data, sequence_index, event, event_index) {
|
|
1896
|
-
const
|
|
1856
|
+
const feature = await this.fetchFeature(event.event);
|
|
1857
|
+
if (!feature)
|
|
1858
|
+
throw new Error(`Feature ${event.event} not found`);
|
|
1859
|
+
const { input } = feature;
|
|
1897
1860
|
await this.validateFeatureDataInput(data, input, event.input, event_index, sequence_index);
|
|
1898
1861
|
}
|
|
1899
1862
|
async checkAndValidateNotificationDataInput(data, sequence_index, event, event_index) {
|
|
1900
|
-
const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = this.fetchNotificationMessage(event.event);
|
|
1863
|
+
const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = await this.fetchNotificationMessage(event.event);
|
|
1901
1864
|
await this.validateNotificationDataInput(data, { callback, notification, email, sms }, event.input, event_index, sequence_index);
|
|
1902
1865
|
}
|
|
1903
1866
|
async checkAndValidatePublishDataInput(data, sequence_index, event, event_index) {
|
|
1904
|
-
const topic = this.fetchMessageBrokerTopic(event.event);
|
|
1867
|
+
const topic = await this.fetchMessageBrokerTopic(event.event);
|
|
1905
1868
|
if (!topic) {
|
|
1906
1869
|
throw new Error(`Topic ${event.event} not registered`);
|
|
1907
1870
|
}
|
|
@@ -1909,14 +1872,14 @@ class ProductsBuilderService {
|
|
|
1909
1872
|
//await this.validatePublishTopicDataInput(data, { data: topicData }, event.input, event_index, sequence_index)
|
|
1910
1873
|
}
|
|
1911
1874
|
async checkAndValidateStorageDataInput(data, sequence_index, event, event_index) {
|
|
1912
|
-
const storage = this.fetchStorage(event.event);
|
|
1875
|
+
const storage = await this.fetchStorage(event.event);
|
|
1913
1876
|
if (!storage) {
|
|
1914
1877
|
throw new Error(`Storage ${event.event} does not exist`);
|
|
1915
1878
|
}
|
|
1916
1879
|
//await this.validateStorageDataInput(data, {}, event.input, event_index, sequence_index);
|
|
1917
1880
|
}
|
|
1918
1881
|
async checkAndValidateJobDataInput(data, sequence_index, event, event_index) {
|
|
1919
|
-
const job = this.fetchJob(event.event);
|
|
1882
|
+
const job = await this.fetchJob(event.event);
|
|
1920
1883
|
if (job.type === productsBuilder_types_1.JobEventTypes.ACTION) {
|
|
1921
1884
|
await this.checkAndValidateActionDataInput(data, sequence_index, event, event_index);
|
|
1922
1885
|
}
|
|
@@ -1956,7 +1919,7 @@ class ProductsBuilderService {
|
|
|
1956
1919
|
await this.checkAndValidatePublishDataInput(data, sequence_index, event, event_index);
|
|
1957
1920
|
}
|
|
1958
1921
|
/*if (event.type === FeatureEventTypes.SUBSCRIBE) {
|
|
1959
|
-
const topic = this.fetchMessageBrokerTopic(event.event);
|
|
1922
|
+
const topic = await this.fetchMessageBrokerTopic(event.event);
|
|
1960
1923
|
|
|
1961
1924
|
if(!topic) {
|
|
1962
1925
|
throw new Error(`Topic ${event.event} not registered`);
|
|
@@ -2421,13 +2384,13 @@ class ProductsBuilderService {
|
|
|
2421
2384
|
}
|
|
2422
2385
|
else {
|
|
2423
2386
|
//const envs =
|
|
2424
|
-
const app = this.fetchApp(access_tag);
|
|
2387
|
+
const app = await this.fetchApp(access_tag);
|
|
2425
2388
|
const { envs } = app;
|
|
2426
2389
|
await Promise.all(envs.map((env) => {
|
|
2427
2390
|
if (stages[0] !== env.auth.auth_tag) {
|
|
2428
2391
|
throw new Error(`Auth ${stages[0]} does not exist on env ${env.product_env_slug} on app ${access_tag}`);
|
|
2429
2392
|
}
|
|
2430
|
-
const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.
|
|
2393
|
+
const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.product.private_key));
|
|
2431
2394
|
// Convert stages to string[] for findFaultyKeys
|
|
2432
2395
|
const stringStages = stages.slice(1).map(stage => String(stage));
|
|
2433
2396
|
const check = (0, objects_utils_1.findFaultyKeys)(stringStages, decrypted);
|
|
@@ -2619,7 +2582,7 @@ class ProductsBuilderService {
|
|
|
2619
2582
|
if (stages.length > 2) {
|
|
2620
2583
|
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`);
|
|
2621
2584
|
}
|
|
2622
|
-
const app = this.fetchApp(String(stages[0]));
|
|
2585
|
+
const app = await this.fetchApp(String(stages[0]));
|
|
2623
2586
|
if (!app) {
|
|
2624
2587
|
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}. `);
|
|
2625
2588
|
}
|
|
@@ -2774,12 +2737,11 @@ class ProductsBuilderService {
|
|
|
2774
2737
|
}
|
|
2775
2738
|
async createFeature(data, throwErrorIfExists = false) {
|
|
2776
2739
|
try {
|
|
2777
|
-
if (!this.fetchFeature(data.tag
|
|
2740
|
+
if (!(await this.fetchFeature(data.tag))) {
|
|
2778
2741
|
await validators_1.CreateProductFeatureSchema.validateAsync(data);
|
|
2779
2742
|
try {
|
|
2780
2743
|
await this.validateFeatureData(data);
|
|
2781
2744
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2782
|
-
await this.initializeProduct(this.product_id);
|
|
2783
2745
|
}
|
|
2784
2746
|
catch (e) {
|
|
2785
2747
|
throw e;
|
|
@@ -2796,7 +2758,7 @@ class ProductsBuilderService {
|
|
|
2796
2758
|
}
|
|
2797
2759
|
async updateFeature(tag, data) {
|
|
2798
2760
|
try {
|
|
2799
|
-
const feature = this.fetchFeature(tag);
|
|
2761
|
+
const feature = await this.fetchFeature(tag);
|
|
2800
2762
|
if (!feature) {
|
|
2801
2763
|
throw new Error(`Feature ${tag} not found`);
|
|
2802
2764
|
}
|
|
@@ -2808,43 +2770,42 @@ class ProductsBuilderService {
|
|
|
2808
2770
|
}
|
|
2809
2771
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id,
|
|
2810
2772
|
tag }, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
2811
|
-
await this.initializeProduct(this.product_id);
|
|
2812
2773
|
}
|
|
2813
2774
|
catch (e) {
|
|
2814
2775
|
throw e;
|
|
2815
2776
|
}
|
|
2816
2777
|
}
|
|
2817
|
-
|
|
2818
|
-
const
|
|
2819
|
-
|
|
2820
|
-
throw new Error(`Feature ${tag} not found`);
|
|
2821
|
-
return feature;
|
|
2778
|
+
async fetchFeatures() {
|
|
2779
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'feature', this.getUserAccess());
|
|
2780
|
+
return components;
|
|
2822
2781
|
}
|
|
2823
|
-
|
|
2824
|
-
|
|
2782
|
+
async fetchFeature(tag) {
|
|
2783
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'feature', tag, this.getUserAccess());
|
|
2784
|
+
return component;
|
|
2825
2785
|
}
|
|
2826
2786
|
async createDatabase(data, throwErrorIfExists = false) {
|
|
2827
2787
|
try {
|
|
2828
2788
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
2829
|
-
if (!this.fetchDatabase(data.tag
|
|
2789
|
+
if (!(await this.fetchDatabase(data.tag))) {
|
|
2830
2790
|
await validators_1.CreateProductDatabaseSchema.validateAsync(data);
|
|
2831
|
-
|
|
2832
|
-
|
|
2791
|
+
const processedEnvs = [];
|
|
2792
|
+
for (const env of data.envs) {
|
|
2793
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2833
2794
|
if (!exists) {
|
|
2834
2795
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
2835
2796
|
}
|
|
2836
|
-
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.
|
|
2837
|
-
|
|
2838
|
-
}
|
|
2839
|
-
|
|
2840
|
-
envs.
|
|
2797
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
2798
|
+
processedEnvs.push(env);
|
|
2799
|
+
}
|
|
2800
|
+
data.envs = processedEnvs;
|
|
2801
|
+
const envs = await this.fetchEnvs();
|
|
2802
|
+
for (const env of envs) {
|
|
2841
2803
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
2842
2804
|
if (exists === -1) {
|
|
2843
2805
|
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
2844
2806
|
}
|
|
2845
|
-
}
|
|
2807
|
+
}
|
|
2846
2808
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.DATABASE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2847
|
-
await this.initializeProduct(this.product_id);
|
|
2848
2809
|
}
|
|
2849
2810
|
else {
|
|
2850
2811
|
if (throwErrorIfExists)
|
|
@@ -2857,7 +2818,7 @@ class ProductsBuilderService {
|
|
|
2857
2818
|
}
|
|
2858
2819
|
async updateDatabase(tag, data) {
|
|
2859
2820
|
try {
|
|
2860
|
-
const db = this.fetchDatabase(tag);
|
|
2821
|
+
const db = await this.fetchDatabase(tag);
|
|
2861
2822
|
if (!db) {
|
|
2862
2823
|
throw new Error(`Database ${tag} not found`);
|
|
2863
2824
|
}
|
|
@@ -2866,15 +2827,16 @@ class ProductsBuilderService {
|
|
|
2866
2827
|
if (data.tag && this.fetchDatabase(data.tag)) {
|
|
2867
2828
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
2868
2829
|
}
|
|
2869
|
-
data.envs = data.envs.map((env) => {
|
|
2870
|
-
const exists = this.fetchEnv(env.slug);
|
|
2830
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
2831
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2871
2832
|
if (!exists) {
|
|
2872
2833
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
2873
2834
|
}
|
|
2874
|
-
if (env.connection_url)
|
|
2875
|
-
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.
|
|
2835
|
+
if (env.connection_url) {
|
|
2836
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
2837
|
+
}
|
|
2876
2838
|
return env;
|
|
2877
|
-
});
|
|
2839
|
+
}));
|
|
2878
2840
|
const overwrite = [];
|
|
2879
2841
|
const newEnvs = [];
|
|
2880
2842
|
data.envs.map((dataEnv) => {
|
|
@@ -2903,25 +2865,18 @@ class ProductsBuilderService {
|
|
|
2903
2865
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
2904
2866
|
//console.log("UPDATED!!!", JSON.stringify(data.envs))
|
|
2905
2867
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { tag, component: enums_1.ProductComponents.DATABASE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
2906
|
-
await this.initializeProduct(this.product_id);
|
|
2907
2868
|
}
|
|
2908
2869
|
catch (e) {
|
|
2909
2870
|
throw e;
|
|
2910
2871
|
}
|
|
2911
2872
|
}
|
|
2912
|
-
|
|
2913
|
-
const
|
|
2914
|
-
|
|
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
|
-
}
|
|
2921
|
-
return database;
|
|
2873
|
+
async fetchDatabases() {
|
|
2874
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'database', this.getUserAccess());
|
|
2875
|
+
return components;
|
|
2922
2876
|
}
|
|
2923
|
-
|
|
2924
|
-
|
|
2877
|
+
async fetchDatabase(tag) {
|
|
2878
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'database', tag, this.getUserAccess());
|
|
2879
|
+
return component;
|
|
2925
2880
|
}
|
|
2926
2881
|
async createDatabaseAction(data, throwErrorIfExists = false) {
|
|
2927
2882
|
try {
|
|
@@ -2932,10 +2887,10 @@ class ProductsBuilderService {
|
|
|
2932
2887
|
if (!databaseTag || !tag) {
|
|
2933
2888
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
2934
2889
|
}
|
|
2935
|
-
const exists = this.fetchDatabaseAction(data.tag);
|
|
2890
|
+
const exists = await this.fetchDatabaseAction(data.tag);
|
|
2936
2891
|
data.tag = tag;
|
|
2937
2892
|
if (!exists) {
|
|
2938
|
-
const database = this.fetchDatabase(databaseTag);
|
|
2893
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
2939
2894
|
let values, template;
|
|
2940
2895
|
if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
|
|
2941
2896
|
await create_productDatabaseAction_validator_1.NOSQLDatabaseActionsSchema.validateAsync(data);
|
|
@@ -2959,7 +2914,6 @@ class ProductsBuilderService {
|
|
|
2959
2914
|
}
|
|
2960
2915
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { data: values, template,
|
|
2961
2916
|
databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2962
|
-
await this.initializeProduct(this.product_id);
|
|
2963
2917
|
}
|
|
2964
2918
|
else {
|
|
2965
2919
|
if (throwErrorIfExists)
|
|
@@ -2970,7 +2924,7 @@ class ProductsBuilderService {
|
|
|
2970
2924
|
throw e;
|
|
2971
2925
|
}
|
|
2972
2926
|
}
|
|
2973
|
-
fetchDatabaseAction(tag, throwErrorIfExists = false) {
|
|
2927
|
+
async fetchDatabaseAction(tag, throwErrorIfExists = false) {
|
|
2974
2928
|
const [databaseTag, actionTag] = tag.split(':');
|
|
2975
2929
|
if (!databaseTag || !actionTag) {
|
|
2976
2930
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
@@ -2997,7 +2951,7 @@ class ProductsBuilderService {
|
|
|
2997
2951
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
2998
2952
|
}
|
|
2999
2953
|
// Fetch required data
|
|
3000
|
-
const database = await this.fetchDatabase(databaseTag
|
|
2954
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
3001
2955
|
const action = await this.fetchDatabaseAction(data.tag, true);
|
|
3002
2956
|
// Construct payload
|
|
3003
2957
|
const payload = Object.assign(Object.assign(Object.assign({}, action), data), { databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.UPDATE });
|
|
@@ -3025,13 +2979,12 @@ class ProductsBuilderService {
|
|
|
3025
2979
|
}
|
|
3026
2980
|
// Update product and reinitialize
|
|
3027
2981
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
3028
|
-
await this.initializeProduct(this.product_id);
|
|
3029
2982
|
}
|
|
3030
2983
|
catch (error) {
|
|
3031
2984
|
throw error;
|
|
3032
2985
|
}
|
|
3033
2986
|
}
|
|
3034
|
-
fetchDatabaseActions(databaseTag) {
|
|
2987
|
+
async fetchDatabaseActions(databaseTag) {
|
|
3035
2988
|
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
3036
2989
|
if (!database)
|
|
3037
2990
|
throw new Error(`Database ${databaseTag} not found`);
|
|
@@ -3055,12 +3008,11 @@ class ProductsBuilderService {
|
|
|
3055
3008
|
data.tag = tag;
|
|
3056
3009
|
await create_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag })); // Change to update;
|
|
3057
3010
|
if (!exists) {
|
|
3058
|
-
const database = this.fetchDatabase(databaseTag
|
|
3011
|
+
const database = await this.fetchDatabase(databaseTag);
|
|
3059
3012
|
if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
|
|
3060
3013
|
throw new Error(`${database.type} does not support migrations`);
|
|
3061
3014
|
}
|
|
3062
3015
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { databaseTag, component: enums_1.ProductComponents.DATABASE_MIGRATION }), this.getUserAccess());
|
|
3063
|
-
await this.initializeProduct(this.product_id);
|
|
3064
3016
|
}
|
|
3065
3017
|
else {
|
|
3066
3018
|
if (throwErrorIfExists)
|
|
@@ -3082,9 +3034,8 @@ class ProductsBuilderService {
|
|
|
3082
3034
|
}
|
|
3083
3035
|
data.tag = tag;
|
|
3084
3036
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, action), Object.assign(Object.assign({}, data), { databaseTag })), { component: enums_1.ProductComponents.DATABASE_MIGRATION }), this.getUserAccess());
|
|
3085
|
-
await this.initializeProduct(this.product_id);
|
|
3086
3037
|
}
|
|
3087
|
-
fetchDatabaseMigration(tag, throwError = false) {
|
|
3038
|
+
async fetchDatabaseMigration(tag, throwError = false) {
|
|
3088
3039
|
const [databaseTag, migrationTag] = tag.split(':');
|
|
3089
3040
|
if (!databaseTag || !migrationTag) {
|
|
3090
3041
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
@@ -3097,7 +3048,7 @@ class ProductsBuilderService {
|
|
|
3097
3048
|
throw new Error(`Database migration ${tag} not found`);
|
|
3098
3049
|
return migration;
|
|
3099
3050
|
}
|
|
3100
|
-
fetchDatabaseMigrations(databaseTag) {
|
|
3051
|
+
async fetchDatabaseMigrations(databaseTag) {
|
|
3101
3052
|
const database = this.product.databases.find((data) => data.tag === databaseTag);
|
|
3102
3053
|
if (!database)
|
|
3103
3054
|
throw new Error(`Database ${databaseTag} not found`);
|
|
@@ -3118,31 +3069,31 @@ class ProductsBuilderService {
|
|
|
3118
3069
|
}
|
|
3119
3070
|
}
|
|
3120
3071
|
if (type === productsBuilder_types_1.JobEventTypes.DATABASE_ACTION) {
|
|
3121
|
-
const found = this.fetchDatabaseAction(event);
|
|
3072
|
+
const found = await this.fetchDatabaseAction(event);
|
|
3122
3073
|
if (!found) {
|
|
3123
3074
|
throw new Error(`Database action ${event} not found`);
|
|
3124
3075
|
}
|
|
3125
3076
|
}
|
|
3126
3077
|
if (type === productsBuilder_types_1.JobEventTypes.FUNCTION) {
|
|
3127
|
-
const found = this.fetchFunction(event);
|
|
3078
|
+
const found = await this.fetchFunction(event);
|
|
3128
3079
|
if (!found) {
|
|
3129
3080
|
throw new Error(`Cloud function ${event} not found`);
|
|
3130
3081
|
}
|
|
3131
3082
|
}
|
|
3132
3083
|
if (type === productsBuilder_types_1.JobEventTypes.STORAGE) {
|
|
3133
|
-
const found = this.fetchStorage(event);
|
|
3084
|
+
const found = await this.fetchStorage(event);
|
|
3134
3085
|
if (!found) {
|
|
3135
3086
|
throw new Error(`Storage ${event} not found`);
|
|
3136
3087
|
}
|
|
3137
3088
|
}
|
|
3138
3089
|
if (type === productsBuilder_types_1.JobEventTypes.NOTIFICATION) {
|
|
3139
|
-
const found = this.fetchNotification(event);
|
|
3090
|
+
const found = await this.fetchNotification(event);
|
|
3140
3091
|
if (!found) {
|
|
3141
3092
|
throw new Error(`Notification ${event} not found`);
|
|
3142
3093
|
}
|
|
3143
3094
|
}
|
|
3144
3095
|
if (type === productsBuilder_types_1.JobEventTypes.PUBLISH) {
|
|
3145
|
-
const found = this.fetchMessageBroker(event);
|
|
3096
|
+
const found = await this.fetchMessageBroker(event);
|
|
3146
3097
|
if (!found) {
|
|
3147
3098
|
throw new Error(`Message Broker ${event} not found`);
|
|
3148
3099
|
}
|
|
@@ -3151,7 +3102,7 @@ class ProductsBuilderService {
|
|
|
3151
3102
|
async createJob(data, throwErrorIfExists = false) {
|
|
3152
3103
|
try {
|
|
3153
3104
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
3154
|
-
if (!this.fetchJob(data.tag)) {
|
|
3105
|
+
if (!(await this.fetchJob(data.tag))) {
|
|
3155
3106
|
await validators_1.CreateProductJobSchema.validateAsync(data);
|
|
3156
3107
|
await this.validateJobEvent(data);
|
|
3157
3108
|
if (data.type === productsBuilder_types_1.JobEventTypes.ACTION) {
|
|
@@ -3173,7 +3124,6 @@ class ProductsBuilderService {
|
|
|
3173
3124
|
const dbAction = await this.fetchDatabaseAction(data.event);
|
|
3174
3125
|
}
|
|
3175
3126
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.JOB, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
3176
|
-
await this.initializeProduct(this.product_id);
|
|
3177
3127
|
}
|
|
3178
3128
|
else {
|
|
3179
3129
|
if (throwErrorIfExists)
|
|
@@ -3196,20 +3146,18 @@ class ProductsBuilderService {
|
|
|
3196
3146
|
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
3197
3147
|
}
|
|
3198
3148
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, job), data), { component: enums_1.ProductComponents.JOB, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
3199
|
-
await this.initializeProduct(this.product_id);
|
|
3200
3149
|
}
|
|
3201
3150
|
catch (e) {
|
|
3202
3151
|
throw e;
|
|
3203
3152
|
}
|
|
3204
3153
|
}
|
|
3205
|
-
|
|
3206
|
-
const
|
|
3207
|
-
|
|
3208
|
-
throw new Error(`Job ${tag} not found`);
|
|
3209
|
-
return job;
|
|
3154
|
+
async fetchJobs() {
|
|
3155
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'job', this.getUserAccess());
|
|
3156
|
+
return components;
|
|
3210
3157
|
}
|
|
3211
|
-
|
|
3212
|
-
|
|
3158
|
+
async fetchJob(tag) {
|
|
3159
|
+
const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'job', tag, this.getUserAccess());
|
|
3160
|
+
return component;
|
|
3213
3161
|
}
|
|
3214
3162
|
getUserAccess() {
|
|
3215
3163
|
return {
|