@configura/web-api 2.0.0-alpha.1 → 2.0.0-alpha.4
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 +1 -1
- package/dist/io/CfgIOProdConfConnector.d.ts +4 -0
- package/dist/io/CfgIOProdConfConnector.js +14 -10
- package/dist/productLoader.js +2 -2
- package/dist/utilitiesCatalogueData.d.ts +10 -1
- package/dist/utilitiesCatalogueData.js +10 -1
- package/dist/utilitiesCataloguePermission.d.ts +8 -2
- package/dist/utilitiesCataloguePermission.js +17 -14
- package/package.json +3 -3
package/dist/CfgProduct.js
CHANGED
|
@@ -419,7 +419,7 @@ export class _CfgProductInternal {
|
|
|
419
419
|
}
|
|
420
420
|
});
|
|
421
421
|
this.root = root !== null && root !== void 0 ? root : this;
|
|
422
|
-
this.key = makeProductKey(prodParams, (_a = _additionalProductRef === null || _additionalProductRef === void 0 ? void 0 : _additionalProductRef.refKey) !== null && _a !== void 0 ? _a : prodParams.partNumber);
|
|
422
|
+
this.key = makeProductKey(Object.assign(Object.assign({}, prodParams), { partNumber: (_a = _additionalProductRef === null || _additionalProductRef === void 0 ? void 0 : _additionalProductRef.refKey) !== null && _a !== void 0 ? _a : prodParams.partNumber }));
|
|
423
423
|
this._selected = optional ? selected : undefined;
|
|
424
424
|
this.isAdditionalProduct = parent !== undefined;
|
|
425
425
|
this._configuration = CfgProductConfiguration.make(initSuccess, initFail, rootFeatureRefs, allRawFeatures, apiSelection, this, this.root);
|
|
@@ -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
|
}));
|
package/dist/productLoader.js
CHANGED
|
@@ -21,7 +21,7 @@ import { makeProductKey, makeSelOptionsKey, } from "./utilitiesCatalogueData.js"
|
|
|
21
21
|
*/
|
|
22
22
|
export function wrapWithGetProductCache(getProduct) {
|
|
23
23
|
const cache = new PromiseCache();
|
|
24
|
-
return (params) => __awaiter(this, void 0, void 0, function* () { return cache.get(makeProductKey(params
|
|
24
|
+
return (params) => __awaiter(this, void 0, void 0, function* () { return cache.get(makeProductKey(params), () => getProduct(params)); });
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Wraps a postValidate function so that it caches for the time it lives.
|
|
@@ -37,7 +37,7 @@ export function wrapWithGetProductCache(getProduct) {
|
|
|
37
37
|
export function wrapWithPostValidateCache(postValidate) {
|
|
38
38
|
const cache = new PromiseCache();
|
|
39
39
|
return (params, body) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
return cache.get(`${makeProductKey(params
|
|
40
|
+
return cache.get(`${makeProductKey(params)}-${makeSelOptionsKey(body.selOptions)}`, () => postValidate(params, body));
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
/** Does both wrapWithGetProductCache and wrapWithPostValidateCache. */
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { DtoAdditionalProductRef, DtoCatalogueParams, DtoCatalogueParamsWithLang, DtoCatalogueParamsWithoutCid, DtoMeasureParam, DtoModel, DtoOrientation, DtoPartsData, DtoPrices, DtoProductData, DtoProductParams, DtoProductParamsWithLang, DtoProductResponse, DtoSelectedOption, DtoTransform, DtoValidateResponse, DtoVector } from "./CatalogueAPI.js";
|
|
2
|
+
/**
|
|
3
|
+
* Makes a string from the params which can be used as a key in for example React. Language is not respected.
|
|
4
|
+
*/
|
|
2
5
|
export declare const makeCatalogueKey: (cat: DtoCatalogueParams) => string;
|
|
3
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Makes a string from the params which can be used as a key in for example React. Language is not respected.
|
|
8
|
+
*/
|
|
9
|
+
export declare const makeProductKey: (prod: DtoProductParams) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Makes a string from selected options, can be used as a key for a selection.
|
|
12
|
+
*/
|
|
4
13
|
export declare const makeSelOptionsKey: (options: DtoSelectedOption[]) => string;
|
|
5
14
|
export declare type RootNodeSource = DtoModel | File;
|
|
6
15
|
export declare type CfgProductData = Omit<Omit<DtoProductData, "models">, "partsData"> & {
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { shallowCompareDictionaries } from "@configura/web-utilities";
|
|
2
|
+
/**
|
|
3
|
+
* Makes a string from the params which can be used as a key in for example React. Language is not respected.
|
|
4
|
+
*/
|
|
2
5
|
export const makeCatalogueKey = (cat) => `${cat.cid}-${cat.enterprise}-${cat.prdCat}-${cat.prdCatVersion}-${cat.priceList}-${cat.vendor}`;
|
|
3
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Makes a string from the params which can be used as a key in for example React. Language is not respected.
|
|
8
|
+
*/
|
|
9
|
+
export const makeProductKey = (prod) => `${makeCatalogueKey(prod)}-${prod.partNumber}`;
|
|
10
|
+
/**
|
|
11
|
+
* Makes a string from selected options, can be used as a key for a selection.
|
|
12
|
+
*/
|
|
4
13
|
export const makeSelOptionsKey = (options) => options.reduce((p, option) => {
|
|
5
14
|
var _a;
|
|
6
15
|
const { code, numericValue, next } = option;
|
|
@@ -4,14 +4,20 @@ interface CataloguePermissionByEnterpriseKey {
|
|
|
4
4
|
}
|
|
5
5
|
export declare const groupAndSortCataloguePermissions: (cataloguePermissions: DtoCataloguePermission[]) => CataloguePermissionByEnterpriseKey;
|
|
6
6
|
export declare const isParamSet: (param: string | undefined) => boolean;
|
|
7
|
-
export declare const createCataloguePermissionsFilter: (
|
|
7
|
+
export declare const createCataloguePermissionsFilter: (catParams: Partial<DtoCatalogueParams>) => (perm: DtoCataloguePermission) => boolean;
|
|
8
8
|
/**
|
|
9
9
|
* Sometimes you will want to use the latest available prdCatVersion. This method will
|
|
10
10
|
* find the highest prdCatVersion version in the cataloguePermissions. If the versions are
|
|
11
11
|
* numeric ("1", "4.3", "0.2") they will be numerically compared, otherwise non localized
|
|
12
12
|
* string compare.
|
|
13
13
|
*/
|
|
14
|
-
export declare const getPrdCatVersionFromPermissions: (cataloguePermissions: DtoCataloguePermission[],
|
|
14
|
+
export declare const getPrdCatVersionFromPermissions: (cataloguePermissions: DtoCataloguePermission[], catParams: {
|
|
15
|
+
cid: number | undefined;
|
|
16
|
+
enterprise: string | undefined;
|
|
17
|
+
prdCat: string | undefined;
|
|
18
|
+
priceList: string | undefined;
|
|
19
|
+
vendor: string | undefined;
|
|
20
|
+
}) => string | undefined;
|
|
15
21
|
/**
|
|
16
22
|
* Sometimes you will want a missing prdCatVersion to represent "Get the current highest version".
|
|
17
23
|
* This method will, if the prdCatVersion is not set, fetch the highest available from the catalogue
|
|
@@ -15,24 +15,27 @@ export const groupAndSortCataloguePermissions = (cataloguePermissions) => {
|
|
|
15
15
|
return cataloguePermissionByEnterpriseKey;
|
|
16
16
|
};
|
|
17
17
|
export const isParamSet = (param) => param !== undefined && param !== "" && param !== "-";
|
|
18
|
-
export const createCataloguePermissionsFilter = (
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
export const createCataloguePermissionsFilter = (catParams) => {
|
|
19
|
+
const { cid, enterprise, prdCat, prdCatVersion, vendor, priceList } = catParams;
|
|
20
|
+
return (perm) => (cid === undefined || cid === perm.cid) &&
|
|
21
|
+
(!isParamSet(enterprise) || enterprise === perm.enterprise) &&
|
|
22
|
+
(!isParamSet(prdCat) || prdCat === perm.prdCat) &&
|
|
23
|
+
(!isParamSet(prdCatVersion) || prdCatVersion === perm.prdCatVersion) &&
|
|
24
|
+
(!isParamSet(vendor) ||
|
|
25
|
+
perm.vendors === undefined ||
|
|
26
|
+
perm.vendors.some((v) => vendor === v)) &&
|
|
27
|
+
(!isParamSet(priceList) ||
|
|
28
|
+
perm.priceLists === undefined ||
|
|
29
|
+
perm.priceLists.some((p) => priceList === p));
|
|
30
|
+
};
|
|
28
31
|
/**
|
|
29
32
|
* Sometimes you will want to use the latest available prdCatVersion. This method will
|
|
30
33
|
* find the highest prdCatVersion version in the cataloguePermissions. If the versions are
|
|
31
34
|
* numeric ("1", "4.3", "0.2") they will be numerically compared, otherwise non localized
|
|
32
35
|
* string compare.
|
|
33
36
|
*/
|
|
34
|
-
export const getPrdCatVersionFromPermissions = (cataloguePermissions,
|
|
35
|
-
const filter = createCataloguePermissionsFilter(
|
|
37
|
+
export const getPrdCatVersionFromPermissions = (cataloguePermissions, catParams) => {
|
|
38
|
+
const filter = createCataloguePermissionsFilter(Object.assign(Object.assign({}, catParams), { prdCatVersion: undefined }));
|
|
36
39
|
const applicablePermissions = cataloguePermissions.filter(filter);
|
|
37
40
|
return applicablePermissions.reduce((pVersion, c) => {
|
|
38
41
|
const cVersion = c.prdCatVersion;
|
|
@@ -55,11 +58,11 @@ export const getPrdCatVersionFromPermissions = (cataloguePermissions, cid, enter
|
|
|
55
58
|
* @param params
|
|
56
59
|
*/
|
|
57
60
|
export const getPrdCatVersionOrLatestFromPermissions = (params, cataloguePermissions) => {
|
|
58
|
-
const {
|
|
61
|
+
const { prdCatVersion } = params;
|
|
59
62
|
if (isParamSet(prdCatVersion)) {
|
|
60
63
|
return prdCatVersion;
|
|
61
64
|
}
|
|
62
|
-
const highestFoundVersion = getPrdCatVersionFromPermissions(cataloguePermissions,
|
|
65
|
+
const highestFoundVersion = getPrdCatVersionFromPermissions(cataloguePermissions, params);
|
|
63
66
|
if (highestFoundVersion === undefined) {
|
|
64
67
|
return prdCatVersion;
|
|
65
68
|
}
|
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.4",
|
|
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.4"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "d4c959d717ae06aafc5678e43ea8a32cace29eeb"
|
|
29
29
|
}
|