@configura/web-api 1.6.1-alpha.7 → 1.6.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 (43) hide show
  1. package/.eslintrc.json +18 -0
  2. package/dist/CatalogueAPI.d.ts +4 -9
  3. package/dist/CatalogueAPI.js +6 -3
  4. package/dist/CfgProduct.d.ts +31 -12
  5. package/dist/CfgProduct.js +124 -45
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +2 -0
  8. package/dist/productConfiguration/CfgFeature.d.ts +13 -3
  9. package/dist/productConfiguration/CfgFeature.js +77 -52
  10. package/dist/productConfiguration/CfgOption.d.ts +30 -8
  11. package/dist/productConfiguration/CfgOption.js +49 -17
  12. package/dist/productConfiguration/CfgProductConfiguration.d.ts +1 -1
  13. package/dist/productConfiguration/CfgProductConfiguration.js +4 -2
  14. package/dist/productConfiguration/filters.js +7 -7
  15. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +21 -0
  16. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -0
  17. package/dist/syncGroups/SyncGroupsHandler.d.ts +41 -0
  18. package/dist/syncGroups/SyncGroupsHandler.js +358 -0
  19. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +27 -0
  20. package/dist/syncGroups/SyncGroupsPathHelper.js +90 -0
  21. package/dist/syncGroups/SyncGroupsState.d.ts +36 -0
  22. package/dist/syncGroups/SyncGroupsState.js +125 -0
  23. package/dist/syncGroups/SyncGroupsTransaction.d.ts +155 -0
  24. package/dist/syncGroups/SyncGroupsTransaction.js +576 -0
  25. package/dist/tasks/TaskHandler.d.ts +1 -1
  26. package/dist/tasks/TaskHandler.js +20 -9
  27. package/dist/tests/testData/collectorForTest.d.ts +1 -1
  28. package/dist/tests/testData/collectorForTest.js +1 -2
  29. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +3 -24
  30. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +30 -101
  31. package/dist/tests/testData/testDataCachedGetProduct.d.ts +1 -1
  32. package/dist/tests/testData/testDataCachedGetProduct.js +16 -27
  33. package/dist/tests/testData/testDataCachedPostValidate.js +5 -5
  34. package/dist/tests/testData/testDataOptions.d.ts +13 -0
  35. package/dist/tests/testData/testDataOptions.js +60 -0
  36. package/dist/tests/testData/testDataProductAggregatedPrice.js +19 -30
  37. package/dist/tests/testData/testDataUpcharge.d.ts +3 -24
  38. package/dist/tests/testData/testDataUpcharge.js +17 -49
  39. package/dist/utilitiesCatalogueData.d.ts +8 -2
  40. package/dist/utilitiesCatalogueData.js +105 -9
  41. package/dist/utilitiesCataloguePermission.d.ts +1 -3
  42. package/dist/utilitiesCataloguePermission.js +10 -14
  43. package/package.json +3 -3
@@ -0,0 +1,576 @@
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
+ import { assert } from "@configura/web-utilities";
11
+ import { CfgProductBubbleMode } from "../CfgProduct.js";
12
+ import { SelectionType, } from "../productConfiguration/CfgFeature.js";
13
+ import { ProductConfigurationBubbleMode, } from "../productConfiguration/CfgOption.js";
14
+ import { SyncGroupsApplyMode } from "./SyncGroupsApplyMode.js";
15
+ import { SyncGroupsPathHelper } from "./SyncGroupsPathHelper.js";
16
+ /**
17
+ * The Transaction is a transient object used to track all the changes made to the supplied
18
+ * SyncGroupState as a result of a (normally) single initial event, like when opening a product
19
+ * or the user selecting an option on an already open product.
20
+ *
21
+ * All state changes are made on an internal copy of the original SyncGroupState (called target)
22
+ * so they can later be used (i.e. committed) at once to the visible product, or safely discarded
23
+ * without affecting anything.
24
+ *
25
+ * The Transaction keeps track of which Features and SyncGroups have been affected so far, to
26
+ * eliminate the risk of infinite loops.
27
+ *
28
+ * Terminology
29
+ * ===========
30
+ *
31
+ * You APPLY things onto the transaction in order to update the sync state inside the transaction.
32
+ * The transaction can then UPDATE other things in order to apply it's sync state onto them.
33
+ *
34
+ * Transaction.applyThing() ...onto the transaction
35
+ * Transaction.updateThing() ...with the transaction
36
+ *
37
+ * @see SyncGroupHandler.ts for more information, including the general resolution algorithm.
38
+ */
39
+ export class SyncGroupsTransaction {
40
+ constructor(syncState, updateMode, productLoader, original, target, initial) {
41
+ this._closed = false;
42
+ this.affectedSelectOneFeatures = new Set();
43
+ this.affectedSelectManyOptions = new Set();
44
+ this.affectedSelectOneSyncGroups = new Set();
45
+ this.affectedSelectManySyncGroupsAndOptions = new Map();
46
+ this.syncState = syncState.clone();
47
+ this.originalSyncState = syncState;
48
+ this.updateMode = updateMode;
49
+ this.productLoader = productLoader;
50
+ this.originalProduct = original;
51
+ this.target = target;
52
+ this.initial = initial;
53
+ }
54
+ static make(syncState, updateMode, product, productLoader, assumeNoStartState) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const t = new this(syncState, updateMode, productLoader, product, yield product.clone(), assumeNoStartState ? undefined : yield product.clone());
57
+ return t;
58
+ });
59
+ }
60
+ /************************************************************************
61
+ * Public API (intentionally limited)
62
+ ************************************************************************/
63
+ get isClosed() {
64
+ return this._closed;
65
+ }
66
+ close() {
67
+ this._closed = true;
68
+ }
69
+ /**
70
+ * This is (among other) the entry point when loading a new product.
71
+ *
72
+ * @returns true if at least one Feature changed it state. This is a bit counter intuitive,
73
+ * but as this method will hand over to applyProduct if it updates the SyncState it can cause
74
+ * the Features to change. And we need to pass that information back to know when to stop.
75
+ */
76
+ applyRootProduct() {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const productWithInitial = { target: this.target, initial: this.initial };
79
+ if (!(yield this.applyProduct(productWithInitial))) {
80
+ // All done!
81
+ return false;
82
+ }
83
+ return yield this.updateRootProduct(undefined);
84
+ });
85
+ }
86
+ /**
87
+ * This is the entry point for an active (often user) selection of an option.
88
+ */
89
+ selectOption(optionPath, on) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const option = SyncGroupsPathHelper.getOptionFromPath(optionPath, this.target);
92
+ const feature = option.parent;
93
+ let change = false;
94
+ let productToValidate = undefined;
95
+ // At this point in handling sync groups we go back to normal selecting.
96
+ //
97
+ // This is because a normal selection can bring features into scope which should push to or
98
+ // (if the SyncGroup is defined) pull from the Sync State.
99
+ //
100
+ // We use BubbleSelected (without validation) as we can delay the validation until after we
101
+ // have applied the SyncGroup (if any).
102
+ if (yield feature.selectOption(option, on, ProductConfigurationBubbleMode.BubbleSelected)) {
103
+ productToValidate = feature.parentProduct;
104
+ change = true;
105
+ switch (feature.selectionType) {
106
+ case SelectionType.SelectOne:
107
+ this.affectedSelectOneFeatures.add(feature);
108
+ break;
109
+ case SelectionType.SelectMany:
110
+ this.affectedSelectManyOptions.add(option);
111
+ break;
112
+ default:
113
+ throw new Error("Should not happen");
114
+ }
115
+ }
116
+ switch (feature.selectionType) {
117
+ case SelectionType.SelectOne:
118
+ this.applySelectOneFeature(feature, true, false);
119
+ break;
120
+ case SelectionType.SelectMany:
121
+ this.applySelectManyOption(option, true);
122
+ break;
123
+ }
124
+ if (yield this.updateRootProduct(productToValidate)) {
125
+ change = true;
126
+ }
127
+ return change;
128
+ });
129
+ }
130
+ /**
131
+ * Overwrites the original Product and SyncGroupState (supplied when creating the Transaction)
132
+ * with the internal versions inside this Transaction.
133
+ *
134
+ * @throws error if the transaction has already been closed.
135
+ */
136
+ commit() {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ assert(this.isClosed === false, "Trying to commit a closed Transaction");
139
+ this.originalSyncState.copyFrom(this.syncState);
140
+ yield this.originalProduct.copyFrom(this.target, false, this.productLoader);
141
+ });
142
+ }
143
+ /************************************************************************
144
+ * Updating things with the Transaction's SyncState
145
+ ************************************************************************/
146
+ /**
147
+ * Apply current sync groups on those who wants to listen until there is no more to settle.
148
+ * @returns true if at least one Feature changed selected Option
149
+ */
150
+ updateRootProduct(productToValidate) {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ const productsToValidate = new Set();
153
+ if (productToValidate !== undefined) {
154
+ productsToValidate.add(productToValidate);
155
+ }
156
+ const productWithInitial = { target: this.target, initial: this.initial };
157
+ yield this.updateProduct(productWithInitial, productsToValidate);
158
+ if (productsToValidate.size === 0) {
159
+ // All have been settled, continue to pullPhase
160
+ return yield this.applyRootProduct();
161
+ }
162
+ if (this.isClosed) {
163
+ // We could exit in more places when the transaction has been aborted, but as
164
+ // revalidate is really the only thing that could be expensive time consuming we only
165
+ // check here.
166
+ return false;
167
+ }
168
+ const promises = [];
169
+ for (const product of productsToValidate) {
170
+ promises.push(product._revalidate(CfgProductBubbleMode.ToRoot, this.productLoader));
171
+ }
172
+ const revalidationResults = yield Promise.all(promises);
173
+ if (revalidationResults.every((r) => !r)) {
174
+ this.close();
175
+ return false;
176
+ }
177
+ // Apply over again, to settle deeper down. Our theory is that the front of "settled" will
178
+ // move deeper and deeper into the tree.
179
+ yield this.updateRootProduct(undefined);
180
+ // We had productsToValidate, and so there must have been a change.
181
+ return true;
182
+ });
183
+ }
184
+ /**
185
+ * Applies the SyncState to the Product and it's AdditionalProducts (sub-products).
186
+ * @param productsToValidate To this all products that will need validation are added.
187
+ */
188
+ updateProduct(product, productsToValidate) {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ const promises = [];
191
+ promises.push(this.updateFeatures(getFeaturesFromProduct(product), productsToValidate));
192
+ for (const additionalProduct of getAdditionalProducts(product)) {
193
+ promises.push(this.updateProduct(additionalProduct, productsToValidate));
194
+ }
195
+ yield Promise.all(promises);
196
+ });
197
+ }
198
+ /**
199
+ * Applies the SyncState to an array of Features.
200
+ * @param productsToValidate To this all products that will need validation are added.
201
+ */
202
+ updateFeatures(features, productsToValidate) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ yield Promise.all(features.map((feature) => __awaiter(this, void 0, void 0, function* () {
205
+ switch (yield this.updateFeature(feature, productsToValidate)) {
206
+ case "stop":
207
+ return;
208
+ case "recurseDown":
209
+ yield this.updateOptions(getSelectedOptions(feature), productsToValidate);
210
+ return;
211
+ }
212
+ })));
213
+ });
214
+ }
215
+ /**
216
+ * Applies the SyncState to an array of Options.
217
+ * @param productsToValidate To this all products that will need validation are added.
218
+ */
219
+ updateOptions(options, productsToValidate) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ yield Promise.all(options.map((option) => {
222
+ return this.updateFeatures(getFeaturesFromOption(option), productsToValidate);
223
+ }));
224
+ });
225
+ }
226
+ /**
227
+ * Applies the SyncState to a Feature
228
+ * @param productsToValidate To this all products that will need validation are added
229
+ * @returns Whether we shall stop recursing down (because we are in a state which we
230
+ * expect to be resolved later), we shall continue recursing down.
231
+ */
232
+ updateFeature(featureWithInitial, productsToValidate) {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ const feature = featureWithInitial.target;
235
+ const syncCode = feature.getSyncCode("pull");
236
+ if (syncCode === undefined) {
237
+ // Just continue down, features with no sync groups are always settled
238
+ return "recurseDown";
239
+ }
240
+ if (syncCode === false) {
241
+ // Here we only handle pull. Initializing those missing in SyncMap
242
+ // we do later. We wait until we have settled as much as we can with what
243
+ // we have now, to increase chances of the values being written to the
244
+ // SyncState being the right ones.
245
+ return "stop";
246
+ }
247
+ switch (feature.selectionType) {
248
+ case SelectionType.Group:
249
+ return "recurseDown";
250
+ case SelectionType.SelectOne:
251
+ return yield this.updateSelectOneFeature(syncCode, featureWithInitial, productsToValidate);
252
+ case SelectionType.SelectMany:
253
+ return yield this.updateSelectManyFeature(syncCode, featureWithInitial, productsToValidate);
254
+ }
255
+ });
256
+ }
257
+ /**
258
+ * Decides if the SyncState can be applied to the SelectOne Feature, and then changes
259
+ * the state of the Feature if so.
260
+ * @param syncCode What SyncGroup the Feature belongs to
261
+ * @param productsToValidate To this all products that will need validation are added
262
+ * @returns Whether we shall stop recursing down (because we are in a state which we
263
+ * expect to be resolved later), we shall continue recursing down.
264
+ */
265
+ updateSelectOneFeature(syncCode, featureWithInitial, productsToValidate) {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ const feature = featureWithInitial.target;
268
+ const featureDidJustComeIntoScope = featureWithInitial.initial === undefined;
269
+ if (this.affectedSelectOneFeatures.has(feature)) {
270
+ // This feature has already changed selection once for this transaction. We expect
271
+ // this to happen very rarely, as the algorithm should settle the selection tree
272
+ // further and further out. Nevertheless, this safeguard is needed to avoid infinite
273
+ // looping if for example the server would return the same data over and over.
274
+ return "recurseDown";
275
+ }
276
+ if (!featureDidJustComeIntoScope && !this.affectedSelectOneSyncGroups.has(syncCode)) {
277
+ return "recurseDown";
278
+ }
279
+ const currentSyncGroupValue = this.syncState.getForSelectOne(syncCode);
280
+ if (currentSyncGroupValue === undefined) {
281
+ // This branch will have to be settled later. Don't go further down here.
282
+ return "stop";
283
+ }
284
+ const selectedOption = feature.selectedOptions[0];
285
+ if (selectedOption !== undefined && selectedOption.code === currentSyncGroupValue) {
286
+ // Settled, continue
287
+ return "recurseDown";
288
+ }
289
+ const optionToSelect = feature.options.find((o) => o.code === currentSyncGroupValue);
290
+ if (optionToSelect === undefined) {
291
+ // No option which can be selected (keep current value and recurse down)
292
+ return "recurseDown";
293
+ }
294
+ // Update the value. Validations are collected so that we do not send more than necessary.
295
+ // Do not recurse further as we will change the state and so what is selected now won't be
296
+ // selected then.
297
+ yield feature.selectOption(optionToSelect._internal, true, ProductConfigurationBubbleMode.ToRoot);
298
+ this.affectedSelectOneFeatures.add(feature);
299
+ productsToValidate.add(feature.parentProduct);
300
+ return "stop";
301
+ });
302
+ }
303
+ /**
304
+ * Decides if the SyncState can be applied to Options in the SelectMany Feature, and
305
+ * then changes the state of the Options if so.
306
+ * @param syncCode What SyncGroup the Feature belongs to
307
+ * @param productsToValidate To this all products that will need validation are added
308
+ * @returns Always "stop" as recursion is handled internally. Return for consistency.
309
+ */
310
+ updateSelectManyFeature(syncCode, feature, productsToValidate) {
311
+ return __awaiter(this, void 0, void 0, function* () {
312
+ const optionsToContinueDown = [];
313
+ for (const option of getOptions(feature)) {
314
+ switch (yield this.updateSelectManyOption(syncCode, option, productsToValidate)) {
315
+ case "stop":
316
+ continue;
317
+ case "recurseDown":
318
+ optionsToContinueDown.push(option);
319
+ continue;
320
+ }
321
+ }
322
+ yield this.updateOptions(optionsToContinueDown, productsToValidate);
323
+ // stop as the method above handles the recursion down
324
+ return "stop";
325
+ });
326
+ }
327
+ /**
328
+ * Decides if the SyncState can be applied to the SelectMany Option, and then changes
329
+ * the state of the Option if so.
330
+ * @param syncCode What SyncGroup the Feature belongs to
331
+ * @param productsToValidate To this all products that will need validation are added
332
+ * @returns Whether we shall stop recursing down (because we are in a state which we
333
+ * expect to be resolved later), we shall continue recursing down.
334
+ */
335
+ updateSelectManyOption(syncCode, optionWithInitial, productsToValidate) {
336
+ return __awaiter(this, void 0, void 0, function* () {
337
+ const option = optionWithInitial.target;
338
+ const featureDidJustComeIntoScope = optionWithInitial.initial === undefined;
339
+ const optionSelected = option.selected;
340
+ const recurseOrStopIfNoChange = optionSelected ? "recurseDown" : "stop";
341
+ if (this.affectedSelectManyOptions.has(option)) {
342
+ // This option has already changed selection once for this transaction. We expect
343
+ // this to happen very rarely, as the algorithm should settle the selection tree
344
+ // further and further out. Nevertheless, this safeguard is needed to avoid infinite
345
+ // looping if for example the server would return the same data over and over.
346
+ return recurseOrStopIfNoChange;
347
+ }
348
+ if (!featureDidJustComeIntoScope &&
349
+ !this.hasSyncGroupAffectedForSelectMany(syncCode, option)) {
350
+ return "recurseDown";
351
+ }
352
+ const syncGroupValueForOption = this.syncState.getForSelectMany(syncCode, option.code);
353
+ if (syncGroupValueForOption === undefined) {
354
+ // The sync group has no opinion on this. If it is selected, just continue down.
355
+ return recurseOrStopIfNoChange;
356
+ }
357
+ if (syncGroupValueForOption === optionSelected) {
358
+ // We are in sync for this option
359
+ return recurseOrStopIfNoChange;
360
+ }
361
+ const feature = option.parent;
362
+ // Update the value. Validations are collected so that we do not
363
+ // send more than necessary. Do not recurse further as we will change
364
+ // the state and so what is selected now won't be selected then.
365
+ yield feature.selectOption(option, syncGroupValueForOption, ProductConfigurationBubbleMode.ToRoot);
366
+ this.affectedSelectManyOptions.add(option);
367
+ productsToValidate.add(feature.parentProduct);
368
+ return "stop";
369
+ });
370
+ }
371
+ /************************************************************************
372
+ * Applying things to the Transaction's SyncState
373
+ ************************************************************************/
374
+ applyProduct(product) {
375
+ return __awaiter(this, void 0, void 0, function* () {
376
+ let change = false;
377
+ if (yield this.applyFeatures(getFeaturesFromProduct(product))) {
378
+ if (this.updateMode === SyncGroupsApplyMode.Strict) {
379
+ return true;
380
+ }
381
+ change = true;
382
+ }
383
+ for (const additionalProduct of getAdditionalProducts(product)) {
384
+ if (yield this.applyProduct(additionalProduct)) {
385
+ if (this.updateMode === SyncGroupsApplyMode.Strict) {
386
+ return true;
387
+ }
388
+ change = true;
389
+ }
390
+ }
391
+ return change;
392
+ });
393
+ }
394
+ applyFeatures(featureWithInitials) {
395
+ return __awaiter(this, void 0, void 0, function* () {
396
+ let change = false;
397
+ for (const featureWithInitial of featureWithInitials) {
398
+ const feature = featureWithInitial.target;
399
+ switch (feature.selectionType) {
400
+ case SelectionType.SelectOne:
401
+ if (this.applySelectOneFeature(feature, false, featureWithInitial.initial === undefined)) {
402
+ change = true;
403
+ }
404
+ break;
405
+ case SelectionType.SelectMany:
406
+ if (this.applySelectManyFeature(featureWithInitial)) {
407
+ change = true;
408
+ }
409
+ break;
410
+ }
411
+ if (change && this.updateMode === SyncGroupsApplyMode.Strict) {
412
+ return true;
413
+ }
414
+ if (yield this.applyOptions(getSelectedOptions(featureWithInitial))) {
415
+ if (this.updateMode === SyncGroupsApplyMode.Strict) {
416
+ return true;
417
+ }
418
+ change = true;
419
+ }
420
+ }
421
+ return change;
422
+ });
423
+ }
424
+ applyOptions(options) {
425
+ return __awaiter(this, void 0, void 0, function* () {
426
+ let change = false;
427
+ for (const option of options) {
428
+ if (yield this.applyFeatures(getFeaturesFromOption(option))) {
429
+ if (this.updateMode === SyncGroupsApplyMode.Strict) {
430
+ return true;
431
+ }
432
+ change = true;
433
+ }
434
+ }
435
+ return change;
436
+ });
437
+ }
438
+ applySelectOneFeature(feature, activeSelectionForce, featureDidJustComeIntoScope) {
439
+ const selectionType = feature.selectionType;
440
+ if (selectionType !== SelectionType.SelectOne) {
441
+ throw new Error("can only be used for selectOne");
442
+ }
443
+ const syncCode = feature.getSyncCode("push");
444
+ if (syncCode === undefined || syncCode === false) {
445
+ return false;
446
+ }
447
+ if (this.affectedSelectOneSyncGroups.has(syncCode)) {
448
+ return false;
449
+ }
450
+ const currentSyncGroupOptionCode = this.syncState.getForSelectOne(syncCode);
451
+ const option = feature.selectedOptions[0];
452
+ if (option === undefined) {
453
+ // Options with no default are never written
454
+ return false;
455
+ }
456
+ if (activeSelectionForce) {
457
+ // To make re-apply happen, even if it actually does not update the sync group
458
+ this.affectedSelectOneSyncGroups.add(syncCode);
459
+ }
460
+ if (option.code === currentSyncGroupOptionCode) {
461
+ return false;
462
+ }
463
+ // featureDidJustComeIntoScope, in CET there is a feature that if a feature appears which
464
+ // can not be set to the current sync group value, then it will set in the opposite
465
+ // direction. Like if the sync group was empty. To avoid bouncing back and forth we will
466
+ // need to enforce that a sync group can only be updated once per transaction
467
+ if (!(activeSelectionForce ||
468
+ currentSyncGroupOptionCode === undefined ||
469
+ (featureDidJustComeIntoScope &&
470
+ feature.options.every((o) => currentSyncGroupOptionCode !== o.code)))) {
471
+ return false;
472
+ }
473
+ this.affectedSelectOneSyncGroups.add(syncCode);
474
+ this.syncState.setForSelectOne(syncCode, option.code);
475
+ return true;
476
+ }
477
+ applySelectManyFeature(featureWithInitial) {
478
+ let change = false;
479
+ for (const optionWithInitial of getOptions(featureWithInitial)) {
480
+ if (this.applySelectManyOption(optionWithInitial.target, false)) {
481
+ if (this.updateMode === SyncGroupsApplyMode.Strict) {
482
+ return true;
483
+ }
484
+ change = true;
485
+ }
486
+ }
487
+ return change;
488
+ }
489
+ applySelectManyOption(option, activeSelectionForce) {
490
+ const feature = option.parent;
491
+ if (feature.selectionType !== SelectionType.SelectMany) {
492
+ throw new Error("can only be used for selectMany");
493
+ }
494
+ const syncCode = feature.getSyncCode("push");
495
+ if (syncCode === undefined || syncCode === false) {
496
+ return false;
497
+ }
498
+ if (this.hasSyncGroupAffectedForSelectMany(syncCode, option)) {
499
+ return false;
500
+ }
501
+ const optionSelected = option.selected;
502
+ const currentSyncGroupValue = this.syncState.getForSelectMany(syncCode, option.code);
503
+ if (activeSelectionForce) {
504
+ // To make re-apply happen, even if it actually does not update the sync group
505
+ this.addSyncGroupAffectedForSelectMany(syncCode, option);
506
+ }
507
+ // We only initialize if the option is selected or we force.
508
+ // activeSelectionForce = active selection by the user.
509
+ if (!(currentSyncGroupValue === undefined && optionSelected) &&
510
+ !(activeSelectionForce && currentSyncGroupValue !== optionSelected)) {
511
+ return false;
512
+ }
513
+ this.addSyncGroupAffectedForSelectMany(syncCode, option);
514
+ this.syncState.setForSelectMany(syncCode, option.code, optionSelected);
515
+ return true;
516
+ }
517
+ addSyncGroupAffectedForSelectMany(syncCode, option) {
518
+ let forSyncCode = this.affectedSelectManySyncGroupsAndOptions.get(syncCode);
519
+ if (forSyncCode === undefined) {
520
+ forSyncCode = new Set();
521
+ this.affectedSelectManySyncGroupsAndOptions.set(syncCode, forSyncCode);
522
+ }
523
+ forSyncCode.add(option.code);
524
+ }
525
+ hasSyncGroupAffectedForSelectMany(syncCode, option) {
526
+ var _a;
527
+ return ((_a = this.affectedSelectManySyncGroupsAndOptions.get(syncCode)) === null || _a === void 0 ? void 0 : _a.has(option.code)) === true;
528
+ }
529
+ }
530
+ function getAdditionalProducts(product) {
531
+ const initial = product.initial;
532
+ return product.target.additionalProducts.map((childTarget) => {
533
+ const refKey = childTarget.refKey;
534
+ const childInitial = initial === null || initial === void 0 ? void 0 : initial.additionalProducts.find((p) => refKey === p.refKey);
535
+ return {
536
+ target: childTarget._internal,
537
+ initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
538
+ };
539
+ });
540
+ }
541
+ function pairOptions(targets, initials) {
542
+ return targets.map((childTarget) => {
543
+ const key = childTarget.key;
544
+ const childInitial = initials === null || initials === void 0 ? void 0 : initials.find((o) => key === o.key);
545
+ return {
546
+ target: childTarget._internal,
547
+ initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
548
+ };
549
+ });
550
+ }
551
+ function getSelectedOptions(feature) {
552
+ var _a;
553
+ return pairOptions(feature.target.selectedOptions, (_a = feature.initial) === null || _a === void 0 ? void 0 : _a.selectedOptions);
554
+ }
555
+ function getOptions(feature) {
556
+ var _a;
557
+ return pairOptions(feature.target.options, (_a = feature.initial) === null || _a === void 0 ? void 0 : _a.options);
558
+ }
559
+ function pairFeatures(targets, initials) {
560
+ return targets.map((childTarget) => {
561
+ const key = childTarget.key;
562
+ const childInitial = initials === null || initials === void 0 ? void 0 : initials.find((f) => key === f.key);
563
+ return {
564
+ target: childTarget._internal,
565
+ initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
566
+ };
567
+ });
568
+ }
569
+ function getFeaturesFromProduct(product) {
570
+ var _a;
571
+ return pairFeatures(product.target.configuration.features, (_a = product.initial) === null || _a === void 0 ? void 0 : _a.configuration.features);
572
+ }
573
+ function getFeaturesFromOption(option) {
574
+ var _a;
575
+ return pairFeatures(option.target.features, (_a = option.initial) === null || _a === void 0 ? void 0 : _a.features);
576
+ }
@@ -16,7 +16,7 @@ export declare class _TaskHandlerInternal {
16
16
  readonly changeObservable: Observable<TasksChangeNotification>;
17
17
  readonly tasks: Task<RenderOrExportFormat>[];
18
18
  constructor(api: CatalogueAPI);
19
- _notifyAllOfChange: () => Promise<void>;
19
+ _notifyAllOfChange: () => void;
20
20
  destroy: () => void;
21
21
  get hasExport(): boolean;
22
22
  get hasRender(): boolean;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Observable } from "@configura/web-utilities";
10
+ import { augmentErrorMessage, Observable } from "@configura/web-utilities";
11
11
  import { exportFormatNames, renderFormatNames, } from "../CatalogueAPI.js";
12
12
  import { isExportFormat, isRenderFormat } from "./formats.js";
13
13
  const productToParams = (product) => (Object.assign(Object.assign({ lang: product.lang }, product.catId), { partNumber: product.partNumber }));
@@ -16,10 +16,10 @@ export class _TaskHandlerInternal {
16
16
  this.api = api;
17
17
  this.changeObservable = new Observable();
18
18
  this.tasks = [];
19
- this._notifyAllOfChange = () => __awaiter(this, void 0, void 0, function* () {
19
+ this._notifyAllOfChange = () => {
20
20
  const freshRef = TaskHandler._makeNewRefFrom(this);
21
21
  this.changeObservable.notifyAll({ freshRef });
22
- });
22
+ };
23
23
  this.destroy = () => {
24
24
  this.changeObservable.stopAllListen();
25
25
  for (const task of this.tasks) {
@@ -125,7 +125,7 @@ export class Task {
125
125
  }
126
126
  catch (e) {
127
127
  this.setStatus("failed");
128
- console.error(e);
128
+ throw e;
129
129
  }
130
130
  });
131
131
  this.restart = () => __awaiter(this, void 0, void 0, function* () {
@@ -136,7 +136,7 @@ export class Task {
136
136
  }
137
137
  catch (e) {
138
138
  this.setStatus("failed");
139
- console.error(e);
139
+ throw e;
140
140
  }
141
141
  });
142
142
  this.scheduleRefresh = () => {
@@ -148,13 +148,14 @@ export class Task {
148
148
  this._modified = result.modified;
149
149
  const status = result.status;
150
150
  switch (status) {
151
- case "finished":
151
+ case "finished": {
152
152
  const url = result.url;
153
153
  if (!url) {
154
154
  throw new Error("No URL from finished task");
155
155
  }
156
156
  this._url = url;
157
157
  break;
158
+ }
158
159
  case "failed":
159
160
  break;
160
161
  case "running":
@@ -177,7 +178,7 @@ export class Task {
177
178
  this._productParams = productToParams(product);
178
179
  this._apiSelection = product.getApiSelection();
179
180
  if (getPreviewUrl !== undefined) {
180
- getPreviewUrl().then((dataUrl) => {
181
+ void getPreviewUrl().then((dataUrl) => {
181
182
  this._previewUrl = dataUrl;
182
183
  this.taskHandler._notifyAllOfChange();
183
184
  });
@@ -235,7 +236,12 @@ class TaskRender extends Task {
235
236
  }
236
237
  postInit() {
237
238
  return __awaiter(this, void 0, void 0, function* () {
238
- return (yield this.taskHandler.api.postRender(this._productParams, Object.assign(Object.assign(Object.assign({}, this._apiSelection), this.taskParams), { format: this.format, width: Math.floor(this.taskParams.width), height: Math.floor(this.taskParams.height) }))).renderStatus;
239
+ try {
240
+ return (yield this.taskHandler.api.postRender(this._productParams, Object.assign(Object.assign(Object.assign({}, this._apiSelection), this.taskParams), { format: this.format, width: Math.floor(this.taskParams.width), height: Math.floor(this.taskParams.height) }))).renderStatus;
241
+ }
242
+ catch (e) {
243
+ throw augmentErrorMessage(e, "Start render request failure");
244
+ }
239
245
  });
240
246
  }
241
247
  pollStatus() {
@@ -254,7 +260,12 @@ class TaskExport extends Task {
254
260
  }
255
261
  postInit() {
256
262
  return __awaiter(this, void 0, void 0, function* () {
257
- return (yield this.taskHandler.api.postExport(this._productParams, Object.assign(Object.assign({}, this._apiSelection), { format: this.format, preferUnzipped: true }))).exportStatus;
263
+ try {
264
+ return (yield this.taskHandler.api.postExport(this._productParams, Object.assign(Object.assign({}, this._apiSelection), { format: this.format, preferUnzipped: true }))).exportStatus;
265
+ }
266
+ catch (e) {
267
+ throw augmentErrorMessage(e, "Start export request failure");
268
+ }
258
269
  });
259
270
  }
260
271
  pollStatus() {