@configura/web-api 1.6.2 → 2.0.0-alpha.10

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 (98) hide show
  1. package/.eslintrc.json +18 -18
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/CatalogueAPI.d.ts +551 -507
  5. package/dist/CatalogueAPI.js +273 -280
  6. package/dist/CfgMeasure.d.ts +32 -32
  7. package/dist/CfgMeasure.js +30 -30
  8. package/dist/CfgProduct.d.ts +268 -258
  9. package/dist/CfgProduct.js +780 -747
  10. package/dist/CfgReferencePathHelper.d.ts +27 -0
  11. package/dist/CfgReferencePathHelper.js +26 -0
  12. package/dist/ConfigurationConverter.d.ts +5 -0
  13. package/dist/ConfigurationConverter.js +72 -0
  14. package/dist/index.d.ts +23 -20
  15. package/dist/index.js +23 -20
  16. package/dist/io/CfgHistoryManager.d.ts +52 -0
  17. package/dist/io/CfgHistoryManager.js +82 -0
  18. package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -0
  19. package/dist/io/CfgHistoryToProdConfConnector.js +56 -0
  20. package/dist/io/CfgIOManager.d.ts +49 -0
  21. package/dist/io/CfgIOManager.js +115 -0
  22. package/dist/io/CfgIOProdConfConnector.d.ts +56 -0
  23. package/dist/io/CfgIOProdConfConnector.js +143 -0
  24. package/dist/io/CfgObservableStateManager.d.ts +26 -0
  25. package/dist/io/CfgObservableStateManager.js +69 -0
  26. package/dist/io/CfgObservableStateToProdConfConnector.d.ts +16 -0
  27. package/dist/io/CfgObservableStateToProdConfConnector.js +17 -0
  28. package/dist/io/CfgWindowEventManager.d.ts +22 -0
  29. package/dist/io/CfgWindowEventManager.js +38 -0
  30. package/dist/io/CfgWindowMessageManager.d.ts +41 -0
  31. package/dist/io/CfgWindowMessageManager.js +87 -0
  32. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +18 -0
  33. package/dist/io/CfgWindowMessageToProdConfConnector.js +19 -0
  34. package/dist/io/index.d.ts +9 -0
  35. package/dist/io/index.js +8 -0
  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 +187 -188
  47. package/dist/productConfiguration/CfgFeature.js +645 -636
  48. package/dist/productConfiguration/CfgOption.d.ts +151 -150
  49. package/dist/productConfiguration/CfgOption.js +416 -426
  50. package/dist/productConfiguration/CfgProductConfiguration.d.ts +117 -120
  51. package/dist/productConfiguration/CfgProductConfiguration.js +307 -309
  52. package/dist/productConfiguration/filters.d.ts +15 -15
  53. package/dist/productConfiguration/filters.js +70 -70
  54. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  55. package/dist/productConfiguration/productParamsGenerator.js +51 -51
  56. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
  57. package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -80
  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 +40 -40
  63. package/dist/syncGroups/SyncGroupsHandler.js +359 -358
  64. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
  65. package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
  66. package/dist/syncGroups/SyncGroupsState.d.ts +35 -35
  67. package/dist/syncGroups/SyncGroupsState.js +125 -125
  68. package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
  69. package/dist/syncGroups/SyncGroupsTransaction.js +576 -576
  70. package/dist/tasks/TaskHandler.d.ts +77 -78
  71. package/dist/tasks/TaskHandler.js +275 -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 -36
  78. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
  79. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +277 -277
  80. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  81. package/dist/tests/testData/testDataCachedGetProduct.js +185 -185
  82. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  83. package/dist/tests/testData/testDataCachedPostValidate.js +183 -183
  84. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
  85. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
  86. package/dist/tests/testData/testDataOptions.d.ts +12 -12
  87. package/dist/tests/testData/testDataOptions.js +60 -60
  88. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
  89. package/dist/tests/testData/testDataProductAggregatedPrice.js +187 -187
  90. package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
  91. package/dist/tests/testData/testDataUpcharge.js +119 -119
  92. package/dist/utilitiesCatalogueData.d.ts +42 -31
  93. package/dist/utilitiesCatalogueData.js +173 -162
  94. package/dist/utilitiesCataloguePermission.d.ts +38 -37
  95. package/dist/utilitiesCataloguePermission.js +79 -80
  96. package/dist/utilitiesNumericValues.d.ts +24 -24
  97. package/dist/utilitiesNumericValues.js +109 -109
  98. package/package.json +3 -3
@@ -0,0 +1,56 @@
1
+ import { DtoAdditionalProductConfiguration, DtoProductConfiguration } from "../CatalogueAPI.js";
2
+ import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
3
+ import { CfgIOManager } from "./CfgIOManager.js";
4
+ export declare const isCfgProdConfMessage: (data: unknown) => data is CfgProdConfMessageV1 | CfgProdConfMessageV2;
5
+ export declare type CfgProdConfMessageV1 = {
6
+ version: "1.0";
7
+ conf: DtoAdditionalProductConfiguration;
8
+ };
9
+ export declare const isCfgProdConfMessageV1: (data: unknown) => data is CfgProdConfMessageV1;
10
+ export declare type CfgProdConfMessageV2 = {
11
+ version: "2.0";
12
+ conf: DtoProductConfiguration;
13
+ };
14
+ export declare const isCfgProdConfMessageV2: (data: unknown) => data is CfgProdConfMessageV2;
15
+ export declare type CfgProdConfMessage = {
16
+ initial: boolean;
17
+ subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[];
18
+ };
19
+ export declare const getHighestVersionProdConfMessage: (subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[]) => CfgProdConfMessageV1 | CfgProdConfMessageV2;
20
+ export declare enum CfgProdConfMessageVersions {
21
+ V1dot0 = 1,
22
+ V2dot0 = 2
23
+ }
24
+ export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
25
+ declare type ProdConfMessageCallback = (message: CfgProdConfMessage) => Promise<void>;
26
+ declare type ProdConfCallback = (conf: DtoProductConfiguration) => Promise<void>;
27
+ /**
28
+ * Base class for connecting the product configuration to an IO channel
29
+ */
30
+ export declare abstract class CfgIOProdConfConnector<S> {
31
+ private readonly _ioManager;
32
+ private readonly _doValidate;
33
+ private readonly _includeExtendedDataInSend;
34
+ private readonly _includeProdParamsInSend;
35
+ private _product;
36
+ private _stopListenToMessage;
37
+ private _stopListenToProdConf;
38
+ constructor(_ioManager: CfgIOManager<S>, _doValidate: boolean, _includeExtendedDataInSend: boolean, // Only v2.0
39
+ _includeProdParamsInSend: boolean);
40
+ destroy: () => void;
41
+ setProduct: (product: CfgProduct | undefined) => Promise<void>;
42
+ private _send;
43
+ protected getInitialProdConf(): DtoProductConfiguration | undefined;
44
+ protected abstract makeSendData(conf: DtoProductConfiguration, initial: boolean): S;
45
+ static makeMessage(conf: DtoProductConfiguration, initial: boolean, sendVersions: CfgProdConfMessageVersions): CfgProdConfMessage;
46
+ static makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
47
+ /**
48
+ * Register the callback to listen for Product Configuration messages
49
+ * @returns A function which when called will cancel listening
50
+ */
51
+ static listenForMessage<S>(callback: ProdConfMessageCallback, ioManager: CfgIOManager<S>): () => void;
52
+ static makeProdConfListener(callback: ProdConfCallback, includeExtendedDataInSend: boolean, includeProdParamsInSend: boolean): (n: CfgProductChangeNotification) => void;
53
+ static listenForProdConf(product: CfgProduct, callback: ProdConfCallback, includeExtendedDataInSend: boolean, includeProdParamsInSend: boolean): () => void;
54
+ }
55
+ export {};
56
+ //# sourceMappingURL=CfgIOProdConfConnector.d.ts.map
@@ -0,0 +1,143 @@
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 const isCfgProdConfMessage = (data) => typeof data === "object" && data !== null && "version" in data && "conf" in data;
12
+ export const isCfgProdConfMessageV1 = (data) => isCfgProdConfMessage(data) && data.version === "1.0";
13
+ export const isCfgProdConfMessageV2 = (data) => isCfgProdConfMessage(data) && data.version === "2.0";
14
+ export const getHighestVersionProdConfMessage = (subMessages) => subMessages
15
+ .slice(1)
16
+ .reduce((a, c) => (a.version < c.version ? c : a), subMessages[0]);
17
+ export var CfgProdConfMessageVersions;
18
+ (function (CfgProdConfMessageVersions) {
19
+ CfgProdConfMessageVersions[CfgProdConfMessageVersions["V1dot0"] = 1] = "V1dot0";
20
+ CfgProdConfMessageVersions[CfgProdConfMessageVersions["V2dot0"] = 2] = "V2dot0";
21
+ })(CfgProdConfMessageVersions || (CfgProdConfMessageVersions = {}));
22
+ export const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
23
+ /**
24
+ * Base class for connecting the product configuration to an IO channel
25
+ */
26
+ export class CfgIOProdConfConnector {
27
+ constructor(_ioManager, _doValidate, _includeExtendedDataInSend, // Only v2.0
28
+ _includeProdParamsInSend // Only v2.0
29
+ ) {
30
+ this._ioManager = _ioManager;
31
+ this._doValidate = _doValidate;
32
+ this._includeExtendedDataInSend = _includeExtendedDataInSend;
33
+ this._includeProdParamsInSend = _includeProdParamsInSend;
34
+ this._stopListenToMessage = undefined;
35
+ 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
+ this.setProduct = (product) => __awaiter(this, void 0, void 0, function* () {
42
+ var _a, _b;
43
+ const currentProduct = this._product;
44
+ const newProduct = product;
45
+ this._product = newProduct;
46
+ // If same product don't do anything at all
47
+ if (currentProduct !== undefined &&
48
+ newProduct !== undefined &&
49
+ currentProduct.isBackedBySame(newProduct)) {
50
+ return;
51
+ }
52
+ if (currentProduct !== undefined) {
53
+ (_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
54
+ (_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
55
+ }
56
+ if (newProduct === undefined) {
57
+ return;
58
+ }
59
+ // We only try to load initial configuration at first load
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));
67
+ this._stopListenToMessage = CfgIOProdConfConnector.listenForMessage((messages) => __awaiter(this, void 0, void 0, function* () {
68
+ const subMessages = messages.subMessages;
69
+ if (subMessages.length === 0) {
70
+ console.warn(`${STAGE_PROD_CONF_MESSAGE_KEY} message without any submessages. Unexpected.`);
71
+ return;
72
+ }
73
+ const highestVersionMessage = getHighestVersionProdConfMessage(subMessages);
74
+ if (isCfgProdConfMessageV1(highestVersionMessage)) {
75
+ yield newProduct.setApiSelection(highestVersionMessage.conf, this._doValidate);
76
+ return;
77
+ }
78
+ if (isCfgProdConfMessageV2(highestVersionMessage)) {
79
+ yield newProduct.setDtoConf(highestVersionMessage.conf, this._doValidate);
80
+ return;
81
+ }
82
+ throw new Error("Unknown message version");
83
+ }), this._ioManager);
84
+ this._stopListenToProdConf = CfgIOProdConfConnector.listenForProdConf(newProduct, (conf) => __awaiter(this, void 0, void 0, function* () { return this._send(this.makeSendData(conf, false)); }), this._includeExtendedDataInSend, this._includeProdParamsInSend);
85
+ });
86
+ this._send = (data) => this._ioManager.send(STAGE_PROD_CONF_MESSAGE_KEY, data);
87
+ }
88
+ getInitialProdConf() {
89
+ return undefined;
90
+ }
91
+ static makeMessage(conf, initial, sendVersions) {
92
+ const result = [];
93
+ if ((sendVersions & CfgProdConfMessageVersions.V1dot0) ===
94
+ CfgProdConfMessageVersions.V1dot0) {
95
+ const v1 = {
96
+ version: "1.0",
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);
108
+ }
109
+ return { subMessages: result, initial };
110
+ }
111
+ static makeMessageListener(callback) {
112
+ return (message) => __awaiter(this, void 0, void 0, function* () {
113
+ const prodConfMessage = message;
114
+ yield callback(prodConfMessage);
115
+ });
116
+ }
117
+ /**
118
+ * Register the callback to listen for Product Configuration messages
119
+ * @returns A function which when called will cancel listening
120
+ */
121
+ static listenForMessage(callback, ioManager) {
122
+ const listener = this.makeMessageListener(callback);
123
+ ioManager.listenForMessage(listener, STAGE_PROD_CONF_MESSAGE_KEY);
124
+ return () => {
125
+ ioManager.stopListenForMessage(listener);
126
+ };
127
+ }
128
+ static makeProdConfListener(callback, includeExtendedDataInSend, includeProdParamsInSend) {
129
+ return (n) => {
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);
138
+ product.listenForChange(listener);
139
+ return () => {
140
+ product.stopListenForChange(listener);
141
+ };
142
+ }
143
+ }
@@ -0,0 +1,26 @@
1
+ import { Observable } from "@configura/web-utilities";
2
+ import { CfgIOManager, IOManagerListener } from "./CfgIOManager.js";
3
+ /**
4
+ * This class is used to coordinate sending and receiving using the observable
5
+ * state in the class. It handles messages sent from the connectors.
6
+ */
7
+ export declare class CfgObservableStateManager extends CfgIOManager<unknown> {
8
+ private static _instance;
9
+ static get instance(): CfgObservableStateManager;
10
+ private constructor();
11
+ readonly stateObservable: Observable<string>;
12
+ private messagesState;
13
+ get stateAsString(): string;
14
+ set stateAsString(s: string);
15
+ listenForStateChange(listener: (v: string) => void): void;
16
+ stopListenForStateChange(listener: (v: string) => void): void;
17
+ listenForMessage(l: IOManagerListener, messageKey: string): boolean;
18
+ /**
19
+ * Removes the listener
20
+ */
21
+ stopListenForMessage(l: IOManagerListener): boolean;
22
+ private _stateListenerBound;
23
+ private _stateListener;
24
+ send(messageKey: string, data: unknown): void;
25
+ }
26
+ //# sourceMappingURL=CfgObservableStateManager.d.ts.map
@@ -0,0 +1,69 @@
1
+ import { Observable } from "@configura/web-utilities";
2
+ import { CfgIOManager } from "./CfgIOManager.js";
3
+ /**
4
+ * This class is used to coordinate sending and receiving using the observable
5
+ * state in the class. It handles messages sent from the connectors.
6
+ */
7
+ export class CfgObservableStateManager extends CfgIOManager {
8
+ constructor() {
9
+ super();
10
+ this.stateObservable = new Observable();
11
+ this.messagesState = {};
12
+ this._stateListenerBound = this._stateListener.bind(this);
13
+ }
14
+ static get instance() {
15
+ if (this._instance === undefined) {
16
+ this._instance = new CfgObservableStateManager();
17
+ }
18
+ return this._instance;
19
+ }
20
+ get stateAsString() {
21
+ return JSON.stringify(CfgObservableStateManager.makeContainer(this.messagesState), null, 2);
22
+ }
23
+ set stateAsString(s) {
24
+ this.stateObservable.notifyAll(s);
25
+ }
26
+ listenForStateChange(listener) {
27
+ this.stateObservable.listen(listener);
28
+ }
29
+ stopListenForStateChange(listener) {
30
+ this.stateObservable.stopListen(listener);
31
+ }
32
+ listenForMessage(l, messageKey) {
33
+ const hadListeners = this.hasMessageListeners;
34
+ const didStartListen = super.listenForMessage(l, messageKey);
35
+ if (!hadListeners && didStartListen) {
36
+ this.stateObservable.listen(this._stateListenerBound, this);
37
+ }
38
+ return didStartListen;
39
+ }
40
+ /**
41
+ * Removes the listener
42
+ */
43
+ stopListenForMessage(l) {
44
+ const didStopListen = super.stopListenForMessage(l);
45
+ if (didStopListen && !this.hasMessageListeners) {
46
+ this.stateObservable.stopListen(this._stateListenerBound);
47
+ }
48
+ return didStopListen;
49
+ }
50
+ _stateListener(data) {
51
+ let asJson;
52
+ try {
53
+ asJson = JSON.parse(data);
54
+ }
55
+ catch (_a) {
56
+ throw new Error("Not JSON data");
57
+ }
58
+ if (!CfgIOManager.isIOContainer(asJson)) {
59
+ console.warn("Not a readable IO container");
60
+ return;
61
+ }
62
+ this.messagesState = asJson.messages;
63
+ super._containerListener(asJson);
64
+ }
65
+ send(messageKey, data) {
66
+ this.messagesState[messageKey] = data;
67
+ this.stateObservable.notifyAll(this.stateAsString, this);
68
+ }
69
+ }
@@ -0,0 +1,16 @@
1
+ import { DtoProductConfiguration } 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
+ private _sendVersions;
13
+ constructor(manager: CfgObservableStateManager, doValidate?: boolean, _sendVersions?: CfgProdConfMessageVersions, includeExtendedDataInSend?: boolean, includeProdParamsInSend?: boolean);
14
+ protected makeSendData(conf: DtoProductConfiguration, initial: boolean): CfgProdConfMessage;
15
+ }
16
+ //# sourceMappingURL=CfgObservableStateToProdConfConnector.d.ts.map
@@ -0,0 +1,17 @@
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, includeExtendedDataInSend, includeProdParamsInSend);
12
+ this._sendVersions = _sendVersions;
13
+ }
14
+ makeSendData(conf, initial) {
15
+ return CfgIOProdConfConnector.makeMessage(conf, initial, this._sendVersions);
16
+ }
17
+ }
@@ -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 is used to coordinate sending and receiving using the post message-API.
5
+ * 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,87 @@
1
+ import { CfgIOManager } from "./CfgIOManager.js";
2
+ import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
3
+ /**
4
+ * This class is used to coordinate sending and receiving using the post message-API.
5
+ * 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
+ if (this.receiveInProgress) {
68
+ return;
69
+ }
70
+ const container = CfgIOManager.makeContainer({
71
+ [messageKey]: data,
72
+ });
73
+ for (const remoteEnd of this._remoteEnds) {
74
+ remoteEnd.postMessage(container, this._targetOrigin);
75
+ }
76
+ }
77
+ _containerListener(event) {
78
+ if (this._acceptableMessageOrigin !== undefined &&
79
+ event.origin !== this._acceptableMessageOrigin) {
80
+ return;
81
+ }
82
+ super._containerListener(event);
83
+ }
84
+ getDataFromEvent(event) {
85
+ return event.data;
86
+ }
87
+ }
@@ -0,0 +1,18 @@
1
+ import { DtoProductConfiguration } 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
+ private _sendVersions;
15
+ constructor(manager: CfgWindowMessageManager, doValidate?: boolean, _sendVersions?: CfgProdConfMessageVersions, includeExtendedDataInSend?: boolean, includeProdParamsInSend?: boolean);
16
+ protected makeSendData(conf: DtoProductConfiguration, initial: boolean): CfgProdConfMessage;
17
+ }
18
+ //# sourceMappingURL=CfgWindowMessageToProdConfConnector.d.ts.map
@@ -0,0 +1,19 @@
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, includeExtendedDataInSend, includeProdParamsInSend);
14
+ this._sendVersions = _sendVersions;
15
+ }
16
+ makeSendData(conf, initial) {
17
+ return CfgIOProdConfConnector.makeMessage(conf, initial, this._sendVersions);
18
+ }
19
+ }
@@ -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
@@ -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