@configura/web-api 3.0.0-alpha.0 → 3.0.0-alpha.2

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.
Files changed (29) hide show
  1. package/dist/CatalogueAPI.d.ts +68 -1
  2. package/dist/CatalogueAPI.js +184 -219
  3. package/dist/CfgMeasure.js +1 -2
  4. package/dist/CfgProduct.js +131 -159
  5. package/dist/io/CfgIOManager.js +2 -11
  6. package/dist/io/CfgIOProdConfConnector.js +14 -25
  7. package/dist/io/CfgObservableStateManager.js +1 -1
  8. package/dist/productConfiguration/CfgFeature.d.ts +5 -0
  9. package/dist/productConfiguration/CfgFeature.js +64 -54
  10. package/dist/productConfiguration/CfgOption.d.ts +44 -0
  11. package/dist/productConfiguration/CfgOption.js +107 -71
  12. package/dist/productConfiguration/CfgProductConfiguration.js +22 -34
  13. package/dist/productConfiguration/productParamsGenerator.js +43 -57
  14. package/dist/productLoader.js +2 -13
  15. package/dist/syncGroups/SyncGroupsHandler.js +60 -83
  16. package/dist/syncGroups/SyncGroupsPathHelper.js +5 -5
  17. package/dist/syncGroups/SyncGroupsState.js +4 -5
  18. package/dist/syncGroups/SyncGroupsTransaction.js +259 -303
  19. package/dist/tasks/TaskHandler.js +53 -64
  20. package/dist/tests/testData/dummyProductForTest.js +4 -1
  21. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +18 -21
  22. package/dist/tests/testData/testDataCachedGetProduct.js +20 -20
  23. package/dist/tests/testData/testDataCachedPostValidate.js +6 -15
  24. package/dist/tests/testData/testDataProductAggregatedPrice.js +21 -21
  25. package/dist/tests/testData/testDataUpcharge.js +31 -22
  26. package/dist/utilitiesCatalogueData.js +21 -9
  27. package/dist/utilitiesCataloguePermission.js +5 -2
  28. package/dist/utilitiesConfiguration.js +21 -23
  29. package/package.json +3 -3
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { SelectionType } from "../productConfiguration/CfgFeature.js";
11
2
  import { ProductConfigurationBubbleMode, } from "../productConfiguration/CfgOption.js";
12
3
  import { SyncGroupsApplyMode } from "./SyncGroupsApplyMode.js";
@@ -239,16 +230,14 @@ import { SyncGroupsTransaction } from "./SyncGroupsTransaction.js";
239
230
  * Send to root for the passed option and any sibling which is selected, provided the Feature
240
231
  * is SelectOne. (As that one (should only be one) can be assumed to be affected).
241
232
  */
242
- function notifyOptionAndSelectedSiblings(option) {
243
- return __awaiter(this, void 0, void 0, function* () {
244
- const committed = false;
245
- const parentFeature = option.parent;
246
- if (parentFeature.selectionType === SelectionType.SelectOne) {
247
- // These only need to be OneLevel, as the final is ToRoot and they share their parent.
248
- yield Promise.all(option.parent.selectedOptions.map((o) => parentFeature._childHasChanged(o._internal, ProductConfigurationBubbleMode.OneLevel, committed)));
249
- }
250
- yield parentFeature._childHasChanged(option, ProductConfigurationBubbleMode.ToRoot, committed);
251
- });
233
+ async function notifyOptionAndSelectedSiblings(option) {
234
+ const committed = false;
235
+ const parentFeature = option.parent;
236
+ if (parentFeature.selectionType === SelectionType.SelectOne) {
237
+ // These only need to be OneLevel, as the final is ToRoot and they share their parent.
238
+ await Promise.all(option.parent.selectedOptions.map((o) => parentFeature._childHasChanged(o._internal, ProductConfigurationBubbleMode.OneLevel, committed)));
239
+ }
240
+ await parentFeature._childHasChanged(option, ProductConfigurationBubbleMode.ToRoot, committed);
252
241
  }
253
242
  /**
254
243
  * Is used to apply the SyncGroups functionality on the Configuration and the other way around.
@@ -287,84 +276,72 @@ export class SyncGroupsHandler {
287
276
  * Used to initially apply the sync state onto a new product so that it is "in sync"
288
277
  * and to reapply the sync state when an optional additional product is selected.
289
278
  */
290
- init(product, productLoader) {
291
- return __awaiter(this, void 0, void 0, function* () {
292
- const transaction = yield this.newTransaction(product, productLoader, true);
293
- try {
294
- yield transaction.applyRootProduct();
295
- yield this.commitTransaction(transaction);
296
- }
297
- finally {
298
- this.closeTransaction(transaction);
299
- }
300
- });
279
+ async init(product, productLoader) {
280
+ const transaction = await this.newTransaction(product, productLoader, true);
281
+ try {
282
+ await transaction.applyRootProduct();
283
+ await this.commitTransaction(transaction);
284
+ }
285
+ finally {
286
+ this.closeTransaction(transaction);
287
+ }
301
288
  }
302
289
  /**
303
290
  * Used when an Option is selected or deselected to apply all consequences of the sync groups.
304
291
  * Can cause multiple extra validation calls to the server.
305
292
  */
306
- selectOption(product, option, on, productLoader) {
307
- return __awaiter(this, void 0, void 0, function* () {
308
- if (product.parent !== undefined) {
309
- console.info("Normally the product passed shall be the root product");
310
- }
311
- yield this.setPending(option);
312
- const transaction = yield this.newTransaction(product, productLoader, false);
313
- try {
314
- const change = yield transaction.selectOption(SyncGroupsPathHelper.getPath(option), on);
315
- // Always commit the transaction. The change-result above only tells if the
316
- // configuration has changed. The SyncState may however also have changed.
317
- yield this.commitTransaction(transaction);
318
- return change;
319
- }
320
- finally {
321
- if (this._pending === option) {
322
- yield this.setPending(undefined);
323
- }
324
- this.closeTransaction(transaction);
293
+ async selectOption(product, option, on, productLoader) {
294
+ if (product.parent !== undefined) {
295
+ console.info("Normally the product passed shall be the root product");
296
+ }
297
+ await this.setPending(option);
298
+ const transaction = await this.newTransaction(product, productLoader, false);
299
+ try {
300
+ const change = await transaction.selectOption(SyncGroupsPathHelper.getPath(option), on);
301
+ // Always commit the transaction. The change-result above only tells if the
302
+ // configuration has changed. The SyncState may however also have changed.
303
+ await this.commitTransaction(transaction);
304
+ return change;
305
+ }
306
+ finally {
307
+ if (this._pending === option) {
308
+ await this.setPending(undefined);
325
309
  }
326
- });
310
+ this.closeTransaction(transaction);
311
+ }
327
312
  }
328
- setPending(newPending) {
329
- return __awaiter(this, void 0, void 0, function* () {
330
- const oldPending = this._pending;
331
- this._pending = newPending;
332
- if (oldPending !== undefined) {
333
- yield notifyOptionAndSelectedSiblings(oldPending);
334
- }
335
- if (newPending !== undefined) {
336
- yield notifyOptionAndSelectedSiblings(newPending);
337
- }
338
- });
313
+ async setPending(newPending) {
314
+ const oldPending = this._pending;
315
+ this._pending = newPending;
316
+ if (oldPending !== undefined) {
317
+ await notifyOptionAndSelectedSiblings(oldPending);
318
+ }
319
+ if (newPending !== undefined) {
320
+ await notifyOptionAndSelectedSiblings(newPending);
321
+ }
339
322
  }
340
323
  get pending() {
341
324
  return this._pending;
342
325
  }
343
- newTransaction(product, productLoader, assumeNoStartProductState) {
344
- var _a;
345
- return __awaiter(this, void 0, void 0, function* () {
346
- if (this._currentTransaction !== undefined) {
347
- this.closeTransaction(this._currentTransaction);
348
- }
349
- const transaction = yield SyncGroupsTransaction.make(this._syncState, this.updateMode, product, productLoader, assumeNoStartProductState);
350
- this._currentTransaction = transaction;
351
- // The transaction object is used as loading token
352
- (_a = this._loadingObservable) === null || _a === void 0 ? void 0 : _a.startChildLoading(transaction);
353
- return transaction;
354
- });
326
+ async newTransaction(product, productLoader, assumeNoStartProductState) {
327
+ if (this._currentTransaction !== undefined) {
328
+ this.closeTransaction(this._currentTransaction);
329
+ }
330
+ const transaction = await SyncGroupsTransaction.make(this._syncState, this.updateMode, product, productLoader, assumeNoStartProductState);
331
+ this._currentTransaction = transaction;
332
+ // The transaction object is used as loading token
333
+ this._loadingObservable?.startChildLoading(transaction);
334
+ return transaction;
355
335
  }
356
336
  closeTransaction(transaction) {
357
- var _a;
358
337
  transaction.close();
359
- (_a = this._loadingObservable) === null || _a === void 0 ? void 0 : _a.stopChildLoading(transaction);
338
+ this._loadingObservable?.stopChildLoading(transaction);
360
339
  }
361
- commitTransaction(transaction) {
362
- return __awaiter(this, void 0, void 0, function* () {
363
- if (transaction.isClosed) {
364
- return;
365
- }
366
- yield transaction.commit();
367
- this.closeTransaction(transaction);
368
- });
340
+ async commitTransaction(transaction) {
341
+ if (transaction.isClosed) {
342
+ return;
343
+ }
344
+ await transaction.commit();
345
+ this.closeTransaction(transaction);
369
346
  }
370
347
  }
@@ -34,7 +34,7 @@ export class SyncGroupsPathHelper {
34
34
  case "p": {
35
35
  const refKey = path.shift();
36
36
  const additional = item.additionalProducts.find((p) => p.refKey === refKey);
37
- assertDefined(additional, `Additional product not found "p, ${refKey !== null && refKey !== void 0 ? refKey : ""}, ${path.join(", ")}"`);
37
+ assertDefined(additional, `Additional product not found "p, ${refKey ?? ""}, ${path.join(", ")}"`);
38
38
  item = additional._internal;
39
39
  break;
40
40
  }
@@ -43,22 +43,22 @@ export class SyncGroupsPathHelper {
43
43
  item = item.configuration._internal;
44
44
  break;
45
45
  default:
46
- throw new Error(`Unexpected path segment "${segment !== null && segment !== void 0 ? segment : ""}"`);
46
+ throw new Error(`Unexpected path segment "${segment ?? ""}"`);
47
47
  }
48
48
  }
49
49
  else if (item instanceof _CfgProductConfigurationInternal) {
50
50
  const feature = item.features.find((f) => f.code === segment);
51
- assertDefined(feature, `Feature not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
51
+ assertDefined(feature, `Feature not found "${segment ?? ""}", ${path.join(", ")}`);
52
52
  item = feature._internal;
53
53
  }
54
54
  else if (item instanceof _CfgFeatureInternal) {
55
55
  const option = item.options.find((o) => o.code === segment);
56
- assertDefined(option, `Option not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
56
+ assertDefined(option, `Option not found "${segment ?? ""}", ${path.join(", ")}`);
57
57
  item = option._internal;
58
58
  }
59
59
  else if (item instanceof _CfgOptionInternal) {
60
60
  const feature = item.features.find((o) => o.code === segment);
61
- assertDefined(feature, `Feature not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
61
+ assertDefined(feature, `Feature not found "${segment ?? ""}", ${path.join(", ")}`);
62
62
  item = feature._internal;
63
63
  }
64
64
  else {
@@ -12,7 +12,7 @@ export class SyncGroupsState {
12
12
  this._verboseLogging = _verboseLogging;
13
13
  this._selectOne = new Map();
14
14
  this._selectMany = new Map();
15
- this.setCompact(initial !== null && initial !== void 0 ? initial : {});
15
+ this.setCompact(initial ?? {});
16
16
  }
17
17
  get verboseLogging() {
18
18
  return this._verboseLogging;
@@ -65,8 +65,7 @@ export class SyncGroupsState {
65
65
  return this._selectOne.get(syncCode);
66
66
  }
67
67
  getForSelectMany(syncCode, optionCode) {
68
- var _a;
69
- return (_a = this._selectMany.get(syncCode)) === null || _a === void 0 ? void 0 : _a.get(optionCode);
68
+ return this._selectMany.get(syncCode)?.get(optionCode);
70
69
  }
71
70
  /** Overrides the current sync state */
72
71
  setCompact(s) {
@@ -133,11 +132,11 @@ export class SyncGroupsState {
133
132
  const styles = [];
134
133
  let msg = "";
135
134
  if (syncCode !== undefined && isMany) {
136
- msg += `%c${optionCode !== null && optionCode !== void 0 ? optionCode : ""}%c in %c${syncCode}%c set to %c${selected ? "on" : "off"}`;
135
+ msg += `%c${optionCode ?? ""}%c in %c${syncCode}%c set to %c${selected ? "on" : "off"}`;
137
136
  styles.push(bold, "", bold, "", bold);
138
137
  }
139
138
  else if (syncCode !== undefined && !isMany) {
140
- msg += `%c${syncCode}%c set to %c${optionCode !== null && optionCode !== void 0 ? optionCode : ""}`;
139
+ msg += `%c${syncCode}%c set to %c${optionCode ?? ""}`;
141
140
  styles.push(bold, "", bold);
142
141
  }
143
142
  msg += "\n\n%cSync State (single)";