@configura/web-api 2.0.0-alpha.3 → 2.0.0-alpha.6
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/dist/CfgProduct.js +11 -8
- package/dist/io/CfgHistoryManager.d.ts +11 -1
- package/dist/io/CfgHistoryManager.js +16 -2
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +4 -4
- package/dist/io/CfgHistoryToProdConfConnector.js +5 -5
- package/dist/io/CfgIOProdConfConnector.d.ts +4 -0
- package/dist/io/CfgIOProdConfConnector.js +14 -10
- package/dist/io/CfgWindowMessageManager.js +3 -0
- package/package.json +3 -3
package/dist/CfgProduct.js
CHANGED
|
@@ -164,9 +164,11 @@ export class _CfgProductInternal {
|
|
|
164
164
|
}
|
|
165
165
|
return conf;
|
|
166
166
|
};
|
|
167
|
-
this.setDtoConf = (s, doValidate, productLoaderForGroupedLoad) => this
|
|
167
|
+
this.setDtoConf = (s, doValidate, productLoaderForGroupedLoad) => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return yield this.setApiSelection(convertDtoConfProdToV1(s), doValidate, productLoaderForGroupedLoad);
|
|
169
|
+
});
|
|
168
170
|
this.setApiSelection = (s, doValidate, productLoaderForGroupedLoad) => __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
return this._setApiSelectionWithOtherProduct(s, doValidate, productLoaderForGroupedLoad, undefined);
|
|
171
|
+
return yield this._setApiSelectionWithOtherProduct(s, doValidate, productLoaderForGroupedLoad, undefined);
|
|
170
172
|
});
|
|
171
173
|
this.copyFrom = (source, doValidate, productLoaderForGroupedLoad) => __awaiter(this, void 0, void 0, function* () {
|
|
172
174
|
return yield this._setApiSelectionWithOtherProduct(convertDtoConfProdToV1(source.getDtoConf(false, false)), doValidate, productLoaderForGroupedLoad, source);
|
|
@@ -203,8 +205,8 @@ export class _CfgProductInternal {
|
|
|
203
205
|
const sourceProductAdditionalProducts = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.additionalProducts;
|
|
204
206
|
assert(!sourceProductAdditionalProducts ||
|
|
205
207
|
additionalProductsCount === sourceProductAdditionalProducts.length, `Passed sourceProduct does not have the same number of additional products as this.`);
|
|
206
|
-
if ((yield Promise.all(apiSelectionAdditionalProducts.map((apiSelectionAdditionalProduct,
|
|
207
|
-
var
|
|
208
|
+
if ((yield Promise.all(apiSelectionAdditionalProducts.map((apiSelectionAdditionalProduct) => __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
var _b;
|
|
208
210
|
const refKey = apiSelectionAdditionalProduct.refKey;
|
|
209
211
|
assertDefined(refKey, "Additional product api configurations must have refKey.");
|
|
210
212
|
const i = additionalProducts.findIndex((a) => refKey === a.refKey);
|
|
@@ -212,12 +214,12 @@ export class _CfgProductInternal {
|
|
|
212
214
|
let sourceProductAdditionalProduct = undefined;
|
|
213
215
|
if (sourceProductAdditionalProducts !== undefined) {
|
|
214
216
|
sourceProductAdditionalProduct =
|
|
215
|
-
(
|
|
217
|
+
(_b = sourceProductAdditionalProducts.find((a) => refKey === a.refKey)) === null || _b === void 0 ? void 0 : _b._internal;
|
|
216
218
|
assertDefined(sourceProductAdditionalProduct, "Additional product not found in sourceProduct");
|
|
217
219
|
}
|
|
218
220
|
const additionalProduct = additionalProducts.splice(i, 1)[0]; // Splicing like this is okay because this is done synchronous. The setCon. is what is async.
|
|
219
|
-
return additionalProduct._internal._setApiSelectionWithOtherProduct(apiSelectionAdditionalProduct, doValidate, productLoaderForGroupedLoad, sourceProductAdditionalProduct);
|
|
220
|
-
}))).some((b) => b)) {
|
|
221
|
+
return yield additionalProduct._internal._setApiSelectionWithOtherProduct(apiSelectionAdditionalProduct, doValidate, productLoaderForGroupedLoad, sourceProductAdditionalProduct);
|
|
222
|
+
})))).some((b) => b)) {
|
|
221
223
|
change = true;
|
|
222
224
|
}
|
|
223
225
|
if (doValidate && configurationChange) {
|
|
@@ -596,12 +598,13 @@ prodParams, settings, optional, loadingObservable, parent, root, additionalProdu
|
|
|
596
598
|
const productResponse = yield productLoaderForGroupedLoad.getProduct(correctDefaultsOnCatalogueParams(prodParams));
|
|
597
599
|
const { productData, rootFeatureRefs, features: allRawFeatures, uuid, unit, } = productResponse;
|
|
598
600
|
const product = yield new Promise((initSuccess, initFail) => {
|
|
601
|
+
var _a;
|
|
599
602
|
const p = new _CfgProductInternal(() => {
|
|
600
603
|
// We absolutely do not want anyone to assign to this._configuration. So we want that field private.
|
|
601
604
|
// But we can not set the api selection synchronously. And the product configuration needs "this". So we use this callback.
|
|
602
605
|
// Feel free to find a nicer more readable solution :)
|
|
603
606
|
initSuccess(p);
|
|
604
|
-
}, initFail, productLoaderRaw, prodParams, settings, optional, !optional, rootFeatureRefs, allRawFeatures, uuid, unit, productData, productData.partsData.selOptions
|
|
607
|
+
}, initFail, productLoaderRaw, prodParams, settings, optional, !optional, rootFeatureRefs, allRawFeatures, uuid, unit, productData, (_a = productData.partsData.selOptions) !== null && _a !== void 0 ? _a : [], loadingObservable, parent, root, additionalProductRef, syncGroupHandler);
|
|
605
608
|
});
|
|
606
609
|
yield product._syncAndLoadAdditionalProducts(productLoaderForGroupedLoad);
|
|
607
610
|
// Product is guaranteed to be root
|
|
@@ -10,9 +10,19 @@ declare type CfgHistoryManagerMessageData = {
|
|
|
10
10
|
*/
|
|
11
11
|
export declare type CfgHistoryManagerSendData<D> = {
|
|
12
12
|
message: D;
|
|
13
|
-
|
|
13
|
+
historyWriteMode: CfgHistoryWriteMode;
|
|
14
14
|
qsKeyValues: Map<string, string | undefined>;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* @param Replace Just updates the URL
|
|
18
|
+
* @param Push Push makes the web browser navigation buttons navigate configuration changes.
|
|
19
|
+
* @param DoNotWrite Do not update the history at all.
|
|
20
|
+
*/
|
|
21
|
+
export declare enum CfgHistoryWriteMode {
|
|
22
|
+
Replace = "Replace",
|
|
23
|
+
Push = "Push",
|
|
24
|
+
DoNotWrite = "DoNotWrite"
|
|
25
|
+
}
|
|
16
26
|
/**
|
|
17
27
|
* This class does nothing on it's own. It is used to coordinate writing to the history, that
|
|
18
28
|
* is, updating the browsing history.
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { mapQueryString, unmapQueryString } from "@configura/web-utilities";
|
|
2
2
|
import { CfgIOManager } from "./CfgIOManager.js";
|
|
3
3
|
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
4
|
+
/**
|
|
5
|
+
* @param Replace Just updates the URL
|
|
6
|
+
* @param Push Push makes the web browser navigation buttons navigate configuration changes.
|
|
7
|
+
* @param DoNotWrite Do not update the history at all.
|
|
8
|
+
*/
|
|
9
|
+
export var CfgHistoryWriteMode;
|
|
10
|
+
(function (CfgHistoryWriteMode) {
|
|
11
|
+
CfgHistoryWriteMode["Replace"] = "Replace";
|
|
12
|
+
CfgHistoryWriteMode["Push"] = "Push";
|
|
13
|
+
CfgHistoryWriteMode["DoNotWrite"] = "DoNotWrite";
|
|
14
|
+
})(CfgHistoryWriteMode || (CfgHistoryWriteMode = {}));
|
|
4
15
|
/**
|
|
5
16
|
* This class does nothing on it's own. It is used to coordinate writing to the history, that
|
|
6
17
|
* is, updating the browsing history.
|
|
@@ -20,14 +31,17 @@ export class CfgHistoryManager extends CfgWindowEventManager {
|
|
|
20
31
|
* Write to the history
|
|
21
32
|
*/
|
|
22
33
|
send(messageKey, data) {
|
|
23
|
-
const { qsKeyValues, message,
|
|
34
|
+
const { qsKeyValues, message, historyWriteMode } = data;
|
|
35
|
+
if (historyWriteMode === CfgHistoryWriteMode.DoNotWrite) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
24
38
|
// Initial data is before user interaction has happened
|
|
25
39
|
const initial = message.initial;
|
|
26
40
|
// At initial we do not replace the URL as we presumable have the defaults
|
|
27
41
|
const newUrl = initial ? null : CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
|
|
28
42
|
// ...but we do replace the state so that we can in the future browse back to here
|
|
29
43
|
const newState = CfgHistoryManager._makeUpdatedState(window.history.state, message, messageKey);
|
|
30
|
-
if (initial ||
|
|
44
|
+
if (initial || historyWriteMode === CfgHistoryWriteMode.Replace || this.receiveInProgress) {
|
|
31
45
|
window.history.replaceState(newState, "", newUrl);
|
|
32
46
|
}
|
|
33
47
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DtoConfProd } from "../CatalogueAPI.js";
|
|
2
|
-
import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
|
|
2
|
+
import { CfgHistoryManager, CfgHistoryManagerSendData, CfgHistoryWriteMode } from "./CfgHistoryManager.js";
|
|
3
3
|
import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
|
|
4
4
|
export declare function dtoConfToString(conf: DtoConfProd): string;
|
|
5
5
|
export declare function stringToDtoConf(conf: string): DtoConfProd;
|
|
@@ -7,14 +7,14 @@ export declare function stringToDtoConf(conf: string): DtoConfProd;
|
|
|
7
7
|
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
8
8
|
*/
|
|
9
9
|
export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
|
|
10
|
-
private readonly
|
|
10
|
+
private readonly _historyWriteMode;
|
|
11
11
|
private readonly _qsKey;
|
|
12
12
|
/**
|
|
13
|
-
* @param
|
|
13
|
+
* @param _historyWriteMode What way to update history.
|
|
14
14
|
* @param _qsKey The Query String key for product configuration.
|
|
15
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
16
|
*/
|
|
17
|
-
constructor(manager: CfgHistoryManager,
|
|
17
|
+
constructor(manager: CfgHistoryManager, _historyWriteMode: CfgHistoryWriteMode, _qsKey?: string, doValidate?: boolean);
|
|
18
18
|
protected getInitialProdConf(): DtoConfProd | undefined;
|
|
19
19
|
protected makeSendData(conf: DtoConfProd, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
|
|
20
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CfgHistoryManager } from "./CfgHistoryManager.js";
|
|
1
|
+
import { CfgHistoryManager, } from "./CfgHistoryManager.js";
|
|
2
2
|
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
|
|
3
3
|
const jsonKeyRegex = /"([^"]+)":/g;
|
|
4
4
|
const keyMap = [
|
|
@@ -30,13 +30,13 @@ export function stringToDtoConf(conf) {
|
|
|
30
30
|
*/
|
|
31
31
|
export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
32
32
|
/**
|
|
33
|
-
* @param
|
|
33
|
+
* @param _historyWriteMode What way to update history.
|
|
34
34
|
* @param _qsKey The Query String key for product configuration.
|
|
35
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
36
|
*/
|
|
37
|
-
constructor(manager,
|
|
37
|
+
constructor(manager, _historyWriteMode, _qsKey = STAGE_PROD_CONF_MESSAGE_KEY, doValidate = true) {
|
|
38
38
|
super(manager, doValidate, CfgProdConfMessageVersions.V2dot0, false, false);
|
|
39
|
-
this.
|
|
39
|
+
this._historyWriteMode = _historyWriteMode;
|
|
40
40
|
this._qsKey = _qsKey;
|
|
41
41
|
}
|
|
42
42
|
getInitialProdConf() {
|
|
@@ -50,7 +50,7 @@ export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
|
50
50
|
return {
|
|
51
51
|
message: this.makeMessage(conf, initial),
|
|
52
52
|
qsKeyValues: new Map([[STAGE_PROD_CONF_MESSAGE_KEY, dtoConfToString(conf)]]),
|
|
53
|
-
|
|
53
|
+
historyWriteMode: this._historyWriteMode,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { DtoAdditionalProductConfiguration, DtoConfProd } from "../CatalogueAPI.js";
|
|
2
2
|
import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
|
|
3
3
|
import { CfgIOManager } from "./CfgIOManager.js";
|
|
4
|
+
export declare const isCfgProdConfMessage: (data: unknown) => data is CfgProdConfMessageV1 | CfgProdConfMessageV2;
|
|
4
5
|
export declare type CfgProdConfMessageV1 = {
|
|
5
6
|
version: "1.0";
|
|
6
7
|
conf: DtoAdditionalProductConfiguration;
|
|
7
8
|
};
|
|
9
|
+
export declare const isCfgProdConfMessageV1: (data: unknown) => data is CfgProdConfMessageV1;
|
|
8
10
|
export declare type CfgProdConfMessageV2 = {
|
|
9
11
|
version: "2.0";
|
|
10
12
|
conf: DtoConfProd;
|
|
11
13
|
};
|
|
14
|
+
export declare const isCfgProdConfMessageV2: (data: unknown) => data is CfgProdConfMessageV2;
|
|
12
15
|
export declare type CfgProdConfMessage = {
|
|
13
16
|
initial: boolean;
|
|
14
17
|
subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[];
|
|
15
18
|
};
|
|
19
|
+
export declare const getHighestVersionProdConfMessage: (subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[]) => CfgProdConfMessageV1 | CfgProdConfMessageV2;
|
|
16
20
|
export declare enum CfgProdConfMessageVersions {
|
|
17
21
|
V1dot0 = 1,
|
|
18
22
|
V2dot0 = 2
|
|
@@ -8,6 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { convertDtoConfProdToV1 } from "../ConfigurationConverter.js";
|
|
11
|
+
export const isCfgProdConfMessage = (data) => typeof data === "object" && data !== null && "version" in data && "conf" in data;
|
|
12
|
+
export const isCfgProdConfMessageV1 = (data) => isCfgProdConfMessage(data) && data.version === "1.0";
|
|
13
|
+
export const isCfgProdConfMessageV2 = (data) => isCfgProdConfMessage(data) && data.version === "2.0";
|
|
14
|
+
export const getHighestVersionProdConfMessage = (subMessages) => subMessages
|
|
15
|
+
.slice(1)
|
|
16
|
+
.reduce((a, c) => (a.version < c.version ? c : a), subMessages[0]);
|
|
11
17
|
export var CfgProdConfMessageVersions;
|
|
12
18
|
(function (CfgProdConfMessageVersions) {
|
|
13
19
|
CfgProdConfMessageVersions[CfgProdConfMessageVersions["V1dot0"] = 1] = "V1dot0";
|
|
@@ -65,16 +71,14 @@ export class CfgIOProdConfConnector {
|
|
|
65
71
|
console.warn(`${STAGE_PROD_CONF_MESSAGE_KEY} message without any submessages. Unexpected.`);
|
|
66
72
|
return;
|
|
67
73
|
}
|
|
68
|
-
const highestVersionMessage = subMessages
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
yield newProduct.setDtoConf(highestVersionMessage.conf, this._doValidate);
|
|
77
|
-
return;
|
|
74
|
+
const highestVersionMessage = getHighestVersionProdConfMessage(subMessages);
|
|
75
|
+
if (isCfgProdConfMessageV1(highestVersionMessage)) {
|
|
76
|
+
yield newProduct.setApiSelection(highestVersionMessage.conf, this._doValidate);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (isCfgProdConfMessageV2(highestVersionMessage)) {
|
|
80
|
+
yield newProduct.setDtoConf(highestVersionMessage.conf, this._doValidate);
|
|
81
|
+
return;
|
|
78
82
|
}
|
|
79
83
|
throw new Error("Unknown message version");
|
|
80
84
|
}));
|
|
@@ -64,6 +64,9 @@ export class CfgWindowMessageManager extends CfgWindowEventManager {
|
|
|
64
64
|
return super.stopListenForMessage(l);
|
|
65
65
|
}
|
|
66
66
|
send(messageKey, data) {
|
|
67
|
+
if (this.receiveInProgress) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
67
70
|
const container = CfgIOManager.makeContainer({
|
|
68
71
|
[messageKey]: data,
|
|
69
72
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@configura/web-api",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.6",
|
|
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": "2.0.0-alpha.
|
|
26
|
+
"@configura/web-utilities": "2.0.0-alpha.6"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "91edc6834460f70904b9914292a5869ad6e8b245"
|
|
29
29
|
}
|