@configura/web-api 1.5.0 → 1.6.0-iotest.1

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 (73) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/CatalogueAPI.d.ts +511 -511
  4. package/dist/CatalogueAPI.js +273 -273
  5. package/dist/CfgMeasure.d.ts +32 -32
  6. package/dist/CfgMeasure.js +30 -30
  7. package/dist/CfgProduct.d.ts +244 -239
  8. package/dist/CfgProduct.js +674 -668
  9. package/dist/index.d.ts +22 -18
  10. package/dist/index.js +22 -18
  11. package/dist/io/CfgHistoryManager.d.ts +30 -0
  12. package/dist/io/CfgHistoryManager.js +62 -0
  13. package/dist/io/CfgHistoryToProdConfConnector.d.ts +10 -0
  14. package/dist/io/CfgHistoryToProdConfConnector.js +20 -0
  15. package/dist/io/CfgIOManager.d.ts +29 -0
  16. package/dist/io/CfgIOManager.js +89 -0
  17. package/dist/io/CfgIOProdConfConnector.d.ts +31 -0
  18. package/dist/io/CfgIOProdConfConnector.js +98 -0
  19. package/dist/io/CfgWindowMessageManager.d.ts +13 -0
  20. package/dist/io/CfgWindowMessageManager.js +28 -0
  21. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +13 -0
  22. package/dist/io/CfgWindowMessageToProdConfConnector.js +17 -0
  23. package/dist/material/CfgMaterialMapping.d.ts +7 -7
  24. package/dist/material/CfgMaterialMapping.js +181 -181
  25. package/dist/material/CfgMtrlApplication.d.ts +18 -18
  26. package/dist/material/CfgMtrlApplication.js +43 -43
  27. package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
  28. package/dist/material/CfgMtrlApplicationSource.js +8 -8
  29. package/dist/material/CfgMtrlSource.d.ts +19 -19
  30. package/dist/material/CfgMtrlSource.js +40 -40
  31. package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
  32. package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
  33. package/dist/productConfiguration/CfgFeature.d.ts +178 -178
  34. package/dist/productConfiguration/CfgFeature.js +611 -611
  35. package/dist/productConfiguration/CfgOption.d.ts +128 -128
  36. package/dist/productConfiguration/CfgOption.js +394 -394
  37. package/dist/productConfiguration/CfgProductConfiguration.d.ts +121 -120
  38. package/dist/productConfiguration/CfgProductConfiguration.js +306 -307
  39. package/dist/productConfiguration/filters.d.ts +15 -15
  40. package/dist/productConfiguration/filters.js +67 -67
  41. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  42. package/dist/productConfiguration/productParamsGenerator.js +51 -51
  43. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
  44. package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -80
  45. package/dist/productLoader.d.ts +33 -33
  46. package/dist/productLoader.js +49 -49
  47. package/dist/tasks/TaskHandler.d.ts +78 -78
  48. package/dist/tasks/TaskHandler.js +265 -265
  49. package/dist/tasks/formats.d.ts +4 -4
  50. package/dist/tasks/formats.js +7 -7
  51. package/dist/tests/testData/collectorForTest.d.ts +73 -73
  52. package/dist/tests/testData/collectorForTest.js +195 -195
  53. package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
  54. package/dist/tests/testData/dummyProductForTest.js +36 -36
  55. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +32 -32
  56. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +348 -348
  57. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  58. package/dist/tests/testData/testDataCachedGetProduct.js +196 -196
  59. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  60. package/dist/tests/testData/testDataCachedPostValidate.js +183 -183
  61. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
  62. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
  63. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
  64. package/dist/tests/testData/testDataProductAggregatedPrice.js +198 -198
  65. package/dist/tests/testData/testDataUpcharge.d.ts +29 -29
  66. package/dist/tests/testData/testDataUpcharge.js +151 -151
  67. package/dist/utilitiesCatalogueData.d.ts +25 -25
  68. package/dist/utilitiesCatalogueData.js +65 -64
  69. package/dist/utilitiesCataloguePermission.d.ts +39 -39
  70. package/dist/utilitiesCataloguePermission.js +84 -84
  71. package/dist/utilitiesNumericValues.d.ts +24 -24
  72. package/dist/utilitiesNumericValues.js +109 -109
  73. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -1,19 +1,23 @@
1
- export * from "./CatalogueAPI.js";
2
- export * from "./CfgProduct.js";
3
- export * from "./material/CfgMaterialMapping.js";
4
- export * from "./material/CfgMtrlApplication.js";
5
- export * from "./material/CfgMtrlApplicationSource.js";
6
- export * from "./material/CfgMtrlSource.js";
7
- export * from "./material/CfgMtrlSourceWithMetaData.js";
8
- export * from "./productConfiguration/CfgFeature.js";
9
- export * from "./productConfiguration/CfgOption.js";
10
- export * from "./productConfiguration/CfgProductConfiguration.js";
11
- export * from "./productConfiguration/filters.js";
12
- export * from "./productConfiguration/productParamsGenerator.js";
13
- export * from "./productLoader.js";
14
- export * from "./tasks/formats.js";
15
- export * from "./tasks/TaskHandler.js";
16
- export * from "./utilitiesCatalogueData.js";
17
- export * from "./utilitiesCataloguePermission.js";
18
- export * from "./utilitiesNumericValues.js";
1
+ export * from "./CatalogueAPI.js";
2
+ export * from "./CfgProduct.js";
3
+ export * from "./io/CfgHistoryManager.js";
4
+ export * from "./io/CfgHistoryToProdConfConnector.js";
5
+ export * from "./io/CfgWindowMessageManager.js";
6
+ export * from "./io/CfgWindowMessageToProdConfConnector.js";
7
+ export * from "./material/CfgMaterialMapping.js";
8
+ export * from "./material/CfgMtrlApplication.js";
9
+ export * from "./material/CfgMtrlApplicationSource.js";
10
+ export * from "./material/CfgMtrlSource.js";
11
+ export * from "./material/CfgMtrlSourceWithMetaData.js";
12
+ export * from "./productConfiguration/CfgFeature.js";
13
+ export * from "./productConfiguration/CfgOption.js";
14
+ export * from "./productConfiguration/CfgProductConfiguration.js";
15
+ export * from "./productConfiguration/filters.js";
16
+ export * from "./productConfiguration/productParamsGenerator.js";
17
+ export * from "./productLoader.js";
18
+ export * from "./tasks/formats.js";
19
+ export * from "./tasks/TaskHandler.js";
20
+ export * from "./utilitiesCatalogueData.js";
21
+ export * from "./utilitiesCataloguePermission.js";
22
+ export * from "./utilitiesNumericValues.js";
19
23
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,18 +1,22 @@
1
- export * from "./CatalogueAPI.js";
2
- export * from "./CfgProduct.js";
3
- export * from "./material/CfgMaterialMapping.js";
4
- export * from "./material/CfgMtrlApplication.js";
5
- export * from "./material/CfgMtrlApplicationSource.js";
6
- export * from "./material/CfgMtrlSource.js";
7
- export * from "./material/CfgMtrlSourceWithMetaData.js";
8
- export * from "./productConfiguration/CfgFeature.js";
9
- export * from "./productConfiguration/CfgOption.js";
10
- export * from "./productConfiguration/CfgProductConfiguration.js";
11
- export * from "./productConfiguration/filters.js";
12
- export * from "./productConfiguration/productParamsGenerator.js";
13
- export * from "./productLoader.js";
14
- export * from "./tasks/formats.js";
15
- export * from "./tasks/TaskHandler.js";
16
- export * from "./utilitiesCatalogueData.js";
17
- export * from "./utilitiesCataloguePermission.js";
18
- export * from "./utilitiesNumericValues.js";
1
+ export * from "./CatalogueAPI.js";
2
+ export * from "./CfgProduct.js";
3
+ export * from "./io/CfgHistoryManager.js";
4
+ export * from "./io/CfgHistoryToProdConfConnector.js";
5
+ export * from "./io/CfgWindowMessageManager.js";
6
+ export * from "./io/CfgWindowMessageToProdConfConnector.js";
7
+ export * from "./material/CfgMaterialMapping.js";
8
+ export * from "./material/CfgMtrlApplication.js";
9
+ export * from "./material/CfgMtrlApplicationSource.js";
10
+ export * from "./material/CfgMtrlSource.js";
11
+ export * from "./material/CfgMtrlSourceWithMetaData.js";
12
+ export * from "./productConfiguration/CfgFeature.js";
13
+ export * from "./productConfiguration/CfgOption.js";
14
+ export * from "./productConfiguration/CfgProductConfiguration.js";
15
+ export * from "./productConfiguration/filters.js";
16
+ export * from "./productConfiguration/productParamsGenerator.js";
17
+ export * from "./productLoader.js";
18
+ export * from "./tasks/formats.js";
19
+ export * from "./tasks/TaskHandler.js";
20
+ export * from "./utilitiesCatalogueData.js";
21
+ export * from "./utilitiesCataloguePermission.js";
22
+ export * from "./utilitiesNumericValues.js";
@@ -0,0 +1,30 @@
1
+ import { CfgIOManager } from "./CfgIOManager.js";
2
+ export declare type CfgHistoryManagerSendData<D> = {
3
+ message: D;
4
+ qsKeyValues: Map<string, string | undefined> | undefined;
5
+ };
6
+ /**
7
+ * Instantiating the class will use the history api to update your
8
+ * url with configuration changes
9
+ * Only handles configuration, not product
10
+ */
11
+ export declare class CfgHistoryManager<D extends {
12
+ initial: boolean;
13
+ }> extends CfgIOManager<"popstate", CfgHistoryManagerSendData<D>> {
14
+ private readonly _useHistoryPush;
15
+ /**
16
+ * @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
17
+ */
18
+ constructor(_useHistoryPush: boolean);
19
+ protected doSend(messageKey: string, data: CfgHistoryManagerSendData<D>): void;
20
+ private static _makeUpdatedUrl;
21
+ private static _makeUpdatedQueryString;
22
+ /**
23
+ * @returns The current query string as a Map
24
+ */
25
+ static _currentQsKeyValues(): Map<string, string>;
26
+ private static _makeUpdatedState;
27
+ protected readonly eventType = "popstate";
28
+ protected getDataFromEvent(event: PopStateEvent): unknown;
29
+ }
30
+ //# sourceMappingURL=CfgHistoryManager.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { mapQueryString, unmapQueryString } from "@configura/web-utilities";
2
+ import { CfgIOManager } from "./CfgIOManager.js";
3
+ /**
4
+ * Instantiating the class will use the history api to update your
5
+ * url with configuration changes
6
+ * Only handles configuration, not product
7
+ */
8
+ export class CfgHistoryManager extends CfgIOManager {
9
+ /**
10
+ * @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
11
+ */
12
+ constructor(_useHistoryPush) {
13
+ super();
14
+ this._useHistoryPush = _useHistoryPush;
15
+ this.eventType = "popstate";
16
+ }
17
+ doSend(messageKey, data) {
18
+ const { qsKeyValues, message } = data;
19
+ const newUrl = qsKeyValues === undefined ? null : CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
20
+ const newState = CfgHistoryManager._makeUpdatedState(message, messageKey);
21
+ if (!message.initial && this._useHistoryPush) {
22
+ window.history.pushState(newState, "", newUrl);
23
+ }
24
+ else {
25
+ window.history.replaceState(newState, "", newUrl);
26
+ }
27
+ }
28
+ static _makeUpdatedUrl(qsKeyValues) {
29
+ const qs = this._makeUpdatedQueryString(qsKeyValues);
30
+ return `${window.location.origin}${window.location.pathname}${qs ? "?" : ""}${qs}${window.location.hash}`;
31
+ }
32
+ static _makeUpdatedQueryString(qsKeyValues) {
33
+ const currentKeyValues = this._currentQsKeyValues();
34
+ for (const [key, value] of qsKeyValues) {
35
+ if (value === undefined) {
36
+ currentKeyValues.delete(key);
37
+ }
38
+ else {
39
+ currentKeyValues.set(key, value);
40
+ }
41
+ }
42
+ return unmapQueryString(currentKeyValues);
43
+ }
44
+ /**
45
+ * @returns The current query string as a Map
46
+ */
47
+ static _currentQsKeyValues() {
48
+ return mapQueryString(window.location.search);
49
+ }
50
+ static _makeUpdatedState(message, messageKey) {
51
+ let messages = {};
52
+ const currentState = window.history.state;
53
+ if (CfgIOManager.isIOContainer(currentState)) {
54
+ messages = currentState.messages;
55
+ }
56
+ messages[messageKey] = message;
57
+ return CfgIOManager.makeContainer(messages);
58
+ }
59
+ getDataFromEvent(event) {
60
+ return event.state;
61
+ }
62
+ }
@@ -0,0 +1,10 @@
1
+ import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
2
+ import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
3
+ export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
4
+ export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<"popstate", CfgHistoryManagerSendData<CfgProdConfMessage>, CfgHistoryManager<CfgProdConfMessage>> {
5
+ private readonly _qsKey;
6
+ constructor(manager: CfgHistoryManager<CfgProdConfMessage>, _qsKey?: string, doValidate?: boolean);
7
+ protected getInitialProdConf(): string | undefined;
8
+ protected makeSendData(prodConfAsString: string, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
9
+ }
10
+ //# sourceMappingURL=CfgHistoryToProdConfConnector.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { CfgHistoryManager } from "./CfgHistoryManager.js";
2
+ import { CfgIOProdConfConnector } from "./CfgIOProdConfConnector.js";
3
+ export const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
4
+ export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
5
+ constructor(manager, _qsKey = STAGE_PROD_CONF_MESSAGE_KEY, doValidate = true) {
6
+ super(manager, doValidate);
7
+ this._qsKey = _qsKey;
8
+ }
9
+ getInitialProdConf() {
10
+ return CfgHistoryManager._currentQsKeyValues().get(this._qsKey);
11
+ }
12
+ makeSendData(prodConfAsString, initial) {
13
+ return {
14
+ message: this.makeMessage(prodConfAsString, initial),
15
+ qsKeyValues: initial
16
+ ? undefined
17
+ : new Map([[STAGE_PROD_CONF_MESSAGE_KEY, prodConfAsString]]),
18
+ };
19
+ }
20
+ }
@@ -0,0 +1,29 @@
1
+ declare type ConfiguraShebang = "c0nf1guraarug1fn0c";
2
+ declare type Listener = (m: unknown) => Promise<void>;
3
+ export declare type CfgIOContainer = {
4
+ shebang: ConfiguraShebang;
5
+ messages: {
6
+ [index: string]: unknown;
7
+ };
8
+ };
9
+ export declare abstract class CfgIOManager<K extends keyof WindowEventMap, S> {
10
+ static isIOContainer: (data: any) => data is CfgIOContainer;
11
+ static hasIOContainerMessageKey: (container: CfgIOContainer, messageKey: string) => boolean;
12
+ static getMessageFromIOContainer: (container: any, messageKey: string) => unknown;
13
+ static makeContainer: (messages: {
14
+ [index: string]: unknown;
15
+ }) => CfgIOContainer;
16
+ private _inhibitSend;
17
+ private _listeners;
18
+ private _getIndexOfListener;
19
+ listen: (l: Listener, messageKey: string) => void;
20
+ stopListen: (l: Listener) => void;
21
+ private _containerListenerBound;
22
+ protected _containerListener(event: WindowEventMap[K]): void;
23
+ send: (messageKey: string, data: S) => void;
24
+ protected abstract doSend(messageKey: string, data: S): void;
25
+ protected abstract readonly eventType: K;
26
+ protected abstract getDataFromEvent(event: WindowEventMap[K]): unknown;
27
+ }
28
+ export {};
29
+ //# sourceMappingURL=CfgIOManager.d.ts.map
@@ -0,0 +1,89 @@
1
+ const CONFIGURA_SHEBANG = "c0nf1guraarug1fn0c";
2
+ export class CfgIOManager {
3
+ constructor() {
4
+ // A lock to avoid circular write
5
+ this._inhibitSend = false;
6
+ this._listeners = [];
7
+ this._getIndexOfListener = (l) => this._listeners.findIndex((item) => l === item.l);
8
+ this.listen = (l, messageKey) => {
9
+ if (this._getIndexOfListener(l) !== -1) {
10
+ console.warn("Tried to add listener twice");
11
+ return;
12
+ }
13
+ const startListenToWindow = this._listeners.length === 0;
14
+ this._listeners.push({ l, messageKey });
15
+ if (startListenToWindow) {
16
+ window.addEventListener(this.eventType, this._containerListenerBound);
17
+ }
18
+ };
19
+ this.stopListen = (l) => {
20
+ const i = this._getIndexOfListener(l);
21
+ if (i === -1) {
22
+ console.warn("Tried to stopListen on unknown listener");
23
+ return;
24
+ }
25
+ this._listeners.splice(i, 1);
26
+ if (this._listeners.length === 0) {
27
+ window.removeEventListener(this.eventType, this._containerListenerBound);
28
+ }
29
+ };
30
+ this._containerListenerBound = this._containerListener.bind(this);
31
+ this.send = (messageKey, data) => {
32
+ if (this._inhibitSend) {
33
+ return;
34
+ }
35
+ this.doSend(messageKey, data);
36
+ };
37
+ }
38
+ _containerListener(event) {
39
+ const data = this.getDataFromEvent(event);
40
+ if (!CfgIOManager.isIOContainer(data)) {
41
+ return;
42
+ }
43
+ // The 15 or so rows below is one of the cases where I believe building a clever
44
+ // data structure of so would probably be worse for performance than just looping
45
+ // as the subscribers are expected to be very few
46
+ const listeners = this._listeners;
47
+ const allMessageKeys = listeners.reduce((a, c) => {
48
+ a.add(c.messageKey);
49
+ return a;
50
+ }, new Set());
51
+ this._inhibitSend = true;
52
+ const promises = [];
53
+ for (const messageKey of allMessageKeys) {
54
+ if (!CfgIOManager.hasIOContainerMessageKey(data, messageKey)) {
55
+ continue;
56
+ }
57
+ const message = CfgIOManager.getMessageFromIOContainer(data, messageKey);
58
+ for (const item of listeners) {
59
+ if (item.messageKey !== messageKey) {
60
+ continue;
61
+ }
62
+ promises.push(item.l(message));
63
+ }
64
+ }
65
+ Promise.all(promises)
66
+ .then(() => {
67
+ this._inhibitSend = false;
68
+ })
69
+ .catch(() => {
70
+ this._inhibitSend = false;
71
+ });
72
+ }
73
+ }
74
+ CfgIOManager.isIOContainer = (data) => data && data.shebang === CONFIGURA_SHEBANG;
75
+ CfgIOManager.hasIOContainerMessageKey = (container, messageKey) => messageKey in container.messages;
76
+ CfgIOManager.getMessageFromIOContainer = (container, messageKey) => {
77
+ if (!CfgIOManager.isIOContainer(container)) {
78
+ throw new Error("The passed data was not a CfgIOContainer. It is to be expected that such data messages can arrive, so please use isIOContainer function to filter them out before calling this.");
79
+ }
80
+ if (!CfgIOManager.hasIOContainerMessageKey(container, messageKey)) {
81
+ throw new Error(`The passed data did not have the messageKey "${messageKey}". You can test for this using hasIOContainerMessageKey function.`);
82
+ }
83
+ // It is assumed that if a message arrives with the right subMessageKey it can cast to T
84
+ return container.messages[messageKey];
85
+ };
86
+ CfgIOManager.makeContainer = (messages) => ({
87
+ shebang: CONFIGURA_SHEBANG,
88
+ messages,
89
+ });
@@ -0,0 +1,31 @@
1
+ import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
2
+ import { CfgIOManager } from "./CfgIOManager.js";
3
+ export declare type CfgProdConfMessage = {
4
+ version: string;
5
+ initial: boolean;
6
+ prodConfAsString: string;
7
+ };
8
+ export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageProdConf";
9
+ export declare const STAGE_PROD_CONF_MESSAGE_VERSION = "1.0";
10
+ export declare type ProdConfCallback = (prodConfAsString: string) => Promise<void>;
11
+ export declare abstract class CfgIOProdConfConnector<K extends keyof WindowEventMap, S, M extends CfgIOManager<K, S>> {
12
+ protected readonly _ioManager: M;
13
+ protected readonly _doValidate: boolean;
14
+ protected _product: CfgProduct | undefined;
15
+ private _stopListenToMessage;
16
+ private _stopListenToProdConf;
17
+ constructor(_ioManager: M, _doValidate: boolean);
18
+ setProduct: (product: CfgProduct | undefined) => Promise<void>;
19
+ protected abstract getInitialProdConf(): string | undefined;
20
+ protected abstract makeSendData(prodConfAsString: string, initial: boolean): S;
21
+ makeMessage(prodConfAsString: string, initial: boolean): CfgProdConfMessage;
22
+ makeMessageListener(callback: ProdConfCallback): (message: unknown) => Promise<void>;
23
+ /**
24
+ * Register the callback to listen for Product Configuration messages
25
+ * @returns A function which when called will cancel listening
26
+ */
27
+ listenForMessage(callback: ProdConfCallback): () => void;
28
+ makeProdConfListener(callback: ProdConfCallback): (n: CfgProductChangeNotification) => void;
29
+ listenForProdConf(product: CfgProduct, callback: ProdConfCallback): () => void;
30
+ }
31
+ //# sourceMappingURL=CfgIOProdConfConnector.d.ts.map
@@ -0,0 +1,98 @@
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
+ export const STAGE_PROD_CONF_MESSAGE_KEY = "stageProdConf";
11
+ export const STAGE_PROD_CONF_MESSAGE_VERSION = "1.0";
12
+ export class CfgIOProdConfConnector {
13
+ constructor(_ioManager, _doValidate) {
14
+ this._ioManager = _ioManager;
15
+ this._doValidate = _doValidate;
16
+ this._stopListenToMessage = undefined;
17
+ this._stopListenToProdConf = undefined;
18
+ this.setProduct = (product) => __awaiter(this, void 0, void 0, function* () {
19
+ var _a, _b;
20
+ const currentProduct = this._product;
21
+ const newProduct = product;
22
+ this._product = newProduct;
23
+ // If same product don't do anything at all
24
+ if (currentProduct !== undefined &&
25
+ newProduct !== undefined &&
26
+ currentProduct.isBackedBySame(newProduct)) {
27
+ return;
28
+ }
29
+ if (currentProduct !== undefined) {
30
+ (_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
31
+ (_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
32
+ }
33
+ if (newProduct === undefined) {
34
+ return;
35
+ }
36
+ if (currentProduct === undefined) {
37
+ const initialProdConf = this.getInitialProdConf();
38
+ if (initialProdConf !== undefined) {
39
+ yield newProduct.setFromApiSelectionString(initialProdConf, this._doValidate);
40
+ }
41
+ }
42
+ this._ioManager.send(STAGE_PROD_CONF_MESSAGE_KEY, this.makeSendData(newProduct.getApiSelectionAsString(), true));
43
+ this._stopListenToMessage = this.listenForMessage((prodConfAsString) => __awaiter(this, void 0, void 0, function* () {
44
+ if (prodConfAsString === newProduct.getApiSelectionAsString()) {
45
+ return;
46
+ }
47
+ yield newProduct.setFromApiSelectionString(prodConfAsString, this._doValidate);
48
+ }));
49
+ this._stopListenToProdConf = this.listenForProdConf(newProduct, (prodConfAsString) => __awaiter(this, void 0, void 0, function* () {
50
+ this._ioManager.send(STAGE_PROD_CONF_MESSAGE_KEY, this.makeSendData(prodConfAsString, false));
51
+ }));
52
+ });
53
+ }
54
+ makeMessage(prodConfAsString, initial) {
55
+ return {
56
+ version: STAGE_PROD_CONF_MESSAGE_VERSION,
57
+ initial,
58
+ prodConfAsString,
59
+ };
60
+ }
61
+ makeMessageListener(callback) {
62
+ return (message) => __awaiter(this, void 0, void 0, function* () {
63
+ const { version, prodConfAsString } = message;
64
+ if (version !== "1.0") {
65
+ console.error(`The a message was passed with an unsupported version "${version}". Currently only ${STAGE_PROD_CONF_MESSAGE_VERSION} is supported.`);
66
+ return;
67
+ }
68
+ yield callback(prodConfAsString);
69
+ });
70
+ }
71
+ /**
72
+ * Register the callback to listen for Product Configuration messages
73
+ * @returns A function which when called will cancel listening
74
+ */
75
+ listenForMessage(callback) {
76
+ const ioManager = this._ioManager;
77
+ const listener = this.makeMessageListener(callback);
78
+ ioManager.listen(listener, STAGE_PROD_CONF_MESSAGE_KEY);
79
+ return () => {
80
+ ioManager.stopListen(listener);
81
+ };
82
+ }
83
+ makeProdConfListener(callback) {
84
+ return (n) => {
85
+ if (!n.committed) {
86
+ return;
87
+ }
88
+ callback(n.freshRef.getApiSelectionAsString());
89
+ };
90
+ }
91
+ listenForProdConf(product, callback) {
92
+ const listener = this.makeProdConfListener(callback);
93
+ product.listenForChange(listener);
94
+ return () => {
95
+ product.stopListenForChange(listener);
96
+ };
97
+ }
98
+ }
@@ -0,0 +1,13 @@
1
+ import { CfgIOManager } from "./CfgIOManager.js";
2
+ export declare type CfgWindowMessageManagerSendData = unknown;
3
+ export declare class CfgWindowMessageManager extends CfgIOManager<"message", CfgWindowMessageManagerSendData> {
4
+ private readonly _remoteEnds;
5
+ private readonly _targetOrigin;
6
+ private readonly _acceptableMessageOrigin?;
7
+ constructor(_remoteEnds: Window[], _targetOrigin?: string, _acceptableMessageOrigin?: string | undefined);
8
+ protected doSend(messageKey: string, data: unknown): void;
9
+ protected _containerListener(event: MessageEvent<any>): void;
10
+ protected readonly eventType = "message";
11
+ protected getDataFromEvent(event: MessageEvent<any>): unknown;
12
+ }
13
+ //# sourceMappingURL=CfgWindowMessageManager.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { CfgIOManager } from "./CfgIOManager.js";
2
+ export class CfgWindowMessageManager extends CfgIOManager {
3
+ constructor(_remoteEnds, _targetOrigin = "*", _acceptableMessageOrigin) {
4
+ super();
5
+ this._remoteEnds = _remoteEnds;
6
+ this._targetOrigin = _targetOrigin;
7
+ this._acceptableMessageOrigin = _acceptableMessageOrigin;
8
+ this.eventType = "message";
9
+ }
10
+ doSend(messageKey, data) {
11
+ const container = CfgIOManager.makeContainer({
12
+ [messageKey]: data,
13
+ });
14
+ for (const remoteEnd of this._remoteEnds) {
15
+ remoteEnd.postMessage(container, this._targetOrigin);
16
+ }
17
+ }
18
+ _containerListener(event) {
19
+ if (this._acceptableMessageOrigin !== undefined &&
20
+ event.origin !== this._acceptableMessageOrigin) {
21
+ return;
22
+ }
23
+ super._containerListener(event);
24
+ }
25
+ getDataFromEvent(event) {
26
+ return event.data;
27
+ }
28
+ }
@@ -0,0 +1,13 @@
1
+ import { CfgIOProdConfConnector } from "./CfgIOProdConfConnector.js";
2
+ import { CfgWindowMessageManager, CfgWindowMessageManagerSendData } from "./CfgWindowMessageManager.js";
3
+ /**
4
+ * Instantiating the class will expose your product to:
5
+ * - Listen for configuration changes posted to this window
6
+ * - Send configuration changes using sendMessage
7
+ */
8
+ export declare class CfgWindowMessageToProdConfConnector extends CfgIOProdConfConnector<"message", CfgWindowMessageManagerSendData, CfgWindowMessageManager> {
9
+ constructor(manager: CfgWindowMessageManager, doValidate?: boolean);
10
+ protected getInitialProdConf(): string | undefined;
11
+ protected makeSendData(prodConfAsString: string, initial: boolean): CfgWindowMessageManagerSendData;
12
+ }
13
+ //# sourceMappingURL=CfgWindowMessageToProdConfConnector.d.ts.map
@@ -0,0 +1,17 @@
1
+ import { CfgIOProdConfConnector } from "./CfgIOProdConfConnector.js";
2
+ /**
3
+ * Instantiating the class will expose your product to:
4
+ * - Listen for configuration changes posted to this window
5
+ * - Send configuration changes using sendMessage
6
+ */
7
+ export class CfgWindowMessageToProdConfConnector extends CfgIOProdConfConnector {
8
+ constructor(manager, doValidate = true) {
9
+ super(manager, doValidate);
10
+ }
11
+ getInitialProdConf() {
12
+ return undefined;
13
+ }
14
+ makeSendData(prodConfAsString, initial) {
15
+ return this.makeMessage(prodConfAsString, initial);
16
+ }
17
+ }
@@ -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