@veloceapps/sdk 6.0.0-9 → 6.0.0-91

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