@configura/web-api 2.0.0-alpha.1 → 2.0.0-alpha.12
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/CatalogueAPI.d.ts +27 -27
- package/dist/CatalogueAPI.js +4 -24
- package/dist/CfgProduct.d.ts +5 -5
- package/dist/CfgProduct.js +18 -16
- package/dist/CfgReferencePathHelper.d.ts +14 -1
- package/dist/CfgReferencePathHelper.js +14 -1
- package/dist/ConfigurationConverter.d.ts +12 -4
- package/dist/ConfigurationConverter.js +88 -11
- package/dist/io/CfgHistoryManager.d.ts +4 -3
- package/dist/io/CfgHistoryManager.js +2 -2
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +3 -5
- package/dist/io/CfgHistoryToProdConfConnector.js +7 -29
- package/dist/io/CfgIOProdConfConnector.d.ts +15 -12
- package/dist/io/CfgIOProdConfConnector.js +31 -29
- package/dist/io/CfgObservableStateManager.d.ts +4 -0
- package/dist/io/CfgObservableStateManager.js +4 -0
- package/dist/io/CfgObservableStateToProdConfConnector.d.ts +4 -3
- package/dist/io/CfgObservableStateToProdConfConnector.js +4 -3
- package/dist/io/CfgWindowMessageManager.d.ts +2 -2
- package/dist/io/CfgWindowMessageManager.js +5 -2
- package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +4 -3
- package/dist/io/CfgWindowMessageToProdConfConnector.js +4 -3
- package/dist/productConfiguration/CfgFeature.d.ts +2 -2
- package/dist/productConfiguration/CfgFeature.js +2 -2
- package/dist/productConfiguration/CfgOption.d.ts +2 -2
- package/dist/productConfiguration/CfgOption.js +2 -2
- package/dist/productConfiguration/CfgProductConfiguration.d.ts +2 -2
- package/dist/productConfiguration/CfgProductConfiguration.js +3 -3
- 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/CatalogueAPI.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface DtoAdditionalProductConfiguration {
|
|
|
5
5
|
selOptions: Array<DtoSelectedOption>;
|
|
6
6
|
additionalProducts?: Array<DtoAdditionalProductConfiguration>;
|
|
7
7
|
}
|
|
8
|
+
/** AdditionalProductConfigurationV2 */
|
|
9
|
+
export interface DtoAdditionalProductConfigurationV2 extends DtoProductConfiguration {
|
|
10
|
+
refKey: string;
|
|
11
|
+
selected: boolean;
|
|
12
|
+
}
|
|
8
13
|
/** AdditionalProductRef */
|
|
9
14
|
export interface DtoAdditionalProductRef {
|
|
10
15
|
refKey: string;
|
|
@@ -22,7 +27,7 @@ export interface DtoApplicationArea {
|
|
|
22
27
|
material?: string;
|
|
23
28
|
preview?: string;
|
|
24
29
|
}
|
|
25
|
-
/**
|
|
30
|
+
/** ApplicationAreasResponse */
|
|
26
31
|
export interface DtoApplicationAreasResponse {
|
|
27
32
|
applicationAreas: Array<DtoApplicationArea>;
|
|
28
33
|
uuid: string;
|
|
@@ -74,31 +79,6 @@ export interface DtoCodeRange {
|
|
|
74
79
|
maxValue: number;
|
|
75
80
|
increment?: number;
|
|
76
81
|
}
|
|
77
|
-
/** ConfAddProd */
|
|
78
|
-
export interface DtoConfAddProd extends DtoConfProd {
|
|
79
|
-
refKey: string;
|
|
80
|
-
selected: boolean;
|
|
81
|
-
}
|
|
82
|
-
/** ConfFeature */
|
|
83
|
-
export interface DtoConfFeature {
|
|
84
|
-
code: string;
|
|
85
|
-
groupCode?: string;
|
|
86
|
-
unit?: string;
|
|
87
|
-
options?: Array<DtoConfOption>;
|
|
88
|
-
}
|
|
89
|
-
/** ConfOption */
|
|
90
|
-
export interface DtoConfOption {
|
|
91
|
-
code: string;
|
|
92
|
-
selected: boolean;
|
|
93
|
-
numericValue?: DtoValueWithUnit;
|
|
94
|
-
features?: Array<DtoConfFeature>;
|
|
95
|
-
}
|
|
96
|
-
/** ConfProd */
|
|
97
|
-
export interface DtoConfProd {
|
|
98
|
-
features?: Array<DtoConfFeature>;
|
|
99
|
-
additionalProducts?: Array<DtoConfAddProd>;
|
|
100
|
-
prodParams?: DtoProductParamsWithLang;
|
|
101
|
-
}
|
|
102
82
|
/** ErrorResponse */
|
|
103
83
|
export interface DtoErrorResponse {
|
|
104
84
|
error: string;
|
|
@@ -147,6 +127,13 @@ export interface DtoFeature {
|
|
|
147
127
|
syncGroup?: DtoSyncGroup;
|
|
148
128
|
unit?: string;
|
|
149
129
|
}
|
|
130
|
+
/** FeatureConfiguration */
|
|
131
|
+
export interface DtoFeatureConfiguration {
|
|
132
|
+
code: string;
|
|
133
|
+
groupCode?: string;
|
|
134
|
+
unit?: string;
|
|
135
|
+
options?: Array<DtoOptionConfiguration>;
|
|
136
|
+
}
|
|
150
137
|
/** FeatureRef */
|
|
151
138
|
export interface DtoFeatureRef {
|
|
152
139
|
code: string;
|
|
@@ -176,7 +163,7 @@ export interface DtoGetPriceListsParams {
|
|
|
176
163
|
vendor: string;
|
|
177
164
|
priceList: string;
|
|
178
165
|
}
|
|
179
|
-
/**
|
|
166
|
+
/** GetProductParams represents the URL parameters of getProduct */
|
|
180
167
|
export interface DtoGetProductParams {
|
|
181
168
|
lang: string;
|
|
182
169
|
enterprise: string;
|
|
@@ -261,6 +248,13 @@ export interface DtoOption {
|
|
|
261
248
|
upcharge?: number;
|
|
262
249
|
priceCodes?: Array<string>;
|
|
263
250
|
}
|
|
251
|
+
/** OptionConfiguration */
|
|
252
|
+
export interface DtoOptionConfiguration {
|
|
253
|
+
code: string;
|
|
254
|
+
selected: boolean;
|
|
255
|
+
numericValue?: DtoValueWithUnit;
|
|
256
|
+
features?: Array<DtoFeatureConfiguration>;
|
|
257
|
+
}
|
|
264
258
|
/** Orientation */
|
|
265
259
|
export interface DtoOrientation {
|
|
266
260
|
yaw: number;
|
|
@@ -359,6 +353,12 @@ export interface DtoProductCatalogueInfo {
|
|
|
359
353
|
exchangeRate: number;
|
|
360
354
|
lastModified: string;
|
|
361
355
|
}
|
|
356
|
+
/** ProductConfiguration */
|
|
357
|
+
export interface DtoProductConfiguration {
|
|
358
|
+
features?: Array<DtoFeatureConfiguration>;
|
|
359
|
+
additionalProducts?: Array<DtoAdditionalProductConfigurationV2>;
|
|
360
|
+
prodParams?: DtoProductParamsWithLang;
|
|
361
|
+
}
|
|
362
362
|
/** ProductData */
|
|
363
363
|
export interface DtoProductData {
|
|
364
364
|
area?: string;
|
package/dist/CatalogueAPI.js
CHANGED
|
@@ -9,28 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
export const dtoExportFormatNames = [
|
|
13
|
-
|
|
14
|
-
"gltf",
|
|
15
|
-
"fbx",
|
|
16
|
-
"dwg",
|
|
17
|
-
"cmdrw",
|
|
18
|
-
"cmfav",
|
|
19
|
-
"cmsym",
|
|
20
|
-
];
|
|
21
|
-
export const dtoExportStatusStatusNames = [
|
|
22
|
-
"pending",
|
|
23
|
-
"running",
|
|
24
|
-
"finished",
|
|
25
|
-
"failed",
|
|
26
|
-
];
|
|
12
|
+
export const dtoExportFormatNames = ["glb", "gltf", "fbx", "dwg", "cmdrw", "cmfav", "cmsym"];
|
|
13
|
+
export const dtoExportStatusStatusNames = ["pending", "running", "finished", "failed"];
|
|
27
14
|
export const dtoRenderFormatNames = ["jpg", "png"];
|
|
28
|
-
export const dtoRenderStatusStatusNames = [
|
|
29
|
-
"pending",
|
|
30
|
-
"running",
|
|
31
|
-
"finished",
|
|
32
|
-
"failed",
|
|
33
|
-
];
|
|
15
|
+
export const dtoRenderStatusStatusNames = ["pending", "running", "finished", "failed"];
|
|
34
16
|
export const dtoSyncGroupMethodsNames = ["pull", "push", "twoWay"];
|
|
35
17
|
export class DtoAPIError extends Error {
|
|
36
18
|
}
|
|
@@ -49,9 +31,7 @@ export class CatalogueAPI {
|
|
|
49
31
|
}
|
|
50
32
|
}
|
|
51
33
|
hasFeature(feature) {
|
|
52
|
-
return
|
|
53
|
-
this.auth.apiSession.features !== undefined &&
|
|
54
|
-
this.auth.apiSession.features.indexOf(feature) > -1);
|
|
34
|
+
return this.auth !== undefined && this.auth.apiSession.features !== undefined && this.auth.apiSession.features.indexOf(feature) > -1;
|
|
55
35
|
}
|
|
56
36
|
fetch(url, options) {
|
|
57
37
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/CfgProduct.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AggregatedLoadingObservable, LengthUnit, Observable, SingleArgCallback } from "@configura/web-utilities";
|
|
2
|
-
import { DtoAdditionalProductConfiguration, DtoAdditionalProductRef, DtoCatalogueParams,
|
|
2
|
+
import { DtoAdditionalProductConfiguration, DtoAdditionalProductRef, DtoCatalogueParams, DtoMeasureParam, DtoMtrlApplication, DtoPrices, DtoProductConfiguration, DtoProductParamsWithLang, DtoTransform } from "./CatalogueAPI.js";
|
|
3
3
|
import { CfgMeasureDefinition } from "./CfgMeasure.js";
|
|
4
4
|
import { _CfgFeatureInternal } from "./productConfiguration/CfgFeature.js";
|
|
5
5
|
import { ProductConfigurationBubbleMode } from "./productConfiguration/CfgOption.js";
|
|
@@ -136,8 +136,8 @@ export declare class _CfgProductInternal {
|
|
|
136
136
|
_additionalProductHasChanged: (freshRef: CfgProduct, bubbleMode: CfgProductBubbleMode, committed: boolean) => Promise<void>;
|
|
137
137
|
/** Called by the configuration to tell its parent that it has changed. */
|
|
138
138
|
_configurationHasChanged: (freshRef: CfgProductConfiguration, bubbleMode: ProductConfigurationBubbleMode, committed: boolean) => Promise<void>;
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
getDtoConfiguration: (includeExtendedData: boolean, includeProductParams: boolean) => DtoProductConfiguration;
|
|
140
|
+
setDtoConfiguration: (s: DtoProductConfiguration, doValidate: boolean, productLoaderForGroupedLoad?: ProductLoader | undefined) => Promise<boolean>;
|
|
141
141
|
setApiSelection: (s: DtoAdditionalProductConfiguration, doValidate: boolean, productLoaderForGroupedLoad?: ProductLoader | undefined) => Promise<boolean>;
|
|
142
142
|
copyFrom: (source: _CfgProductInternal, doValidate: boolean, productLoaderForGroupedLoad?: ProductLoader | undefined) => Promise<boolean>;
|
|
143
143
|
private _setApiSelectionWithOtherProduct;
|
|
@@ -256,8 +256,8 @@ export declare class CfgProduct {
|
|
|
256
256
|
* selections on a product is needed, such as when doing Render or Export.
|
|
257
257
|
*/
|
|
258
258
|
getApiSelection: () => DtoAdditionalProductConfiguration;
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
getDtoConfiguration: (includeExtendedData?: boolean, includeProductParams?: boolean) => DtoProductConfiguration;
|
|
260
|
+
setDtoConfiguration: (s: DtoProductConfiguration, doValidate?: boolean) => Promise<boolean>;
|
|
261
261
|
setApiSelection: (s: DtoAdditionalProductConfiguration, doValidate?: boolean) => Promise<boolean>;
|
|
262
262
|
listenForChange: (l: SingleArgCallback<CfgProductChangeNotification>) => void;
|
|
263
263
|
stopListenForChange: (l: SingleArgCallback<CfgProductChangeNotification>) => void;
|
package/dist/CfgProduct.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { AggregatedLoadingObservable, assert, assertDefined, augmentErrorMessage, compareArrays, count, Observable, toLengthUnit, } from "@configura/web-utilities";
|
|
11
11
|
import { CfgMeasureDefinition } from "./CfgMeasure.js";
|
|
12
|
-
import {
|
|
12
|
+
import { convertDtoProductConfigurationToV1 } from "./ConfigurationConverter.js";
|
|
13
13
|
import { ProductConfigurationBubbleMode } from "./productConfiguration/CfgOption.js";
|
|
14
14
|
import { CfgProductConfiguration } from "./productConfiguration/CfgProductConfiguration.js";
|
|
15
15
|
import { collectAdditionalProductRefs } from "./productConfiguration/utilitiesProductConfiguration.js";
|
|
@@ -140,9 +140,9 @@ export class _CfgProductInternal {
|
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
|
-
this.
|
|
143
|
+
this.getDtoConfiguration = (includeExtendedData, includeProductParams) => {
|
|
144
144
|
const conf = {};
|
|
145
|
-
const features = this.configuration._internal.
|
|
145
|
+
const features = this.configuration._internal.getDtoConfiguration(includeExtendedData);
|
|
146
146
|
if (0 < features.length) {
|
|
147
147
|
conf.features = features;
|
|
148
148
|
}
|
|
@@ -151,7 +151,7 @@ export class _CfgProductInternal {
|
|
|
151
151
|
}
|
|
152
152
|
const additionalProducts = this.additionalProducts;
|
|
153
153
|
if (0 < additionalProducts.length) {
|
|
154
|
-
conf.additionalProducts = additionalProducts.map((p) => p._internal.
|
|
154
|
+
conf.additionalProducts = additionalProducts.map((p) => p._internal.getDtoConfiguration(includeExtendedData, includeProductParams));
|
|
155
155
|
}
|
|
156
156
|
if (this.isAdditionalProduct) {
|
|
157
157
|
const refKey = this.refKey;
|
|
@@ -164,12 +164,14 @@ export class _CfgProductInternal {
|
|
|
164
164
|
}
|
|
165
165
|
return conf;
|
|
166
166
|
};
|
|
167
|
-
this.
|
|
167
|
+
this.setDtoConfiguration = (s, doValidate, productLoaderForGroupedLoad) => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return yield this.setApiSelection(convertDtoProductConfigurationToV1(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
|
-
return yield this._setApiSelectionWithOtherProduct(
|
|
174
|
+
return yield this._setApiSelectionWithOtherProduct(convertDtoProductConfigurationToV1(source.getDtoConfiguration(false, false)), doValidate, productLoaderForGroupedLoad, source);
|
|
173
175
|
});
|
|
174
176
|
this._setApiSelectionWithOtherProduct = (s, doValidate, productLoaderForGroupedLoad, sourceProduct) => __awaiter(this, void 0, void 0, function* () {
|
|
175
177
|
// Wrap with cache will make getProduct for this function call use the same server call
|
|
@@ -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) {
|
|
@@ -419,7 +421,7 @@ export class _CfgProductInternal {
|
|
|
419
421
|
}
|
|
420
422
|
});
|
|
421
423
|
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);
|
|
424
|
+
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
425
|
this._selected = optional ? selected : undefined;
|
|
424
426
|
this.isAdditionalProduct = parent !== undefined;
|
|
425
427
|
this._configuration = CfgProductConfiguration.make(initSuccess, initFail, rootFeatureRefs, allRawFeatures, apiSelection, this, this.root);
|
|
@@ -649,9 +651,9 @@ export class CfgProduct {
|
|
|
649
651
|
* configuration, optional products and additional products. Used when a full view of all
|
|
650
652
|
* selections on a product is needed, such as when doing Render or Export.
|
|
651
653
|
*/
|
|
652
|
-
this.getApiSelection = () =>
|
|
653
|
-
this.
|
|
654
|
-
this.
|
|
654
|
+
this.getApiSelection = () => convertDtoProductConfigurationToV1(this._internal.getDtoConfiguration(false, false), true);
|
|
655
|
+
this.getDtoConfiguration = (includeExtendedData = false, includeProductParams = false) => this._internal.getDtoConfiguration(includeExtendedData, includeProductParams);
|
|
656
|
+
this.setDtoConfiguration = (s, doValidate = false) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.setDtoConfiguration(s, doValidate); });
|
|
655
657
|
this.setApiSelection = (s, doValidate = false) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.setApiSelection(s, doValidate); });
|
|
656
658
|
this.listenForChange = (l) => this._internal.changeObservable.listen(l);
|
|
657
659
|
this.stopListenForChange = (l) => this._internal.changeObservable.stopListen(l);
|
|
@@ -8,7 +8,20 @@ import { DtoCatalogueParamsWithLang, DtoProductParamsWithLang } from "./Catalogu
|
|
|
8
8
|
* Internally at Configura we try to stick with this format.
|
|
9
9
|
*/
|
|
10
10
|
export declare class CfgReferencePathHelper {
|
|
11
|
+
/**
|
|
12
|
+
* Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
|
|
13
|
+
* @param browsingRootUrl The URL where Stage browsing begins
|
|
14
|
+
* @param catParams What catalogue to generate URL for.
|
|
15
|
+
* @returns An URL to a catalogue
|
|
16
|
+
*/
|
|
11
17
|
static getCataloguePath: (browsingRootUrl: string, catParams: DtoCatalogueParamsWithLang) => string;
|
|
12
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
|
|
20
|
+
* @param browsingRootUrl The URL where Stage browsing begins
|
|
21
|
+
* @param productParams What product to generate URL for.
|
|
22
|
+
* @param separator Optional, defaults to "product", but can be changed to indicate another function.
|
|
23
|
+
* @returns An URL to a product
|
|
24
|
+
*/
|
|
25
|
+
static getProductPath: (browsingRootUrl: string, productParams: DtoProductParamsWithLang, separator?: string) => string;
|
|
13
26
|
}
|
|
14
27
|
//# sourceMappingURL=CfgReferencePathHelper.d.ts.map
|
|
@@ -9,5 +9,18 @@ import { encodeURIComponents } from "@configura/web-utilities";
|
|
|
9
9
|
*/
|
|
10
10
|
export class CfgReferencePathHelper {
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
|
|
14
|
+
* @param browsingRootUrl The URL where Stage browsing begins
|
|
15
|
+
* @param catParams What catalogue to generate URL for.
|
|
16
|
+
* @returns An URL to a catalogue
|
|
17
|
+
*/
|
|
12
18
|
CfgReferencePathHelper.getCataloguePath = (browsingRootUrl, catParams) => `${browsingRootUrl}/${encodeURIComponents(catParams.cid, catParams.lang, catParams.enterprise, catParams.prdCat, catParams.prdCatVersion, catParams.vendor, catParams.priceList)}`;
|
|
13
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Use to generate URLs in our reference format. This is the format Configura uses in our integrations.
|
|
21
|
+
* @param browsingRootUrl The URL where Stage browsing begins
|
|
22
|
+
* @param productParams What product to generate URL for.
|
|
23
|
+
* @param separator Optional, defaults to "product", but can be changed to indicate another function.
|
|
24
|
+
* @returns An URL to a product
|
|
25
|
+
*/
|
|
26
|
+
CfgReferencePathHelper.getProductPath = (browsingRootUrl, productParams, separator = "product") => `${CfgReferencePathHelper.getCataloguePath(browsingRootUrl, productParams)}/${separator}/${encodeURIComponent(productParams.partNumber)}`;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { DtoAdditionalProductConfiguration,
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
1
|
+
import { DtoAdditionalProductConfiguration, DtoAdditionalProductConfigurationV2, DtoFeatureConfiguration, DtoProductConfiguration, DtoSelectedOption } from "./CatalogueAPI.js";
|
|
2
|
+
export declare const isDtoProductConfigurationAdditional: (value: DtoProductConfiguration) => value is DtoAdditionalProductConfigurationV2;
|
|
3
|
+
export declare const convertDtoProductConfigurationToV1: (conf: DtoProductConfiguration, silenceWarnings?: boolean) => DtoAdditionalProductConfiguration;
|
|
4
|
+
export declare const convertDtoFeatureConfigurationsToSelOptions: (features: DtoFeatureConfiguration[], silenceWarnings?: boolean) => DtoSelectedOption[];
|
|
5
|
+
/**
|
|
6
|
+
* Serializes and compacts the configuration into a format especially suited for URLs
|
|
7
|
+
*/
|
|
8
|
+
export declare const dtoProductConfigurationToCompactString: (conf: DtoProductConfiguration) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Deserializes and inflates the configuration from the compacted format
|
|
11
|
+
*/
|
|
12
|
+
export declare const compactStringToDtoProductConfiguration: (versionAndConf: string) => DtoProductConfiguration;
|
|
5
13
|
//# sourceMappingURL=ConfigurationConverter.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const isDtoProductConfigurationAdditional = (value) => "refKey" in value;
|
|
2
2
|
// As this has potential to flood the terminal we only inform once
|
|
3
3
|
let hasInformedAboutProdParams = false;
|
|
4
4
|
let hasInformedAboutGroupCode = false;
|
|
5
5
|
let hasInformedAboutUnit = false;
|
|
6
|
-
export const
|
|
6
|
+
export const convertDtoProductConfigurationToV1 = (conf, silenceWarnings = false) => {
|
|
7
7
|
var _a, _b;
|
|
8
8
|
if (!silenceWarnings && conf.prodParams !== undefined && !hasInformedAboutProdParams) {
|
|
9
9
|
hasInformedAboutProdParams = true;
|
|
@@ -12,22 +12,22 @@ export const convertDtoConfProdToV1 = (conf, silenceWarnings = false) => {
|
|
|
12
12
|
const result = {
|
|
13
13
|
selOptions: ((_a = conf.features) !== null && _a !== void 0 ? _a : []).map((f) => ({
|
|
14
14
|
code: "!~!",
|
|
15
|
-
next:
|
|
15
|
+
next: convertDtoFeatureConfigurationToApiSelection(f, silenceWarnings),
|
|
16
16
|
})),
|
|
17
|
-
additionalProducts: ((_b = conf.additionalProducts) !== null && _b !== void 0 ? _b : []).map((p) =>
|
|
17
|
+
additionalProducts: ((_b = conf.additionalProducts) !== null && _b !== void 0 ? _b : []).map((p) => convertDtoProductConfigurationToV1(p, silenceWarnings)),
|
|
18
18
|
selected: true,
|
|
19
19
|
};
|
|
20
|
-
if (
|
|
20
|
+
if (isDtoProductConfigurationAdditional(conf)) {
|
|
21
21
|
result.refKey = conf.refKey;
|
|
22
22
|
result.selected = conf.selected;
|
|
23
23
|
}
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
|
-
export const
|
|
26
|
+
export const convertDtoFeatureConfigurationsToSelOptions = (features, silenceWarnings = false) => (features !== null && features !== void 0 ? features : []).map((f) => ({
|
|
27
27
|
code: "!~!",
|
|
28
|
-
next:
|
|
28
|
+
next: convertDtoFeatureConfigurationToApiSelection(f, silenceWarnings),
|
|
29
29
|
}));
|
|
30
|
-
const
|
|
30
|
+
const convertDtoFeatureConfigurationToApiSelection = (feature, silenceWarnings) => {
|
|
31
31
|
const { groupCode, options, unit } = feature;
|
|
32
32
|
if (!silenceWarnings && groupCode !== undefined && !hasInformedAboutGroupCode) {
|
|
33
33
|
hasInformedAboutGroupCode = true;
|
|
@@ -39,13 +39,13 @@ const convertDtoConfFeatureToApiSelection = (feature, silenceWarnings) => {
|
|
|
39
39
|
}
|
|
40
40
|
const result = {};
|
|
41
41
|
for (const option of (options !== null && options !== void 0 ? options : []).filter((o) => o.selected)) {
|
|
42
|
-
result[option.code] =
|
|
42
|
+
result[option.code] = convertDtoOptionConfigurationToSelectedOption(option, silenceWarnings);
|
|
43
43
|
}
|
|
44
44
|
return result;
|
|
45
45
|
};
|
|
46
|
-
const
|
|
46
|
+
const convertDtoOptionConfigurationToSelectedOption = (option, silenceWarnings) => {
|
|
47
47
|
const { features, code, numericValue } = option;
|
|
48
|
-
const selectionTrees = (features !== null && features !== void 0 ? features : []).map((f) =>
|
|
48
|
+
const selectionTrees = (features !== null && features !== void 0 ? features : []).map((f) => convertDtoFeatureConfigurationToApiSelection(f, silenceWarnings));
|
|
49
49
|
const mergedSelectionTree = {};
|
|
50
50
|
let anyItems = false;
|
|
51
51
|
for (const selectionTree of selectionTrees) {
|
|
@@ -70,3 +70,80 @@ const convertDtoConfOptionToSelectedOption = (option, silenceWarnings) => {
|
|
|
70
70
|
}
|
|
71
71
|
return selectedOption;
|
|
72
72
|
};
|
|
73
|
+
const versionedRegex = /^v(\d+)(.+)$/;
|
|
74
|
+
const jsonKeyRegex = /"([^"]+)":/g;
|
|
75
|
+
const swapIntoUrlAdaptedRegex = /[{}"]/g;
|
|
76
|
+
const swapFromUrlAdaptedRegex = /[-~_]/g;
|
|
77
|
+
const shortToLong = new Map();
|
|
78
|
+
const longToShort = new Map();
|
|
79
|
+
// The replacement scheme here assumes this will only be used for keys
|
|
80
|
+
// in DtoProductConfiguration and the knowledge that it contains no one
|
|
81
|
+
// one char keys.
|
|
82
|
+
for (const [long, short] of [
|
|
83
|
+
["configuration", "c"],
|
|
84
|
+
["additionalProducts", "a"],
|
|
85
|
+
["prodParams", "p"],
|
|
86
|
+
["refKey", "r"],
|
|
87
|
+
["selected", "s"],
|
|
88
|
+
["features", "f"],
|
|
89
|
+
["code", "d"],
|
|
90
|
+
["options", "o"],
|
|
91
|
+
["numericValue", "n"],
|
|
92
|
+
["groupCode", "g"],
|
|
93
|
+
["unit", "u"],
|
|
94
|
+
]) {
|
|
95
|
+
shortToLong.set(short, long);
|
|
96
|
+
longToShort.set(long, short);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* As certain chars are abundant in JSON but less abundant in the actual data
|
|
100
|
+
* we swap these so that frequent characters do not need to be URL-encoded.
|
|
101
|
+
*/
|
|
102
|
+
const jsonStringSwapCharsForUrl = (data) => data.replace(swapIntoUrlAdaptedRegex, (char) => {
|
|
103
|
+
switch (char) {
|
|
104
|
+
case "{":
|
|
105
|
+
return "~";
|
|
106
|
+
case "}":
|
|
107
|
+
return "-";
|
|
108
|
+
case '"':
|
|
109
|
+
return "_";
|
|
110
|
+
default:
|
|
111
|
+
throw new Error(`Unexpected char "${char}" in swap for URL`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
const jsonStringSwapCharsFromUrl = (data) => data.replace(swapFromUrlAdaptedRegex, (char) => {
|
|
115
|
+
switch (char) {
|
|
116
|
+
case "~":
|
|
117
|
+
return "{";
|
|
118
|
+
case "-":
|
|
119
|
+
return "}";
|
|
120
|
+
case "_":
|
|
121
|
+
return '"';
|
|
122
|
+
default:
|
|
123
|
+
throw new Error(`Unexpected char "${char}" in swap from URL`);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
const compactDtoProductConfigurationJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = longToShort.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
|
|
127
|
+
const expandDtoProductConfigurationJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = shortToLong.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
|
|
128
|
+
/**
|
|
129
|
+
* Serializes and compacts the configuration into a format especially suited for URLs
|
|
130
|
+
*/
|
|
131
|
+
export const dtoProductConfigurationToCompactString = (conf) => "v1" +
|
|
132
|
+
jsonStringSwapCharsForUrl(compactDtoProductConfigurationJsonKeys(JSON.stringify(conf, undefined, "")));
|
|
133
|
+
/**
|
|
134
|
+
* Deserializes and inflates the configuration from the compacted format
|
|
135
|
+
*/
|
|
136
|
+
export const compactStringToDtoProductConfiguration = (versionAndConf) => {
|
|
137
|
+
const match = versionedRegex.exec(versionAndConf);
|
|
138
|
+
if (match === null) {
|
|
139
|
+
throw new Error("Could not match version string");
|
|
140
|
+
}
|
|
141
|
+
const [, version, conf] = match;
|
|
142
|
+
if (version !== "1") {
|
|
143
|
+
throw new Error("Unknown packed URL version");
|
|
144
|
+
}
|
|
145
|
+
if (conf === "") {
|
|
146
|
+
throw new Error("No conf found");
|
|
147
|
+
}
|
|
148
|
+
return JSON.parse(expandDtoProductConfigurationJsonKeys(jsonStringSwapCharsFromUrl(conf)));
|
|
149
|
+
};
|
|
@@ -4,7 +4,8 @@ declare type CfgHistoryManagerMessageData = {
|
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
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
|
|
7
|
+
* used as the "state" in the history-frame, and the qsKeyValues, which are query string
|
|
8
|
+
* key-values used in the URL.
|
|
8
9
|
* When navigating back and forth the stage (message) is used to restore the old state. When
|
|
9
10
|
* opening a window with no prior history the Query String will be used.
|
|
10
11
|
*/
|
|
@@ -14,8 +15,8 @@ export declare type CfgHistoryManagerSendData<D> = {
|
|
|
14
15
|
qsKeyValues: Map<string, string | undefined>;
|
|
15
16
|
};
|
|
16
17
|
/**
|
|
17
|
-
* This class
|
|
18
|
-
*
|
|
18
|
+
* This class is used to coordinate writing and reading to the browser history.
|
|
19
|
+
* It handles messages sent from the connectors.
|
|
19
20
|
*/
|
|
20
21
|
export declare class CfgHistoryManager extends CfgWindowEventManager<"popstate", CfgHistoryManagerSendData<CfgHistoryManagerMessageData>> {
|
|
21
22
|
private static _instance;
|
|
@@ -2,8 +2,8 @@ import { mapQueryString, unmapQueryString } from "@configura/web-utilities";
|
|
|
2
2
|
import { CfgIOManager } from "./CfgIOManager.js";
|
|
3
3
|
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
4
4
|
/**
|
|
5
|
-
* This class
|
|
6
|
-
*
|
|
5
|
+
* This class is used to coordinate writing and reading to the browser history.
|
|
6
|
+
* It handles messages sent from the connectors.
|
|
7
7
|
*/
|
|
8
8
|
export class CfgHistoryManager extends CfgWindowEventManager {
|
|
9
9
|
constructor() {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DtoProductConfiguration } from "../CatalogueAPI.js";
|
|
2
2
|
import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
|
|
3
3
|
import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
|
|
4
|
-
export declare function dtoConfToString(conf: DtoConfProd): string;
|
|
5
|
-
export declare function stringToDtoConf(conf: string): DtoConfProd;
|
|
6
4
|
/**
|
|
7
5
|
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
8
6
|
*/
|
|
@@ -15,7 +13,7 @@ export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnecto
|
|
|
15
13
|
* @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
14
|
*/
|
|
17
15
|
constructor(manager: CfgHistoryManager, _useHistoryPush: boolean, _qsKey?: string, doValidate?: boolean);
|
|
18
|
-
protected getInitialProdConf():
|
|
19
|
-
protected makeSendData(conf:
|
|
16
|
+
protected getInitialProdConf(): DtoProductConfiguration | undefined;
|
|
17
|
+
protected makeSendData(conf: DtoProductConfiguration, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
|
|
20
18
|
}
|
|
21
19
|
//# sourceMappingURL=CfgHistoryToProdConfConnector.d.ts.map
|
|
@@ -1,30 +1,6 @@
|
|
|
1
|
+
import { compactStringToDtoProductConfiguration, dtoProductConfigurationToCompactString, } from "../ConfigurationConverter.js";
|
|
1
2
|
import { CfgHistoryManager } from "./CfgHistoryManager.js";
|
|
2
3
|
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
4
|
/**
|
|
29
5
|
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
30
6
|
*/
|
|
@@ -35,7 +11,7 @@ export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
|
35
11
|
* @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
12
|
*/
|
|
37
13
|
constructor(manager, _useHistoryPush, _qsKey = STAGE_PROD_CONF_MESSAGE_KEY, doValidate = true) {
|
|
38
|
-
super(manager, doValidate,
|
|
14
|
+
super(manager, doValidate, false, false);
|
|
39
15
|
this._useHistoryPush = _useHistoryPush;
|
|
40
16
|
this._qsKey = _qsKey;
|
|
41
17
|
}
|
|
@@ -44,12 +20,14 @@ export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
|
44
20
|
if (s === undefined) {
|
|
45
21
|
return undefined;
|
|
46
22
|
}
|
|
47
|
-
return
|
|
23
|
+
return compactStringToDtoProductConfiguration(s);
|
|
48
24
|
}
|
|
49
25
|
makeSendData(conf, initial) {
|
|
50
26
|
return {
|
|
51
|
-
message:
|
|
52
|
-
qsKeyValues: new Map([
|
|
27
|
+
message: CfgIOProdConfConnector.makeMessage(conf, initial, CfgProdConfMessageVersions.V2dot0),
|
|
28
|
+
qsKeyValues: new Map([
|
|
29
|
+
[STAGE_PROD_CONF_MESSAGE_KEY, dtoProductConfigurationToCompactString(conf)],
|
|
30
|
+
]),
|
|
53
31
|
useHistoryPush: this._useHistoryPush,
|
|
54
32
|
};
|
|
55
33
|
}
|
|
@@ -1,53 +1,56 @@
|
|
|
1
|
-
import { DtoAdditionalProductConfiguration,
|
|
1
|
+
import { DtoAdditionalProductConfiguration, DtoProductConfiguration } 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
|
-
conf:
|
|
12
|
+
conf: DtoProductConfiguration;
|
|
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
|
|
19
23
|
}
|
|
20
24
|
export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
|
|
21
25
|
declare type ProdConfMessageCallback = (message: CfgProdConfMessage) => Promise<void>;
|
|
22
|
-
declare type ProdConfCallback = (conf:
|
|
26
|
+
declare type ProdConfCallback = (conf: DtoProductConfiguration) => Promise<void>;
|
|
23
27
|
/**
|
|
24
28
|
* Base class for connecting the product configuration to an IO channel
|
|
25
29
|
*/
|
|
26
30
|
export declare abstract class CfgIOProdConfConnector<S> {
|
|
27
31
|
private readonly _ioManager;
|
|
28
32
|
private readonly _doValidate;
|
|
29
|
-
private readonly _sendVersions;
|
|
30
33
|
private readonly _includeExtendedDataInSend;
|
|
31
34
|
private readonly _includeProdParamsInSend;
|
|
32
35
|
private _product;
|
|
33
36
|
private _stopListenToMessage;
|
|
34
37
|
private _stopListenToProdConf;
|
|
35
|
-
constructor(_ioManager: CfgIOManager<S>, _doValidate: boolean,
|
|
38
|
+
constructor(_ioManager: CfgIOManager<S>, _doValidate: boolean, _includeExtendedDataInSend: boolean, // Only v2.0
|
|
36
39
|
_includeProdParamsInSend: boolean);
|
|
37
40
|
destroy: () => void;
|
|
38
41
|
setProduct: (product: CfgProduct | undefined) => Promise<void>;
|
|
39
42
|
private _send;
|
|
40
|
-
protected getInitialProdConf():
|
|
41
|
-
protected abstract makeSendData(conf:
|
|
42
|
-
makeMessage(conf:
|
|
43
|
-
makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
|
|
43
|
+
protected getInitialProdConf(): DtoProductConfiguration | undefined;
|
|
44
|
+
protected abstract makeSendData(conf: DtoProductConfiguration, initial: boolean): S;
|
|
45
|
+
static makeMessage(conf: DtoProductConfiguration, initial: boolean, sendVersions: CfgProdConfMessageVersions): CfgProdConfMessage;
|
|
46
|
+
static makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
|
|
44
47
|
/**
|
|
45
48
|
* Register the callback to listen for Product Configuration messages
|
|
46
49
|
* @returns A function which when called will cancel listening
|
|
47
50
|
*/
|
|
48
|
-
listenForMessage(callback: ProdConfMessageCallback): () => void;
|
|
49
|
-
makeProdConfListener(callback: ProdConfCallback): (n: CfgProductChangeNotification) => void;
|
|
50
|
-
listenForProdConf(product: CfgProduct, callback: ProdConfCallback): () => void;
|
|
51
|
+
static listenForMessage<S>(callback: ProdConfMessageCallback, ioManager: CfgIOManager<S>): () => void;
|
|
52
|
+
static makeProdConfListener(callback: ProdConfCallback, includeExtendedDataInSend: boolean, includeProdParamsInSend: boolean): (n: CfgProductChangeNotification) => void;
|
|
53
|
+
static listenForProdConf(product: CfgProduct, callback: ProdConfCallback, includeExtendedDataInSend: boolean, includeProdParamsInSend: boolean): () => void;
|
|
51
54
|
}
|
|
52
55
|
export {};
|
|
53
56
|
//# sourceMappingURL=CfgIOProdConfConnector.d.ts.map
|
|
@@ -7,7 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { convertDtoProductConfigurationToV1 } 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";
|
|
@@ -18,12 +24,11 @@ export const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
|
|
|
18
24
|
* Base class for connecting the product configuration to an IO channel
|
|
19
25
|
*/
|
|
20
26
|
export class CfgIOProdConfConnector {
|
|
21
|
-
constructor(_ioManager, _doValidate,
|
|
27
|
+
constructor(_ioManager, _doValidate, _includeExtendedDataInSend, // Only v2.0
|
|
22
28
|
_includeProdParamsInSend // Only v2.0
|
|
23
29
|
) {
|
|
24
30
|
this._ioManager = _ioManager;
|
|
25
31
|
this._doValidate = _doValidate;
|
|
26
|
-
this._sendVersions = _sendVersions;
|
|
27
32
|
this._includeExtendedDataInSend = _includeExtendedDataInSend;
|
|
28
33
|
this._includeProdParamsInSend = _includeProdParamsInSend;
|
|
29
34
|
this._stopListenToMessage = undefined;
|
|
@@ -55,47 +60,45 @@ export class CfgIOProdConfConnector {
|
|
|
55
60
|
if (currentProduct === undefined) {
|
|
56
61
|
const initialProdConf = this.getInitialProdConf();
|
|
57
62
|
if (initialProdConf !== undefined) {
|
|
58
|
-
yield newProduct.
|
|
63
|
+
yield newProduct.setDtoConfiguration(initialProdConf, this._doValidate);
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
|
-
this._send(this.makeSendData(newProduct.
|
|
62
|
-
this._stopListenToMessage =
|
|
66
|
+
this._send(this.makeSendData(newProduct.getDtoConfiguration(this._includeExtendedDataInSend, this._includeProdParamsInSend), true));
|
|
67
|
+
this._stopListenToMessage = CfgIOProdConfConnector.listenForMessage((messages) => __awaiter(this, void 0, void 0, function* () {
|
|
63
68
|
const subMessages = messages.subMessages;
|
|
64
69
|
if (subMessages.length === 0) {
|
|
65
70
|
console.warn(`${STAGE_PROD_CONF_MESSAGE_KEY} message without any submessages. Unexpected.`);
|
|
66
71
|
return;
|
|
67
72
|
}
|
|
68
|
-
const highestVersionMessage = subMessages
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
yield newProduct.setDtoConf(highestVersionMessage.conf, this._doValidate);
|
|
77
|
-
return;
|
|
73
|
+
const highestVersionMessage = getHighestVersionProdConfMessage(subMessages);
|
|
74
|
+
if (isCfgProdConfMessageV1(highestVersionMessage)) {
|
|
75
|
+
yield newProduct.setApiSelection(highestVersionMessage.conf, this._doValidate);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (isCfgProdConfMessageV2(highestVersionMessage)) {
|
|
79
|
+
yield newProduct.setDtoConfiguration(highestVersionMessage.conf, this._doValidate);
|
|
80
|
+
return;
|
|
78
81
|
}
|
|
79
82
|
throw new Error("Unknown message version");
|
|
80
|
-
}));
|
|
81
|
-
this._stopListenToProdConf =
|
|
83
|
+
}), this._ioManager);
|
|
84
|
+
this._stopListenToProdConf = CfgIOProdConfConnector.listenForProdConf(newProduct, (conf) => __awaiter(this, void 0, void 0, function* () { return this._send(this.makeSendData(conf, false)); }), this._includeExtendedDataInSend, this._includeProdParamsInSend);
|
|
82
85
|
});
|
|
83
86
|
this._send = (data) => this._ioManager.send(STAGE_PROD_CONF_MESSAGE_KEY, data);
|
|
84
87
|
}
|
|
85
88
|
getInitialProdConf() {
|
|
86
89
|
return undefined;
|
|
87
90
|
}
|
|
88
|
-
makeMessage(conf, initial) {
|
|
91
|
+
static makeMessage(conf, initial, sendVersions) {
|
|
89
92
|
const result = [];
|
|
90
|
-
if ((
|
|
93
|
+
if ((sendVersions & CfgProdConfMessageVersions.V1dot0) ===
|
|
91
94
|
CfgProdConfMessageVersions.V1dot0) {
|
|
92
95
|
const v1 = {
|
|
93
96
|
version: "1.0",
|
|
94
|
-
conf:
|
|
97
|
+
conf: convertDtoProductConfigurationToV1(conf, true),
|
|
95
98
|
};
|
|
96
99
|
result.push(v1);
|
|
97
100
|
}
|
|
98
|
-
if ((
|
|
101
|
+
if ((sendVersions & CfgProdConfMessageVersions.V2dot0) ===
|
|
99
102
|
CfgProdConfMessageVersions.V2dot0) {
|
|
100
103
|
const v2 = {
|
|
101
104
|
version: "2.0",
|
|
@@ -105,7 +108,7 @@ export class CfgIOProdConfConnector {
|
|
|
105
108
|
}
|
|
106
109
|
return { subMessages: result, initial };
|
|
107
110
|
}
|
|
108
|
-
makeMessageListener(callback) {
|
|
111
|
+
static makeMessageListener(callback) {
|
|
109
112
|
return (message) => __awaiter(this, void 0, void 0, function* () {
|
|
110
113
|
const prodConfMessage = message;
|
|
111
114
|
yield callback(prodConfMessage);
|
|
@@ -115,24 +118,23 @@ export class CfgIOProdConfConnector {
|
|
|
115
118
|
* Register the callback to listen for Product Configuration messages
|
|
116
119
|
* @returns A function which when called will cancel listening
|
|
117
120
|
*/
|
|
118
|
-
listenForMessage(callback) {
|
|
119
|
-
const ioManager = this._ioManager;
|
|
121
|
+
static listenForMessage(callback, ioManager) {
|
|
120
122
|
const listener = this.makeMessageListener(callback);
|
|
121
123
|
ioManager.listenForMessage(listener, STAGE_PROD_CONF_MESSAGE_KEY);
|
|
122
124
|
return () => {
|
|
123
125
|
ioManager.stopListenForMessage(listener);
|
|
124
126
|
};
|
|
125
127
|
}
|
|
126
|
-
makeProdConfListener(callback) {
|
|
128
|
+
static makeProdConfListener(callback, includeExtendedDataInSend, includeProdParamsInSend) {
|
|
127
129
|
return (n) => {
|
|
128
130
|
if (!n.committed) {
|
|
129
131
|
return;
|
|
130
132
|
}
|
|
131
|
-
callback(n.freshRef.
|
|
133
|
+
callback(n.freshRef.getDtoConfiguration(includeExtendedDataInSend, includeProdParamsInSend));
|
|
132
134
|
};
|
|
133
135
|
}
|
|
134
|
-
listenForProdConf(product, callback) {
|
|
135
|
-
const listener = this.makeProdConfListener(callback);
|
|
136
|
+
static listenForProdConf(product, callback, includeExtendedDataInSend, includeProdParamsInSend) {
|
|
137
|
+
const listener = this.makeProdConfListener(callback, includeExtendedDataInSend, includeProdParamsInSend);
|
|
136
138
|
product.listenForChange(listener);
|
|
137
139
|
return () => {
|
|
138
140
|
product.stopListenForChange(listener);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Observable } from "@configura/web-utilities";
|
|
2
2
|
import { CfgIOManager, IOManagerListener } from "./CfgIOManager.js";
|
|
3
|
+
/**
|
|
4
|
+
* This class is used to coordinate sending and receiving using the observable
|
|
5
|
+
* state in the class. It handles messages sent from the connectors.
|
|
6
|
+
*/
|
|
3
7
|
export declare class CfgObservableStateManager extends CfgIOManager<unknown> {
|
|
4
8
|
private static _instance;
|
|
5
9
|
static get instance(): CfgObservableStateManager;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Observable } from "@configura/web-utilities";
|
|
2
2
|
import { CfgIOManager } from "./CfgIOManager.js";
|
|
3
|
+
/**
|
|
4
|
+
* This class is used to coordinate sending and receiving using the observable
|
|
5
|
+
* state in the class. It handles messages sent from the connectors.
|
|
6
|
+
*/
|
|
3
7
|
export class CfgObservableStateManager extends CfgIOManager {
|
|
4
8
|
constructor() {
|
|
5
9
|
super();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DtoProductConfiguration } from "../CatalogueAPI.js";
|
|
2
2
|
import { CfgIOProdConfConnector, CfgProdConfMessage, CfgProdConfMessageVersions } from "./CfgIOProdConfConnector.js";
|
|
3
3
|
import { CfgObservableStateManager } from "./CfgObservableStateManager.js";
|
|
4
4
|
/**
|
|
@@ -9,7 +9,8 @@ import { CfgObservableStateManager } from "./CfgObservableStateManager.js";
|
|
|
9
9
|
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
10
10
|
*/
|
|
11
11
|
export declare class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector<CfgProdConfMessage> {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
private _sendVersions;
|
|
13
|
+
constructor(manager: CfgObservableStateManager, doValidate?: boolean, _sendVersions?: CfgProdConfMessageVersions, includeExtendedDataInSend?: boolean, includeProdParamsInSend?: boolean);
|
|
14
|
+
protected makeSendData(conf: DtoProductConfiguration, initial: boolean): CfgProdConfMessage;
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=CfgObservableStateToProdConfConnector.d.ts.map
|
|
@@ -7,10 +7,11 @@ import { CfgIOProdConfConnector, CfgProdConfMessageVersions, } from "./CfgIOProd
|
|
|
7
7
|
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
8
8
|
*/
|
|
9
9
|
export class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector {
|
|
10
|
-
constructor(manager, doValidate = true,
|
|
11
|
-
super(manager, doValidate,
|
|
10
|
+
constructor(manager, doValidate = true, _sendVersions = CfgProdConfMessageVersions.V2dot0, includeExtendedDataInSend = false, includeProdParamsInSend = false) {
|
|
11
|
+
super(manager, doValidate, includeExtendedDataInSend, includeProdParamsInSend);
|
|
12
|
+
this._sendVersions = _sendVersions;
|
|
12
13
|
}
|
|
13
14
|
makeSendData(conf, initial) {
|
|
14
|
-
return
|
|
15
|
+
return CfgIOProdConfConnector.makeMessage(conf, initial, this._sendVersions);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IOManagerListener } from "./CfgIOManager.js";
|
|
2
2
|
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
3
3
|
/**
|
|
4
|
-
* This class
|
|
5
|
-
*
|
|
4
|
+
* This class is used to coordinate sending and receiving using the post message-API.
|
|
5
|
+
* See https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
|
|
6
6
|
*/
|
|
7
7
|
export declare class CfgWindowMessageManager extends CfgWindowEventManager<"message", unknown> {
|
|
8
8
|
private static _instance;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CfgIOManager } from "./CfgIOManager.js";
|
|
2
2
|
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
3
3
|
/**
|
|
4
|
-
* This class
|
|
5
|
-
*
|
|
4
|
+
* This class is used to coordinate sending and receiving using the post message-API.
|
|
5
|
+
* See https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
|
|
6
6
|
*/
|
|
7
7
|
export class CfgWindowMessageManager extends CfgWindowEventManager {
|
|
8
8
|
/**
|
|
@@ -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
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DtoProductConfiguration } from "../CatalogueAPI.js";
|
|
2
2
|
import { CfgIOProdConfConnector, CfgProdConfMessage, CfgProdConfMessageVersions } from "./CfgIOProdConfConnector.js";
|
|
3
3
|
import { CfgWindowMessageManager } from "./CfgWindowMessageManager.js";
|
|
4
4
|
/**
|
|
@@ -11,7 +11,8 @@ import { CfgWindowMessageManager } from "./CfgWindowMessageManager.js";
|
|
|
11
11
|
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
12
12
|
*/
|
|
13
13
|
export declare class CfgWindowMessageToProdConfConnector extends CfgIOProdConfConnector<CfgProdConfMessage> {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
private _sendVersions;
|
|
15
|
+
constructor(manager: CfgWindowMessageManager, doValidate?: boolean, _sendVersions?: CfgProdConfMessageVersions, includeExtendedDataInSend?: boolean, includeProdParamsInSend?: boolean);
|
|
16
|
+
protected makeSendData(conf: DtoProductConfiguration, initial: boolean): CfgProdConfMessage;
|
|
16
17
|
}
|
|
17
18
|
//# sourceMappingURL=CfgWindowMessageToProdConfConnector.d.ts.map
|
|
@@ -9,10 +9,11 @@ import { CfgIOProdConfConnector, CfgProdConfMessageVersions, } from "./CfgIOProd
|
|
|
9
9
|
* @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
|
|
10
10
|
*/
|
|
11
11
|
export class CfgWindowMessageToProdConfConnector extends CfgIOProdConfConnector {
|
|
12
|
-
constructor(manager, doValidate = true,
|
|
13
|
-
super(manager, doValidate,
|
|
12
|
+
constructor(manager, doValidate = true, _sendVersions = CfgProdConfMessageVersions.V2dot0, includeExtendedDataInSend = false, includeProdParamsInSend = false) {
|
|
13
|
+
super(manager, doValidate, includeExtendedDataInSend, includeProdParamsInSend);
|
|
14
|
+
this._sendVersions = _sendVersions;
|
|
14
15
|
}
|
|
15
16
|
makeSendData(conf, initial) {
|
|
16
|
-
return
|
|
17
|
+
return CfgIOProdConfConnector.makeMessage(conf, initial, this._sendVersions);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LengthUnit, Observable, SingleArgCallback } from "@configura/web-utilities";
|
|
2
|
-
import {
|
|
2
|
+
import { DtoFeature, DtoFeatureConfiguration, DtoSelectedOption, DtoSyncGroup, DtoSyncGroupMethods } from "../CatalogueAPI.js";
|
|
3
3
|
import { CfgProduct, _CfgProductInternal } from "../CfgProduct.js";
|
|
4
4
|
import { CfgMtrlApplication } from "../material/CfgMtrlApplication.js";
|
|
5
5
|
import { SyncCode } from "../syncGroups/SyncGroupsHandler.js";
|
|
@@ -99,7 +99,7 @@ export declare class _CfgFeatureInternal {
|
|
|
99
99
|
* as nonexisting children can not call their parent.
|
|
100
100
|
*/
|
|
101
101
|
_childHasChanged: (childOption: _CfgOptionInternal, bubbleMode: ProductConfigurationBubbleMode, committed: boolean) => Promise<void>;
|
|
102
|
-
|
|
102
|
+
getDtoConfiguration: (includeExtendedData: boolean) => DtoFeatureConfiguration;
|
|
103
103
|
setApiSelection: (apiOptionSelectionMap: {
|
|
104
104
|
[index: string]: DtoSelectedOption;
|
|
105
105
|
} | undefined) => Promise<boolean>;
|
|
@@ -114,7 +114,7 @@ export class _CfgFeatureInternal {
|
|
|
114
114
|
}
|
|
115
115
|
yield this._notifyAllOfChange(bubbleMode, committed);
|
|
116
116
|
});
|
|
117
|
-
this.
|
|
117
|
+
this.getDtoConfiguration = (includeExtendedData) => {
|
|
118
118
|
const result = {
|
|
119
119
|
code: this.code,
|
|
120
120
|
};
|
|
@@ -124,7 +124,7 @@ export class _CfgFeatureInternal {
|
|
|
124
124
|
}
|
|
125
125
|
const selectedOptions = this._selectedOptions;
|
|
126
126
|
if (0 < selectedOptions.length) {
|
|
127
|
-
result.options = selectedOptions.map((o) => o._internal.
|
|
127
|
+
result.options = selectedOptions.map((o) => o._internal.getDtoConfiguration(includeExtendedData));
|
|
128
128
|
}
|
|
129
129
|
return result;
|
|
130
130
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LengthUnit, Observable, SingleArgCallback } from "@configura/web-utilities";
|
|
2
|
-
import {
|
|
2
|
+
import { DtoFeature, DtoOption, DtoOptionConfiguration, DtoSelectedOption } from "../CatalogueAPI.js";
|
|
3
3
|
import { CfgProduct, _CfgProductInternal } from "../CfgProduct.js";
|
|
4
4
|
import { CfgMtrlApplication } from "../material/CfgMtrlApplication.js";
|
|
5
5
|
import { NumericValuesSelection } from "../utilitiesNumericValues.js";
|
|
@@ -89,7 +89,7 @@ export declare class _CfgOptionInternal {
|
|
|
89
89
|
get features(): CfgFeature[];
|
|
90
90
|
/** Called by child to tell its parent that it has changed. */
|
|
91
91
|
_childHasChanged: (freshRef: CfgFeature, bubbleMode: ProductConfigurationBubbleMode, committed: boolean) => Promise<void>;
|
|
92
|
-
|
|
92
|
+
getDtoConfiguration: (includeExtendedData: boolean) => DtoOptionConfiguration;
|
|
93
93
|
setApiSelection: (apiOptionSelection: DtoSelectedOption | undefined) => Promise<boolean>;
|
|
94
94
|
structureCompare: (other: _CfgOptionInternal, strictOrder?: boolean, descriptionMatch?: boolean) => boolean;
|
|
95
95
|
tryMatchSelection: (other: CfgOption, descriptionMatch?: boolean) => Promise<boolean>;
|
|
@@ -110,7 +110,7 @@ export class _CfgOptionInternal {
|
|
|
110
110
|
yield this.parent._childHasChanged(this, bubbleMode, committed);
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
|
-
this.
|
|
113
|
+
this.getDtoConfiguration = (includeExtendedData) => {
|
|
114
114
|
const { features, isUseNumericValue, code, selected, numericValue } = this;
|
|
115
115
|
if (!selected) {
|
|
116
116
|
throw new Error("Currently only useable on selected options. Selected in the result is for future use.");
|
|
@@ -128,7 +128,7 @@ export class _CfgOptionInternal {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
if (0 < features.length) {
|
|
131
|
-
result.features = features.map((f) => f._internal.
|
|
131
|
+
result.features = features.map((f) => f._internal.getDtoConfiguration(includeExtendedData));
|
|
132
132
|
}
|
|
133
133
|
return result;
|
|
134
134
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LengthUnit, LengthValue, Observable, SingleArgCallback } from "@configura/web-utilities";
|
|
2
|
-
import {
|
|
2
|
+
import { DtoFeature, DtoFeatureConfiguration, DtoFeatureRef, DtoSelectedOption } from "../CatalogueAPI.js";
|
|
3
3
|
import { CfgProduct, _CfgProductInternal } from "../CfgProduct.js";
|
|
4
4
|
import { CfgFeature, _CfgFeatureInternal } from "./CfgFeature.js";
|
|
5
5
|
import { ProductConfigurationBubbleMode } from "./CfgOption.js";
|
|
@@ -34,7 +34,7 @@ export declare class _CfgProductConfigurationInternal {
|
|
|
34
34
|
_freshRefDescendants(): void;
|
|
35
35
|
/** Called by child to tell its parent that it has changed. */
|
|
36
36
|
_childHasChanged: (freshRef: CfgFeature, bubbleMode: ProductConfigurationBubbleMode, committed: boolean) => Promise<void>;
|
|
37
|
-
|
|
37
|
+
getDtoConfiguration: (includeExtendedData: boolean) => DtoFeatureConfiguration[];
|
|
38
38
|
/**
|
|
39
39
|
* When used internally the notifications are taken care off by the caller, but if set from
|
|
40
40
|
* outside we want notifications to bubble all the way to the root.
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { compareArrays, count, isEqualLength, isLengthUnit, Observable, toError, toLengthUnit, } from "@configura/web-utilities";
|
|
11
11
|
import { CfgProduct } from "../CfgProduct.js";
|
|
12
|
-
import {
|
|
12
|
+
import { convertDtoFeatureConfigurationsToSelOptions } from "../ConfigurationConverter.js";
|
|
13
13
|
import { CfgFeature } from "./CfgFeature.js";
|
|
14
14
|
import { ProductConfigurationBubbleMode } from "./CfgOption.js";
|
|
15
15
|
import { syncCfgFeatures } from "./utilitiesProductConfiguration.js";
|
|
@@ -55,7 +55,7 @@ export class _CfgProductConfigurationInternal {
|
|
|
55
55
|
features[i] = freshRef;
|
|
56
56
|
yield this._notifyAllOfChange(bubbleMode, committed);
|
|
57
57
|
});
|
|
58
|
-
this.
|
|
58
|
+
this.getDtoConfiguration = (includeExtendedData) => this._features.map((f) => f._internal.getDtoConfiguration(includeExtendedData));
|
|
59
59
|
/**
|
|
60
60
|
* When used internally the notifications are taken care off by the caller, but if set from
|
|
61
61
|
* outside we want notifications to bubble all the way to the root.
|
|
@@ -233,7 +233,7 @@ export class CfgProductConfiguration {
|
|
|
233
233
|
*/
|
|
234
234
|
this.tryMatchSelection = (other, descriptionMatch = false // Match on case insensitive description, not code
|
|
235
235
|
) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.tryMatchSelection(other._internal, descriptionMatch, true); });
|
|
236
|
-
this.getApiSelection = () =>
|
|
236
|
+
this.getApiSelection = () => convertDtoFeatureConfigurationsToSelOptions(this._internal.getDtoConfiguration(false), true);
|
|
237
237
|
/**
|
|
238
238
|
* This method does not propagate its selections.
|
|
239
239
|
* This method will not cause validation calls. Data is assumed to already be validated.
|
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.12",
|
|
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.12"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "82ffe4d0ec20d169b4e7ddb94b8207b6aa7d62a2"
|
|
29
29
|
}
|