@configura/web-api 1.6.1 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +18 -18
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/CatalogueAPI.d.ts +551 -507
- package/dist/CatalogueAPI.js +293 -280
- package/dist/CfgMeasure.d.ts +32 -32
- package/dist/CfgMeasure.js +30 -30
- package/dist/CfgProduct.d.ts +268 -258
- package/dist/CfgProduct.js +778 -747
- package/dist/CfgReferencePathHelper.d.ts +14 -0
- package/dist/CfgReferencePathHelper.js +13 -0
- package/dist/ConfigurationConverter.d.ts +5 -0
- package/dist/ConfigurationConverter.js +72 -0
- package/dist/index.d.ts +23 -20
- package/dist/index.js +23 -20
- package/dist/io/CfgHistoryManager.d.ts +51 -0
- package/dist/io/CfgHistoryManager.js +82 -0
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -0
- package/dist/io/CfgHistoryToProdConfConnector.js +56 -0
- package/dist/io/CfgIOManager.d.ts +49 -0
- package/dist/io/CfgIOManager.js +115 -0
- package/dist/io/CfgIOProdConfConnector.d.ts +53 -0
- package/dist/io/CfgIOProdConfConnector.js +141 -0
- package/dist/io/CfgObservableStateManager.d.ts +22 -0
- package/dist/io/CfgObservableStateManager.js +65 -0
- package/dist/io/CfgObservableStateToProdConfConnector.d.ts +15 -0
- package/dist/io/CfgObservableStateToProdConfConnector.js +16 -0
- package/dist/io/CfgWindowEventManager.d.ts +22 -0
- package/dist/io/CfgWindowEventManager.js +38 -0
- package/dist/io/CfgWindowMessageManager.d.ts +41 -0
- package/dist/io/CfgWindowMessageManager.js +84 -0
- package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +17 -0
- package/dist/io/CfgWindowMessageToProdConfConnector.js +18 -0
- package/dist/io/index.d.ts +9 -0
- package/dist/io/index.js +8 -0
- package/dist/material/CfgMaterialMapping.d.ts +7 -7
- package/dist/material/CfgMaterialMapping.js +181 -181
- package/dist/material/CfgMtrlApplication.d.ts +18 -18
- package/dist/material/CfgMtrlApplication.js +43 -43
- package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
- package/dist/material/CfgMtrlApplicationSource.js +8 -8
- package/dist/material/CfgMtrlSource.d.ts +19 -19
- package/dist/material/CfgMtrlSource.js +40 -40
- package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
- package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
- package/dist/productConfiguration/CfgFeature.d.ts +187 -188
- package/dist/productConfiguration/CfgFeature.js +645 -636
- package/dist/productConfiguration/CfgOption.d.ts +151 -150
- package/dist/productConfiguration/CfgOption.js +416 -426
- package/dist/productConfiguration/CfgProductConfiguration.d.ts +117 -120
- package/dist/productConfiguration/CfgProductConfiguration.js +307 -309
- package/dist/productConfiguration/filters.d.ts +15 -15
- package/dist/productConfiguration/filters.js +70 -70
- package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
- package/dist/productConfiguration/productParamsGenerator.js +51 -51
- package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
- package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -80
- package/dist/productLoader.d.ts +33 -33
- package/dist/productLoader.js +49 -49
- package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
- package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
- package/dist/syncGroups/SyncGroupsHandler.d.ts +40 -40
- package/dist/syncGroups/SyncGroupsHandler.js +359 -358
- package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
- package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
- package/dist/syncGroups/SyncGroupsState.d.ts +35 -35
- package/dist/syncGroups/SyncGroupsState.js +125 -125
- package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
- package/dist/syncGroups/SyncGroupsTransaction.js +576 -576
- package/dist/tasks/TaskHandler.d.ts +77 -78
- package/dist/tasks/TaskHandler.js +275 -276
- package/dist/tasks/formats.d.ts +4 -4
- package/dist/tasks/formats.js +7 -7
- package/dist/tests/testData/collectorForTest.d.ts +73 -73
- package/dist/tests/testData/collectorForTest.js +194 -194
- package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
- package/dist/tests/testData/dummyProductForTest.js +32 -36
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +277 -277
- package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
- package/dist/tests/testData/testDataCachedGetProduct.js +185 -185
- package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
- package/dist/tests/testData/testDataCachedPostValidate.js +183 -183
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
- package/dist/tests/testData/testDataOptions.d.ts +12 -12
- package/dist/tests/testData/testDataOptions.js +60 -60
- package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
- package/dist/tests/testData/testDataProductAggregatedPrice.js +187 -187
- package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
- package/dist/tests/testData/testDataUpcharge.js +119 -119
- package/dist/utilitiesCatalogueData.d.ts +42 -31
- package/dist/utilitiesCatalogueData.js +173 -162
- package/dist/utilitiesCataloguePermission.d.ts +38 -37
- package/dist/utilitiesCataloguePermission.js +79 -80
- package/dist/utilitiesNumericValues.d.ts +24 -24
- package/dist/utilitiesNumericValues.js +109 -109
- package/package.json +3 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DtoCatalogueParamsWithLang, DtoProductParamsWithLang } from "./CatalogueAPI";
|
|
2
|
+
/**
|
|
3
|
+
* These methods aims to provide a default suggested way of building
|
|
4
|
+
* URLs to Products and Catalogues. By using consistent URL:s copy-paste
|
|
5
|
+
* between systems becomes easy and this can aid when debugging.
|
|
6
|
+
* Using this format on URL is no requirement. In fact, most of our
|
|
7
|
+
* integrators do not, as they do not expose the Catalogue-path.
|
|
8
|
+
* Internally at Configura we try to stick with this format.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CfgReferencePathHelper {
|
|
11
|
+
static getCataloguePath: (browsingRootUrl: string, catParams: DtoCatalogueParamsWithLang) => string;
|
|
12
|
+
static getProductPath: (browsingRootUrl: string, productParams: DtoProductParamsWithLang) => string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=CfgReferencePathHelper.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { encodeURIComponents } from "@configura/web-utilities";
|
|
2
|
+
/**
|
|
3
|
+
* These methods aims to provide a default suggested way of building
|
|
4
|
+
* URLs to Products and Catalogues. By using consistent URL:s copy-paste
|
|
5
|
+
* between systems becomes easy and this can aid when debugging.
|
|
6
|
+
* Using this format on URL is no requirement. In fact, most of our
|
|
7
|
+
* integrators do not, as they do not expose the Catalogue-path.
|
|
8
|
+
* Internally at Configura we try to stick with this format.
|
|
9
|
+
*/
|
|
10
|
+
export class CfgReferencePathHelper {
|
|
11
|
+
}
|
|
12
|
+
CfgReferencePathHelper.getCataloguePath = (browsingRootUrl, catParams) => `${browsingRootUrl}/${encodeURIComponents(catParams.cid, catParams.lang, catParams.enterprise, catParams.prdCat, catParams.prdCatVersion, catParams.vendor, catParams.priceList)}`;
|
|
13
|
+
CfgReferencePathHelper.getProductPath = (browsingRootUrl, productParams) => `${CfgReferencePathHelper.getCataloguePath(browsingRootUrl, productParams)}/product/${encodeURIComponent(productParams.partNumber)}`;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DtoAdditionalProductConfiguration, DtoConfAddProd, DtoConfFeature, DtoConfProd, DtoSelectedOption } from "./CatalogueAPI.js";
|
|
2
|
+
export declare const isDtoConfProdAdditional: (value: DtoConfProd) => value is DtoConfAddProd;
|
|
3
|
+
export declare const convertDtoConfProdToV1: (conf: DtoConfProd, silenceWarnings?: boolean) => DtoAdditionalProductConfiguration;
|
|
4
|
+
export declare const convertDtoConfFeaturesToSelOptions: (features: DtoConfFeature[], silenceWarnings?: boolean) => DtoSelectedOption[];
|
|
5
|
+
//# sourceMappingURL=ConfigurationConverter.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const isDtoConfProdAdditional = (value) => "refKey" in value;
|
|
2
|
+
// As this has potential to flood the terminal we only inform once
|
|
3
|
+
let hasInformedAboutProdParams = false;
|
|
4
|
+
let hasInformedAboutGroupCode = false;
|
|
5
|
+
let hasInformedAboutUnit = false;
|
|
6
|
+
export const convertDtoConfProdToV1 = (conf, silenceWarnings = false) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
if (!silenceWarnings && conf.prodParams !== undefined && !hasInformedAboutProdParams) {
|
|
9
|
+
hasInformedAboutProdParams = true;
|
|
10
|
+
console.info("Incoming DtoProductConfiguration contains prodParams. These will be ignored.");
|
|
11
|
+
}
|
|
12
|
+
const result = {
|
|
13
|
+
selOptions: ((_a = conf.features) !== null && _a !== void 0 ? _a : []).map((f) => ({
|
|
14
|
+
code: "!~!",
|
|
15
|
+
next: convertDtoConfFeatureToApiSelection(f, silenceWarnings),
|
|
16
|
+
})),
|
|
17
|
+
additionalProducts: ((_b = conf.additionalProducts) !== null && _b !== void 0 ? _b : []).map((p) => convertDtoConfProdToV1(p, silenceWarnings)),
|
|
18
|
+
selected: true,
|
|
19
|
+
};
|
|
20
|
+
if (isDtoConfProdAdditional(conf)) {
|
|
21
|
+
result.refKey = conf.refKey;
|
|
22
|
+
result.selected = conf.selected;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
export const convertDtoConfFeaturesToSelOptions = (features, silenceWarnings = false) => (features !== null && features !== void 0 ? features : []).map((f) => ({
|
|
27
|
+
code: "!~!",
|
|
28
|
+
next: convertDtoConfFeatureToApiSelection(f, silenceWarnings),
|
|
29
|
+
}));
|
|
30
|
+
const convertDtoConfFeatureToApiSelection = (feature, silenceWarnings) => {
|
|
31
|
+
const { groupCode, options, unit } = feature;
|
|
32
|
+
if (!silenceWarnings && groupCode !== undefined && !hasInformedAboutGroupCode) {
|
|
33
|
+
hasInformedAboutGroupCode = true;
|
|
34
|
+
console.info("Incoming DtoFeature contains groupCode. It will be ignored.");
|
|
35
|
+
}
|
|
36
|
+
if (!silenceWarnings && unit !== undefined && !hasInformedAboutUnit) {
|
|
37
|
+
hasInformedAboutUnit = true;
|
|
38
|
+
console.info("Incoming DtoFeature contains a unit. It will be ignored.");
|
|
39
|
+
}
|
|
40
|
+
const result = {};
|
|
41
|
+
for (const option of (options !== null && options !== void 0 ? options : []).filter((o) => o.selected)) {
|
|
42
|
+
result[option.code] = convertDtoConfOptionToSelectedOption(option, silenceWarnings);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
const convertDtoConfOptionToSelectedOption = (option, silenceWarnings) => {
|
|
47
|
+
const { features, code, numericValue } = option;
|
|
48
|
+
const selectionTrees = (features !== null && features !== void 0 ? features : []).map((f) => convertDtoConfFeatureToApiSelection(f, silenceWarnings));
|
|
49
|
+
const mergedSelectionTree = {};
|
|
50
|
+
let anyItems = false;
|
|
51
|
+
for (const selectionTree of selectionTrees) {
|
|
52
|
+
if (selectionTree === undefined) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
for (const key of Object.keys(selectionTree)) {
|
|
56
|
+
if (mergedSelectionTree[key] !== undefined) {
|
|
57
|
+
console.warn(`The key (${key}) is already used in the selection tree. Option code: "${code}".`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
mergedSelectionTree[key] = selectionTree[key];
|
|
61
|
+
anyItems = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const selectedOption = {
|
|
65
|
+
code,
|
|
66
|
+
numericValue,
|
|
67
|
+
};
|
|
68
|
+
if (anyItems) {
|
|
69
|
+
selectedOption.next = mergedSelectionTree;
|
|
70
|
+
}
|
|
71
|
+
return selectedOption;
|
|
72
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
export * from "./CatalogueAPI.js";
|
|
2
|
-
export * from "./CfgProduct.js";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./material/
|
|
7
|
-
export * from "./material/
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./productConfiguration/
|
|
12
|
-
export * from "./productConfiguration/
|
|
13
|
-
export * from "./
|
|
14
|
-
export * from "./
|
|
15
|
-
export * from "./
|
|
16
|
-
export * from "./
|
|
17
|
-
export * from "./
|
|
18
|
-
export * from "./
|
|
19
|
-
export * from "./
|
|
20
|
-
export * from "./
|
|
1
|
+
export * from "./CatalogueAPI.js";
|
|
2
|
+
export * from "./CfgProduct.js";
|
|
3
|
+
export * from "./CfgReferencePathHelper.js";
|
|
4
|
+
export * from "./ConfigurationConverter.js";
|
|
5
|
+
export * from "./io/index.js";
|
|
6
|
+
export * from "./material/CfgMaterialMapping.js";
|
|
7
|
+
export * from "./material/CfgMtrlApplication.js";
|
|
8
|
+
export * from "./material/CfgMtrlApplicationSource.js";
|
|
9
|
+
export * from "./material/CfgMtrlSource.js";
|
|
10
|
+
export * from "./material/CfgMtrlSourceWithMetaData.js";
|
|
11
|
+
export * from "./productConfiguration/CfgFeature.js";
|
|
12
|
+
export * from "./productConfiguration/CfgOption.js";
|
|
13
|
+
export * from "./productConfiguration/CfgProductConfiguration.js";
|
|
14
|
+
export * from "./productConfiguration/filters.js";
|
|
15
|
+
export * from "./productConfiguration/productParamsGenerator.js";
|
|
16
|
+
export * from "./productLoader.js";
|
|
17
|
+
export * from "./syncGroups/SyncGroupsApplyMode.js";
|
|
18
|
+
export * from "./syncGroups/SyncGroupsHandler.js";
|
|
19
|
+
export * from "./tasks/formats.js";
|
|
20
|
+
export * from "./tasks/TaskHandler.js";
|
|
21
|
+
export * from "./utilitiesCatalogueData.js";
|
|
22
|
+
export * from "./utilitiesCataloguePermission.js";
|
|
23
|
+
export * from "./utilitiesNumericValues.js";
|
|
21
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
export * from "./CatalogueAPI.js";
|
|
2
|
-
export * from "./CfgProduct.js";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./material/
|
|
7
|
-
export * from "./material/
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./productConfiguration/
|
|
12
|
-
export * from "./productConfiguration/
|
|
13
|
-
export * from "./
|
|
14
|
-
export * from "./
|
|
15
|
-
export * from "./
|
|
16
|
-
export * from "./
|
|
17
|
-
export * from "./
|
|
18
|
-
export * from "./
|
|
19
|
-
export * from "./
|
|
20
|
-
export * from "./
|
|
1
|
+
export * from "./CatalogueAPI.js";
|
|
2
|
+
export * from "./CfgProduct.js";
|
|
3
|
+
export * from "./CfgReferencePathHelper.js";
|
|
4
|
+
export * from "./ConfigurationConverter.js";
|
|
5
|
+
export * from "./io/index.js";
|
|
6
|
+
export * from "./material/CfgMaterialMapping.js";
|
|
7
|
+
export * from "./material/CfgMtrlApplication.js";
|
|
8
|
+
export * from "./material/CfgMtrlApplicationSource.js";
|
|
9
|
+
export * from "./material/CfgMtrlSource.js";
|
|
10
|
+
export * from "./material/CfgMtrlSourceWithMetaData.js";
|
|
11
|
+
export * from "./productConfiguration/CfgFeature.js";
|
|
12
|
+
export * from "./productConfiguration/CfgOption.js";
|
|
13
|
+
export * from "./productConfiguration/CfgProductConfiguration.js";
|
|
14
|
+
export * from "./productConfiguration/filters.js";
|
|
15
|
+
export * from "./productConfiguration/productParamsGenerator.js";
|
|
16
|
+
export * from "./productLoader.js";
|
|
17
|
+
export * from "./syncGroups/SyncGroupsApplyMode.js";
|
|
18
|
+
export * from "./syncGroups/SyncGroupsHandler.js";
|
|
19
|
+
export * from "./tasks/formats.js";
|
|
20
|
+
export * from "./tasks/TaskHandler.js";
|
|
21
|
+
export * from "./utilitiesCatalogueData.js";
|
|
22
|
+
export * from "./utilitiesCataloguePermission.js";
|
|
23
|
+
export * from "./utilitiesNumericValues.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
2
|
+
declare type CfgHistoryManagerMessageData = {
|
|
3
|
+
initial: boolean;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The collected data used when sending. For history this both contains the message, which is
|
|
7
|
+
* used as the "state" in the history-frame, and the qsKeyValues, which are used in the URL.
|
|
8
|
+
* When navigating back and forth the stage (message) is used to restore the old state. When
|
|
9
|
+
* opening a window with no prior history the Query String will be used.
|
|
10
|
+
*/
|
|
11
|
+
export declare type CfgHistoryManagerSendData<D> = {
|
|
12
|
+
message: D;
|
|
13
|
+
useHistoryPush: boolean;
|
|
14
|
+
qsKeyValues: Map<string, string | undefined>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* This class does nothing on it's own. It is used to coordinate writing to the history, that
|
|
18
|
+
* is, updating the browsing history.
|
|
19
|
+
*/
|
|
20
|
+
export declare class CfgHistoryManager extends CfgWindowEventManager<"popstate", CfgHistoryManagerSendData<CfgHistoryManagerMessageData>> {
|
|
21
|
+
private static _instance;
|
|
22
|
+
static get instance(): CfgHistoryManager;
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Write to the history
|
|
26
|
+
*/
|
|
27
|
+
send(messageKey: string, data: CfgHistoryManagerSendData<CfgHistoryManagerMessageData>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Takes the current in browser URL and updates it with the provided Query String values.
|
|
30
|
+
* Old Query String is replaced.
|
|
31
|
+
*/
|
|
32
|
+
private static _makeUpdatedUrl;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the current in browser Query String updated with the key values provided.
|
|
35
|
+
* If a value is undefined in the passed map it will be deleted from the Query String.
|
|
36
|
+
*/
|
|
37
|
+
private static _makeUpdatedQueryString;
|
|
38
|
+
/**
|
|
39
|
+
* @returns The current in browser Query String as a Map
|
|
40
|
+
*/
|
|
41
|
+
static currentQsKeyValues(): Map<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* If the passed currentState is a CfgIOContainer it will update it with the
|
|
44
|
+
* passed message. If not it will create a new CfgIOContainer with the message.
|
|
45
|
+
*/
|
|
46
|
+
private static _makeUpdatedState;
|
|
47
|
+
protected readonly eventType = "popstate";
|
|
48
|
+
protected getDataFromEvent(event: PopStateEvent): unknown;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=CfgHistoryManager.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { mapQueryString, unmapQueryString } from "@configura/web-utilities";
|
|
2
|
+
import { CfgIOManager } from "./CfgIOManager.js";
|
|
3
|
+
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
4
|
+
/**
|
|
5
|
+
* This class does nothing on it's own. It is used to coordinate writing to the history, that
|
|
6
|
+
* is, updating the browsing history.
|
|
7
|
+
*/
|
|
8
|
+
export class CfgHistoryManager extends CfgWindowEventManager {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.eventType = "popstate";
|
|
12
|
+
}
|
|
13
|
+
static get instance() {
|
|
14
|
+
if (this._instance === undefined) {
|
|
15
|
+
this._instance = new CfgHistoryManager();
|
|
16
|
+
}
|
|
17
|
+
return this._instance;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Write to the history
|
|
21
|
+
*/
|
|
22
|
+
send(messageKey, data) {
|
|
23
|
+
const { qsKeyValues, message, useHistoryPush } = data;
|
|
24
|
+
// Initial data is before user interaction has happened
|
|
25
|
+
const initial = message.initial;
|
|
26
|
+
// At initial we do not replace the URL as we presumable have the defaults
|
|
27
|
+
const newUrl = initial ? null : CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
|
|
28
|
+
// ...but we do replace the state so that we can in the future browse back to here
|
|
29
|
+
const newState = CfgHistoryManager._makeUpdatedState(window.history.state, message, messageKey);
|
|
30
|
+
if (initial || !useHistoryPush || this.receiveInProgress) {
|
|
31
|
+
window.history.replaceState(newState, "", newUrl);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
window.history.pushState(newState, "", newUrl);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Takes the current in browser URL and updates it with the provided Query String values.
|
|
39
|
+
* Old Query String is replaced.
|
|
40
|
+
*/
|
|
41
|
+
static _makeUpdatedUrl(qsKeyValues) {
|
|
42
|
+
const qs = this._makeUpdatedQueryString(qsKeyValues);
|
|
43
|
+
return `${window.location.origin}${window.location.pathname}${qs ? "?" : ""}${qs}${window.location.hash}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the current in browser Query String updated with the key values provided.
|
|
47
|
+
* If a value is undefined in the passed map it will be deleted from the Query String.
|
|
48
|
+
*/
|
|
49
|
+
static _makeUpdatedQueryString(qsKeyValues) {
|
|
50
|
+
const currentKeyValues = this.currentQsKeyValues();
|
|
51
|
+
for (const [key, value] of qsKeyValues) {
|
|
52
|
+
if (value === undefined) {
|
|
53
|
+
currentKeyValues.delete(key);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
currentKeyValues.set(key, value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return unmapQueryString(currentKeyValues);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @returns The current in browser Query String as a Map
|
|
63
|
+
*/
|
|
64
|
+
static currentQsKeyValues() {
|
|
65
|
+
return mapQueryString(window.location.search);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* If the passed currentState is a CfgIOContainer it will update it with the
|
|
69
|
+
* passed message. If not it will create a new CfgIOContainer with the message.
|
|
70
|
+
*/
|
|
71
|
+
static _makeUpdatedState(currentState, message, messageKey) {
|
|
72
|
+
let messages = {};
|
|
73
|
+
if (CfgIOManager.isIOContainer(currentState)) {
|
|
74
|
+
messages = currentState.messages;
|
|
75
|
+
}
|
|
76
|
+
messages[messageKey] = message;
|
|
77
|
+
return CfgIOManager.makeContainer(messages);
|
|
78
|
+
}
|
|
79
|
+
getDataFromEvent(event) {
|
|
80
|
+
return event.state;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DtoConfProd } from "../CatalogueAPI.js";
|
|
2
|
+
import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
|
|
3
|
+
import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
|
|
4
|
+
export declare function dtoConfToString(conf: DtoConfProd): string;
|
|
5
|
+
export declare function stringToDtoConf(conf: string): DtoConfProd;
|
|
6
|
+
/**
|
|
7
|
+
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
|
|
10
|
+
private readonly _useHistoryPush;
|
|
11
|
+
private readonly _qsKey;
|
|
12
|
+
/**
|
|
13
|
+
* @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
|
|
14
|
+
* @param _qsKey The Query String key for product configuration.
|
|
15
|
+
* @param doValidate When popping from the history stack (navigating in the browser), should a navigate call be sent to the server to verify that the product configuration is still valid?
|
|
16
|
+
*/
|
|
17
|
+
constructor(manager: CfgHistoryManager, _useHistoryPush: boolean, _qsKey?: string, doValidate?: boolean);
|
|
18
|
+
protected getInitialProdConf(): DtoConfProd | undefined;
|
|
19
|
+
protected makeSendData(conf: DtoConfProd, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=CfgHistoryToProdConfConnector.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CfgHistoryManager } from "./CfgHistoryManager.js";
|
|
2
|
+
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
|
|
3
|
+
const jsonKeyRegex = /"([^"]+)":/g;
|
|
4
|
+
const keyMap = [
|
|
5
|
+
["configuration", "cn"],
|
|
6
|
+
["additionalProducts", "as"],
|
|
7
|
+
["prodParams", "pp"],
|
|
8
|
+
["refKey", "rk"],
|
|
9
|
+
["selected", "se"],
|
|
10
|
+
["features", "fs"],
|
|
11
|
+
["code", "cd"],
|
|
12
|
+
["options", "os"],
|
|
13
|
+
["numericValue", "nu"],
|
|
14
|
+
["groupCode", "gc"],
|
|
15
|
+
["unit", "un"],
|
|
16
|
+
];
|
|
17
|
+
// todo: Could be worth making faster
|
|
18
|
+
const toCompact = (key) => { var _a, _b; return (_b = (_a = keyMap.find((i) => i[0] === key)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : key; };
|
|
19
|
+
const toExpanded = (key) => { var _a, _b; return (_b = (_a = keyMap.find((i) => i[1] === key)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : key; };
|
|
20
|
+
export function dtoConfToString(conf) {
|
|
21
|
+
const stringified = JSON.stringify(conf, undefined, "");
|
|
22
|
+
return stringified.replace(jsonKeyRegex, (_, key) => `"${toCompact(key)}":`);
|
|
23
|
+
}
|
|
24
|
+
export function stringToDtoConf(conf) {
|
|
25
|
+
const expandedKeys = conf.replace(jsonKeyRegex, (_, key) => `"${toExpanded(key)}":`);
|
|
26
|
+
return JSON.parse(expandedKeys);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
30
|
+
*/
|
|
31
|
+
export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
32
|
+
/**
|
|
33
|
+
* @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
|
|
34
|
+
* @param _qsKey The Query String key for product configuration.
|
|
35
|
+
* @param doValidate When popping from the history stack (navigating in the browser), should a navigate call be sent to the server to verify that the product configuration is still valid?
|
|
36
|
+
*/
|
|
37
|
+
constructor(manager, _useHistoryPush, _qsKey = STAGE_PROD_CONF_MESSAGE_KEY, doValidate = true) {
|
|
38
|
+
super(manager, doValidate, CfgProdConfMessageVersions.V2dot0, false, false);
|
|
39
|
+
this._useHistoryPush = _useHistoryPush;
|
|
40
|
+
this._qsKey = _qsKey;
|
|
41
|
+
}
|
|
42
|
+
getInitialProdConf() {
|
|
43
|
+
const s = CfgHistoryManager.currentQsKeyValues().get(this._qsKey);
|
|
44
|
+
if (s === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return stringToDtoConf(s);
|
|
48
|
+
}
|
|
49
|
+
makeSendData(conf, initial) {
|
|
50
|
+
return {
|
|
51
|
+
message: this.makeMessage(conf, initial),
|
|
52
|
+
qsKeyValues: new Map([[STAGE_PROD_CONF_MESSAGE_KEY, dtoConfToString(conf)]]),
|
|
53
|
+
useHistoryPush: this._useHistoryPush,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare type ConfiguraAttribute = "C0nf1gura";
|
|
2
|
+
declare type ConfiguraShebang = "arug1fn0C";
|
|
3
|
+
declare const CONFIGURA_ATTRIBUTE: ConfiguraAttribute;
|
|
4
|
+
export declare type IOManagerListener = (data: unknown) => Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* The container format used when the environment is globally shared with things
|
|
7
|
+
* outside our control. The "shebang" is a magic string that should prevent from a
|
|
8
|
+
* CfgIOContainer being confused with something else.
|
|
9
|
+
*/
|
|
10
|
+
export declare type CfgIOContainer = {
|
|
11
|
+
[CONFIGURA_ATTRIBUTE]: ConfiguraShebang;
|
|
12
|
+
messages: {
|
|
13
|
+
[index: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Base class for classes handling input and output in globally shared environments.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class CfgIOManager<S> {
|
|
20
|
+
/**
|
|
21
|
+
* Listen for the message messageKey being received.
|
|
22
|
+
*/
|
|
23
|
+
listenForMessage(l: IOManagerListener, messageKey: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Removes the listener
|
|
26
|
+
*/
|
|
27
|
+
stopListenForMessage(l: IOManagerListener): boolean;
|
|
28
|
+
static isIOContainer: (data: unknown) => data is CfgIOContainer;
|
|
29
|
+
static hasIOContainerMessageKey: (container: CfgIOContainer, messageKey: string) => boolean;
|
|
30
|
+
static getMessageFromIOContainer: (container: unknown, messageKey: string) => unknown;
|
|
31
|
+
static makeContainer: (messages: {
|
|
32
|
+
[index: string]: unknown;
|
|
33
|
+
}) => CfgIOContainer;
|
|
34
|
+
private _receiveInProgress;
|
|
35
|
+
private static _inhibitAllReceive;
|
|
36
|
+
get receiveInProgress(): boolean;
|
|
37
|
+
private _messageListeners;
|
|
38
|
+
private _getIndexOfMessageListener;
|
|
39
|
+
get hasMessageListeners(): boolean;
|
|
40
|
+
protected _containerListener(data: unknown): void;
|
|
41
|
+
/**
|
|
42
|
+
* Send the data with messageKey. This can for example be pushing or
|
|
43
|
+
* replacing on the history stack or sending a message using the
|
|
44
|
+
* window.message API.
|
|
45
|
+
*/
|
|
46
|
+
abstract send(messageKey: string, data: S): void;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=CfgIOManager.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
const CONFIGURA_ATTRIBUTE = "C0nf1gura";
|
|
11
|
+
const CONFIGURA_SHEBANG = "arug1fn0C";
|
|
12
|
+
// Support function. Did not manage to check both attribute and value in one step
|
|
13
|
+
const hasConfiguraAttribute = (data) => {
|
|
14
|
+
return typeof data === "object" && data !== null;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Base class for classes handling input and output in globally shared environments.
|
|
18
|
+
*/
|
|
19
|
+
export class CfgIOManager {
|
|
20
|
+
constructor() {
|
|
21
|
+
// A lock to avoid circular write. Asynchronous conditions can make this not be enough.
|
|
22
|
+
// Avoid creating pre-conditions where this can happen.
|
|
23
|
+
this._receiveInProgress = false;
|
|
24
|
+
this._messageListeners = [];
|
|
25
|
+
this._getIndexOfMessageListener = (l) => this._messageListeners.findIndex((item) => l === item.l);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Listen for the message messageKey being received.
|
|
29
|
+
*/
|
|
30
|
+
listenForMessage(l, messageKey) {
|
|
31
|
+
if (this._getIndexOfMessageListener(l) !== -1) {
|
|
32
|
+
console.warn("Tried to add listener twice");
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
this._messageListeners.push({ l, messageKey });
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Removes the listener
|
|
40
|
+
*/
|
|
41
|
+
stopListenForMessage(l) {
|
|
42
|
+
const i = this._getIndexOfMessageListener(l);
|
|
43
|
+
if (i === -1) {
|
|
44
|
+
console.warn("Tried to stopListen on unknown listener");
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
this._messageListeners.splice(i, 1);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
get receiveInProgress() {
|
|
51
|
+
return this._receiveInProgress;
|
|
52
|
+
}
|
|
53
|
+
get hasMessageListeners() {
|
|
54
|
+
return 0 < this._messageListeners.length;
|
|
55
|
+
}
|
|
56
|
+
_containerListener(data) {
|
|
57
|
+
if (CfgIOManager._inhibitAllReceive) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!CfgIOManager.isIOContainer(data)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
CfgIOManager._inhibitAllReceive = true;
|
|
64
|
+
this._receiveInProgress = true;
|
|
65
|
+
// The 15 or so rows below is one of the cases where I believe building a clever
|
|
66
|
+
// data structure of so would probably be worse for performance than just looping
|
|
67
|
+
// as the subscribers are expected to be very few
|
|
68
|
+
const listeners = this._messageListeners;
|
|
69
|
+
const allMessageKeys = listeners.reduce((a, c) => {
|
|
70
|
+
a.add(c.messageKey);
|
|
71
|
+
return a;
|
|
72
|
+
}, new Set());
|
|
73
|
+
const promises = [];
|
|
74
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
for (const messageKey of allMessageKeys) {
|
|
76
|
+
if (!CfgIOManager.hasIOContainerMessageKey(data, messageKey)) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const message = CfgIOManager.getMessageFromIOContainer(data, messageKey);
|
|
80
|
+
for (const item of listeners) {
|
|
81
|
+
if (item.messageKey !== messageKey) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// async, not waiting. Might need to change.
|
|
85
|
+
promises.push(item.l(message));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}))();
|
|
89
|
+
Promise.all(promises)
|
|
90
|
+
.then(() => {
|
|
91
|
+
this._receiveInProgress = false;
|
|
92
|
+
CfgIOManager._inhibitAllReceive = false;
|
|
93
|
+
})
|
|
94
|
+
.catch(() => {
|
|
95
|
+
this._receiveInProgress = false;
|
|
96
|
+
CfgIOManager._inhibitAllReceive = false;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
CfgIOManager.isIOContainer = (data) => hasConfiguraAttribute(data) && data[CONFIGURA_ATTRIBUTE] === CONFIGURA_SHEBANG;
|
|
101
|
+
CfgIOManager.hasIOContainerMessageKey = (container, messageKey) => messageKey in container.messages;
|
|
102
|
+
CfgIOManager.getMessageFromIOContainer = (container, messageKey) => {
|
|
103
|
+
if (!CfgIOManager.isIOContainer(container)) {
|
|
104
|
+
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.");
|
|
105
|
+
}
|
|
106
|
+
if (!CfgIOManager.hasIOContainerMessageKey(container, messageKey)) {
|
|
107
|
+
throw new Error(`The passed data did not have the messageKey "${messageKey}". You can test for this using hasIOContainerMessageKey function.`);
|
|
108
|
+
}
|
|
109
|
+
return container.messages[messageKey];
|
|
110
|
+
};
|
|
111
|
+
CfgIOManager.makeContainer = (messages) => ({
|
|
112
|
+
[CONFIGURA_ATTRIBUTE]: CONFIGURA_SHEBANG,
|
|
113
|
+
messages,
|
|
114
|
+
});
|
|
115
|
+
CfgIOManager._inhibitAllReceive = false;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DtoAdditionalProductConfiguration, DtoConfProd } from "../CatalogueAPI.js";
|
|
2
|
+
import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
|
|
3
|
+
import { CfgIOManager } from "./CfgIOManager.js";
|
|
4
|
+
export declare type CfgProdConfMessageV1 = {
|
|
5
|
+
version: "1.0";
|
|
6
|
+
conf: DtoAdditionalProductConfiguration;
|
|
7
|
+
};
|
|
8
|
+
export declare type CfgProdConfMessageV2 = {
|
|
9
|
+
version: "2.0";
|
|
10
|
+
conf: DtoConfProd;
|
|
11
|
+
};
|
|
12
|
+
export declare type CfgProdConfMessage = {
|
|
13
|
+
initial: boolean;
|
|
14
|
+
subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[];
|
|
15
|
+
};
|
|
16
|
+
export declare enum CfgProdConfMessageVersions {
|
|
17
|
+
V1dot0 = 1,
|
|
18
|
+
V2dot0 = 2
|
|
19
|
+
}
|
|
20
|
+
export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
|
|
21
|
+
declare type ProdConfMessageCallback = (message: CfgProdConfMessage) => Promise<void>;
|
|
22
|
+
declare type ProdConfCallback = (conf: DtoConfProd) => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Base class for connecting the product configuration to an IO channel
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class CfgIOProdConfConnector<S> {
|
|
27
|
+
private readonly _ioManager;
|
|
28
|
+
private readonly _doValidate;
|
|
29
|
+
private readonly _sendVersions;
|
|
30
|
+
private readonly _includeExtendedDataInSend;
|
|
31
|
+
private readonly _includeProdParamsInSend;
|
|
32
|
+
private _product;
|
|
33
|
+
private _stopListenToMessage;
|
|
34
|
+
private _stopListenToProdConf;
|
|
35
|
+
constructor(_ioManager: CfgIOManager<S>, _doValidate: boolean, _sendVersions: CfgProdConfMessageVersions, _includeExtendedDataInSend: boolean, // Only v2.0
|
|
36
|
+
_includeProdParamsInSend: boolean);
|
|
37
|
+
destroy: () => void;
|
|
38
|
+
setProduct: (product: CfgProduct | undefined) => Promise<void>;
|
|
39
|
+
private _send;
|
|
40
|
+
protected getInitialProdConf(): DtoConfProd | undefined;
|
|
41
|
+
protected abstract makeSendData(conf: DtoConfProd, initial: boolean): S;
|
|
42
|
+
makeMessage(conf: DtoConfProd, initial: boolean): CfgProdConfMessage;
|
|
43
|
+
makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Register the callback to listen for Product Configuration messages
|
|
46
|
+
* @returns A function which when called will cancel listening
|
|
47
|
+
*/
|
|
48
|
+
listenForMessage(callback: ProdConfMessageCallback): () => void;
|
|
49
|
+
makeProdConfListener(callback: ProdConfCallback): (n: CfgProductChangeNotification) => void;
|
|
50
|
+
listenForProdConf(product: CfgProduct, callback: ProdConfCallback): () => void;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=CfgIOProdConfConnector.d.ts.map
|