@configura/web-api 3.0.0-alpha.1 → 3.0.0-alpha.3
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/CatalogueAPI.d.ts +68 -1
- package/dist/CatalogueAPI.js +184 -219
- package/dist/CfgMeasure.js +1 -2
- package/dist/CfgProduct.d.ts +22 -3
- package/dist/CfgProduct.js +172 -162
- package/dist/io/CfgIOManager.js +2 -11
- package/dist/io/CfgIOProdConfConnector.js +14 -25
- package/dist/io/CfgObservableStateManager.js +1 -1
- package/dist/productConfiguration/CfgFeature.d.ts +5 -0
- package/dist/productConfiguration/CfgFeature.js +68 -53
- package/dist/productConfiguration/CfgOption.d.ts +8 -0
- package/dist/productConfiguration/CfgOption.js +68 -73
- package/dist/productConfiguration/CfgProductConfiguration.js +22 -34
- package/dist/productConfiguration/productParamsGenerator.js +43 -57
- package/dist/productLoader.js +2 -13
- package/dist/syncGroups/SyncGroupsHandler.js +60 -83
- package/dist/syncGroups/SyncGroupsPathHelper.js +5 -5
- package/dist/syncGroups/SyncGroupsState.js +4 -5
- package/dist/syncGroups/SyncGroupsTransaction.d.ts +19 -1
- package/dist/syncGroups/SyncGroupsTransaction.js +352 -303
- package/dist/tasks/TaskHandler.js +53 -64
- package/dist/tests/testData/dummyProductForTest.js +4 -1
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +18 -21
- package/dist/tests/testData/testDataCachedGetProduct.js +20 -20
- package/dist/tests/testData/testDataCachedPostValidate.js +6 -15
- package/dist/tests/testData/testDataProductAggregatedPrice.js +21 -21
- package/dist/tests/testData/testDataUpcharge.js +31 -22
- package/dist/utilitiesCatalogueData.js +21 -9
- package/dist/utilitiesCataloguePermission.js +5 -2
- package/dist/utilitiesConfiguration.js +21 -23
- 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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
338
|
+
this._loadingObservable?.stopChildLoading(transaction);
|
|
360
339
|
}
|
|
361
|
-
commitTransaction(transaction) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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)";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _CfgProductInternal } from "../CfgProduct.js";
|
|
2
|
+
import { _CfgOptionInternal } from "../productConfiguration/CfgOption.js";
|
|
2
3
|
import { ProductLoader } from "../productLoader.js";
|
|
3
4
|
import { SyncGroupsApplyMode } from "./SyncGroupsApplyMode.js";
|
|
4
5
|
import { CfgPath } from "./SyncGroupsPathHelper.js";
|
|
@@ -91,7 +92,7 @@ export declare class SyncGroupsTransaction {
|
|
|
91
92
|
* Apply current sync groups on those who wants to listen until there is no more to settle.
|
|
92
93
|
* @returns true if at least one Feature changed selected Option
|
|
93
94
|
*/
|
|
94
|
-
|
|
95
|
+
updateRootProduct(productToValidate: _CfgProductInternal | undefined): Promise<boolean>;
|
|
95
96
|
/**
|
|
96
97
|
* Applies the SyncState to the Product and it's AdditionalProducts (sub-products).
|
|
97
98
|
* @param productsToValidate To this all products that will need validation are added.
|
|
@@ -149,7 +150,24 @@ export declare class SyncGroupsTransaction {
|
|
|
149
150
|
private applySelectOneFeature;
|
|
150
151
|
private applySelectManyFeature;
|
|
151
152
|
private applySelectManyOption;
|
|
153
|
+
/**
|
|
154
|
+
* Applies the given diff to the transaction's sync state.
|
|
155
|
+
*/
|
|
156
|
+
applyFromDiff(diffs: _CfgOptionInternal[]): void;
|
|
157
|
+
/**
|
|
158
|
+
* Applies the new state for the given option to the transaction's sync state.
|
|
159
|
+
*/
|
|
160
|
+
private applyNewStateFor;
|
|
152
161
|
private addSyncGroupAffectedForSelectMany;
|
|
153
162
|
private hasSyncGroupAffectedForSelectMany;
|
|
154
163
|
}
|
|
164
|
+
/************************************************************************
|
|
165
|
+
* Product diffing
|
|
166
|
+
************************************************************************/
|
|
167
|
+
/**
|
|
168
|
+
* Finds all options that have changed in the new product compared to the original product.
|
|
169
|
+
*
|
|
170
|
+
* This is used to determine which options need to be updated in the sync state.
|
|
171
|
+
*/
|
|
172
|
+
export declare function generateSelectionDiff(originalProduct: _CfgProductInternal, newProduct: _CfgProductInternal): _CfgOptionInternal[] | null;
|
|
155
173
|
//# sourceMappingURL=SyncGroupsTransaction.d.ts.map
|