@veloceapps/sdk 8.0.0-2 → 8.0.0-200

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