@veloceapps/sdk 8.0.0-8 → 8.0.0-80

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. package/README.md +0 -1
  2. package/cms/utils/element.utils.d.ts +1 -0
  3. package/cms/vendor-map.d.ts +2 -1
  4. package/core/modules/configuration/services/configuration-runtime.service.d.ts +1 -1
  5. package/core/modules/configuration/services/configuration.service.d.ts +6 -1
  6. package/core/modules/flow-configuration/types/update.types.d.ts +1 -1
  7. package/core/pipes/action-code.pipe.d.ts +8 -0
  8. package/core/pipes/index.d.ts +1 -0
  9. package/core/pipes/pipes.module.d.ts +2 -1
  10. package/core/services/context.service.d.ts +1 -0
  11. package/core/services/runtime-settings.service.d.ts +4 -1
  12. package/core/types/formatting-settings.types.d.ts +2 -0
  13. package/esm2020/cms/components/element-children/element-children.component.mjs +3 -3
  14. package/esm2020/cms/components/element-children/element-children.module.mjs +4 -4
  15. package/esm2020/cms/components/element-drop-handle/element-drop-handle.component.mjs +3 -3
  16. package/esm2020/cms/components/element-drop-handle/element-drop-handle.module.mjs +4 -4
  17. package/esm2020/cms/components/element-renderer/element-renderer.component.mjs +3 -3
  18. package/esm2020/cms/components/element-renderer/element-renderer.module.mjs +4 -4
  19. package/esm2020/cms/components/element-tools-panel/element-tools-panel.component.mjs +5 -5
  20. package/esm2020/cms/components/plugin.component.mjs +3 -3
  21. package/esm2020/cms/components/preview/preview.component.mjs +3 -3
  22. package/esm2020/cms/components/preview/preview.module.mjs +4 -4
  23. package/esm2020/cms/directives/custom-template.directive.mjs +7 -7
  24. package/esm2020/cms/launcher.module.mjs +4 -4
  25. package/esm2020/cms/modules/federated/federated-host.directive.mjs +3 -3
  26. package/esm2020/cms/modules/federated/federated.component.mjs +3 -3
  27. package/esm2020/cms/modules/federated/federated.module.mjs +4 -4
  28. package/esm2020/cms/modules/migrations/migrations.module.mjs +4 -4
  29. package/esm2020/cms/modules/migrations/services/migrations.service.mjs +3 -3
  30. package/esm2020/cms/modules/runtime/runtime.module.mjs +4 -4
  31. package/esm2020/cms/modules/runtime/services/compilation.service.mjs +3 -3
  32. package/esm2020/cms/modules/runtime/services/runtime-editor.service.mjs +3 -3
  33. package/esm2020/cms/modules/runtime/services/runtime.service.mjs +3 -3
  34. package/esm2020/cms/plugins/configuration.plugin.mjs +3 -3
  35. package/esm2020/cms/plugins/element-hover.plugin.mjs +3 -3
  36. package/esm2020/cms/plugins/io.plugin.mjs +8 -7
  37. package/esm2020/cms/plugins/page.plugin.mjs +3 -3
  38. package/esm2020/cms/plugins/region.plugin.mjs +3 -3
  39. package/esm2020/cms/plugins/script.plugin.mjs +3 -3
  40. package/esm2020/cms/services/element-context.service.mjs +3 -3
  41. package/esm2020/cms/services/integration.state.mjs +3 -3
  42. package/esm2020/cms/services/io-provider.service.mjs +3 -3
  43. package/esm2020/cms/services/resources.service.mjs +3 -3
  44. package/esm2020/cms/services/templates.service.mjs +3 -3
  45. package/esm2020/cms/utils/element.utils.mjs +10 -3
  46. package/esm2020/cms/utils/elements-resolver.mjs +2 -2
  47. package/esm2020/cms/vendor-map.mjs +3 -2
  48. package/esm2020/core/core.module.mjs +7 -6
  49. package/esm2020/core/directives/directives.module.mjs +4 -4
  50. package/esm2020/core/directives/primeng-calendar.directive.mjs +3 -3
  51. package/esm2020/core/modules/configuration/configuration.module.mjs +4 -4
  52. package/esm2020/core/modules/configuration/services/configuration-runtime.service.mjs +11 -14
  53. package/esm2020/core/modules/configuration/services/configuration.service.mjs +28 -9
  54. package/esm2020/core/modules/configuration/services/configuration.state.mjs +3 -3
  55. package/esm2020/core/modules/configuration/services/runtime-context.service.mjs +9 -9
  56. package/esm2020/core/modules/flow-configuration/flow-configuration.module.mjs +4 -4
  57. package/esm2020/core/modules/flow-configuration/services/flow-configuration.service.mjs +3 -3
  58. package/esm2020/core/modules/flow-configuration/services/flow-update.service.mjs +7 -14
  59. package/esm2020/core/modules/flow-configuration/types/update.types.mjs +1 -1
  60. package/esm2020/core/pipes/action-code.pipe.mjs +20 -0
  61. package/esm2020/core/pipes/date.pipe.mjs +3 -3
  62. package/esm2020/core/pipes/index.mjs +2 -1
  63. package/esm2020/core/pipes/number.pipe.mjs +3 -3
  64. package/esm2020/core/pipes/pipes.module.mjs +8 -7
  65. package/esm2020/core/pipes/price.pipe.mjs +3 -3
  66. package/esm2020/core/services/context.service.mjs +17 -5
  67. package/esm2020/core/services/metric-calculation/metric-calculation.service.mjs +3 -3
  68. package/esm2020/core/services/product-images.service.mjs +3 -3
  69. package/esm2020/core/services/quote-draft.service.mjs +3 -3
  70. package/esm2020/core/services/runtime-settings.service.mjs +20 -5
  71. package/esm2020/core/types/formatting-settings.types.mjs +1 -1
  72. package/esm2020/src/components/dialog/dialog.component.mjs +3 -3
  73. package/esm2020/src/components/dialog/dialog.module.mjs +4 -4
  74. package/esm2020/src/components/doc-gen/doc-gen.component.mjs +11 -15
  75. package/esm2020/src/components/doc-gen/doc-gen.module.mjs +4 -4
  76. package/esm2020/src/components/guided-selling/guided-selling.component.mjs +10 -13
  77. package/esm2020/src/components/guided-selling/guided-selling.module.mjs +4 -4
  78. package/esm2020/src/components/header/cart-overlay/cart-preview.component.mjs +3 -3
  79. package/esm2020/src/components/header/cart-overlay/cart-preview.module.mjs +4 -4
  80. package/esm2020/src/components/header/header.component.mjs +4 -4
  81. package/esm2020/src/components/header/header.module.mjs +4 -4
  82. package/esm2020/src/components/header/metrics/metrics.component.mjs +4 -4
  83. package/esm2020/src/components/header/metrics/metrics.module.mjs +4 -4
  84. package/esm2020/src/flow-routing.module.mjs +5 -22
  85. package/esm2020/src/flow.component.mjs +3 -3
  86. package/esm2020/src/flow.module.mjs +4 -4
  87. package/esm2020/src/guards/context.guard.mjs +3 -3
  88. package/esm2020/src/guards/product-unload.guard.mjs +7 -4
  89. package/esm2020/src/guards/root.guard.mjs +3 -3
  90. package/esm2020/src/pages/assets/assets.component.mjs +3 -3
  91. package/esm2020/src/pages/assets/assets.module.mjs +4 -4
  92. package/esm2020/src/pages/catalog/catalog.component.mjs +3 -3
  93. package/esm2020/src/pages/catalog/catalog.module.mjs +4 -4
  94. package/esm2020/src/pages/debug/debug.component.mjs +3 -3
  95. package/esm2020/src/pages/debug/debug.module.mjs +4 -4
  96. package/esm2020/src/pages/empty-account/empty-account.component.mjs +3 -3
  97. package/esm2020/src/pages/empty-account/empty-account.module.mjs +4 -4
  98. package/esm2020/src/pages/product/product.component.mjs +5 -6
  99. package/esm2020/src/pages/product/product.module.mjs +4 -4
  100. package/esm2020/src/pages/record-not-found/record-not-found.component.mjs +3 -3
  101. package/esm2020/src/pages/record-not-found/record-not-found.module.mjs +4 -4
  102. package/esm2020/src/pages/remote/remote.component.mjs +8 -9
  103. package/esm2020/src/pages/remote/remote.module.mjs +4 -4
  104. package/esm2020/src/pages/shopping-cart/shopping-cart.component.mjs +3 -3
  105. package/esm2020/src/pages/shopping-cart/shopping-cart.module.mjs +4 -4
  106. package/esm2020/src/resolvers/flow.resolver.mjs +3 -3
  107. package/esm2020/src/resolvers/quote.resolver.mjs +3 -3
  108. package/esm2020/src/services/doc-gen.service.mjs +3 -3
  109. package/esm2020/src/services/flow-dialog.service.mjs +3 -3
  110. package/esm2020/src/services/flow-router.service.mjs +5 -5
  111. package/esm2020/src/services/flow.service.mjs +13 -5
  112. package/esm2020/src/services/guided-selling.service.mjs +3 -3
  113. package/fesm2015/veloceapps-sdk-cms.mjs +123 -114
  114. package/fesm2015/veloceapps-sdk-cms.mjs.map +1 -1
  115. package/fesm2015/veloceapps-sdk-core.mjs +1053 -1000
  116. package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
  117. package/fesm2015/veloceapps-sdk.mjs +221 -364
  118. package/fesm2015/veloceapps-sdk.mjs.map +1 -1
  119. package/fesm2020/veloceapps-sdk-cms.mjs +123 -114
  120. package/fesm2020/veloceapps-sdk-cms.mjs.map +1 -1
  121. package/fesm2020/veloceapps-sdk-core.mjs +578 -527
  122. package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
  123. package/fesm2020/veloceapps-sdk.mjs +218 -365
  124. package/fesm2020/veloceapps-sdk.mjs.map +1 -1
  125. package/package.json +3 -11
  126. package/src/components/doc-gen/doc-gen.component.d.ts +3 -6
  127. package/src/components/guided-selling/guided-selling.component.d.ts +2 -4
  128. package/src/flow-routing.module.d.ts +6 -7
  129. package/src/guards/product-unload.guard.d.ts +2 -2
  130. package/esm2020/runtime/components/component-preview/component-preview.component.mjs +0 -125
  131. package/esm2020/runtime/components/index.mjs +0 -5
  132. package/esm2020/runtime/components/section-renderer/section-renderer.component.mjs +0 -67
  133. package/esm2020/runtime/components/ui-runtime/runtime.component.mjs +0 -440
  134. package/esm2020/runtime/components/ui-runtime-preview/runtime-preview.component.mjs +0 -108
  135. package/esm2020/runtime/execution/components/children-placeholder/children-placeholder.component.mjs +0 -60
  136. package/esm2020/runtime/execution/components/context-provider/context-provider.component.mjs +0 -39
  137. package/esm2020/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.mjs +0 -67
  138. package/esm2020/runtime/execution/components/federated/federated.component.mjs +0 -74
  139. package/esm2020/runtime/execution/components/velo-attribute/velo-attribute.component.mjs +0 -60
  140. package/esm2020/runtime/execution/components/velo-multiselect/velo-multiselect.component.mjs +0 -130
  141. package/esm2020/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.mjs +0 -72
  142. package/esm2020/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.mjs +0 -97
  143. package/esm2020/runtime/execution/components/velo-port-radio/velo-port-radio.component.mjs +0 -142
  144. package/esm2020/runtime/execution/components/velo-type/velo-type.component.mjs +0 -119
  145. package/esm2020/runtime/execution/directives/section-script.directive.mjs +0 -247
  146. package/esm2020/runtime/execution/directives/sf-query.directive.mjs +0 -35
  147. package/esm2020/runtime/execution/directives/velo-attribute.directive.mjs +0 -88
  148. package/esm2020/runtime/execution/directives/velo-port.directive.mjs +0 -376
  149. package/esm2020/runtime/execution/directives/vl-approval.directive.mjs +0 -23
  150. package/esm2020/runtime/execution/directives/vl-document-attachments.directive.mjs +0 -36
  151. package/esm2020/runtime/execution/directives/vl-document-templates.directive.mjs +0 -60
  152. package/esm2020/runtime/execution/directives/vl-quote.directive.mjs +0 -42
  153. package/esm2020/runtime/execution/directives/vl-ramp.directive.mjs +0 -55
  154. package/esm2020/runtime/execution/runtime-execution.module.mjs +0 -133
  155. package/esm2020/runtime/execution/utils/federated.util.mjs +0 -32
  156. package/esm2020/runtime/index.mjs +0 -5
  157. package/esm2020/runtime/runtime.module.mjs +0 -74
  158. package/esm2020/runtime/services/cart.service.mjs +0 -29
  159. package/esm2020/runtime/services/collapsible-state.service.mjs +0 -34
  160. package/esm2020/runtime/services/configuration.service.mjs +0 -119
  161. package/esm2020/runtime/services/current-state.service.mjs +0 -17
  162. package/esm2020/runtime/services/form-scope.service.mjs +0 -30
  163. package/esm2020/runtime/services/index.mjs +0 -4
  164. package/esm2020/runtime/services/product-model-cache.service.mjs +0 -31
  165. package/esm2020/runtime/services/runtime-context.service.mjs +0 -60
  166. package/esm2020/runtime/services/runtime-form.service.mjs +0 -219
  167. package/esm2020/runtime/services/runtime.service.mjs +0 -115
  168. package/esm2020/runtime/services/section-helper.service.mjs +0 -27
  169. package/esm2020/runtime/services/section-scope.service.mjs +0 -36
  170. package/esm2020/runtime/services/section-store.service.mjs +0 -22
  171. package/esm2020/runtime/services/section.service.mjs +0 -117
  172. package/esm2020/runtime/types/bound-data.types.mjs +0 -7
  173. package/esm2020/runtime/types/index.mjs +0 -3
  174. package/esm2020/runtime/types/quote-states.types.mjs +0 -2
  175. package/esm2020/runtime/types/runtime.types.mjs +0 -2
  176. package/esm2020/runtime/types/script-registry.types.mjs +0 -51
  177. package/esm2020/runtime/utils/line-item.util.mjs +0 -270
  178. package/esm2020/runtime/utils/section.utils.mjs +0 -26
  179. package/esm2020/runtime/utils/sections-binder.helper.mjs +0 -105
  180. package/esm2020/runtime/veloceapps-sdk-runtime.mjs +0 -5
  181. package/esm2020/src/pages/legacy-product/legacy-product.component.mjs +0 -137
  182. package/esm2020/src/pages/legacy-product/legacy-product.module.mjs +0 -19
  183. package/fesm2015/veloceapps-sdk-runtime.mjs +0 -3770
  184. package/fesm2015/veloceapps-sdk-runtime.mjs.map +0 -1
  185. package/fesm2020/veloceapps-sdk-runtime.mjs +0 -3767
  186. package/fesm2020/veloceapps-sdk-runtime.mjs.map +0 -1
  187. package/runtime/README.md +0 -5
  188. package/runtime/components/component-preview/component-preview.component.d.ts +0 -27
  189. package/runtime/components/index.d.ts +0 -4
  190. package/runtime/components/section-renderer/section-renderer.component.d.ts +0 -25
  191. package/runtime/components/ui-runtime/runtime.component.d.ts +0 -53
  192. package/runtime/components/ui-runtime-preview/runtime-preview.component.d.ts +0 -27
  193. package/runtime/execution/components/children-placeholder/children-placeholder.component.d.ts +0 -30
  194. package/runtime/execution/components/context-provider/context-provider.component.d.ts +0 -14
  195. package/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.d.ts +0 -25
  196. package/runtime/execution/components/federated/federated.component.d.ts +0 -36
  197. package/runtime/execution/components/velo-attribute/velo-attribute.component.d.ts +0 -19
  198. package/runtime/execution/components/velo-multiselect/velo-multiselect.component.d.ts +0 -35
  199. package/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.d.ts +0 -22
  200. package/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.d.ts +0 -22
  201. package/runtime/execution/components/velo-port-radio/velo-port-radio.component.d.ts +0 -28
  202. package/runtime/execution/components/velo-type/velo-type.component.d.ts +0 -31
  203. package/runtime/execution/directives/section-script.directive.d.ts +0 -59
  204. package/runtime/execution/directives/sf-query.directive.d.ts +0 -15
  205. package/runtime/execution/directives/velo-attribute.directive.d.ts +0 -26
  206. package/runtime/execution/directives/velo-port.directive.d.ts +0 -74
  207. package/runtime/execution/directives/vl-approval.directive.d.ts +0 -10
  208. package/runtime/execution/directives/vl-document-attachments.directive.d.ts +0 -15
  209. package/runtime/execution/directives/vl-document-templates.directive.d.ts +0 -33
  210. package/runtime/execution/directives/vl-quote.directive.d.ts +0 -14
  211. package/runtime/execution/directives/vl-ramp.directive.d.ts +0 -15
  212. package/runtime/execution/runtime-execution.module.d.ts +0 -25
  213. package/runtime/execution/utils/federated.util.d.ts +0 -6
  214. package/runtime/index.d.ts +0 -4
  215. package/runtime/runtime.module.d.ts +0 -16
  216. package/runtime/services/cart.service.d.ts +0 -15
  217. package/runtime/services/collapsible-state.service.d.ts +0 -15
  218. package/runtime/services/configuration.service.d.ts +0 -20
  219. package/runtime/services/current-state.service.d.ts +0 -8
  220. package/runtime/services/form-scope.service.d.ts +0 -20
  221. package/runtime/services/index.d.ts +0 -3
  222. package/runtime/services/product-model-cache.service.d.ts +0 -14
  223. package/runtime/services/runtime-context.service.d.ts +0 -16
  224. package/runtime/services/runtime-form.service.d.ts +0 -24
  225. package/runtime/services/runtime.service.d.ts +0 -44
  226. package/runtime/services/section-helper.service.d.ts +0 -8
  227. package/runtime/services/section-scope.service.d.ts +0 -14
  228. package/runtime/services/section-store.service.d.ts +0 -11
  229. package/runtime/services/section.service.d.ts +0 -30
  230. package/runtime/types/bound-data.types.d.ts +0 -13
  231. package/runtime/types/index.d.ts +0 -2
  232. package/runtime/types/quote-states.types.d.ts +0 -6
  233. package/runtime/types/runtime.types.d.ts +0 -19
  234. package/runtime/types/script-registry.types.d.ts +0 -13
  235. package/runtime/utils/line-item.util.d.ts +0 -34
  236. package/runtime/utils/section.utils.d.ts +0 -2
  237. package/runtime/utils/sections-binder.helper.d.ts +0 -16
  238. package/src/pages/legacy-product/legacy-product.component.d.ts +0 -37
  239. package/src/pages/legacy-product/legacy-product.module.d.ts +0 -9
@@ -1,17 +1,17 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, Injectable, NgModule, inject, Directive, Input, LOCALE_ID, Pipe } from '@angular/core';
3
- import { UUID, ConfigurationContextMode, ConfigurationContext, RuntimeModel, getUIDefinitionProperties, isLegacyUIDefinition, SalesforceIdUtils, ConfigurationMode, ConfigurationTranslatorUtils, EntityUtil, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, parseJsonSafely, formatNumber } from '@veloceapps/core';
4
- import { BehaviorSubject, combineLatest, zip, noop, throwError, shareReplay as shareReplay$1, switchMap as switchMap$1, of, tap as tap$1, map as map$2, 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';
3
+ import { UUID, ConfigurationContextMode, ConfigurationContext, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, DEFAULT_ACTION_CODE_LABELS, parseJsonSafely, ConfigurationMode, ConfigurationTranslatorUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, EntityUtil, formatNumber } from '@veloceapps/core';
4
+ import { BehaviorSubject, zip, noop, combineLatest, map as map$2, tap as tap$1, throwError, shareReplay as shareReplay$1, of, switchMap as switchMap$1, catchError as catchError$1, Subject, take as take$1, distinctUntilChanged } from 'rxjs';
5
+ import { filter, tap, map, switchMap, skip, take, shareReplay, catchError, finalize, first } from 'rxjs/operators';
6
6
  import * as i1 from '@veloceapps/api';
7
7
  import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloceapps/api';
8
- import { merge, flatten, sortBy, map as map$1, isEqual, transform, omit, cloneDeep, uniq } from 'lodash';
8
+ import { merge, isEqual, flatten, sortBy, map as map$1, omit, uniqBy, transform, cloneDeep, uniq } from 'lodash';
9
+ import moment from 'moment';
9
10
  import { HttpErrorResponse } from '@angular/common/http';
10
11
  import * as i4 from '@veloceapps/components';
11
12
  import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
12
13
  import * as i5 from 'primeng/api';
13
14
  import * as i6 from 'primeng/dynamicdialog';
14
- import moment from 'moment';
15
15
  import { NgControl } from '@angular/forms';
16
16
  import { DATE_PIPE_DEFAULT_OPTIONS, formatDate } from '@angular/common';
17
17
 
@@ -97,6 +97,13 @@ class ContextService {
97
97
  create(headerId, mode) {
98
98
  return this.contextApiService.getContext(headerId, mode).pipe(tap(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map(() => this.resolve()));
99
99
  }
100
+ initTestMode() {
101
+ return this.create('TestId', ConfigurationContextMode.TEST).pipe(map(context => {
102
+ return this.update({
103
+ properties: Object.assign(Object.assign({}, context.properties), { RuntimeMode: ConfigurationContextMode.TEST, StartDate: new Date().toISOString().substring(0, 10), standalone: 'true' }),
104
+ });
105
+ }));
106
+ }
100
107
  update(partialContext) {
101
108
  const originalContext = this.resolve();
102
109
  const updatedContext = Object.assign(Object.assign(Object.assign({}, originalContext), partialContext), { properties: Object.assign(Object.assign({}, originalContext.properties), partialContext.properties) });
@@ -113,179 +120,306 @@ class ContextService {
113
120
  this.context.next(null);
114
121
  }
115
122
  }
116
- ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
117
- ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ContextService, providedIn: 'root' });
118
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ContextService, decorators: [{
123
+ ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
124
+ ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService, providedIn: 'root' });
125
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextService, decorators: [{
119
126
  type: Injectable,
120
127
  args: [{ providedIn: 'root' }]
121
128
  }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
122
129
 
123
- class RuntimeContextService {
124
- constructor(configurationApiService) {
125
- this.configurationApiService = configurationApiService;
126
- }
127
- getRuntimeContext(productId, offeringId) {
128
- return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(map(runtimeData => {
129
- var _a;
130
- const uiDefinitionContainer = this.getUIDefinitionContainer(runtimeData);
131
- const runtimeModel = RuntimeModel.create(runtimeData.types, runtimeData.products);
132
- const { productName, properties } = (_a = Array.from(runtimeModel.components.values()).find(c => c.productId === productId)) !== null && _a !== void 0 ? _a : {};
133
- const uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
134
- return {
135
- modelId: runtimeData.modelId,
136
- uiDefinitionContainer: uiDefinitionContainer,
137
- runtimeModel: runtimeModel,
138
- runtimeMode: RuntimeMode.PROD,
139
- productId: productId,
140
- productType: (properties === null || properties === void 0 ? void 0 : properties['displayName']) || productName,
141
- offeringId: offeringId,
142
- properties: {
143
- PricingEnabled: uiDefinitionProperties.pricingEnabled ? 'true' : 'false',
144
- PriceListId: uiDefinitionProperties.priceList,
145
- },
146
- };
147
- }));
148
- }
149
- getUIDefinitionContainer(runtimeData) {
150
- var _a;
151
- const containers = runtimeData.uiDefinitions.filter(container => !isLegacyUIDefinition(container.source));
152
- return (_a = containers.find(container => container.source.primary)) !== null && _a !== void 0 ? _a : containers[0];
130
+ function calculateMetricByMethod(lineItems, metric, method) {
131
+ const items = getLineItemsByMethod(lineItems, method);
132
+ return items.reduce((acc, li) => {
133
+ let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
134
+ if (method === 'avg' && li.length > 0) {
135
+ value /= li.length;
136
+ }
137
+ return acc + value;
138
+ }, 0);
139
+ }
140
+ function getLineItemsByMethod(lineItems, method) {
141
+ switch (method) {
142
+ case 'first': {
143
+ return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
144
+ }
145
+ case 'last': {
146
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
147
+ const products = rootTermItems.map(lineItem => [
148
+ lineItem,
149
+ ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
150
+ ]);
151
+ return products
152
+ .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
153
+ .filter((li) => Boolean(li))
154
+ .map(item => [item]);
155
+ }
156
+ case 'avg': {
157
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
158
+ return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
159
+ }
160
+ case 'sum': {
161
+ return lineItems.map(item => [item]);
162
+ }
163
+ default: {
164
+ return lineItems.map(item => [item]);
165
+ }
153
166
  }
154
167
  }
155
- RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
156
- RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeContextService });
157
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeContextService, decorators: [{
158
- type: Injectable
159
- }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
168
+ function getDateValue(date) {
169
+ return date ? new Date(date).getTime() : 0;
170
+ }
160
171
 
161
- class ConfigurationRuntimeService {
162
- constructor(apiService, contextService, runtimeContextService) {
163
- this.apiService = apiService;
164
- this.contextService = contextService;
165
- this.runtimeContextService = runtimeContextService;
166
- this._isInitialized = false;
167
- this.uiDefinitionProperties = {};
172
+ class QuoteDraftService {
173
+ get isInitialized() {
174
+ return this.isInitializedSubj$.getValue();
168
175
  }
169
- reset() {
170
- this._isInitialized = false;
171
- this._runtimeContext = undefined;
172
- this.initializationProps = undefined;
173
- this.uiDefinitionProperties = {};
176
+ set isInitialized(value) {
177
+ if (this.isInitialized !== value) {
178
+ this.isInitializedSubj$.next(value);
179
+ }
174
180
  }
175
- initTestMode(uiDefinitionContainer) {
176
- var _a;
177
- this.uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
178
- const uiDefinitionExternals = (_a = uiDefinitionContainer.source.externals) !== null && _a !== void 0 ? _a : {};
179
- return combineLatest([
180
- this.apiService.getRuntimeDataByModelId(uiDefinitionContainer.modelId),
181
- this.contextService.create('TestId', ConfigurationContextMode.TEST),
182
- ]).pipe(first(), map(([runtimeData, context]) => {
183
- var _a;
184
- this.contextService.update({
185
- properties: Object.assign(Object.assign(Object.assign(Object.assign({}, (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.properties), context.properties), { ModelId: uiDefinitionContainer.modelId, RuntimeMode: ConfigurationContextMode.TEST, PricingEnabled: this.uiDefinitionProperties.pricingEnabled ? 'true' : 'false', StartDate: new Date().toISOString().substring(0, 10), PriceListId: this.uiDefinitionProperties.priceList, offeringId: this.uiDefinitionProperties.offeringId, standalone: 'true' }), uiDefinitionExternals),
186
- });
187
- this._runtimeContext = {
188
- modelId: uiDefinitionContainer.modelId,
189
- runtimeModel: RuntimeModel.create(runtimeData.types, runtimeData.products),
190
- runtimeMode: RuntimeMode.TEST,
191
- uiDefinitionContainer,
192
- };
193
- return this._runtimeContext;
194
- }), tap(() => (this._isInitialized = true)));
181
+ get hasUnsavedChanges() {
182
+ return this._hasUnsavedChanges;
195
183
  }
196
- init(props) {
197
- this.initializationProps = props;
198
- const context = this.contextService.resolve();
199
- return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
200
- var _a, _b;
201
- this.uiDefinitionProperties = getUIDefinitionProperties(runtimeContext.uiDefinitionContainer);
202
- const { PriceListId } = (_a = context.properties) !== null && _a !== void 0 ? _a : {};
203
- const mergeContext = Object.assign(Object.assign({}, runtimeContext), { properties: Object.assign(Object.assign(Object.assign({}, runtimeContext.properties), context.properties), { PricingEnabled: PriceListId ? 'true' : 'false' }) });
204
- this.id15to18('AccountId', mergeContext.properties);
205
- this._runtimeContext = mergeContext;
206
- if (context.properties && ((_b = this._runtimeContext.properties) === null || _b === void 0 ? void 0 : _b.StartDate)) {
207
- this.contextService.update({
208
- properties: Object.assign(Object.assign({}, this._runtimeContext.properties), context.properties),
209
- });
210
- }
211
- return this._runtimeContext;
212
- }), tap(() => (this._isInitialized = true)));
184
+ set hasUnsavedChanges(value) {
185
+ var _a, _b;
186
+ this._hasUnsavedChanges = value;
187
+ if (!this._hasUnsavedChanges) {
188
+ this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
189
+ }
213
190
  }
214
- overrideUIDefinition(uiDefinitionContainer) {
215
- if (!this._runtimeContext) {
191
+ get hasProducts$() {
192
+ return this.quoteSubj$.pipe(map(() => this.hasProducts));
193
+ }
194
+ get hasProducts() {
195
+ const quoteDraft = this.quoteSubj$.value;
196
+ return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
197
+ }
198
+ constructor(context, quoteApiService, priceApiService) {
199
+ this.context = context;
200
+ this.quoteApiService = quoteApiService;
201
+ this.priceApiService = priceApiService;
202
+ this.quoteSubj$ = new BehaviorSubject(null);
203
+ this.resetSubj$ = new BehaviorSubject(true);
204
+ this.isInitializedSubj$ = new BehaviorSubject(false);
205
+ this.initialCurrentState = [];
206
+ this._hasUnsavedChanges = false;
207
+ this.allPriceLists = [];
208
+ this.assetPriceLists = [];
209
+ this.reset$ = this.resetSubj$.asObservable();
210
+ 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));
211
+ this.isInitializedSubj$
212
+ .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
213
+ .subscribe();
214
+ }
215
+ reset() {
216
+ this.resetSubj$.next(true);
217
+ this.quoteSubj$.next(null);
218
+ this.hasUnsavedChanges = false;
219
+ }
220
+ init(quoteId, params) {
221
+ return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
222
+ this.allPriceLists = allPriceLists;
223
+ this.quoteSubj$.next(quote);
224
+ this.context.update(quote.context);
225
+ this.populateActivePriceLists$();
226
+ }), map(() => noop()), take(1));
227
+ }
228
+ setCurrentLineItemState(lineItems) {
229
+ const quoteDraft = this.quoteSubj$.value;
230
+ if (!quoteDraft) {
216
231
  return;
217
232
  }
218
- this._runtimeContext.uiDefinitionContainer = uiDefinitionContainer;
219
- this.uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
233
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
220
234
  }
221
- id15to18(propertyName, source) {
222
- if (!source) {
235
+ updateQuoteDraft(update) {
236
+ const quoteDraft = this.quoteSubj$.value;
237
+ if (!quoteDraft) {
223
238
  return;
224
239
  }
225
- const value = source[propertyName];
226
- if (typeof value === 'string' && value.length === 15) {
227
- source[propertyName] = SalesforceIdUtils.generateId18FromId15(value);
240
+ if (update.context) {
241
+ this.context.set(update.context);
228
242
  }
243
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
229
244
  }
230
- get isInitialized() {
231
- return this._isInitialized;
232
- }
233
- get runtimeModel() {
234
- var _a;
235
- return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
245
+ updateByPriceSummary(priceSummary) {
246
+ const quoteDraft = this.quoteSubj$.value;
247
+ if (!quoteDraft) {
248
+ return;
249
+ }
250
+ const updatedCurrentState = this.currentState.map(lineItem => {
251
+ const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
252
+ return updated !== null && updated !== void 0 ? updated : lineItem;
253
+ });
254
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
236
255
  }
237
- get runtimeContext() {
238
- return this._runtimeContext;
256
+ get quoteDraft$() {
257
+ return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
239
258
  }
240
- }
241
- ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
242
- ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationRuntimeService });
243
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
244
- type: Injectable
245
- }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
246
-
247
- const findLineItem = (id, lineItems) => {
248
- return findLineItemWithComparator(lineItems, (li) => li.id === id);
249
- };
250
- const findLineItemWithComparator = (lineItems, comparator) => {
251
- let currentLevel = lineItems;
252
- while (currentLevel.length) {
253
- const found = currentLevel.find(comparator);
254
- if (found) {
255
- return found;
259
+ get quoteDraft() {
260
+ const quote = this.quoteSubj$.value;
261
+ if (!quote) {
262
+ return null;
256
263
  }
257
- currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
264
+ return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
258
265
  }
259
- return;
260
- };
261
- const insertLineItem = (lineItem, parentId, toInsert) => {
262
- const insertData = lineItem.id === parentId ? [toInsert] : [];
263
- return Object.assign(Object.assign({}, lineItem), { lineItems: [
264
- ...insertData,
265
- ...lineItem.lineItems.map(li => {
266
- return insertLineItem(li, parentId, toInsert);
267
- }),
268
- ] });
269
- };
270
- const removeLineItem = (lineItem, idToRemove) => {
271
- return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems
272
- .map(li => {
273
- if (li.id === idToRemove) {
274
- return;
275
- }
276
- else if (li.lineItems.length) {
277
- return removeLineItem(li, idToRemove);
278
- }
279
- return li;
280
- })
281
- .filter(r => !!r) });
282
- };
283
- const replaceLineItem = (lineItem, replaceTo, skipCardinalityCalculation = false) => {
284
- if (lineItem.id === replaceTo.id) {
285
- if (!skipCardinalityCalculation) {
286
- return Object.assign({}, recalculateCardinalityVariables(lineItem, replaceTo));
266
+ get quoteDraftForActivePriceList() {
267
+ const quoteDraft = this.quoteDraft;
268
+ if (!quoteDraft) {
269
+ return null;
287
270
  }
288
- else {
271
+ return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
272
+ }
273
+ get currentState$() {
274
+ return this.quoteDraft$.pipe(map(quote => quote.currentState));
275
+ }
276
+ get currentState() {
277
+ var _a, _b;
278
+ return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
279
+ }
280
+ /**
281
+ * Stream of activeCurrentState
282
+ */
283
+ get activeCurrentState$() {
284
+ return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
285
+ }
286
+ /**
287
+ * activeCurrentState is currentState passed through additional filters
288
+ */
289
+ get activeCurrentState() {
290
+ var _a, _b;
291
+ let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
292
+ currentState = this.filterByActivePriceList(currentState);
293
+ return currentState;
294
+ }
295
+ /**
296
+ * Stream of activeInitialState
297
+ */
298
+ get activeInitialState$() {
299
+ return this.quoteDraft$.pipe(map(() => this.activeInitialState));
300
+ }
301
+ /**
302
+ * activeInitialState is initialState passed through additional filters
303
+ */
304
+ get activeInitialState() {
305
+ var _a, _b;
306
+ const ctx = this.context.resolve();
307
+ let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
308
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
309
+ initialState = this.filterByActivePriceList(initialState);
310
+ }
311
+ return initialState;
312
+ }
313
+ get isStandalone() {
314
+ return this.context.resolve().properties.standalone === 'true';
315
+ }
316
+ get isStandalone$() {
317
+ return this.context.resolve$().pipe(map(() => this.isStandalone));
318
+ }
319
+ getInitialCurrentState() {
320
+ return this.initialCurrentState;
321
+ }
322
+ isEditMode$() {
323
+ return this.context.resolve$().pipe(map(() => this.isEditMode()));
324
+ }
325
+ isEditMode() {
326
+ const context = this.context.resolve();
327
+ if (context.mode === ConfigurationContextMode.ACCOUNT) {
328
+ return true;
329
+ }
330
+ if (context.mode === ConfigurationContextMode.QUOTE) {
331
+ return context.properties.Status === 'Draft';
332
+ }
333
+ return false;
334
+ }
335
+ updateActivePriceList(priceListId) {
336
+ this.context.update({ properties: { PriceListId: priceListId } });
337
+ }
338
+ populateActivePriceLists$() {
339
+ const ctx = this.context.resolve();
340
+ const quoteDraft = this.quoteDraft;
341
+ if (!quoteDraft) {
342
+ return;
343
+ }
344
+ // In ACCOUNT mode populate price lists from related assets
345
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
346
+ // Populate list of price lists
347
+ this.assetPriceLists = quoteDraft.currentState
348
+ .map(({ priceListId }) => priceListId)
349
+ .reduce((trunk, priceListId) => {
350
+ var _a, _b;
351
+ if (!priceListId || trunk.some(item => item.id === priceListId)) {
352
+ return trunk;
353
+ }
354
+ return [
355
+ ...trunk,
356
+ { 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 : '' },
357
+ ];
358
+ }, []);
359
+ }
360
+ }
361
+ filterByActivePriceList(lineItems) {
362
+ const ctx = this.context.resolve();
363
+ return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
364
+ }
365
+ markAsUpdated(quote) {
366
+ if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === ConfigurationContextMode.ACCOUNT) {
367
+ this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
368
+ }
369
+ else {
370
+ this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
371
+ }
372
+ }
373
+ }
374
+ QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
375
+ QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
376
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, decorators: [{
377
+ type: Injectable,
378
+ args: [{ providedIn: 'root' }]
379
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
380
+
381
+ const findLineItem = (id, lineItems) => {
382
+ return findLineItemWithComparator(lineItems, (li) => li.id === id);
383
+ };
384
+ const findLineItemWithComparator = (lineItems, comparator) => {
385
+ let currentLevel = lineItems;
386
+ while (currentLevel.length) {
387
+ const found = currentLevel.find(comparator);
388
+ if (found) {
389
+ return found;
390
+ }
391
+ currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
392
+ }
393
+ return;
394
+ };
395
+ const insertLineItem = (lineItem, parentId, toInsert) => {
396
+ const insertData = lineItem.id === parentId ? [toInsert] : [];
397
+ return Object.assign(Object.assign({}, lineItem), { lineItems: [
398
+ ...insertData,
399
+ ...lineItem.lineItems.map(li => {
400
+ return insertLineItem(li, parentId, toInsert);
401
+ }),
402
+ ] });
403
+ };
404
+ const removeLineItem = (lineItem, idToRemove) => {
405
+ return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems
406
+ .map(li => {
407
+ if (li.id === idToRemove) {
408
+ return;
409
+ }
410
+ else if (li.lineItems.length) {
411
+ return removeLineItem(li, idToRemove);
412
+ }
413
+ return li;
414
+ })
415
+ .filter(r => !!r) });
416
+ };
417
+ const replaceLineItem = (lineItem, replaceTo, skipCardinalityCalculation = false) => {
418
+ if (lineItem.id === replaceTo.id) {
419
+ if (!skipCardinalityCalculation) {
420
+ return Object.assign({}, recalculateCardinalityVariables(lineItem, replaceTo));
421
+ }
422
+ else {
289
423
  return Object.assign({}, replaceTo);
290
424
  }
291
425
  }
@@ -452,230 +586,268 @@ class LineItemWorker {
452
586
  }
453
587
  }
454
588
 
455
- class QuoteDraftService {
456
- get isInitialized() {
457
- return this.isInitializedSubj$.getValue();
458
- }
459
- set isInitialized(value) {
460
- if (this.isInitialized !== value) {
461
- this.isInitializedSubj$.next(value);
589
+ function extractMetadata(uiDefinition) {
590
+ return omit(uiDefinition, [
591
+ 'children',
592
+ 'pages',
593
+ 'components',
594
+ ]);
595
+ }
596
+
597
+ class FlowUpdateService {
598
+ update(rootLineItems, updates, charges) {
599
+ let remainingUpdates = [...updates];
600
+ let currentLevel = rootLineItems;
601
+ while (currentLevel.length && remainingUpdates.length) {
602
+ currentLevel.forEach(li => {
603
+ const unhandledUpdates = [];
604
+ remainingUpdates.forEach(update => {
605
+ let updated = false;
606
+ switch (update.dataType) {
607
+ case 'LINEITEM':
608
+ updated = this.applyLineItemUpdate(li, update, charges);
609
+ break;
610
+ case 'CHARGE':
611
+ updated = this.applyChargeUpdate(li, update);
612
+ break;
613
+ case 'GROUP_CHARGE':
614
+ updated = this.applyChargeGroupUpdate(li, update);
615
+ break;
616
+ default:
617
+ // Unknown dataType. Do not try to handle it anymore
618
+ updated = true;
619
+ }
620
+ if (!updated) {
621
+ unhandledUpdates.push(update);
622
+ }
623
+ });
624
+ remainingUpdates = unhandledUpdates;
625
+ });
626
+ currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
462
627
  }
463
628
  }
464
- get hasUnsavedChanges() {
465
- return this._hasUnsavedChanges;
629
+ delete(lineItems, id) {
630
+ const idsToRemove = [id];
631
+ const topLevelLineItem = lineItems.find(li => li.id === id);
632
+ if (topLevelLineItem) {
633
+ // find term-related line items (which are only top level)
634
+ // expired term line items won't be deleted
635
+ let foundTermLineItem = topLevelLineItem;
636
+ while (foundTermLineItem) {
637
+ foundTermLineItem = lineItems.find(li => foundTermLineItem && li.rampInstanceId === foundTermLineItem.id);
638
+ if (foundTermLineItem) {
639
+ idsToRemove.push(foundTermLineItem.id);
640
+ }
641
+ }
642
+ }
643
+ const filtered = lineItems.filter(lineItem => !idsToRemove.includes(lineItem.id));
644
+ return filtered.map(lineItem => new LineItemWorker(lineItem).remove(id).li);
466
645
  }
467
- set hasUnsavedChanges(value) {
468
- var _a, _b;
469
- this._hasUnsavedChanges = value;
470
- if (!this._hasUnsavedChanges) {
471
- this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
646
+ applyLineItemUpdate(lineItem, update, charges) {
647
+ if (lineItem.id !== update.id) {
648
+ return false;
649
+ }
650
+ switch (update.attributeType) {
651
+ case 'QTY':
652
+ lineItem.qty = update.newValue;
653
+ break;
654
+ case 'EFFECTIVE_START_DATE':
655
+ lineItem.properties['StartDate'] = moment(update.newValue).format('YYYY-MM-DD');
656
+ break;
657
+ case 'END_DATE':
658
+ lineItem.properties['EndDate'] = moment(update.newValue).format('YYYY-MM-DD');
659
+ break;
660
+ case 'PRICE_ADJUSTMENT':
661
+ {
662
+ const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
663
+ if (charge) {
664
+ charge.priceAdjustment = update.newValue;
665
+ }
666
+ }
667
+ break;
668
+ case 'LIST_PRICE_ADJUSTMENT':
669
+ case 'MARGIN_ADJUSTMENT':
670
+ {
671
+ const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
672
+ if (charge) {
673
+ charge.listPriceAdjustment = update.newValue;
674
+ }
675
+ }
676
+ break;
677
+ case 'COST_ADJUSTMENT':
678
+ {
679
+ const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
680
+ if (charge) {
681
+ charge.costAdjustment = update.newValue;
682
+ }
683
+ }
684
+ break;
685
+ default:
686
+ throw new Error(`Not suppored AttributeType for LineItem update: ${update.attributeType}`);
472
687
  }
688
+ return true;
473
689
  }
474
- get hasProducts$() {
475
- return this.quoteSubj$.pipe(map(() => this.hasProducts));
476
- }
477
- get hasProducts() {
478
- const quoteDraft = this.quoteSubj$.value;
479
- return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
480
- }
481
- constructor(context, quoteApiService, priceApiService) {
482
- this.context = context;
483
- this.quoteApiService = quoteApiService;
484
- this.priceApiService = priceApiService;
485
- this.quoteSubj$ = new BehaviorSubject(null);
486
- this.resetSubj$ = new BehaviorSubject(true);
487
- this.isInitializedSubj$ = new BehaviorSubject(false);
488
- this.initialCurrentState = [];
489
- this._hasUnsavedChanges = false;
490
- this.allPriceLists = [];
491
- this.assetPriceLists = [];
492
- this.reset$ = this.resetSubj$.asObservable();
493
- 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));
494
- this.isInitializedSubj$
495
- .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
496
- .subscribe();
497
- }
498
- reset() {
499
- this.resetSubj$.next(true);
500
- this.quoteSubj$.next(null);
501
- this.hasUnsavedChanges = false;
502
- }
503
- init(quoteId, params) {
504
- return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
505
- this.allPriceLists = allPriceLists;
506
- this.quoteSubj$.next(quote);
507
- this.context.update(quote.context);
508
- this.populateActivePriceLists$();
509
- }), map(() => noop()), take(1));
510
- }
511
- setCurrentLineItemState(lineItems) {
512
- const quoteDraft = this.quoteSubj$.value;
513
- if (!quoteDraft) {
514
- return;
690
+ applyChargeUpdate(lineItem, update) {
691
+ const foundCharge = lineItem.chargeItems.find(({ id }) => id === update.id);
692
+ if (!foundCharge) {
693
+ return false;
515
694
  }
516
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
517
- }
518
- updateQuoteDraft(update) {
519
- const quoteDraft = this.quoteSubj$.value;
520
- if (!quoteDraft) {
521
- return;
695
+ if (update.attributeType === 'PRICE_ADJUSTMENT') {
696
+ foundCharge.priceAdjustment = update.newValue;
522
697
  }
523
- if (update.context) {
524
- this.context.set(update.context);
698
+ else if (update.attributeType === 'LIST_PRICE_ADJUSTMENT') {
699
+ foundCharge.listPriceAdjustment = update.newValue;
525
700
  }
526
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
527
- }
528
- updateByPriceSummary(priceSummary) {
529
- const quoteDraft = this.quoteSubj$.value;
530
- if (!quoteDraft) {
531
- return;
701
+ else {
702
+ throw new Error(`Not suppored AttributeType for Charge Item update: ${update.attributeType}`);
532
703
  }
533
- const updatedCurrentState = this.currentState.map(lineItem => {
534
- const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
535
- return updated !== null && updated !== void 0 ? updated : lineItem;
536
- });
537
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
538
- }
539
- get quoteDraft$() {
540
- return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
704
+ return true;
541
705
  }
542
- get quoteDraft() {
543
- const quote = this.quoteSubj$.value;
544
- if (!quote) {
545
- return null;
706
+ applyChargeGroupUpdate(lineItem, update) {
707
+ const foundChargeGroup = ChargeGroupUtils.findChargeGroupById(update.id, lineItem);
708
+ if (!foundChargeGroup) {
709
+ return false;
546
710
  }
547
- return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
548
- }
549
- get quoteDraftForActivePriceList() {
550
- const quoteDraft = this.quoteDraft;
551
- if (!quoteDraft) {
552
- return null;
711
+ if (update.attributeType === 'PRICE_ADJUSTMENT') {
712
+ foundChargeGroup.priceAdjustment = update.newValue;
553
713
  }
554
- return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
555
- }
556
- get currentState$() {
557
- return this.quoteDraft$.pipe(map(quote => quote.currentState));
558
- }
559
- get currentState() {
560
- var _a, _b;
561
- return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
714
+ else if (update.attributeType === 'LIST_PRICE_ADJUSTMENT') {
715
+ foundChargeGroup.listPriceAdjustment = update.newValue;
716
+ }
717
+ else {
718
+ throw new Error(`Not suppored AttributeType for Charge Group Item update: ${update.attributeType}`);
719
+ }
720
+ return true;
562
721
  }
563
- /**
564
- * Stream of activeCurrentState
565
- */
566
- get activeCurrentState$() {
567
- return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
722
+ }
723
+ FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
724
+ FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowUpdateService });
725
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowUpdateService, decorators: [{
726
+ type: Injectable
727
+ }] });
728
+
729
+ class RuntimeSettingsService {
730
+ constructor(configurationSettingsApiService) {
731
+ this.configurationSettingsApiService = configurationSettingsApiService;
732
+ this.configurationSettings$ = new BehaviorSubject({});
733
+ this.currencySettings$ = new BehaviorSubject({
734
+ iso: DEFAULT_CURRENCY_ISO_CODE,
735
+ symbol: DEFAULT_CURRENCY_SYMBOL,
736
+ });
737
+ this.shoppingCartSettings$ = new BehaviorSubject([]);
738
+ this.getCurrencySymbol = (locale, currency) => {
739
+ return (0)
740
+ .toLocaleString(locale, { style: 'currency', currency, minimumFractionDigits: 0, maximumFractionDigits: 0 })
741
+ .replace(/\d/g, '')
742
+ .trim();
743
+ };
568
744
  }
569
- /**
570
- * activeCurrentState is currentState passed through additional filters
571
- */
572
- get activeCurrentState() {
573
- var _a, _b;
574
- let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
575
- currentState = this.filterByActivePriceList(currentState);
576
- return currentState;
745
+ create() {
746
+ return this.configurationSettingsApiService.fetchSettings().pipe(map$2(settings => this.parseConfigurationSettings(settings)), tap$1(configurationSettings => {
747
+ var _a;
748
+ this.configurationSettings$.next(configurationSettings);
749
+ this.addShoppingCartSettings((_a = configurationSettings['shopping-cart']) !== null && _a !== void 0 ? _a : []);
750
+ this.formattingSettings = this.getFormattingSettings();
751
+ }), map$2(() => undefined));
577
752
  }
578
- /**
579
- * Stream of activeInitialState
580
- */
581
- get activeInitialState$() {
582
- return this.quoteDraft$.pipe(map(() => this.activeInitialState));
753
+ initCurrency(iso) {
754
+ if (iso) {
755
+ const symbol = this.getCurrencySymbol('en-US', iso);
756
+ this.currencySettings$.next({ iso, symbol });
757
+ }
583
758
  }
584
- /**
585
- * activeInitialState is initialState passed through additional filters
586
- */
587
- get activeInitialState() {
759
+ getFormattingSettings() {
588
760
  var _a, _b;
589
- const ctx = this.context.resolve();
590
- let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
591
- if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
592
- initialState = this.filterByActivePriceList(initialState);
761
+ if (this.formattingSettings) {
762
+ return this.formattingSettings;
593
763
  }
594
- return initialState;
764
+ const shoppingCartSettings = (_a = this.getConfigurationSettings()['shopping-cart']) === null || _a === void 0 ? void 0 : _a.reduce((acc, setting) => {
765
+ return Object.assign(Object.assign({}, acc), { [setting.id]: setting.properties });
766
+ }, {});
767
+ const currencySettings = this.getCurrencySettings();
768
+ const dateFormat = (validateDateFormat((_b = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.DATE_FORMAT) !== null && _b !== void 0 ? _b : '') && (shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.DATE_FORMAT)) ||
769
+ DEFAULT_DATE_FORMAT;
770
+ const decimalSeparator = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.DECIMAL_SEPARATOR;
771
+ const thousandsSeparator = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.THOUSANDS_SEPARATOR;
772
+ // the number of decimal places can be 0
773
+ const priceScale = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.PRICE_SCALE;
774
+ const decimalsCount = priceScale !== null && priceScale !== '' && !isNaN(Number(priceScale)) && Number(priceScale) >= 0
775
+ ? Number(priceScale)
776
+ : DEFAULT_DECIMALS_COUNT;
777
+ const actionCodeSettings = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.STATUS_LABEL;
778
+ return {
779
+ currencySymbol: currencySettings.symbol,
780
+ dateFormats: getSupportedDateFormats(dateFormat),
781
+ decimalsCount,
782
+ decimalSeparator: decimalSeparator !== undefined && ['.', ','].includes(decimalSeparator)
783
+ ? decimalSeparator
784
+ : DEFAULT_DECIMAL_SEPARATOR,
785
+ // thousands separator can be a blank value, so it can also be null
786
+ thousandsSeparator: thousandsSeparator !== undefined && ['.', ',', '', null].includes(thousandsSeparator)
787
+ ? thousandsSeparator || ''
788
+ : DEFAULT_THOUSANDS_SEPARATOR,
789
+ actionCodeLabels: (actionCodeSettings === null || actionCodeSettings === void 0 ? void 0 : actionCodeSettings.length)
790
+ ? actionCodeSettings.reduce((result, setting) => (Object.assign(Object.assign({}, result), { [setting.status_label]: setting.custom_label })), {})
791
+ : DEFAULT_ACTION_CODE_LABELS,
792
+ };
595
793
  }
596
- get isStandalone() {
597
- return this.context.resolve().properties.standalone === 'true';
794
+ getConfigurationSettings() {
795
+ return this.configurationSettings$.value;
598
796
  }
599
- get isStandalone$() {
600
- return this.context.resolve$().pipe(map(() => this.isStandalone));
797
+ getShoppingCartSettings() {
798
+ return this.shoppingCartSettings$.value;
601
799
  }
602
- getInitialCurrentState() {
603
- return this.initialCurrentState;
800
+ getCurrencySettings() {
801
+ return this.currencySettings$.value;
604
802
  }
605
- isEditMode$() {
606
- return this.context.resolve$().pipe(map(() => this.isEditMode()));
803
+ parseConfigurationSettings(settings) {
804
+ return settings.reduce((acc, setting) => {
805
+ switch (setting.key) {
806
+ case 'shopping-cart':
807
+ acc['shopping-cart'] = parseJsonSafely(setting.value, []);
808
+ break;
809
+ case 'navigation':
810
+ acc.navigation = parseJsonSafely(setting.value, {});
811
+ break;
812
+ case 'flows':
813
+ acc.flows = parseJsonSafely(setting.value, []);
814
+ break;
815
+ default:
816
+ acc[setting.key] = setting.value;
817
+ }
818
+ return acc;
819
+ }, {});
607
820
  }
608
- isEditMode() {
609
- const context = this.context.resolve();
610
- if (context.mode === ConfigurationContextMode.ACCOUNT) {
611
- return true;
612
- }
613
- if (context.mode === ConfigurationContextMode.QUOTE) {
614
- return context.properties.Status === 'Draft';
615
- }
616
- return false;
821
+ addShoppingCartSettings(settings) {
822
+ // uniqBy removes items with the biggest index
823
+ const newSettings = uniqBy([...settings, ...this.shoppingCartSettings$.value], 'id');
824
+ this.shoppingCartSettings$.next(newSettings);
617
825
  }
618
- updateActivePriceList(priceListId) {
619
- this.context.update({ properties: { PriceListId: priceListId } });
620
- }
621
- populateActivePriceLists$() {
622
- const ctx = this.context.resolve();
623
- const quoteDraft = this.quoteDraft;
624
- if (!quoteDraft) {
625
- return;
626
- }
627
- // In ACCOUNT mode populate price lists from related assets
628
- if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
629
- // Populate list of price lists
630
- this.assetPriceLists = quoteDraft.currentState
631
- .map(({ priceListId }) => priceListId)
632
- .reduce((trunk, priceListId) => {
633
- var _a, _b;
634
- if (!priceListId || trunk.some(item => item.id === priceListId)) {
635
- return trunk;
636
- }
637
- return [
638
- ...trunk,
639
- { 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 : '' },
640
- ];
641
- }, []);
642
- }
643
- }
644
- filterByActivePriceList(lineItems) {
645
- const ctx = this.context.resolve();
646
- return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
647
- }
648
- markAsUpdated(quote) {
649
- if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === ConfigurationContextMode.ACCOUNT) {
650
- this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
651
- }
652
- else {
653
- this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
654
- }
655
- }
656
- }
657
- QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
658
- QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
659
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: QuoteDraftService, decorators: [{
660
- type: Injectable,
661
- args: [{ providedIn: 'root' }]
662
- }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
663
-
664
- class ConfigurationService {
665
- constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
666
- this.quoteDraftService = quoteDraftService;
667
- this.runtimeService = runtimeService;
668
- this.contextService = contextService;
669
- this.configurationApiService = configurationApiService;
670
- this.messageService = messageService;
671
- this.dialogService = dialogService;
672
- this.mode = ConfigurationMode.SEARCH;
673
- this.lineItem = new BehaviorSubject(undefined);
674
- this.charges = new BehaviorSubject({});
675
- this.pricePlans = new BehaviorSubject({});
676
- this.isLoadingSubj$ = new BehaviorSubject(false);
677
- this.isLoading$ = this.isLoadingSubj$.asObservable();
678
- this.hasUnsavedChanges = false;
826
+ }
827
+ RuntimeSettingsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, deps: [{ token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
828
+ RuntimeSettingsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, providedIn: 'root' });
829
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, decorators: [{
830
+ type: Injectable,
831
+ args: [{ providedIn: 'root' }]
832
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
833
+
834
+ class ConfigurationService {
835
+ constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService, runtimeSettings) {
836
+ this.quoteDraftService = quoteDraftService;
837
+ this.runtimeService = runtimeService;
838
+ this.contextService = contextService;
839
+ this.configurationApiService = configurationApiService;
840
+ this.messageService = messageService;
841
+ this.dialogService = dialogService;
842
+ this.runtimeSettings = runtimeSettings;
843
+ this.mode = ConfigurationMode.SEARCH;
844
+ this.lineItem = new BehaviorSubject(undefined);
845
+ this.charges = new BehaviorSubject({});
846
+ this.pricePlans = new BehaviorSubject({});
847
+ this.procedureContext = new BehaviorSubject({});
848
+ this.isLoadingSubj$ = new BehaviorSubject(false);
849
+ this.isLoading$ = this.isLoadingSubj$.asObservable();
850
+ this.hasUnsavedChanges = false;
679
851
  }
680
852
  reset() {
681
853
  this.hasUnsavedChanges = false;
@@ -749,6 +921,12 @@ class ConfigurationService {
749
921
  get pricePlansSnapshot() {
750
922
  return this.pricePlans.value;
751
923
  }
924
+ get procedureContext$() {
925
+ return this.procedureContext.asObservable();
926
+ }
927
+ get procedureContextSnapshot() {
928
+ return this.procedureContext.value;
929
+ }
752
930
  configure() {
753
931
  return this.configureRequest$(this.generateRequest());
754
932
  }
@@ -759,11 +937,20 @@ class ConfigurationService {
759
937
  const uiDefinitionProperties = this.getUIDefinitionProperties();
760
938
  const mainPricingEnabled = (_a = runtimeContext.properties) === null || _a === void 0 ? void 0 : _a.PricingEnabled;
761
939
  const pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
940
+ const customPriceApi = this.runtimeSettings.getConfigurationSettings()['CUSTOM_PRICE_API'];
762
941
  this.isLoadingSubj$.next(true);
763
- return this.configurationApiService.configureLineItem({ configurationRequest, runtimeModel, pricingEnabled }).pipe(tap(({ lineItem, context, charges, pricePlans, deletedLineItems }) => {
942
+ const configure$ = pricingEnabled && customPriceApi
943
+ ? this.configurationApiService.customConfigurePrice({ url: customPriceApi, configurationRequest, runtimeModel })
944
+ : this.configurationApiService.configureLineItem({
945
+ configurationRequest,
946
+ runtimeModel,
947
+ pricingEnabled,
948
+ });
949
+ return configure$.pipe(tap(({ lineItem, context, charges, pricePlans, deletedLineItems, procedureContext }) => {
764
950
  this.contextService.update(context !== null && context !== void 0 ? context : {});
765
951
  this.charges.next(charges !== null && charges !== void 0 ? charges : {});
766
952
  this.pricePlans.next(pricePlans !== null && pricePlans !== void 0 ? pricePlans : {});
953
+ this.procedureContext.next(procedureContext !== null && procedureContext !== void 0 ? procedureContext : {});
767
954
  if (lineItem) {
768
955
  this.lineItem.next(lineItem);
769
956
  }
@@ -820,8 +1007,8 @@ class ConfigurationService {
820
1007
  return request;
821
1008
  }
822
1009
  getUIDefinitionProperties() {
823
- var _a;
824
- return Object.assign(Object.assign({}, getUIDefinitionProperties(this.getRuntimeContext().uiDefinitionContainer)), ((_a = this.runtimeService.uiDefinitionProperties) !== null && _a !== void 0 ? _a : {}));
1010
+ var _a, _b, _c;
1011
+ return Object.assign(Object.assign({}, ((_b = (_a = this.getRuntimeContext().uiDefinitionContainer) === null || _a === void 0 ? void 0 : _a.source.properties) !== null && _b !== void 0 ? _b : {})), ((_c = this.runtimeService.uiDefinitionProperties) !== null && _c !== void 0 ? _c : {}));
825
1012
  }
826
1013
  showInactiveProductsConfirmation() {
827
1014
  const confirmationConfig = {
@@ -856,437 +1043,516 @@ class ConfigurationService {
856
1043
  return (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
857
1044
  }
858
1045
  }
859
- ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i5.MessageService }, { token: i6.DialogService }], target: i0.ɵɵFactoryTarget.Injectable });
860
- ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationService });
861
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationService, decorators: [{
1046
+ ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i5.MessageService }, { token: i6.DialogService }, { token: RuntimeSettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
1047
+ ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService });
1048
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService, decorators: [{
862
1049
  type: Injectable
863
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6.DialogService }]; } });
1050
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6.DialogService }, { type: RuntimeSettingsService }]; } });
864
1051
 
865
- class ConfigurationState {
866
- constructor(statefulConfigurationApiService, runtimeService, configurationService, toastService) {
867
- this.statefulConfigurationApiService = statefulConfigurationApiService;
868
- this.runtimeService = runtimeService;
1052
+ class FlowConfigurationService {
1053
+ constructor(proceduresApiService, contextService, quoteDraftService, updateService, configurationService) {
1054
+ this.proceduresApiService = proceduresApiService;
1055
+ this.contextService = contextService;
1056
+ this.quoteDraftService = quoteDraftService;
1057
+ this.updateService = updateService;
869
1058
  this.configurationService = configurationService;
870
- this.toastService = toastService;
871
- this.stateSubj$ = new BehaviorSubject({});
872
- this.state$ = this.stateSubj$.asObservable();
873
- this.stateId = null;
874
1059
  }
875
- init$() {
876
- return this.configurationService.configure().pipe(switchMap$1(() => {
877
- var _a, _b;
878
- if (!this.isStatefulConfiguration) {
879
- return of(undefined);
880
- }
881
- const { actions, selectors } = (_b = (_a = this.runtimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
882
- return this.statefulConfigurationApiService.init({
883
- request: this.configurationService.generateRequest(),
884
- actions: actions === null || actions === void 0 ? void 0 : actions.map(action => ({ name: action.apiName, script: action.script })),
885
- selectors: selectors === null || selectors === void 0 ? void 0 : selectors.map(selector => ({ name: selector.apiName, script: selector.script })),
886
- });
887
- }), tap$1(stateId => (this.stateId = stateId || null)), map$2(() => undefined));
1060
+ calculate$(quoteDraft) {
1061
+ return this.proceduresApiService.apply$(quoteDraft).pipe(tap$1(result => {
1062
+ // sort the result current state based on the quote draft initial state
1063
+ const initialStateIds = quoteDraft.initialState.map(lineItem => lineItem.integrationId);
1064
+ result.currentState = result.currentState
1065
+ .slice()
1066
+ .sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
1067
+ this.quoteDraftService.updateQuoteDraft(result);
1068
+ }), map$2(noop));
888
1069
  }
889
- cleanup() {
890
- this.stateId = null;
891
- this.configurationService.reset();
892
- this.stateSubj$.next({});
1070
+ calculate(quoteDraft) {
1071
+ this.calculate$(quoteDraft).subscribe();
893
1072
  }
894
- execute$(req) {
895
- if (this.isStatefulConfiguration) {
896
- return this.executeStateful$(req);
897
- }
898
- else {
899
- return this.executeStateless$(req);
1073
+ update$(updates) {
1074
+ const quoteDraft = this.quoteDraftService.quoteDraft;
1075
+ if (!quoteDraft) {
1076
+ return of(null);
900
1077
  }
1078
+ return of([]).pipe(map$2(() => {
1079
+ const updatedState = cloneDeep(quoteDraft.currentState);
1080
+ this.updateService.update(updatedState, updates, quoteDraft.charges);
1081
+ return updatedState;
1082
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
901
1083
  }
902
- dispatch$(actionName, inputData) {
903
- return this.execute$({ actions: [{ name: actionName, inputData }] });
904
- }
905
- select$(selectorName, inputData) {
906
- const requestId = UUID.UUID();
907
- return this.execute$({
908
- selectors: {
909
- [requestId]: {
910
- name: selectorName,
911
- inputData,
912
- },
913
- },
914
- }).pipe(map$2(() => this.stateSubj$.value[requestId]), tap$1(() => this.stateSubj$.next(omit(this.stateSubj$.value, requestId))));
1084
+ update(updates) {
1085
+ this.update$(updates).subscribe();
915
1086
  }
916
- get isStatefulConfiguration() {
917
- var _a;
918
- return (_a = this.runtimeService.uiDefinitionProperties.statefulConfigurationEnabled) !== null && _a !== void 0 ? _a : false;
1087
+ revert$(lineItemId) {
1088
+ const quoteDraft = this.quoteDraftService.quoteDraft;
1089
+ const initialCurrentState = this.quoteDraftService.getInitialCurrentState();
1090
+ const currentState = this.quoteDraftService.activeCurrentState;
1091
+ const currentLineItemIndex = currentState.findIndex(({ id }) => id === lineItemId);
1092
+ const currentLineItem = currentState[currentLineItemIndex];
1093
+ const initialLineItem = initialCurrentState.find(({ integrationId }) => integrationId === (currentLineItem === null || currentLineItem === void 0 ? void 0 : currentLineItem.integrationId));
1094
+ if (!quoteDraft || !currentLineItem || !initialLineItem) {
1095
+ return of(null);
1096
+ }
1097
+ const updatedState = cloneDeep(currentState);
1098
+ updatedState.splice(currentLineItemIndex, 1, initialLineItem);
1099
+ return of([]).pipe(tap$1(() => {
1100
+ this.quoteDraftService.setCurrentLineItemState(updatedState);
1101
+ }), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
919
1102
  }
920
- executeStateless$(request) {
921
- return of(undefined).pipe(switchMap$1(() => {
922
- var _a;
923
- // Apply actions and execute configuration/price call
924
- // No need to run configuration if no actions in the request
925
- if (!((_a = request.actions) === null || _a === void 0 ? void 0 : _a.length)) {
926
- return of(undefined);
927
- }
928
- let configurationRequest = this.configurationService.generateRequest();
929
- request.actions.forEach(action => {
930
- var _a;
931
- configurationRequest = (_a = this.executeActionScript(configurationRequest, action)) !== null && _a !== void 0 ? _a : configurationRequest;
932
- });
933
- return this.configurationService.configureRequest$(configurationRequest);
934
- }), tap$1(() => {
935
- if (!request.selectors) {
936
- return;
937
- }
938
- // Run selectors and apply them to the state
939
- const finalConfigurationRequest = this.configurationService.generateRequest();
940
- const selectorsResult = EntityUtil.entries(request.selectors).reduce((trunk, [key, selector]) => {
941
- trunk[key] = this.executeSelectorScript(finalConfigurationRequest, selector);
942
- return trunk;
943
- }, {});
944
- this.stateSubj$.next(Object.assign(Object.assign({}, this.stateSubj$.value), selectorsResult));
945
- }), map$2(() => undefined));
1103
+ revert(lineItemId) {
1104
+ this.revert$(lineItemId).subscribe();
946
1105
  }
947
- executeStateful$(request) {
948
- if (!this.stateId) {
949
- return of(undefined);
1106
+ delete$(ids) {
1107
+ const quoteDraft = this.quoteDraftService.quoteDraft;
1108
+ const currentState = this.quoteDraftService.currentState;
1109
+ if (!quoteDraft) {
1110
+ return of(null);
950
1111
  }
951
- return this.statefulConfigurationApiService.execute(this.stateId, request).pipe(tap$1(response => {
952
- this.stateId = response.stateId;
953
- const updatedState = this.stateSubj$.value;
954
- EntityUtil.entries(response.selectors).forEach(([key, value]) => {
955
- if (!value.success) {
956
- if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
957
- this.toastService.add({ summary: value.errorMessage, severity: ToastType.error });
958
- }
959
- return;
960
- }
961
- updatedState[key] = value.result;
962
- });
963
- this.stateSubj$.next(updatedState);
964
- }), map$2(() => undefined));
1112
+ 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());
965
1113
  }
966
- executeActionScript(request, processor) {
967
- var _a, _b, _c;
968
- const { actions } = (_b = (_a = this.runtimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
969
- const script = (_c = actions === null || actions === void 0 ? void 0 : actions.find(action => action.apiName === processor.name)) === null || _c === void 0 ? void 0 : _c.script;
970
- if (!script) {
971
- return null;
1114
+ delete(ids) {
1115
+ this.delete$(ids).subscribe();
1116
+ }
1117
+ addTerm$(term) {
1118
+ const quoteDraft = this.quoteDraftService.quoteDraft;
1119
+ if (!quoteDraft) {
1120
+ return of(null);
972
1121
  }
973
- return this.executeProcessorScript(request, script, processor.inputData);
1122
+ const updatedState = [...quoteDraft.currentState, term];
1123
+ return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
974
1124
  }
975
- executeSelectorScript(request, processor) {
976
- var _a, _b, _c;
977
- const { selectors } = (_b = (_a = this.runtimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
978
- const script = (_c = selectors === null || selectors === void 0 ? void 0 : selectors.find(selector => selector.apiName === processor.name)) === null || _c === void 0 ? void 0 : _c.script;
979
- if (!script) {
980
- return null;
1125
+ addToCart$(props) {
1126
+ const quoteDraft = this.quoteDraftService.quoteDraft;
1127
+ if (!quoteDraft) {
1128
+ return of(null);
981
1129
  }
982
- return this.executeProcessorScript(request, script, processor.inputData);
1130
+ return this.configurationService.configureExternal$(props).pipe(map$2(lineItem => {
1131
+ var _a, _b, _c;
1132
+ const model = this.configurationService.getRuntimeModel();
1133
+ 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;
1134
+ const lineItems = multiplyLineItems(lineItem, (_c = props.qty) !== null && _c !== void 0 ? _c : 1, split);
1135
+ return [...quoteDraft.currentState, ...lineItems];
1136
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
983
1137
  }
984
- executeProcessorScript(request, script, inputData) {
985
- return new Function(`${script}\nreturn transform;`)()({
986
- request,
987
- inputData: inputData,
988
- });
1138
+ get() {
1139
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
989
1140
  }
990
- }
991
- ConfigurationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationState, deps: [{ token: i1.StatefulConfigurationApiService }, { token: ConfigurationRuntimeService }, { token: ConfigurationService }, { token: i4.ToastService }], target: i0.ɵɵFactoryTarget.Injectable });
992
- ConfigurationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationState });
993
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationState, decorators: [{
994
- type: Injectable
995
- }], ctorParameters: function () { return [{ type: i1.StatefulConfigurationApiService }, { type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: i4.ToastService }]; } });
996
-
997
- function extractMetadata(uiDefinition) {
998
- return omit(uiDefinition, [
999
- 'children',
1000
- 'pages',
1001
- 'components',
1002
- ]);
1003
- }
1004
-
1005
- class FlowUpdateService {
1006
- update(rootLineItems, updates, charges) {
1007
- let remainingUpdates = [...updates];
1008
- let currentLevel = rootLineItems;
1009
- while (currentLevel.length && remainingUpdates.length) {
1010
- currentLevel.forEach(li => {
1011
- const unhandledUpdates = [];
1012
- remainingUpdates.forEach(update => {
1013
- let updated = false;
1014
- switch (update.dataType) {
1015
- case 'LINEITEM':
1016
- updated = this.applyLineItemUpdate(li, update, charges);
1017
- break;
1018
- case 'CHARGE':
1019
- updated = this.applyChargeUpdate(li, update);
1020
- break;
1021
- case 'GROUP_CHARGE':
1022
- updated = this.applyChargeGroupUpdate(li, update);
1023
- break;
1024
- default:
1025
- // Unknown dataType. Do not try to handle it anymore
1026
- updated = true;
1027
- }
1028
- if (!updated) {
1029
- unhandledUpdates.push(update);
1030
- }
1031
- });
1032
- remainingUpdates = unhandledUpdates;
1033
- });
1034
- currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
1035
- }
1141
+ getSnapshot() {
1142
+ var _a, _b;
1143
+ return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
1036
1144
  }
1037
- delete(lineItems, id) {
1038
- const idsToRemove = [id];
1039
- const topLevelLineItem = lineItems.find(li => li.id === id);
1040
- if (topLevelLineItem) {
1041
- // find term-related line items (which are only top level)
1042
- // expired term line items won't be deleted
1043
- let foundTermLineItem = topLevelLineItem;
1044
- while (foundTermLineItem) {
1045
- foundTermLineItem = lineItems.find(li => foundTermLineItem && li.rampInstanceId === foundTermLineItem.id);
1046
- if (foundTermLineItem) {
1047
- idsToRemove.push(foundTermLineItem.id);
1145
+ get charges$() {
1146
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ charges }) => charges));
1147
+ }
1148
+ get pricePlans$() {
1149
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ pricePlans }) => pricePlans));
1150
+ }
1151
+ get activeMetrics$() {
1152
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ activeMetrics }) => activeMetrics));
1153
+ }
1154
+ get chargesSnapshot() {
1155
+ var _a, _b;
1156
+ return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.charges) !== null && _b !== void 0 ? _b : {};
1157
+ }
1158
+ get pricePlansSnapshot() {
1159
+ var _a, _b;
1160
+ return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.pricePlans) !== null && _b !== void 0 ? _b : {};
1161
+ }
1162
+ get activeMetricsSnapshot() {
1163
+ var _a, _b;
1164
+ return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.activeMetrics) !== null && _b !== void 0 ? _b : [];
1165
+ }
1166
+ get contextSnapshot() {
1167
+ return this.contextService.resolve();
1168
+ }
1169
+ get context$() {
1170
+ return this.contextService.resolve$();
1171
+ }
1172
+ handleErrorAndBounceBack() {
1173
+ return (source$) => {
1174
+ return source$.pipe(catchError$1(error => {
1175
+ console.error(error);
1176
+ // bounce back if configuration call has failed
1177
+ const quoteDraft = this.quoteDraftService.quoteDraft;
1178
+ if (quoteDraft) {
1179
+ this.quoteDraftService.updateQuoteDraft(quoteDraft);
1048
1180
  }
1181
+ return throwError(() => error);
1182
+ }));
1183
+ };
1184
+ }
1185
+ }
1186
+ FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
1187
+ FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService });
1188
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService, decorators: [{
1189
+ type: Injectable
1190
+ }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1191
+
1192
+ class MetricsCalculationService {
1193
+ get onMetricsUpdate$() {
1194
+ return this.metricsUpdated$.asObservable();
1195
+ }
1196
+ constructor(quoteDraftService, flowConfiguration, settingsService) {
1197
+ this.quoteDraftService = quoteDraftService;
1198
+ this.flowConfiguration = flowConfiguration;
1199
+ this.settingsService = settingsService;
1200
+ this.metricsUpdated$ = new Subject();
1201
+ this.quoteMetricsSettings = {};
1202
+ this.metricsCalculationMethodMap = {};
1203
+ this.metricsData = {};
1204
+ this.activeMetricRules = [];
1205
+ this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(metricRule => metricRule.metrics.some(metric => !!metric.totalName));
1206
+ combineLatest([
1207
+ this.quoteDraftService.currentState$,
1208
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
1209
+ ]).subscribe(([lineItems, setting]) => {
1210
+ let settingsData = {};
1211
+ try {
1212
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
1049
1213
  }
1050
- }
1051
- const filtered = lineItems.filter(lineItem => !idsToRemove.includes(lineItem.id));
1052
- return filtered.map(lineItem => new LineItemWorker(lineItem).remove(id).li);
1214
+ catch (error) {
1215
+ settingsData = {};
1216
+ }
1217
+ this.quoteMetricsSettings = settingsData;
1218
+ this.updateMetrics(lineItems);
1219
+ });
1053
1220
  }
1054
- applyLineItemUpdate(lineItem, update, charges) {
1055
- if (lineItem.id !== update.id) {
1056
- return false;
1221
+ getMetricValue(metric) {
1222
+ return this.metricsData[metric] || 0;
1223
+ }
1224
+ updateMetrics(lineItems) {
1225
+ const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
1226
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
1227
+ this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
1228
+ this.metricsUpdated$.next();
1229
+ }
1230
+ calculateMetric(lineItems, metric) {
1231
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
1232
+ }
1233
+ buildMetricsCalculationMethods(metricKeys, initial) {
1234
+ return metricKeys.reduce((acc, name) => {
1235
+ var _a, _b;
1236
+ if (acc[name]) {
1237
+ return acc;
1238
+ }
1239
+ acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
1240
+ const metricRule = this.getMetricRuleByTotalMetricName(name);
1241
+ 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;
1242
+ if (this.quoteMetricsSettings[settingKey]) {
1243
+ acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
1244
+ }
1245
+ return acc;
1246
+ }, initial);
1247
+ }
1248
+ collectMetricKeys(lineItems) {
1249
+ const keys = [];
1250
+ lineItems.forEach(lineItem => {
1251
+ keys.push(...Object.keys(lineItem.totalMetrics || {}));
1252
+ keys.push(...this.collectMetricKeys(lineItem.lineItems));
1253
+ });
1254
+ return uniq(keys);
1255
+ }
1256
+ getMetricRuleByTotalMetricName(name) {
1257
+ return this.activeMetricRules.find(metricRule => metricRule.metrics.find(metric => metric.totalName === name));
1258
+ }
1259
+ }
1260
+ MetricsCalculationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: FlowConfigurationService }, { token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1261
+ MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
1262
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: MetricsCalculationService, decorators: [{
1263
+ type: Injectable,
1264
+ args: [{ providedIn: 'root' }]
1265
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1.ConfigurationSettingsApiService }]; } });
1266
+
1267
+ class ProductImagesService {
1268
+ constructor(productApiService) {
1269
+ this.productApiService = productApiService;
1270
+ this.imagesMap$ = new BehaviorSubject({});
1271
+ }
1272
+ getImageUrl$(productId) {
1273
+ if (this.imagesMap$.value[productId] == null) {
1274
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
1275
+ this.fetchProductImage(productId);
1057
1276
  }
1058
- switch (update.attributeType) {
1059
- case 'QTY':
1060
- lineItem.qty = update.newValue;
1061
- break;
1062
- case 'EFFECTIVE_START_DATE':
1063
- lineItem.properties['StartDate'] = moment(update.newValue).format('YYYY-MM-DD');
1064
- break;
1065
- case 'END_DATE':
1066
- lineItem.properties['EndDate'] = moment(update.newValue).format('YYYY-MM-DD');
1067
- break;
1068
- case 'PRICE_ADJUSTMENT':
1069
- {
1070
- const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
1071
- if (charge) {
1072
- charge.priceAdjustment = update.newValue;
1073
- }
1074
- }
1075
- break;
1076
- case 'LIST_PRICE_ADJUSTMENT':
1077
- {
1078
- const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
1079
- if (charge) {
1080
- charge.listPriceAdjustment = update.newValue;
1081
- }
1082
- }
1083
- break;
1084
- case 'COST':
1085
- {
1086
- const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
1087
- if (charge) {
1088
- charge.netCost = update.newValue;
1089
- }
1090
- }
1091
- break;
1092
- case 'MARGIN_PERCENT':
1093
- {
1094
- const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
1095
- if (charge) {
1096
- charge.marginPercent = update.newValue;
1097
- }
1098
- }
1099
- break;
1100
- default:
1101
- throw new Error(`Not suppored AttributeType for LineItem update: ${update.attributeType}`);
1277
+ return this.imagesMap$.pipe(map$2(imagesMap => imagesMap[productId]), distinctUntilChanged());
1278
+ }
1279
+ fetchProductImage(productId) {
1280
+ this.productApiService
1281
+ .fetchImage$(productId)
1282
+ .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 }))))
1283
+ .subscribe();
1284
+ }
1285
+ }
1286
+ ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1287
+ ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
1288
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService, decorators: [{
1289
+ type: Injectable,
1290
+ args: [{ providedIn: 'root' }]
1291
+ }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
1292
+
1293
+ class RuntimeContextService {
1294
+ constructor(configurationApiService) {
1295
+ this.configurationApiService = configurationApiService;
1296
+ }
1297
+ getRuntimeContext(productId, offeringId) {
1298
+ return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(map(runtimeData => {
1299
+ var _a;
1300
+ const uiDefinitionContainer = this.getUIDefinitionContainer(runtimeData);
1301
+ const runtimeModel = RuntimeModel.create(runtimeData.types, runtimeData.products);
1302
+ const { productName, properties } = (_a = Array.from(runtimeModel.components.values()).find(c => c.productId === productId)) !== null && _a !== void 0 ? _a : {};
1303
+ const uiDefinitionProperties = uiDefinitionContainer === null || uiDefinitionContainer === void 0 ? void 0 : uiDefinitionContainer.source.properties;
1304
+ return {
1305
+ modelId: runtimeData.modelId,
1306
+ uiDefinitionContainer: uiDefinitionContainer,
1307
+ runtimeModel: runtimeModel,
1308
+ runtimeMode: RuntimeMode.PROD,
1309
+ productId: productId,
1310
+ productType: (properties === null || properties === void 0 ? void 0 : properties['displayName']) || productName,
1311
+ offeringId: offeringId,
1312
+ properties: {
1313
+ PricingEnabled: (uiDefinitionProperties === null || uiDefinitionProperties === void 0 ? void 0 : uiDefinitionProperties.pricingEnabled) ? 'true' : 'false',
1314
+ PriceListId: uiDefinitionProperties === null || uiDefinitionProperties === void 0 ? void 0 : uiDefinitionProperties.priceList,
1315
+ },
1316
+ };
1317
+ }));
1318
+ }
1319
+ getUIDefinitionContainer(runtimeData) {
1320
+ var _a;
1321
+ const containers = runtimeData.uiDefinitions.filter(container => isNotLegacyUIDefinition(container.source));
1322
+ return (_a = containers.find(container => container.source.primary)) !== null && _a !== void 0 ? _a : containers[0];
1323
+ }
1324
+ }
1325
+ RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1326
+ RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService });
1327
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService, decorators: [{
1328
+ type: Injectable
1329
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
1330
+
1331
+ class ConfigurationRuntimeService {
1332
+ constructor(apiService, contextService, runtimeContextService) {
1333
+ this.apiService = apiService;
1334
+ this.contextService = contextService;
1335
+ this.runtimeContextService = runtimeContextService;
1336
+ this._isInitialized = false;
1337
+ this.uiDefinitionProperties = {};
1338
+ }
1339
+ reset() {
1340
+ this._isInitialized = false;
1341
+ this._runtimeContext = undefined;
1342
+ this.initializationProps = undefined;
1343
+ this.uiDefinitionProperties = {};
1344
+ }
1345
+ initTestMode(uiDefinitionContainer) {
1346
+ var _a, _b;
1347
+ this.uiDefinitionProperties = (_a = uiDefinitionContainer.source.properties) !== null && _a !== void 0 ? _a : {};
1348
+ const uiDefinitionExternals = (_b = uiDefinitionContainer.source.externals) !== null && _b !== void 0 ? _b : {};
1349
+ return combineLatest([
1350
+ this.apiService.getRuntimeDataByModelId(uiDefinitionContainer.modelId),
1351
+ this.contextService.initTestMode(),
1352
+ ]).pipe(first(), map(([runtimeData, context]) => {
1353
+ var _a;
1354
+ this.contextService.update({
1355
+ properties: Object.assign(Object.assign(Object.assign(Object.assign({}, (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.properties), context.properties), { ModelId: uiDefinitionContainer.modelId, PricingEnabled: this.uiDefinitionProperties.pricingEnabled ? 'true' : 'false', PriceListId: this.uiDefinitionProperties.priceList, offeringId: this.uiDefinitionProperties.offeringId }), uiDefinitionExternals),
1356
+ });
1357
+ this._runtimeContext = {
1358
+ modelId: uiDefinitionContainer.modelId,
1359
+ runtimeModel: RuntimeModel.create(runtimeData.types, runtimeData.products),
1360
+ runtimeMode: RuntimeMode.TEST,
1361
+ uiDefinitionContainer,
1362
+ };
1363
+ return this._runtimeContext;
1364
+ }), tap(() => (this._isInitialized = true)));
1365
+ }
1366
+ init(props) {
1367
+ this.initializationProps = props;
1368
+ const context = this.contextService.resolve();
1369
+ return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
1370
+ var _a, _b, _c, _d;
1371
+ this.uiDefinitionProperties = (_b = (_a = runtimeContext.uiDefinitionContainer) === null || _a === void 0 ? void 0 : _a.source.properties) !== null && _b !== void 0 ? _b : {};
1372
+ const { PriceListId } = (_c = context.properties) !== null && _c !== void 0 ? _c : {};
1373
+ const mergeContext = Object.assign(Object.assign({}, runtimeContext), { properties: Object.assign(Object.assign(Object.assign({}, runtimeContext.properties), context.properties), { PricingEnabled: PriceListId ? 'true' : 'false' }) });
1374
+ this.id15to18('AccountId', mergeContext.properties);
1375
+ this._runtimeContext = mergeContext;
1376
+ if (context.properties && ((_d = this._runtimeContext.properties) === null || _d === void 0 ? void 0 : _d.StartDate)) {
1377
+ this.contextService.update({
1378
+ properties: Object.assign(Object.assign({}, this._runtimeContext.properties), context.properties),
1379
+ });
1380
+ }
1381
+ return this._runtimeContext;
1382
+ }), tap(() => (this._isInitialized = true)));
1383
+ }
1384
+ overrideUIDefinition(uiDefinitionContainer) {
1385
+ var _a;
1386
+ if (!this._runtimeContext) {
1387
+ return;
1102
1388
  }
1103
- return true;
1389
+ this._runtimeContext.uiDefinitionContainer = uiDefinitionContainer;
1390
+ this.uiDefinitionProperties = (_a = uiDefinitionContainer.source.properties) !== null && _a !== void 0 ? _a : {};
1104
1391
  }
1105
- applyChargeUpdate(lineItem, update) {
1106
- const foundCharge = lineItem.chargeItems.find(({ id }) => id === update.id);
1107
- if (!foundCharge) {
1108
- return false;
1109
- }
1110
- if (update.attributeType === 'PRICE_ADJUSTMENT') {
1111
- foundCharge.priceAdjustment = update.newValue;
1112
- }
1113
- else if (update.attributeType === 'LIST_PRICE_ADJUSTMENT') {
1114
- foundCharge.listPriceAdjustment = update.newValue;
1392
+ id15to18(propertyName, source) {
1393
+ if (!source) {
1394
+ return;
1115
1395
  }
1116
- else {
1117
- throw new Error(`Not suppored AttributeType for Charge Item update: ${update.attributeType}`);
1396
+ const value = source[propertyName];
1397
+ if (typeof value === 'string' && value.length === 15) {
1398
+ source[propertyName] = SalesforceIdUtils.generateId18FromId15(value);
1118
1399
  }
1119
- return true;
1120
1400
  }
1121
- applyChargeGroupUpdate(lineItem, update) {
1122
- const foundChargeGroup = ChargeGroupUtils.findChargeGroupById(update.id, lineItem);
1123
- if (!foundChargeGroup) {
1124
- return false;
1125
- }
1126
- if (update.attributeType === 'PRICE_ADJUSTMENT') {
1127
- foundChargeGroup.priceAdjustment = update.newValue;
1128
- }
1129
- else if (update.attributeType === 'LIST_PRICE_ADJUSTMENT') {
1130
- foundChargeGroup.listPriceAdjustment = update.newValue;
1131
- }
1132
- else {
1133
- throw new Error(`Not suppored AttributeType for Charge Group Item update: ${update.attributeType}`);
1134
- }
1135
- return true;
1401
+ get isInitialized() {
1402
+ return this._isInitialized;
1403
+ }
1404
+ get runtimeModel() {
1405
+ var _a;
1406
+ return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
1407
+ }
1408
+ get runtimeContext() {
1409
+ return this._runtimeContext;
1136
1410
  }
1137
1411
  }
1138
- FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1139
- FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowUpdateService });
1140
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowUpdateService, decorators: [{
1412
+ ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
1413
+ ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService });
1414
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
1141
1415
  type: Injectable
1142
- }] });
1416
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
1143
1417
 
1144
- class FlowConfigurationService {
1145
- constructor(proceduresApiService, contextService, quoteDraftService, updateService, configurationService) {
1146
- this.proceduresApiService = proceduresApiService;
1147
- this.contextService = contextService;
1148
- this.quoteDraftService = quoteDraftService;
1149
- this.updateService = updateService;
1418
+ class ConfigurationState {
1419
+ constructor(statefulConfigurationApiService, runtimeService, configurationService, toastService) {
1420
+ this.statefulConfigurationApiService = statefulConfigurationApiService;
1421
+ this.runtimeService = runtimeService;
1150
1422
  this.configurationService = configurationService;
1423
+ this.toastService = toastService;
1424
+ this.stateSubj$ = new BehaviorSubject({});
1425
+ this.state$ = this.stateSubj$.asObservable();
1426
+ this.stateId = null;
1151
1427
  }
1152
- calculate$(quoteDraft) {
1153
- return this.proceduresApiService.apply$(quoteDraft).pipe(tap$1(result => {
1154
- // sort the result current state based on the quote draft initial state
1155
- const initialStateIds = quoteDraft.initialState.map(lineItem => lineItem.integrationId);
1156
- result.currentState = result.currentState
1157
- .slice()
1158
- .sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
1159
- this.quoteDraftService.updateQuoteDraft(result);
1160
- }), map$2(noop));
1428
+ init$() {
1429
+ return this.configurationService.configure().pipe(switchMap$1(() => {
1430
+ var _a, _b;
1431
+ if (!this.isStatefulConfiguration) {
1432
+ return of(undefined);
1433
+ }
1434
+ const { actions, selectors } = (_b = (_a = this.runtimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
1435
+ return this.statefulConfigurationApiService.init({
1436
+ request: this.configurationService.generateRequest(),
1437
+ actions: actions === null || actions === void 0 ? void 0 : actions.map(action => ({ name: action.apiName, script: action.script })),
1438
+ selectors: selectors === null || selectors === void 0 ? void 0 : selectors.map(selector => ({ name: selector.apiName, script: selector.script })),
1439
+ });
1440
+ }), tap$1(stateId => (this.stateId = stateId || null)), map$2(() => undefined));
1161
1441
  }
1162
- calculate(quoteDraft) {
1163
- this.calculate$(quoteDraft).subscribe();
1442
+ cleanup() {
1443
+ this.stateId = null;
1444
+ this.configurationService.reset();
1445
+ this.stateSubj$.next({});
1164
1446
  }
1165
- update$(updates) {
1166
- const quoteDraft = this.quoteDraftService.quoteDraft;
1167
- if (!quoteDraft) {
1168
- return of(null);
1447
+ execute$(req) {
1448
+ if (this.isStatefulConfiguration) {
1449
+ return this.executeStateful$(req);
1169
1450
  }
1170
- return of([]).pipe(map$2(() => {
1171
- const updatedState = cloneDeep(quoteDraft.currentState);
1172
- this.updateService.update(updatedState, updates, quoteDraft.charges);
1173
- return updatedState;
1174
- }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1175
- }
1176
- update(updates) {
1177
- this.update$(updates).subscribe();
1178
- }
1179
- revert$(lineItemId) {
1180
- const quoteDraft = this.quoteDraftService.quoteDraft;
1181
- const initialCurrentState = this.quoteDraftService.getInitialCurrentState();
1182
- const currentState = this.quoteDraftService.activeCurrentState;
1183
- const currentLineItemIndex = currentState.findIndex(({ id }) => id === lineItemId);
1184
- const currentLineItem = currentState[currentLineItemIndex];
1185
- const initialLineItem = initialCurrentState.find(({ integrationId }) => integrationId === (currentLineItem === null || currentLineItem === void 0 ? void 0 : currentLineItem.integrationId));
1186
- if (!quoteDraft || !currentLineItem || !initialLineItem) {
1187
- return of(null);
1451
+ else {
1452
+ return this.executeStateless$(req);
1188
1453
  }
1189
- const updatedState = cloneDeep(currentState);
1190
- updatedState.splice(currentLineItemIndex, 1, initialLineItem);
1191
- return of([]).pipe(tap$1(() => {
1192
- this.quoteDraftService.setCurrentLineItemState(updatedState);
1193
- }), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1194
1454
  }
1195
- revert(lineItemId) {
1196
- this.revert$(lineItemId).subscribe();
1455
+ dispatch$(actionName, inputData) {
1456
+ return this.execute$({ actions: [{ name: actionName, inputData }] });
1197
1457
  }
1198
- delete$(ids) {
1199
- const quoteDraft = this.quoteDraftService.quoteDraft;
1200
- const currentState = this.quoteDraftService.currentState;
1201
- if (!quoteDraft) {
1202
- return of(null);
1203
- }
1204
- 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());
1458
+ select$(selectorName, inputData) {
1459
+ const requestId = UUID.UUID();
1460
+ return this.execute$({
1461
+ selectors: {
1462
+ [requestId]: {
1463
+ name: selectorName,
1464
+ inputData,
1465
+ },
1466
+ },
1467
+ }).pipe(map$2(() => this.stateSubj$.value[requestId]), tap$1(() => this.stateSubj$.next(omit(this.stateSubj$.value, requestId))));
1205
1468
  }
1206
- delete(ids) {
1207
- this.delete$(ids).subscribe();
1469
+ get isStatefulConfiguration() {
1470
+ var _a;
1471
+ return (_a = this.runtimeService.uiDefinitionProperties.statefulConfigurationEnabled) !== null && _a !== void 0 ? _a : false;
1208
1472
  }
1209
- addTerm$(term) {
1210
- const quoteDraft = this.quoteDraftService.quoteDraft;
1211
- if (!quoteDraft) {
1212
- return of(null);
1213
- }
1214
- const updatedState = [...quoteDraft.currentState, term];
1215
- return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1473
+ executeStateless$(request) {
1474
+ return of(undefined).pipe(switchMap$1(() => {
1475
+ var _a;
1476
+ // Apply actions and execute configuration/price call
1477
+ // No need to run configuration if no actions in the request
1478
+ if (!((_a = request.actions) === null || _a === void 0 ? void 0 : _a.length)) {
1479
+ return of(undefined);
1480
+ }
1481
+ let configurationRequest = this.configurationService.generateRequest();
1482
+ request.actions.forEach(action => {
1483
+ var _a;
1484
+ configurationRequest = (_a = this.executeActionScript(configurationRequest, action)) !== null && _a !== void 0 ? _a : configurationRequest;
1485
+ });
1486
+ return this.configurationService.configureRequest$(configurationRequest);
1487
+ }), tap$1(() => {
1488
+ if (!request.selectors) {
1489
+ return;
1490
+ }
1491
+ // Run selectors and apply them to the state
1492
+ const finalConfigurationRequest = this.configurationService.generateRequest();
1493
+ const selectorsResult = EntityUtil.entries(request.selectors).reduce((trunk, [key, selector]) => {
1494
+ trunk[key] = this.executeSelectorScript(finalConfigurationRequest, selector);
1495
+ return trunk;
1496
+ }, {});
1497
+ this.stateSubj$.next(Object.assign(Object.assign({}, this.stateSubj$.value), selectorsResult));
1498
+ }), map$2(() => undefined));
1216
1499
  }
1217
- addToCart$(props) {
1218
- const quoteDraft = this.quoteDraftService.quoteDraft;
1219
- if (!quoteDraft) {
1220
- return of(null);
1500
+ executeStateful$(request) {
1501
+ if (!this.stateId) {
1502
+ return of(undefined);
1221
1503
  }
1222
- return this.configurationService.configureExternal$(props).pipe(map$2(lineItem => {
1223
- var _a, _b, _c;
1224
- const model = this.configurationService.getRuntimeModel();
1225
- 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;
1226
- const lineItems = multiplyLineItems(lineItem, (_c = props.qty) !== null && _c !== void 0 ? _c : 1, split);
1227
- return [...quoteDraft.currentState, ...lineItems];
1228
- }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1229
- }
1230
- get() {
1231
- return this.quoteDraftService.quoteDraft$.pipe(map$2(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
1232
- }
1233
- getSnapshot() {
1234
- var _a, _b;
1235
- return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
1236
- }
1237
- get charges$() {
1238
- return this.quoteDraftService.quoteDraft$.pipe(map$2(({ charges }) => charges));
1239
- }
1240
- get pricePlans$() {
1241
- return this.quoteDraftService.quoteDraft$.pipe(map$2(({ pricePlans }) => pricePlans));
1242
- }
1243
- get activeMetrics$() {
1244
- return this.quoteDraftService.quoteDraft$.pipe(map$2(({ activeMetrics }) => activeMetrics));
1245
- }
1246
- get chargesSnapshot() {
1247
- var _a, _b;
1248
- return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.charges) !== null && _b !== void 0 ? _b : {};
1249
- }
1250
- get pricePlansSnapshot() {
1251
- var _a, _b;
1252
- return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.pricePlans) !== null && _b !== void 0 ? _b : {};
1253
- }
1254
- get activeMetricsSnapshot() {
1255
- var _a, _b;
1256
- return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.activeMetrics) !== null && _b !== void 0 ? _b : [];
1504
+ return this.statefulConfigurationApiService.execute(this.stateId, request).pipe(tap$1(response => {
1505
+ this.stateId = response.stateId;
1506
+ const updatedState = this.stateSubj$.value;
1507
+ EntityUtil.entries(response.selectors).forEach(([key, value]) => {
1508
+ if (!value.success) {
1509
+ if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
1510
+ this.toastService.add({ summary: value.errorMessage, severity: ToastType.error });
1511
+ }
1512
+ return;
1513
+ }
1514
+ updatedState[key] = value.result;
1515
+ });
1516
+ this.stateSubj$.next(updatedState);
1517
+ }), map$2(() => undefined));
1257
1518
  }
1258
- get contextSnapshot() {
1259
- return this.contextService.resolve();
1519
+ executeActionScript(request, processor) {
1520
+ var _a, _b, _c;
1521
+ const { actions } = (_b = (_a = this.runtimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
1522
+ const script = (_c = actions === null || actions === void 0 ? void 0 : actions.find(action => action.apiName === processor.name)) === null || _c === void 0 ? void 0 : _c.script;
1523
+ if (!script) {
1524
+ return null;
1525
+ }
1526
+ return this.executeProcessorScript(request, script, processor.inputData);
1260
1527
  }
1261
- get context$() {
1262
- return this.contextService.resolve$();
1528
+ executeSelectorScript(request, processor) {
1529
+ var _a, _b, _c;
1530
+ const { selectors } = (_b = (_a = this.runtimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
1531
+ const script = (_c = selectors === null || selectors === void 0 ? void 0 : selectors.find(selector => selector.apiName === processor.name)) === null || _c === void 0 ? void 0 : _c.script;
1532
+ if (!script) {
1533
+ return null;
1534
+ }
1535
+ return this.executeProcessorScript(request, script, processor.inputData);
1263
1536
  }
1264
- handleErrorAndBounceBack() {
1265
- return (source$) => {
1266
- return source$.pipe(catchError$1(error => {
1267
- console.error(error);
1268
- // bounce back if configuration call has failed
1269
- const quoteDraft = this.quoteDraftService.quoteDraft;
1270
- if (quoteDraft) {
1271
- this.quoteDraftService.updateQuoteDraft(quoteDraft);
1272
- }
1273
- return throwError(() => error);
1274
- }));
1275
- };
1537
+ executeProcessorScript(request, script, inputData) {
1538
+ return new Function(`${script}\nreturn transform;`)()({
1539
+ request,
1540
+ inputData: inputData,
1541
+ });
1276
1542
  }
1277
1543
  }
1278
- FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
1279
- FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowConfigurationService });
1280
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowConfigurationService, decorators: [{
1544
+ ConfigurationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState, deps: [{ token: i1.StatefulConfigurationApiService }, { token: ConfigurationRuntimeService }, { token: ConfigurationService }, { token: i4.ToastService }], target: i0.ɵɵFactoryTarget.Injectable });
1545
+ ConfigurationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState });
1546
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState, decorators: [{
1281
1547
  type: Injectable
1282
- }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1548
+ }], ctorParameters: function () { return [{ type: i1.StatefulConfigurationApiService }, { type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: i4.ToastService }]; } });
1283
1549
 
1284
1550
  class FlowConfigurationModule {
1285
1551
  }
1286
- FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1287
- FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: FlowConfigurationModule });
1288
- FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
1289
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1552
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1553
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
1554
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
1555
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1290
1556
  type: NgModule,
1291
1557
  args: [{
1292
1558
  imports: [],
@@ -1296,9 +1562,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
1296
1562
 
1297
1563
  class ConfigurationModule {
1298
1564
  }
1299
- ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1300
- ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1301
- ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationModule, providers: [
1565
+ ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1566
+ ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1567
+ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, providers: [
1302
1568
  ContextApiService,
1303
1569
  ProductModelApiService,
1304
1570
  ConfigurationApiService,
@@ -1307,7 +1573,7 @@ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ver
1307
1573
  ConfigurationService,
1308
1574
  ConfigurationState,
1309
1575
  ], imports: [ConfirmationDialogModule] });
1310
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ConfigurationModule, decorators: [{
1576
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, decorators: [{
1311
1577
  type: NgModule,
1312
1578
  args: [{
1313
1579
  imports: [ConfirmationDialogModule],
@@ -1323,251 +1589,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
1323
1589
  }]
1324
1590
  }] });
1325
1591
 
1326
- function calculateMetricByMethod(lineItems, metric, method) {
1327
- const items = getLineItemsByMethod(lineItems, method);
1328
- return items.reduce((acc, li) => {
1329
- let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
1330
- if (method === 'avg' && li.length > 0) {
1331
- value /= li.length;
1332
- }
1333
- return acc + value;
1334
- }, 0);
1335
- }
1336
- function getLineItemsByMethod(lineItems, method) {
1337
- switch (method) {
1338
- case 'first': {
1339
- return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
1340
- }
1341
- case 'last': {
1342
- const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1343
- const products = rootTermItems.map(lineItem => [
1344
- lineItem,
1345
- ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
1346
- ]);
1347
- return products
1348
- .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
1349
- .filter((li) => Boolean(li))
1350
- .map(item => [item]);
1351
- }
1352
- case 'avg': {
1353
- const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1354
- return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
1355
- }
1356
- case 'sum': {
1357
- return lineItems.map(item => [item]);
1358
- }
1359
- default: {
1360
- return lineItems.map(item => [item]);
1361
- }
1362
- }
1363
- }
1364
- function getDateValue(date) {
1365
- return date ? new Date(date).getTime() : 0;
1366
- }
1367
-
1368
- class MetricsCalculationService {
1369
- get onMetricsUpdate$() {
1370
- return this.metricsUpdated$.asObservable();
1371
- }
1372
- constructor(quoteDraftService, flowConfiguration, settingsService) {
1373
- this.quoteDraftService = quoteDraftService;
1374
- this.flowConfiguration = flowConfiguration;
1375
- this.settingsService = settingsService;
1376
- this.metricsUpdated$ = new Subject();
1377
- this.quoteMetricsSettings = {};
1378
- this.metricsCalculationMethodMap = {};
1379
- this.metricsData = {};
1380
- this.activeMetricRules = [];
1381
- this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(metricRule => metricRule.metrics.some(metric => !!metric.totalName));
1382
- combineLatest([
1383
- this.quoteDraftService.currentState$,
1384
- this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
1385
- ]).subscribe(([lineItems, setting]) => {
1386
- let settingsData = {};
1387
- try {
1388
- settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
1389
- }
1390
- catch (error) {
1391
- settingsData = {};
1392
- }
1393
- this.quoteMetricsSettings = settingsData;
1394
- this.updateMetrics(lineItems);
1395
- });
1396
- }
1397
- getMetricValue(metric) {
1398
- return this.metricsData[metric] || 0;
1399
- }
1400
- updateMetrics(lineItems) {
1401
- const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
1402
- this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
1403
- this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
1404
- this.metricsUpdated$.next();
1405
- }
1406
- calculateMetric(lineItems, metric) {
1407
- return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
1408
- }
1409
- buildMetricsCalculationMethods(metricKeys, initial) {
1410
- return metricKeys.reduce((acc, name) => {
1411
- var _a, _b;
1412
- if (acc[name]) {
1413
- return acc;
1414
- }
1415
- acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
1416
- const metricRule = this.getMetricRuleByTotalMetricName(name);
1417
- 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;
1418
- if (this.quoteMetricsSettings[settingKey]) {
1419
- acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
1420
- }
1421
- return acc;
1422
- }, initial);
1423
- }
1424
- collectMetricKeys(lineItems) {
1425
- const keys = [];
1426
- lineItems.forEach(lineItem => {
1427
- keys.push(...Object.keys(lineItem.totalMetrics || {}));
1428
- keys.push(...this.collectMetricKeys(lineItem.lineItems));
1429
- });
1430
- return uniq(keys);
1431
- }
1432
- getMetricRuleByTotalMetricName(name) {
1433
- return this.activeMetricRules.find(metricRule => metricRule.metrics.find(metric => metric.totalName === name));
1434
- }
1435
- }
1436
- MetricsCalculationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: FlowConfigurationService }, { token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1437
- MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
1438
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: MetricsCalculationService, decorators: [{
1439
- type: Injectable,
1440
- args: [{ providedIn: 'root' }]
1441
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1.ConfigurationSettingsApiService }]; } });
1442
-
1443
- class ProductImagesService {
1444
- constructor(productApiService) {
1445
- this.productApiService = productApiService;
1446
- this.imagesMap$ = new BehaviorSubject({});
1447
- }
1448
- getImageUrl$(productId) {
1449
- if (this.imagesMap$.value[productId] == null) {
1450
- this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
1451
- this.fetchProductImage(productId);
1452
- }
1453
- return this.imagesMap$.pipe(map$2(imagesMap => imagesMap[productId]), distinctUntilChanged());
1454
- }
1455
- fetchProductImage(productId) {
1456
- this.productApiService
1457
- .fetchImage$(productId)
1458
- .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 }))))
1459
- .subscribe();
1460
- }
1461
- }
1462
- ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1463
- ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
1464
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: ProductImagesService, decorators: [{
1465
- type: Injectable,
1466
- args: [{ providedIn: 'root' }]
1467
- }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
1468
-
1469
- class RuntimeSettingsService {
1470
- constructor(configurationSettingsApiService) {
1471
- this.configurationSettingsApiService = configurationSettingsApiService;
1472
- this.configurationSettings$ = new BehaviorSubject({});
1473
- this.currencySettings$ = new BehaviorSubject({
1474
- iso: DEFAULT_CURRENCY_ISO_CODE,
1475
- symbol: DEFAULT_CURRENCY_SYMBOL,
1476
- });
1477
- this.getCurrencySymbol = (locale, currency) => {
1478
- return (0)
1479
- .toLocaleString(locale, { style: 'currency', currency, minimumFractionDigits: 0, maximumFractionDigits: 0 })
1480
- .replace(/\d/g, '')
1481
- .trim();
1482
- };
1483
- }
1484
- create() {
1485
- return this.configurationSettingsApiService.fetchSettings().pipe(map$2(settings => this.parseConfigurationSettings(settings)), tap$1(configurationSettings => {
1486
- this.configurationSettings$.next(configurationSettings);
1487
- this.formattingSettings = this.getFormattingSettings();
1488
- }), map$2(() => undefined));
1489
- }
1490
- initCurrency(iso) {
1491
- if (iso) {
1492
- const symbol = this.getCurrencySymbol('en-US', iso);
1493
- this.currencySettings$.next({ iso, symbol });
1494
- }
1495
- }
1496
- getFormattingSettings() {
1497
- var _a, _b;
1498
- if (this.formattingSettings) {
1499
- return this.formattingSettings;
1500
- }
1501
- const shoppingCartSettings = (_a = this.getConfigurationSettings()['shopping-cart']) === null || _a === void 0 ? void 0 : _a.reduce((acc, setting) => {
1502
- return Object.assign(Object.assign({}, acc), { [setting.id]: setting.properties });
1503
- }, {});
1504
- const currencySettings = this.getCurrencySettings();
1505
- const dateFormat = (validateDateFormat((_b = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.DATE_FORMAT) !== null && _b !== void 0 ? _b : '') && (shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.DATE_FORMAT)) ||
1506
- DEFAULT_DATE_FORMAT;
1507
- const decimalSeparator = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.DECIMAL_SEPARATOR;
1508
- const thousandsSeparator = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.THOUSANDS_SEPARATOR;
1509
- // the number of decimal places can be 0
1510
- const priceScale = shoppingCartSettings === null || shoppingCartSettings === void 0 ? void 0 : shoppingCartSettings.PRICE_SCALE;
1511
- const decimalsCount = priceScale !== null && priceScale !== '' && !isNaN(Number(priceScale)) && Number(priceScale) >= 0
1512
- ? Number(priceScale)
1513
- : DEFAULT_DECIMALS_COUNT;
1514
- return {
1515
- currencySymbol: currencySettings.symbol,
1516
- dateFormats: getSupportedDateFormats(dateFormat),
1517
- decimalsCount,
1518
- decimalSeparator: decimalSeparator !== undefined && ['.', ','].includes(decimalSeparator)
1519
- ? decimalSeparator
1520
- : DEFAULT_DECIMAL_SEPARATOR,
1521
- // thousands separator can be a blank value, so it can also be null
1522
- thousandsSeparator: thousandsSeparator !== undefined && ['.', ',', '', null].includes(thousandsSeparator)
1523
- ? thousandsSeparator || ''
1524
- : DEFAULT_THOUSANDS_SEPARATOR,
1525
- };
1526
- }
1527
- getConfigurationSettings() {
1528
- return this.configurationSettings$.value;
1529
- }
1530
- getCurrencySettings() {
1531
- return this.currencySettings$.value;
1532
- }
1533
- parseConfigurationSettings(settings) {
1534
- return settings.reduce((acc, setting) => {
1535
- switch (setting.key) {
1536
- case 'shopping-cart':
1537
- acc['shopping-cart'] = parseJsonSafely(setting.value, []);
1538
- break;
1539
- case 'navigation':
1540
- acc.navigation = parseJsonSafely(setting.value, {});
1541
- break;
1542
- case 'flows':
1543
- acc.flows = parseJsonSafely(setting.value, []);
1544
- break;
1545
- default:
1546
- acc[setting.key] = setting.value;
1547
- }
1548
- return acc;
1549
- }, {});
1550
- }
1551
- }
1552
- RuntimeSettingsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeSettingsService, deps: [{ token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1553
- RuntimeSettingsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeSettingsService, providedIn: 'root' });
1554
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: RuntimeSettingsService, decorators: [{
1555
- type: Injectable,
1556
- args: [{ providedIn: 'root' }]
1557
- }], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
1558
-
1559
1592
  const DEFAULT_FORMATTING_SETTINGS = {
1560
1593
  currencySymbol: DEFAULT_CURRENCY_SYMBOL,
1561
1594
  decimalsCount: DEFAULT_DECIMALS_COUNT,
1562
1595
  dateFormats: getSupportedDateFormats(DEFAULT_DATE_FORMAT),
1563
1596
  decimalSeparator: DEFAULT_DECIMAL_SEPARATOR,
1564
1597
  thousandsSeparator: DEFAULT_THOUSANDS_SEPARATOR,
1598
+ actionCodeLabels: DEFAULT_ACTION_CODE_LABELS,
1565
1599
  };
1566
1600
  class SdkCoreModule {
1567
1601
  }
1568
- SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1569
- SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1570
- SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkCoreModule, providers: [
1602
+ SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1603
+ SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1604
+ SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, providers: [
1571
1605
  ContextService,
1572
1606
  QuoteDraftService,
1573
1607
  ProductImagesService,
@@ -1578,7 +1612,7 @@ SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version:
1578
1612
  useExisting: RuntimeSettingsService,
1579
1613
  },
1580
1614
  ], imports: [ConfigurationModule, FlowConfigurationModule] });
1581
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkCoreModule, decorators: [{
1615
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, decorators: [{
1582
1616
  type: NgModule,
1583
1617
  args: [{
1584
1618
  imports: [ConfigurationModule, FlowConfigurationModule],
@@ -1621,9 +1655,9 @@ class CalendarDirective {
1621
1655
  }
1622
1656
  }
1623
1657
  }
1624
- CalendarDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CalendarDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1625
- CalendarDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.8", type: CalendarDirective, selector: "[vlCalendar]", inputs: { vlCalendar: "vlCalendar" }, ngImport: i0 });
1626
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: CalendarDirective, decorators: [{
1658
+ CalendarDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CalendarDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1659
+ CalendarDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: CalendarDirective, selector: "[vlCalendar]", inputs: { vlCalendar: "vlCalendar" }, ngImport: i0 });
1660
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CalendarDirective, decorators: [{
1627
1661
  type: Directive,
1628
1662
  args: [{
1629
1663
  selector: '[vlCalendar]',
@@ -1634,10 +1668,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
1634
1668
 
1635
1669
  class SdkDirectivesModule {
1636
1670
  }
1637
- SdkDirectivesModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkDirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1638
- SdkDirectivesModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: SdkDirectivesModule, declarations: [CalendarDirective], exports: [CalendarDirective] });
1639
- SdkDirectivesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkDirectivesModule });
1640
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkDirectivesModule, decorators: [{
1671
+ SdkDirectivesModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkDirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1672
+ SdkDirectivesModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SdkDirectivesModule, declarations: [CalendarDirective], exports: [CalendarDirective] });
1673
+ SdkDirectivesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkDirectivesModule });
1674
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkDirectivesModule, decorators: [{
1641
1675
  type: NgModule,
1642
1676
  args: [{
1643
1677
  declarations: [CalendarDirective],
@@ -1670,9 +1704,9 @@ class DatePipe {
1670
1704
  }
1671
1705
  }
1672
1706
  }
1673
- DatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: DatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1674
- DatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: DatePipe, name: "vlDate" });
1675
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: DatePipe, decorators: [{
1707
+ DatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1708
+ DatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: DatePipe, name: "vlDate" });
1709
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DatePipe, decorators: [{
1676
1710
  type: Pipe,
1677
1711
  args: [{
1678
1712
  name: 'vlDate',
@@ -1694,9 +1728,9 @@ class NumberPipe {
1694
1728
  return formatNumber(price, (_a = this.formattingSettings) === null || _a === void 0 ? void 0 : _a.thousandsSeparator, (_b = this.formattingSettings) === null || _b === void 0 ? void 0 : _b.decimalSeparator, (_c = this.formattingSettings) === null || _c === void 0 ? void 0 : _c.decimalsCount);
1695
1729
  }
1696
1730
  }
1697
- NumberPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: NumberPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1698
- NumberPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: NumberPipe, name: "vlNumber" });
1699
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: NumberPipe, decorators: [{
1731
+ NumberPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NumberPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1732
+ NumberPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: NumberPipe, name: "vlNumber" });
1733
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NumberPipe, decorators: [{
1700
1734
  type: Pipe,
1701
1735
  args: [{
1702
1736
  name: 'vlNumber',
@@ -1721,25 +1755,44 @@ class PricePipe {
1721
1755
  return `${((_a = this.formattingSettings) === null || _a === void 0 ? void 0 : _a.currencySymbol) || DEFAULT_CURRENCY_SYMBOL}${formatNumber(price, (_b = this.formattingSettings) === null || _b === void 0 ? void 0 : _b.thousandsSeparator, (_c = this.formattingSettings) === null || _c === void 0 ? void 0 : _c.decimalSeparator, (_d = this.formattingSettings) === null || _d === void 0 ? void 0 : _d.decimalsCount)}`;
1722
1756
  }
1723
1757
  }
1724
- PricePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: PricePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1725
- PricePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: PricePipe, name: "vlPrice" });
1726
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: PricePipe, decorators: [{
1758
+ PricePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PricePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1759
+ PricePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: PricePipe, name: "vlPrice" });
1760
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: PricePipe, decorators: [{
1727
1761
  type: Pipe,
1728
1762
  args: [{
1729
1763
  name: 'vlPrice',
1730
1764
  }]
1731
1765
  }] });
1732
1766
 
1767
+ class ActionCodePipe {
1768
+ constructor() {
1769
+ var _a;
1770
+ this.formattingSettings = (_a = inject(FORMATTING_SETTINGS_TOKEN, { optional: true })) === null || _a === void 0 ? void 0 : _a.getFormattingSettings();
1771
+ }
1772
+ transform(actionCode) {
1773
+ var _a, _b;
1774
+ return (_b = (_a = this.formattingSettings) === null || _a === void 0 ? void 0 : _a.actionCodeLabels[actionCode]) !== null && _b !== void 0 ? _b : actionCode;
1775
+ }
1776
+ }
1777
+ ActionCodePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionCodePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1778
+ ActionCodePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: ActionCodePipe, name: "vlActionCode" });
1779
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionCodePipe, decorators: [{
1780
+ type: Pipe,
1781
+ args: [{
1782
+ name: 'vlActionCode',
1783
+ }]
1784
+ }] });
1785
+
1733
1786
  class SdkPipesModule {
1734
1787
  }
1735
- SdkPipesModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkPipesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1736
- SdkPipesModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.8", ngImport: i0, type: SdkPipesModule, declarations: [NumberPipe, PricePipe, DatePipe], exports: [NumberPipe, PricePipe, DatePipe] });
1737
- SdkPipesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkPipesModule });
1738
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: SdkPipesModule, decorators: [{
1788
+ SdkPipesModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkPipesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1789
+ SdkPipesModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SdkPipesModule, declarations: [NumberPipe, PricePipe, DatePipe, ActionCodePipe], exports: [NumberPipe, PricePipe, DatePipe, ActionCodePipe] });
1790
+ SdkPipesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkPipesModule });
1791
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkPipesModule, decorators: [{
1739
1792
  type: NgModule,
1740
1793
  args: [{
1741
- declarations: [NumberPipe, PricePipe, DatePipe],
1742
- exports: [NumberPipe, PricePipe, DatePipe],
1794
+ declarations: [NumberPipe, PricePipe, DatePipe, ActionCodePipe],
1795
+ exports: [NumberPipe, PricePipe, DatePipe, ActionCodePipe],
1743
1796
  }]
1744
1797
  }] });
1745
1798
 
@@ -1747,5 +1800,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
1747
1800
  * Generated bundle index. Do not edit.
1748
1801
  */
1749
1802
 
1750
- export { CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationState, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, MetricsCalculationService, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, calculateCardinalityVariables, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateLineItem, generateModifiedAssetsMap, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isLineItemModified, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
1803
+ export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationState, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, MetricsCalculationService, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, calculateCardinalityVariables, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateLineItem, generateModifiedAssetsMap, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isLineItemModified, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
1751
1804
  //# sourceMappingURL=veloceapps-sdk-core.mjs.map