@configura/web-api 1.5.0-alpha.0 → 1.6.1-alpha.0

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 (42) hide show
  1. package/dist/CatalogueAPI.d.ts +9 -2
  2. package/dist/CatalogueAPI.js +23 -0
  3. package/dist/CfgMeasure.d.ts +2 -2
  4. package/dist/CfgMeasure.js +1 -1
  5. package/dist/CfgProduct.d.ts +50 -4
  6. package/dist/CfgProduct.js +151 -17
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +2 -0
  9. package/dist/productConfiguration/CfgFeature.d.ts +19 -2
  10. package/dist/productConfiguration/CfgFeature.js +57 -6
  11. package/dist/productConfiguration/CfgOption.d.ts +12 -1
  12. package/dist/productConfiguration/CfgOption.js +29 -2
  13. package/dist/productConfiguration/CfgProductConfiguration.d.ts +4 -2
  14. package/dist/productConfiguration/CfgProductConfiguration.js +17 -0
  15. package/dist/productLoader.d.ts +1 -1
  16. package/dist/syncGroups/SyncGroupsApplier.d.ts +20 -0
  17. package/dist/syncGroups/SyncGroupsApplier.js +519 -0
  18. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +15 -0
  19. package/dist/syncGroups/SyncGroupsApplyMode.js +15 -0
  20. package/dist/syncGroups/SyncGroupsHandler.d.ts +30 -0
  21. package/dist/syncGroups/SyncGroupsHandler.js +71 -0
  22. package/dist/syncGroups/SyncGroupsState.d.ts +20 -0
  23. package/dist/syncGroups/SyncGroupsState.js +61 -0
  24. package/dist/syncGroups/SyncGroupsTransaction.d.ts +50 -0
  25. package/dist/syncGroups/SyncGroupsTransaction.js +106 -0
  26. package/dist/tasks/TaskHandler.js +4 -3
  27. package/dist/tasks/formats.d.ts +1 -3
  28. package/dist/tasks/formats.js +3 -4
  29. package/dist/tests/testData/dummyProductForTest.d.ts +2 -2
  30. package/dist/tests/testData/dummyProductForTest.js +1 -1
  31. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +3 -3
  32. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +27 -98
  33. package/dist/tests/testData/testDataCachedGetProduct.js +8 -19
  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.d.ts +3 -3
  37. package/dist/tests/testData/testDataProductAggregatedPrice.js +14 -25
  38. package/dist/tests/testData/testDataUpcharge.js +16 -48
  39. package/dist/utilitiesCatalogueData.d.ts +7 -1
  40. package/dist/utilitiesCatalogueData.js +102 -0
  41. package/dist/utilitiesNumericValues.d.ts +1 -1
  42. package/package.json +3 -3
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Is used to keep track of the current value of the SyncGroups. Is fully separated between
3
+ * SelectOne and SelectMany as Features of the two types are synced separately.
4
+ */
5
+ export class SyncGroupsState {
6
+ constructor() {
7
+ this._selectOne = new Map();
8
+ this._selectMany = new Map();
9
+ }
10
+ clone() {
11
+ const result = new SyncGroupsState();
12
+ result.setFrom(this);
13
+ return result;
14
+ }
15
+ /**
16
+ * Replaces the current state
17
+ */
18
+ setFrom(other) {
19
+ this._selectOne.clear();
20
+ this._selectMany.clear();
21
+ for (const [k, v] of other._selectOne) {
22
+ this._selectOne.set(k, v);
23
+ }
24
+ for (const [sourceSyncCode, sourceOptionToSelected] of other._selectMany) {
25
+ const targetOptionToSelected = new Map();
26
+ for (const [sourceOptionCode, sourceIsSelected] of sourceOptionToSelected) {
27
+ targetOptionToSelected.set(sourceOptionCode, sourceIsSelected);
28
+ }
29
+ this._selectMany.set(sourceSyncCode, targetOptionToSelected);
30
+ }
31
+ }
32
+ setForSelectOne(syncCode, optionCode) {
33
+ this._selectOne.set(syncCode, optionCode);
34
+ this.logDebug();
35
+ }
36
+ setForSelectMany(syncCode, optionCode, selected) {
37
+ let forSyncCode = this._selectMany.get(syncCode);
38
+ if (forSyncCode === undefined) {
39
+ forSyncCode = new Map();
40
+ this._selectMany.set(syncCode, forSyncCode);
41
+ }
42
+ forSyncCode.set(optionCode, selected);
43
+ this.logDebug();
44
+ }
45
+ getForSelectOne(syncCode) {
46
+ return this._selectOne.get(syncCode);
47
+ }
48
+ getForSelectMany(syncCode, optionCode) {
49
+ var _a;
50
+ return (_a = this._selectMany.get(syncCode)) === null || _a === void 0 ? void 0 : _a.get(optionCode);
51
+ }
52
+ logDebug() {
53
+ console.table(Array.from(this._selectOne.entries()));
54
+ console.table(Array.from(this._selectMany.entries()).reduce((a, [groupCode, optionCodeToSelected]) => {
55
+ for (const [optionCode, selected] of optionCodeToSelected) {
56
+ a.push([groupCode, optionCode, selected]);
57
+ }
58
+ return a;
59
+ }, []));
60
+ }
61
+ }
@@ -0,0 +1,50 @@
1
+ import { CfgPath, _CfgProductInternal } from "../CfgProduct.js";
2
+ import { _CfgFeatureInternal } from "../productConfiguration/CfgFeature.js";
3
+ import { _CfgOptionInternal } from "../productConfiguration/CfgOption.js";
4
+ import { ProductLoader } from "../productLoader.js";
5
+ import { SyncGroupsApplyMode } from "./SyncGroupsApplyMode.js";
6
+ import { OptionCode, SyncCode } from "./SyncGroupsHandler.js";
7
+ import { SyncGroupsState } from "./SyncGroupsState.js";
8
+ /**
9
+ * A transaction is normally limited to one user interaction. Like opening a product or
10
+ * selecting an option. This object is used to keep data for one transaction. In particular
11
+ * what Features and what SyncGroups have been affected in the transaction. This is a means
12
+ * to eliminate the risk of infinite loops.
13
+ */
14
+ export declare class SyncGroupsTransaction {
15
+ readonly syncState: SyncGroupsState;
16
+ readonly updateMode: SyncGroupsApplyMode;
17
+ readonly productLoader: ProductLoader;
18
+ readonly original: _CfgProductInternal;
19
+ readonly target: _CfgProductInternal;
20
+ readonly initial: _CfgProductInternal | undefined;
21
+ static make(syncState: SyncGroupsState, updateMode: SyncGroupsApplyMode, product: _CfgProductInternal, productLoader: ProductLoader, assumeNoStartState: boolean): Promise<SyncGroupsTransaction>;
22
+ /**
23
+ *
24
+ * @param syncState A clone of the original syncState. Replaces the original syncState if nothing fails and the transaction doesn't get aborted
25
+ * @param updateMode
26
+ * @param productLoader
27
+ * @param original The product instance that this transaction will be applied on provided nothing fails and the transaction doesn't get aborted
28
+ * @param target A clone of the original product used to apply the configuration changes to
29
+ * @param initial A clone of the original product used to track what the original state was. As a safe measure we do not use originalProduct for this, as it might be changed by someone else
30
+ */
31
+ private constructor();
32
+ private _aborted;
33
+ private affectedSelectOneFeatures;
34
+ private affectedSelectManyOptions;
35
+ private affectedSelectOneSyncGroups;
36
+ private affectedSelectManySyncGroupsAndOptions;
37
+ get isAborted(): boolean;
38
+ abort(): void;
39
+ init(): Promise<boolean>;
40
+ selectOption(optionPath: CfgPath, on: boolean): Promise<boolean>;
41
+ addSelectOneFeatureAffected(feature: _CfgFeatureInternal): void;
42
+ addSelectManyOptionAffected(option: _CfgOptionInternal): void;
43
+ hasSelectOneFeatureBeenAffected(feature: _CfgFeatureInternal): boolean;
44
+ hasSelectManyOptionBeenAffected(option: _CfgOptionInternal): boolean;
45
+ addSyncGroupAffectedForSelectOne(syncCode: SyncCode): void;
46
+ addSyncGroupAffectedForSelectMany(syncCode: SyncCode, optionCode: OptionCode): void;
47
+ isSyncGroupAffectedForSelectOne(syncCode: SyncCode): boolean;
48
+ isSyncGroupAffectedForSelectMany(syncCode: SyncCode, optionCode: OptionCode): boolean;
49
+ }
50
+ //# sourceMappingURL=SyncGroupsTransaction.d.ts.map
@@ -0,0 +1,106 @@
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 { SelectionType } from "../productConfiguration/CfgFeature.js";
11
+ import { SyncGroupsApplier } from "./SyncGroupsApplier.js";
12
+ /**
13
+ * A transaction is normally limited to one user interaction. Like opening a product or
14
+ * selecting an option. This object is used to keep data for one transaction. In particular
15
+ * what Features and what SyncGroups have been affected in the transaction. This is a means
16
+ * to eliminate the risk of infinite loops.
17
+ */
18
+ export class SyncGroupsTransaction {
19
+ /**
20
+ *
21
+ * @param syncState A clone of the original syncState. Replaces the original syncState if nothing fails and the transaction doesn't get aborted
22
+ * @param updateMode
23
+ * @param productLoader
24
+ * @param original The product instance that this transaction will be applied on provided nothing fails and the transaction doesn't get aborted
25
+ * @param target A clone of the original product used to apply the configuration changes to
26
+ * @param initial A clone of the original product used to track what the original state was. As a safe measure we do not use originalProduct for this, as it might be changed by someone else
27
+ */
28
+ constructor(syncState, updateMode, productLoader, original, target, initial) {
29
+ this.syncState = syncState;
30
+ this.updateMode = updateMode;
31
+ this.productLoader = productLoader;
32
+ this.original = original;
33
+ this.target = target;
34
+ this.initial = initial;
35
+ this._aborted = false;
36
+ this.affectedSelectOneFeatures = new Set();
37
+ this.affectedSelectManyOptions = new Set();
38
+ this.affectedSelectOneSyncGroups = new Set();
39
+ this.affectedSelectManySyncGroupsAndOptions = new Map();
40
+ }
41
+ static make(syncState, updateMode, product, productLoader, assumeNoStartState) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const t = new this(syncState.clone(), updateMode, productLoader, product, yield product.clone(), assumeNoStartState ? undefined : yield product.clone());
44
+ return t;
45
+ });
46
+ }
47
+ get isAborted() {
48
+ return this._aborted;
49
+ }
50
+ abort() {
51
+ this._aborted = true;
52
+ }
53
+ init() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ return yield SyncGroupsApplier.init(this);
56
+ });
57
+ }
58
+ selectOption(optionPath, on) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const targetOption = this.target.getOptionFromPath(optionPath);
61
+ return yield SyncGroupsApplier.selectOption(this, targetOption, on);
62
+ });
63
+ }
64
+ addSelectOneFeatureAffected(feature) {
65
+ if (feature.selectionType !== SelectionType.SelectOne) {
66
+ throw new Error("Can only be used for SelectOne Feature");
67
+ }
68
+ this.affectedSelectOneFeatures.add(feature);
69
+ }
70
+ addSelectManyOptionAffected(option) {
71
+ if (option.parent.selectionType !== SelectionType.SelectMany) {
72
+ throw new Error("Can only be used for option in SelectMany Feature");
73
+ }
74
+ this.affectedSelectManyOptions.add(option);
75
+ }
76
+ hasSelectOneFeatureBeenAffected(feature) {
77
+ if (feature.selectionType !== SelectionType.SelectOne) {
78
+ throw new Error("Can only be used for SelectOne Feature");
79
+ }
80
+ return this.affectedSelectOneFeatures.has(feature);
81
+ }
82
+ hasSelectManyOptionBeenAffected(option) {
83
+ if (option.parent.selectionType !== SelectionType.SelectMany) {
84
+ throw new Error("Can only be used for option in SelectMany Feature");
85
+ }
86
+ return this.affectedSelectManyOptions.has(option);
87
+ }
88
+ addSyncGroupAffectedForSelectOne(syncCode) {
89
+ this.affectedSelectOneSyncGroups.add(syncCode);
90
+ }
91
+ addSyncGroupAffectedForSelectMany(syncCode, optionCode) {
92
+ let forSyncCode = this.affectedSelectManySyncGroupsAndOptions.get(syncCode);
93
+ if (forSyncCode === undefined) {
94
+ forSyncCode = new Set();
95
+ this.affectedSelectManySyncGroupsAndOptions.set(syncCode, forSyncCode);
96
+ }
97
+ forSyncCode.add(optionCode);
98
+ }
99
+ isSyncGroupAffectedForSelectOne(syncCode) {
100
+ return this.affectedSelectOneSyncGroups.has(syncCode);
101
+ }
102
+ isSyncGroupAffectedForSelectMany(syncCode, optionCode) {
103
+ var _a;
104
+ return ((_a = this.affectedSelectManySyncGroupsAndOptions.get(syncCode)) === null || _a === void 0 ? void 0 : _a.has(optionCode)) === true;
105
+ }
106
+ }
@@ -8,7 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { Observable } from "@configura/web-utilities";
11
- import { allExportFormats, allRenderFormats, isExportFormat, isRenderFormat, } from "./formats.js";
11
+ import { exportFormatNames, renderFormatNames, } from "../CatalogueAPI.js";
12
+ import { isExportFormat, isRenderFormat } from "./formats.js";
12
13
  const productToParams = (product) => (Object.assign(Object.assign({ lang: product.lang }, product.catId), { partNumber: product.partNumber }));
13
14
  export class _TaskHandlerInternal {
14
15
  constructor(api) {
@@ -55,10 +56,10 @@ export class _TaskHandlerInternal {
55
56
  get availableFormats() {
56
57
  const result = [];
57
58
  if (this.hasExport) {
58
- result.push(...allExportFormats);
59
+ result.push(...exportFormatNames);
59
60
  }
60
61
  if (this.hasRender) {
61
- result.push(...allRenderFormats);
62
+ result.push(...renderFormatNames);
62
63
  }
63
64
  return result;
64
65
  }
@@ -1,6 +1,4 @@
1
- import { ExportFormat, RenderFormat } from "../CatalogueAPI";
2
- export declare const allRenderFormats: RenderFormat[];
3
- export declare const allExportFormats: ExportFormat[];
1
+ import { ExportFormat, RenderFormat } from "../CatalogueAPI.js";
4
2
  export declare type RenderOrExportFormat = RenderFormat | ExportFormat;
5
3
  export declare function isRenderFormat(type: unknown): type is RenderFormat;
6
4
  export declare function isExportFormat(type: unknown): type is ExportFormat;
@@ -1,8 +1,7 @@
1
- export const allRenderFormats = ["jpg", "png"];
2
- export const allExportFormats = ["fbx", "dwg", "cmdrw", "cmfav", "cmsym"];
1
+ import { exportFormatNames, renderFormatNames, } from "../CatalogueAPI.js";
3
2
  export function isRenderFormat(type) {
4
- return allRenderFormats.some((f) => type === f);
3
+ return renderFormatNames.some((f) => type === f);
5
4
  }
6
5
  export function isExportFormat(type) {
7
- return allExportFormats.some((f) => type === f);
6
+ return exportFormatNames.some((f) => type === f);
8
7
  }
@@ -1,5 +1,5 @@
1
- import { CatalogueParams } from "../../CatalogueAPI";
2
- import { CfgProduct } from "../../CfgProduct";
1
+ import { CatalogueParams } from "../../CatalogueAPI.js";
2
+ import { CfgProduct } from "../../CfgProduct.js";
3
3
  export declare const dummyCatId: CatalogueParams;
4
4
  export declare const getDummyCfgProduct: () => Promise<CfgProduct>;
5
5
  //# sourceMappingURL=dummyProductForTest.d.ts.map
@@ -1,4 +1,4 @@
1
- import { CfgProduct } from "../../CfgProduct";
1
+ import { CfgProduct } from "../../CfgProduct.js";
2
2
  export const dummyCatId = {
3
3
  enterprise: "enterprise",
4
4
  prdCat: "prdCat",
@@ -1,6 +1,6 @@
1
- import { GetProductParams } from "../../CatalogueAPI";
2
- import { CfgProduct } from "../../CfgProduct";
3
- import { CfgProductResponse } from "../../utilitiesCatalogueData";
1
+ import { GetProductParams } from "../../CatalogueAPI.js";
2
+ import { CfgProduct } from "../../CfgProduct.js";
3
+ import { CfgProductResponse } from "../../utilitiesCatalogueData.js";
4
4
  export declare const getTestProduct: (params: GetProductParams) => Promise<CfgProductResponse>;
5
5
  export declare const cfgProductTest: (testFunc: (product: CfgProduct) => Promise<void>, prepFunc?: ((product: CfgProduct) => Promise<void>) | undefined) => Promise<{
6
6
  beforeSnapshot: {
@@ -7,9 +7,10 @@ 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 { CfgProduct } from "../../CfgProduct";
11
- import { Collector } from "./collectorForTest";
12
- import { dummyCatId } from "./dummyProductForTest";
10
+ import { CfgProduct } from "../../CfgProduct.js";
11
+ import { Collector } from "./collectorForTest.js";
12
+ import { dummyCatId } from "./dummyProductForTest.js";
13
+ import { letterOptionCodeA, letterOptionCodeB, letterOptionCodeC, letterOptions, } from "./testDataOptions.js";
13
14
  const A = () => ({
14
15
  uuid: "A",
15
16
  unit: "m",
@@ -19,96 +20,37 @@ const A = () => ({
19
20
  description: "",
20
21
  numericOrder: false,
21
22
  options: [
22
- {
23
- code: "optionA",
24
- description: "",
25
- additionalProductRefs: [
23
+ Object.assign(Object.assign({}, letterOptions[0]), { additionalProductRefs: [
26
24
  { refKey: "C_0", catId: dummyCatId, partNumber: "C" },
27
25
  { refKey: "B_0", catId: dummyCatId, partNumber: "B" },
28
- ],
29
- },
30
- {
31
- code: "optionB",
32
- description: "",
33
- },
34
- {
35
- code: "optionC",
36
- description: "",
37
- additionalProductRefs: [{ refKey: "D", catId: dummyCatId, partNumber: "D" }],
38
- },
26
+ ] }),
27
+ letterOptions[1],
28
+ Object.assign(Object.assign({}, letterOptions[2]), { additionalProductRefs: [{ refKey: "D", catId: dummyCatId, partNumber: "D" }] }),
39
29
  ],
40
30
  },
41
31
  {
42
32
  code: "featureX",
43
33
  description: "",
44
34
  numericOrder: false,
45
- options: [
46
- {
47
- code: "optionA",
48
- description: "",
49
- },
50
- {
51
- code: "optionB",
52
- description: "",
53
- },
54
- {
55
- code: "optionC",
56
- description: "",
57
- },
58
- ],
35
+ options: [...letterOptions],
59
36
  },
60
37
  {
61
38
  code: "featureNotUsed",
62
39
  description: "",
63
40
  numericOrder: false,
64
- options: [
65
- {
66
- code: "optionA",
67
- description: "",
68
- },
69
- {
70
- code: "optionB",
71
- description: "",
72
- },
73
- ],
41
+ options: [...letterOptions],
74
42
  },
75
43
  {
76
44
  code: "featureOptionCSelectedAtStart",
77
45
  description: "",
78
46
  numericOrder: false,
79
- options: [
80
- {
81
- code: "optionA",
82
- description: "",
83
- },
84
- {
85
- code: "optionB",
86
- description: "",
87
- },
88
- {
89
- code: "optionC",
90
- description: "",
91
- },
92
- ],
47
+ options: [...letterOptions],
93
48
  },
94
49
  {
95
50
  code: "featureSelectMany",
96
51
  description: "",
97
52
  numericOrder: false,
98
- options: [
99
- {
100
- code: "optionA",
101
- description: "",
102
- },
103
- {
104
- code: "optionB",
105
- description: "",
106
- },
107
- {
108
- code: "optionC",
109
- description: "",
110
- },
111
- ],
53
+ options: [...letterOptions],
112
54
  },
113
55
  ],
114
56
  productData: {
@@ -123,24 +65,24 @@ const A = () => ({
123
65
  {
124
66
  code: "!~!",
125
67
  next: {
126
- optionA: {
127
- code: "optionA",
68
+ [letterOptionCodeA]: {
69
+ code: letterOptionCodeA,
128
70
  },
129
71
  },
130
72
  },
131
73
  {
132
74
  code: "!~!",
133
75
  next: {
134
- optionB: {
135
- code: "optionB",
76
+ [letterOptionCodeB]: {
77
+ code: letterOptionCodeB,
136
78
  },
137
79
  },
138
80
  },
139
81
  {
140
82
  code: "!~!",
141
83
  next: {
142
- optionC: {
143
- code: "optionC",
84
+ [letterOptionCodeC]: {
85
+ code: letterOptionCodeC,
144
86
  },
145
87
  },
146
88
  },
@@ -219,20 +161,7 @@ const C = () => ({
219
161
  code: "featureC",
220
162
  description: "",
221
163
  numericOrder: false,
222
- options: [
223
- {
224
- code: "optionA",
225
- description: "",
226
- },
227
- {
228
- code: "optionB",
229
- description: "",
230
- },
231
- {
232
- code: "optionC",
233
- description: "",
234
- },
235
- ],
164
+ options: [...letterOptions],
236
165
  },
237
166
  ],
238
167
  productData: {
@@ -246,8 +175,8 @@ const C = () => ({
246
175
  {
247
176
  code: "!~!",
248
177
  next: {
249
- optionA: {
250
- code: "optionA",
178
+ [letterOptionCodeA]: {
179
+ code: letterOptionCodeA,
251
180
  },
252
181
  },
253
182
  },
@@ -297,8 +226,8 @@ export const cfgProductTest = (testFunc, prepFunc) => __awaiter(void 0, void 0,
297
226
  {
298
227
  code: "!~!",
299
228
  next: {
300
- optionC: {
301
- code: "optionC",
229
+ [letterOptionCodeC]: {
230
+ code: letterOptionCodeC,
302
231
  },
303
232
  },
304
233
  },
@@ -307,16 +236,16 @@ export const cfgProductTest = (testFunc, prepFunc) => __awaiter(void 0, void 0,
307
236
  productData.partsData.selOptions.push({
308
237
  code: "!~!",
309
238
  next: {
310
- optionC: {
311
- code: "optionC",
239
+ [letterOptionCodeC]: {
240
+ code: letterOptionCodeC,
312
241
  },
313
242
  },
314
243
  });
315
244
  productData.partsData.selOptions.push({
316
245
  code: "!~!",
317
246
  next: {
318
- optionC: {
319
- code: "optionC",
247
+ [letterOptionCodeC]: {
248
+ code: letterOptionCodeC,
320
249
  },
321
250
  },
322
251
  });
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { CfgProduct } from "../../CfgProduct.js";
11
11
  import { wrapWithGetProductCache } from "../../productLoader.js";
12
12
  import { dummyCatId } from "./dummyProductForTest.js";
13
+ import { letterOptionCodeA, letterOptions } from "./testDataOptions.js";
13
14
  let prodKeyArray = [];
14
15
  const A = () => ({
15
16
  uuid: "A",
@@ -20,24 +21,12 @@ const A = () => ({
20
21
  description: "",
21
22
  numericOrder: false,
22
23
  options: [
23
- {
24
- code: "optionA",
25
- description: "",
26
- additionalProductRefs: [
24
+ Object.assign(Object.assign({}, letterOptions[0]), { additionalProductRefs: [
27
25
  { refKey: "C_0", catId: dummyCatId, partNumber: "C" },
28
26
  { refKey: "B_0", catId: dummyCatId, partNumber: "B" },
29
- ],
30
- },
31
- {
32
- code: "optionB",
33
- description: "",
34
- additionalProductRefs: [{ refKey: "E", catId: dummyCatId, partNumber: "E" }],
35
- },
36
- {
37
- code: "optionC",
38
- description: "",
39
- additionalProductRefs: [{ refKey: "D", catId: dummyCatId, partNumber: "D" }],
40
- },
27
+ ] }),
28
+ Object.assign(Object.assign({}, letterOptions[1]), { additionalProductRefs: [{ refKey: "E", catId: dummyCatId, partNumber: "E" }] }),
29
+ Object.assign(Object.assign({}, letterOptions[2]), { additionalProductRefs: [{ refKey: "D", catId: dummyCatId, partNumber: "D" }] }),
41
30
  ],
42
31
  },
43
32
  ],
@@ -53,8 +42,8 @@ const A = () => ({
53
42
  {
54
43
  code: "!~!",
55
44
  next: {
56
- optionA: {
57
- code: "optionA",
45
+ [letterOptionCodeA]: {
46
+ code: letterOptionCodeA,
58
47
  },
59
48
  },
60
49
  },
@@ -165,7 +154,7 @@ export const cachedProductLoaderTest = () => __awaiter(void 0, void 0, void 0, f
165
154
  getProduct: getTestProduct,
166
155
  postValidate: (params, _body) => __awaiter(void 0, void 0, void 0, function* () {
167
156
  const productData = (yield getTestProduct(params, true)).productData;
168
- let code = "optionA";
157
+ let code = letterOptionCodeA;
169
158
  for (let test in _body.selOptions[0].next) {
170
159
  code = test;
171
160
  break;
@@ -0,0 +1,13 @@
1
+ import { Option, SelectedOption } from "../../CatalogueAPI.js";
2
+ export declare function addDefaultsToMockSelectedOption(root: SelectedOption, optionCodeToAdd: string | undefined, optionCodesToRemove: string[], unlessOptionCodes: string[]): void;
3
+ export declare const letterOptionCodeA = "optA";
4
+ export declare const letterOptionCodeB = "optB";
5
+ export declare const letterOptionCodeC = "optC";
6
+ export declare const letterOptionCodeD = "optD";
7
+ export declare const letterOptionCodeE = "optE";
8
+ export declare const letterOptionCodeF = "optF";
9
+ export declare const letterOptions: Option[];
10
+ export declare const toggleOptionCodeOff = "optOff";
11
+ export declare const toggleOptionCodeOn = "optOn";
12
+ export declare const toggleOptions: Option[];
13
+ //# sourceMappingURL=testDataOptions.d.ts.map
@@ -0,0 +1,60 @@
1
+ export function addDefaultsToMockSelectedOption(root, optionCodeToAdd, optionCodesToRemove, unlessOptionCodes) {
2
+ let next = root.next;
3
+ if (next === undefined) {
4
+ if (optionCodeToAdd === undefined) {
5
+ return;
6
+ }
7
+ next = {};
8
+ root.next = next;
9
+ }
10
+ for (const oCode of unlessOptionCodes) {
11
+ if (next[oCode] !== undefined) {
12
+ return;
13
+ }
14
+ }
15
+ for (const oCode of optionCodesToRemove) {
16
+ delete next[oCode];
17
+ }
18
+ if (optionCodeToAdd === undefined) {
19
+ return;
20
+ }
21
+ next[optionCodeToAdd] = { code: optionCodeToAdd };
22
+ }
23
+ export const letterOptionCodeA = "optA";
24
+ export const letterOptionCodeB = "optB";
25
+ export const letterOptionCodeC = "optC";
26
+ export const letterOptionCodeD = "optD";
27
+ export const letterOptionCodeE = "optE";
28
+ export const letterOptionCodeF = "optF";
29
+ export const letterOptions = [
30
+ {
31
+ code: letterOptionCodeA,
32
+ description: "",
33
+ },
34
+ {
35
+ code: letterOptionCodeB,
36
+ description: "",
37
+ },
38
+ {
39
+ code: letterOptionCodeC,
40
+ description: "",
41
+ },
42
+ {
43
+ code: letterOptionCodeD,
44
+ description: "",
45
+ },
46
+ {
47
+ code: letterOptionCodeE,
48
+ description: "",
49
+ },
50
+ {
51
+ code: letterOptionCodeF,
52
+ description: "",
53
+ },
54
+ ];
55
+ export const toggleOptionCodeOff = "optOff";
56
+ export const toggleOptionCodeOn = "optOn";
57
+ export const toggleOptions = [
58
+ { code: toggleOptionCodeOff, description: "" },
59
+ { code: toggleOptionCodeOn, description: "" },
60
+ ];
@@ -1,6 +1,6 @@
1
- import { GetProductParams, SelectedOption } from "../../CatalogueAPI";
2
- import { CfgProduct } from "../../CfgProduct";
3
- import { CfgProductResponse } from "../../utilitiesCatalogueData";
1
+ import { GetProductParams, SelectedOption } from "../../CatalogueAPI.js";
2
+ import { CfgProduct } from "../../CfgProduct.js";
3
+ import { CfgProductResponse } from "../../utilitiesCatalogueData.js";
4
4
  export declare const getTestProduct: (params: GetProductParams) => Promise<CfgProductResponse>;
5
5
  export declare function getSelOptions(option: string): SelectedOption[];
6
6
  export declare const cfgProductPriceTest: (testFunc?: ((cfgProduct: CfgProduct) => Promise<void>) | undefined, featureOption?: string | undefined) => Promise<CfgProduct>;