@ductape/sdk 0.0.4-v5 → 0.0.4-v7
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/index.d.ts +2 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/processor/repos/sms.repo.d.ts +4 -4
- package/dist/processor/repos/sms.repo.js +23 -10
- package/dist/processor/repos/sms.repo.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +2 -1
- package/dist/processor/services/processor.service.js +1 -0
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/products/services/products.service.d.ts +1 -1
- package/dist/products/services/products.service.js +61 -14
- package/dist/products/services/products.service.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.userAuth.validator.js +1 -0
- package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
- package/dist/types/processor.types.d.ts +11 -0
- package/dist/types/processor.types.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +3 -1
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/package.json +1 -1
|
@@ -113,7 +113,7 @@ export default class ProductsBuilderService implements IProductsBuilderService {
|
|
|
113
113
|
private createNewProduct;
|
|
114
114
|
checkIfProductExists(name: string): Promise<false | IProduct>;
|
|
115
115
|
fetchProduct(): IProduct;
|
|
116
|
-
createSession(data: IProductSession): Promise<void>;
|
|
116
|
+
createSession(data: Partial<IProductSession>, throwErrorIfExists?: boolean): Promise<void>;
|
|
117
117
|
updateSession(tag: string, data: Partial<IProductSession>): Promise<void>;
|
|
118
118
|
fetchSession(tag: string): IProductSession | null;
|
|
119
119
|
fetchSessions(): Array<IProductSession>;
|
|
@@ -192,19 +192,46 @@ class ProductsBuilderService {
|
|
|
192
192
|
}
|
|
193
193
|
return this.product;
|
|
194
194
|
}
|
|
195
|
-
async createSession(data) {
|
|
195
|
+
async createSession(data, throwErrorIfExists = false) {
|
|
196
196
|
try {
|
|
197
|
-
|
|
198
|
-
if (!
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
await validators_1.CreateProductSessionSchema.validateAsync(data);
|
|
198
|
+
if (!data.tag) {
|
|
199
|
+
throw new Error('tag field is required');
|
|
200
|
+
}
|
|
201
|
+
const exists = this.fetchSession(data.tag);
|
|
202
|
+
if (!exists) {
|
|
203
|
+
if (!data.selector.startsWith('$Schema{')) {
|
|
204
|
+
throw new Error('Selector should be in the format $Schema{...}{key}');
|
|
205
|
+
}
|
|
206
|
+
const stages = (0, string_utils_1.extractStages)(data.selector);
|
|
207
|
+
let current = data.schema;
|
|
208
|
+
for (const stage of stages) {
|
|
209
|
+
if (current && typeof current === 'object' && stage in current) {
|
|
210
|
+
current = current[stage];
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
throw new Error(`${data.selector} not found in event sample`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (current === null ||
|
|
217
|
+
typeof current === "undefined" ||
|
|
218
|
+
typeof current === "object") {
|
|
219
|
+
throw new Error("Selector value is not allowed to be an object|array|null|undefined");
|
|
220
|
+
}
|
|
221
|
+
data.schema_data = await this.inputsService.parseJson({
|
|
201
222
|
data: data.schema,
|
|
202
|
-
expected: inputs_types_1.ExpectedValues.PARSESAMPLE
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
223
|
+
expected: inputs_types_1.ExpectedValues.PARSESAMPLE
|
|
224
|
+
});
|
|
225
|
+
data.selectorValue = current;
|
|
226
|
+
delete data.tag;
|
|
227
|
+
const payload = Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE });
|
|
228
|
+
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|
|
206
229
|
await this.initializeProduct(this.product_id);
|
|
207
230
|
}
|
|
231
|
+
else {
|
|
232
|
+
if (throwErrorIfExists)
|
|
233
|
+
throw new Error(`Session ${data.tag} already exists`);
|
|
234
|
+
}
|
|
208
235
|
}
|
|
209
236
|
catch (e) {
|
|
210
237
|
throw e;
|
|
@@ -212,13 +239,13 @@ class ProductsBuilderService {
|
|
|
212
239
|
}
|
|
213
240
|
async updateSession(tag, data) {
|
|
214
241
|
try {
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
217
|
-
throw new Error(`Session ${tag} not found`);
|
|
242
|
+
const session = this.fetchSession(tag);
|
|
243
|
+
if (!session) {
|
|
244
|
+
throw new Error(`Session with tag: ${tag} not found`);
|
|
218
245
|
}
|
|
219
246
|
//const { _id } = auth;
|
|
220
247
|
await validators_1.UpdateProductSessionSchema.validateAsync(data); // Change to update;
|
|
221
|
-
if (data.tag && this.
|
|
248
|
+
if (data.tag && this.fetchSession(data.tag) && data.tag !== tag) {
|
|
222
249
|
throw new Error(`tag ${data.tag} is in use`); // TODO: also check on the backend
|
|
223
250
|
}
|
|
224
251
|
if (!data.tag) {
|
|
@@ -230,8 +257,28 @@ class ProductsBuilderService {
|
|
|
230
257
|
expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
|
|
231
258
|
category: enums_1.Categories.DATA,
|
|
232
259
|
}));
|
|
260
|
+
if (!data.selector) {
|
|
261
|
+
throw new Error('Selector is expected when updating schema');
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (data.selector) {
|
|
265
|
+
const stages = (0, string_utils_1.extractStages)(data.selector);
|
|
266
|
+
let current = data.schema;
|
|
267
|
+
for (const stage of stages) {
|
|
268
|
+
if (current && typeof current === 'object' && stage in current) {
|
|
269
|
+
current = current[stage];
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
throw new Error(`${data.selector} not found in event sample`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (current === null ||
|
|
276
|
+
typeof current === "undefined" ||
|
|
277
|
+
typeof current === "object") {
|
|
278
|
+
throw new Error("Selector value is not allowed to be an object|array|null|undefined");
|
|
279
|
+
}
|
|
233
280
|
}
|
|
234
|
-
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({},
|
|
281
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, session), data)), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
235
282
|
await this.initializeProduct(this.product_id);
|
|
236
283
|
}
|
|
237
284
|
catch (e) {
|