@configura/web-api 2.2.0-alpha.1 → 2.2.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.
Files changed (102) hide show
  1. package/.eslintrc.json +5 -5
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/CatalogueAPI.d.ts +633 -633
  5. package/dist/CatalogueAPI.js +312 -312
  6. package/dist/CfgMeasure.d.ts +32 -32
  7. package/dist/CfgMeasure.js +30 -30
  8. package/dist/CfgProduct.d.ts +359 -344
  9. package/dist/CfgProduct.js +1005 -992
  10. package/dist/CfgReferencePathHelper.d.ts +26 -26
  11. package/dist/CfgReferencePathHelper.js +26 -26
  12. package/dist/index.d.ts +24 -24
  13. package/dist/index.js +24 -24
  14. package/dist/io/CfgHistoryManager.d.ts +83 -83
  15. package/dist/io/CfgHistoryManager.js +144 -144
  16. package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -21
  17. package/dist/io/CfgHistoryToProdConfConnector.js +50 -50
  18. package/dist/io/CfgIOManager.d.ts +53 -53
  19. package/dist/io/CfgIOManager.js +134 -134
  20. package/dist/io/CfgIOProdConfConnector.d.ts +54 -54
  21. package/dist/io/CfgIOProdConfConnector.js +139 -139
  22. package/dist/io/CfgIOWarningSupplier.d.ts +3 -3
  23. package/dist/io/CfgIOWarningSupplier.js +1 -1
  24. package/dist/io/CfgObservableStateManager.d.ts +25 -25
  25. package/dist/io/CfgObservableStateManager.js +69 -69
  26. package/dist/io/CfgObservableStateToProdConfConnector.d.ts +15 -15
  27. package/dist/io/CfgObservableStateToProdConfConnector.js +17 -17
  28. package/dist/io/CfgWindowEventManager.d.ts +21 -21
  29. package/dist/io/CfgWindowEventManager.js +38 -38
  30. package/dist/io/CfgWindowMessageManager.d.ts +40 -40
  31. package/dist/io/CfgWindowMessageManager.js +91 -91
  32. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +17 -17
  33. package/dist/io/CfgWindowMessageToProdConfConnector.js +19 -19
  34. package/dist/io/index.d.ts +8 -8
  35. package/dist/io/index.js +8 -8
  36. package/dist/material/CfgMaterialMapping.d.ts +7 -7
  37. package/dist/material/CfgMaterialMapping.js +181 -181
  38. package/dist/material/CfgMtrlApplication.d.ts +18 -18
  39. package/dist/material/CfgMtrlApplication.js +43 -43
  40. package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
  41. package/dist/material/CfgMtrlApplicationSource.js +8 -8
  42. package/dist/material/CfgMtrlSource.d.ts +19 -19
  43. package/dist/material/CfgMtrlSource.js +40 -40
  44. package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
  45. package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
  46. package/dist/productConfiguration/CfgFeature.d.ts +199 -199
  47. package/dist/productConfiguration/CfgFeature.js +691 -691
  48. package/dist/productConfiguration/CfgOption.d.ts +160 -160
  49. package/dist/productConfiguration/CfgOption.js +464 -464
  50. package/dist/productConfiguration/CfgProductConfiguration.d.ts +136 -129
  51. package/dist/productConfiguration/CfgProductConfiguration.js +355 -346
  52. package/dist/productConfiguration/filters.d.ts +17 -17
  53. package/dist/productConfiguration/filters.js +141 -141
  54. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  55. package/dist/productConfiguration/productParamsGenerator.js +65 -65
  56. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
  57. package/dist/productConfiguration/utilitiesProductConfiguration.js +89 -87
  58. package/dist/productLoader.d.ts +33 -33
  59. package/dist/productLoader.js +49 -49
  60. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
  61. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
  62. package/dist/syncGroups/SyncGroupsHandler.d.ts +47 -47
  63. package/dist/syncGroups/SyncGroupsHandler.js +370 -370
  64. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
  65. package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
  66. package/dist/syncGroups/SyncGroupsState.d.ts +39 -39
  67. package/dist/syncGroups/SyncGroupsState.js +167 -167
  68. package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
  69. package/dist/syncGroups/SyncGroupsTransaction.js +589 -589
  70. package/dist/tasks/TaskHandler.d.ts +77 -77
  71. package/dist/tasks/TaskHandler.js +276 -276
  72. package/dist/tasks/formats.d.ts +4 -4
  73. package/dist/tasks/formats.js +7 -7
  74. package/dist/tests/testData/collectorForTest.d.ts +73 -73
  75. package/dist/tests/testData/collectorForTest.js +194 -194
  76. package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
  77. package/dist/tests/testData/dummyProductForTest.js +32 -32
  78. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
  79. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +282 -282
  80. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  81. package/dist/tests/testData/testDataCachedGetProduct.js +187 -187
  82. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  83. package/dist/tests/testData/testDataCachedPostValidate.js +185 -185
  84. package/dist/tests/testData/testDataConstraints.d.ts +3 -3
  85. package/dist/tests/testData/testDataConstraints.js +174 -174
  86. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
  87. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
  88. package/dist/tests/testData/testDataOptions.d.ts +12 -12
  89. package/dist/tests/testData/testDataOptions.js +60 -60
  90. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
  91. package/dist/tests/testData/testDataProductAggregatedPrice.js +189 -189
  92. package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
  93. package/dist/tests/testData/testDataUpcharge.js +121 -121
  94. package/dist/utilitiesCatalogueData.d.ts +47 -47
  95. package/dist/utilitiesCatalogueData.js +180 -180
  96. package/dist/utilitiesCataloguePermission.d.ts +38 -38
  97. package/dist/utilitiesCataloguePermission.js +79 -79
  98. package/dist/utilitiesConfiguration.d.ts +28 -28
  99. package/dist/utilitiesConfiguration.js +200 -200
  100. package/dist/utilitiesNumericValues.d.ts +24 -24
  101. package/dist/utilitiesNumericValues.js +114 -114
  102. package/package.json +3 -3
@@ -1,29 +1,29 @@
1
- import { DtoAdditionalProductConf, DtoAdditionalProductConfiguration, DtoFeatureConf, DtoProductConf, DtoSelectedOption } from "./CatalogueAPI.js";
2
- /**
3
- * @param ExtendedData Extra data, i.e. units and groupCodes
4
- * @param ProductParams What Product the conf is for, and the same for any Additional Products.
5
- * @param SyncGroupState The current sync group state
6
- */
7
- export declare enum CfgProdConfParts {
8
- NoExtra = 0,
9
- ExtendedData = 1,
10
- ProdParams = 2,
11
- SyncGroupState = 4
12
- }
13
- /** Is the newer version of product configuration */
14
- export declare const isProductConf: (value: DtoAdditionalProductConfiguration | DtoProductConf) => value is DtoAdditionalProductConf;
15
- /** Is the older version of product configuration */
16
- export declare const isAdditionalProductConfiguration: (value: DtoAdditionalProductConfiguration | DtoProductConf) => value is DtoAdditionalProductConfiguration;
17
- export declare const isDtoProductConfAdditional: (value: DtoProductConf) => value is DtoAdditionalProductConf;
18
- export declare const convertDtoProductConfToV1: (conf: DtoProductConf, silenceWarnings?: boolean) => DtoAdditionalProductConfiguration;
19
- export declare const convertDtoFeatureConfsToSelOptions: (features: DtoFeatureConf[], silenceWarnings?: boolean) => DtoSelectedOption[];
20
- /**
21
- * Serializes and compacts the configuration into a format especially suited for URLs
22
- */
23
- export declare const dtoProductConfigurationToCompactString: (conf: DtoProductConf) => string;
24
- /**
25
- * Deserializes and inflates the configuration from the compacted format
26
- */
27
- export declare const compactStringToDtoProductConf: (versionAndConf: string) => DtoProductConf;
28
- export declare const stripExtendedDataFromDtoProductConf: (conf: DtoProductConf, toStrip: CfgProdConfParts) => DtoProductConf;
1
+ import { DtoAdditionalProductConf, DtoAdditionalProductConfiguration, DtoFeatureConf, DtoProductConf, DtoSelectedOption } from "./CatalogueAPI.js";
2
+ /**
3
+ * @param ExtendedData Extra data, i.e. units and groupCodes
4
+ * @param ProductParams What Product the conf is for, and the same for any Additional Products.
5
+ * @param SyncGroupState The current sync group state
6
+ */
7
+ export declare enum CfgProdConfParts {
8
+ NoExtra = 0,
9
+ ExtendedData = 1,
10
+ ProdParams = 2,
11
+ SyncGroupState = 4
12
+ }
13
+ /** Is the newer version of product configuration */
14
+ export declare const isProductConf: (value: DtoAdditionalProductConfiguration | DtoProductConf) => value is DtoAdditionalProductConf;
15
+ /** Is the older version of product configuration */
16
+ export declare const isAdditionalProductConfiguration: (value: DtoAdditionalProductConfiguration | DtoProductConf) => value is DtoAdditionalProductConfiguration;
17
+ export declare const isDtoProductConfAdditional: (value: DtoProductConf) => value is DtoAdditionalProductConf;
18
+ export declare const convertDtoProductConfToV1: (conf: DtoProductConf, silenceWarnings?: boolean) => DtoAdditionalProductConfiguration;
19
+ export declare const convertDtoFeatureConfsToSelOptions: (features: DtoFeatureConf[], silenceWarnings?: boolean) => DtoSelectedOption[];
20
+ /**
21
+ * Serializes and compacts the configuration into a format especially suited for URLs
22
+ */
23
+ export declare const dtoProductConfigurationToCompactString: (conf: DtoProductConf) => string;
24
+ /**
25
+ * Deserializes and inflates the configuration from the compacted format
26
+ */
27
+ export declare const compactStringToDtoProductConf: (versionAndConf: string) => DtoProductConf;
28
+ export declare const stripExtendedDataFromDtoProductConf: (conf: DtoProductConf, toStrip: CfgProdConfParts) => DtoProductConf;
29
29
  //# sourceMappingURL=utilitiesConfiguration.d.ts.map
@@ -1,200 +1,200 @@
1
- /**
2
- * @param ExtendedData Extra data, i.e. units and groupCodes
3
- * @param ProductParams What Product the conf is for, and the same for any Additional Products.
4
- * @param SyncGroupState The current sync group state
5
- */
6
- export var CfgProdConfParts;
7
- (function (CfgProdConfParts) {
8
- CfgProdConfParts[CfgProdConfParts["NoExtra"] = 0] = "NoExtra";
9
- CfgProdConfParts[CfgProdConfParts["ExtendedData"] = 1] = "ExtendedData";
10
- CfgProdConfParts[CfgProdConfParts["ProdParams"] = 2] = "ProdParams";
11
- CfgProdConfParts[CfgProdConfParts["SyncGroupState"] = 4] = "SyncGroupState";
12
- })(CfgProdConfParts || (CfgProdConfParts = {}));
13
- /** Is the newer version of product configuration */
14
- export const isProductConf = (value) => !("selOptions" in value);
15
- /** Is the older version of product configuration */
16
- export const isAdditionalProductConfiguration = (value) => "selOptions" in value;
17
- export const isDtoProductConfAdditional = (value) => "refKey" in value;
18
- // As this has potential to flood the terminal we only inform once
19
- let hasInformedAboutProdParams = false;
20
- let hasInformedAboutGroupCode = false;
21
- let hasInformedAboutUnit = false;
22
- export const convertDtoProductConfToV1 = (conf, silenceWarnings = false) => {
23
- var _a, _b;
24
- if (!silenceWarnings && conf.prodParams !== undefined && !hasInformedAboutProdParams) {
25
- hasInformedAboutProdParams = true;
26
- console.info("Incoming DtoProductConf contains prodParams. These will be ignored.");
27
- }
28
- const result = {
29
- selOptions: ((_a = conf.features) !== null && _a !== void 0 ? _a : []).map((f) => ({
30
- code: "!~!",
31
- next: convertDtoFeatureConfToApiSelection(f, silenceWarnings),
32
- })),
33
- additionalProducts: ((_b = conf.additionalProducts) !== null && _b !== void 0 ? _b : []).map((p) => convertDtoProductConfToV1(p, silenceWarnings)),
34
- selected: true,
35
- };
36
- if (isDtoProductConfAdditional(conf)) {
37
- result.refKey = conf.refKey;
38
- result.selected = conf.selected;
39
- }
40
- return result;
41
- };
42
- export const convertDtoFeatureConfsToSelOptions = (features, silenceWarnings = false) => (features !== null && features !== void 0 ? features : []).map((f) => ({
43
- code: "!~!",
44
- next: convertDtoFeatureConfToApiSelection(f, silenceWarnings),
45
- }));
46
- const convertDtoFeatureConfToApiSelection = (feature, silenceWarnings) => {
47
- const { groupCode, options, unit } = feature;
48
- if (!silenceWarnings && groupCode !== undefined && !hasInformedAboutGroupCode) {
49
- hasInformedAboutGroupCode = true;
50
- console.info("Incoming DtoFeature contains groupCode. It will be ignored.");
51
- }
52
- if (!silenceWarnings && unit !== undefined && !hasInformedAboutUnit) {
53
- hasInformedAboutUnit = true;
54
- console.info("Incoming DtoFeature contains a unit. It will be ignored.");
55
- }
56
- const result = {};
57
- for (const option of (options !== null && options !== void 0 ? options : []).filter((o) => o.selected)) {
58
- result[option.code] = convertDtoOptionConfToSelectedOption(option, silenceWarnings);
59
- }
60
- return result;
61
- };
62
- const convertDtoOptionConfToSelectedOption = (option, silenceWarnings) => {
63
- const { features, code, numericValue } = option;
64
- const selectionTrees = (features !== null && features !== void 0 ? features : []).map((f) => convertDtoFeatureConfToApiSelection(f, silenceWarnings));
65
- const mergedSelectionTree = {};
66
- let anyItems = false;
67
- for (const selectionTree of selectionTrees) {
68
- if (selectionTree === undefined) {
69
- continue;
70
- }
71
- for (const key of Object.keys(selectionTree)) {
72
- if (mergedSelectionTree[key] !== undefined) {
73
- console.warn(`The key (${key}) is already used in the selection tree. Option code: "${code}".`);
74
- continue;
75
- }
76
- mergedSelectionTree[key] = selectionTree[key];
77
- anyItems = true;
78
- }
79
- }
80
- const selectedOption = {
81
- code,
82
- numericValue,
83
- };
84
- if (anyItems) {
85
- selectedOption.next = mergedSelectionTree;
86
- }
87
- return selectedOption;
88
- };
89
- const versionedRegex = /^v(\d+)(.+)$/;
90
- const jsonKeyRegex = /"([^"]+)":/g;
91
- const swapForUrlAdaptedRegex = /[-~_{}"]/g;
92
- const shortToLong = new Map();
93
- const longToShort = new Map();
94
- // The replacement scheme here assumes this will only be used for keys
95
- // in DtoProductConf and the knowledge that it contains no one
96
- // one char keys.
97
- for (const [long, short] of [
98
- ["configuration", "c"],
99
- ["additionalProducts", "a"],
100
- ["prodParams", "p"],
101
- ["refKey", "r"],
102
- ["selected", "s"],
103
- ["features", "f"],
104
- ["code", "d"],
105
- ["options", "o"],
106
- ["numericValue", "n"],
107
- ["groupCode", "g"],
108
- ["unit", "u"],
109
- ["syncGroupState", "sgs"],
110
- ["selectOne", "so"],
111
- ["selectMany", "sm"],
112
- ["syncCode", "sc"],
113
- ["optionCode", "oc"],
114
- ]) {
115
- shortToLong.set(short, long);
116
- longToShort.set(long, short);
117
- }
118
- /**
119
- * As certain chars are abundant in JSON but less abundant in the actual data
120
- * we swap these so that frequent characters do not need to be URL-encoded.
121
- */
122
- const jsonStringSwapCharsForUrl = (data) => data.replace(swapForUrlAdaptedRegex, (char) => {
123
- switch (char) {
124
- case "{":
125
- return "~";
126
- case "}":
127
- return "-";
128
- case '"':
129
- return "_";
130
- case "~":
131
- return "{";
132
- case "-":
133
- return "}";
134
- case "_":
135
- return '"';
136
- default:
137
- throw new Error(`Unexpected char "${char}" in swap for URL`);
138
- }
139
- });
140
- const compactDtoProductConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = longToShort.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
141
- const expandDtoProductConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = shortToLong.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
142
- /**
143
- * Serializes and compacts the configuration into a format especially suited for URLs
144
- */
145
- export const dtoProductConfigurationToCompactString = (conf) => "v1" +
146
- jsonStringSwapCharsForUrl(compactDtoProductConfJsonKeys(JSON.stringify(conf, undefined, "")));
147
- /**
148
- * Deserializes and inflates the configuration from the compacted format
149
- */
150
- export const compactStringToDtoProductConf = (versionAndConf) => {
151
- const match = versionedRegex.exec(versionAndConf);
152
- if (match === null) {
153
- throw new Error("Could not match version string");
154
- }
155
- const [, version, conf] = match;
156
- if (version !== "1") {
157
- throw new Error("Unknown packed URL version");
158
- }
159
- if (conf === "") {
160
- throw new Error("No conf found");
161
- }
162
- return JSON.parse(expandDtoProductConfJsonKeys(jsonStringSwapCharsForUrl(conf)));
163
- };
164
- export const stripExtendedDataFromDtoProductConf = (conf, toStrip) => {
165
- var _a, _b;
166
- const stripped = {
167
- features: (_a = conf.features) === null || _a === void 0 ? void 0 : _a.map((f) => stripExtendedDataFromDtoFeatureConf(f, toStrip)),
168
- additionalProducts: (_b = conf.additionalProducts) === null || _b === void 0 ? void 0 : _b.map(stripExtendedDataFromDtoAdditionalProductConfiguration),
169
- };
170
- if ((toStrip & CfgProdConfParts.SyncGroupState) !== CfgProdConfParts.SyncGroupState) {
171
- stripped.syncGroupState = conf.syncGroupState;
172
- }
173
- if ((toStrip & CfgProdConfParts.ProdParams) !== CfgProdConfParts.ProdParams) {
174
- stripped.prodParams = conf.prodParams;
175
- }
176
- return stripped;
177
- };
178
- const stripExtendedDataFromDtoAdditionalProductConfiguration = (conf, toStrip) => (Object.assign(Object.assign({}, stripExtendedDataFromDtoProductConf(conf, toStrip)), { refKey: conf.refKey, selected: conf.selected }));
179
- const stripExtendedDataFromDtoFeatureConf = (conf, toStrip) => {
180
- var _a;
181
- const stripped = {
182
- code: conf.code,
183
- options: (_a = conf.options) === null || _a === void 0 ? void 0 : _a.map((o) => stripExtendedDataFromDtoOptionConf(o, toStrip)),
184
- };
185
- if ((toStrip & CfgProdConfParts.ExtendedData) !== CfgProdConfParts.ExtendedData) {
186
- // Keep in sync with getDtoConf in CfgFeature
187
- stripped.groupCode = conf.groupCode;
188
- stripped.unit = conf.unit;
189
- }
190
- return stripped;
191
- };
192
- const stripExtendedDataFromDtoOptionConf = (conf, toStrip) => {
193
- var _a;
194
- return ({
195
- code: conf.code,
196
- selected: conf.selected,
197
- numericValue: conf.numericValue,
198
- features: (_a = conf.features) === null || _a === void 0 ? void 0 : _a.map((f) => stripExtendedDataFromDtoFeatureConf(f, toStrip)),
199
- });
200
- };
1
+ /**
2
+ * @param ExtendedData Extra data, i.e. units and groupCodes
3
+ * @param ProductParams What Product the conf is for, and the same for any Additional Products.
4
+ * @param SyncGroupState The current sync group state
5
+ */
6
+ export var CfgProdConfParts;
7
+ (function (CfgProdConfParts) {
8
+ CfgProdConfParts[CfgProdConfParts["NoExtra"] = 0] = "NoExtra";
9
+ CfgProdConfParts[CfgProdConfParts["ExtendedData"] = 1] = "ExtendedData";
10
+ CfgProdConfParts[CfgProdConfParts["ProdParams"] = 2] = "ProdParams";
11
+ CfgProdConfParts[CfgProdConfParts["SyncGroupState"] = 4] = "SyncGroupState";
12
+ })(CfgProdConfParts || (CfgProdConfParts = {}));
13
+ /** Is the newer version of product configuration */
14
+ export const isProductConf = (value) => !("selOptions" in value);
15
+ /** Is the older version of product configuration */
16
+ export const isAdditionalProductConfiguration = (value) => "selOptions" in value;
17
+ export const isDtoProductConfAdditional = (value) => "refKey" in value;
18
+ // As this has potential to flood the terminal we only inform once
19
+ let hasInformedAboutProdParams = false;
20
+ let hasInformedAboutGroupCode = false;
21
+ let hasInformedAboutUnit = false;
22
+ export const convertDtoProductConfToV1 = (conf, silenceWarnings = false) => {
23
+ var _a, _b;
24
+ if (!silenceWarnings && conf.prodParams !== undefined && !hasInformedAboutProdParams) {
25
+ hasInformedAboutProdParams = true;
26
+ console.info("Incoming DtoProductConf contains prodParams. These will be ignored.");
27
+ }
28
+ const result = {
29
+ selOptions: ((_a = conf.features) !== null && _a !== void 0 ? _a : []).map((f) => ({
30
+ code: "!~!",
31
+ next: convertDtoFeatureConfToApiSelection(f, silenceWarnings),
32
+ })),
33
+ additionalProducts: ((_b = conf.additionalProducts) !== null && _b !== void 0 ? _b : []).map((p) => convertDtoProductConfToV1(p, silenceWarnings)),
34
+ selected: true,
35
+ };
36
+ if (isDtoProductConfAdditional(conf)) {
37
+ result.refKey = conf.refKey;
38
+ result.selected = conf.selected;
39
+ }
40
+ return result;
41
+ };
42
+ export const convertDtoFeatureConfsToSelOptions = (features, silenceWarnings = false) => (features !== null && features !== void 0 ? features : []).map((f) => ({
43
+ code: "!~!",
44
+ next: convertDtoFeatureConfToApiSelection(f, silenceWarnings),
45
+ }));
46
+ const convertDtoFeatureConfToApiSelection = (feature, silenceWarnings) => {
47
+ const { groupCode, options, unit } = feature;
48
+ if (!silenceWarnings && groupCode !== undefined && !hasInformedAboutGroupCode) {
49
+ hasInformedAboutGroupCode = true;
50
+ console.info("Incoming DtoFeature contains groupCode. It will be ignored.");
51
+ }
52
+ if (!silenceWarnings && unit !== undefined && !hasInformedAboutUnit) {
53
+ hasInformedAboutUnit = true;
54
+ console.info("Incoming DtoFeature contains a unit. It will be ignored.");
55
+ }
56
+ const result = {};
57
+ for (const option of (options !== null && options !== void 0 ? options : []).filter((o) => o.selected)) {
58
+ result[option.code] = convertDtoOptionConfToSelectedOption(option, silenceWarnings);
59
+ }
60
+ return result;
61
+ };
62
+ const convertDtoOptionConfToSelectedOption = (option, silenceWarnings) => {
63
+ const { features, code, numericValue } = option;
64
+ const selectionTrees = (features !== null && features !== void 0 ? features : []).map((f) => convertDtoFeatureConfToApiSelection(f, silenceWarnings));
65
+ const mergedSelectionTree = {};
66
+ let anyItems = false;
67
+ for (const selectionTree of selectionTrees) {
68
+ if (selectionTree === undefined) {
69
+ continue;
70
+ }
71
+ for (const key of Object.keys(selectionTree)) {
72
+ if (mergedSelectionTree[key] !== undefined) {
73
+ console.warn(`The key (${key}) is already used in the selection tree. Option code: "${code}".`);
74
+ continue;
75
+ }
76
+ mergedSelectionTree[key] = selectionTree[key];
77
+ anyItems = true;
78
+ }
79
+ }
80
+ const selectedOption = {
81
+ code,
82
+ numericValue,
83
+ };
84
+ if (anyItems) {
85
+ selectedOption.next = mergedSelectionTree;
86
+ }
87
+ return selectedOption;
88
+ };
89
+ const versionedRegex = /^v(\d+)(.+)$/;
90
+ const jsonKeyRegex = /"([^"]+)":/g;
91
+ const swapForUrlAdaptedRegex = /[-~_{}"]/g;
92
+ const shortToLong = new Map();
93
+ const longToShort = new Map();
94
+ // The replacement scheme here assumes this will only be used for keys
95
+ // in DtoProductConf and the knowledge that it contains no one
96
+ // one char keys.
97
+ for (const [long, short] of [
98
+ ["configuration", "c"],
99
+ ["additionalProducts", "a"],
100
+ ["prodParams", "p"],
101
+ ["refKey", "r"],
102
+ ["selected", "s"],
103
+ ["features", "f"],
104
+ ["code", "d"],
105
+ ["options", "o"],
106
+ ["numericValue", "n"],
107
+ ["groupCode", "g"],
108
+ ["unit", "u"],
109
+ ["syncGroupState", "sgs"],
110
+ ["selectOne", "so"],
111
+ ["selectMany", "sm"],
112
+ ["syncCode", "sc"],
113
+ ["optionCode", "oc"],
114
+ ]) {
115
+ shortToLong.set(short, long);
116
+ longToShort.set(long, short);
117
+ }
118
+ /**
119
+ * As certain chars are abundant in JSON but less abundant in the actual data
120
+ * we swap these so that frequent characters do not need to be URL-encoded.
121
+ */
122
+ const jsonStringSwapCharsForUrl = (data) => data.replace(swapForUrlAdaptedRegex, (char) => {
123
+ switch (char) {
124
+ case "{":
125
+ return "~";
126
+ case "}":
127
+ return "-";
128
+ case '"':
129
+ return "_";
130
+ case "~":
131
+ return "{";
132
+ case "-":
133
+ return "}";
134
+ case "_":
135
+ return '"';
136
+ default:
137
+ throw new Error(`Unexpected char "${char}" in swap for URL`);
138
+ }
139
+ });
140
+ const compactDtoProductConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = longToShort.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
141
+ const expandDtoProductConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = shortToLong.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
142
+ /**
143
+ * Serializes and compacts the configuration into a format especially suited for URLs
144
+ */
145
+ export const dtoProductConfigurationToCompactString = (conf) => "v1" +
146
+ jsonStringSwapCharsForUrl(compactDtoProductConfJsonKeys(JSON.stringify(conf, undefined, "")));
147
+ /**
148
+ * Deserializes and inflates the configuration from the compacted format
149
+ */
150
+ export const compactStringToDtoProductConf = (versionAndConf) => {
151
+ const match = versionedRegex.exec(versionAndConf);
152
+ if (match === null) {
153
+ throw new Error("Could not match version string");
154
+ }
155
+ const [, version, conf] = match;
156
+ if (version !== "1") {
157
+ throw new Error("Unknown packed URL version");
158
+ }
159
+ if (conf === "") {
160
+ throw new Error("No conf found");
161
+ }
162
+ return JSON.parse(expandDtoProductConfJsonKeys(jsonStringSwapCharsForUrl(conf)));
163
+ };
164
+ export const stripExtendedDataFromDtoProductConf = (conf, toStrip) => {
165
+ var _a, _b;
166
+ const stripped = {
167
+ features: (_a = conf.features) === null || _a === void 0 ? void 0 : _a.map((f) => stripExtendedDataFromDtoFeatureConf(f, toStrip)),
168
+ additionalProducts: (_b = conf.additionalProducts) === null || _b === void 0 ? void 0 : _b.map(stripExtendedDataFromDtoAdditionalProductConfiguration),
169
+ };
170
+ if ((toStrip & CfgProdConfParts.SyncGroupState) !== CfgProdConfParts.SyncGroupState) {
171
+ stripped.syncGroupState = conf.syncGroupState;
172
+ }
173
+ if ((toStrip & CfgProdConfParts.ProdParams) !== CfgProdConfParts.ProdParams) {
174
+ stripped.prodParams = conf.prodParams;
175
+ }
176
+ return stripped;
177
+ };
178
+ const stripExtendedDataFromDtoAdditionalProductConfiguration = (conf, toStrip) => (Object.assign(Object.assign({}, stripExtendedDataFromDtoProductConf(conf, toStrip)), { refKey: conf.refKey, selected: conf.selected }));
179
+ const stripExtendedDataFromDtoFeatureConf = (conf, toStrip) => {
180
+ var _a;
181
+ const stripped = {
182
+ code: conf.code,
183
+ options: (_a = conf.options) === null || _a === void 0 ? void 0 : _a.map((o) => stripExtendedDataFromDtoOptionConf(o, toStrip)),
184
+ };
185
+ if ((toStrip & CfgProdConfParts.ExtendedData) !== CfgProdConfParts.ExtendedData) {
186
+ // Keep in sync with getDtoConf in CfgFeature
187
+ stripped.groupCode = conf.groupCode;
188
+ stripped.unit = conf.unit;
189
+ }
190
+ return stripped;
191
+ };
192
+ const stripExtendedDataFromDtoOptionConf = (conf, toStrip) => {
193
+ var _a;
194
+ return ({
195
+ code: conf.code,
196
+ selected: conf.selected,
197
+ numericValue: conf.numericValue,
198
+ features: (_a = conf.features) === null || _a === void 0 ? void 0 : _a.map((f) => stripExtendedDataFromDtoFeatureConf(f, toStrip)),
199
+ });
200
+ };
@@ -1,25 +1,25 @@
1
- import { DtoCodeRange } from "./CatalogueAPI.js";
2
- export declare class NumericValuesSelection {
3
- constructor(rawRanges: DtoCodeRange[]);
4
- readonly ranges: (NumericValueRangeDefinition | NumericValueDiscrete)[];
5
- includesValue(value: number): boolean;
6
- get first(): number;
7
- get legend(): string;
8
- }
9
- export declare class NumericValueDiscrete {
10
- readonly value: number;
11
- constructor(value: number);
12
- includesValue(value: number): boolean;
13
- get first(): number;
14
- get legend(): string;
15
- }
16
- export declare class NumericValueRangeDefinition {
17
- constructor(rawRange: DtoCodeRange);
18
- readonly minValue: number;
19
- readonly maxValue: number;
20
- readonly increment: number | undefined;
21
- includesValue(value: number): boolean;
22
- get first(): number;
23
- get legend(): string;
24
- }
1
+ import { DtoCodeRange } from "./CatalogueAPI.js";
2
+ export declare class NumericValuesSelection {
3
+ constructor(rawRanges: DtoCodeRange[]);
4
+ readonly ranges: (NumericValueRangeDefinition | NumericValueDiscrete)[];
5
+ includesValue(value: number): boolean;
6
+ get first(): number;
7
+ get legend(): string;
8
+ }
9
+ export declare class NumericValueDiscrete {
10
+ readonly value: number;
11
+ constructor(value: number);
12
+ includesValue(value: number): boolean;
13
+ get first(): number;
14
+ get legend(): string;
15
+ }
16
+ export declare class NumericValueRangeDefinition {
17
+ constructor(rawRange: DtoCodeRange);
18
+ readonly minValue: number;
19
+ readonly maxValue: number;
20
+ readonly increment: number | undefined;
21
+ includesValue(value: number): boolean;
22
+ get first(): number;
23
+ get legend(): string;
24
+ }
25
25
  //# sourceMappingURL=utilitiesNumericValues.d.ts.map