@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.
- package/.eslintrc.json +1 -14
- package/dist/CatalogueAPI.d.ts +103 -32
- package/dist/CatalogueAPI.js +62 -6
- package/dist/CfgProduct.d.ts +90 -14
- package/dist/CfgProduct.js +266 -56
- package/dist/CfgReferencePathHelper.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/io/CfgHistoryManager.d.ts +33 -1
- package/dist/io/CfgHistoryManager.js +68 -6
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +11 -10
- package/dist/io/CfgHistoryToProdConfConnector.js +32 -38
- package/dist/io/CfgIOManager.d.ts +5 -0
- package/dist/io/CfgIOManager.js +20 -1
- package/dist/io/CfgIOProdConfConnector.d.ts +17 -18
- package/dist/io/CfgIOProdConfConnector.js +52 -58
- package/dist/io/CfgIOWarningSupplier.d.ts +4 -0
- package/dist/io/CfgIOWarningSupplier.js +1 -0
- package/dist/io/CfgObservableStateToProdConfConnector.d.ts +4 -4
- package/dist/io/CfgObservableStateToProdConfConnector.js +3 -3
- package/dist/io/CfgWindowMessageManager.js +4 -0
- package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +4 -4
- package/dist/io/CfgWindowMessageToProdConfConnector.js +3 -3
- package/dist/productConfiguration/CfgFeature.d.ts +12 -7
- package/dist/productConfiguration/CfgFeature.js +33 -14
- package/dist/productConfiguration/CfgOption.d.ts +16 -10
- package/dist/productConfiguration/CfgOption.js +46 -18
- package/dist/productConfiguration/CfgProductConfiguration.d.ts +27 -16
- package/dist/productConfiguration/CfgProductConfiguration.js +53 -29
- package/dist/productConfiguration/filters.d.ts +6 -4
- package/dist/productConfiguration/filters.js +94 -23
- package/dist/productConfiguration/productParamsGenerator.d.ts +3 -3
- package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +1 -1
- package/dist/productConfiguration/utilitiesProductConfiguration.js +11 -4
- package/dist/productLoader.d.ts +3 -3
- package/dist/productLoader.js +1 -1
- package/dist/syncGroups/SyncGroupsHandler.d.ts +9 -2
- package/dist/syncGroups/SyncGroupsHandler.js +15 -4
- package/dist/syncGroups/SyncGroupsState.d.ts +5 -1
- package/dist/syncGroups/SyncGroupsState.js +44 -2
- package/dist/syncGroups/SyncGroupsTransaction.js +34 -21
- package/dist/tasks/TaskHandler.d.ts +2 -2
- package/dist/tasks/TaskHandler.js +2 -1
- package/dist/tests/testData/dummyProductForTest.d.ts +2 -2
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +14 -9
- package/dist/tests/testData/testDataCachedGetProduct.js +2 -0
- package/dist/tests/testData/testDataCachedPostValidate.js +2 -0
- package/dist/tests/testData/testDataProductAggregatedPrice.js +3 -1
- package/dist/tests/testData/testDataUpcharge.js +2 -0
- package/dist/utilitiesCatalogueData.d.ts +14 -9
- package/dist/utilitiesCatalogueData.js +7 -0
- package/dist/utilitiesCataloguePermission.d.ts +4 -4
- package/dist/utilitiesConfiguration.d.ts +29 -0
- package/dist/utilitiesConfiguration.js +200 -0
- package/dist/utilitiesNumericValues.js +13 -8
- package/package.json +3 -3
- package/dist/ConfigurationConverter.d.ts +0 -5
- package/dist/ConfigurationConverter.js +0 -72
|
@@ -2,6 +2,21 @@ import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
|
2
2
|
declare type CfgHistoryManagerMessageData = {
|
|
3
3
|
initial: boolean;
|
|
4
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* How the history is updated.
|
|
7
|
+
* @param DoNotWrite Only listens to initial URL-values.
|
|
8
|
+
* @param Replace Replaces the current history frame at updates.
|
|
9
|
+
* @param Push Adds history frames at updates.
|
|
10
|
+
* @param ReplaceAndUpdateUrl Replaces the current history frame at updates and updates the browser URL
|
|
11
|
+
* @param PushAndUpdateUrl Adds history frames at updates and updates the browser URL
|
|
12
|
+
*/
|
|
13
|
+
export declare enum HistoryMode {
|
|
14
|
+
DoNotWrite = 0,
|
|
15
|
+
Replace = 1,
|
|
16
|
+
Push = 2,
|
|
17
|
+
ReplaceAndUpdateUrl = 3,
|
|
18
|
+
PushAndUpdateUrl = 4
|
|
19
|
+
}
|
|
5
20
|
/**
|
|
6
21
|
* The collected data used when sending. For history this both contains the message, which is
|
|
7
22
|
* used as the "state" in the history-frame, and the qsKeyValues, which are query string
|
|
@@ -11,7 +26,7 @@ declare type CfgHistoryManagerMessageData = {
|
|
|
11
26
|
*/
|
|
12
27
|
export declare type CfgHistoryManagerSendData<D> = {
|
|
13
28
|
message: D;
|
|
14
|
-
|
|
29
|
+
mode: HistoryMode;
|
|
15
30
|
qsKeyValues: Map<string, string | undefined>;
|
|
16
31
|
};
|
|
17
32
|
/**
|
|
@@ -22,6 +37,22 @@ export declare class CfgHistoryManager extends CfgWindowEventManager<"popstate",
|
|
|
22
37
|
private static _instance;
|
|
23
38
|
static get instance(): CfgHistoryManager;
|
|
24
39
|
private constructor();
|
|
40
|
+
private _aggregatedQsKeyValues;
|
|
41
|
+
private _urlUpdateObservable;
|
|
42
|
+
/**
|
|
43
|
+
* @returns The current browser URL updated with the latest updates from
|
|
44
|
+
* the Connectors.
|
|
45
|
+
*/
|
|
46
|
+
getUrl(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Listen for updated URL:s. This doesn't have to mean the URL in the
|
|
49
|
+
* browser has been updated.
|
|
50
|
+
*/
|
|
51
|
+
listenForUrl(listener: (url: string) => void): void;
|
|
52
|
+
/**
|
|
53
|
+
* Stop listen.
|
|
54
|
+
*/
|
|
55
|
+
stopListenForUrl(listener: (url: string) => void): void;
|
|
25
56
|
/**
|
|
26
57
|
* Write to the history
|
|
27
58
|
*/
|
|
@@ -47,6 +78,7 @@ export declare class CfgHistoryManager extends CfgWindowEventManager<"popstate",
|
|
|
47
78
|
private static _makeUpdatedState;
|
|
48
79
|
protected readonly eventType = "popstate";
|
|
49
80
|
protected getDataFromEvent(event: PopStateEvent): unknown;
|
|
81
|
+
static getMessageFromCurrentHistoryState(messageKey: string): unknown | undefined;
|
|
50
82
|
}
|
|
51
83
|
export {};
|
|
52
84
|
//# sourceMappingURL=CfgHistoryManager.d.ts.map
|
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
import { mapQueryString, unmapQueryString } from "@configura/web-utilities";
|
|
1
|
+
import { mapQueryString, Observable, unmapQueryString } from "@configura/web-utilities";
|
|
2
2
|
import { CfgIOManager } from "./CfgIOManager.js";
|
|
3
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 = {}));
|
|
4
20
|
/**
|
|
5
21
|
* This class is used to coordinate writing and reading to the browser history.
|
|
6
22
|
* It handles messages sent from the connectors.
|
|
@@ -8,6 +24,8 @@ import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
|
8
24
|
export class CfgHistoryManager extends CfgWindowEventManager {
|
|
9
25
|
constructor() {
|
|
10
26
|
super();
|
|
27
|
+
this._aggregatedQsKeyValues = new Map();
|
|
28
|
+
this._urlUpdateObservable = new Observable();
|
|
11
29
|
this.eventType = "popstate";
|
|
12
30
|
}
|
|
13
31
|
static get instance() {
|
|
@@ -16,22 +34,56 @@ export class CfgHistoryManager extends CfgWindowEventManager {
|
|
|
16
34
|
}
|
|
17
35
|
return this._instance;
|
|
18
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
|
+
}
|
|
19
57
|
/**
|
|
20
58
|
* Write to the history
|
|
21
59
|
*/
|
|
22
60
|
send(messageKey, data) {
|
|
23
|
-
const { qsKeyValues, message,
|
|
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
|
+
}
|
|
24
69
|
// Initial data is before user interaction has happened
|
|
25
70
|
const initial = message.initial;
|
|
71
|
+
const url = CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
|
|
26
72
|
// At initial we do not replace the URL as we presumable have the defaults
|
|
27
|
-
const
|
|
73
|
+
const writeUrl = initial ||
|
|
74
|
+
!(mode === HistoryMode.PushAndUpdateUrl || mode === HistoryMode.ReplaceAndUpdateUrl)
|
|
75
|
+
? null
|
|
76
|
+
: url;
|
|
28
77
|
// ...but we do replace the state so that we can in the future browse back to here
|
|
29
78
|
const newState = CfgHistoryManager._makeUpdatedState(window.history.state, message, messageKey);
|
|
30
|
-
if (initial ||
|
|
31
|
-
|
|
79
|
+
if (initial ||
|
|
80
|
+
mode === HistoryMode.Replace ||
|
|
81
|
+
mode === HistoryMode.ReplaceAndUpdateUrl ||
|
|
82
|
+
this.receiveInProgress) {
|
|
83
|
+
window.history.replaceState(newState, "", writeUrl);
|
|
32
84
|
}
|
|
33
85
|
else {
|
|
34
|
-
window.history.pushState(newState, "",
|
|
86
|
+
window.history.pushState(newState, "", writeUrl);
|
|
35
87
|
}
|
|
36
88
|
}
|
|
37
89
|
/**
|
|
@@ -79,4 +131,14 @@ export class CfgHistoryManager extends CfgWindowEventManager {
|
|
|
79
131
|
getDataFromEvent(event) {
|
|
80
132
|
return event.state;
|
|
81
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
|
+
}
|
|
82
144
|
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
|
|
1
|
+
import { DtoProductConf } from "../CatalogueAPI.js";
|
|
2
|
+
import { CfgHistoryManager, CfgHistoryManagerSendData, HistoryMode } from "./CfgHistoryManager.js";
|
|
3
3
|
import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
|
|
4
|
-
export declare function dtoConfToString(conf: DtoProductConfiguration): string;
|
|
5
|
-
export declare function stringToDtoConf(conf: string): DtoProductConfiguration;
|
|
6
4
|
/**
|
|
7
5
|
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
8
6
|
*/
|
|
9
7
|
export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
|
|
10
|
-
private readonly
|
|
8
|
+
private readonly _mode;
|
|
11
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
|
+
};
|
|
12
15
|
/**
|
|
13
|
-
* @param
|
|
16
|
+
* @param _mode
|
|
14
17
|
* @param _qsKey The Query String key for product configuration.
|
|
15
|
-
* @param doValidate When popping from the history stack (navigating in the browser), should a navigate call be sent to the server to verify that the product configuration is still valid?
|
|
16
18
|
*/
|
|
17
|
-
constructor(
|
|
18
|
-
protected
|
|
19
|
-
protected makeSendData(conf: DtoProductConfiguration, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
|
|
19
|
+
private constructor();
|
|
20
|
+
protected makeSendData(conf: DtoProductConf, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
|
|
20
21
|
}
|
|
21
22
|
//# sourceMappingURL=CfgHistoryToProdConfConnector.d.ts.map
|
|
@@ -1,56 +1,50 @@
|
|
|
1
|
+
import { augmentErrorMessage } from "@configura/web-utilities";
|
|
2
|
+
import { CfgProdConfParts, compactStringToDtoProductConf, dtoProductConfigurationToCompactString, } from "../utilitiesConfiguration.js";
|
|
1
3
|
import { CfgHistoryManager } from "./CfgHistoryManager.js";
|
|
2
|
-
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
|
|
3
|
-
const jsonKeyRegex = /"([^"]+)":/g;
|
|
4
|
-
const keyMap = [
|
|
5
|
-
["configuration", "cn"],
|
|
6
|
-
["additionalProducts", "as"],
|
|
7
|
-
["prodParams", "pp"],
|
|
8
|
-
["refKey", "rk"],
|
|
9
|
-
["selected", "se"],
|
|
10
|
-
["features", "fs"],
|
|
11
|
-
["code", "cd"],
|
|
12
|
-
["options", "os"],
|
|
13
|
-
["numericValue", "nu"],
|
|
14
|
-
["groupCode", "gc"],
|
|
15
|
-
["unit", "un"],
|
|
16
|
-
];
|
|
17
|
-
// todo: Could be worth making faster
|
|
18
|
-
const toCompact = (key) => { var _a, _b; return (_b = (_a = keyMap.find((i) => i[0] === key)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : key; };
|
|
19
|
-
const toExpanded = (key) => { var _a, _b; return (_b = (_a = keyMap.find((i) => i[1] === key)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : key; };
|
|
20
|
-
export function dtoConfToString(conf) {
|
|
21
|
-
const stringified = JSON.stringify(conf, undefined, "");
|
|
22
|
-
return stringified.replace(jsonKeyRegex, (_, key) => `"${toCompact(key)}":`);
|
|
23
|
-
}
|
|
24
|
-
export function stringToDtoConf(conf) {
|
|
25
|
-
const expandedKeys = conf.replace(jsonKeyRegex, (_, key) => `"${toExpanded(key)}":`);
|
|
26
|
-
return JSON.parse(expandedKeys);
|
|
27
|
-
}
|
|
4
|
+
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, getHighestVersionProdConfMessage, isCfgProdConfMessageV2, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
|
|
28
5
|
/**
|
|
29
6
|
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
30
7
|
*/
|
|
31
8
|
export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
32
9
|
/**
|
|
33
|
-
* @param
|
|
10
|
+
* @param _mode
|
|
34
11
|
* @param _qsKey The Query String key for product configuration.
|
|
35
|
-
* @param doValidate When popping from the history stack (navigating in the browser), should a navigate call be sent to the server to verify that the product configuration is still valid?
|
|
36
12
|
*/
|
|
37
|
-
constructor(manager,
|
|
38
|
-
super(manager,
|
|
39
|
-
this.
|
|
13
|
+
constructor(manager, _mode, _qsKey) {
|
|
14
|
+
super(manager, CfgProdConfParts.SyncGroupState);
|
|
15
|
+
this._mode = _mode;
|
|
40
16
|
this._qsKey = _qsKey;
|
|
41
17
|
}
|
|
42
|
-
getInitialProdConf() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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);
|
|
46
33
|
}
|
|
47
|
-
|
|
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 };
|
|
48
42
|
}
|
|
49
43
|
makeSendData(conf, initial) {
|
|
50
44
|
return {
|
|
51
45
|
message: CfgIOProdConfConnector.makeMessage(conf, initial, CfgProdConfMessageVersions.V2dot0),
|
|
52
|
-
qsKeyValues: new Map([[
|
|
53
|
-
|
|
46
|
+
qsKeyValues: new Map([[this._qsKey, dtoProductConfigurationToCompactString(conf)]]),
|
|
47
|
+
mode: this._mode,
|
|
54
48
|
};
|
|
55
49
|
}
|
|
56
50
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CfgIOWarningSupplier } from "./CfgIOWarningSupplier";
|
|
1
2
|
declare type ConfiguraAttribute = "C0nf1gura";
|
|
2
3
|
declare type ConfiguraShebang = "arug1fn0C";
|
|
3
4
|
declare const CONFIGURA_ATTRIBUTE: ConfiguraAttribute;
|
|
@@ -17,6 +18,10 @@ export declare type CfgIOContainer = {
|
|
|
17
18
|
* Base class for classes handling input and output in globally shared environments.
|
|
18
19
|
*/
|
|
19
20
|
export declare abstract class CfgIOManager<S> {
|
|
21
|
+
private _warningSuppliers;
|
|
22
|
+
addWarningSupplier(supplier: CfgIOWarningSupplier): void;
|
|
23
|
+
removeWarningSupplier(supplier: CfgIOWarningSupplier): void;
|
|
24
|
+
getWarnings(): string[];
|
|
20
25
|
/**
|
|
21
26
|
* Listen for the message messageKey being received.
|
|
22
27
|
*/
|
package/dist/io/CfgIOManager.js
CHANGED
|
@@ -18,12 +18,31 @@ const hasConfiguraAttribute = (data) => {
|
|
|
18
18
|
*/
|
|
19
19
|
export class CfgIOManager {
|
|
20
20
|
constructor() {
|
|
21
|
+
this._warningSuppliers = [];
|
|
21
22
|
// A lock to avoid circular write. Asynchronous conditions can make this not be enough.
|
|
22
23
|
// Avoid creating pre-conditions where this can happen.
|
|
23
24
|
this._receiveInProgress = false;
|
|
24
25
|
this._messageListeners = [];
|
|
25
26
|
this._getIndexOfMessageListener = (l) => this._messageListeners.findIndex((item) => l === item.l);
|
|
26
27
|
}
|
|
28
|
+
addWarningSupplier(supplier) {
|
|
29
|
+
this._warningSuppliers.push(supplier);
|
|
30
|
+
}
|
|
31
|
+
removeWarningSupplier(supplier) {
|
|
32
|
+
const i = this._warningSuppliers.indexOf(supplier);
|
|
33
|
+
if (i === -1) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this._warningSuppliers.splice(i, 1);
|
|
37
|
+
}
|
|
38
|
+
getWarnings() {
|
|
39
|
+
return this._warningSuppliers.reduce((aggregated, supplier) => {
|
|
40
|
+
for (const warning of supplier.getWarnings()) {
|
|
41
|
+
aggregated.push(warning);
|
|
42
|
+
}
|
|
43
|
+
return aggregated;
|
|
44
|
+
}, []);
|
|
45
|
+
}
|
|
27
46
|
/**
|
|
28
47
|
* Listen for the message messageKey being received.
|
|
29
48
|
*/
|
|
@@ -81,7 +100,7 @@ export class CfgIOManager {
|
|
|
81
100
|
if (item.messageKey !== messageKey) {
|
|
82
101
|
continue;
|
|
83
102
|
}
|
|
84
|
-
// async, not waiting. Might need to change.
|
|
103
|
+
// async, not waiting on each other. Might need to change.
|
|
85
104
|
promises.push(item.l(message));
|
|
86
105
|
}
|
|
87
106
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { DtoAdditionalProductConfiguration,
|
|
1
|
+
import { DtoAdditionalProductConfiguration, DtoProductConf } from "../CatalogueAPI.js";
|
|
2
2
|
import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
|
|
3
|
+
import { CfgProdConfParts } from "../utilitiesConfiguration.js";
|
|
3
4
|
import { CfgIOManager } from "./CfgIOManager.js";
|
|
5
|
+
import { CfgIOWarningSupplier } from "./CfgIOWarningSupplier.js";
|
|
4
6
|
export declare const isCfgProdConfMessage: (data: unknown) => data is CfgProdConfMessageV1 | CfgProdConfMessageV2;
|
|
5
7
|
export declare type CfgProdConfMessageV1 = {
|
|
6
8
|
version: "1.0";
|
|
@@ -9,7 +11,7 @@ export declare type CfgProdConfMessageV1 = {
|
|
|
9
11
|
export declare const isCfgProdConfMessageV1: (data: unknown) => data is CfgProdConfMessageV1;
|
|
10
12
|
export declare type CfgProdConfMessageV2 = {
|
|
11
13
|
version: "2.0";
|
|
12
|
-
conf:
|
|
14
|
+
conf: DtoProductConf;
|
|
13
15
|
};
|
|
14
16
|
export declare const isCfgProdConfMessageV2: (data: unknown) => data is CfgProdConfMessageV2;
|
|
15
17
|
export declare type CfgProdConfMessage = {
|
|
@@ -23,34 +25,31 @@ export declare enum CfgProdConfMessageVersions {
|
|
|
23
25
|
}
|
|
24
26
|
export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
|
|
25
27
|
declare type ProdConfMessageCallback = (message: CfgProdConfMessage) => Promise<void>;
|
|
26
|
-
declare type ProdConfCallback = (conf:
|
|
28
|
+
declare type ProdConfCallback = (conf: DtoProductConf) => Promise<void>;
|
|
27
29
|
/**
|
|
28
30
|
* Base class for connecting the product configuration to an IO channel
|
|
29
31
|
*/
|
|
30
|
-
export declare abstract class CfgIOProdConfConnector<S> {
|
|
31
|
-
|
|
32
|
-
private readonly
|
|
33
|
-
|
|
34
|
-
private readonly _includeProdParamsInSend;
|
|
35
|
-
private _product;
|
|
32
|
+
export declare abstract class CfgIOProdConfConnector<S> implements CfgIOWarningSupplier {
|
|
33
|
+
protected readonly _ioManager: CfgIOManager<S>;
|
|
34
|
+
private readonly _includeInSend;
|
|
35
|
+
protected _product: CfgProduct | undefined;
|
|
36
36
|
private _stopListenToMessage;
|
|
37
37
|
private _stopListenToProdConf;
|
|
38
|
-
constructor(_ioManager: CfgIOManager<S>,
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
constructor(_ioManager: CfgIOManager<S>, _includeInSend: CfgProdConfParts);
|
|
39
|
+
destroy(): void;
|
|
40
|
+
getWarnings(): string[];
|
|
41
41
|
setProduct: (product: CfgProduct | undefined) => Promise<void>;
|
|
42
42
|
private _send;
|
|
43
|
-
protected
|
|
44
|
-
|
|
45
|
-
static
|
|
46
|
-
static makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
|
|
43
|
+
protected abstract makeSendData(conf: DtoProductConf, initial: boolean): S;
|
|
44
|
+
static makeMessage: (conf: DtoProductConf, initial: boolean, sendVersions: CfgProdConfMessageVersions) => CfgProdConfMessage;
|
|
45
|
+
static makeMessageListener: (callback: ProdConfMessageCallback) => (message: unknown) => Promise<void>;
|
|
47
46
|
/**
|
|
48
47
|
* Register the callback to listen for Product Configuration messages
|
|
49
48
|
* @returns A function which when called will cancel listening
|
|
50
49
|
*/
|
|
51
50
|
static listenForMessage<S>(callback: ProdConfMessageCallback, ioManager: CfgIOManager<S>): () => void;
|
|
52
|
-
static makeProdConfListener(callback: ProdConfCallback,
|
|
53
|
-
static listenForProdConf(product: CfgProduct, callback: ProdConfCallback,
|
|
51
|
+
static makeProdConfListener: (callback: ProdConfCallback, includeInSend: CfgProdConfParts) => (n: CfgProductChangeNotification) => void;
|
|
52
|
+
static listenForProdConf(product: CfgProduct, callback: ProdConfCallback, includeInSend: CfgProdConfParts): () => void;
|
|
54
53
|
}
|
|
55
54
|
export {};
|
|
56
55
|
//# sourceMappingURL=CfgIOProdConfConnector.d.ts.map
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { convertDtoProductConfToV1 } from "../utilitiesConfiguration.js";
|
|
11
11
|
export const isCfgProdConfMessage = (data) => typeof data === "object" && data !== null && "version" in data && "conf" in data;
|
|
12
12
|
export const isCfgProdConfMessageV1 = (data) => isCfgProdConfMessage(data) && data.version === "1.0";
|
|
13
13
|
export const isCfgProdConfMessageV2 = (data) => isCfgProdConfMessage(data) && data.version === "2.0";
|
|
@@ -24,20 +24,12 @@ export const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
|
|
|
24
24
|
* Base class for connecting the product configuration to an IO channel
|
|
25
25
|
*/
|
|
26
26
|
export class CfgIOProdConfConnector {
|
|
27
|
-
constructor(_ioManager,
|
|
28
|
-
_includeProdParamsInSend // Only v2.0
|
|
27
|
+
constructor(_ioManager, _includeInSend // Only for v2.0
|
|
29
28
|
) {
|
|
30
29
|
this._ioManager = _ioManager;
|
|
31
|
-
this.
|
|
32
|
-
this._includeExtendedDataInSend = _includeExtendedDataInSend;
|
|
33
|
-
this._includeProdParamsInSend = _includeProdParamsInSend;
|
|
30
|
+
this._includeInSend = _includeInSend;
|
|
34
31
|
this._stopListenToMessage = undefined;
|
|
35
32
|
this._stopListenToProdConf = undefined;
|
|
36
|
-
this.destroy = () => {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
(_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
39
|
-
(_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
40
|
-
};
|
|
41
33
|
this.setProduct = (product) => __awaiter(this, void 0, void 0, function* () {
|
|
42
34
|
var _a, _b;
|
|
43
35
|
const currentProduct = this._product;
|
|
@@ -56,14 +48,7 @@ export class CfgIOProdConfConnector {
|
|
|
56
48
|
if (newProduct === undefined) {
|
|
57
49
|
return;
|
|
58
50
|
}
|
|
59
|
-
|
|
60
|
-
if (currentProduct === undefined) {
|
|
61
|
-
const initialProdConf = this.getInitialProdConf();
|
|
62
|
-
if (initialProdConf !== undefined) {
|
|
63
|
-
yield newProduct.setDtoConf(initialProdConf, this._doValidate);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this._send(this.makeSendData(newProduct.getDtoConf(this._includeExtendedDataInSend, this._includeProdParamsInSend), true));
|
|
51
|
+
this._send(this.makeSendData(newProduct.getDtoConf(this._includeInSend), true));
|
|
67
52
|
this._stopListenToMessage = CfgIOProdConfConnector.listenForMessage((messages) => __awaiter(this, void 0, void 0, function* () {
|
|
68
53
|
const subMessages = messages.subMessages;
|
|
69
54
|
if (subMessages.length === 0) {
|
|
@@ -72,47 +57,34 @@ export class CfgIOProdConfConnector {
|
|
|
72
57
|
}
|
|
73
58
|
const highestVersionMessage = getHighestVersionProdConfMessage(subMessages);
|
|
74
59
|
if (isCfgProdConfMessageV1(highestVersionMessage)) {
|
|
75
|
-
yield newProduct.setApiSelection(highestVersionMessage.conf
|
|
60
|
+
yield newProduct.setApiSelection(highestVersionMessage.conf);
|
|
76
61
|
return;
|
|
77
62
|
}
|
|
78
63
|
if (isCfgProdConfMessageV2(highestVersionMessage)) {
|
|
79
|
-
yield newProduct.setDtoConf(highestVersionMessage.conf
|
|
64
|
+
yield newProduct.setDtoConf(highestVersionMessage.conf);
|
|
80
65
|
return;
|
|
81
66
|
}
|
|
82
67
|
throw new Error("Unknown message version");
|
|
83
68
|
}), this._ioManager);
|
|
84
|
-
this._stopListenToProdConf = CfgIOProdConfConnector.listenForProdConf(newProduct, (conf) => __awaiter(this, void 0, void 0, function* () { return this._send(this.makeSendData(conf, false)); }), this.
|
|
69
|
+
this._stopListenToProdConf = CfgIOProdConfConnector.listenForProdConf(newProduct, (conf) => __awaiter(this, void 0, void 0, function* () { return this._send(this.makeSendData(conf, false)); }), this._includeInSend);
|
|
85
70
|
});
|
|
86
71
|
this._send = (data) => this._ioManager.send(STAGE_PROD_CONF_MESSAGE_KEY, data);
|
|
72
|
+
_ioManager.addWarningSupplier(this);
|
|
87
73
|
}
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
destroy() {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
(_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
77
|
+
(_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
78
|
+
this._ioManager.removeWarningSupplier(this);
|
|
90
79
|
}
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
conf: convertDtoConfProdToV1(conf, true),
|
|
98
|
-
};
|
|
99
|
-
result.push(v1);
|
|
100
|
-
}
|
|
101
|
-
if ((sendVersions & CfgProdConfMessageVersions.V2dot0) ===
|
|
102
|
-
CfgProdConfMessageVersions.V2dot0) {
|
|
103
|
-
const v2 = {
|
|
104
|
-
version: "2.0",
|
|
105
|
-
conf,
|
|
106
|
-
};
|
|
107
|
-
result.push(v2);
|
|
80
|
+
getWarnings() {
|
|
81
|
+
const product = this._product;
|
|
82
|
+
if (product !== undefined && product.hasRootFeaturesChanged) {
|
|
83
|
+
return [
|
|
84
|
+
"In at least one of the Products, Functional Selection has taken place, thereby changing what root Features are used. The SDK can not yet apply a serialized configuration in these cases. Extracting this data from the SDK for external applications can work, but reinserting the data into Stage will most likely fail.",
|
|
85
|
+
];
|
|
108
86
|
}
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
static makeMessageListener(callback) {
|
|
112
|
-
return (message) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const prodConfMessage = message;
|
|
114
|
-
yield callback(prodConfMessage);
|
|
115
|
-
});
|
|
87
|
+
return [];
|
|
116
88
|
}
|
|
117
89
|
/**
|
|
118
90
|
* Register the callback to listen for Product Configuration messages
|
|
@@ -125,19 +97,41 @@ export class CfgIOProdConfConnector {
|
|
|
125
97
|
ioManager.stopListenForMessage(listener);
|
|
126
98
|
};
|
|
127
99
|
}
|
|
128
|
-
static
|
|
129
|
-
|
|
130
|
-
if (!n.committed) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
callback(n.freshRef.getDtoConf(includeExtendedDataInSend, includeProdParamsInSend));
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
static listenForProdConf(product, callback, includeExtendedDataInSend, includeProdParamsInSend) {
|
|
137
|
-
const listener = this.makeProdConfListener(callback, includeExtendedDataInSend, includeProdParamsInSend);
|
|
100
|
+
static listenForProdConf(product, callback, includeInSend) {
|
|
101
|
+
const listener = this.makeProdConfListener(callback, includeInSend);
|
|
138
102
|
product.listenForChange(listener);
|
|
139
103
|
return () => {
|
|
140
104
|
product.stopListenForChange(listener);
|
|
141
105
|
};
|
|
142
106
|
}
|
|
143
107
|
}
|
|
108
|
+
CfgIOProdConfConnector.makeMessage = (conf, initial, sendVersions) => {
|
|
109
|
+
const result = [];
|
|
110
|
+
if ((sendVersions & CfgProdConfMessageVersions.V1dot0) ===
|
|
111
|
+
CfgProdConfMessageVersions.V1dot0) {
|
|
112
|
+
const v1 = {
|
|
113
|
+
version: "1.0",
|
|
114
|
+
conf: convertDtoProductConfToV1(conf, true),
|
|
115
|
+
};
|
|
116
|
+
result.push(v1);
|
|
117
|
+
}
|
|
118
|
+
if ((sendVersions & CfgProdConfMessageVersions.V2dot0) ===
|
|
119
|
+
CfgProdConfMessageVersions.V2dot0) {
|
|
120
|
+
const v2 = {
|
|
121
|
+
version: "2.0",
|
|
122
|
+
conf,
|
|
123
|
+
};
|
|
124
|
+
result.push(v2);
|
|
125
|
+
}
|
|
126
|
+
return { subMessages: result, initial };
|
|
127
|
+
};
|
|
128
|
+
CfgIOProdConfConnector.makeMessageListener = (callback) => (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
const prodConfMessage = message;
|
|
130
|
+
yield callback(prodConfMessage);
|
|
131
|
+
});
|
|
132
|
+
CfgIOProdConfConnector.makeProdConfListener = (callback, includeInSend) => (n) => {
|
|
133
|
+
if (!n.committed) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
callback(n.freshRef.getDtoConf(includeInSend));
|
|
137
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DtoProductConf } from "../CatalogueAPI.js";
|
|
2
|
+
import { CfgProdConfParts } from "../utilitiesConfiguration.js";
|
|
2
3
|
import { CfgIOProdConfConnector, CfgProdConfMessage, CfgProdConfMessageVersions } from "./CfgIOProdConfConnector.js";
|
|
3
4
|
import { CfgObservableStateManager } from "./CfgObservableStateManager.js";
|
|
4
5
|
/**
|
|
5
6
|
* Instantiating this will make the observable state update with the product configuration.
|
|
6
|
-
* @param doValidate Run server side product validation for incoming
|
|
7
7
|
* @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
|
|
8
8
|
* @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
|
|
9
9
|
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
10
10
|
*/
|
|
11
11
|
export declare class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector<CfgProdConfMessage> {
|
|
12
12
|
private _sendVersions;
|
|
13
|
-
constructor(manager: CfgObservableStateManager,
|
|
14
|
-
protected makeSendData(conf:
|
|
13
|
+
constructor(manager: CfgObservableStateManager, _sendVersions?: CfgProdConfMessageVersions, includeInSend?: CfgProdConfParts);
|
|
14
|
+
protected makeSendData(conf: DtoProductConf, initial: boolean): CfgProdConfMessage;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=CfgObservableStateToProdConfConnector.d.ts.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { CfgProdConfParts } from "../utilitiesConfiguration.js";
|
|
1
2
|
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, } from "./CfgIOProdConfConnector.js";
|
|
2
3
|
/**
|
|
3
4
|
* Instantiating this will make the observable state update with the product configuration.
|
|
4
|
-
* @param doValidate Run server side product validation for incoming
|
|
5
5
|
* @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
|
|
6
6
|
* @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
|
|
7
7
|
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
8
8
|
*/
|
|
9
9
|
export class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector {
|
|
10
|
-
constructor(manager,
|
|
11
|
-
super(manager,
|
|
10
|
+
constructor(manager, _sendVersions = CfgProdConfMessageVersions.V2dot0, includeInSend = CfgProdConfParts.NoExtra) {
|
|
11
|
+
super(manager, includeInSend);
|
|
12
12
|
this._sendVersions = _sendVersions;
|
|
13
13
|
}
|
|
14
14
|
makeSendData(conf, initial) {
|
|
@@ -70,6 +70,10 @@ export class CfgWindowMessageManager extends CfgWindowEventManager {
|
|
|
70
70
|
const container = CfgIOManager.makeContainer({
|
|
71
71
|
[messageKey]: data,
|
|
72
72
|
});
|
|
73
|
+
const warnings = this.getWarnings();
|
|
74
|
+
if (warnings.length !== 0) {
|
|
75
|
+
warnings.forEach((w) => console.warn(w));
|
|
76
|
+
}
|
|
73
77
|
for (const remoteEnd of this._remoteEnds) {
|
|
74
78
|
remoteEnd.postMessage(container, this._targetOrigin);
|
|
75
79
|
}
|