@ductape/sdk 0.0.4-v2 → 0.0.4-v21
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/services/workspaceApi.service.js +1 -0
- package/dist/api/services/workspaceApi.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 +7 -5
- 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 +556 -201
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/request.service.d.ts +36 -0
- package/dist/processor/services/request.service.js +304 -0
- package/dist/processor/services/request.service.js.map +1 -0
- package/dist/processor/types/request.types.d.ts +14 -0
- package/dist/processor/types/request.types.js +3 -0
- package/dist/processor/types/request.types.js.map +1 -0
- package/dist/processor/utils/processor.utils.d.ts +3 -0
- package/dist/processor/utils/processor.utils.js +88 -5
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/request.utils.d.ts +20 -0
- package/dist/processor/utils/request.utils.js +113 -0
- package/dist/processor/utils/request.utils.js.map +1 -0
- package/dist/processor/utils/storage.util.js +54 -40
- package/dist/processor/utils/storage.util.js.map +1 -1
- package/dist/products/services/products.service.d.ts +21 -6
- package/dist/products/services/products.service.js +286 -44
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/utils/string.utils.d.ts +1 -1
- package/dist/products/utils/string.utils.js +14 -2
- package/dist/products/utils/string.utils.js.map +1 -1
- package/dist/products/validators/index.d.ts +2 -1
- package/dist/products/validators/index.js +3 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
- package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
- package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
- package/dist/test/test.health.d.ts +1 -0
- package/dist/test/test.health.js +49 -0
- package/dist/test/test.health.js.map +1 -0
- package/dist/test/test.import.js +51 -4
- package/dist/test/test.import.js.map +1 -1
- package/dist/test/test.imports.js +22 -7
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.processor.js +32 -115
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.products.d.ts +1 -0
- package/dist/test/test.products.js +49 -0
- package/dist/test/test.products.js.map +1 -0
- package/dist/types/appBuilder.types.d.ts +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 +59 -3
- 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,27 @@ 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
|
+
// Convert stages to string[] for functions expecting string[]
|
|
229
|
+
const stringStages = stages.map(stage => String(stage));
|
|
230
|
+
const user = (0, processor_utils_1.extractSelectorValue)(data, stringStages, session.selector);
|
|
231
|
+
const expiry = (0, processor_utils_1.calculateJWTExpiry)(session.expiry, session.period);
|
|
232
|
+
const end_at = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
|
|
136
233
|
const JWT = await loadJWT();
|
|
137
234
|
if (JWT) {
|
|
138
|
-
const
|
|
235
|
+
const session_id = (0, uuid_1.v4)();
|
|
236
|
+
const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, this.productBuilderService.fetchProduct().private_key, { expiresIn: expiry });
|
|
139
237
|
const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.productBuilderService.fetchProduct().private_key);
|
|
140
238
|
// WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
|
|
141
|
-
|
|
239
|
+
const details = {
|
|
240
|
+
identifier: user,
|
|
241
|
+
start_at: Date.now(),
|
|
242
|
+
end_at,
|
|
243
|
+
session_tag: tag,
|
|
244
|
+
data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), this.productBuilderService.fetchProduct().private_key),
|
|
245
|
+
session_id
|
|
246
|
+
};
|
|
247
|
+
await this.processorApiService.createSessionInfo(Object.assign({ product_tag, env: slug, refreshToken }, details), this.getUserAccess());
|
|
142
248
|
return {
|
|
143
249
|
token,
|
|
144
250
|
refreshToken,
|
|
@@ -152,6 +258,40 @@ class ProcessorService {
|
|
|
152
258
|
throw e;
|
|
153
259
|
}
|
|
154
260
|
}
|
|
261
|
+
async refreshSession(payload) {
|
|
262
|
+
await this.productBuilderService.initializeProductByTag(payload.product);
|
|
263
|
+
// validate token validity
|
|
264
|
+
const { refreshToken } = payload, payloadData = __rest(payload, ["refreshToken"]);
|
|
265
|
+
const valid = await this.processorApiService.validateRefreshToken({ refreshToken, product: payload.product, env: payload.env }, this.getUserAccess());
|
|
266
|
+
if (valid) {
|
|
267
|
+
const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, this.productBuilderService.fetchProduct().private_key));
|
|
268
|
+
return await this.generateSession(Object.assign(Object.assign({}, payloadData), { data }));
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
throw new Error(`Invalid refresh token`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async decryptSession(data) {
|
|
275
|
+
await this.productBuilderService.initializeProductByTag(data.product);
|
|
276
|
+
const JWT = await loadJWT();
|
|
277
|
+
if (!JWT) {
|
|
278
|
+
throw new Error(`Running in browser, token service not loaded.`);
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
const res = await JWT.verify(data.token, this.productBuilderService.fetchProduct().private_key);
|
|
282
|
+
if (res.session !== data.tag) {
|
|
283
|
+
throw new Error(`Invalid token for session ${data.tag}`);
|
|
284
|
+
}
|
|
285
|
+
if (res.env !== data.env) {
|
|
286
|
+
throw new Error(`Invalid session env`);
|
|
287
|
+
}
|
|
288
|
+
return res.data;
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
console.log(e);
|
|
292
|
+
throw new Error("Invalid/Expired token");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
155
295
|
async registerWebhook(data) {
|
|
156
296
|
const { product: product_tag, access_tag, webhook_tag, envs } = data;
|
|
157
297
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
@@ -301,7 +441,6 @@ class ProcessorService {
|
|
|
301
441
|
throw new Error(`Quota ${quota_tag} not found`);
|
|
302
442
|
}
|
|
303
443
|
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
444
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
306
445
|
if (!this.processEnv.active) {
|
|
307
446
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -311,6 +450,7 @@ class ProcessorService {
|
|
|
311
450
|
this.validateJSONFeatureInput(input, quotaInput, additional_logs);
|
|
312
451
|
// split processes
|
|
313
452
|
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
453
|
+
await this.logService.publish();
|
|
314
454
|
return await this.runQuotaOptions(options, input, additional_logs);
|
|
315
455
|
}
|
|
316
456
|
catch (e) {
|
|
@@ -320,17 +460,25 @@ class ProcessorService {
|
|
|
320
460
|
}
|
|
321
461
|
}
|
|
322
462
|
async runQuotaOptions(options, input, additional_logs) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
463
|
+
try {
|
|
464
|
+
const quotaManager = new quota_service_1.default(options, this.redisClient);
|
|
465
|
+
const getNextProvider = quotaManager.getNextProvider();
|
|
466
|
+
const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
|
|
467
|
+
const result = await this.processEvent({
|
|
468
|
+
app: getNextProvider.app,
|
|
469
|
+
type: getNextProvider.type,
|
|
470
|
+
event: getNextProvider.event,
|
|
471
|
+
input: quotaInput,
|
|
472
|
+
retries: getNextProvider.retries,
|
|
473
|
+
allow_fail: false
|
|
474
|
+
});
|
|
475
|
+
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 }));
|
|
476
|
+
return result;
|
|
477
|
+
}
|
|
478
|
+
catch (e) {
|
|
479
|
+
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 }));
|
|
480
|
+
throw e;
|
|
481
|
+
}
|
|
334
482
|
}
|
|
335
483
|
async mapQuotaFallbackInput(providerInput, quotaInput, app) {
|
|
336
484
|
if (Array.isArray(providerInput)) {
|
|
@@ -350,10 +498,14 @@ class ProcessorService {
|
|
|
350
498
|
}
|
|
351
499
|
async overrideQuotaFallbackInput(value, quotaInput, app) {
|
|
352
500
|
if (value.startsWith('$Input{')) {
|
|
353
|
-
|
|
501
|
+
const stages = (0, string_utils_1.extractStages)(value);
|
|
502
|
+
return quotaInput[String(stages[0])];
|
|
354
503
|
}
|
|
355
504
|
else if (value.startsWith('$Auth')) {
|
|
356
|
-
|
|
505
|
+
const stages = (0, string_utils_1.extractStages)(value);
|
|
506
|
+
// Convert stages to string[] for functions expecting string[]
|
|
507
|
+
const stringStages = stages.map(stage => String(stage));
|
|
508
|
+
return await this.generateAuthValue(stringStages, app, [], {});
|
|
357
509
|
}
|
|
358
510
|
else if (value.startsWith('$')) {
|
|
359
511
|
this.input = Object.assign(Object.assign({}, this.input), { input: quotaInput });
|
|
@@ -420,7 +572,6 @@ class ProcessorService {
|
|
|
420
572
|
throw new Error(`Fallback "${fallback_tag}" not found`);
|
|
421
573
|
}
|
|
422
574
|
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
575
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
425
576
|
if (!this.processEnv.active) {
|
|
426
577
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -470,7 +621,6 @@ class ProcessorService {
|
|
|
470
621
|
feature_id: this.feature._id,
|
|
471
622
|
};
|
|
472
623
|
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
624
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
475
625
|
if (!this.processEnv.active) {
|
|
476
626
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -502,13 +652,7 @@ class ProcessorService {
|
|
|
502
652
|
}
|
|
503
653
|
}
|
|
504
654
|
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
|
-
}
|
|
655
|
+
if (!this.logService) {
|
|
512
656
|
this.logService = new logs_service_1.default({
|
|
513
657
|
product_id: this.productId,
|
|
514
658
|
workspace_id: this.workspace_id,
|
|
@@ -517,6 +661,14 @@ class ProcessorService {
|
|
|
517
661
|
token: this.token,
|
|
518
662
|
env_type: this.environment,
|
|
519
663
|
});
|
|
664
|
+
}
|
|
665
|
+
try {
|
|
666
|
+
if (this.productTag) {
|
|
667
|
+
await this.productBuilderService.initializeProductByTag(this.productTag); // validate product_exists
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
await this.productBuilderService.initializeProduct(this.productId);
|
|
671
|
+
}
|
|
520
672
|
const { _id: product_id, workspace_id } = this.productBuilderService.fetchProduct();
|
|
521
673
|
this.productId = product_id;
|
|
522
674
|
if (workspace_id !== this.workspace_id) {
|
|
@@ -529,9 +681,34 @@ class ProcessorService {
|
|
|
529
681
|
throw e;
|
|
530
682
|
}
|
|
531
683
|
}
|
|
684
|
+
async initializePricing(additional_logs, access_tag) {
|
|
685
|
+
if (!this.logService) {
|
|
686
|
+
this.logService = new logs_service_1.default({
|
|
687
|
+
product_id: this.productId,
|
|
688
|
+
workspace_id: this.workspace_id,
|
|
689
|
+
public_key: this.public_key,
|
|
690
|
+
user_id: this.user_id,
|
|
691
|
+
token: this.token,
|
|
692
|
+
env_type: this.environment,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
try {
|
|
696
|
+
console.log(`Initializing pricing for access tag: ${access_tag}`);
|
|
697
|
+
const product_app = this.productBuilderService.fetchApp(access_tag); // validate app exists
|
|
698
|
+
console.log(`Found product app: ${JSON.stringify(product_app)}`);
|
|
699
|
+
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(product_app.access_tag);
|
|
700
|
+
await this.pricingService.initializePricingByTag(product_app.pricing_tag, app._id);
|
|
701
|
+
const { pricing_tag } = this.pricingService.fetchPricing();
|
|
702
|
+
this.pricingTag = pricing_tag;
|
|
703
|
+
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 }));
|
|
704
|
+
}
|
|
705
|
+
catch (e) {
|
|
706
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
707
|
+
throw e;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
532
710
|
fetchFeature(tag, additional_logs) {
|
|
533
711
|
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
712
|
const feature = this.productBuilderService.fetchFeature(tag); // validate feature exists
|
|
536
713
|
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
714
|
return feature;
|
|
@@ -543,7 +720,6 @@ class ProcessorService {
|
|
|
543
720
|
}
|
|
544
721
|
fetchQuota(tag, additional_logs) {
|
|
545
722
|
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
723
|
const quota = this.productBuilderService.fetchQuota(tag); // validate feature exists
|
|
548
724
|
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
725
|
return quota;
|
|
@@ -555,7 +731,6 @@ class ProcessorService {
|
|
|
555
731
|
}
|
|
556
732
|
fetchFallback(tag, additional_logs) {
|
|
557
733
|
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
734
|
const fallback = this.productBuilderService.fetchFallback(tag); // validate feature exists
|
|
560
735
|
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
736
|
return fallback;
|
|
@@ -567,7 +742,6 @@ class ProcessorService {
|
|
|
567
742
|
}
|
|
568
743
|
fetchEnv(env, additional_logs) {
|
|
569
744
|
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
745
|
const product_env = this.productBuilderService.fetchEnv(env); // validate env exists
|
|
572
746
|
if (!product_env) {
|
|
573
747
|
throw new Error(`Env ${env} not found`);
|
|
@@ -582,7 +756,6 @@ class ProcessorService {
|
|
|
582
756
|
}
|
|
583
757
|
validateJSONFeatureInput(input, feature_input, additional_logs) {
|
|
584
758
|
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
759
|
(0, processor_utils_1.validateFeatureJSONInput)(input, feature_input);
|
|
587
760
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
588
761
|
}
|
|
@@ -593,7 +766,6 @@ class ProcessorService {
|
|
|
593
766
|
}
|
|
594
767
|
async splitSequenceIntoLevels(data, additional_logs) {
|
|
595
768
|
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
769
|
const levels = {};
|
|
598
770
|
const tagMap = new Map(data.map((seq) => [seq.tag, seq]));
|
|
599
771
|
const assignedLevels = new Map();
|
|
@@ -630,7 +802,6 @@ class ProcessorService {
|
|
|
630
802
|
}
|
|
631
803
|
async processSequenceLevels(additional_logs) {
|
|
632
804
|
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
805
|
const levelEvents = {};
|
|
635
806
|
Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
|
|
636
807
|
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
|
|
@@ -658,7 +829,6 @@ class ProcessorService {
|
|
|
658
829
|
successful_feature_execution = true;
|
|
659
830
|
}
|
|
660
831
|
else if (this.processingFailure) {
|
|
661
|
-
console.log("PROCESSING FAILURE", this.processingFailure);
|
|
662
832
|
message = 'Process feature - processing';
|
|
663
833
|
status = types_1.LogEventStatus.PROCESSING;
|
|
664
834
|
successful_feature_execution = false;
|
|
@@ -674,7 +844,7 @@ class ProcessorService {
|
|
|
674
844
|
return true;
|
|
675
845
|
}
|
|
676
846
|
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 }));
|
|
847
|
+
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
848
|
throw e;
|
|
679
849
|
}
|
|
680
850
|
}
|
|
@@ -702,7 +872,6 @@ class ProcessorService {
|
|
|
702
872
|
const { failure } = this.processingOutput;
|
|
703
873
|
const promises = failure.map((failed) => {
|
|
704
874
|
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
875
|
return this.processEvent(failed.event); // process events should also take care of this.processingOutput
|
|
707
876
|
}
|
|
708
877
|
if (failed.retries_left === 0 && !failed.allow_fail) {
|
|
@@ -747,7 +916,6 @@ class ProcessorService {
|
|
|
747
916
|
}
|
|
748
917
|
fetchActionRequestDependents(input, additional_logs) {
|
|
749
918
|
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
919
|
const dependents = [];
|
|
752
920
|
if (input.query) {
|
|
753
921
|
dependents.push(...this.fetchDependents(input.query, additional_logs));
|
|
@@ -779,7 +947,6 @@ class ProcessorService {
|
|
|
779
947
|
}
|
|
780
948
|
fetchDependents(obj, additional_logs) {
|
|
781
949
|
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
950
|
const dependants = [];
|
|
784
951
|
for (const key in obj) {
|
|
785
952
|
const value = obj[key];
|
|
@@ -790,8 +957,8 @@ class ProcessorService {
|
|
|
790
957
|
if (values[i].startsWith('$Sequence')) {
|
|
791
958
|
const stages = this.productBuilderService.extractStages(values[i]);
|
|
792
959
|
dependants.push({
|
|
793
|
-
sequence_tag: stages[0],
|
|
794
|
-
event_tag: stages[1],
|
|
960
|
+
sequence_tag: String(stages[0]),
|
|
961
|
+
event_tag: String(stages[1]),
|
|
795
962
|
});
|
|
796
963
|
}
|
|
797
964
|
else if (values[i].startsWith('$')) {
|
|
@@ -801,8 +968,8 @@ class ProcessorService {
|
|
|
801
968
|
if (arg.startsWith('$Sequence')) {
|
|
802
969
|
const stages = this.productBuilderService.extractStages(arg);
|
|
803
970
|
dependants.push({
|
|
804
|
-
sequence_tag: stages[0],
|
|
805
|
-
event_tag: stages[1],
|
|
971
|
+
sequence_tag: String(stages[0]),
|
|
972
|
+
event_tag: String(stages[1]),
|
|
806
973
|
});
|
|
807
974
|
}
|
|
808
975
|
});
|
|
@@ -821,7 +988,6 @@ class ProcessorService {
|
|
|
821
988
|
return dependants;
|
|
822
989
|
}
|
|
823
990
|
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
991
|
throw e;
|
|
826
992
|
}
|
|
827
993
|
}
|
|
@@ -829,7 +995,7 @@ class ProcessorService {
|
|
|
829
995
|
const dependants = [];
|
|
830
996
|
if (value.startsWith('$Sequence')) {
|
|
831
997
|
const stages = this.productBuilderService.extractStages(value);
|
|
832
|
-
dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
|
|
998
|
+
dependants.push({ sequence_tag: String(stages[0]), event_tag: String(stages[1]) });
|
|
833
999
|
}
|
|
834
1000
|
else if (value.startsWith('$')) {
|
|
835
1001
|
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(value);
|
|
@@ -838,8 +1004,8 @@ class ProcessorService {
|
|
|
838
1004
|
if (arg.startsWith('$Sequence')) {
|
|
839
1005
|
const stages = this.productBuilderService.extractStages(arg);
|
|
840
1006
|
dependants.push({
|
|
841
|
-
sequence_tag: stages[0],
|
|
842
|
-
event_tag: stages[1],
|
|
1007
|
+
sequence_tag: String(stages[0]),
|
|
1008
|
+
event_tag: String(stages[1]),
|
|
843
1009
|
});
|
|
844
1010
|
}
|
|
845
1011
|
else {
|
|
@@ -855,7 +1021,6 @@ class ProcessorService {
|
|
|
855
1021
|
}
|
|
856
1022
|
async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
|
|
857
1023
|
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
1024
|
const payload = {};
|
|
860
1025
|
const { body: actionBody, query: actionQuery, headers: actionHeaders, params: actionParams } = object;
|
|
861
1026
|
if (actionBody) {
|
|
@@ -912,8 +1077,8 @@ class ProcessorService {
|
|
|
912
1077
|
}
|
|
913
1078
|
async generatePayload(obj, event, additional_logs, sample = [], index = {}, loopIndex = null) {
|
|
914
1079
|
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
1080
|
const payload = {};
|
|
1081
|
+
console.log("Payload Construction", { obj, event, sample, index, loopIndex });
|
|
917
1082
|
const keys = Object.keys(obj);
|
|
918
1083
|
for (let i = 0; i < keys.length; i++) {
|
|
919
1084
|
const key = keys[i];
|
|
@@ -959,22 +1124,32 @@ class ProcessorService {
|
|
|
959
1124
|
const locatorFor$Index = (0, string_utils_1.validateAndLocateTag)(value);
|
|
960
1125
|
if (value.startsWith('$Auth{') && value.endsWith('}')) {
|
|
961
1126
|
// should only be allowed in apps
|
|
962
|
-
|
|
1127
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1128
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1129
|
+
return await this.generateAuthValue(stringStages, app, sample, additional_logs);
|
|
963
1130
|
}
|
|
964
1131
|
else if (value.startsWith('$Sequence{') && value.endsWith('}')) {
|
|
965
|
-
|
|
1132
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1133
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1134
|
+
return await this.generateSequenceValue(stringStages, locatorFor$Index, loopIndex); // pass
|
|
966
1135
|
}
|
|
967
1136
|
else if (value.startsWith('$Input{') && value.endsWith('}')) {
|
|
968
|
-
|
|
1137
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1138
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1139
|
+
return await this.generateInputValue(this.input.input, stringStages);
|
|
969
1140
|
}
|
|
970
1141
|
else if (value === '$Default') {
|
|
971
1142
|
return await this.generateDefaultValue(sample, Object.assign(Object.assign({}, index), { key }));
|
|
972
1143
|
}
|
|
973
1144
|
else if (value.startsWith('$Variable{') && value.endsWith('}')) {
|
|
974
|
-
|
|
1145
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1146
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1147
|
+
return await this.generateVariableValue(stringStages);
|
|
975
1148
|
}
|
|
976
1149
|
else if (value.startsWith('$Constant{') && value.endsWith('}')) {
|
|
977
|
-
|
|
1150
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1151
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1152
|
+
return await this.generateConstantValue(stringStages);
|
|
978
1153
|
}
|
|
979
1154
|
else if (value.startsWith('$Size{') || value.startsWith('$Length{')) {
|
|
980
1155
|
const { matchLength, matchSize } = (0, string_utils_1.checkLengthAndSizeMatches)(value);
|
|
@@ -1099,6 +1274,7 @@ class ProcessorService {
|
|
|
1099
1274
|
const placeholdersStr = match[1];
|
|
1100
1275
|
const separator = match[2];
|
|
1101
1276
|
const placeHolders = placeholdersStr.split(',').map((data) => data.trim());
|
|
1277
|
+
console.log('placeHolders', { placeHolders, separator });
|
|
1102
1278
|
const values = await Promise.all(placeHolders.map(async (holder) => {
|
|
1103
1279
|
return await this.generateStringValues(holder, app, additional_logs, sample, index, key, loopIndex);
|
|
1104
1280
|
}));
|
|
@@ -1417,6 +1593,7 @@ class ProcessorService {
|
|
|
1417
1593
|
}
|
|
1418
1594
|
async generateAuthValue(stages, app, sample, additional_logs) {
|
|
1419
1595
|
try {
|
|
1596
|
+
console.log("Generate Auth Data", { stages, app, sample });
|
|
1420
1597
|
let auth_data = await this.fetchAuthData(app, additional_logs); //TODO: should use stages[0]
|
|
1421
1598
|
// take the app tag in index 0..
|
|
1422
1599
|
if (!auth_data) {
|
|
@@ -1432,7 +1609,6 @@ class ProcessorService {
|
|
|
1432
1609
|
}
|
|
1433
1610
|
async fetchAuthData(app_tag, additional_logs) {
|
|
1434
1611
|
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
1612
|
const app = this.productBuilderService.fetchApp(app_tag);
|
|
1437
1613
|
if (!app) {
|
|
1438
1614
|
throw new Error(`App ${app_tag} not found in $Auth value`);
|
|
@@ -1444,6 +1620,7 @@ class ProcessorService {
|
|
|
1444
1620
|
if (!env.auth) {
|
|
1445
1621
|
throw new Error(`App ${app_tag} in auth needs to have a definition for auth in env: ${this.processEnv.slug}`);
|
|
1446
1622
|
}
|
|
1623
|
+
console.log("Envroment", env.auth);
|
|
1447
1624
|
let values = env.auth.values;
|
|
1448
1625
|
if (!values) {
|
|
1449
1626
|
// no auth values
|
|
@@ -1451,6 +1628,7 @@ class ProcessorService {
|
|
|
1451
1628
|
}
|
|
1452
1629
|
if (!env.auth.expiry || (env.auth.expiry && Date.now() > new Date(env.auth.expiry).getTime())) {
|
|
1453
1630
|
// refresh
|
|
1631
|
+
console.log("REFRESH DATA", env, app_tag);
|
|
1454
1632
|
values = await this.getAndStoreAuth(env, app_tag);
|
|
1455
1633
|
}
|
|
1456
1634
|
const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchProduct().private_key);
|
|
@@ -1563,7 +1741,18 @@ class ProcessorService {
|
|
|
1563
1741
|
parent_tag: event.event,
|
|
1564
1742
|
name: 'Process feature job',
|
|
1565
1743
|
};
|
|
1566
|
-
|
|
1744
|
+
const input = {
|
|
1745
|
+
env: event.env.slug,
|
|
1746
|
+
product: this.productTag,
|
|
1747
|
+
event: event.event,
|
|
1748
|
+
retries: event.retries,
|
|
1749
|
+
input: event.input,
|
|
1750
|
+
start_at: event.start_at || 0,
|
|
1751
|
+
cache: event.cache,
|
|
1752
|
+
session: this.input.session
|
|
1753
|
+
};
|
|
1754
|
+
// TODO: fix this
|
|
1755
|
+
return this.processJob(input, additional_logs);
|
|
1567
1756
|
}
|
|
1568
1757
|
}
|
|
1569
1758
|
catch (e) {
|
|
@@ -1587,16 +1776,25 @@ class ProcessorService {
|
|
|
1587
1776
|
}
|
|
1588
1777
|
return output;
|
|
1589
1778
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1779
|
+
async runJobs(job, additional_logs = {}) {
|
|
1780
|
+
if (job.name === types_1.FeatureEventTypes.ACTION) {
|
|
1781
|
+
await this.processAction(job.data);
|
|
1782
|
+
}
|
|
1592
1783
|
}
|
|
1593
1784
|
async processFailedAndWaiting() { }
|
|
1594
|
-
async
|
|
1595
|
-
var _a, _b, _c, _d;
|
|
1785
|
+
async fetchResult(process_id) {
|
|
1596
1786
|
const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
|
|
1597
1787
|
if (!result) {
|
|
1598
1788
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1599
1789
|
}
|
|
1790
|
+
await this.productBuilderService.initializeProduct(result.product_id);
|
|
1791
|
+
result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchProduct().private_key));
|
|
1792
|
+
result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchProduct().private_key));
|
|
1793
|
+
return result;
|
|
1794
|
+
}
|
|
1795
|
+
async generateOutput(process_id) {
|
|
1796
|
+
var _a, _b, _c, _d;
|
|
1797
|
+
const result = await this.fetchResult(process_id);
|
|
1600
1798
|
if (result.component === types_1.LogEventTypes.FEATURE) {
|
|
1601
1799
|
const additional_logs = {
|
|
1602
1800
|
parent_tag: result.input.tag,
|
|
@@ -1635,7 +1833,7 @@ class ProcessorService {
|
|
|
1635
1833
|
}
|
|
1636
1834
|
}
|
|
1637
1835
|
async resumeProcess(process_id) {
|
|
1638
|
-
const result =
|
|
1836
|
+
const result = await this.fetchResult(process_id);
|
|
1639
1837
|
if (!result) {
|
|
1640
1838
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1641
1839
|
}
|
|
@@ -1677,7 +1875,7 @@ class ProcessorService {
|
|
|
1677
1875
|
}
|
|
1678
1876
|
async replayProcess(process_id) {
|
|
1679
1877
|
var _a, _b, _c;
|
|
1680
|
-
const result =
|
|
1878
|
+
const result = await this.fetchResult(process_id);
|
|
1681
1879
|
if (!result) {
|
|
1682
1880
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1683
1881
|
}
|
|
@@ -1740,9 +1938,10 @@ class ProcessorService {
|
|
|
1740
1938
|
async getAndStoreAuth(appEnv, access_tag) {
|
|
1741
1939
|
try {
|
|
1742
1940
|
// const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.fetchProduct().private_key));
|
|
1743
|
-
const payload = appEnv.auth.data;
|
|
1941
|
+
const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.fetchProduct().private_key));
|
|
1744
1942
|
let app = await this.fetchThirdPartyApp(access_tag);
|
|
1745
1943
|
const auth = app.auths.find((item) => item.tag === appEnv.auth.auth_tag);
|
|
1944
|
+
console.log("JAMESY", auth);
|
|
1746
1945
|
if (!auth) {
|
|
1747
1946
|
// throw an error
|
|
1748
1947
|
throw new Error(`Cannot find auth ${appEnv.auth.auth_tag} on environment ${appEnv.product_env_slug}`);
|
|
@@ -1757,6 +1956,7 @@ class ProcessorService {
|
|
|
1757
1956
|
if (env.base_url) {
|
|
1758
1957
|
request_base_url = env.base_url;
|
|
1759
1958
|
}
|
|
1959
|
+
console.log("payloadabi!!!!", payload);
|
|
1760
1960
|
const results = await this.sendActionRequest(request_base_url, url, payload, method, appEnv.app_env_slug);
|
|
1761
1961
|
const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchProduct().private_key);
|
|
1762
1962
|
const productApp = this.productBuilderService.fetchApp(access_tag);
|
|
@@ -1805,7 +2005,6 @@ class ProcessorService {
|
|
|
1805
2005
|
}
|
|
1806
2006
|
async processConditionalCheck(event, additional_logs = {}) {
|
|
1807
2007
|
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
2008
|
const [, initiator, operator, value] = parts;
|
|
1810
2009
|
const initiatorValue = await this.generateStringValues(initiator, event.app, additional_logs);
|
|
1811
2010
|
let valueValue;
|
|
@@ -1817,7 +2016,6 @@ class ProcessorService {
|
|
|
1817
2016
|
else {
|
|
1818
2017
|
valueValue = value;
|
|
1819
2018
|
}
|
|
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
2019
|
const pass = (0, processor_utils_1.compareValues)(initiatorValue, operator, valueValue);
|
|
1822
2020
|
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
2021
|
if (!pass) {
|
|
@@ -1842,7 +2040,6 @@ class ProcessorService {
|
|
|
1842
2040
|
}
|
|
1843
2041
|
async extractLoopIndexes(event, additional_logs = {}) {
|
|
1844
2042
|
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
2043
|
const [, initiator, operator, value] = parts;
|
|
1847
2044
|
let valueValue;
|
|
1848
2045
|
if (!(0, string_utils_1.isNumeric)(value)) {
|
|
@@ -1877,8 +2074,9 @@ class ProcessorService {
|
|
|
1877
2074
|
const { envs: productEnvs, version } = productApp;
|
|
1878
2075
|
const { app_env_slug } = productEnvs.find((item) => item.product_env_slug === this.processEnv.slug);
|
|
1879
2076
|
additional_logs.app_env = app_env_slug;
|
|
2077
|
+
console.log(app, appEnvs);
|
|
1880
2078
|
const env = appEnvs.find((item) => item.slug === app_env_slug); // fetch the actuall app Environment variable
|
|
1881
|
-
if (!active) {
|
|
2079
|
+
if (!active && recipient_workspace_id !== this.baseLogs.workspace_id) {
|
|
1882
2080
|
throw new Error(`App ${event.app} version ${app.version} is not active`);
|
|
1883
2081
|
}
|
|
1884
2082
|
if (!env.active) {
|
|
@@ -1913,10 +2111,10 @@ class ProcessorService {
|
|
|
1913
2111
|
input: inputString,
|
|
1914
2112
|
privateKey: product.private_key,
|
|
1915
2113
|
expiry: productCache.expiry,
|
|
1916
|
-
});
|
|
2114
|
+
}, additional_logs);
|
|
1917
2115
|
if (check) {
|
|
1918
2116
|
result = JSON.parse(check);
|
|
1919
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run action -
|
|
2117
|
+
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
2118
|
if (returnValue) {
|
|
1921
2119
|
return result;
|
|
1922
2120
|
}
|
|
@@ -1955,18 +2153,18 @@ class ProcessorService {
|
|
|
1955
2153
|
component_tag: action_tag,
|
|
1956
2154
|
component_type: types_1.ProductComponents.ACTION,
|
|
1957
2155
|
product_tag: this.productTag,
|
|
1958
|
-
});
|
|
2156
|
+
}, additional_logs);
|
|
1959
2157
|
}
|
|
1960
2158
|
return result;
|
|
1961
2159
|
}
|
|
1962
2160
|
catch (e) {
|
|
1963
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), {
|
|
2161
|
+
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
2162
|
throw e;
|
|
1965
2163
|
}
|
|
1966
2164
|
}
|
|
1967
2165
|
async processRequest(payload, event, retries, additional_logs, returnValue = false) {
|
|
2166
|
+
var _a;
|
|
1968
2167
|
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
2168
|
const start = Date.now();
|
|
1971
2169
|
try {
|
|
1972
2170
|
let results = (0, processor_utils_1.generateMockData)(resource, env.slug, payloads);
|
|
@@ -1976,7 +2174,11 @@ class ProcessorService {
|
|
|
1976
2174
|
const end = Date.now();
|
|
1977
2175
|
this.requestTime += end - start;
|
|
1978
2176
|
this.totalRequests += 1;
|
|
1979
|
-
this.
|
|
2177
|
+
const { pricing_tag, pricing_cost, is_overage, currency } = await this.processPricingCost(Object.assign(Object.assign({}, additional_logs), { app_id, workspace_id: this.workspace_id }));
|
|
2178
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { pricing_tag,
|
|
2179
|
+
pricing_cost,
|
|
2180
|
+
currency,
|
|
2181
|
+
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
2182
|
end }));
|
|
1981
2183
|
await this.addToSuccessOutput(event, results, additional_logs);
|
|
1982
2184
|
if (returnValue) {
|
|
@@ -1988,11 +2190,16 @@ class ProcessorService {
|
|
|
1988
2190
|
}
|
|
1989
2191
|
catch (e) {
|
|
1990
2192
|
const end = Date.now();
|
|
2193
|
+
let error = e;
|
|
2194
|
+
if ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) {
|
|
2195
|
+
error = e.response.data;
|
|
2196
|
+
}
|
|
1991
2197
|
this.requestTime += end - start;
|
|
1992
2198
|
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,
|
|
2199
|
+
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
2200
|
end }));
|
|
1995
2201
|
try {
|
|
2202
|
+
console.log(e);
|
|
1996
2203
|
const value = await this.addToFailureOutput(e, event, {
|
|
1997
2204
|
request_base_url,
|
|
1998
2205
|
resource,
|
|
@@ -2017,11 +2224,75 @@ class ProcessorService {
|
|
|
2017
2224
|
}
|
|
2018
2225
|
}
|
|
2019
2226
|
}
|
|
2227
|
+
async processPricingCost(additional_logs) {
|
|
2228
|
+
try {
|
|
2229
|
+
const { app_id, workspace_id } = additional_logs;
|
|
2230
|
+
if (!app_id || !workspace_id) {
|
|
2231
|
+
throw new Error('app_id and workspace_id are required in additional_logs');
|
|
2232
|
+
}
|
|
2233
|
+
const primaryPricing = this.pricingService.fetchPricing();
|
|
2234
|
+
const overagePricing = this.pricingService.fetchOveragePricing();
|
|
2235
|
+
const requests = await this.requestTrackerService.incrementRequest(app_id, workspace_id);
|
|
2236
|
+
const limitCheck = (0, request_utils_1.checkLimitExceeded)(requests, primaryPricing.limits);
|
|
2237
|
+
let finalCost = 0;
|
|
2238
|
+
let usedPricing = primaryPricing;
|
|
2239
|
+
let isOverage = false;
|
|
2240
|
+
let finalCurrency = primaryPricing.currency;
|
|
2241
|
+
if ((0, request_utils_1.isFreeTag)(primaryPricing.pricing_tag)) {
|
|
2242
|
+
if (limitCheck.exceeded) {
|
|
2243
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2244
|
+
finalCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2245
|
+
usedPricing = overagePricing;
|
|
2246
|
+
isOverage = true;
|
|
2247
|
+
finalCurrency = overagePricing.currency;
|
|
2248
|
+
}
|
|
2249
|
+
else {
|
|
2250
|
+
finalCost = 0;
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
else {
|
|
2254
|
+
if (limitCheck.exceeded) {
|
|
2255
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2256
|
+
const overageCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2257
|
+
finalCost = overageCost;
|
|
2258
|
+
isOverage = true;
|
|
2259
|
+
}
|
|
2260
|
+
else {
|
|
2261
|
+
const pricingRequests = (0, request_utils_1.calculateRequests)(requests);
|
|
2262
|
+
finalCost = (0, request_utils_1.calculateCost)(primaryPricing.pricing_mode, primaryPricing.unit_price, pricingRequests);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - success', data: {
|
|
2266
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2267
|
+
cost: finalCost,
|
|
2268
|
+
currency: finalCurrency,
|
|
2269
|
+
is_overage: isOverage,
|
|
2270
|
+
requests: requests,
|
|
2271
|
+
limit_exceeded: limitCheck.exceeded
|
|
2272
|
+
}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2273
|
+
return {
|
|
2274
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2275
|
+
pricing_cost: Math.round(finalCost * 100) / 100,
|
|
2276
|
+
currency: finalCurrency,
|
|
2277
|
+
is_overage: isOverage,
|
|
2278
|
+
requests_made: requests,
|
|
2279
|
+
limit_exceeded: limitCheck.exceeded,
|
|
2280
|
+
exceeded_limits: limitCheck.exceededLimits
|
|
2281
|
+
};
|
|
2282
|
+
}
|
|
2283
|
+
catch (e) {
|
|
2284
|
+
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 }));
|
|
2285
|
+
throw e;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2020
2288
|
async addToSuccessOutput(event, output, additional_logs) {
|
|
2021
2289
|
// Remove event from failed, skipped, and waiting arrays
|
|
2022
2290
|
this.processingOutput.failure = this.processingOutput.failure.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2023
2291
|
this.processingOutput.skipped = this.processingOutput.skipped.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2024
2292
|
this.processingOutput.waiting = this.processingOutput.waiting.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2293
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2294
|
+
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2295
|
+
}
|
|
2025
2296
|
this.processingOutput.success.push({ event, output });
|
|
2026
2297
|
await this.processWaitingEvents(additional_logs);
|
|
2027
2298
|
if (this.checkIsSuccessful() && this.doneWithProcessing) {
|
|
@@ -2076,6 +2347,12 @@ class ProcessorService {
|
|
|
2076
2347
|
max = metrices.max;
|
|
2077
2348
|
}
|
|
2078
2349
|
const { allow_fail, retries } = event;
|
|
2350
|
+
let retryable = true;
|
|
2351
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2352
|
+
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2353
|
+
if (!this.feature || (this.feature && !event.allow_fail))
|
|
2354
|
+
retryable = false;
|
|
2355
|
+
}
|
|
2079
2356
|
let retries_left = retries || max;
|
|
2080
2357
|
if (exists > -1) {
|
|
2081
2358
|
retries_left = this.processingOutput.failure[exists].retries_left - 1;
|
|
@@ -2122,7 +2399,7 @@ class ProcessorService {
|
|
|
2122
2399
|
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
2400
|
//throw new Error("Run out of retries")
|
|
2124
2401
|
this.end = Date.now();
|
|
2125
|
-
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
2402
|
+
await this.writeResult(types_1.LogEventStatus.FAIL, retryable);
|
|
2126
2403
|
await this.logService.publish();
|
|
2127
2404
|
//throw new Error("Terminate Process")
|
|
2128
2405
|
}
|
|
@@ -2133,52 +2410,15 @@ class ProcessorService {
|
|
|
2133
2410
|
}
|
|
2134
2411
|
}
|
|
2135
2412
|
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
|
-
}
|
|
2413
|
+
var _a;
|
|
2414
|
+
const isSpecial = error_code === '1000';
|
|
2415
|
+
if (isSpecial) {
|
|
2416
|
+
return { allow_fail: true, max: (retries === null || retries === void 0 ? void 0 : retries.max) || 0, retry_at: 500 };
|
|
2417
|
+
}
|
|
2418
|
+
const policy = (_a = retries === null || retries === void 0 ? void 0 : retries.policy) === null || _a === void 0 ? void 0 : _a[error_code];
|
|
2419
|
+
const allow_fail = policy ? policy.available : true;
|
|
2420
|
+
const retry_at = policy ? policy.lag : 0;
|
|
2421
|
+
const max = (retries === null || retries === void 0 ? void 0 : retries.max) || 0;
|
|
2182
2422
|
return { allow_fail, max, retry_at };
|
|
2183
2423
|
}
|
|
2184
2424
|
async sendActionRequest(base_url, resource, payload, method, env) {
|
|
@@ -2204,6 +2444,7 @@ class ProcessorService {
|
|
|
2204
2444
|
timeout: 15000,
|
|
2205
2445
|
withCredentials: false
|
|
2206
2446
|
};
|
|
2447
|
+
console.log("REQUEST!!!!", request);
|
|
2207
2448
|
const response = await axios_1.default.request(request);
|
|
2208
2449
|
return response.data;
|
|
2209
2450
|
}
|
|
@@ -2221,7 +2462,7 @@ class ProcessorService {
|
|
|
2221
2462
|
name: 'Process Storage',
|
|
2222
2463
|
};
|
|
2223
2464
|
try {
|
|
2224
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2465
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2225
2466
|
this.input = input;
|
|
2226
2467
|
this.start = Date.now();
|
|
2227
2468
|
this.component = types_1.LogEventTypes.STORAGE;
|
|
@@ -2239,7 +2480,6 @@ class ProcessorService {
|
|
|
2239
2480
|
if (!productEnv.active) {
|
|
2240
2481
|
throw new Error(`Environment ${env} is not active`);
|
|
2241
2482
|
}
|
|
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
2483
|
const payload = {
|
|
2244
2484
|
type: types_1.FeatureEventTypes.STORAGE,
|
|
2245
2485
|
event,
|
|
@@ -2254,7 +2494,7 @@ class ProcessorService {
|
|
|
2254
2494
|
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
2495
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2256
2496
|
await this.logService.publish();
|
|
2257
|
-
return result;
|
|
2497
|
+
return Object.assign(Object.assign({}, result), { process_id: this.process_id });
|
|
2258
2498
|
}
|
|
2259
2499
|
catch (e) {
|
|
2260
2500
|
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 +2515,7 @@ class ProcessorService {
|
|
|
2275
2515
|
name: `Subscribe to broker topic`,
|
|
2276
2516
|
};
|
|
2277
2517
|
try {
|
|
2278
|
-
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2518
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2279
2519
|
this.start = Date.now();
|
|
2280
2520
|
this.productTag = data.product;
|
|
2281
2521
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
@@ -2324,7 +2564,7 @@ class ProcessorService {
|
|
|
2324
2564
|
name: 'Publish to broker topic',
|
|
2325
2565
|
};
|
|
2326
2566
|
try {
|
|
2327
|
-
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2567
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2328
2568
|
this.start = Date.now();
|
|
2329
2569
|
// clone
|
|
2330
2570
|
this.clone = (0, processor_utils_1.structuredClone)(data.input);
|
|
@@ -2341,7 +2581,6 @@ class ProcessorService {
|
|
|
2341
2581
|
if (!productEnv.active) {
|
|
2342
2582
|
throw new Error(`Environment ${data.env} is not active`);
|
|
2343
2583
|
}
|
|
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
2584
|
const payload = {
|
|
2346
2585
|
type: types_1.FeatureEventTypes.PUBLISH,
|
|
2347
2586
|
event: data.event,
|
|
@@ -2365,7 +2604,113 @@ class ProcessorService {
|
|
|
2365
2604
|
return { process_id: this.process_id };
|
|
2366
2605
|
}
|
|
2367
2606
|
}
|
|
2368
|
-
async processJob(job) {
|
|
2607
|
+
async processJob(job, additional_logs = {}) {
|
|
2608
|
+
var _a;
|
|
2609
|
+
const productJob = this.productBuilderService.fetchJob(job.event);
|
|
2610
|
+
if (!productJob) {
|
|
2611
|
+
throw new Error(`Job ${job.event} not found`);
|
|
2612
|
+
}
|
|
2613
|
+
await this.validateActionDataMappingInput(job.input, productJob.type);
|
|
2614
|
+
const NOW = Date.now();
|
|
2615
|
+
// Treat anything above Jan 1, 2023 as a timestamp (to be safe and future-proof)
|
|
2616
|
+
const IS_PROBABLY_TIMESTAMP = job.start_at > 1672531200000;
|
|
2617
|
+
const delay = Math.max(0, IS_PROBABLY_TIMESTAMP ? job.start_at - NOW : job.start_at);
|
|
2618
|
+
let jobInput;
|
|
2619
|
+
if (productJob.type === types_1.JobEventTypes.ACTION) {
|
|
2620
|
+
const input = {
|
|
2621
|
+
env: job.env,
|
|
2622
|
+
product: job.product,
|
|
2623
|
+
app: productJob.app,
|
|
2624
|
+
cache: job.cache,
|
|
2625
|
+
input: job.input,
|
|
2626
|
+
event: job.event,
|
|
2627
|
+
session: job.session
|
|
2628
|
+
};
|
|
2629
|
+
jobInput = input;
|
|
2630
|
+
}
|
|
2631
|
+
else if (productJob.type === types_1.JobEventTypes.DATABASE_ACTION) {
|
|
2632
|
+
const input = {
|
|
2633
|
+
env: job.env,
|
|
2634
|
+
product: job.product,
|
|
2635
|
+
cache: job.cache,
|
|
2636
|
+
input: job.input,
|
|
2637
|
+
event: job.event,
|
|
2638
|
+
session: job.session,
|
|
2639
|
+
};
|
|
2640
|
+
jobInput = input;
|
|
2641
|
+
}
|
|
2642
|
+
else if (productJob.type === types_1.JobEventTypes.FALLBACK || productJob.type === types_1.JobEventTypes.QUOTA || productJob.type === types_1.JobEventTypes.FEATURE) {
|
|
2643
|
+
const input = {
|
|
2644
|
+
input: job.input,
|
|
2645
|
+
product: job.product,
|
|
2646
|
+
env: job.env,
|
|
2647
|
+
tag: job.event,
|
|
2648
|
+
session: job.session,
|
|
2649
|
+
cache: job.cache,
|
|
2650
|
+
};
|
|
2651
|
+
jobInput = input;
|
|
2652
|
+
}
|
|
2653
|
+
else if (productJob.type === types_1.JobEventTypes.NOTIFICATION) {
|
|
2654
|
+
const input = {
|
|
2655
|
+
env: job.env,
|
|
2656
|
+
product: job.product,
|
|
2657
|
+
event: job.event,
|
|
2658
|
+
input: job.input,
|
|
2659
|
+
session: job.session,
|
|
2660
|
+
cache: job.cache
|
|
2661
|
+
};
|
|
2662
|
+
jobInput = input;
|
|
2663
|
+
}
|
|
2664
|
+
else if (productJob.type === types_1.JobEventTypes.PUBLISH) {
|
|
2665
|
+
const input = {
|
|
2666
|
+
env: job.env,
|
|
2667
|
+
product: job.product,
|
|
2668
|
+
event: job.event,
|
|
2669
|
+
cache: job.cache,
|
|
2670
|
+
session: job.session,
|
|
2671
|
+
input: job.input
|
|
2672
|
+
};
|
|
2673
|
+
jobInput = input;
|
|
2674
|
+
}
|
|
2675
|
+
else if (productJob.type === types_1.JobEventTypes.STORAGE) {
|
|
2676
|
+
const input = {
|
|
2677
|
+
env: job.env,
|
|
2678
|
+
product: job.product,
|
|
2679
|
+
event: job.event,
|
|
2680
|
+
cache: job.cache,
|
|
2681
|
+
session: job.session,
|
|
2682
|
+
input: job.input
|
|
2683
|
+
};
|
|
2684
|
+
jobInput = input;
|
|
2685
|
+
}
|
|
2686
|
+
else {
|
|
2687
|
+
throw new Error(`Job type ${productJob.type} not supported`);
|
|
2688
|
+
}
|
|
2689
|
+
const options = {};
|
|
2690
|
+
// Handle `delay` only if repeat.every is not defined
|
|
2691
|
+
if (!((_a = job.repeat) === null || _a === void 0 ? void 0 : _a.every)) {
|
|
2692
|
+
options.delay = delay;
|
|
2693
|
+
}
|
|
2694
|
+
// Add repeat config if defined
|
|
2695
|
+
if (job.repeat) {
|
|
2696
|
+
const { every, cron, tz, limit, endDate } = job.repeat;
|
|
2697
|
+
options.repeat = cron
|
|
2698
|
+
? {
|
|
2699
|
+
cron,
|
|
2700
|
+
tz,
|
|
2701
|
+
limit,
|
|
2702
|
+
endDate,
|
|
2703
|
+
}
|
|
2704
|
+
: every
|
|
2705
|
+
? {
|
|
2706
|
+
every,
|
|
2707
|
+
limit,
|
|
2708
|
+
endDate,
|
|
2709
|
+
}
|
|
2710
|
+
: undefined;
|
|
2711
|
+
}
|
|
2712
|
+
await this.queues.jobs.add(productJob.type, jobInput, options);
|
|
2713
|
+
}
|
|
2369
2714
|
async sendExpoNotification(payload, device_tokens) {
|
|
2370
2715
|
const message = {
|
|
2371
2716
|
to: device_tokens,
|
|
@@ -2404,24 +2749,18 @@ class ProcessorService {
|
|
|
2404
2749
|
}
|
|
2405
2750
|
}
|
|
2406
2751
|
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
2752
|
(0, processor_utils_1.validateNotification)(template, payload);
|
|
2409
2753
|
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
2754
|
const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
|
|
2412
2755
|
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
2756
|
await this.sendExpoNotification({ title, body, data }, payload.device_tokens);
|
|
2415
2757
|
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
2758
|
}
|
|
2417
2759
|
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
2760
|
(0, processor_utils_1.validateNotification)(template, payload);
|
|
2420
2761
|
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
2762
|
const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
|
|
2423
2763
|
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
2764
|
await this.sendFirebaseNotification({ title, body, data }, payload.device_tokens, notification.credentials);
|
|
2426
2765
|
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
2766
|
}
|
|
@@ -2431,8 +2770,6 @@ class ProcessorService {
|
|
|
2431
2770
|
const input = notification.input;
|
|
2432
2771
|
try {
|
|
2433
2772
|
//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
2773
|
const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
|
|
2437
2774
|
const message = this.productBuilderService.fetchNotificationMessage(event);
|
|
2438
2775
|
if (!message) {
|
|
@@ -2452,15 +2789,23 @@ class ProcessorService {
|
|
|
2452
2789
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2453
2790
|
}));
|
|
2454
2791
|
//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
2792
|
if (push && notifications.type === types_1.Notifiers.EXPO) {
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2793
|
+
try {
|
|
2794
|
+
await this.ProcessExpoNotification(notifications, message, input.push_notification, additional_logs);
|
|
2795
|
+
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 }));
|
|
2796
|
+
}
|
|
2797
|
+
catch (e) {
|
|
2798
|
+
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 }));
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
if (push && notifications.type === types_1.Notifiers.FIREBASE) {
|
|
2802
|
+
try {
|
|
2803
|
+
await this.ProcessFirebaseNotification(notifications, message, input.push_notification, additional_logs);
|
|
2804
|
+
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 }));
|
|
2805
|
+
}
|
|
2806
|
+
catch (e) {
|
|
2807
|
+
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 }));
|
|
2808
|
+
}
|
|
2464
2809
|
}
|
|
2465
2810
|
if (email && emails) {
|
|
2466
2811
|
input.email.subject = await this.generatePayload(input.email.subject, notification, additional_logs, message.email_data.filter((data) => data.parent_key === 'subject'));
|
|
@@ -2472,37 +2817,28 @@ class ProcessorService {
|
|
|
2472
2817
|
}));
|
|
2473
2818
|
//await this.inputService.validateInput(validationPayload, message.email_data);
|
|
2474
2819
|
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
2820
|
const { sender_email: from } = emails, auth = __rest(emails, ["sender_email"]);
|
|
2478
2821
|
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
2822
|
const templateMaker = (0, handlebars_1.compile)(email.template);
|
|
2485
2823
|
const template = templateMaker(input.email.template);
|
|
2486
2824
|
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 }));
|
|
2825
|
+
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
2826
|
const mailOptions = {
|
|
2489
2827
|
from,
|
|
2490
2828
|
to: input.email.recipients,
|
|
2491
2829
|
subject,
|
|
2492
2830
|
template,
|
|
2493
2831
|
};
|
|
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
2832
|
try {
|
|
2496
2833
|
const transporter = await (0, processor_utils_1.mailerClient)(auth);
|
|
2497
2834
|
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 }));
|
|
2835
|
+
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
2836
|
}
|
|
2500
2837
|
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 }));
|
|
2838
|
+
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
2839
|
}
|
|
2503
2840
|
}
|
|
2504
2841
|
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
2842
|
const payload = {
|
|
2507
2843
|
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
2844
|
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 +2854,29 @@ class ProcessorService {
|
|
|
2518
2854
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2519
2855
|
}));
|
|
2520
2856
|
//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
2857
|
const url = new URL(callbacks.url);
|
|
2523
2858
|
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
2859
|
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 }));
|
|
2860
|
+
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
2861
|
}
|
|
2528
2862
|
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 }));
|
|
2863
|
+
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
2864
|
}
|
|
2531
2865
|
}
|
|
2532
2866
|
if (sms && smses) {
|
|
2533
2867
|
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
2868
|
input.sms.body = await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body);
|
|
2536
2869
|
const SmsClient = await (0, sms_repo_1.loadSMSClient)();
|
|
2537
2870
|
const smsClient = new SmsClient(smses);
|
|
2538
2871
|
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
2872
|
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 }));
|
|
2873
|
+
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
2874
|
}
|
|
2542
2875
|
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 }));
|
|
2876
|
+
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
2877
|
}
|
|
2545
2878
|
}
|
|
2546
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), {
|
|
2879
|
+
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
2880
|
}
|
|
2548
2881
|
catch (e) {
|
|
2549
2882
|
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 +3061,6 @@ class ProcessorService {
|
|
|
2728
3061
|
const input = data.input;
|
|
2729
3062
|
try {
|
|
2730
3063
|
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
3064
|
const storage = await this.productBuilderService.fetchStorage(event);
|
|
2734
3065
|
const storageEnv = storage.envs.find((el) => el.slug === env.slug);
|
|
2735
3066
|
if (!storageEnv) {
|
|
@@ -2749,19 +3080,17 @@ class ProcessorService {
|
|
|
2749
3080
|
input: inputString,
|
|
2750
3081
|
privateKey: product.private_key,
|
|
2751
3082
|
expiry: productCache.expiry,
|
|
2752
|
-
});
|
|
3083
|
+
}, additional_logs);
|
|
2753
3084
|
if (check) {
|
|
2754
3085
|
result = JSON.parse(check);
|
|
2755
3086
|
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
3087
|
return result;
|
|
2757
3088
|
}
|
|
2758
3089
|
}
|
|
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
3090
|
input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
|
|
2761
3091
|
input.fileName = input.fileName ? await this.generateStringValues(input.fileName, '', additional_logs, []) : undefined;
|
|
2762
3092
|
input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
|
|
2763
3093
|
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
3094
|
if (cache_tag && this.redisClient) {
|
|
2766
3095
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
2767
3096
|
if (!productCache) {
|
|
@@ -2777,12 +3106,11 @@ class ProcessorService {
|
|
|
2777
3106
|
component_tag: event,
|
|
2778
3107
|
component_type: types_1.ProductComponents.STORAGE,
|
|
2779
3108
|
product_tag: this.productTag,
|
|
2780
|
-
});
|
|
3109
|
+
}, additional_logs);
|
|
2781
3110
|
}
|
|
2782
3111
|
return result;
|
|
2783
3112
|
}
|
|
2784
3113
|
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
3114
|
throw e;
|
|
2787
3115
|
}
|
|
2788
3116
|
}
|
|
@@ -2791,8 +3119,6 @@ class ProcessorService {
|
|
|
2791
3119
|
const input = db_action.input;
|
|
2792
3120
|
try {
|
|
2793
3121
|
//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
3122
|
const [database_tag, action_tag] = event.split(':');
|
|
2797
3123
|
const product = this.productBuilderService.fetchProduct();
|
|
2798
3124
|
const database = await this.productBuilderService.fetchDatabase(database_tag);
|
|
@@ -2802,7 +3128,6 @@ class ProcessorService {
|
|
|
2802
3128
|
throw new Error(`Database env for ${env.slug} not found`);
|
|
2803
3129
|
}
|
|
2804
3130
|
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
3131
|
input.data = await this.generatePayload(input.data, db_action, additional_logs, databaseAction.data);
|
|
2807
3132
|
if (Array.isArray(input.data)) {
|
|
2808
3133
|
await Promise.all(input.data.map(async (d) => {
|
|
@@ -2830,11 +3155,9 @@ class ProcessorService {
|
|
|
2830
3155
|
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
3156
|
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
2832
3157
|
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
3158
|
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
3159
|
}
|
|
2836
3160
|
}
|
|
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
3161
|
let result;
|
|
2839
3162
|
if (cache_tag && this.redisClient) {
|
|
2840
3163
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
@@ -2847,7 +3170,7 @@ class ProcessorService {
|
|
|
2847
3170
|
input: inputString,
|
|
2848
3171
|
privateKey: product.private_key,
|
|
2849
3172
|
expiry: productCache.expiry,
|
|
2850
|
-
});
|
|
3173
|
+
}, additional_logs);
|
|
2851
3174
|
if (check) {
|
|
2852
3175
|
result = JSON.parse(check);
|
|
2853
3176
|
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 +3206,6 @@ class ProcessorService {
|
|
|
2883
3206
|
}
|
|
2884
3207
|
//await this.logService.publish();
|
|
2885
3208
|
// 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
3209
|
await this.addToSuccessOutput(db_action, result, additional_logs);
|
|
2888
3210
|
if (cache_tag && this.redisClient) {
|
|
2889
3211
|
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
@@ -2900,8 +3222,9 @@ class ProcessorService {
|
|
|
2900
3222
|
product_tag: this.productTag,
|
|
2901
3223
|
component_tag: database_tag,
|
|
2902
3224
|
component_type: types_1.ProductComponents.DATABASE_ACTION,
|
|
2903
|
-
});
|
|
3225
|
+
}, additional_logs);
|
|
2904
3226
|
}
|
|
3227
|
+
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
3228
|
return result;
|
|
2906
3229
|
}
|
|
2907
3230
|
catch (e) {
|
|
@@ -2914,8 +3237,6 @@ class ProcessorService {
|
|
|
2914
3237
|
const input = data.input;
|
|
2915
3238
|
try {
|
|
2916
3239
|
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
3240
|
const [brokerTag, topicTag] = event.split(':');
|
|
2920
3241
|
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
2921
3242
|
if (!broker) {
|
|
@@ -2941,12 +3262,13 @@ class ProcessorService {
|
|
|
2941
3262
|
url = queueUrl.url;
|
|
2942
3263
|
}
|
|
2943
3264
|
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
3265
|
const createBrokerService = await loadBrokerService();
|
|
2946
3266
|
if (createBrokerService) {
|
|
2947
3267
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
2948
3268
|
await brokerService.subscribe(url, input.callback);
|
|
2949
|
-
|
|
3269
|
+
if (this.feature) {
|
|
3270
|
+
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 }));
|
|
3271
|
+
}
|
|
2950
3272
|
return;
|
|
2951
3273
|
}
|
|
2952
3274
|
else {
|
|
@@ -2964,8 +3286,6 @@ class ProcessorService {
|
|
|
2964
3286
|
const input = data.input;
|
|
2965
3287
|
try {
|
|
2966
3288
|
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
3289
|
const [brokerTag, topicTag] = event.split(':');
|
|
2970
3290
|
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
2971
3291
|
if (!broker) {
|
|
@@ -2991,12 +3311,13 @@ class ProcessorService {
|
|
|
2991
3311
|
url = queueUrl.url;
|
|
2992
3312
|
}
|
|
2993
3313
|
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
3314
|
const createBrokerService = await loadBrokerService();
|
|
2996
3315
|
if (createBrokerService) {
|
|
2997
3316
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
2998
3317
|
await brokerService.publish(url, input.message);
|
|
2999
|
-
|
|
3318
|
+
if (this.feature) {
|
|
3319
|
+
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 }));
|
|
3320
|
+
}
|
|
3000
3321
|
return;
|
|
3001
3322
|
}
|
|
3002
3323
|
else {
|
|
@@ -3041,6 +3362,7 @@ class ProcessorService {
|
|
|
3041
3362
|
url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchProduct().private_key),
|
|
3042
3363
|
provider: storageEnv.type,
|
|
3043
3364
|
product: this.productTag,
|
|
3365
|
+
process_id: this.process_id,
|
|
3044
3366
|
workspace_id: this.workspace_id,
|
|
3045
3367
|
type: input.mimeType,
|
|
3046
3368
|
event: data.event,
|
|
@@ -3091,18 +3413,19 @@ class ProcessorService {
|
|
|
3091
3413
|
return value;
|
|
3092
3414
|
}
|
|
3093
3415
|
}
|
|
3094
|
-
async writeResult(status) {
|
|
3416
|
+
async writeResult(status, retryable = true) {
|
|
3095
3417
|
this.processorApiService.saveResult({
|
|
3096
3418
|
status,
|
|
3097
3419
|
component: this.component,
|
|
3098
3420
|
start: this.start,
|
|
3099
3421
|
end: this.end,
|
|
3100
|
-
|
|
3422
|
+
retryable,
|
|
3423
|
+
result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchProduct().private_key),
|
|
3101
3424
|
process_id: this.process_id,
|
|
3102
3425
|
feature_id: this.feature ? this.feature._id : null,
|
|
3103
3426
|
product_id: this.productId,
|
|
3104
3427
|
env: this.processEnv.slug,
|
|
3105
|
-
input: this.input,
|
|
3428
|
+
input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchProduct().private_key),
|
|
3106
3429
|
}, this.getUserAccess());
|
|
3107
3430
|
}
|
|
3108
3431
|
async validateActionDataMappingInput(input, type) {
|
|
@@ -3134,7 +3457,7 @@ class ProcessorService {
|
|
|
3134
3457
|
this.component = types_1.LogEventTypes.ACTION;
|
|
3135
3458
|
try {
|
|
3136
3459
|
// validate input do not allow $Sequence or $Length and $Size of $Input
|
|
3137
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3460
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3138
3461
|
this.input = action;
|
|
3139
3462
|
this.start = Date.now();
|
|
3140
3463
|
this.productTag = product_tag;
|
|
@@ -3148,6 +3471,7 @@ class ProcessorService {
|
|
|
3148
3471
|
data: input,
|
|
3149
3472
|
};
|
|
3150
3473
|
await this.intializeProduct(additional_logs);
|
|
3474
|
+
await this.initializePricing(additional_logs, app);
|
|
3151
3475
|
this.process_id = process_id;
|
|
3152
3476
|
this.baseLogs.product_id = this.productId;
|
|
3153
3477
|
const productEnv = this.fetchEnv(env, additional_logs);
|
|
@@ -3155,7 +3479,6 @@ class ProcessorService {
|
|
|
3155
3479
|
if (!productEnv.active) {
|
|
3156
3480
|
throw new Error(`Environment ${env} is not active`);
|
|
3157
3481
|
}
|
|
3158
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action initiated', status: types_1.LogEventStatus.PROCESSING }));
|
|
3159
3482
|
const result = await this.runAction({
|
|
3160
3483
|
type: types_1.FeatureEventTypes.ACTION,
|
|
3161
3484
|
event,
|
|
@@ -3173,7 +3496,8 @@ class ProcessorService {
|
|
|
3173
3496
|
return result;
|
|
3174
3497
|
}
|
|
3175
3498
|
catch (e) {
|
|
3176
|
-
|
|
3499
|
+
console.log("ERRRRROORRRRR!!!!!!", e);
|
|
3500
|
+
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
3501
|
this.end = Date.now();
|
|
3178
3502
|
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
3179
3503
|
await this.logService.publish();
|
|
@@ -3195,7 +3519,7 @@ class ProcessorService {
|
|
|
3195
3519
|
name: 'Process database action',
|
|
3196
3520
|
};
|
|
3197
3521
|
try {
|
|
3198
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3522
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3199
3523
|
this.input = action;
|
|
3200
3524
|
this.start = Date.now();
|
|
3201
3525
|
this.productTag = product_tag;
|
|
@@ -3210,7 +3534,6 @@ class ProcessorService {
|
|
|
3210
3534
|
if (!productEnv.active) {
|
|
3211
3535
|
throw new Error(`Environment ${env} is not active`);
|
|
3212
3536
|
}
|
|
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
3537
|
const payload = {
|
|
3215
3538
|
type: types_1.FeatureEventTypes.DB_ACTION,
|
|
3216
3539
|
event,
|
|
@@ -3250,7 +3573,7 @@ class ProcessorService {
|
|
|
3250
3573
|
name: 'Process Notification',
|
|
3251
3574
|
};
|
|
3252
3575
|
try {
|
|
3253
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3576
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3254
3577
|
this.input = action;
|
|
3255
3578
|
this.start = Date.now();
|
|
3256
3579
|
this.productTag = product_tag;
|
|
@@ -3265,7 +3588,6 @@ class ProcessorService {
|
|
|
3265
3588
|
if (!productEnv.active) {
|
|
3266
3589
|
throw new Error(`Environment ${env} is not active`);
|
|
3267
3590
|
}
|
|
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
3591
|
const payload = {
|
|
3270
3592
|
type: types_1.FeatureEventTypes.NOTIFICATION,
|
|
3271
3593
|
event,
|
|
@@ -3309,7 +3631,7 @@ class ProcessorService {
|
|
|
3309
3631
|
public_key: this.public_key,
|
|
3310
3632
|
};
|
|
3311
3633
|
}
|
|
3312
|
-
async addToCache(payload) {
|
|
3634
|
+
async addToCache(payload, additional_logs) {
|
|
3313
3635
|
if (!this.redisClient) {
|
|
3314
3636
|
throw 'redis client not setup';
|
|
3315
3637
|
}
|
|
@@ -3325,13 +3647,15 @@ class ProcessorService {
|
|
|
3325
3647
|
product_tag,
|
|
3326
3648
|
component_tag,
|
|
3327
3649
|
component_type }), this.getUserAccess());
|
|
3650
|
+
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
3651
|
await this.redisClient.hSet(key, 'data', encryptedData);
|
|
3329
3652
|
await this.redisClient.hSet(key, 'lastUpdated', timestamp);
|
|
3330
3653
|
}
|
|
3331
|
-
async fetchFromCache(payload) {
|
|
3654
|
+
async fetchFromCache(payload, additional_logs) {
|
|
3332
3655
|
var _a;
|
|
3333
3656
|
const { input, privateKey, cache_tag, expiry } = payload;
|
|
3334
3657
|
const key = `${cache_tag}-${CryptoJS.SHA512(input)}`;
|
|
3658
|
+
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
3659
|
if (!this.redisClient) {
|
|
3336
3660
|
return null;
|
|
3337
3661
|
}
|
|
@@ -3339,8 +3663,10 @@ class ProcessorService {
|
|
|
3339
3663
|
if (!record || !record.data || !record.lastUpdated) {
|
|
3340
3664
|
const checkRemote = await this.processorApiService.fetchRemoteCacheByKey(key, this.getUserAccess());
|
|
3341
3665
|
if (!checkRemote) {
|
|
3666
|
+
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
3667
|
return null;
|
|
3343
3668
|
}
|
|
3669
|
+
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
3670
|
record = { data: checkRemote.value, expiresAt: (_a = checkRemote.expiry) === null || _a === void 0 ? void 0 : _a.getTime().toString() };
|
|
3345
3671
|
}
|
|
3346
3672
|
if (record.lastUpdated) {
|
|
@@ -3348,13 +3674,42 @@ class ProcessorService {
|
|
|
3348
3674
|
if (expiry) {
|
|
3349
3675
|
const expiryTime = lastUpdated + expiry;
|
|
3350
3676
|
if (Date.now() > expiryTime) {
|
|
3677
|
+
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
3678
|
await this.redisClient.del(key);
|
|
3352
3679
|
return null;
|
|
3353
3680
|
}
|
|
3354
3681
|
}
|
|
3355
3682
|
}
|
|
3683
|
+
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
3684
|
return (0, processor_utils_1.decrypt)(record.data, privateKey);
|
|
3357
3685
|
}
|
|
3686
|
+
/**
|
|
3687
|
+
* Writes the healthcheck result to Redis cache for fast status retrieval.
|
|
3688
|
+
*/
|
|
3689
|
+
async writeHealthcheckResultToCache(data, result) {
|
|
3690
|
+
if (!this.redisClient)
|
|
3691
|
+
return;
|
|
3692
|
+
const key = `healthcheck:${data.product}:${data.healthcheck}:${data.env}`;
|
|
3693
|
+
console.log("LOG TO CACHE", key, JSON.stringify(result));
|
|
3694
|
+
await this.redisClient.set(key, JSON.stringify(result));
|
|
3695
|
+
console.log();
|
|
3696
|
+
}
|
|
3697
|
+
/**
|
|
3698
|
+
* Fetches the latest healthcheck status for a product/env from Redis cache.
|
|
3699
|
+
*/
|
|
3700
|
+
async getHealthcheckStatusFromCache(productTag, envSlug) {
|
|
3701
|
+
if (!this.redisClient)
|
|
3702
|
+
return null;
|
|
3703
|
+
const key = `healthcheck:${productTag}:${envSlug}`;
|
|
3704
|
+
const cached = await this.redisClient.get(key);
|
|
3705
|
+
return cached ? JSON.parse(cached) : null;
|
|
3706
|
+
}
|
|
3707
|
+
/**
|
|
3708
|
+
* Updates the healthcheck in the remote DB for a product with all envs' results.
|
|
3709
|
+
*/
|
|
3710
|
+
async updateHealthcheckOnProcessor(productTag, envs) {
|
|
3711
|
+
return this.productBuilderService.updateHealthcheck(productTag, { envs });
|
|
3712
|
+
}
|
|
3358
3713
|
}
|
|
3359
3714
|
exports.default = ProcessorService;
|
|
3360
3715
|
//# sourceMappingURL=processor.service.js.map
|