@configura/web-api 1.3.0-alpha.4 → 1.3.0-alpha.5

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 (57) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/CatalogueAPI.d.ts +502 -448
  4. package/dist/CatalogueAPI.js +206 -206
  5. package/dist/CfgMeasure.d.ts +33 -0
  6. package/dist/CfgMeasure.js +30 -0
  7. package/dist/CfgProduct.d.ts +217 -116
  8. package/dist/CfgProduct.js +634 -588
  9. package/dist/index.d.ts +16 -15
  10. package/dist/index.js +16 -15
  11. package/dist/material/CfgMaterialMapping.d.ts +7 -7
  12. package/dist/material/CfgMaterialMapping.js +181 -176
  13. package/dist/material/CfgMtrlApplication.d.ts +18 -18
  14. package/dist/material/CfgMtrlApplication.js +43 -43
  15. package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
  16. package/dist/material/CfgMtrlApplicationSource.js +8 -8
  17. package/dist/material/CfgMtrlSource.d.ts +19 -19
  18. package/dist/material/CfgMtrlSource.js +40 -40
  19. package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
  20. package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
  21. package/dist/productConfiguration/CfgFeature.d.ts +160 -134
  22. package/dist/productConfiguration/CfgFeature.js +593 -483
  23. package/dist/productConfiguration/CfgOption.d.ts +128 -112
  24. package/dist/productConfiguration/CfgOption.js +394 -293
  25. package/dist/productConfiguration/CfgProductConfiguration.d.ts +120 -50
  26. package/dist/productConfiguration/CfgProductConfiguration.js +307 -198
  27. package/dist/productConfiguration/filters.d.ts +7 -7
  28. package/dist/productConfiguration/filters.js +29 -29
  29. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  30. package/dist/productConfiguration/productParamsGenerator.js +51 -51
  31. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -9
  32. package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -61
  33. package/dist/productLoader.d.ts +33 -11
  34. package/dist/productLoader.js +49 -41
  35. package/dist/tests/testData/collectorForTest.d.ts +73 -73
  36. package/dist/tests/testData/collectorForTest.js +195 -195
  37. package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
  38. package/dist/tests/testData/dummyProductForTest.js +36 -35
  39. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +32 -32
  40. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +381 -368
  41. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  42. package/dist/tests/testData/testDataCachedGetProduct.js +205 -199
  43. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  44. package/dist/tests/testData/testDataCachedPostValidate.js +195 -189
  45. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
  46. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1119 -1117
  47. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +28 -28
  48. package/dist/tests/testData/testDataProductAggregatedPrice.js +210 -205
  49. package/dist/tests/testData/testDataUpcharge.d.ts +29 -29
  50. package/dist/tests/testData/testDataUpcharge.js +163 -159
  51. package/dist/utilitiesCatalogueData.d.ts +22 -20
  52. package/dist/utilitiesCatalogueData.js +64 -64
  53. package/dist/utilitiesCataloguePermission.d.ts +39 -39
  54. package/dist/utilitiesCataloguePermission.js +84 -84
  55. package/dist/utilitiesNumericValues.d.ts +25 -0
  56. package/dist/utilitiesNumericValues.js +109 -0
  57. package/package.json +3 -3
@@ -1,51 +1,51 @@
1
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
2
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
3
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
5
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
6
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
7
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
8
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
9
- function fulfill(value) { resume("next", value); }
10
- function reject(value) { resume("throw", value); }
11
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
12
- };
13
- import { toError } from "@configura/web-utilities";
14
- import { CfgProduct } from "../CfgProduct.js";
15
- import { applyProductRefFilters } from "./filters.js";
16
- export function generateProductConfigurations(api, lang, catalogues, filters, settings) {
17
- return __asyncGenerator(this, arguments, function* generateProductConfigurations_1() {
18
- const catalogueCount = catalogues.length;
19
- const catalogueEntries = catalogues.entries();
20
- for (const [catalogueIndex, catalogueParams] of catalogueEntries) {
21
- const params = Object.assign(Object.assign({}, catalogueParams), { lang });
22
- try {
23
- const [applicationAreasResponse, toc] = yield __await(Promise.all([
24
- api.getApplicationAreas(params),
25
- api.getTocFlat(params),
26
- ]));
27
- const [, productRefs] = applyProductRefFilters(filters, (toc === null || toc === void 0 ? void 0 : toc.prdRefs) || []);
28
- const productCount = productRefs.length;
29
- const productEntries = productRefs.entries();
30
- for (const [productIndex, prdRef] of productEntries) {
31
- const startTime = performance.now();
32
- const product = yield __await(CfgProduct.make(api, lang, params, prdRef.partNr, settings));
33
- const getProductDuration = performance.now() - startTime;
34
- yield yield __await({
35
- applicationAreasResponse,
36
- catalogueCount,
37
- catalogueIndex,
38
- catalogueParams,
39
- getProductDuration,
40
- product,
41
- productCount,
42
- productIndex,
43
- });
44
- }
45
- }
46
- catch (e) {
47
- yield yield __await(toError(e));
48
- }
49
- }
50
- });
51
- }
1
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
2
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
3
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
5
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
6
+ function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
7
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
8
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
9
+ function fulfill(value) { resume("next", value); }
10
+ function reject(value) { resume("throw", value); }
11
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
12
+ };
13
+ import { toError } from "@configura/web-utilities";
14
+ import { CfgProduct } from "../CfgProduct.js";
15
+ import { applyProductRefFilters } from "./filters.js";
16
+ export function generateProductConfigurations(api, lang, catalogues, filters, settings) {
17
+ return __asyncGenerator(this, arguments, function* generateProductConfigurations_1() {
18
+ const catalogueCount = catalogues.length;
19
+ const catalogueEntries = catalogues.entries();
20
+ for (const [catalogueIndex, catalogueParams] of catalogueEntries) {
21
+ const params = Object.assign(Object.assign({}, catalogueParams), { lang });
22
+ try {
23
+ const [applicationAreasResponse, toc] = yield __await(Promise.all([
24
+ api.getApplicationAreas(params),
25
+ api.getTocFlat(params),
26
+ ]));
27
+ const [, productRefs] = applyProductRefFilters(filters, (toc === null || toc === void 0 ? void 0 : toc.prdRefs) || []);
28
+ const productCount = productRefs.length;
29
+ const productEntries = productRefs.entries();
30
+ for (const [productIndex, prdRef] of productEntries) {
31
+ const startTime = performance.now();
32
+ const product = yield __await(CfgProduct.make(api, lang, params, prdRef.partNr, settings));
33
+ const getProductDuration = performance.now() - startTime;
34
+ yield yield __await({
35
+ applicationAreasResponse,
36
+ catalogueCount,
37
+ catalogueIndex,
38
+ catalogueParams,
39
+ getProductDuration,
40
+ product,
41
+ productCount,
42
+ productIndex,
43
+ });
44
+ }
45
+ }
46
+ catch (e) {
47
+ yield yield __await(toError(e));
48
+ }
49
+ }
50
+ });
51
+ }
@@ -1,10 +1,18 @@
1
- import { AdditionalProductRef, Feature, FeatureRef } from "../CatalogueAPI.js";
2
- import { _CfgProductInternal } from "../CfgProduct.js";
3
- import { CfgMtrlApplication } from "../material/CfgMtrlApplication.js";
4
- import { CfgFeature } from "./CfgFeature.js";
5
- import { _CfgOptionInternal } from "./CfgOption.js";
6
- import { CfgProductConfiguration, _CfgProductConfigurationInternal } from "./CfgProductConfiguration.js";
7
- export declare function syncCfgFeatures(newFeatureRefs: FeatureRef[], currentFeatures: CfgFeature[], allRawFeatures: Feature[], parent: _CfgProductConfigurationInternal | _CfgOptionInternal, parentProduct: _CfgProductInternal, rootProduct: _CfgProductInternal): CfgFeature[];
8
- export declare function getMtrlPreview(mtrlApplications: CfgMtrlApplication[] | undefined): string | undefined;
9
- export declare function collectAdditionalProductRefs(parent: CfgProductConfiguration): AdditionalProductRef[];
1
+ import { AdditionalProductRef, Feature, FeatureRef } from "../CatalogueAPI.js";
2
+ import { _CfgProductInternal } from "../CfgProduct.js";
3
+ import { CfgMtrlApplication } from "../material/CfgMtrlApplication.js";
4
+ import { CfgFeature } from "./CfgFeature.js";
5
+ import { _CfgOptionInternal } from "./CfgOption.js";
6
+ import { CfgProductConfiguration, _CfgProductConfigurationInternal } from "./CfgProductConfiguration.js";
7
+ /**
8
+ * Returns a new array of CfgFeatures that maps to the newFeatureRefs array. Uses CfgFeatures from
9
+ * currentFeatures if they can be found, otherwise makes new.
10
+ */
11
+ export declare function syncCfgFeatures(newFeatureRefs: FeatureRef[], currentFeatures: CfgFeature[], allRawFeatures: Feature[], parent: _CfgProductConfigurationInternal | _CfgOptionInternal, parentConfiguration: _CfgProductConfigurationInternal, parentProduct: _CfgProductInternal, rootProduct: _CfgProductInternal): CfgFeature[];
12
+ export declare function getMtrlPreview(mtrlApplications: CfgMtrlApplication[] | undefined): string | undefined;
13
+ /**
14
+ * Recursively find all additional product references given a product configuration.
15
+ * Only selected options are considered.
16
+ */
17
+ export declare function collectAdditionalProductRefs(parent: CfgProductConfiguration): AdditionalProductRef[];
10
18
  //# sourceMappingURL=utilitiesProductConfiguration.d.ts.map
@@ -1,61 +1,80 @@
1
- import { someMatch } from "@configura/web-utilities";
2
- import { CfgFeature } from "./CfgFeature.js";
3
- import { CfgOption } from "./CfgOption.js";
4
- import { CfgProductConfiguration, } from "./CfgProductConfiguration.js";
5
- /// Returns a new array of CfgFeatures that maps to the newFeatureRefs array. Uses
6
- /// CfgFeatures from currentFeatures if they can be found, otherwise makes new.
7
- export function syncCfgFeatures(newFeatureRefs, currentFeatures, allRawFeatures, parent, parentProduct, rootProduct) {
8
- const usedRawFeatures = newFeatureRefs
9
- .map((r) => r.code)
10
- .map((c) => {
11
- const rawFeature = allRawFeatures.find((f) => c === f.code);
12
- if (rawFeature === undefined) {
13
- throw new Error(`Feature not found. Requested feature code: "${c}".`);
14
- }
15
- return rawFeature;
16
- });
17
- const hasDuplicateDescription = someMatch(usedRawFeatures, (l, r) => {
18
- return l.description.toLowerCase() === r.description.toLowerCase();
19
- });
20
- currentFeatures = currentFeatures.slice();
21
- return usedRawFeatures.map((f) => {
22
- // Description based code helps when switching between
23
- // products with similar feature-options tree and trying
24
- // to retain made selections
25
- const key = f.description + (f.description === "" || hasDuplicateDescription ? f.code : "");
26
- const i = currentFeatures.findIndex((cfgF) => cfgF.code === f.code && cfgF.key === key);
27
- if (i === -1) {
28
- return CfgFeature.make(f, allRawFeatures, key, parent, parentProduct, rootProduct);
29
- }
30
- return currentFeatures.splice(i, 1)[0];
31
- });
32
- }
33
- export function getMtrlPreview(mtrlApplications) {
34
- if (mtrlApplications === undefined) {
35
- return;
36
- }
37
- const first = mtrlApplications[0];
38
- if (first === undefined) {
39
- return;
40
- }
41
- return first.previewUrl;
42
- }
43
- /// Recursively find all additional product references given a
44
- /// product configuration. Only selected options are considered.
45
- export function collectAdditionalProductRefs(parent) {
46
- function c(parent) {
47
- const result = [];
48
- if (parent instanceof CfgOption && parent.selected) {
49
- result.push(...(parent.rawOption.additionalProductRefs || []));
50
- }
51
- if (parent instanceof CfgProductConfiguration || parent.selected) {
52
- for (const feature of parent.features) {
53
- for (const option of feature.options) {
54
- result.push(...c(option));
55
- }
56
- }
57
- }
58
- return result;
59
- }
60
- return c(parent);
61
- }
1
+ import { someMatch } from "@configura/web-utilities";
2
+ import { CfgFeature } from "./CfgFeature.js";
3
+ import { CfgOption } from "./CfgOption.js";
4
+ import { CfgProductConfiguration, } from "./CfgProductConfiguration.js";
5
+ /**
6
+ * Returns a new array of CfgFeatures that maps to the newFeatureRefs array. Uses CfgFeatures from
7
+ * currentFeatures if they can be found, otherwise makes new.
8
+ */
9
+ export function syncCfgFeatures(newFeatureRefs, currentFeatures, allRawFeatures, parent, parentConfiguration, parentProduct, rootProduct) {
10
+ const usedRawFeatures = newFeatureRefs
11
+ .map((r) => r.code)
12
+ .map((c) => {
13
+ const rawFeature = allRawFeatures.find((f) => c === f.code);
14
+ if (rawFeature === undefined) {
15
+ throw new Error(`Feature not found. Requested feature code: "${c}".`);
16
+ }
17
+ return rawFeature;
18
+ });
19
+ const hasDuplicateDescription = someMatch(usedRawFeatures, (l, r) => {
20
+ return l.description.toLowerCase() === r.description.toLowerCase();
21
+ });
22
+ const newFeatures = [];
23
+ for (const f of usedRawFeatures) {
24
+ const fCode = f.code;
25
+ const fDescription = f.description;
26
+ // It is possible in Cat Creator to add the same Feature twice
27
+ // to the root of a Product. This fills no apparent purpose,
28
+ // and in CET the seem to behave as if they were the same.
29
+ // Removing the duplicates causes sync issues where the server
30
+ // expects all copies, and hence we short circuit them here
31
+ // by letting them refer to the same object instead.
32
+ const twin = newFeatures.find((f) => f.code === fCode);
33
+ if (twin !== undefined) {
34
+ newFeatures.push(twin);
35
+ continue;
36
+ }
37
+ // Description based code helps when switching between
38
+ // products with similar feature-options tree and trying
39
+ // to retain made selections
40
+ const key = fDescription + (fDescription === "" || hasDuplicateDescription ? fCode : "");
41
+ const existingFeature = currentFeatures.find((cfgF) => cfgF.code === fCode && cfgF.key === key);
42
+ if (existingFeature !== undefined) {
43
+ newFeatures.push(existingFeature);
44
+ continue;
45
+ }
46
+ newFeatures.push(CfgFeature.make(f, allRawFeatures, key, parent, parentConfiguration, parentProduct, rootProduct));
47
+ }
48
+ return newFeatures;
49
+ }
50
+ export function getMtrlPreview(mtrlApplications) {
51
+ if (mtrlApplications === undefined) {
52
+ return;
53
+ }
54
+ const first = mtrlApplications[0];
55
+ if (first === undefined) {
56
+ return;
57
+ }
58
+ return first.previewUrl;
59
+ }
60
+ /**
61
+ * Recursively find all additional product references given a product configuration.
62
+ * Only selected options are considered.
63
+ */
64
+ export function collectAdditionalProductRefs(parent) {
65
+ function c(parent) {
66
+ const result = [];
67
+ if (parent instanceof CfgOption && parent.selected) {
68
+ result.push(...(parent.rawOption.additionalProductRefs || []));
69
+ }
70
+ if (parent instanceof CfgProductConfiguration || parent.selected) {
71
+ for (const feature of parent.features) {
72
+ for (const option of feature.options) {
73
+ result.push(...c(option));
74
+ }
75
+ }
76
+ }
77
+ return result;
78
+ }
79
+ return c(parent);
80
+ }
@@ -1,12 +1,34 @@
1
- import { GetProductParams, PostValidateParams, ValidateRequest } from "./CatalogueAPI";
2
- import { CfgProductResponse, CfgValidateResponse } from "./utilitiesCatalogueData.js";
3
- export declare type GetProduct = (params: GetProductParams) => Promise<CfgProductResponse>;
4
- export declare type PostValidate = (params: PostValidateParams, body: ValidateRequest) => Promise<CfgValidateResponse>;
5
- export declare type ProductLoader = {
6
- getProduct: GetProduct;
7
- postValidate: PostValidate;
8
- };
9
- export declare function wrapWithGetProductCache(getProduct: GetProduct): GetProduct;
10
- export declare function wrapWithPostValidateCache(postValidate: PostValidate): PostValidate;
11
- export declare function wrapWithCache(loader: ProductLoader): ProductLoader;
1
+ import { GetProductParams, PostValidateParams, ValidateRequest } from "./CatalogueAPI";
2
+ import { CfgProductResponse, CfgValidateResponse } from "./utilitiesCatalogueData.js";
3
+ export declare type GetProduct = (params: GetProductParams) => Promise<CfgProductResponse>;
4
+ export declare type PostValidate = (params: PostValidateParams, body: ValidateRequest) => Promise<CfgValidateResponse>;
5
+ export declare type ProductLoader = {
6
+ getProduct: GetProduct;
7
+ postValidate: PostValidate;
8
+ };
9
+ /**
10
+ * Wraps a getProduct function so that it caches for the time it lives.
11
+ *
12
+ * It has no cache invalidation or timeouts, so whatever ends up in the cache stays there
13
+ * indefinitely. For this reason we recommend using this with caution.
14
+ *
15
+ * In our Example App we use it to cache the internal calls in additional products as in such a
16
+ * product you tend to frequently get calls to same sub-product. Such as loading the same table leg
17
+ * four times.
18
+ */
19
+ export declare function wrapWithGetProductCache(getProduct: GetProduct): GetProduct;
20
+ /**
21
+ * Wraps a postValidate function so that it caches for the time it lives.
22
+ *
23
+ * It has no cache invalidation or timeouts, so whatever ends up in the cache stays there
24
+ * indefinitely. We recommend you do not use this unless you are really, really sure what you are
25
+ * doing.
26
+ *
27
+ * The SDK uses it for additional products to avoid validating for example the same table legs four
28
+ * times at the same time. There we make sure the this cache only stays in scope for one user
29
+ * interaction. No longer than the actions caused by a user clicking an option.
30
+ */
31
+ export declare function wrapWithPostValidateCache(postValidate: PostValidate): PostValidate;
32
+ /** Does both wrapWithGetProductCache and wrapWithPostValidateCache. */
33
+ export declare function wrapWithCache(loader: ProductLoader): ProductLoader;
12
34
  //# sourceMappingURL=productLoader.d.ts.map
@@ -1,41 +1,49 @@
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
- import { PromiseCache } from "@configura/web-utilities";
11
- import { makeProductKey, makeSelOptionsKey, } from "./utilitiesCatalogueData.js";
12
- /// Wraps a getProduct function so that it caches for the time it lives.
13
- /// It has no cache invalidation or timeouts, so whatever ends up in the cache stays
14
- /// there indefinitely. For this reason we recommend using this with caution.
15
- /// In our Example App we use it to cache the internal calls in additional products
16
- /// as in such a product you tend to frequently get calls to same sub-product. Such
17
- /// as loading the same table leg four times.
18
- export function wrapWithGetProductCache(getProduct) {
19
- const cache = new PromiseCache();
20
- return (params) => __awaiter(this, void 0, void 0, function* () { return cache.get(makeProductKey(params, params.partNumber), () => getProduct(params)); });
21
- }
22
- /// Wraps a postValidate function so that it caches for the time it lives.
23
- /// It has no cache invalidation or timeouts, so whatever ends up in the cache stays
24
- /// there indefinitely. We recommend you do not use this unless you are really, really
25
- /// sure what you are doing.
26
- /// We use it in additional products to avoid validating for example the same table legs four
27
- /// times at the same time. There we make sure the this cache only stays in scope for one
28
- /// user interaction. No longer than the actions caused by a user clicking an option.
29
- export function wrapWithPostValidateCache(postValidate) {
30
- const cache = new PromiseCache();
31
- return (params, body) => __awaiter(this, void 0, void 0, function* () {
32
- return cache.get(`${makeProductKey(params, params.partNumber)}-${makeSelOptionsKey(body.selOptions)}`, () => postValidate(params, body));
33
- });
34
- }
35
- // Does both wrapWithGetProductCache and wrapWithPostValidateCache
36
- export function wrapWithCache(loader) {
37
- return {
38
- getProduct: wrapWithGetProductCache(loader.getProduct.bind(loader)),
39
- postValidate: wrapWithPostValidateCache(loader.postValidate.bind(loader)),
40
- };
41
- }
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
+ import { PromiseCache } from "@configura/web-utilities";
11
+ import { makeProductKey, makeSelOptionsKey, } from "./utilitiesCatalogueData.js";
12
+ /**
13
+ * Wraps a getProduct function so that it caches for the time it lives.
14
+ *
15
+ * It has no cache invalidation or timeouts, so whatever ends up in the cache stays there
16
+ * indefinitely. For this reason we recommend using this with caution.
17
+ *
18
+ * In our Example App we use it to cache the internal calls in additional products as in such a
19
+ * product you tend to frequently get calls to same sub-product. Such as loading the same table leg
20
+ * four times.
21
+ */
22
+ export function wrapWithGetProductCache(getProduct) {
23
+ const cache = new PromiseCache();
24
+ return (params) => __awaiter(this, void 0, void 0, function* () { return cache.get(makeProductKey(params, params.partNumber), () => getProduct(params)); });
25
+ }
26
+ /**
27
+ * Wraps a postValidate function so that it caches for the time it lives.
28
+ *
29
+ * It has no cache invalidation or timeouts, so whatever ends up in the cache stays there
30
+ * indefinitely. We recommend you do not use this unless you are really, really sure what you are
31
+ * doing.
32
+ *
33
+ * The SDK uses it for additional products to avoid validating for example the same table legs four
34
+ * times at the same time. There we make sure the this cache only stays in scope for one user
35
+ * interaction. No longer than the actions caused by a user clicking an option.
36
+ */
37
+ export function wrapWithPostValidateCache(postValidate) {
38
+ const cache = new PromiseCache();
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));
41
+ });
42
+ }
43
+ /** Does both wrapWithGetProductCache and wrapWithPostValidateCache. */
44
+ export function wrapWithCache(loader) {
45
+ return {
46
+ getProduct: wrapWithGetProductCache(loader.getProduct.bind(loader)),
47
+ postValidate: wrapWithPostValidateCache(loader.postValidate.bind(loader)),
48
+ };
49
+ }
@@ -1,74 +1,74 @@
1
- import { CfgProduct } from "../../CfgProduct";
2
- import { CfgFeature } from "../../productConfiguration/CfgFeature";
3
- import { CfgOption } from "../../productConfiguration/CfgOption";
4
- import { CfgProductConfiguration } from "../../productConfiguration/CfgProductConfiguration";
5
- declare type SnapShotForWrapper = {
6
- path: string;
7
- selected: boolean;
8
- };
9
- declare type SnapShotForWrapperWithoutRef = SnapShotForWrapper & {
10
- productConfiguration: SnapShotForConfiguration;
11
- additionalProducts: SnapShotForWrapper[];
12
- };
13
- declare type SnapShotForWrapperWithRef = SnapShotForWrapper & {
14
- ref: CfgProduct;
15
- productConfiguration: SnapShotForConfigurationWithRef;
16
- additionalProducts: SnapShotForWrapperWithRef[];
17
- };
18
- declare type SnapShotForConfiguration = {
19
- path: string;
20
- };
21
- declare type SnapShotForConfigurationWithoutRef = SnapShotForConfiguration & {
22
- features: SnapShotForFeature[];
23
- };
24
- declare type SnapShotForConfigurationWithRef = SnapShotForConfiguration & {
25
- ref: CfgProductConfiguration;
26
- features: SnapShotForFeatureWithRef[];
27
- };
28
- declare type SnapShotForFeature = {
29
- path: string;
30
- };
31
- declare type SnapShotForFeatureWithoutRef = SnapShotForFeature & {
32
- options: SnapShotForOption[];
33
- };
34
- declare type SnapShotForFeatureWithRef = SnapShotForFeature & {
35
- ref: CfgFeature;
36
- options: SnapShotForOptionWithRef[];
37
- };
38
- declare type SnapShotForOption = {
39
- path: string;
40
- selected: boolean;
41
- };
42
- declare type SnapShotForOptionWithoutRef = SnapShotForOption & {
43
- features: SnapShotForFeature[];
44
- };
45
- declare type SnapShotForOptionWithRef = SnapShotForOption & {
46
- ref: CfgOption;
47
- features: SnapShotForFeatureWithRef[];
48
- };
49
- export declare class Collector {
50
- product: CfgProduct;
51
- static stripRefsForWrapper: (w: SnapShotForWrapperWithRef) => SnapShotForWrapperWithoutRef;
52
- static stripRefsForConf: (c: SnapShotForConfigurationWithRef) => SnapShotForConfigurationWithoutRef;
53
- static stripRefsForFeature: (f: SnapShotForFeatureWithRef) => SnapShotForFeatureWithoutRef;
54
- static stripRefsForOption: (o: SnapShotForOptionWithRef) => SnapShotForOptionWithoutRef;
55
- constructor(product: CfgProduct);
56
- notifications: string[];
57
- pushNotification: (message: string) => void;
58
- takeSnapshot: () => SnapShotForWrapperWithRef;
59
- compareSnapshot: (o: SnapShotForWrapperWithRef, n: SnapShotForWrapperWithRef) => string[];
60
- takeRefSnapshotForWrapper: (path: string, product: CfgProduct) => SnapShotForWrapperWithRef;
61
- compareSnapshotForWrapper: (result: string[], o: SnapShotForWrapperWithRef, n: SnapShotForWrapperWithRef) => void;
62
- takeRefSnapshopForConf: (path: string, productConfiguration: CfgProductConfiguration) => SnapShotForConfigurationWithRef;
63
- compareSnapshopForConf: (result: string[], o: SnapShotForConfigurationWithRef, n: SnapShotForConfigurationWithRef) => void;
64
- takeRefSnapshotForFeature: (path: string, feature: CfgFeature) => SnapShotForFeatureWithRef;
65
- compareSnapshopForFeature: (result: string[], o: SnapShotForFeatureWithRef, n: SnapShotForFeatureWithRef) => void;
66
- takeRefSnapshotForOption: (path: string, option: CfgOption) => SnapShotForOptionWithRef;
67
- compareSnapshopForOption: (result: string[], o: SnapShotForOptionWithRef, n: SnapShotForOptionWithRef) => void;
68
- addListenersForProduct: (path: string, product: CfgProduct) => void;
69
- addListenersForProductConfiguration: (path: string, productConfiguration: CfgProductConfiguration) => void;
70
- addListenersForFeature: (path: string, feature: CfgFeature) => void;
71
- addListenersForOption: (path: string, option: CfgOption) => void;
72
- }
73
- export {};
1
+ import { CfgProduct } from "../../CfgProduct";
2
+ import { CfgFeature } from "../../productConfiguration/CfgFeature";
3
+ import { CfgOption } from "../../productConfiguration/CfgOption";
4
+ import { CfgProductConfiguration } from "../../productConfiguration/CfgProductConfiguration";
5
+ declare type SnapShotForWrapper = {
6
+ path: string;
7
+ selected: boolean;
8
+ };
9
+ declare type SnapShotForWrapperWithoutRef = SnapShotForWrapper & {
10
+ productConfiguration: SnapShotForConfiguration;
11
+ additionalProducts: SnapShotForWrapper[];
12
+ };
13
+ declare type SnapShotForWrapperWithRef = SnapShotForWrapper & {
14
+ ref: CfgProduct;
15
+ productConfiguration: SnapShotForConfigurationWithRef;
16
+ additionalProducts: SnapShotForWrapperWithRef[];
17
+ };
18
+ declare type SnapShotForConfiguration = {
19
+ path: string;
20
+ };
21
+ declare type SnapShotForConfigurationWithoutRef = SnapShotForConfiguration & {
22
+ features: SnapShotForFeature[];
23
+ };
24
+ declare type SnapShotForConfigurationWithRef = SnapShotForConfiguration & {
25
+ ref: CfgProductConfiguration;
26
+ features: SnapShotForFeatureWithRef[];
27
+ };
28
+ declare type SnapShotForFeature = {
29
+ path: string;
30
+ };
31
+ declare type SnapShotForFeatureWithoutRef = SnapShotForFeature & {
32
+ options: SnapShotForOption[];
33
+ };
34
+ declare type SnapShotForFeatureWithRef = SnapShotForFeature & {
35
+ ref: CfgFeature;
36
+ options: SnapShotForOptionWithRef[];
37
+ };
38
+ declare type SnapShotForOption = {
39
+ path: string;
40
+ selected: boolean;
41
+ };
42
+ declare type SnapShotForOptionWithoutRef = SnapShotForOption & {
43
+ features: SnapShotForFeature[];
44
+ };
45
+ declare type SnapShotForOptionWithRef = SnapShotForOption & {
46
+ ref: CfgOption;
47
+ features: SnapShotForFeatureWithRef[];
48
+ };
49
+ export declare class Collector {
50
+ product: CfgProduct;
51
+ static stripRefsForWrapper: (w: SnapShotForWrapperWithRef) => SnapShotForWrapperWithoutRef;
52
+ static stripRefsForConf: (c: SnapShotForConfigurationWithRef) => SnapShotForConfigurationWithoutRef;
53
+ static stripRefsForFeature: (f: SnapShotForFeatureWithRef) => SnapShotForFeatureWithoutRef;
54
+ static stripRefsForOption: (o: SnapShotForOptionWithRef) => SnapShotForOptionWithoutRef;
55
+ constructor(product: CfgProduct);
56
+ notifications: string[];
57
+ pushNotification: (message: string) => void;
58
+ takeSnapshot: () => SnapShotForWrapperWithRef;
59
+ compareSnapshot: (o: SnapShotForWrapperWithRef, n: SnapShotForWrapperWithRef) => string[];
60
+ takeRefSnapshotForWrapper: (path: string, product: CfgProduct) => SnapShotForWrapperWithRef;
61
+ compareSnapshotForWrapper: (result: string[], o: SnapShotForWrapperWithRef, n: SnapShotForWrapperWithRef) => void;
62
+ takeRefSnapshopForConf: (path: string, productConfiguration: CfgProductConfiguration) => SnapShotForConfigurationWithRef;
63
+ compareSnapshopForConf: (result: string[], o: SnapShotForConfigurationWithRef, n: SnapShotForConfigurationWithRef) => void;
64
+ takeRefSnapshotForFeature: (path: string, feature: CfgFeature) => SnapShotForFeatureWithRef;
65
+ compareSnapshopForFeature: (result: string[], o: SnapShotForFeatureWithRef, n: SnapShotForFeatureWithRef) => void;
66
+ takeRefSnapshotForOption: (path: string, option: CfgOption) => SnapShotForOptionWithRef;
67
+ compareSnapshopForOption: (result: string[], o: SnapShotForOptionWithRef, n: SnapShotForOptionWithRef) => void;
68
+ addListenersForProduct: (path: string, product: CfgProduct) => void;
69
+ addListenersForProductConfiguration: (path: string, productConfiguration: CfgProductConfiguration) => void;
70
+ addListenersForFeature: (path: string, feature: CfgFeature) => void;
71
+ addListenersForOption: (path: string, option: CfgOption) => void;
72
+ }
73
+ export {};
74
74
  //# sourceMappingURL=collectorForTest.d.ts.map