@veloceapps/sdk 8.0.0-99 → 9.0.0-1
Sign up to get free protection for your applications and to get access to all the features.
- package/cms/README.md +0 -20
- package/cms/cms.actions.d.ts +9 -1
- package/cms/components/preview/preview.component.d.ts +2 -3
- package/cms/components/preview/preview.types.d.ts +4 -0
- package/cms/index.d.ts +1 -0
- package/cms/modules/runtime/services/runtime.service.d.ts +1 -1
- package/cms/services/index.d.ts +0 -1
- package/cms/services/resources.service.d.ts +2 -0
- package/cms/types/index.d.ts +0 -1
- package/cms/utils/element-metadata-worker.d.ts +11 -0
- package/cms/utils/elements-resolver.d.ts +0 -2
- package/cms/utils/index.d.ts +3 -0
- package/cms/utils/transpilation-worker.d.ts +13 -0
- package/cms/vendor-map.d.ts +21 -18
- package/core/README.md +20 -0
- package/core/modules/configuration/configuration.module.d.ts +2 -1
- package/core/modules/configuration/helpers.d.ts +2 -1
- package/core/modules/configuration/index.d.ts +1 -1
- package/core/modules/configuration/services/configuration-state.service.d.ts +54 -0
- package/core/modules/configuration/services/configuration.service.d.ts +6 -6
- package/core/modules/configuration/types/configuration.types.d.ts +4 -0
- package/core/modules/flow-configuration/flow-configuration.module.d.ts +2 -1
- package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +5 -0
- package/core/services/context.service.d.ts +2 -0
- package/core/services/flow-info.service.d.ts +29 -0
- package/core/services/flow-state-configuration.service.d.ts +19 -0
- package/core/services/flow-state.service.d.ts +80 -0
- package/core/services/index.d.ts +4 -1
- package/core/services/quote-draft.service.d.ts +12 -28
- package/core/types/flow-customization.types.d.ts +22 -0
- package/core/types/flow-state.types.d.ts +11 -0
- package/core/types/index.d.ts +3 -1
- package/{cms → core}/types/integration.types.d.ts +0 -1
- package/core/utils/line-item.utils.d.ts +1 -3
- package/esm2020/cms/cms.actions.mjs +11 -1
- package/esm2020/cms/components/element-renderer/element-renderer.component.mjs +3 -3
- package/esm2020/cms/components/element-tools-panel/element-tools-panel.component.mjs +3 -3
- package/esm2020/cms/components/preview/preview.component.mjs +10 -10
- package/esm2020/cms/components/preview/preview.module.mjs +2 -2
- package/esm2020/cms/components/preview/preview.types.mjs +1 -1
- package/esm2020/cms/index.mjs +2 -1
- package/esm2020/cms/launcher.module.mjs +4 -4
- package/esm2020/cms/modules/migrations/migrations.mjs +2 -2
- package/esm2020/cms/modules/migrations/services/migrations.service.mjs +6 -2
- package/esm2020/cms/modules/runtime/services/compilation.service.mjs +8 -8
- package/esm2020/cms/modules/runtime/services/runtime.service.mjs +4 -4
- package/esm2020/cms/plugins/configuration.plugin.mjs +8 -4
- package/esm2020/cms/services/index.mjs +1 -2
- package/esm2020/cms/services/io-provider.service.mjs +10 -9
- package/esm2020/cms/services/resources.service.mjs +10 -6
- package/esm2020/cms/services/templates.service.mjs +10 -9
- package/esm2020/cms/types/index.mjs +1 -2
- package/esm2020/cms/utils/element-metadata-worker.mjs +31 -0
- package/esm2020/cms/utils/elements-resolver.mjs +13 -27
- package/esm2020/cms/utils/encoding.utils.mjs +3 -2
- package/esm2020/cms/utils/index.mjs +4 -1
- package/esm2020/cms/utils/path.utils.mjs +3 -3
- package/esm2020/cms/utils/script.utils.mjs +19 -15
- package/esm2020/cms/utils/transpilation-worker.mjs +52 -0
- package/esm2020/cms/vendor-map.mjs +10 -5
- package/esm2020/core/core.module.mjs +19 -3
- package/esm2020/core/modules/configuration/configuration.module.mjs +7 -23
- package/esm2020/core/modules/configuration/helpers.mjs +21 -1
- package/esm2020/core/modules/configuration/index.mjs +2 -2
- package/esm2020/core/modules/configuration/services/configuration-state.service.mjs +335 -0
- package/esm2020/core/modules/configuration/services/configuration.service.mjs +56 -50
- package/esm2020/core/modules/configuration/types/configuration.types.mjs +1 -1
- package/esm2020/core/modules/flow-configuration/flow-configuration.module.mjs +6 -6
- package/esm2020/core/modules/flow-configuration/services/flow-configuration.service.mjs +12 -9
- package/esm2020/core/services/context.service.mjs +17 -5
- package/esm2020/core/services/flow-info.service.mjs +99 -0
- package/esm2020/core/services/flow-state-configuration.service.mjs +53 -0
- package/esm2020/core/services/flow-state.service.mjs +512 -0
- package/esm2020/core/services/index.mjs +5 -2
- package/esm2020/core/services/integration.state.mjs +36 -0
- package/esm2020/core/services/product-images.service.mjs +4 -5
- package/esm2020/core/services/quote-draft.service.mjs +39 -91
- package/esm2020/core/services/runtime-settings.service.mjs +7 -5
- package/esm2020/core/types/flow-customization.types.mjs +3 -0
- package/esm2020/core/types/flow-state.types.mjs +2 -0
- package/esm2020/core/types/index.mjs +4 -2
- package/esm2020/core/types/integration.types.mjs +2 -0
- package/esm2020/core/utils/line-item.utils.mjs +33 -32
- package/esm2020/src/components/doc-gen/doc-gen.component.mjs +44 -51
- package/esm2020/src/components/flow-header/flow-header.component.mjs +36 -47
- package/esm2020/src/components/guided-selling/guided-selling.component.mjs +35 -46
- package/esm2020/src/flow-routing.module.mjs +5 -18
- package/esm2020/src/flow.component.mjs +22 -37
- package/esm2020/src/guards/context.guard.mjs +6 -11
- package/esm2020/src/guards/flow.guard.mjs +23 -9
- package/esm2020/src/pages/assets/assets.component.mjs +30 -34
- package/esm2020/src/pages/catalog/catalog.component.mjs +30 -34
- package/esm2020/src/pages/debug/debug.component.mjs +2 -2
- package/esm2020/src/pages/product/product.component.mjs +34 -20
- package/esm2020/src/pages/record-not-found/record-not-found.component.mjs +6 -3
- package/esm2020/src/pages/remote/remote.component.mjs +15 -14
- package/esm2020/src/pages/shopping-cart/shopping-cart.component.mjs +31 -35
- package/esm2020/src/resolvers/flow.resolver.mjs +37 -55
- package/esm2020/src/resolvers/quote.resolver.mjs +55 -67
- package/esm2020/src/services/doc-gen.service.mjs +4 -3
- package/esm2020/src/services/flow-dialog.service.mjs +17 -6
- package/esm2020/src/services/flow-router.service.mjs +42 -15
- package/esm2020/src/services/flow.service.mjs +67 -52
- package/esm2020/src/services/guided-selling.service.mjs +5 -4
- package/esm2020/src/types/index.mjs +1 -2
- package/fesm2015/veloceapps-sdk-cms.mjs +270 -191
- package/fesm2015/veloceapps-sdk-cms.mjs.map +1 -1
- package/fesm2015/veloceapps-sdk-core.mjs +1195 -427
- package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
- package/fesm2015/veloceapps-sdk.mjs +776 -826
- package/fesm2015/veloceapps-sdk.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk-cms.mjs +275 -206
- package/fesm2020/veloceapps-sdk-cms.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk-core.mjs +1176 -454
- package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
- package/fesm2020/veloceapps-sdk.mjs +899 -945
- package/fesm2020/veloceapps-sdk.mjs.map +1 -1
- package/package.json +8 -7
- package/src/components/doc-gen/doc-gen.component.d.ts +7 -10
- package/src/components/flow-header/flow-header.component.d.ts +6 -9
- package/src/components/guided-selling/guided-selling.component.d.ts +6 -9
- package/src/flow-routing.module.d.ts +1 -2
- package/src/flow.component.d.ts +7 -12
- package/src/guards/context.guard.d.ts +0 -1
- package/src/guards/flow.guard.d.ts +1 -1
- package/src/pages/assets/assets.component.d.ts +5 -7
- package/src/pages/catalog/catalog.component.d.ts +5 -7
- package/src/pages/product/product.component.d.ts +8 -7
- package/src/pages/record-not-found/record-not-found.component.d.ts +2 -0
- package/src/pages/remote/remote.component.d.ts +2 -3
- package/src/pages/shopping-cart/shopping-cart.component.d.ts +5 -7
- package/src/resolvers/flow.resolver.d.ts +6 -9
- package/src/resolvers/quote.resolver.d.ts +7 -14
- package/src/services/doc-gen.service.d.ts +1 -1
- package/src/services/flow-dialog.service.d.ts +4 -2
- package/src/services/flow-router.service.d.ts +6 -3
- package/src/services/flow.service.d.ts +10 -14
- package/src/services/guided-selling.service.d.ts +1 -1
- package/src/types/index.d.ts +0 -1
- package/core/modules/configuration/services/configuration.state.d.ts +0 -30
- package/core/services/metric-calculation/metric-calculation.service.d.ts +0 -25
- package/core/services/metric-calculation/metric-calculation.types.d.ts +0 -1
- package/core/services/metric-calculation/metric-calculation.utils.d.ts +0 -5
- package/esm2020/cms/services/integration.state.mjs +0 -37
- package/esm2020/cms/types/integration.types.mjs +0 -2
- package/esm2020/core/modules/configuration/services/configuration.state.mjs +0 -142
- package/esm2020/core/services/metric-calculation/metric-calculation.service.mjs +0 -85
- package/esm2020/core/services/metric-calculation/metric-calculation.types.mjs +0 -2
- package/esm2020/core/services/metric-calculation/metric-calculation.utils.mjs +0 -42
- package/esm2020/src/pages/empty-account/empty-account.component.mjs +0 -12
- package/esm2020/src/pages/empty-account/empty-account.module.mjs +0 -20
- package/esm2020/src/types/flow-customization.types.mjs +0 -3
- package/src/pages/empty-account/empty-account.component.d.ts +0 -5
- package/src/pages/empty-account/empty-account.module.d.ts +0 -10
- package/src/types/flow-customization.types.d.ts +0 -12
- /package/{cms → core}/services/integration.state.d.ts +0 -0
@@ -1,17 +1,17 @@
|
|
1
1
|
import * as i0 from '@angular/core';
|
2
|
-
import { InjectionToken, Injectable, NgModule, inject, Directive, Input, LOCALE_ID, Pipe } from '@angular/core';
|
3
|
-
import { UUID, ConfigurationContextMode, ConfigurationContext, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, DEFAULT_ACTION_CODE_LABELS, parseJsonSafely, ConfigurationMode, ConfigurationTranslatorUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils,
|
4
|
-
import { BehaviorSubject,
|
5
|
-
import { map, filter, tap, switchMap, skip, take, shareReplay, catchError, finalize, first } from 'rxjs/operators';
|
2
|
+
import { InjectionToken, Injectable, Optional, Inject, NgModule, inject, Directive, Input, LOCALE_ID, Pipe } from '@angular/core';
|
3
|
+
import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, isDefined, ConfigurationProcessorTypes, EntityUtil, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, DEFAULT_ACTION_CODE_LABELS, parseJsonSafely, ConfigurationMode, ConfigurationTranslatorUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, DEFAULT_TIME_FORMAT, formatNumber } from '@veloceapps/core';
|
4
|
+
import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, of, forkJoin, zip, combineLatest, Subject, filter as filter$1, shareReplay as shareReplay$1, finalize, takeUntil, buffer, debounceTime, share, take as take$1, distinctUntilChanged } from 'rxjs';
|
5
|
+
import { map, filter, tap, switchMap as switchMap$1, skip, take, shareReplay, catchError as catchError$1, finalize as finalize$1, first } from 'rxjs/operators';
|
6
6
|
import * as i1 from '@veloceapps/api';
|
7
|
-
import {
|
8
|
-
import { merge, isEqual, flatten, sortBy, map as map$
|
7
|
+
import { ApiModule } from '@veloceapps/api';
|
8
|
+
import { merge, isEmpty, isEqual, cloneDeep, assign, flatten, entries, sortBy, map as map$2, omit, uniqBy, transform } from 'lodash';
|
9
|
+
import * as i6 from '@veloceapps/components';
|
10
|
+
import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
|
9
11
|
import moment from 'moment';
|
10
12
|
import { HttpErrorResponse } from '@angular/common/http';
|
11
|
-
import * as i4 from '@veloceapps/components';
|
12
|
-
import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
|
13
13
|
import * as i5 from 'primeng/api';
|
14
|
-
import * as i6 from 'primeng/dynamicdialog';
|
14
|
+
import * as i6$1 from 'primeng/dynamicdialog';
|
15
15
|
import { NgControl } from '@angular/forms';
|
16
16
|
import { DATE_PIPE_DEFAULT_OPTIONS, formatDate } from '@angular/common';
|
17
17
|
|
@@ -48,6 +48,29 @@ const getGuidedSellingConfigurationRequest = (data, context) => {
|
|
48
48
|
},
|
49
49
|
};
|
50
50
|
};
|
51
|
+
const generateConfigurationLineItem = (props, qty = 1) => {
|
52
|
+
var _a, _b, _c;
|
53
|
+
const id = UUID.UUID();
|
54
|
+
const attributes = Object.entries((_a = props.attributesMap) !== null && _a !== void 0 ? _a : {}).map(([name, value]) => ({
|
55
|
+
name,
|
56
|
+
value,
|
57
|
+
cfgStatus: 'User',
|
58
|
+
}));
|
59
|
+
const lineItems = [];
|
60
|
+
return {
|
61
|
+
id,
|
62
|
+
type: (_b = props.product.typeName) !== null && _b !== void 0 ? _b : '',
|
63
|
+
cfgStatus: 'Default',
|
64
|
+
actionCode: 'ADD',
|
65
|
+
qty,
|
66
|
+
attributes,
|
67
|
+
lineItems,
|
68
|
+
productName: props.product.name,
|
69
|
+
productId: (_c = props.product.id) !== null && _c !== void 0 ? _c : '',
|
70
|
+
};
|
71
|
+
};
|
72
|
+
|
73
|
+
const FLOW_CUSTOMIZATION = new InjectionToken('FLOW_CUSTOMIZATION');
|
51
74
|
|
52
75
|
const FORMATTING_SETTINGS_TOKEN = new InjectionToken('Summary of formatting settings for variant types of data, e.g. numbers, text, dates, etc');
|
53
76
|
|
@@ -81,7 +104,20 @@ class ContextService {
|
|
81
104
|
return this.context.pipe(map(Boolean));
|
82
105
|
}
|
83
106
|
get mode() {
|
84
|
-
return this.resolve().properties
|
107
|
+
return this.resolve().properties['#mode'];
|
108
|
+
}
|
109
|
+
get isEditMode$() {
|
110
|
+
return this.resolve$().pipe(map(() => this.isEditMode));
|
111
|
+
}
|
112
|
+
get isEditMode() {
|
113
|
+
const context = this.resolve();
|
114
|
+
if (context.properties['#mode'] === ConfigurationContextMode.ACCOUNT) {
|
115
|
+
return true;
|
116
|
+
}
|
117
|
+
if (context.properties['#mode'] === ConfigurationContextMode.QUOTE) {
|
118
|
+
return context.properties.Status === 'Draft';
|
119
|
+
}
|
120
|
+
return false;
|
85
121
|
}
|
86
122
|
resolve() {
|
87
123
|
if (!this.context.value) {
|
@@ -119,55 +155,111 @@ class ContextService {
|
|
119
155
|
}
|
120
156
|
}
|
121
157
|
ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
122
|
-
ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService
|
158
|
+
ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService });
|
123
159
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService, decorators: [{
|
124
|
-
type: Injectable
|
125
|
-
args: [{ providedIn: 'root' }]
|
160
|
+
type: Injectable
|
126
161
|
}], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
|
127
162
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
163
|
+
class FlowInfoService {
|
164
|
+
get flow() {
|
165
|
+
return this.flowSubj$.value;
|
166
|
+
}
|
167
|
+
set flow(value) {
|
168
|
+
this.flowSubj$.next(value);
|
169
|
+
}
|
170
|
+
get isLegacy() {
|
171
|
+
var _a;
|
172
|
+
return !!this.flow && ((_a = this.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful) == null;
|
173
|
+
}
|
174
|
+
get isStateful() {
|
175
|
+
var _a;
|
176
|
+
return !!((_a = this.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful);
|
177
|
+
}
|
178
|
+
constructor(flowsApiService, templatesApiService, customizationService) {
|
179
|
+
this.flowsApiService = flowsApiService;
|
180
|
+
this.templatesApiService = templatesApiService;
|
181
|
+
this.customizationService = customizationService;
|
182
|
+
this.templates = {};
|
183
|
+
this.defaultTemplates = {
|
184
|
+
flowEngine: 'Flow Engine',
|
185
|
+
};
|
186
|
+
this.flowSubj$ = new BehaviorSubject(null);
|
187
|
+
this.flow$ = this.flowSubj$.asObservable();
|
188
|
+
}
|
189
|
+
init$(flowId, params) {
|
190
|
+
this.params = params;
|
191
|
+
return this.flowsApiService.getFlow(flowId).pipe(switchMap(flow => this.initFlowTemplates$(flow).pipe(map$1(() => flow))), tap$1(flow => this.flowSubj$.next(flow)), map$1(noop), catchError(e => {
|
192
|
+
this.flowSubj$.next(null);
|
193
|
+
return throwError(() => e);
|
194
|
+
}));
|
195
|
+
}
|
196
|
+
cleanup() {
|
197
|
+
this.flowSubj$.next(null);
|
198
|
+
this.params = undefined;
|
199
|
+
this.templates = {};
|
200
|
+
}
|
201
|
+
initFlowTemplates$(flow) {
|
202
|
+
var _a, _b, _c;
|
203
|
+
if (isEmpty(flow.properties.templates)) {
|
204
|
+
return of(undefined);
|
157
205
|
}
|
158
|
-
|
159
|
-
|
206
|
+
return forkJoin([
|
207
|
+
this.templatesApiService.fetchTemplates$(),
|
208
|
+
(_c = (_b = (_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getTemplates) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : of([]),
|
209
|
+
]).pipe(map$1(([templates, localTemplates]) => {
|
210
|
+
Object.entries(Object.assign(Object.assign({}, this.defaultTemplates), flow.properties.templates)).forEach(([key, name]) => {
|
211
|
+
var _a;
|
212
|
+
const type = this.remapTemplateName(key);
|
213
|
+
if (type) {
|
214
|
+
this.templates[type] =
|
215
|
+
(_a = localTemplates.find(template => template.name === name && template.type === type)) !== null && _a !== void 0 ? _a : templates.find(template => template.name === name && template.type === type);
|
216
|
+
}
|
217
|
+
});
|
218
|
+
}));
|
219
|
+
}
|
220
|
+
remapTemplateName(templateType) {
|
221
|
+
switch (templateType) {
|
222
|
+
case 'flowEngine':
|
223
|
+
return UITemplateType.FLOW_ENGINE;
|
224
|
+
default:
|
225
|
+
break;
|
160
226
|
}
|
161
|
-
|
162
|
-
|
227
|
+
switch (templateType) {
|
228
|
+
case 'assets':
|
229
|
+
case 'shoppingCart':
|
230
|
+
// No separate Assets template at the moment
|
231
|
+
return UITemplateType.SHOPPING_CART;
|
232
|
+
case 'catalog':
|
233
|
+
return UITemplateType.CATALOG;
|
234
|
+
case 'docGen':
|
235
|
+
return UITemplateType.DOCGEN;
|
236
|
+
case 'guidedSelling':
|
237
|
+
return UITemplateType.GUIDED_SELLING;
|
238
|
+
case 'flowHeader':
|
239
|
+
return UITemplateType.FLOW_HEADER;
|
240
|
+
default:
|
241
|
+
break;
|
163
242
|
}
|
243
|
+
return undefined;
|
164
244
|
}
|
165
245
|
}
|
166
|
-
|
167
|
-
|
168
|
-
|
246
|
+
FlowInfoService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowInfoService, deps: [{ token: i1.FlowsApiService }, { token: i1.UITemplatesApiService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
247
|
+
FlowInfoService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowInfoService });
|
248
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowInfoService, decorators: [{
|
249
|
+
type: Injectable
|
250
|
+
}], ctorParameters: function () {
|
251
|
+
return [{ type: i1.FlowsApiService }, { type: i1.UITemplatesApiService }, { type: undefined, decorators: [{
|
252
|
+
type: Optional
|
253
|
+
}, {
|
254
|
+
type: Inject,
|
255
|
+
args: [FLOW_CUSTOMIZATION]
|
256
|
+
}] }];
|
257
|
+
} });
|
169
258
|
|
170
259
|
class QuoteDraftService {
|
260
|
+
get isInitialized$() {
|
261
|
+
return this.isInitializedSubj$.asObservable();
|
262
|
+
}
|
171
263
|
get isInitialized() {
|
172
264
|
return this.isInitializedSubj$.getValue();
|
173
265
|
}
|
@@ -190,40 +282,56 @@ class QuoteDraftService {
|
|
190
282
|
return this.quoteSubj$.pipe(map(() => this.hasProducts));
|
191
283
|
}
|
192
284
|
get hasProducts() {
|
193
|
-
|
194
|
-
return Boolean(
|
285
|
+
var _a;
|
286
|
+
return Boolean((_a = this.quoteSubj$.value) === null || _a === void 0 ? void 0 : _a.currentState.length);
|
287
|
+
}
|
288
|
+
get hasAssets$() {
|
289
|
+
return this.assetsSubj$.pipe(map(() => this.hasAssets));
|
290
|
+
}
|
291
|
+
get hasAssets() {
|
292
|
+
var _a;
|
293
|
+
return Boolean((_a = this.assetsSubj$.value) === null || _a === void 0 ? void 0 : _a.currentState.length);
|
294
|
+
}
|
295
|
+
get assetsState() {
|
296
|
+
return this.assetsSubj$.value;
|
195
297
|
}
|
196
|
-
constructor(context,
|
298
|
+
constructor(context, accountApiService, quoteApiService) {
|
197
299
|
this.context = context;
|
300
|
+
this.accountApiService = accountApiService;
|
198
301
|
this.quoteApiService = quoteApiService;
|
199
|
-
this.priceApiService = priceApiService;
|
200
302
|
this.quoteSubj$ = new BehaviorSubject(null);
|
303
|
+
this.assetsSubj$ = new BehaviorSubject(null);
|
201
304
|
this.resetSubj$ = new BehaviorSubject(true);
|
202
305
|
this.isInitializedSubj$ = new BehaviorSubject(false);
|
203
306
|
this.initialCurrentState = [];
|
204
307
|
this._hasUnsavedChanges = false;
|
205
|
-
this.allPriceLists = [];
|
206
|
-
this.assetPriceLists = [];
|
207
308
|
this.reset$ = this.resetSubj$.asObservable();
|
208
|
-
this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), map(priceList => priceList !== null && priceList !== void 0 ? priceList : null));
|
209
309
|
this.isInitializedSubj$
|
210
|
-
.pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
|
310
|
+
.pipe(filter(isInitialized => isInitialized), switchMap$1(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
|
211
311
|
.subscribe();
|
212
312
|
}
|
213
313
|
reset() {
|
214
314
|
this.resetSubj$.next(true);
|
215
315
|
this.quoteSubj$.next(null);
|
316
|
+
this.assetsSubj$.next(null);
|
216
317
|
this.isInitialized = false;
|
217
318
|
this.hasUnsavedChanges = false;
|
218
319
|
}
|
219
|
-
init(
|
220
|
-
|
221
|
-
|
320
|
+
init(headerId, params) {
|
321
|
+
const ctx = this.context.resolve();
|
322
|
+
const accountId = this.context.mode === ConfigurationContextMode.ACCOUNT ? headerId : ctx.properties.AccountId;
|
323
|
+
return zip(accountId ? this.accountApiService.getAssetsState(accountId, params) : of(null), this.quoteApiService.getQuoteState(headerId, params)).pipe(tap(([assets, quote]) => {
|
324
|
+
if (assets) {
|
325
|
+
this.assetsSubj$.next(assets);
|
326
|
+
}
|
222
327
|
this.quoteSubj$.next(quote);
|
223
328
|
this.context.update(quote.context);
|
224
|
-
this.populateActivePriceLists$();
|
225
329
|
}), map(() => noop()), take(1));
|
226
330
|
}
|
331
|
+
finalizeInit() {
|
332
|
+
this.isInitialized = true;
|
333
|
+
this.hasUnsavedChanges = false;
|
334
|
+
}
|
227
335
|
setCurrentLineItemState(lineItems) {
|
228
336
|
const quoteDraft = this.quoteSubj$.value;
|
229
337
|
if (!quoteDraft) {
|
@@ -252,6 +360,9 @@ class QuoteDraftService {
|
|
252
360
|
});
|
253
361
|
this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
|
254
362
|
}
|
363
|
+
setAssetsState(assetsState) {
|
364
|
+
this.assetsSubj$.next(assetsState);
|
365
|
+
}
|
255
366
|
get quoteDraft$() {
|
256
367
|
return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
|
257
368
|
}
|
@@ -262,13 +373,6 @@ class QuoteDraftService {
|
|
262
373
|
}
|
263
374
|
return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
|
264
375
|
}
|
265
|
-
get quoteDraftForActivePriceList() {
|
266
|
-
const quoteDraft = this.quoteDraft;
|
267
|
-
if (!quoteDraft) {
|
268
|
-
return null;
|
269
|
-
}
|
270
|
-
return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
|
271
|
-
}
|
272
376
|
get currentState$() {
|
273
377
|
return this.quoteDraft$.pipe(map(quote => quote.currentState));
|
274
378
|
}
|
@@ -276,39 +380,6 @@ class QuoteDraftService {
|
|
276
380
|
var _a, _b;
|
277
381
|
return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
|
278
382
|
}
|
279
|
-
/**
|
280
|
-
* Stream of activeCurrentState
|
281
|
-
*/
|
282
|
-
get activeCurrentState$() {
|
283
|
-
return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
|
284
|
-
}
|
285
|
-
/**
|
286
|
-
* activeCurrentState is currentState passed through additional filters
|
287
|
-
*/
|
288
|
-
get activeCurrentState() {
|
289
|
-
var _a, _b;
|
290
|
-
let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
|
291
|
-
currentState = this.filterByActivePriceList(currentState);
|
292
|
-
return currentState;
|
293
|
-
}
|
294
|
-
/**
|
295
|
-
* Stream of activeInitialState
|
296
|
-
*/
|
297
|
-
get activeInitialState$() {
|
298
|
-
return this.quoteDraft$.pipe(map(() => this.activeInitialState));
|
299
|
-
}
|
300
|
-
/**
|
301
|
-
* activeInitialState is initialState passed through additional filters
|
302
|
-
*/
|
303
|
-
get activeInitialState() {
|
304
|
-
var _a, _b;
|
305
|
-
const ctx = this.context.resolve();
|
306
|
-
let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
|
307
|
-
if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
|
308
|
-
initialState = this.filterByActivePriceList(initialState);
|
309
|
-
}
|
310
|
-
return initialState;
|
311
|
-
}
|
312
383
|
get isStandalone() {
|
313
384
|
return this.context.resolve().properties.standalone === 'true';
|
314
385
|
}
|
@@ -331,51 +402,535 @@ class QuoteDraftService {
|
|
331
402
|
}
|
332
403
|
return false;
|
333
404
|
}
|
334
|
-
|
335
|
-
|
405
|
+
markAsUpdated(quote) {
|
406
|
+
if ((quote === null || quote === void 0 ? void 0 : quote.context.properties['#mode']) === ConfigurationContextMode.ACCOUNT) {
|
407
|
+
this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
|
408
|
+
}
|
409
|
+
else {
|
410
|
+
this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
|
411
|
+
}
|
336
412
|
}
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
413
|
+
}
|
414
|
+
QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.AccountApiService }, { token: i1.QuoteApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
415
|
+
QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService });
|
416
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, decorators: [{
|
417
|
+
type: Injectable
|
418
|
+
}], ctorParameters: function () { return [{ type: ContextService }, { type: i1.AccountApiService }, { type: i1.QuoteApiService }]; } });
|
419
|
+
|
420
|
+
class FlowStateService {
|
421
|
+
constructor(contextService, quoteDraftService, flowInfoService, flowConfiguration, processorsApiService, flowStateApiService, quoteApiService, toastService, customizationService) {
|
422
|
+
this.contextService = contextService;
|
423
|
+
this.quoteDraftService = quoteDraftService;
|
424
|
+
this.flowInfoService = flowInfoService;
|
425
|
+
this.flowConfiguration = flowConfiguration;
|
426
|
+
this.processorsApiService = processorsApiService;
|
427
|
+
this.flowStateApiService = flowStateApiService;
|
428
|
+
this.quoteApiService = quoteApiService;
|
429
|
+
this.toastService = toastService;
|
430
|
+
this.customizationService = customizationService;
|
431
|
+
this.NOT_INITIALIZED = Symbol();
|
432
|
+
this.EXECUTION_BUFFER_TIME = 100;
|
433
|
+
this.executedFunctions = {};
|
434
|
+
this.stateId$ = new BehaviorSubject(null);
|
435
|
+
this._hasStatefulUnsavedChanges = true;
|
436
|
+
this.processors = {};
|
437
|
+
this.subscriptions = {};
|
438
|
+
this.flowStore = {};
|
439
|
+
this.statefulExecutionInProgress$ = new BehaviorSubject(false);
|
440
|
+
this.statefulRequestStream$ = new Subject();
|
441
|
+
this.cleanup$ = new Subject();
|
442
|
+
this.statefulExecutionRequest$ = this.initBufferedRequest$();
|
443
|
+
/*
|
444
|
+
In stateless mode watch QuoteDraft changes and call executeRequest so that
|
445
|
+
all subscriptions get their updates according to updated QuoteDraft
|
446
|
+
*/
|
447
|
+
this.isInitialized$()
|
448
|
+
.pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.flowConfiguration.updated$), switchMap(() => this.executeRequest$({}, true)))
|
449
|
+
.subscribe();
|
450
|
+
this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
|
451
|
+
if (this.flowInfoService.isLegacy) {
|
452
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.charges));
|
453
|
+
}
|
454
|
+
else {
|
455
|
+
return this.subscribe$(UITemplateType.FLOW_ENGINE, 'CHARGES', null, {
|
456
|
+
cold: true,
|
457
|
+
}).pipe(map$1(response => (response.success ? response.result : {})));
|
458
|
+
}
|
459
|
+
}), shareReplay$1(1));
|
460
|
+
this.charges$.subscribe();
|
461
|
+
this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
|
462
|
+
if (this.flowInfoService.isLegacy) {
|
463
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.pricePlans));
|
464
|
+
}
|
465
|
+
else {
|
466
|
+
return this.subscribe$(UITemplateType.FLOW_ENGINE, 'PRICE_PLANS', null, {
|
467
|
+
cold: true,
|
468
|
+
}).pipe(map$1(response => (response.success ? response.result : {})));
|
469
|
+
}
|
470
|
+
}), shareReplay$1(1));
|
471
|
+
this.pricePlans$.subscribe();
|
472
|
+
this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
|
473
|
+
if (this.flowInfoService.isLegacy) {
|
474
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.activeMetrics));
|
475
|
+
}
|
476
|
+
else {
|
477
|
+
return this.subscribe$(UITemplateType.FLOW_ENGINE, 'ACTIVE_METRICS', null, {
|
478
|
+
cold: true,
|
479
|
+
}).pipe(map$1(response => (response.success ? response.result : [])));
|
480
|
+
}
|
481
|
+
}), shareReplay$1(1));
|
482
|
+
this.activeMetrics$.subscribe();
|
483
|
+
this.isPriceListLocked$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
|
484
|
+
if (this.flowInfoService.isLegacy) {
|
485
|
+
return of(false);
|
486
|
+
}
|
487
|
+
else {
|
488
|
+
return this.subscribe$(UITemplateType.FLOW_ENGINE, 'IS_PRICE_LIST_LOCKED', null, {
|
489
|
+
cold: true,
|
490
|
+
}).pipe(map$1(response => (response.success ? response.result : false)));
|
491
|
+
}
|
492
|
+
}), shareReplay$1(1));
|
493
|
+
this.isPriceListLocked$.subscribe();
|
494
|
+
}
|
495
|
+
init$() {
|
496
|
+
return this.initProcessors$().pipe(switchMap(() => {
|
497
|
+
if (this.getFlowSafe().properties.stateful) {
|
498
|
+
return this.initStateful$();
|
499
|
+
}
|
500
|
+
else {
|
501
|
+
return this.initStateless$();
|
502
|
+
}
|
503
|
+
}));
|
504
|
+
}
|
505
|
+
cleanup() {
|
506
|
+
Object.values(this.subscriptions).forEach(({ data$ }) => data$.complete());
|
507
|
+
this.subscriptions = {};
|
508
|
+
if (this.stateId$.value) {
|
509
|
+
this.flowStateApiService.cancel(this.stateId$.value).subscribe();
|
510
|
+
this.stateId$.next(null);
|
342
511
|
}
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
512
|
+
this.processors = {};
|
513
|
+
this.flowStore = {};
|
514
|
+
this.cleanup$.next();
|
515
|
+
}
|
516
|
+
get hasUnsavedChanges() {
|
517
|
+
return this.getFlowSafe().properties.stateful
|
518
|
+
? this._hasStatefulUnsavedChanges
|
519
|
+
: this.quoteDraftService.hasUnsavedChanges;
|
520
|
+
}
|
521
|
+
get stateId() {
|
522
|
+
return this.stateId$.value;
|
523
|
+
}
|
524
|
+
get isExecutionInProgress$() {
|
525
|
+
return this.statefulExecutionInProgress$.asObservable();
|
526
|
+
}
|
527
|
+
isInitialized$() {
|
528
|
+
return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
|
529
|
+
}
|
530
|
+
isInitialized() {
|
531
|
+
return Boolean(this.stateId$.value) || this.quoteDraftService.isInitialized;
|
532
|
+
}
|
533
|
+
execute$(scope, exec) {
|
534
|
+
const request = this.execToRequest(scope, exec);
|
535
|
+
return this.executeRequest$(request).pipe(map$1(result => {
|
536
|
+
// Keep only requested results
|
537
|
+
const actualSelectors = Object.entries(result.selectors).reduce((trunk, [requestId, result]) => {
|
538
|
+
var _a;
|
539
|
+
if ((_a = exec.selectors) === null || _a === void 0 ? void 0 : _a[requestId]) {
|
540
|
+
trunk[requestId] = result;
|
352
541
|
}
|
353
|
-
return
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
542
|
+
return trunk;
|
543
|
+
}, {});
|
544
|
+
return actualSelectors;
|
545
|
+
}));
|
546
|
+
}
|
547
|
+
dispatch$(scope, action, inputData) {
|
548
|
+
const exec = {
|
549
|
+
actions: [{ name: action, inputData }],
|
550
|
+
};
|
551
|
+
const request = this.execToRequest(scope, exec);
|
552
|
+
return this.executeRequest$(request).pipe(map$1(noop));
|
553
|
+
}
|
554
|
+
select$(scope, selectorName, inputData) {
|
555
|
+
const requestId = this.generateRequestId(scope, selectorName, inputData);
|
556
|
+
const request = this.execToRequest(scope, {
|
557
|
+
selectors: {
|
558
|
+
[requestId]: {
|
559
|
+
name: selectorName,
|
560
|
+
inputData,
|
561
|
+
},
|
562
|
+
},
|
563
|
+
});
|
564
|
+
return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
|
565
|
+
}
|
566
|
+
subscribe$(scope, selectorName, inputData, options) {
|
567
|
+
const requestId = this.generateRequestId(scope, selectorName, inputData);
|
568
|
+
let subscription = this.subscriptions[requestId];
|
569
|
+
if (!subscription) {
|
570
|
+
const request = this.execToRequest(scope, {
|
571
|
+
selectors: {
|
572
|
+
[requestId]: {
|
573
|
+
name: selectorName,
|
574
|
+
inputData,
|
575
|
+
},
|
576
|
+
},
|
577
|
+
});
|
578
|
+
subscription = {
|
579
|
+
request,
|
580
|
+
data$: new BehaviorSubject(this.NOT_INITIALIZED),
|
581
|
+
};
|
582
|
+
this.subscriptions[requestId] = subscription;
|
583
|
+
if (!(options === null || options === void 0 ? void 0 : options.cold)) {
|
584
|
+
this.executeRequest$(request).subscribe();
|
585
|
+
}
|
358
586
|
}
|
587
|
+
return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
|
588
|
+
var _a;
|
589
|
+
if (!((_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$.observed)) {
|
590
|
+
delete this.subscriptions[requestId];
|
591
|
+
}
|
592
|
+
}));
|
359
593
|
}
|
360
|
-
|
361
|
-
|
362
|
-
|
594
|
+
save$() {
|
595
|
+
if (this.getFlowSafe().properties.stateful) {
|
596
|
+
if (this.stateId$.value) {
|
597
|
+
return this.flowStateApiService.save(this.stateId$.value);
|
598
|
+
}
|
599
|
+
}
|
600
|
+
else {
|
601
|
+
const quoteDraft = this.quoteDraftService.quoteDraft;
|
602
|
+
if (quoteDraft) {
|
603
|
+
return this.quoteApiService.upsertQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
|
604
|
+
this.contextService.update({ properties: { ConfigurationId: configurationId } });
|
605
|
+
}));
|
606
|
+
}
|
607
|
+
}
|
608
|
+
return of({ quoteId: '' });
|
363
609
|
}
|
364
|
-
|
365
|
-
if ((
|
366
|
-
|
610
|
+
submit$() {
|
611
|
+
if (this.getFlowSafe().properties.stateful) {
|
612
|
+
if (this.stateId$.value) {
|
613
|
+
return this.flowStateApiService.submit(this.stateId$.value);
|
614
|
+
}
|
367
615
|
}
|
368
616
|
else {
|
369
|
-
|
617
|
+
const quoteDraft = this.quoteDraftService.quoteDraft;
|
618
|
+
if (quoteDraft) {
|
619
|
+
return this.quoteApiService.submitQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
|
620
|
+
this.contextService.update({ properties: { ConfigurationId: configurationId } });
|
621
|
+
}));
|
622
|
+
}
|
623
|
+
}
|
624
|
+
return of({ quoteId: '' });
|
625
|
+
}
|
626
|
+
getFlowStore() {
|
627
|
+
return this.flowStore;
|
628
|
+
}
|
629
|
+
getOwnerIdByScope(scope) {
|
630
|
+
var _a;
|
631
|
+
const ownerId = (_a = this.flowInfoService.templates[scope]) === null || _a === void 0 ? void 0 : _a.id;
|
632
|
+
if (!ownerId) {
|
633
|
+
throw `OwnerId is not found for scope ${scope}`;
|
634
|
+
}
|
635
|
+
return ownerId;
|
636
|
+
}
|
637
|
+
getScopeByOwnerId(id) {
|
638
|
+
for (const template of Object.values(this.flowInfoService.templates)) {
|
639
|
+
if (template.id === id) {
|
640
|
+
return template.type;
|
641
|
+
}
|
642
|
+
}
|
643
|
+
return;
|
644
|
+
}
|
645
|
+
execToRequest(scope, exec) {
|
646
|
+
var _a;
|
647
|
+
const ownerId = this.getOwnerIdByScope(scope);
|
648
|
+
return {
|
649
|
+
actions: (_a = exec.actions) === null || _a === void 0 ? void 0 : _a.map(action => { var _a; return ({ apiName: action.name, ownerId, inputData: (_a = action.inputData) !== null && _a !== void 0 ? _a : {} }); }),
|
650
|
+
selectors: exec.selectors &&
|
651
|
+
Object.entries(exec.selectors).reduce((trunk, [key, selector]) => {
|
652
|
+
var _a;
|
653
|
+
return (Object.assign(Object.assign({}, trunk), { [key]: { apiName: selector.name, ownerId, inputData: (_a = selector.inputData) !== null && _a !== void 0 ? _a : {} } }));
|
654
|
+
}, {}),
|
655
|
+
};
|
656
|
+
}
|
657
|
+
executeRequest$(request, forceSubscriptions = false) {
|
658
|
+
var _a;
|
659
|
+
const fullRequest = cloneDeep(request);
|
660
|
+
if (((_a = fullRequest.actions) === null || _a === void 0 ? void 0 : _a.length) || forceSubscriptions) {
|
661
|
+
for (const subscription of Object.values(this.subscriptions)) {
|
662
|
+
fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
|
663
|
+
}
|
664
|
+
}
|
665
|
+
const execution$ = this.getFlowSafe().properties.stateful
|
666
|
+
? this.executeStateful$(fullRequest)
|
667
|
+
: this.executeStateless$(fullRequest);
|
668
|
+
return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
|
669
|
+
}
|
670
|
+
handleSelectorsResponse(selectors) {
|
671
|
+
Object.entries(selectors).forEach(([requestId, selectorResult]) => {
|
672
|
+
var _a;
|
673
|
+
if (!selectorResult.success) {
|
674
|
+
this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
|
675
|
+
}
|
676
|
+
const subscription$ = (_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$;
|
677
|
+
if (subscription$ && subscription$.value !== selectorResult) {
|
678
|
+
subscription$.next(selectorResult);
|
679
|
+
}
|
680
|
+
});
|
681
|
+
}
|
682
|
+
initStateful$() {
|
683
|
+
var _a;
|
684
|
+
// Subscriptions
|
685
|
+
this.subscribe$(UITemplateType.FLOW_ENGINE, 'CONTEXT', null, { cold: true })
|
686
|
+
.pipe(tap$1(response => {
|
687
|
+
if (response.success) {
|
688
|
+
this.contextService.update(response.result);
|
689
|
+
}
|
690
|
+
}), takeUntil(this.cleanup$))
|
691
|
+
.subscribe();
|
692
|
+
const processorsList = flatten(Object.values(this.processors).map(ownerMap => Object.values(ownerMap !== null && ownerMap !== void 0 ? ownerMap : {})));
|
693
|
+
const processors = processorsList.length ? processorsList : undefined;
|
694
|
+
const selectors = Object.values(this.subscriptions)
|
695
|
+
.map(({ request }) => request.selectors)
|
696
|
+
.filter(isDefined)
|
697
|
+
.reduce((trunk, selectors) => (Object.assign(Object.assign({}, trunk), selectors)), {});
|
698
|
+
const request = this.getDefaultExecutionRequestDTO();
|
699
|
+
return this.flowStateApiService
|
700
|
+
.init({
|
701
|
+
quoteId: this.contextService.resolve().headerId,
|
702
|
+
params: (_a = this.flowInfoService.params) !== null && _a !== void 0 ? _a : {},
|
703
|
+
actionsOverride: processors === null || processors === void 0 ? void 0 : processors.filter(processor => processor.type === ConfigurationProcessorTypes.ACTION),
|
704
|
+
selectorsOverride: processors === null || processors === void 0 ? void 0 : processors.filter(processor => processor.type === ConfigurationProcessorTypes.SELECTOR),
|
705
|
+
selectors: Object.assign(Object.assign({}, selectors), request.selectors),
|
706
|
+
actions: request.actions,
|
707
|
+
})
|
708
|
+
.pipe(map$1(({ stateId, selectors }) => {
|
709
|
+
this.handleSelectorsResponse(selectors);
|
710
|
+
this.stateId$.next(stateId);
|
711
|
+
}));
|
712
|
+
}
|
713
|
+
initBufferedRequest$() {
|
714
|
+
return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap(requests => {
|
715
|
+
if (!this.stateId$.value) {
|
716
|
+
throw 'Stateful session is not initialized';
|
717
|
+
}
|
718
|
+
// merge buffered requests
|
719
|
+
const request = {
|
720
|
+
actions: requests.flatMap(({ actions }) => actions).filter(isDefined),
|
721
|
+
selectors: requests
|
722
|
+
.map(({ selectors }) => selectors)
|
723
|
+
.filter(isDefined)
|
724
|
+
.reduce((acc, selectorsMap) => Object.assign(acc, selectorsMap), {}),
|
725
|
+
};
|
726
|
+
this.statefulExecutionInProgress$.next(true);
|
727
|
+
return this.flowStateApiService.execute(this.stateId$.value, request);
|
728
|
+
}), tap$1(({ stateId }) => this.stateId$.next(stateId)), share(), tap$1(() => this.statefulExecutionInProgress$.next(false)), catchError(e => {
|
729
|
+
this.statefulExecutionInProgress$.next(false);
|
730
|
+
return throwError(() => e);
|
731
|
+
}));
|
732
|
+
}
|
733
|
+
executeStateful$(request) {
|
734
|
+
return this.statefulExecutionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
|
735
|
+
// make sure stream switches to statefulExecutionRequest$ before pushing an execution request
|
736
|
+
combineLatest([
|
737
|
+
this.statefulExecutionRequest$,
|
738
|
+
of(undefined).pipe(tap$1(() => this.statefulRequestStream$.next(request))),
|
739
|
+
])), map$1(([response]) => response), take$1(1));
|
740
|
+
}
|
741
|
+
initStateless$() {
|
742
|
+
var _a;
|
743
|
+
const { headerId } = this.contextService.resolve();
|
744
|
+
return this.quoteDraftService.init(headerId, (_a = this.flowInfoService.params) !== null && _a !== void 0 ? _a : {}).pipe(tap$1(() => {
|
745
|
+
const assets = this.quoteDraftService.assetsState;
|
746
|
+
if (assets) {
|
747
|
+
this.flowStore = Object.assign(Object.assign({}, this.flowStore), { assets });
|
748
|
+
}
|
749
|
+
}), switchMap(() => this.executeRequest$(this.getDefaultExecutionRequestDTO())), switchMap(() => this.calculate$()), tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
|
750
|
+
}
|
751
|
+
calculate$() {
|
752
|
+
var _a;
|
753
|
+
const flowState = this.quoteDraftService.quoteDraft;
|
754
|
+
if (!flowState) {
|
755
|
+
return of(undefined);
|
756
|
+
}
|
757
|
+
/*
|
758
|
+
Don't execute procedures when:
|
759
|
+
* Initializing a standalone product configuration UI, as procedure is execute in /price call
|
760
|
+
* Initializing an empty account (account with no assets)
|
761
|
+
*/
|
762
|
+
const isEmptyAccountMode = this.contextService.mode === ConfigurationContextMode.ACCOUNT &&
|
763
|
+
!this.quoteDraftService.hasProducts &&
|
764
|
+
!this.quoteDraftService.hasAssets &&
|
765
|
+
!((_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState.length);
|
766
|
+
if (this.quoteDraftService.isStandalone || isEmptyAccountMode) {
|
767
|
+
return of(undefined);
|
768
|
+
}
|
769
|
+
return this.flowConfiguration.calculate$(flowState);
|
770
|
+
}
|
771
|
+
executeStateless$(request) {
|
772
|
+
return of(undefined).pipe(tap$1(() => this.executeStatelessActions(request)), switchMap(() => {
|
773
|
+
var _a;
|
774
|
+
/*
|
775
|
+
Skip price calculation in case
|
776
|
+
1. No actions in the request
|
777
|
+
2. Initialization process execution (state not initialized yet)
|
778
|
+
*/
|
779
|
+
if (!((_a = request.actions) === null || _a === void 0 ? void 0 : _a.length) || !this.isInitialized()) {
|
780
|
+
return of(undefined);
|
781
|
+
}
|
782
|
+
else {
|
783
|
+
return this.calculate$();
|
784
|
+
}
|
785
|
+
}), map$1(() => this.executeStatelessSelectors(request)));
|
786
|
+
}
|
787
|
+
executeStatelessActions(request) {
|
788
|
+
var _a;
|
789
|
+
if (!this.quoteDraftService.quoteDraft || !((_a = request.actions) === null || _a === void 0 ? void 0 : _a.length)) {
|
790
|
+
return;
|
791
|
+
}
|
792
|
+
let flowState = this.quoteDraftService.quoteDraft;
|
793
|
+
request.actions.forEach(action => {
|
794
|
+
var _a;
|
795
|
+
try {
|
796
|
+
flowState = (_a = this.executeActionScript(flowState, action)) !== null && _a !== void 0 ? _a : flowState;
|
797
|
+
}
|
798
|
+
catch (e) {
|
799
|
+
console.error(e);
|
800
|
+
this.toastService.add({ severity: ToastType.error, summary: String(e) });
|
801
|
+
throw e;
|
802
|
+
}
|
803
|
+
});
|
804
|
+
this.quoteDraftService.updateQuoteDraft(flowState);
|
805
|
+
}
|
806
|
+
executeStatelessSelectors(request) {
|
807
|
+
var _a;
|
808
|
+
if (!this.quoteDraftService.quoteDraft) {
|
809
|
+
throw 'QuoteDraft is not initialized';
|
810
|
+
}
|
811
|
+
const flowState = this.quoteDraftService.quoteDraft;
|
812
|
+
return EntityUtil.entries((_a = request.selectors) !== null && _a !== void 0 ? _a : {}).reduce((result, [key, selector]) => {
|
813
|
+
try {
|
814
|
+
result.selectors[key] = {
|
815
|
+
success: true,
|
816
|
+
result: this.executeSelectorScript(flowState, selector),
|
817
|
+
};
|
818
|
+
}
|
819
|
+
catch (e) {
|
820
|
+
console.error(e);
|
821
|
+
result.selectors[key] = {
|
822
|
+
success: false,
|
823
|
+
errorMessage: String(e),
|
824
|
+
};
|
825
|
+
}
|
826
|
+
return result;
|
827
|
+
}, { stateId: '', selectors: {} });
|
828
|
+
}
|
829
|
+
getFlowSafe() {
|
830
|
+
if (!this.flowInfoService.flow) {
|
831
|
+
throw 'Flow is not defined';
|
832
|
+
}
|
833
|
+
return this.flowInfoService.flow;
|
834
|
+
}
|
835
|
+
initProcessors$() {
|
836
|
+
var _a;
|
837
|
+
const hasOverrides = Boolean((_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getTemplateConfigurationProcessors);
|
838
|
+
const flow = this.getFlowSafe();
|
839
|
+
if (flow.properties.stateful && !hasOverrides) {
|
840
|
+
// Skip initialization as backend will take processors from SF
|
841
|
+
return of(undefined);
|
842
|
+
}
|
843
|
+
const owners$ = Object.values(this.flowInfoService.templates)
|
844
|
+
.map(template => {
|
845
|
+
var _a, _b, _c;
|
846
|
+
if (!template) {
|
847
|
+
return;
|
848
|
+
}
|
849
|
+
const localProcessors$ = (_c = (_b = (_a = this.customizationService) === null || _a === void 0 ? void 0 : _a.getTemplateConfigurationProcessors) === null || _b === void 0 ? void 0 : _b.call(_a, template.name)) !== null && _c !== void 0 ? _c : of(null);
|
850
|
+
return localProcessors$.pipe(switchMap(processors => processors ? of(processors) : this.processorsApiService.fetchConfigurationProcessors$(template.id)), tap$1(processors => {
|
851
|
+
const processorsMap = processors.reduce((acc, p) => {
|
852
|
+
acc[p.apiName] = p;
|
853
|
+
return acc;
|
854
|
+
}, {});
|
855
|
+
this.processors[template.id] = processorsMap;
|
856
|
+
}));
|
857
|
+
})
|
858
|
+
.filter(isDefined);
|
859
|
+
if (!owners$.length) {
|
860
|
+
return of(undefined);
|
861
|
+
}
|
862
|
+
return forkJoin(owners$).pipe(map$1(noop));
|
863
|
+
}
|
864
|
+
executeActionScript(request, executable) {
|
865
|
+
var _a;
|
866
|
+
const configurationProcessor = (_a = this.processors[executable.ownerId]) === null || _a === void 0 ? void 0 : _a[executable.apiName];
|
867
|
+
if (!(configurationProcessor === null || configurationProcessor === void 0 ? void 0 : configurationProcessor.script)) {
|
868
|
+
const scope = this.getScopeByOwnerId(executable.ownerId);
|
869
|
+
const scopeText = scope ? ` in ${scope}` : '';
|
870
|
+
throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
|
370
871
|
}
|
872
|
+
return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
|
873
|
+
}
|
874
|
+
executeSelectorScript(request, executable) {
|
875
|
+
var _a;
|
876
|
+
const configurationProcessor = (_a = this.processors[executable.ownerId]) === null || _a === void 0 ? void 0 : _a[executable.apiName];
|
877
|
+
if (!(configurationProcessor === null || configurationProcessor === void 0 ? void 0 : configurationProcessor.script)) {
|
878
|
+
const scope = this.getScopeByOwnerId(executable.ownerId);
|
879
|
+
const scopeText = scope ? ` in ${scope}` : '';
|
880
|
+
throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
|
881
|
+
}
|
882
|
+
return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
|
883
|
+
}
|
884
|
+
executeProcessorScript(request, configurationProcessor, inputData) {
|
885
|
+
var _a;
|
886
|
+
const scope = this.getScopeByOwnerId((_a = configurationProcessor.ownerId) !== null && _a !== void 0 ? _a : '');
|
887
|
+
let functionToExecute = this.executedFunctions[scope + configurationProcessor.apiName];
|
888
|
+
if (!functionToExecute) {
|
889
|
+
const script = `${configurationProcessor.script}\nreturn transform;`;
|
890
|
+
const sourceMap = `\n//# sourceURL=${scope ? scope + '/' : ''}${configurationProcessor.apiName}.js`;
|
891
|
+
functionToExecute = new Function(script + sourceMap)();
|
892
|
+
this.executedFunctions[scope + configurationProcessor.apiName] = functionToExecute;
|
893
|
+
}
|
894
|
+
return functionToExecute({
|
895
|
+
request,
|
896
|
+
inputData,
|
897
|
+
flowStore: this.flowStore,
|
898
|
+
});
|
899
|
+
}
|
900
|
+
generateRequestId(scope, selectorName, inputData) {
|
901
|
+
const inputDataHash = UUID.hex(JSON.stringify(inputData) || '').slice(0, 8);
|
902
|
+
return `${scope}/${selectorName}/${inputDataHash}`;
|
903
|
+
}
|
904
|
+
getDefaultExecutionRequestDTO() {
|
905
|
+
var _a;
|
906
|
+
const request = {
|
907
|
+
actions: [],
|
908
|
+
selectors: {},
|
909
|
+
};
|
910
|
+
if (this.getFlowSafe().properties.standalone) {
|
911
|
+
return request;
|
912
|
+
}
|
913
|
+
const flowEngineTemplateId = this.getOwnerIdByScope(UITemplateType.FLOW_ENGINE);
|
914
|
+
(_a = request.actions) === null || _a === void 0 ? void 0 : _a.push({
|
915
|
+
apiName: 'UPDATE_CONTEXT_PROPERTIES',
|
916
|
+
ownerId: flowEngineTemplateId,
|
917
|
+
inputData: this.contextService.resolve().properties,
|
918
|
+
});
|
919
|
+
return request;
|
371
920
|
}
|
372
921
|
}
|
373
|
-
|
374
|
-
|
375
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type:
|
376
|
-
type: Injectable
|
377
|
-
|
378
|
-
}
|
922
|
+
FlowStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, deps: [{ token: ContextService }, { token: QuoteDraftService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.ConfigurationProcessorsApiService }, { token: i1.FlowStateApiService }, { token: i1.QuoteApiService }, { token: i6.ToastService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
923
|
+
FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService });
|
924
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, decorators: [{
|
925
|
+
type: Injectable
|
926
|
+
}], ctorParameters: function () {
|
927
|
+
return [{ type: ContextService }, { type: QuoteDraftService }, { type: FlowInfoService }, { type: FlowConfigurationService }, { type: i1.ConfigurationProcessorsApiService }, { type: i1.FlowStateApiService }, { type: i1.QuoteApiService }, { type: i6.ToastService }, { type: undefined, decorators: [{
|
928
|
+
type: Optional
|
929
|
+
}, {
|
930
|
+
type: Inject,
|
931
|
+
args: [FLOW_CUSTOMIZATION]
|
932
|
+
}] }];
|
933
|
+
} });
|
379
934
|
|
380
935
|
const findLineItem = (id, lineItems) => {
|
381
936
|
return findLineItemWithComparator(lineItems, (li) => li.id === id);
|
@@ -424,28 +979,45 @@ const replaceLineItem = (lineItem, replaceTo, skipCardinalityCalculation = false
|
|
424
979
|
}
|
425
980
|
return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo, skipCardinalityCalculation)) });
|
426
981
|
};
|
427
|
-
const
|
982
|
+
const collectCardinalityComputations = (portDomains) => {
|
983
|
+
const cardinalityComputations = new Map();
|
984
|
+
entries(portDomains).forEach(([key, portDomain]) => {
|
985
|
+
cardinalityComputations.set(key, portDomain.properties['cardinalityComputation'] === 'true');
|
986
|
+
});
|
987
|
+
return cardinalityComputations;
|
988
|
+
};
|
989
|
+
const calculateCardinalityVariables = (lineItems, cardinalityComputations) => {
|
428
990
|
const cardVars = new Map();
|
429
991
|
lineItems
|
430
992
|
.filter(({ port, type }) => !!port && !!type)
|
431
993
|
.forEach(li => {
|
432
994
|
var _a;
|
433
|
-
|
434
|
-
|
995
|
+
if (cardinalityComputations.get(`${li.port}`)) {
|
996
|
+
const cardinalityVariableName = `#CV-${li.type}@${li.port}`;
|
997
|
+
cardVars.set(cardinalityVariableName, ((_a = cardVars.get(cardinalityVariableName)) !== null && _a !== void 0 ? _a : 0) + li.qty);
|
998
|
+
}
|
435
999
|
});
|
436
1000
|
return cardVars;
|
437
1001
|
};
|
1002
|
+
const cardinalityRegexp = new RegExp('#CV-[a-zA-Z0-9_]+@(?<portName>[a-zA-Z0-9_]+)');
|
438
1003
|
const recalculateCardinalityVariables = (original, updated) => {
|
439
|
-
|
440
|
-
const
|
1004
|
+
var _a, _b;
|
1005
|
+
const cardinalityComputations = collectCardinalityComputations((_b = (_a = updated.portDomains) !== null && _a !== void 0 ? _a : original.portDomains) !== null && _b !== void 0 ? _b : {});
|
1006
|
+
const cardinalityVariables = calculateCardinalityVariables(updated.lineItems, cardinalityComputations);
|
1007
|
+
const originalCardinalityVariables = calculateCardinalityVariables(original.lineItems, cardinalityComputations);
|
441
1008
|
originalCardinalityVariables.forEach((value, key) => {
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
1009
|
+
var _a;
|
1010
|
+
const execArray = cardinalityRegexp.exec(key);
|
1011
|
+
const portName = (_a = execArray === null || execArray === void 0 ? void 0 : execArray.groups) === null || _a === void 0 ? void 0 : _a['portName'];
|
1012
|
+
if (!portName || cardinalityComputations.get(portName)) {
|
1013
|
+
if (cardinalityVariables.get(key) === value) {
|
1014
|
+
// no need to update cardinality if no changes
|
1015
|
+
cardinalityVariables.delete(key);
|
1016
|
+
}
|
1017
|
+
else if (!cardinalityVariables.has(key)) {
|
1018
|
+
// remove last item from port
|
1019
|
+
cardinalityVariables.set(key, 0);
|
1020
|
+
}
|
449
1021
|
}
|
450
1022
|
});
|
451
1023
|
return Object.assign(Object.assign({}, updated), { attributes: upsertAttributes(updated.attributes, [...cardinalityVariables].map(([name, value]) => ({ name, value, cfgStatus: 'Changed' }))) });
|
@@ -462,7 +1034,7 @@ const upsertAttributes = (originalAttributes, attributesToUpsert) => {
|
|
462
1034
|
const [origAttr] = getAttributes(acc, [name]);
|
463
1035
|
return [
|
464
1036
|
...acc.filter(attr => attr.name !== name),
|
465
|
-
Object.assign(Object.assign({}, (origAttr !== null && origAttr !== void 0 ? origAttr : { name })), { cfgStatus: origAttr ? 'Changed' : 'User', value }),
|
1037
|
+
Object.assign(Object.assign({}, (origAttr !== null && origAttr !== void 0 ? origAttr : { name, type: '' })), { cfgStatus: origAttr ? 'Changed' : 'User', value }),
|
466
1038
|
];
|
467
1039
|
}, originalAttributes);
|
468
1040
|
};
|
@@ -497,21 +1069,6 @@ const getRecommendedPrices = (portDomain, type) => {
|
|
497
1069
|
}, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
|
498
1070
|
return { net, list };
|
499
1071
|
};
|
500
|
-
const generateModifiedAssetsMap = (lineItems) => {
|
501
|
-
return lineItems.reduce((acc, li) => {
|
502
|
-
var _a;
|
503
|
-
const isModified = isLineItemModified(li);
|
504
|
-
if (!isModified) {
|
505
|
-
return acc;
|
506
|
-
}
|
507
|
-
const target = getOriginParent(lineItems, li);
|
508
|
-
const id = (_a = target === null || target === void 0 ? void 0 : target.assetId) !== null && _a !== void 0 ? _a : target === null || target === void 0 ? void 0 : target.openOrderLineItemId;
|
509
|
-
if (id) {
|
510
|
-
acc[id] = true;
|
511
|
-
}
|
512
|
-
return acc;
|
513
|
-
}, {});
|
514
|
-
};
|
515
1072
|
const getOriginParent = (lineItems, currentLineItem) => {
|
516
1073
|
let target = currentLineItem;
|
517
1074
|
while (target && target.rampInstanceId) {
|
@@ -519,16 +1076,16 @@ const getOriginParent = (lineItems, currentLineItem) => {
|
|
519
1076
|
}
|
520
1077
|
return target;
|
521
1078
|
};
|
522
|
-
const
|
523
|
-
if (
|
1079
|
+
const assetPredicateFn = (lineItem, assetId) => {
|
1080
|
+
if (!assetId) {
|
524
1081
|
return false;
|
525
1082
|
}
|
526
|
-
return lineItem.
|
1083
|
+
return lineItem.assetId === assetId || lineItem.openOrderLineItemId === assetId;
|
527
1084
|
};
|
528
1085
|
const multiplyLineItems = (lineItem, qty, split) => {
|
529
1086
|
if (split) {
|
530
1087
|
const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
|
531
|
-
return map$
|
1088
|
+
return map$2(new Array(qty), () => unifyIds(lineItem));
|
532
1089
|
}
|
533
1090
|
else {
|
534
1091
|
return [
|
@@ -545,18 +1102,16 @@ const filterOutTechnicalAttributes = (attributes) => {
|
|
545
1102
|
|
546
1103
|
var lineItem_utils = /*#__PURE__*/Object.freeze({
|
547
1104
|
__proto__: null,
|
548
|
-
|
1105
|
+
assetPredicateFn: assetPredicateFn,
|
549
1106
|
filterOutTechnicalAttributes: filterOutTechnicalAttributes,
|
550
1107
|
findLineItem: findLineItem,
|
551
1108
|
findLineItemWithComparator: findLineItemWithComparator,
|
552
1109
|
generateLineItem: generateLineItem,
|
553
|
-
generateModifiedAssetsMap: generateModifiedAssetsMap,
|
554
1110
|
getAttributeValue: getAttributeValue,
|
555
1111
|
getAttributes: getAttributes,
|
556
1112
|
getOriginParent: getOriginParent,
|
557
1113
|
getRecommendedPrices: getRecommendedPrices,
|
558
1114
|
insertLineItem: insertLineItem,
|
559
|
-
isLineItemModified: isLineItemModified,
|
560
1115
|
isTechnicalAttribute: isTechnicalAttribute,
|
561
1116
|
mapAttributes: mapAttributes,
|
562
1117
|
multiplyLineItems: multiplyLineItems,
|
@@ -742,17 +1297,20 @@ class RuntimeSettingsService {
|
|
742
1297
|
};
|
743
1298
|
}
|
744
1299
|
create() {
|
745
|
-
return this.configurationSettingsApiService.fetchSettings().pipe(map$
|
1300
|
+
return this.configurationSettingsApiService.fetchSettings().pipe(map$1(settings => this.parseConfigurationSettings(settings)), tap$1(configurationSettings => {
|
746
1301
|
var _a;
|
747
1302
|
this.configurationSettings$.next(configurationSettings);
|
748
1303
|
this.addShoppingCartSettings((_a = configurationSettings['shopping-cart']) !== null && _a !== void 0 ? _a : []);
|
749
1304
|
this.formattingSettings = this.getFormattingSettings();
|
750
|
-
}), map$
|
1305
|
+
}), map$1(() => undefined));
|
751
1306
|
}
|
752
1307
|
initCurrency(iso) {
|
753
1308
|
if (iso) {
|
754
1309
|
const symbol = this.getCurrencySymbol('en-US', iso);
|
755
1310
|
this.currencySettings$.next({ iso, symbol });
|
1311
|
+
if (this.formattingSettings) {
|
1312
|
+
this.formattingSettings.currencySymbol = symbol;
|
1313
|
+
}
|
756
1314
|
}
|
757
1315
|
}
|
758
1316
|
getFormattingSettings() {
|
@@ -824,10 +1382,9 @@ class RuntimeSettingsService {
|
|
824
1382
|
}
|
825
1383
|
}
|
826
1384
|
RuntimeSettingsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, deps: [{ token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
827
|
-
RuntimeSettingsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService
|
1385
|
+
RuntimeSettingsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService });
|
828
1386
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, decorators: [{
|
829
|
-
type: Injectable
|
830
|
-
args: [{ providedIn: 'root' }]
|
1387
|
+
type: Injectable
|
831
1388
|
}], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
|
832
1389
|
|
833
1390
|
class ConfigurationService {
|
@@ -840,10 +1397,7 @@ class ConfigurationService {
|
|
840
1397
|
this.dialogService = dialogService;
|
841
1398
|
this.runtimeSettings = runtimeSettings;
|
842
1399
|
this.mode = ConfigurationMode.SEARCH;
|
843
|
-
this.
|
844
|
-
this.charges = new BehaviorSubject({});
|
845
|
-
this.pricePlans = new BehaviorSubject({});
|
846
|
-
this.procedureContext = new BehaviorSubject({});
|
1400
|
+
this.configurationState = new BehaviorSubject(null);
|
847
1401
|
this.isLoadingSubj$ = new BehaviorSubject(false);
|
848
1402
|
this.isLoading$ = this.isLoadingSubj$.asObservable();
|
849
1403
|
this.hasUnsavedChanges = false;
|
@@ -852,23 +1406,23 @@ class ConfigurationService {
|
|
852
1406
|
this.hasUnsavedChanges = false;
|
853
1407
|
this.runtimeService.reset();
|
854
1408
|
this.configurableRamp = undefined;
|
855
|
-
this.
|
856
|
-
this.charges.next({});
|
857
|
-
this.pricePlans.next({});
|
1409
|
+
this.configurationState.next(null);
|
858
1410
|
}
|
859
1411
|
patch$(lineItem, options) {
|
860
|
-
|
1412
|
+
const source = this.getSnapshot();
|
1413
|
+
if (!source) {
|
861
1414
|
return throwError(() => new Error(`Source LineItem not found`));
|
862
1415
|
}
|
863
1416
|
const skipCardinalityCalculation = (options === null || options === void 0 ? void 0 : options.skipCardinalityCalculation) || this.contextSnapshot.properties['#skipCardinalityCalculation'] === 'true';
|
864
|
-
this.configurableRamp = new LineItemWorker(
|
865
|
-
return this.configure().pipe(catchError(error => {
|
1417
|
+
this.configurableRamp = new LineItemWorker(source).replace(lineItem, skipCardinalityCalculation).li;
|
1418
|
+
return this.configure().pipe(catchError$1(error => {
|
866
1419
|
console.error(error);
|
867
1420
|
if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
|
868
1421
|
this.messageService.add({ severity: 'error', summary: error });
|
869
1422
|
}
|
870
1423
|
// bounce back if configuration call has failed
|
871
|
-
|
1424
|
+
const prevState = this.configurationState.value;
|
1425
|
+
this.configurationState.next(prevState ? Object.assign({}, prevState) : null);
|
872
1426
|
return throwError(() => error);
|
873
1427
|
}), tap(() => {
|
874
1428
|
if (!this.hasUnsavedChanges) {
|
@@ -883,10 +1437,11 @@ class ConfigurationService {
|
|
883
1437
|
this.configurableRamp = lineItem;
|
884
1438
|
}
|
885
1439
|
get() {
|
886
|
-
return this.
|
1440
|
+
return this.configurationState.pipe(map(state => state === null || state === void 0 ? void 0 : state.lineItem), shareReplay$1());
|
887
1441
|
}
|
888
1442
|
getSnapshot() {
|
889
|
-
|
1443
|
+
var _a, _b;
|
1444
|
+
return ((_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.lineItem) ? Object.assign({}, (_b = this.configurationState.value) === null || _b === void 0 ? void 0 : _b.lineItem) : undefined;
|
890
1445
|
}
|
891
1446
|
getRuntimeModel() {
|
892
1447
|
const runtimeModel = this.runtimeService.runtimeModel;
|
@@ -902,6 +1457,12 @@ class ConfigurationService {
|
|
902
1457
|
}
|
903
1458
|
return runtimeContext;
|
904
1459
|
}
|
1460
|
+
get state$() {
|
1461
|
+
return this.configurationState.asObservable();
|
1462
|
+
}
|
1463
|
+
get stateSnapshot() {
|
1464
|
+
return this.configurationState.value;
|
1465
|
+
}
|
905
1466
|
get contextSnapshot() {
|
906
1467
|
return this.contextService.resolve();
|
907
1468
|
}
|
@@ -909,22 +1470,25 @@ class ConfigurationService {
|
|
909
1470
|
return this.contextService.resolve$();
|
910
1471
|
}
|
911
1472
|
get charges$() {
|
912
|
-
return this.
|
1473
|
+
return this.configurationState.pipe(map(state => { var _a; return (_a = state === null || state === void 0 ? void 0 : state.charges) !== null && _a !== void 0 ? _a : {}; }));
|
913
1474
|
}
|
914
1475
|
get chargesSnapshot() {
|
915
|
-
|
1476
|
+
var _a, _b;
|
1477
|
+
return (_b = (_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.charges) !== null && _b !== void 0 ? _b : {};
|
916
1478
|
}
|
917
1479
|
get pricePlans$() {
|
918
|
-
return this.
|
1480
|
+
return this.configurationState.pipe(map(state => { var _a; return (_a = state === null || state === void 0 ? void 0 : state.pricePlans) !== null && _a !== void 0 ? _a : {}; }));
|
919
1481
|
}
|
920
1482
|
get pricePlansSnapshot() {
|
921
|
-
|
1483
|
+
var _a, _b;
|
1484
|
+
return (_b = (_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.pricePlans) !== null && _b !== void 0 ? _b : {};
|
922
1485
|
}
|
923
1486
|
get procedureContext$() {
|
924
|
-
return this.
|
1487
|
+
return this.configurationState.pipe(map(state => { var _a; return (_a = state === null || state === void 0 ? void 0 : state.procedureContext) !== null && _a !== void 0 ? _a : {}; }));
|
925
1488
|
}
|
926
1489
|
get procedureContextSnapshot() {
|
927
|
-
|
1490
|
+
var _a, _b;
|
1491
|
+
return (_b = (_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.procedureContext) !== null && _b !== void 0 ? _b : {};
|
928
1492
|
}
|
929
1493
|
configure() {
|
930
1494
|
return this.configureRequest$(this.generateRequest());
|
@@ -945,45 +1509,58 @@ class ConfigurationService {
|
|
945
1509
|
runtimeModel,
|
946
1510
|
pricingEnabled,
|
947
1511
|
});
|
948
|
-
return configure$.pipe(tap(
|
949
|
-
|
950
|
-
this.
|
951
|
-
this.
|
952
|
-
|
953
|
-
if (lineItem) {
|
954
|
-
this.lineItem.next(lineItem);
|
955
|
-
}
|
956
|
-
if (deletedLineItems === null || deletedLineItems === void 0 ? void 0 : deletedLineItems.length) {
|
1512
|
+
return configure$.pipe(tap(result => {
|
1513
|
+
var _a;
|
1514
|
+
this.contextService.update(result.context);
|
1515
|
+
this.configurationState.next(result);
|
1516
|
+
if ((_a = result.deletedLineItems) === null || _a === void 0 ? void 0 : _a.length) {
|
957
1517
|
this.showInactiveProductsConfirmation();
|
958
1518
|
}
|
959
|
-
this.configurableRamp = lineItem;
|
960
|
-
}), map(({ lineItem }) => lineItem), catchError(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })), finalize(() => this.isLoadingSubj$.next(false)));
|
1519
|
+
this.configurableRamp = result.lineItem;
|
1520
|
+
}), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })), finalize$1(() => this.isLoadingSubj$.next(false)));
|
961
1521
|
}
|
962
1522
|
configureExternal$(props) {
|
963
1523
|
return this.runtimeService
|
964
1524
|
.init({ productId: props.productId, defaultQty: props.qty, attributesMap: props.attributesMap })
|
965
|
-
.pipe(switchMap(() => this.configure()), first(), catchError(error => {
|
1525
|
+
.pipe(switchMap$1(() => this.configure()), first(), catchError$1(error => {
|
966
1526
|
this.messageService.add({ severity: ToastType.error, summary: error });
|
967
1527
|
throw error;
|
968
|
-
}), finalize(() => this.reset()));
|
1528
|
+
}), finalize$1(() => this.reset()));
|
969
1529
|
}
|
970
1530
|
configureGuidedSelling$(data) {
|
971
1531
|
return this.configurationApiService
|
972
1532
|
.configureLineItem({
|
973
1533
|
configurationRequest: getGuidedSellingConfigurationRequest(data, this.contextService.resolve()),
|
974
1534
|
})
|
975
|
-
.pipe(catchError(error => {
|
1535
|
+
.pipe(catchError$1(error => {
|
976
1536
|
if (error instanceof HttpErrorResponse) {
|
977
1537
|
this.messageService.add({ severity: ToastType.error, summary: error.error.message || error.error });
|
978
1538
|
}
|
979
1539
|
throw error;
|
980
1540
|
}));
|
981
1541
|
}
|
982
|
-
generateRequest() {
|
1542
|
+
generateRequest(lightMode = true) {
|
983
1543
|
var _a, _b;
|
1544
|
+
const lineItem = this.generateLineItem();
|
1545
|
+
let request = {
|
1546
|
+
lineItem,
|
1547
|
+
mode: this.mode,
|
1548
|
+
step: !((_a = this.configurationState.value) === null || _a === void 0 ? void 0 : _a.lineItem) ? RuntimeStep.START : RuntimeStep.UPDATE,
|
1549
|
+
attributeDomainMode: 'ALL',
|
1550
|
+
context: this.contextService.resolve(),
|
1551
|
+
lineItems: ((_b = this.quoteDraftService.quoteDraft) === null || _b === void 0 ? void 0 : _b.currentState) || [],
|
1552
|
+
asset: this.getAsset(),
|
1553
|
+
};
|
1554
|
+
if (lightMode) {
|
1555
|
+
request = ConfigurationTranslatorUtils.lightenConfigurationRequest(request);
|
1556
|
+
}
|
1557
|
+
return request;
|
1558
|
+
}
|
1559
|
+
generateLineItem() {
|
1560
|
+
var _a;
|
984
1561
|
const runtimeContext = this.getRuntimeContext();
|
985
1562
|
const uiDefinitionProperties = this.getUIDefinitionProperties();
|
986
|
-
let lineItem = this.configurableRamp;
|
1563
|
+
let lineItem = cloneDeep(this.configurableRamp);
|
987
1564
|
if (!lineItem) {
|
988
1565
|
const { initializationProps } = (_a = this.runtimeService) !== null && _a !== void 0 ? _a : {};
|
989
1566
|
lineItem = getDefaultLineItem(runtimeContext, uiDefinitionProperties, initializationProps === null || initializationProps === void 0 ? void 0 : initializationProps.defaultQty);
|
@@ -993,17 +1570,16 @@ class ConfigurationService {
|
|
993
1570
|
lineItem = new LineItemWorker(lineItem).patchAttribute(attributes).li;
|
994
1571
|
}
|
995
1572
|
}
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
return request;
|
1573
|
+
return lineItem;
|
1574
|
+
}
|
1575
|
+
getAsset() {
|
1576
|
+
var _a, _b;
|
1577
|
+
const lineItem = this.configurableRamp;
|
1578
|
+
if (!lineItem) {
|
1579
|
+
return;
|
1580
|
+
}
|
1581
|
+
const assetId = (_a = lineItem.assetId) !== null && _a !== void 0 ? _a : lineItem.openOrderLineItemId;
|
1582
|
+
return (_b = this.quoteDraftService.assetsState) === null || _b === void 0 ? void 0 : _b.initialState.find(li => assetPredicateFn(li, assetId));
|
1007
1583
|
}
|
1008
1584
|
getUIDefinitionProperties() {
|
1009
1585
|
var _a, _b, _c;
|
@@ -1033,20 +1609,12 @@ class ConfigurationService {
|
|
1033
1609
|
}
|
1034
1610
|
});
|
1035
1611
|
}
|
1036
|
-
getAsset() {
|
1037
|
-
var _a;
|
1038
|
-
const lineItem = this.configurableRamp;
|
1039
|
-
if (!lineItem) {
|
1040
|
-
return;
|
1041
|
-
}
|
1042
|
-
return (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
|
1043
|
-
}
|
1044
1612
|
}
|
1045
|
-
ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i5.MessageService }, { token: i6.DialogService }, { token: RuntimeSettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
|
1613
|
+
ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i5.MessageService }, { token: i6$1.DialogService }, { token: RuntimeSettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
|
1046
1614
|
ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService });
|
1047
1615
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService, decorators: [{
|
1048
1616
|
type: Injectable
|
1049
|
-
}], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6.DialogService }, { type: RuntimeSettingsService }]; } });
|
1617
|
+
}], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6$1.DialogService }, { type: RuntimeSettingsService }]; } });
|
1050
1618
|
|
1051
1619
|
class FlowConfigurationService {
|
1052
1620
|
constructor(proceduresApiService, contextService, quoteDraftService, updateService, configurationService) {
|
@@ -1055,6 +1623,8 @@ class FlowConfigurationService {
|
|
1055
1623
|
this.quoteDraftService = quoteDraftService;
|
1056
1624
|
this.updateService = updateService;
|
1057
1625
|
this.configurationService = configurationService;
|
1626
|
+
this.updatedSubj$ = new Subject();
|
1627
|
+
this.updated$ = this.updatedSubj$.asObservable();
|
1058
1628
|
}
|
1059
1629
|
calculate$(quoteDraft) {
|
1060
1630
|
return this.proceduresApiService.apply$(quoteDraft).pipe(tap$1(result => {
|
@@ -1064,7 +1634,7 @@ class FlowConfigurationService {
|
|
1064
1634
|
.slice()
|
1065
1635
|
.sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
|
1066
1636
|
this.quoteDraftService.updateQuoteDraft(result);
|
1067
|
-
}), map$
|
1637
|
+
}), map$1(noop));
|
1068
1638
|
}
|
1069
1639
|
calculate(quoteDraft) {
|
1070
1640
|
this.calculate$(quoteDraft).subscribe();
|
@@ -1074,11 +1644,11 @@ class FlowConfigurationService {
|
|
1074
1644
|
if (!quoteDraft) {
|
1075
1645
|
return of(null);
|
1076
1646
|
}
|
1077
|
-
return of([]).pipe(map$
|
1647
|
+
return of([]).pipe(map$1(() => {
|
1078
1648
|
const updatedState = cloneDeep(quoteDraft.currentState);
|
1079
1649
|
this.updateService.update(updatedState, updates, quoteDraft.charges);
|
1080
1650
|
return updatedState;
|
1081
|
-
}), switchMap
|
1651
|
+
}), switchMap(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
|
1082
1652
|
}
|
1083
1653
|
update(updates) {
|
1084
1654
|
this.update$(updates).subscribe();
|
@@ -1086,7 +1656,7 @@ class FlowConfigurationService {
|
|
1086
1656
|
revert$(lineItemId) {
|
1087
1657
|
const quoteDraft = this.quoteDraftService.quoteDraft;
|
1088
1658
|
const initialCurrentState = this.quoteDraftService.getInitialCurrentState();
|
1089
|
-
const currentState = this.quoteDraftService.
|
1659
|
+
const currentState = this.quoteDraftService.currentState;
|
1090
1660
|
const currentLineItemIndex = currentState.findIndex(({ id }) => id === lineItemId);
|
1091
1661
|
const currentLineItem = currentState[currentLineItemIndex];
|
1092
1662
|
const initialLineItem = initialCurrentState.find(({ integrationId }) => integrationId === (currentLineItem === null || currentLineItem === void 0 ? void 0 : currentLineItem.integrationId));
|
@@ -1097,7 +1667,7 @@ class FlowConfigurationService {
|
|
1097
1667
|
updatedState.splice(currentLineItemIndex, 1, initialLineItem);
|
1098
1668
|
return of([]).pipe(tap$1(() => {
|
1099
1669
|
this.quoteDraftService.setCurrentLineItemState(updatedState);
|
1100
|
-
}), switchMap
|
1670
|
+
}), switchMap(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
|
1101
1671
|
}
|
1102
1672
|
revert(lineItemId) {
|
1103
1673
|
this.revert$(lineItemId).subscribe();
|
@@ -1108,7 +1678,7 @@ class FlowConfigurationService {
|
|
1108
1678
|
if (!quoteDraft) {
|
1109
1679
|
return of(null);
|
1110
1680
|
}
|
1111
|
-
return of([]).pipe(map$
|
1681
|
+
return of([]).pipe(map$1(() => ids.reduce((result, id) => this.updateService.delete(result, id), currentState)), switchMap(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
|
1112
1682
|
}
|
1113
1683
|
delete(ids) {
|
1114
1684
|
this.delete$(ids).subscribe();
|
@@ -1119,36 +1689,36 @@ class FlowConfigurationService {
|
|
1119
1689
|
return of(null);
|
1120
1690
|
}
|
1121
1691
|
const updatedState = [...quoteDraft.currentState, term];
|
1122
|
-
return of([]).pipe(switchMap
|
1692
|
+
return of([]).pipe(switchMap(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
|
1123
1693
|
}
|
1124
1694
|
addToCart$(props) {
|
1125
1695
|
const quoteDraft = this.quoteDraftService.quoteDraft;
|
1126
1696
|
if (!quoteDraft) {
|
1127
1697
|
return of(null);
|
1128
1698
|
}
|
1129
|
-
return this.configurationService.configureExternal$(props).pipe(map$
|
1699
|
+
return this.configurationService.configureExternal$(props).pipe(map$1(lineItem => {
|
1130
1700
|
var _a, _b, _c;
|
1131
1701
|
const model = this.configurationService.getRuntimeModel();
|
1132
1702
|
const split = (_b = (_a = model === null || model === void 0 ? void 0 : model.types.find(type => type.name === lineItem.type)) === null || _a === void 0 ? void 0 : _a.split) !== null && _b !== void 0 ? _b : false;
|
1133
1703
|
const lineItems = multiplyLineItems(lineItem, (_c = props.qty) !== null && _c !== void 0 ? _c : 1, split);
|
1134
1704
|
return [...quoteDraft.currentState, ...lineItems];
|
1135
|
-
}), switchMap
|
1705
|
+
}), switchMap(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
|
1136
1706
|
}
|
1137
1707
|
get() {
|
1138
|
-
return this.quoteDraftService.quoteDraft$.pipe(map$
|
1708
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.currentState), shareReplay$1());
|
1139
1709
|
}
|
1140
1710
|
getSnapshot() {
|
1141
1711
|
var _a, _b;
|
1142
1712
|
return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
|
1143
1713
|
}
|
1144
1714
|
get charges$() {
|
1145
|
-
return this.quoteDraftService.quoteDraft$.pipe(map$
|
1715
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(({ charges }) => charges));
|
1146
1716
|
}
|
1147
1717
|
get pricePlans$() {
|
1148
|
-
return this.quoteDraftService.quoteDraft$.pipe(map$
|
1718
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(({ pricePlans }) => pricePlans));
|
1149
1719
|
}
|
1150
1720
|
get activeMetrics$() {
|
1151
|
-
return this.quoteDraftService.quoteDraft$.pipe(map$
|
1721
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(({ activeMetrics }) => activeMetrics));
|
1152
1722
|
}
|
1153
1723
|
get chargesSnapshot() {
|
1154
1724
|
var _a, _b;
|
@@ -1170,12 +1740,13 @@ class FlowConfigurationService {
|
|
1170
1740
|
}
|
1171
1741
|
handleErrorAndBounceBack() {
|
1172
1742
|
return (source$) => {
|
1173
|
-
return source$.pipe(catchError
|
1743
|
+
return source$.pipe(catchError(error => {
|
1174
1744
|
console.error(error);
|
1175
1745
|
// bounce back if configuration call has failed
|
1176
1746
|
const quoteDraft = this.quoteDraftService.quoteDraft;
|
1177
1747
|
if (quoteDraft) {
|
1178
1748
|
this.quoteDraftService.updateQuoteDraft(quoteDraft);
|
1749
|
+
this.updatedSubj$.next();
|
1179
1750
|
}
|
1180
1751
|
return throwError(() => error);
|
1181
1752
|
}));
|
@@ -1188,80 +1759,93 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
1188
1759
|
type: Injectable
|
1189
1760
|
}], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
|
1190
1761
|
|
1191
|
-
class
|
1192
|
-
|
1193
|
-
|
1762
|
+
class FlowConfigurationModule {
|
1763
|
+
}
|
1764
|
+
FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1765
|
+
FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, imports: [ApiModule] });
|
1766
|
+
FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService], imports: [ApiModule] });
|
1767
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
|
1768
|
+
type: NgModule,
|
1769
|
+
args: [{
|
1770
|
+
imports: [ApiModule],
|
1771
|
+
providers: [FlowConfigurationService, FlowUpdateService],
|
1772
|
+
}]
|
1773
|
+
}] });
|
1774
|
+
|
1775
|
+
class FlowStateConfigurationService {
|
1776
|
+
constructor(flowInfoService, flowConfigurationService, flowStateApiService, flowStateService) {
|
1777
|
+
this.flowInfoService = flowInfoService;
|
1778
|
+
this.flowConfigurationService = flowConfigurationService;
|
1779
|
+
this.flowStateApiService = flowStateApiService;
|
1780
|
+
this.flowStateService = flowStateService;
|
1781
|
+
this.configurationStateId$ = new BehaviorSubject(null);
|
1194
1782
|
}
|
1195
|
-
|
1196
|
-
this.
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
this.
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
this.quoteDraftService.currentState$,
|
1207
|
-
this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
|
1208
|
-
]).subscribe(([lineItems, setting]) => {
|
1209
|
-
let settingsData = {};
|
1210
|
-
try {
|
1211
|
-
settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
|
1783
|
+
get configurationStateId() {
|
1784
|
+
return this.configurationStateId$.value;
|
1785
|
+
}
|
1786
|
+
addToCart$(props) {
|
1787
|
+
var _a;
|
1788
|
+
let request$;
|
1789
|
+
const stateful = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful;
|
1790
|
+
if (stateful) {
|
1791
|
+
const stateId = this.flowStateService.stateId;
|
1792
|
+
if (!stateId) {
|
1793
|
+
request$ = of();
|
1212
1794
|
}
|
1213
|
-
|
1214
|
-
|
1795
|
+
else {
|
1796
|
+
const lineItem = generateConfigurationLineItem(props, props.qty);
|
1797
|
+
request$ = this.flowStateApiService.newConfiguration(stateId, { lineItem }).pipe(tap$1(r => this.configurationStateId$.next(r.stateId)), switchMap(() => {
|
1798
|
+
if (!this.configurationStateId) {
|
1799
|
+
return of();
|
1800
|
+
}
|
1801
|
+
return this.flowStateApiService.saveConfiguration(stateId, this.configurationStateId).pipe(tap$1(() => this.configurationStateId$.next(null)), map$1(noop));
|
1802
|
+
}));
|
1215
1803
|
}
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1804
|
+
}
|
1805
|
+
else {
|
1806
|
+
request$ = this.flowConfigurationService.addToCart$(props).pipe(map$1(noop));
|
1807
|
+
}
|
1808
|
+
return request$.pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), map$1(noop));
|
1219
1809
|
}
|
1220
|
-
|
1221
|
-
|
1810
|
+
}
|
1811
|
+
FlowStateConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, deps: [{ token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.FlowStateApiService }, { token: FlowStateService }], target: i0.ɵɵFactoryTarget.Injectable });
|
1812
|
+
FlowStateConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService });
|
1813
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, decorators: [{
|
1814
|
+
type: Injectable
|
1815
|
+
}], ctorParameters: function () { return [{ type: FlowInfoService }, { type: FlowConfigurationService }, { type: i1.FlowStateApiService }, { type: FlowStateService }]; } });
|
1816
|
+
|
1817
|
+
class IntegrationState {
|
1818
|
+
constructor() {
|
1819
|
+
this.stateSubj$ = new BehaviorSubject({});
|
1820
|
+
this.action$ = new Subject();
|
1222
1821
|
}
|
1223
|
-
|
1224
|
-
|
1225
|
-
this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
|
1226
|
-
this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
|
1227
|
-
this.metricsUpdated$.next();
|
1822
|
+
get state$() {
|
1823
|
+
return this.stateSubj$.asObservable();
|
1228
1824
|
}
|
1229
|
-
|
1230
|
-
return
|
1825
|
+
get state() {
|
1826
|
+
return this.stateSubj$.getValue();
|
1231
1827
|
}
|
1232
|
-
|
1233
|
-
|
1234
|
-
var _a, _b;
|
1235
|
-
if (acc[name]) {
|
1236
|
-
return acc;
|
1237
|
-
}
|
1238
|
-
acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
|
1239
|
-
const metricRule = this.getMetricRuleByTotalMetricName(name);
|
1240
|
-
const settingKey = ((_b = (_a = metricRule === null || metricRule === void 0 ? void 0 : metricRule.metrics) === null || _a === void 0 ? void 0 : _a.find(metric => metric.totalName === name)) === null || _b === void 0 ? void 0 : _b.name) || name;
|
1241
|
-
if (this.quoteMetricsSettings[settingKey]) {
|
1242
|
-
acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
|
1243
|
-
}
|
1244
|
-
return acc;
|
1245
|
-
}, initial);
|
1828
|
+
patchState(update) {
|
1829
|
+
this.stateSubj$.next(Object.assign(Object.assign({}, this.stateSubj$.getValue()), update));
|
1246
1830
|
}
|
1247
|
-
|
1248
|
-
|
1249
|
-
lineItems.forEach(lineItem => {
|
1250
|
-
keys.push(...Object.keys(lineItem.totalMetrics || {}));
|
1251
|
-
keys.push(...this.collectMetricKeys(lineItem.lineItems));
|
1252
|
-
});
|
1253
|
-
return uniq(keys);
|
1831
|
+
dispatch(action) {
|
1832
|
+
this.action$.next(action);
|
1254
1833
|
}
|
1255
|
-
|
1256
|
-
return this.
|
1834
|
+
listen$(actionType) {
|
1835
|
+
return this.action$.pipe(filter$1(action => action.type === actionType), map$1(action => action.payload));
|
1836
|
+
}
|
1837
|
+
listenAll$() {
|
1838
|
+
return this.action$.asObservable();
|
1839
|
+
}
|
1840
|
+
clear() {
|
1841
|
+
this.stateSubj$.next({});
|
1257
1842
|
}
|
1258
1843
|
}
|
1259
|
-
|
1260
|
-
|
1261
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type:
|
1262
|
-
type: Injectable
|
1263
|
-
|
1264
|
-
}], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1.ConfigurationSettingsApiService }]; } });
|
1844
|
+
IntegrationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
1845
|
+
IntegrationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState });
|
1846
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState, decorators: [{
|
1847
|
+
type: Injectable
|
1848
|
+
}] });
|
1265
1849
|
|
1266
1850
|
class ProductImagesService {
|
1267
1851
|
constructor(productApiService) {
|
@@ -1273,20 +1857,19 @@ class ProductImagesService {
|
|
1273
1857
|
this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
|
1274
1858
|
this.fetchProductImage(productId);
|
1275
1859
|
}
|
1276
|
-
return this.imagesMap$.pipe(map$
|
1860
|
+
return this.imagesMap$.pipe(map$1(imagesMap => { var _a; return (_a = imagesMap[productId]) !== null && _a !== void 0 ? _a : null; }), distinctUntilChanged());
|
1277
1861
|
}
|
1278
1862
|
fetchProductImage(productId) {
|
1279
1863
|
this.productApiService
|
1280
1864
|
.fetchImage$(productId)
|
1281
|
-
.pipe(map$
|
1865
|
+
.pipe(map$1(file => URL.createObjectURL(file)), catchError(() => of('')), tap$1(url => this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: url }))))
|
1282
1866
|
.subscribe();
|
1283
1867
|
}
|
1284
1868
|
}
|
1285
1869
|
ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
1286
|
-
ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService
|
1870
|
+
ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService });
|
1287
1871
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService, decorators: [{
|
1288
|
-
type: Injectable
|
1289
|
-
args: [{ providedIn: 'root' }]
|
1872
|
+
type: Injectable
|
1290
1873
|
}], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
|
1291
1874
|
|
1292
1875
|
class RuntimeContextService {
|
@@ -1414,63 +1997,225 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
1414
1997
|
type: Injectable
|
1415
1998
|
}], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
|
1416
1999
|
|
1417
|
-
class
|
1418
|
-
constructor(
|
1419
|
-
this.
|
1420
|
-
this.runtimeService = runtimeService;
|
2000
|
+
class ConfigurationStateService {
|
2001
|
+
constructor(configurationRuntimeService, configurationService, quoteDraftService, toastService, flowStateService, flowInfoService, flowConfigurationService, flowStateApiService, quoteApiService) {
|
2002
|
+
this.configurationRuntimeService = configurationRuntimeService;
|
1421
2003
|
this.configurationService = configurationService;
|
2004
|
+
this.quoteDraftService = quoteDraftService;
|
1422
2005
|
this.toastService = toastService;
|
1423
|
-
this.
|
1424
|
-
this.
|
2006
|
+
this.flowStateService = flowStateService;
|
2007
|
+
this.flowInfoService = flowInfoService;
|
2008
|
+
this.flowConfigurationService = flowConfigurationService;
|
2009
|
+
this.flowStateApiService = flowStateApiService;
|
2010
|
+
this.quoteApiService = quoteApiService;
|
2011
|
+
this.isInitialized$ = new BehaviorSubject(false);
|
2012
|
+
this.canceledConfiguration$ = new Subject();
|
2013
|
+
this.NOT_INITIALIZED = Symbol();
|
2014
|
+
this.EXECUTION_BUFFER_TIME = 100;
|
2015
|
+
this.executedFunctions = {};
|
1425
2016
|
this.stateId = null;
|
2017
|
+
this.ownerId = '';
|
2018
|
+
this.subscriptions = {};
|
2019
|
+
this.configurationStore = {};
|
2020
|
+
this.statefulExecutionInProgress$ = new BehaviorSubject(false);
|
2021
|
+
this.statefulRequestStream$ = new Subject();
|
2022
|
+
this.statefulExecutionRequest$ = this.initBufferedRequest$();
|
1426
2023
|
}
|
1427
2024
|
init$() {
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
}), tap$1(stateId => (this.stateId = stateId || null)), map$2(() => undefined));
|
2025
|
+
let request$;
|
2026
|
+
if (this.flowStateService.stateId && this.isStatefulConfiguration) {
|
2027
|
+
request$ = this.initStateful$();
|
2028
|
+
}
|
2029
|
+
else {
|
2030
|
+
request$ = this.initStateless$();
|
2031
|
+
}
|
2032
|
+
return request$.pipe(finalize(() => {
|
2033
|
+
this.isInitialized$.next(true);
|
2034
|
+
this.canceledConfiguration$ = new Subject();
|
2035
|
+
}));
|
1440
2036
|
}
|
1441
2037
|
cleanup() {
|
1442
|
-
this.
|
2038
|
+
Object.values(this.subscriptions).forEach(({ data$ }) => data$.complete());
|
2039
|
+
this.subscriptions = {};
|
2040
|
+
if (this.stateId) {
|
2041
|
+
this.cancelConfiguration();
|
2042
|
+
}
|
2043
|
+
this.configurationStore = {};
|
2044
|
+
this.executedFunctions = {};
|
1443
2045
|
this.configurationService.reset();
|
1444
|
-
this.stateSubj$.next({});
|
1445
2046
|
}
|
1446
|
-
execute$(req) {
|
2047
|
+
execute$(req, forceSubscriptions) {
|
2048
|
+
var _a;
|
2049
|
+
const fullRequest = cloneDeep(req);
|
2050
|
+
if (((_a = fullRequest.actions) === null || _a === void 0 ? void 0 : _a.length) || forceSubscriptions) {
|
2051
|
+
for (const subscription of Object.values(this.subscriptions)) {
|
2052
|
+
fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
|
2053
|
+
}
|
2054
|
+
}
|
2055
|
+
let execution$;
|
1447
2056
|
if (this.isStatefulConfiguration) {
|
1448
|
-
|
2057
|
+
execution$ = this.executeStateful$(fullRequest);
|
1449
2058
|
}
|
1450
2059
|
else {
|
1451
|
-
|
2060
|
+
execution$ = this.executeStateless$(fullRequest);
|
1452
2061
|
}
|
2062
|
+
return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
|
2063
|
+
}
|
2064
|
+
handleSelectorsResponse(selectors) {
|
2065
|
+
Object.entries(selectors).forEach(([requestId, selectorResult]) => {
|
2066
|
+
var _a;
|
2067
|
+
if (!selectorResult.success) {
|
2068
|
+
this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
|
2069
|
+
}
|
2070
|
+
const subscription$ = (_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$;
|
2071
|
+
if (subscription$) {
|
2072
|
+
subscription$.next(selectorResult);
|
2073
|
+
}
|
2074
|
+
});
|
1453
2075
|
}
|
1454
|
-
dispatch$(actionName, inputData) {
|
1455
|
-
return this.execute$({ actions: [{
|
2076
|
+
dispatch$(actionName, inputData = {}) {
|
2077
|
+
return this.execute$({ actions: [{ apiName: actionName, inputData, ownerId: this.ownerId }] });
|
1456
2078
|
}
|
1457
|
-
select$(selectorName, inputData) {
|
2079
|
+
select$(selectorName, inputData = {}) {
|
1458
2080
|
const requestId = UUID.UUID();
|
1459
2081
|
return this.execute$({
|
1460
2082
|
selectors: {
|
1461
2083
|
[requestId]: {
|
1462
|
-
|
2084
|
+
apiName: selectorName,
|
1463
2085
|
inputData,
|
2086
|
+
ownerId: this.ownerId,
|
1464
2087
|
},
|
1465
2088
|
},
|
1466
|
-
}).pipe(map$
|
2089
|
+
}).pipe(map$1(response => response.selectors[requestId]));
|
2090
|
+
}
|
2091
|
+
subscribe$(selectorName, inputData = {}, options) {
|
2092
|
+
const requestId = UUID.UUID();
|
2093
|
+
let subscription = this.subscriptions[requestId];
|
2094
|
+
if (!subscription) {
|
2095
|
+
const request = {
|
2096
|
+
selectors: {
|
2097
|
+
[requestId]: {
|
2098
|
+
apiName: selectorName,
|
2099
|
+
inputData,
|
2100
|
+
ownerId: this.ownerId,
|
2101
|
+
},
|
2102
|
+
},
|
2103
|
+
};
|
2104
|
+
subscription = {
|
2105
|
+
request,
|
2106
|
+
data$: new BehaviorSubject(this.NOT_INITIALIZED),
|
2107
|
+
};
|
2108
|
+
this.subscriptions[requestId] = subscription;
|
2109
|
+
if (!(options === null || options === void 0 ? void 0 : options.cold)) {
|
2110
|
+
this.execute$(request).subscribe();
|
2111
|
+
}
|
2112
|
+
}
|
2113
|
+
return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), distinctUntilChanged(), finalize(() => {
|
2114
|
+
var _a;
|
2115
|
+
if (!((_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$.observed)) {
|
2116
|
+
delete this.subscriptions[requestId];
|
2117
|
+
}
|
2118
|
+
}), takeUntil(this.canceledConfiguration$));
|
2119
|
+
}
|
2120
|
+
saveConfiguration(quoteId, flow) {
|
2121
|
+
var _a, _b, _c, _d;
|
2122
|
+
if (this.isStatefulConfiguration) {
|
2123
|
+
return this.flowStateApiService
|
2124
|
+
.saveConfiguration((_a = this.flowStateService.stateId) !== null && _a !== void 0 ? _a : '', (_b = this.stateId) !== null && _b !== void 0 ? _b : '')
|
2125
|
+
.pipe(switchMap(r => this.flowStateService.executeRequest$({}, true).pipe(map$1(() => r))));
|
2126
|
+
}
|
2127
|
+
else {
|
2128
|
+
if (!flow) {
|
2129
|
+
if (!quoteId) {
|
2130
|
+
return of({ quoteId: '' });
|
2131
|
+
}
|
2132
|
+
const rootLineItem = this.configurationService.getSnapshot();
|
2133
|
+
const asset = this.configurationService.getAsset();
|
2134
|
+
const currentState = rootLineItem ? [rootLineItem] : [];
|
2135
|
+
const initialState = asset ? [asset] : [];
|
2136
|
+
return this.quoteApiService
|
2137
|
+
.getQuoteState(quoteId)
|
2138
|
+
.pipe(switchMap(quoteDraft => this.quoteApiService.upsertQuote(Object.assign(Object.assign({}, quoteDraft), { currentState, initialState }))));
|
2139
|
+
}
|
2140
|
+
else {
|
2141
|
+
const quoteDraft = this.quoteDraftService.quoteDraft;
|
2142
|
+
const lineItem = this.configurationService.getSnapshot();
|
2143
|
+
if (!quoteDraft || !lineItem) {
|
2144
|
+
return of({ quoteId: '' });
|
2145
|
+
}
|
2146
|
+
const isNewLineItem = quoteDraft.currentState.every(li => li.id !== lineItem.id);
|
2147
|
+
let currentState;
|
2148
|
+
if (isNewLineItem) {
|
2149
|
+
currentState = [...quoteDraft.currentState, lineItem];
|
2150
|
+
}
|
2151
|
+
else {
|
2152
|
+
currentState = quoteDraft.currentState.map(li => (li.id === lineItem.id ? lineItem : li));
|
2153
|
+
}
|
2154
|
+
const asset = this.configurationService.getAsset();
|
2155
|
+
const initialState = [...((_d = (_c = this.quoteDraftService.quoteDraft) === null || _c === void 0 ? void 0 : _c.initialState) !== null && _d !== void 0 ? _d : [])];
|
2156
|
+
if (asset) {
|
2157
|
+
if (!initialState.some(li => li.id === asset.id)) {
|
2158
|
+
initialState.push(asset);
|
2159
|
+
}
|
2160
|
+
}
|
2161
|
+
return this.flowConfigurationService
|
2162
|
+
.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState, initialState }))
|
2163
|
+
.pipe(map$1(() => ({ quoteId: '' })));
|
2164
|
+
}
|
2165
|
+
}
|
2166
|
+
}
|
2167
|
+
cancelConfiguration() {
|
2168
|
+
var _a, _b;
|
2169
|
+
if (!this.isInitialized$.value) {
|
2170
|
+
return of(undefined);
|
2171
|
+
}
|
2172
|
+
this.canceledConfiguration$.next();
|
2173
|
+
this.canceledConfiguration$.complete();
|
2174
|
+
this.subscriptions = {};
|
2175
|
+
this.isInitialized$.next(false);
|
2176
|
+
if (!this.isInitialized$.value || !this.isStatefulConfiguration) {
|
2177
|
+
return of(undefined);
|
2178
|
+
}
|
2179
|
+
return this.flowStateApiService.cancelConfiguration((_a = this.flowStateService.stateId) !== null && _a !== void 0 ? _a : '', (_b = this.stateId) !== null && _b !== void 0 ? _b : '');
|
1467
2180
|
}
|
1468
2181
|
get isStatefulConfiguration() {
|
1469
|
-
var _a;
|
1470
|
-
return (_a = this.
|
2182
|
+
var _a, _b;
|
2183
|
+
return (_b = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful) !== null && _b !== void 0 ? _b : false;
|
2184
|
+
}
|
2185
|
+
initStateful$() {
|
2186
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
2187
|
+
this.ownerId = (_c = (_b = (_a = this.configurationRuntimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '';
|
2188
|
+
const lineItemId = (_e = (_d = this.configurationRuntimeService.runtimeContext) === null || _d === void 0 ? void 0 : _d.properties) === null || _e === void 0 ? void 0 : _e.lineItemId;
|
2189
|
+
if (!this.flowStateService.stateId) {
|
2190
|
+
return of(undefined);
|
2191
|
+
}
|
2192
|
+
const container = (_f = this.configurationRuntimeService.runtimeContext) === null || _f === void 0 ? void 0 : _f.uiDefinitionContainer;
|
2193
|
+
const lineItem = this.configurationService.generateLineItem();
|
2194
|
+
let request$;
|
2195
|
+
if (!lineItemId) {
|
2196
|
+
request$ = this.flowStateApiService.newConfiguration(this.flowStateService.stateId, {
|
2197
|
+
lineItem,
|
2198
|
+
actionsOverride: (_g = container === null || container === void 0 ? void 0 : container.actions) === null || _g === void 0 ? void 0 : _g.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
|
2199
|
+
selectorsOverride: (_h = container === null || container === void 0 ? void 0 : container.selectors) === null || _h === void 0 ? void 0 : _h.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
|
2200
|
+
});
|
2201
|
+
}
|
2202
|
+
else {
|
2203
|
+
request$ = this.flowStateApiService.startConfiguration(this.flowStateService.stateId, {
|
2204
|
+
lineItemId,
|
2205
|
+
actionsOverride: (_j = container === null || container === void 0 ? void 0 : container.actions) === null || _j === void 0 ? void 0 : _j.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
|
2206
|
+
selectorsOverride: (_k = container === null || container === void 0 ? void 0 : container.selectors) === null || _k === void 0 ? void 0 : _k.map(processor => (Object.assign(Object.assign({}, processor), { ownerId: this.ownerId }))),
|
2207
|
+
});
|
2208
|
+
}
|
2209
|
+
return request$.pipe(map$1(r => {
|
2210
|
+
this.stateId = r.stateId;
|
2211
|
+
return undefined;
|
2212
|
+
}));
|
2213
|
+
}
|
2214
|
+
initStateless$() {
|
2215
|
+
return this.configurationService.configure().pipe(map$1(() => undefined));
|
1471
2216
|
}
|
1472
2217
|
executeStateless$(request) {
|
1473
|
-
return of(undefined).pipe(switchMap
|
2218
|
+
return of(undefined).pipe(switchMap(() => {
|
1474
2219
|
var _a;
|
1475
2220
|
// Apply actions and execute configuration/price call
|
1476
2221
|
// No need to run configuration if no actions in the request
|
@@ -1483,108 +2228,115 @@ class ConfigurationState {
|
|
1483
2228
|
configurationRequest = (_a = this.executeActionScript(configurationRequest, action)) !== null && _a !== void 0 ? _a : configurationRequest;
|
1484
2229
|
});
|
1485
2230
|
return this.configurationService.configureRequest$(configurationRequest);
|
1486
|
-
}),
|
1487
|
-
|
1488
|
-
return;
|
1489
|
-
}
|
2231
|
+
}), map$1(() => {
|
2232
|
+
var _a;
|
1490
2233
|
// Run selectors and apply them to the state
|
1491
|
-
const
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
}, {
|
1496
|
-
|
1497
|
-
|
2234
|
+
const configurationState = cloneDeep(this.configurationService.stateSnapshot);
|
2235
|
+
if (!configurationState) {
|
2236
|
+
return { stateId: '', selectors: {} };
|
2237
|
+
}
|
2238
|
+
const selectorsResult = EntityUtil.entries((_a = request.selectors) !== null && _a !== void 0 ? _a : {}).reduce((result, [key, selector]) => {
|
2239
|
+
try {
|
2240
|
+
result.selectors[key] = {
|
2241
|
+
success: true,
|
2242
|
+
result: this.executeSelectorScript(configurationState, selector),
|
2243
|
+
};
|
2244
|
+
}
|
2245
|
+
catch (e) {
|
2246
|
+
console.error(e);
|
2247
|
+
result.selectors[key] = {
|
2248
|
+
success: false,
|
2249
|
+
errorMessage: String(e),
|
2250
|
+
};
|
2251
|
+
}
|
2252
|
+
return result;
|
2253
|
+
}, { stateId: '', selectors: {} });
|
2254
|
+
return selectorsResult;
|
2255
|
+
}), catchError(error => {
|
2256
|
+
if (!this.configurationRuntimeService.uiDefinitionProperties.suppressToastMessages) {
|
2257
|
+
this.toastService.add({ severity: ToastType.error, summary: String(error) });
|
2258
|
+
}
|
2259
|
+
return throwError(() => error);
|
2260
|
+
}));
|
2261
|
+
}
|
2262
|
+
initBufferedRequest$() {
|
2263
|
+
return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap(requests => {
|
2264
|
+
if (!this.flowStateService.stateId || !this.stateId) {
|
2265
|
+
throw 'Stateful session is not initialized';
|
2266
|
+
}
|
2267
|
+
// merge buffered requests
|
2268
|
+
const request = {
|
2269
|
+
actions: requests.flatMap(({ actions }) => actions).filter(isDefined),
|
2270
|
+
selectors: requests
|
2271
|
+
.map(({ selectors }) => selectors)
|
2272
|
+
.filter(isDefined)
|
2273
|
+
.reduce((acc, selectorsMap) => Object.assign(acc, selectorsMap), {}),
|
2274
|
+
};
|
2275
|
+
this.statefulExecutionInProgress$.next(true);
|
2276
|
+
return this.flowStateApiService.executeConfiguration(this.flowStateService.stateId, this.stateId, request);
|
2277
|
+
}), tap$1(({ stateId }) => (this.stateId = stateId)), share(), tap$1(() => this.statefulExecutionInProgress$.next(false)), catchError(e => {
|
2278
|
+
this.statefulExecutionInProgress$.next(false);
|
2279
|
+
return throwError(() => e);
|
2280
|
+
}));
|
1498
2281
|
}
|
1499
2282
|
executeStateful$(request) {
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
EntityUtil.entries(response.selectors).forEach(([key, value]) => {
|
1507
|
-
if (!value.success) {
|
1508
|
-
if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
|
1509
|
-
this.toastService.add({ summary: value.errorMessage, severity: ToastType.error });
|
1510
|
-
}
|
1511
|
-
return;
|
1512
|
-
}
|
1513
|
-
updatedState[key] = value.result;
|
1514
|
-
});
|
1515
|
-
this.stateSubj$.next(updatedState);
|
1516
|
-
}), map$2(() => undefined));
|
2283
|
+
return this.statefulExecutionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
|
2284
|
+
// make sure stream switches to statefulExecutionRequest$ before pushing an execution request
|
2285
|
+
combineLatest([
|
2286
|
+
this.statefulExecutionRequest$,
|
2287
|
+
of(undefined).pipe(tap$1(() => this.statefulRequestStream$.next(request))),
|
2288
|
+
])), map$1(([response]) => response), take$1(1));
|
1517
2289
|
}
|
1518
2290
|
executeActionScript(request, processor) {
|
1519
|
-
var _a, _b
|
1520
|
-
const { actions } = (_b = (_a = this.
|
1521
|
-
const
|
1522
|
-
if (!script) {
|
1523
|
-
|
2291
|
+
var _a, _b;
|
2292
|
+
const { actions } = (_b = (_a = this.configurationRuntimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
|
2293
|
+
const configurationProcessor = actions === null || actions === void 0 ? void 0 : actions.find(action => action.apiName === processor.apiName);
|
2294
|
+
if (!(configurationProcessor === null || configurationProcessor === void 0 ? void 0 : configurationProcessor.script)) {
|
2295
|
+
throw `ConfigurationProcessor ${processor.apiName} not found`;
|
1524
2296
|
}
|
1525
|
-
return this.executeProcessorScript(request,
|
2297
|
+
return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
|
1526
2298
|
}
|
1527
2299
|
executeSelectorScript(request, processor) {
|
1528
|
-
var _a, _b
|
1529
|
-
const { selectors } = (_b = (_a = this.
|
1530
|
-
const
|
1531
|
-
if (!script) {
|
1532
|
-
|
1533
|
-
}
|
1534
|
-
return this.executeProcessorScript(request,
|
1535
|
-
}
|
1536
|
-
executeProcessorScript(request,
|
1537
|
-
|
2300
|
+
var _a, _b;
|
2301
|
+
const { selectors } = (_b = (_a = this.configurationRuntimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
|
2302
|
+
const configurationProcessor = selectors === null || selectors === void 0 ? void 0 : selectors.find(selector => selector.apiName === processor.apiName);
|
2303
|
+
if (!(configurationProcessor === null || configurationProcessor === void 0 ? void 0 : configurationProcessor.script)) {
|
2304
|
+
throw `ConfigurationProcessor ${processor.apiName} not found`;
|
2305
|
+
}
|
2306
|
+
return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
|
2307
|
+
}
|
2308
|
+
executeProcessorScript(request, configurationProcessor, inputData) {
|
2309
|
+
let functionToExecute = this.executedFunctions[configurationProcessor.apiName];
|
2310
|
+
if (!functionToExecute) {
|
2311
|
+
const script = `${configurationProcessor.script}\nreturn transform;`;
|
2312
|
+
const sourceMap = `\n//# sourceURL=${configurationProcessor.apiName}.js`;
|
2313
|
+
functionToExecute = new Function(script + sourceMap)();
|
2314
|
+
this.executedFunctions[configurationProcessor.apiName] = functionToExecute;
|
2315
|
+
}
|
2316
|
+
return functionToExecute({
|
1538
2317
|
request,
|
1539
|
-
inputData
|
2318
|
+
inputData,
|
2319
|
+
flowStore: this.flowStateService.getFlowStore(),
|
2320
|
+
configurationStore: this.configurationStore,
|
1540
2321
|
});
|
1541
2322
|
}
|
1542
2323
|
}
|
1543
|
-
|
1544
|
-
|
1545
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type:
|
2324
|
+
ConfigurationStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService, deps: [{ token: ConfigurationRuntimeService }, { token: ConfigurationService }, { token: QuoteDraftService }, { token: i6.ToastService }, { token: FlowStateService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.FlowStateApiService }, { token: i1.QuoteApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
2325
|
+
ConfigurationStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService });
|
2326
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService, decorators: [{
|
1546
2327
|
type: Injectable
|
1547
|
-
}], ctorParameters: function () { return [{ type:
|
1548
|
-
|
1549
|
-
class FlowConfigurationModule {
|
1550
|
-
}
|
1551
|
-
FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1552
|
-
FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
|
1553
|
-
FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
|
1554
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
|
1555
|
-
type: NgModule,
|
1556
|
-
args: [{
|
1557
|
-
imports: [],
|
1558
|
-
providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
|
1559
|
-
}]
|
1560
|
-
}] });
|
2328
|
+
}], ctorParameters: function () { return [{ type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: QuoteDraftService }, { type: i6.ToastService }, { type: FlowStateService }, { type: FlowInfoService }, { type: FlowConfigurationService }, { type: i1.FlowStateApiService }, { type: i1.QuoteApiService }]; } });
|
1561
2329
|
|
1562
2330
|
class ConfigurationModule {
|
1563
2331
|
}
|
1564
2332
|
ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1565
|
-
ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
|
1566
|
-
ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, providers: [
|
1567
|
-
ContextApiService,
|
1568
|
-
ProductModelApiService,
|
1569
|
-
ConfigurationApiService,
|
1570
|
-
ConfigurationRuntimeService,
|
1571
|
-
RuntimeContextService,
|
1572
|
-
ConfigurationService,
|
1573
|
-
ConfigurationState,
|
1574
|
-
], imports: [ConfirmationDialogModule] });
|
2333
|
+
ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule, ApiModule] });
|
2334
|
+
ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, providers: [ConfigurationRuntimeService, RuntimeContextService, ConfigurationService, ConfigurationStateService], imports: [ConfirmationDialogModule, ApiModule] });
|
1575
2335
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, decorators: [{
|
1576
2336
|
type: NgModule,
|
1577
2337
|
args: [{
|
1578
|
-
imports: [ConfirmationDialogModule],
|
1579
|
-
providers: [
|
1580
|
-
ContextApiService,
|
1581
|
-
ProductModelApiService,
|
1582
|
-
ConfigurationApiService,
|
1583
|
-
ConfigurationRuntimeService,
|
1584
|
-
RuntimeContextService,
|
1585
|
-
ConfigurationService,
|
1586
|
-
ConfigurationState,
|
1587
|
-
],
|
2338
|
+
imports: [ConfirmationDialogModule, ApiModule],
|
2339
|
+
providers: [ConfigurationRuntimeService, RuntimeContextService, ConfigurationService, ConfigurationStateService],
|
1588
2340
|
}]
|
1589
2341
|
}] });
|
1590
2342
|
|
@@ -1601,6 +2353,14 @@ class SdkCoreModule {
|
|
1601
2353
|
SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1602
2354
|
SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
|
1603
2355
|
SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, providers: [
|
2356
|
+
ContextService,
|
2357
|
+
FlowInfoService,
|
2358
|
+
QuoteDraftService,
|
2359
|
+
ProductImagesService,
|
2360
|
+
IntegrationState,
|
2361
|
+
FlowStateService,
|
2362
|
+
FlowStateConfigurationService,
|
2363
|
+
RuntimeSettingsService,
|
1604
2364
|
{
|
1605
2365
|
provide: FORMATTING_SETTINGS_TOKEN,
|
1606
2366
|
useExisting: RuntimeSettingsService,
|
@@ -1611,6 +2371,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
1611
2371
|
args: [{
|
1612
2372
|
imports: [ConfigurationModule, FlowConfigurationModule],
|
1613
2373
|
providers: [
|
2374
|
+
ContextService,
|
2375
|
+
FlowInfoService,
|
2376
|
+
QuoteDraftService,
|
2377
|
+
ProductImagesService,
|
2378
|
+
IntegrationState,
|
2379
|
+
FlowStateService,
|
2380
|
+
FlowStateConfigurationService,
|
2381
|
+
RuntimeSettingsService,
|
1614
2382
|
{
|
1615
2383
|
provide: FORMATTING_SETTINGS_TOKEN,
|
1616
2384
|
useExisting: RuntimeSettingsService,
|
@@ -1795,5 +2563,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
1795
2563
|
* Generated bundle index. Do not edit.
|
1796
2564
|
*/
|
1797
2565
|
|
1798
|
-
export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService,
|
2566
|
+
export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationStateService, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowInfoService, FlowStateConfigurationService, FlowStateService, FlowUpdateService, IntegrationState, LineItemWorker, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, assetPredicateFn, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateConfigurationLineItem, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
|
1799
2567
|
//# sourceMappingURL=veloceapps-sdk-core.mjs.map
|