@veloceapps/sdk 6.0.0-19 → 6.0.0-20

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 (130) hide show
  1. package/bundles/veloceapps-sdk-cms.umd.js +133 -66
  2. package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
  3. package/bundles/veloceapps-sdk-core.umd.js +689 -622
  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 +200 -133
  8. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  9. package/cms/vendor-map.d.ts +15 -12
  10. package/core/modules/configuration/services/configuration-runtime.service.d.ts +1 -1
  11. package/core/modules/configuration/services/configuration.service.d.ts +2 -1
  12. package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +3 -2
  13. package/core/services/metric-calculation/metric-calculation.service.d.ts +1 -1
  14. package/esm2015/cms/components/element-children/element-children.component.js +3 -3
  15. package/esm2015/cms/components/element-children/element-children.module.js +4 -4
  16. package/esm2015/cms/components/element-renderer/element-renderer.component.js +3 -3
  17. package/esm2015/cms/components/element-renderer/element-renderer.module.js +4 -4
  18. package/esm2015/cms/components/plugin.component.js +3 -3
  19. package/esm2015/cms/components/preview/preview.component.js +3 -3
  20. package/esm2015/cms/components/preview/preview.module.js +4 -4
  21. package/esm2015/cms/directives/custom-template.directive.js +3 -3
  22. package/esm2015/cms/launcher.module.js +4 -4
  23. package/esm2015/cms/modules/federated/federated.component.js +3 -3
  24. package/esm2015/cms/modules/federated/federated.module.js +4 -4
  25. package/esm2015/cms/plugins/configuration.plugin.js +3 -3
  26. package/esm2015/cms/plugins/io.plugin.js +3 -3
  27. package/esm2015/cms/plugins/script.plugin.js +3 -3
  28. package/esm2015/cms/services/dynamic-module.service.js +3 -3
  29. package/esm2015/cms/services/element-context.service.js +3 -3
  30. package/esm2015/cms/services/integration.state.js +3 -3
  31. package/esm2015/cms/services/io-provider.service.js +3 -3
  32. package/esm2015/cms/services/launcher.service.js +3 -3
  33. package/esm2015/cms/services/templates.service.js +3 -3
  34. package/esm2015/core/core.module.js +4 -4
  35. package/esm2015/core/modules/configuration/configuration.module.js +4 -4
  36. package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +5 -5
  37. package/esm2015/core/modules/configuration/services/configuration.service.js +11 -10
  38. package/esm2015/core/modules/configuration/services/runtime-context.service.js +3 -3
  39. package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +4 -4
  40. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +10 -9
  41. package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +3 -3
  42. package/esm2015/core/services/context.service.js +3 -3
  43. package/esm2015/core/services/metric-calculation/metric-calculation.service.js +5 -5
  44. package/esm2015/core/services/product-images.service.js +3 -3
  45. package/esm2015/core/services/quote-draft.service.js +3 -3
  46. package/esm2015/runtime/components/component-preview/component-preview.component.js +4 -4
  47. package/esm2015/runtime/components/section-renderer/section-renderer.component.js +3 -3
  48. package/esm2015/runtime/components/ui-runtime/runtime.component.js +3 -3
  49. package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
  50. package/esm2015/runtime/execution/components/children-placeholder/children-placeholder.component.js +6 -6
  51. package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +3 -3
  52. package/esm2015/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.js +3 -3
  53. package/esm2015/runtime/execution/components/federated/federated.component.js +3 -3
  54. package/esm2015/runtime/execution/components/velo-attribute/velo-attribute.component.js +3 -3
  55. package/esm2015/runtime/execution/components/velo-multiselect/velo-multiselect.component.js +3 -3
  56. package/esm2015/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.js +3 -3
  57. package/esm2015/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.js +3 -3
  58. package/esm2015/runtime/execution/components/velo-port-radio/velo-port-radio.component.js +3 -3
  59. package/esm2015/runtime/execution/components/velo-type/velo-type.component.js +3 -3
  60. package/esm2015/runtime/execution/directives/section-script.directive.js +3 -3
  61. package/esm2015/runtime/execution/directives/sf-query.directive.js +3 -3
  62. package/esm2015/runtime/execution/directives/velo-attribute.directive.js +3 -3
  63. package/esm2015/runtime/execution/directives/velo-port.directive.js +18 -18
  64. package/esm2015/runtime/execution/directives/vl-approval.directive.js +3 -3
  65. package/esm2015/runtime/execution/directives/vl-document-attachments.directive.js +3 -3
  66. package/esm2015/runtime/execution/directives/vl-document-templates.directive.js +3 -3
  67. package/esm2015/runtime/execution/directives/vl-quote.directive.js +3 -3
  68. package/esm2015/runtime/execution/directives/vl-ramp.directive.js +3 -3
  69. package/esm2015/runtime/execution/runtime-execution.module.js +4 -4
  70. package/esm2015/runtime/runtime.module.js +4 -4
  71. package/esm2015/runtime/services/cart.service.js +3 -3
  72. package/esm2015/runtime/services/collapsible-state.service.js +3 -3
  73. package/esm2015/runtime/services/configuration.service.js +3 -3
  74. package/esm2015/runtime/services/current-state.service.js +3 -3
  75. package/esm2015/runtime/services/form-scope.service.js +3 -3
  76. package/esm2015/runtime/services/product-model-cache.service.js +3 -3
  77. package/esm2015/runtime/services/runtime-context.service.js +3 -3
  78. package/esm2015/runtime/services/runtime-form.service.js +3 -3
  79. package/esm2015/runtime/services/runtime.service.js +3 -3
  80. package/esm2015/runtime/services/section-helper.service.js +3 -3
  81. package/esm2015/runtime/services/section-scope.service.js +3 -3
  82. package/esm2015/runtime/services/section-store.service.js +3 -3
  83. package/esm2015/runtime/services/section.service.js +6 -6
  84. package/esm2015/src/components/dialog/dialog.component.js +3 -3
  85. package/esm2015/src/components/dialog/dialog.module.js +4 -4
  86. package/esm2015/src/components/doc-gen/doc-gen.component.js +3 -3
  87. package/esm2015/src/components/doc-gen/doc-gen.module.js +4 -4
  88. package/esm2015/src/components/header/cart-overlay/cart-preview.component.js +3 -3
  89. package/esm2015/src/components/header/cart-overlay/cart-preview.module.js +4 -4
  90. package/esm2015/src/components/header/header.component.js +3 -3
  91. package/esm2015/src/components/header/header.module.js +4 -4
  92. package/esm2015/src/components/header/metrics/metrics.component.js +3 -3
  93. package/esm2015/src/components/header/metrics/metrics.module.js +4 -4
  94. package/esm2015/src/flow-routing.module.js +4 -4
  95. package/esm2015/src/flow.component.js +3 -3
  96. package/esm2015/src/flow.module.js +4 -4
  97. package/esm2015/src/guards/context.guard.js +3 -3
  98. package/esm2015/src/guards/product-unload.guard.js +3 -3
  99. package/esm2015/src/guards/root.guard.js +3 -3
  100. package/esm2015/src/pages/catalog/catalog.component.js +3 -3
  101. package/esm2015/src/pages/catalog/catalog.module.js +4 -4
  102. package/esm2015/src/pages/debug/debug.component.js +3 -3
  103. package/esm2015/src/pages/debug/debug.module.js +4 -4
  104. package/esm2015/src/pages/empty-account/empty-account.component.js +3 -3
  105. package/esm2015/src/pages/empty-account/empty-account.module.js +4 -4
  106. package/esm2015/src/pages/legacy-product/legacy-product.component.js +3 -3
  107. package/esm2015/src/pages/legacy-product/legacy-product.module.js +4 -4
  108. package/esm2015/src/pages/product/product.component.js +3 -3
  109. package/esm2015/src/pages/product/product.module.js +4 -4
  110. package/esm2015/src/pages/record-not-found/record-not-found.component.js +3 -3
  111. package/esm2015/src/pages/record-not-found/record-not-found.module.js +4 -4
  112. package/esm2015/src/pages/remote/remote.component.js +3 -3
  113. package/esm2015/src/pages/remote/remote.module.js +4 -4
  114. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +3 -3
  115. package/esm2015/src/pages/shopping-cart/shopping-cart.module.js +4 -4
  116. package/esm2015/src/resolvers/flow.resolver.js +3 -3
  117. package/esm2015/src/resolvers/quote.resolver.js +3 -3
  118. package/esm2015/src/services/doc-gen.service.js +3 -3
  119. package/esm2015/src/services/flow-dialog.service.js +3 -3
  120. package/esm2015/src/services/flow-router.service.js +3 -3
  121. package/esm2015/src/services/flow.service.js +3 -3
  122. package/fesm2015/veloceapps-sdk-cms.js +62 -62
  123. package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
  124. package/fesm2015/veloceapps-sdk-core.js +487 -487
  125. package/fesm2015/veloceapps-sdk-core.js.map +1 -1
  126. package/fesm2015/veloceapps-sdk-runtime.js +138 -138
  127. package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
  128. package/fesm2015/veloceapps-sdk.js +129 -129
  129. package/fesm2015/veloceapps-sdk.js.map +1 -1
  130. package/package.json +1 -1
@@ -1,15 +1,15 @@
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';
9
- import moment from 'moment';
8
+ import { merge, flatten, sortBy, map as map$1, isEqual, cloneDeep, uniq } from 'lodash';
10
9
  import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
11
- import * as i4 from 'primeng/api';
12
- import * as i5 from 'primeng/dynamicdialog';
10
+ import * as i5 from 'primeng/api';
11
+ import * as i6 from 'primeng/dynamicdialog';
12
+ import moment from 'moment';
13
13
 
14
14
  const getDefaultLineItem = (context, uiDefinitionProperties, qty = 1) => {
15
15
  var _a, _b, _c;
@@ -50,386 +50,34 @@ class ContextService {
50
50
  }
51
51
  return Object.assign({}, this.context.value);
52
52
  }
53
- resolve$() {
54
- return this.context.pipe(filter((ctx) => Boolean(ctx)));
55
- }
56
- create(headerId, mode) {
57
- return this.contextApiService.getContext(headerId, mode).pipe(tap(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map(() => this.resolve()));
58
- }
59
- update(partialContext) {
60
- const originalContext = this.resolve();
61
- const updatedContext = Object.assign(Object.assign(Object.assign({}, originalContext), partialContext), { properties: Object.assign(Object.assign({}, originalContext.properties), partialContext.properties) });
62
- this.context.next(updatedContext);
63
- return updatedContext;
64
- }
65
- set(context) {
66
- const originalContext = this.resolve();
67
- const updatedContext = Object.assign(Object.assign({}, originalContext), context);
68
- this.context.next(updatedContext);
69
- return updatedContext;
70
- }
71
- delete() {
72
- this.context.next(null);
73
- }
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: [{
78
- type: Injectable,
79
- args: [{ providedIn: 'root' }]
80
- }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
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, flowConfiguration, settingsService) {
335
- this.quoteDraftService = quoteDraftService;
336
- this.flowConfiguration = flowConfiguration;
337
- this.settingsService = settingsService;
338
- this.metricsUpdated$ = new Subject();
339
- this.quoteMetricsSettings = {};
340
- this.metricsCalculationMethodMap = {};
341
- this.metricsData = {};
342
- this.activeMetricRules = [];
343
- this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(metricRule => metricRule.metrics.some(metric => !!metric.totalName));
344
- combineLatest([
345
- this.quoteDraftService.currentState$,
346
- this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
347
- ]).subscribe(([lineItems, setting]) => {
348
- let settingsData = {};
349
- try {
350
- settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
351
- }
352
- catch (error) {
353
- settingsData = {};
354
- }
355
- this.quoteMetricsSettings = settingsData;
356
- this.updateMetrics(lineItems);
357
- });
358
- }
359
- get onMetricsUpdate$() {
360
- return this.metricsUpdated$.asObservable();
361
- }
362
- getMetricValue(metric) {
363
- return this.metricsData[metric] || 0;
364
- }
365
- updateMetrics(lineItems) {
366
- const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
367
- this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
368
- this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
369
- this.metricsUpdated$.next();
370
- }
371
- calculateMetric(lineItems, metric) {
372
- return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
373
- }
374
- buildMetricsCalculationMethods(metricKeys, initial) {
375
- return metricKeys.reduce((acc, name) => {
376
- var _a, _b;
377
- if (acc[name]) {
378
- return acc;
379
- }
380
- acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
381
- const metricRule = this.getMetricRuleByTotalMetricName(name);
382
- 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;
383
- if (this.quoteMetricsSettings[settingKey]) {
384
- acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
385
- }
386
- return acc;
387
- }, initial);
388
- }
389
- collectMetricKeys(lineItems) {
390
- const keys = [];
391
- lineItems.forEach(lineItem => {
392
- keys.push(...Object.keys(lineItem.totalMetrics || {}));
393
- keys.push(...this.collectMetricKeys(lineItem.lineItems));
394
- });
395
- return uniq(keys);
53
+ resolve$() {
54
+ return this.context.pipe(filter((ctx) => Boolean(ctx)));
396
55
  }
397
- getMetricRuleByTotalMetricName(name) {
398
- return this.activeMetricRules.find(metricRule => metricRule.metrics.find(metric => metric.totalName === name));
56
+ create(headerId, mode) {
57
+ return this.contextApiService.getContext(headerId, mode).pipe(tap(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map(() => this.resolve()));
399
58
  }
400
- }
401
- MetricsCalculationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: FlowConfigurationService }, { token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
402
- MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
403
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, decorators: [{
404
- type: Injectable,
405
- args: [{ providedIn: 'root' }]
406
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1.ConfigurationSettingsApiService }]; } });
407
-
408
- class ProductImagesService {
409
- constructor(productApiService) {
410
- this.productApiService = productApiService;
411
- this.imagesMap$ = new BehaviorSubject({});
59
+ update(partialContext) {
60
+ const originalContext = this.resolve();
61
+ const updatedContext = Object.assign(Object.assign(Object.assign({}, originalContext), partialContext), { properties: Object.assign(Object.assign({}, originalContext.properties), partialContext.properties) });
62
+ this.context.next(updatedContext);
63
+ return updatedContext;
412
64
  }
413
- getImageUrl$(productId) {
414
- if (this.imagesMap$.value[productId] == null) {
415
- this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
416
- this.fetchProductImage(productId);
417
- }
418
- return this.imagesMap$.pipe(map$1(imagesMap => imagesMap[productId]), distinctUntilChanged());
65
+ set(context) {
66
+ const originalContext = this.resolve();
67
+ const updatedContext = Object.assign(Object.assign({}, originalContext), context);
68
+ this.context.next(updatedContext);
69
+ return updatedContext;
419
70
  }
420
- fetchProductImage(productId) {
421
- this.productApiService
422
- .fetchImage$(productId)
423
- .pipe(map$1(file => URL.createObjectURL(file)), catchError(() => of('')), tap$1(url => this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: url }))))
424
- .subscribe();
71
+ delete() {
72
+ this.context.next(null);
425
73
  }
426
74
  }
427
- ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
428
- ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
429
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, 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: [{
430
78
  type: Injectable,
431
79
  args: [{ providedIn: 'root' }]
432
- }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
80
+ }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
433
81
 
434
82
  class RuntimeContextService {
435
83
  constructor(configurationApiService) {
@@ -470,9 +118,9 @@ class RuntimeContextService {
470
118
  return uiDefinition;
471
119
  }
472
120
  }
473
- RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
474
- RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService });
475
- 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: [{
476
124
  type: Injectable
477
125
  }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
478
126
 
@@ -553,9 +201,9 @@ class ConfigurationRuntimeService {
553
201
  return this._runtimeContext;
554
202
  }
555
203
  }
556
- 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 });
557
- ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService });
558
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
204
+ 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 });
205
+ ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationRuntimeService });
206
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
559
207
  type: Injectable
560
208
  }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
561
209
 
@@ -630,78 +278,287 @@ const patchAttributes = (rootLineItem, id, attrs) => {
630
278
  if (!lineItem) {
631
279
  return rootLineItem;
632
280
  }
633
- const attributes = upsertAttributes(lineItem.attributes, attrs);
634
- return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes }));
635
- };
636
- const getAttributeValue = (attributes, name) => { var _a; return (_a = attributes.find(attr => attr.name === name)) === null || _a === void 0 ? void 0 : _a.value; };
637
- const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
638
- return {
639
- id: UUID.UUID(),
640
- port,
641
- type,
642
- actionCode: 'ADD',
643
- cfgStatus: 'New',
644
- attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
645
- lineItems,
646
- parentId,
647
- qty: 1,
648
- };
649
- };
650
- const getRecommendedPrices = (portDomain, type) => {
651
- var _a, _b;
652
- const domainType = portDomain.domainTypes.find(({ name }) => name === type);
653
- 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) => {
654
- const [netPrice, listPrice] = acc;
655
- return [netPrice + rp.netPrice, listPrice + rp.listPrice];
656
- }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
657
- return { net, list };
658
- };
659
- const multiplyLineItems = (lineItem, qty, split) => {
660
- if (split) {
661
- const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
662
- return map$2(new Array(qty), () => unifyIds(lineItem));
281
+ const attributes = upsertAttributes(lineItem.attributes, attrs);
282
+ return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes }));
283
+ };
284
+ const getAttributeValue = (attributes, name) => { var _a; return (_a = attributes.find(attr => attr.name === name)) === null || _a === void 0 ? void 0 : _a.value; };
285
+ const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
286
+ return {
287
+ id: UUID.UUID(),
288
+ port,
289
+ type,
290
+ actionCode: 'ADD',
291
+ cfgStatus: 'New',
292
+ attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
293
+ lineItems,
294
+ parentId,
295
+ qty: 1,
296
+ };
297
+ };
298
+ const getRecommendedPrices = (portDomain, type) => {
299
+ var _a, _b;
300
+ const domainType = portDomain.domainTypes.find(({ name }) => name === type);
301
+ 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) => {
302
+ const [netPrice, listPrice] = acc;
303
+ return [netPrice + rp.netPrice, listPrice + rp.listPrice];
304
+ }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
305
+ return { net, list };
306
+ };
307
+ const multiplyLineItems = (lineItem, qty, split) => {
308
+ if (split) {
309
+ const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
310
+ return map$1(new Array(qty), () => unifyIds(lineItem));
311
+ }
312
+ else {
313
+ return [
314
+ Object.assign(Object.assign({}, lineItem), { qty: qty }),
315
+ ];
316
+ }
317
+ };
318
+
319
+ var lineItem_utils = /*#__PURE__*/Object.freeze({
320
+ __proto__: null,
321
+ findLineItem: findLineItem,
322
+ findLineItemWithComparator: findLineItemWithComparator,
323
+ insertLineItem: insertLineItem,
324
+ removeLineItem: removeLineItem,
325
+ replaceLineItem: replaceLineItem,
326
+ mapAttributes: mapAttributes,
327
+ getAttributes: getAttributes,
328
+ upsertAttributes: upsertAttributes,
329
+ patchAttributes: patchAttributes,
330
+ getAttributeValue: getAttributeValue,
331
+ generateLineItem: generateLineItem,
332
+ getRecommendedPrices: getRecommendedPrices,
333
+ multiplyLineItems: multiplyLineItems
334
+ });
335
+
336
+ class LineItemWorker {
337
+ constructor(src) {
338
+ this.li = Object.assign({}, src);
339
+ }
340
+ insert(parentId, toInsert) {
341
+ return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
342
+ }
343
+ remove(id) {
344
+ return new LineItemWorker(removeLineItem(this.li, id));
345
+ }
346
+ replace(toReplace) {
347
+ return new LineItemWorker(replaceLineItem(this.li, toReplace));
348
+ }
349
+ patchAttribute(attrs, id) {
350
+ return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
351
+ }
352
+ }
353
+
354
+ class QuoteDraftService {
355
+ constructor(context, quoteApiService, priceApiService) {
356
+ this.context = context;
357
+ this.quoteApiService = quoteApiService;
358
+ this.priceApiService = priceApiService;
359
+ this.quoteSubj$ = new BehaviorSubject(null);
360
+ this.resetSubj$ = new BehaviorSubject(true);
361
+ this.isInitializedSubj$ = new BehaviorSubject(false);
362
+ this.initialCurrentState = [];
363
+ this._hasUnsavedChanges = false;
364
+ this.allPriceLists = [];
365
+ this.assetPriceLists = [];
366
+ this.reset$ = this.resetSubj$.asObservable();
367
+ 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));
368
+ this.isInitializedSubj$
369
+ .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
370
+ .subscribe();
371
+ }
372
+ get isInitialized() {
373
+ return this.isInitializedSubj$.getValue();
374
+ }
375
+ set isInitialized(value) {
376
+ if (this.isInitialized !== value) {
377
+ this.isInitializedSubj$.next(value);
378
+ }
379
+ }
380
+ get hasUnsavedChanges() {
381
+ return this._hasUnsavedChanges;
382
+ }
383
+ set hasUnsavedChanges(value) {
384
+ var _a, _b;
385
+ this._hasUnsavedChanges = value;
386
+ if (!this._hasUnsavedChanges) {
387
+ this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
388
+ }
389
+ }
390
+ get hasAssets$() {
391
+ return this.quoteSubj$.pipe(map(() => this.hasAssets));
392
+ }
393
+ get hasAssets() {
394
+ const quoteDraft = this.quoteSubj$.value;
395
+ return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
396
+ }
397
+ reset() {
398
+ this.resetSubj$.next(true);
399
+ this.quoteSubj$.next(null);
400
+ this.hasUnsavedChanges = false;
401
+ }
402
+ init(quoteId, params) {
403
+ return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
404
+ this.allPriceLists = allPriceLists;
405
+ this.quoteSubj$.next(quote);
406
+ this.context.update(quote.context);
407
+ this.populateActivePriceLists$();
408
+ }), map(() => noop()), take(1));
409
+ }
410
+ setCurrentLineItemState(lineItems) {
411
+ const quoteDraft = this.quoteSubj$.value;
412
+ if (!quoteDraft) {
413
+ return;
414
+ }
415
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
416
+ }
417
+ updateQuoteDraft(update) {
418
+ const quoteDraft = this.quoteSubj$.value;
419
+ if (!quoteDraft) {
420
+ return;
421
+ }
422
+ if (update.context) {
423
+ this.context.set(update.context);
424
+ }
425
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
426
+ }
427
+ updateByPriceSummary(priceSummary) {
428
+ const quoteDraft = this.quoteSubj$.value;
429
+ if (!quoteDraft) {
430
+ return;
431
+ }
432
+ const updatedCurrentState = this.currentState.map(lineItem => {
433
+ const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
434
+ return updated !== null && updated !== void 0 ? updated : lineItem;
435
+ });
436
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
437
+ }
438
+ get quoteDraft$() {
439
+ return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
440
+ }
441
+ get quoteDraft() {
442
+ const quote = this.quoteSubj$.value;
443
+ if (!quote) {
444
+ return null;
445
+ }
446
+ return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
447
+ }
448
+ get quoteDraftForActivePriceList() {
449
+ const quoteDraft = this.quoteDraft;
450
+ if (!quoteDraft) {
451
+ return null;
452
+ }
453
+ return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
454
+ }
455
+ get currentState$() {
456
+ return this.quoteDraft$.pipe(map(quote => quote.currentState));
457
+ }
458
+ get currentState() {
459
+ var _a, _b;
460
+ return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
461
+ }
462
+ /**
463
+ * Stream of activeCurrentState
464
+ */
465
+ get activeCurrentState$() {
466
+ return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
467
+ }
468
+ /**
469
+ * activeCurrentState is currentState passed through additional filters
470
+ */
471
+ get activeCurrentState() {
472
+ var _a, _b;
473
+ let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
474
+ currentState = this.filterByActivePriceList(currentState);
475
+ return currentState;
476
+ }
477
+ /**
478
+ * Stream of activeInitialState
479
+ */
480
+ get activeInitialState$() {
481
+ return this.quoteDraft$.pipe(map(() => this.activeInitialState));
482
+ }
483
+ /**
484
+ * activeInitialState is initialState passed through additional filters
485
+ */
486
+ get activeInitialState() {
487
+ var _a, _b;
488
+ const ctx = this.context.resolve();
489
+ let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
490
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
491
+ initialState = this.filterByActivePriceList(initialState);
492
+ }
493
+ return initialState;
494
+ }
495
+ get isStandalone() {
496
+ return this.context.resolve().properties.standalone === 'true';
663
497
  }
664
- else {
665
- return [
666
- Object.assign(Object.assign({}, lineItem), { qty: qty }),
667
- ];
498
+ get isStandalone$() {
499
+ return this.context.resolve$().pipe(map(() => this.isStandalone));
668
500
  }
669
- };
670
-
671
- var lineItem_utils = /*#__PURE__*/Object.freeze({
672
- __proto__: null,
673
- findLineItem: findLineItem,
674
- findLineItemWithComparator: findLineItemWithComparator,
675
- insertLineItem: insertLineItem,
676
- removeLineItem: removeLineItem,
677
- replaceLineItem: replaceLineItem,
678
- mapAttributes: mapAttributes,
679
- getAttributes: getAttributes,
680
- upsertAttributes: upsertAttributes,
681
- patchAttributes: patchAttributes,
682
- getAttributeValue: getAttributeValue,
683
- generateLineItem: generateLineItem,
684
- getRecommendedPrices: getRecommendedPrices,
685
- multiplyLineItems: multiplyLineItems
686
- });
687
-
688
- class LineItemWorker {
689
- constructor(src) {
690
- this.li = Object.assign({}, src);
501
+ getInitialCurrentState() {
502
+ return this.initialCurrentState;
691
503
  }
692
- insert(parentId, toInsert) {
693
- return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
504
+ isEditMode$() {
505
+ return this.context.resolve$().pipe(map(() => this.isEditMode()));
694
506
  }
695
- remove(id) {
696
- return new LineItemWorker(removeLineItem(this.li, id));
507
+ isEditMode() {
508
+ const context = this.context.resolve();
509
+ if (context.mode === ConfigurationContextMode.ACCOUNT) {
510
+ return true;
511
+ }
512
+ if (context.mode === ConfigurationContextMode.QUOTE) {
513
+ return context.properties.Status === 'Draft';
514
+ }
515
+ return false;
697
516
  }
698
- replace(toReplace) {
699
- return new LineItemWorker(replaceLineItem(this.li, toReplace));
517
+ updateActivePriceList(priceListId) {
518
+ this.context.update({ properties: { PriceListId: priceListId } });
700
519
  }
701
- patchAttribute(attrs, id) {
702
- return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
520
+ populateActivePriceLists$() {
521
+ const ctx = this.context.resolve();
522
+ const quoteDraft = this.quoteDraft;
523
+ if (!quoteDraft) {
524
+ return;
525
+ }
526
+ // In ACCOUNT mode populate price lists from related assets
527
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
528
+ // Populate list of price lists
529
+ this.assetPriceLists = quoteDraft.currentState
530
+ .map(({ priceListId }) => priceListId)
531
+ .reduce((trunk, priceListId) => {
532
+ var _a, _b;
533
+ if (!priceListId || trunk.some(item => item.id === priceListId)) {
534
+ return trunk;
535
+ }
536
+ return [
537
+ ...trunk,
538
+ { 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 : '' },
539
+ ];
540
+ }, []);
541
+ }
542
+ }
543
+ filterByActivePriceList(lineItems) {
544
+ const ctx = this.context.resolve();
545
+ return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
546
+ }
547
+ markAsUpdated(quote) {
548
+ if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === ConfigurationContextMode.ACCOUNT) {
549
+ this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
550
+ }
551
+ else {
552
+ this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
553
+ }
703
554
  }
704
555
  }
556
+ 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 });
557
+ QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
558
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, decorators: [{
559
+ type: Injectable,
560
+ args: [{ providedIn: 'root' }]
561
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
705
562
 
706
563
  class ConfigurationService {
707
564
  constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
@@ -734,7 +591,7 @@ class ConfigurationService {
734
591
  this.states.asset = this.states.configurableRamp
735
592
  ? this.runtimeService.getAsset(this.states.configurableRamp)
736
593
  : undefined;
737
- return this.configure().pipe(catchError$1(error => {
594
+ return this.configure().pipe(catchError(error => {
738
595
  console.error(error);
739
596
  if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
740
597
  this.messageService.add({ severity: 'error', summary: error });
@@ -808,13 +665,13 @@ class ConfigurationService {
808
665
  }
809
666
  return lineItem;
810
667
  }))
811
- .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)); })));
668
+ .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)); })));
812
669
  }
813
670
  configureExternal$(productId, qty) {
814
671
  this.updateCurrentStates({
815
672
  currentState: this.quoteDraftService.currentState,
816
673
  });
817
- return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError$1(error => {
674
+ return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError(error => {
818
675
  this.messageService.add({ severity: ToastType.error, summary: error });
819
676
  throw error;
820
677
  }), finalize(() => this.reset()));
@@ -856,11 +713,11 @@ class ConfigurationService {
856
713
  });
857
714
  }
858
715
  }
859
- 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 });
860
- ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService });
861
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService, decorators: [{
716
+ 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 });
717
+ ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService });
718
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService, decorators: [{
862
719
  type: Injectable
863
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i4.MessageService }, { type: i5.DialogService }]; } });
720
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6.DialogService }]; } });
864
721
 
865
722
  class FlowUpdateService {
866
723
  update(rootLineItems, updates) {
@@ -979,9 +836,9 @@ class FlowUpdateService {
979
836
  return true;
980
837
  }
981
838
  }
982
- FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
983
- FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService });
984
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService, decorators: [{
839
+ FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
840
+ FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService });
841
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService, decorators: [{
985
842
  type: Injectable
986
843
  }] });
987
844
 
@@ -1001,7 +858,7 @@ class FlowConfigurationService {
1001
858
  .slice()
1002
859
  .sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
1003
860
  this.quoteDraftService.updateQuoteDraft(result);
1004
- }), map$1(noop));
861
+ }), map$2(noop));
1005
862
  }
1006
863
  calculate(quoteDraft) {
1007
864
  this.calculate$(quoteDraft).subscribe();
@@ -1011,11 +868,11 @@ class FlowConfigurationService {
1011
868
  if (!quoteDraft) {
1012
869
  return of(null);
1013
870
  }
1014
- return of([]).pipe(map$1(() => {
871
+ return of([]).pipe(map$2(() => {
1015
872
  const updatedState = cloneDeep(quoteDraft.currentState);
1016
873
  this.updateService.update(updatedState, updates);
1017
874
  return updatedState;
1018
- }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
875
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1019
876
  }
1020
877
  update(updates) {
1021
878
  this.update$(updates).subscribe();
@@ -1034,7 +891,7 @@ class FlowConfigurationService {
1034
891
  updatedState.splice(currentLineItemIndex, 1, initialLineItem);
1035
892
  return of([]).pipe(tap$1(() => {
1036
893
  this.quoteDraftService.setCurrentLineItemState(updatedState);
1037
- }), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
894
+ }), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1038
895
  }
1039
896
  revert(lineItemId) {
1040
897
  this.revert$(lineItemId).subscribe();
@@ -1045,7 +902,7 @@ class FlowConfigurationService {
1045
902
  if (!quoteDraft) {
1046
903
  return of(null);
1047
904
  }
1048
- 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());
905
+ 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());
1049
906
  }
1050
907
  delete(ids) {
1051
908
  this.delete$(ids).subscribe();
@@ -1056,36 +913,36 @@ class FlowConfigurationService {
1056
913
  return of(null);
1057
914
  }
1058
915
  const updatedState = [...quoteDraft.currentState, term];
1059
- return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
916
+ return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1060
917
  }
1061
918
  addToCart$(productId, qty) {
1062
919
  const quoteDraft = this.quoteDraftService.quoteDraft;
1063
920
  if (!quoteDraft) {
1064
921
  return of(null);
1065
922
  }
1066
- return this.configurationService.configureExternal$(productId, qty).pipe(map$1(lineItem => {
923
+ return this.configurationService.configureExternal$(productId, qty).pipe(map$2(lineItem => {
1067
924
  var _a, _b;
1068
925
  const model = this.configurationService.getRuntimeModel();
1069
926
  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;
1070
927
  const lineItems = multiplyLineItems(lineItem, qty !== null && qty !== void 0 ? qty : 1, split);
1071
928
  return [...quoteDraft.currentState, ...lineItems];
1072
- }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
929
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1073
930
  }
1074
931
  get() {
1075
- return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
932
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
1076
933
  }
1077
934
  getSnapshot() {
1078
935
  var _a, _b;
1079
936
  return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
1080
937
  }
1081
938
  get charges$() {
1082
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ charges }) => charges));
939
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ charges }) => charges));
1083
940
  }
1084
941
  get pricePlans$() {
1085
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ pricePlans }) => pricePlans));
942
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ pricePlans }) => pricePlans));
1086
943
  }
1087
944
  get activeMetrics$() {
1088
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ activeMetrics }) => activeMetrics));
945
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ activeMetrics }) => activeMetrics));
1089
946
  }
1090
947
  get chargesSnapshot() {
1091
948
  var _a, _b;
@@ -1107,7 +964,7 @@ class FlowConfigurationService {
1107
964
  }
1108
965
  handleErrorAndBounceBack() {
1109
966
  return (source$) => {
1110
- return source$.pipe(catchError(error => {
967
+ return source$.pipe(catchError$1(error => {
1111
968
  console.error(error);
1112
969
  // bounce back if configuration call has failed
1113
970
  const quoteDraft = this.quoteDraftService.quoteDraft;
@@ -1119,18 +976,18 @@ class FlowConfigurationService {
1119
976
  };
1120
977
  }
1121
978
  }
1122
- 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 });
1123
- FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService });
1124
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, decorators: [{
979
+ 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 });
980
+ FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService });
981
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService, decorators: [{
1125
982
  type: Injectable
1126
983
  }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1127
984
 
1128
985
  class FlowConfigurationModule {
1129
986
  }
1130
- FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1131
- FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule });
1132
- FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService], imports: [[]] });
1133
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, decorators: [{
987
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
988
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule });
989
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService], imports: [[]] });
990
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1134
991
  type: NgModule,
1135
992
  args: [{
1136
993
  imports: [],
@@ -1140,9 +997,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
1140
997
 
1141
998
  class ConfigurationModule {
1142
999
  }
1143
- ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1144
- ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1145
- ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, providers: [
1000
+ ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1001
+ ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1002
+ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, providers: [
1146
1003
  ContextApiService,
1147
1004
  ProductModelApiService,
1148
1005
  ConfigurationApiService,
@@ -1150,7 +1007,7 @@ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ver
1150
1007
  RuntimeContextService,
1151
1008
  ConfigurationService,
1152
1009
  ], imports: [[ConfirmationDialogModule]] });
1153
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, decorators: [{
1010
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, decorators: [{
1154
1011
  type: NgModule,
1155
1012
  args: [{
1156
1013
  imports: [ConfirmationDialogModule],
@@ -1165,12 +1022,155 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
1165
1022
  }]
1166
1023
  }] });
1167
1024
 
1025
+ function calculateMetricByMethod(lineItems, metric, method) {
1026
+ const items = getLineItemsByMethod(lineItems, method);
1027
+ return items.reduce((acc, li) => {
1028
+ let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
1029
+ if (method === 'avg' && li.length > 0) {
1030
+ value /= li.length;
1031
+ }
1032
+ return acc + value;
1033
+ }, 0);
1034
+ }
1035
+ function getLineItemsByMethod(lineItems, method) {
1036
+ switch (method) {
1037
+ case 'first': {
1038
+ return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
1039
+ }
1040
+ case 'last': {
1041
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1042
+ const products = rootTermItems.map(lineItem => [
1043
+ lineItem,
1044
+ ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
1045
+ ]);
1046
+ return products
1047
+ .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
1048
+ .filter((li) => Boolean(li))
1049
+ .map(item => [item]);
1050
+ }
1051
+ case 'avg': {
1052
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1053
+ return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
1054
+ }
1055
+ case 'sum': {
1056
+ return lineItems.map(item => [item]);
1057
+ }
1058
+ default: {
1059
+ return lineItems.map(item => [item]);
1060
+ }
1061
+ }
1062
+ }
1063
+ function getDateValue(date) {
1064
+ return date ? new Date(date).getTime() : 0;
1065
+ }
1066
+
1067
+ class MetricsCalculationService {
1068
+ constructor(quoteDraftService, flowConfiguration, settingsService) {
1069
+ this.quoteDraftService = quoteDraftService;
1070
+ this.flowConfiguration = flowConfiguration;
1071
+ this.settingsService = settingsService;
1072
+ this.metricsUpdated$ = new Subject();
1073
+ this.quoteMetricsSettings = {};
1074
+ this.metricsCalculationMethodMap = {};
1075
+ this.metricsData = {};
1076
+ this.activeMetricRules = [];
1077
+ this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(metricRule => metricRule.metrics.some(metric => !!metric.totalName));
1078
+ combineLatest([
1079
+ this.quoteDraftService.currentState$,
1080
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
1081
+ ]).subscribe(([lineItems, setting]) => {
1082
+ let settingsData = {};
1083
+ try {
1084
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
1085
+ }
1086
+ catch (error) {
1087
+ settingsData = {};
1088
+ }
1089
+ this.quoteMetricsSettings = settingsData;
1090
+ this.updateMetrics(lineItems);
1091
+ });
1092
+ }
1093
+ get onMetricsUpdate$() {
1094
+ return this.metricsUpdated$.asObservable();
1095
+ }
1096
+ getMetricValue(metric) {
1097
+ return this.metricsData[metric] || 0;
1098
+ }
1099
+ updateMetrics(lineItems) {
1100
+ const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
1101
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
1102
+ this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
1103
+ this.metricsUpdated$.next();
1104
+ }
1105
+ calculateMetric(lineItems, metric) {
1106
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
1107
+ }
1108
+ buildMetricsCalculationMethods(metricKeys, initial) {
1109
+ return metricKeys.reduce((acc, name) => {
1110
+ var _a, _b;
1111
+ if (acc[name]) {
1112
+ return acc;
1113
+ }
1114
+ acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
1115
+ const metricRule = this.getMetricRuleByTotalMetricName(name);
1116
+ 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;
1117
+ if (this.quoteMetricsSettings[settingKey]) {
1118
+ acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
1119
+ }
1120
+ return acc;
1121
+ }, initial);
1122
+ }
1123
+ collectMetricKeys(lineItems) {
1124
+ const keys = [];
1125
+ lineItems.forEach(lineItem => {
1126
+ keys.push(...Object.keys(lineItem.totalMetrics || {}));
1127
+ keys.push(...this.collectMetricKeys(lineItem.lineItems));
1128
+ });
1129
+ return uniq(keys);
1130
+ }
1131
+ getMetricRuleByTotalMetricName(name) {
1132
+ return this.activeMetricRules.find(metricRule => metricRule.metrics.find(metric => metric.totalName === name));
1133
+ }
1134
+ }
1135
+ 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 });
1136
+ MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
1137
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, decorators: [{
1138
+ type: Injectable,
1139
+ args: [{ providedIn: 'root' }]
1140
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1.ConfigurationSettingsApiService }]; } });
1141
+
1142
+ class ProductImagesService {
1143
+ constructor(productApiService) {
1144
+ this.productApiService = productApiService;
1145
+ this.imagesMap$ = new BehaviorSubject({});
1146
+ }
1147
+ getImageUrl$(productId) {
1148
+ if (this.imagesMap$.value[productId] == null) {
1149
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
1150
+ this.fetchProductImage(productId);
1151
+ }
1152
+ return this.imagesMap$.pipe(map$2(imagesMap => imagesMap[productId]), distinctUntilChanged());
1153
+ }
1154
+ fetchProductImage(productId) {
1155
+ this.productApiService
1156
+ .fetchImage$(productId)
1157
+ .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 }))))
1158
+ .subscribe();
1159
+ }
1160
+ }
1161
+ ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1162
+ ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
1163
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, decorators: [{
1164
+ type: Injectable,
1165
+ args: [{ providedIn: 'root' }]
1166
+ }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
1167
+
1168
1168
  class SdkCoreModule {
1169
1169
  }
1170
- SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1171
- SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1172
- SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1173
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, decorators: [{
1170
+ SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1171
+ SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1172
+ SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1173
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, decorators: [{
1174
1174
  type: NgModule,
1175
1175
  args: [{
1176
1176
  imports: [ConfigurationModule, FlowConfigurationModule],