@configura/web-api 1.6.1 → 2.0.0-alpha.2
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 +18 -18
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/CatalogueAPI.d.ts +551 -507
- package/dist/CatalogueAPI.js +293 -280
- package/dist/CfgMeasure.d.ts +32 -32
- package/dist/CfgMeasure.js +30 -30
- package/dist/CfgProduct.d.ts +268 -258
- package/dist/CfgProduct.js +778 -747
- package/dist/CfgReferencePathHelper.d.ts +14 -0
- package/dist/CfgReferencePathHelper.js +13 -0
- package/dist/ConfigurationConverter.d.ts +5 -0
- package/dist/ConfigurationConverter.js +72 -0
- package/dist/index.d.ts +23 -20
- package/dist/index.js +23 -20
- package/dist/io/CfgHistoryManager.d.ts +51 -0
- package/dist/io/CfgHistoryManager.js +82 -0
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -0
- package/dist/io/CfgHistoryToProdConfConnector.js +56 -0
- package/dist/io/CfgIOManager.d.ts +49 -0
- package/dist/io/CfgIOManager.js +115 -0
- package/dist/io/CfgIOProdConfConnector.d.ts +53 -0
- package/dist/io/CfgIOProdConfConnector.js +141 -0
- package/dist/io/CfgObservableStateManager.d.ts +22 -0
- package/dist/io/CfgObservableStateManager.js +65 -0
- package/dist/io/CfgObservableStateToProdConfConnector.d.ts +15 -0
- package/dist/io/CfgObservableStateToProdConfConnector.js +16 -0
- package/dist/io/CfgWindowEventManager.d.ts +22 -0
- package/dist/io/CfgWindowEventManager.js +38 -0
- package/dist/io/CfgWindowMessageManager.d.ts +41 -0
- package/dist/io/CfgWindowMessageManager.js +84 -0
- package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +17 -0
- package/dist/io/CfgWindowMessageToProdConfConnector.js +18 -0
- package/dist/io/index.d.ts +9 -0
- package/dist/io/index.js +8 -0
- package/dist/material/CfgMaterialMapping.d.ts +7 -7
- package/dist/material/CfgMaterialMapping.js +181 -181
- package/dist/material/CfgMtrlApplication.d.ts +18 -18
- package/dist/material/CfgMtrlApplication.js +43 -43
- package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
- package/dist/material/CfgMtrlApplicationSource.js +8 -8
- package/dist/material/CfgMtrlSource.d.ts +19 -19
- package/dist/material/CfgMtrlSource.js +40 -40
- package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
- package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
- package/dist/productConfiguration/CfgFeature.d.ts +187 -188
- package/dist/productConfiguration/CfgFeature.js +645 -636
- package/dist/productConfiguration/CfgOption.d.ts +151 -150
- package/dist/productConfiguration/CfgOption.js +416 -426
- package/dist/productConfiguration/CfgProductConfiguration.d.ts +117 -120
- package/dist/productConfiguration/CfgProductConfiguration.js +307 -309
- package/dist/productConfiguration/filters.d.ts +15 -15
- package/dist/productConfiguration/filters.js +70 -70
- package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
- package/dist/productConfiguration/productParamsGenerator.js +51 -51
- package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
- package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -80
- package/dist/productLoader.d.ts +33 -33
- package/dist/productLoader.js +49 -49
- package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
- package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
- package/dist/syncGroups/SyncGroupsHandler.d.ts +40 -40
- package/dist/syncGroups/SyncGroupsHandler.js +359 -358
- package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
- package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
- package/dist/syncGroups/SyncGroupsState.d.ts +35 -35
- package/dist/syncGroups/SyncGroupsState.js +125 -125
- package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
- package/dist/syncGroups/SyncGroupsTransaction.js +576 -576
- package/dist/tasks/TaskHandler.d.ts +77 -78
- package/dist/tasks/TaskHandler.js +275 -276
- package/dist/tasks/formats.d.ts +4 -4
- package/dist/tasks/formats.js +7 -7
- package/dist/tests/testData/collectorForTest.d.ts +73 -73
- package/dist/tests/testData/collectorForTest.js +194 -194
- package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
- package/dist/tests/testData/dummyProductForTest.js +32 -36
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +277 -277
- package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
- package/dist/tests/testData/testDataCachedGetProduct.js +185 -185
- package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
- package/dist/tests/testData/testDataCachedPostValidate.js +183 -183
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
- package/dist/tests/testData/testDataOptions.d.ts +12 -12
- package/dist/tests/testData/testDataOptions.js +60 -60
- package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
- package/dist/tests/testData/testDataProductAggregatedPrice.js +187 -187
- package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
- package/dist/tests/testData/testDataUpcharge.js +119 -119
- package/dist/utilitiesCatalogueData.d.ts +42 -31
- package/dist/utilitiesCatalogueData.js +173 -162
- package/dist/utilitiesCataloguePermission.d.ts +38 -37
- package/dist/utilitiesCataloguePermission.js +79 -80
- package/dist/utilitiesNumericValues.d.ts +24 -24
- package/dist/utilitiesNumericValues.js +109 -109
- package/package.json +3 -3
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { convertDtoConfProdToV1 } from "../ConfigurationConverter.js";
|
|
11
|
+
export var CfgProdConfMessageVersions;
|
|
12
|
+
(function (CfgProdConfMessageVersions) {
|
|
13
|
+
CfgProdConfMessageVersions[CfgProdConfMessageVersions["V1dot0"] = 1] = "V1dot0";
|
|
14
|
+
CfgProdConfMessageVersions[CfgProdConfMessageVersions["V2dot0"] = 2] = "V2dot0";
|
|
15
|
+
})(CfgProdConfMessageVersions || (CfgProdConfMessageVersions = {}));
|
|
16
|
+
export const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
|
|
17
|
+
/**
|
|
18
|
+
* Base class for connecting the product configuration to an IO channel
|
|
19
|
+
*/
|
|
20
|
+
export class CfgIOProdConfConnector {
|
|
21
|
+
constructor(_ioManager, _doValidate, _sendVersions, _includeExtendedDataInSend, // Only v2.0
|
|
22
|
+
_includeProdParamsInSend // Only v2.0
|
|
23
|
+
) {
|
|
24
|
+
this._ioManager = _ioManager;
|
|
25
|
+
this._doValidate = _doValidate;
|
|
26
|
+
this._sendVersions = _sendVersions;
|
|
27
|
+
this._includeExtendedDataInSend = _includeExtendedDataInSend;
|
|
28
|
+
this._includeProdParamsInSend = _includeProdParamsInSend;
|
|
29
|
+
this._stopListenToMessage = undefined;
|
|
30
|
+
this._stopListenToProdConf = undefined;
|
|
31
|
+
this.destroy = () => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
(_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
34
|
+
(_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
35
|
+
};
|
|
36
|
+
this.setProduct = (product) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const currentProduct = this._product;
|
|
39
|
+
const newProduct = product;
|
|
40
|
+
this._product = newProduct;
|
|
41
|
+
// If same product don't do anything at all
|
|
42
|
+
if (currentProduct !== undefined &&
|
|
43
|
+
newProduct !== undefined &&
|
|
44
|
+
currentProduct.isBackedBySame(newProduct)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (currentProduct !== undefined) {
|
|
48
|
+
(_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
49
|
+
(_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
50
|
+
}
|
|
51
|
+
if (newProduct === undefined) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// We only try to load initial configuration at first load
|
|
55
|
+
if (currentProduct === undefined) {
|
|
56
|
+
const initialProdConf = this.getInitialProdConf();
|
|
57
|
+
if (initialProdConf !== undefined) {
|
|
58
|
+
yield newProduct.setDtoConf(initialProdConf, this._doValidate);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
this._send(this.makeSendData(newProduct.getDtoConf(this._includeExtendedDataInSend, this._includeProdParamsInSend), true));
|
|
62
|
+
this._stopListenToMessage = this.listenForMessage((messages) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const subMessages = messages.subMessages;
|
|
64
|
+
if (subMessages.length === 0) {
|
|
65
|
+
console.warn(`${STAGE_PROD_CONF_MESSAGE_KEY} message without any submessages. Unexpected.`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const highestVersionMessage = subMessages
|
|
69
|
+
.slice(1)
|
|
70
|
+
.reduce((a, c) => (a.version < c.version ? c : a), subMessages[0]);
|
|
71
|
+
switch (highestVersionMessage.version) {
|
|
72
|
+
case "1.0":
|
|
73
|
+
yield newProduct.setApiSelection(highestVersionMessage.conf, this._doValidate);
|
|
74
|
+
return;
|
|
75
|
+
case "2.0":
|
|
76
|
+
yield newProduct.setDtoConf(highestVersionMessage.conf, this._doValidate);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
throw new Error("Unknown message version");
|
|
80
|
+
}));
|
|
81
|
+
this._stopListenToProdConf = this.listenForProdConf(newProduct, (conf) => __awaiter(this, void 0, void 0, function* () { return this._send(this.makeSendData(conf, false)); }));
|
|
82
|
+
});
|
|
83
|
+
this._send = (data) => this._ioManager.send(STAGE_PROD_CONF_MESSAGE_KEY, data);
|
|
84
|
+
}
|
|
85
|
+
getInitialProdConf() {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
makeMessage(conf, initial) {
|
|
89
|
+
const result = [];
|
|
90
|
+
if ((this._sendVersions & CfgProdConfMessageVersions.V1dot0) ===
|
|
91
|
+
CfgProdConfMessageVersions.V1dot0) {
|
|
92
|
+
const v1 = {
|
|
93
|
+
version: "1.0",
|
|
94
|
+
conf: convertDtoConfProdToV1(conf, true),
|
|
95
|
+
};
|
|
96
|
+
result.push(v1);
|
|
97
|
+
}
|
|
98
|
+
if ((this._sendVersions & CfgProdConfMessageVersions.V2dot0) ===
|
|
99
|
+
CfgProdConfMessageVersions.V2dot0) {
|
|
100
|
+
const v2 = {
|
|
101
|
+
version: "2.0",
|
|
102
|
+
conf,
|
|
103
|
+
};
|
|
104
|
+
result.push(v2);
|
|
105
|
+
}
|
|
106
|
+
return { subMessages: result, initial };
|
|
107
|
+
}
|
|
108
|
+
makeMessageListener(callback) {
|
|
109
|
+
return (message) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const prodConfMessage = message;
|
|
111
|
+
yield callback(prodConfMessage);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Register the callback to listen for Product Configuration messages
|
|
116
|
+
* @returns A function which when called will cancel listening
|
|
117
|
+
*/
|
|
118
|
+
listenForMessage(callback) {
|
|
119
|
+
const ioManager = this._ioManager;
|
|
120
|
+
const listener = this.makeMessageListener(callback);
|
|
121
|
+
ioManager.listenForMessage(listener, STAGE_PROD_CONF_MESSAGE_KEY);
|
|
122
|
+
return () => {
|
|
123
|
+
ioManager.stopListenForMessage(listener);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
makeProdConfListener(callback) {
|
|
127
|
+
return (n) => {
|
|
128
|
+
if (!n.committed) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
callback(n.freshRef.getDtoConf(this._includeExtendedDataInSend, this._includeProdParamsInSend));
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
listenForProdConf(product, callback) {
|
|
135
|
+
const listener = this.makeProdConfListener(callback);
|
|
136
|
+
product.listenForChange(listener);
|
|
137
|
+
return () => {
|
|
138
|
+
product.stopListenForChange(listener);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Observable } from "@configura/web-utilities";
|
|
2
|
+
import { CfgIOManager, IOManagerListener } from "./CfgIOManager.js";
|
|
3
|
+
export declare class CfgObservableStateManager extends CfgIOManager<unknown> {
|
|
4
|
+
private static _instance;
|
|
5
|
+
static get instance(): CfgObservableStateManager;
|
|
6
|
+
private constructor();
|
|
7
|
+
readonly stateObservable: Observable<string>;
|
|
8
|
+
private messagesState;
|
|
9
|
+
get stateAsString(): string;
|
|
10
|
+
set stateAsString(s: string);
|
|
11
|
+
listenForStateChange(listener: (v: string) => void): void;
|
|
12
|
+
stopListenForStateChange(listener: (v: string) => void): void;
|
|
13
|
+
listenForMessage(l: IOManagerListener, messageKey: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Removes the listener
|
|
16
|
+
*/
|
|
17
|
+
stopListenForMessage(l: IOManagerListener): boolean;
|
|
18
|
+
private _stateListenerBound;
|
|
19
|
+
private _stateListener;
|
|
20
|
+
send(messageKey: string, data: unknown): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=CfgObservableStateManager.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Observable } from "@configura/web-utilities";
|
|
2
|
+
import { CfgIOManager } from "./CfgIOManager.js";
|
|
3
|
+
export class CfgObservableStateManager extends CfgIOManager {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.stateObservable = new Observable();
|
|
7
|
+
this.messagesState = {};
|
|
8
|
+
this._stateListenerBound = this._stateListener.bind(this);
|
|
9
|
+
}
|
|
10
|
+
static get instance() {
|
|
11
|
+
if (this._instance === undefined) {
|
|
12
|
+
this._instance = new CfgObservableStateManager();
|
|
13
|
+
}
|
|
14
|
+
return this._instance;
|
|
15
|
+
}
|
|
16
|
+
get stateAsString() {
|
|
17
|
+
return JSON.stringify(CfgObservableStateManager.makeContainer(this.messagesState), null, 2);
|
|
18
|
+
}
|
|
19
|
+
set stateAsString(s) {
|
|
20
|
+
this.stateObservable.notifyAll(s);
|
|
21
|
+
}
|
|
22
|
+
listenForStateChange(listener) {
|
|
23
|
+
this.stateObservable.listen(listener);
|
|
24
|
+
}
|
|
25
|
+
stopListenForStateChange(listener) {
|
|
26
|
+
this.stateObservable.stopListen(listener);
|
|
27
|
+
}
|
|
28
|
+
listenForMessage(l, messageKey) {
|
|
29
|
+
const hadListeners = this.hasMessageListeners;
|
|
30
|
+
const didStartListen = super.listenForMessage(l, messageKey);
|
|
31
|
+
if (!hadListeners && didStartListen) {
|
|
32
|
+
this.stateObservable.listen(this._stateListenerBound, this);
|
|
33
|
+
}
|
|
34
|
+
return didStartListen;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Removes the listener
|
|
38
|
+
*/
|
|
39
|
+
stopListenForMessage(l) {
|
|
40
|
+
const didStopListen = super.stopListenForMessage(l);
|
|
41
|
+
if (didStopListen && !this.hasMessageListeners) {
|
|
42
|
+
this.stateObservable.stopListen(this._stateListenerBound);
|
|
43
|
+
}
|
|
44
|
+
return didStopListen;
|
|
45
|
+
}
|
|
46
|
+
_stateListener(data) {
|
|
47
|
+
let asJson;
|
|
48
|
+
try {
|
|
49
|
+
asJson = JSON.parse(data);
|
|
50
|
+
}
|
|
51
|
+
catch (_a) {
|
|
52
|
+
throw new Error("Not JSON data");
|
|
53
|
+
}
|
|
54
|
+
if (!CfgIOManager.isIOContainer(asJson)) {
|
|
55
|
+
console.warn("Not a readable IO container");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.messagesState = asJson.messages;
|
|
59
|
+
super._containerListener(asJson);
|
|
60
|
+
}
|
|
61
|
+
send(messageKey, data) {
|
|
62
|
+
this.messagesState[messageKey] = data;
|
|
63
|
+
this.stateObservable.notifyAll(this.stateAsString, this);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DtoConfProd } from "../CatalogueAPI.js";
|
|
2
|
+
import { CfgIOProdConfConnector, CfgProdConfMessage, CfgProdConfMessageVersions } from "./CfgIOProdConfConnector.js";
|
|
3
|
+
import { CfgObservableStateManager } from "./CfgObservableStateManager.js";
|
|
4
|
+
/**
|
|
5
|
+
* Instantiating this will make the observable state update with the product configuration.
|
|
6
|
+
* @param doValidate Run server side product validation for incoming
|
|
7
|
+
* @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
|
|
8
|
+
* @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
|
|
9
|
+
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector<CfgProdConfMessage> {
|
|
12
|
+
constructor(manager: CfgObservableStateManager, doValidate?: boolean, sendVersions?: CfgProdConfMessageVersions, includeExtendedDataInSend?: boolean, includeProdParamsInSend?: boolean);
|
|
13
|
+
protected makeSendData(conf: DtoConfProd, initial: boolean): CfgProdConfMessage;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=CfgObservableStateToProdConfConnector.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, } from "./CfgIOProdConfConnector.js";
|
|
2
|
+
/**
|
|
3
|
+
* Instantiating this will make the observable state update with the product configuration.
|
|
4
|
+
* @param doValidate Run server side product validation for incoming
|
|
5
|
+
* @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
|
|
6
|
+
* @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
|
|
7
|
+
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
8
|
+
*/
|
|
9
|
+
export class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector {
|
|
10
|
+
constructor(manager, doValidate = true, sendVersions = CfgProdConfMessageVersions.V2dot0, includeExtendedDataInSend = false, includeProdParamsInSend = false) {
|
|
11
|
+
super(manager, doValidate, sendVersions, includeExtendedDataInSend, includeProdParamsInSend);
|
|
12
|
+
}
|
|
13
|
+
makeSendData(conf, initial) {
|
|
14
|
+
return this.makeMessage(conf, initial);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CfgIOManager, IOManagerListener } from "./CfgIOManager.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for classes handling input and output in globally shared environments, using
|
|
4
|
+
* event listeners on the window object, for example the History API and window.message API.
|
|
5
|
+
* These are global resources where data not being handled by Stage can appear.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class CfgWindowEventManager<K extends keyof WindowEventMap, S> extends CfgIOManager<S> {
|
|
8
|
+
/**
|
|
9
|
+
* Listen for the message messageKey being received. This can for example be the history stack
|
|
10
|
+
* being popped or a window.message being received.
|
|
11
|
+
*/
|
|
12
|
+
listenForMessage(l: IOManagerListener, messageKey: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Removes the listener
|
|
15
|
+
*/
|
|
16
|
+
stopListenForMessage(l: IOManagerListener): boolean;
|
|
17
|
+
private _windowEventListenerBound;
|
|
18
|
+
private _windowEventListener;
|
|
19
|
+
protected abstract readonly eventType: K;
|
|
20
|
+
protected abstract getDataFromEvent(event: WindowEventMap[K]): unknown;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=CfgWindowEventManager.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CfgIOManager } from "./CfgIOManager.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for classes handling input and output in globally shared environments, using
|
|
4
|
+
* event listeners on the window object, for example the History API and window.message API.
|
|
5
|
+
* These are global resources where data not being handled by Stage can appear.
|
|
6
|
+
*/
|
|
7
|
+
export class CfgWindowEventManager extends CfgIOManager {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this._windowEventListenerBound = this._windowEventListener.bind(this);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Listen for the message messageKey being received. This can for example be the history stack
|
|
14
|
+
* being popped or a window.message being received.
|
|
15
|
+
*/
|
|
16
|
+
listenForMessage(l, messageKey) {
|
|
17
|
+
const hadListeners = this.hasMessageListeners;
|
|
18
|
+
const didStartListen = super.listenForMessage(l, messageKey);
|
|
19
|
+
if (!hadListeners && didStartListen) {
|
|
20
|
+
window.addEventListener(this.eventType, this._windowEventListenerBound);
|
|
21
|
+
}
|
|
22
|
+
return didStartListen;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Removes the listener
|
|
26
|
+
*/
|
|
27
|
+
stopListenForMessage(l) {
|
|
28
|
+
const didStopListen = super.stopListenForMessage(l);
|
|
29
|
+
if (didStopListen && !this.hasMessageListeners) {
|
|
30
|
+
window.removeEventListener(this.eventType, this._windowEventListenerBound);
|
|
31
|
+
}
|
|
32
|
+
return didStopListen;
|
|
33
|
+
}
|
|
34
|
+
_windowEventListener(event) {
|
|
35
|
+
const data = this.getDataFromEvent(event);
|
|
36
|
+
super._containerListener(data);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IOManagerListener } from "./CfgIOManager.js";
|
|
2
|
+
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
3
|
+
/**
|
|
4
|
+
* This class does nothing on it's own. It is used to coordinate sending and receiving
|
|
5
|
+
* using the post message-API. See https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
|
|
6
|
+
*/
|
|
7
|
+
export declare class CfgWindowMessageManager extends CfgWindowEventManager<"message", unknown> {
|
|
8
|
+
private static _instance;
|
|
9
|
+
static get instance(): CfgWindowMessageManager;
|
|
10
|
+
/**
|
|
11
|
+
* If uncertain about security, please read https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
|
|
12
|
+
*/
|
|
13
|
+
private constructor();
|
|
14
|
+
private _doListenForIncoming;
|
|
15
|
+
private _remoteEnds;
|
|
16
|
+
private _targetOrigin;
|
|
17
|
+
private _acceptableMessageOrigin;
|
|
18
|
+
/**
|
|
19
|
+
* Listen for incoming messages or not
|
|
20
|
+
*/
|
|
21
|
+
set doListenForIncoming(v: boolean);
|
|
22
|
+
/**
|
|
23
|
+
* What window object outgoing messages should be sent to. Leave empty if you don't want to broadcast.
|
|
24
|
+
*/
|
|
25
|
+
set remoteEnds(v: Window[]);
|
|
26
|
+
/**
|
|
27
|
+
* What origins of the target window are acceptable.
|
|
28
|
+
*/
|
|
29
|
+
set targetOrigin(v: string);
|
|
30
|
+
/**
|
|
31
|
+
* @param _acceptableMessageOrigin What message origins we accept incoming from.
|
|
32
|
+
*/
|
|
33
|
+
set acceptableMessageOrigin(v: string);
|
|
34
|
+
listenForMessage(l: IOManagerListener, messageKey: string): boolean;
|
|
35
|
+
stopListenForMessage(l: IOManagerListener): boolean;
|
|
36
|
+
send(messageKey: string, data: unknown): void;
|
|
37
|
+
protected _containerListener(event: MessageEvent): void;
|
|
38
|
+
protected readonly eventType = "message";
|
|
39
|
+
protected getDataFromEvent(event: MessageEvent): unknown;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=CfgWindowMessageManager.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CfgIOManager } from "./CfgIOManager.js";
|
|
2
|
+
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
3
|
+
/**
|
|
4
|
+
* This class does nothing on it's own. It is used to coordinate sending and receiving
|
|
5
|
+
* using the post message-API. See https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
|
|
6
|
+
*/
|
|
7
|
+
export class CfgWindowMessageManager extends CfgWindowEventManager {
|
|
8
|
+
/**
|
|
9
|
+
* If uncertain about security, please read https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
|
|
10
|
+
*/
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this._doListenForIncoming = true;
|
|
14
|
+
this._remoteEnds = [];
|
|
15
|
+
this._targetOrigin = "*";
|
|
16
|
+
this._acceptableMessageOrigin = undefined;
|
|
17
|
+
this.eventType = "message";
|
|
18
|
+
}
|
|
19
|
+
static get instance() {
|
|
20
|
+
if (this._instance === undefined) {
|
|
21
|
+
this._instance = new CfgWindowMessageManager();
|
|
22
|
+
}
|
|
23
|
+
return this._instance;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Listen for incoming messages or not
|
|
27
|
+
*/
|
|
28
|
+
set doListenForIncoming(v) {
|
|
29
|
+
this._doListenForIncoming = v;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What window object outgoing messages should be sent to. Leave empty if you don't want to broadcast.
|
|
33
|
+
*/
|
|
34
|
+
set remoteEnds(v) {
|
|
35
|
+
for (const remote of v) {
|
|
36
|
+
if (remote === window) {
|
|
37
|
+
console.warn("You are providing your own window as a remote end.");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
this._remoteEnds = v;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* What origins of the target window are acceptable.
|
|
44
|
+
*/
|
|
45
|
+
set targetOrigin(v) {
|
|
46
|
+
this._targetOrigin = v;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @param _acceptableMessageOrigin What message origins we accept incoming from.
|
|
50
|
+
*/
|
|
51
|
+
set acceptableMessageOrigin(v) {
|
|
52
|
+
this._acceptableMessageOrigin = v;
|
|
53
|
+
}
|
|
54
|
+
listenForMessage(l, messageKey) {
|
|
55
|
+
if (!this._doListenForIncoming) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return super.listenForMessage(l, messageKey);
|
|
59
|
+
}
|
|
60
|
+
stopListenForMessage(l) {
|
|
61
|
+
if (!this._doListenForIncoming) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return super.stopListenForMessage(l);
|
|
65
|
+
}
|
|
66
|
+
send(messageKey, data) {
|
|
67
|
+
const container = CfgIOManager.makeContainer({
|
|
68
|
+
[messageKey]: data,
|
|
69
|
+
});
|
|
70
|
+
for (const remoteEnd of this._remoteEnds) {
|
|
71
|
+
remoteEnd.postMessage(container, this._targetOrigin);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
_containerListener(event) {
|
|
75
|
+
if (this._acceptableMessageOrigin !== undefined &&
|
|
76
|
+
event.origin !== this._acceptableMessageOrigin) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
super._containerListener(event);
|
|
80
|
+
}
|
|
81
|
+
getDataFromEvent(event) {
|
|
82
|
+
return event.data;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DtoConfProd } from "../CatalogueAPI.js";
|
|
2
|
+
import { CfgIOProdConfConnector, CfgProdConfMessage, CfgProdConfMessageVersions } from "./CfgIOProdConfConnector.js";
|
|
3
|
+
import { CfgWindowMessageManager } from "./CfgWindowMessageManager.js";
|
|
4
|
+
/**
|
|
5
|
+
* Instantiating this will make Stage send product configuration changes using the post message-API.
|
|
6
|
+
* It will also make Stage listen for incoming product configuration update messages.
|
|
7
|
+
* This can be used to communicate in and out of an iframe for example.
|
|
8
|
+
* @param doValidate Run server side product validation for incoming
|
|
9
|
+
* @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
|
|
10
|
+
* @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
|
|
11
|
+
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
12
|
+
*/
|
|
13
|
+
export declare class CfgWindowMessageToProdConfConnector extends CfgIOProdConfConnector<CfgProdConfMessage> {
|
|
14
|
+
constructor(manager: CfgWindowMessageManager, doValidate?: boolean, sendVersions?: CfgProdConfMessageVersions, includeExtendedDataInSend?: boolean, includeProdParamsInSend?: boolean);
|
|
15
|
+
protected makeSendData(conf: DtoConfProd, initial: boolean): CfgProdConfMessage;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=CfgWindowMessageToProdConfConnector.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, } from "./CfgIOProdConfConnector.js";
|
|
2
|
+
/**
|
|
3
|
+
* Instantiating this will make Stage send product configuration changes using the post message-API.
|
|
4
|
+
* It will also make Stage listen for incoming product configuration update messages.
|
|
5
|
+
* This can be used to communicate in and out of an iframe for example.
|
|
6
|
+
* @param doValidate Run server side product validation for incoming
|
|
7
|
+
* @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
|
|
8
|
+
* @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
|
|
9
|
+
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
10
|
+
*/
|
|
11
|
+
export class CfgWindowMessageToProdConfConnector extends CfgIOProdConfConnector {
|
|
12
|
+
constructor(manager, doValidate = true, sendVersions = CfgProdConfMessageVersions.V2dot0, includeExtendedDataInSend = false, includeProdParamsInSend = false) {
|
|
13
|
+
super(manager, doValidate, sendVersions, includeExtendedDataInSend, includeProdParamsInSend);
|
|
14
|
+
}
|
|
15
|
+
makeSendData(conf, initial) {
|
|
16
|
+
return this.makeMessage(conf, initial);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./CfgHistoryManager.js";
|
|
2
|
+
export * from "./CfgHistoryToProdConfConnector.js";
|
|
3
|
+
export * from "./CfgIOManager.js";
|
|
4
|
+
export * from "./CfgIOProdConfConnector.js";
|
|
5
|
+
export * from "./CfgObservableStateManager.js";
|
|
6
|
+
export * from "./CfgObservableStateToProdConfConnector.js";
|
|
7
|
+
export * from "./CfgWindowMessageManager.js";
|
|
8
|
+
export * from "./CfgWindowMessageToProdConfConnector.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/io/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./CfgHistoryManager.js";
|
|
2
|
+
export * from "./CfgHistoryToProdConfConnector.js";
|
|
3
|
+
export * from "./CfgIOManager.js";
|
|
4
|
+
export * from "./CfgIOProdConfConnector.js";
|
|
5
|
+
export * from "./CfgObservableStateManager.js";
|
|
6
|
+
export * from "./CfgObservableStateToProdConfConnector.js";
|
|
7
|
+
export * from "./CfgWindowMessageManager.js";
|
|
8
|
+
export * from "./CfgWindowMessageToProdConfConnector.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CfgProductConfiguration } from "../productConfiguration/CfgProductConfiguration.js";
|
|
2
|
-
import { CfgMtrlApplication } from "./CfgMtrlApplication.js";
|
|
3
|
-
import { CfgMtrlSourceWithMetaData } from "./CfgMtrlSourceWithMetaData.js";
|
|
4
|
-
export declare type CfgMaterialMapping = Map<string, CfgMtrlSourceWithMetaData>;
|
|
5
|
-
export declare function aggregateAllMaterialApplications(applicationAreas: CfgMtrlApplication[], productMtrlApplications: CfgMtrlApplication[], productConfiguration: CfgProductConfiguration, debugMtrlApplications?: CfgMtrlApplication[]): CfgMaterialMapping;
|
|
6
|
-
export declare function logMtrlSourceWithMetaDataToConsole(mtrlSourceWithMetaData: CfgMtrlSourceWithMetaData): void;
|
|
7
|
-
export declare function logMaterialMappingToConsole(areasToMaterials: CfgMaterialMapping): void;
|
|
1
|
+
import { CfgProductConfiguration } from "../productConfiguration/CfgProductConfiguration.js";
|
|
2
|
+
import { CfgMtrlApplication } from "./CfgMtrlApplication.js";
|
|
3
|
+
import { CfgMtrlSourceWithMetaData } from "./CfgMtrlSourceWithMetaData.js";
|
|
4
|
+
export declare type CfgMaterialMapping = Map<string, CfgMtrlSourceWithMetaData>;
|
|
5
|
+
export declare function aggregateAllMaterialApplications(applicationAreas: CfgMtrlApplication[], productMtrlApplications: CfgMtrlApplication[], productConfiguration: CfgProductConfiguration, debugMtrlApplications?: CfgMtrlApplication[]): CfgMaterialMapping;
|
|
6
|
+
export declare function logMtrlSourceWithMetaDataToConsole(mtrlSourceWithMetaData: CfgMtrlSourceWithMetaData): void;
|
|
7
|
+
export declare function logMaterialMappingToConsole(areasToMaterials: CfgMaterialMapping): void;
|
|
8
8
|
//# sourceMappingURL=CfgMaterialMapping.d.ts.map
|