@configura/web-api 1.6.0-iotest.4 → 1.6.1-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.
Files changed (51) hide show
  1. package/dist/CfgProduct.d.ts +34 -17
  2. package/dist/CfgProduct.js +118 -54
  3. package/dist/index.d.ts +2 -6
  4. package/dist/index.js +2 -6
  5. package/dist/productConfiguration/CfgFeature.d.ts +2 -1
  6. package/dist/productConfiguration/CfgFeature.js +26 -20
  7. package/dist/productConfiguration/CfgOption.d.ts +30 -8
  8. package/dist/productConfiguration/CfgOption.js +50 -18
  9. package/dist/productConfiguration/CfgProductConfiguration.d.ts +1 -2
  10. package/dist/productConfiguration/CfgProductConfiguration.js +9 -8
  11. package/dist/productConfiguration/filters.d.ts +1 -1
  12. package/dist/productConfiguration/filters.js +6 -3
  13. package/dist/syncGroups/SyncGroupsApplier.d.ts +20 -0
  14. package/dist/syncGroups/SyncGroupsApplier.js +520 -0
  15. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +21 -0
  16. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -0
  17. package/dist/syncGroups/SyncGroupsHandler.d.ts +40 -0
  18. package/dist/syncGroups/SyncGroupsHandler.js +352 -0
  19. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +27 -0
  20. package/dist/syncGroups/SyncGroupsPathHelper.js +89 -0
  21. package/dist/syncGroups/SyncGroupsState.d.ts +26 -0
  22. package/dist/syncGroups/SyncGroupsState.js +111 -0
  23. package/dist/syncGroups/SyncGroupsTransaction.d.ts +51 -0
  24. package/dist/syncGroups/SyncGroupsTransaction.js +100 -0
  25. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +24 -95
  26. package/dist/tests/testData/testDataCachedGetProduct.js +8 -19
  27. package/dist/tests/testData/testDataOptions.d.ts +13 -0
  28. package/dist/tests/testData/testDataOptions.js +60 -0
  29. package/dist/tests/testData/testDataProductAggregatedPrice.js +12 -23
  30. package/dist/tests/testData/testDataUpcharge.js +16 -48
  31. package/dist/utilitiesCatalogueData.d.ts +7 -1
  32. package/dist/utilitiesCatalogueData.js +104 -1
  33. package/package.json +3 -3
  34. package/dist/io/CfgHistoryManager.d.ts +0 -26
  35. package/dist/io/CfgHistoryManager.js +0 -58
  36. package/dist/io/CfgHistoryToCameraConfConnector.d.ts +0 -15
  37. package/dist/io/CfgHistoryToCameraConfConnector.js +0 -58
  38. package/dist/io/CfgHistoryToProdConfConnector.d.ts +0 -14
  39. package/dist/io/CfgHistoryToProdConfConnector.js +0 -24
  40. package/dist/io/CfgIOCameraConfConnector.d.ts +0 -31
  41. package/dist/io/CfgIOCameraConfConnector.js +0 -72
  42. package/dist/io/CfgIOManager.d.ts +0 -29
  43. package/dist/io/CfgIOManager.js +0 -89
  44. package/dist/io/CfgIOProdConfConnector.d.ts +0 -36
  45. package/dist/io/CfgIOProdConfConnector.js +0 -102
  46. package/dist/io/CfgWindowMessageManager.d.ts +0 -13
  47. package/dist/io/CfgWindowMessageManager.js +0 -33
  48. package/dist/io/CfgWindowMessageToCameraConfConnector.d.ts +0 -6
  49. package/dist/io/CfgWindowMessageToCameraConfConnector.js +0 -6
  50. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +0 -14
  51. package/dist/io/CfgWindowMessageToProdConfConnector.js +0 -17
@@ -4,7 +4,8 @@ export const makeProductKey = (cat, pKey) => `${makeCatalogueKey(cat)}-${pKey}`;
4
4
  export const makeSelOptionsKey = (options) => options.reduce((p, option) => {
5
5
  var _a;
6
6
  const { code, numericValue, next } = option;
7
- p += `_{${code}${numericValue === undefined ? "" : `_${numericValue.value}${(_a = numericValue.unit) !== null && _a !== void 0 ? _a : ""}`}`;
7
+ p += `_{${code}`;
8
+ p += numericValue === undefined ? "" : `_${numericValue.value}${(_a = numericValue.unit) !== null && _a !== void 0 ? _a : ""}`;
8
9
  if (next === undefined) {
9
10
  return p;
10
11
  }
@@ -63,3 +64,105 @@ export const decodeProductParams = (params) => {
63
64
  const decoded = Object.assign(Object.assign({}, decodeCatalogueParams(params)), { partNumber: decodeURIComponent(params.partNumber) });
64
65
  return decoded;
65
66
  };
67
+ export function isSameCatalogueParams(left, right) {
68
+ return (left.enterprise === right.enterprise &&
69
+ left.prdCat === right.prdCat &&
70
+ left.prdCatVersion === right.prdCatVersion &&
71
+ left.priceList === right.priceList &&
72
+ left.vendor === right.vendor);
73
+ }
74
+ export function isSameVector(left, right) {
75
+ return left.x === right.x && left.y === right.y && left.z === right.z;
76
+ }
77
+ export function isSameOrientation(left, right) {
78
+ return left.pitch === right.pitch && left.roll === right.roll && left.yaw === right.yaw;
79
+ }
80
+ export function isSameAnchor(left, right) {
81
+ var _a, _b;
82
+ if (left.code !== right.code) {
83
+ return false;
84
+ }
85
+ if (left.anchorPoint !== right.anchorPoint) {
86
+ return false;
87
+ }
88
+ const leftMeasurePriorities = (_a = left.measurePriority) !== null && _a !== void 0 ? _a : [];
89
+ const rightMeasurePriorities = (_b = right.measurePriority) !== null && _b !== void 0 ? _b : [];
90
+ if (leftMeasurePriorities.length !== rightMeasurePriorities.length) {
91
+ return false;
92
+ }
93
+ if (leftMeasurePriorities.some((p, i) => p.url !== rightMeasurePriorities[i].url)) {
94
+ return false;
95
+ }
96
+ return true;
97
+ }
98
+ export function isSameTransform(left, right) {
99
+ const leftTransformPos = left.pos;
100
+ const rightTransformPos = right.pos;
101
+ const leftTransformRot = left.rot;
102
+ const rightTransformRot = right.rot;
103
+ const leftTransformScale = left.scale;
104
+ const rightTransformScale = right.scale;
105
+ if ((leftTransformPos === undefined) !== (rightTransformPos === undefined)) {
106
+ return false;
107
+ }
108
+ if ((leftTransformRot === undefined) !== (rightTransformRot === undefined)) {
109
+ return false;
110
+ }
111
+ if ((leftTransformScale === undefined) !== (rightTransformScale === undefined)) {
112
+ return false;
113
+ }
114
+ if (leftTransformPos !== undefined &&
115
+ rightTransformPos !== undefined &&
116
+ !isSameVector(leftTransformPos, rightTransformPos)) {
117
+ return false;
118
+ }
119
+ if (leftTransformRot !== undefined &&
120
+ rightTransformRot !== undefined &&
121
+ !isSameOrientation(leftTransformRot, rightTransformRot)) {
122
+ return false;
123
+ }
124
+ if (leftTransformScale !== undefined &&
125
+ rightTransformScale !== undefined &&
126
+ !isSameVector(leftTransformScale, rightTransformScale)) {
127
+ return false;
128
+ }
129
+ return true;
130
+ }
131
+ export function isSameProductRef(left, right) {
132
+ if (left.refKey !== right.refKey) {
133
+ return false;
134
+ }
135
+ if (left.partNumber !== right.partNumber) {
136
+ return false;
137
+ }
138
+ if (!isSameCatalogueParams(left.catId, right.catId)) {
139
+ return false;
140
+ }
141
+ if (left.refDescription !== right.refDescription) {
142
+ return false;
143
+ }
144
+ const leftAnchor = left.anchor;
145
+ const rightAnchor = right.anchor;
146
+ if ((leftAnchor === undefined) !== (rightAnchor === undefined)) {
147
+ return false;
148
+ }
149
+ if (leftAnchor !== undefined &&
150
+ rightAnchor !== undefined &&
151
+ !isSameAnchor(leftAnchor, rightAnchor)) {
152
+ return false;
153
+ }
154
+ const leftTransform = left.transform;
155
+ const rightTransform = right.transform;
156
+ if ((leftTransform === undefined) !== (rightTransform === undefined)) {
157
+ return false;
158
+ }
159
+ if (leftTransform !== undefined &&
160
+ rightTransform !== undefined &&
161
+ !isSameTransform(leftTransform, rightTransform)) {
162
+ return false;
163
+ }
164
+ if (left.optional !== right.optional) {
165
+ return false;
166
+ }
167
+ return true;
168
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configura/web-api",
3
- "version": "1.6.0-iotest.4",
3
+ "version": "1.6.1-alpha.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@configura/web-utilities": "1.6.0-iotest.4"
26
+ "@configura/web-utilities": "1.6.1-alpha.2"
27
27
  },
28
- "gitHead": "d6eb7775e09c974d24dc5f44c97a26d4d42c3c68"
28
+ "gitHead": "e4b98f07293de3363e402a343194a9931d00732a"
29
29
  }
@@ -1,26 +0,0 @@
1
- import { CfgIOManager } from "./CfgIOManager.js";
2
- export declare type CfgHistoryManagerSendData<D> = {
3
- message: D;
4
- useHistoryPush: boolean;
5
- qsKeyValues: Map<string, string | undefined> | undefined;
6
- };
7
- /**
8
- * Instantiating the class will use the history api to update your
9
- * url with configuration changes
10
- * Only handles configuration, not product
11
- */
12
- export declare class CfgHistoryManager<D extends {
13
- initial: boolean;
14
- }> extends CfgIOManager<"popstate", CfgHistoryManagerSendData<D>> {
15
- protected doSend(messageKey: string, data: CfgHistoryManagerSendData<D>): void;
16
- private static _makeUpdatedUrl;
17
- private static _makeUpdatedQueryString;
18
- /**
19
- * @returns The current query string as a Map
20
- */
21
- static currentQsKeyValues(): Map<string, string>;
22
- private static _makeUpdatedState;
23
- protected readonly eventType = "popstate";
24
- protected getDataFromEvent(event: PopStateEvent): unknown;
25
- }
26
- //# sourceMappingURL=CfgHistoryManager.d.ts.map
@@ -1,58 +0,0 @@
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
- constructor() {
10
- super(...arguments);
11
- this.eventType = "popstate";
12
- }
13
- doSend(messageKey, data) {
14
- const { qsKeyValues, message, useHistoryPush } = data;
15
- const newUrl = qsKeyValues === undefined ? null : CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
16
- const newState = CfgHistoryManager._makeUpdatedState(message, messageKey);
17
- if (!message.initial && useHistoryPush) {
18
- window.history.pushState(newState, "", newUrl);
19
- }
20
- else {
21
- window.history.replaceState(newState, "", newUrl);
22
- }
23
- }
24
- static _makeUpdatedUrl(qsKeyValues) {
25
- const qs = this._makeUpdatedQueryString(qsKeyValues);
26
- return `${window.location.origin}${window.location.pathname}${qs ? "?" : ""}${qs}${window.location.hash}`;
27
- }
28
- static _makeUpdatedQueryString(qsKeyValues) {
29
- const currentKeyValues = this.currentQsKeyValues();
30
- for (const [key, value] of qsKeyValues) {
31
- if (value === undefined) {
32
- currentKeyValues.delete(key);
33
- }
34
- else {
35
- currentKeyValues.set(key, value);
36
- }
37
- }
38
- return unmapQueryString(currentKeyValues);
39
- }
40
- /**
41
- * @returns The current query string as a Map
42
- */
43
- static currentQsKeyValues() {
44
- return mapQueryString(window.location.search);
45
- }
46
- static _makeUpdatedState(message, messageKey) {
47
- let messages = {};
48
- const currentState = window.history.state;
49
- if (CfgIOManager.isIOContainer(currentState)) {
50
- messages = currentState.messages;
51
- }
52
- messages[messageKey] = message;
53
- return CfgIOManager.makeContainer(messages);
54
- }
55
- getDataFromEvent(event) {
56
- return event.state;
57
- }
58
- }
@@ -1,15 +0,0 @@
1
- import { Observable } from "@configura/web-utilities";
2
- import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
3
- import { CfgCameraConf, CfgCameraConfMessage, CfgIOCameraConfConnector } from "./CfgIOCameraConfConnector.js";
4
- export declare class CfgHistoryToCameraConfConnector extends CfgIOCameraConfConnector<"popstate", CfgHistoryManagerSendData<CfgCameraConfMessage>, CfgHistoryManager<CfgCameraConfMessage>> {
5
- private readonly defaults;
6
- private readonly _qsKeyYaw;
7
- private readonly _qsKeyPitch;
8
- static make(manager: CfgHistoryManager<CfgCameraConfMessage>, defaults: CfgCameraConf, cameraControl: Observable<CfgCameraConf>, qsKeyYaw?: string, qsKeyPitch?: string): {
9
- instance: CfgHistoryToCameraConfConnector;
10
- initial: CfgCameraConf;
11
- };
12
- private constructor();
13
- protected makeSendData(cameraConf: CfgCameraConf, initial: boolean): CfgHistoryManagerSendData<CfgCameraConfMessage>;
14
- }
15
- //# sourceMappingURL=CfgHistoryToCameraConfConnector.d.ts.map
@@ -1,58 +0,0 @@
1
- import { degToRad, radToDeg } from "@configura/web-utilities";
2
- import { CfgHistoryManager } from "./CfgHistoryManager.js";
3
- import { CfgIOCameraConfConnector, } from "./CfgIOCameraConfConnector.js";
4
- const YAW_QS_KEY = "stageyaw";
5
- const PITCH_QS_KEY = "stagepitch";
6
- function qsAsNumber(qsMap, key) {
7
- const asString = qsMap.get(key);
8
- if (asString === undefined) {
9
- return undefined;
10
- }
11
- const asNumber = parseFloat(asString);
12
- if (!isFinite(asNumber)) {
13
- return undefined;
14
- }
15
- return degToRad(asNumber);
16
- }
17
- function addToMap(map, key, value) {
18
- if (value === undefined) {
19
- map.delete(key);
20
- }
21
- else {
22
- const timesHundredString = `${Math.round(100 * radToDeg(value))}`;
23
- const decimalPlace = timesHundredString.length - 2;
24
- map.set(key, `${timesHundredString.substring(0, decimalPlace)}.${timesHundredString.substring(decimalPlace)}`);
25
- }
26
- }
27
- export class CfgHistoryToCameraConfConnector extends CfgIOCameraConfConnector {
28
- constructor(manager, defaults, initial, cameraControl, _qsKeyYaw, _qsKeyPitch) {
29
- super(manager, initial, cameraControl);
30
- this.defaults = defaults;
31
- this._qsKeyYaw = _qsKeyYaw;
32
- this._qsKeyPitch = _qsKeyPitch;
33
- }
34
- static make(manager, defaults, cameraControl, qsKeyYaw = YAW_QS_KEY, qsKeyPitch = PITCH_QS_KEY) {
35
- var _a, _b;
36
- const qsKeyValues = CfgHistoryManager.currentQsKeyValues();
37
- const initial = {
38
- yaw: (_a = qsAsNumber(qsKeyValues, qsKeyYaw)) !== null && _a !== void 0 ? _a : defaults.yaw,
39
- pitch: (_b = qsAsNumber(qsKeyValues, qsKeyPitch)) !== null && _b !== void 0 ? _b : defaults.pitch,
40
- };
41
- const instance = new CfgHistoryToCameraConfConnector(manager, defaults, initial, cameraControl, qsKeyYaw, qsKeyPitch);
42
- return { instance, initial };
43
- }
44
- makeSendData(cameraConf, initial) {
45
- let qsKeyValues = undefined;
46
- if (!initial &&
47
- !(this.defaults.pitch === cameraConf.pitch && this.defaults.yaw === cameraConf.yaw)) {
48
- qsKeyValues = new Map();
49
- addToMap(qsKeyValues, this._qsKeyYaw, cameraConf.yaw);
50
- addToMap(qsKeyValues, this._qsKeyPitch, cameraConf.pitch);
51
- }
52
- return {
53
- message: this.makeMessage(cameraConf, initial),
54
- qsKeyValues,
55
- useHistoryPush: false,
56
- };
57
- }
58
- }
@@ -1,14 +0,0 @@
1
- import { AdditionalProductConfiguration } from "../CatalogueAPI.js";
2
- import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
3
- import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
4
- export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<"popstate", CfgHistoryManagerSendData<CfgProdConfMessage>, CfgHistoryManager<CfgProdConfMessage>> {
5
- private readonly _useHistoryPush;
6
- private readonly _qsKey;
7
- /**
8
- * @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
9
- */
10
- constructor(manager: CfgHistoryManager<CfgProdConfMessage>, _useHistoryPush: boolean, _qsKey?: string, doValidate?: boolean);
11
- protected getInitialProdConf(): string | undefined;
12
- protected makeSendData(prodConf: AdditionalProductConfiguration, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
13
- }
14
- //# sourceMappingURL=CfgHistoryToProdConfConnector.d.ts.map
@@ -1,24 +0,0 @@
1
- import { CfgHistoryManager } from "./CfgHistoryManager.js";
2
- import { CfgIOProdConfConnector, prodConfToString, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
3
- export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
4
- /**
5
- * @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
6
- */
7
- constructor(manager, _useHistoryPush, _qsKey = STAGE_PROD_CONF_MESSAGE_KEY, doValidate = true) {
8
- super(manager, doValidate);
9
- this._useHistoryPush = _useHistoryPush;
10
- this._qsKey = _qsKey;
11
- }
12
- getInitialProdConf() {
13
- return CfgHistoryManager.currentQsKeyValues().get(this._qsKey);
14
- }
15
- makeSendData(prodConf, initial) {
16
- return {
17
- message: this.makeMessage(prodConf, initial),
18
- qsKeyValues: initial
19
- ? undefined
20
- : new Map([[STAGE_PROD_CONF_MESSAGE_KEY, prodConfToString(prodConf)]]),
21
- useHistoryPush: this._useHistoryPush,
22
- };
23
- }
24
- }
@@ -1,31 +0,0 @@
1
- import { Observable } from "@configura/web-utilities";
2
- import { CfgIOManager } from "./CfgIOManager.js";
3
- export declare type CfgCameraConf = {
4
- yaw?: number;
5
- pitch?: number;
6
- };
7
- export declare type CfgCameraConfMessage = {
8
- version: string;
9
- initial: boolean;
10
- } & CfgCameraConf;
11
- export declare const STAGE_CAMERA_CONF_MESSAGE_KEY = "stagecameraconf";
12
- export declare const STAGE_CAMERA_MESSAGE_VERSION = "1.0";
13
- declare type CameraConfMessageCallback = (message: CfgCameraConfMessage) => Promise<void>;
14
- declare type CameraConfCallback = (conf: CfgCameraConf) => Promise<void>;
15
- export declare abstract class CfgIOCameraConfConnector<K extends keyof WindowEventMap, S, M extends CfgIOManager<K, S>> {
16
- private readonly _ioManager;
17
- private readonly _cameraControl;
18
- constructor(_ioManager: M, initialCameraConf: CfgCameraConf, _cameraControl: Observable<CfgCameraConf>);
19
- private _delayId;
20
- protected abstract makeSendData(cameraConf: CfgCameraConf, initial: boolean): S;
21
- makeMessage(cameraConf: CfgCameraConf, initial: boolean): CfgCameraConfMessage;
22
- makeMessageListener(callback: CameraConfMessageCallback): (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: CameraConfMessageCallback): () => void;
28
- listenForCamera(callback: CameraConfCallback): () => void;
29
- }
30
- export {};
31
- //# sourceMappingURL=CfgIOCameraConfConnector.d.ts.map
@@ -1,72 +0,0 @@
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
- // Chrome is not happy if history updates are sent to rapidly.
11
- // And message receivers probably don't want to get flooded either.
12
- const THROTTLING_DELAY = 100;
13
- export const STAGE_CAMERA_CONF_MESSAGE_KEY = "stagecameraconf";
14
- export const STAGE_CAMERA_MESSAGE_VERSION = "1.0";
15
- export class CfgIOCameraConfConnector {
16
- constructor(_ioManager, initialCameraConf, _cameraControl) {
17
- this._ioManager = _ioManager;
18
- this._cameraControl = _cameraControl;
19
- _ioManager.send(STAGE_CAMERA_CONF_MESSAGE_KEY, this.makeSendData(initialCameraConf, true));
20
- this.listenForMessage((message) => __awaiter(this, void 0, void 0, function* () {
21
- if (this._delayId !== undefined) {
22
- return;
23
- }
24
- _cameraControl.notifyAll(message, this);
25
- }));
26
- this.listenForCamera((cameraConf) => __awaiter(this, void 0, void 0, function* () {
27
- window.clearTimeout(this._delayId);
28
- this._delayId = window.setTimeout(() => {
29
- _ioManager.send(STAGE_CAMERA_CONF_MESSAGE_KEY, this.makeSendData(cameraConf, false));
30
- this._delayId = undefined;
31
- }, THROTTLING_DELAY);
32
- }));
33
- }
34
- makeMessage(cameraConf, initial) {
35
- return {
36
- version: STAGE_CAMERA_MESSAGE_VERSION,
37
- initial,
38
- yaw: cameraConf.yaw,
39
- pitch: cameraConf.pitch,
40
- };
41
- }
42
- makeMessageListener(callback) {
43
- return (message) => __awaiter(this, void 0, void 0, function* () {
44
- const cameraConfMessage = message;
45
- const version = cameraConfMessage.version;
46
- if (version !== "1.0") {
47
- console.error(`The a message was passed with an unsupported version "${version}". Currently only ${STAGE_CAMERA_MESSAGE_VERSION} is supported.`);
48
- return;
49
- }
50
- yield callback(cameraConfMessage);
51
- });
52
- }
53
- /**
54
- * Register the callback to listen for Product Configuration messages
55
- * @returns A function which when called will cancel listening
56
- */
57
- listenForMessage(callback) {
58
- const ioManager = this._ioManager;
59
- const listener = this.makeMessageListener(callback);
60
- ioManager.listen(listener, STAGE_CAMERA_CONF_MESSAGE_KEY);
61
- return () => {
62
- ioManager.stopListen(listener);
63
- };
64
- }
65
- listenForCamera(callback) {
66
- const cameraControl = this._cameraControl;
67
- cameraControl.listen(callback, this);
68
- return () => {
69
- cameraControl.stopListen(callback);
70
- };
71
- }
72
- }
@@ -1,29 +0,0 @@
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
@@ -1,89 +0,0 @@
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
- });
@@ -1,36 +0,0 @@
1
- import { AdditionalProductConfiguration } from "../CatalogueAPI.js";
2
- import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
3
- import { CfgIOManager } from "./CfgIOManager.js";
4
- export declare type CfgProdConfMessage = {
5
- version: string;
6
- initial: boolean;
7
- prodConf: AdditionalProductConfiguration;
8
- };
9
- export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
10
- export declare const STAGE_PROD_CONF_MESSAGE_VERSION = "1.0";
11
- declare type ProdConfMessageCallback = (message: CfgProdConfMessage) => Promise<void>;
12
- declare type ProdConfCallback = (prodConf: AdditionalProductConfiguration) => Promise<void>;
13
- export declare function prodConfToString(conf: AdditionalProductConfiguration): string;
14
- export declare function stringToProdConf(conf: string): AdditionalProductConfiguration;
15
- export declare abstract class CfgIOProdConfConnector<K extends keyof WindowEventMap, S, M extends CfgIOManager<K, S>> {
16
- private readonly _ioManager;
17
- private readonly _doValidate;
18
- protected _product: CfgProduct | undefined;
19
- private _stopListenToMessage;
20
- private _stopListenToProdConf;
21
- constructor(_ioManager: M, _doValidate: boolean);
22
- setProduct: (product: CfgProduct | undefined) => Promise<void>;
23
- protected abstract getInitialProdConf(): string | undefined;
24
- protected abstract makeSendData(prodConf: AdditionalProductConfiguration, initial: boolean): S;
25
- makeMessage(prodConf: AdditionalProductConfiguration, initial: boolean): CfgProdConfMessage;
26
- makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
27
- /**
28
- * Register the callback to listen for Product Configuration messages
29
- * @returns A function which when called will cancel listening
30
- */
31
- listenForMessage(callback: ProdConfMessageCallback): () => void;
32
- makeProdConfListener(callback: ProdConfCallback): (n: CfgProductChangeNotification) => void;
33
- listenForProdConf(product: CfgProduct, callback: ProdConfCallback): () => void;
34
- }
35
- export {};
36
- //# sourceMappingURL=CfgIOProdConfConnector.d.ts.map