@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,144 +1,144 @@
1
- import { mapQueryString, Observable, unmapQueryString } from "@configura/web-utilities";
2
- import { CfgIOManager } from "./CfgIOManager.js";
3
- import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
4
- /**
5
- * How the history is updated.
6
- * @param DoNotWrite Only listens to initial URL-values.
7
- * @param Replace Replaces the current history frame at updates.
8
- * @param Push Adds history frames at updates.
9
- * @param ReplaceAndUpdateUrl Replaces the current history frame at updates and updates the browser URL
10
- * @param PushAndUpdateUrl Adds history frames at updates and updates the browser URL
11
- */
12
- export var HistoryMode;
13
- (function (HistoryMode) {
14
- HistoryMode[HistoryMode["DoNotWrite"] = 0] = "DoNotWrite";
15
- HistoryMode[HistoryMode["Replace"] = 1] = "Replace";
16
- HistoryMode[HistoryMode["Push"] = 2] = "Push";
17
- HistoryMode[HistoryMode["ReplaceAndUpdateUrl"] = 3] = "ReplaceAndUpdateUrl";
18
- HistoryMode[HistoryMode["PushAndUpdateUrl"] = 4] = "PushAndUpdateUrl";
19
- })(HistoryMode || (HistoryMode = {}));
20
- /**
21
- * This class is used to coordinate writing and reading to the browser history.
22
- * It handles messages sent from the connectors.
23
- */
24
- export class CfgHistoryManager extends CfgWindowEventManager {
25
- constructor() {
26
- super();
27
- this._aggregatedQsKeyValues = new Map();
28
- this._urlUpdateObservable = new Observable();
29
- this.eventType = "popstate";
30
- }
31
- static get instance() {
32
- if (this._instance === undefined) {
33
- this._instance = new CfgHistoryManager();
34
- }
35
- return this._instance;
36
- }
37
- /**
38
- * @returns The current browser URL updated with the latest updates from
39
- * the Connectors.
40
- */
41
- getUrl() {
42
- return CfgHistoryManager._makeUpdatedUrl(this._aggregatedQsKeyValues);
43
- }
44
- /**
45
- * Listen for updated URL:s. This doesn't have to mean the URL in the
46
- * browser has been updated.
47
- */
48
- listenForUrl(listener) {
49
- this._urlUpdateObservable.listen(listener);
50
- }
51
- /**
52
- * Stop listen.
53
- */
54
- stopListenForUrl(listener) {
55
- this._urlUpdateObservable.stopListen(listener);
56
- }
57
- /**
58
- * Write to the history
59
- */
60
- send(messageKey, data) {
61
- const { qsKeyValues, message, mode } = data;
62
- for (const keyValue of qsKeyValues) {
63
- this._aggregatedQsKeyValues.set(keyValue[0], keyValue[1]);
64
- }
65
- this._urlUpdateObservable.notifyAll(this.getUrl());
66
- if (mode === HistoryMode.DoNotWrite) {
67
- return;
68
- }
69
- // Initial data is before user interaction has happened
70
- const initial = message.initial;
71
- const url = CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
72
- // At initial we do not replace the URL as we presumable have the defaults
73
- const writeUrl = initial ||
74
- !(mode === HistoryMode.PushAndUpdateUrl || mode === HistoryMode.ReplaceAndUpdateUrl)
75
- ? null
76
- : url;
77
- // ...but we do replace the state so that we can in the future browse back to here
78
- const newState = CfgHistoryManager._makeUpdatedState(window.history.state, message, messageKey);
79
- if (initial ||
80
- mode === HistoryMode.Replace ||
81
- mode === HistoryMode.ReplaceAndUpdateUrl ||
82
- this.receiveInProgress) {
83
- window.history.replaceState(newState, "", writeUrl);
84
- }
85
- else {
86
- window.history.pushState(newState, "", writeUrl);
87
- }
88
- }
89
- /**
90
- * Takes the current in browser URL and updates it with the provided Query String values.
91
- * Old Query String is replaced.
92
- */
93
- static _makeUpdatedUrl(qsKeyValues) {
94
- const qs = this._makeUpdatedQueryString(qsKeyValues);
95
- return `${window.location.origin}${window.location.pathname}${qs ? "?" : ""}${qs}${window.location.hash}`;
96
- }
97
- /**
98
- * Returns the current in browser Query String updated with the key values provided.
99
- * If a value is undefined in the passed map it will be deleted from the Query String.
100
- */
101
- static _makeUpdatedQueryString(qsKeyValues) {
102
- const currentKeyValues = this.currentQsKeyValues();
103
- for (const [key, value] of qsKeyValues) {
104
- if (value === undefined) {
105
- currentKeyValues.delete(key);
106
- }
107
- else {
108
- currentKeyValues.set(key, value);
109
- }
110
- }
111
- return unmapQueryString(currentKeyValues);
112
- }
113
- /**
114
- * @returns The current in browser Query String as a Map
115
- */
116
- static currentQsKeyValues() {
117
- return mapQueryString(window.location.search);
118
- }
119
- /**
120
- * If the passed currentState is a CfgIOContainer it will update it with the
121
- * passed message. If not it will create a new CfgIOContainer with the message.
122
- */
123
- static _makeUpdatedState(currentState, message, messageKey) {
124
- let messages = {};
125
- if (CfgIOManager.isIOContainer(currentState)) {
126
- messages = currentState.messages;
127
- }
128
- messages[messageKey] = message;
129
- return CfgIOManager.makeContainer(messages);
130
- }
131
- getDataFromEvent(event) {
132
- return event.state;
133
- }
134
- static getMessageFromCurrentHistoryState(messageKey) {
135
- const state = window.history.state;
136
- if (!CfgIOManager.isIOContainer(state)) {
137
- return undefined;
138
- }
139
- if (!CfgIOManager.hasIOContainerMessageKey(state, messageKey)) {
140
- return undefined;
141
- }
142
- return CfgIOManager.getMessageFromIOContainer(state, messageKey);
143
- }
144
- }
1
+ import { mapQueryString, Observable, unmapQueryString } from "@configura/web-utilities";
2
+ import { CfgIOManager } from "./CfgIOManager.js";
3
+ import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
4
+ /**
5
+ * How the history is updated.
6
+ * @param DoNotWrite Only listens to initial URL-values.
7
+ * @param Replace Replaces the current history frame at updates.
8
+ * @param Push Adds history frames at updates.
9
+ * @param ReplaceAndUpdateUrl Replaces the current history frame at updates and updates the browser URL
10
+ * @param PushAndUpdateUrl Adds history frames at updates and updates the browser URL
11
+ */
12
+ export var HistoryMode;
13
+ (function (HistoryMode) {
14
+ HistoryMode[HistoryMode["DoNotWrite"] = 0] = "DoNotWrite";
15
+ HistoryMode[HistoryMode["Replace"] = 1] = "Replace";
16
+ HistoryMode[HistoryMode["Push"] = 2] = "Push";
17
+ HistoryMode[HistoryMode["ReplaceAndUpdateUrl"] = 3] = "ReplaceAndUpdateUrl";
18
+ HistoryMode[HistoryMode["PushAndUpdateUrl"] = 4] = "PushAndUpdateUrl";
19
+ })(HistoryMode || (HistoryMode = {}));
20
+ /**
21
+ * This class is used to coordinate writing and reading to the browser history.
22
+ * It handles messages sent from the connectors.
23
+ */
24
+ export class CfgHistoryManager extends CfgWindowEventManager {
25
+ constructor() {
26
+ super();
27
+ this._aggregatedQsKeyValues = new Map();
28
+ this._urlUpdateObservable = new Observable();
29
+ this.eventType = "popstate";
30
+ }
31
+ static get instance() {
32
+ if (this._instance === undefined) {
33
+ this._instance = new CfgHistoryManager();
34
+ }
35
+ return this._instance;
36
+ }
37
+ /**
38
+ * @returns The current browser URL updated with the latest updates from
39
+ * the Connectors.
40
+ */
41
+ getUrl() {
42
+ return CfgHistoryManager._makeUpdatedUrl(this._aggregatedQsKeyValues);
43
+ }
44
+ /**
45
+ * Listen for updated URL:s. This doesn't have to mean the URL in the
46
+ * browser has been updated.
47
+ */
48
+ listenForUrl(listener) {
49
+ this._urlUpdateObservable.listen(listener);
50
+ }
51
+ /**
52
+ * Stop listen.
53
+ */
54
+ stopListenForUrl(listener) {
55
+ this._urlUpdateObservable.stopListen(listener);
56
+ }
57
+ /**
58
+ * Write to the history
59
+ */
60
+ send(messageKey, data) {
61
+ const { qsKeyValues, message, mode } = data;
62
+ for (const keyValue of qsKeyValues) {
63
+ this._aggregatedQsKeyValues.set(keyValue[0], keyValue[1]);
64
+ }
65
+ this._urlUpdateObservable.notifyAll(this.getUrl());
66
+ if (mode === HistoryMode.DoNotWrite) {
67
+ return;
68
+ }
69
+ // Initial data is before user interaction has happened
70
+ const initial = message.initial;
71
+ const url = CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
72
+ // At initial we do not replace the URL as we presumable have the defaults
73
+ const writeUrl = initial ||
74
+ !(mode === HistoryMode.PushAndUpdateUrl || mode === HistoryMode.ReplaceAndUpdateUrl)
75
+ ? null
76
+ : url;
77
+ // ...but we do replace the state so that we can in the future browse back to here
78
+ const newState = CfgHistoryManager._makeUpdatedState(window.history.state, message, messageKey);
79
+ if (initial ||
80
+ mode === HistoryMode.Replace ||
81
+ mode === HistoryMode.ReplaceAndUpdateUrl ||
82
+ this.receiveInProgress) {
83
+ window.history.replaceState(newState, "", writeUrl);
84
+ }
85
+ else {
86
+ window.history.pushState(newState, "", writeUrl);
87
+ }
88
+ }
89
+ /**
90
+ * Takes the current in browser URL and updates it with the provided Query String values.
91
+ * Old Query String is replaced.
92
+ */
93
+ static _makeUpdatedUrl(qsKeyValues) {
94
+ const qs = this._makeUpdatedQueryString(qsKeyValues);
95
+ return `${window.location.origin}${window.location.pathname}${qs ? "?" : ""}${qs}${window.location.hash}`;
96
+ }
97
+ /**
98
+ * Returns the current in browser Query String updated with the key values provided.
99
+ * If a value is undefined in the passed map it will be deleted from the Query String.
100
+ */
101
+ static _makeUpdatedQueryString(qsKeyValues) {
102
+ const currentKeyValues = this.currentQsKeyValues();
103
+ for (const [key, value] of qsKeyValues) {
104
+ if (value === undefined) {
105
+ currentKeyValues.delete(key);
106
+ }
107
+ else {
108
+ currentKeyValues.set(key, value);
109
+ }
110
+ }
111
+ return unmapQueryString(currentKeyValues);
112
+ }
113
+ /**
114
+ * @returns The current in browser Query String as a Map
115
+ */
116
+ static currentQsKeyValues() {
117
+ return mapQueryString(window.location.search);
118
+ }
119
+ /**
120
+ * If the passed currentState is a CfgIOContainer it will update it with the
121
+ * passed message. If not it will create a new CfgIOContainer with the message.
122
+ */
123
+ static _makeUpdatedState(currentState, message, messageKey) {
124
+ let messages = {};
125
+ if (CfgIOManager.isIOContainer(currentState)) {
126
+ messages = currentState.messages;
127
+ }
128
+ messages[messageKey] = message;
129
+ return CfgIOManager.makeContainer(messages);
130
+ }
131
+ getDataFromEvent(event) {
132
+ return event.state;
133
+ }
134
+ static getMessageFromCurrentHistoryState(messageKey) {
135
+ const state = window.history.state;
136
+ if (!CfgIOManager.isIOContainer(state)) {
137
+ return undefined;
138
+ }
139
+ if (!CfgIOManager.hasIOContainerMessageKey(state, messageKey)) {
140
+ return undefined;
141
+ }
142
+ return CfgIOManager.getMessageFromIOContainer(state, messageKey);
143
+ }
144
+ }
@@ -1,22 +1,22 @@
1
- import { DtoProductConf } from "../CatalogueAPI.js";
2
- import { CfgHistoryManager, CfgHistoryManagerSendData, HistoryMode } from "./CfgHistoryManager.js";
3
- import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
4
- /**
5
- * Instantiating this will make the browser history (and URL) update with the product configuration.
6
- */
7
- export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
8
- private readonly _mode;
9
- private readonly _qsKey;
10
- private static getInitialProdConf;
11
- static make(manager: CfgHistoryManager, mode: HistoryMode, qsKey?: string): {
12
- instance: CfgHistoryToProdConfConnector;
13
- initial: DtoProductConf | undefined;
14
- };
15
- /**
16
- * @param _mode
17
- * @param _qsKey The Query String key for product configuration.
18
- */
19
- private constructor();
20
- protected makeSendData(conf: DtoProductConf, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
21
- }
1
+ import { DtoProductConf } from "../CatalogueAPI.js";
2
+ import { CfgHistoryManager, CfgHistoryManagerSendData, HistoryMode } from "./CfgHistoryManager.js";
3
+ import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
4
+ /**
5
+ * Instantiating this will make the browser history (and URL) update with the product configuration.
6
+ */
7
+ export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
8
+ private readonly _mode;
9
+ private readonly _qsKey;
10
+ private static getInitialProdConf;
11
+ static make(manager: CfgHistoryManager, mode: HistoryMode, qsKey?: string): {
12
+ instance: CfgHistoryToProdConfConnector;
13
+ initial: DtoProductConf | undefined;
14
+ };
15
+ /**
16
+ * @param _mode
17
+ * @param _qsKey The Query String key for product configuration.
18
+ */
19
+ private constructor();
20
+ protected makeSendData(conf: DtoProductConf, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
21
+ }
22
22
  //# sourceMappingURL=CfgHistoryToProdConfConnector.d.ts.map
@@ -1,50 +1,50 @@
1
- import { augmentErrorMessage } from "@configura/web-utilities";
2
- import { CfgProdConfParts, compactStringToDtoProductConf, dtoProductConfigurationToCompactString, } from "../utilitiesConfiguration.js";
3
- import { CfgHistoryManager } from "./CfgHistoryManager.js";
4
- import { CfgIOProdConfConnector, CfgProdConfMessageVersions, getHighestVersionProdConfMessage, isCfgProdConfMessageV2, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
5
- /**
6
- * Instantiating this will make the browser history (and URL) update with the product configuration.
7
- */
8
- export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
9
- /**
10
- * @param _mode
11
- * @param _qsKey The Query String key for product configuration.
12
- */
13
- constructor(manager, _mode, _qsKey) {
14
- super(manager, CfgProdConfParts.SyncGroupState);
15
- this._mode = _mode;
16
- this._qsKey = _qsKey;
17
- }
18
- static getInitialProdConf(qsKey) {
19
- // First try to use the state, if that doesn't work use the query string
20
- const initialMessage = CfgHistoryManager.getMessageFromCurrentHistoryState(STAGE_PROD_CONF_MESSAGE_KEY);
21
- if (initialMessage !== undefined) {
22
- const highestVersionMessage = getHighestVersionProdConfMessage(initialMessage.subMessages);
23
- if (isCfgProdConfMessageV2(highestVersionMessage)) {
24
- return highestVersionMessage.conf;
25
- }
26
- }
27
- try {
28
- const s = CfgHistoryManager.currentQsKeyValues().get(qsKey);
29
- if (s === undefined) {
30
- return undefined;
31
- }
32
- return compactStringToDtoProductConf(s);
33
- }
34
- catch (err) {
35
- throw augmentErrorMessage(err, "Failed read configuration from query string");
36
- }
37
- }
38
- static make(manager, mode, qsKey = STAGE_PROD_CONF_MESSAGE_KEY) {
39
- const initial = this.getInitialProdConf(qsKey);
40
- const instance = new CfgHistoryToProdConfConnector(manager, mode, qsKey);
41
- return { instance, initial };
42
- }
43
- makeSendData(conf, initial) {
44
- return {
45
- message: CfgIOProdConfConnector.makeMessage(conf, initial, CfgProdConfMessageVersions.V2dot0),
46
- qsKeyValues: new Map([[this._qsKey, dtoProductConfigurationToCompactString(conf)]]),
47
- mode: this._mode,
48
- };
49
- }
50
- }
1
+ import { augmentErrorMessage } from "@configura/web-utilities";
2
+ import { CfgProdConfParts, compactStringToDtoProductConf, dtoProductConfigurationToCompactString, } from "../utilitiesConfiguration.js";
3
+ import { CfgHistoryManager } from "./CfgHistoryManager.js";
4
+ import { CfgIOProdConfConnector, CfgProdConfMessageVersions, getHighestVersionProdConfMessage, isCfgProdConfMessageV2, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
5
+ /**
6
+ * Instantiating this will make the browser history (and URL) update with the product configuration.
7
+ */
8
+ export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
9
+ /**
10
+ * @param _mode
11
+ * @param _qsKey The Query String key for product configuration.
12
+ */
13
+ constructor(manager, _mode, _qsKey) {
14
+ super(manager, CfgProdConfParts.SyncGroupState);
15
+ this._mode = _mode;
16
+ this._qsKey = _qsKey;
17
+ }
18
+ static getInitialProdConf(qsKey) {
19
+ // First try to use the state, if that doesn't work use the query string
20
+ const initialMessage = CfgHistoryManager.getMessageFromCurrentHistoryState(STAGE_PROD_CONF_MESSAGE_KEY);
21
+ if (initialMessage !== undefined) {
22
+ const highestVersionMessage = getHighestVersionProdConfMessage(initialMessage.subMessages);
23
+ if (isCfgProdConfMessageV2(highestVersionMessage)) {
24
+ return highestVersionMessage.conf;
25
+ }
26
+ }
27
+ try {
28
+ const s = CfgHistoryManager.currentQsKeyValues().get(qsKey);
29
+ if (s === undefined) {
30
+ return undefined;
31
+ }
32
+ return compactStringToDtoProductConf(s);
33
+ }
34
+ catch (err) {
35
+ throw augmentErrorMessage(err, "Failed read configuration from query string");
36
+ }
37
+ }
38
+ static make(manager, mode, qsKey = STAGE_PROD_CONF_MESSAGE_KEY) {
39
+ const initial = this.getInitialProdConf(qsKey);
40
+ const instance = new CfgHistoryToProdConfConnector(manager, mode, qsKey);
41
+ return { instance, initial };
42
+ }
43
+ makeSendData(conf, initial) {
44
+ return {
45
+ message: CfgIOProdConfConnector.makeMessage(conf, initial, CfgProdConfMessageVersions.V2dot0),
46
+ qsKeyValues: new Map([[this._qsKey, dtoProductConfigurationToCompactString(conf)]]),
47
+ mode: this._mode,
48
+ };
49
+ }
50
+ }
@@ -1,54 +1,54 @@
1
- import { CfgIOWarningSupplier } from "./CfgIOWarningSupplier";
2
- declare type ConfiguraAttribute = "C0nf1gura";
3
- declare type ConfiguraShebang = "arug1fn0C";
4
- declare const CONFIGURA_ATTRIBUTE: ConfiguraAttribute;
5
- export declare type IOManagerListener = (data: unknown) => Promise<void>;
6
- /**
7
- * The container format used when the environment is globally shared with things
8
- * outside our control. The "shebang" is a magic string that should prevent from a
9
- * CfgIOContainer being confused with something else.
10
- */
11
- export declare type CfgIOContainer = {
12
- [CONFIGURA_ATTRIBUTE]: ConfiguraShebang;
13
- messages: {
14
- [index: string]: unknown;
15
- };
16
- };
17
- /**
18
- * Base class for classes handling input and output in globally shared environments.
19
- */
20
- export declare abstract class CfgIOManager<S> {
21
- private _warningSuppliers;
22
- addWarningSupplier(supplier: CfgIOWarningSupplier): void;
23
- removeWarningSupplier(supplier: CfgIOWarningSupplier): void;
24
- getWarnings(): string[];
25
- /**
26
- * Listen for the message messageKey being received.
27
- */
28
- listenForMessage(l: IOManagerListener, messageKey: string): boolean;
29
- /**
30
- * Removes the listener
31
- */
32
- stopListenForMessage(l: IOManagerListener): boolean;
33
- static isIOContainer: (data: unknown) => data is CfgIOContainer;
34
- static hasIOContainerMessageKey: (container: CfgIOContainer, messageKey: string) => boolean;
35
- static getMessageFromIOContainer: (container: unknown, messageKey: string) => unknown;
36
- static makeContainer: (messages: {
37
- [index: string]: unknown;
38
- }) => CfgIOContainer;
39
- private _receiveInProgress;
40
- private static _inhibitAllReceive;
41
- get receiveInProgress(): boolean;
42
- private _messageListeners;
43
- private _getIndexOfMessageListener;
44
- get hasMessageListeners(): boolean;
45
- protected _containerListener(data: unknown): void;
46
- /**
47
- * Send the data with messageKey. This can for example be pushing or
48
- * replacing on the history stack or sending a message using the
49
- * window.message API.
50
- */
51
- abstract send(messageKey: string, data: S): void;
52
- }
53
- export {};
1
+ import { CfgIOWarningSupplier } from "./CfgIOWarningSupplier";
2
+ declare type ConfiguraAttribute = "C0nf1gura";
3
+ declare type ConfiguraShebang = "arug1fn0C";
4
+ declare const CONFIGURA_ATTRIBUTE: ConfiguraAttribute;
5
+ export declare type IOManagerListener = (data: unknown) => Promise<void>;
6
+ /**
7
+ * The container format used when the environment is globally shared with things
8
+ * outside our control. The "shebang" is a magic string that should prevent from a
9
+ * CfgIOContainer being confused with something else.
10
+ */
11
+ export declare type CfgIOContainer = {
12
+ [CONFIGURA_ATTRIBUTE]: ConfiguraShebang;
13
+ messages: {
14
+ [index: string]: unknown;
15
+ };
16
+ };
17
+ /**
18
+ * Base class for classes handling input and output in globally shared environments.
19
+ */
20
+ export declare abstract class CfgIOManager<S> {
21
+ private _warningSuppliers;
22
+ addWarningSupplier(supplier: CfgIOWarningSupplier): void;
23
+ removeWarningSupplier(supplier: CfgIOWarningSupplier): void;
24
+ getWarnings(): string[];
25
+ /**
26
+ * Listen for the message messageKey being received.
27
+ */
28
+ listenForMessage(l: IOManagerListener, messageKey: string): boolean;
29
+ /**
30
+ * Removes the listener
31
+ */
32
+ stopListenForMessage(l: IOManagerListener): boolean;
33
+ static isIOContainer: (data: unknown) => data is CfgIOContainer;
34
+ static hasIOContainerMessageKey: (container: CfgIOContainer, messageKey: string) => boolean;
35
+ static getMessageFromIOContainer: (container: unknown, messageKey: string) => unknown;
36
+ static makeContainer: (messages: {
37
+ [index: string]: unknown;
38
+ }) => CfgIOContainer;
39
+ private _receiveInProgress;
40
+ private static _inhibitAllReceive;
41
+ get receiveInProgress(): boolean;
42
+ private _messageListeners;
43
+ private _getIndexOfMessageListener;
44
+ get hasMessageListeners(): boolean;
45
+ protected _containerListener(data: unknown): void;
46
+ /**
47
+ * Send the data with messageKey. This can for example be pushing or
48
+ * replacing on the history stack or sending a message using the
49
+ * window.message API.
50
+ */
51
+ abstract send(messageKey: string, data: S): void;
52
+ }
53
+ export {};
54
54
  //# sourceMappingURL=CfgIOManager.d.ts.map