@configura/web-api 2.0.0-alpha.9 → 2.1.0-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 (58) hide show
  1. package/.eslintrc.json +1 -14
  2. package/dist/CatalogueAPI.d.ts +103 -32
  3. package/dist/CatalogueAPI.js +62 -6
  4. package/dist/CfgProduct.d.ts +90 -14
  5. package/dist/CfgProduct.js +266 -56
  6. package/dist/CfgReferencePathHelper.d.ts +3 -3
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/io/CfgHistoryManager.d.ts +33 -1
  10. package/dist/io/CfgHistoryManager.js +68 -6
  11. package/dist/io/CfgHistoryToProdConfConnector.d.ts +11 -10
  12. package/dist/io/CfgHistoryToProdConfConnector.js +32 -38
  13. package/dist/io/CfgIOManager.d.ts +5 -0
  14. package/dist/io/CfgIOManager.js +20 -1
  15. package/dist/io/CfgIOProdConfConnector.d.ts +17 -18
  16. package/dist/io/CfgIOProdConfConnector.js +52 -58
  17. package/dist/io/CfgIOWarningSupplier.d.ts +4 -0
  18. package/dist/io/CfgIOWarningSupplier.js +1 -0
  19. package/dist/io/CfgObservableStateToProdConfConnector.d.ts +4 -4
  20. package/dist/io/CfgObservableStateToProdConfConnector.js +3 -3
  21. package/dist/io/CfgWindowMessageManager.js +4 -0
  22. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +4 -4
  23. package/dist/io/CfgWindowMessageToProdConfConnector.js +3 -3
  24. package/dist/productConfiguration/CfgFeature.d.ts +12 -7
  25. package/dist/productConfiguration/CfgFeature.js +33 -14
  26. package/dist/productConfiguration/CfgOption.d.ts +16 -10
  27. package/dist/productConfiguration/CfgOption.js +46 -18
  28. package/dist/productConfiguration/CfgProductConfiguration.d.ts +27 -16
  29. package/dist/productConfiguration/CfgProductConfiguration.js +53 -29
  30. package/dist/productConfiguration/filters.d.ts +6 -4
  31. package/dist/productConfiguration/filters.js +94 -23
  32. package/dist/productConfiguration/productParamsGenerator.d.ts +3 -3
  33. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +1 -1
  34. package/dist/productConfiguration/utilitiesProductConfiguration.js +11 -4
  35. package/dist/productLoader.d.ts +3 -3
  36. package/dist/productLoader.js +1 -1
  37. package/dist/syncGroups/SyncGroupsHandler.d.ts +9 -2
  38. package/dist/syncGroups/SyncGroupsHandler.js +15 -4
  39. package/dist/syncGroups/SyncGroupsState.d.ts +5 -1
  40. package/dist/syncGroups/SyncGroupsState.js +44 -2
  41. package/dist/syncGroups/SyncGroupsTransaction.js +34 -21
  42. package/dist/tasks/TaskHandler.d.ts +2 -2
  43. package/dist/tasks/TaskHandler.js +2 -1
  44. package/dist/tests/testData/dummyProductForTest.d.ts +2 -2
  45. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +14 -9
  46. package/dist/tests/testData/testDataCachedGetProduct.js +2 -0
  47. package/dist/tests/testData/testDataCachedPostValidate.js +2 -0
  48. package/dist/tests/testData/testDataProductAggregatedPrice.js +3 -1
  49. package/dist/tests/testData/testDataUpcharge.js +2 -0
  50. package/dist/utilitiesCatalogueData.d.ts +14 -9
  51. package/dist/utilitiesCatalogueData.js +7 -0
  52. package/dist/utilitiesCataloguePermission.d.ts +4 -4
  53. package/dist/utilitiesConfiguration.d.ts +29 -0
  54. package/dist/utilitiesConfiguration.js +200 -0
  55. package/dist/utilitiesNumericValues.js +13 -8
  56. package/package.json +3 -3
  57. package/dist/ConfigurationConverter.d.ts +0 -5
  58. package/dist/ConfigurationConverter.js +0 -72
@@ -44,6 +44,7 @@ export class NumericValueDiscrete {
44
44
  return `${round(this.value)}`;
45
45
  }
46
46
  }
47
+ const ACCEPTABLE_STEP_DEVIATION = 0.0000001;
47
48
  export class NumericValueRangeDefinition {
48
49
  constructor(rawRange) {
49
50
  const { minValue, maxValue, increment } = rawRange;
@@ -56,19 +57,19 @@ export class NumericValueRangeDefinition {
56
57
  if (value < start || end < value) {
57
58
  return false;
58
59
  }
59
- // TODO: This comparison will often fail due to the fact that all the values used are
60
+ // This comparison would often fail due to the fact that all the values used are
60
61
  // base-2 (binary) floating point numbers based on base-10 (decimal) input strings.
61
62
  //
62
63
  // Such calculations are often not 100% accurate as is visible in JS by simply
63
64
  // computing "0.1 + 0.2" which should equal about "0.30000000000000004" != "0.3".
64
65
  //
65
- // The easiest workaround is to define an static accuracy, say "6 decimals" and round
66
- // everything when comparing. One could also use a scaled version of Number.EPSILON to
67
- // dynamically match the precision to the precision of the input numbers.
66
+ // We have used the easiest workaround, to simply be a bit fuzzy with the checks and
67
+ // allow values that are very, very close to being on a step.
68
68
  //
69
- // Both workarounds share the same problem however; an infinite number of numbers will be
70
- // included in the range since an "infinite" number of values will map to the same rounded
71
- // actual number.
69
+ // This workaround comes with two major compromises:
70
+ // 1. The fuzziness needed depends on how many steps the checked values pass on the way.
71
+ // 2. An infinite number of numbers will be included in the range since many an "infinite"
72
+ // number of values close to each step will map to it.
72
73
  //
73
74
  // The proper fix is probably to use a fixed point mathematics, where we either define a
74
75
  // maximum of say 6 decimals or the number of decimals vary on the number of decimals given
@@ -79,7 +80,11 @@ export class NumericValueRangeDefinition {
79
80
  // and that is how the numbers are stored in CatCreator if you use a db3-file. If it is a
80
81
  // string there as well, everything is dandy. Otherwise we might get problems with rounding
81
82
  // or infinite decimals during the conversions to/from the db3-file.
82
- return step === undefined || (value - start) % step === 0;
83
+ if (step === undefined) {
84
+ return true;
85
+ }
86
+ const deviation = (value - start) % step;
87
+ return (deviation < ACCEPTABLE_STEP_DEVIATION || step - deviation < ACCEPTABLE_STEP_DEVIATION);
83
88
  }
84
89
  get first() {
85
90
  return this.minValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configura/web-api",
3
- "version": "2.0.0-alpha.9",
3
+ "version": "2.1.0-alpha.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@configura/web-utilities": "2.0.0-alpha.9"
26
+ "@configura/web-utilities": "2.1.0-alpha.0"
27
27
  },
28
- "gitHead": "734f4e65f7d3dc9836c5c0321dbe6c36bbfa2531"
28
+ "gitHead": "883ad6e31a55f05124dd0a6b2047c36ef6e6cea1"
29
29
  }
@@ -1,5 +0,0 @@
1
- import { DtoAdditionalProductConfiguration, DtoAdditionalProductConfigurationV2, DtoFeatureConfiguration, DtoProductConfiguration, DtoSelectedOption } from "./CatalogueAPI.js";
2
- export declare const isDtoConfProdAdditional: (value: DtoProductConfiguration) => value is DtoAdditionalProductConfigurationV2;
3
- export declare const convertDtoConfProdToV1: (conf: DtoProductConfiguration, silenceWarnings?: boolean) => DtoAdditionalProductConfiguration;
4
- export declare const convertDtoConfFeaturesToSelOptions: (features: DtoFeatureConfiguration[], silenceWarnings?: boolean) => DtoSelectedOption[];
5
- //# sourceMappingURL=ConfigurationConverter.d.ts.map
@@ -1,72 +0,0 @@
1
- export const isDtoConfProdAdditional = (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 convertDtoConfProdToV1 = (conf, silenceWarnings = false) => {
7
- var _a, _b;
8
- if (!silenceWarnings && conf.prodParams !== undefined && !hasInformedAboutProdParams) {
9
- hasInformedAboutProdParams = true;
10
- console.info("Incoming DtoProductConfiguration 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: convertDtoConfFeatureToApiSelection(f, silenceWarnings),
16
- })),
17
- additionalProducts: ((_b = conf.additionalProducts) !== null && _b !== void 0 ? _b : []).map((p) => convertDtoConfProdToV1(p, silenceWarnings)),
18
- selected: true,
19
- };
20
- if (isDtoConfProdAdditional(conf)) {
21
- result.refKey = conf.refKey;
22
- result.selected = conf.selected;
23
- }
24
- return result;
25
- };
26
- export const convertDtoConfFeaturesToSelOptions = (features, silenceWarnings = false) => (features !== null && features !== void 0 ? features : []).map((f) => ({
27
- code: "!~!",
28
- next: convertDtoConfFeatureToApiSelection(f, silenceWarnings),
29
- }));
30
- const convertDtoConfFeatureToApiSelection = (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] = convertDtoConfOptionToSelectedOption(option, silenceWarnings);
43
- }
44
- return result;
45
- };
46
- const convertDtoConfOptionToSelectedOption = (option, silenceWarnings) => {
47
- const { features, code, numericValue } = option;
48
- const selectionTrees = (features !== null && features !== void 0 ? features : []).map((f) => convertDtoConfFeatureToApiSelection(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
- };