@ductape/sdk 0.0.4-v4 → 0.0.4-v40
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 +48 -2
- package/dist/api/services/appApi.service.js +101 -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 +39 -1
- package/dist/api/services/productsApi.service.js +76 -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 +6 -1
- package/dist/api/urls.js +12 -2
- package/dist/api/urls.js.map +1 -1
- package/dist/api/utils/cache.utils.d.ts +1 -1
- package/dist/api/utils/cache.utils.js +2 -2
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/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.d.ts +41 -33
- package/dist/apps/services/app.service.js +473 -185
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js +21 -2
- package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.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/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 +1009 -91
- package/dist/index.js +969 -126
- 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/messagebrokers/kafka.service.js +0 -2
- package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +9 -1
- package/dist/processor/services/messagebrokers/rabbitmq.service.js +40 -11
- package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +40 -9
- package/dist/processor/services/processor.service.js +638 -276
- 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 +89 -6
- 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 +98 -77
- package/dist/products/services/products.service.js +569 -325
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/services/utils/crypt.utils.d.ts +1 -0
- package/dist/products/services/utils/crypt.utils.js +17 -0
- package/dist/products/services/utils/crypt.utils.js.map +1 -0
- package/dist/products/services/utils/functions.utils.d.ts +13 -0
- package/dist/products/services/utils/functions.utils.js +294 -0
- package/dist/products/services/utils/functions.utils.js.map +1 -0
- package/dist/products/services/utils/objects.utils.d.ts +13 -0
- package/dist/products/services/utils/objects.utils.js +89 -0
- package/dist/products/services/utils/objects.utils.js.map +1 -0
- package/dist/products/services/utils/string.utils.d.ts +12 -0
- package/dist/products/services/utils/string.utils.js +168 -0
- package/dist/products/services/utils/string.utils.js.map +1 -0
- 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.productMessageBrokers.validator.js +9 -4
- package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productNotification.validator.js +5 -2
- package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
- package/dist/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.notifiers.d.ts +1 -0
- package/dist/test/test.notifiers.js +85 -0
- package/dist/test/test.notifiers.js.map +1 -0
- 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 +4 -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 +66 -9
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +52 -8
- 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 +15 -3
|
@@ -56,8 +56,8 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
56
56
|
const processorApi_service_1 = require("../../api/services/processorApi.service");
|
|
57
57
|
const expo_client_1 = __importDefault(require("../../clients/expo.client"));
|
|
58
58
|
const handlebars_1 = require("handlebars");
|
|
59
|
-
const functions_utils_1 = require("../../products/utils/functions.utils");
|
|
60
|
-
const string_utils_1 = require("../../products/utils/string.utils");
|
|
59
|
+
const functions_utils_1 = require("../../products/services/utils/functions.utils");
|
|
60
|
+
const string_utils_1 = require("../../products/services/utils/string.utils");
|
|
61
61
|
const create_productFeature_validator_1 = require("../../products/validators/joi-validators/create.productFeature.validator");
|
|
62
62
|
const validators_1 = require("../../products/validators");
|
|
63
63
|
const uuid_1 = require("uuid");
|
|
@@ -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,89 @@ 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 healthchecks = await this.productBuilderService.fetchProductHealthchecks();
|
|
143
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
144
|
+
for (const healthcheck of healthchecks) {
|
|
145
|
+
for (const env of healthcheck.envs) {
|
|
146
|
+
// Each env gets its own worker (setInterval)
|
|
147
|
+
const interval = healthcheck.interval || 60000; // default 60s
|
|
148
|
+
setInterval(async () => {
|
|
149
|
+
try {
|
|
150
|
+
// Decrypt input for this env
|
|
151
|
+
let decryptedInput = env.input;
|
|
152
|
+
if (typeof decryptedInput === 'string') {
|
|
153
|
+
decryptedInput = JSON.parse((0, processor_utils_1.decrypt)(decryptedInput, privateKey));
|
|
154
|
+
}
|
|
155
|
+
// Prepare action input
|
|
156
|
+
const actionInput = {
|
|
157
|
+
env: env.slug,
|
|
158
|
+
product: this.productTag,
|
|
159
|
+
app: healthcheck.app,
|
|
160
|
+
input: decryptedInput,
|
|
161
|
+
event: healthcheck.event,
|
|
162
|
+
retries: healthcheck.retries || 0,
|
|
163
|
+
};
|
|
164
|
+
// Process the action
|
|
165
|
+
const result = await this.processAction(actionInput);
|
|
166
|
+
// Log result (success/failure)
|
|
167
|
+
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 }));
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
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 }));
|
|
171
|
+
}
|
|
172
|
+
}, interval);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Manually trigger healthcheck processing for all healthchecks (can be called externally if needed)
|
|
178
|
+
*/
|
|
179
|
+
async processAllHealthchecksForProduct(productTag) {
|
|
180
|
+
await this.productBuilderService.initializeProductByTag(productTag);
|
|
181
|
+
const healthchecks = await this.productBuilderService.fetchProductHealthchecks();
|
|
182
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
183
|
+
for (const healthcheck of healthchecks) {
|
|
184
|
+
for (const env of healthcheck.envs) {
|
|
185
|
+
try {
|
|
186
|
+
let decryptedInput = env.input;
|
|
187
|
+
if (typeof decryptedInput === 'string') {
|
|
188
|
+
decryptedInput = JSON.parse((0, processor_utils_1.decrypt)(decryptedInput, privateKey));
|
|
189
|
+
}
|
|
190
|
+
const actionInput = {
|
|
191
|
+
env: env.slug,
|
|
192
|
+
product: productTag,
|
|
193
|
+
app: healthcheck.app,
|
|
194
|
+
input: decryptedInput,
|
|
195
|
+
event: healthcheck.event,
|
|
196
|
+
retries: healthcheck.retries || 0,
|
|
197
|
+
};
|
|
198
|
+
const result = await this.processAction(actionInput);
|
|
199
|
+
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 }));
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
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 }));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
115
205
|
}
|
|
116
206
|
}
|
|
117
207
|
async generateSession(payload) {
|
|
@@ -122,23 +212,37 @@ class ProcessorService {
|
|
|
122
212
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
123
213
|
});
|
|
124
214
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
125
|
-
|
|
126
|
-
const session = this.productBuilderService.fetchSession(tag);
|
|
215
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
216
|
+
const session = await this.productBuilderService.fetchSession(tag);
|
|
127
217
|
if (!session) {
|
|
128
218
|
throw new Error(`Session with tag ${tag} does not exist`);
|
|
129
219
|
}
|
|
130
|
-
const env = this.productBuilderService.fetchEnv(slug);
|
|
220
|
+
const env = await this.productBuilderService.fetchEnv(slug);
|
|
131
221
|
if (!env) {
|
|
132
222
|
throw new Error(`Env with slug ${slug} does not exist`);
|
|
133
223
|
}
|
|
134
224
|
await this.inputService.validateInput(input, session.schema_data);
|
|
135
|
-
const
|
|
225
|
+
const stages = (0, string_utils_1.extractStages)(session.selector);
|
|
226
|
+
// Convert stages to string[] for functions expecting string[]
|
|
227
|
+
const stringStages = stages.map(stage => String(stage));
|
|
228
|
+
const user = (0, processor_utils_1.extractSelectorValue)(data, stringStages, session.selector);
|
|
229
|
+
const expiry = (0, processor_utils_1.calculateJWTExpiry)(session.expiry, session.period);
|
|
230
|
+
const end_at = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
|
|
136
231
|
const JWT = await loadJWT();
|
|
137
232
|
if (JWT) {
|
|
138
|
-
const
|
|
139
|
-
const
|
|
233
|
+
const session_id = (0, uuid_1.v4)();
|
|
234
|
+
const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, privateKey, { expiresIn: expiry });
|
|
235
|
+
const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), privateKey);
|
|
140
236
|
// WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
|
|
141
|
-
|
|
237
|
+
const details = {
|
|
238
|
+
identifier: user,
|
|
239
|
+
start_at: Date.now(),
|
|
240
|
+
end_at,
|
|
241
|
+
session_tag: tag,
|
|
242
|
+
data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), privateKey),
|
|
243
|
+
session_id
|
|
244
|
+
};
|
|
245
|
+
await this.processorApiService.createSessionInfo(Object.assign({ product_tag, env: slug, refreshToken }, details), this.getUserAccess());
|
|
142
246
|
return {
|
|
143
247
|
token,
|
|
144
248
|
refreshToken,
|
|
@@ -152,11 +256,46 @@ class ProcessorService {
|
|
|
152
256
|
throw e;
|
|
153
257
|
}
|
|
154
258
|
}
|
|
259
|
+
async refreshSession(payload) {
|
|
260
|
+
await this.productBuilderService.initializeProductByTag(payload.product);
|
|
261
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
262
|
+
// validate token validity
|
|
263
|
+
const { refreshToken } = payload, payloadData = __rest(payload, ["refreshToken"]);
|
|
264
|
+
const valid = await this.processorApiService.validateRefreshToken({ refreshToken, product: payload.product, env: payload.env }, this.getUserAccess());
|
|
265
|
+
if (valid) {
|
|
266
|
+
const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, privateKey));
|
|
267
|
+
return await this.generateSession(Object.assign(Object.assign({}, payloadData), { data }));
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
throw new Error(`Invalid refresh token`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async decryptSession(data) {
|
|
274
|
+
await this.productBuilderService.initializeProductByTag(data.product);
|
|
275
|
+
const privateKey = this.productBuilderService.fetchPrivateKey();
|
|
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, privateKey);
|
|
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);
|
|
158
|
-
const
|
|
159
|
-
const { version, envs: appEnvs } = this.productBuilderService.fetchApp(access_tag);
|
|
298
|
+
const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
|
|
160
299
|
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
|
|
161
300
|
const { webhooks } = app.versions.find((data) => data.tag === version);
|
|
162
301
|
if (!webhooks) {
|
|
@@ -167,7 +306,7 @@ class ProcessorService {
|
|
|
167
306
|
if (!webhook) {
|
|
168
307
|
throw new Error(`Webhook tag ${webhook_tag} not found`);
|
|
169
308
|
}
|
|
170
|
-
const productEnvs = this.productBuilderService.fetchEnvs();
|
|
309
|
+
const productEnvs = await this.productBuilderService.fetchEnvs();
|
|
171
310
|
productEnvs.map((env) => {
|
|
172
311
|
const exists = envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
173
312
|
if (exists === -1) {
|
|
@@ -211,7 +350,7 @@ class ProcessorService {
|
|
|
211
350
|
if (replacedUrl && replacedUrl !== env.url && replacedUrl) {
|
|
212
351
|
throw new Error(`Ductape expects the url ${replacedUrl} in request body to match inputted url ${env.url}`);
|
|
213
352
|
}
|
|
214
|
-
const exists = this.fetchEnv(env.slug, {});
|
|
353
|
+
const exists = await this.fetchEnv(env.slug, {});
|
|
215
354
|
if (!exists) {
|
|
216
355
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
217
356
|
}
|
|
@@ -233,7 +372,7 @@ class ProcessorService {
|
|
|
233
372
|
webhook_tag,
|
|
234
373
|
version,
|
|
235
374
|
sender_workspace_id: app.workspace_id,
|
|
236
|
-
receiver_workspace_id:
|
|
375
|
+
receiver_workspace_id: this.getUserAccess().workspace_id,
|
|
237
376
|
app_tag: app.tag,
|
|
238
377
|
product_tag,
|
|
239
378
|
active,
|
|
@@ -244,8 +383,7 @@ class ProcessorService {
|
|
|
244
383
|
async generateWebhookLink(data) {
|
|
245
384
|
const { product: product_tag, access_tag, webhook_tag, env: product_env, url, method } = data;
|
|
246
385
|
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
247
|
-
const
|
|
248
|
-
const { version, envs: appEnvs } = this.productBuilderService.fetchApp(access_tag);
|
|
386
|
+
const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
|
|
249
387
|
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
|
|
250
388
|
const { webhooks } = app.versions.find((data) => data.tag === version);
|
|
251
389
|
if (!webhooks) {
|
|
@@ -266,7 +404,7 @@ class ProcessorService {
|
|
|
266
404
|
webhook_tag,
|
|
267
405
|
version,
|
|
268
406
|
sender_workspace_id: app.workspace_id,
|
|
269
|
-
receiver_workspace_id:
|
|
407
|
+
receiver_workspace_id: this.getUserAccess().workspace_id,
|
|
270
408
|
app_tag: app.tag,
|
|
271
409
|
product_tag,
|
|
272
410
|
active: false,
|
|
@@ -296,13 +434,12 @@ class ProcessorService {
|
|
|
296
434
|
process_id,
|
|
297
435
|
data: input,
|
|
298
436
|
};
|
|
299
|
-
this.quota = this.fetchQuota(quota_tag, additional_logs);
|
|
437
|
+
this.quota = await this.fetchQuota(quota_tag, additional_logs);
|
|
300
438
|
if (!this.quota) {
|
|
301
439
|
throw new Error(`Quota ${quota_tag} not found`);
|
|
302
440
|
}
|
|
303
441
|
this.logService.setFeatureId(this.quota._id);
|
|
304
|
-
this.
|
|
305
|
-
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
442
|
+
this.processEnv = await this.fetchEnv(env, additional_logs);
|
|
306
443
|
if (!this.processEnv.active) {
|
|
307
444
|
throw new Error(`Environment ${data.env} is not active`);
|
|
308
445
|
}
|
|
@@ -311,6 +448,7 @@ class ProcessorService {
|
|
|
311
448
|
this.validateJSONFeatureInput(input, quotaInput, additional_logs);
|
|
312
449
|
// split processes
|
|
313
450
|
//this.sequenceLevels = this.splitSequenceIntoLevels(sequence, additional_logs);
|
|
451
|
+
await this.logService.publish();
|
|
314
452
|
return await this.runQuotaOptions(options, input, additional_logs);
|
|
315
453
|
}
|
|
316
454
|
catch (e) {
|
|
@@ -320,17 +458,25 @@ class ProcessorService {
|
|
|
320
458
|
}
|
|
321
459
|
}
|
|
322
460
|
async runQuotaOptions(options, input, additional_logs) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
461
|
+
try {
|
|
462
|
+
const quotaManager = new quota_service_1.default(options, this.redisClient);
|
|
463
|
+
const getNextProvider = quotaManager.getNextProvider();
|
|
464
|
+
const quotaInput = await this.mapQuotaFallbackInput(getNextProvider.input, input, getNextProvider.app);
|
|
465
|
+
const result = await this.processEvent({
|
|
466
|
+
app: getNextProvider.app,
|
|
467
|
+
type: getNextProvider.type,
|
|
468
|
+
event: getNextProvider.event,
|
|
469
|
+
input: quotaInput,
|
|
470
|
+
retries: getNextProvider.retries,
|
|
471
|
+
allow_fail: false
|
|
472
|
+
});
|
|
473
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota successful', successful_execution: true, data: { result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.PROCESSING }));
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
476
|
+
catch (e) {
|
|
477
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process quota failed', failed_execution: true, data: { e }, status: types_1.LogEventStatus.PROCESSING }));
|
|
478
|
+
throw e;
|
|
479
|
+
}
|
|
334
480
|
}
|
|
335
481
|
async mapQuotaFallbackInput(providerInput, quotaInput, app) {
|
|
336
482
|
if (Array.isArray(providerInput)) {
|
|
@@ -350,10 +496,14 @@ class ProcessorService {
|
|
|
350
496
|
}
|
|
351
497
|
async overrideQuotaFallbackInput(value, quotaInput, app) {
|
|
352
498
|
if (value.startsWith('$Input{')) {
|
|
353
|
-
|
|
499
|
+
const stages = (0, string_utils_1.extractStages)(value);
|
|
500
|
+
return quotaInput[String(stages[0])];
|
|
354
501
|
}
|
|
355
502
|
else if (value.startsWith('$Auth')) {
|
|
356
|
-
|
|
503
|
+
const stages = (0, string_utils_1.extractStages)(value);
|
|
504
|
+
// Convert stages to string[] for functions expecting string[]
|
|
505
|
+
const stringStages = stages.map(stage => String(stage));
|
|
506
|
+
return await this.generateAuthValue(stringStages, app, [], {});
|
|
357
507
|
}
|
|
358
508
|
else if (value.startsWith('$')) {
|
|
359
509
|
this.input = Object.assign(Object.assign({}, this.input), { input: quotaInput });
|
|
@@ -415,13 +565,12 @@ class ProcessorService {
|
|
|
415
565
|
process_id,
|
|
416
566
|
data: input,
|
|
417
567
|
};
|
|
418
|
-
this.fallback = this.fetchFallback(fallback_tag, additional_logs);
|
|
568
|
+
this.fallback = await this.fetchFallback(fallback_tag, additional_logs);
|
|
419
569
|
if (!this.fallback) {
|
|
420
570
|
throw new Error(`Fallback "${fallback_tag}" not found`);
|
|
421
571
|
}
|
|
422
572
|
this.logService.setFeatureId(this.fallback._id);
|
|
423
|
-
this.
|
|
424
|
-
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
573
|
+
this.processEnv = await this.fetchEnv(env, additional_logs);
|
|
425
574
|
if (!this.processEnv.active) {
|
|
426
575
|
throw new Error(`Environment ${data.env} is not active`);
|
|
427
576
|
}
|
|
@@ -454,7 +603,7 @@ class ProcessorService {
|
|
|
454
603
|
this.component = types_1.LogEventTypes.FEATURE;
|
|
455
604
|
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
456
605
|
this.process_id = process_id;
|
|
457
|
-
this.feature = this.fetchFeature(feature_tag, additional_logs);
|
|
606
|
+
this.feature = await this.fetchFeature(feature_tag, additional_logs);
|
|
458
607
|
if (!this.feature) {
|
|
459
608
|
throw new Error(`Feature "${feature_tag}" not found`);
|
|
460
609
|
}
|
|
@@ -470,8 +619,7 @@ class ProcessorService {
|
|
|
470
619
|
feature_id: this.feature._id,
|
|
471
620
|
};
|
|
472
621
|
this.logService.setFeatureId(this.feature._id);
|
|
473
|
-
this.
|
|
474
|
-
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
622
|
+
this.processEnv = await this.fetchEnv(env, additional_logs);
|
|
475
623
|
if (!this.processEnv.active) {
|
|
476
624
|
throw new Error(`Environment ${data.env} is not active`);
|
|
477
625
|
}
|
|
@@ -502,6 +650,16 @@ class ProcessorService {
|
|
|
502
650
|
}
|
|
503
651
|
}
|
|
504
652
|
async intializeProduct(additional_logs) {
|
|
653
|
+
if (!this.logService) {
|
|
654
|
+
this.logService = new logs_service_1.default({
|
|
655
|
+
product_id: this.productId,
|
|
656
|
+
workspace_id: this.workspace_id,
|
|
657
|
+
public_key: this.public_key,
|
|
658
|
+
user_id: this.user_id,
|
|
659
|
+
token: this.token,
|
|
660
|
+
env_type: this.environment,
|
|
661
|
+
});
|
|
662
|
+
}
|
|
505
663
|
try {
|
|
506
664
|
if (this.productTag) {
|
|
507
665
|
await this.productBuilderService.initializeProductByTag(this.productTag); // validate product_exists
|
|
@@ -509,6 +667,20 @@ class ProcessorService {
|
|
|
509
667
|
else {
|
|
510
668
|
await this.productBuilderService.initializeProduct(this.productId);
|
|
511
669
|
}
|
|
670
|
+
this.productId = this.productBuilderService.fetchProductId();
|
|
671
|
+
const workspace_id = this.productBuilderService.fetchWorkspaceId();
|
|
672
|
+
if (workspace_id !== this.workspace_id) {
|
|
673
|
+
throw new Error('Access Denied');
|
|
674
|
+
}
|
|
675
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Product initialize - success', data: { product_id: this.productId }, status: types_1.LogEventStatus.SUCCESS }));
|
|
676
|
+
}
|
|
677
|
+
catch (e) {
|
|
678
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Product initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
679
|
+
throw e;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
async initializePricing(additional_logs, access_tag) {
|
|
683
|
+
if (!this.logService) {
|
|
512
684
|
this.logService = new logs_service_1.default({
|
|
513
685
|
product_id: this.productId,
|
|
514
686
|
workspace_id: this.workspace_id,
|
|
@@ -517,22 +689,25 @@ class ProcessorService {
|
|
|
517
689
|
token: this.token,
|
|
518
690
|
env_type: this.environment,
|
|
519
691
|
});
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}
|
|
525
|
-
|
|
692
|
+
}
|
|
693
|
+
try {
|
|
694
|
+
console.log(`Initializing pricing for access tag: ${access_tag}`);
|
|
695
|
+
const product_app = await this.productBuilderService.fetchApp(access_tag); // validate app exists
|
|
696
|
+
console.log(`Found product app: ${JSON.stringify(product_app)}`);
|
|
697
|
+
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(product_app.access_tag);
|
|
698
|
+
await this.pricingService.initializePricingByTag(product_app.pricing_tag, app._id);
|
|
699
|
+
const { pricing_tag } = this.pricingService.fetchPricing();
|
|
700
|
+
this.pricingTag = pricing_tag;
|
|
701
|
+
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 }));
|
|
526
702
|
}
|
|
527
703
|
catch (e) {
|
|
528
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: '
|
|
704
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
529
705
|
throw e;
|
|
530
706
|
}
|
|
531
707
|
}
|
|
532
|
-
fetchFeature(tag, additional_logs) {
|
|
708
|
+
async fetchFeature(tag, additional_logs) {
|
|
533
709
|
try {
|
|
534
|
-
this.
|
|
535
|
-
const feature = this.productBuilderService.fetchFeature(tag); // validate feature exists
|
|
710
|
+
const feature = await this.productBuilderService.fetchFeature(tag); // validate feature exists
|
|
536
711
|
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
712
|
return feature;
|
|
538
713
|
}
|
|
@@ -541,10 +716,9 @@ class ProcessorService {
|
|
|
541
716
|
throw e;
|
|
542
717
|
}
|
|
543
718
|
}
|
|
544
|
-
fetchQuota(tag, additional_logs) {
|
|
719
|
+
async fetchQuota(tag, additional_logs) {
|
|
545
720
|
try {
|
|
546
|
-
|
|
547
|
-
const quota = this.productBuilderService.fetchQuota(tag); // validate feature exists
|
|
721
|
+
const quota = await this.productBuilderService.fetchQuota(tag); // validate feature exists
|
|
548
722
|
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
723
|
return quota;
|
|
550
724
|
}
|
|
@@ -553,10 +727,9 @@ class ProcessorService {
|
|
|
553
727
|
throw e;
|
|
554
728
|
}
|
|
555
729
|
}
|
|
556
|
-
fetchFallback(tag, additional_logs) {
|
|
730
|
+
async fetchFallback(tag, additional_logs) {
|
|
557
731
|
try {
|
|
558
|
-
|
|
559
|
-
const fallback = this.productBuilderService.fetchFallback(tag); // validate feature exists
|
|
732
|
+
const fallback = await this.productBuilderService.fetchFallback(tag); // validate feature exists
|
|
560
733
|
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
734
|
return fallback;
|
|
562
735
|
}
|
|
@@ -565,10 +738,9 @@ class ProcessorService {
|
|
|
565
738
|
throw e;
|
|
566
739
|
}
|
|
567
740
|
}
|
|
568
|
-
fetchEnv(env, additional_logs) {
|
|
741
|
+
async fetchEnv(env, additional_logs) {
|
|
569
742
|
try {
|
|
570
|
-
this.
|
|
571
|
-
const product_env = this.productBuilderService.fetchEnv(env); // validate env exists
|
|
743
|
+
const product_env = await this.productBuilderService.fetchEnv(env); // validate env exists
|
|
572
744
|
if (!product_env) {
|
|
573
745
|
throw new Error(`Env ${env} not found`);
|
|
574
746
|
}
|
|
@@ -582,7 +754,6 @@ class ProcessorService {
|
|
|
582
754
|
}
|
|
583
755
|
validateJSONFeatureInput(input, feature_input, additional_logs) {
|
|
584
756
|
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
757
|
(0, processor_utils_1.validateFeatureJSONInput)(input, feature_input);
|
|
587
758
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Input validation - success', data: {}, status: types_1.LogEventStatus.SUCCESS }));
|
|
588
759
|
}
|
|
@@ -593,7 +764,6 @@ class ProcessorService {
|
|
|
593
764
|
}
|
|
594
765
|
async splitSequenceIntoLevels(data, additional_logs) {
|
|
595
766
|
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
767
|
const levels = {};
|
|
598
768
|
const tagMap = new Map(data.map((seq) => [seq.tag, seq]));
|
|
599
769
|
const assignedLevels = new Map();
|
|
@@ -630,7 +800,6 @@ class ProcessorService {
|
|
|
630
800
|
}
|
|
631
801
|
async processSequenceLevels(additional_logs) {
|
|
632
802
|
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
803
|
const levelEvents = {};
|
|
635
804
|
Object.entries(this.sequenceLevels).forEach(([level, sequences]) => {
|
|
636
805
|
levelEvents[parseInt(level)] = this.fetchLevelEvents(sequences, parseInt(level));
|
|
@@ -658,7 +827,6 @@ class ProcessorService {
|
|
|
658
827
|
successful_feature_execution = true;
|
|
659
828
|
}
|
|
660
829
|
else if (this.processingFailure) {
|
|
661
|
-
console.log("PROCESSING FAILURE", this.processingFailure);
|
|
662
830
|
message = 'Process feature - processing';
|
|
663
831
|
status = types_1.LogEventStatus.PROCESSING;
|
|
664
832
|
successful_feature_execution = false;
|
|
@@ -674,7 +842,7 @@ class ProcessorService {
|
|
|
674
842
|
return true;
|
|
675
843
|
}
|
|
676
844
|
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 }));
|
|
845
|
+
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
846
|
throw e;
|
|
679
847
|
}
|
|
680
848
|
}
|
|
@@ -702,7 +870,6 @@ class ProcessorService {
|
|
|
702
870
|
const { failure } = this.processingOutput;
|
|
703
871
|
const promises = failure.map((failed) => {
|
|
704
872
|
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
873
|
return this.processEvent(failed.event); // process events should also take care of this.processingOutput
|
|
707
874
|
}
|
|
708
875
|
if (failed.retries_left === 0 && !failed.allow_fail) {
|
|
@@ -747,7 +914,6 @@ class ProcessorService {
|
|
|
747
914
|
}
|
|
748
915
|
fetchActionRequestDependents(input, additional_logs) {
|
|
749
916
|
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
917
|
const dependents = [];
|
|
752
918
|
if (input.query) {
|
|
753
919
|
dependents.push(...this.fetchDependents(input.query, additional_logs));
|
|
@@ -779,7 +945,6 @@ class ProcessorService {
|
|
|
779
945
|
}
|
|
780
946
|
fetchDependents(obj, additional_logs) {
|
|
781
947
|
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
948
|
const dependants = [];
|
|
784
949
|
for (const key in obj) {
|
|
785
950
|
const value = obj[key];
|
|
@@ -790,8 +955,8 @@ class ProcessorService {
|
|
|
790
955
|
if (values[i].startsWith('$Sequence')) {
|
|
791
956
|
const stages = this.productBuilderService.extractStages(values[i]);
|
|
792
957
|
dependants.push({
|
|
793
|
-
sequence_tag: stages[0],
|
|
794
|
-
event_tag: stages[1],
|
|
958
|
+
sequence_tag: String(stages[0]),
|
|
959
|
+
event_tag: String(stages[1]),
|
|
795
960
|
});
|
|
796
961
|
}
|
|
797
962
|
else if (values[i].startsWith('$')) {
|
|
@@ -801,8 +966,8 @@ class ProcessorService {
|
|
|
801
966
|
if (arg.startsWith('$Sequence')) {
|
|
802
967
|
const stages = this.productBuilderService.extractStages(arg);
|
|
803
968
|
dependants.push({
|
|
804
|
-
sequence_tag: stages[0],
|
|
805
|
-
event_tag: stages[1],
|
|
969
|
+
sequence_tag: String(stages[0]),
|
|
970
|
+
event_tag: String(stages[1]),
|
|
806
971
|
});
|
|
807
972
|
}
|
|
808
973
|
});
|
|
@@ -821,7 +986,6 @@ class ProcessorService {
|
|
|
821
986
|
return dependants;
|
|
822
987
|
}
|
|
823
988
|
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
989
|
throw e;
|
|
826
990
|
}
|
|
827
991
|
}
|
|
@@ -829,7 +993,7 @@ class ProcessorService {
|
|
|
829
993
|
const dependants = [];
|
|
830
994
|
if (value.startsWith('$Sequence')) {
|
|
831
995
|
const stages = this.productBuilderService.extractStages(value);
|
|
832
|
-
dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
|
|
996
|
+
dependants.push({ sequence_tag: String(stages[0]), event_tag: String(stages[1]) });
|
|
833
997
|
}
|
|
834
998
|
else if (value.startsWith('$')) {
|
|
835
999
|
const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(value);
|
|
@@ -838,8 +1002,8 @@ class ProcessorService {
|
|
|
838
1002
|
if (arg.startsWith('$Sequence')) {
|
|
839
1003
|
const stages = this.productBuilderService.extractStages(arg);
|
|
840
1004
|
dependants.push({
|
|
841
|
-
sequence_tag: stages[0],
|
|
842
|
-
event_tag: stages[1],
|
|
1005
|
+
sequence_tag: String(stages[0]),
|
|
1006
|
+
event_tag: String(stages[1]),
|
|
843
1007
|
});
|
|
844
1008
|
}
|
|
845
1009
|
else {
|
|
@@ -855,7 +1019,6 @@ class ProcessorService {
|
|
|
855
1019
|
}
|
|
856
1020
|
async constructJSONDataPayloads(object, additional_logs, samples, event, loopIndex = 0) {
|
|
857
1021
|
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
1022
|
const payload = {};
|
|
860
1023
|
const { body: actionBody, query: actionQuery, headers: actionHeaders, params: actionParams } = object;
|
|
861
1024
|
if (actionBody) {
|
|
@@ -912,8 +1075,8 @@ class ProcessorService {
|
|
|
912
1075
|
}
|
|
913
1076
|
async generatePayload(obj, event, additional_logs, sample = [], index = {}, loopIndex = null) {
|
|
914
1077
|
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
1078
|
const payload = {};
|
|
1079
|
+
console.log("Payload Construction", { obj, event, sample, index, loopIndex });
|
|
917
1080
|
const keys = Object.keys(obj);
|
|
918
1081
|
for (let i = 0; i < keys.length; i++) {
|
|
919
1082
|
const key = keys[i];
|
|
@@ -959,22 +1122,32 @@ class ProcessorService {
|
|
|
959
1122
|
const locatorFor$Index = (0, string_utils_1.validateAndLocateTag)(value);
|
|
960
1123
|
if (value.startsWith('$Auth{') && value.endsWith('}')) {
|
|
961
1124
|
// should only be allowed in apps
|
|
962
|
-
|
|
1125
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1126
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1127
|
+
return await this.generateAuthValue(stringStages, app, sample, additional_logs);
|
|
963
1128
|
}
|
|
964
1129
|
else if (value.startsWith('$Sequence{') && value.endsWith('}')) {
|
|
965
|
-
|
|
1130
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1131
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1132
|
+
return await this.generateSequenceValue(stringStages, locatorFor$Index, loopIndex); // pass
|
|
966
1133
|
}
|
|
967
1134
|
else if (value.startsWith('$Input{') && value.endsWith('}')) {
|
|
968
|
-
|
|
1135
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1136
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1137
|
+
return await this.generateInputValue(this.input.input, stringStages);
|
|
969
1138
|
}
|
|
970
1139
|
else if (value === '$Default') {
|
|
971
1140
|
return await this.generateDefaultValue(sample, Object.assign(Object.assign({}, index), { key }));
|
|
972
1141
|
}
|
|
973
1142
|
else if (value.startsWith('$Variable{') && value.endsWith('}')) {
|
|
974
|
-
|
|
1143
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1144
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1145
|
+
return await this.generateVariableValue(stringStages);
|
|
975
1146
|
}
|
|
976
1147
|
else if (value.startsWith('$Constant{') && value.endsWith('}')) {
|
|
977
|
-
|
|
1148
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1149
|
+
const stringStages = stages.map(stage => String(stage));
|
|
1150
|
+
return await this.generateConstantValue(stringStages);
|
|
978
1151
|
}
|
|
979
1152
|
else if (value.startsWith('$Size{') || value.startsWith('$Length{')) {
|
|
980
1153
|
const { matchLength, matchSize } = (0, string_utils_1.checkLengthAndSizeMatches)(value);
|
|
@@ -1099,6 +1272,7 @@ class ProcessorService {
|
|
|
1099
1272
|
const placeholdersStr = match[1];
|
|
1100
1273
|
const separator = match[2];
|
|
1101
1274
|
const placeHolders = placeholdersStr.split(',').map((data) => data.trim());
|
|
1275
|
+
console.log('placeHolders', { placeHolders, separator });
|
|
1102
1276
|
const values = await Promise.all(placeHolders.map(async (holder) => {
|
|
1103
1277
|
return await this.generateStringValues(holder, app, additional_logs, sample, index, key, loopIndex);
|
|
1104
1278
|
}));
|
|
@@ -1371,7 +1545,7 @@ class ProcessorService {
|
|
|
1371
1545
|
}
|
|
1372
1546
|
async generateVariableValue(stages) {
|
|
1373
1547
|
try {
|
|
1374
|
-
const app = this.productBuilderService.fetchApp(stages[0]);
|
|
1548
|
+
const app = await this.productBuilderService.fetchApp(stages[0]);
|
|
1375
1549
|
const env = app.envs.find((items) => items.product_env_slug === this.processEnv.slug);
|
|
1376
1550
|
if (!env) {
|
|
1377
1551
|
throw new Error(`App ${stages[0]} variables needs to have a definition for env: ${this.processEnv.slug}`);
|
|
@@ -1417,6 +1591,7 @@ class ProcessorService {
|
|
|
1417
1591
|
}
|
|
1418
1592
|
async generateAuthValue(stages, app, sample, additional_logs) {
|
|
1419
1593
|
try {
|
|
1594
|
+
console.log("Generate Auth Data", { stages, app, sample });
|
|
1420
1595
|
let auth_data = await this.fetchAuthData(app, additional_logs); //TODO: should use stages[0]
|
|
1421
1596
|
// take the app tag in index 0..
|
|
1422
1597
|
if (!auth_data) {
|
|
@@ -1432,8 +1607,7 @@ class ProcessorService {
|
|
|
1432
1607
|
}
|
|
1433
1608
|
async fetchAuthData(app_tag, additional_logs) {
|
|
1434
1609
|
try {
|
|
1435
|
-
|
|
1436
|
-
const app = this.productBuilderService.fetchApp(app_tag);
|
|
1610
|
+
const app = await this.productBuilderService.fetchApp(app_tag);
|
|
1437
1611
|
if (!app) {
|
|
1438
1612
|
throw new Error(`App ${app_tag} not found in $Auth value`);
|
|
1439
1613
|
}
|
|
@@ -1444,6 +1618,7 @@ class ProcessorService {
|
|
|
1444
1618
|
if (!env.auth) {
|
|
1445
1619
|
throw new Error(`App ${app_tag} in auth needs to have a definition for auth in env: ${this.processEnv.slug}`);
|
|
1446
1620
|
}
|
|
1621
|
+
console.log("Envroment", env.auth);
|
|
1447
1622
|
let values = env.auth.values;
|
|
1448
1623
|
if (!values) {
|
|
1449
1624
|
// no auth values
|
|
@@ -1451,9 +1626,10 @@ class ProcessorService {
|
|
|
1451
1626
|
}
|
|
1452
1627
|
if (!env.auth.expiry || (env.auth.expiry && Date.now() > new Date(env.auth.expiry).getTime())) {
|
|
1453
1628
|
// refresh
|
|
1629
|
+
console.log("REFRESH DATA", env, app_tag);
|
|
1454
1630
|
values = await this.getAndStoreAuth(env, app_tag);
|
|
1455
1631
|
}
|
|
1456
|
-
const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.
|
|
1632
|
+
const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchPrivateKey());
|
|
1457
1633
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch auth data - success', data: { auth: (0, processor_utils_1.anonymizeValue)(decrypted) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
1458
1634
|
return JSON.parse(decrypted);
|
|
1459
1635
|
}
|
|
@@ -1563,7 +1739,18 @@ class ProcessorService {
|
|
|
1563
1739
|
parent_tag: event.event,
|
|
1564
1740
|
name: 'Process feature job',
|
|
1565
1741
|
};
|
|
1566
|
-
|
|
1742
|
+
const input = {
|
|
1743
|
+
env: event.env.slug,
|
|
1744
|
+
product: this.productTag,
|
|
1745
|
+
event: event.event,
|
|
1746
|
+
retries: event.retries,
|
|
1747
|
+
input: event.input,
|
|
1748
|
+
start_at: event.start_at || 0,
|
|
1749
|
+
cache: event.cache,
|
|
1750
|
+
session: this.input.session
|
|
1751
|
+
};
|
|
1752
|
+
// TODO: fix this
|
|
1753
|
+
return this.processJob(input, additional_logs);
|
|
1567
1754
|
}
|
|
1568
1755
|
}
|
|
1569
1756
|
catch (e) {
|
|
@@ -1587,16 +1774,25 @@ class ProcessorService {
|
|
|
1587
1774
|
}
|
|
1588
1775
|
return output;
|
|
1589
1776
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1777
|
+
async runJobs(job, additional_logs = {}) {
|
|
1778
|
+
if (job.name === types_1.FeatureEventTypes.ACTION) {
|
|
1779
|
+
await this.processAction(job.data);
|
|
1780
|
+
}
|
|
1592
1781
|
}
|
|
1593
1782
|
async processFailedAndWaiting() { }
|
|
1594
|
-
async
|
|
1595
|
-
var _a, _b, _c, _d;
|
|
1783
|
+
async fetchResult(process_id) {
|
|
1596
1784
|
const result = await this.processorApiService.fetchResult(process_id, this.getUserAccess());
|
|
1597
1785
|
if (!result) {
|
|
1598
1786
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1599
1787
|
}
|
|
1788
|
+
await this.productBuilderService.initializeProduct(result.product_id);
|
|
1789
|
+
result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchPrivateKey()));
|
|
1790
|
+
result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchPrivateKey()));
|
|
1791
|
+
return result;
|
|
1792
|
+
}
|
|
1793
|
+
async generateOutput(process_id) {
|
|
1794
|
+
var _a, _b, _c, _d;
|
|
1795
|
+
const result = await this.fetchResult(process_id);
|
|
1600
1796
|
if (result.component === types_1.LogEventTypes.FEATURE) {
|
|
1601
1797
|
const additional_logs = {
|
|
1602
1798
|
parent_tag: result.input.tag,
|
|
@@ -1635,7 +1831,7 @@ class ProcessorService {
|
|
|
1635
1831
|
}
|
|
1636
1832
|
}
|
|
1637
1833
|
async resumeProcess(process_id) {
|
|
1638
|
-
const result =
|
|
1834
|
+
const result = await this.fetchResult(process_id);
|
|
1639
1835
|
if (!result) {
|
|
1640
1836
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1641
1837
|
}
|
|
@@ -1655,7 +1851,7 @@ class ProcessorService {
|
|
|
1655
1851
|
if (result.component === types_1.LogEventTypes.FEATURE) {
|
|
1656
1852
|
this.feature = await this.fetchFeature(result.input.tag, additional_logs);
|
|
1657
1853
|
const { input: featureInput, sequence, output } = this.feature;
|
|
1658
|
-
this.processEnv = this.fetchEnv(result.env, additional_logs);
|
|
1854
|
+
this.processEnv = await this.fetchEnv(result.env, additional_logs);
|
|
1659
1855
|
if (!this.processEnv.active) {
|
|
1660
1856
|
throw new Error(`Environment ${result.env} is not active`);
|
|
1661
1857
|
}
|
|
@@ -1677,7 +1873,7 @@ class ProcessorService {
|
|
|
1677
1873
|
}
|
|
1678
1874
|
async replayProcess(process_id) {
|
|
1679
1875
|
var _a, _b, _c;
|
|
1680
|
-
const result =
|
|
1876
|
+
const result = await this.fetchResult(process_id);
|
|
1681
1877
|
if (!result) {
|
|
1682
1878
|
throw new Error(`Invalid process id ${process_id}`);
|
|
1683
1879
|
}
|
|
@@ -1697,7 +1893,7 @@ class ProcessorService {
|
|
|
1697
1893
|
//await this.processWaitingEvents(additional_logs);
|
|
1698
1894
|
this.feature = await this.fetchFeature(result.input.tag, additional_logs);
|
|
1699
1895
|
const { input: featureInput, sequence, output } = this.feature;
|
|
1700
|
-
this.processEnv = this.fetchEnv(result.env, additional_logs);
|
|
1896
|
+
this.processEnv = await this.fetchEnv(result.env, additional_logs);
|
|
1701
1897
|
if (!this.processEnv.active) {
|
|
1702
1898
|
throw new Error(`Environment ${result.env} is not active`);
|
|
1703
1899
|
}
|
|
@@ -1712,7 +1908,7 @@ class ProcessorService {
|
|
|
1712
1908
|
((_b = result.result.success[0]) === null || _b === void 0 ? void 0 : _b.event) ||
|
|
1713
1909
|
((_c = result.result.skipped[0]) === null || _c === void 0 ? void 0 : _c.event) ||
|
|
1714
1910
|
result.result.waiting[0].event;
|
|
1715
|
-
this.processEnv = this.fetchEnv(result.env, additional_logs);
|
|
1911
|
+
this.processEnv = await this.fetchEnv(result.env, additional_logs);
|
|
1716
1912
|
this.start = Date.now();
|
|
1717
1913
|
await this.processEvent(event);
|
|
1718
1914
|
this.end = Date.now();
|
|
@@ -1739,10 +1935,11 @@ class ProcessorService {
|
|
|
1739
1935
|
}
|
|
1740
1936
|
async getAndStoreAuth(appEnv, access_tag) {
|
|
1741
1937
|
try {
|
|
1742
|
-
// const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.
|
|
1743
|
-
const payload = appEnv.auth.data;
|
|
1938
|
+
// const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.fetchPrivateKey()));
|
|
1939
|
+
const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.fetchPrivateKey()));
|
|
1744
1940
|
let app = await this.fetchThirdPartyApp(access_tag);
|
|
1745
1941
|
const auth = app.auths.find((item) => item.tag === appEnv.auth.auth_tag);
|
|
1942
|
+
console.log("JAMESY", auth);
|
|
1746
1943
|
if (!auth) {
|
|
1747
1944
|
// throw an error
|
|
1748
1945
|
throw new Error(`Cannot find auth ${appEnv.auth.auth_tag} on environment ${appEnv.product_env_slug}`);
|
|
@@ -1757,9 +1954,16 @@ class ProcessorService {
|
|
|
1757
1954
|
if (env.base_url) {
|
|
1758
1955
|
request_base_url = env.base_url;
|
|
1759
1956
|
}
|
|
1957
|
+
if (action.envs && action.envs.length) {
|
|
1958
|
+
const env = action.envs.find((item) => item.slug === appEnv.app_env_slug);
|
|
1959
|
+
if (env && env.base_url) {
|
|
1960
|
+
request_base_url = env.base_url;
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
console.log("payloadabi!!!!", payload);
|
|
1760
1964
|
const results = await this.sendActionRequest(request_base_url, url, payload, method, appEnv.app_env_slug);
|
|
1761
|
-
const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.
|
|
1762
|
-
const productApp = this.productBuilderService.fetchApp(access_tag);
|
|
1965
|
+
const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchPrivateKey());
|
|
1966
|
+
const productApp = await this.productBuilderService.fetchApp(access_tag);
|
|
1763
1967
|
for (let i = 0; i < productApp.envs.length; i++) {
|
|
1764
1968
|
if (productApp.envs[i].app_env_slug === env.slug) {
|
|
1765
1969
|
productApp.envs[i].auth.values = values; // write new values
|
|
@@ -1805,7 +2009,6 @@ class ProcessorService {
|
|
|
1805
2009
|
}
|
|
1806
2010
|
async processConditionalCheck(event, additional_logs = {}) {
|
|
1807
2011
|
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
2012
|
const [, initiator, operator, value] = parts;
|
|
1810
2013
|
const initiatorValue = await this.generateStringValues(initiator, event.app, additional_logs);
|
|
1811
2014
|
let valueValue;
|
|
@@ -1817,7 +2020,6 @@ class ProcessorService {
|
|
|
1817
2020
|
else {
|
|
1818
2021
|
valueValue = value;
|
|
1819
2022
|
}
|
|
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
2023
|
const pass = (0, processor_utils_1.compareValues)(initiatorValue, operator, valueValue);
|
|
1822
2024
|
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
2025
|
if (!pass) {
|
|
@@ -1842,7 +2044,6 @@ class ProcessorService {
|
|
|
1842
2044
|
}
|
|
1843
2045
|
async extractLoopIndexes(event, additional_logs = {}) {
|
|
1844
2046
|
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
2047
|
const [, initiator, operator, value] = parts;
|
|
1847
2048
|
let valueValue;
|
|
1848
2049
|
if (!(0, string_utils_1.isNumeric)(value)) {
|
|
@@ -1873,12 +2074,13 @@ class ProcessorService {
|
|
|
1873
2074
|
}
|
|
1874
2075
|
let app = await this.fetchThirdPartyApp(access_tag);
|
|
1875
2076
|
const { actions, envs: appEnvs, retries, workspace_id: recipient_workspace_id, active } = app;
|
|
1876
|
-
const productApp = this.productBuilderService.fetchApp(access_tag);
|
|
2077
|
+
const productApp = await this.productBuilderService.fetchApp(access_tag);
|
|
1877
2078
|
const { envs: productEnvs, version } = productApp;
|
|
1878
2079
|
const { app_env_slug } = productEnvs.find((item) => item.product_env_slug === this.processEnv.slug);
|
|
1879
2080
|
additional_logs.app_env = app_env_slug;
|
|
2081
|
+
console.log(app, appEnvs);
|
|
1880
2082
|
const env = appEnvs.find((item) => item.slug === app_env_slug); // fetch the actuall app Environment variable
|
|
1881
|
-
if (!active) {
|
|
2083
|
+
if (!active && recipient_workspace_id !== this.baseLogs.workspace_id) {
|
|
1882
2084
|
throw new Error(`App ${event.app} version ${app.version} is not active`);
|
|
1883
2085
|
}
|
|
1884
2086
|
if (!env.active) {
|
|
@@ -1893,6 +2095,12 @@ class ProcessorService {
|
|
|
1893
2095
|
if (env.base_url) {
|
|
1894
2096
|
request_base_url = env.base_url;
|
|
1895
2097
|
}
|
|
2098
|
+
if (action.envs && action.envs.length) {
|
|
2099
|
+
const env = action.envs.find((item) => item.slug === app_env_slug);
|
|
2100
|
+
if (env && env.base_url) {
|
|
2101
|
+
request_base_url = env.base_url;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
1896
2104
|
const samples = {
|
|
1897
2105
|
query: (query === null || query === void 0 ? void 0 : query.data) || [],
|
|
1898
2106
|
headers: (headers === null || headers === void 0 ? void 0 : headers.data) || [],
|
|
@@ -1901,9 +2109,9 @@ class ProcessorService {
|
|
|
1901
2109
|
};
|
|
1902
2110
|
let payloads;
|
|
1903
2111
|
let result;
|
|
1904
|
-
const product = this.productBuilderService.fetchProduct();
|
|
2112
|
+
//const product = this.productBuilderService.fetchProduct();
|
|
1905
2113
|
if (cache_tag && this.redisClient) {
|
|
1906
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
2114
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
1907
2115
|
if (!productCache) {
|
|
1908
2116
|
throw new Error('Invalid cache tag ');
|
|
1909
2117
|
}
|
|
@@ -1911,12 +2119,12 @@ class ProcessorService {
|
|
|
1911
2119
|
const check = await this.fetchFromCache({
|
|
1912
2120
|
cache_tag,
|
|
1913
2121
|
input: inputString,
|
|
1914
|
-
privateKey:
|
|
2122
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
1915
2123
|
expiry: productCache.expiry,
|
|
1916
|
-
});
|
|
2124
|
+
}, additional_logs);
|
|
1917
2125
|
if (check) {
|
|
1918
2126
|
result = JSON.parse(check);
|
|
1919
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Run action -
|
|
2127
|
+
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
2128
|
if (returnValue) {
|
|
1921
2129
|
return result;
|
|
1922
2130
|
}
|
|
@@ -1941,32 +2149,32 @@ class ProcessorService {
|
|
|
1941
2149
|
}
|
|
1942
2150
|
}
|
|
1943
2151
|
if (cache_tag && this.redisClient && result) {
|
|
1944
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
2152
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
1945
2153
|
if (!productCache) {
|
|
1946
2154
|
throw new Error('Invalid cache tag ');
|
|
1947
2155
|
}
|
|
1948
2156
|
const inputString = JSON.stringify(event.input);
|
|
1949
2157
|
await this.addToCache({
|
|
1950
2158
|
input: inputString,
|
|
1951
|
-
privateKey:
|
|
2159
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
1952
2160
|
data: JSON.stringify(result),
|
|
1953
2161
|
cache_tag,
|
|
1954
2162
|
timestamp: Date.now(),
|
|
1955
2163
|
component_tag: action_tag,
|
|
1956
2164
|
component_type: types_1.ProductComponents.ACTION,
|
|
1957
2165
|
product_tag: this.productTag,
|
|
1958
|
-
});
|
|
2166
|
+
}, additional_logs);
|
|
1959
2167
|
}
|
|
1960
2168
|
return result;
|
|
1961
2169
|
}
|
|
1962
2170
|
catch (e) {
|
|
1963
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), {
|
|
2171
|
+
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
2172
|
throw e;
|
|
1965
2173
|
}
|
|
1966
2174
|
}
|
|
1967
2175
|
async processRequest(payload, event, retries, additional_logs, returnValue = false) {
|
|
2176
|
+
var _a;
|
|
1968
2177
|
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
2178
|
const start = Date.now();
|
|
1971
2179
|
try {
|
|
1972
2180
|
let results = (0, processor_utils_1.generateMockData)(resource, env.slug, payloads);
|
|
@@ -1976,7 +2184,11 @@ class ProcessorService {
|
|
|
1976
2184
|
const end = Date.now();
|
|
1977
2185
|
this.requestTime += end - start;
|
|
1978
2186
|
this.totalRequests += 1;
|
|
1979
|
-
this.
|
|
2187
|
+
const { pricing_tag, pricing_cost, is_overage, currency } = await this.processPricingCost(Object.assign(Object.assign({}, additional_logs), { app_id, workspace_id: this.workspace_id }));
|
|
2188
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { pricing_tag,
|
|
2189
|
+
pricing_cost,
|
|
2190
|
+
currency,
|
|
2191
|
+
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
2192
|
end }));
|
|
1981
2193
|
await this.addToSuccessOutput(event, results, additional_logs);
|
|
1982
2194
|
if (returnValue) {
|
|
@@ -1988,11 +2200,16 @@ class ProcessorService {
|
|
|
1988
2200
|
}
|
|
1989
2201
|
catch (e) {
|
|
1990
2202
|
const end = Date.now();
|
|
2203
|
+
let error = e;
|
|
2204
|
+
if ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) {
|
|
2205
|
+
error = e.response.data;
|
|
2206
|
+
}
|
|
1991
2207
|
this.requestTime += end - start;
|
|
1992
2208
|
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,
|
|
2209
|
+
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
2210
|
end }));
|
|
1995
2211
|
try {
|
|
2212
|
+
console.log(e);
|
|
1996
2213
|
const value = await this.addToFailureOutput(e, event, {
|
|
1997
2214
|
request_base_url,
|
|
1998
2215
|
resource,
|
|
@@ -2017,11 +2234,75 @@ class ProcessorService {
|
|
|
2017
2234
|
}
|
|
2018
2235
|
}
|
|
2019
2236
|
}
|
|
2237
|
+
async processPricingCost(additional_logs) {
|
|
2238
|
+
try {
|
|
2239
|
+
const { app_id, workspace_id } = additional_logs;
|
|
2240
|
+
if (!app_id || !workspace_id) {
|
|
2241
|
+
throw new Error('app_id and workspace_id are required in additional_logs');
|
|
2242
|
+
}
|
|
2243
|
+
const primaryPricing = this.pricingService.fetchPricing();
|
|
2244
|
+
const overagePricing = this.pricingService.fetchOveragePricing();
|
|
2245
|
+
const requests = await this.requestTrackerService.incrementRequest(app_id, workspace_id);
|
|
2246
|
+
const limitCheck = (0, request_utils_1.checkLimitExceeded)(requests, primaryPricing.limits);
|
|
2247
|
+
let finalCost = 0;
|
|
2248
|
+
let usedPricing = primaryPricing;
|
|
2249
|
+
let isOverage = false;
|
|
2250
|
+
let finalCurrency = primaryPricing.currency;
|
|
2251
|
+
if ((0, request_utils_1.isFreeTag)(primaryPricing.pricing_tag)) {
|
|
2252
|
+
if (limitCheck.exceeded) {
|
|
2253
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2254
|
+
finalCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2255
|
+
usedPricing = overagePricing;
|
|
2256
|
+
isOverage = true;
|
|
2257
|
+
finalCurrency = overagePricing.currency;
|
|
2258
|
+
}
|
|
2259
|
+
else {
|
|
2260
|
+
finalCost = 0;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
else {
|
|
2264
|
+
if (limitCheck.exceeded) {
|
|
2265
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2266
|
+
const overageCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2267
|
+
finalCost = overageCost;
|
|
2268
|
+
isOverage = true;
|
|
2269
|
+
}
|
|
2270
|
+
else {
|
|
2271
|
+
const pricingRequests = (0, request_utils_1.calculateRequests)(requests);
|
|
2272
|
+
finalCost = (0, request_utils_1.calculateCost)(primaryPricing.pricing_mode, primaryPricing.unit_price, pricingRequests);
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - success', data: {
|
|
2276
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2277
|
+
cost: finalCost,
|
|
2278
|
+
currency: finalCurrency,
|
|
2279
|
+
is_overage: isOverage,
|
|
2280
|
+
requests: requests,
|
|
2281
|
+
limit_exceeded: limitCheck.exceeded
|
|
2282
|
+
}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2283
|
+
return {
|
|
2284
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2285
|
+
pricing_cost: Math.round(finalCost * 100) / 100,
|
|
2286
|
+
currency: finalCurrency,
|
|
2287
|
+
is_overage: isOverage,
|
|
2288
|
+
requests_made: requests,
|
|
2289
|
+
limit_exceeded: limitCheck.exceeded,
|
|
2290
|
+
exceeded_limits: limitCheck.exceededLimits
|
|
2291
|
+
};
|
|
2292
|
+
}
|
|
2293
|
+
catch (e) {
|
|
2294
|
+
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 }));
|
|
2295
|
+
throw e;
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2020
2298
|
async addToSuccessOutput(event, output, additional_logs) {
|
|
2021
2299
|
// Remove event from failed, skipped, and waiting arrays
|
|
2022
2300
|
this.processingOutput.failure = this.processingOutput.failure.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2023
2301
|
this.processingOutput.skipped = this.processingOutput.skipped.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2024
2302
|
this.processingOutput.waiting = this.processingOutput.waiting.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
2303
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2304
|
+
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2305
|
+
}
|
|
2025
2306
|
this.processingOutput.success.push({ event, output });
|
|
2026
2307
|
await this.processWaitingEvents(additional_logs);
|
|
2027
2308
|
if (this.checkIsSuccessful() && this.doneWithProcessing) {
|
|
@@ -2076,6 +2357,12 @@ class ProcessorService {
|
|
|
2076
2357
|
max = metrices.max;
|
|
2077
2358
|
}
|
|
2078
2359
|
const { allow_fail, retries } = event;
|
|
2360
|
+
let retryable = true;
|
|
2361
|
+
if (event.type === types_1.FeatureEventTypes.STORAGE) {
|
|
2362
|
+
event = (0, processor_utils_1.cleanBlob)(event);
|
|
2363
|
+
if (!this.feature || (this.feature && !event.allow_fail))
|
|
2364
|
+
retryable = false;
|
|
2365
|
+
}
|
|
2079
2366
|
let retries_left = retries || max;
|
|
2080
2367
|
if (exists > -1) {
|
|
2081
2368
|
retries_left = this.processingOutput.failure[exists].retries_left - 1;
|
|
@@ -2122,7 +2409,7 @@ class ProcessorService {
|
|
|
2122
2409
|
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
2410
|
//throw new Error("Run out of retries")
|
|
2124
2411
|
this.end = Date.now();
|
|
2125
|
-
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
2412
|
+
await this.writeResult(types_1.LogEventStatus.FAIL, retryable);
|
|
2126
2413
|
await this.logService.publish();
|
|
2127
2414
|
//throw new Error("Terminate Process")
|
|
2128
2415
|
}
|
|
@@ -2133,52 +2420,15 @@ class ProcessorService {
|
|
|
2133
2420
|
}
|
|
2134
2421
|
}
|
|
2135
2422
|
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
|
-
}
|
|
2423
|
+
var _a;
|
|
2424
|
+
const isSpecial = error_code === '1000';
|
|
2425
|
+
if (isSpecial) {
|
|
2426
|
+
return { allow_fail: true, max: (retries === null || retries === void 0 ? void 0 : retries.max) || 0, retry_at: 500 };
|
|
2427
|
+
}
|
|
2428
|
+
const policy = (_a = retries === null || retries === void 0 ? void 0 : retries.policy) === null || _a === void 0 ? void 0 : _a[error_code];
|
|
2429
|
+
const allow_fail = policy ? policy.available : true;
|
|
2430
|
+
const retry_at = policy ? policy.lag : 0;
|
|
2431
|
+
const max = (retries === null || retries === void 0 ? void 0 : retries.max) || 0;
|
|
2182
2432
|
return { allow_fail, max, retry_at };
|
|
2183
2433
|
}
|
|
2184
2434
|
async sendActionRequest(base_url, resource, payload, method, env) {
|
|
@@ -2204,6 +2454,7 @@ class ProcessorService {
|
|
|
2204
2454
|
timeout: 15000,
|
|
2205
2455
|
withCredentials: false
|
|
2206
2456
|
};
|
|
2457
|
+
console.log("REQUEST!!!!", request);
|
|
2207
2458
|
const response = await axios_1.default.request(request);
|
|
2208
2459
|
return response.data;
|
|
2209
2460
|
}
|
|
@@ -2221,7 +2472,7 @@ class ProcessorService {
|
|
|
2221
2472
|
name: 'Process Storage',
|
|
2222
2473
|
};
|
|
2223
2474
|
try {
|
|
2224
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2475
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
2225
2476
|
this.input = input;
|
|
2226
2477
|
this.start = Date.now();
|
|
2227
2478
|
this.component = types_1.LogEventTypes.STORAGE;
|
|
@@ -2234,12 +2485,11 @@ class ProcessorService {
|
|
|
2234
2485
|
process_id, data: this.clone }, additional_logs);
|
|
2235
2486
|
await this.intializeProduct(additional_logs);
|
|
2236
2487
|
this.process_id = process_id;
|
|
2237
|
-
const productEnv = this.fetchEnv(env, additional_logs);
|
|
2488
|
+
const productEnv = await this.fetchEnv(env, additional_logs);
|
|
2238
2489
|
this.processEnv = productEnv;
|
|
2239
2490
|
if (!productEnv.active) {
|
|
2240
2491
|
throw new Error(`Environment ${env} is not active`);
|
|
2241
2492
|
}
|
|
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
2493
|
const payload = {
|
|
2244
2494
|
type: types_1.FeatureEventTypes.STORAGE,
|
|
2245
2495
|
event,
|
|
@@ -2254,7 +2504,7 @@ class ProcessorService {
|
|
|
2254
2504
|
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
2505
|
await this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
2256
2506
|
await this.logService.publish();
|
|
2257
|
-
return result;
|
|
2507
|
+
return Object.assign(Object.assign({}, result), { process_id: this.process_id });
|
|
2258
2508
|
}
|
|
2259
2509
|
catch (e) {
|
|
2260
2510
|
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 +2525,7 @@ class ProcessorService {
|
|
|
2275
2525
|
name: `Subscribe to broker topic`,
|
|
2276
2526
|
};
|
|
2277
2527
|
try {
|
|
2278
|
-
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2528
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
|
|
2279
2529
|
this.start = Date.now();
|
|
2280
2530
|
this.productTag = data.product;
|
|
2281
2531
|
const process_id = (0, processor_utils_1.generateObjectId)();
|
|
@@ -2284,7 +2534,7 @@ class ProcessorService {
|
|
|
2284
2534
|
await this.intializeProduct(additional_logs);
|
|
2285
2535
|
this.baseLogs.product_id = this.productId;
|
|
2286
2536
|
this.process_id = process_id;
|
|
2287
|
-
const productEnv = this.fetchEnv(data.env, additional_logs);
|
|
2537
|
+
const productEnv = await this.fetchEnv(data.env, additional_logs);
|
|
2288
2538
|
this.processEnv = productEnv;
|
|
2289
2539
|
if (!productEnv.active) {
|
|
2290
2540
|
throw new Error(`Environment ${data.env} is not active`);
|
|
@@ -2324,7 +2574,7 @@ class ProcessorService {
|
|
|
2324
2574
|
name: 'Publish to broker topic',
|
|
2325
2575
|
};
|
|
2326
2576
|
try {
|
|
2327
|
-
this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2577
|
+
await this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
|
|
2328
2578
|
this.start = Date.now();
|
|
2329
2579
|
// clone
|
|
2330
2580
|
this.clone = (0, processor_utils_1.structuredClone)(data.input);
|
|
@@ -2336,12 +2586,11 @@ class ProcessorService {
|
|
|
2336
2586
|
await this.intializeProduct(additional_logs);
|
|
2337
2587
|
this.baseLogs.product_id = this.productId;
|
|
2338
2588
|
this.process_id = process_id;
|
|
2339
|
-
const productEnv = this.fetchEnv(data.env, additional_logs);
|
|
2589
|
+
const productEnv = await this.fetchEnv(data.env, additional_logs);
|
|
2340
2590
|
this.processEnv = productEnv;
|
|
2341
2591
|
if (!productEnv.active) {
|
|
2342
2592
|
throw new Error(`Environment ${data.env} is not active`);
|
|
2343
2593
|
}
|
|
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
2594
|
const payload = {
|
|
2346
2595
|
type: types_1.FeatureEventTypes.PUBLISH,
|
|
2347
2596
|
event: data.event,
|
|
@@ -2365,7 +2614,113 @@ class ProcessorService {
|
|
|
2365
2614
|
return { process_id: this.process_id };
|
|
2366
2615
|
}
|
|
2367
2616
|
}
|
|
2368
|
-
async processJob(job) {
|
|
2617
|
+
async processJob(job, additional_logs = {}) {
|
|
2618
|
+
var _a;
|
|
2619
|
+
const productJob = await this.productBuilderService.fetchJob(job.event);
|
|
2620
|
+
if (!productJob) {
|
|
2621
|
+
throw new Error(`Job ${job.event} not found`);
|
|
2622
|
+
}
|
|
2623
|
+
await this.validateActionDataMappingInput(job.input, productJob.type);
|
|
2624
|
+
const NOW = Date.now();
|
|
2625
|
+
// Treat anything above Jan 1, 2023 as a timestamp (to be safe and future-proof)
|
|
2626
|
+
const IS_PROBABLY_TIMESTAMP = job.start_at > 1672531200000;
|
|
2627
|
+
const delay = Math.max(0, IS_PROBABLY_TIMESTAMP ? job.start_at - NOW : job.start_at);
|
|
2628
|
+
let jobInput;
|
|
2629
|
+
if (productJob.type === types_1.JobEventTypes.ACTION) {
|
|
2630
|
+
const input = {
|
|
2631
|
+
env: job.env,
|
|
2632
|
+
product: job.product,
|
|
2633
|
+
app: productJob.app,
|
|
2634
|
+
cache: job.cache,
|
|
2635
|
+
input: job.input,
|
|
2636
|
+
event: job.event,
|
|
2637
|
+
session: job.session
|
|
2638
|
+
};
|
|
2639
|
+
jobInput = input;
|
|
2640
|
+
}
|
|
2641
|
+
else if (productJob.type === types_1.JobEventTypes.DATABASE_ACTION) {
|
|
2642
|
+
const input = {
|
|
2643
|
+
env: job.env,
|
|
2644
|
+
product: job.product,
|
|
2645
|
+
cache: job.cache,
|
|
2646
|
+
input: job.input,
|
|
2647
|
+
event: job.event,
|
|
2648
|
+
session: job.session,
|
|
2649
|
+
};
|
|
2650
|
+
jobInput = input;
|
|
2651
|
+
}
|
|
2652
|
+
else if (productJob.type === types_1.JobEventTypes.FALLBACK || productJob.type === types_1.JobEventTypes.QUOTA || productJob.type === types_1.JobEventTypes.FEATURE) {
|
|
2653
|
+
const input = {
|
|
2654
|
+
input: job.input,
|
|
2655
|
+
product: job.product,
|
|
2656
|
+
env: job.env,
|
|
2657
|
+
tag: job.event,
|
|
2658
|
+
session: job.session,
|
|
2659
|
+
cache: job.cache,
|
|
2660
|
+
};
|
|
2661
|
+
jobInput = input;
|
|
2662
|
+
}
|
|
2663
|
+
else if (productJob.type === types_1.JobEventTypes.NOTIFICATION) {
|
|
2664
|
+
const input = {
|
|
2665
|
+
env: job.env,
|
|
2666
|
+
product: job.product,
|
|
2667
|
+
event: job.event,
|
|
2668
|
+
input: job.input,
|
|
2669
|
+
session: job.session,
|
|
2670
|
+
cache: job.cache
|
|
2671
|
+
};
|
|
2672
|
+
jobInput = input;
|
|
2673
|
+
}
|
|
2674
|
+
else if (productJob.type === types_1.JobEventTypes.PUBLISH) {
|
|
2675
|
+
const input = {
|
|
2676
|
+
env: job.env,
|
|
2677
|
+
product: job.product,
|
|
2678
|
+
event: job.event,
|
|
2679
|
+
cache: job.cache,
|
|
2680
|
+
session: job.session,
|
|
2681
|
+
input: job.input
|
|
2682
|
+
};
|
|
2683
|
+
jobInput = input;
|
|
2684
|
+
}
|
|
2685
|
+
else if (productJob.type === types_1.JobEventTypes.STORAGE) {
|
|
2686
|
+
const input = {
|
|
2687
|
+
env: job.env,
|
|
2688
|
+
product: job.product,
|
|
2689
|
+
event: job.event,
|
|
2690
|
+
cache: job.cache,
|
|
2691
|
+
session: job.session,
|
|
2692
|
+
input: job.input
|
|
2693
|
+
};
|
|
2694
|
+
jobInput = input;
|
|
2695
|
+
}
|
|
2696
|
+
else {
|
|
2697
|
+
throw new Error(`Job type ${productJob.type} not supported`);
|
|
2698
|
+
}
|
|
2699
|
+
const options = {};
|
|
2700
|
+
// Handle `delay` only if repeat.every is not defined
|
|
2701
|
+
if (!((_a = job.repeat) === null || _a === void 0 ? void 0 : _a.every)) {
|
|
2702
|
+
options.delay = delay;
|
|
2703
|
+
}
|
|
2704
|
+
// Add repeat config if defined
|
|
2705
|
+
if (job.repeat) {
|
|
2706
|
+
const { every, cron, tz, limit, endDate } = job.repeat;
|
|
2707
|
+
options.repeat = cron
|
|
2708
|
+
? {
|
|
2709
|
+
cron,
|
|
2710
|
+
tz,
|
|
2711
|
+
limit,
|
|
2712
|
+
endDate,
|
|
2713
|
+
}
|
|
2714
|
+
: every
|
|
2715
|
+
? {
|
|
2716
|
+
every,
|
|
2717
|
+
limit,
|
|
2718
|
+
endDate,
|
|
2719
|
+
}
|
|
2720
|
+
: undefined;
|
|
2721
|
+
}
|
|
2722
|
+
await this.queues.jobs.add(productJob.type, jobInput, options);
|
|
2723
|
+
}
|
|
2369
2724
|
async sendExpoNotification(payload, device_tokens) {
|
|
2370
2725
|
const message = {
|
|
2371
2726
|
to: device_tokens,
|
|
@@ -2404,24 +2759,18 @@ class ProcessorService {
|
|
|
2404
2759
|
}
|
|
2405
2760
|
}
|
|
2406
2761
|
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
2762
|
(0, processor_utils_1.validateNotification)(template, payload);
|
|
2409
2763
|
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
2764
|
const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
|
|
2412
2765
|
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
2766
|
await this.sendExpoNotification({ title, body, data }, payload.device_tokens);
|
|
2415
2767
|
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
2768
|
}
|
|
2417
2769
|
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
2770
|
(0, processor_utils_1.validateNotification)(template, payload);
|
|
2420
2771
|
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
2772
|
const { title, body, data } = (0, processor_utils_1.generateNotificationTemplate)(template, payload);
|
|
2423
2773
|
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
2774
|
await this.sendFirebaseNotification({ title, body, data }, payload.device_tokens, notification.credentials);
|
|
2426
2775
|
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
2776
|
}
|
|
@@ -2431,10 +2780,8 @@ class ProcessorService {
|
|
|
2431
2780
|
const input = notification.input;
|
|
2432
2781
|
try {
|
|
2433
2782
|
//await this.intializeProduct(additional_logs);
|
|
2434
|
-
this.
|
|
2435
|
-
|
|
2436
|
-
const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
|
|
2437
|
-
const message = this.productBuilderService.fetchNotificationMessage(event);
|
|
2783
|
+
const notificationEvent = await this.productBuilderService.fetchNotification(event.split(":")[0]);
|
|
2784
|
+
const message = await this.productBuilderService.fetchNotificationMessage(event);
|
|
2438
2785
|
if (!message) {
|
|
2439
2786
|
throw new Error(`Message ${event} not found`);
|
|
2440
2787
|
}
|
|
@@ -2452,15 +2799,23 @@ class ProcessorService {
|
|
|
2452
2799
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2453
2800
|
}));
|
|
2454
2801
|
//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
2802
|
if (push && notifications.type === types_1.Notifiers.EXPO) {
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2803
|
+
try {
|
|
2804
|
+
await this.ProcessExpoNotification(notifications, message, input.push_notification, additional_logs);
|
|
2805
|
+
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 }));
|
|
2806
|
+
}
|
|
2807
|
+
catch (e) {
|
|
2808
|
+
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 }));
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
if (push && notifications.type === types_1.Notifiers.FIREBASE) {
|
|
2812
|
+
try {
|
|
2813
|
+
await this.ProcessFirebaseNotification(notifications, message, input.push_notification, additional_logs);
|
|
2814
|
+
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 }));
|
|
2815
|
+
}
|
|
2816
|
+
catch (e) {
|
|
2817
|
+
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 }));
|
|
2818
|
+
}
|
|
2464
2819
|
}
|
|
2465
2820
|
if (email && emails) {
|
|
2466
2821
|
input.email.subject = await this.generatePayload(input.email.subject, notification, additional_logs, message.email_data.filter((data) => data.parent_key === 'subject'));
|
|
@@ -2472,37 +2827,28 @@ class ProcessorService {
|
|
|
2472
2827
|
}));
|
|
2473
2828
|
//await this.inputService.validateInput(validationPayload, message.email_data);
|
|
2474
2829
|
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
2830
|
const { sender_email: from } = emails, auth = __rest(emails, ["sender_email"]);
|
|
2478
2831
|
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
2832
|
const templateMaker = (0, handlebars_1.compile)(email.template);
|
|
2485
2833
|
const template = templateMaker(input.email.template);
|
|
2486
2834
|
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 }));
|
|
2835
|
+
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
2836
|
const mailOptions = {
|
|
2489
2837
|
from,
|
|
2490
2838
|
to: input.email.recipients,
|
|
2491
2839
|
subject,
|
|
2492
2840
|
template,
|
|
2493
2841
|
};
|
|
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
2842
|
try {
|
|
2496
2843
|
const transporter = await (0, processor_utils_1.mailerClient)(auth);
|
|
2497
2844
|
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 }));
|
|
2845
|
+
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
2846
|
}
|
|
2500
2847
|
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 }));
|
|
2848
|
+
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
2849
|
}
|
|
2503
2850
|
}
|
|
2504
2851
|
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
2852
|
const payload = {
|
|
2507
2853
|
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
2854
|
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 +2864,29 @@ class ProcessorService {
|
|
|
2518
2864
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2519
2865
|
}));
|
|
2520
2866
|
//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
2867
|
const url = new URL(callbacks.url);
|
|
2523
2868
|
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
2869
|
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 }));
|
|
2870
|
+
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
2871
|
}
|
|
2528
2872
|
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 }));
|
|
2873
|
+
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
2874
|
}
|
|
2531
2875
|
}
|
|
2532
2876
|
if (sms && smses) {
|
|
2533
2877
|
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
2878
|
input.sms.body = await (0, processor_utils_1.replacePlaceholderString)(sms, input.sms.body);
|
|
2536
2879
|
const SmsClient = await (0, sms_repo_1.loadSMSClient)();
|
|
2537
2880
|
const smsClient = new SmsClient(smses);
|
|
2538
2881
|
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
2882
|
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 }));
|
|
2883
|
+
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
2884
|
}
|
|
2542
2885
|
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 }));
|
|
2886
|
+
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
2887
|
}
|
|
2545
2888
|
}
|
|
2546
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), {
|
|
2889
|
+
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
2890
|
}
|
|
2548
2891
|
catch (e) {
|
|
2549
2892
|
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 }));
|
|
@@ -2566,14 +2909,14 @@ class ProcessorService {
|
|
|
2566
2909
|
name: 'Run Migration',
|
|
2567
2910
|
};
|
|
2568
2911
|
await this.intializeProduct(additional_logs);
|
|
2569
|
-
const db = this.productBuilderService.fetchDatabase(dbTag);
|
|
2912
|
+
const db = await this.productBuilderService.fetchDatabase(dbTag);
|
|
2570
2913
|
if (!db) {
|
|
2571
2914
|
throw new Error('Database not found');
|
|
2572
2915
|
}
|
|
2573
2916
|
if (db.type === types_1.DatabaseTypes.MONGODB) {
|
|
2574
2917
|
throw new Error(`${db.type} does not support migrations`);
|
|
2575
2918
|
}
|
|
2576
|
-
const migration = this.productBuilderService.fetchDatabaseMigration(tag);
|
|
2919
|
+
const migration = await this.productBuilderService.fetchDatabaseMigration(tag);
|
|
2577
2920
|
if (!migration) {
|
|
2578
2921
|
throw new Error('Database migration not found');
|
|
2579
2922
|
}
|
|
@@ -2581,12 +2924,11 @@ class ProcessorService {
|
|
|
2581
2924
|
if (!dbEnv) {
|
|
2582
2925
|
throw new Error(`Environment ${env} not found`);
|
|
2583
2926
|
}
|
|
2584
|
-
const productEnv = this.fetchEnv(env, additional_logs);
|
|
2927
|
+
const productEnv = await this.fetchEnv(env, additional_logs);
|
|
2585
2928
|
if (!productEnv.active) {
|
|
2586
2929
|
throw new Error(`Environment ${env} is not active`);
|
|
2587
2930
|
}
|
|
2588
|
-
const
|
|
2589
|
-
const migrations = this.productBuilderService.fetchDatabaseMigrations(dbTag);
|
|
2931
|
+
const migrations = await this.productBuilderService.fetchDatabaseMigrations(dbTag);
|
|
2590
2932
|
//this.processEnv = productEnv;
|
|
2591
2933
|
/* const check = migration.envs.find((migrationEnv) => migrationEnv.slug === env);
|
|
2592
2934
|
if (!check) {
|
|
@@ -2598,7 +2940,7 @@ class ProcessorService {
|
|
|
2598
2940
|
const migrationsToRun = (0, processor_utils_1.getMigrationsToRun)((0, processor_utils_1.structuredClone)(migrations), type, migrationTag, env);
|
|
2599
2941
|
if (db.type === types_1.DatabaseTypes.POSTGRES) {
|
|
2600
2942
|
const PostgresDBHandler = await (0, postgres_repo_1.loadPostgresHandler)();
|
|
2601
|
-
const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(dbEnv.connection_url,
|
|
2943
|
+
const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(dbEnv.connection_url, this.productBuilderService.fetchPrivateKey()));
|
|
2602
2944
|
for (const migrationToRun of migrationsToRun) {
|
|
2603
2945
|
const envS = migration.envs.find((envT) => envT.slug === env && type === envT.type);
|
|
2604
2946
|
if (envS && envS.status === types_1.MigrationStatus.PROCESSED) {
|
|
@@ -2667,7 +3009,7 @@ class ProcessorService {
|
|
|
2667
3009
|
status: LogEventStatus.PROCESSING,
|
|
2668
3010
|
});
|
|
2669
3011
|
|
|
2670
|
-
const cloudFunction = this.productBuilderService.fetchFunction(data.event);
|
|
3012
|
+
const cloudFunction = await this.productBuilderService.fetchFunction(data.event);
|
|
2671
3013
|
|
|
2672
3014
|
this.logService.add({
|
|
2673
3015
|
...this.baseLogs,
|
|
@@ -2728,18 +3070,15 @@ class ProcessorService {
|
|
|
2728
3070
|
const input = data.input;
|
|
2729
3071
|
try {
|
|
2730
3072
|
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
3073
|
const storage = await this.productBuilderService.fetchStorage(event);
|
|
2734
3074
|
const storageEnv = storage.envs.find((el) => el.slug === env.slug);
|
|
2735
3075
|
if (!storageEnv) {
|
|
2736
3076
|
throw new Error(`Storage env for ${env.slug} not found`);
|
|
2737
3077
|
}
|
|
2738
3078
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch storage details - success', data: { storage }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2739
|
-
const product = this.productBuilderService.fetchProduct();
|
|
2740
3079
|
let result;
|
|
2741
3080
|
if (cache_tag && this.redisClient) {
|
|
2742
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
3081
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
2743
3082
|
if (!productCache) {
|
|
2744
3083
|
throw new Error('Invalid cache tag ');
|
|
2745
3084
|
}
|
|
@@ -2747,42 +3086,39 @@ class ProcessorService {
|
|
|
2747
3086
|
const check = await this.fetchFromCache({
|
|
2748
3087
|
cache_tag,
|
|
2749
3088
|
input: inputString,
|
|
2750
|
-
privateKey:
|
|
3089
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
2751
3090
|
expiry: productCache.expiry,
|
|
2752
|
-
});
|
|
3091
|
+
}, additional_logs);
|
|
2753
3092
|
if (check) {
|
|
2754
3093
|
result = JSON.parse(check);
|
|
2755
3094
|
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
3095
|
return result;
|
|
2757
3096
|
}
|
|
2758
3097
|
}
|
|
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
3098
|
input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
|
|
2761
3099
|
input.fileName = input.fileName ? await this.generateStringValues(input.fileName, '', additional_logs, []) : undefined;
|
|
2762
3100
|
input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
|
|
2763
3101
|
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
3102
|
if (cache_tag && this.redisClient) {
|
|
2766
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
3103
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
2767
3104
|
if (!productCache) {
|
|
2768
3105
|
throw new Error('Invalid cache tag ');
|
|
2769
3106
|
}
|
|
2770
3107
|
const inputString = JSON.stringify(input);
|
|
2771
3108
|
await this.addToCache({
|
|
2772
3109
|
input: inputString,
|
|
2773
|
-
privateKey:
|
|
3110
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
2774
3111
|
data: JSON.stringify(result),
|
|
2775
3112
|
cache_tag,
|
|
2776
3113
|
timestamp: Date.now(),
|
|
2777
3114
|
component_tag: event,
|
|
2778
3115
|
component_type: types_1.ProductComponents.STORAGE,
|
|
2779
3116
|
product_tag: this.productTag,
|
|
2780
|
-
});
|
|
3117
|
+
}, additional_logs);
|
|
2781
3118
|
}
|
|
2782
3119
|
return result;
|
|
2783
3120
|
}
|
|
2784
3121
|
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
3122
|
throw e;
|
|
2787
3123
|
}
|
|
2788
3124
|
}
|
|
@@ -2791,10 +3127,7 @@ class ProcessorService {
|
|
|
2791
3127
|
const input = db_action.input;
|
|
2792
3128
|
try {
|
|
2793
3129
|
//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
3130
|
const [database_tag, action_tag] = event.split(':');
|
|
2797
|
-
const product = this.productBuilderService.fetchProduct();
|
|
2798
3131
|
const database = await this.productBuilderService.fetchDatabase(database_tag);
|
|
2799
3132
|
const databaseAction = await this.productBuilderService.fetchDatabaseAction(event);
|
|
2800
3133
|
const databaseEnv = database.envs.find((el) => el.slug === env.slug);
|
|
@@ -2802,7 +3135,6 @@ class ProcessorService {
|
|
|
2802
3135
|
throw new Error(`Database env for ${env.slug} not found`);
|
|
2803
3136
|
}
|
|
2804
3137
|
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
3138
|
input.data = await this.generatePayload(input.data, db_action, additional_logs, databaseAction.data);
|
|
2807
3139
|
if (Array.isArray(input.data)) {
|
|
2808
3140
|
await Promise.all(input.data.map(async (d) => {
|
|
@@ -2830,14 +3162,12 @@ class ProcessorService {
|
|
|
2830
3162
|
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
3163
|
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
2832
3164
|
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
3165
|
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
3166
|
}
|
|
2836
3167
|
}
|
|
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
3168
|
let result;
|
|
2839
3169
|
if (cache_tag && this.redisClient) {
|
|
2840
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
3170
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
2841
3171
|
if (!productCache) {
|
|
2842
3172
|
throw new Error('Invalid cache tag ');
|
|
2843
3173
|
}
|
|
@@ -2845,9 +3175,9 @@ class ProcessorService {
|
|
|
2845
3175
|
const check = await this.fetchFromCache({
|
|
2846
3176
|
cache_tag,
|
|
2847
3177
|
input: inputString,
|
|
2848
|
-
privateKey:
|
|
3178
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
2849
3179
|
expiry: productCache.expiry,
|
|
2850
|
-
});
|
|
3180
|
+
}, additional_logs);
|
|
2851
3181
|
if (check) {
|
|
2852
3182
|
result = JSON.parse(check);
|
|
2853
3183
|
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 }));
|
|
@@ -2876,32 +3206,32 @@ class ProcessorService {
|
|
|
2876
3206
|
if (!PostgresDBHandler) {
|
|
2877
3207
|
throw new Error(`Running in browser, postgres handler not loaded.`);
|
|
2878
3208
|
}
|
|
2879
|
-
const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.
|
|
3209
|
+
const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchPrivateKey()));
|
|
2880
3210
|
if (databaseAction.type !== types_1.DatabaseActionTypes.AGGREGATE) {
|
|
2881
3211
|
result = await pgHandler[databaseAction.type](databaseAction.data, template, input.data);
|
|
2882
3212
|
}
|
|
2883
3213
|
}
|
|
2884
3214
|
//await this.logService.publish();
|
|
2885
3215
|
// 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
3216
|
await this.addToSuccessOutput(db_action, result, additional_logs);
|
|
2888
3217
|
if (cache_tag && this.redisClient) {
|
|
2889
|
-
const productCache = this.productBuilderService.fetchCache(cache_tag);
|
|
3218
|
+
const productCache = await this.productBuilderService.fetchCache(cache_tag);
|
|
2890
3219
|
if (!productCache) {
|
|
2891
3220
|
throw new Error('Invalid cache tag ');
|
|
2892
3221
|
}
|
|
2893
3222
|
const inputString = JSON.stringify(input);
|
|
2894
3223
|
await this.addToCache({
|
|
2895
3224
|
input: inputString,
|
|
2896
|
-
privateKey:
|
|
3225
|
+
privateKey: this.productBuilderService.fetchPrivateKey(),
|
|
2897
3226
|
data: JSON.stringify(result),
|
|
2898
3227
|
cache_tag,
|
|
2899
3228
|
timestamp: Date.now(),
|
|
2900
3229
|
product_tag: this.productTag,
|
|
2901
3230
|
component_tag: database_tag,
|
|
2902
3231
|
component_type: types_1.ProductComponents.DATABASE_ACTION,
|
|
2903
|
-
});
|
|
3232
|
+
}, additional_logs);
|
|
2904
3233
|
}
|
|
3234
|
+
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
3235
|
return result;
|
|
2906
3236
|
}
|
|
2907
3237
|
catch (e) {
|
|
@@ -2914,10 +3244,8 @@ class ProcessorService {
|
|
|
2914
3244
|
const input = data.input;
|
|
2915
3245
|
try {
|
|
2916
3246
|
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
3247
|
const [brokerTag, topicTag] = event.split(':');
|
|
2920
|
-
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
3248
|
+
const broker = await this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
2921
3249
|
if (!broker) {
|
|
2922
3250
|
throw new Error(`Message Broker ${brokerTag} not found`);
|
|
2923
3251
|
}
|
|
@@ -2925,7 +3253,7 @@ class ProcessorService {
|
|
|
2925
3253
|
if (!brokerEnv) {
|
|
2926
3254
|
throw new Error(`Broker env for ${env.slug} not found`);
|
|
2927
3255
|
}
|
|
2928
|
-
const topic = this.productBuilderService.fetchMessageBrokerTopic(event);
|
|
3256
|
+
const topic = await this.productBuilderService.fetchMessageBrokerTopic(event);
|
|
2929
3257
|
if (!topic) {
|
|
2930
3258
|
throw new Error(`Topic ${topicTag} not found in broker ${brokerTag}`);
|
|
2931
3259
|
}
|
|
@@ -2941,12 +3269,13 @@ class ProcessorService {
|
|
|
2941
3269
|
url = queueUrl.url;
|
|
2942
3270
|
}
|
|
2943
3271
|
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
3272
|
const createBrokerService = await loadBrokerService();
|
|
2946
3273
|
if (createBrokerService) {
|
|
2947
3274
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
2948
3275
|
await brokerService.subscribe(url, input.callback);
|
|
2949
|
-
|
|
3276
|
+
if (this.feature) {
|
|
3277
|
+
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 }));
|
|
3278
|
+
}
|
|
2950
3279
|
return;
|
|
2951
3280
|
}
|
|
2952
3281
|
else {
|
|
@@ -2964,10 +3293,8 @@ class ProcessorService {
|
|
|
2964
3293
|
const input = data.input;
|
|
2965
3294
|
try {
|
|
2966
3295
|
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
3296
|
const [brokerTag, topicTag] = event.split(':');
|
|
2970
|
-
const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
3297
|
+
const broker = await this.productBuilderService.fetchMessageBroker(brokerTag);
|
|
2971
3298
|
if (!broker) {
|
|
2972
3299
|
throw new Error(`Message Broker ${brokerTag} not found`);
|
|
2973
3300
|
}
|
|
@@ -2975,7 +3302,7 @@ class ProcessorService {
|
|
|
2975
3302
|
if (!brokerEnv) {
|
|
2976
3303
|
throw new Error(`Broker env for ${env.slug} not found`);
|
|
2977
3304
|
}
|
|
2978
|
-
const topic = this.productBuilderService.fetchMessageBrokerTopic(event);
|
|
3305
|
+
const topic = await this.productBuilderService.fetchMessageBrokerTopic(event);
|
|
2979
3306
|
if (!topic) {
|
|
2980
3307
|
throw new Error(`Topic ${topicTag} not found in broker ${brokerTag}`);
|
|
2981
3308
|
}
|
|
@@ -2991,12 +3318,13 @@ class ProcessorService {
|
|
|
2991
3318
|
url = queueUrl.url;
|
|
2992
3319
|
}
|
|
2993
3320
|
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
3321
|
const createBrokerService = await loadBrokerService();
|
|
2996
3322
|
if (createBrokerService) {
|
|
2997
3323
|
const brokerService = createBrokerService(brokerEnv.type, brokerEnv.config);
|
|
2998
3324
|
await brokerService.publish(url, input.message);
|
|
2999
|
-
|
|
3325
|
+
if (this.feature) {
|
|
3326
|
+
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 }));
|
|
3327
|
+
}
|
|
3000
3328
|
return;
|
|
3001
3329
|
}
|
|
3002
3330
|
else {
|
|
@@ -3038,9 +3366,10 @@ class ProcessorService {
|
|
|
3038
3366
|
const result = { url: await (0, storage_util_1.uploadBlobToCloud)({ data: input.buffer, destinationPath: input.fileName, config }) };
|
|
3039
3367
|
try {
|
|
3040
3368
|
await this.processorApiService.saveFileURL({
|
|
3041
|
-
url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.
|
|
3369
|
+
url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchPrivateKey()),
|
|
3042
3370
|
provider: storageEnv.type,
|
|
3043
3371
|
product: this.productTag,
|
|
3372
|
+
process_id: this.process_id,
|
|
3044
3373
|
workspace_id: this.workspace_id,
|
|
3045
3374
|
type: input.mimeType,
|
|
3046
3375
|
event: data.event,
|
|
@@ -3091,18 +3420,19 @@ class ProcessorService {
|
|
|
3091
3420
|
return value;
|
|
3092
3421
|
}
|
|
3093
3422
|
}
|
|
3094
|
-
async writeResult(status) {
|
|
3423
|
+
async writeResult(status, retryable = true) {
|
|
3095
3424
|
this.processorApiService.saveResult({
|
|
3096
3425
|
status,
|
|
3097
3426
|
component: this.component,
|
|
3098
3427
|
start: this.start,
|
|
3099
3428
|
end: this.end,
|
|
3100
|
-
|
|
3429
|
+
retryable,
|
|
3430
|
+
result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchPrivateKey()),
|
|
3101
3431
|
process_id: this.process_id,
|
|
3102
3432
|
feature_id: this.feature ? this.feature._id : null,
|
|
3103
3433
|
product_id: this.productId,
|
|
3104
3434
|
env: this.processEnv.slug,
|
|
3105
|
-
input: this.input,
|
|
3435
|
+
input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchPrivateKey()),
|
|
3106
3436
|
}, this.getUserAccess());
|
|
3107
3437
|
}
|
|
3108
3438
|
async validateActionDataMappingInput(input, type) {
|
|
@@ -3134,7 +3464,7 @@ class ProcessorService {
|
|
|
3134
3464
|
this.component = types_1.LogEventTypes.ACTION;
|
|
3135
3465
|
try {
|
|
3136
3466
|
// validate input do not allow $Sequence or $Length and $Size of $Input
|
|
3137
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3467
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
|
|
3138
3468
|
this.input = action;
|
|
3139
3469
|
this.start = Date.now();
|
|
3140
3470
|
this.productTag = product_tag;
|
|
@@ -3148,14 +3478,14 @@ class ProcessorService {
|
|
|
3148
3478
|
data: input,
|
|
3149
3479
|
};
|
|
3150
3480
|
await this.intializeProduct(additional_logs);
|
|
3481
|
+
await this.initializePricing(additional_logs, app);
|
|
3151
3482
|
this.process_id = process_id;
|
|
3152
3483
|
this.baseLogs.product_id = this.productId;
|
|
3153
|
-
const productEnv = this.fetchEnv(env, additional_logs);
|
|
3484
|
+
const productEnv = await this.fetchEnv(env, additional_logs);
|
|
3154
3485
|
this.processEnv = productEnv;
|
|
3155
3486
|
if (!productEnv.active) {
|
|
3156
3487
|
throw new Error(`Environment ${env} is not active`);
|
|
3157
3488
|
}
|
|
3158
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action initiated', status: types_1.LogEventStatus.PROCESSING }));
|
|
3159
3489
|
const result = await this.runAction({
|
|
3160
3490
|
type: types_1.FeatureEventTypes.ACTION,
|
|
3161
3491
|
event,
|
|
@@ -3173,7 +3503,8 @@ class ProcessorService {
|
|
|
3173
3503
|
return result;
|
|
3174
3504
|
}
|
|
3175
3505
|
catch (e) {
|
|
3176
|
-
|
|
3506
|
+
console.log("ERRRRROORRRRR!!!!!!", e);
|
|
3507
|
+
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
3508
|
this.end = Date.now();
|
|
3178
3509
|
await this.writeResult(types_1.LogEventStatus.FAIL);
|
|
3179
3510
|
await this.logService.publish();
|
|
@@ -3195,7 +3526,7 @@ class ProcessorService {
|
|
|
3195
3526
|
name: 'Process database action',
|
|
3196
3527
|
};
|
|
3197
3528
|
try {
|
|
3198
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3529
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
|
|
3199
3530
|
this.input = action;
|
|
3200
3531
|
this.start = Date.now();
|
|
3201
3532
|
this.productTag = product_tag;
|
|
@@ -3205,12 +3536,11 @@ class ProcessorService {
|
|
|
3205
3536
|
await this.intializeProduct(additional_logs);
|
|
3206
3537
|
this.baseLogs.product_id = this.productId;
|
|
3207
3538
|
this.process_id = process_id;
|
|
3208
|
-
const productEnv = this.fetchEnv(env, additional_logs);
|
|
3539
|
+
const productEnv = await this.fetchEnv(env, additional_logs);
|
|
3209
3540
|
this.processEnv = productEnv;
|
|
3210
3541
|
if (!productEnv.active) {
|
|
3211
3542
|
throw new Error(`Environment ${env} is not active`);
|
|
3212
3543
|
}
|
|
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
3544
|
const payload = {
|
|
3215
3545
|
type: types_1.FeatureEventTypes.DB_ACTION,
|
|
3216
3546
|
event,
|
|
@@ -3250,7 +3580,7 @@ class ProcessorService {
|
|
|
3250
3580
|
name: 'Process Notification',
|
|
3251
3581
|
};
|
|
3252
3582
|
try {
|
|
3253
|
-
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3583
|
+
await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
|
|
3254
3584
|
this.input = action;
|
|
3255
3585
|
this.start = Date.now();
|
|
3256
3586
|
this.productTag = product_tag;
|
|
@@ -3260,12 +3590,11 @@ class ProcessorService {
|
|
|
3260
3590
|
await this.intializeProduct(additional_logs);
|
|
3261
3591
|
this.process_id = process_id;
|
|
3262
3592
|
this.baseLogs.product_id = this.productId;
|
|
3263
|
-
const productEnv = this.fetchEnv(env, additional_logs);
|
|
3593
|
+
const productEnv = await this.fetchEnv(env, additional_logs);
|
|
3264
3594
|
this.processEnv = productEnv;
|
|
3265
3595
|
if (!productEnv.active) {
|
|
3266
3596
|
throw new Error(`Environment ${env} is not active`);
|
|
3267
3597
|
}
|
|
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
3598
|
const payload = {
|
|
3270
3599
|
type: types_1.FeatureEventTypes.NOTIFICATION,
|
|
3271
3600
|
event,
|
|
@@ -3293,7 +3622,7 @@ class ProcessorService {
|
|
|
3293
3622
|
try {
|
|
3294
3623
|
const data = await this.processorApiService.fetchRemoteCaches(payload, this.getUserAccess());
|
|
3295
3624
|
return data.map((data) => {
|
|
3296
|
-
data.value = (0, processor_utils_1.decrypt)(data.value, this.productBuilderService.
|
|
3625
|
+
data.value = (0, processor_utils_1.decrypt)(data.value, this.productBuilderService.fetchPrivateKey());
|
|
3297
3626
|
return data;
|
|
3298
3627
|
});
|
|
3299
3628
|
}
|
|
@@ -3309,7 +3638,7 @@ class ProcessorService {
|
|
|
3309
3638
|
public_key: this.public_key,
|
|
3310
3639
|
};
|
|
3311
3640
|
}
|
|
3312
|
-
async addToCache(payload) {
|
|
3641
|
+
async addToCache(payload, additional_logs) {
|
|
3313
3642
|
if (!this.redisClient) {
|
|
3314
3643
|
throw 'redis client not setup';
|
|
3315
3644
|
}
|
|
@@ -3325,13 +3654,15 @@ class ProcessorService {
|
|
|
3325
3654
|
product_tag,
|
|
3326
3655
|
component_tag,
|
|
3327
3656
|
component_type }), this.getUserAccess());
|
|
3657
|
+
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
3658
|
await this.redisClient.hSet(key, 'data', encryptedData);
|
|
3329
3659
|
await this.redisClient.hSet(key, 'lastUpdated', timestamp);
|
|
3330
3660
|
}
|
|
3331
|
-
async fetchFromCache(payload) {
|
|
3661
|
+
async fetchFromCache(payload, additional_logs) {
|
|
3332
3662
|
var _a;
|
|
3333
3663
|
const { input, privateKey, cache_tag, expiry } = payload;
|
|
3334
3664
|
const key = `${cache_tag}-${CryptoJS.SHA512(input)}`;
|
|
3665
|
+
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
3666
|
if (!this.redisClient) {
|
|
3336
3667
|
return null;
|
|
3337
3668
|
}
|
|
@@ -3339,8 +3670,10 @@ class ProcessorService {
|
|
|
3339
3670
|
if (!record || !record.data || !record.lastUpdated) {
|
|
3340
3671
|
const checkRemote = await this.processorApiService.fetchRemoteCacheByKey(key, this.getUserAccess());
|
|
3341
3672
|
if (!checkRemote) {
|
|
3673
|
+
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
3674
|
return null;
|
|
3343
3675
|
}
|
|
3676
|
+
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
3677
|
record = { data: checkRemote.value, expiresAt: (_a = checkRemote.expiry) === null || _a === void 0 ? void 0 : _a.getTime().toString() };
|
|
3345
3678
|
}
|
|
3346
3679
|
if (record.lastUpdated) {
|
|
@@ -3348,13 +3681,42 @@ class ProcessorService {
|
|
|
3348
3681
|
if (expiry) {
|
|
3349
3682
|
const expiryTime = lastUpdated + expiry;
|
|
3350
3683
|
if (Date.now() > expiryTime) {
|
|
3684
|
+
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
3685
|
await this.redisClient.del(key);
|
|
3352
3686
|
return null;
|
|
3353
3687
|
}
|
|
3354
3688
|
}
|
|
3355
3689
|
}
|
|
3690
|
+
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
3691
|
return (0, processor_utils_1.decrypt)(record.data, privateKey);
|
|
3357
3692
|
}
|
|
3693
|
+
/**
|
|
3694
|
+
* Writes the healthcheck result to Redis cache for fast status retrieval.
|
|
3695
|
+
*/
|
|
3696
|
+
async writeHealthcheckResultToCache(data, result) {
|
|
3697
|
+
if (!this.redisClient)
|
|
3698
|
+
return;
|
|
3699
|
+
const key = `healthcheck:${data.product}:${data.healthcheck}:${data.env}`;
|
|
3700
|
+
console.log("LOG TO CACHE", key, JSON.stringify(result));
|
|
3701
|
+
await this.redisClient.set(key, JSON.stringify(result));
|
|
3702
|
+
console.log();
|
|
3703
|
+
}
|
|
3704
|
+
/**
|
|
3705
|
+
* Fetches the latest healthcheck status for a product/env from Redis cache.
|
|
3706
|
+
*/
|
|
3707
|
+
async getHealthcheckStatusFromCache(productTag, envSlug) {
|
|
3708
|
+
if (!this.redisClient)
|
|
3709
|
+
return null;
|
|
3710
|
+
const key = `healthcheck:${productTag}:${envSlug}`;
|
|
3711
|
+
const cached = await this.redisClient.get(key);
|
|
3712
|
+
return cached ? JSON.parse(cached) : null;
|
|
3713
|
+
}
|
|
3714
|
+
/**
|
|
3715
|
+
* Updates the healthcheck in the remote DB for a product with all envs' results.
|
|
3716
|
+
*/
|
|
3717
|
+
async updateHealthcheckOnProcessor(productTag, envs) {
|
|
3718
|
+
return this.productBuilderService.updateHealthcheck(productTag, { envs });
|
|
3719
|
+
}
|
|
3358
3720
|
}
|
|
3359
3721
|
exports.default = ProcessorService;
|
|
3360
3722
|
//# sourceMappingURL=processor.service.js.map
|