@ductape/sdk 0.0.3-beta8 → 0.0.4-v10
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 +15 -1
- package/dist/api/services/processorApi.service.js +28 -0
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +7 -2
- package/dist/api/services/productsApi.service.js +24 -2
- 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 +5 -0
- package/dist/api/urls.js +6 -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/apps.client.js +1 -1
- package/dist/clients/apps.client.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 +4 -11
- package/dist/imports/repos/openApi.repo.js +50 -28
- 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 +33 -6
- package/dist/index.js +121 -11
- package/dist/index.js.map +1 -1
- package/dist/inputs/inputs.service.js +2 -2
- package/dist/inputs/inputs.service.js.map +1 -1
- package/dist/inputs/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.service.js +1 -0
- package/dist/logs/logs.service.js.map +1 -1
- package/dist/logs/logs.types.d.ts +4 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/processor/repos/sms.repo.d.ts +4 -4
- package/dist/processor/repos/sms.repo.js +23 -10
- package/dist/processor/repos/sms.repo.js.map +1 -1
- package/dist/processor/services/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 +61 -18
- package/dist/processor/services/processor.service.js +714 -316
- 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 +6 -230
- package/dist/processor/utils/processor.utils.js +212 -122
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/storage.util.js +54 -40
- package/dist/processor/utils/storage.util.js.map +1 -1
- package/dist/products/services/products.service.d.ts +26 -7
- package/dist/products/services/products.service.js +427 -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 +48 -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 +48 -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 +20 -12
- 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/index.types.d.ts +5 -0
- package/dist/types/index.types.js.map +1 -1
- package/dist/types/processor.types.d.ts +89 -4
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +40 -8
- package/dist/types/productsBuilder.types.js +3 -0
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/package.json +11 -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,8 @@ 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"));
|
|
72
|
+
//import { Job, Queue, Worker } from 'bullmq';
|
|
70
73
|
async function loadBrokerService() {
|
|
71
74
|
if (typeof window === 'undefined') {
|
|
72
75
|
const { createBrokerService } = await Promise.resolve().then(() => __importStar(require('./messagebrokers')));
|
|
@@ -74,20 +77,31 @@ async function loadBrokerService() {
|
|
|
74
77
|
}
|
|
75
78
|
return null;
|
|
76
79
|
}
|
|
80
|
+
async function loadJWT() {
|
|
81
|
+
if (typeof window === 'undefined') {
|
|
82
|
+
const JWT = await Promise.resolve().then(() => __importStar(require("jsonwebtoken")));
|
|
83
|
+
return JWT;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
77
87
|
class ProcessorService {
|
|
78
|
-
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
|
|
88
|
+
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client, queues }) {
|
|
79
89
|
this.workspace_id = workspace_id;
|
|
80
90
|
this.public_key = public_key;
|
|
81
91
|
this.user_id = user_id;
|
|
82
92
|
this.token = token;
|
|
93
|
+
this.published = false;
|
|
83
94
|
this.productBuilderService = new products_service_1.default({
|
|
84
95
|
workspace_id,
|
|
85
96
|
public_key,
|
|
86
97
|
user_id,
|
|
87
98
|
token,
|
|
88
99
|
env_type,
|
|
100
|
+
redis_client
|
|
89
101
|
});
|
|
90
102
|
this.inputService = new inputs_service_1.default();
|
|
103
|
+
this.requestTime = 0;
|
|
104
|
+
this.totalRequests = 0;
|
|
91
105
|
this.processingOutput = {
|
|
92
106
|
success: [],
|
|
93
107
|
failure: [],
|
|
@@ -100,6 +114,93 @@ class ProcessorService {
|
|
|
100
114
|
if (redis_client) {
|
|
101
115
|
this.redisClient = redis_client;
|
|
102
116
|
}
|
|
117
|
+
if (queues) {
|
|
118
|
+
this.queues = queues;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async generateSession(payload) {
|
|
122
|
+
try {
|
|
123
|
+
const { product: product_tag, env: slug, tag, data } = payload;
|
|
124
|
+
const input = await this.inputService.parseJson({
|
|
125
|
+
data,
|
|
126
|
+
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
127
|
+
});
|
|
128
|
+
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
129
|
+
// const product = this.productBuilderService.fetchProduct();
|
|
130
|
+
const session = this.productBuilderService.fetchSession(tag);
|
|
131
|
+
if (!session) {
|
|
132
|
+
throw new Error(`Session with tag ${tag} does not exist`);
|
|
133
|
+
}
|
|
134
|
+
const env = this.productBuilderService.fetchEnv(slug);
|
|
135
|
+
if (!env) {
|
|
136
|
+
throw new Error(`Env with slug ${slug} does not exist`);
|
|
137
|
+
}
|
|
138
|
+
await this.inputService.validateInput(input, session.schema_data);
|
|
139
|
+
const stages = (0, string_utils_1.extractStages)(session.selector);
|
|
140
|
+
const user = (0, processor_utils_1.extractSelectorValue)(data, stages, session.selector);
|
|
141
|
+
const expiry = (0, processor_utils_1.calculateJWTExpiry)(session.expiry, session.period);
|
|
142
|
+
const end_at = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
|
|
143
|
+
const JWT = await loadJWT();
|
|
144
|
+
if (JWT) {
|
|
145
|
+
const session_id = (0, uuid_1.v4)();
|
|
146
|
+
const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, this.productBuilderService.fetchProduct().private_key, { expiresIn: expiry });
|
|
147
|
+
const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.productBuilderService.fetchProduct().private_key);
|
|
148
|
+
// WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
|
|
149
|
+
const details = {
|
|
150
|
+
identifier: user,
|
|
151
|
+
start_at: Date.now(),
|
|
152
|
+
end_at,
|
|
153
|
+
session_tag: tag,
|
|
154
|
+
data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), this.productBuilderService.fetchProduct().private_key),
|
|
155
|
+
session_id
|
|
156
|
+
};
|
|
157
|
+
await this.processorApiService.createSessionInfo(Object.assign({ product_tag, env: slug, refreshToken }, details), this.getUserAccess());
|
|
158
|
+
return {
|
|
159
|
+
token,
|
|
160
|
+
refreshToken,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
throw new Error(`Running in browser, token service not loaded.`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
throw e;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async refreshSession(payload) {
|
|
172
|
+
await this.productBuilderService.initializeProductByTag(payload.product);
|
|
173
|
+
// validate token validity
|
|
174
|
+
const { refreshToken } = payload, payloadData = __rest(payload, ["refreshToken"]);
|
|
175
|
+
const valid = await this.processorApiService.validateRefreshToken({ refreshToken, product: payload.product, env: payload.env }, this.getUserAccess());
|
|
176
|
+
if (valid) {
|
|
177
|
+
const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, this.productBuilderService.fetchProduct().private_key));
|
|
178
|
+
return await this.generateSession(Object.assign(Object.assign({}, payloadData), { data }));
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
throw new Error(`Invalid refresh token`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async decryptSession(data) {
|
|
185
|
+
await this.productBuilderService.initializeProductByTag(data.product);
|
|
186
|
+
const JWT = await loadJWT();
|
|
187
|
+
if (!JWT) {
|
|
188
|
+
throw new Error(`Running in browser, token service not loaded.`);
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
const res = await JWT.verify(data.token, this.productBuilderService.fetchProduct().private_key);
|
|
192
|
+
if (res.session !== data.tag) {
|
|
193
|
+
throw new Error(`Invalid token for session ${data.tag}`);
|
|
194
|
+
}
|
|
195
|
+
if (res.env !== data.env) {
|
|
196
|
+
throw new Error(`Invalid session env`);
|
|
197
|
+
}
|
|
198
|
+
return res.data;
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
console.log(e);
|
|
202
|
+
throw new Error("Invalid/Expired token");
|
|
203
|
+
}
|
|
103
204
|
}
|
|
104
205
|
async registerWebhook(data) {
|
|
105
206
|
const { product: product_tag, access_tag, webhook_tag, envs } = data;
|
|
@@ -225,7 +326,6 @@ class ProcessorService {
|
|
|
225
326
|
}
|
|
226
327
|
async processQuota(data) {
|
|
227
328
|
this.start = Date.now();
|
|
228
|
-
this.input = data;
|
|
229
329
|
const { product: product_tag, env, input, tag: quota_tag } = data;
|
|
230
330
|
try {
|
|
231
331
|
this.productTag = product_tag;
|
|
@@ -247,8 +347,10 @@ class ProcessorService {
|
|
|
247
347
|
data: input,
|
|
248
348
|
};
|
|
249
349
|
this.quota = this.fetchQuota(quota_tag, additional_logs);
|
|
350
|
+
if (!this.quota) {
|
|
351
|
+
throw new Error(`Quota ${quota_tag} not found`);
|
|
352
|
+
}
|
|
250
353
|
this.logService.setFeatureId(this.quota._id);
|
|
251
|
-
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
354
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
253
355
|
if (!this.processEnv.active) {
|
|
254
356
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -258,19 +360,99 @@ class ProcessorService {
|
|
|
258
360
|
this.validateJSONFeatureInput(input, quotaInput, additional_logs);
|
|
259
361
|
// split processes
|
|
260
362
|
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
261
|
-
|
|
363
|
+
await this.logService.publish();
|
|
364
|
+
return await this.runQuotaOptions(options, input, additional_logs);
|
|
262
365
|
}
|
|
263
366
|
catch (e) {
|
|
264
367
|
this.end = Date.now();
|
|
265
|
-
this.logService.publish();
|
|
368
|
+
await this.logService.publish();
|
|
266
369
|
throw e;
|
|
267
370
|
}
|
|
268
371
|
}
|
|
269
|
-
async runQuotaOptions(options, additional_logs) {
|
|
270
|
-
|
|
372
|
+
async runQuotaOptions(options, input, additional_logs) {
|
|
373
|
+
try {
|
|
374
|
+
const quotaManager = new quota_service_1.default(options, this.redisClient);
|
|
375
|
+
const getNextProvider = quotaManager.getNextProvider();
|
|
376
|
+
const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
|
|
377
|
+
const result = await this.processEvent({
|
|
378
|
+
app: getNextProvider.app,
|
|
379
|
+
type: getNextProvider.type,
|
|
380
|
+
event: getNextProvider.event,
|
|
381
|
+
input: quotaInput,
|
|
382
|
+
retries: getNextProvider.retries,
|
|
383
|
+
allow_fail: false
|
|
384
|
+
});
|
|
385
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota successful', successful_execution: true, data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
catch (e) {
|
|
389
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota failed', failed_execution: true, data: { e }, status: types_1.LogEventStatus.PROCESSING }));
|
|
390
|
+
throw e;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async mapQuotaFallbackInput(providerInput, quotaInput, app) {
|
|
394
|
+
if (Array.isArray(providerInput)) {
|
|
395
|
+
return providerInput.map(async (item) => await this.mapQuotaFallbackInput(item, quotaInput, app));
|
|
396
|
+
}
|
|
397
|
+
else if (providerInput && typeof providerInput === 'object') {
|
|
398
|
+
const result = {};
|
|
399
|
+
for (const key in providerInput) {
|
|
400
|
+
result[key] = await this.mapQuotaFallbackInput(providerInput[key], quotaInput, app);
|
|
401
|
+
}
|
|
402
|
+
return result;
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
// Base case: primitive value
|
|
406
|
+
return await this.overrideQuotaFallbackInput(providerInput, quotaInput, app);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async overrideQuotaFallbackInput(value, quotaInput, app) {
|
|
410
|
+
if (value.startsWith('$Input{')) {
|
|
411
|
+
return quotaInput[(0, string_utils_1.extractStages)(value)[0]];
|
|
412
|
+
}
|
|
413
|
+
else if (value.startsWith('$Auth')) {
|
|
414
|
+
return await this.generateAuthValue((0, string_utils_1.extractStages)(value), app, [], {});
|
|
415
|
+
}
|
|
416
|
+
else if (value.startsWith('$')) {
|
|
417
|
+
this.input = Object.assign(Object.assign({}, this.input), { input: quotaInput });
|
|
418
|
+
return await this.generateOperatorValues(value, '', {});
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
return value;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async runFallbackOptions(options, input, additional_logs) {
|
|
425
|
+
return await this.executeActionWithFallback(options, input);
|
|
426
|
+
}
|
|
427
|
+
async executeActionWithFallback(providers, input) {
|
|
428
|
+
let index = 0;
|
|
429
|
+
for (const provider of providers) {
|
|
430
|
+
try {
|
|
431
|
+
const payload = {
|
|
432
|
+
app: provider.app,
|
|
433
|
+
type: provider.type,
|
|
434
|
+
event: provider.event,
|
|
435
|
+
input: await this.mapQuotaFallbackInput(provider.input, input, provider.app),
|
|
436
|
+
retries: provider.retries,
|
|
437
|
+
allow_fail: false
|
|
438
|
+
};
|
|
439
|
+
const result = await this.processEvent(payload);
|
|
440
|
+
if (result.status === types_1.LogEventStatus.FAIL) {
|
|
441
|
+
throw new Error(result.errors);
|
|
442
|
+
}
|
|
443
|
+
index++;
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
if (index > 0) {
|
|
447
|
+
throw error;
|
|
448
|
+
}
|
|
449
|
+
console.warn(`${provider.app || provider.event} failed: ${error}`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
//throw new Error("All providers failed.");
|
|
453
|
+
}
|
|
271
454
|
async processFallback(data) {
|
|
272
455
|
this.start = Date.now();
|
|
273
|
-
this.input = data;
|
|
274
456
|
const { product: product_tag, env, input, tag: fallback_tag } = data;
|
|
275
457
|
try {
|
|
276
458
|
this.productTag = product_tag;
|
|
@@ -287,13 +469,15 @@ class ProcessorService {
|
|
|
287
469
|
product_id: this.productId,
|
|
288
470
|
workspace_id: this.workspace_id,
|
|
289
471
|
env,
|
|
290
|
-
type: types_1.LogEventTypes.
|
|
472
|
+
type: types_1.LogEventTypes.FALLBACK,
|
|
291
473
|
process_id,
|
|
292
474
|
data: input,
|
|
293
475
|
};
|
|
294
476
|
this.fallback = this.fetchFallback(fallback_tag, additional_logs);
|
|
295
|
-
|
|
296
|
-
|
|
477
|
+
if (!this.fallback) {
|
|
478
|
+
throw new Error(`Fallback "${fallback_tag}" not found`);
|
|
479
|
+
}
|
|
480
|
+
this.logService.setFeatureId(this.fallback._id);
|
|
297
481
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
298
482
|
if (!this.processEnv.active) {
|
|
299
483
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -303,15 +487,15 @@ class ProcessorService {
|
|
|
303
487
|
this.validateJSONFeatureInput(input, fallbackInput, additional_logs);
|
|
304
488
|
// split processes
|
|
305
489
|
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
306
|
-
return await this.runFallbackOptions(options, additional_logs);
|
|
490
|
+
return await this.runFallbackOptions(options, input, additional_logs);
|
|
307
491
|
}
|
|
308
492
|
catch (e) {
|
|
309
493
|
this.end = Date.now();
|
|
310
|
-
this.logService.publish();
|
|
494
|
+
await this.logService.publish();
|
|
311
495
|
throw e;
|
|
312
496
|
}
|
|
313
497
|
}
|
|
314
|
-
async processFeature(data) {
|
|
498
|
+
async processFeature(data, awaitResolution = false) {
|
|
315
499
|
this.start = Date.now();
|
|
316
500
|
this.input = data;
|
|
317
501
|
const { product: product_tag, env, input, tag: feature_tag } = data;
|
|
@@ -322,12 +506,15 @@ class ProcessorService {
|
|
|
322
506
|
additional_logs = {
|
|
323
507
|
name: 'Process feature',
|
|
324
508
|
type: types_1.LogEventTypes.FEATURE,
|
|
325
|
-
parent_tag: feature_tag,
|
|
326
509
|
};
|
|
327
510
|
await this.intializeProduct(additional_logs);
|
|
328
511
|
this.component = types_1.LogEventTypes.FEATURE;
|
|
329
512
|
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
330
513
|
this.process_id = process_id;
|
|
514
|
+
this.feature = this.fetchFeature(feature_tag, additional_logs);
|
|
515
|
+
if (!this.feature) {
|
|
516
|
+
throw new Error(`Feature "${feature_tag}" not found`);
|
|
517
|
+
}
|
|
331
518
|
this.baseLogs = {
|
|
332
519
|
product_tag: this.productTag,
|
|
333
520
|
product_id: this.productId,
|
|
@@ -336,10 +523,10 @@ class ProcessorService {
|
|
|
336
523
|
type: types_1.LogEventTypes.FEATURE,
|
|
337
524
|
process_id,
|
|
338
525
|
data: input,
|
|
526
|
+
feature_tag: feature_tag,
|
|
527
|
+
feature_id: this.feature._id,
|
|
339
528
|
};
|
|
340
|
-
this.feature = this.fetchFeature(feature_tag, additional_logs);
|
|
341
529
|
this.logService.setFeatureId(this.feature._id);
|
|
342
|
-
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
530
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
344
531
|
if (!this.processEnv.active) {
|
|
345
532
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -348,7 +535,7 @@ class ProcessorService {
|
|
|
348
535
|
// validate feature input and log failure
|
|
349
536
|
this.validateJSONFeatureInput(input, featureInput, additional_logs);
|
|
350
537
|
// split processes
|
|
351
|
-
this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
538
|
+
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
352
539
|
await this.processSequenceLevels(additional_logs);
|
|
353
540
|
return { process_id };
|
|
354
541
|
//return this.generateOutput(output as unknown as Record<string, IFeatureOutput>);
|
|
@@ -357,7 +544,7 @@ class ProcessorService {
|
|
|
357
544
|
this.end = Date.now();
|
|
358
545
|
if (this.logService) {
|
|
359
546
|
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();
|
|
547
|
+
await this.logService.publish();
|
|
361
548
|
if (passedValidation) {
|
|
362
549
|
return { process_id: this.process_id };
|
|
363
550
|
}
|
|
@@ -371,13 +558,7 @@ class ProcessorService {
|
|
|
371
558
|
}
|
|
372
559
|
}
|
|
373
560
|
async intializeProduct(additional_logs) {
|
|
374
|
-
|
|
375
|
-
if (this.productTag) {
|
|
376
|
-
await this.productBuilderService.initializeProductByTag(this.productTag); // validate product_exists
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
await this.productBuilderService.initializeProduct(this.productId);
|
|
380
|
-
}
|
|
561
|
+
if (!this.logService) {
|
|
381
562
|
this.logService = new logs_service_1.default({
|
|
382
563
|
product_id: this.productId,
|
|
383
564
|
workspace_id: this.workspace_id,
|
|
@@ -386,6 +567,14 @@ class ProcessorService {
|
|
|
386
567
|
token: this.token,
|
|
387
568
|
env_type: this.environment,
|
|
388
569
|
});
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
if (this.productTag) {
|
|
573
|
+
await this.productBuilderService.initializeProductByTag(this.productTag); // validate product_exists
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
await this.productBuilderService.initializeProduct(this.productId);
|
|
577
|
+
}
|
|
389
578
|
const { _id: product_id, workspace_id } = this.productBuilderService.fetchProduct();
|
|
390
579
|
this.productId = product_id;
|
|
391
580
|
if (workspace_id !== this.workspace_id) {
|
|
@@ -394,14 +583,12 @@ class ProcessorService {
|
|
|
394
583
|
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
584
|
}
|
|
396
585
|
catch (e) {
|
|
397
|
-
console.log(e);
|
|
398
586
|
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
587
|
throw e;
|
|
400
588
|
}
|
|
401
589
|
}
|
|
402
590
|
fetchFeature(tag, additional_logs) {
|
|
403
591
|
try {
|
|
404
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch feature - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
|
|
405
592
|
const feature = this.productBuilderService.fetchFeature(tag); // validate feature exists
|
|
406
593
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch feature - success', data: { tag, feature }, status: types_1.LogEventStatus.SUCCESS }));
|
|
407
594
|
return feature;
|
|
@@ -413,7 +600,6 @@ class ProcessorService {
|
|
|
413
600
|
}
|
|
414
601
|
fetchQuota(tag, additional_logs) {
|
|
415
602
|
try {
|
|
416
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch quota - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
|
|
417
603
|
const quota = this.productBuilderService.fetchQuota(tag); // validate feature exists
|
|
418
604
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch quota - success', data: { tag, quota }, status: types_1.LogEventStatus.SUCCESS }));
|
|
419
605
|
return quota;
|
|
@@ -425,7 +611,6 @@ class ProcessorService {
|
|
|
425
611
|
}
|
|
426
612
|
fetchFallback(tag, additional_logs) {
|
|
427
613
|
try {
|
|
428
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch fallback - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
|
|
429
614
|
const fallback = this.productBuilderService.fetchFallback(tag); // validate feature exists
|
|
430
615
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch fallback - success', data: { tag, fallback }, status: types_1.LogEventStatus.SUCCESS }));
|
|
431
616
|
return fallback;
|
|
@@ -437,7 +622,6 @@ class ProcessorService {
|
|
|
437
622
|
}
|
|
438
623
|
fetchEnv(env, additional_logs) {
|
|
439
624
|
try {
|
|
440
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch environment - initiated', data: { slug: env }, status: types_1.LogEventStatus.PROCESSING }));
|
|
441
625
|
const product_env = this.productBuilderService.fetchEnv(env); // validate env exists
|
|
442
626
|
if (!product_env) {
|
|
443
627
|
throw new Error(`Env ${env} not found`);
|
|
@@ -452,7 +636,6 @@ class ProcessorService {
|
|
|
452
636
|
}
|
|
453
637
|
validateJSONFeatureInput(input, feature_input, additional_logs) {
|
|
454
638
|
try {
|
|
455
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - initiated', data: { input: (0, processor_utils_1.anonymizeObject)(input), feature_input }, status: types_1.LogEventStatus.PROCESSING }));
|
|
456
639
|
(0, processor_utils_1.validateFeatureJSONInput)(input, feature_input);
|
|
457
640
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
458
641
|
}
|
|
@@ -461,9 +644,8 @@ class ProcessorService {
|
|
|
461
644
|
throw e;
|
|
462
645
|
}
|
|
463
646
|
}
|
|
464
|
-
splitSequenceIntoLevels(data, additional_logs) {
|
|
647
|
+
async splitSequenceIntoLevels(data, additional_logs) {
|
|
465
648
|
try {
|
|
466
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
467
649
|
const levels = {};
|
|
468
650
|
const tagMap = new Map(data.map((seq) => [seq.tag, seq]));
|
|
469
651
|
const assignedLevels = new Map();
|
|
@@ -500,10 +682,9 @@ class ProcessorService {
|
|
|
500
682
|
}
|
|
501
683
|
async processSequenceLevels(additional_logs) {
|
|
502
684
|
try {
|
|
503
|
-
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
685
|
const levelEvents = {};
|
|
505
686
|
Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
|
|
506
|
-
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences);
|
|
687
|
+
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
|
|
507
688
|
});
|
|
508
689
|
let previousLevelComplete = true;
|
|
509
690
|
for (const level of Object.keys(levelEvents)
|
|
@@ -516,58 +697,93 @@ class ProcessorService {
|
|
|
516
697
|
break;
|
|
517
698
|
}
|
|
518
699
|
}
|
|
519
|
-
|
|
520
|
-
|
|
700
|
+
this.doneWithProcessing = true;
|
|
701
|
+
if (previousLevelComplete && !this.published) {
|
|
702
|
+
let message;
|
|
703
|
+
let status;
|
|
704
|
+
let successful_feature_execution;
|
|
705
|
+
let failed_feature_execution;
|
|
706
|
+
if (this.processingOutput.failure.length === 0) {
|
|
707
|
+
message = 'Process feature - success';
|
|
708
|
+
status = types_1.LogEventStatus.SUCCESS;
|
|
709
|
+
successful_feature_execution = true;
|
|
710
|
+
}
|
|
711
|
+
else if (this.processingFailure) {
|
|
712
|
+
message = 'Process feature - processing';
|
|
713
|
+
status = types_1.LogEventStatus.PROCESSING;
|
|
714
|
+
successful_feature_execution = false;
|
|
715
|
+
failed_feature_execution = false;
|
|
716
|
+
}
|
|
717
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_feature_execution,
|
|
718
|
+
failed_feature_execution,
|
|
719
|
+
message, data: {}, status }));
|
|
720
|
+
await this.logService.publish();
|
|
521
721
|
this.end = Date.now();
|
|
522
|
-
this.writeResult(
|
|
722
|
+
await this.writeResult(status);
|
|
523
723
|
}
|
|
724
|
+
return true;
|
|
524
725
|
}
|
|
525
726
|
catch (e) {
|
|
526
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process levels - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
727
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process sequence levels - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
527
728
|
throw e;
|
|
528
729
|
}
|
|
529
730
|
}
|
|
530
731
|
async processLevelEvents(events, additional_logs) {
|
|
531
|
-
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
732
|
+
try {
|
|
733
|
+
const promises = events.map((event) => {
|
|
734
|
+
const dependants = this.fetchActionRequestDependents(event.input, additional_logs);
|
|
735
|
+
const passed = this.checkDependentsSuccess(dependants);
|
|
736
|
+
if (passed) {
|
|
737
|
+
// TODO: comparison to see if all depending events are in success || dependants is empty
|
|
738
|
+
return this.processEvent(event);
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
this.addToWaitingOutput(event, dependants);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
return Promise.all(promises);
|
|
745
|
+
}
|
|
746
|
+
catch (e) {
|
|
747
|
+
throw e;
|
|
748
|
+
}
|
|
542
749
|
}
|
|
543
750
|
async processFailedEvents(additional_logs) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
751
|
+
try {
|
|
752
|
+
const { failure } = this.processingOutput;
|
|
753
|
+
const promises = failure.map((failed) => {
|
|
754
|
+
if (failed.retries_left > 0 && new Date().getTime() > failed.retry_at) {
|
|
755
|
+
return this.processEvent(failed.event); // process events should also take care of this.processingOutput
|
|
756
|
+
}
|
|
757
|
+
if (failed.retries_left === 0 && !failed.allow_fail) {
|
|
758
|
+
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 }));
|
|
759
|
+
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`);
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
Promise.all(promises);
|
|
763
|
+
}
|
|
764
|
+
catch (e) {
|
|
765
|
+
throw e;
|
|
766
|
+
}
|
|
556
767
|
}
|
|
557
768
|
async processWaitingEvents(additional_logs) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
769
|
+
try {
|
|
770
|
+
const { waiting } = this.processingOutput;
|
|
771
|
+
const promises = waiting.map((waiting) => {
|
|
772
|
+
const { dependants } = waiting;
|
|
773
|
+
if (this.checkDependentsSuccess(dependants)) {
|
|
774
|
+
// TODO: comparison to see if all depending events are in success || dependants is empty
|
|
775
|
+
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 }));
|
|
776
|
+
return this.processEvent(waiting.event);
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
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 }));
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
return Promise.all(promises);
|
|
783
|
+
}
|
|
784
|
+
catch (e) {
|
|
785
|
+
throw e;
|
|
786
|
+
}
|
|
571
787
|
}
|
|
572
788
|
checkDependentsSuccess(dependants) {
|
|
573
789
|
let pass = true;
|
|
@@ -580,7 +796,6 @@ class ProcessorService {
|
|
|
580
796
|
}
|
|
581
797
|
fetchActionRequestDependents(input, additional_logs) {
|
|
582
798
|
try {
|
|
583
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch request dependencies - initialized', data: input, status: types_1.LogEventStatus.PROCESSING }));
|
|
584
799
|
const dependents = [];
|
|
585
800
|
if (input.query) {
|
|
586
801
|
dependents.push(...this.fetchDependents(input.query, additional_logs));
|
|
@@ -597,6 +812,12 @@ class ProcessorService {
|
|
|
597
812
|
if (input.data) {
|
|
598
813
|
dependents.push(...this.fetchDependents(input.data, additional_logs));
|
|
599
814
|
}
|
|
815
|
+
if (input.fileName) {
|
|
816
|
+
dependents.push(...this.valueStringDepsCheck(input.fileName));
|
|
817
|
+
}
|
|
818
|
+
if (input.buffer) {
|
|
819
|
+
dependents.push(...this.valueStringDepsCheck(input.buffer));
|
|
820
|
+
}
|
|
600
821
|
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
822
|
return dependents;
|
|
602
823
|
}
|
|
@@ -606,7 +827,6 @@ class ProcessorService {
|
|
|
606
827
|
}
|
|
607
828
|
fetchDependents(obj, additional_logs) {
|
|
608
829
|
try {
|
|
609
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch dependents - initiated', data: obj, status: types_1.LogEventStatus.PROCESSING }));
|
|
610
830
|
const dependants = [];
|
|
611
831
|
for (const key in obj) {
|
|
612
832
|
const value = obj[key];
|
|
@@ -621,6 +841,20 @@ class ProcessorService {
|
|
|
621
841
|
event_tag: stages[1],
|
|
622
842
|
});
|
|
623
843
|
}
|
|
844
|
+
else if (values[i].startsWith('$')) {
|
|
845
|
+
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(values[i]);
|
|
846
|
+
if (funcArgs.args.length) {
|
|
847
|
+
funcArgs.args.map((arg) => {
|
|
848
|
+
if (arg.startsWith('$Sequence')) {
|
|
849
|
+
const stages = this.productBuilderService.extractStages(arg);
|
|
850
|
+
dependants.push({
|
|
851
|
+
sequence_tag: stages[0],
|
|
852
|
+
event_tag: stages[1],
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
}
|
|
624
858
|
}
|
|
625
859
|
}
|
|
626
860
|
else {
|
|
@@ -628,22 +862,45 @@ class ProcessorService {
|
|
|
628
862
|
}
|
|
629
863
|
}
|
|
630
864
|
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
|
-
}
|
|
865
|
+
dependants.push(...this.valueStringDepsCheck(value.trim()));
|
|
635
866
|
}
|
|
636
867
|
}
|
|
637
868
|
return dependants;
|
|
638
869
|
}
|
|
639
870
|
catch (e) {
|
|
640
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch dependents - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
641
871
|
throw e;
|
|
642
872
|
}
|
|
643
873
|
}
|
|
874
|
+
valueStringDepsCheck(value) {
|
|
875
|
+
const dependants = [];
|
|
876
|
+
if (value.startsWith('$Sequence')) {
|
|
877
|
+
const stages = this.productBuilderService.extractStages(value);
|
|
878
|
+
dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
|
|
879
|
+
}
|
|
880
|
+
else if (value.startsWith('$')) {
|
|
881
|
+
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(value);
|
|
882
|
+
if (funcArgs && funcArgs.args.length) {
|
|
883
|
+
funcArgs.args.map((arg) => {
|
|
884
|
+
if (arg.startsWith('$Sequence')) {
|
|
885
|
+
const stages = this.productBuilderService.extractStages(arg);
|
|
886
|
+
dependants.push({
|
|
887
|
+
sequence_tag: stages[0],
|
|
888
|
+
event_tag: stages[1],
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
else {
|
|
892
|
+
const args = arg.split(',');
|
|
893
|
+
args.map((arg) => {
|
|
894
|
+
dependants.push(...this.valueStringDepsCheck(arg.trim()));
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return dependants;
|
|
901
|
+
}
|
|
644
902
|
async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
|
|
645
903
|
try {
|
|
646
|
-
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 }));
|
|
647
904
|
const payload = {};
|
|
648
905
|
const { body: actionBody, query: actionQuery, headers: actionHeaders, params: actionParams } = object;
|
|
649
906
|
if (actionBody) {
|
|
@@ -700,7 +957,6 @@ class ProcessorService {
|
|
|
700
957
|
}
|
|
701
958
|
async generatePayload(obj, event, additional_logs, sample = [], index = {}, loopIndex = null) {
|
|
702
959
|
try {
|
|
703
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate payload - initiated', data: { obj, event, sample }, status: types_1.LogEventStatus.PROCESSING }));
|
|
704
960
|
const payload = {};
|
|
705
961
|
const keys = Object.keys(obj);
|
|
706
962
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -797,7 +1053,7 @@ class ProcessorService {
|
|
|
797
1053
|
return await this.sumValues(value, app, additional_logs, sample, index, key, loopIndex);
|
|
798
1054
|
}
|
|
799
1055
|
else if (value.startsWith('$Substract(') && value.endsWith(')')) {
|
|
800
|
-
return await this.
|
|
1056
|
+
return await this.subtractValues(value, app, additional_logs, sample, index, key, loopIndex);
|
|
801
1057
|
}
|
|
802
1058
|
else if (value.startsWith('$Pick(') && value.endsWith(')')) {
|
|
803
1059
|
return await this.pickValue(value, app, additional_logs, sample, index, key, loopIndex);
|
|
@@ -1189,7 +1445,7 @@ class ProcessorService {
|
|
|
1189
1445
|
}
|
|
1190
1446
|
}
|
|
1191
1447
|
decorateValue(value, sample) {
|
|
1192
|
-
if (sample.decorator) {
|
|
1448
|
+
if (sample && sample.decorator) {
|
|
1193
1449
|
if (sample.decoratorPosition &&
|
|
1194
1450
|
sample.decoratorPosition == types_1.DecoratorPostions.APPEND &&
|
|
1195
1451
|
!value.endsWith(sample.decorator)) {
|
|
@@ -1220,7 +1476,6 @@ class ProcessorService {
|
|
|
1220
1476
|
}
|
|
1221
1477
|
async fetchAuthData(app_tag, additional_logs) {
|
|
1222
1478
|
try {
|
|
1223
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching auth data - initiated', data: { app_tag, env: this.processEnv.slug }, status: types_1.LogEventStatus.PROCESSING }));
|
|
1224
1479
|
const app = this.productBuilderService.fetchApp(app_tag);
|
|
1225
1480
|
if (!app) {
|
|
1226
1481
|
throw new Error(`App ${app_tag} not found in $Auth value`);
|
|
@@ -1286,7 +1541,7 @@ class ProcessorService {
|
|
|
1286
1541
|
}*/
|
|
1287
1542
|
if (event.type === types_1.FeatureEventTypes.ACTION) {
|
|
1288
1543
|
const additional_logs = {
|
|
1289
|
-
parent_tag:
|
|
1544
|
+
parent_tag: event.app,
|
|
1290
1545
|
child_tag: event.event,
|
|
1291
1546
|
type: types_1.LogEventTypes.ACTION,
|
|
1292
1547
|
name: 'Process feature action',
|
|
@@ -1314,8 +1569,12 @@ class ProcessorService {
|
|
|
1314
1569
|
return this.runStorage(event, additional_logs);
|
|
1315
1570
|
}
|
|
1316
1571
|
if (event.type === types_1.FeatureEventTypes.FEATURE) {
|
|
1317
|
-
|
|
1318
|
-
|
|
1572
|
+
const additional_logs = {
|
|
1573
|
+
parent_tag: event.event,
|
|
1574
|
+
type: types_1.LogEventTypes.FEATURE,
|
|
1575
|
+
name: 'Process sub-feature',
|
|
1576
|
+
};
|
|
1577
|
+
return this.runFeature(event, additional_logs);
|
|
1319
1578
|
}
|
|
1320
1579
|
if (event.type === types_1.FeatureEventTypes.NOTIFICATION) {
|
|
1321
1580
|
const [parent_tag, child_tag] = event.event.split(':');
|
|
@@ -1336,11 +1595,9 @@ class ProcessorService {
|
|
|
1336
1595
|
name: 'Process feature broker event',
|
|
1337
1596
|
};
|
|
1338
1597
|
try {
|
|
1339
|
-
console.log("GRENADYE ALASOOOO!");
|
|
1340
1598
|
return this.runBrokerPublish(event, additional_logs);
|
|
1341
1599
|
}
|
|
1342
1600
|
catch (e) {
|
|
1343
|
-
console.log("GRENADYE ALASOOOO!!!!");
|
|
1344
1601
|
}
|
|
1345
1602
|
}
|
|
1346
1603
|
if (event.type === types_1.FeatureEventTypes.JOB) {
|
|
@@ -1349,30 +1606,70 @@ class ProcessorService {
|
|
|
1349
1606
|
parent_tag: event.event,
|
|
1350
1607
|
name: 'Process feature job',
|
|
1351
1608
|
};
|
|
1352
|
-
|
|
1609
|
+
const input = {
|
|
1610
|
+
env: event.env.slug,
|
|
1611
|
+
product: this.productTag,
|
|
1612
|
+
event: event.event,
|
|
1613
|
+
retries: event.retries,
|
|
1614
|
+
input: event.input,
|
|
1615
|
+
start_at: event.start_at || 0,
|
|
1616
|
+
cache: event.cache,
|
|
1617
|
+
session: this.input.session
|
|
1618
|
+
};
|
|
1619
|
+
// TODO: fix this
|
|
1620
|
+
return this.processJob(input, additional_logs);
|
|
1353
1621
|
}
|
|
1354
1622
|
}
|
|
1355
1623
|
catch (e) {
|
|
1356
1624
|
throw e;
|
|
1357
1625
|
}
|
|
1358
1626
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1627
|
+
async runFeature(event, additional_logs) {
|
|
1628
|
+
const freshInstance = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
1629
|
+
const result = await freshInstance.processFeature({
|
|
1630
|
+
product: this.productTag,
|
|
1631
|
+
tag: event.event,
|
|
1632
|
+
env: this.processEnv.slug,
|
|
1633
|
+
input: event.input,
|
|
1634
|
+
}, true);
|
|
1635
|
+
const output = await freshInstance.generateOutput(result.process_id);
|
|
1636
|
+
if (output.status === types_1.LogEventStatus.FAIL) {
|
|
1637
|
+
await this.addToFailureOutput(output.errors, event, { process_id: result.process_id }, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
|
|
1638
|
+
}
|
|
1639
|
+
else if (output.status === types_1.LogEventStatus.SUCCESS) {
|
|
1640
|
+
await this.addToSuccessOutput(event, output.data, Object.assign(Object.assign({}, additional_logs), { process_id: result.process_id }));
|
|
1641
|
+
}
|
|
1642
|
+
return output;
|
|
1643
|
+
}
|
|
1644
|
+
async runJobs(job, additional_logs = {}) {
|
|
1645
|
+
if (job.name === types_1.FeatureEventTypes.ACTION) {
|
|
1646
|
+
await this.processAction(job.data);
|
|
1647
|
+
}
|
|
1361
1648
|
}
|
|
1362
1649
|
async processFailedAndWaiting() { }
|
|
1363
|
-
async
|
|
1364
|
-
|
|
1365
|
-
const result = (await this.processorApiService.fetchResult(process_id, this.getUserAccess()));
|
|
1650
|
+
async fetchResult(process_id) {
|
|
1651
|
+
const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
|
|
1366
1652
|
if (!result) {
|
|
1367
1653
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1368
1654
|
}
|
|
1655
|
+
await this.productBuilderService.initializeProduct(result.product_id);
|
|
1656
|
+
result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchProduct().private_key));
|
|
1657
|
+
result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchProduct().private_key));
|
|
1658
|
+
return result;
|
|
1659
|
+
}
|
|
1660
|
+
async generateOutput(process_id) {
|
|
1661
|
+
var _a, _b, _c, _d;
|
|
1662
|
+
const result = await this.fetchResult(process_id);
|
|
1369
1663
|
if (result.component === types_1.LogEventTypes.FEATURE) {
|
|
1370
1664
|
const additional_logs = {
|
|
1371
1665
|
parent_tag: result.input.tag,
|
|
1372
1666
|
type: types_1.LogEventTypes.FEATURE,
|
|
1373
1667
|
name: 'Fetching Process Result',
|
|
1374
1668
|
};
|
|
1375
|
-
if (result.status === types_1.LogEventStatus.
|
|
1669
|
+
if (result.status === types_1.LogEventStatus.PROCESSING) {
|
|
1670
|
+
return { process_id, status: result.status };
|
|
1671
|
+
}
|
|
1672
|
+
else if (result.status === types_1.LogEventStatus.SUCCESS) {
|
|
1376
1673
|
this.productTag = result.input.product;
|
|
1377
1674
|
await this.intializeProduct(additional_logs);
|
|
1378
1675
|
this.processingOutput = result.result;
|
|
@@ -1388,7 +1685,7 @@ class ProcessorService {
|
|
|
1388
1685
|
return { process_id, status: result.status, errors };
|
|
1389
1686
|
}
|
|
1390
1687
|
}
|
|
1391
|
-
else {
|
|
1688
|
+
else if (result) {
|
|
1392
1689
|
if ((_a = result.result.success[0]) === null || _a === void 0 ? void 0 : _a.output) {
|
|
1393
1690
|
return { process_id, status: result.status, data: (_b = result.result.success[0]) === null || _b === void 0 ? void 0 : _b.output };
|
|
1394
1691
|
}
|
|
@@ -1401,7 +1698,7 @@ class ProcessorService {
|
|
|
1401
1698
|
}
|
|
1402
1699
|
}
|
|
1403
1700
|
async resumeProcess(process_id) {
|
|
1404
|
-
const result =
|
|
1701
|
+
const result = await this.fetchResult(process_id);
|
|
1405
1702
|
if (!result) {
|
|
1406
1703
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1407
1704
|
}
|
|
@@ -1428,7 +1725,7 @@ class ProcessorService {
|
|
|
1428
1725
|
// validate feature input and log failure
|
|
1429
1726
|
this.validateJSONFeatureInput(result.input.input, featureInput, additional_logs);
|
|
1430
1727
|
// split processes
|
|
1431
|
-
this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1728
|
+
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1432
1729
|
await this.processSequenceLevels(additional_logs);
|
|
1433
1730
|
}
|
|
1434
1731
|
else {
|
|
@@ -1437,13 +1734,13 @@ class ProcessorService {
|
|
|
1437
1734
|
if (this.processingOutput.failure.length > 0) {
|
|
1438
1735
|
status = types_1.LogEventStatus.FAIL;
|
|
1439
1736
|
}
|
|
1440
|
-
this.writeResult(status);
|
|
1737
|
+
await this.writeResult(status);
|
|
1441
1738
|
}
|
|
1442
1739
|
return { process_id };
|
|
1443
1740
|
}
|
|
1444
1741
|
async replayProcess(process_id) {
|
|
1445
1742
|
var _a, _b, _c;
|
|
1446
|
-
const result =
|
|
1743
|
+
const result = await this.fetchResult(process_id);
|
|
1447
1744
|
if (!result) {
|
|
1448
1745
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1449
1746
|
}
|
|
@@ -1470,7 +1767,7 @@ class ProcessorService {
|
|
|
1470
1767
|
// validate feature input and log failure
|
|
1471
1768
|
this.validateJSONFeatureInput(result.input.input, featureInput, additional_logs);
|
|
1472
1769
|
// split processes
|
|
1473
|
-
this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1770
|
+
this.sequenceLevels = await this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
1474
1771
|
await this.processSequenceLevels(additional_logs);
|
|
1475
1772
|
}
|
|
1476
1773
|
else {
|
|
@@ -1482,20 +1779,20 @@ class ProcessorService {
|
|
|
1482
1779
|
this.start = Date.now();
|
|
1483
1780
|
await this.processEvent(event);
|
|
1484
1781
|
this.end = Date.now();
|
|
1485
|
-
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
1486
|
-
this.logService.publish();
|
|
1782
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
1783
|
+
await this.logService.publish();
|
|
1487
1784
|
}
|
|
1488
1785
|
return { process_id };
|
|
1489
1786
|
}
|
|
1490
|
-
fetchLevelEvents(level) {
|
|
1787
|
+
fetchLevelEvents(sequence, level) {
|
|
1491
1788
|
const events = [];
|
|
1492
|
-
for (let i = 0; i <
|
|
1493
|
-
events.push(...this.appendSequenceDataToLevelEvents(
|
|
1789
|
+
for (let i = 0; i < sequence.length; i++) {
|
|
1790
|
+
events.push(...this.appendSequenceDataToLevelEvents(sequence[i], level));
|
|
1494
1791
|
}
|
|
1495
1792
|
return events;
|
|
1496
1793
|
}
|
|
1497
|
-
appendSequenceDataToLevelEvents(sequence) {
|
|
1498
|
-
const { events,
|
|
1794
|
+
appendSequenceDataToLevelEvents(sequence, level) {
|
|
1795
|
+
const { events, tag } = sequence;
|
|
1499
1796
|
for (let i = 0; i < events.length; i++) {
|
|
1500
1797
|
events[i].sequence_level = level;
|
|
1501
1798
|
events[i].sequence_tag = tag;
|
|
@@ -1571,7 +1868,6 @@ class ProcessorService {
|
|
|
1571
1868
|
}
|
|
1572
1869
|
async processConditionalCheck(event, additional_logs = {}) {
|
|
1573
1870
|
const parts = (0, string_utils_1.extractConditionalParts)(event.condition.check);
|
|
1574
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Check conditional - initiated', data: { condition: event.condition, parts }, status: types_1.LogEventStatus.PROCESSING, action: event.event }));
|
|
1575
1871
|
const [, initiator, operator, value] = parts;
|
|
1576
1872
|
const initiatorValue = await this.generateStringValues(initiator, event.app, additional_logs);
|
|
1577
1873
|
let valueValue;
|
|
@@ -1583,7 +1879,6 @@ class ProcessorService {
|
|
|
1583
1879
|
else {
|
|
1584
1880
|
valueValue = value;
|
|
1585
1881
|
}
|
|
1586
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate check conditional - initiated', data: { condition: { initiatorValue, operator, valueValue } }, status: types_1.LogEventStatus.PROCESSING, action: event.event }));
|
|
1587
1882
|
const pass = (0, processor_utils_1.compareValues)(initiatorValue, operator, valueValue);
|
|
1588
1883
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate check condition - success', data: { condition: { initiatorValue, operator, valueValue }, pass }, status: types_1.LogEventStatus.SUCCESS, action: event.event }));
|
|
1589
1884
|
if (!pass) {
|
|
@@ -1608,7 +1903,6 @@ class ProcessorService {
|
|
|
1608
1903
|
}
|
|
1609
1904
|
async extractLoopIndexes(event, additional_logs = {}) {
|
|
1610
1905
|
const parts = (0, string_utils_1.extractConditionalParts)(event.condition.check);
|
|
1611
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Loop conditional - initiated', data: { condition: event.condition, parts }, status: types_1.LogEventStatus.PROCESSING, action: event.event }));
|
|
1612
1906
|
const [, initiator, operator, value] = parts;
|
|
1613
1907
|
let valueValue;
|
|
1614
1908
|
if (!(0, string_utils_1.isNumeric)(value)) {
|
|
@@ -1624,15 +1918,13 @@ class ProcessorService {
|
|
|
1624
1918
|
// generate indexes
|
|
1625
1919
|
return (0, processor_utils_1.generateIndexes)(operator, iter, init, valueValue);
|
|
1626
1920
|
}
|
|
1627
|
-
async runAction(event, additional_logs, returnValue =
|
|
1921
|
+
async runAction(event, additional_logs, returnValue = true) {
|
|
1628
1922
|
try {
|
|
1629
|
-
console.log("RUNNING ACTION!!!!!");
|
|
1630
1923
|
const { event: action_tag, app: access_tag, condition, cache: cache_tag } = event;
|
|
1631
1924
|
let indexes = [];
|
|
1632
1925
|
if (condition &&
|
|
1633
1926
|
condition.type === types_1.Conditions.CHECK &&
|
|
1634
1927
|
(await this.processConditionalCheck(event, additional_logs))) {
|
|
1635
|
-
console.log("RUNNING ACTION SKIPPED!!!!!");
|
|
1636
1928
|
// if it fails, it would add to skipped queue
|
|
1637
1929
|
return;
|
|
1638
1930
|
}
|
|
@@ -1681,18 +1973,21 @@ class ProcessorService {
|
|
|
1681
1973
|
input: inputString,
|
|
1682
1974
|
privateKey: product.private_key,
|
|
1683
1975
|
expiry: productCache.expiry,
|
|
1684
|
-
});
|
|
1976
|
+
}, additional_logs);
|
|
1685
1977
|
if (check) {
|
|
1686
1978
|
result = JSON.parse(check);
|
|
1687
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run action -
|
|
1979
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run action - response from cache', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS, cache_tag, action: event.event }));
|
|
1688
1980
|
if (returnValue) {
|
|
1689
1981
|
return result;
|
|
1690
1982
|
}
|
|
1691
1983
|
}
|
|
1692
1984
|
}
|
|
1693
|
-
if (request_type === types_1.DataFormats.JSON || !request_type) {
|
|
1985
|
+
if (request_type === types_1.DataFormats.JSON || request_type === types_1.DataFormats.URLENCODED || !request_type) {
|
|
1694
1986
|
if (indexes.length == 0) {
|
|
1695
1987
|
payloads = await this.constructJSONDataPayloads(event.input, additional_logs, samples, event);
|
|
1988
|
+
if (request_type === types_1.DataFormats.URLENCODED) {
|
|
1989
|
+
payloads.body = (0, processor_utils_1.toFormUrlEncoded)(payloads.body);
|
|
1990
|
+
}
|
|
1696
1991
|
additional_logs.recipient_workspace_id = recipient_workspace_id;
|
|
1697
1992
|
result = await this.processRequest({ request_base_url, resource, method, env, payloads, app_id: app._id }, event, retries, additional_logs, returnValue);
|
|
1698
1993
|
}
|
|
@@ -1720,24 +2015,26 @@ class ProcessorService {
|
|
|
1720
2015
|
component_tag: action_tag,
|
|
1721
2016
|
component_type: types_1.ProductComponents.ACTION,
|
|
1722
2017
|
product_tag: this.productTag,
|
|
1723
|
-
});
|
|
1724
|
-
}
|
|
1725
|
-
if (result && returnValue) {
|
|
1726
|
-
return result;
|
|
2018
|
+
}, additional_logs);
|
|
1727
2019
|
}
|
|
2020
|
+
return result;
|
|
1728
2021
|
}
|
|
1729
2022
|
catch (e) {
|
|
1730
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), {
|
|
2023
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run Action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
1731
2024
|
throw e;
|
|
1732
2025
|
}
|
|
1733
2026
|
}
|
|
1734
2027
|
async processRequest(payload, event, retries, additional_logs, returnValue = false) {
|
|
1735
2028
|
const { request_base_url, resource, payloads, method, env, app_id } = payload;
|
|
1736
|
-
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
2029
|
const start = Date.now();
|
|
1738
2030
|
try {
|
|
1739
|
-
|
|
2031
|
+
let results = (0, processor_utils_1.generateMockData)(resource, env.slug, payloads);
|
|
2032
|
+
if (!results) {
|
|
2033
|
+
results = await this.sendActionRequest(request_base_url, resource, payloads, method, env.slug);
|
|
2034
|
+
}
|
|
1740
2035
|
const end = Date.now();
|
|
2036
|
+
this.requestTime += end - start;
|
|
2037
|
+
this.totalRequests += 1;
|
|
1741
2038
|
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
2039
|
end }));
|
|
1743
2040
|
await this.addToSuccessOutput(event, results, additional_logs);
|
|
@@ -1750,10 +2047,17 @@ class ProcessorService {
|
|
|
1750
2047
|
}
|
|
1751
2048
|
catch (e) {
|
|
1752
2049
|
const end = Date.now();
|
|
1753
|
-
|
|
2050
|
+
let error = e;
|
|
2051
|
+
if (e.response.data) {
|
|
2052
|
+
error = e.response.data;
|
|
2053
|
+
}
|
|
2054
|
+
this.requestTime += end - start;
|
|
2055
|
+
this.totalRequests += 1;
|
|
2056
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - failed', failed_execution: true, data: { e: error, input: (0, processor_utils_1.anonymizeObject)(payloads) }, status: types_1.LogEventStatus.FAIL, app_id, action: event.event, start,
|
|
1754
2057
|
end }));
|
|
1755
2058
|
try {
|
|
1756
|
-
|
|
2059
|
+
console.log(e);
|
|
2060
|
+
const value = await this.addToFailureOutput(e, event, {
|
|
1757
2061
|
request_base_url,
|
|
1758
2062
|
resource,
|
|
1759
2063
|
method,
|
|
@@ -1761,6 +2065,9 @@ class ProcessorService {
|
|
|
1761
2065
|
payloads,
|
|
1762
2066
|
app_id,
|
|
1763
2067
|
}, additional_logs, retries);
|
|
2068
|
+
if (value) {
|
|
2069
|
+
return value;
|
|
2070
|
+
}
|
|
1764
2071
|
//if (returnValue) {
|
|
1765
2072
|
return {
|
|
1766
2073
|
process_id: this.process_id,
|
|
@@ -1779,8 +2086,29 @@ class ProcessorService {
|
|
|
1779
2086
|
this.processingOutput.failure = this.processingOutput.failure.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
1780
2087
|
this.processingOutput.skipped = this.processingOutput.skipped.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
1781
2088
|
this.processingOutput.waiting = this.processingOutput.waiting.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2089
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2090
|
+
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2091
|
+
}
|
|
1782
2092
|
this.processingOutput.success.push({ event, output });
|
|
1783
2093
|
await this.processWaitingEvents(additional_logs);
|
|
2094
|
+
if (this.checkIsSuccessful() && this.doneWithProcessing) {
|
|
2095
|
+
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 }));
|
|
2096
|
+
await this.logService.publish();
|
|
2097
|
+
this.end = Date.now();
|
|
2098
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
checkIsSuccessful() {
|
|
2102
|
+
let success = true;
|
|
2103
|
+
this.processingOutput.failure.find((output) => {
|
|
2104
|
+
if (!output.allow_fail) {
|
|
2105
|
+
success = false;
|
|
2106
|
+
}
|
|
2107
|
+
});
|
|
2108
|
+
if (this.processingOutput.waiting.length > 0) {
|
|
2109
|
+
success = false;
|
|
2110
|
+
}
|
|
2111
|
+
return success;
|
|
1784
2112
|
}
|
|
1785
2113
|
addToWaitingOutput(event, dependants) {
|
|
1786
2114
|
const exists = this.processingOutput.waiting.findIndex((item) => {
|
|
@@ -1794,8 +2122,9 @@ class ProcessorService {
|
|
|
1794
2122
|
}
|
|
1795
2123
|
// addToSkippedOutput()
|
|
1796
2124
|
}
|
|
1797
|
-
addToFailureOutput(e, event, payload, additional_logs, policy = {}) {
|
|
2125
|
+
async addToFailureOutput(e, event, payload, additional_logs, policy = {}) {
|
|
1798
2126
|
try {
|
|
2127
|
+
this.processingFailure = true;
|
|
1799
2128
|
const exists = this.processingOutput.failure.findIndex((item) => {
|
|
1800
2129
|
if (item.event.sequence_tag) {
|
|
1801
2130
|
return item.event.event === event.event && item.event.sequence_tag === event.sequence_tag;
|
|
@@ -1814,6 +2143,12 @@ class ProcessorService {
|
|
|
1814
2143
|
max = metrices.max;
|
|
1815
2144
|
}
|
|
1816
2145
|
const { allow_fail, retries } = event;
|
|
2146
|
+
let retryable = true;
|
|
2147
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2148
|
+
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2149
|
+
if (!this.feature || (this.feature && !event.allow_fail))
|
|
2150
|
+
retryable = false;
|
|
2151
|
+
}
|
|
1817
2152
|
let retries_left = retries || max;
|
|
1818
2153
|
if (exists > -1) {
|
|
1819
2154
|
retries_left = this.processingOutput.failure[exists].retries_left - 1;
|
|
@@ -1853,11 +2188,16 @@ class ProcessorService {
|
|
|
1853
2188
|
}, retry_at);
|
|
1854
2189
|
}
|
|
1855
2190
|
if (allow_fail === false && retries_left === 0) {
|
|
2191
|
+
this.published = true;
|
|
2192
|
+
if (this.feature) {
|
|
2193
|
+
additional_logs.failed_feature_execution = true;
|
|
2194
|
+
}
|
|
1856
2195
|
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
2196
|
//throw new Error("Run out of retries")
|
|
1858
2197
|
this.end = Date.now();
|
|
1859
|
-
this.writeResult(types_1.LogEventStatus.FAIL);
|
|
1860
|
-
this.logService.publish();
|
|
2198
|
+
await this.writeResult(types_1.LogEventStatus.FAIL, retryable);
|
|
2199
|
+
await this.logService.publish();
|
|
2200
|
+
//throw new Error("Terminate Process")
|
|
1861
2201
|
}
|
|
1862
2202
|
return output;
|
|
1863
2203
|
}
|
|
@@ -1866,52 +2206,15 @@ class ProcessorService {
|
|
|
1866
2206
|
}
|
|
1867
2207
|
}
|
|
1868
2208
|
generateRetryMetrices(error_code, retries) {
|
|
1869
|
-
var _a
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
case '502':
|
|
1879
|
-
allow_fail = ((_c = retries === null || retries === void 0 ? void 0 : retries.policy[502]) === null || _c === void 0 ? void 0 : _c.available) || false;
|
|
1880
|
-
retry_at = ((_d = retries === null || retries === void 0 ? void 0 : retries.policy[502]) === null || _d === void 0 ? void 0 : _d.lag) || 0;
|
|
1881
|
-
break;
|
|
1882
|
-
case '503':
|
|
1883
|
-
allow_fail = ((_e = retries === null || retries === void 0 ? void 0 : retries.policy[503]) === null || _e === void 0 ? void 0 : _e.available) || false;
|
|
1884
|
-
retry_at = ((_f = retries === null || retries === void 0 ? void 0 : retries.policy[503]) === null || _f === void 0 ? void 0 : _f.lag) || 0;
|
|
1885
|
-
break;
|
|
1886
|
-
case '504':
|
|
1887
|
-
allow_fail = ((_g = retries === null || retries === void 0 ? void 0 : retries.policy[504]) === null || _g === void 0 ? void 0 : _g.available) || false;
|
|
1888
|
-
retry_at = ((_h = retries === null || retries === void 0 ? void 0 : retries.policy[504]) === null || _h === void 0 ? void 0 : _h.lag) || 0;
|
|
1889
|
-
break;
|
|
1890
|
-
case '400':
|
|
1891
|
-
allow_fail = ((_j = retries === null || retries === void 0 ? void 0 : retries.policy[400]) === null || _j === void 0 ? void 0 : _j.available) || false;
|
|
1892
|
-
retry_at = ((_k = retries === null || retries === void 0 ? void 0 : retries.policy[400]) === null || _k === void 0 ? void 0 : _k.lag) || 0;
|
|
1893
|
-
break;
|
|
1894
|
-
case '401':
|
|
1895
|
-
allow_fail = ((_l = retries === null || retries === void 0 ? void 0 : retries.policy[401]) === null || _l === void 0 ? void 0 : _l.available) || false;
|
|
1896
|
-
retry_at = ((_m = retries === null || retries === void 0 ? void 0 : retries.policy[401]) === null || _m === void 0 ? void 0 : _m.lag) || 0;
|
|
1897
|
-
break;
|
|
1898
|
-
case '403':
|
|
1899
|
-
allow_fail = ((_o = retries === null || retries === void 0 ? void 0 : retries.policy[403]) === null || _o === void 0 ? void 0 : _o.available) || false;
|
|
1900
|
-
retry_at = ((_p = retries === null || retries === void 0 ? void 0 : retries.policy[403]) === null || _p === void 0 ? void 0 : _p.lag) || 0;
|
|
1901
|
-
break;
|
|
1902
|
-
case '404':
|
|
1903
|
-
allow_fail = ((_q = retries === null || retries === void 0 ? void 0 : retries.policy[404]) === null || _q === void 0 ? void 0 : _q.available) || false;
|
|
1904
|
-
retry_at = ((_r = retries === null || retries === void 0 ? void 0 : retries.policy[404]) === null || _r === void 0 ? void 0 : _r.lag) || 0;
|
|
1905
|
-
break;
|
|
1906
|
-
case '1000': // all non http errors
|
|
1907
|
-
allow_fail = true;
|
|
1908
|
-
retry_at = 500;
|
|
1909
|
-
default:
|
|
1910
|
-
allow_fail = true;
|
|
1911
|
-
retry_at = 0;
|
|
1912
|
-
max = 0;
|
|
1913
|
-
break;
|
|
1914
|
-
}
|
|
2209
|
+
var _a;
|
|
2210
|
+
const isSpecial = error_code === '1000';
|
|
2211
|
+
if (isSpecial) {
|
|
2212
|
+
return { allow_fail: true, max: (retries === null || retries === void 0 ? void 0 : retries.max) || 0, retry_at: 500 };
|
|
2213
|
+
}
|
|
2214
|
+
const policy = (_a = retries === null || retries === void 0 ? void 0 : retries.policy) === null || _a === void 0 ? void 0 : _a[error_code];
|
|
2215
|
+
const allow_fail = policy ? policy.available : true;
|
|
2216
|
+
const retry_at = policy ? policy.lag : 0;
|
|
2217
|
+
const max = (retries === null || retries === void 0 ? void 0 : retries.max) || 0;
|
|
1915
2218
|
return { allow_fail, max, retry_at };
|
|
1916
2219
|
}
|
|
1917
2220
|
async sendActionRequest(base_url, resource, payload, method, env) {
|
|
@@ -1924,20 +2227,24 @@ class ProcessorService {
|
|
|
1924
2227
|
}
|
|
1925
2228
|
}
|
|
1926
2229
|
const authHeaders = headers;
|
|
2230
|
+
if (!base_url.endsWith('/') && !resource.startsWith('/')) {
|
|
2231
|
+
base_url = base_url + '/';
|
|
2232
|
+
}
|
|
1927
2233
|
const request = {
|
|
1928
2234
|
url: resource,
|
|
1929
2235
|
method,
|
|
2236
|
+
baseURL: base_url,
|
|
1930
2237
|
data: body,
|
|
1931
2238
|
params: query,
|
|
1932
2239
|
headers: authHeaders,
|
|
2240
|
+
timeout: 15000,
|
|
2241
|
+
withCredentials: false
|
|
1933
2242
|
};
|
|
1934
|
-
|
|
1935
|
-
base_url = base_url + '/';
|
|
1936
|
-
}
|
|
1937
|
-
const response = await (0, http_client_1.default)(base_url).request(request);
|
|
2243
|
+
const response = await axios_1.default.request(request);
|
|
1938
2244
|
return response.data;
|
|
1939
2245
|
}
|
|
1940
2246
|
catch (e) {
|
|
2247
|
+
//console.error("LOG ERROR", e);
|
|
1941
2248
|
throw e;
|
|
1942
2249
|
}
|
|
1943
2250
|
}
|
|
@@ -1950,8 +2257,8 @@ class ProcessorService {
|
|
|
1950
2257
|
name: 'Process Storage',
|
|
1951
2258
|
};
|
|
1952
2259
|
try {
|
|
1953
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
1954
|
-
this.input =
|
|
2260
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2261
|
+
this.input = input;
|
|
1955
2262
|
this.start = Date.now();
|
|
1956
2263
|
this.component = types_1.LogEventTypes.STORAGE;
|
|
1957
2264
|
// clone
|
|
@@ -1968,7 +2275,6 @@ class ProcessorService {
|
|
|
1968
2275
|
if (!productEnv.active) {
|
|
1969
2276
|
throw new Error(`Environment ${env} is not active`);
|
|
1970
2277
|
}
|
|
1971
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - initiated', status: types_1.LogEventStatus.PROCESSING, storage: new Blob([action.input.buffer]).size }));
|
|
1972
2278
|
const payload = {
|
|
1973
2279
|
type: types_1.FeatureEventTypes.STORAGE,
|
|
1974
2280
|
event,
|
|
@@ -1981,14 +2287,14 @@ class ProcessorService {
|
|
|
1981
2287
|
const result = await this.runStorage(payload);
|
|
1982
2288
|
this.end = Date.now();
|
|
1983
2289
|
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();
|
|
1986
|
-
return result;
|
|
2290
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2291
|
+
await this.logService.publish();
|
|
2292
|
+
return Object.assign(Object.assign({}, result), { process_id: this.process_id });
|
|
1987
2293
|
}
|
|
1988
2294
|
catch (e) {
|
|
1989
2295
|
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
2296
|
this.end = Date.now();
|
|
1991
|
-
this.logService.publish();
|
|
2297
|
+
await this.logService.publish();
|
|
1992
2298
|
return { process_id: this.process_id };
|
|
1993
2299
|
}
|
|
1994
2300
|
}
|
|
@@ -2004,7 +2310,7 @@ class ProcessorService {
|
|
|
2004
2310
|
name: `Subscribe to broker topic`,
|
|
2005
2311
|
};
|
|
2006
2312
|
try {
|
|
2007
|
-
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2313
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2008
2314
|
this.start = Date.now();
|
|
2009
2315
|
this.productTag = data.product;
|
|
2010
2316
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
@@ -2030,14 +2336,14 @@ class ProcessorService {
|
|
|
2030
2336
|
const result = await this.runBrokerSubscribe(payload);
|
|
2031
2337
|
this.end = Date.now();
|
|
2032
2338
|
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();
|
|
2339
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2340
|
+
await this.logService.publish();
|
|
2035
2341
|
return result;
|
|
2036
2342
|
}
|
|
2037
2343
|
catch (e) {
|
|
2038
2344
|
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
2345
|
this.end = Date.now();
|
|
2040
|
-
this.logService.publish();
|
|
2346
|
+
await this.logService.publish();
|
|
2041
2347
|
return { process_id: this.process_id };
|
|
2042
2348
|
}
|
|
2043
2349
|
}
|
|
@@ -2053,8 +2359,7 @@ class ProcessorService {
|
|
|
2053
2359
|
name: 'Publish to broker topic',
|
|
2054
2360
|
};
|
|
2055
2361
|
try {
|
|
2056
|
-
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2057
|
-
console.log("JAPANESE MIRRORS", data.input);
|
|
2362
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2058
2363
|
this.start = Date.now();
|
|
2059
2364
|
// clone
|
|
2060
2365
|
this.clone = (0, processor_utils_1.structuredClone)(data.input);
|
|
@@ -2068,11 +2373,9 @@ class ProcessorService {
|
|
|
2068
2373
|
this.process_id = process_id;
|
|
2069
2374
|
const productEnv = this.fetchEnv(data.env, additional_logs);
|
|
2070
2375
|
this.processEnv = productEnv;
|
|
2071
|
-
console.log("JAPANESE MIRRORS 2", productEnv);
|
|
2072
2376
|
if (!productEnv.active) {
|
|
2073
2377
|
throw new Error(`Environment ${data.env} is not active`);
|
|
2074
2378
|
}
|
|
2075
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to topic - initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
2076
2379
|
const payload = {
|
|
2077
2380
|
type: types_1.FeatureEventTypes.PUBLISH,
|
|
2078
2381
|
event: data.event,
|
|
@@ -2085,19 +2388,124 @@ class ProcessorService {
|
|
|
2085
2388
|
const result = await this.runBrokerPublish(payload);
|
|
2086
2389
|
this.end = Date.now();
|
|
2087
2390
|
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();
|
|
2391
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2392
|
+
await this.logService.publish();
|
|
2090
2393
|
return result;
|
|
2091
2394
|
}
|
|
2092
2395
|
catch (e) {
|
|
2093
|
-
console.log(e);
|
|
2094
2396
|
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
2397
|
this.end = Date.now();
|
|
2096
|
-
this.logService.publish();
|
|
2398
|
+
await this.logService.publish();
|
|
2097
2399
|
return { process_id: this.process_id };
|
|
2098
2400
|
}
|
|
2099
2401
|
}
|
|
2100
|
-
async processJob(job) {
|
|
2402
|
+
async processJob(job, additional_logs = {}) {
|
|
2403
|
+
var _a;
|
|
2404
|
+
const productJob = this.productBuilderService.fetchJob(job.event);
|
|
2405
|
+
if (!productJob) {
|
|
2406
|
+
throw new Error(`Job ${job.event} not found`);
|
|
2407
|
+
}
|
|
2408
|
+
await this.validateActionDataMappingInput(job.input, productJob.type);
|
|
2409
|
+
const NOW = Date.now();
|
|
2410
|
+
// Treat anything above Jan 1, 2023 as a timestamp (to be safe and future-proof)
|
|
2411
|
+
const IS_PROBABLY_TIMESTAMP = job.start_at > 1672531200000;
|
|
2412
|
+
const delay = Math.max(0, IS_PROBABLY_TIMESTAMP ? job.start_at - NOW : job.start_at);
|
|
2413
|
+
let jobInput;
|
|
2414
|
+
if (productJob.type === types_1.JobEventTypes.ACTION) {
|
|
2415
|
+
const input = {
|
|
2416
|
+
env: job.env,
|
|
2417
|
+
product: job.product,
|
|
2418
|
+
app: productJob.app,
|
|
2419
|
+
cache: job.cache,
|
|
2420
|
+
input: job.input,
|
|
2421
|
+
event: job.event,
|
|
2422
|
+
session: job.session
|
|
2423
|
+
};
|
|
2424
|
+
jobInput = input;
|
|
2425
|
+
}
|
|
2426
|
+
else if (productJob.type === types_1.JobEventTypes.DATABASE_ACTION) {
|
|
2427
|
+
const input = {
|
|
2428
|
+
env: job.env,
|
|
2429
|
+
product: job.product,
|
|
2430
|
+
cache: job.cache,
|
|
2431
|
+
input: job.input,
|
|
2432
|
+
event: job.event,
|
|
2433
|
+
session: job.session,
|
|
2434
|
+
};
|
|
2435
|
+
jobInput = input;
|
|
2436
|
+
}
|
|
2437
|
+
else if (productJob.type === types_1.JobEventTypes.FALLBACK || productJob.type === types_1.JobEventTypes.QUOTA || productJob.type === types_1.JobEventTypes.FEATURE) {
|
|
2438
|
+
const input = {
|
|
2439
|
+
input: job.input,
|
|
2440
|
+
product: job.product,
|
|
2441
|
+
env: job.env,
|
|
2442
|
+
tag: job.event,
|
|
2443
|
+
session: job.session,
|
|
2444
|
+
cache: job.cache,
|
|
2445
|
+
};
|
|
2446
|
+
jobInput = input;
|
|
2447
|
+
}
|
|
2448
|
+
else if (productJob.type === types_1.JobEventTypes.NOTIFICATION) {
|
|
2449
|
+
const input = {
|
|
2450
|
+
env: job.env,
|
|
2451
|
+
product: job.product,
|
|
2452
|
+
event: job.event,
|
|
2453
|
+
input: job.input,
|
|
2454
|
+
session: job.session,
|
|
2455
|
+
cache: job.cache
|
|
2456
|
+
};
|
|
2457
|
+
jobInput = input;
|
|
2458
|
+
}
|
|
2459
|
+
else if (productJob.type === types_1.JobEventTypes.PUBLISH) {
|
|
2460
|
+
const input = {
|
|
2461
|
+
env: job.env,
|
|
2462
|
+
product: job.product,
|
|
2463
|
+
event: job.event,
|
|
2464
|
+
cache: job.cache,
|
|
2465
|
+
session: job.session,
|
|
2466
|
+
input: job.input
|
|
2467
|
+
};
|
|
2468
|
+
jobInput = input;
|
|
2469
|
+
}
|
|
2470
|
+
else if (productJob.type === types_1.JobEventTypes.STORAGE) {
|
|
2471
|
+
const input = {
|
|
2472
|
+
env: job.env,
|
|
2473
|
+
product: job.product,
|
|
2474
|
+
event: job.event,
|
|
2475
|
+
cache: job.cache,
|
|
2476
|
+
session: job.session,
|
|
2477
|
+
input: job.input
|
|
2478
|
+
};
|
|
2479
|
+
jobInput = input;
|
|
2480
|
+
}
|
|
2481
|
+
else {
|
|
2482
|
+
throw new Error(`Job type ${productJob.type} not supported`);
|
|
2483
|
+
}
|
|
2484
|
+
const options = {};
|
|
2485
|
+
// Handle `delay` only if repeat.every is not defined
|
|
2486
|
+
if (!((_a = job.repeat) === null || _a === void 0 ? void 0 : _a.every)) {
|
|
2487
|
+
options.delay = delay;
|
|
2488
|
+
}
|
|
2489
|
+
// Add repeat config if defined
|
|
2490
|
+
if (job.repeat) {
|
|
2491
|
+
const { every, cron, tz, limit, endDate } = job.repeat;
|
|
2492
|
+
options.repeat = cron
|
|
2493
|
+
? {
|
|
2494
|
+
cron,
|
|
2495
|
+
tz,
|
|
2496
|
+
limit,
|
|
2497
|
+
endDate,
|
|
2498
|
+
}
|
|
2499
|
+
: every
|
|
2500
|
+
? {
|
|
2501
|
+
every,
|
|
2502
|
+
limit,
|
|
2503
|
+
endDate,
|
|
2504
|
+
}
|
|
2505
|
+
: undefined;
|
|
2506
|
+
}
|
|
2507
|
+
await this.queues.jobs.add(productJob.type, jobInput, options);
|
|
2508
|
+
}
|
|
2101
2509
|
async sendExpoNotification(payload, device_tokens) {
|
|
2102
2510
|
const message = {
|
|
2103
2511
|
to: device_tokens,
|
|
@@ -2106,7 +2514,6 @@ class ProcessorService {
|
|
|
2106
2514
|
body: payload.body,
|
|
2107
2515
|
data: (0, processor_utils_1.convertStringToObject)(payload.data),
|
|
2108
2516
|
};
|
|
2109
|
-
console.log("MESSAGE!!!", message);
|
|
2110
2517
|
try {
|
|
2111
2518
|
await (0, expo_client_1.default)().post('', message, (0, processor_utils_1.generateAxiosConfig)());
|
|
2112
2519
|
}
|
|
@@ -2125,7 +2532,6 @@ class ProcessorService {
|
|
|
2125
2532
|
try {
|
|
2126
2533
|
const admin = require('firebase-admin');
|
|
2127
2534
|
const serviceAccount = credentials;
|
|
2128
|
-
console.log("MESSAGE", message);
|
|
2129
2535
|
admin.initializeApp({
|
|
2130
2536
|
credential: admin.credential.cert(serviceAccount),
|
|
2131
2537
|
});
|
|
@@ -2138,24 +2544,18 @@ class ProcessorService {
|
|
|
2138
2544
|
}
|
|
2139
2545
|
}
|
|
2140
2546
|
async ProcessExpoNotification(notification, template, payload, additional_logs) {
|
|
2141
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate notification payload - initiated', data: { notification, payload: (0, processor_utils_1.anonymizeObject)(payload) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2142
2547
|
(0, processor_utils_1.validateNotification)(template, payload);
|
|
2143
2548
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate notification payload - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2144
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate notification template - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2145
2549
|
const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
|
|
2146
2550
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate notification template - success', data: { title, body, data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2147
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Expo notification - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2148
2551
|
await this.sendExpoNotification({ title, body, data }, payload.device_tokens);
|
|
2149
2552
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Expo notification - success', data: { title, body, data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2150
2553
|
}
|
|
2151
2554
|
async ProcessFirebaseNotification(notification, template, payload, additional_logs) {
|
|
2152
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate Firebase notification payload - initiated', data: { notification, payload: (0, processor_utils_1.anonymizeObject)(payload) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2153
2555
|
(0, processor_utils_1.validateNotification)(template, payload);
|
|
2154
2556
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate Firebase notification payload - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2155
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate Firebase notification template - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2156
2557
|
const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
|
|
2157
2558
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate Firebase notification template - success', data: { title, body: (0, processor_utils_1.anonymizeObject)(data), data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2158
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Firebase notification - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2159
2559
|
await this.sendFirebaseNotification({ title, body, data }, payload.device_tokens, notification.credentials);
|
|
2160
2560
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Firebase notification - success', data: { title, body: (0, processor_utils_1.anonymizeObject)(data), data: (0, processor_utils_1.anonymizeObject)(data) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2161
2561
|
}
|
|
@@ -2165,10 +2565,11 @@ class ProcessorService {
|
|
|
2165
2565
|
const input = notification.input;
|
|
2166
2566
|
try {
|
|
2167
2567
|
//await this.intializeProduct(additional_logs);
|
|
2168
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempting notification', data: { notification }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2169
|
-
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
2568
|
const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
|
|
2171
2569
|
const message = this.productBuilderService.fetchNotificationMessage(event);
|
|
2570
|
+
if (!message) {
|
|
2571
|
+
throw new Error(`Message ${event} not found`);
|
|
2572
|
+
}
|
|
2172
2573
|
const { envs } = notificationEvent;
|
|
2173
2574
|
const { push_notifications: notifications, emails, callbacks, sms: smses } = envs.find((data) => data.slug === notification.env.slug);
|
|
2174
2575
|
const { push_notification: push, email, callback, sms } = message;
|
|
@@ -2183,15 +2584,23 @@ class ProcessorService {
|
|
|
2183
2584
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2184
2585
|
}));
|
|
2185
2586
|
//await this.inputService.validateInput(validationPayload, message.push_notification_data, "Push Notifications");
|
|
2186
|
-
if (push && notifications.type === types_1.Notifiers.FIREBASE) {
|
|
2187
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Processing Expo notification - initiated', data: { notification, input: (0, processor_utils_1.anonymizeObject)(input.push_notification) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2188
|
-
await this.ProcessExpoNotification(notifications, message, input.push_notification, additional_logs);
|
|
2189
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Processing Expo notification - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2190
|
-
}
|
|
2191
2587
|
if (push && notifications.type === types_1.Notifiers.EXPO) {
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2588
|
+
try {
|
|
2589
|
+
await this.ProcessExpoNotification(notifications, message, input.push_notification, additional_logs);
|
|
2590
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Processing Expo notification - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2591
|
+
}
|
|
2592
|
+
catch (e) {
|
|
2593
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Processing Expo notification - failed', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
if (push && notifications.type === types_1.Notifiers.FIREBASE) {
|
|
2597
|
+
try {
|
|
2598
|
+
await this.ProcessFirebaseNotification(notifications, message, input.push_notification, additional_logs);
|
|
2599
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Processing Firebase notification - success', data: { notification, input: (0, processor_utils_1.anonymizeObject)(input.push_notification) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2600
|
+
}
|
|
2601
|
+
catch (e) {
|
|
2602
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Processing Firebase notification - failed', data: { notification, input: (0, processor_utils_1.anonymizeObject)(input.push_notification) }, status: types_1.LogEventStatus.FAIL }));
|
|
2603
|
+
}
|
|
2195
2604
|
}
|
|
2196
2605
|
if (email && emails) {
|
|
2197
2606
|
input.email.subject = await this.generatePayload(input.email.subject, notification, additional_logs, message.email_data.filter((data) => data.parent_key === 'subject'));
|
|
@@ -2203,37 +2612,28 @@ class ProcessorService {
|
|
|
2203
2612
|
}));
|
|
2204
2613
|
//await this.inputService.validateInput(validationPayload, message.email_data);
|
|
2205
2614
|
input.email.recipients.map((email) => this.inputService.validateEmailString({ key: 'to', value: email }));
|
|
2206
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process email - initiated', data: { email: (0, processor_utils_1.anonymizeObject)(email), input: (0, processor_utils_1.anonymizeObject)(input.email) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2207
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt email auth fetch - initiated', data: { emails: (0, processor_utils_1.anonymizeObject)(emails) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2208
2615
|
const { sender_email: from } = emails, auth = __rest(emails, ["sender_email"]);
|
|
2209
2616
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt email auth fetch - success', data: { from: (0, processor_utils_1.anonymizeValue)(from), host: (0, processor_utils_1.anonymizeValue)(auth.host), port: (0, processor_utils_1.anonymizeValue)(auth.port) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2210
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - initiated', data: {
|
|
2211
|
-
template: (0, processor_utils_1.anonymizeValue)(email.template),
|
|
2212
|
-
subject: (0, processor_utils_1.anonymizeValue)(email.subject),
|
|
2213
|
-
input: (0, processor_utils_1.anonymizeObject)(input.email),
|
|
2214
|
-
}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2215
2617
|
const templateMaker = (0, handlebars_1.compile)(email.template);
|
|
2216
2618
|
const template = templateMaker(input.email.template);
|
|
2217
2619
|
const subject = (0, processor_utils_1.replacePlaceholderString)(email.subject, input.email.subject || {});
|
|
2218
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - success', data: { template: (0, processor_utils_1.anonymizeValue)(template), subject: (0, processor_utils_1.anonymizeValue)(subject) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2620
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - success', data: { template: (0, processor_utils_1.anonymizeValue)(template), subject: (0, processor_utils_1.anonymizeValue)(subject), input: (0, processor_utils_1.anonymizeObject)(input.email), }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2219
2621
|
const mailOptions = {
|
|
2220
2622
|
from,
|
|
2221
2623
|
to: input.email.recipients,
|
|
2222
2624
|
subject,
|
|
2223
2625
|
template,
|
|
2224
2626
|
};
|
|
2225
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - initiated', data: { template: (0, processor_utils_1.anonymizeValue)(template), subject: (0, processor_utils_1.anonymizeValue)(subject), to: input.email.recipients.map((data) => (0, processor_utils_1.anonymizeValue)(data)) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2226
2627
|
try {
|
|
2227
2628
|
const transporter = await (0, processor_utils_1.mailerClient)(auth);
|
|
2228
2629
|
const response = await transporter.sendMail(mailOptions);
|
|
2229
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - success', data: { response }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2630
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - success', successful_execution: true, data: { response }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2230
2631
|
}
|
|
2231
2632
|
catch (e) {
|
|
2232
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2633
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Send email - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2233
2634
|
}
|
|
2234
2635
|
}
|
|
2235
2636
|
if (callback && callbacks) {
|
|
2236
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process callback - initiated', data: Object.assign(Object.assign({}, callbacks), { data: (0, processor_utils_1.anonymizeObject)(callback) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
2237
2637
|
const payload = {
|
|
2238
2638
|
query: Object.assign(Object.assign({}, (_a = input.callback) === null || _a === void 0 ? void 0 : _a.query), (_b = callbacks.auth) === null || _b === void 0 ? void 0 : _b.query),
|
|
2239
2639
|
headers: Object.assign(Object.assign({}, (_c = input.callback) === null || _c === void 0 ? void 0 : _c.headers), (_d = callbacks.auth) === null || _d === void 0 ? void 0 : _d.headers),
|
|
@@ -2249,43 +2649,34 @@ class ProcessorService {
|
|
|
2249
2649
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2250
2650
|
}));
|
|
2251
2651
|
//this.inputService.validateInput(validationPayload, message.callback_data);
|
|
2252
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate callback payload - initiated', data: Object.assign(Object.assign({}, callbacks), { data: (0, processor_utils_1.anonymizeObject)(payload) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
2253
2652
|
const url = new URL(callbacks.url);
|
|
2254
2653
|
try {
|
|
2255
|
-
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
2654
|
await this.sendActionRequest(url.origin, url.pathname, payload, callbacks.method, '');
|
|
2262
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send callback - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2655
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, name: 'Send callback - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2263
2656
|
}
|
|
2264
2657
|
catch (e) {
|
|
2265
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send callback - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2658
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Send callback - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2266
2659
|
}
|
|
2267
2660
|
}
|
|
2268
2661
|
if (sms && smses) {
|
|
2269
2662
|
try {
|
|
2270
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process sms - initiated', data: { data: sms, config: (0, processor_utils_1.anonymizeObject)(smses) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2271
2663
|
input.sms.body = await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body);
|
|
2272
2664
|
const SmsClient = await (0, sms_repo_1.loadSMSClient)();
|
|
2273
2665
|
const smsClient = new SmsClient(smses);
|
|
2274
2666
|
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
2667
|
const res = await smsClient.sendMessage(input.sms.body, input.sms.recipients);
|
|
2277
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - success', data: res, status: types_1.LogEventStatus.SUCCESS }));
|
|
2668
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - success', successful_execution: true, data: res, status: types_1.LogEventStatus.SUCCESS }));
|
|
2278
2669
|
}
|
|
2279
2670
|
catch (e) {
|
|
2280
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process sms - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2671
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Process sms - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2281
2672
|
}
|
|
2282
2673
|
}
|
|
2283
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), {
|
|
2674
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt notification - success', data: notification, status: types_1.LogEventStatus.SUCCESS }));
|
|
2284
2675
|
}
|
|
2285
2676
|
catch (e) {
|
|
2286
|
-
|
|
2287
|
-
this.logService.
|
|
2288
|
-
|
|
2677
|
+
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 }));
|
|
2678
|
+
//await this.logService.publish();
|
|
2679
|
+
throw e;
|
|
2289
2680
|
}
|
|
2290
2681
|
}
|
|
2291
2682
|
async runMigration(product_tag, tag, env, type) {
|
|
@@ -2363,9 +2754,8 @@ class ProcessorService {
|
|
|
2363
2754
|
}
|
|
2364
2755
|
}
|
|
2365
2756
|
catch (e) {
|
|
2366
|
-
console.log(e);
|
|
2367
2757
|
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();
|
|
2758
|
+
await this.logService.publish();
|
|
2369
2759
|
}
|
|
2370
2760
|
}
|
|
2371
2761
|
/*async runFunction(data: IFeatureEvent, additional_logs: Partial<ILogData>): Promise<any> {
|
|
@@ -2458,7 +2848,7 @@ class ProcessorService {
|
|
|
2458
2848
|
data: e,
|
|
2459
2849
|
status: LogEventStatus.FAIL,
|
|
2460
2850
|
});
|
|
2461
|
-
this.logService.publish();
|
|
2851
|
+
await this.logService.publish();
|
|
2462
2852
|
}
|
|
2463
2853
|
}*/
|
|
2464
2854
|
async runStorage(data, additional_logs = {}) {
|
|
@@ -2466,8 +2856,6 @@ class ProcessorService {
|
|
|
2466
2856
|
const input = data.input;
|
|
2467
2857
|
try {
|
|
2468
2858
|
await this.intializeProduct(additional_logs);
|
|
2469
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt storage - initiated', data: this.clone, status: types_1.LogEventStatus.PROCESSING }));
|
|
2470
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch storage details - initiated', data: this.clone, status: types_1.LogEventStatus.PROCESSING }));
|
|
2471
2859
|
const storage = await this.productBuilderService.fetchStorage(event);
|
|
2472
2860
|
const storageEnv = storage.envs.find((el) => el.slug === env.slug);
|
|
2473
2861
|
if (!storageEnv) {
|
|
@@ -2487,20 +2875,17 @@ class ProcessorService {
|
|
|
2487
2875
|
input: inputString,
|
|
2488
2876
|
privateKey: product.private_key,
|
|
2489
2877
|
expiry: productCache.expiry,
|
|
2490
|
-
});
|
|
2878
|
+
}, additional_logs);
|
|
2491
2879
|
if (check) {
|
|
2492
2880
|
result = JSON.parse(check);
|
|
2493
2881
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Store file - return from cache', data: { result }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2494
2882
|
return result;
|
|
2495
2883
|
}
|
|
2496
2884
|
}
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
input.
|
|
2500
|
-
input.fileName = file.fileName;
|
|
2501
|
-
input.mimeType = file.mimeType;
|
|
2885
|
+
input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
|
|
2886
|
+
input.fileName = input.fileName ? await this.generateStringValues(input.fileName, '', additional_logs, []) : undefined;
|
|
2887
|
+
input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
|
|
2502
2888
|
result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
|
|
2503
|
-
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
2889
|
if (cache_tag && this.redisClient) {
|
|
2505
2890
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
2506
2891
|
if (!productCache) {
|
|
@@ -2516,13 +2901,11 @@ class ProcessorService {
|
|
|
2516
2901
|
component_tag: event,
|
|
2517
2902
|
component_type: types_1.ProductComponents.STORAGE,
|
|
2518
2903
|
product_tag: this.productTag,
|
|
2519
|
-
});
|
|
2904
|
+
}, additional_logs);
|
|
2520
2905
|
}
|
|
2521
2906
|
return result;
|
|
2522
2907
|
}
|
|
2523
2908
|
catch (e) {
|
|
2524
|
-
console.log(e);
|
|
2525
|
-
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
2909
|
throw e;
|
|
2527
2910
|
}
|
|
2528
2911
|
}
|
|
@@ -2531,8 +2914,6 @@ class ProcessorService {
|
|
|
2531
2914
|
const input = db_action.input;
|
|
2532
2915
|
try {
|
|
2533
2916
|
//await this.intializeProduct(additional_logs);
|
|
2534
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt database action - initiated', data: db_action, status: types_1.LogEventStatus.PROCESSING }));
|
|
2535
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch database action - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2536
2917
|
const [database_tag, action_tag] = event.split(':');
|
|
2537
2918
|
const product = this.productBuilderService.fetchProduct();
|
|
2538
2919
|
const database = await this.productBuilderService.fetchDatabase(database_tag);
|
|
@@ -2542,7 +2923,6 @@ class ProcessorService {
|
|
|
2542
2923
|
throw new Error(`Database env for ${env.slug} not found`);
|
|
2543
2924
|
}
|
|
2544
2925
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch database action - success', data: databaseAction, status: types_1.LogEventStatus.SUCCESS }));
|
|
2545
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database action payload - initiated', data: { payload: (0, processor_utils_1.anonymizeObject)(input.data) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2546
2926
|
input.data = await this.generatePayload(input.data, db_action, additional_logs, databaseAction.data);
|
|
2547
2927
|
if (Array.isArray(input.data)) {
|
|
2548
2928
|
await Promise.all(input.data.map(async (d) => {
|
|
@@ -2558,21 +2938,21 @@ class ProcessorService {
|
|
|
2558
2938
|
data: input.data,
|
|
2559
2939
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2560
2940
|
}));
|
|
2561
|
-
const filterValidationPayload = (await this.inputService.parseJson({
|
|
2562
|
-
data: input.filter,
|
|
2563
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2564
|
-
}));
|
|
2565
2941
|
this.inputService.validateInput(dataValidationPayload, databaseAction.data);
|
|
2566
|
-
|
|
2942
|
+
if (input.filter) {
|
|
2943
|
+
const filterValidationPayload = (await this.inputService.parseJson({
|
|
2944
|
+
data: input.filter,
|
|
2945
|
+
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2946
|
+
}));
|
|
2947
|
+
this.inputService.validateInput(filterValidationPayload, databaseAction.filterData);
|
|
2948
|
+
}
|
|
2567
2949
|
}
|
|
2568
2950
|
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
2951
|
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
2570
2952
|
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
2571
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database update action filter - initiated', data: { filter: (0, processor_utils_1.anonymizeObject)(input.filter) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2572
2953
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate database update action filter - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2573
2954
|
}
|
|
2574
2955
|
}
|
|
2575
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run database action query - initiated', data: { payload: (0, processor_utils_1.anonymizeObject)(input) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2576
2956
|
let result;
|
|
2577
2957
|
if (cache_tag && this.redisClient) {
|
|
2578
2958
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
@@ -2585,7 +2965,7 @@ class ProcessorService {
|
|
|
2585
2965
|
input: inputString,
|
|
2586
2966
|
privateKey: product.private_key,
|
|
2587
2967
|
expiry: productCache.expiry,
|
|
2588
|
-
});
|
|
2968
|
+
}, additional_logs);
|
|
2589
2969
|
if (check) {
|
|
2590
2970
|
result = JSON.parse(check);
|
|
2591
2971
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run database action query - return from cache', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
@@ -2598,7 +2978,7 @@ class ProcessorService {
|
|
|
2598
2978
|
if (!MongoDBHandler) {
|
|
2599
2979
|
throw new Error(`Running in browser, mongo handler not loaded.`);
|
|
2600
2980
|
}
|
|
2601
|
-
const mongoHandler = new MongoDBHandler(
|
|
2981
|
+
const mongoHandler = new MongoDBHandler(databaseEnv.connection_url);
|
|
2602
2982
|
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
2603
2983
|
const filterTemplate = typeof databaseAction.filterTemplate === 'string'
|
|
2604
2984
|
? databaseAction.filterTemplate
|
|
@@ -2619,9 +2999,8 @@ class ProcessorService {
|
|
|
2619
2999
|
result = await pgHandler[databaseAction.type](databaseAction.data, template, input.data);
|
|
2620
3000
|
}
|
|
2621
3001
|
}
|
|
2622
|
-
//this.logService.publish();
|
|
3002
|
+
//await this.logService.publish();
|
|
2623
3003
|
// const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
|
|
2624
|
-
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
3004
|
await this.addToSuccessOutput(db_action, result, additional_logs);
|
|
2626
3005
|
if (cache_tag && this.redisClient) {
|
|
2627
3006
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
@@ -2638,12 +3017,14 @@ class ProcessorService {
|
|
|
2638
3017
|
product_tag: this.productTag,
|
|
2639
3018
|
component_tag: database_tag,
|
|
2640
3019
|
component_type: types_1.ProductComponents.DATABASE_ACTION,
|
|
2641
|
-
});
|
|
3020
|
+
}, additional_logs);
|
|
2642
3021
|
}
|
|
3022
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Attempt database action - successful', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2643
3023
|
return result;
|
|
2644
3024
|
}
|
|
2645
3025
|
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 }));
|
|
3026
|
+
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 }));
|
|
3027
|
+
throw e;
|
|
2647
3028
|
}
|
|
2648
3029
|
}
|
|
2649
3030
|
async runBrokerSubscribe(data, additional_logs = {}) {
|
|
@@ -2651,8 +3032,6 @@ class ProcessorService {
|
|
|
2651
3032
|
const input = data.input;
|
|
2652
3033
|
try {
|
|
2653
3034
|
await this.intializeProduct(additional_logs);
|
|
2654
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt broker topic subscription - initiated', data: { event }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2655
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch broker details - initiated', data: { event }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2656
3035
|
const [brokerTag, topicTag] = event.split(':');
|
|
2657
3036
|
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
2658
3037
|
if (!broker) {
|
|
@@ -2678,12 +3057,13 @@ class ProcessorService {
|
|
|
2678
3057
|
url = queueUrl.url;
|
|
2679
3058
|
}
|
|
2680
3059
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch broker details - success', data: { event, broker }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2681
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Subscribe to broker topic - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2682
3060
|
const createBrokerService = await loadBrokerService();
|
|
2683
3061
|
if (createBrokerService) {
|
|
2684
3062
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
2685
3063
|
await brokerService.subscribe(url, input.callback);
|
|
2686
|
-
|
|
3064
|
+
if (this.feature) {
|
|
3065
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Subscribe to broker topic - success', data: { event }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3066
|
+
}
|
|
2687
3067
|
return;
|
|
2688
3068
|
}
|
|
2689
3069
|
else {
|
|
@@ -2701,8 +3081,6 @@ class ProcessorService {
|
|
|
2701
3081
|
const input = data.input;
|
|
2702
3082
|
try {
|
|
2703
3083
|
await this.intializeProduct(additional_logs);
|
|
2704
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt publish to broker topic - initiated', data: { event }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2705
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch broker details - initiated', data: { event }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2706
3084
|
const [brokerTag, topicTag] = event.split(':');
|
|
2707
3085
|
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
2708
3086
|
if (!broker) {
|
|
@@ -2728,12 +3106,13 @@ class ProcessorService {
|
|
|
2728
3106
|
url = queueUrl.url;
|
|
2729
3107
|
}
|
|
2730
3108
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch broker details - success', data: { event, broker }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2731
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to broker topic initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2732
3109
|
const createBrokerService = await loadBrokerService();
|
|
2733
3110
|
if (createBrokerService) {
|
|
2734
3111
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
2735
3112
|
await brokerService.publish(url, input.message);
|
|
2736
|
-
|
|
3113
|
+
if (this.feature) {
|
|
3114
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Publish to broker topic - success', successful_execution: true, data: { event }, status: types_1.LogEventStatus.SUCCESS }));
|
|
3115
|
+
}
|
|
2737
3116
|
return;
|
|
2738
3117
|
}
|
|
2739
3118
|
else {
|
|
@@ -2743,7 +3122,6 @@ class ProcessorService {
|
|
|
2743
3122
|
}
|
|
2744
3123
|
catch (e) {
|
|
2745
3124
|
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
3125
|
throw e;
|
|
2748
3126
|
}
|
|
2749
3127
|
}
|
|
@@ -2774,13 +3152,30 @@ class ProcessorService {
|
|
|
2774
3152
|
Object.assign(config, { awsConfig: cloudConfig });
|
|
2775
3153
|
}
|
|
2776
3154
|
const result = { url: await (0, storage_util_1.uploadBlobToCloud)({ data: input.buffer, destinationPath: input.fileName, config }) };
|
|
3155
|
+
try {
|
|
3156
|
+
await this.processorApiService.saveFileURL({
|
|
3157
|
+
url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchProduct().private_key),
|
|
3158
|
+
provider: storageEnv.type,
|
|
3159
|
+
product: this.productTag,
|
|
3160
|
+
process_id: this.process_id,
|
|
3161
|
+
workspace_id: this.workspace_id,
|
|
3162
|
+
type: input.mimeType,
|
|
3163
|
+
event: data.event,
|
|
3164
|
+
env: data.env.slug,
|
|
3165
|
+
size: Buffer.from(input.buffer).length
|
|
3166
|
+
}, this.getUserAccess());
|
|
3167
|
+
}
|
|
3168
|
+
catch (e) { }
|
|
2777
3169
|
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
3170
|
await this.addToSuccessOutput(data, result, additional_logs);
|
|
2779
3171
|
return result;
|
|
2780
3172
|
}
|
|
2781
3173
|
catch (e) {
|
|
2782
3174
|
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);
|
|
3175
|
+
const value = await this.addToFailureOutput(e, data, { storageEnv }, additional_logs);
|
|
3176
|
+
if (value) {
|
|
3177
|
+
return value;
|
|
3178
|
+
}
|
|
2784
3179
|
throw e;
|
|
2785
3180
|
}
|
|
2786
3181
|
}
|
|
@@ -2803,7 +3198,7 @@ class ProcessorService {
|
|
|
2803
3198
|
}
|
|
2804
3199
|
catch (e) {
|
|
2805
3200
|
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, {
|
|
3201
|
+
const value = await this.addToFailureOutput(e, db_action, {
|
|
2807
3202
|
db_action,
|
|
2808
3203
|
input,
|
|
2809
3204
|
database_tag,
|
|
@@ -2813,18 +3208,19 @@ class ProcessorService {
|
|
|
2813
3208
|
return value;
|
|
2814
3209
|
}
|
|
2815
3210
|
}
|
|
2816
|
-
async writeResult(status) {
|
|
3211
|
+
async writeResult(status, retryable = true) {
|
|
2817
3212
|
this.processorApiService.saveResult({
|
|
2818
3213
|
status,
|
|
2819
3214
|
component: this.component,
|
|
2820
3215
|
start: this.start,
|
|
2821
3216
|
end: this.end,
|
|
2822
|
-
|
|
3217
|
+
retryable,
|
|
3218
|
+
result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchProduct().private_key),
|
|
2823
3219
|
process_id: this.process_id,
|
|
2824
3220
|
feature_id: this.feature ? this.feature._id : null,
|
|
2825
3221
|
product_id: this.productId,
|
|
2826
3222
|
env: this.processEnv.slug,
|
|
2827
|
-
input: this.input,
|
|
3223
|
+
input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchProduct().private_key),
|
|
2828
3224
|
}, this.getUserAccess());
|
|
2829
3225
|
}
|
|
2830
3226
|
async validateActionDataMappingInput(input, type) {
|
|
@@ -2856,7 +3252,7 @@ class ProcessorService {
|
|
|
2856
3252
|
this.component = types_1.LogEventTypes.ACTION;
|
|
2857
3253
|
try {
|
|
2858
3254
|
// validate input do not allow $Sequence or $Length and $Size of $Input
|
|
2859
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3255
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
2860
3256
|
this.input = action;
|
|
2861
3257
|
this.start = Date.now();
|
|
2862
3258
|
this.productTag = product_tag;
|
|
@@ -2877,7 +3273,6 @@ class ProcessorService {
|
|
|
2877
3273
|
if (!productEnv.active) {
|
|
2878
3274
|
throw new Error(`Environment ${env} is not active`);
|
|
2879
3275
|
}
|
|
2880
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action initiated', status: types_1.LogEventStatus.PROCESSING }));
|
|
2881
3276
|
const result = await this.runAction({
|
|
2882
3277
|
type: types_1.FeatureEventTypes.ACTION,
|
|
2883
3278
|
event,
|
|
@@ -2888,18 +3283,17 @@ class ProcessorService {
|
|
|
2888
3283
|
retries: retries || 0,
|
|
2889
3284
|
allow_fail: false,
|
|
2890
3285
|
}, additional_logs, true);
|
|
2891
|
-
console.log("RESULT ===>>>>", result);
|
|
2892
3286
|
this.end = Date.now();
|
|
2893
3287
|
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();
|
|
3288
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3289
|
+
await this.logService.publish();
|
|
2896
3290
|
return result;
|
|
2897
3291
|
}
|
|
2898
3292
|
catch (e) {
|
|
2899
|
-
console.log(e);
|
|
2900
3293
|
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
3294
|
this.end = Date.now();
|
|
2902
|
-
this.
|
|
3295
|
+
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
3296
|
+
await this.logService.publish();
|
|
2903
3297
|
return { process_id: this.process_id };
|
|
2904
3298
|
}
|
|
2905
3299
|
}
|
|
@@ -2918,7 +3312,7 @@ class ProcessorService {
|
|
|
2918
3312
|
name: 'Process database action',
|
|
2919
3313
|
};
|
|
2920
3314
|
try {
|
|
2921
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3315
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
2922
3316
|
this.input = action;
|
|
2923
3317
|
this.start = Date.now();
|
|
2924
3318
|
this.productTag = product_tag;
|
|
@@ -2933,7 +3327,6 @@ class ProcessorService {
|
|
|
2933
3327
|
if (!productEnv.active) {
|
|
2934
3328
|
throw new Error(`Environment ${env} is not active`);
|
|
2935
3329
|
}
|
|
2936
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute database action', data: { action: (0, processor_utils_1.anonymizeObject)(action) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2937
3330
|
const payload = {
|
|
2938
3331
|
type: types_1.FeatureEventTypes.DB_ACTION,
|
|
2939
3332
|
event,
|
|
@@ -2946,14 +3339,14 @@ class ProcessorService {
|
|
|
2946
3339
|
const result = await this.runDBAction(payload, additional_logs);
|
|
2947
3340
|
this.end = Date.now();
|
|
2948
3341
|
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();
|
|
3342
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3343
|
+
await this.logService.publish();
|
|
2951
3344
|
return result;
|
|
2952
3345
|
}
|
|
2953
3346
|
catch (e) {
|
|
2954
3347
|
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
3348
|
this.end = Date.now();
|
|
2956
|
-
this.logService.publish();
|
|
3349
|
+
await this.logService.publish();
|
|
2957
3350
|
return { process_id: this.process_id };
|
|
2958
3351
|
}
|
|
2959
3352
|
}
|
|
@@ -2973,7 +3366,7 @@ class ProcessorService {
|
|
|
2973
3366
|
name: 'Process Notification',
|
|
2974
3367
|
};
|
|
2975
3368
|
try {
|
|
2976
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3369
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
2977
3370
|
this.input = action;
|
|
2978
3371
|
this.start = Date.now();
|
|
2979
3372
|
this.productTag = product_tag;
|
|
@@ -2988,7 +3381,6 @@ class ProcessorService {
|
|
|
2988
3381
|
if (!productEnv.active) {
|
|
2989
3382
|
throw new Error(`Environment ${env} is not active`);
|
|
2990
3383
|
}
|
|
2991
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send notification - initiated', data: { action: (0, processor_utils_1.anonymizeObject)(action) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2992
3384
|
const payload = {
|
|
2993
3385
|
type: types_1.FeatureEventTypes.NOTIFICATION,
|
|
2994
3386
|
event,
|
|
@@ -3001,14 +3393,14 @@ class ProcessorService {
|
|
|
3001
3393
|
const result = await this.runNotification(payload, additional_logs);
|
|
3002
3394
|
this.end = Date.now();
|
|
3003
3395
|
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();
|
|
3396
|
+
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
3397
|
+
await this.logService.publish();
|
|
3006
3398
|
return { process_id };
|
|
3007
3399
|
}
|
|
3008
3400
|
catch (e) {
|
|
3009
3401
|
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
3402
|
this.end = Date.now();
|
|
3011
|
-
this.logService.publish();
|
|
3403
|
+
await this.logService.publish();
|
|
3012
3404
|
return { process_id: this.process_id };
|
|
3013
3405
|
}
|
|
3014
3406
|
}
|
|
@@ -3032,7 +3424,7 @@ class ProcessorService {
|
|
|
3032
3424
|
public_key: this.public_key,
|
|
3033
3425
|
};
|
|
3034
3426
|
}
|
|
3035
|
-
async addToCache(payload) {
|
|
3427
|
+
async addToCache(payload, additional_logs) {
|
|
3036
3428
|
if (!this.redisClient) {
|
|
3037
3429
|
throw 'redis client not setup';
|
|
3038
3430
|
}
|
|
@@ -3048,13 +3440,15 @@ class ProcessorService {
|
|
|
3048
3440
|
product_tag,
|
|
3049
3441
|
component_tag,
|
|
3050
3442
|
component_type }), this.getUserAccess());
|
|
3443
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Renewing expired Cache Value', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
|
|
3051
3444
|
await this.redisClient.hSet(key, 'data', encryptedData);
|
|
3052
3445
|
await this.redisClient.hSet(key, 'lastUpdated', timestamp);
|
|
3053
3446
|
}
|
|
3054
|
-
async fetchFromCache(payload) {
|
|
3447
|
+
async fetchFromCache(payload, additional_logs) {
|
|
3055
3448
|
var _a;
|
|
3056
3449
|
const { input, privateKey, cache_tag, expiry } = payload;
|
|
3057
3450
|
const key = `${cache_tag}-${CryptoJS.SHA512(input)}`;
|
|
3451
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching from Cache', data: { key }, status: types_1.LogEventStatus.PROCESSING, cache_tag }));
|
|
3058
3452
|
if (!this.redisClient) {
|
|
3059
3453
|
return null;
|
|
3060
3454
|
}
|
|
@@ -3062,8 +3456,10 @@ class ProcessorService {
|
|
|
3062
3456
|
if (!record || !record.data || !record.lastUpdated) {
|
|
3063
3457
|
const checkRemote = await this.processorApiService.fetchRemoteCacheByKey(key, this.getUserAccess());
|
|
3064
3458
|
if (!checkRemote) {
|
|
3459
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Remote Cache Not Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.FAIL, cache_tag }));
|
|
3065
3460
|
return null;
|
|
3066
3461
|
}
|
|
3462
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Remote Cache Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
|
|
3067
3463
|
record = { data: checkRemote.value, expiresAt: (_a = checkRemote.expiry) === null || _a === void 0 ? void 0 : _a.getTime().toString() };
|
|
3068
3464
|
}
|
|
3069
3465
|
if (record.lastUpdated) {
|
|
@@ -3071,11 +3467,13 @@ class ProcessorService {
|
|
|
3071
3467
|
if (expiry) {
|
|
3072
3468
|
const expiryTime = lastUpdated + expiry;
|
|
3073
3469
|
if (Date.now() > expiryTime) {
|
|
3470
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Deleting expired Cache Value', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
|
|
3074
3471
|
await this.redisClient.del(key);
|
|
3075
3472
|
return null;
|
|
3076
3473
|
}
|
|
3077
3474
|
}
|
|
3078
3475
|
}
|
|
3476
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Cache Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
|
|
3079
3477
|
return (0, processor_utils_1.decrypt)(record.data, privateKey);
|
|
3080
3478
|
}
|
|
3081
3479
|
}
|