@veloceapps/sdk 6.0.0-10 → 6.0.0-101

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