@configura/web-api 2.0.0-alpha.20 → 2.0.0-alpha.21

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 (100) hide show
  1. package/.eslintrc.json +5 -18
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/CatalogueAPI.d.ts +597 -581
  5. package/dist/CatalogueAPI.js +328 -328
  6. package/dist/CfgMeasure.d.ts +32 -32
  7. package/dist/CfgMeasure.js +30 -30
  8. package/dist/CfgProduct.d.ts +328 -330
  9. package/dist/CfgProduct.js +934 -879
  10. package/dist/CfgReferencePathHelper.d.ts +26 -26
  11. package/dist/CfgReferencePathHelper.js +26 -26
  12. package/dist/ConfigurationConverter.d.ts +17 -13
  13. package/dist/ConfigurationConverter.js +175 -166
  14. package/dist/index.d.ts +23 -23
  15. package/dist/index.js +23 -23
  16. package/dist/io/CfgHistoryManager.d.ts +83 -83
  17. package/dist/io/CfgHistoryManager.js +144 -150
  18. package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -17
  19. package/dist/io/CfgHistoryToProdConfConnector.js +50 -47
  20. package/dist/io/CfgIOManager.d.ts +53 -53
  21. package/dist/io/CfgIOManager.js +134 -134
  22. package/dist/io/CfgIOProdConfConnector.d.ts +64 -56
  23. package/dist/io/CfgIOProdConfConnector.js +149 -158
  24. package/dist/io/CfgIOWarningSupplier.d.ts +3 -3
  25. package/dist/io/CfgIOWarningSupplier.js +1 -1
  26. package/dist/io/CfgObservableStateManager.d.ts +25 -25
  27. package/dist/io/CfgObservableStateManager.js +69 -69
  28. package/dist/io/CfgObservableStateToProdConfConnector.d.ts +14 -14
  29. package/dist/io/CfgObservableStateToProdConfConnector.js +16 -16
  30. package/dist/io/CfgWindowEventManager.d.ts +21 -21
  31. package/dist/io/CfgWindowEventManager.js +38 -38
  32. package/dist/io/CfgWindowMessageManager.d.ts +40 -40
  33. package/dist/io/CfgWindowMessageManager.js +91 -91
  34. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +16 -16
  35. package/dist/io/CfgWindowMessageToProdConfConnector.js +18 -18
  36. package/dist/io/index.d.ts +8 -8
  37. package/dist/io/index.js +8 -8
  38. package/dist/material/CfgMaterialMapping.d.ts +7 -7
  39. package/dist/material/CfgMaterialMapping.js +181 -181
  40. package/dist/material/CfgMtrlApplication.d.ts +18 -18
  41. package/dist/material/CfgMtrlApplication.js +43 -43
  42. package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
  43. package/dist/material/CfgMtrlApplicationSource.js +8 -8
  44. package/dist/material/CfgMtrlSource.d.ts +19 -19
  45. package/dist/material/CfgMtrlSource.js +40 -40
  46. package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
  47. package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
  48. package/dist/productConfiguration/CfgFeature.d.ts +189 -189
  49. package/dist/productConfiguration/CfgFeature.js +658 -658
  50. package/dist/productConfiguration/CfgOption.d.ts +151 -151
  51. package/dist/productConfiguration/CfgOption.js +422 -422
  52. package/dist/productConfiguration/CfgProductConfiguration.d.ts +129 -129
  53. package/dist/productConfiguration/CfgProductConfiguration.js +340 -340
  54. package/dist/productConfiguration/filters.d.ts +15 -15
  55. package/dist/productConfiguration/filters.js +70 -70
  56. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  57. package/dist/productConfiguration/productParamsGenerator.js +51 -51
  58. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
  59. package/dist/productConfiguration/utilitiesProductConfiguration.js +87 -87
  60. package/dist/productLoader.d.ts +33 -33
  61. package/dist/productLoader.js +49 -49
  62. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
  63. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
  64. package/dist/syncGroups/SyncGroupsHandler.d.ts +47 -43
  65. package/dist/syncGroups/SyncGroupsHandler.js +370 -363
  66. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
  67. package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
  68. package/dist/syncGroups/SyncGroupsState.d.ts +39 -35
  69. package/dist/syncGroups/SyncGroupsState.js +167 -125
  70. package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
  71. package/dist/syncGroups/SyncGroupsTransaction.js +589 -589
  72. package/dist/tasks/TaskHandler.d.ts +77 -77
  73. package/dist/tasks/TaskHandler.js +276 -276
  74. package/dist/tasks/formats.d.ts +4 -4
  75. package/dist/tasks/formats.js +7 -7
  76. package/dist/tests/testData/collectorForTest.d.ts +73 -73
  77. package/dist/tests/testData/collectorForTest.js +194 -194
  78. package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
  79. package/dist/tests/testData/dummyProductForTest.js +32 -32
  80. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
  81. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +282 -278
  82. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  83. package/dist/tests/testData/testDataCachedGetProduct.js +187 -186
  84. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  85. package/dist/tests/testData/testDataCachedPostValidate.js +185 -184
  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 -188
  92. package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
  93. package/dist/tests/testData/testDataUpcharge.js +121 -120
  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/utilitiesNumericValues.d.ts +24 -24
  99. package/dist/utilitiesNumericValues.js +114 -109
  100. package/package.json +3 -3
@@ -1,27 +1,27 @@
1
- import { DtoCatalogueParamsWithCidAndLang, DtoProductParamsWithCidAndLang } from "./CatalogueAPI";
2
- /**
3
- * These methods aims to provide a default suggested way of building
4
- * URLs to Products and Catalogues. By using consistent URL:s copy-paste
5
- * between systems becomes easy and this can aid when debugging.
6
- * Using this format on URL is no requirement. In fact, most of our
7
- * integrators do not, as they do not expose the Catalogue-path.
8
- * Internally at Configura we try to stick with this format.
9
- */
10
- export declare class CfgReferencePathHelper {
11
- /**
12
- * Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
13
- * @param browsingRootUrl The URL where Stage browsing begins
14
- * @param catParams What catalogue to generate URL for.
15
- * @returns An URL to a catalogue
16
- */
17
- static getCataloguePath: (browsingRootUrl: string, catParams: DtoCatalogueParamsWithCidAndLang) => string;
18
- /**
19
- * Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
20
- * @param browsingRootUrl The URL where Stage browsing begins
21
- * @param productParams What product to generate URL for.
22
- * @param separator Optional, defaults to "product", but can be changed to indicate another function.
23
- * @returns An URL to a product
24
- */
25
- static getProductPath: (browsingRootUrl: string, productParams: DtoProductParamsWithCidAndLang, separator?: string) => string;
26
- }
1
+ import { DtoCatalogueParamsWithCidAndLang, DtoProductParamsWithCidAndLang } from "./CatalogueAPI";
2
+ /**
3
+ * These methods aims to provide a default suggested way of building
4
+ * URLs to Products and Catalogues. By using consistent URL:s copy-paste
5
+ * between systems becomes easy and this can aid when debugging.
6
+ * Using this format on URL is no requirement. In fact, most of our
7
+ * integrators do not, as they do not expose the Catalogue-path.
8
+ * Internally at Configura we try to stick with this format.
9
+ */
10
+ export declare class CfgReferencePathHelper {
11
+ /**
12
+ * Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
13
+ * @param browsingRootUrl The URL where Stage browsing begins
14
+ * @param catParams What catalogue to generate URL for.
15
+ * @returns An URL to a catalogue
16
+ */
17
+ static getCataloguePath: (browsingRootUrl: string, catParams: DtoCatalogueParamsWithCidAndLang) => string;
18
+ /**
19
+ * Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
20
+ * @param browsingRootUrl The URL where Stage browsing begins
21
+ * @param productParams What product to generate URL for.
22
+ * @param separator Optional, defaults to "product", but can be changed to indicate another function.
23
+ * @returns An URL to a product
24
+ */
25
+ static getProductPath: (browsingRootUrl: string, productParams: DtoProductParamsWithCidAndLang, separator?: string) => string;
26
+ }
27
27
  //# sourceMappingURL=CfgReferencePathHelper.d.ts.map
@@ -1,26 +1,26 @@
1
- import { encodeURIComponents } from "@configura/web-utilities";
2
- /**
3
- * These methods aims to provide a default suggested way of building
4
- * URLs to Products and Catalogues. By using consistent URL:s copy-paste
5
- * between systems becomes easy and this can aid when debugging.
6
- * Using this format on URL is no requirement. In fact, most of our
7
- * integrators do not, as they do not expose the Catalogue-path.
8
- * Internally at Configura we try to stick with this format.
9
- */
10
- export class CfgReferencePathHelper {
11
- }
12
- /**
13
- * Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
14
- * @param browsingRootUrl The URL where Stage browsing begins
15
- * @param catParams What catalogue to generate URL for.
16
- * @returns An URL to a catalogue
17
- */
18
- CfgReferencePathHelper.getCataloguePath = (browsingRootUrl, catParams) => `${browsingRootUrl}/${encodeURIComponents(catParams.cid, catParams.lang, catParams.enterprise, catParams.prdCat, catParams.prdCatVersion, catParams.vendor, catParams.priceList)}`;
19
- /**
20
- * Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
21
- * @param browsingRootUrl The URL where Stage browsing begins
22
- * @param productParams What product to generate URL for.
23
- * @param separator Optional, defaults to "product", but can be changed to indicate another function.
24
- * @returns An URL to a product
25
- */
26
- CfgReferencePathHelper.getProductPath = (browsingRootUrl, productParams, separator = "product") => `${CfgReferencePathHelper.getCataloguePath(browsingRootUrl, productParams)}/${separator}/${encodeURIComponent(productParams.partNumber)}`;
1
+ import { encodeURIComponents } from "@configura/web-utilities";
2
+ /**
3
+ * These methods aims to provide a default suggested way of building
4
+ * URLs to Products and Catalogues. By using consistent URL:s copy-paste
5
+ * between systems becomes easy and this can aid when debugging.
6
+ * Using this format on URL is no requirement. In fact, most of our
7
+ * integrators do not, as they do not expose the Catalogue-path.
8
+ * Internally at Configura we try to stick with this format.
9
+ */
10
+ export class CfgReferencePathHelper {
11
+ }
12
+ /**
13
+ * Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
14
+ * @param browsingRootUrl The URL where Stage browsing begins
15
+ * @param catParams What catalogue to generate URL for.
16
+ * @returns An URL to a catalogue
17
+ */
18
+ CfgReferencePathHelper.getCataloguePath = (browsingRootUrl, catParams) => `${browsingRootUrl}/${encodeURIComponents(catParams.cid, catParams.lang, catParams.enterprise, catParams.prdCat, catParams.prdCatVersion, catParams.vendor, catParams.priceList)}`;
19
+ /**
20
+ * Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
21
+ * @param browsingRootUrl The URL where Stage browsing begins
22
+ * @param productParams What product to generate URL for.
23
+ * @param separator Optional, defaults to "product", but can be changed to indicate another function.
24
+ * @returns An URL to a product
25
+ */
26
+ CfgReferencePathHelper.getProductPath = (browsingRootUrl, productParams, separator = "product") => `${CfgReferencePathHelper.getCataloguePath(browsingRootUrl, productParams)}/${separator}/${encodeURIComponent(productParams.partNumber)}`;
@@ -1,14 +1,18 @@
1
- import { DtoAdditionalProductConf, DtoAdditionalProductConfiguration, DtoFeatureConf, DtoProductConf, DtoSelectedOption } from "./CatalogueAPI.js";
2
- export declare const isDtoProductConfAdditional: (value: DtoProductConf) => value is DtoAdditionalProductConf;
3
- export declare const convertDtoProductConfToV1: (conf: DtoProductConf, silenceWarnings?: boolean) => DtoAdditionalProductConfiguration;
4
- export declare const convertDtoFeatureConfsToSelOptions: (features: DtoFeatureConf[], silenceWarnings?: boolean) => DtoSelectedOption[];
5
- /**
6
- * Serializes and compacts the configuration into a format especially suited for URLs
7
- */
8
- export declare const dtoProductConfigurationToCompactString: (conf: DtoProductConf) => string;
9
- /**
10
- * Deserializes and inflates the configuration from the compacted format
11
- */
12
- export declare const compactStringToDtoProductConf: (versionAndConf: string) => DtoProductConf;
13
- export declare const stripExtendedDataFromDtoProductConf: (conf: DtoProductConf) => DtoProductConf;
1
+ import { DtoAdditionalProductConf, DtoAdditionalProductConfiguration, DtoFeatureConf, DtoProductConf, DtoSelectedOption } from "./CatalogueAPI.js";
2
+ /** Is the newer version of product configuration */
3
+ export declare const isProductConf: (value: DtoAdditionalProductConfiguration | DtoProductConf) => value is DtoAdditionalProductConf;
4
+ /** Is the older version of product configuration */
5
+ export declare const isAdditionalProductConfiguration: (value: DtoAdditionalProductConfiguration | DtoProductConf) => value is DtoAdditionalProductConfiguration;
6
+ export declare const isDtoProductConfAdditional: (value: DtoProductConf) => value is DtoAdditionalProductConf;
7
+ export declare const convertDtoProductConfToV1: (conf: DtoProductConf, silenceWarnings?: boolean) => DtoAdditionalProductConfiguration;
8
+ export declare const convertDtoFeatureConfsToSelOptions: (features: DtoFeatureConf[], silenceWarnings?: boolean) => DtoSelectedOption[];
9
+ /**
10
+ * Serializes and compacts the configuration into a format especially suited for URLs
11
+ */
12
+ export declare const dtoProductConfigurationToCompactString: (conf: DtoProductConf) => string;
13
+ /**
14
+ * Deserializes and inflates the configuration from the compacted format
15
+ */
16
+ export declare const compactStringToDtoProductConf: (versionAndConf: string) => DtoProductConf;
17
+ export declare const stripExtendedDataFromDtoProductConf: (conf: DtoProductConf) => DtoProductConf;
14
18
  //# sourceMappingURL=ConfigurationConverter.d.ts.map
@@ -1,166 +1,175 @@
1
- export const isDtoProductConfAdditional = (value) => "refKey" in value;
2
- // As this has potential to flood the terminal we only inform once
3
- let hasInformedAboutProdParams = false;
4
- let hasInformedAboutGroupCode = false;
5
- let hasInformedAboutUnit = false;
6
- export const convertDtoProductConfToV1 = (conf, silenceWarnings = false) => {
7
- var _a, _b;
8
- if (!silenceWarnings && conf.prodParams !== undefined && !hasInformedAboutProdParams) {
9
- hasInformedAboutProdParams = true;
10
- console.info("Incoming DtoProductConf contains prodParams. These will be ignored.");
11
- }
12
- const result = {
13
- selOptions: ((_a = conf.features) !== null && _a !== void 0 ? _a : []).map((f) => ({
14
- code: "!~!",
15
- next: convertDtoFeatureConfToApiSelection(f, silenceWarnings),
16
- })),
17
- additionalProducts: ((_b = conf.additionalProducts) !== null && _b !== void 0 ? _b : []).map((p) => convertDtoProductConfToV1(p, silenceWarnings)),
18
- selected: true,
19
- };
20
- if (isDtoProductConfAdditional(conf)) {
21
- result.refKey = conf.refKey;
22
- result.selected = conf.selected;
23
- }
24
- return result;
25
- };
26
- export const convertDtoFeatureConfsToSelOptions = (features, silenceWarnings = false) => (features !== null && features !== void 0 ? features : []).map((f) => ({
27
- code: "!~!",
28
- next: convertDtoFeatureConfToApiSelection(f, silenceWarnings),
29
- }));
30
- const convertDtoFeatureConfToApiSelection = (feature, silenceWarnings) => {
31
- const { groupCode, options, unit } = feature;
32
- if (!silenceWarnings && groupCode !== undefined && !hasInformedAboutGroupCode) {
33
- hasInformedAboutGroupCode = true;
34
- console.info("Incoming DtoFeature contains groupCode. It will be ignored.");
35
- }
36
- if (!silenceWarnings && unit !== undefined && !hasInformedAboutUnit) {
37
- hasInformedAboutUnit = true;
38
- console.info("Incoming DtoFeature contains a unit. It will be ignored.");
39
- }
40
- const result = {};
41
- for (const option of (options !== null && options !== void 0 ? options : []).filter((o) => o.selected)) {
42
- result[option.code] = convertDtoOptionConfToSelectedOption(option, silenceWarnings);
43
- }
44
- return result;
45
- };
46
- const convertDtoOptionConfToSelectedOption = (option, silenceWarnings) => {
47
- const { features, code, numericValue } = option;
48
- const selectionTrees = (features !== null && features !== void 0 ? features : []).map((f) => convertDtoFeatureConfToApiSelection(f, silenceWarnings));
49
- const mergedSelectionTree = {};
50
- let anyItems = false;
51
- for (const selectionTree of selectionTrees) {
52
- if (selectionTree === undefined) {
53
- continue;
54
- }
55
- for (const key of Object.keys(selectionTree)) {
56
- if (mergedSelectionTree[key] !== undefined) {
57
- console.warn(`The key (${key}) is already used in the selection tree. Option code: "${code}".`);
58
- continue;
59
- }
60
- mergedSelectionTree[key] = selectionTree[key];
61
- anyItems = true;
62
- }
63
- }
64
- const selectedOption = {
65
- code,
66
- numericValue,
67
- };
68
- if (anyItems) {
69
- selectedOption.next = mergedSelectionTree;
70
- }
71
- return selectedOption;
72
- };
73
- const versionedRegex = /^v(\d+)(.+)$/;
74
- const jsonKeyRegex = /"([^"]+)":/g;
75
- const swapForUrlAdaptedRegex = /[-~_{}"]/g;
76
- const shortToLong = new Map();
77
- const longToShort = new Map();
78
- // The replacement scheme here assumes this will only be used for keys
79
- // in DtoProductConf and the knowledge that it contains no one
80
- // one char keys.
81
- for (const [long, short] of [
82
- ["configuration", "c"],
83
- ["additionalProducts", "a"],
84
- ["prodParams", "p"],
85
- ["refKey", "r"],
86
- ["selected", "s"],
87
- ["features", "f"],
88
- ["code", "d"],
89
- ["options", "o"],
90
- ["numericValue", "n"],
91
- ["groupCode", "g"],
92
- ["unit", "u"],
93
- ]) {
94
- shortToLong.set(short, long);
95
- longToShort.set(long, short);
96
- }
97
- /**
98
- * As certain chars are abundant in JSON but less abundant in the actual data
99
- * we swap these so that frequent characters do not need to be URL-encoded.
100
- */
101
- const jsonStringSwapCharsForUrl = (data) => data.replace(swapForUrlAdaptedRegex, (char) => {
102
- switch (char) {
103
- case "{":
104
- return "~";
105
- case "}":
106
- return "-";
107
- case '"':
108
- return "_";
109
- case "~":
110
- return "{";
111
- case "-":
112
- return "}";
113
- case "_":
114
- return '"';
115
- default:
116
- throw new Error(`Unexpected char "${char}" in swap for URL`);
117
- }
118
- });
119
- const compactDtoProductConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = longToShort.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
120
- const expandDtoProductConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = shortToLong.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
121
- /**
122
- * Serializes and compacts the configuration into a format especially suited for URLs
123
- */
124
- export const dtoProductConfigurationToCompactString = (conf) => "v1" +
125
- jsonStringSwapCharsForUrl(compactDtoProductConfJsonKeys(JSON.stringify(conf, undefined, "")));
126
- /**
127
- * Deserializes and inflates the configuration from the compacted format
128
- */
129
- export const compactStringToDtoProductConf = (versionAndConf) => {
130
- const match = versionedRegex.exec(versionAndConf);
131
- if (match === null) {
132
- throw new Error("Could not match version string");
133
- }
134
- const [, version, conf] = match;
135
- if (version !== "1") {
136
- throw new Error("Unknown packed URL version");
137
- }
138
- if (conf === "") {
139
- throw new Error("No conf found");
140
- }
141
- return JSON.parse(expandDtoProductConfJsonKeys(jsonStringSwapCharsForUrl(conf)));
142
- };
143
- export const stripExtendedDataFromDtoProductConf = (conf) => {
144
- var _a, _b;
145
- return ({
146
- features: (_a = conf.features) === null || _a === void 0 ? void 0 : _a.map(stripExtendedDataFromDtoFeatureConf),
147
- additionalProducts: (_b = conf.additionalProducts) === null || _b === void 0 ? void 0 : _b.map(stripExtendedDataFromDtoAdditionalProductConfiguration),
148
- });
149
- };
150
- const stripExtendedDataFromDtoAdditionalProductConfiguration = (conf) => (Object.assign(Object.assign({}, stripExtendedDataFromDtoProductConf(conf)), { refKey: conf.refKey, selected: conf.selected }));
151
- const stripExtendedDataFromDtoFeatureConf = (conf) => {
152
- var _a;
153
- return ({
154
- code: conf.code,
155
- options: (_a = conf.options) === null || _a === void 0 ? void 0 : _a.map(stripExtendedDataFromDtoOptionConf),
156
- });
157
- };
158
- const stripExtendedDataFromDtoOptionConf = (conf) => {
159
- var _a;
160
- return ({
161
- code: conf.code,
162
- selected: conf.selected,
163
- numericValue: conf.numericValue,
164
- features: (_a = conf.features) === null || _a === void 0 ? void 0 : _a.map(stripExtendedDataFromDtoFeatureConf),
165
- });
166
- };
1
+ /** Is the newer version of product configuration */
2
+ export const isProductConf = (value) => !("selOptions" in value);
3
+ /** Is the older version of product configuration */
4
+ export const isAdditionalProductConfiguration = (value) => "selOptions" in value;
5
+ export const isDtoProductConfAdditional = (value) => "refKey" in value;
6
+ // As this has potential to flood the terminal we only inform once
7
+ let hasInformedAboutProdParams = false;
8
+ let hasInformedAboutGroupCode = false;
9
+ let hasInformedAboutUnit = false;
10
+ export const convertDtoProductConfToV1 = (conf, silenceWarnings = false) => {
11
+ var _a, _b;
12
+ if (!silenceWarnings && conf.prodParams !== undefined && !hasInformedAboutProdParams) {
13
+ hasInformedAboutProdParams = true;
14
+ console.info("Incoming DtoProductConf contains prodParams. These will be ignored.");
15
+ }
16
+ const result = {
17
+ selOptions: ((_a = conf.features) !== null && _a !== void 0 ? _a : []).map((f) => ({
18
+ code: "!~!",
19
+ next: convertDtoFeatureConfToApiSelection(f, silenceWarnings),
20
+ })),
21
+ additionalProducts: ((_b = conf.additionalProducts) !== null && _b !== void 0 ? _b : []).map((p) => convertDtoProductConfToV1(p, silenceWarnings)),
22
+ selected: true,
23
+ };
24
+ if (isDtoProductConfAdditional(conf)) {
25
+ result.refKey = conf.refKey;
26
+ result.selected = conf.selected;
27
+ }
28
+ return result;
29
+ };
30
+ export const convertDtoFeatureConfsToSelOptions = (features, silenceWarnings = false) => (features !== null && features !== void 0 ? features : []).map((f) => ({
31
+ code: "!~!",
32
+ next: convertDtoFeatureConfToApiSelection(f, silenceWarnings),
33
+ }));
34
+ const convertDtoFeatureConfToApiSelection = (feature, silenceWarnings) => {
35
+ const { groupCode, options, unit } = feature;
36
+ if (!silenceWarnings && groupCode !== undefined && !hasInformedAboutGroupCode) {
37
+ hasInformedAboutGroupCode = true;
38
+ console.info("Incoming DtoFeature contains groupCode. It will be ignored.");
39
+ }
40
+ if (!silenceWarnings && unit !== undefined && !hasInformedAboutUnit) {
41
+ hasInformedAboutUnit = true;
42
+ console.info("Incoming DtoFeature contains a unit. It will be ignored.");
43
+ }
44
+ const result = {};
45
+ for (const option of (options !== null && options !== void 0 ? options : []).filter((o) => o.selected)) {
46
+ result[option.code] = convertDtoOptionConfToSelectedOption(option, silenceWarnings);
47
+ }
48
+ return result;
49
+ };
50
+ const convertDtoOptionConfToSelectedOption = (option, silenceWarnings) => {
51
+ const { features, code, numericValue } = option;
52
+ const selectionTrees = (features !== null && features !== void 0 ? features : []).map((f) => convertDtoFeatureConfToApiSelection(f, silenceWarnings));
53
+ const mergedSelectionTree = {};
54
+ let anyItems = false;
55
+ for (const selectionTree of selectionTrees) {
56
+ if (selectionTree === undefined) {
57
+ continue;
58
+ }
59
+ for (const key of Object.keys(selectionTree)) {
60
+ if (mergedSelectionTree[key] !== undefined) {
61
+ console.warn(`The key (${key}) is already used in the selection tree. Option code: "${code}".`);
62
+ continue;
63
+ }
64
+ mergedSelectionTree[key] = selectionTree[key];
65
+ anyItems = true;
66
+ }
67
+ }
68
+ const selectedOption = {
69
+ code,
70
+ numericValue,
71
+ };
72
+ if (anyItems) {
73
+ selectedOption.next = mergedSelectionTree;
74
+ }
75
+ return selectedOption;
76
+ };
77
+ const versionedRegex = /^v(\d+)(.+)$/;
78
+ const jsonKeyRegex = /"([^"]+)":/g;
79
+ const swapForUrlAdaptedRegex = /[-~_{}"]/g;
80
+ const shortToLong = new Map();
81
+ const longToShort = new Map();
82
+ // The replacement scheme here assumes this will only be used for keys
83
+ // in DtoProductConf and the knowledge that it contains no one
84
+ // one char keys.
85
+ for (const [long, short] of [
86
+ ["configuration", "c"],
87
+ ["additionalProducts", "a"],
88
+ ["prodParams", "p"],
89
+ ["refKey", "r"],
90
+ ["selected", "s"],
91
+ ["features", "f"],
92
+ ["code", "d"],
93
+ ["options", "o"],
94
+ ["numericValue", "n"],
95
+ ["groupCode", "g"],
96
+ ["unit", "u"],
97
+ ["syncGroupState", "sgs"],
98
+ ["selectOne", "so"],
99
+ ["selectMany", "sm"],
100
+ ["syncCode", "sc"],
101
+ ["optionCode", "oc"],
102
+ ]) {
103
+ shortToLong.set(short, long);
104
+ longToShort.set(long, short);
105
+ }
106
+ /**
107
+ * As certain chars are abundant in JSON but less abundant in the actual data
108
+ * we swap these so that frequent characters do not need to be URL-encoded.
109
+ */
110
+ const jsonStringSwapCharsForUrl = (data) => data.replace(swapForUrlAdaptedRegex, (char) => {
111
+ switch (char) {
112
+ case "{":
113
+ return "~";
114
+ case "}":
115
+ return "-";
116
+ case '"':
117
+ return "_";
118
+ case "~":
119
+ return "{";
120
+ case "-":
121
+ return "}";
122
+ case "_":
123
+ return '"';
124
+ default:
125
+ throw new Error(`Unexpected char "${char}" in swap for URL`);
126
+ }
127
+ });
128
+ const compactDtoProductConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = longToShort.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
129
+ const expandDtoProductConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = shortToLong.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
130
+ /**
131
+ * Serializes and compacts the configuration into a format especially suited for URLs
132
+ */
133
+ export const dtoProductConfigurationToCompactString = (conf) => "v1" +
134
+ jsonStringSwapCharsForUrl(compactDtoProductConfJsonKeys(JSON.stringify(conf, undefined, "")));
135
+ /**
136
+ * Deserializes and inflates the configuration from the compacted format
137
+ */
138
+ export const compactStringToDtoProductConf = (versionAndConf) => {
139
+ const match = versionedRegex.exec(versionAndConf);
140
+ if (match === null) {
141
+ throw new Error("Could not match version string");
142
+ }
143
+ const [, version, conf] = match;
144
+ if (version !== "1") {
145
+ throw new Error("Unknown packed URL version");
146
+ }
147
+ if (conf === "") {
148
+ throw new Error("No conf found");
149
+ }
150
+ return JSON.parse(expandDtoProductConfJsonKeys(jsonStringSwapCharsForUrl(conf)));
151
+ };
152
+ export const stripExtendedDataFromDtoProductConf = (conf) => {
153
+ var _a, _b;
154
+ return ({
155
+ features: (_a = conf.features) === null || _a === void 0 ? void 0 : _a.map(stripExtendedDataFromDtoFeatureConf),
156
+ additionalProducts: (_b = conf.additionalProducts) === null || _b === void 0 ? void 0 : _b.map(stripExtendedDataFromDtoAdditionalProductConfiguration),
157
+ });
158
+ };
159
+ const stripExtendedDataFromDtoAdditionalProductConfiguration = (conf) => (Object.assign(Object.assign({}, stripExtendedDataFromDtoProductConf(conf)), { refKey: conf.refKey, selected: conf.selected }));
160
+ const stripExtendedDataFromDtoFeatureConf = (conf) => {
161
+ var _a;
162
+ return ({
163
+ code: conf.code,
164
+ options: (_a = conf.options) === null || _a === void 0 ? void 0 : _a.map(stripExtendedDataFromDtoOptionConf),
165
+ });
166
+ };
167
+ const stripExtendedDataFromDtoOptionConf = (conf) => {
168
+ var _a;
169
+ return ({
170
+ code: conf.code,
171
+ selected: conf.selected,
172
+ numericValue: conf.numericValue,
173
+ features: (_a = conf.features) === null || _a === void 0 ? void 0 : _a.map(stripExtendedDataFromDtoFeatureConf),
174
+ });
175
+ };
package/dist/index.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- export * from "./CatalogueAPI.js";
2
- export * from "./CfgProduct.js";
3
- export * from "./CfgReferencePathHelper.js";
4
- export * from "./ConfigurationConverter.js";
5
- export * from "./io/index.js";
6
- export * from "./material/CfgMaterialMapping.js";
7
- export * from "./material/CfgMtrlApplication.js";
8
- export * from "./material/CfgMtrlApplicationSource.js";
9
- export * from "./material/CfgMtrlSource.js";
10
- export * from "./material/CfgMtrlSourceWithMetaData.js";
11
- export * from "./productConfiguration/CfgFeature.js";
12
- export * from "./productConfiguration/CfgOption.js";
13
- export * from "./productConfiguration/CfgProductConfiguration.js";
14
- export * from "./productConfiguration/filters.js";
15
- export * from "./productConfiguration/productParamsGenerator.js";
16
- export * from "./productLoader.js";
17
- export * from "./syncGroups/SyncGroupsApplyMode.js";
18
- export * from "./syncGroups/SyncGroupsHandler.js";
19
- export * from "./tasks/formats.js";
20
- export * from "./tasks/TaskHandler.js";
21
- export * from "./utilitiesCatalogueData.js";
22
- export * from "./utilitiesCataloguePermission.js";
23
- export * from "./utilitiesNumericValues.js";
1
+ export * from "./CatalogueAPI.js";
2
+ export * from "./CfgProduct.js";
3
+ export * from "./CfgReferencePathHelper.js";
4
+ export * from "./ConfigurationConverter.js";
5
+ export * from "./io/index.js";
6
+ export * from "./material/CfgMaterialMapping.js";
7
+ export * from "./material/CfgMtrlApplication.js";
8
+ export * from "./material/CfgMtrlApplicationSource.js";
9
+ export * from "./material/CfgMtrlSource.js";
10
+ export * from "./material/CfgMtrlSourceWithMetaData.js";
11
+ export * from "./productConfiguration/CfgFeature.js";
12
+ export * from "./productConfiguration/CfgOption.js";
13
+ export * from "./productConfiguration/CfgProductConfiguration.js";
14
+ export * from "./productConfiguration/filters.js";
15
+ export * from "./productConfiguration/productParamsGenerator.js";
16
+ export * from "./productLoader.js";
17
+ export * from "./syncGroups/SyncGroupsApplyMode.js";
18
+ export * from "./syncGroups/SyncGroupsHandler.js";
19
+ export * from "./tasks/formats.js";
20
+ export * from "./tasks/TaskHandler.js";
21
+ export * from "./utilitiesCatalogueData.js";
22
+ export * from "./utilitiesCataloguePermission.js";
23
+ export * from "./utilitiesNumericValues.js";
24
24
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,23 +1,23 @@
1
- export * from "./CatalogueAPI.js";
2
- export * from "./CfgProduct.js";
3
- export * from "./CfgReferencePathHelper.js";
4
- export * from "./ConfigurationConverter.js";
5
- export * from "./io/index.js";
6
- export * from "./material/CfgMaterialMapping.js";
7
- export * from "./material/CfgMtrlApplication.js";
8
- export * from "./material/CfgMtrlApplicationSource.js";
9
- export * from "./material/CfgMtrlSource.js";
10
- export * from "./material/CfgMtrlSourceWithMetaData.js";
11
- export * from "./productConfiguration/CfgFeature.js";
12
- export * from "./productConfiguration/CfgOption.js";
13
- export * from "./productConfiguration/CfgProductConfiguration.js";
14
- export * from "./productConfiguration/filters.js";
15
- export * from "./productConfiguration/productParamsGenerator.js";
16
- export * from "./productLoader.js";
17
- export * from "./syncGroups/SyncGroupsApplyMode.js";
18
- export * from "./syncGroups/SyncGroupsHandler.js";
19
- export * from "./tasks/formats.js";
20
- export * from "./tasks/TaskHandler.js";
21
- export * from "./utilitiesCatalogueData.js";
22
- export * from "./utilitiesCataloguePermission.js";
23
- export * from "./utilitiesNumericValues.js";
1
+ export * from "./CatalogueAPI.js";
2
+ export * from "./CfgProduct.js";
3
+ export * from "./CfgReferencePathHelper.js";
4
+ export * from "./ConfigurationConverter.js";
5
+ export * from "./io/index.js";
6
+ export * from "./material/CfgMaterialMapping.js";
7
+ export * from "./material/CfgMtrlApplication.js";
8
+ export * from "./material/CfgMtrlApplicationSource.js";
9
+ export * from "./material/CfgMtrlSource.js";
10
+ export * from "./material/CfgMtrlSourceWithMetaData.js";
11
+ export * from "./productConfiguration/CfgFeature.js";
12
+ export * from "./productConfiguration/CfgOption.js";
13
+ export * from "./productConfiguration/CfgProductConfiguration.js";
14
+ export * from "./productConfiguration/filters.js";
15
+ export * from "./productConfiguration/productParamsGenerator.js";
16
+ export * from "./productLoader.js";
17
+ export * from "./syncGroups/SyncGroupsApplyMode.js";
18
+ export * from "./syncGroups/SyncGroupsHandler.js";
19
+ export * from "./tasks/formats.js";
20
+ export * from "./tasks/TaskHandler.js";
21
+ export * from "./utilitiesCatalogueData.js";
22
+ export * from "./utilitiesCataloguePermission.js";
23
+ export * from "./utilitiesNumericValues.js";