@veloceapps/sdk 8.0.0-19 → 8.0.0-191

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