@veloceapps/sdk 3.1.16 → 3.1.17-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/bundles/veloce-sdk-core.umd.js +212 -68
  2. package/bundles/veloce-sdk-core.umd.js.map +1 -1
  3. package/bundles/veloce-sdk-runtime.umd.js +5 -6
  4. package/bundles/veloce-sdk-runtime.umd.js.map +1 -1
  5. package/bundles/veloce-sdk.umd.js +42 -35
  6. package/bundles/veloce-sdk.umd.js.map +1 -1
  7. package/cms/vendor-map.d.ts +124 -116
  8. package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +11 -17
  9. package/core/services/quote-draft.service.d.ts +41 -7
  10. package/esm2015/core/modules/configuration/services/configuration.service.js +3 -3
  11. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +43 -49
  12. package/esm2015/core/services/quote-draft.service.js +138 -22
  13. package/esm2015/runtime/components/ui-runtime/runtime.component.js +2 -2
  14. package/esm2015/runtime/execution/directives/section-script.directive.js +2 -2
  15. package/esm2015/runtime/services/cart.service.js +2 -3
  16. package/esm2015/runtime/services/section.service.js +1 -1
  17. package/esm2015/src/components/header/header.component.js +23 -19
  18. package/esm2015/src/components/header/header.types.js +1 -1
  19. package/esm2015/src/pages/legacy-product/legacy-product.component.js +4 -4
  20. package/esm2015/src/pages/product/product.component.js +8 -5
  21. package/esm2015/src/resolvers/quote.resolver.js +4 -11
  22. package/esm2015/src/services/flow.service.js +6 -5
  23. package/fesm2015/veloce-sdk-core.js +177 -66
  24. package/fesm2015/veloce-sdk-core.js.map +1 -1
  25. package/fesm2015/veloce-sdk-runtime.js +3 -4
  26. package/fesm2015/veloce-sdk-runtime.js.map +1 -1
  27. package/fesm2015/veloce-sdk.js +38 -36
  28. package/fesm2015/veloce-sdk.js.map +1 -1
  29. package/package.json +1 -1
  30. package/runtime/services/cart.service.d.ts +1 -1
  31. package/src/components/header/header.component.d.ts +5 -2
  32. package/src/components/header/header.types.d.ts +0 -1
  33. package/src/pages/product/product.component.d.ts +1 -0
  34. package/src/resolvers/quote.resolver.d.ts +0 -1
@@ -18,8 +18,8 @@ export class FlowService {
18
18
  this.integrationState
19
19
  .listen$(FlowAction.FLOW_CONFIGURE_PRODUCT)
20
20
  .pipe(takeUntil(this.cleanup$), tap(payload => {
21
- var _a, _b, _c;
22
- const productId = (_a = payload.productId) !== null && _a !== void 0 ? _a : (_c = (_b = this.quoteDraftService.quoteSnapshot) === null || _b === void 0 ? void 0 : _b.currentState.find(li => li.id === payload.lineItemId)) === null || _c === void 0 ? void 0 : _c.productId;
21
+ var _a, _b;
22
+ const productId = (_a = payload.productId) !== null && _a !== void 0 ? _a : (_b = this.quoteDraftService.currentState.find(li => li.id === payload.lineItemId)) === null || _b === void 0 ? void 0 : _b.productId;
23
23
  if (productId) {
24
24
  this.flowRouterService.navigateToProductConfiguration(productId, payload.lineItemId);
25
25
  }
@@ -39,7 +39,7 @@ export class FlowService {
39
39
  if (!lineItem) {
40
40
  return of(undefined);
41
41
  }
42
- const currentState = this.flowConfigurationService.getSnapshot();
42
+ const currentState = this.quoteDraftService.currentState;
43
43
  const isNewLineItem = currentState.every(li => li.id !== lineItem.id);
44
44
  let updatedState;
45
45
  if (isNewLineItem) {
@@ -48,7 +48,8 @@ export class FlowService {
48
48
  else {
49
49
  updatedState = currentState.map(li => (li.id === lineItem.id ? lineItem : li));
50
50
  }
51
- return this.flowConfigurationService.calculate$(updatedState);
51
+ this.quoteDraftService.setCurrentLineItemState(updatedState);
52
+ return this.flowConfigurationService.calculate$();
52
53
  }), tap(() => {
53
54
  this.configurationService.hasUnsavedChanges = false;
54
55
  this.flowRouterService.navigateToShoppingCart();
@@ -64,4 +65,4 @@ FlowService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version:
64
65
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowService, decorators: [{
65
66
  type: Injectable
66
67
  }], ctorParameters: function () { return [{ type: i1.IntegrationState }, { type: i2.FlowRouterService }, { type: i3.QuoteDraftService }, { type: i3.ConfigurationService }, { type: i3.FlowConfigurationService }]; } });
67
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmxvdy5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vbGlicy9zZGsvc3JjL3NlcnZpY2VzL2Zsb3cuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRTNDLE9BQU8sRUFBRSxVQUFVLEVBQW9CLE1BQU0saUJBQWlCLENBQUM7QUFFL0QsT0FBTyxFQUFFLEVBQUUsRUFBRSxPQUFPLEVBQUUsU0FBUyxFQUFFLFNBQVMsRUFBRSxHQUFHLEVBQUUsTUFBTSxNQUFNLENBQUM7Ozs7O0FBSTlELE1BQU0sT0FBTyxXQUFXO0lBR3RCLFlBQ1UsZ0JBQWtDLEVBQ2xDLGlCQUFvQyxFQUNwQyxpQkFBb0MsRUFDcEMsb0JBQTBDLEVBQzFDLHdCQUFrRDtRQUpsRCxxQkFBZ0IsR0FBaEIsZ0JBQWdCLENBQWtCO1FBQ2xDLHNCQUFpQixHQUFqQixpQkFBaUIsQ0FBbUI7UUFDcEMsc0JBQWlCLEdBQWpCLGlCQUFpQixDQUFtQjtRQUNwQyx5QkFBb0IsR0FBcEIsb0JBQW9CLENBQXNCO1FBQzFDLDZCQUF3QixHQUF4Qix3QkFBd0IsQ0FBMEI7UUFQcEQsYUFBUSxHQUFHLElBQUksT0FBTyxFQUFRLENBQUM7SUFRcEMsQ0FBQztJQUVHLGlCQUFpQjtRQUN0QixJQUFJLENBQUMsZ0JBQWdCO2FBQ2xCLE9BQU8sQ0FBOEMsVUFBVSxDQUFDLHNCQUFzQ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ApXG4gICAgICAuc3Vic2NyaWJlKCk7XG4gIH1cblxuICBwdWJsaWMgY2xlYW51cCgpOiB2b2lkIHtcbiAgICB0aGlzLmNsZWFudXAkLm5leHQoKTtcbiAgfVxufVxuIl19
@@ -1,8 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, NgModule } from '@angular/core';
3
3
  import { UUID, ConfigurationContext, ConfigurationContextMode, RuntimeModel, SalesforceIdUtils, ConfigurationMode } from '@veloce/core';
4
- import { BehaviorSubject, map as map$1, distinctUntilChanged, catchError, of, tap as tap$1, zip, combineLatest, throwError, shareReplay, noop, switchMap as switchMap$1 } from 'rxjs';
5
- import { filter, tap, map, take, first, catchError as catchError$1, switchMap, finalize } from 'rxjs/operators';
4
+ import { BehaviorSubject, map as map$1, distinctUntilChanged, catchError, of, tap as tap$1, zip, noop, combineLatest, throwError, shareReplay as shareReplay$1, switchMap as switchMap$1 } from 'rxjs';
5
+ import { filter, tap, map, switchMap, take, shareReplay, first, catchError as catchError$1, finalize } from 'rxjs/operators';
6
6
  import * as i1 from '@veloce/api';
7
7
  import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloce/api';
8
8
  import { merge, flatten, sortBy, cloneDeep } from 'lodash';
@@ -100,57 +100,119 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
100
100
  }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
101
101
 
102
102
  class QuoteDraftService {
103
- constructor(context, quoteApiService, priceApiService) {
103
+ constructor(context, quoteApiService, priceApiService, sfApiService) {
104
104
  this.context = context;
105
105
  this.quoteApiService = quoteApiService;
106
106
  this.priceApiService = priceApiService;
107
+ this.sfApiService = sfApiService;
107
108
  this.quoteSubj$ = new BehaviorSubject(null);
108
109
  this.resetSubj$ = new BehaviorSubject(true);
109
- this.priceLists = [];
110
+ /**
111
+ * @key pricePlanId
112
+ * @value priceListId
113
+ */
114
+ this.planIdsMap = {};
110
115
  this.isInitialized = false;
116
+ this.allPriceLists = [];
117
+ this.assetPriceLists = [];
111
118
  this.hasUnsavedChanges = false;
112
119
  this.reset$ = this.resetSubj$.asObservable();
120
+ this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), filter((priceList) => Boolean(priceList)));
113
121
  }
114
122
  reset() {
115
123
  this.resetSubj$.next(true);
116
124
  this.quoteSubj$.next(null);
117
125
  }
118
126
  init(quoteId, params) {
119
- return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists(), this.context.resolve$()).pipe(tap(([quote, priceLists, context]) => {
127
+ return zip(this.context.resolve$(), this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([context, quote, allPriceLists]) => {
128
+ this.allPriceLists = allPriceLists;
120
129
  this.quoteSubj$.next(quote);
121
- this.priceLists = priceLists;
122
- this.quotePriceList = priceLists.find(p => p.id === context.properties.PriceListId);
123
130
  this.context.update(Object.assign(Object.assign(Object.assign({}, context), quote.context), { properties: Object.assign(Object.assign({}, context.properties), quote.context.properties) }));
124
- }), map(() => {
125
- this.isInitialized = true;
126
- }), take(1));
131
+ }), switchMap(() => this.populateActivePriceLists$()), map(() => noop()), tap(() => (this.isInitialized = true)), take(1));
127
132
  }
128
133
  setCurrentLineItemState(lineItems) {
129
- const quote = this.quoteSubj$.value;
130
- if (!quote) {
134
+ const quoteDraft = this.quoteSubj$.value;
135
+ if (!quoteDraft) {
131
136
  return;
132
137
  }
133
- this.quoteSubj$.next(Object.assign(Object.assign({}, quote), { currentState: lineItems }));
138
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
134
139
  this.markAsUpdated();
135
140
  }
141
+ updateQuoteDraft(update) {
142
+ const quoteDraft = this.quoteSubj$.value;
143
+ if (!quoteDraft) {
144
+ return;
145
+ }
146
+ if (update.context) {
147
+ this.context.update(update.context);
148
+ }
149
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
150
+ }
136
151
  updateByPriceSummary(priceSummary) {
137
- const quote = this.quoteSubj$.value;
138
- if (!quote) {
152
+ const quoteDraft = this.quoteSubj$.value;
153
+ if (!quoteDraft) {
139
154
  return;
140
155
  }
141
- this.quoteSubj$.next(Object.assign(Object.assign({}, quote), { currentState: priceSummary.lineItems, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
156
+ const updatedCurrentState = this.currentState.map(lineItem => {
157
+ const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
158
+ return updated !== null && updated !== void 0 ? updated : lineItem;
159
+ });
160
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
142
161
  this.markAsUpdated();
143
162
  }
144
- get quote$() {
145
- return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteSnapshot), filter((quote) => Boolean(quote)));
163
+ get quoteDraft$() {
164
+ return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
146
165
  }
147
- get quoteSnapshot() {
166
+ get quoteDraft() {
148
167
  const quote = this.quoteSubj$.value;
149
168
  if (!quote) {
150
169
  return null;
151
170
  }
152
171
  return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
153
172
  }
173
+ get currentState$() {
174
+ return this.quoteDraft$.pipe(map(quote => quote.currentState));
175
+ }
176
+ get currentState() {
177
+ var _a, _b;
178
+ return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
179
+ }
180
+ /**
181
+ * Stream of activeCurrentState
182
+ */
183
+ get activeCurrentState$() {
184
+ return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
185
+ }
186
+ /**
187
+ * activeCurrentState is currentState passed through additional filters
188
+ */
189
+ get activeCurrentState() {
190
+ var _a, _b;
191
+ const ctx = this.context.resolve();
192
+ let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
193
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
194
+ currentState = this.filterByActivePriceList(currentState);
195
+ }
196
+ return currentState;
197
+ }
198
+ /**
199
+ * Stream of activeInitialState
200
+ */
201
+ get activeInitialState$() {
202
+ return this.quoteDraft$.pipe(map(() => this.activeInitialState));
203
+ }
204
+ /**
205
+ * activeInitialState is initialState passed through additional filters
206
+ */
207
+ get activeInitialState() {
208
+ var _a, _b;
209
+ const ctx = this.context.resolve();
210
+ let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
211
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
212
+ initialState = this.filterByActivePriceList(initialState);
213
+ }
214
+ return initialState;
215
+ }
154
216
  get isStandalone() {
155
217
  return this.context.resolve().properties.standalone === 'true';
156
218
  }
@@ -167,18 +229,72 @@ class QuoteDraftService {
167
229
  }
168
230
  return false;
169
231
  }
232
+ updateActivePriceList(priceListId) {
233
+ this.context.update({ properties: { PriceListId: priceListId } });
234
+ }
235
+ /**
236
+ * Query PricePlan infos for the assets
237
+ * TODO: remove when backend will send priceListId for assets
238
+ */
239
+ getAssetsPlanInfos$(quoteDraft) {
240
+ var _a;
241
+ const pricePlanIds = (_a = quoteDraft === null || quoteDraft === void 0 ? void 0 : quoteDraft.initialState.map(li => li.planId).filter((id) => typeof id === 'string').filter((item, i, arr) => arr.indexOf(item) === i)) !== null && _a !== void 0 ? _a : [];
242
+ if (!pricePlanIds.length) {
243
+ return of([]);
244
+ }
245
+ const priceListIdFieldName = 'VELOCPQ__PriceListId__c';
246
+ const searchRequest = {
247
+ rawCondition: `Id in ('${pricePlanIds.join("','")}')`,
248
+ fields: ['Id', priceListIdFieldName],
249
+ };
250
+ return this.sfApiService
251
+ .query(searchRequest, 'VELOCPQ__PricePlan__c')
252
+ .pipe(map(result => result.map(item => ({ id: item.Id, priceListId: item[priceListIdFieldName] })).filter(Boolean)));
253
+ }
254
+ populateActivePriceLists$() {
255
+ const ctx = this.context.resolve();
256
+ const quoteDraft = this.quoteDraft;
257
+ if (!quoteDraft) {
258
+ return of(undefined);
259
+ }
260
+ // In ACCOUNT mode populate price lists from related assets
261
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
262
+ return this.getAssetsPlanInfos$(quoteDraft).pipe(tap(pricePlanInfos => {
263
+ this.assetPriceLists = pricePlanInfos.map(item => {
264
+ var _a, _b;
265
+ return ({
266
+ id: item.priceListId,
267
+ name: (_b = (_a = this.allPriceLists.find(priceList => priceList.id === item.priceListId)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '',
268
+ });
269
+ });
270
+ this.planIdsMap = pricePlanInfos.reduce((trunk, item) => (Object.assign(Object.assign({}, trunk), { [item.id]: item.priceListId })), {});
271
+ const activePriceList = this.assetPriceLists[0];
272
+ this.updateActivePriceList(activePriceList.id);
273
+ // Update PriceListId in context properties
274
+ // TODO: remove it when backend will have such logic
275
+ if (this.assetPriceLists.length) {
276
+ this.context.update({ properties: { PriceListId: activePriceList.id } });
277
+ }
278
+ }), map(noop));
279
+ }
280
+ return of(undefined);
281
+ }
282
+ filterByActivePriceList(lineItems) {
283
+ const ctx = this.context.resolve();
284
+ return lineItems.filter(li => !li.planId || this.planIdsMap[li.planId] === ctx.properties.PriceListId);
285
+ }
170
286
  markAsUpdated() {
171
287
  if (this.isInitialized && !this.hasUnsavedChanges) {
172
288
  this.hasUnsavedChanges = true;
173
289
  }
174
290
  }
175
291
  }
176
- QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
292
+ QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }, { token: i1.SalesforceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
177
293
  QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
178
294
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, decorators: [{
179
295
  type: Injectable,
180
296
  args: [{ providedIn: 'root' }]
181
- }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
297
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }, { type: i1.SalesforceApiService }]; } });
182
298
 
183
299
  class RuntimeContextService {
184
300
  constructor(configurationApiService, messageService) {
@@ -498,7 +614,7 @@ class ConfigurationService {
498
614
  this.states = Object.assign(Object.assign({}, this.states), update);
499
615
  }
500
616
  get() {
501
- return this.lineItem.asObservable().pipe(shareReplay());
617
+ return this.lineItem.asObservable().pipe(shareReplay$1());
502
618
  }
503
619
  getSnapshot() {
504
620
  return this.lineItem.value ? Object.assign({}, this.lineItem.value) : undefined;
@@ -532,8 +648,6 @@ class ConfigurationService {
532
648
  const qty = (_d = this.runtimeService.initializationProps) === null || _d === void 0 ? void 0 : _d.defaultQty;
533
649
  const lineItem = (_e = this.states.configurableRamp) !== null && _e !== void 0 ? _e : getDefaultLineItem(runtimeContext, uiDefinitionProperties, qty);
534
650
  const configurationRequest = this.createRequest(lineItem);
535
- configurationRequest.lineItems = this.states.currentState || [];
536
- configurationRequest.asset = this.states.asset;
537
651
  const mainPricingEnabled = (_f = runtimeContext.properties) === null || _f === void 0 ? void 0 : _f.PricingEnabled;
538
652
  const pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
539
653
  return this.configurationApiService
@@ -565,6 +679,8 @@ class ConfigurationService {
565
679
  step: !this.lineItem.value ? RuntimeStep.START : RuntimeStep.UPDATE,
566
680
  attributeDomainMode: 'ALL',
567
681
  context: this.contextService.resolve(),
682
+ lineItems: this.states.currentState || [],
683
+ asset: this.states.asset,
568
684
  };
569
685
  }
570
686
  showInactiveProductsConfirmation() {
@@ -709,70 +825,65 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
709
825
  }] });
710
826
 
711
827
  class FlowConfigurationService {
712
- constructor(priceApiService, contextService, quoteDraftService, messageService, updateService, configurationService) {
713
- this.priceApiService = priceApiService;
828
+ constructor(proceduresApiService, contextService, quoteDraftService, updateService, configurationService) {
829
+ this.proceduresApiService = proceduresApiService;
714
830
  this.contextService = contextService;
715
831
  this.quoteDraftService = quoteDraftService;
716
- this.messageService = messageService;
717
832
  this.updateService = updateService;
718
833
  this.configurationService = configurationService;
719
- this.charges = new BehaviorSubject({});
720
- this.bounceBackUpdate$ = new BehaviorSubject(true);
721
834
  }
722
- reset() {
723
- this.charges.next({});
724
- }
725
- initialize$() {
726
- var _a;
727
- (_a = this.resetSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
728
- this.resetSubscription = this.quoteDraftService.reset$.subscribe(() => this.reset());
729
- return this.calculate$(this.getSnapshot()).pipe(map$1(noop));
730
- }
731
- calculate$(currentState) {
732
- const context = this.contextService.resolve();
733
- return this.priceApiService.calculate({ context, currentState }).pipe(tap$1((result) => {
734
- this.quoteDraftService.updateByPriceSummary(result);
735
- this.charges.next(result.charges);
736
- if (context) {
737
- this.contextService.update({ properties: context.properties });
738
- }
739
- }), this.handleError());
835
+ calculate$() {
836
+ const quoteDraft = this.quoteDraftService.quoteDraft;
837
+ if (!quoteDraft || !quoteDraft.currentState.length) {
838
+ return of(undefined);
839
+ }
840
+ return this.proceduresApiService.apply$(quoteDraft).pipe(tap$1(result => this.quoteDraftService.updateQuoteDraft(result)), map$1(noop));
740
841
  }
741
- calculate(currentState) {
742
- this.calculate$(currentState).subscribe();
842
+ calculate() {
843
+ this.calculate$().subscribe();
743
844
  }
744
845
  update$(updates) {
745
- const lineItems = cloneDeep(this.getSnapshot());
746
- return of([]).pipe(tap$1(() => this.updateService.update(lineItems, updates)), this.handleError(), switchMap$1(() => this.calculate$(lineItems)));
846
+ const currentState = this.quoteDraftService.currentState;
847
+ return of([]).pipe(tap$1(() => {
848
+ const updatedState = cloneDeep(currentState);
849
+ this.updateService.update(updatedState, updates);
850
+ this.quoteDraftService.setCurrentLineItemState(updatedState);
851
+ }), switchMap$1(() => this.calculate$()), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack(currentState));
747
852
  }
748
853
  update(updates) {
749
854
  this.update$(updates).subscribe();
750
855
  }
751
856
  delete$(ids) {
752
- return of([]).pipe(map$1(() => ids.reduce((result, id) => this.updateService.delete(result, id), this.getSnapshot())), this.handleError(), switchMap$1(currentState => this.calculate$(currentState)));
857
+ const currentState = this.quoteDraftService.currentState;
858
+ return of([]).pipe(tap$1(() => {
859
+ const updatedState = ids.reduce((result, id) => this.updateService.delete(result, id), currentState);
860
+ this.quoteDraftService.setCurrentLineItemState(updatedState);
861
+ }), switchMap$1(() => this.calculate$()), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack(currentState));
753
862
  }
754
863
  delete(ids) {
755
864
  this.delete$(ids).subscribe();
756
865
  }
757
- get() {
758
- return combineLatest([this.quoteDraftService.quote$, this.bounceBackUpdate$]).pipe(map$1(([quoteDraft]) => quoteDraft.currentState), shareReplay());
866
+ addTerm$(term) {
867
+ const currentState = this.quoteDraftService.currentState;
868
+ return of([]).pipe(tap$1(() => this.quoteDraftService.setCurrentLineItemState([...currentState, term])), switchMap$1(() => this.calculate$()), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack(currentState));
759
869
  }
760
870
  addToCart$(productId, qty) {
761
- return this.configurationService.configureExternal$(productId, qty).pipe(tap$1(lineItem => {
762
- var _a, _b;
763
- const currentState = (_b = (_a = this.quoteDraftService.quoteSnapshot) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
764
- this.quoteDraftService.setCurrentLineItemState([...currentState, lineItem]);
765
- }), map$1(noop));
871
+ const currentState = this.quoteDraftService.currentState;
872
+ return this.configurationService.configureExternal$(productId, qty).pipe(tap$1(lineItem => this.quoteDraftService.setCurrentLineItemState([...currentState, lineItem])), switchMap$1(() => this.calculate$()), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack(currentState));
873
+ }
874
+ get() {
875
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
766
876
  }
767
877
  getSnapshot() {
768
878
  var _a, _b;
769
- return (_b = (_a = this.quoteDraftService.quoteSnapshot) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
879
+ return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
770
880
  }
771
881
  get charges$() {
772
- return this.charges.asObservable();
882
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(({ charges }) => charges));
773
883
  }
774
884
  get chargesSnapshot() {
775
- return this.charges.value;
885
+ var _a, _b;
886
+ return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.charges) !== null && _b !== void 0 ? _b : {};
776
887
  }
777
888
  get contextSnapshot() {
778
889
  return this.contextService.resolve();
@@ -780,22 +891,22 @@ class FlowConfigurationService {
780
891
  get context$() {
781
892
  return this.contextService.resolve$();
782
893
  }
783
- handleError() {
894
+ handleErrorAndBounceBack(stateToRestore) {
784
895
  return (source$) => {
785
896
  return source$.pipe(catchError(error => {
786
897
  console.error(error);
787
898
  // bounce back if configuration call has failed
788
- this.bounceBackUpdate$.next(true);
899
+ this.quoteDraftService.setCurrentLineItemState(stateToRestore);
789
900
  return throwError(() => error);
790
901
  }));
791
902
  };
792
903
  }
793
904
  }
794
- FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.PriceApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: i2.MessageService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
905
+ FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
795
906
  FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService });
796
907
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, decorators: [{
797
908
  type: Injectable
798
- }], ctorParameters: function () { return [{ type: i1.PriceApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: i2.MessageService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
909
+ }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
799
910
 
800
911
  class FlowConfigurationModule {
801
912
  }