@veloceapps/sdk 6.0.0-3 → 6.0.0-31

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 (150) hide show
  1. package/bundles/veloceapps-sdk-cms.umd.js +144 -72
  2. package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
  3. package/bundles/veloceapps-sdk-core.umd.js +724 -611
  4. package/bundles/veloceapps-sdk-core.umd.js.map +1 -1
  5. package/bundles/veloceapps-sdk-runtime.umd.js +209 -142
  6. package/bundles/veloceapps-sdk-runtime.umd.js.map +1 -1
  7. package/bundles/veloceapps-sdk.umd.js +360 -296
  8. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  9. package/cms/vendor-map.d.ts +26 -14
  10. package/core/modules/configuration/services/configuration-runtime.service.d.ts +2 -4
  11. package/core/modules/configuration/services/configuration.service.d.ts +6 -4
  12. package/core/modules/configuration/types/configuration-runtime.types.d.ts +0 -2
  13. package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +6 -3
  14. package/core/services/metric-calculation/metric-calculation.service.d.ts +5 -1
  15. package/core/services/quote-draft.service.d.ts +2 -2
  16. package/core/types/index.d.ts +0 -1
  17. package/core/utils/line-item.utils.d.ts +2 -0
  18. package/esm2015/cms/components/element-children/element-children.component.js +3 -3
  19. package/esm2015/cms/components/element-children/element-children.module.js +4 -4
  20. package/esm2015/cms/components/element-renderer/element-renderer.component.js +3 -3
  21. package/esm2015/cms/components/element-renderer/element-renderer.module.js +4 -4
  22. package/esm2015/cms/components/plugin.component.js +3 -3
  23. package/esm2015/cms/components/preview/preview.component.js +3 -3
  24. package/esm2015/cms/components/preview/preview.module.js +4 -4
  25. package/esm2015/cms/directives/custom-template.directive.js +3 -3
  26. package/esm2015/cms/launcher.module.js +4 -4
  27. package/esm2015/cms/modules/federated/federated.component.js +3 -3
  28. package/esm2015/cms/modules/federated/federated.module.js +4 -4
  29. package/esm2015/cms/plugins/configuration.plugin.js +3 -3
  30. package/esm2015/cms/plugins/io.plugin.js +3 -3
  31. package/esm2015/cms/plugins/script.plugin.js +3 -3
  32. package/esm2015/cms/services/dynamic-module.service.js +3 -3
  33. package/esm2015/cms/services/element-context.service.js +3 -3
  34. package/esm2015/cms/services/integration.state.js +3 -3
  35. package/esm2015/cms/services/io-provider.service.js +3 -3
  36. package/esm2015/cms/services/launcher.service.js +6 -5
  37. package/esm2015/cms/services/templates.service.js +3 -3
  38. package/esm2015/cms/vendor-map.js +11 -4
  39. package/esm2015/core/core.module.js +4 -4
  40. package/esm2015/core/modules/configuration/configuration.module.js +4 -4
  41. package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +5 -10
  42. package/esm2015/core/modules/configuration/services/configuration.service.js +27 -24
  43. package/esm2015/core/modules/configuration/services/runtime-context.service.js +3 -3
  44. package/esm2015/core/modules/configuration/types/configuration-runtime.types.js +1 -1
  45. package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +4 -4
  46. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +17 -9
  47. package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +3 -3
  48. package/esm2015/core/services/context.service.js +3 -3
  49. package/esm2015/core/services/metric-calculation/metric-calculation.service.js +18 -9
  50. package/esm2015/core/services/product-images.service.js +3 -3
  51. package/esm2015/core/services/quote-draft.service.js +7 -7
  52. package/esm2015/core/types/index.js +1 -2
  53. package/esm2015/core/utils/line-item.utils.js +27 -11
  54. package/esm2015/runtime/components/component-preview/component-preview.component.js +4 -4
  55. package/esm2015/runtime/components/section-renderer/section-renderer.component.js +3 -3
  56. package/esm2015/runtime/components/ui-runtime/runtime.component.js +3 -3
  57. package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
  58. package/esm2015/runtime/execution/components/children-placeholder/children-placeholder.component.js +6 -6
  59. package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +3 -3
  60. package/esm2015/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.js +3 -3
  61. package/esm2015/runtime/execution/components/federated/federated.component.js +3 -3
  62. package/esm2015/runtime/execution/components/velo-attribute/velo-attribute.component.js +3 -3
  63. package/esm2015/runtime/execution/components/velo-multiselect/velo-multiselect.component.js +3 -3
  64. package/esm2015/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.js +3 -3
  65. package/esm2015/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.js +3 -3
  66. package/esm2015/runtime/execution/components/velo-port-radio/velo-port-radio.component.js +3 -3
  67. package/esm2015/runtime/execution/components/velo-type/velo-type.component.js +3 -3
  68. package/esm2015/runtime/execution/directives/section-script.directive.js +3 -3
  69. package/esm2015/runtime/execution/directives/sf-query.directive.js +3 -3
  70. package/esm2015/runtime/execution/directives/velo-attribute.directive.js +3 -3
  71. package/esm2015/runtime/execution/directives/velo-port.directive.js +18 -18
  72. package/esm2015/runtime/execution/directives/vl-approval.directive.js +3 -3
  73. package/esm2015/runtime/execution/directives/vl-document-attachments.directive.js +3 -3
  74. package/esm2015/runtime/execution/directives/vl-document-templates.directive.js +3 -3
  75. package/esm2015/runtime/execution/directives/vl-quote.directive.js +4 -4
  76. package/esm2015/runtime/execution/directives/vl-ramp.directive.js +3 -3
  77. package/esm2015/runtime/execution/runtime-execution.module.js +4 -4
  78. package/esm2015/runtime/runtime.module.js +4 -4
  79. package/esm2015/runtime/services/cart.service.js +3 -3
  80. package/esm2015/runtime/services/collapsible-state.service.js +3 -3
  81. package/esm2015/runtime/services/configuration.service.js +4 -4
  82. package/esm2015/runtime/services/current-state.service.js +3 -3
  83. package/esm2015/runtime/services/form-scope.service.js +3 -3
  84. package/esm2015/runtime/services/product-model-cache.service.js +3 -3
  85. package/esm2015/runtime/services/runtime-context.service.js +3 -3
  86. package/esm2015/runtime/services/runtime-form.service.js +3 -3
  87. package/esm2015/runtime/services/runtime.service.js +4 -4
  88. package/esm2015/runtime/services/section-helper.service.js +3 -3
  89. package/esm2015/runtime/services/section-scope.service.js +3 -3
  90. package/esm2015/runtime/services/section-store.service.js +3 -3
  91. package/esm2015/runtime/services/section.service.js +6 -6
  92. package/esm2015/runtime/types/index.js +2 -1
  93. package/esm2015/runtime/types/quote-states.types.js +2 -0
  94. package/esm2015/src/components/dialog/dialog.component.js +3 -3
  95. package/esm2015/src/components/dialog/dialog.module.js +4 -4
  96. package/esm2015/src/components/doc-gen/doc-gen.component.js +3 -3
  97. package/esm2015/src/components/doc-gen/doc-gen.module.js +4 -4
  98. package/esm2015/src/components/header/cart-overlay/cart-preview.component.js +3 -3
  99. package/esm2015/src/components/header/cart-overlay/cart-preview.module.js +4 -4
  100. package/esm2015/src/components/header/header.component.js +6 -6
  101. package/esm2015/src/components/header/header.module.js +4 -4
  102. package/esm2015/src/components/header/metrics/metrics.component.js +79 -67
  103. package/esm2015/src/components/header/metrics/metrics.definitions.js +1 -8
  104. package/esm2015/src/components/header/metrics/metrics.module.js +4 -4
  105. package/esm2015/src/flow-routing.module.js +4 -4
  106. package/esm2015/src/flow.component.js +3 -3
  107. package/esm2015/src/flow.module.js +4 -4
  108. package/esm2015/src/guards/context.guard.js +3 -3
  109. package/esm2015/src/guards/product-unload.guard.js +3 -3
  110. package/esm2015/src/guards/root.guard.js +3 -3
  111. package/esm2015/src/pages/catalog/catalog.component.js +3 -3
  112. package/esm2015/src/pages/catalog/catalog.module.js +4 -4
  113. package/esm2015/src/pages/debug/debug.component.js +3 -3
  114. package/esm2015/src/pages/debug/debug.module.js +4 -4
  115. package/esm2015/src/pages/empty-account/empty-account.component.js +3 -3
  116. package/esm2015/src/pages/empty-account/empty-account.module.js +4 -4
  117. package/esm2015/src/pages/legacy-product/legacy-product.component.js +4 -4
  118. package/esm2015/src/pages/legacy-product/legacy-product.module.js +4 -4
  119. package/esm2015/src/pages/product/product.component.js +5 -12
  120. package/esm2015/src/pages/product/product.module.js +4 -4
  121. package/esm2015/src/pages/record-not-found/record-not-found.component.js +3 -3
  122. package/esm2015/src/pages/record-not-found/record-not-found.module.js +4 -4
  123. package/esm2015/src/pages/remote/remote.component.js +5 -8
  124. package/esm2015/src/pages/remote/remote.module.js +4 -4
  125. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +3 -3
  126. package/esm2015/src/pages/shopping-cart/shopping-cart.module.js +4 -4
  127. package/esm2015/src/resolvers/flow.resolver.js +3 -3
  128. package/esm2015/src/resolvers/quote.resolver.js +8 -8
  129. package/esm2015/src/services/doc-gen.service.js +3 -3
  130. package/esm2015/src/services/flow-dialog.service.js +3 -3
  131. package/esm2015/src/services/flow-router.service.js +3 -3
  132. package/esm2015/src/services/flow.service.js +3 -3
  133. package/esm2015/src/utils/flow.utils.js +3 -3
  134. package/fesm2015/veloceapps-sdk-cms.js +74 -67
  135. package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
  136. package/fesm2015/veloceapps-sdk-core.js +520 -490
  137. package/fesm2015/veloceapps-sdk-core.js.map +1 -1
  138. package/fesm2015/veloceapps-sdk-runtime.js +138 -138
  139. package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
  140. package/fesm2015/veloceapps-sdk.js +238 -242
  141. package/fesm2015/veloceapps-sdk.js.map +1 -1
  142. package/package.json +1 -1
  143. package/runtime/services/configuration.service.d.ts +2 -1
  144. package/runtime/services/runtime.service.d.ts +2 -1
  145. package/runtime/types/index.d.ts +1 -0
  146. package/{core → runtime}/types/quote-states.types.d.ts +0 -0
  147. package/src/components/header/metrics/metrics.component.d.ts +15 -6
  148. package/src/components/header/metrics/metrics.definitions.d.ts +0 -3
  149. package/src/pages/product/product.component.d.ts +0 -1
  150. package/esm2015/core/types/quote-states.types.js +0 -2
@@ -1,14 +1,14 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, NgModule } from '@angular/core';
3
- import { UUID, ConfigurationContext, ConfigurationContextMode, RuntimeModel, SalesforceIdUtils, ConfigurationMode, ChargeGroupUtils } from '@veloceapps/core';
4
- import { BehaviorSubject, zip, noop, combineLatest, Subject, take as take$1, map as map$1, distinctUntilChanged, catchError, of, tap as tap$1, throwError, shareReplay as shareReplay$1, switchMap as switchMap$1 } from 'rxjs';
5
- import { filter, tap, map, switchMap, skip, take, shareReplay, first, catchError as catchError$1, finalize } from 'rxjs/operators';
3
+ import { UUID, ConfigurationContext, RuntimeModel, ConfigurationContextMode, SalesforceIdUtils, ConfigurationMode, ChargeGroupUtils } from '@veloceapps/core';
4
+ import { BehaviorSubject, combineLatest, zip, noop, throwError, shareReplay as shareReplay$1, tap as tap$1, map as map$2, of, switchMap as switchMap$1, catchError as catchError$1, Subject, take as take$1, distinctUntilChanged } from 'rxjs';
5
+ import { filter, tap, map, first, switchMap, skip, take, shareReplay, catchError, finalize } from 'rxjs/operators';
6
6
  import * as i1 from '@veloceapps/api';
7
7
  import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloceapps/api';
8
- import { merge, isEqual, uniq, flatten, sortBy, map as map$2, cloneDeep } from 'lodash';
8
+ import { merge, flatten, sortBy, map as map$1, isEqual, cloneDeep, uniq } from 'lodash';
9
9
  import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
10
- import * as i4 from 'primeng/api';
11
- import * as i5 from 'primeng/dynamicdialog';
10
+ import * as i5 from 'primeng/api';
11
+ import * as i6 from 'primeng/dynamicdialog';
12
12
  import moment from 'moment';
13
13
 
14
14
  const getDefaultLineItem = (context, uiDefinitionProperties, qty = 1) => {
@@ -72,357 +72,13 @@ class ContextService {
72
72
  this.context.next(null);
73
73
  }
74
74
  }
75
- ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
76
- ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, providedIn: 'root' });
77
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, decorators: [{
75
+ ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
76
+ ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, providedIn: 'root' });
77
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, decorators: [{
78
78
  type: Injectable,
79
79
  args: [{ providedIn: 'root' }]
80
80
  }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
81
81
 
82
- function calculateMetricByMethod(lineItems, metric, method) {
83
- const items = getLineItemsByMethod(lineItems, method);
84
- return items.reduce((acc, li) => {
85
- let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
86
- if (method === 'avg' && li.length > 0) {
87
- value /= li.length;
88
- }
89
- return acc + value;
90
- }, 0);
91
- }
92
- function getLineItemsByMethod(lineItems, method) {
93
- switch (method) {
94
- case 'first': {
95
- return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
96
- }
97
- case 'last': {
98
- const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
99
- const products = rootTermItems.map(lineItem => [
100
- lineItem,
101
- ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
102
- ]);
103
- return products
104
- .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
105
- .filter((li) => Boolean(li))
106
- .map(item => [item]);
107
- }
108
- case 'avg': {
109
- const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
110
- return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
111
- }
112
- case 'sum': {
113
- return lineItems.map(item => [item]);
114
- }
115
- default: {
116
- return lineItems.map(item => [item]);
117
- }
118
- }
119
- }
120
- function getDateValue(date) {
121
- return date ? new Date(date).getTime() : 0;
122
- }
123
-
124
- class QuoteDraftService {
125
- constructor(context, quoteApiService, priceApiService) {
126
- this.context = context;
127
- this.quoteApiService = quoteApiService;
128
- this.priceApiService = priceApiService;
129
- this.quoteSubj$ = new BehaviorSubject(null);
130
- this.resetSubj$ = new BehaviorSubject(true);
131
- this.isInitializedSubj$ = new BehaviorSubject(false);
132
- this.initialCurrentState = [];
133
- this._hasUnsavedChanges = false;
134
- this.allPriceLists = [];
135
- this.assetPriceLists = [];
136
- this.reset$ = this.resetSubj$.asObservable();
137
- 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));
138
- this.isInitializedSubj$
139
- .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
140
- .subscribe();
141
- }
142
- get isInitialized() {
143
- return this.isInitializedSubj$.getValue();
144
- }
145
- set isInitialized(value) {
146
- if (this.isInitialized !== value) {
147
- this.isInitializedSubj$.next(value);
148
- }
149
- }
150
- get hasUnsavedChanges() {
151
- return this._hasUnsavedChanges;
152
- }
153
- set hasUnsavedChanges(value) {
154
- var _a, _b;
155
- this._hasUnsavedChanges = value;
156
- if (!this._hasUnsavedChanges) {
157
- this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
158
- }
159
- }
160
- get hasAssets$() {
161
- return this.quoteSubj$.pipe(map(() => this.hasAssets));
162
- }
163
- get hasAssets() {
164
- const quoteDraft = this.quoteSubj$.value;
165
- return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
166
- }
167
- reset() {
168
- this.resetSubj$.next(true);
169
- this.quoteSubj$.next(null);
170
- this.hasUnsavedChanges = false;
171
- }
172
- init(quoteId, params) {
173
- return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
174
- this.allPriceLists = allPriceLists;
175
- this.quoteSubj$.next(quote);
176
- this.context.update(quote.context);
177
- this.populateActivePriceLists$();
178
- }), map(() => noop()), take(1));
179
- }
180
- setCurrentLineItemState(lineItems) {
181
- const quoteDraft = this.quoteSubj$.value;
182
- if (!quoteDraft) {
183
- return;
184
- }
185
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
186
- }
187
- updateQuoteDraft(update) {
188
- const quoteDraft = this.quoteSubj$.value;
189
- if (!quoteDraft) {
190
- return;
191
- }
192
- if (update.context) {
193
- this.context.set(update.context);
194
- }
195
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
196
- }
197
- updateByPriceSummary(priceSummary) {
198
- const quoteDraft = this.quoteSubj$.value;
199
- if (!quoteDraft) {
200
- return;
201
- }
202
- const updatedCurrentState = this.currentState.map(lineItem => {
203
- const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
204
- return updated !== null && updated !== void 0 ? updated : lineItem;
205
- });
206
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
207
- }
208
- get quoteDraft$() {
209
- return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
210
- }
211
- get quoteDraft() {
212
- const quote = this.quoteSubj$.value;
213
- if (!quote) {
214
- return null;
215
- }
216
- return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
217
- }
218
- get quoteDraftForActivePriceList() {
219
- const quoteDraft = this.quoteDraft;
220
- if (!quoteDraft) {
221
- return null;
222
- }
223
- return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
224
- }
225
- get currentState$() {
226
- return this.quoteDraft$.pipe(map(quote => quote.currentState));
227
- }
228
- get currentState() {
229
- var _a, _b;
230
- return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
231
- }
232
- /**
233
- * Stream of activeCurrentState
234
- */
235
- get activeCurrentState$() {
236
- return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
237
- }
238
- /**
239
- * activeCurrentState is currentState passed through additional filters
240
- */
241
- get activeCurrentState() {
242
- var _a, _b;
243
- let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
244
- currentState = this.filterByActivePriceList(currentState);
245
- return currentState;
246
- }
247
- /**
248
- * Stream of activeInitialState
249
- */
250
- get activeInitialState$() {
251
- return this.quoteDraft$.pipe(map(() => this.activeInitialState));
252
- }
253
- /**
254
- * activeInitialState is initialState passed through additional filters
255
- */
256
- get activeInitialState() {
257
- var _a, _b;
258
- const ctx = this.context.resolve();
259
- let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
260
- if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
261
- initialState = this.filterByActivePriceList(initialState);
262
- }
263
- return initialState;
264
- }
265
- get isStandalone() {
266
- return this.context.resolve().properties.standalone === 'true';
267
- }
268
- get isStandalone$() {
269
- return this.context.resolve$().pipe(map(() => this.isStandalone));
270
- }
271
- getInitialCurrentState() {
272
- return this.initialCurrentState;
273
- }
274
- isEditMode$() {
275
- return this.context.resolve$().pipe(map(() => this.isEditMode()));
276
- }
277
- isEditMode() {
278
- const context = this.context.resolve();
279
- if (context.mode === ConfigurationContextMode.ACCOUNT) {
280
- return true;
281
- }
282
- if (context.mode === ConfigurationContextMode.QUOTE) {
283
- return context.properties.Status === 'Draft';
284
- }
285
- return false;
286
- }
287
- updateActivePriceList(priceListId) {
288
- this.context.update({ properties: { PriceListId: priceListId } });
289
- }
290
- populateActivePriceLists$() {
291
- const ctx = this.context.resolve();
292
- const quoteDraft = this.quoteDraft;
293
- if (!quoteDraft) {
294
- return;
295
- }
296
- // In ACCOUNT mode populate price lists from related assets
297
- if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
298
- // Populate list of price lists
299
- this.assetPriceLists = quoteDraft.currentState
300
- .map(({ priceListId }) => priceListId)
301
- .reduce((trunk, priceListId) => {
302
- var _a, _b;
303
- if (!priceListId || trunk.some(item => item.id === priceListId)) {
304
- return trunk;
305
- }
306
- return [
307
- ...trunk,
308
- { id: priceListId, name: (_b = (_a = this.allPriceLists.find(item => item.id === priceListId)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '' },
309
- ];
310
- }, []);
311
- }
312
- }
313
- filterByActivePriceList(lineItems) {
314
- const ctx = this.context.resolve();
315
- return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
316
- }
317
- markAsUpdated(quote) {
318
- if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === ConfigurationContextMode.ACCOUNT) {
319
- this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
320
- }
321
- else {
322
- this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
323
- }
324
- }
325
- }
326
- 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 });
327
- QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
328
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, decorators: [{
329
- type: Injectable,
330
- args: [{ providedIn: 'root' }]
331
- }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
332
-
333
- class MetricsCalculationService {
334
- constructor(quoteDraftService, settingsService) {
335
- this.quoteDraftService = quoteDraftService;
336
- this.settingsService = settingsService;
337
- this.metricsUpdated$ = new Subject();
338
- this.quoteMetricsSettings = {};
339
- this.metricsCalculationMethodMap = {};
340
- this.metricsData = {};
341
- combineLatest([
342
- this.quoteDraftService.currentState$,
343
- this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
344
- ]).subscribe(([lineItems, setting]) => {
345
- let settingsData = {};
346
- try {
347
- settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
348
- }
349
- catch (error) {
350
- settingsData = {};
351
- }
352
- this.quoteMetricsSettings = settingsData;
353
- this.updateMetrics(lineItems);
354
- });
355
- }
356
- get onMetricsUpdate$() {
357
- return this.metricsUpdated$.asObservable();
358
- }
359
- getMetricValue(metric) {
360
- return this.metricsData[metric] || 0;
361
- }
362
- updateMetrics(lineItems) {
363
- const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
364
- this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
365
- this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
366
- this.metricsUpdated$.next();
367
- }
368
- calculateMetric(lineItems, metric) {
369
- return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
370
- }
371
- buildMetricsCalculationMethods(metricKeys, initial) {
372
- return metricKeys.reduce((acc, name) => {
373
- if (acc[name]) {
374
- return acc;
375
- }
376
- acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
377
- const settingKey = name.replace(/VDM_|Total_/g, '');
378
- if (this.quoteMetricsSettings[settingKey]) {
379
- acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
380
- }
381
- return acc;
382
- }, initial);
383
- }
384
- collectMetricKeys(lineItems) {
385
- const keys = [];
386
- lineItems.forEach(lineItem => {
387
- keys.push(...Object.keys(lineItem.totalMetrics || {}));
388
- keys.push(...this.collectMetricKeys(lineItem.lineItems));
389
- });
390
- return uniq(keys);
391
- }
392
- }
393
- MetricsCalculationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
394
- MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
395
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, decorators: [{
396
- type: Injectable,
397
- args: [{ providedIn: 'root' }]
398
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: i1.ConfigurationSettingsApiService }]; } });
399
-
400
- class ProductImagesService {
401
- constructor(productApiService) {
402
- this.productApiService = productApiService;
403
- this.imagesMap$ = new BehaviorSubject({});
404
- }
405
- getImageUrl$(productId) {
406
- if (this.imagesMap$.value[productId] == null) {
407
- this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
408
- this.fetchProductImage(productId);
409
- }
410
- return this.imagesMap$.pipe(map$1(imagesMap => imagesMap[productId]), distinctUntilChanged());
411
- }
412
- fetchProductImage(productId) {
413
- this.productApiService
414
- .fetchImage$(productId)
415
- .pipe(map$1(file => URL.createObjectURL(file)), catchError(() => of('')), tap$1(url => this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: url }))))
416
- .subscribe();
417
- }
418
- }
419
- ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
420
- ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
421
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, decorators: [{
422
- type: Injectable,
423
- args: [{ providedIn: 'root' }]
424
- }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
425
-
426
82
  class RuntimeContextService {
427
83
  constructor(configurationApiService) {
428
84
  this.configurationApiService = configurationApiService;
@@ -462,9 +118,9 @@ class RuntimeContextService {
462
118
  return uiDefinition;
463
119
  }
464
120
  }
465
- RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
466
- RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService });
467
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService, decorators: [{
121
+ RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
122
+ RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService });
123
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService, decorators: [{
468
124
  type: Injectable
469
125
  }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
470
126
 
@@ -479,7 +135,6 @@ class ConfigurationRuntimeService {
479
135
  reset() {
480
136
  this._isInitialized = false;
481
137
  this._runtimeContext = undefined;
482
- this._assets = undefined;
483
138
  this.initializationProps = undefined;
484
139
  this.uiDefinitionProperties = {};
485
140
  }
@@ -505,7 +160,6 @@ class ConfigurationRuntimeService {
505
160
  }
506
161
  init(props) {
507
162
  this.initializationProps = props;
508
- this._assets = props.assets;
509
163
  const context = this.contextService.resolve();
510
164
  return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
511
165
  var _a, _b, _c, _d;
@@ -531,9 +185,6 @@ class ConfigurationRuntimeService {
531
185
  source[propertyName] = SalesforceIdUtils.generateId18FromId15(value);
532
186
  }
533
187
  }
534
- getAsset(lineItem) {
535
- return this._assets && this._assets.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
536
- }
537
188
  get isInitialized() {
538
189
  return this._isInitialized;
539
190
  }
@@ -545,9 +196,9 @@ class ConfigurationRuntimeService {
545
196
  return this._runtimeContext;
546
197
  }
547
198
  }
548
- ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
549
- ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService });
550
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
199
+ ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
200
+ ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationRuntimeService });
201
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
551
202
  type: Injectable
552
203
  }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
553
204
 
@@ -589,17 +240,33 @@ const removeLineItem = (lineItem, idToRemove) => {
589
240
  };
590
241
  const replaceLineItem = (lineItem, replaceTo) => {
591
242
  if (lineItem.id === replaceTo.id) {
592
- return Object.assign({}, replaceTo);
243
+ return Object.assign({}, recalculateCardinalityVariables(lineItem, replaceTo));
593
244
  }
594
- return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(li => {
595
- if (li.id === replaceTo.id) {
596
- return replaceTo;
597
- }
598
- else if (li.lineItems.length) {
599
- return replaceLineItem(li, replaceTo);
600
- }
601
- return li;
602
- }) });
245
+ return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo)) });
246
+ };
247
+ const calculateCardinalityVariables = (lineItems) => {
248
+ const cardVars = new Map();
249
+ lineItems.forEach(li => {
250
+ var _a;
251
+ const cardinalityVariableName = `#CV-${li.type}@${li.port}`;
252
+ cardVars.set(cardinalityVariableName, ((_a = cardVars.get(cardinalityVariableName)) !== null && _a !== void 0 ? _a : 0) + li.qty);
253
+ });
254
+ return cardVars;
255
+ };
256
+ const recalculateCardinalityVariables = (original, updated) => {
257
+ const cardinalityVariables = calculateCardinalityVariables(updated.lineItems);
258
+ const originalCardinalityVariables = calculateCardinalityVariables(original.lineItems);
259
+ originalCardinalityVariables.forEach((value, key) => {
260
+ if (cardinalityVariables.get(key) === value) {
261
+ // no need to update cardinality if no changes
262
+ cardinalityVariables.delete(key);
263
+ }
264
+ else if (!cardinalityVariables.has(key)) {
265
+ // remove last item from port
266
+ cardinalityVariables.set(key, 0);
267
+ }
268
+ });
269
+ return Object.assign(Object.assign({}, updated), { attributes: upsertAttributes(updated.attributes, [...cardinalityVariables].map(([name, value]) => ({ name, value }))) });
603
270
  };
604
271
  const mapAttributes = (attributes) => {
605
272
  return attributes.reduce((acc, { name, value }) => (Object.assign(Object.assign({}, acc), { [name]: value })), {});
@@ -622,78 +289,289 @@ const patchAttributes = (rootLineItem, id, attrs) => {
622
289
  if (!lineItem) {
623
290
  return rootLineItem;
624
291
  }
625
- const attributes = upsertAttributes(lineItem.attributes, attrs);
626
- return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes }));
627
- };
628
- const getAttributeValue = (attributes, name) => { var _a; return (_a = attributes.find(attr => attr.name === name)) === null || _a === void 0 ? void 0 : _a.value; };
629
- const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
630
- return {
631
- id: UUID.UUID(),
632
- port,
633
- type,
634
- actionCode: 'ADD',
635
- cfgStatus: 'New',
636
- attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
637
- lineItems,
638
- parentId,
639
- qty: 1,
640
- };
641
- };
642
- const getRecommendedPrices = (portDomain, type) => {
643
- var _a, _b;
644
- const domainType = portDomain.domainTypes.find(({ name }) => name === type);
645
- const [net, list] = (_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(({ chargeMethod }) => chargeMethod === 'ONE_TIME').reduce((acc, rp) => {
646
- const [netPrice, listPrice] = acc;
647
- return [netPrice + rp.netPrice, listPrice + rp.listPrice];
648
- }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
649
- return { net, list };
650
- };
651
- const multiplyLineItems = (lineItem, qty, split) => {
652
- if (split) {
653
- const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
654
- return map$2(new Array(qty), () => unifyIds(lineItem));
292
+ const attributes = upsertAttributes(lineItem.attributes, attrs);
293
+ return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes }));
294
+ };
295
+ const getAttributeValue = (attributes, name) => { var _a; return (_a = attributes.find(attr => attr.name === name)) === null || _a === void 0 ? void 0 : _a.value; };
296
+ const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
297
+ return {
298
+ id: UUID.UUID(),
299
+ port,
300
+ type,
301
+ actionCode: 'ADD',
302
+ cfgStatus: 'New',
303
+ attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
304
+ lineItems,
305
+ parentId,
306
+ qty: 1,
307
+ };
308
+ };
309
+ const getRecommendedPrices = (portDomain, type) => {
310
+ var _a, _b;
311
+ const domainType = portDomain.domainTypes.find(({ name }) => name === type);
312
+ const [net, list] = (_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(({ chargeMethod }) => chargeMethod === 'ONE_TIME').reduce((acc, rp) => {
313
+ const [netPrice, listPrice] = acc;
314
+ return [netPrice + rp.netPrice, listPrice + rp.listPrice];
315
+ }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
316
+ return { net, list };
317
+ };
318
+ const multiplyLineItems = (lineItem, qty, split) => {
319
+ if (split) {
320
+ const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
321
+ return map$1(new Array(qty), () => unifyIds(lineItem));
322
+ }
323
+ else {
324
+ return [
325
+ Object.assign(Object.assign({}, lineItem), { qty: qty }),
326
+ ];
327
+ }
328
+ };
329
+
330
+ var lineItem_utils = /*#__PURE__*/Object.freeze({
331
+ __proto__: null,
332
+ findLineItem: findLineItem,
333
+ findLineItemWithComparator: findLineItemWithComparator,
334
+ insertLineItem: insertLineItem,
335
+ removeLineItem: removeLineItem,
336
+ replaceLineItem: replaceLineItem,
337
+ calculateCardinalityVariables: calculateCardinalityVariables,
338
+ recalculateCardinalityVariables: recalculateCardinalityVariables,
339
+ mapAttributes: mapAttributes,
340
+ getAttributes: getAttributes,
341
+ upsertAttributes: upsertAttributes,
342
+ patchAttributes: patchAttributes,
343
+ getAttributeValue: getAttributeValue,
344
+ generateLineItem: generateLineItem,
345
+ getRecommendedPrices: getRecommendedPrices,
346
+ multiplyLineItems: multiplyLineItems
347
+ });
348
+
349
+ class LineItemWorker {
350
+ constructor(src) {
351
+ this.li = Object.assign({}, src);
352
+ }
353
+ insert(parentId, toInsert) {
354
+ return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
355
+ }
356
+ remove(id) {
357
+ return new LineItemWorker(removeLineItem(this.li, id));
358
+ }
359
+ replace(toReplace) {
360
+ return new LineItemWorker(replaceLineItem(this.li, toReplace));
361
+ }
362
+ patchAttribute(attrs, id) {
363
+ return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
364
+ }
365
+ }
366
+
367
+ class QuoteDraftService {
368
+ constructor(context, quoteApiService, priceApiService) {
369
+ this.context = context;
370
+ this.quoteApiService = quoteApiService;
371
+ this.priceApiService = priceApiService;
372
+ this.quoteSubj$ = new BehaviorSubject(null);
373
+ this.resetSubj$ = new BehaviorSubject(true);
374
+ this.isInitializedSubj$ = new BehaviorSubject(false);
375
+ this.initialCurrentState = [];
376
+ this._hasUnsavedChanges = false;
377
+ this.allPriceLists = [];
378
+ this.assetPriceLists = [];
379
+ this.reset$ = this.resetSubj$.asObservable();
380
+ 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));
381
+ this.isInitializedSubj$
382
+ .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
383
+ .subscribe();
384
+ }
385
+ get isInitialized() {
386
+ return this.isInitializedSubj$.getValue();
387
+ }
388
+ set isInitialized(value) {
389
+ if (this.isInitialized !== value) {
390
+ this.isInitializedSubj$.next(value);
391
+ }
392
+ }
393
+ get hasUnsavedChanges() {
394
+ return this._hasUnsavedChanges;
395
+ }
396
+ set hasUnsavedChanges(value) {
397
+ var _a, _b;
398
+ this._hasUnsavedChanges = value;
399
+ if (!this._hasUnsavedChanges) {
400
+ this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
401
+ }
402
+ }
403
+ get hasProducts$() {
404
+ return this.quoteSubj$.pipe(map(() => this.hasProducts));
405
+ }
406
+ get hasProducts() {
407
+ const quoteDraft = this.quoteSubj$.value;
408
+ return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
409
+ }
410
+ reset() {
411
+ this.resetSubj$.next(true);
412
+ this.quoteSubj$.next(null);
413
+ this.hasUnsavedChanges = false;
414
+ }
415
+ init(quoteId, params) {
416
+ return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
417
+ this.allPriceLists = allPriceLists;
418
+ this.quoteSubj$.next(quote);
419
+ this.context.update(quote.context);
420
+ this.populateActivePriceLists$();
421
+ }), map(() => noop()), take(1));
422
+ }
423
+ setCurrentLineItemState(lineItems) {
424
+ const quoteDraft = this.quoteSubj$.value;
425
+ if (!quoteDraft) {
426
+ return;
427
+ }
428
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
429
+ }
430
+ updateQuoteDraft(update) {
431
+ const quoteDraft = this.quoteSubj$.value;
432
+ if (!quoteDraft) {
433
+ return;
434
+ }
435
+ if (update.context) {
436
+ this.context.set(update.context);
437
+ }
438
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
439
+ }
440
+ updateByPriceSummary(priceSummary) {
441
+ const quoteDraft = this.quoteSubj$.value;
442
+ if (!quoteDraft) {
443
+ return;
444
+ }
445
+ const updatedCurrentState = this.currentState.map(lineItem => {
446
+ const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
447
+ return updated !== null && updated !== void 0 ? updated : lineItem;
448
+ });
449
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
450
+ }
451
+ get quoteDraft$() {
452
+ return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
453
+ }
454
+ get quoteDraft() {
455
+ const quote = this.quoteSubj$.value;
456
+ if (!quote) {
457
+ return null;
458
+ }
459
+ return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
460
+ }
461
+ get quoteDraftForActivePriceList() {
462
+ const quoteDraft = this.quoteDraft;
463
+ if (!quoteDraft) {
464
+ return null;
465
+ }
466
+ return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
467
+ }
468
+ get currentState$() {
469
+ return this.quoteDraft$.pipe(map(quote => quote.currentState));
470
+ }
471
+ get currentState() {
472
+ var _a, _b;
473
+ return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
474
+ }
475
+ /**
476
+ * Stream of activeCurrentState
477
+ */
478
+ get activeCurrentState$() {
479
+ return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
480
+ }
481
+ /**
482
+ * activeCurrentState is currentState passed through additional filters
483
+ */
484
+ get activeCurrentState() {
485
+ var _a, _b;
486
+ let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
487
+ currentState = this.filterByActivePriceList(currentState);
488
+ return currentState;
489
+ }
490
+ /**
491
+ * Stream of activeInitialState
492
+ */
493
+ get activeInitialState$() {
494
+ return this.quoteDraft$.pipe(map(() => this.activeInitialState));
495
+ }
496
+ /**
497
+ * activeInitialState is initialState passed through additional filters
498
+ */
499
+ get activeInitialState() {
500
+ var _a, _b;
501
+ const ctx = this.context.resolve();
502
+ let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
503
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
504
+ initialState = this.filterByActivePriceList(initialState);
505
+ }
506
+ return initialState;
507
+ }
508
+ get isStandalone() {
509
+ return this.context.resolve().properties.standalone === 'true';
655
510
  }
656
- else {
657
- return [
658
- Object.assign(Object.assign({}, lineItem), { qty: qty }),
659
- ];
511
+ get isStandalone$() {
512
+ return this.context.resolve$().pipe(map(() => this.isStandalone));
660
513
  }
661
- };
662
-
663
- var lineItem_utils = /*#__PURE__*/Object.freeze({
664
- __proto__: null,
665
- findLineItem: findLineItem,
666
- findLineItemWithComparator: findLineItemWithComparator,
667
- insertLineItem: insertLineItem,
668
- removeLineItem: removeLineItem,
669
- replaceLineItem: replaceLineItem,
670
- mapAttributes: mapAttributes,
671
- getAttributes: getAttributes,
672
- upsertAttributes: upsertAttributes,
673
- patchAttributes: patchAttributes,
674
- getAttributeValue: getAttributeValue,
675
- generateLineItem: generateLineItem,
676
- getRecommendedPrices: getRecommendedPrices,
677
- multiplyLineItems: multiplyLineItems
678
- });
679
-
680
- class LineItemWorker {
681
- constructor(src) {
682
- this.li = Object.assign({}, src);
514
+ getInitialCurrentState() {
515
+ return this.initialCurrentState;
683
516
  }
684
- insert(parentId, toInsert) {
685
- return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
517
+ isEditMode$() {
518
+ return this.context.resolve$().pipe(map(() => this.isEditMode()));
686
519
  }
687
- remove(id) {
688
- return new LineItemWorker(removeLineItem(this.li, id));
520
+ isEditMode() {
521
+ const context = this.context.resolve();
522
+ if (context.mode === ConfigurationContextMode.ACCOUNT) {
523
+ return true;
524
+ }
525
+ if (context.mode === ConfigurationContextMode.QUOTE) {
526
+ return context.properties.Status === 'Draft';
527
+ }
528
+ return false;
689
529
  }
690
- replace(toReplace) {
691
- return new LineItemWorker(replaceLineItem(this.li, toReplace));
530
+ updateActivePriceList(priceListId) {
531
+ this.context.update({ properties: { PriceListId: priceListId } });
692
532
  }
693
- patchAttribute(attrs, id) {
694
- return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
533
+ populateActivePriceLists$() {
534
+ const ctx = this.context.resolve();
535
+ const quoteDraft = this.quoteDraft;
536
+ if (!quoteDraft) {
537
+ return;
538
+ }
539
+ // In ACCOUNT mode populate price lists from related assets
540
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
541
+ // Populate list of price lists
542
+ this.assetPriceLists = quoteDraft.currentState
543
+ .map(({ priceListId }) => priceListId)
544
+ .reduce((trunk, priceListId) => {
545
+ var _a, _b;
546
+ if (!priceListId || trunk.some(item => item.id === priceListId)) {
547
+ return trunk;
548
+ }
549
+ return [
550
+ ...trunk,
551
+ { id: priceListId, name: (_b = (_a = this.allPriceLists.find(item => item.id === priceListId)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '' },
552
+ ];
553
+ }, []);
554
+ }
555
+ }
556
+ filterByActivePriceList(lineItems) {
557
+ const ctx = this.context.resolve();
558
+ return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
559
+ }
560
+ markAsUpdated(quote) {
561
+ if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === ConfigurationContextMode.ACCOUNT) {
562
+ this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
563
+ }
564
+ else {
565
+ this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
566
+ }
695
567
  }
696
568
  }
569
+ QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
570
+ QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
571
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, decorators: [{
572
+ type: Injectable,
573
+ args: [{ providedIn: 'root' }]
574
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
697
575
 
698
576
  class ConfigurationService {
699
577
  constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
@@ -704,7 +582,6 @@ class ConfigurationService {
704
582
  this.messageService = messageService;
705
583
  this.dialogService = dialogService;
706
584
  this.mode = ConfigurationMode.SEARCH;
707
- this.states = {};
708
585
  this.lineItem = new BehaviorSubject(undefined);
709
586
  this.charges = new BehaviorSubject({});
710
587
  this.pricePlans = new BehaviorSubject({});
@@ -713,7 +590,7 @@ class ConfigurationService {
713
590
  reset() {
714
591
  this.hasUnsavedChanges = false;
715
592
  this.runtimeService.reset();
716
- this.states = {};
593
+ this.configurableRamp = undefined;
717
594
  this.lineItem.next(undefined);
718
595
  this.charges.next({});
719
596
  this.pricePlans.next({});
@@ -722,11 +599,8 @@ class ConfigurationService {
722
599
  if (!this.lineItem.value) {
723
600
  return throwError(() => new Error(`Source LineItem not found`));
724
601
  }
725
- this.states.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem).li;
726
- this.states.asset = this.states.configurableRamp
727
- ? this.runtimeService.getAsset(this.states.configurableRamp)
728
- : undefined;
729
- return this.configure().pipe(catchError$1(error => {
602
+ this.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem).li;
603
+ return this.configure().pipe(catchError(error => {
730
604
  console.error(error);
731
605
  if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
732
606
  this.messageService.add({ severity: 'error', summary: error });
@@ -743,8 +617,8 @@ class ConfigurationService {
743
617
  patch(lineItem) {
744
618
  this.patch$(lineItem).subscribe();
745
619
  }
746
- updateCurrentStates(update) {
747
- this.states = Object.assign(Object.assign({}, this.states), update);
620
+ setConfigurableRamp(lineItem) {
621
+ this.configurableRamp = lineItem;
748
622
  }
749
623
  get() {
750
624
  return this.lineItem.asObservable().pipe(shareReplay$1());
@@ -785,7 +659,7 @@ class ConfigurationService {
785
659
  }
786
660
  const uiDefinitionProperties = Object.assign(Object.assign({}, ((_b = (_a = runtimeContext.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {})), ((_c = this.runtimeService.uiDefinitionProperties) !== null && _c !== void 0 ? _c : {}));
787
661
  const qty = (_d = this.runtimeService.initializationProps) === null || _d === void 0 ? void 0 : _d.defaultQty;
788
- const lineItem = (_e = this.states.configurableRamp) !== null && _e !== void 0 ? _e : getDefaultLineItem(runtimeContext, uiDefinitionProperties, qty);
662
+ const lineItem = (_e = this.configurableRamp) !== null && _e !== void 0 ? _e : getDefaultLineItem(runtimeContext, uiDefinitionProperties, qty);
789
663
  const configurationRequest = this.createRequest(lineItem);
790
664
  const mainPricingEnabled = (_f = runtimeContext.properties) === null || _f === void 0 ? void 0 : _f.PricingEnabled;
791
665
  const pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
@@ -800,26 +674,24 @@ class ConfigurationService {
800
674
  }
801
675
  return lineItem;
802
676
  }))
803
- .pipe(tap(lineItem => lineItem && this.lineItem.next(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)); })));
677
+ .pipe(tap(lineItem => lineItem && this.lineItem.next(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)); })));
804
678
  }
805
679
  configureExternal$(productId, qty) {
806
- this.updateCurrentStates({
807
- currentState: this.quoteDraftService.currentState,
808
- });
809
- return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError$1(error => {
680
+ return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError(error => {
810
681
  this.messageService.add({ severity: ToastType.error, summary: error });
811
682
  throw error;
812
683
  }), finalize(() => this.reset()));
813
684
  }
814
685
  createRequest(lineItem) {
686
+ var _a;
815
687
  return {
816
688
  lineItem,
817
689
  mode: this.mode,
818
690
  step: !this.lineItem.value ? RuntimeStep.START : RuntimeStep.UPDATE,
819
691
  attributeDomainMode: 'ALL',
820
692
  context: this.contextService.resolve(),
821
- lineItems: this.states.currentState || [],
822
- asset: this.states.asset,
693
+ lineItems: ((_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) || [],
694
+ asset: this.getAsset(),
823
695
  };
824
696
  }
825
697
  showInactiveProductsConfirmation() {
@@ -847,12 +719,20 @@ class ConfigurationService {
847
719
  }
848
720
  });
849
721
  }
722
+ getAsset() {
723
+ var _a;
724
+ const lineItem = this.configurableRamp;
725
+ if (!lineItem) {
726
+ return;
727
+ }
728
+ return (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
729
+ }
850
730
  }
851
- ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i4.MessageService }, { token: i5.DialogService }], target: i0.ɵɵFactoryTarget.Injectable });
852
- ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService });
853
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService, decorators: [{
731
+ ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i5.MessageService }, { token: i6.DialogService }], target: i0.ɵɵFactoryTarget.Injectable });
732
+ ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService });
733
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService, decorators: [{
854
734
  type: Injectable
855
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i4.MessageService }, { type: i5.DialogService }]; } });
735
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6.DialogService }]; } });
856
736
 
857
737
  class FlowUpdateService {
858
738
  update(rootLineItems, updates) {
@@ -971,9 +851,9 @@ class FlowUpdateService {
971
851
  return true;
972
852
  }
973
853
  }
974
- FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
975
- FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService });
976
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService, decorators: [{
854
+ FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
855
+ FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService });
856
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService, decorators: [{
977
857
  type: Injectable
978
858
  }] });
979
859
 
@@ -993,7 +873,7 @@ class FlowConfigurationService {
993
873
  .slice()
994
874
  .sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
995
875
  this.quoteDraftService.updateQuoteDraft(result);
996
- }), map$1(noop));
876
+ }), map$2(noop));
997
877
  }
998
878
  calculate(quoteDraft) {
999
879
  this.calculate$(quoteDraft).subscribe();
@@ -1003,11 +883,11 @@ class FlowConfigurationService {
1003
883
  if (!quoteDraft) {
1004
884
  return of(null);
1005
885
  }
1006
- return of([]).pipe(map$1(() => {
886
+ return of([]).pipe(map$2(() => {
1007
887
  const updatedState = cloneDeep(quoteDraft.currentState);
1008
888
  this.updateService.update(updatedState, updates);
1009
889
  return updatedState;
1010
- }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
890
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1011
891
  }
1012
892
  update(updates) {
1013
893
  this.update$(updates).subscribe();
@@ -1026,7 +906,7 @@ class FlowConfigurationService {
1026
906
  updatedState.splice(currentLineItemIndex, 1, initialLineItem);
1027
907
  return of([]).pipe(tap$1(() => {
1028
908
  this.quoteDraftService.setCurrentLineItemState(updatedState);
1029
- }), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
909
+ }), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1030
910
  }
1031
911
  revert(lineItemId) {
1032
912
  this.revert$(lineItemId).subscribe();
@@ -1037,7 +917,7 @@ class FlowConfigurationService {
1037
917
  if (!quoteDraft) {
1038
918
  return of(null);
1039
919
  }
1040
- return of([]).pipe(map$1(() => ids.reduce((result, id) => this.updateService.delete(result, id), currentState)), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
920
+ return of([]).pipe(map$2(() => ids.reduce((result, id) => this.updateService.delete(result, id), currentState)), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1041
921
  }
1042
922
  delete(ids) {
1043
923
  this.delete$(ids).subscribe();
@@ -1048,33 +928,36 @@ class FlowConfigurationService {
1048
928
  return of(null);
1049
929
  }
1050
930
  const updatedState = [...quoteDraft.currentState, term];
1051
- return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
931
+ return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1052
932
  }
1053
933
  addToCart$(productId, qty) {
1054
934
  const quoteDraft = this.quoteDraftService.quoteDraft;
1055
935
  if (!quoteDraft) {
1056
936
  return of(null);
1057
937
  }
1058
- return this.configurationService.configureExternal$(productId, qty).pipe(map$1(lineItem => {
938
+ return this.configurationService.configureExternal$(productId, qty).pipe(map$2(lineItem => {
1059
939
  var _a, _b;
1060
940
  const model = this.configurationService.getRuntimeModel();
1061
941
  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;
1062
942
  const lineItems = multiplyLineItems(lineItem, qty !== null && qty !== void 0 ? qty : 1, split);
1063
943
  return [...quoteDraft.currentState, ...lineItems];
1064
- }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
944
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1065
945
  }
1066
946
  get() {
1067
- return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
947
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
1068
948
  }
1069
949
  getSnapshot() {
1070
950
  var _a, _b;
1071
951
  return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
1072
952
  }
1073
953
  get charges$() {
1074
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ charges }) => charges));
954
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ charges }) => charges));
1075
955
  }
1076
956
  get pricePlans$() {
1077
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ pricePlans }) => pricePlans));
957
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ pricePlans }) => pricePlans));
958
+ }
959
+ get activeMetrics$() {
960
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ activeMetrics }) => activeMetrics));
1078
961
  }
1079
962
  get chargesSnapshot() {
1080
963
  var _a, _b;
@@ -1084,6 +967,10 @@ class FlowConfigurationService {
1084
967
  var _a, _b;
1085
968
  return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.pricePlans) !== null && _b !== void 0 ? _b : {};
1086
969
  }
970
+ get activeMetricsSnapshot() {
971
+ var _a, _b;
972
+ return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.activeMetrics) !== null && _b !== void 0 ? _b : [];
973
+ }
1087
974
  get contextSnapshot() {
1088
975
  return this.contextService.resolve();
1089
976
  }
@@ -1092,7 +979,7 @@ class FlowConfigurationService {
1092
979
  }
1093
980
  handleErrorAndBounceBack() {
1094
981
  return (source$) => {
1095
- return source$.pipe(catchError(error => {
982
+ return source$.pipe(catchError$1(error => {
1096
983
  console.error(error);
1097
984
  // bounce back if configuration call has failed
1098
985
  const quoteDraft = this.quoteDraftService.quoteDraft;
@@ -1104,18 +991,18 @@ class FlowConfigurationService {
1104
991
  };
1105
992
  }
1106
993
  }
1107
- 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 });
1108
- FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService });
1109
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, decorators: [{
994
+ FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
995
+ FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService });
996
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService, decorators: [{
1110
997
  type: Injectable
1111
998
  }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1112
999
 
1113
1000
  class FlowConfigurationModule {
1114
1001
  }
1115
- FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1116
- FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule });
1117
- FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService], imports: [[]] });
1118
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1002
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1003
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule });
1004
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService], imports: [[]] });
1005
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1119
1006
  type: NgModule,
1120
1007
  args: [{
1121
1008
  imports: [],
@@ -1125,9 +1012,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
1125
1012
 
1126
1013
  class ConfigurationModule {
1127
1014
  }
1128
- ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1129
- ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1130
- ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, providers: [
1015
+ ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1016
+ ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1017
+ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, providers: [
1131
1018
  ContextApiService,
1132
1019
  ProductModelApiService,
1133
1020
  ConfigurationApiService,
@@ -1135,7 +1022,7 @@ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ver
1135
1022
  RuntimeContextService,
1136
1023
  ConfigurationService,
1137
1024
  ], imports: [[ConfirmationDialogModule]] });
1138
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, decorators: [{
1025
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, decorators: [{
1139
1026
  type: NgModule,
1140
1027
  args: [{
1141
1028
  imports: [ConfirmationDialogModule],
@@ -1150,12 +1037,155 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
1150
1037
  }]
1151
1038
  }] });
1152
1039
 
1040
+ function calculateMetricByMethod(lineItems, metric, method) {
1041
+ const items = getLineItemsByMethod(lineItems, method);
1042
+ return items.reduce((acc, li) => {
1043
+ let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
1044
+ if (method === 'avg' && li.length > 0) {
1045
+ value /= li.length;
1046
+ }
1047
+ return acc + value;
1048
+ }, 0);
1049
+ }
1050
+ function getLineItemsByMethod(lineItems, method) {
1051
+ switch (method) {
1052
+ case 'first': {
1053
+ return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
1054
+ }
1055
+ case 'last': {
1056
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1057
+ const products = rootTermItems.map(lineItem => [
1058
+ lineItem,
1059
+ ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
1060
+ ]);
1061
+ return products
1062
+ .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
1063
+ .filter((li) => Boolean(li))
1064
+ .map(item => [item]);
1065
+ }
1066
+ case 'avg': {
1067
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1068
+ return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
1069
+ }
1070
+ case 'sum': {
1071
+ return lineItems.map(item => [item]);
1072
+ }
1073
+ default: {
1074
+ return lineItems.map(item => [item]);
1075
+ }
1076
+ }
1077
+ }
1078
+ function getDateValue(date) {
1079
+ return date ? new Date(date).getTime() : 0;
1080
+ }
1081
+
1082
+ class MetricsCalculationService {
1083
+ constructor(quoteDraftService, flowConfiguration, settingsService) {
1084
+ this.quoteDraftService = quoteDraftService;
1085
+ this.flowConfiguration = flowConfiguration;
1086
+ this.settingsService = settingsService;
1087
+ this.metricsUpdated$ = new Subject();
1088
+ this.quoteMetricsSettings = {};
1089
+ this.metricsCalculationMethodMap = {};
1090
+ this.metricsData = {};
1091
+ this.activeMetricRules = [];
1092
+ this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(metricRule => metricRule.metrics.some(metric => !!metric.totalName));
1093
+ combineLatest([
1094
+ this.quoteDraftService.currentState$,
1095
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
1096
+ ]).subscribe(([lineItems, setting]) => {
1097
+ let settingsData = {};
1098
+ try {
1099
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
1100
+ }
1101
+ catch (error) {
1102
+ settingsData = {};
1103
+ }
1104
+ this.quoteMetricsSettings = settingsData;
1105
+ this.updateMetrics(lineItems);
1106
+ });
1107
+ }
1108
+ get onMetricsUpdate$() {
1109
+ return this.metricsUpdated$.asObservable();
1110
+ }
1111
+ getMetricValue(metric) {
1112
+ return this.metricsData[metric] || 0;
1113
+ }
1114
+ updateMetrics(lineItems) {
1115
+ const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
1116
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
1117
+ this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
1118
+ this.metricsUpdated$.next();
1119
+ }
1120
+ calculateMetric(lineItems, metric) {
1121
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
1122
+ }
1123
+ buildMetricsCalculationMethods(metricKeys, initial) {
1124
+ return metricKeys.reduce((acc, name) => {
1125
+ var _a, _b;
1126
+ if (acc[name]) {
1127
+ return acc;
1128
+ }
1129
+ acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
1130
+ const metricRule = this.getMetricRuleByTotalMetricName(name);
1131
+ 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;
1132
+ if (this.quoteMetricsSettings[settingKey]) {
1133
+ acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
1134
+ }
1135
+ return acc;
1136
+ }, initial);
1137
+ }
1138
+ collectMetricKeys(lineItems) {
1139
+ const keys = [];
1140
+ lineItems.forEach(lineItem => {
1141
+ keys.push(...Object.keys(lineItem.totalMetrics || {}));
1142
+ keys.push(...this.collectMetricKeys(lineItem.lineItems));
1143
+ });
1144
+ return uniq(keys);
1145
+ }
1146
+ getMetricRuleByTotalMetricName(name) {
1147
+ return this.activeMetricRules.find(metricRule => metricRule.metrics.find(metric => metric.totalName === name));
1148
+ }
1149
+ }
1150
+ MetricsCalculationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: FlowConfigurationService }, { token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1151
+ MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
1152
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, decorators: [{
1153
+ type: Injectable,
1154
+ args: [{ providedIn: 'root' }]
1155
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1.ConfigurationSettingsApiService }]; } });
1156
+
1157
+ class ProductImagesService {
1158
+ constructor(productApiService) {
1159
+ this.productApiService = productApiService;
1160
+ this.imagesMap$ = new BehaviorSubject({});
1161
+ }
1162
+ getImageUrl$(productId) {
1163
+ if (this.imagesMap$.value[productId] == null) {
1164
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
1165
+ this.fetchProductImage(productId);
1166
+ }
1167
+ return this.imagesMap$.pipe(map$2(imagesMap => imagesMap[productId]), distinctUntilChanged());
1168
+ }
1169
+ fetchProductImage(productId) {
1170
+ this.productApiService
1171
+ .fetchImage$(productId)
1172
+ .pipe(map$2(file => URL.createObjectURL(file)), catchError$1(() => of('')), tap$1(url => this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: url }))))
1173
+ .subscribe();
1174
+ }
1175
+ }
1176
+ ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1177
+ ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
1178
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, decorators: [{
1179
+ type: Injectable,
1180
+ args: [{ providedIn: 'root' }]
1181
+ }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
1182
+
1153
1183
  class SdkCoreModule {
1154
1184
  }
1155
- SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1156
- SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1157
- SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1158
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, decorators: [{
1185
+ SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1186
+ SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1187
+ SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1188
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, decorators: [{
1159
1189
  type: NgModule,
1160
1190
  args: [{
1161
1191
  imports: [ConfigurationModule, FlowConfigurationModule],
@@ -1167,5 +1197,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
1167
1197
  * Generated bundle index. Do not edit.
1168
1198
  */
1169
1199
 
1170
- export { ConfigurationRuntimeService, ConfigurationService, ContextService, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, MetricsCalculationService, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeStep, SdkCoreModule, findLineItem, findLineItemWithComparator, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getRecommendedPrices, insertLineItem, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, removeLineItem, replaceLineItem, upsertAttributes };
1200
+ export { ConfigurationRuntimeService, ConfigurationService, ContextService, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, MetricsCalculationService, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeStep, SdkCoreModule, calculateCardinalityVariables, findLineItem, findLineItemWithComparator, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getRecommendedPrices, insertLineItem, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
1171
1201
  //# sourceMappingURL=veloceapps-sdk-core.js.map