@ductape/sdk 0.0.4-v2 → 0.0.4-v20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/services/appApi.service.d.ts +2 -2
- package/dist/api/services/appApi.service.js +1 -2
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/pricingApi.service.d.ts +10 -0
- package/dist/api/services/pricingApi.service.js +34 -0
- package/dist/api/services/pricingApi.service.js.map +1 -0
- package/dist/api/services/processorApi.service.d.ts +12 -2
- package/dist/api/services/processorApi.service.js +12 -2
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +7 -1
- package/dist/api/services/productsApi.service.js +33 -0
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/userApi.service.js +1 -0
- package/dist/api/services/userApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +7 -1
- package/dist/api/urls.js +13 -2
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/strings.utils.d.ts +2 -0
- package/dist/api/utils/strings.utils.js +14 -0
- package/dist/api/utils/strings.utils.js.map +1 -1
- package/dist/apps/services/app.service.js +1 -1
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
- package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
- package/dist/clients/apps.client.js +1 -1
- package/dist/clients/apps.client.js.map +1 -1
- package/dist/clients/pricing.client.d.ts +3 -0
- package/dist/clients/pricing.client.js +33 -0
- package/dist/clients/pricing.client.js.map +1 -0
- package/dist/imports/imports.service.d.ts +3 -3
- package/dist/imports/imports.service.js +7 -7
- package/dist/imports/imports.service.js.map +1 -1
- package/dist/imports/imports.types.d.ts +8 -0
- package/dist/imports/repos/openApi.repo.d.ts +1 -2
- package/dist/imports/repos/openApi.repo.js +43 -71
- package/dist/imports/repos/openApi.repo.js.map +1 -1
- package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
- package/dist/imports/repos/postmanV21.repo.js +29 -2
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +953 -46
- package/dist/index.js +918 -81
- package/dist/index.js.map +1 -1
- package/dist/inputs/inputs.service.js +2 -2
- package/dist/inputs/inputs.service.js.map +1 -1
- package/dist/inputs/utils/inputs.utils.create.js +1 -1
- package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
- package/dist/logs/logs.service.js +1 -0
- package/dist/logs/logs.service.js.map +1 -1
- package/dist/logs/logs.types.d.ts +5 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/parsers/index.d.ts +3 -0
- package/dist/parsers/index.js +27 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
- package/dist/parsers/pipelines/postman.pipelines.js +103 -0
- package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
- package/dist/parsers/types/postman.types.d.ts +200 -0
- package/dist/parsers/types/postman.types.js +3 -0
- package/dist/parsers/types/postman.types.js.map +1 -0
- package/dist/parsers/utils/postman.utils.d.ts +12 -0
- package/dist/parsers/utils/postman.utils.js +116 -0
- package/dist/parsers/utils/postman.utils.js.map +1 -0
- package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
- package/dist/parsers/validators/postman-auth.validators.js +127 -0
- package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
- package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-request.validators.js +139 -0
- package/dist/parsers/validators/postman-request.validators.js.map +1 -0
- package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
- package/dist/parsers/validators/postman-response.validators.js +150 -0
- package/dist/parsers/validators/postman-response.validators.js.map +1 -0
- package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
- package/dist/parsers/validators/postman-variable.validators.js +163 -0
- package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
- package/dist/pricing/pricing.repo.d.ts +0 -0
- package/dist/pricing/pricing.repo.js +1 -0
- package/dist/pricing/pricing.repo.js.map +1 -0
- package/dist/pricing/pricing.service.d.ts +24 -0
- package/dist/pricing/pricing.service.js +51 -0
- package/dist/pricing/pricing.service.js.map +1 -0
- package/dist/pricing/pricing.types.d.ts +76 -0
- package/dist/pricing/pricing.types.js +21 -0
- package/dist/pricing/pricing.types.js.map +1 -0
- package/dist/pricing/utils/string.utils.d.ts +1 -0
- package/dist/pricing/utils/string.utils.js +9 -0
- package/dist/pricing/utils/string.utils.js.map +1 -0
- package/dist/processor/repos/sms.repo.d.ts +4 -4
- package/dist/processor/repos/sms.repo.js +23 -10
- package/dist/processor/repos/sms.repo.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +36 -5
- package/dist/processor/services/processor.service.js +526 -187
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/request.service.d.ts +36 -0
- package/dist/processor/services/request.service.js +304 -0
- package/dist/processor/services/request.service.js.map +1 -0
- package/dist/processor/types/request.types.d.ts +14 -0
- package/dist/processor/types/request.types.js +3 -0
- package/dist/processor/types/request.types.js.map +1 -0
- package/dist/processor/utils/processor.utils.d.ts +3 -0
- package/dist/processor/utils/processor.utils.js +88 -5
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/request.utils.d.ts +20 -0
- package/dist/processor/utils/request.utils.js +113 -0
- package/dist/processor/utils/request.utils.js.map +1 -0
- package/dist/processor/utils/storage.util.js +54 -40
- package/dist/processor/utils/storage.util.js.map +1 -1
- package/dist/products/services/products.service.d.ts +19 -4
- package/dist/products/services/products.service.js +256 -29
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/validators/index.d.ts +2 -1
- package/dist/products/validators/index.js +3 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
- package/dist/test/test.health.d.ts +1 -0
- package/dist/test/test.health.js +49 -0
- package/dist/test/test.health.js.map +1 -0
- package/dist/test/test.import.js +51 -4
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.imports.js +22 -7
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.processor.js +32 -115
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.products.d.ts +1 -0
- package/dist/test/test.products.js +49 -0
- package/dist/test/test.products.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +1 -11
- package/dist/types/enums.d.ts +3 -1
- package/dist/types/enums.js +2 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/index.types.d.ts +4 -0
- package/dist/types/pricing.types.d.ts +4 -0
- package/dist/types/pricing.types.js +3 -0
- package/dist/types/pricing.types.js.map +1 -0
- package/dist/types/processor.types.d.ts +68 -9
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +58 -2
- package/dist/types/productsBuilder.types.js +9 -1
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/types/request-tracker.interface.d.ts +0 -0
- package/dist/types/request-tracker.interface.js +1 -0
- package/dist/types/request-tracker.interface.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/package.json +13 -1
|
@@ -69,6 +69,9 @@ const postgres_repo_1 = require("../repos/postgres.repo");
|
|
|
69
69
|
const storage_util_1 = require("../utils/storage.util");
|
|
70
70
|
const sms_repo_1 = require("../repos/sms.repo");
|
|
71
71
|
const quota_service_1 = __importDefault(require("./quota.service"));
|
|
72
|
+
const pricing_service_1 = __importDefault(require("../../pricing/pricing.service"));
|
|
73
|
+
const request_utils_1 = require("../utils/request.utils");
|
|
74
|
+
const request_service_1 = __importDefault(require("./request.service"));
|
|
72
75
|
async function loadBrokerService() {
|
|
73
76
|
if (typeof window === 'undefined') {
|
|
74
77
|
const { createBrokerService } = await Promise.resolve().then(() => __importStar(require('./messagebrokers')));
|
|
@@ -77,14 +80,14 @@ async function loadBrokerService() {
|
|
|
77
80
|
return null;
|
|
78
81
|
}
|
|
79
82
|
async function loadJWT() {
|
|
80
|
-
if (typeof window === undefined) {
|
|
83
|
+
if (typeof window === 'undefined') {
|
|
81
84
|
const JWT = await Promise.resolve().then(() => __importStar(require("jsonwebtoken")));
|
|
82
85
|
return JWT;
|
|
83
86
|
}
|
|
84
87
|
return null;
|
|
85
88
|
}
|
|
86
89
|
class ProcessorService {
|
|
87
|
-
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
|
|
90
|
+
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client, queues }) {
|
|
88
91
|
this.workspace_id = workspace_id;
|
|
89
92
|
this.public_key = public_key;
|
|
90
93
|
this.user_id = user_id;
|
|
@@ -98,6 +101,14 @@ class ProcessorService {
|
|
|
98
101
|
env_type,
|
|
99
102
|
redis_client
|
|
100
103
|
});
|
|
104
|
+
this.pricingService = new pricing_service_1.default({
|
|
105
|
+
workspace_id,
|
|
106
|
+
public_key,
|
|
107
|
+
user_id,
|
|
108
|
+
token,
|
|
109
|
+
env_type,
|
|
110
|
+
redis_client,
|
|
111
|
+
});
|
|
101
112
|
this.inputService = new inputs_service_1.default();
|
|
102
113
|
this.requestTime = 0;
|
|
103
114
|
this.totalRequests = 0;
|
|
@@ -108,10 +119,91 @@ class ProcessorService {
|
|
|
108
119
|
skipped: [],
|
|
109
120
|
};
|
|
110
121
|
this.apps = [];
|
|
122
|
+
this.requestTrackerService = request_service_1.default.getInstance(redis_client);
|
|
111
123
|
this.processorApiService = new processorApi_service_1.ProcessorApiService(env_type);
|
|
112
124
|
this.environment = env_type;
|
|
113
|
-
if (redis_client) {
|
|
125
|
+
if (redis_client && this.productTag) {
|
|
114
126
|
this.redisClient = redis_client;
|
|
127
|
+
// Start healthcheck workers automatically
|
|
128
|
+
this.startHealthcheckWorkers();
|
|
129
|
+
}
|
|
130
|
+
if (queues) {
|
|
131
|
+
this.queues = queues;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Start healthcheck workers for all products/environments after Redis is connected.
|
|
136
|
+
* This is called automatically in the constructor if redisClient is present.
|
|
137
|
+
*/
|
|
138
|
+
async startHealthcheckWorkers() {
|
|
139
|
+
// Fetch all products (or the current product if context is single-tenant)
|
|
140
|
+
// For demo, we use the current product only
|
|
141
|
+
await this.productBuilderService.initializeProductByTag(this.productTag);
|
|
142
|
+
const product = this.productBuilderService.fetchProduct();
|
|
143
|
+
const healthchecks = product.healthchecks || [];
|
|
144
|
+
const privateKey = product.private_key;
|
|
145
|
+
for (const healthcheck of healthchecks) {
|
|
146
|
+
for (const env of healthcheck.envs) {
|
|
147
|
+
// Each env gets its own worker (setInterval)
|
|
148
|
+
const interval = healthcheck.interval || 60000; // default 60s
|
|
149
|
+
setInterval(async () => {
|
|
150
|
+
try {
|
|
151
|
+
// Decrypt input for this env
|
|
152
|
+
let decryptedInput = env.input;
|
|
153
|
+
if (typeof decryptedInput === 'string') {
|
|
154
|
+
decryptedInput = JSON.parse((0, processor_utils_1.decrypt)(decryptedInput, privateKey));
|
|
155
|
+
}
|
|
156
|
+
// Prepare action input
|
|
157
|
+
const actionInput = {
|
|
158
|
+
env: env.slug,
|
|
159
|
+
product: product.tag,
|
|
160
|
+
app: healthcheck.app,
|
|
161
|
+
input: decryptedInput,
|
|
162
|
+
event: healthcheck.event,
|
|
163
|
+
retries: healthcheck.retries || 0,
|
|
164
|
+
};
|
|
165
|
+
// Process the action
|
|
166
|
+
const result = await this.processAction(actionInput);
|
|
167
|
+
// Log result (success/failure)
|
|
168
|
+
this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { message: `Healthcheck processed for ${healthcheck.tag} in env ${env.slug}`, data: { result }, status: types_1.LogEventStatus.SUCCESS }));
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { message: `Healthcheck failed for ${healthcheck.tag} in env ${env.slug}`, data: { error: e.toString() }, status: types_1.LogEventStatus.FAIL }));
|
|
172
|
+
}
|
|
173
|
+
}, interval);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Manually trigger healthcheck processing for all healthchecks (can be called externally if needed)
|
|
179
|
+
*/
|
|
180
|
+
async processAllHealthchecksForProduct(productTag) {
|
|
181
|
+
await this.productBuilderService.initializeProductByTag(productTag);
|
|
182
|
+
const product = this.productBuilderService.fetchProduct();
|
|
183
|
+
const healthchecks = product.healthchecks || [];
|
|
184
|
+
const privateKey = product.private_key;
|
|
185
|
+
for (const healthcheck of healthchecks) {
|
|
186
|
+
for (const env of healthcheck.envs) {
|
|
187
|
+
try {
|
|
188
|
+
let decryptedInput = env.input;
|
|
189
|
+
if (typeof decryptedInput === 'string') {
|
|
190
|
+
decryptedInput = JSON.parse((0, processor_utils_1.decrypt)(decryptedInput, privateKey));
|
|
191
|
+
}
|
|
192
|
+
const actionInput = {
|
|
193
|
+
env: env.slug,
|
|
194
|
+
product: product.tag,
|
|
195
|
+
app: healthcheck.app,
|
|
196
|
+
input: decryptedInput,
|
|
197
|
+
event: healthcheck.event,
|
|
198
|
+
retries: healthcheck.retries || 0,
|
|
199
|
+
};
|
|
200
|
+
const result = await this.processAction(actionInput);
|
|
201
|
+
this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { message: `Manual healthcheck processed for ${healthcheck.tag} in env ${env.slug}`, data: { result }, status: types_1.LogEventStatus.SUCCESS }));
|
|
202
|
+
}
|
|
203
|
+
catch (e) {
|
|
204
|
+
this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { message: `Manual healthcheck failed for ${healthcheck.tag} in env ${env.slug}`, data: { error: e.toString() }, status: types_1.LogEventStatus.FAIL }));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
115
207
|
}
|
|
116
208
|
}
|
|
117
209
|
async generateSession(payload) {
|
|
@@ -132,13 +224,25 @@ class ProcessorService {
|
|
|
132
224
|
throw new Error(`Env with slug ${slug} does not exist`);
|
|
133
225
|
}
|
|
134
226
|
await this.inputService.validateInput(input, session.schema_data);
|
|
135
|
-
const
|
|
227
|
+
const stages = (0, string_utils_1.extractStages)(session.selector);
|
|
228
|
+
const user = (0, processor_utils_1.extractSelectorValue)(data, stages, session.selector);
|
|
229
|
+
const expiry = (0, processor_utils_1.calculateJWTExpiry)(session.expiry, session.period);
|
|
230
|
+
const end_at = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
|
|
136
231
|
const JWT = await loadJWT();
|
|
137
232
|
if (JWT) {
|
|
138
|
-
const
|
|
233
|
+
const session_id = (0, uuid_1.v4)();
|
|
234
|
+
const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, this.productBuilderService.fetchProduct().private_key, { expiresIn: expiry });
|
|
139
235
|
const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.productBuilderService.fetchProduct().private_key);
|
|
140
236
|
// WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
|
|
141
|
-
|
|
237
|
+
const details = {
|
|
238
|
+
identifier: user,
|
|
239
|
+
start_at: Date.now(),
|
|
240
|
+
end_at,
|
|
241
|
+
session_tag: tag,
|
|
242
|
+
data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), this.productBuilderService.fetchProduct().private_key),
|
|
243
|
+
session_id
|
|
244
|
+
};
|
|
245
|
+
await this.processorApiService.createSessionInfo(Object.assign({ product_tag, env: slug, refreshToken }, details), this.getUserAccess());
|
|
142
246
|
return {
|
|
143
247
|
token,
|
|
144
248
|
refreshToken,
|
|
@@ -152,6 +256,40 @@ class ProcessorService {
|
|
|
152
256
|
throw e;
|
|
153
257
|
}
|
|
154
258
|
}
|
|
259
|
+
async refreshSession(payload) {
|
|
260
|
+
await this.productBuilderService.initializeProductByTag(payload.product);
|
|
261
|
+
// validate token validity
|
|
262
|
+
const { refreshToken } = payload, payloadData = __rest(payload, ["refreshToken"]);
|
|
263
|
+
const valid = await this.processorApiService.validateRefreshToken({ refreshToken, product: payload.product, env: payload.env }, this.getUserAccess());
|
|
264
|
+
if (valid) {
|
|
265
|
+
const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, this.productBuilderService.fetchProduct().private_key));
|
|
266
|
+
return await this.generateSession(Object.assign(Object.assign({}, payloadData), { data }));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
throw new Error(`Invalid refresh token`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async decryptSession(data) {
|
|
273
|
+
await this.productBuilderService.initializeProductByTag(data.product);
|
|
274
|
+
const JWT = await loadJWT();
|
|
275
|
+
if (!JWT) {
|
|
276
|
+
throw new Error(`Running in browser, token service not loaded.`);
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
const res = await JWT.verify(data.token, this.productBuilderService.fetchProduct().private_key);
|
|
280
|
+
if (res.session !== data.tag) {
|
|
281
|
+
throw new Error(`Invalid token for session ${data.tag}`);
|
|
282
|
+
}
|
|
283
|
+
if (res.env !== data.env) {
|
|
284
|
+
throw new Error(`Invalid session env`);
|
|
285
|
+
}
|
|
286
|
+
return res.data;
|
|
287
|
+
}
|
|
288
|
+
catch (e) {
|
|
289
|
+
console.log(e);
|
|
290
|
+
throw new Error("Invalid/Expired token");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
155
293
|
async registerWebhook(data) {
|
|
156
294
|
const { product: product_tag, access_tag, webhook_tag, envs } = data;
|
|
157
295
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
@@ -301,7 +439,6 @@ class ProcessorService {
|
|
|
301
439
|
throw new Error(`Quota ${quota_tag} not found`);
|
|
302
440
|
}
|
|
303
441
|
this.logService.setFeatureId(this.quota._id);
|
|
304
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
305
442
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
306
443
|
if (!this.processEnv.active) {
|
|
307
444
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -311,6 +448,7 @@ class ProcessorService {
|
|
|
311
448
|
this.validateJSONFeatureInput(input, quotaInput, additional_logs);
|
|
312
449
|
// split processes
|
|
313
450
|
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
451
|
+
await this.logService.publish();
|
|
314
452
|
return await this.runQuotaOptions(options, input, additional_logs);
|
|
315
453
|
}
|
|
316
454
|
catch (e) {
|
|
@@ -320,17 +458,25 @@ class ProcessorService {
|
|
|
320
458
|
}
|
|
321
459
|
}
|
|
322
460
|
async runQuotaOptions(options, input, additional_logs) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
461
|
+
try {
|
|
462
|
+
const quotaManager = new quota_service_1.default(options, this.redisClient);
|
|
463
|
+
const getNextProvider = quotaManager.getNextProvider();
|
|
464
|
+
const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
|
|
465
|
+
const result = await this.processEvent({
|
|
466
|
+
app: getNextProvider.app,
|
|
467
|
+
type: getNextProvider.type,
|
|
468
|
+
event: getNextProvider.event,
|
|
469
|
+
input: quotaInput,
|
|
470
|
+
retries: getNextProvider.retries,
|
|
471
|
+
allow_fail: false
|
|
472
|
+
});
|
|
473
|
+
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 }));
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
476
|
+
catch (e) {
|
|
477
|
+
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 }));
|
|
478
|
+
throw e;
|
|
479
|
+
}
|
|
334
480
|
}
|
|
335
481
|
async mapQuotaFallbackInput(providerInput, quotaInput, app) {
|
|
336
482
|
if (Array.isArray(providerInput)) {
|
|
@@ -420,7 +566,6 @@ class ProcessorService {
|
|
|
420
566
|
throw new Error(`Fallback "${fallback_tag}" not found`);
|
|
421
567
|
}
|
|
422
568
|
this.logService.setFeatureId(this.fallback._id);
|
|
423
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process fallback initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
424
569
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
425
570
|
if (!this.processEnv.active) {
|
|
426
571
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -470,7 +615,6 @@ class ProcessorService {
|
|
|
470
615
|
feature_id: this.feature._id,
|
|
471
616
|
};
|
|
472
617
|
this.logService.setFeatureId(this.feature._id);
|
|
473
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process feature initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
474
618
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
475
619
|
if (!this.processEnv.active) {
|
|
476
620
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -502,13 +646,7 @@ class ProcessorService {
|
|
|
502
646
|
}
|
|
503
647
|
}
|
|
504
648
|
async intializeProduct(additional_logs) {
|
|
505
|
-
|
|
506
|
-
if (this.productTag) {
|
|
507
|
-
await this.productBuilderService.initializeProductByTag(this.productTag); // validate product_exists
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
await this.productBuilderService.initializeProduct(this.productId);
|
|
511
|
-
}
|
|
649
|
+
if (!this.logService) {
|
|
512
650
|
this.logService = new logs_service_1.default({
|
|
513
651
|
product_id: this.productId,
|
|
514
652
|
workspace_id: this.workspace_id,
|
|
@@ -517,6 +655,14 @@ class ProcessorService {
|
|
|
517
655
|
token: this.token,
|
|
518
656
|
env_type: this.environment,
|
|
519
657
|
});
|
|
658
|
+
}
|
|
659
|
+
try {
|
|
660
|
+
if (this.productTag) {
|
|
661
|
+
await this.productBuilderService.initializeProductByTag(this.productTag); // validate product_exists
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
await this.productBuilderService.initializeProduct(this.productId);
|
|
665
|
+
}
|
|
520
666
|
const { _id: product_id, workspace_id } = this.productBuilderService.fetchProduct();
|
|
521
667
|
this.productId = product_id;
|
|
522
668
|
if (workspace_id !== this.workspace_id) {
|
|
@@ -529,9 +675,34 @@ class ProcessorService {
|
|
|
529
675
|
throw e;
|
|
530
676
|
}
|
|
531
677
|
}
|
|
678
|
+
async initializePricing(additional_logs, access_tag) {
|
|
679
|
+
if (!this.logService) {
|
|
680
|
+
this.logService = new logs_service_1.default({
|
|
681
|
+
product_id: this.productId,
|
|
682
|
+
workspace_id: this.workspace_id,
|
|
683
|
+
public_key: this.public_key,
|
|
684
|
+
user_id: this.user_id,
|
|
685
|
+
token: this.token,
|
|
686
|
+
env_type: this.environment,
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
try {
|
|
690
|
+
console.log(`Initializing pricing for access tag: ${access_tag}`);
|
|
691
|
+
const product_app = this.productBuilderService.fetchApp(access_tag); // validate app exists
|
|
692
|
+
console.log(`Found product app: ${JSON.stringify(product_app)}`);
|
|
693
|
+
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(product_app.access_tag);
|
|
694
|
+
await this.pricingService.initializePricingByTag(product_app.pricing_tag, app._id);
|
|
695
|
+
const { pricing_tag } = this.pricingService.fetchPricing();
|
|
696
|
+
this.pricingTag = pricing_tag;
|
|
697
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - success', data: { pricing_tag: this.pricingTag }, status: types_1.LogEventStatus.SUCCESS }));
|
|
698
|
+
}
|
|
699
|
+
catch (e) {
|
|
700
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
701
|
+
throw e;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
532
704
|
fetchFeature(tag, additional_logs) {
|
|
533
705
|
try {
|
|
534
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch feature - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
|
|
535
706
|
const feature = this.productBuilderService.fetchFeature(tag); // validate feature exists
|
|
536
707
|
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 }));
|
|
537
708
|
return feature;
|
|
@@ -543,7 +714,6 @@ class ProcessorService {
|
|
|
543
714
|
}
|
|
544
715
|
fetchQuota(tag, additional_logs) {
|
|
545
716
|
try {
|
|
546
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch quota - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
|
|
547
717
|
const quota = this.productBuilderService.fetchQuota(tag); // validate feature exists
|
|
548
718
|
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 }));
|
|
549
719
|
return quota;
|
|
@@ -555,7 +725,6 @@ class ProcessorService {
|
|
|
555
725
|
}
|
|
556
726
|
fetchFallback(tag, additional_logs) {
|
|
557
727
|
try {
|
|
558
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch fallback - initiated', data: { tag }, status: types_1.LogEventStatus.PROCESSING }));
|
|
559
728
|
const fallback = this.productBuilderService.fetchFallback(tag); // validate feature exists
|
|
560
729
|
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 }));
|
|
561
730
|
return fallback;
|
|
@@ -567,7 +736,6 @@ class ProcessorService {
|
|
|
567
736
|
}
|
|
568
737
|
fetchEnv(env, additional_logs) {
|
|
569
738
|
try {
|
|
570
|
-
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 }));
|
|
571
739
|
const product_env = this.productBuilderService.fetchEnv(env); // validate env exists
|
|
572
740
|
if (!product_env) {
|
|
573
741
|
throw new Error(`Env ${env} not found`);
|
|
@@ -582,7 +750,6 @@ class ProcessorService {
|
|
|
582
750
|
}
|
|
583
751
|
validateJSONFeatureInput(input, feature_input, additional_logs) {
|
|
584
752
|
try {
|
|
585
|
-
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 }));
|
|
586
753
|
(0, processor_utils_1.validateFeatureJSONInput)(input, feature_input);
|
|
587
754
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
588
755
|
}
|
|
@@ -593,7 +760,6 @@ class ProcessorService {
|
|
|
593
760
|
}
|
|
594
761
|
async splitSequenceIntoLevels(data, additional_logs) {
|
|
595
762
|
try {
|
|
596
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Split sequence - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
597
763
|
const levels = {};
|
|
598
764
|
const tagMap = new Map(data.map((seq) => [seq.tag, seq]));
|
|
599
765
|
const assignedLevels = new Map();
|
|
@@ -630,7 +796,6 @@ class ProcessorService {
|
|
|
630
796
|
}
|
|
631
797
|
async processSequenceLevels(additional_logs) {
|
|
632
798
|
try {
|
|
633
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process levels - initiated', data: { levels: this.sequenceLevels }, status: types_1.LogEventStatus.PROCESSING }));
|
|
634
799
|
const levelEvents = {};
|
|
635
800
|
Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
|
|
636
801
|
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
|
|
@@ -658,7 +823,6 @@ class ProcessorService {
|
|
|
658
823
|
successful_feature_execution = true;
|
|
659
824
|
}
|
|
660
825
|
else if (this.processingFailure) {
|
|
661
|
-
console.log("PROCESSING FAILURE", this.processingFailure);
|
|
662
826
|
message = 'Process feature - processing';
|
|
663
827
|
status = types_1.LogEventStatus.PROCESSING;
|
|
664
828
|
successful_feature_execution = false;
|
|
@@ -674,7 +838,7 @@ class ProcessorService {
|
|
|
674
838
|
return true;
|
|
675
839
|
}
|
|
676
840
|
catch (e) {
|
|
677
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process levels - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
841
|
+
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 }));
|
|
678
842
|
throw e;
|
|
679
843
|
}
|
|
680
844
|
}
|
|
@@ -702,7 +866,6 @@ class ProcessorService {
|
|
|
702
866
|
const { failure } = this.processingOutput;
|
|
703
867
|
const promises = failure.map((failed) => {
|
|
704
868
|
if (failed.retries_left > 0 && new Date().getTime() > failed.retry_at) {
|
|
705
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Reprocess failed events - initiated', data: Object.assign({}, failed), status: types_1.LogEventStatus.PROCESSING }));
|
|
706
869
|
return this.processEvent(failed.event); // process events should also take care of this.processingOutput
|
|
707
870
|
}
|
|
708
871
|
if (failed.retries_left === 0 && !failed.allow_fail) {
|
|
@@ -747,7 +910,6 @@ class ProcessorService {
|
|
|
747
910
|
}
|
|
748
911
|
fetchActionRequestDependents(input, additional_logs) {
|
|
749
912
|
try {
|
|
750
|
-
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 }));
|
|
751
913
|
const dependents = [];
|
|
752
914
|
if (input.query) {
|
|
753
915
|
dependents.push(...this.fetchDependents(input.query, additional_logs));
|
|
@@ -779,7 +941,6 @@ class ProcessorService {
|
|
|
779
941
|
}
|
|
780
942
|
fetchDependents(obj, additional_logs) {
|
|
781
943
|
try {
|
|
782
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch dependents - initiated', data: obj, status: types_1.LogEventStatus.PROCESSING }));
|
|
783
944
|
const dependants = [];
|
|
784
945
|
for (const key in obj) {
|
|
785
946
|
const value = obj[key];
|
|
@@ -821,7 +982,6 @@ class ProcessorService {
|
|
|
821
982
|
return dependants;
|
|
822
983
|
}
|
|
823
984
|
catch (e) {
|
|
824
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch dependents - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
825
985
|
throw e;
|
|
826
986
|
}
|
|
827
987
|
}
|
|
@@ -855,7 +1015,6 @@ class ProcessorService {
|
|
|
855
1015
|
}
|
|
856
1016
|
async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
|
|
857
1017
|
try {
|
|
858
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Construct JSON payloads - initiated', data: { object, samples }, status: types_1.LogEventStatus.PROCESSING }));
|
|
859
1018
|
const payload = {};
|
|
860
1019
|
const { body: actionBody, query: actionQuery, headers: actionHeaders, params: actionParams } = object;
|
|
861
1020
|
if (actionBody) {
|
|
@@ -912,8 +1071,8 @@ class ProcessorService {
|
|
|
912
1071
|
}
|
|
913
1072
|
async generatePayload(obj, event, additional_logs, sample = [], index = {}, loopIndex = null) {
|
|
914
1073
|
try {
|
|
915
|
-
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 }));
|
|
916
1074
|
const payload = {};
|
|
1075
|
+
console.log("Payload Construction", { obj, event, sample, index, loopIndex });
|
|
917
1076
|
const keys = Object.keys(obj);
|
|
918
1077
|
for (let i = 0; i < keys.length; i++) {
|
|
919
1078
|
const key = keys[i];
|
|
@@ -1099,6 +1258,7 @@ class ProcessorService {
|
|
|
1099
1258
|
const placeholdersStr = match[1];
|
|
1100
1259
|
const separator = match[2];
|
|
1101
1260
|
const placeHolders = placeholdersStr.split(',').map((data) => data.trim());
|
|
1261
|
+
console.log('placeHolders', { placeHolders, separator });
|
|
1102
1262
|
const values = await Promise.all(placeHolders.map(async (holder) => {
|
|
1103
1263
|
return await this.generateStringValues(holder, app, additional_logs, sample, index, key, loopIndex);
|
|
1104
1264
|
}));
|
|
@@ -1417,6 +1577,7 @@ class ProcessorService {
|
|
|
1417
1577
|
}
|
|
1418
1578
|
async generateAuthValue(stages, app, sample, additional_logs) {
|
|
1419
1579
|
try {
|
|
1580
|
+
console.log("Generate Auth Data", { stages, app, sample });
|
|
1420
1581
|
let auth_data = await this.fetchAuthData(app, additional_logs); //TODO: should use stages[0]
|
|
1421
1582
|
// take the app tag in index 0..
|
|
1422
1583
|
if (!auth_data) {
|
|
@@ -1432,7 +1593,6 @@ class ProcessorService {
|
|
|
1432
1593
|
}
|
|
1433
1594
|
async fetchAuthData(app_tag, additional_logs) {
|
|
1434
1595
|
try {
|
|
1435
|
-
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 }));
|
|
1436
1596
|
const app = this.productBuilderService.fetchApp(app_tag);
|
|
1437
1597
|
if (!app) {
|
|
1438
1598
|
throw new Error(`App ${app_tag} not found in $Auth value`);
|
|
@@ -1444,6 +1604,7 @@ class ProcessorService {
|
|
|
1444
1604
|
if (!env.auth) {
|
|
1445
1605
|
throw new Error(`App ${app_tag} in auth needs to have a definition for auth in env: ${this.processEnv.slug}`);
|
|
1446
1606
|
}
|
|
1607
|
+
console.log("Envroment", env.auth);
|
|
1447
1608
|
let values = env.auth.values;
|
|
1448
1609
|
if (!values) {
|
|
1449
1610
|
// no auth values
|
|
@@ -1451,6 +1612,7 @@ class ProcessorService {
|
|
|
1451
1612
|
}
|
|
1452
1613
|
if (!env.auth.expiry || (env.auth.expiry && Date.now() > new Date(env.auth.expiry).getTime())) {
|
|
1453
1614
|
// refresh
|
|
1615
|
+
console.log("REFRESH DATA", env, app_tag);
|
|
1454
1616
|
values = await this.getAndStoreAuth(env, app_tag);
|
|
1455
1617
|
}
|
|
1456
1618
|
const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchProduct().private_key);
|
|
@@ -1563,7 +1725,18 @@ class ProcessorService {
|
|
|
1563
1725
|
parent_tag: event.event,
|
|
1564
1726
|
name: 'Process feature job',
|
|
1565
1727
|
};
|
|
1566
|
-
|
|
1728
|
+
const input = {
|
|
1729
|
+
env: event.env.slug,
|
|
1730
|
+
product: this.productTag,
|
|
1731
|
+
event: event.event,
|
|
1732
|
+
retries: event.retries,
|
|
1733
|
+
input: event.input,
|
|
1734
|
+
start_at: event.start_at || 0,
|
|
1735
|
+
cache: event.cache,
|
|
1736
|
+
session: this.input.session
|
|
1737
|
+
};
|
|
1738
|
+
// TODO: fix this
|
|
1739
|
+
return this.processJob(input, additional_logs);
|
|
1567
1740
|
}
|
|
1568
1741
|
}
|
|
1569
1742
|
catch (e) {
|
|
@@ -1587,16 +1760,25 @@ class ProcessorService {
|
|
|
1587
1760
|
}
|
|
1588
1761
|
return output;
|
|
1589
1762
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1763
|
+
async runJobs(job, additional_logs = {}) {
|
|
1764
|
+
if (job.name === types_1.FeatureEventTypes.ACTION) {
|
|
1765
|
+
await this.processAction(job.data);
|
|
1766
|
+
}
|
|
1592
1767
|
}
|
|
1593
1768
|
async processFailedAndWaiting() { }
|
|
1594
|
-
async
|
|
1595
|
-
var _a, _b, _c, _d;
|
|
1769
|
+
async fetchResult(process_id) {
|
|
1596
1770
|
const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
|
|
1597
1771
|
if (!result) {
|
|
1598
1772
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1599
1773
|
}
|
|
1774
|
+
await this.productBuilderService.initializeProduct(result.product_id);
|
|
1775
|
+
result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchProduct().private_key));
|
|
1776
|
+
result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchProduct().private_key));
|
|
1777
|
+
return result;
|
|
1778
|
+
}
|
|
1779
|
+
async generateOutput(process_id) {
|
|
1780
|
+
var _a, _b, _c, _d;
|
|
1781
|
+
const result = await this.fetchResult(process_id);
|
|
1600
1782
|
if (result.component === types_1.LogEventTypes.FEATURE) {
|
|
1601
1783
|
const additional_logs = {
|
|
1602
1784
|
parent_tag: result.input.tag,
|
|
@@ -1635,7 +1817,7 @@ class ProcessorService {
|
|
|
1635
1817
|
}
|
|
1636
1818
|
}
|
|
1637
1819
|
async resumeProcess(process_id) {
|
|
1638
|
-
const result =
|
|
1820
|
+
const result = await this.fetchResult(process_id);
|
|
1639
1821
|
if (!result) {
|
|
1640
1822
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1641
1823
|
}
|
|
@@ -1677,7 +1859,7 @@ class ProcessorService {
|
|
|
1677
1859
|
}
|
|
1678
1860
|
async replayProcess(process_id) {
|
|
1679
1861
|
var _a, _b, _c;
|
|
1680
|
-
const result =
|
|
1862
|
+
const result = await this.fetchResult(process_id);
|
|
1681
1863
|
if (!result) {
|
|
1682
1864
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1683
1865
|
}
|
|
@@ -1740,9 +1922,10 @@ class ProcessorService {
|
|
|
1740
1922
|
async getAndStoreAuth(appEnv, access_tag) {
|
|
1741
1923
|
try {
|
|
1742
1924
|
// const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.fetchProduct().private_key));
|
|
1743
|
-
const payload = appEnv.auth.data;
|
|
1925
|
+
const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.fetchProduct().private_key));
|
|
1744
1926
|
let app = await this.fetchThirdPartyApp(access_tag);
|
|
1745
1927
|
const auth = app.auths.find((item) => item.tag === appEnv.auth.auth_tag);
|
|
1928
|
+
console.log("JAMESY", auth);
|
|
1746
1929
|
if (!auth) {
|
|
1747
1930
|
// throw an error
|
|
1748
1931
|
throw new Error(`Cannot find auth ${appEnv.auth.auth_tag} on environment ${appEnv.product_env_slug}`);
|
|
@@ -1757,6 +1940,7 @@ class ProcessorService {
|
|
|
1757
1940
|
if (env.base_url) {
|
|
1758
1941
|
request_base_url = env.base_url;
|
|
1759
1942
|
}
|
|
1943
|
+
console.log("payloadabi!!!!", payload);
|
|
1760
1944
|
const results = await this.sendActionRequest(request_base_url, url, payload, method, appEnv.app_env_slug);
|
|
1761
1945
|
const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchProduct().private_key);
|
|
1762
1946
|
const productApp = this.productBuilderService.fetchApp(access_tag);
|
|
@@ -1805,7 +1989,6 @@ class ProcessorService {
|
|
|
1805
1989
|
}
|
|
1806
1990
|
async processConditionalCheck(event, additional_logs = {}) {
|
|
1807
1991
|
const parts = (0, string_utils_1.extractConditionalParts)(event.condition.check);
|
|
1808
|
-
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 }));
|
|
1809
1992
|
const [, initiator, operator, value] = parts;
|
|
1810
1993
|
const initiatorValue = await this.generateStringValues(initiator, event.app, additional_logs);
|
|
1811
1994
|
let valueValue;
|
|
@@ -1817,7 +2000,6 @@ class ProcessorService {
|
|
|
1817
2000
|
else {
|
|
1818
2001
|
valueValue = value;
|
|
1819
2002
|
}
|
|
1820
|
-
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 }));
|
|
1821
2003
|
const pass = (0, processor_utils_1.compareValues)(initiatorValue, operator, valueValue);
|
|
1822
2004
|
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 }));
|
|
1823
2005
|
if (!pass) {
|
|
@@ -1842,7 +2024,6 @@ class ProcessorService {
|
|
|
1842
2024
|
}
|
|
1843
2025
|
async extractLoopIndexes(event, additional_logs = {}) {
|
|
1844
2026
|
const parts = (0, string_utils_1.extractConditionalParts)(event.condition.check);
|
|
1845
|
-
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 }));
|
|
1846
2027
|
const [, initiator, operator, value] = parts;
|
|
1847
2028
|
let valueValue;
|
|
1848
2029
|
if (!(0, string_utils_1.isNumeric)(value)) {
|
|
@@ -1877,8 +2058,9 @@ class ProcessorService {
|
|
|
1877
2058
|
const { envs: productEnvs, version } = productApp;
|
|
1878
2059
|
const { app_env_slug } = productEnvs.find((item) => item.product_env_slug === this.processEnv.slug);
|
|
1879
2060
|
additional_logs.app_env = app_env_slug;
|
|
2061
|
+
console.log(app, appEnvs);
|
|
1880
2062
|
const env = appEnvs.find((item) => item.slug === app_env_slug); // fetch the actuall app Environment variable
|
|
1881
|
-
if (!active) {
|
|
2063
|
+
if (!active && recipient_workspace_id !== this.baseLogs.workspace_id) {
|
|
1882
2064
|
throw new Error(`App ${event.app} version ${app.version} is not active`);
|
|
1883
2065
|
}
|
|
1884
2066
|
if (!env.active) {
|
|
@@ -1913,10 +2095,10 @@ class ProcessorService {
|
|
|
1913
2095
|
input: inputString,
|
|
1914
2096
|
privateKey: product.private_key,
|
|
1915
2097
|
expiry: productCache.expiry,
|
|
1916
|
-
});
|
|
2098
|
+
}, additional_logs);
|
|
1917
2099
|
if (check) {
|
|
1918
2100
|
result = JSON.parse(check);
|
|
1919
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run action -
|
|
2101
|
+
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 }));
|
|
1920
2102
|
if (returnValue) {
|
|
1921
2103
|
return result;
|
|
1922
2104
|
}
|
|
@@ -1955,18 +2137,18 @@ class ProcessorService {
|
|
|
1955
2137
|
component_tag: action_tag,
|
|
1956
2138
|
component_type: types_1.ProductComponents.ACTION,
|
|
1957
2139
|
product_tag: this.productTag,
|
|
1958
|
-
});
|
|
2140
|
+
}, additional_logs);
|
|
1959
2141
|
}
|
|
1960
2142
|
return result;
|
|
1961
2143
|
}
|
|
1962
2144
|
catch (e) {
|
|
1963
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), {
|
|
2145
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run Action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
1964
2146
|
throw e;
|
|
1965
2147
|
}
|
|
1966
2148
|
}
|
|
1967
2149
|
async processRequest(payload, event, retries, additional_logs, returnValue = false) {
|
|
2150
|
+
var _a;
|
|
1968
2151
|
const { request_base_url, resource, payloads, method, env, app_id } = payload;
|
|
1969
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - initiated', data: { request: (0, processor_utils_1.anonymizeObject)(payload) }, status: types_1.LogEventStatus.PROCESSING, app_id, action: event.event }));
|
|
1970
2152
|
const start = Date.now();
|
|
1971
2153
|
try {
|
|
1972
2154
|
let results = (0, processor_utils_1.generateMockData)(resource, env.slug, payloads);
|
|
@@ -1976,7 +2158,11 @@ class ProcessorService {
|
|
|
1976
2158
|
const end = Date.now();
|
|
1977
2159
|
this.requestTime += end - start;
|
|
1978
2160
|
this.totalRequests += 1;
|
|
1979
|
-
this.
|
|
2161
|
+
const { pricing_tag, pricing_cost, is_overage, currency } = await this.processPricingCost(Object.assign(Object.assign({}, additional_logs), { app_id, workspace_id: this.workspace_id }));
|
|
2162
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { pricing_tag,
|
|
2163
|
+
pricing_cost,
|
|
2164
|
+
currency,
|
|
2165
|
+
is_overage, 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,
|
|
1980
2166
|
end }));
|
|
1981
2167
|
await this.addToSuccessOutput(event, results, additional_logs);
|
|
1982
2168
|
if (returnValue) {
|
|
@@ -1988,11 +2174,16 @@ class ProcessorService {
|
|
|
1988
2174
|
}
|
|
1989
2175
|
catch (e) {
|
|
1990
2176
|
const end = Date.now();
|
|
2177
|
+
let error = e;
|
|
2178
|
+
if ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) {
|
|
2179
|
+
error = e.response.data;
|
|
2180
|
+
}
|
|
1991
2181
|
this.requestTime += end - start;
|
|
1992
2182
|
this.totalRequests += 1;
|
|
1993
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - failed', failed_execution: true, data: { e }, status: types_1.LogEventStatus.FAIL, app_id, action: event.event, start,
|
|
2183
|
+
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,
|
|
1994
2184
|
end }));
|
|
1995
2185
|
try {
|
|
2186
|
+
console.log(e);
|
|
1996
2187
|
const value = await this.addToFailureOutput(e, event, {
|
|
1997
2188
|
request_base_url,
|
|
1998
2189
|
resource,
|
|
@@ -2017,11 +2208,75 @@ class ProcessorService {
|
|
|
2017
2208
|
}
|
|
2018
2209
|
}
|
|
2019
2210
|
}
|
|
2211
|
+
async processPricingCost(additional_logs) {
|
|
2212
|
+
try {
|
|
2213
|
+
const { app_id, workspace_id } = additional_logs;
|
|
2214
|
+
if (!app_id || !workspace_id) {
|
|
2215
|
+
throw new Error('app_id and workspace_id are required in additional_logs');
|
|
2216
|
+
}
|
|
2217
|
+
const primaryPricing = this.pricingService.fetchPricing();
|
|
2218
|
+
const overagePricing = this.pricingService.fetchOveragePricing();
|
|
2219
|
+
const requests = await this.requestTrackerService.incrementRequest(app_id, workspace_id);
|
|
2220
|
+
const limitCheck = (0, request_utils_1.checkLimitExceeded)(requests, primaryPricing.limits);
|
|
2221
|
+
let finalCost = 0;
|
|
2222
|
+
let usedPricing = primaryPricing;
|
|
2223
|
+
let isOverage = false;
|
|
2224
|
+
let finalCurrency = primaryPricing.currency;
|
|
2225
|
+
if ((0, request_utils_1.isFreeTag)(primaryPricing.pricing_tag)) {
|
|
2226
|
+
if (limitCheck.exceeded) {
|
|
2227
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2228
|
+
finalCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2229
|
+
usedPricing = overagePricing;
|
|
2230
|
+
isOverage = true;
|
|
2231
|
+
finalCurrency = overagePricing.currency;
|
|
2232
|
+
}
|
|
2233
|
+
else {
|
|
2234
|
+
finalCost = 0;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
else {
|
|
2238
|
+
if (limitCheck.exceeded) {
|
|
2239
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2240
|
+
const overageCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2241
|
+
finalCost = overageCost;
|
|
2242
|
+
isOverage = true;
|
|
2243
|
+
}
|
|
2244
|
+
else {
|
|
2245
|
+
const pricingRequests = (0, request_utils_1.calculateRequests)(requests);
|
|
2246
|
+
finalCost = (0, request_utils_1.calculateCost)(primaryPricing.pricing_mode, primaryPricing.unit_price, pricingRequests);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - success', data: {
|
|
2250
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2251
|
+
cost: finalCost,
|
|
2252
|
+
currency: finalCurrency,
|
|
2253
|
+
is_overage: isOverage,
|
|
2254
|
+
requests: requests,
|
|
2255
|
+
limit_exceeded: limitCheck.exceeded
|
|
2256
|
+
}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2257
|
+
return {
|
|
2258
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2259
|
+
pricing_cost: Math.round(finalCost * 100) / 100,
|
|
2260
|
+
currency: finalCurrency,
|
|
2261
|
+
is_overage: isOverage,
|
|
2262
|
+
requests_made: requests,
|
|
2263
|
+
limit_exceeded: limitCheck.exceeded,
|
|
2264
|
+
exceeded_limits: limitCheck.exceededLimits
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
catch (e) {
|
|
2268
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - failed', data: { error: e }, status: types_1.LogEventStatus.FAIL }));
|
|
2269
|
+
throw e;
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2020
2272
|
async addToSuccessOutput(event, output, additional_logs) {
|
|
2021
2273
|
// Remove event from failed, skipped, and waiting arrays
|
|
2022
2274
|
this.processingOutput.failure = this.processingOutput.failure.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2023
2275
|
this.processingOutput.skipped = this.processingOutput.skipped.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2024
2276
|
this.processingOutput.waiting = this.processingOutput.waiting.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2277
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2278
|
+
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2279
|
+
}
|
|
2025
2280
|
this.processingOutput.success.push({ event, output });
|
|
2026
2281
|
await this.processWaitingEvents(additional_logs);
|
|
2027
2282
|
if (this.checkIsSuccessful() && this.doneWithProcessing) {
|
|
@@ -2076,6 +2331,12 @@ class ProcessorService {
|
|
|
2076
2331
|
max = metrices.max;
|
|
2077
2332
|
}
|
|
2078
2333
|
const { allow_fail, retries } = event;
|
|
2334
|
+
let retryable = true;
|
|
2335
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2336
|
+
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2337
|
+
if (!this.feature || (this.feature && !event.allow_fail))
|
|
2338
|
+
retryable = false;
|
|
2339
|
+
}
|
|
2079
2340
|
let retries_left = retries || max;
|
|
2080
2341
|
if (exists > -1) {
|
|
2081
2342
|
retries_left = this.processingOutput.failure[exists].retries_left - 1;
|
|
@@ -2122,7 +2383,7 @@ class ProcessorService {
|
|
|
2122
2383
|
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 }));
|
|
2123
2384
|
//throw new Error("Run out of retries")
|
|
2124
2385
|
this.end = Date.now();
|
|
2125
|
-
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
2386
|
+
await this.writeResult(types_1.LogEventStatus.FAIL, retryable);
|
|
2126
2387
|
await this.logService.publish();
|
|
2127
2388
|
//throw new Error("Terminate Process")
|
|
2128
2389
|
}
|
|
@@ -2133,52 +2394,15 @@ class ProcessorService {
|
|
|
2133
2394
|
}
|
|
2134
2395
|
}
|
|
2135
2396
|
generateRetryMetrices(error_code, retries) {
|
|
2136
|
-
var _a
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
case '502':
|
|
2146
|
-
allow_fail = ((_c = retries === null || retries === void 0 ? void 0 : retries.policy[502]) === null || _c === void 0 ? void 0 : _c.available) || false;
|
|
2147
|
-
retry_at = ((_d = retries === null || retries === void 0 ? void 0 : retries.policy[502]) === null || _d === void 0 ? void 0 : _d.lag) || 0;
|
|
2148
|
-
break;
|
|
2149
|
-
case '503':
|
|
2150
|
-
allow_fail = ((_e = retries === null || retries === void 0 ? void 0 : retries.policy[503]) === null || _e === void 0 ? void 0 : _e.available) || false;
|
|
2151
|
-
retry_at = ((_f = retries === null || retries === void 0 ? void 0 : retries.policy[503]) === null || _f === void 0 ? void 0 : _f.lag) || 0;
|
|
2152
|
-
break;
|
|
2153
|
-
case '504':
|
|
2154
|
-
allow_fail = ((_g = retries === null || retries === void 0 ? void 0 : retries.policy[504]) === null || _g === void 0 ? void 0 : _g.available) || false;
|
|
2155
|
-
retry_at = ((_h = retries === null || retries === void 0 ? void 0 : retries.policy[504]) === null || _h === void 0 ? void 0 : _h.lag) || 0;
|
|
2156
|
-
break;
|
|
2157
|
-
case '400':
|
|
2158
|
-
allow_fail = ((_j = retries === null || retries === void 0 ? void 0 : retries.policy[400]) === null || _j === void 0 ? void 0 : _j.available) || false;
|
|
2159
|
-
retry_at = ((_k = retries === null || retries === void 0 ? void 0 : retries.policy[400]) === null || _k === void 0 ? void 0 : _k.lag) || 0;
|
|
2160
|
-
break;
|
|
2161
|
-
case '401':
|
|
2162
|
-
allow_fail = ((_l = retries === null || retries === void 0 ? void 0 : retries.policy[401]) === null || _l === void 0 ? void 0 : _l.available) || false;
|
|
2163
|
-
retry_at = ((_m = retries === null || retries === void 0 ? void 0 : retries.policy[401]) === null || _m === void 0 ? void 0 : _m.lag) || 0;
|
|
2164
|
-
break;
|
|
2165
|
-
case '403':
|
|
2166
|
-
allow_fail = ((_o = retries === null || retries === void 0 ? void 0 : retries.policy[403]) === null || _o === void 0 ? void 0 : _o.available) || false;
|
|
2167
|
-
retry_at = ((_p = retries === null || retries === void 0 ? void 0 : retries.policy[403]) === null || _p === void 0 ? void 0 : _p.lag) || 0;
|
|
2168
|
-
break;
|
|
2169
|
-
case '404':
|
|
2170
|
-
allow_fail = ((_q = retries === null || retries === void 0 ? void 0 : retries.policy[404]) === null || _q === void 0 ? void 0 : _q.available) || false;
|
|
2171
|
-
retry_at = ((_r = retries === null || retries === void 0 ? void 0 : retries.policy[404]) === null || _r === void 0 ? void 0 : _r.lag) || 0;
|
|
2172
|
-
break;
|
|
2173
|
-
case '1000': // all non http errors
|
|
2174
|
-
allow_fail = true;
|
|
2175
|
-
retry_at = 500;
|
|
2176
|
-
default:
|
|
2177
|
-
allow_fail = true;
|
|
2178
|
-
retry_at = 0;
|
|
2179
|
-
max = 0;
|
|
2180
|
-
break;
|
|
2181
|
-
}
|
|
2397
|
+
var _a;
|
|
2398
|
+
const isSpecial = error_code === '1000';
|
|
2399
|
+
if (isSpecial) {
|
|
2400
|
+
return { allow_fail: true, max: (retries === null || retries === void 0 ? void 0 : retries.max) || 0, retry_at: 500 };
|
|
2401
|
+
}
|
|
2402
|
+
const policy = (_a = retries === null || retries === void 0 ? void 0 : retries.policy) === null || _a === void 0 ? void 0 : _a[error_code];
|
|
2403
|
+
const allow_fail = policy ? policy.available : true;
|
|
2404
|
+
const retry_at = policy ? policy.lag : 0;
|
|
2405
|
+
const max = (retries === null || retries === void 0 ? void 0 : retries.max) || 0;
|
|
2182
2406
|
return { allow_fail, max, retry_at };
|
|
2183
2407
|
}
|
|
2184
2408
|
async sendActionRequest(base_url, resource, payload, method, env) {
|
|
@@ -2204,6 +2428,7 @@ class ProcessorService {
|
|
|
2204
2428
|
timeout: 15000,
|
|
2205
2429
|
withCredentials: false
|
|
2206
2430
|
};
|
|
2431
|
+
console.log("REQUEST!!!!", request);
|
|
2207
2432
|
const response = await axios_1.default.request(request);
|
|
2208
2433
|
return response.data;
|
|
2209
2434
|
}
|
|
@@ -2221,7 +2446,7 @@ class ProcessorService {
|
|
|
2221
2446
|
name: 'Process Storage',
|
|
2222
2447
|
};
|
|
2223
2448
|
try {
|
|
2224
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2449
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2225
2450
|
this.input = input;
|
|
2226
2451
|
this.start = Date.now();
|
|
2227
2452
|
this.component = types_1.LogEventTypes.STORAGE;
|
|
@@ -2239,7 +2464,6 @@ class ProcessorService {
|
|
|
2239
2464
|
if (!productEnv.active) {
|
|
2240
2465
|
throw new Error(`Environment ${env} is not active`);
|
|
2241
2466
|
}
|
|
2242
|
-
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 }));
|
|
2243
2467
|
const payload = {
|
|
2244
2468
|
type: types_1.FeatureEventTypes.STORAGE,
|
|
2245
2469
|
event,
|
|
@@ -2254,7 +2478,7 @@ class ProcessorService {
|
|
|
2254
2478
|
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 }));
|
|
2255
2479
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2256
2480
|
await this.logService.publish();
|
|
2257
|
-
return result;
|
|
2481
|
+
return Object.assign(Object.assign({}, result), { process_id: this.process_id });
|
|
2258
2482
|
}
|
|
2259
2483
|
catch (e) {
|
|
2260
2484
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Storing file - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
@@ -2275,7 +2499,7 @@ class ProcessorService {
|
|
|
2275
2499
|
name: `Subscribe to broker topic`,
|
|
2276
2500
|
};
|
|
2277
2501
|
try {
|
|
2278
|
-
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2502
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2279
2503
|
this.start = Date.now();
|
|
2280
2504
|
this.productTag = data.product;
|
|
2281
2505
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
@@ -2324,7 +2548,7 @@ class ProcessorService {
|
|
|
2324
2548
|
name: 'Publish to broker topic',
|
|
2325
2549
|
};
|
|
2326
2550
|
try {
|
|
2327
|
-
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2551
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2328
2552
|
this.start = Date.now();
|
|
2329
2553
|
// clone
|
|
2330
2554
|
this.clone = (0, processor_utils_1.structuredClone)(data.input);
|
|
@@ -2341,7 +2565,6 @@ class ProcessorService {
|
|
|
2341
2565
|
if (!productEnv.active) {
|
|
2342
2566
|
throw new Error(`Environment ${data.env} is not active`);
|
|
2343
2567
|
}
|
|
2344
|
-
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 }));
|
|
2345
2568
|
const payload = {
|
|
2346
2569
|
type: types_1.FeatureEventTypes.PUBLISH,
|
|
2347
2570
|
event: data.event,
|
|
@@ -2365,7 +2588,113 @@ class ProcessorService {
|
|
|
2365
2588
|
return { process_id: this.process_id };
|
|
2366
2589
|
}
|
|
2367
2590
|
}
|
|
2368
|
-
async processJob(job) {
|
|
2591
|
+
async processJob(job, additional_logs = {}) {
|
|
2592
|
+
var _a;
|
|
2593
|
+
const productJob = this.productBuilderService.fetchJob(job.event);
|
|
2594
|
+
if (!productJob) {
|
|
2595
|
+
throw new Error(`Job ${job.event} not found`);
|
|
2596
|
+
}
|
|
2597
|
+
await this.validateActionDataMappingInput(job.input, productJob.type);
|
|
2598
|
+
const NOW = Date.now();
|
|
2599
|
+
// Treat anything above Jan 1, 2023 as a timestamp (to be safe and future-proof)
|
|
2600
|
+
const IS_PROBABLY_TIMESTAMP = job.start_at > 1672531200000;
|
|
2601
|
+
const delay = Math.max(0, IS_PROBABLY_TIMESTAMP ? job.start_at - NOW : job.start_at);
|
|
2602
|
+
let jobInput;
|
|
2603
|
+
if (productJob.type === types_1.JobEventTypes.ACTION) {
|
|
2604
|
+
const input = {
|
|
2605
|
+
env: job.env,
|
|
2606
|
+
product: job.product,
|
|
2607
|
+
app: productJob.app,
|
|
2608
|
+
cache: job.cache,
|
|
2609
|
+
input: job.input,
|
|
2610
|
+
event: job.event,
|
|
2611
|
+
session: job.session
|
|
2612
|
+
};
|
|
2613
|
+
jobInput = input;
|
|
2614
|
+
}
|
|
2615
|
+
else if (productJob.type === types_1.JobEventTypes.DATABASE_ACTION) {
|
|
2616
|
+
const input = {
|
|
2617
|
+
env: job.env,
|
|
2618
|
+
product: job.product,
|
|
2619
|
+
cache: job.cache,
|
|
2620
|
+
input: job.input,
|
|
2621
|
+
event: job.event,
|
|
2622
|
+
session: job.session,
|
|
2623
|
+
};
|
|
2624
|
+
jobInput = input;
|
|
2625
|
+
}
|
|
2626
|
+
else if (productJob.type === types_1.JobEventTypes.FALLBACK || productJob.type === types_1.JobEventTypes.QUOTA || productJob.type === types_1.JobEventTypes.FEATURE) {
|
|
2627
|
+
const input = {
|
|
2628
|
+
input: job.input,
|
|
2629
|
+
product: job.product,
|
|
2630
|
+
env: job.env,
|
|
2631
|
+
tag: job.event,
|
|
2632
|
+
session: job.session,
|
|
2633
|
+
cache: job.cache,
|
|
2634
|
+
};
|
|
2635
|
+
jobInput = input;
|
|
2636
|
+
}
|
|
2637
|
+
else if (productJob.type === types_1.JobEventTypes.NOTIFICATION) {
|
|
2638
|
+
const input = {
|
|
2639
|
+
env: job.env,
|
|
2640
|
+
product: job.product,
|
|
2641
|
+
event: job.event,
|
|
2642
|
+
input: job.input,
|
|
2643
|
+
session: job.session,
|
|
2644
|
+
cache: job.cache
|
|
2645
|
+
};
|
|
2646
|
+
jobInput = input;
|
|
2647
|
+
}
|
|
2648
|
+
else if (productJob.type === types_1.JobEventTypes.PUBLISH) {
|
|
2649
|
+
const input = {
|
|
2650
|
+
env: job.env,
|
|
2651
|
+
product: job.product,
|
|
2652
|
+
event: job.event,
|
|
2653
|
+
cache: job.cache,
|
|
2654
|
+
session: job.session,
|
|
2655
|
+
input: job.input
|
|
2656
|
+
};
|
|
2657
|
+
jobInput = input;
|
|
2658
|
+
}
|
|
2659
|
+
else if (productJob.type === types_1.JobEventTypes.STORAGE) {
|
|
2660
|
+
const input = {
|
|
2661
|
+
env: job.env,
|
|
2662
|
+
product: job.product,
|
|
2663
|
+
event: job.event,
|
|
2664
|
+
cache: job.cache,
|
|
2665
|
+
session: job.session,
|
|
2666
|
+
input: job.input
|
|
2667
|
+
};
|
|
2668
|
+
jobInput = input;
|
|
2669
|
+
}
|
|
2670
|
+
else {
|
|
2671
|
+
throw new Error(`Job type ${productJob.type} not supported`);
|
|
2672
|
+
}
|
|
2673
|
+
const options = {};
|
|
2674
|
+
// Handle `delay` only if repeat.every is not defined
|
|
2675
|
+
if (!((_a = job.repeat) === null || _a === void 0 ? void 0 : _a.every)) {
|
|
2676
|
+
options.delay = delay;
|
|
2677
|
+
}
|
|
2678
|
+
// Add repeat config if defined
|
|
2679
|
+
if (job.repeat) {
|
|
2680
|
+
const { every, cron, tz, limit, endDate } = job.repeat;
|
|
2681
|
+
options.repeat = cron
|
|
2682
|
+
? {
|
|
2683
|
+
cron,
|
|
2684
|
+
tz,
|
|
2685
|
+
limit,
|
|
2686
|
+
endDate,
|
|
2687
|
+
}
|
|
2688
|
+
: every
|
|
2689
|
+
? {
|
|
2690
|
+
every,
|
|
2691
|
+
limit,
|
|
2692
|
+
endDate,
|
|
2693
|
+
}
|
|
2694
|
+
: undefined;
|
|
2695
|
+
}
|
|
2696
|
+
await this.queues.jobs.add(productJob.type, jobInput, options);
|
|
2697
|
+
}
|
|
2369
2698
|
async sendExpoNotification(payload, device_tokens) {
|
|
2370
2699
|
const message = {
|
|
2371
2700
|
to: device_tokens,
|
|
@@ -2404,24 +2733,18 @@ class ProcessorService {
|
|
|
2404
2733
|
}
|
|
2405
2734
|
}
|
|
2406
2735
|
async ProcessExpoNotification(notification, template, payload, additional_logs) {
|
|
2407
|
-
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 }));
|
|
2408
2736
|
(0, processor_utils_1.validateNotification)(template, payload);
|
|
2409
2737
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Validate notification payload - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2410
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate notification template - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2411
2738
|
const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
|
|
2412
2739
|
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 }));
|
|
2413
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Expo notification - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2414
2740
|
await this.sendExpoNotification({ title, body, data }, payload.device_tokens);
|
|
2415
2741
|
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 }));
|
|
2416
2742
|
}
|
|
2417
2743
|
async ProcessFirebaseNotification(notification, template, payload, additional_logs) {
|
|
2418
|
-
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 }));
|
|
2419
2744
|
(0, processor_utils_1.validateNotification)(template, payload);
|
|
2420
2745
|
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 }));
|
|
2421
|
-
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 }));
|
|
2422
2746
|
const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
|
|
2423
2747
|
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 }));
|
|
2424
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send Firebase notification - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2425
2748
|
await this.sendFirebaseNotification({ title, body, data }, payload.device_tokens, notification.credentials);
|
|
2426
2749
|
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 }));
|
|
2427
2750
|
}
|
|
@@ -2431,8 +2754,6 @@ class ProcessorService {
|
|
|
2431
2754
|
const input = notification.input;
|
|
2432
2755
|
try {
|
|
2433
2756
|
//await this.intializeProduct(additional_logs);
|
|
2434
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempting notification', data: { notification }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2435
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching notification details', data: { notification }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2436
2757
|
const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
|
|
2437
2758
|
const message = this.productBuilderService.fetchNotificationMessage(event);
|
|
2438
2759
|
if (!message) {
|
|
@@ -2452,15 +2773,23 @@ class ProcessorService {
|
|
|
2452
2773
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2453
2774
|
}));
|
|
2454
2775
|
//await this.inputService.validateInput(validationPayload, message.push_notification_data, "Push Notifications");
|
|
2455
|
-
if (push && notifications.type === types_1.Notifiers.FIREBASE) {
|
|
2456
|
-
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 }));
|
|
2457
|
-
await this.ProcessExpoNotification(notifications, message, input.push_notification, additional_logs);
|
|
2458
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Processing Expo notification - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2459
|
-
}
|
|
2460
2776
|
if (push && notifications.type === types_1.Notifiers.EXPO) {
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2777
|
+
try {
|
|
2778
|
+
await this.ProcessExpoNotification(notifications, message, input.push_notification, additional_logs);
|
|
2779
|
+
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 }));
|
|
2780
|
+
}
|
|
2781
|
+
catch (e) {
|
|
2782
|
+
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 }));
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
if (push && notifications.type === types_1.Notifiers.FIREBASE) {
|
|
2786
|
+
try {
|
|
2787
|
+
await this.ProcessFirebaseNotification(notifications, message, input.push_notification, additional_logs);
|
|
2788
|
+
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 }));
|
|
2789
|
+
}
|
|
2790
|
+
catch (e) {
|
|
2791
|
+
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 }));
|
|
2792
|
+
}
|
|
2464
2793
|
}
|
|
2465
2794
|
if (email && emails) {
|
|
2466
2795
|
input.email.subject = await this.generatePayload(input.email.subject, notification, additional_logs, message.email_data.filter((data) => data.parent_key === 'subject'));
|
|
@@ -2472,37 +2801,28 @@ class ProcessorService {
|
|
|
2472
2801
|
}));
|
|
2473
2802
|
//await this.inputService.validateInput(validationPayload, message.email_data);
|
|
2474
2803
|
input.email.recipients.map((email) => this.inputService.validateEmailString({ key: 'to', value: email }));
|
|
2475
|
-
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 }));
|
|
2476
|
-
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 }));
|
|
2477
2804
|
const { sender_email: from } = emails, auth = __rest(emails, ["sender_email"]);
|
|
2478
2805
|
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 }));
|
|
2479
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Generate email template - initiated', data: {
|
|
2480
|
-
template: (0, processor_utils_1.anonymizeValue)(email.template),
|
|
2481
|
-
subject: (0, processor_utils_1.anonymizeValue)(email.subject),
|
|
2482
|
-
input: (0, processor_utils_1.anonymizeObject)(input.email),
|
|
2483
|
-
}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2484
2806
|
const templateMaker = (0, handlebars_1.compile)(email.template);
|
|
2485
2807
|
const template = templateMaker(input.email.template);
|
|
2486
2808
|
const subject = (0, processor_utils_1.replacePlaceholderString)(email.subject, input.email.subject || {});
|
|
2487
|
-
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 }));
|
|
2809
|
+
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 }));
|
|
2488
2810
|
const mailOptions = {
|
|
2489
2811
|
from,
|
|
2490
2812
|
to: input.email.recipients,
|
|
2491
2813
|
subject,
|
|
2492
2814
|
template,
|
|
2493
2815
|
};
|
|
2494
|
-
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 }));
|
|
2495
2816
|
try {
|
|
2496
2817
|
const transporter = await (0, processor_utils_1.mailerClient)(auth);
|
|
2497
2818
|
const response = await transporter.sendMail(mailOptions);
|
|
2498
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - success', data: { response }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2819
|
+
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 }));
|
|
2499
2820
|
}
|
|
2500
2821
|
catch (e) {
|
|
2501
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send email - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2822
|
+
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 }));
|
|
2502
2823
|
}
|
|
2503
2824
|
}
|
|
2504
2825
|
if (callback && callbacks) {
|
|
2505
|
-
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 }));
|
|
2506
2826
|
const payload = {
|
|
2507
2827
|
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),
|
|
2508
2828
|
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),
|
|
@@ -2518,32 +2838,29 @@ class ProcessorService {
|
|
|
2518
2838
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2519
2839
|
}));
|
|
2520
2840
|
//this.inputService.validateInput(validationPayload, message.callback_data);
|
|
2521
|
-
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 }));
|
|
2522
2841
|
const url = new URL(callbacks.url);
|
|
2523
2842
|
try {
|
|
2524
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send callback - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2525
2843
|
await this.sendActionRequest(url.origin, url.pathname, payload, callbacks.method, '');
|
|
2526
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send callback - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2844
|
+
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 }));
|
|
2527
2845
|
}
|
|
2528
2846
|
catch (e) {
|
|
2529
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Send callback - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2847
|
+
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 }));
|
|
2530
2848
|
}
|
|
2531
2849
|
}
|
|
2532
2850
|
if (sms && smses) {
|
|
2533
2851
|
try {
|
|
2534
|
-
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 }));
|
|
2535
2852
|
input.sms.body = await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body);
|
|
2536
2853
|
const SmsClient = await (0, sms_repo_1.loadSMSClient)();
|
|
2537
2854
|
const smsClient = new SmsClient(smses);
|
|
2538
2855
|
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 }));
|
|
2539
2856
|
const res = await smsClient.sendMessage(input.sms.body, input.sms.recipients);
|
|
2540
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { name: 'Send sms - success', data: res, status: types_1.LogEventStatus.SUCCESS }));
|
|
2857
|
+
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 }));
|
|
2541
2858
|
}
|
|
2542
2859
|
catch (e) {
|
|
2543
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process sms - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2860
|
+
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 }));
|
|
2544
2861
|
}
|
|
2545
2862
|
}
|
|
2546
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), {
|
|
2863
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Attempt notification - success', data: notification, status: types_1.LogEventStatus.SUCCESS }));
|
|
2547
2864
|
}
|
|
2548
2865
|
catch (e) {
|
|
2549
2866
|
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 }));
|
|
@@ -2728,8 +3045,6 @@ class ProcessorService {
|
|
|
2728
3045
|
const input = data.input;
|
|
2729
3046
|
try {
|
|
2730
3047
|
await this.intializeProduct(additional_logs);
|
|
2731
|
-
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 }));
|
|
2732
|
-
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 }));
|
|
2733
3048
|
const storage = await this.productBuilderService.fetchStorage(event);
|
|
2734
3049
|
const storageEnv = storage.envs.find((el) => el.slug === env.slug);
|
|
2735
3050
|
if (!storageEnv) {
|
|
@@ -2749,19 +3064,17 @@ class ProcessorService {
|
|
|
2749
3064
|
input: inputString,
|
|
2750
3065
|
privateKey: product.private_key,
|
|
2751
3066
|
expiry: productCache.expiry,
|
|
2752
|
-
});
|
|
3067
|
+
}, additional_logs);
|
|
2753
3068
|
if (check) {
|
|
2754
3069
|
result = JSON.parse(check);
|
|
2755
3070
|
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 }));
|
|
2756
3071
|
return result;
|
|
2757
3072
|
}
|
|
2758
3073
|
}
|
|
2759
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Store file - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2760
3074
|
input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
|
|
2761
3075
|
input.fileName = input.fileName ? await this.generateStringValues(input.fileName, '', additional_logs, []) : undefined;
|
|
2762
3076
|
input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
|
|
2763
3077
|
result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
|
|
2764
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Store file - success', data: { result }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2765
3078
|
if (cache_tag && this.redisClient) {
|
|
2766
3079
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
2767
3080
|
if (!productCache) {
|
|
@@ -2777,12 +3090,11 @@ class ProcessorService {
|
|
|
2777
3090
|
component_tag: event,
|
|
2778
3091
|
component_type: types_1.ProductComponents.STORAGE,
|
|
2779
3092
|
product_tag: this.productTag,
|
|
2780
|
-
});
|
|
3093
|
+
}, additional_logs);
|
|
2781
3094
|
}
|
|
2782
3095
|
return result;
|
|
2783
3096
|
}
|
|
2784
3097
|
catch (e) {
|
|
2785
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt storage - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2786
3098
|
throw e;
|
|
2787
3099
|
}
|
|
2788
3100
|
}
|
|
@@ -2791,8 +3103,6 @@ class ProcessorService {
|
|
|
2791
3103
|
const input = db_action.input;
|
|
2792
3104
|
try {
|
|
2793
3105
|
//await this.intializeProduct(additional_logs);
|
|
2794
|
-
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 }));
|
|
2795
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch database action - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2796
3106
|
const [database_tag, action_tag] = event.split(':');
|
|
2797
3107
|
const product = this.productBuilderService.fetchProduct();
|
|
2798
3108
|
const database = await this.productBuilderService.fetchDatabase(database_tag);
|
|
@@ -2802,7 +3112,6 @@ class ProcessorService {
|
|
|
2802
3112
|
throw new Error(`Database env for ${env.slug} not found`);
|
|
2803
3113
|
}
|
|
2804
3114
|
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 }));
|
|
2805
|
-
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 }));
|
|
2806
3115
|
input.data = await this.generatePayload(input.data, db_action, additional_logs, databaseAction.data);
|
|
2807
3116
|
if (Array.isArray(input.data)) {
|
|
2808
3117
|
await Promise.all(input.data.map(async (d) => {
|
|
@@ -2830,11 +3139,9 @@ class ProcessorService {
|
|
|
2830
3139
|
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 }));
|
|
2831
3140
|
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
2832
3141
|
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
2833
|
-
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 }));
|
|
2834
3142
|
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 }));
|
|
2835
3143
|
}
|
|
2836
3144
|
}
|
|
2837
|
-
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 }));
|
|
2838
3145
|
let result;
|
|
2839
3146
|
if (cache_tag && this.redisClient) {
|
|
2840
3147
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
@@ -2847,7 +3154,7 @@ class ProcessorService {
|
|
|
2847
3154
|
input: inputString,
|
|
2848
3155
|
privateKey: product.private_key,
|
|
2849
3156
|
expiry: productCache.expiry,
|
|
2850
|
-
});
|
|
3157
|
+
}, additional_logs);
|
|
2851
3158
|
if (check) {
|
|
2852
3159
|
result = JSON.parse(check);
|
|
2853
3160
|
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 }));
|
|
@@ -2883,7 +3190,6 @@ class ProcessorService {
|
|
|
2883
3190
|
}
|
|
2884
3191
|
//await this.logService.publish();
|
|
2885
3192
|
// const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
|
|
2886
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { successful_execution: true, message: 'Run database action query - success', data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2887
3193
|
await this.addToSuccessOutput(db_action, result, additional_logs);
|
|
2888
3194
|
if (cache_tag && this.redisClient) {
|
|
2889
3195
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
@@ -2900,8 +3206,9 @@ class ProcessorService {
|
|
|
2900
3206
|
product_tag: this.productTag,
|
|
2901
3207
|
component_tag: database_tag,
|
|
2902
3208
|
component_type: types_1.ProductComponents.DATABASE_ACTION,
|
|
2903
|
-
});
|
|
3209
|
+
}, additional_logs);
|
|
2904
3210
|
}
|
|
3211
|
+
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 }));
|
|
2905
3212
|
return result;
|
|
2906
3213
|
}
|
|
2907
3214
|
catch (e) {
|
|
@@ -2914,8 +3221,6 @@ class ProcessorService {
|
|
|
2914
3221
|
const input = data.input;
|
|
2915
3222
|
try {
|
|
2916
3223
|
await this.intializeProduct(additional_logs);
|
|
2917
|
-
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 }));
|
|
2918
|
-
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 }));
|
|
2919
3224
|
const [brokerTag, topicTag] = event.split(':');
|
|
2920
3225
|
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
2921
3226
|
if (!broker) {
|
|
@@ -2941,12 +3246,13 @@ class ProcessorService {
|
|
|
2941
3246
|
url = queueUrl.url;
|
|
2942
3247
|
}
|
|
2943
3248
|
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 }));
|
|
2944
|
-
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 }));
|
|
2945
3249
|
const createBrokerService = await loadBrokerService();
|
|
2946
3250
|
if (createBrokerService) {
|
|
2947
3251
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
2948
3252
|
await brokerService.subscribe(url, input.callback);
|
|
2949
|
-
|
|
3253
|
+
if (this.feature) {
|
|
3254
|
+
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 }));
|
|
3255
|
+
}
|
|
2950
3256
|
return;
|
|
2951
3257
|
}
|
|
2952
3258
|
else {
|
|
@@ -2964,8 +3270,6 @@ class ProcessorService {
|
|
|
2964
3270
|
const input = data.input;
|
|
2965
3271
|
try {
|
|
2966
3272
|
await this.intializeProduct(additional_logs);
|
|
2967
|
-
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 }));
|
|
2968
|
-
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 }));
|
|
2969
3273
|
const [brokerTag, topicTag] = event.split(':');
|
|
2970
3274
|
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
2971
3275
|
if (!broker) {
|
|
@@ -2991,12 +3295,13 @@ class ProcessorService {
|
|
|
2991
3295
|
url = queueUrl.url;
|
|
2992
3296
|
}
|
|
2993
3297
|
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 }));
|
|
2994
|
-
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 }));
|
|
2995
3298
|
const createBrokerService = await loadBrokerService();
|
|
2996
3299
|
if (createBrokerService) {
|
|
2997
3300
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
2998
3301
|
await brokerService.publish(url, input.message);
|
|
2999
|
-
|
|
3302
|
+
if (this.feature) {
|
|
3303
|
+
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 }));
|
|
3304
|
+
}
|
|
3000
3305
|
return;
|
|
3001
3306
|
}
|
|
3002
3307
|
else {
|
|
@@ -3041,6 +3346,7 @@ class ProcessorService {
|
|
|
3041
3346
|
url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchProduct().private_key),
|
|
3042
3347
|
provider: storageEnv.type,
|
|
3043
3348
|
product: this.productTag,
|
|
3349
|
+
process_id: this.process_id,
|
|
3044
3350
|
workspace_id: this.workspace_id,
|
|
3045
3351
|
type: input.mimeType,
|
|
3046
3352
|
event: data.event,
|
|
@@ -3091,18 +3397,19 @@ class ProcessorService {
|
|
|
3091
3397
|
return value;
|
|
3092
3398
|
}
|
|
3093
3399
|
}
|
|
3094
|
-
async writeResult(status) {
|
|
3400
|
+
async writeResult(status, retryable = true) {
|
|
3095
3401
|
this.processorApiService.saveResult({
|
|
3096
3402
|
status,
|
|
3097
3403
|
component: this.component,
|
|
3098
3404
|
start: this.start,
|
|
3099
3405
|
end: this.end,
|
|
3100
|
-
|
|
3406
|
+
retryable,
|
|
3407
|
+
result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchProduct().private_key),
|
|
3101
3408
|
process_id: this.process_id,
|
|
3102
3409
|
feature_id: this.feature ? this.feature._id : null,
|
|
3103
3410
|
product_id: this.productId,
|
|
3104
3411
|
env: this.processEnv.slug,
|
|
3105
|
-
input: this.input,
|
|
3412
|
+
input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchProduct().private_key),
|
|
3106
3413
|
}, this.getUserAccess());
|
|
3107
3414
|
}
|
|
3108
3415
|
async validateActionDataMappingInput(input, type) {
|
|
@@ -3134,7 +3441,7 @@ class ProcessorService {
|
|
|
3134
3441
|
this.component = types_1.LogEventTypes.ACTION;
|
|
3135
3442
|
try {
|
|
3136
3443
|
// validate input do not allow $Sequence or $Length and $Size of $Input
|
|
3137
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3444
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3138
3445
|
this.input = action;
|
|
3139
3446
|
this.start = Date.now();
|
|
3140
3447
|
this.productTag = product_tag;
|
|
@@ -3148,6 +3455,7 @@ class ProcessorService {
|
|
|
3148
3455
|
data: input,
|
|
3149
3456
|
};
|
|
3150
3457
|
await this.intializeProduct(additional_logs);
|
|
3458
|
+
await this.initializePricing(additional_logs, app);
|
|
3151
3459
|
this.process_id = process_id;
|
|
3152
3460
|
this.baseLogs.product_id = this.productId;
|
|
3153
3461
|
const productEnv = this.fetchEnv(env, additional_logs);
|
|
@@ -3155,7 +3463,6 @@ class ProcessorService {
|
|
|
3155
3463
|
if (!productEnv.active) {
|
|
3156
3464
|
throw new Error(`Environment ${env} is not active`);
|
|
3157
3465
|
}
|
|
3158
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action initiated', status: types_1.LogEventStatus.PROCESSING }));
|
|
3159
3466
|
const result = await this.runAction({
|
|
3160
3467
|
type: types_1.FeatureEventTypes.ACTION,
|
|
3161
3468
|
event,
|
|
@@ -3173,7 +3480,8 @@ class ProcessorService {
|
|
|
3173
3480
|
return result;
|
|
3174
3481
|
}
|
|
3175
3482
|
catch (e) {
|
|
3176
|
-
|
|
3483
|
+
console.log("ERRRRROORRRRR!!!!!!", e);
|
|
3484
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - failed', data: { e: e.toString() }, status: types_1.LogEventStatus.FAIL }));
|
|
3177
3485
|
this.end = Date.now();
|
|
3178
3486
|
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
3179
3487
|
await this.logService.publish();
|
|
@@ -3195,7 +3503,7 @@ class ProcessorService {
|
|
|
3195
3503
|
name: 'Process database action',
|
|
3196
3504
|
};
|
|
3197
3505
|
try {
|
|
3198
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3506
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3199
3507
|
this.input = action;
|
|
3200
3508
|
this.start = Date.now();
|
|
3201
3509
|
this.productTag = product_tag;
|
|
@@ -3210,7 +3518,6 @@ class ProcessorService {
|
|
|
3210
3518
|
if (!productEnv.active) {
|
|
3211
3519
|
throw new Error(`Environment ${env} is not active`);
|
|
3212
3520
|
}
|
|
3213
|
-
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 }));
|
|
3214
3521
|
const payload = {
|
|
3215
3522
|
type: types_1.FeatureEventTypes.DB_ACTION,
|
|
3216
3523
|
event,
|
|
@@ -3250,7 +3557,7 @@ class ProcessorService {
|
|
|
3250
3557
|
name: 'Process Notification',
|
|
3251
3558
|
};
|
|
3252
3559
|
try {
|
|
3253
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3560
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3254
3561
|
this.input = action;
|
|
3255
3562
|
this.start = Date.now();
|
|
3256
3563
|
this.productTag = product_tag;
|
|
@@ -3265,7 +3572,6 @@ class ProcessorService {
|
|
|
3265
3572
|
if (!productEnv.active) {
|
|
3266
3573
|
throw new Error(`Environment ${env} is not active`);
|
|
3267
3574
|
}
|
|
3268
|
-
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 }));
|
|
3269
3575
|
const payload = {
|
|
3270
3576
|
type: types_1.FeatureEventTypes.NOTIFICATION,
|
|
3271
3577
|
event,
|
|
@@ -3309,7 +3615,7 @@ class ProcessorService {
|
|
|
3309
3615
|
public_key: this.public_key,
|
|
3310
3616
|
};
|
|
3311
3617
|
}
|
|
3312
|
-
async addToCache(payload) {
|
|
3618
|
+
async addToCache(payload, additional_logs) {
|
|
3313
3619
|
if (!this.redisClient) {
|
|
3314
3620
|
throw 'redis client not setup';
|
|
3315
3621
|
}
|
|
@@ -3325,13 +3631,15 @@ class ProcessorService {
|
|
|
3325
3631
|
product_tag,
|
|
3326
3632
|
component_tag,
|
|
3327
3633
|
component_type }), this.getUserAccess());
|
|
3634
|
+
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 }));
|
|
3328
3635
|
await this.redisClient.hSet(key, 'data', encryptedData);
|
|
3329
3636
|
await this.redisClient.hSet(key, 'lastUpdated', timestamp);
|
|
3330
3637
|
}
|
|
3331
|
-
async fetchFromCache(payload) {
|
|
3638
|
+
async fetchFromCache(payload, additional_logs) {
|
|
3332
3639
|
var _a;
|
|
3333
3640
|
const { input, privateKey, cache_tag, expiry } = payload;
|
|
3334
3641
|
const key = `${cache_tag}-${CryptoJS.SHA512(input)}`;
|
|
3642
|
+
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 }));
|
|
3335
3643
|
if (!this.redisClient) {
|
|
3336
3644
|
return null;
|
|
3337
3645
|
}
|
|
@@ -3339,8 +3647,10 @@ class ProcessorService {
|
|
|
3339
3647
|
if (!record || !record.data || !record.lastUpdated) {
|
|
3340
3648
|
const checkRemote = await this.processorApiService.fetchRemoteCacheByKey(key, this.getUserAccess());
|
|
3341
3649
|
if (!checkRemote) {
|
|
3650
|
+
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 }));
|
|
3342
3651
|
return null;
|
|
3343
3652
|
}
|
|
3653
|
+
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 }));
|
|
3344
3654
|
record = { data: checkRemote.value, expiresAt: (_a = checkRemote.expiry) === null || _a === void 0 ? void 0 : _a.getTime().toString() };
|
|
3345
3655
|
}
|
|
3346
3656
|
if (record.lastUpdated) {
|
|
@@ -3348,13 +3658,42 @@ class ProcessorService {
|
|
|
3348
3658
|
if (expiry) {
|
|
3349
3659
|
const expiryTime = lastUpdated + expiry;
|
|
3350
3660
|
if (Date.now() > expiryTime) {
|
|
3661
|
+
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 }));
|
|
3351
3662
|
await this.redisClient.del(key);
|
|
3352
3663
|
return null;
|
|
3353
3664
|
}
|
|
3354
3665
|
}
|
|
3355
3666
|
}
|
|
3667
|
+
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 }));
|
|
3356
3668
|
return (0, processor_utils_1.decrypt)(record.data, privateKey);
|
|
3357
3669
|
}
|
|
3670
|
+
/**
|
|
3671
|
+
* Writes the healthcheck result to Redis cache for fast status retrieval.
|
|
3672
|
+
*/
|
|
3673
|
+
async writeHealthcheckResultToCache(data, result) {
|
|
3674
|
+
if (!this.redisClient)
|
|
3675
|
+
return;
|
|
3676
|
+
const key = `healthcheck:${data.product}:${data.healthcheck}:${data.env}`;
|
|
3677
|
+
console.log("LOG TO CACHE", key, JSON.stringify(result));
|
|
3678
|
+
await this.redisClient.set(key, JSON.stringify(result));
|
|
3679
|
+
console.log();
|
|
3680
|
+
}
|
|
3681
|
+
/**
|
|
3682
|
+
* Fetches the latest healthcheck status for a product/env from Redis cache.
|
|
3683
|
+
*/
|
|
3684
|
+
async getHealthcheckStatusFromCache(productTag, envSlug) {
|
|
3685
|
+
if (!this.redisClient)
|
|
3686
|
+
return null;
|
|
3687
|
+
const key = `healthcheck:${productTag}:${envSlug}`;
|
|
3688
|
+
const cached = await this.redisClient.get(key);
|
|
3689
|
+
return cached ? JSON.parse(cached) : null;
|
|
3690
|
+
}
|
|
3691
|
+
/**
|
|
3692
|
+
* Updates the healthcheck in the remote DB for a product with all envs' results.
|
|
3693
|
+
*/
|
|
3694
|
+
async updateHealthcheckOnProcessor(productTag, envs) {
|
|
3695
|
+
return this.productBuilderService.updateHealthcheck(productTag, { envs });
|
|
3696
|
+
}
|
|
3358
3697
|
}
|
|
3359
3698
|
exports.default = ProcessorService;
|
|
3360
3699
|
//# sourceMappingURL=processor.service.js.map
|