@ductape/sdk 0.0.3-beta1 → 0.0.3-beta11
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.js +2 -2
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/processorApi.service.d.ts +3 -1
- package/dist/api/services/processorApi.service.js +9 -0
- package/dist/api/services/processorApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.js +1 -1
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/urls.d.ts +1 -0
- package/dist/api/urls.js +2 -1
- package/dist/api/urls.js.map +1 -1
- package/dist/apps/services/app.service.d.ts +3 -3
- package/dist/apps/services/app.service.js +84 -50
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/validators/joi-validators/update.appAction.validator.d.ts +2 -2
- package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -11
- package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
- package/dist/imports/repos/postmanV21.repo.js +1 -1
- package/dist/imports/repos/postmanV21.repo.js.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +47 -4
- package/dist/index.js.map +1 -1
- package/dist/inputs/validators/inputs.validator.parse.js +1 -0
- package/dist/inputs/validators/inputs.validator.parse.js.map +1 -1
- package/dist/logs/logs.service.js +1 -1
- package/dist/logs/logs.service.js.map +1 -1
- package/dist/logs/logs.types.d.ts +1 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/processor/services/fallback.service.d.ts +2 -2
- package/dist/processor/services/fallback.service.js +11 -10
- package/dist/processor/services/fallback.service.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +4 -1
- package/dist/processor/services/processor.service.js +98 -19
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/quota.service.d.ts +4 -13
- package/dist/processor/services/quota.service.js +11 -2
- package/dist/processor/services/quota.service.js.map +1 -1
- package/dist/processor/utils/storage.util.js +1 -0
- package/dist/processor/utils/storage.util.js.map +1 -1
- package/dist/products/services/products.service.d.ts +40 -32
- package/dist/products/services/products.service.js +236 -141
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/utils/string.utils.js +1 -0
- package/dist/products/utils/string.utils.js.map +1 -1
- package/dist/products/validators/index.d.ts +3 -1
- package/dist/products/validators/index.js +5 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +25 -18
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productFeature.validator.js +2 -0
- package/dist/products/validators/joi-validators/create.productFeature.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productNotificationMessage.validator.js +1 -1
- package/dist/products/validators/joi-validators/create.productQuota.validator.js +2 -0
- package/dist/products/validators/joi-validators/create.productQuota.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.userAuth.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js +47 -0
- package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.dataValue.validator.d.ts +1 -1
- package/dist/products/validators/joi-validators/update.dataValue.validator.js +3 -2
- package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productFeature.validator.js +2 -0
- package/dist/products/validators/joi-validators/update.productFeature.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productNotificationMessage.validator.js +2 -1
- package/dist/products/validators/joi-validators/update.productNotificationMessage.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productQuota.validator.js +8 -7
- package/dist/products/validators/joi-validators/update.productQuota.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.userAuth.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js +47 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -0
- package/dist/test/test.logs.js +6 -6
- package/dist/test/test.logs.js.map +1 -1
- package/dist/types/appBuilder.types.d.ts +16 -0
- package/dist/types/enums.d.ts +5 -0
- package/dist/types/enums.js +7 -1
- package/dist/types/enums.js.map +1 -1
- package/dist/types/inputs.types.d.ts +2 -0
- package/dist/types/inputs.types.js.map +1 -1
- package/dist/types/processor.types.d.ts +15 -0
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +14 -1
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/package.json +2 -1
|
@@ -67,6 +67,9 @@ const mongo_repo_1 = require("../repos/mongo.repo");
|
|
|
67
67
|
const postgres_repo_1 = require("../repos/postgres.repo");
|
|
68
68
|
const storage_util_1 = require("../utils/storage.util");
|
|
69
69
|
const sms_repo_1 = require("../repos/sms.repo");
|
|
70
|
+
const quota_service_1 = __importDefault(require("./quota.service"));
|
|
71
|
+
const fallback_service_1 = __importDefault(require("./fallback.service"));
|
|
72
|
+
const productsApi_service_1 = require("../../api/services/productsApi.service");
|
|
70
73
|
async function loadBrokerService() {
|
|
71
74
|
if (typeof window === 'undefined') {
|
|
72
75
|
const { createBrokerService } = await Promise.resolve().then(() => __importStar(require('./messagebrokers')));
|
|
@@ -74,6 +77,13 @@ async function loadBrokerService() {
|
|
|
74
77
|
}
|
|
75
78
|
return null;
|
|
76
79
|
}
|
|
80
|
+
async function loadJWT() {
|
|
81
|
+
if (typeof window === undefined) {
|
|
82
|
+
const JWT = await Promise.resolve().then(() => __importStar(require("jsonwebtoken")));
|
|
83
|
+
return JWT;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
77
87
|
class ProcessorService {
|
|
78
88
|
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
|
|
79
89
|
this.workspace_id = workspace_id;
|
|
@@ -100,6 +110,45 @@ class ProcessorService {
|
|
|
100
110
|
if (redis_client) {
|
|
101
111
|
this.redisClient = redis_client;
|
|
102
112
|
}
|
|
113
|
+
this.productApi = new productsApi_service_1.ProductsApiService(env_type);
|
|
114
|
+
}
|
|
115
|
+
async generateSession(payload) {
|
|
116
|
+
try {
|
|
117
|
+
const { product: product_tag, env: slug, tag, data } = payload;
|
|
118
|
+
const input = await this.inputService.parseJson({
|
|
119
|
+
data,
|
|
120
|
+
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
121
|
+
});
|
|
122
|
+
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
123
|
+
// const product = this.productBuilderService.fetchProduct();
|
|
124
|
+
const session = this.productBuilderService.fetchSession(tag);
|
|
125
|
+
if (!session) {
|
|
126
|
+
throw new Error(`Session with tag ${tag} does not exist`);
|
|
127
|
+
}
|
|
128
|
+
const env = this.productBuilderService.fetchEnv(slug);
|
|
129
|
+
if (!env) {
|
|
130
|
+
throw new Error(`Env with slug ${slug} does not exist`);
|
|
131
|
+
}
|
|
132
|
+
await this.inputService.validateInput(input, session.schema_data);
|
|
133
|
+
const expiry = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
|
|
134
|
+
const JWT = await loadJWT();
|
|
135
|
+
if (JWT) {
|
|
136
|
+
const token = JWT.sign(JSON.stringify(Object.assign({ type: "token" }, data)), this.productBuilderService.fetchProduct().private_key, { expiresIn: expiry });
|
|
137
|
+
const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.productBuilderService.fetchProduct().private_key);
|
|
138
|
+
// WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
|
|
139
|
+
await this.processorApiService.createRefreshToken({ product_tag, env: slug, refreshToken }, this.getUserAccess());
|
|
140
|
+
return {
|
|
141
|
+
token,
|
|
142
|
+
refreshToken,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
throw new Error(`Running in browser, token service not loaded.`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
103
152
|
}
|
|
104
153
|
async registerWebhook(data) {
|
|
105
154
|
const { product: product_tag, access_tag, webhook_tag, envs } = data;
|
|
@@ -266,8 +315,21 @@ class ProcessorService {
|
|
|
266
315
|
throw e;
|
|
267
316
|
}
|
|
268
317
|
}
|
|
269
|
-
async runQuotaOptions(options, additional_logs) {
|
|
270
|
-
|
|
318
|
+
async runQuotaOptions(options, additional_logs) {
|
|
319
|
+
const quotaManager = new quota_service_1.default(options);
|
|
320
|
+
const getNextProvider = quotaManager.getNextProvider();
|
|
321
|
+
await this.processEvent({
|
|
322
|
+
type: getNextProvider.type,
|
|
323
|
+
event: getNextProvider.event,
|
|
324
|
+
input: getNextProvider.input,
|
|
325
|
+
retries: getNextProvider.retries,
|
|
326
|
+
allow_fail: false
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
async runFallbackOptions(options, additional_logs) {
|
|
330
|
+
const fallbackManager = new fallback_service_1.default(options);
|
|
331
|
+
await fallbackManager.executeActionWithFallback(this.processEvent);
|
|
332
|
+
}
|
|
271
333
|
async processFallback(data) {
|
|
272
334
|
this.start = Date.now();
|
|
273
335
|
this.input = data;
|
|
@@ -322,12 +384,13 @@ class ProcessorService {
|
|
|
322
384
|
additional_logs = {
|
|
323
385
|
name: 'Process feature',
|
|
324
386
|
type: types_1.LogEventTypes.FEATURE,
|
|
325
|
-
parent_tag: feature_tag,
|
|
326
387
|
};
|
|
388
|
+
console.log(additional_logs);
|
|
327
389
|
await this.intializeProduct(additional_logs);
|
|
328
390
|
this.component = types_1.LogEventTypes.FEATURE;
|
|
329
391
|
const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
|
|
330
392
|
this.process_id = process_id;
|
|
393
|
+
this.feature = this.fetchFeature(feature_tag, additional_logs);
|
|
331
394
|
this.baseLogs = {
|
|
332
395
|
product_tag: this.productTag,
|
|
333
396
|
product_id: this.productId,
|
|
@@ -336,8 +399,9 @@ class ProcessorService {
|
|
|
336
399
|
type: types_1.LogEventTypes.FEATURE,
|
|
337
400
|
process_id,
|
|
338
401
|
data: input,
|
|
402
|
+
feature_tag: feature_tag,
|
|
403
|
+
feature_id: this.feature._id,
|
|
339
404
|
};
|
|
340
|
-
this.feature = this.fetchFeature(feature_tag, additional_logs);
|
|
341
405
|
this.logService.setFeatureId(this.feature._id);
|
|
342
406
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process feature initiated', data: Object.assign(Object.assign({}, data), { input: (0, processor_utils_1.anonymizeObject)(data.input) }), status: types_1.LogEventStatus.PROCESSING }));
|
|
343
407
|
this.processEnv = this.fetchEnv(env, additional_logs);
|
|
@@ -394,6 +458,7 @@ class ProcessorService {
|
|
|
394
458
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Product initialize - success', data: { product_id: this.productId }, status: types_1.LogEventStatus.SUCCESS }));
|
|
395
459
|
}
|
|
396
460
|
catch (e) {
|
|
461
|
+
console.log(e);
|
|
397
462
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Product initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
398
463
|
throw e;
|
|
399
464
|
}
|
|
@@ -1625,11 +1690,13 @@ class ProcessorService {
|
|
|
1625
1690
|
}
|
|
1626
1691
|
async runAction(event, additional_logs, returnValue = false) {
|
|
1627
1692
|
try {
|
|
1693
|
+
console.log("RUNNING ACTION!!!!!");
|
|
1628
1694
|
const { event: action_tag, app: access_tag, condition, cache: cache_tag } = event;
|
|
1629
1695
|
let indexes = [];
|
|
1630
1696
|
if (condition &&
|
|
1631
1697
|
condition.type === types_1.Conditions.CHECK &&
|
|
1632
1698
|
(await this.processConditionalCheck(event, additional_logs))) {
|
|
1699
|
+
console.log("RUNNING ACTION SKIPPED!!!!!");
|
|
1633
1700
|
// if it fails, it would add to skipped queue
|
|
1634
1701
|
return;
|
|
1635
1702
|
}
|
|
@@ -1724,8 +1791,8 @@ class ProcessorService {
|
|
|
1724
1791
|
}
|
|
1725
1792
|
}
|
|
1726
1793
|
catch (e) {
|
|
1727
|
-
|
|
1728
|
-
|
|
1794
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Run Action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
1795
|
+
throw e;
|
|
1729
1796
|
}
|
|
1730
1797
|
}
|
|
1731
1798
|
async processRequest(payload, event, retries, additional_logs, returnValue = false) {
|
|
@@ -1948,7 +2015,7 @@ class ProcessorService {
|
|
|
1948
2015
|
};
|
|
1949
2016
|
try {
|
|
1950
2017
|
this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
|
|
1951
|
-
this.input =
|
|
2018
|
+
this.input = input;
|
|
1952
2019
|
this.start = Date.now();
|
|
1953
2020
|
this.component = types_1.LogEventTypes.STORAGE;
|
|
1954
2021
|
// clone
|
|
@@ -2166,6 +2233,9 @@ class ProcessorService {
|
|
|
2166
2233
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetching notification details', data: { notification }, status: types_1.LogEventStatus.PROCESSING }));
|
|
2167
2234
|
const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
|
|
2168
2235
|
const message = this.productBuilderService.fetchNotificationMessage(event);
|
|
2236
|
+
if (!message) {
|
|
2237
|
+
throw new Error(`Message ${event} not found`);
|
|
2238
|
+
}
|
|
2169
2239
|
const { envs } = notificationEvent;
|
|
2170
2240
|
const { push_notifications: notifications, emails, callbacks, sms: smses } = envs.find((data) => data.slug === notification.env.slug);
|
|
2171
2241
|
const { push_notification: push, email, callback, sms } = message;
|
|
@@ -2281,8 +2351,9 @@ class ProcessorService {
|
|
|
2281
2351
|
}
|
|
2282
2352
|
catch (e) {
|
|
2283
2353
|
console.log(e);
|
|
2284
|
-
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt notification - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2285
|
-
this.logService.publish();
|
|
2354
|
+
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 }));
|
|
2355
|
+
//this.logService.publish();
|
|
2356
|
+
throw e;
|
|
2286
2357
|
}
|
|
2287
2358
|
}
|
|
2288
2359
|
async runMigration(product_tag, tag, env, type) {
|
|
@@ -2492,10 +2563,10 @@ class ProcessorService {
|
|
|
2492
2563
|
}
|
|
2493
2564
|
}
|
|
2494
2565
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Store file - initiated', data: {}, status: types_1.LogEventStatus.PROCESSING }));
|
|
2495
|
-
|
|
2496
|
-
input.
|
|
2497
|
-
input.
|
|
2498
|
-
input.
|
|
2566
|
+
input.buffer = input.buffer ? await this.generateStringValues(input.buffer, '', additional_logs, []) : undefined;
|
|
2567
|
+
input.fileName = input.fileName ? await this.generateStringValues(input.fileName, '', additional_logs, []) : undefined;
|
|
2568
|
+
input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
|
|
2569
|
+
console.log("CHINYERE", input.buffer, input.fileName);
|
|
2499
2570
|
result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
|
|
2500
2571
|
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 }));
|
|
2501
2572
|
if (cache_tag && this.redisClient) {
|
|
@@ -2555,12 +2626,14 @@ class ProcessorService {
|
|
|
2555
2626
|
data: input.data,
|
|
2556
2627
|
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2557
2628
|
}));
|
|
2558
|
-
const filterValidationPayload = (await this.inputService.parseJson({
|
|
2559
|
-
data: input.filter,
|
|
2560
|
-
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2561
|
-
}));
|
|
2562
2629
|
this.inputService.validateInput(dataValidationPayload, databaseAction.data);
|
|
2563
|
-
|
|
2630
|
+
if (input.filter) {
|
|
2631
|
+
const filterValidationPayload = (await this.inputService.parseJson({
|
|
2632
|
+
data: input.filter,
|
|
2633
|
+
expected: types_1.ExpectedValues.PARSEINPUT,
|
|
2634
|
+
}));
|
|
2635
|
+
this.inputService.validateInput(filterValidationPayload, databaseAction.filterData);
|
|
2636
|
+
}
|
|
2564
2637
|
}
|
|
2565
2638
|
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 }));
|
|
2566
2639
|
if (database.type === types_1.DatabaseTypes.MONGODB) {
|
|
@@ -2595,6 +2668,8 @@ class ProcessorService {
|
|
|
2595
2668
|
if (!MongoDBHandler) {
|
|
2596
2669
|
throw new Error(`Running in browser, mongo handler not loaded.`);
|
|
2597
2670
|
}
|
|
2671
|
+
console.log("PRIVATE KEY!!!", this.productBuilderService.fetchProduct().private_key);
|
|
2672
|
+
console.log("AMAZONS", (0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchProduct().private_key));
|
|
2598
2673
|
const mongoHandler = new MongoDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchProduct().private_key));
|
|
2599
2674
|
if (databaseAction.type === types_1.DatabaseActionTypes.UPDATE) {
|
|
2600
2675
|
const filterTemplate = typeof databaseAction.filterTemplate === 'string'
|
|
@@ -2640,7 +2715,9 @@ class ProcessorService {
|
|
|
2640
2715
|
return result;
|
|
2641
2716
|
}
|
|
2642
2717
|
catch (e) {
|
|
2643
|
-
|
|
2718
|
+
console.log(e);
|
|
2719
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { failed_execution: true, message: 'Attempt database action - failed', data: { e: e.toString() }, status: types_1.LogEventStatus.FAIL }));
|
|
2720
|
+
throw e;
|
|
2644
2721
|
}
|
|
2645
2722
|
}
|
|
2646
2723
|
async runBrokerSubscribe(data, additional_logs = {}) {
|
|
@@ -2885,6 +2962,7 @@ class ProcessorService {
|
|
|
2885
2962
|
retries: retries || 0,
|
|
2886
2963
|
allow_fail: false,
|
|
2887
2964
|
}, additional_logs, true);
|
|
2965
|
+
console.log("RESULT ===>>>>", result);
|
|
2888
2966
|
this.end = Date.now();
|
|
2889
2967
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - success', data: { input: (0, processor_utils_1.anonymizeObject)(input), result: (0, processor_utils_1.anonymizeObject)(result) }, status: types_1.LogEventStatus.SUCCESS }));
|
|
2890
2968
|
this.writeResult(types_1.LogEventStatus.SUCCESS);
|
|
@@ -2892,6 +2970,7 @@ class ProcessorService {
|
|
|
2892
2970
|
return result;
|
|
2893
2971
|
}
|
|
2894
2972
|
catch (e) {
|
|
2973
|
+
console.log(e);
|
|
2895
2974
|
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
|
|
2896
2975
|
this.end = Date.now();
|
|
2897
2976
|
this.logService.publish();
|