@ductape/sdk 0.0.3-beta9 → 0.0.4-v3
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 +3 -1
- package/dist/api/services/appApi.service.js +41 -2
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/processorApi.service.d.ts +5 -1
- package/dist/api/services/processorApi.service.js +18 -0
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +5 -2
- package/dist/api/services/productsApi.service.js +12 -1
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/userApi.service.d.ts +2 -1
- package/dist/api/services/userApi.service.js +1 -1
- package/dist/api/services/userApi.service.js.map +1 -1
- package/dist/api/services/webhooksApi.service.d.ts +4 -1
- package/dist/api/services/webhooksApi.service.js +6 -3
- package/dist/api/services/webhooksApi.service.js.map +1 -1
- package/dist/api/services/workspaceApi.service.d.ts +2 -1
- package/dist/api/services/workspaceApi.service.js +1 -1
- package/dist/api/services/workspaceApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +3 -0
- package/dist/api/urls.js +4 -1
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/cache.utils.d.ts +3 -0
- package/dist/api/utils/cache.utils.js +18 -0
- package/dist/api/utils/cache.utils.js.map +1 -0
- package/dist/apps/services/app.service.d.ts +3 -3
- package/dist/apps/services/app.service.js +153 -75
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/utils/objects.utils.d.ts +1 -1
- package/dist/apps/utils/objects.utils.js +5 -3
- package/dist/apps/utils/objects.utils.js.map +1 -1
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +1 -1
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/create.appWebhookEvent.validator.js +1 -0
- package/dist/apps/validators/joi-validators/create.appWebhookEvent.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.d.ts +2 -2
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -11
- package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appWebhookEvent.validator.js +2 -0
- package/dist/apps/validators/joi-validators/update.appWebhookEvent.validator.js.map +1 -1
- package/dist/clients/webhooks.client.d.ts +2 -1
- package/dist/clients/webhooks.client.js +2 -2
- package/dist/clients/webhooks.client.js.map +1 -1
- package/dist/imports/imports.service.d.ts +2 -3
- package/dist/imports/imports.service.js +4 -45
- package/dist/imports/imports.service.js.map +1 -1
- package/dist/imports/imports.types.d.ts +238 -0
- package/dist/imports/repos/openApi.repo.d.ts +5 -11
- package/dist/imports/repos/openApi.repo.js +77 -27
- package/dist/imports/repos/openApi.repo.js.map +1 -1
- package/dist/imports/repos/postmanV21.repo.js +1 -1
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +25 -6
- package/dist/index.js +63 -4
- package/dist/index.js.map +1 -1
- package/dist/inputs/validators/inputs.validator.parse.js +1 -0
- package/dist/inputs/validators/inputs.validator.parse.js.map +1 -1
- package/dist/logs/logs.service.d.ts +1 -1
- package/dist/logs/logs.types.d.ts +3 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/processor/services/fallback.service.d.ts +0 -1
- package/dist/processor/services/fallback.service.js +0 -16
- package/dist/processor/services/fallback.service.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +53 -14
- package/dist/processor/services/processor.service.js +429 -152
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/quota.service.d.ts +6 -13
- package/dist/processor/services/quota.service.js +12 -3
- package/dist/processor/services/quota.service.js.map +1 -1
- package/dist/processor/utils/processor.utils.d.ts +3 -230
- package/dist/processor/utils/processor.utils.js +133 -118
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/products/services/products.service.d.ts +25 -7
- package/dist/products/services/products.service.js +365 -147
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/utils/functions.utils.d.ts +1 -0
- package/dist/products/utils/functions.utils.js +11 -0
- package/dist/products/utils/functions.utils.js.map +1 -1
- package/dist/products/validators/index.d.ts +3 -1
- package/dist/products/validators/index.js +5 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productFallback.validator.js +7 -1
- package/dist/products/validators/joi-validators/create.productFallback.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productFeature.validator.js +2 -0
- package/dist/products/validators/joi-validators/create.productFeature.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productQuota.validator.js +10 -2
- package/dist/products/validators/joi-validators/create.productQuota.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.userAuth.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js +47 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.d.ts +1 -1
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +3 -2
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productFallback.validator.js +7 -2
- package/dist/products/validators/joi-validators/update.productFallback.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productFeature.validator.js +2 -0
- package/dist/products/validators/joi-validators/update.productFeature.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productQuota.validator.js +12 -7
- package/dist/products/validators/joi-validators/update.productQuota.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.userAuth.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js +47 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -0
- package/dist/test/test.import.openapi.d.ts +1 -0
- package/dist/test/test.import.openapi.js +76 -0
- package/dist/test/test.import.openapi.js.map +1 -0
- package/dist/test/test.logs.js +1 -2
- package/dist/test/test.logs.js.map +1 -1
- package/dist/types/appBuilder.types.d.ts +19 -1
- package/dist/types/enums.d.ts +6 -0
- package/dist/types/enums.js +8 -1
- package/dist/types/enums.js.map +1 -1
- package/dist/types/processor.types.d.ts +28 -0
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +29 -7
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/package.json +6 -2
|
@@ -52,10 +52,11 @@ const types_1 = require("../../types");
|
|
|
52
52
|
const logs_service_1 = __importDefault(require("../../logs/logs.service"));
|
|
53
53
|
const inputs_service_1 = __importDefault(require("../../inputs/inputs.service"));
|
|
54
54
|
const processor_utils_1 = require("../utils/processor.utils");
|
|
55
|
-
const
|
|
55
|
+
const axios_1 = __importDefault(require("axios"));
|
|
56
56
|
const processorApi_service_1 = require("../../api/services/processorApi.service");
|
|
57
57
|
const expo_client_1 = __importDefault(require("../../clients/expo.client"));
|
|
58
58
|
const handlebars_1 = require("handlebars");
|
|
59
|
+
const functions_utils_1 = require("../../products/utils/functions.utils");
|
|
59
60
|
const string_utils_1 = require("../../products/utils/string.utils");
|
|
60
61
|
const create_productFeature_validator_1 = require("../../products/validators/joi-validators/create.productFeature.validator");
|
|
61
62
|
const validators_1 = require("../../products/validators");
|
|
@@ -67,6 +68,7 @@ const mongo_repo_1 = require("../repos/mongo.repo");
|
|
|
67
68
|
const postgres_repo_1 = require("../repos/postgres.repo");
|
|
68
69
|
const storage_util_1 = require("../utils/storage.util");
|
|
69
70
|
const sms_repo_1 = require("../repos/sms.repo");
|
|
71
|
+
const quota_service_1 = __importDefault(require("./quota.service"));
|
|
70
72
|
async function loadBrokerService() {
|
|
71
73
|
if (typeof window === 'undefined') {
|
|
72
74
|
const { createBrokerService } = await Promise.resolve().then(() => __importStar(require('./messagebrokers')));
|
|
@@ -74,20 +76,31 @@ async function loadBrokerService() {
|
|
|
74
76
|
}
|
|
75
77
|
return null;
|
|
76
78
|
}
|
|
79
|
+
async function loadJWT() {
|
|
80
|
+
if (typeof window === undefined) {
|
|
81
|
+
const JWT = await Promise.resolve().then(() => __importStar(require("jsonwebtoken")));
|
|
82
|
+
return JWT;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
77
86
|
class ProcessorService {
|
|
78
87
|
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
|
|
79
88
|
this.workspace_id = workspace_id;
|
|
80
89
|
this.public_key = public_key;
|
|
81
90
|
this.user_id = user_id;
|
|
82
91
|
this.token = token;
|
|
92
|
+
this.published = false;
|
|
83
93
|
this.productBuilderService = new products_service_1.default({
|
|
84
94
|
workspace_id,
|
|
85
95
|
public_key,
|
|
86
96
|
user_id,
|
|
87
97
|
token,
|
|
88
98
|
env_type,
|
|
99
|
+
redis_client
|
|
89
100
|
});
|
|
90
101
|
this.inputService = new inputs_service_1.default();
|
|
102
|
+
this.requestTime = 0;
|
|
103
|
+
this.totalRequests = 0;
|
|
91
104
|
this.processingOutput = {
|
|
92
105
|
success: [],
|
|
93
106
|
failure: [],
|
|
@@ -101,6 +114,44 @@ class ProcessorService {
|
|
|
101
114
|
this.redisClient = redis_client;
|
|
102
115
|
}
|
|
103
116
|
}
|
|
117
|
+
async generateSession(payload) {
|
|
118
|
+
try {
|
|
119
|
+
const { product: product_tag, env: slug, tag, data } = payload;
|
|
120
|
+
const input = await this.inputService.parseJson({
|
|
121
|
+
data,
|
|
122
|
+
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
123
|
+
});
|
|
124
|
+
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
125
|
+
// const product = this.productBuilderService.fetchProduct();
|
|
126
|
+
const session = this.productBuilderService.fetchSession(tag);
|
|
127
|
+
if (!session) {
|
|
128
|
+
throw new Error(`Session with tag ${tag} does not exist`);
|
|
129
|
+
}
|
|
130
|
+
const env = this.productBuilderService.fetchEnv(slug);
|
|
131
|
+
if (!env) {
|
|
132
|
+
throw new Error(`Env with slug ${slug} does not exist`);
|
|
133
|
+
}
|
|
134
|
+
await this.inputService.validateInput(input, session.schema_data);
|
|
135
|
+
const expiry = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
|
|
136
|
+
const JWT = await loadJWT();
|
|
137
|
+
if (JWT) {
|
|
138
|
+
const token = JWT.sign(JSON.stringify(Object.assign({ type: "token" }, data)), this.productBuilderService.fetchProduct().private_key, { expiresIn: expiry });
|
|
139
|
+
const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.productBuilderService.fetchProduct().private_key);
|
|
140
|
+
// WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
|
|
141
|
+
await this.processorApiService.createRefreshToken({ product_tag, env: slug, refreshToken }, this.getUserAccess());
|
|
142
|
+
return {
|
|
143
|
+
token,
|
|
144
|
+
refreshToken,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw new Error(`Running in browser, token service not loaded.`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
throw e;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
104
155
|
async registerWebhook(data) {
|
|
105
156
|
const { product: product_tag, access_tag, webhook_tag, envs } = data;
|
|
106
157
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
@@ -225,7 +276,6 @@ class ProcessorService {
|
|
|
225
276
|
}
|
|
226
277
|
async processQuota(data) {
|
|
227
278
|
this.start = Date.now();
|
|
228
|
-
this.input = data;
|
|
229
279
|
const { product: product_tag, env, input, tag: quota_tag } = data;
|
|
230
280
|
try {
|
|
231
281
|
this.productTag = product_tag;
|
|
@@ -247,6 +297,9 @@ class ProcessorService {
|
|
|
247
297
|
data: input,
|
|
248
298
|
};
|
|
249
299
|
this.quota = this.fetchQuota(quota_tag, additional_logs);
|
|
300
|
+
if (!this.quota) {
|
|
301
|
+
throw new Error(`Quota ${quota_tag} not found`);
|
|
302
|
+
}
|
|
250
303
|
this.logService.setFeatureId(this.quota._id);
|
|
251
304
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
252
305
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
@@ -258,19 +311,90 @@ class ProcessorService {
|
|
|
258
311
|
this.validateJSONFeatureInput(input, quotaInput, additional_logs);
|
|
259
312
|
// split processes
|
|
260
313
|
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
261
|
-
return await this.runQuotaOptions(options, additional_logs);
|
|
314
|
+
return await this.runQuotaOptions(options, input, additional_logs);
|
|
262
315
|
}
|
|
263
316
|
catch (e) {
|
|
264
317
|
this.end = Date.now();
|
|
265
|
-
this.logService.publish();
|
|
318
|
+
await this.logService.publish();
|
|
266
319
|
throw e;
|
|
267
320
|
}
|
|
268
321
|
}
|
|
269
|
-
async runQuotaOptions(options, additional_logs) {
|
|
270
|
-
|
|
322
|
+
async runQuotaOptions(options, input, additional_logs) {
|
|
323
|
+
const quotaManager = new quota_service_1.default(options, this.redisClient);
|
|
324
|
+
const getNextProvider = quotaManager.getNextProvider();
|
|
325
|
+
const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
|
|
326
|
+
return await this.processEvent({
|
|
327
|
+
app: getNextProvider.app,
|
|
328
|
+
type: getNextProvider.type,
|
|
329
|
+
event: getNextProvider.event,
|
|
330
|
+
input: quotaInput,
|
|
331
|
+
retries: getNextProvider.retries,
|
|
332
|
+
allow_fail: false
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
async mapQuotaFallbackInput(providerInput, quotaInput, app) {
|
|
336
|
+
if (Array.isArray(providerInput)) {
|
|
337
|
+
return providerInput.map(async (item) => await this.mapQuotaFallbackInput(item, quotaInput, app));
|
|
338
|
+
}
|
|
339
|
+
else if (providerInput && typeof providerInput === 'object') {
|
|
340
|
+
const result = {};
|
|
341
|
+
for (const key in providerInput) {
|
|
342
|
+
result[key] = await this.mapQuotaFallbackInput(providerInput[key], quotaInput, app);
|
|
343
|
+
}
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
// Base case: primitive value
|
|
348
|
+
return await this.overrideQuotaFallbackInput(providerInput, quotaInput, app);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async overrideQuotaFallbackInput(value, quotaInput, app) {
|
|
352
|
+
if (value.startsWith('$Input{')) {
|
|
353
|
+
return quotaInput[(0, string_utils_1.extractStages)(value)[0]];
|
|
354
|
+
}
|
|
355
|
+
else if (value.startsWith('$Auth')) {
|
|
356
|
+
return await this.generateAuthValue((0, string_utils_1.extractStages)(value), app, [], {});
|
|
357
|
+
}
|
|
358
|
+
else if (value.startsWith('$')) {
|
|
359
|
+
this.input = Object.assign(Object.assign({}, this.input), { input: quotaInput });
|
|
360
|
+
return await this.generateOperatorValues(value, '', {});
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
return value;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async runFallbackOptions(options, input, additional_logs) {
|
|
367
|
+
return await this.executeActionWithFallback(options, input);
|
|
368
|
+
}
|
|
369
|
+
async executeActionWithFallback(providers, input) {
|
|
370
|
+
let index = 0;
|
|
371
|
+
for (const provider of providers) {
|
|
372
|
+
try {
|
|
373
|
+
const payload = {
|
|
374
|
+
app: provider.app,
|
|
375
|
+
type: provider.type,
|
|
376
|
+
event: provider.event,
|
|
377
|
+
input: await this.mapQuotaFallbackInput(provider.input, input, provider.app),
|
|
378
|
+
retries: provider.retries,
|
|
379
|
+
allow_fail: false
|
|
380
|
+
};
|
|
381
|
+
const result = await this.processEvent(payload);
|
|
382
|
+
if (result.status === types_1.LogEventStatus.FAIL) {
|
|
383
|
+
throw new Error(result.errors);
|
|
384
|
+
}
|
|
385
|
+
index++;
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
if (index > 0) {
|
|
389
|
+
throw error;
|
|
390
|
+
}
|
|
391
|
+
console.warn(`${provider.app || provider.event} failed: ${error}`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
//throw new Error("All providers failed.");
|
|
395
|
+
}
|
|
271
396
|
async processFallback(data) {
|
|
272
397
|
this.start = Date.now();
|
|
273
|
-
this.input = data;
|
|
274
398
|
const { product: product_tag, env, input, tag: fallback_tag } = data;
|
|
275
399
|
try {
|
|
276
400
|
this.productTag = product_tag;
|
|
@@ -287,12 +411,15 @@ class ProcessorService {
|
|
|
287
411
|
product_id: this.productId,
|
|
288
412
|
workspace_id: this.workspace_id,
|
|
289
413
|
env,
|
|
290
|
-
type: types_1.LogEventTypes.
|
|
414
|
+
type: types_1.LogEventTypes.FALLBACK,
|
|
291
415
|
process_id,
|
|
292
416
|
data: input,
|
|
293
417
|
};
|
|
294
418
|
this.fallback = this.fetchFallback(fallback_tag, additional_logs);
|
|
295
|
-
|
|
419
|
+
if (!this.fallback) {
|
|
420
|
+
throw new Error(`Fallback "${fallback_tag}" not found`);
|
|
421
|
+
}
|
|
422
|
+
this.logService.setFeatureId(this.fallback._id);
|
|
296
423
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process fallback initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
297
424
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
298
425
|
if (!this.processEnv.active) {
|
|
@@ -303,15 +430,15 @@ class ProcessorService {
|
|
|
303
430
|
this.validateJSONFeatureInput(input, fallbackInput, additional_logs);
|
|
304
431
|
// split processes
|
|
305
432
|
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
306
|
-
return await this.runFallbackOptions(options, additional_logs);
|
|
433
|
+
return await this.runFallbackOptions(options, input, additional_logs);
|
|
307
434
|
}
|
|
308
435
|
catch (e) {
|
|
309
436
|
this.end = Date.now();
|
|
310
|
-
this.logService.publish();
|
|
437
|
+
await this.logService.publish();
|
|
311
438
|
throw e;
|
|
312
439
|
}
|
|
313
440
|
}
|
|
314
|
-
async processFeature(data) {
|
|
441
|
+
async processFeature(data, awaitResolution = false) {
|
|
315
442
|
this.start = Date.now();
|
|
316
443
|
this.input = data;
|
|
317
444
|
const { product: product_tag, env, input, tag: feature_tag } = data;
|
|
@@ -322,12 +449,15 @@ class ProcessorService {
|
|
|
322
449
|
additional_logs = {
|
|
323
450
|
name: 'Process feature',
|
|
324
451
|
type: types_1.LogEventTypes.FEATURE,
|
|
325
|
-
parent_tag: feature_tag,
|
|
326
452
|
};
|
|
327
453
|
await this.intializeProduct(additional_logs);
|
|
328
454
|
this.component = types_1.LogEventTypes.FEATURE;
|
|
329
455
|
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
330
456
|
this.process_id = process_id;
|
|
457
|
+
this.feature = this.fetchFeature(feature_tag, additional_logs);
|
|
458
|
+
if (!this.feature) {
|
|
459
|
+
throw new Error(`Feature "${feature_tag}" not found`);
|
|
460
|
+
}
|
|
331
461
|
this.baseLogs = {
|
|
332
462
|
product_tag: this.productTag,
|
|
333
463
|
product_id: this.productId,
|
|
@@ -336,8 +466,9 @@ class ProcessorService {
|
|
|
336
466
|
type: types_1.LogEventTypes.FEATURE,
|
|
337
467
|
process_id,
|
|
338
468
|
data: input,
|
|
469
|
+
feature_tag: feature_tag,
|
|
470
|
+
feature_id: this.feature._id,
|
|
339
471
|
};
|
|
340
|
-
this.feature = this.fetchFeature(feature_tag, additional_logs);
|
|
341
472
|
this.logService.setFeatureId(this.feature._id);
|
|
342
473
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process feature initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
343
474
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
@@ -348,7 +479,7 @@ class ProcessorService {
|
|
|
348
479
|
// validate feature input and log failure
|
|
349
480
|
this.validateJSONFeatureInput(input, featureInput, additional_logs);
|
|
350
481
|
// split processes
|
|
351
|
-
this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
482
|
+
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
352
483
|
await this.processSequenceLevels(additional_logs);
|
|
353
484
|
return { process_id };
|
|
354
485
|
//return this.generateOutput(output as unknown as Record<string, IFeatureOutput>);
|
|
@@ -357,7 +488,7 @@ class ProcessorService {
|
|
|
357
488
|
this.end = Date.now();
|
|
358
489
|
if (this.logService) {
|
|
359
490
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process feature - failed', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
360
|
-
this.logService.publish();
|
|
491
|
+
await this.logService.publish();
|
|
361
492
|
if (passedValidation) {
|
|
362
493
|
return { process_id: this.process_id };
|
|
363
494
|
}
|
|
@@ -394,7 +525,6 @@ class ProcessorService {
|
|
|
394
525
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Product initialize - success', data: { product_id: this.productId }, status: types_1.LogEventStatus.SUCCESS }));
|
|
395
526
|
}
|
|
396
527
|
catch (e) {
|
|
397
|
-
console.log(e);
|
|
398
528
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Product initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
399
529
|
throw e;
|
|
400
530
|
}
|
|
@@ -461,7 +591,7 @@ class ProcessorService {
|
|
|
461
591
|
throw e;
|
|
462
592
|
}
|
|
463
593
|
}
|
|
464
|
-
splitSequenceIntoLevels(data, additional_logs) {
|
|
594
|
+
async splitSequenceIntoLevels(data, additional_logs) {
|
|
465
595
|
try {
|
|
466
596
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
467
597
|
const levels = {};
|
|
@@ -503,7 +633,7 @@ class ProcessorService {
|
|
|
503
633
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process levels - initiated', data: { levels: this.sequenceLevels }, status: types_1.LogEventStatus.PROCESSING }));
|
|
504
634
|
const levelEvents = {};
|
|
505
635
|
Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
|
|
506
|
-
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences);
|
|
636
|
+
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
|
|
507
637
|
});
|
|
508
638
|
let previousLevelComplete = true;
|
|
509
639
|
for (const level of Object.keys(levelEvents)
|
|
@@ -516,11 +646,32 @@ class ProcessorService {
|
|
|
516
646
|
break;
|
|
517
647
|
}
|
|
518
648
|
}
|
|
519
|
-
|
|
520
|
-
|
|
649
|
+
this.doneWithProcessing = true;
|
|
650
|
+
if (previousLevelComplete && !this.published) {
|
|
651
|
+
let message;
|
|
652
|
+
let status;
|
|
653
|
+
let successful_feature_execution;
|
|
654
|
+
let failed_feature_execution;
|
|
655
|
+
if (this.processingOutput.failure.length === 0) {
|
|
656
|
+
message = 'Process feature - success';
|
|
657
|
+
status = types_1.LogEventStatus.SUCCESS;
|
|
658
|
+
successful_feature_execution = true;
|
|
659
|
+
}
|
|
660
|
+
else if (this.processingFailure) {
|
|
661
|
+
console.log("PROCESSING FAILURE", this.processingFailure);
|
|
662
|
+
message = 'Process feature - processing';
|
|
663
|
+
status = types_1.LogEventStatus.PROCESSING;
|
|
664
|
+
successful_feature_execution = false;
|
|
665
|
+
failed_feature_execution = false;
|
|
666
|
+
}
|
|
667
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_feature_execution,
|
|
668
|
+
failed_feature_execution,
|
|
669
|
+
message, data: {}, status }));
|
|
670
|
+
await this.logService.publish();
|
|
521
671
|
this.end = Date.now();
|
|
522
|
-
this.writeResult(
|
|
672
|
+
await this.writeResult(status);
|
|
523
673
|
}
|
|
674
|
+
return true;
|
|
524
675
|
}
|
|
525
676
|
catch (e) {
|
|
526
677
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process levels - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
@@ -528,46 +679,62 @@ class ProcessorService {
|
|
|
528
679
|
}
|
|
529
680
|
}
|
|
530
681
|
async processLevelEvents(events, additional_logs) {
|
|
531
|
-
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
682
|
+
try {
|
|
683
|
+
const promises = events.map((event) => {
|
|
684
|
+
const dependants = this.fetchActionRequestDependents(event.input, additional_logs);
|
|
685
|
+
const passed = this.checkDependentsSuccess(dependants);
|
|
686
|
+
if (passed) {
|
|
687
|
+
// TODO: comparison to see if all depending events are in success || dependants is empty
|
|
688
|
+
return this.processEvent(event);
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
this.addToWaitingOutput(event, dependants);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
return Promise.all(promises);
|
|
695
|
+
}
|
|
696
|
+
catch (e) {
|
|
697
|
+
throw e;
|
|
698
|
+
}
|
|
542
699
|
}
|
|
543
700
|
async processFailedEvents(additional_logs) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
701
|
+
try {
|
|
702
|
+
const { failure } = this.processingOutput;
|
|
703
|
+
const promises = failure.map((failed) => {
|
|
704
|
+
if (failed.retries_left > 0 && new Date().getTime() > failed.retry_at) {
|
|
705
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess failed events - initiated', data: Object.assign({}, failed), status: types_1.LogEventStatus.PROCESSING }));
|
|
706
|
+
return this.processEvent(failed.event); // process events should also take care of this.processingOutput
|
|
707
|
+
}
|
|
708
|
+
if (failed.retries_left === 0 && !failed.allow_fail) {
|
|
709
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess failed events - failed', data: Object.assign(Object.assign({}, failed), { reason: 'Ran out of Retries' }), status: types_1.LogEventStatus.FAIL }));
|
|
710
|
+
throw new Error(`Event ${failed.event.event} failed in sequence ${failed.event.sequence_tag}, ran out of retries and the feature cannot run without it succeeding`);
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
Promise.all(promises);
|
|
714
|
+
}
|
|
715
|
+
catch (e) {
|
|
716
|
+
throw e;
|
|
717
|
+
}
|
|
556
718
|
}
|
|
557
719
|
async processWaitingEvents(additional_logs) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
720
|
+
try {
|
|
721
|
+
const { waiting } = this.processingOutput;
|
|
722
|
+
const promises = waiting.map((waiting) => {
|
|
723
|
+
const { dependants } = waiting;
|
|
724
|
+
if (this.checkDependentsSuccess(dependants)) {
|
|
725
|
+
// TODO: comparison to see if all depending events are in success || dependants is empty
|
|
726
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess waiting events - initiated', data: Object.assign({}, waiting), status: types_1.LogEventStatus.PROCESSING }));
|
|
727
|
+
return this.processEvent(waiting.event);
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess waiting events - waiting', data: Object.assign({}, waiting), status: types_1.LogEventStatus.WAITING }));
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
return Promise.all(promises);
|
|
734
|
+
}
|
|
735
|
+
catch (e) {
|
|
736
|
+
throw e;
|
|
737
|
+
}
|
|
571
738
|
}
|
|
572
739
|
checkDependentsSuccess(dependants) {
|
|
573
740
|
let pass = true;
|
|
@@ -597,6 +764,12 @@ class ProcessorService {
|
|
|
597
764
|
if (input.data) {
|
|
598
765
|
dependents.push(...this.fetchDependents(input.data, additional_logs));
|
|
599
766
|
}
|
|
767
|
+
if (input.fileName) {
|
|
768
|
+
dependents.push(...this.valueStringDepsCheck(input.fileName));
|
|
769
|
+
}
|
|
770
|
+
if (input.buffer) {
|
|
771
|
+
dependents.push(...this.valueStringDepsCheck(input.buffer));
|
|
772
|
+
}
|
|
600
773
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch request dependencies - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), dependents }, status: types_1.LogEventStatus.SUCCESS }));
|
|
601
774
|
return dependents;
|
|
602
775
|
}
|
|
@@ -621,6 +794,20 @@ class ProcessorService {
|
|
|
621
794
|
event_tag: stages[1],
|
|
622
795
|
});
|
|
623
796
|
}
|
|
797
|
+
else if (values[i].startsWith('$')) {
|
|
798
|
+
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(values[i]);
|
|
799
|
+
if (funcArgs.args.length) {
|
|
800
|
+
funcArgs.args.map((arg) => {
|
|
801
|
+
if (arg.startsWith('$Sequence')) {
|
|
802
|
+
const stages = this.productBuilderService.extractStages(arg);
|
|
803
|
+
dependants.push({
|
|
804
|
+
sequence_tag: stages[0],
|
|
805
|
+
event_tag: stages[1],
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
}
|
|
624
811
|
}
|
|
625
812
|
}
|
|
626
813
|
else {
|
|
@@ -628,10 +815,7 @@ class ProcessorService {
|
|
|
628
815
|
}
|
|
629
816
|
}
|
|
630
817
|
else if (typeof value === 'string') {
|
|
631
|
-
|
|
632
|
-
const stages = this.productBuilderService.extractStages(value);
|
|
633
|
-
dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
|
|
634
|
-
}
|
|
818
|
+
dependants.push(...this.valueStringDepsCheck(value.trim()));
|
|
635
819
|
}
|
|
636
820
|
}
|
|
637
821
|
return dependants;
|
|
@@ -641,6 +825,34 @@ class ProcessorService {
|
|
|
641
825
|
throw e;
|
|
642
826
|
}
|
|
643
827
|
}
|
|
828
|
+
valueStringDepsCheck(value) {
|
|
829
|
+
const dependants = [];
|
|
830
|
+
if (value.startsWith('$Sequence')) {
|
|
831
|
+
const stages = this.productBuilderService.extractStages(value);
|
|
832
|
+
dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
|
|
833
|
+
}
|
|
834
|
+
else if (value.startsWith('$')) {
|
|
835
|
+
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(value);
|
|
836
|
+
if (funcArgs && funcArgs.args.length) {
|
|
837
|
+
funcArgs.args.map((arg) => {
|
|
838
|
+
if (arg.startsWith('$Sequence')) {
|
|
839
|
+
const stages = this.productBuilderService.extractStages(arg);
|
|
840
|
+
dependants.push({
|
|
841
|
+
sequence_tag: stages[0],
|
|
842
|
+
event_tag: stages[1],
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
else {
|
|
846
|
+
const args = arg.split(',');
|
|
847
|
+
args.map((arg) => {
|
|
848
|
+
dependants.push(...this.valueStringDepsCheck(arg.trim()));
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return dependants;
|
|
855
|
+
}
|
|
644
856
|
async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
|
|
645
857
|
try {
|
|
646
858
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Construct JSON payloads - initiated', data: { object, samples }, status: types_1.LogEventStatus.PROCESSING }));
|
|
@@ -797,7 +1009,7 @@ class ProcessorService {
|
|
|
797
1009
|
return await this.sumValues(value, app, additional_logs, sample, index, key, loopIndex);
|
|
798
1010
|
}
|
|
799
1011
|
else if (value.startsWith('$Substract(') && value.endsWith(')')) {
|
|
800
|
-
return await this.
|
|
1012
|
+
return await this.subtractValues(value, app, additional_logs, sample, index, key, loopIndex);
|
|
801
1013
|
}
|
|
802
1014
|
else if (value.startsWith('$Pick(') && value.endsWith(')')) {
|
|
803
1015
|
return await this.pickValue(value, app, additional_logs, sample, index, key, loopIndex);
|
|
@@ -1189,7 +1401,7 @@ class ProcessorService {
|
|
|
1189
1401
|
}
|
|
1190
1402
|
}
|
|
1191
1403
|
decorateValue(value, sample) {
|
|
1192
|
-
if (sample.decorator) {
|
|
1404
|
+
if (sample && sample.decorator) {
|
|
1193
1405
|
if (sample.decoratorPosition &&
|
|
1194
1406
|
sample.decoratorPosition == types_1.DecoratorPostions.APPEND &&
|
|
1195
1407
|
!value.endsWith(sample.decorator)) {
|
|
@@ -1286,7 +1498,7 @@ class ProcessorService {
|
|
|
1286
1498
|
}*/
|
|
1287
1499
|
if (event.type === types_1.FeatureEventTypes.ACTION) {
|
|
1288
1500
|
const additional_logs = {
|
|
1289
|
-
parent_tag:
|
|
1501
|
+
parent_tag: event.app,
|
|
1290
1502
|
child_tag: event.event,
|
|
1291
1503
|
type: types_1.LogEventTypes.ACTION,
|
|
1292
1504
|
name: 'Process feature action',
|
|
@@ -1314,8 +1526,12 @@ class ProcessorService {
|
|
|
1314
1526
|
return this.runStorage(event, additional_logs);
|
|
1315
1527
|
}
|
|
1316
1528
|
if (event.type === types_1.FeatureEventTypes.FEATURE) {
|
|
1317
|
-
|
|
1318
|
-
|
|
1529
|
+
const additional_logs = {
|
|
1530
|
+
parent_tag: event.event,
|
|
1531
|
+
type: types_1.LogEventTypes.FEATURE,
|
|
1532
|
+
name: 'Process sub-feature',
|
|
1533
|
+
};
|
|
1534
|
+
return this.runFeature(event, additional_logs);
|
|
1319
1535
|
}
|
|
1320
1536
|
if (event.type === types_1.FeatureEventTypes.NOTIFICATION) {
|
|
1321
1537
|
const [parent_tag, child_tag] = event.event.split(':');
|
|
@@ -1336,11 +1552,9 @@ class ProcessorService {
|
|
|
1336
1552
|
name: 'Process feature broker event',
|
|
1337
1553
|
};
|
|
1338
1554
|
try {
|
|
1339
|
-
console.log("GRENADYE ALASOOOO!");
|
|
1340
1555
|
return this.runBrokerPublish(event, additional_logs);
|
|
1341
1556
|
}
|
|
1342
1557
|
catch (e) {
|
|
1343
|
-
console.log("GRENADYE ALASOOOO!!!!");
|
|
1344
1558
|
}
|
|
1345
1559
|
}
|
|
1346
1560
|
if (event.type === types_1.FeatureEventTypes.JOB) {
|
|
@@ -1356,13 +1570,30 @@ class ProcessorService {
|
|
|
1356
1570
|
throw e;
|
|
1357
1571
|
}
|
|
1358
1572
|
}
|
|
1573
|
+
async runFeature(event, additional_logs) {
|
|
1574
|
+
const freshInstance = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
1575
|
+
const result = await freshInstance.processFeature({
|
|
1576
|
+
product: this.productTag,
|
|
1577
|
+
tag: event.event,
|
|
1578
|
+
env: this.processEnv.slug,
|
|
1579
|
+
input: event.input,
|
|
1580
|
+
}, true);
|
|
1581
|
+
const output = await freshInstance.generateOutput(result.process_id);
|
|
1582
|
+
if (output.status === types_1.LogEventStatus.FAIL) {
|
|
1583
|
+
await this.addToFailureOutput(output.errors, event, { process_id: result.process_id }, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
|
|
1584
|
+
}
|
|
1585
|
+
else if (output.status === types_1.LogEventStatus.SUCCESS) {
|
|
1586
|
+
await this.addToSuccessOutput(event, output.data, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
|
|
1587
|
+
}
|
|
1588
|
+
return output;
|
|
1589
|
+
}
|
|
1359
1590
|
runJob(event, additional_logs) {
|
|
1360
1591
|
throw new Error('Method not implemented.');
|
|
1361
1592
|
}
|
|
1362
1593
|
async processFailedAndWaiting() { }
|
|
1363
1594
|
async generateOutput(process_id) {
|
|
1364
1595
|
var _a, _b, _c, _d;
|
|
1365
|
-
const result =
|
|
1596
|
+
const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
|
|
1366
1597
|
if (!result) {
|
|
1367
1598
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1368
1599
|
}
|
|
@@ -1372,7 +1603,10 @@ class ProcessorService {
|
|
|
1372
1603
|
type: types_1.LogEventTypes.FEATURE,
|
|
1373
1604
|
name: 'Fetching Process Result',
|
|
1374
1605
|
};
|
|
1375
|
-
if (result.status === types_1.LogEventStatus.
|
|
1606
|
+
if (result.status === types_1.LogEventStatus.PROCESSING) {
|
|
1607
|
+
return { process_id, status: result.status };
|
|
1608
|
+
}
|
|
1609
|
+
else if (result.status === types_1.LogEventStatus.SUCCESS) {
|
|
1376
1610
|
this.productTag = result.input.product;
|
|
1377
1611
|
await this.intializeProduct(additional_logs);
|
|
1378
1612
|
this.processingOutput = result.result;
|
|
@@ -1388,7 +1622,7 @@ class ProcessorService {
|
|
|
1388
1622
|
return { process_id, status: result.status, errors };
|
|
1389
1623
|
}
|
|
1390
1624
|
}
|
|
1391
|
-
else {
|
|
1625
|
+
else if (result) {
|
|
1392
1626
|
if ((_a = result.result.success[0]) === null || _a === void 0 ? void 0 : _a.output) {
|
|
1393
1627
|
return { process_id, status: result.status, data: (_b = result.result.success[0]) === null || _b === void 0 ? void 0 : _b.output };
|
|
1394
1628
|
}
|
|
@@ -1428,7 +1662,7 @@ class ProcessorService {
|
|
|
1428
1662
|
// validate feature input and log failure
|
|
1429
1663
|
this.validateJSONFeatureInput(result.input.input, featureInput, additional_logs);
|
|
1430
1664
|
// split processes
|
|
1431
|
-
this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1665
|
+
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1432
1666
|
await this.processSequenceLevels(additional_logs);
|
|
1433
1667
|
}
|
|
1434
1668
|
else {
|
|
@@ -1437,7 +1671,7 @@ class ProcessorService {
|
|
|
1437
1671
|
if (this.processingOutput.failure.length > 0) {
|
|
1438
1672
|
status = types_1.LogEventStatus.FAIL;
|
|
1439
1673
|
}
|
|
1440
|
-
this.writeResult(status);
|
|
1674
|
+
await this.writeResult(status);
|
|
1441
1675
|
}
|
|
1442
1676
|
return { process_id };
|
|
1443
1677
|
}
|
|
@@ -1470,7 +1704,7 @@ class ProcessorService {
|
|
|
1470
1704
|
// validate feature input and log failure
|
|
1471
1705
|
this.validateJSONFeatureInput(result.input.input, featureInput, additional_logs);
|
|
1472
1706
|
// split processes
|
|
1473
|
-
this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1707
|
+
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1474
1708
|
await this.processSequenceLevels(additional_logs);
|
|
1475
1709
|
}
|
|
1476
1710
|
else {
|
|
@@ -1482,20 +1716,20 @@ class ProcessorService {
|
|
|
1482
1716
|
this.start = Date.now();
|
|
1483
1717
|
await this.processEvent(event);
|
|
1484
1718
|
this.end = Date.now();
|
|
1485
|
-
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
1486
|
-
this.logService.publish();
|
|
1719
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
1720
|
+
await this.logService.publish();
|
|
1487
1721
|
}
|
|
1488
1722
|
return { process_id };
|
|
1489
1723
|
}
|
|
1490
|
-
fetchLevelEvents(level) {
|
|
1724
|
+
fetchLevelEvents(sequence, level) {
|
|
1491
1725
|
const events = [];
|
|
1492
|
-
for (let i = 0; i <
|
|
1493
|
-
events.push(...this.appendSequenceDataToLevelEvents(
|
|
1726
|
+
for (let i = 0; i < sequence.length; i++) {
|
|
1727
|
+
events.push(...this.appendSequenceDataToLevelEvents(sequence[i], level));
|
|
1494
1728
|
}
|
|
1495
1729
|
return events;
|
|
1496
1730
|
}
|
|
1497
|
-
appendSequenceDataToLevelEvents(sequence) {
|
|
1498
|
-
const { events,
|
|
1731
|
+
appendSequenceDataToLevelEvents(sequence, level) {
|
|
1732
|
+
const { events, tag } = sequence;
|
|
1499
1733
|
for (let i = 0; i < events.length; i++) {
|
|
1500
1734
|
events[i].sequence_level = level;
|
|
1501
1735
|
events[i].sequence_tag = tag;
|
|
@@ -1624,15 +1858,13 @@ class ProcessorService {
|
|
|
1624
1858
|
// generate indexes
|
|
1625
1859
|
return (0, processor_utils_1.generateIndexes)(operator, iter, init, valueValue);
|
|
1626
1860
|
}
|
|
1627
|
-
async runAction(event, additional_logs, returnValue =
|
|
1861
|
+
async runAction(event, additional_logs, returnValue = true) {
|
|
1628
1862
|
try {
|
|
1629
|
-
console.log("RUNNING ACTION!!!!!");
|
|
1630
1863
|
const { event: action_tag, app: access_tag, condition, cache: cache_tag } = event;
|
|
1631
1864
|
let indexes = [];
|
|
1632
1865
|
if (condition &&
|
|
1633
1866
|
condition.type === types_1.Conditions.CHECK &&
|
|
1634
1867
|
(await this.processConditionalCheck(event, additional_logs))) {
|
|
1635
|
-
console.log("RUNNING ACTION SKIPPED!!!!!");
|
|
1636
1868
|
// if it fails, it would add to skipped queue
|
|
1637
1869
|
return;
|
|
1638
1870
|
}
|
|
@@ -1690,9 +1922,12 @@ class ProcessorService {
|
|
|
1690
1922
|
}
|
|
1691
1923
|
}
|
|
1692
1924
|
}
|
|
1693
|
-
if (request_type === types_1.DataFormats.JSON || !request_type) {
|
|
1925
|
+
if (request_type === types_1.DataFormats.JSON || request_type === types_1.DataFormats.URLENCODED || !request_type) {
|
|
1694
1926
|
if (indexes.length == 0) {
|
|
1695
1927
|
payloads = await this.constructJSONDataPayloads(event.input, additional_logs, samples, event);
|
|
1928
|
+
if (request_type === types_1.DataFormats.URLENCODED) {
|
|
1929
|
+
payloads.body = (0, processor_utils_1.toFormUrlEncoded)(payloads.body);
|
|
1930
|
+
}
|
|
1696
1931
|
additional_logs.recipient_workspace_id = recipient_workspace_id;
|
|
1697
1932
|
result = await this.processRequest({ request_base_url, resource, method, env, payloads, app_id: app._id }, event, retries, additional_logs, returnValue);
|
|
1698
1933
|
}
|
|
@@ -1722,9 +1957,7 @@ class ProcessorService {
|
|
|
1722
1957
|
product_tag: this.productTag,
|
|
1723
1958
|
});
|
|
1724
1959
|
}
|
|
1725
|
-
|
|
1726
|
-
return result;
|
|
1727
|
-
}
|
|
1960
|
+
return result;
|
|
1728
1961
|
}
|
|
1729
1962
|
catch (e) {
|
|
1730
1963
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Run Action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
@@ -1736,8 +1969,13 @@ class ProcessorService {
|
|
|
1736
1969
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - initiated', data: { request: (0, processor_utils_1.anonymizeObject)(payload) }, status: types_1.LogEventStatus.PROCESSING, app_id, action: event.event }));
|
|
1737
1970
|
const start = Date.now();
|
|
1738
1971
|
try {
|
|
1739
|
-
|
|
1972
|
+
let results = (0, processor_utils_1.generateMockData)(resource, env.slug, payloads);
|
|
1973
|
+
if (!results) {
|
|
1974
|
+
results = await this.sendActionRequest(request_base_url, resource, payloads, method, env.slug);
|
|
1975
|
+
}
|
|
1740
1976
|
const end = Date.now();
|
|
1977
|
+
this.requestTime += end - start;
|
|
1978
|
+
this.totalRequests += 1;
|
|
1741
1979
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - success', successful_execution: true, data: { response: (0, processor_utils_1.anonymizeObject)(results) }, status: types_1.LogEventStatus.SUCCESS, app_id, action: event.event, start,
|
|
1742
1980
|
end }));
|
|
1743
1981
|
await this.addToSuccessOutput(event, results, additional_logs);
|
|
@@ -1750,10 +1988,12 @@ class ProcessorService {
|
|
|
1750
1988
|
}
|
|
1751
1989
|
catch (e) {
|
|
1752
1990
|
const end = Date.now();
|
|
1991
|
+
this.requestTime += end - start;
|
|
1992
|
+
this.totalRequests += 1;
|
|
1753
1993
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - failed', failed_execution: true, data: { e }, status: types_1.LogEventStatus.FAIL, app_id, action: event.event, start,
|
|
1754
1994
|
end }));
|
|
1755
1995
|
try {
|
|
1756
|
-
const value = this.addToFailureOutput(e, event, {
|
|
1996
|
+
const value = await this.addToFailureOutput(e, event, {
|
|
1757
1997
|
request_base_url,
|
|
1758
1998
|
resource,
|
|
1759
1999
|
method,
|
|
@@ -1761,6 +2001,9 @@ class ProcessorService {
|
|
|
1761
2001
|
payloads,
|
|
1762
2002
|
app_id,
|
|
1763
2003
|
}, additional_logs, retries);
|
|
2004
|
+
if (value) {
|
|
2005
|
+
return value;
|
|
2006
|
+
}
|
|
1764
2007
|
//if (returnValue) {
|
|
1765
2008
|
return {
|
|
1766
2009
|
process_id: this.process_id,
|
|
@@ -1781,6 +2024,24 @@ class ProcessorService {
|
|
|
1781
2024
|
this.processingOutput.waiting = this.processingOutput.waiting.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
1782
2025
|
this.processingOutput.success.push({ event, output });
|
|
1783
2026
|
await this.processWaitingEvents(additional_logs);
|
|
2027
|
+
if (this.checkIsSuccessful() && this.doneWithProcessing) {
|
|
2028
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_feature_execution: true, message: 'Process feature - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2029
|
+
await this.logService.publish();
|
|
2030
|
+
this.end = Date.now();
|
|
2031
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
checkIsSuccessful() {
|
|
2035
|
+
let success = true;
|
|
2036
|
+
this.processingOutput.failure.find((output) => {
|
|
2037
|
+
if (!output.allow_fail) {
|
|
2038
|
+
success = false;
|
|
2039
|
+
}
|
|
2040
|
+
});
|
|
2041
|
+
if (this.processingOutput.waiting.length > 0) {
|
|
2042
|
+
success = false;
|
|
2043
|
+
}
|
|
2044
|
+
return success;
|
|
1784
2045
|
}
|
|
1785
2046
|
addToWaitingOutput(event, dependants) {
|
|
1786
2047
|
const exists = this.processingOutput.waiting.findIndex((item) => {
|
|
@@ -1794,8 +2055,9 @@ class ProcessorService {
|
|
|
1794
2055
|
}
|
|
1795
2056
|
// addToSkippedOutput()
|
|
1796
2057
|
}
|
|
1797
|
-
addToFailureOutput(e, event, payload, additional_logs, policy = {}) {
|
|
2058
|
+
async addToFailureOutput(e, event, payload, additional_logs, policy = {}) {
|
|
1798
2059
|
try {
|
|
2060
|
+
this.processingFailure = true;
|
|
1799
2061
|
const exists = this.processingOutput.failure.findIndex((item) => {
|
|
1800
2062
|
if (item.event.sequence_tag) {
|
|
1801
2063
|
return item.event.event === event.event && item.event.sequence_tag === event.sequence_tag;
|
|
@@ -1853,11 +2115,16 @@ class ProcessorService {
|
|
|
1853
2115
|
}, retry_at);
|
|
1854
2116
|
}
|
|
1855
2117
|
if (allow_fail === false && retries_left === 0) {
|
|
2118
|
+
this.published = true;
|
|
2119
|
+
if (this.feature) {
|
|
2120
|
+
additional_logs.failed_feature_execution = true;
|
|
2121
|
+
}
|
|
1856
2122
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Ran out of retries - failed', data: Object.assign(Object.assign({}, output), { payload: (0, processor_utils_1.anonymizeObject)(output.payload) }), status: types_1.LogEventStatus.FAIL }));
|
|
1857
2123
|
//throw new Error("Run out of retries")
|
|
1858
2124
|
this.end = Date.now();
|
|
1859
|
-
this.writeResult(types_1.LogEventStatus.FAIL);
|
|
1860
|
-
this.logService.publish();
|
|
2125
|
+
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
2126
|
+
await this.logService.publish();
|
|
2127
|
+
//throw new Error("Terminate Process")
|
|
1861
2128
|
}
|
|
1862
2129
|
return output;
|
|
1863
2130
|
}
|
|
@@ -1924,20 +2191,24 @@ class ProcessorService {
|
|
|
1924
2191
|
}
|
|
1925
2192
|
}
|
|
1926
2193
|
const authHeaders = headers;
|
|
2194
|
+
if (!base_url.endsWith('/') && !resource.startsWith('/')) {
|
|
2195
|
+
base_url = base_url + '/';
|
|
2196
|
+
}
|
|
1927
2197
|
const request = {
|
|
1928
2198
|
url: resource,
|
|
1929
2199
|
method,
|
|
2200
|
+
baseURL: base_url,
|
|
1930
2201
|
data: body,
|
|
1931
2202
|
params: query,
|
|
1932
2203
|
headers: authHeaders,
|
|
2204
|
+
timeout: 15000,
|
|
2205
|
+
withCredentials: false
|
|
1933
2206
|
};
|
|
1934
|
-
|
|
1935
|
-
base_url = base_url + '/';
|
|
1936
|
-
}
|
|
1937
|
-
const response = await (0, http_client_1.default)(base_url).request(request);
|
|
2207
|
+
const response = await axios_1.default.request(request);
|
|
1938
2208
|
return response.data;
|
|
1939
2209
|
}
|
|
1940
2210
|
catch (e) {
|
|
2211
|
+
//console.error("LOG ERROR", e);
|
|
1941
2212
|
throw e;
|
|
1942
2213
|
}
|
|
1943
2214
|
}
|
|
@@ -1951,7 +2222,7 @@ class ProcessorService {
|
|
|
1951
2222
|
};
|
|
1952
2223
|
try {
|
|
1953
2224
|
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
1954
|
-
this.input =
|
|
2225
|
+
this.input = input;
|
|
1955
2226
|
this.start = Date.now();
|
|
1956
2227
|
this.component = types_1.LogEventTypes.STORAGE;
|
|
1957
2228
|
// clone
|
|
@@ -1981,14 +2252,14 @@ class ProcessorService {
|
|
|
1981
2252
|
const result = await this.runStorage(payload);
|
|
1982
2253
|
this.end = Date.now();
|
|
1983
2254
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - success', data: { input: this.clone, result }, status: types_1.LogEventStatus.SUCCESS }));
|
|
1984
|
-
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
1985
|
-
this.logService.publish();
|
|
2255
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2256
|
+
await this.logService.publish();
|
|
1986
2257
|
return result;
|
|
1987
2258
|
}
|
|
1988
2259
|
catch (e) {
|
|
1989
2260
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
1990
2261
|
this.end = Date.now();
|
|
1991
|
-
this.logService.publish();
|
|
2262
|
+
await this.logService.publish();
|
|
1992
2263
|
return { process_id: this.process_id };
|
|
1993
2264
|
}
|
|
1994
2265
|
}
|
|
@@ -2030,14 +2301,14 @@ class ProcessorService {
|
|
|
2030
2301
|
const result = await this.runBrokerSubscribe(payload);
|
|
2031
2302
|
this.end = Date.now();
|
|
2032
2303
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Subscribe to topic - success', data: { input: this.clone, result }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2033
|
-
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2034
|
-
this.logService.publish();
|
|
2304
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2305
|
+
await this.logService.publish();
|
|
2035
2306
|
return result;
|
|
2036
2307
|
}
|
|
2037
2308
|
catch (e) {
|
|
2038
2309
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Subscribe to topic - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2039
2310
|
this.end = Date.now();
|
|
2040
|
-
this.logService.publish();
|
|
2311
|
+
await this.logService.publish();
|
|
2041
2312
|
return { process_id: this.process_id };
|
|
2042
2313
|
}
|
|
2043
2314
|
}
|
|
@@ -2054,7 +2325,6 @@ class ProcessorService {
|
|
|
2054
2325
|
};
|
|
2055
2326
|
try {
|
|
2056
2327
|
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2057
|
-
console.log("JAPANESE MIRRORS", data.input);
|
|
2058
2328
|
this.start = Date.now();
|
|
2059
2329
|
// clone
|
|
2060
2330
|
this.clone = (0, processor_utils_1.structuredClone)(data.input);
|
|
@@ -2068,7 +2338,6 @@ class ProcessorService {
|
|
|
2068
2338
|
this.process_id = process_id;
|
|
2069
2339
|
const productEnv = this.fetchEnv(data.env, additional_logs);
|
|
2070
2340
|
this.processEnv = productEnv;
|
|
2071
|
-
console.log("JAPANESE MIRRORS 2", productEnv);
|
|
2072
2341
|
if (!productEnv.active) {
|
|
2073
2342
|
throw new Error(`Environment ${data.env} is not active`);
|
|
2074
2343
|
}
|
|
@@ -2085,15 +2354,14 @@ class ProcessorService {
|
|
|
2085
2354
|
const result = await this.runBrokerPublish(payload);
|
|
2086
2355
|
this.end = Date.now();
|
|
2087
2356
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publishing to topic - success', data: { input: (0, processor_utils_1.anonymizeObject)(this.clone), result }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2088
|
-
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2089
|
-
this.logService.publish();
|
|
2357
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2358
|
+
await this.logService.publish();
|
|
2090
2359
|
return result;
|
|
2091
2360
|
}
|
|
2092
2361
|
catch (e) {
|
|
2093
|
-
console.log(e);
|
|
2094
2362
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publishing to topic - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2095
2363
|
this.end = Date.now();
|
|
2096
|
-
this.logService.publish();
|
|
2364
|
+
await this.logService.publish();
|
|
2097
2365
|
return { process_id: this.process_id };
|
|
2098
2366
|
}
|
|
2099
2367
|
}
|
|
@@ -2106,7 +2374,6 @@ class ProcessorService {
|
|
|
2106
2374
|
body: payload.body,
|
|
2107
2375
|
data: (0, processor_utils_1.convertStringToObject)(payload.data),
|
|
2108
2376
|
};
|
|
2109
|
-
console.log("MESSAGE!!!", message);
|
|
2110
2377
|
try {
|
|
2111
2378
|
await (0, expo_client_1.default)().post('', message, (0, processor_utils_1.generateAxiosConfig)());
|
|
2112
2379
|
}
|
|
@@ -2125,7 +2392,6 @@ class ProcessorService {
|
|
|
2125
2392
|
try {
|
|
2126
2393
|
const admin = require('firebase-admin');
|
|
2127
2394
|
const serviceAccount = credentials;
|
|
2128
|
-
console.log("MESSAGE", message);
|
|
2129
2395
|
admin.initializeApp({
|
|
2130
2396
|
credential: admin.credential.cert(serviceAccount),
|
|
2131
2397
|
});
|
|
@@ -2169,6 +2435,9 @@ class ProcessorService {
|
|
|
2169
2435
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching notification details', data: { notification }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2170
2436
|
const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
|
|
2171
2437
|
const message = this.productBuilderService.fetchNotificationMessage(event);
|
|
2438
|
+
if (!message) {
|
|
2439
|
+
throw new Error(`Message ${event} not found`);
|
|
2440
|
+
}
|
|
2172
2441
|
const { envs } = notificationEvent;
|
|
2173
2442
|
const { push_notifications: notifications, emails, callbacks, sms: smses } = envs.find((data) => data.slug === notification.env.slug);
|
|
2174
2443
|
const { push_notification: push, email, callback, sms } = message;
|
|
@@ -2253,11 +2522,6 @@ class ProcessorService {
|
|
|
2253
2522
|
const url = new URL(callbacks.url);
|
|
2254
2523
|
try {
|
|
2255
2524
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send callback - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2256
|
-
console.log("CALLBACK!!!!", {
|
|
2257
|
-
url,
|
|
2258
|
-
payload,
|
|
2259
|
-
method: callbacks.method
|
|
2260
|
-
});
|
|
2261
2525
|
await this.sendActionRequest(url.origin, url.pathname, payload, callbacks.method, '');
|
|
2262
2526
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send callback - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2263
2527
|
}
|
|
@@ -2272,7 +2536,6 @@ class ProcessorService {
|
|
|
2272
2536
|
const SmsClient = await (0, sms_repo_1.loadSMSClient)();
|
|
2273
2537
|
const smsClient = new SmsClient(smses);
|
|
2274
2538
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - initiated', data: { message: input.sms.body, config: (0, processor_utils_1.anonymizeObject)(smses) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2275
|
-
console.log("SMS!!!!", input.sms, smses);
|
|
2276
2539
|
const res = await smsClient.sendMessage(input.sms.body, input.sms.recipients);
|
|
2277
2540
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - success', data: res, status: types_1.LogEventStatus.SUCCESS }));
|
|
2278
2541
|
}
|
|
@@ -2283,9 +2546,9 @@ class ProcessorService {
|
|
|
2283
2546
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Attempt notification - success', data: notification, status: types_1.LogEventStatus.SUCCESS }));
|
|
2284
2547
|
}
|
|
2285
2548
|
catch (e) {
|
|
2286
|
-
|
|
2287
|
-
this.logService.
|
|
2288
|
-
|
|
2549
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt notification - failed', data: { e: e.toString() }, status: types_1.LogEventStatus.FAIL }));
|
|
2550
|
+
//await this.logService.publish();
|
|
2551
|
+
throw e;
|
|
2289
2552
|
}
|
|
2290
2553
|
}
|
|
2291
2554
|
async runMigration(product_tag, tag, env, type) {
|
|
@@ -2363,9 +2626,8 @@ class ProcessorService {
|
|
|
2363
2626
|
}
|
|
2364
2627
|
}
|
|
2365
2628
|
catch (e) {
|
|
2366
|
-
console.log(e);
|
|
2367
2629
|
this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { failed_execution: true, message: 'Attempt migration - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
2368
|
-
this.logService.publish();
|
|
2630
|
+
await this.logService.publish();
|
|
2369
2631
|
}
|
|
2370
2632
|
}
|
|
2371
2633
|
/*async runFunction(data: IFeatureEvent, additional_logs: Partial<ILogData>): Promise<any> {
|
|
@@ -2458,7 +2720,7 @@ class ProcessorService {
|
|
|
2458
2720
|
data: e,
|
|
2459
2721
|
status: LogEventStatus.FAIL,
|
|
2460
2722
|
});
|
|
2461
|
-
this.logService.publish();
|
|
2723
|
+
await this.logService.publish();
|
|
2462
2724
|
}
|
|
2463
2725
|
}*/
|
|
2464
2726
|
async runStorage(data, additional_logs = {}) {
|
|
@@ -2495,10 +2757,9 @@ class ProcessorService {
|
|
|
2495
2757
|
}
|
|
2496
2758
|
}
|
|
2497
2759
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Store file - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2498
|
-
|
|
2499
|
-
input.
|
|
2500
|
-
input.
|
|
2501
|
-
input.mimeType = file.mimeType;
|
|
2760
|
+
input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
|
|
2761
|
+
input.fileName = input.fileName ? await this.generateStringValues(input.fileName, '', additional_logs, []) : undefined;
|
|
2762
|
+
input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
|
|
2502
2763
|
result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
|
|
2503
2764
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Store file - success', data: { result }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2504
2765
|
if (cache_tag && this.redisClient) {
|
|
@@ -2521,7 +2782,6 @@ class ProcessorService {
|
|
|
2521
2782
|
return result;
|
|
2522
2783
|
}
|
|
2523
2784
|
catch (e) {
|
|
2524
|
-
console.log(e);
|
|
2525
2785
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt storage - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2526
2786
|
throw e;
|
|
2527
2787
|
}
|
|
@@ -2558,12 +2818,14 @@ class ProcessorService {
|
|
|
2558
2818
|
data: input.data,
|
|
2559
2819
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2560
2820
|
}));
|
|
2561
|
-
const filterValidationPayload = (await this.inputService.parseJson({
|
|
2562
|
-
data: input.filter,
|
|
2563
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2564
|
-
}));
|
|
2565
2821
|
this.inputService.validateInput(dataValidationPayload, databaseAction.data);
|
|
2566
|
-
|
|
2822
|
+
if (input.filter) {
|
|
2823
|
+
const filterValidationPayload = (await this.inputService.parseJson({
|
|
2824
|
+
data: input.filter,
|
|
2825
|
+
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2826
|
+
}));
|
|
2827
|
+
this.inputService.validateInput(filterValidationPayload, databaseAction.filterData);
|
|
2828
|
+
}
|
|
2567
2829
|
}
|
|
2568
2830
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database action payload - success', data: { db_action, payload: (0, processor_utils_1.anonymizeObject)(input.data) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2569
2831
|
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
@@ -2598,7 +2860,7 @@ class ProcessorService {
|
|
|
2598
2860
|
if (!MongoDBHandler) {
|
|
2599
2861
|
throw new Error(`Running in browser, mongo handler not loaded.`);
|
|
2600
2862
|
}
|
|
2601
|
-
const mongoHandler = new MongoDBHandler(
|
|
2863
|
+
const mongoHandler = new MongoDBHandler(databaseEnv.connection_url);
|
|
2602
2864
|
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
2603
2865
|
const filterTemplate = typeof databaseAction.filterTemplate === 'string'
|
|
2604
2866
|
? databaseAction.filterTemplate
|
|
@@ -2619,7 +2881,7 @@ class ProcessorService {
|
|
|
2619
2881
|
result = await pgHandler[databaseAction.type](databaseAction.data, template, input.data);
|
|
2620
2882
|
}
|
|
2621
2883
|
}
|
|
2622
|
-
//this.logService.publish();
|
|
2884
|
+
//await this.logService.publish();
|
|
2623
2885
|
// const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
|
|
2624
2886
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Run database action query - success', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2625
2887
|
await this.addToSuccessOutput(db_action, result, additional_logs);
|
|
@@ -2643,7 +2905,8 @@ class ProcessorService {
|
|
|
2643
2905
|
return result;
|
|
2644
2906
|
}
|
|
2645
2907
|
catch (e) {
|
|
2646
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt database action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2908
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt database action - failed', data: { e: e.toString() }, status: types_1.LogEventStatus.FAIL }));
|
|
2909
|
+
throw e;
|
|
2647
2910
|
}
|
|
2648
2911
|
}
|
|
2649
2912
|
async runBrokerSubscribe(data, additional_logs = {}) {
|
|
@@ -2743,7 +3006,6 @@ class ProcessorService {
|
|
|
2743
3006
|
}
|
|
2744
3007
|
catch (e) {
|
|
2745
3008
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt publish to broker topic - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2746
|
-
console.log("JERMOOOOO!!!");
|
|
2747
3009
|
throw e;
|
|
2748
3010
|
}
|
|
2749
3011
|
}
|
|
@@ -2774,13 +3036,29 @@ class ProcessorService {
|
|
|
2774
3036
|
Object.assign(config, { awsConfig: cloudConfig });
|
|
2775
3037
|
}
|
|
2776
3038
|
const result = { url: await (0, storage_util_1.uploadBlobToCloud)({ data: input.buffer, destinationPath: input.fileName, config }) };
|
|
3039
|
+
try {
|
|
3040
|
+
await this.processorApiService.saveFileURL({
|
|
3041
|
+
url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchProduct().private_key),
|
|
3042
|
+
provider: storageEnv.type,
|
|
3043
|
+
product: this.productTag,
|
|
3044
|
+
workspace_id: this.workspace_id,
|
|
3045
|
+
type: input.mimeType,
|
|
3046
|
+
event: data.event,
|
|
3047
|
+
env: data.env.slug,
|
|
3048
|
+
size: Buffer.from(input.buffer).length
|
|
3049
|
+
}, this.getUserAccess());
|
|
3050
|
+
}
|
|
3051
|
+
catch (e) { }
|
|
2777
3052
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Run storage request - success', data: { payload: this.clone, result }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2778
3053
|
await this.addToSuccessOutput(data, result, additional_logs);
|
|
2779
3054
|
return result;
|
|
2780
3055
|
}
|
|
2781
3056
|
catch (e) {
|
|
2782
3057
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Run storage request - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2783
|
-
const value = this.addToFailureOutput(e, data, { storageEnv }, additional_logs);
|
|
3058
|
+
const value = await this.addToFailureOutput(e, data, { storageEnv }, additional_logs);
|
|
3059
|
+
if (value) {
|
|
3060
|
+
return value;
|
|
3061
|
+
}
|
|
2784
3062
|
throw e;
|
|
2785
3063
|
}
|
|
2786
3064
|
}
|
|
@@ -2803,7 +3081,7 @@ class ProcessorService {
|
|
|
2803
3081
|
}
|
|
2804
3082
|
catch (e) {
|
|
2805
3083
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Running database query - failed', data: { payload: (0, processor_utils_1.anonymizeObject)(input), e }, status: types_1.LogEventStatus.FAIL }));
|
|
2806
|
-
const value = this.addToFailureOutput(e, db_action, {
|
|
3084
|
+
const value = await this.addToFailureOutput(e, db_action, {
|
|
2807
3085
|
db_action,
|
|
2808
3086
|
input,
|
|
2809
3087
|
database_tag,
|
|
@@ -2888,18 +3166,17 @@ class ProcessorService {
|
|
|
2888
3166
|
retries: retries || 0,
|
|
2889
3167
|
allow_fail: false,
|
|
2890
3168
|
}, additional_logs, true);
|
|
2891
|
-
console.log("RESULT ===>>>>", result);
|
|
2892
3169
|
this.end = Date.now();
|
|
2893
3170
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2894
|
-
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2895
|
-
this.logService.publish();
|
|
3171
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3172
|
+
await this.logService.publish();
|
|
2896
3173
|
return result;
|
|
2897
3174
|
}
|
|
2898
3175
|
catch (e) {
|
|
2899
|
-
console.log(e);
|
|
2900
3176
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2901
3177
|
this.end = Date.now();
|
|
2902
|
-
this.
|
|
3178
|
+
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
3179
|
+
await this.logService.publish();
|
|
2903
3180
|
return { process_id: this.process_id };
|
|
2904
3181
|
}
|
|
2905
3182
|
}
|
|
@@ -2946,14 +3223,14 @@ class ProcessorService {
|
|
|
2946
3223
|
const result = await this.runDBAction(payload, additional_logs);
|
|
2947
3224
|
this.end = Date.now();
|
|
2948
3225
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2949
|
-
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2950
|
-
this.logService.publish();
|
|
3226
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3227
|
+
await this.logService.publish();
|
|
2951
3228
|
return result;
|
|
2952
3229
|
}
|
|
2953
3230
|
catch (e) {
|
|
2954
3231
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2955
3232
|
this.end = Date.now();
|
|
2956
|
-
this.logService.publish();
|
|
3233
|
+
await this.logService.publish();
|
|
2957
3234
|
return { process_id: this.process_id };
|
|
2958
3235
|
}
|
|
2959
3236
|
}
|
|
@@ -3001,14 +3278,14 @@ class ProcessorService {
|
|
|
3001
3278
|
const result = await this.runNotification(payload, additional_logs);
|
|
3002
3279
|
this.end = Date.now();
|
|
3003
3280
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send notification - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3004
|
-
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3005
|
-
this.logService.publish();
|
|
3281
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3282
|
+
await this.logService.publish();
|
|
3006
3283
|
return { process_id };
|
|
3007
3284
|
}
|
|
3008
3285
|
catch (e) {
|
|
3009
3286
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send notification - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
3010
3287
|
this.end = Date.now();
|
|
3011
|
-
this.logService.publish();
|
|
3288
|
+
await this.logService.publish();
|
|
3012
3289
|
return { process_id: this.process_id };
|
|
3013
3290
|
}
|
|
3014
3291
|
}
|