@veloceapps/sdk 8.0.0-9 → 8.0.0-90

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