@ductape/sdk 0.0.4-v4 → 0.0.4-v41
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.productMessageBrokerTopic.validator.js +1 -0
- package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
- 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.productMessageBrokerTopic.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.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 +67 -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
|
@@ -10,7 +10,7 @@ const inputs_service_1 = __importDefault(require("../../inputs/inputs.service"))
|
|
|
10
10
|
const string_utils_1 = require("../utils/string.utils");
|
|
11
11
|
const strings_utils_1 = require("../../api/utils/strings.utils");
|
|
12
12
|
const workspaceApi_service_1 = require("../../api/services/workspaceApi.service");
|
|
13
|
-
const string_utils_2 = require("../../products/utils/string.utils");
|
|
13
|
+
const string_utils_2 = require("../../products/services/utils/string.utils");
|
|
14
14
|
const objects_utils_1 = require("../utils/objects.utils");
|
|
15
15
|
const create_appWebhook_validator_1 = require("../validators/joi-validators/create.appWebhook.validator");
|
|
16
16
|
const update_appWebhook_validator_1 = require("../validators/joi-validators/update.appWebhook.validator");
|
|
@@ -36,7 +36,7 @@ class AppBuilderService {
|
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
const app = await this.createNewApp(data);
|
|
39
|
-
await this.initializeApp(app._id);
|
|
39
|
+
//await this.initializeApp(app._id);
|
|
40
40
|
}
|
|
41
41
|
return { app_id: this.app._id };
|
|
42
42
|
}
|
|
@@ -44,12 +44,20 @@ class AppBuilderService {
|
|
|
44
44
|
throw e;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
initAppVersion() {
|
|
48
|
-
|
|
47
|
+
initAppVersion(versionTag) {
|
|
48
|
+
if (versionTag) {
|
|
49
|
+
this.appVersion = this.app.versions.find((version) => version.tag === versionTag);
|
|
50
|
+
if (!this.appVersion) {
|
|
51
|
+
throw new Error(`Version ${versionTag} not found`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.appVersion = this.app.versions.find((version) => version.latest === true);
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
async initializeAppByTag(app_tag) {
|
|
51
59
|
try {
|
|
52
|
-
this.app = await this.appApi.
|
|
60
|
+
this.app = await this.appApi.initApp(app_tag, this.getUserAccess());
|
|
53
61
|
this.app_id = this.app._id;
|
|
54
62
|
this.initAppVersion();
|
|
55
63
|
}
|
|
@@ -59,7 +67,7 @@ class AppBuilderService {
|
|
|
59
67
|
}
|
|
60
68
|
async initializeApp(app_id) {
|
|
61
69
|
try {
|
|
62
|
-
this.app = await this.appApi.
|
|
70
|
+
this.app = await this.appApi.initApp(app_id, this.getUserAccess());
|
|
63
71
|
this.app_id = app_id;
|
|
64
72
|
this.initAppVersion();
|
|
65
73
|
}
|
|
@@ -106,7 +114,7 @@ class AppBuilderService {
|
|
|
106
114
|
throw new Error('App not initialized');
|
|
107
115
|
await validators_1.UpdateAppBuilderSchema.validateAsync(data);
|
|
108
116
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, data), { component: types_1.AppComponents.APP, action: types_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
109
|
-
await this.initializeApp(this.app_id);
|
|
117
|
+
//await this.initializeApp(this.app_id);
|
|
110
118
|
}
|
|
111
119
|
catch (e) {
|
|
112
120
|
throw e;
|
|
@@ -115,10 +123,11 @@ class AppBuilderService {
|
|
|
115
123
|
async createEnv(data, throwErrorIfExists = false) {
|
|
116
124
|
try {
|
|
117
125
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
118
|
-
|
|
126
|
+
const existingEnv = await this.fetchEnv(data.slug, false);
|
|
127
|
+
if (!existingEnv) {
|
|
119
128
|
await validators_1.CreateAppEnvSchema.validateAsync(data);
|
|
120
129
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, data), { component: types_1.AppComponents.ENV, action: types_1.RequestAction.CREATE }), this.getUserAccess());
|
|
121
|
-
await this.initializeApp(this.app_id);
|
|
130
|
+
//await this.initializeApp(this.app_id);
|
|
122
131
|
}
|
|
123
132
|
else {
|
|
124
133
|
if (throwErrorIfExists)
|
|
@@ -131,24 +140,29 @@ class AppBuilderService {
|
|
|
131
140
|
}
|
|
132
141
|
async updateEnv(slug, data) {
|
|
133
142
|
try {
|
|
134
|
-
// const { _id } = this.fetchEnv(slug);
|
|
143
|
+
// const { _id } = await this.fetchEnv(slug);
|
|
135
144
|
await validators_1.UpdateAppEnvSchema.validateAsync(Object.assign(Object.assign({}, data), { slug }));
|
|
136
|
-
if (data.slug
|
|
137
|
-
|
|
145
|
+
if (data.slug) {
|
|
146
|
+
const existingEnv = await this.fetchEnv(data.slug, false);
|
|
147
|
+
if (existingEnv) {
|
|
148
|
+
throw new Error(`slug ${slug} is in use`); // TODO: also check on the backend
|
|
149
|
+
}
|
|
138
150
|
}
|
|
139
151
|
// TODO: check
|
|
140
152
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({ slug }, data), { component: types_1.AppComponents.ENV, action: types_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
141
|
-
await this.initializeApp(this.app_id);
|
|
153
|
+
//await this.initializeApp(this.app_id);
|
|
142
154
|
}
|
|
143
155
|
catch (e) {
|
|
144
156
|
throw e;
|
|
145
157
|
}
|
|
146
158
|
}
|
|
147
|
-
fetchEnvs() {
|
|
148
|
-
|
|
159
|
+
async fetchEnvs() {
|
|
160
|
+
const components = await this.appApi.fetchAppComponents(this.app_id, 'env', this.getUserAccess(), this.appVersion.tag);
|
|
161
|
+
return components;
|
|
149
162
|
}
|
|
150
|
-
fetchEnv(slug, throwErrorIfExists = true) {
|
|
151
|
-
const
|
|
163
|
+
async fetchEnv(slug, throwErrorIfExists = true) {
|
|
164
|
+
const envs = await this.fetchEnvs();
|
|
165
|
+
const env = envs.find((data) => data.slug === slug);
|
|
152
166
|
if (!env && throwErrorIfExists)
|
|
153
167
|
throw new Error(`Env ${slug} not found`);
|
|
154
168
|
return env;
|
|
@@ -179,137 +193,395 @@ class AppBuilderService {
|
|
|
179
193
|
},
|
|
180
194
|
};
|
|
181
195
|
}
|
|
196
|
+
// Helper function to merge metadata into parsed schema data
|
|
197
|
+
mergeMetadataIntoSchema(parsedData, metadataMap) {
|
|
198
|
+
if (!metadataMap || Object.keys(metadataMap).length === 0) {
|
|
199
|
+
return parsedData;
|
|
200
|
+
}
|
|
201
|
+
return parsedData.map(item => {
|
|
202
|
+
const metadata = metadataMap[item.key || ''];
|
|
203
|
+
if (metadata) {
|
|
204
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, item), (metadata.minLength !== undefined ? { minLength: metadata.minLength } : {})), (metadata.maxLength !== undefined ? { maxLength: metadata.maxLength } : {})), (metadata.required !== undefined ? { required: metadata.required } : {})), (metadata.type !== undefined ? { type: metadata.type } : {}));
|
|
205
|
+
}
|
|
206
|
+
return item;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
// Helper function to merge nested metadata for body fields
|
|
210
|
+
mergeNestedBodyMetadata(parsedData, fieldsMetadata) {
|
|
211
|
+
if (!fieldsMetadata || Object.keys(fieldsMetadata).length === 0) {
|
|
212
|
+
return parsedData;
|
|
213
|
+
}
|
|
214
|
+
const applyMetadataRecursively = (data, pathPrefix = '') => {
|
|
215
|
+
return data.map((item) => {
|
|
216
|
+
const fullPath = pathPrefix ? `${pathPrefix}.${item.key}` : item.key;
|
|
217
|
+
const metadata = fieldsMetadata[fullPath];
|
|
218
|
+
let updatedItem = Object.assign({}, item);
|
|
219
|
+
if (metadata) {
|
|
220
|
+
updatedItem = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, updatedItem), (metadata.minLength !== undefined ? { minLength: metadata.minLength } : {})), (metadata.maxLength !== undefined ? { maxLength: metadata.maxLength } : {})), (metadata.required !== undefined ? { required: metadata.required } : {})), (metadata.type !== undefined ? { type: metadata.type } : {}));
|
|
221
|
+
}
|
|
222
|
+
// Recursively apply to nested data (if the parsed item has nested structure)
|
|
223
|
+
if (updatedItem.data && Array.isArray(updatedItem.data) && updatedItem.data.length > 0) {
|
|
224
|
+
updatedItem.data = applyMetadataRecursively(updatedItem.data, fullPath);
|
|
225
|
+
}
|
|
226
|
+
return updatedItem;
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
return applyMetadataRecursively(parsedData);
|
|
230
|
+
}
|
|
182
231
|
async createAction(data, throwErrorIfExists = false) {
|
|
232
|
+
// Validate schema
|
|
233
|
+
await validators_1.CreateAppActionSchema.validateAsync(data);
|
|
234
|
+
data.tag = (0, string_utils_1.tagify)(data.tag);
|
|
235
|
+
const { tag } = data;
|
|
236
|
+
// Check if action already exists
|
|
237
|
+
let exists;
|
|
183
238
|
try {
|
|
184
|
-
|
|
185
|
-
if (!data.resource)
|
|
186
|
-
throw new Error('resource is required');
|
|
187
|
-
data.resource = (0, strings_utils_1.extractURLPath)(url);
|
|
188
|
-
await validators_1.CreateAppActionSchema.validateAsync(data);
|
|
189
|
-
data.tag = (0, string_utils_1.tagify)(data.tag);
|
|
190
|
-
const { tag } = data;
|
|
191
|
-
let exists;
|
|
192
|
-
try {
|
|
193
|
-
exists = this.fetchAction(tag);
|
|
194
|
-
}
|
|
195
|
-
catch (e) {
|
|
196
|
-
exists = false;
|
|
197
|
-
}
|
|
198
|
-
if (!exists) {
|
|
199
|
-
data.resource = url;
|
|
200
|
-
//await this.updateActionProcess(tag, { ...data }, RequestAction.CREATE);
|
|
201
|
-
}
|
|
202
|
-
if (exists && throwErrorIfExists) {
|
|
203
|
-
throw new Error(`App action ${tag} already exists`);
|
|
204
|
-
}
|
|
239
|
+
exists = await this.fetchAction(tag);
|
|
205
240
|
}
|
|
206
241
|
catch (e) {
|
|
207
|
-
|
|
242
|
+
exists = false;
|
|
243
|
+
}
|
|
244
|
+
if (exists && throwErrorIfExists) {
|
|
245
|
+
throw new Error(`App action ${tag} already exists`);
|
|
246
|
+
}
|
|
247
|
+
if (exists) {
|
|
248
|
+
return; // Silently skip if already exists and not throwing error
|
|
249
|
+
}
|
|
250
|
+
// Build the action body (similar to updateAction but without fetching existing action)
|
|
251
|
+
const body = {
|
|
252
|
+
tag: data.tag,
|
|
253
|
+
name: data.name,
|
|
254
|
+
method: data.method,
|
|
255
|
+
request_type: data.request_type || types_1.DataFormats.JSON,
|
|
256
|
+
description: data.description || '',
|
|
257
|
+
responses: []
|
|
258
|
+
};
|
|
259
|
+
// Batch all parsing operations for parallel execution
|
|
260
|
+
const parseOperations = [];
|
|
261
|
+
const parseKeys = [];
|
|
262
|
+
// Prepare params parsing
|
|
263
|
+
if (data.params) {
|
|
264
|
+
parseKeys.push('params');
|
|
265
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
266
|
+
data: data.params.sample,
|
|
267
|
+
expected: types_1.ExpectedValues.PARSESAMPLE,
|
|
268
|
+
category: types_1.Categories.PARAMS
|
|
269
|
+
}).then(parsedData => ({
|
|
270
|
+
key: 'params',
|
|
271
|
+
parsedData: parsedData,
|
|
272
|
+
metadata: this.extractMetadata(data.params)
|
|
273
|
+
})));
|
|
274
|
+
}
|
|
275
|
+
// Prepare query parsing
|
|
276
|
+
if (data.query) {
|
|
277
|
+
parseKeys.push('query');
|
|
278
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
279
|
+
data: data.query.sample,
|
|
280
|
+
expected: types_1.ExpectedValues.PARSESAMPLE,
|
|
281
|
+
category: types_1.Categories.QUERY
|
|
282
|
+
}).then(parsedData => ({
|
|
283
|
+
key: 'query',
|
|
284
|
+
parsedData: parsedData,
|
|
285
|
+
metadata: this.extractMetadata(data.query)
|
|
286
|
+
})));
|
|
287
|
+
}
|
|
288
|
+
// Prepare body parsing
|
|
289
|
+
if (data.body) {
|
|
290
|
+
const fieldsMetadata = data.body.fieldsMetadata;
|
|
291
|
+
const bodySample = data.body.sample || data.body;
|
|
292
|
+
parseKeys.push('body');
|
|
293
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
294
|
+
data: bodySample,
|
|
295
|
+
expected: types_1.ExpectedValues.PARSESAMPLE,
|
|
296
|
+
category: types_1.Categories.BODY
|
|
297
|
+
}).then(parsedData => ({
|
|
298
|
+
key: 'body',
|
|
299
|
+
parsedData: parsedData,
|
|
300
|
+
fieldsMetadata,
|
|
301
|
+
bodySample,
|
|
302
|
+
metadata: fieldsMetadata ? null : this.extractMetadata(data.body)
|
|
303
|
+
})));
|
|
304
|
+
}
|
|
305
|
+
// Prepare headers parsing
|
|
306
|
+
if (data.headers) {
|
|
307
|
+
parseKeys.push('headers');
|
|
308
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
309
|
+
data: data.headers.sample,
|
|
310
|
+
expected: types_1.ExpectedValues.PARSESAMPLE,
|
|
311
|
+
category: types_1.Categories.HEADER
|
|
312
|
+
}).then(parsedData => ({
|
|
313
|
+
key: 'headers',
|
|
314
|
+
parsedData: parsedData,
|
|
315
|
+
metadata: this.extractMetadata(data.headers)
|
|
316
|
+
})));
|
|
317
|
+
}
|
|
318
|
+
// Prepare response parsing
|
|
319
|
+
if (data.response) {
|
|
320
|
+
parseKeys.push('response');
|
|
321
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
322
|
+
data: data.response.body,
|
|
323
|
+
expected: types_1.ExpectedValues.PARSESAMPLE
|
|
324
|
+
}).then(parsedData => ({
|
|
325
|
+
key: 'response',
|
|
326
|
+
parsedData: parsedData
|
|
327
|
+
})));
|
|
328
|
+
}
|
|
329
|
+
// Execute all parsing operations in parallel
|
|
330
|
+
const parseResults = await Promise.all(parseOperations);
|
|
331
|
+
// Process parsed results
|
|
332
|
+
for (const result of parseResults) {
|
|
333
|
+
switch (result.key) {
|
|
334
|
+
case 'params':
|
|
335
|
+
body.params = {
|
|
336
|
+
type: types_1.InputsTypes.JSON,
|
|
337
|
+
sample: JSON.stringify(data.params.sample),
|
|
338
|
+
data: this.mergeMetadataIntoSchema(result.parsedData, result.metadata)
|
|
339
|
+
};
|
|
340
|
+
break;
|
|
341
|
+
case 'query':
|
|
342
|
+
body.query = {
|
|
343
|
+
type: types_1.InputsTypes.JSON,
|
|
344
|
+
sample: JSON.stringify(data.query.sample),
|
|
345
|
+
data: this.mergeMetadataIntoSchema(result.parsedData, result.metadata)
|
|
346
|
+
};
|
|
347
|
+
break;
|
|
348
|
+
case 'body':
|
|
349
|
+
let finalData = result.parsedData;
|
|
350
|
+
if (result.fieldsMetadata) {
|
|
351
|
+
finalData = this.mergeNestedBodyMetadata(result.parsedData, result.fieldsMetadata);
|
|
352
|
+
}
|
|
353
|
+
else if (result.metadata && Object.keys(result.metadata).length > 0) {
|
|
354
|
+
finalData = this.mergeMetadataIntoSchema(result.parsedData, result.metadata);
|
|
355
|
+
}
|
|
356
|
+
body.body = {
|
|
357
|
+
type: types_1.InputsTypes.JSON,
|
|
358
|
+
sample: JSON.stringify(result.bodySample),
|
|
359
|
+
data: finalData
|
|
360
|
+
};
|
|
361
|
+
break;
|
|
362
|
+
case 'headers':
|
|
363
|
+
body.headers = {
|
|
364
|
+
type: types_1.InputsTypes.JSON,
|
|
365
|
+
sample: JSON.stringify(data.headers.sample),
|
|
366
|
+
data: this.mergeMetadataIntoSchema(result.parsedData, result.metadata)
|
|
367
|
+
};
|
|
368
|
+
break;
|
|
369
|
+
case 'response':
|
|
370
|
+
const response = {
|
|
371
|
+
name: data.response.name || `Response - ${data.response.status_code}`,
|
|
372
|
+
tag: data.tag,
|
|
373
|
+
response_format: data.response.response_format,
|
|
374
|
+
status_code: data.response.status_code,
|
|
375
|
+
success: data.response.success,
|
|
376
|
+
body: {
|
|
377
|
+
sample: JSON.stringify(data.response.body),
|
|
378
|
+
type: types_1.InputsTypes.JSON,
|
|
379
|
+
data: result.parsedData,
|
|
380
|
+
status_code: data.response.status_code,
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
body.responses = [response];
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
208
386
|
}
|
|
387
|
+
// Handle resource URL parsing (only if not already provided params/query)
|
|
388
|
+
if (data.resource) {
|
|
389
|
+
const { params, query: queryData } = await this.extractResourceData(data.resource);
|
|
390
|
+
body.resource = (0, strings_utils_1.extractURLPath)(data.resource);
|
|
391
|
+
// Merge resource-extracted params/query with existing ones
|
|
392
|
+
body.params = Object.assign(Object.assign({}, body.params), params);
|
|
393
|
+
body.query = Object.assign(Object.assign({}, body.query), queryData);
|
|
394
|
+
}
|
|
395
|
+
// Create action via API
|
|
396
|
+
await this.updateActionProcess(tag, body, types_1.RequestAction.CREATE);
|
|
397
|
+
// Update local cache instead of full app refetch
|
|
398
|
+
//this.appVersion.actions.push(body as IAppAction);
|
|
209
399
|
}
|
|
210
|
-
|
|
211
|
-
|
|
400
|
+
// Helper method to extract metadata from data object
|
|
401
|
+
extractMetadata(data) {
|
|
402
|
+
const metadataMap = {};
|
|
403
|
+
if (data && data.data && Array.isArray(data.data)) {
|
|
404
|
+
data.data.forEach((item) => {
|
|
405
|
+
if (item.metadata) {
|
|
406
|
+
metadataMap[item.key] = item.metadata;
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return metadataMap;
|
|
411
|
+
}
|
|
412
|
+
async fetchActions() {
|
|
413
|
+
const components = await this.appApi.fetchAppComponents(this.app_id, 'action', this.getUserAccess(), this.appVersion.tag);
|
|
414
|
+
return components;
|
|
212
415
|
}
|
|
213
|
-
fetchAction(identifier) {
|
|
214
|
-
const
|
|
416
|
+
async fetchAction(identifier) {
|
|
417
|
+
const actions = await this.fetchActions();
|
|
418
|
+
const action = actions.find((data) => data.tag === identifier || data._id === identifier);
|
|
215
419
|
if (!action)
|
|
216
420
|
throw new Error(`Action ${identifier} not found`);
|
|
217
421
|
return action;
|
|
218
422
|
}
|
|
219
423
|
async updateAction(tag, data) {
|
|
424
|
+
// Validate schema
|
|
220
425
|
await validators_1.UpdateAppActionSchema.validateAsync(data);
|
|
221
|
-
const action = this.fetchAction(tag);
|
|
426
|
+
const action = await this.fetchAction(tag);
|
|
222
427
|
const body = action;
|
|
223
428
|
if (!action) {
|
|
224
429
|
throw new Error(`Action ${tag} not found`);
|
|
225
430
|
}
|
|
431
|
+
// Batch all parsing operations for parallel execution
|
|
432
|
+
const parseOperations = [];
|
|
433
|
+
// Prepare params parsing
|
|
226
434
|
if (data.params) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
435
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
436
|
+
data: data.params.sample,
|
|
437
|
+
expected: types_1.ExpectedValues.PARSESAMPLE,
|
|
438
|
+
category: types_1.Categories.PARAMS
|
|
439
|
+
}).then(parsedData => ({
|
|
440
|
+
key: 'params',
|
|
441
|
+
parsedData: parsedData
|
|
442
|
+
})));
|
|
232
443
|
}
|
|
444
|
+
// Prepare query parsing
|
|
233
445
|
if (data.query) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
446
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
447
|
+
data: data.query.sample,
|
|
448
|
+
expected: types_1.ExpectedValues.PARSESAMPLE,
|
|
449
|
+
category: types_1.Categories.QUERY
|
|
450
|
+
}).then(parsedData => ({
|
|
451
|
+
key: 'query',
|
|
452
|
+
parsedData: parsedData
|
|
453
|
+
})));
|
|
239
454
|
}
|
|
455
|
+
// Prepare body parsing
|
|
240
456
|
if (data.body) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
457
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
458
|
+
data: data.body.sample,
|
|
459
|
+
expected: types_1.ExpectedValues.PARSESAMPLE,
|
|
460
|
+
category: types_1.Categories.BODY
|
|
461
|
+
}).then(parsedData => ({
|
|
462
|
+
key: 'body',
|
|
463
|
+
parsedData: parsedData
|
|
464
|
+
})));
|
|
246
465
|
}
|
|
466
|
+
// Prepare headers parsing
|
|
247
467
|
if (data.headers) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
468
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
469
|
+
data: data.headers.sample,
|
|
470
|
+
expected: types_1.ExpectedValues.PARSESAMPLE,
|
|
471
|
+
category: types_1.Categories.HEADER
|
|
472
|
+
}).then(parsedData => ({
|
|
473
|
+
key: 'headers',
|
|
474
|
+
parsedData: parsedData
|
|
475
|
+
})));
|
|
253
476
|
}
|
|
477
|
+
// Prepare response parsing
|
|
478
|
+
if (data.response) {
|
|
479
|
+
parseOperations.push(this.inputsService.parseJson({
|
|
480
|
+
data: data.response.body,
|
|
481
|
+
expected: types_1.ExpectedValues.PARSESAMPLE
|
|
482
|
+
}).then(parsedData => ({
|
|
483
|
+
key: 'response',
|
|
484
|
+
parsedData: parsedData
|
|
485
|
+
})));
|
|
486
|
+
}
|
|
487
|
+
// Execute all parsing operations in parallel
|
|
488
|
+
const parseResults = await Promise.all(parseOperations);
|
|
489
|
+
// Process parsed results
|
|
490
|
+
for (const result of parseResults) {
|
|
491
|
+
switch (result.key) {
|
|
492
|
+
case 'params':
|
|
493
|
+
body.params = {
|
|
494
|
+
type: types_1.InputsTypes.JSON,
|
|
495
|
+
sample: JSON.stringify(data.params),
|
|
496
|
+
data: result.parsedData
|
|
497
|
+
};
|
|
498
|
+
break;
|
|
499
|
+
case 'query':
|
|
500
|
+
body.query = {
|
|
501
|
+
type: types_1.InputsTypes.JSON,
|
|
502
|
+
sample: JSON.stringify(data.query),
|
|
503
|
+
data: result.parsedData
|
|
504
|
+
};
|
|
505
|
+
break;
|
|
506
|
+
case 'body':
|
|
507
|
+
body.body = {
|
|
508
|
+
type: types_1.InputsTypes.JSON,
|
|
509
|
+
sample: JSON.stringify(data.body),
|
|
510
|
+
data: result.parsedData
|
|
511
|
+
};
|
|
512
|
+
break;
|
|
513
|
+
case 'headers':
|
|
514
|
+
body.headers = {
|
|
515
|
+
type: types_1.InputsTypes.JSON,
|
|
516
|
+
sample: JSON.stringify(data.headers),
|
|
517
|
+
data: result.parsedData
|
|
518
|
+
};
|
|
519
|
+
break;
|
|
520
|
+
case 'response':
|
|
521
|
+
body.responses = action.responses;
|
|
522
|
+
const response = {
|
|
523
|
+
name: `Response - ${data.response.status_code}`,
|
|
524
|
+
response_format: data.response.response_format,
|
|
525
|
+
status_code: data.response.status_code,
|
|
526
|
+
success: data.response.success,
|
|
527
|
+
body: {
|
|
528
|
+
sample: JSON.stringify(data.response.body),
|
|
529
|
+
type: types_1.InputsTypes.JSON,
|
|
530
|
+
data: result.parsedData,
|
|
531
|
+
status_code: data.response.status_code,
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
const statusIndex = body.responses.findIndex((resp) => resp.status_code === data.response.status_code);
|
|
535
|
+
if (data.response.success === true) {
|
|
536
|
+
const index = action.responses.findIndex((resp) => resp.success === true);
|
|
537
|
+
if (index > -1) {
|
|
538
|
+
body.responses[index] = response;
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
if (statusIndex > -1) {
|
|
542
|
+
body.responses.splice(statusIndex, 1);
|
|
543
|
+
}
|
|
544
|
+
body.responses.push(response);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
if (statusIndex > -1) {
|
|
549
|
+
body.responses.splice(statusIndex, 1);
|
|
550
|
+
}
|
|
551
|
+
body.responses.push(response);
|
|
552
|
+
}
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
// Handle resource URL parsing
|
|
254
557
|
if (data.resource) {
|
|
255
558
|
const { params, query: queryData } = await this.extractResourceData(data.resource);
|
|
256
559
|
body.resource = (0, strings_utils_1.extractURLPath)(data.resource);
|
|
560
|
+
// Merge resource-extracted params/query with existing ones
|
|
257
561
|
body.params = Object.assign(Object.assign({}, body.params), params);
|
|
258
562
|
body.query = Object.assign(Object.assign({}, body.query), queryData);
|
|
259
563
|
}
|
|
564
|
+
// Update simple fields
|
|
260
565
|
if (data.description) {
|
|
261
566
|
body.description = data.description;
|
|
262
567
|
}
|
|
263
|
-
/*if(body.description === ''){
|
|
264
|
-
body.description = undefined
|
|
265
|
-
}*/
|
|
266
568
|
if (data.method) {
|
|
267
569
|
body.method = data.method;
|
|
268
570
|
}
|
|
269
571
|
if (data.request_type) {
|
|
270
572
|
body.request_type = data.request_type;
|
|
271
573
|
}
|
|
272
|
-
|
|
273
|
-
body.responses = action.responses;
|
|
274
|
-
const response = {
|
|
275
|
-
name: `Response - ${data.response.status_code}`,
|
|
276
|
-
response_format: data.response.response_format,
|
|
277
|
-
status_code: data.response.status_code,
|
|
278
|
-
success: data.response.success,
|
|
279
|
-
body: {
|
|
280
|
-
sample: JSON.stringify(data.response.body),
|
|
281
|
-
type: types_1.InputsTypes.JSON,
|
|
282
|
-
data: await this.inputsService.parseJson({
|
|
283
|
-
data: data.response.body,
|
|
284
|
-
expected: types_1.ExpectedValues.PARSESAMPLE
|
|
285
|
-
}),
|
|
286
|
-
status_code: data.response.status_code,
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
const statusIndex = body.responses.findIndex((resp) => resp.status_code === data.response.status_code);
|
|
290
|
-
if (data.response.success === true) {
|
|
291
|
-
const index = action.responses.findIndex((resp) => resp.success === true);
|
|
292
|
-
if (index > -1) {
|
|
293
|
-
body.responses[index] = response;
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
if (statusIndex > -1) {
|
|
297
|
-
body.responses.splice(statusIndex, 1);
|
|
298
|
-
}
|
|
299
|
-
body.responses.push(response);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
if (statusIndex > -1) {
|
|
304
|
-
body.responses.splice(statusIndex, 1);
|
|
305
|
-
}
|
|
306
|
-
body.responses.push(response);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
574
|
+
// Update action via API
|
|
309
575
|
await this.updateActionProcess(tag, body, types_1.RequestAction.UPDATE);
|
|
576
|
+
// Update local cache instead of full app refetch
|
|
577
|
+
//const actionIndex = this.appVersion.actions.findIndex(a => a.tag === tag || a._id === action._id);
|
|
578
|
+
//if (actionIndex > -1) {
|
|
579
|
+
//this.appVersion.actions[actionIndex] = body as IAppAction;
|
|
580
|
+
//}
|
|
310
581
|
}
|
|
311
582
|
async updateActionProcess(tag, data, action) {
|
|
312
|
-
const query = Object.assign({ component: types_1.AppComponents.ACTION, action
|
|
583
|
+
const query = Object.assign({ component: types_1.AppComponents.ACTION, action,
|
|
584
|
+
tag }, data);
|
|
313
585
|
await this.appApi.updateApp(this.app_id, query, this.getUserAccess());
|
|
314
586
|
}
|
|
315
587
|
async createActionRequestData(category, tag, payload, throwErrorIfExists = false) {
|
|
@@ -341,10 +613,10 @@ class AppBuilderService {
|
|
|
341
613
|
return Object.assign(Object.assign({}, payload), { sample, data });
|
|
342
614
|
}
|
|
343
615
|
// private fetc
|
|
344
|
-
fetchActionRequestData(category, tag) {
|
|
616
|
+
async fetchActionRequestData(category, tag) {
|
|
345
617
|
try {
|
|
346
618
|
let data;
|
|
347
|
-
const action = this.fetchAction(tag);
|
|
619
|
+
const action = await this.fetchAction(tag);
|
|
348
620
|
if (category === types_1.Categories.BODY) {
|
|
349
621
|
const { body } = action;
|
|
350
622
|
data = body.data;
|
|
@@ -370,10 +642,10 @@ class AppBuilderService {
|
|
|
370
642
|
throw e;
|
|
371
643
|
}
|
|
372
644
|
}
|
|
373
|
-
fetchActionRequestSample(category, tag) {
|
|
645
|
+
async fetchActionRequestSample(category, tag) {
|
|
374
646
|
try {
|
|
375
647
|
let sample;
|
|
376
|
-
const action = this.fetchAction(tag);
|
|
648
|
+
const action = await this.fetchAction(tag);
|
|
377
649
|
if (category === types_1.Categories.BODY) {
|
|
378
650
|
const { body } = action;
|
|
379
651
|
sample = body.sample;
|
|
@@ -401,10 +673,10 @@ class AppBuilderService {
|
|
|
401
673
|
}
|
|
402
674
|
async createAppActionResponse(action_tag, payload) {
|
|
403
675
|
try {
|
|
404
|
-
this.fetchAction(action_tag);
|
|
676
|
+
await this.fetchAction(action_tag);
|
|
405
677
|
await validators_1.CreateAppActionResponseSchema.validateAsync(Object.assign({}, payload));
|
|
406
678
|
payload.tag = (0, string_utils_1.tagify)(payload.tag);
|
|
407
|
-
const exists = this.fetchAppActionResponse(action_tag, payload.tag);
|
|
679
|
+
const exists = await this.fetchAppActionResponse(action_tag, payload.tag);
|
|
408
680
|
if (!exists) {
|
|
409
681
|
payload = await this.parseResponsePayload(payload);
|
|
410
682
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, payload), { action_tag, action: types_1.RequestAction.CREATE, component: types_1.AppComponents.ACTION_RESPONSE }), this.getUserAccess());
|
|
@@ -451,19 +723,21 @@ class AppBuilderService {
|
|
|
451
723
|
payload.body.data = data;
|
|
452
724
|
payload.body.sample = JSON.stringify(payload.body.sample);
|
|
453
725
|
if (payload.envs && payload.envs.length) {
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
return
|
|
457
|
-
});
|
|
726
|
+
const envIds = await Promise.all(payload.envs.map(async (slug) => {
|
|
727
|
+
const env = await this.fetchEnv(slug);
|
|
728
|
+
return env._id;
|
|
729
|
+
}));
|
|
730
|
+
payload.envs = envIds;
|
|
458
731
|
}
|
|
459
732
|
return payload;
|
|
460
733
|
}
|
|
461
|
-
fetchAppActionResponse(action_tag, response_tag, throwErrorIfExists = false) {
|
|
462
|
-
const
|
|
463
|
-
const
|
|
464
|
-
|
|
734
|
+
async fetchAppActionResponse(action_tag, response_tag, throwErrorIfExists = false) {
|
|
735
|
+
const action = await this.fetchAction(action_tag);
|
|
736
|
+
const { responses } = action;
|
|
737
|
+
const response = responses.find((data) => data.tag === response_tag);
|
|
738
|
+
if (!response && throwErrorIfExists)
|
|
465
739
|
throw new Error(`Response ${response_tag} not found`);
|
|
466
|
-
return
|
|
740
|
+
return response;
|
|
467
741
|
}
|
|
468
742
|
/*async extractEventData(data: Partial<IAppEvent>): Promise<Partial<IAppEvent>> {
|
|
469
743
|
if (data.response) {
|
|
@@ -541,7 +815,7 @@ class AppBuilderService {
|
|
|
541
815
|
this.getUserAccess(),
|
|
542
816
|
);
|
|
543
817
|
|
|
544
|
-
await this.initializeApp(this.app_id);
|
|
818
|
+
//await this.initializeApp(this.app_id);
|
|
545
819
|
} catch (e) {
|
|
546
820
|
throw e;
|
|
547
821
|
}
|
|
@@ -572,7 +846,7 @@ class AppBuilderService {
|
|
|
572
846
|
this.getUserAccess(),
|
|
573
847
|
);
|
|
574
848
|
|
|
575
|
-
await this.initializeApp(this.app_id);
|
|
849
|
+
//await this.initializeApp(this.app_id);
|
|
576
850
|
} catch (e) {
|
|
577
851
|
throw e;
|
|
578
852
|
}
|
|
@@ -647,11 +921,11 @@ class AppBuilderService {
|
|
|
647
921
|
throw new Error(`token has to have one of body, headers, params or query set`);
|
|
648
922
|
}
|
|
649
923
|
if (setup_type === types_1.AuthTypes.CREDENTIALS) {
|
|
650
|
-
this.fetchAction(action_tag);
|
|
924
|
+
await this.fetchAction(action_tag);
|
|
651
925
|
}
|
|
652
926
|
data = await this.extractAuthData(Object.assign({}, data));
|
|
653
927
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, data), { action: types_1.RequestAction.CREATE, component: types_1.AppComponents.AUTH }), this.getUserAccess());
|
|
654
|
-
await this.initializeApp(this.app_id);
|
|
928
|
+
//await this.initializeApp(this.app_id);
|
|
655
929
|
}
|
|
656
930
|
catch (e) {
|
|
657
931
|
throw e;
|
|
@@ -660,21 +934,23 @@ class AppBuilderService {
|
|
|
660
934
|
async updateAuth(tag, data) {
|
|
661
935
|
try {
|
|
662
936
|
await validators_1.UpdateAppAuthSchema.validateAsync(data);
|
|
663
|
-
const auth = this.fetchAuth(tag);
|
|
937
|
+
const auth = await this.fetchAuth(tag);
|
|
664
938
|
data = await this.extractAuthData(Object.assign(Object.assign({}, auth), data));
|
|
665
939
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({ tag }, data), { action: types_1.RequestAction.UPDATE, component: types_1.AppComponents.AUTH }), this.getUserAccess());
|
|
666
|
-
await this.initializeApp(this.app_id);
|
|
667
|
-
await this.initializeApp(this.app_id);
|
|
940
|
+
//await this.initializeApp(this.app_id);
|
|
941
|
+
//await this.initializeApp(this.app_id);
|
|
668
942
|
}
|
|
669
943
|
catch (e) {
|
|
670
944
|
throw e;
|
|
671
945
|
}
|
|
672
946
|
}
|
|
673
|
-
fetchAuths() {
|
|
674
|
-
|
|
947
|
+
async fetchAuths() {
|
|
948
|
+
const components = await this.appApi.fetchAppComponents(this.app_id, 'auth', this.getUserAccess(), this.appVersion.tag);
|
|
949
|
+
return components;
|
|
675
950
|
}
|
|
676
|
-
fetchAuth(tag) {
|
|
677
|
-
const
|
|
951
|
+
async fetchAuth(tag) {
|
|
952
|
+
const auths = await this.fetchAuths();
|
|
953
|
+
const auth = auths.find((data) => data.tag === tag);
|
|
678
954
|
if (!auth)
|
|
679
955
|
throw new Error(`Auth ${tag} not found`);
|
|
680
956
|
return auth;
|
|
@@ -682,13 +958,13 @@ class AppBuilderService {
|
|
|
682
958
|
async createVariable(data, throwErrorIfExists = false) {
|
|
683
959
|
try {
|
|
684
960
|
await validators_1.CreateAppVariableSchema.validateAsync(data);
|
|
685
|
-
const exists = this.fetchVariable(data.key, false);
|
|
961
|
+
const exists = await this.fetchVariable(data.key, false);
|
|
686
962
|
if (exists && throwErrorIfExists)
|
|
687
963
|
throw new Error(`Variable ${data.key} exists`);
|
|
688
964
|
if (!exists) {
|
|
689
965
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, data), { action: types_1.RequestAction.CREATE, component: types_1.AppComponents.VARIABLE }), this.getUserAccess());
|
|
690
966
|
}
|
|
691
|
-
await this.initializeApp(this.app_id);
|
|
967
|
+
//await this.initializeApp(this.app_id);
|
|
692
968
|
}
|
|
693
969
|
catch (e) {
|
|
694
970
|
throw e;
|
|
@@ -697,19 +973,21 @@ class AppBuilderService {
|
|
|
697
973
|
async updateVariable(key, data) {
|
|
698
974
|
try {
|
|
699
975
|
await validators_1.UpdateAppVariableSchema.validateAsync(data);
|
|
700
|
-
this.fetchVariable(key);
|
|
976
|
+
await this.fetchVariable(key);
|
|
701
977
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, data), { key, action: types_1.RequestAction.UPDATE, component: types_1.AppComponents.VARIABLE }), this.getUserAccess());
|
|
702
|
-
await this.initializeApp(this.app_id);
|
|
978
|
+
//await this.initializeApp(this.app_id);
|
|
703
979
|
}
|
|
704
980
|
catch (e) {
|
|
705
981
|
throw e;
|
|
706
982
|
}
|
|
707
983
|
}
|
|
708
|
-
fetchVariables() {
|
|
709
|
-
|
|
984
|
+
async fetchVariables() {
|
|
985
|
+
const components = await this.appApi.fetchAppComponents(this.app_id, 'variable', this.getUserAccess(), this.appVersion.tag);
|
|
986
|
+
return components;
|
|
710
987
|
}
|
|
711
|
-
fetchVariable(key, throwErrorIfExists = true) {
|
|
712
|
-
const
|
|
988
|
+
async fetchVariable(key, throwErrorIfExists = true) {
|
|
989
|
+
const variables = await this.fetchVariables();
|
|
990
|
+
const variable = variables.find((data) => data.key === key);
|
|
713
991
|
if (!variable && throwErrorIfExists)
|
|
714
992
|
throw new Error(`Variable ${key} not found`);
|
|
715
993
|
return variable;
|
|
@@ -717,11 +995,11 @@ class AppBuilderService {
|
|
|
717
995
|
async createConstant(data, throwErrorIfExists = false) {
|
|
718
996
|
try {
|
|
719
997
|
await validators_1.CreateAppConstantSchema.validateAsync(data);
|
|
720
|
-
const exists = this.fetchConstant(data.key, false);
|
|
998
|
+
const exists = await this.fetchConstant(data.key, false);
|
|
721
999
|
if (exists && throwErrorIfExists)
|
|
722
1000
|
throw new Error(`Constant ${data.key} exists`);
|
|
723
1001
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, data), { action: types_1.RequestAction.CREATE, component: types_1.AppComponents.CONSTANT }), this.getUserAccess());
|
|
724
|
-
await this.initializeApp(this.app_id);
|
|
1002
|
+
//await this.initializeApp(this.app_id);
|
|
725
1003
|
}
|
|
726
1004
|
catch (e) {
|
|
727
1005
|
throw e;
|
|
@@ -729,15 +1007,17 @@ class AppBuilderService {
|
|
|
729
1007
|
}
|
|
730
1008
|
async updateConstant(key, data) {
|
|
731
1009
|
await validators_1.UpdateAppConstantSchema.validateAsync(data);
|
|
732
|
-
this.fetchConstant(key);
|
|
1010
|
+
await this.fetchConstant(key);
|
|
733
1011
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, data), { action: types_1.RequestAction.UPDATE, component: types_1.AppComponents.CONSTANT }), this.getUserAccess());
|
|
734
|
-
await this.initializeApp(this.app_id);
|
|
1012
|
+
//await this.initializeApp(this.app_id);
|
|
735
1013
|
}
|
|
736
|
-
fetchConstants() {
|
|
737
|
-
|
|
1014
|
+
async fetchConstants() {
|
|
1015
|
+
const components = await this.appApi.fetchAppComponents(this.app_id, 'constant', this.getUserAccess(), this.appVersion.tag);
|
|
1016
|
+
return components;
|
|
738
1017
|
}
|
|
739
|
-
fetchConstant(key, throwErrorIfExists = true) {
|
|
740
|
-
const
|
|
1018
|
+
async fetchConstant(key, throwErrorIfExists = true) {
|
|
1019
|
+
const constants = await this.fetchConstants();
|
|
1020
|
+
const variable = constants.find((data) => data.key === key);
|
|
741
1021
|
if (!variable && throwErrorIfExists)
|
|
742
1022
|
throw new Error(`Constant ${key} not found`);
|
|
743
1023
|
return variable;
|
|
@@ -747,17 +1027,19 @@ class AppBuilderService {
|
|
|
747
1027
|
if (stages.length === 0) {
|
|
748
1028
|
throw new Error(`Missing locators in ${locator}`);
|
|
749
1029
|
}
|
|
1030
|
+
// Convert stages to string[] for functions expecting string[]
|
|
1031
|
+
const stringStages = stages.map(stage => String(stage));
|
|
750
1032
|
if (locator.startsWith('$Body{')) {
|
|
751
|
-
await this.updateValidation(types_1.AppCategories.BODY,
|
|
1033
|
+
await this.updateValidation(types_1.AppCategories.BODY, stringStages, update);
|
|
752
1034
|
}
|
|
753
1035
|
else if (locator.startsWith('$Query{')) {
|
|
754
|
-
await this.updateValidation(types_1.AppCategories.QUERY,
|
|
1036
|
+
await this.updateValidation(types_1.AppCategories.QUERY, stringStages, update);
|
|
755
1037
|
}
|
|
756
1038
|
else if (locator.startsWith('$Params{')) {
|
|
757
|
-
await this.updateValidation(types_1.AppCategories.PARAMS,
|
|
1039
|
+
await this.updateValidation(types_1.AppCategories.PARAMS, stringStages, update);
|
|
758
1040
|
}
|
|
759
1041
|
else if (locator.startsWith('$Header{')) {
|
|
760
|
-
await this.updateValidation(types_1.AppCategories.HEADER,
|
|
1042
|
+
await this.updateValidation(types_1.AppCategories.HEADER, stringStages, update);
|
|
761
1043
|
}
|
|
762
1044
|
else {
|
|
763
1045
|
throw new Error(`Invalid input ${locator}`);
|
|
@@ -766,7 +1048,7 @@ class AppBuilderService {
|
|
|
766
1048
|
async updateValidation(category, stages, update) {
|
|
767
1049
|
try {
|
|
768
1050
|
const action_tag = stages[0];
|
|
769
|
-
const action = this.fetchAction(action_tag);
|
|
1051
|
+
const action = await this.fetchAction(action_tag);
|
|
770
1052
|
const data = action[category];
|
|
771
1053
|
let level = -1;
|
|
772
1054
|
let key = '';
|
|
@@ -805,8 +1087,8 @@ class AppBuilderService {
|
|
|
805
1087
|
'responses',
|
|
806
1088
|
...exclude,
|
|
807
1089
|
]);
|
|
808
|
-
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({ tag: action_tag },
|
|
809
|
-
await this.initializeApp(this.app_id);
|
|
1090
|
+
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({ tag: action_tag }, action), { component: types_1.AppComponents.VALIDATION, action: types_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
1091
|
+
//await this.initializeApp(this.app_id);
|
|
810
1092
|
}
|
|
811
1093
|
catch (e) {
|
|
812
1094
|
throw e;
|
|
@@ -815,10 +1097,11 @@ class AppBuilderService {
|
|
|
815
1097
|
async createWebhook(data, throwErrorIfExists = false) {
|
|
816
1098
|
try {
|
|
817
1099
|
// TODO: figure out a way to check if this has run before, halt if it has
|
|
818
|
-
|
|
1100
|
+
const existingWebhook = await this.fetchWebhook(data.tag);
|
|
1101
|
+
if (!existingWebhook) {
|
|
819
1102
|
await create_appWebhook_validator_1.IAppWebhookSchema.validateAsync(data);
|
|
820
|
-
data.envs = data.envs.map((env) => {
|
|
821
|
-
const exists = this.fetchEnv(env.slug);
|
|
1103
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
1104
|
+
const exists = await this.fetchEnv(env.slug);
|
|
822
1105
|
if (!exists) {
|
|
823
1106
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
824
1107
|
}
|
|
@@ -836,8 +1119,8 @@ class AppBuilderService {
|
|
|
836
1119
|
env.sample_data = [...bodyTemplate, ...queryTemplate, ...paramsTemplate, ...headerTemplate];
|
|
837
1120
|
}
|
|
838
1121
|
return env;
|
|
839
|
-
});
|
|
840
|
-
const envs = this.fetchEnvs();
|
|
1122
|
+
}));
|
|
1123
|
+
const envs = await this.fetchEnvs();
|
|
841
1124
|
envs.map((env) => {
|
|
842
1125
|
const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
843
1126
|
if (exists === -1) {
|
|
@@ -845,7 +1128,7 @@ class AppBuilderService {
|
|
|
845
1128
|
}
|
|
846
1129
|
});
|
|
847
1130
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({}, data), { component: types_1.AppComponents.WEBHOOK, action: types_1.RequestAction.CREATE }), this.getUserAccess());
|
|
848
|
-
await this.initializeApp(this.app_id);
|
|
1131
|
+
//await this.initializeApp(this.app_id);
|
|
849
1132
|
}
|
|
850
1133
|
else {
|
|
851
1134
|
if (throwErrorIfExists)
|
|
@@ -858,13 +1141,17 @@ class AppBuilderService {
|
|
|
858
1141
|
}
|
|
859
1142
|
async updateWebhook(tag, data) {
|
|
860
1143
|
try {
|
|
861
|
-
const
|
|
1144
|
+
const webhook = await this.fetchWebhook(tag);
|
|
1145
|
+
const { _id, envs } = webhook;
|
|
862
1146
|
await update_appWebhook_validator_1.IAppWebhookUpdateSchema.validateAsync(data); // Change to update;
|
|
863
|
-
if (data.tag
|
|
864
|
-
|
|
1147
|
+
if (data.tag) {
|
|
1148
|
+
const existingWebhook = await this.fetchWebhook(data.tag);
|
|
1149
|
+
if (existingWebhook) {
|
|
1150
|
+
throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
|
|
1151
|
+
}
|
|
865
1152
|
}
|
|
866
|
-
data.envs = data.envs.map((env) => {
|
|
867
|
-
const exists = this.fetchEnv(env.slug);
|
|
1153
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
1154
|
+
const exists = await this.fetchEnv(env.slug);
|
|
868
1155
|
if (!exists) {
|
|
869
1156
|
throw new Error(`Env ${env.slug} does not exist`);
|
|
870
1157
|
}
|
|
@@ -880,12 +1167,13 @@ class AppBuilderService {
|
|
|
880
1167
|
env.sample_data = [...bodyTemplate, ...queryTemplate, ...paramsTemplate, ...headerTemplate];
|
|
881
1168
|
}
|
|
882
1169
|
return env;
|
|
883
|
-
});
|
|
1170
|
+
}));
|
|
884
1171
|
const overwrite = [];
|
|
885
1172
|
const newEnvs = [];
|
|
886
|
-
|
|
1173
|
+
for (const env of envs) {
|
|
887
1174
|
const exists = data.envs.findIndex((dataEnv) => env.slug === dataEnv.slug);
|
|
888
|
-
|
|
1175
|
+
const envExists = await this.fetchEnv(env.slug, false);
|
|
1176
|
+
if (!envExists) {
|
|
889
1177
|
throw new Error(`Product Environment ${env.slug} doesn't exist`);
|
|
890
1178
|
}
|
|
891
1179
|
if (exists === -1) {
|
|
@@ -894,7 +1182,7 @@ class AppBuilderService {
|
|
|
894
1182
|
else {
|
|
895
1183
|
overwrite.push(Object.assign(Object.assign({}, env), data.envs[exists]));
|
|
896
1184
|
}
|
|
897
|
-
}
|
|
1185
|
+
}
|
|
898
1186
|
const unchanged = [];
|
|
899
1187
|
envs.map((env) => {
|
|
900
1188
|
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
@@ -906,20 +1194,20 @@ class AppBuilderService {
|
|
|
906
1194
|
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
907
1195
|
data.envs = [...overwrite, ...newEnvs];
|
|
908
1196
|
await this.appApi.updateApp(this.app_id, Object.assign(Object.assign({ _id }, data), { component: types_1.AppComponents.WEBHOOK, action: types_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
909
|
-
await this.initializeApp(this.app_id);
|
|
1197
|
+
//await this.initializeApp(this.app_id);
|
|
910
1198
|
}
|
|
911
1199
|
catch (e) {
|
|
912
1200
|
throw e;
|
|
913
1201
|
}
|
|
914
1202
|
}
|
|
915
|
-
fetchWebhook(tag) {
|
|
916
|
-
|
|
917
|
-
const exists =
|
|
1203
|
+
async fetchWebhook(tag) {
|
|
1204
|
+
const webhooks = await this.fetchWebhooks();
|
|
1205
|
+
const exists = webhooks === null || webhooks === void 0 ? void 0 : webhooks.find((data) => data.tag === tag);
|
|
918
1206
|
return exists;
|
|
919
1207
|
}
|
|
920
|
-
fetchWebhooks() {
|
|
921
|
-
|
|
922
|
-
return
|
|
1208
|
+
async fetchWebhooks() {
|
|
1209
|
+
const components = await this.appApi.fetchAppComponents(this.app_id, 'webhook', this.getUserAccess(), this.appVersion.tag);
|
|
1210
|
+
return components;
|
|
923
1211
|
}
|
|
924
1212
|
async createWebhookEvent(data, throwErrorIfExists = false) {
|
|
925
1213
|
try {
|
|
@@ -931,7 +1219,7 @@ class AppBuilderService {
|
|
|
931
1219
|
if (!webhookTag || !tag) {
|
|
932
1220
|
throw new Error(`tag is expected to be defined as "webhook_tag:event_tag"`);
|
|
933
1221
|
}
|
|
934
|
-
const exists = this.fetchWebhookEvent(data.tag);
|
|
1222
|
+
const exists = await this.fetchWebhookEvent(data.tag);
|
|
935
1223
|
data.tag = tag;
|
|
936
1224
|
if (!exists) {
|
|
937
1225
|
if (!data.selector.startsWith('$Event{')) {
|
|
@@ -953,7 +1241,7 @@ class AppBuilderService {
|
|
|
953
1241
|
throw new Error("Selector value is not allowed to be an object|array|null|undefined");
|
|
954
1242
|
}
|
|
955
1243
|
//check other webhooksevents to see if there are other places where selector and selectorValue match up
|
|
956
|
-
const existing = this.fetchWebhookEvents(webhookTag);
|
|
1244
|
+
const existing = await this.fetchWebhookEvents(webhookTag);
|
|
957
1245
|
existing === null || existing === void 0 ? void 0 : existing.map((event) => {
|
|
958
1246
|
if (event.selector === data.selector && event.selectorValue === current) {
|
|
959
1247
|
throw new Error(`Selector ${data.selector} with value ${current} already exists on event ${event.tag}`);
|
|
@@ -968,7 +1256,7 @@ class AppBuilderService {
|
|
|
968
1256
|
const payload = Object.assign(Object.assign({}, data), { webhookTag,
|
|
969
1257
|
tag, component: types_1.AppComponents.WEBHOOK_EVENT, action: types_1.RequestAction.CREATE });
|
|
970
1258
|
await this.appApi.updateApp(this.app_id, payload, this.getUserAccess());
|
|
971
|
-
await this.initializeApp(this.app_id);
|
|
1259
|
+
//await this.initializeApp(this.app_id);
|
|
972
1260
|
}
|
|
973
1261
|
else {
|
|
974
1262
|
if (throwErrorIfExists)
|
|
@@ -1017,7 +1305,7 @@ class AppBuilderService {
|
|
|
1017
1305
|
throw new Error("Selector value is not allowed to be an object|array|null|undefined");
|
|
1018
1306
|
}
|
|
1019
1307
|
//check other webhooksevents to see if there are other places where selector and selectorValue match up
|
|
1020
|
-
const existing = this.fetchWebhookEvents(webhookTag);
|
|
1308
|
+
const existing = await this.fetchWebhookEvents(webhookTag);
|
|
1021
1309
|
existing === null || existing === void 0 ? void 0 : existing.map((event) => {
|
|
1022
1310
|
if (event.selector === data.selector && event.selectorValue === current && event.tag !== tag) {
|
|
1023
1311
|
throw new Error(`Selector ${data.selector} with value ${current} already exists on event ${event.tag}`);
|
|
@@ -1035,26 +1323,26 @@ class AppBuilderService {
|
|
|
1035
1323
|
webhookTag, component: types_1.AppComponents.WEBHOOK_EVENT, action: types_1.RequestAction.UPDATE });
|
|
1036
1324
|
// Update product and reinitialize
|
|
1037
1325
|
await this.appApi.updateApp(this.app_id, payload, this.getUserAccess());
|
|
1038
|
-
await this.initializeApp(this.app_id);
|
|
1326
|
+
//await this.initializeApp(this.app_id);
|
|
1039
1327
|
}
|
|
1040
1328
|
catch (error) {
|
|
1041
1329
|
throw error;
|
|
1042
1330
|
}
|
|
1043
1331
|
}
|
|
1044
|
-
fetchWebhookEvent(tag) {
|
|
1332
|
+
async fetchWebhookEvent(tag) {
|
|
1045
1333
|
const [webhookTag, eventTag] = tag.split(':');
|
|
1046
1334
|
;
|
|
1047
1335
|
if (!webhookTag || !eventTag) {
|
|
1048
1336
|
throw new Error(`webhook events should be in the format webhook_tag:event_tag`);
|
|
1049
1337
|
}
|
|
1050
|
-
const events = this.fetchWebhookEvents(webhookTag);
|
|
1338
|
+
const events = await this.fetchWebhookEvents(webhookTag);
|
|
1051
1339
|
const event = events.find((event) => {
|
|
1052
1340
|
return event.tag === eventTag;
|
|
1053
1341
|
});
|
|
1054
1342
|
return event;
|
|
1055
1343
|
}
|
|
1056
|
-
fetchWebhookEvents(tag) {
|
|
1057
|
-
const webhook = this.fetchWebhook(tag);
|
|
1344
|
+
async fetchWebhookEvents(tag) {
|
|
1345
|
+
const webhook = await this.fetchWebhook(tag);
|
|
1058
1346
|
if (!webhook) {
|
|
1059
1347
|
throw new Error(`Webhook ${tag} does not exist`);
|
|
1060
1348
|
}
|