@configura/web-api 2.0.0-alpha.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.
@@ -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);
@@ -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, params.partNumber), () => getProduct(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, params.partNumber)}-${makeSelOptionsKey(body.selOptions)}`, () => postValidate(params, body));
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
- export declare const makeProductKey: (cat: DtoCatalogueParams, pKey: string) => string;
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
- export const makeProductKey = (cat, pKey) => `${makeCatalogueKey(cat)}-${pKey}`;
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: (cid: number | undefined, enterprise: string | undefined, prdCat: string | undefined, prdCatVersion: string | undefined, priceList: string | undefined, vendor: string | undefined) => (perm: DtoCataloguePermission) => boolean;
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[], cid: number | undefined, enterprise: string | undefined, prdCat: string | undefined, priceList: string | undefined, vendor: string | undefined) => string | undefined;
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 = (cid, enterprise, prdCat, prdCatVersion, priceList, vendor) => (perm) => (cid === undefined || cid === perm.cid) &&
19
- (!isParamSet(enterprise) || enterprise === perm.enterprise) &&
20
- (!isParamSet(prdCat) || prdCat === perm.prdCat) &&
21
- (!isParamSet(prdCatVersion) || prdCatVersion === perm.prdCatVersion) &&
22
- (!isParamSet(vendor) ||
23
- perm.vendors === undefined ||
24
- perm.vendors.some((v) => vendor === v)) &&
25
- (!isParamSet(priceList) ||
26
- perm.priceLists === undefined ||
27
- perm.priceLists.some((p) => priceList === p));
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, cid, enterprise, prdCat, priceList, vendor) => {
35
- const filter = createCataloguePermissionsFilter(cid, enterprise, prdCat, "-", priceList, vendor);
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 { cid, enterprise, prdCat, prdCatVersion, priceList, vendor } = params;
61
+ const { prdCatVersion } = params;
59
62
  if (isParamSet(prdCatVersion)) {
60
63
  return prdCatVersion;
61
64
  }
62
- const highestFoundVersion = getPrdCatVersionFromPermissions(cataloguePermissions, cid, enterprise, prdCat, priceList, vendor);
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.1",
3
+ "version": "2.0.0-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": "2.0.0-alpha.1"
26
+ "@configura/web-utilities": "2.0.0-alpha.2"
27
27
  },
28
- "gitHead": "f35367369c2e0189ed8181ae91040a149c729368"
28
+ "gitHead": "70b1f8c6426c11420f00b031912e1023d3b591bf"
29
29
  }