@veloceapps/sdk 8.0.0-1 → 8.0.0-100

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