@veloceapps/sdk 8.0.0-18 → 8.0.0-180

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 +7 -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 +26 -15
  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 +51 -0
  22. package/core/modules/configuration/services/configuration.service.d.ts +10 -5
  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 +79 -0
  34. package/core/services/index.d.ts +4 -1
  35. package/core/services/quote-draft.service.d.ts +8 -1
  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 +6 -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 -0
  42. package/core/types/pipe.types.d.ts +1 -0
  43. package/core/utils/line-item.utils.d.ts +0 -1
  44. package/esm2020/cms/cms.actions.mjs +15 -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 +304 -0
  75. package/esm2020/core/modules/configuration/services/configuration.service.mjs +68 -45
  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 +10 -7
  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 +506 -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 +32 -8
  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 +30 -15
  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 +22 -12
  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 +72 -23
  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 +287 -195
  131. package/fesm2015/veloceapps-sdk-cms.mjs.map +1 -1
  132. package/fesm2015/veloceapps-sdk-core.mjs +1595 -728
  133. package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
  134. package/fesm2015/veloceapps-sdk.mjs +740 -1451
  135. package/fesm2015/veloceapps-sdk.mjs.map +1 -1
  136. package/fesm2020/veloceapps-sdk-cms.mjs +291 -209
  137. package/fesm2020/veloceapps-sdk-cms.mjs.map +1 -1
  138. package/fesm2020/veloceapps-sdk-core.mjs +1741 -910
  139. package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
  140. package/fesm2020/veloceapps-sdk.mjs +802 -1511
  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 +7 -6
  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 +10 -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, Subject, filter as filter$1, zip, combineLatest, 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, flatten, entries, sortBy, map as map$2, omit, isEqual, cloneDeep, assign, uniqBy, 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,200 +193,450 @@ 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
- class QuoteDraftService {
282
- get isInitialized() {
283
- return this.isInitializedSubj$.getValue();
284
- }
285
- set isInitialized(value) {
286
- if (this.isInitialized !== value) {
287
- this.isInitializedSubj$.next(value);
287
+ const findLineItem = (id, lineItems) => {
288
+ return findLineItemWithComparator(lineItems, (li) => li.id === id);
289
+ };
290
+ const findLineItemWithComparator = (lineItems, comparator) => {
291
+ let currentLevel = lineItems;
292
+ while (currentLevel.length) {
293
+ const found = currentLevel.find(comparator);
294
+ if (found) {
295
+ return found;
288
296
  }
297
+ currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
289
298
  }
290
- get hasUnsavedChanges() {
291
- return this._hasUnsavedChanges;
292
- }
293
- set hasUnsavedChanges(value) {
294
- this._hasUnsavedChanges = value;
295
- if (!this._hasUnsavedChanges) {
296
- this.initialCurrentState = this.quoteDraft?.currentState ?? [];
299
+ return;
300
+ };
301
+ const insertLineItem = (lineItem, parentId, toInsert) => {
302
+ const insertData = lineItem.id === parentId ? [toInsert] : [];
303
+ return {
304
+ ...lineItem,
305
+ lineItems: [
306
+ ...insertData,
307
+ ...lineItem.lineItems.map(li => {
308
+ return insertLineItem(li, parentId, toInsert);
309
+ }),
310
+ ],
311
+ };
312
+ };
313
+ const removeLineItem = (lineItem, idToRemove) => {
314
+ return {
315
+ ...lineItem,
316
+ lineItems: lineItem.lineItems
317
+ .map(li => {
318
+ if (li.id === idToRemove) {
319
+ return;
320
+ }
321
+ else if (li.lineItems.length) {
322
+ return removeLineItem(li, idToRemove);
323
+ }
324
+ return li;
325
+ })
326
+ .filter(r => !!r),
327
+ };
328
+ };
329
+ const replaceLineItem = (lineItem, replaceTo, skipCardinalityCalculation = false) => {
330
+ if (lineItem.id === replaceTo.id) {
331
+ if (!skipCardinalityCalculation) {
332
+ return { ...recalculateCardinalityVariables(lineItem, replaceTo) };
333
+ }
334
+ else {
335
+ return { ...replaceTo };
297
336
  }
298
337
  }
299
- get hasProducts$() {
300
- return this.quoteSubj$.pipe(map(() => this.hasProducts));
301
- }
302
- get hasProducts() {
303
- const quoteDraft = this.quoteSubj$.value;
304
- return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
305
- }
306
- constructor(context, quoteApiService, priceApiService) {
307
- this.context = context;
308
- this.quoteApiService = quoteApiService;
309
- this.priceApiService = priceApiService;
310
- this.quoteSubj$ = new BehaviorSubject(null);
311
- this.resetSubj$ = new BehaviorSubject(true);
312
- this.isInitializedSubj$ = new BehaviorSubject(false);
313
- this.initialCurrentState = [];
314
- this._hasUnsavedChanges = false;
315
- this.allPriceLists = [];
316
- this.assetPriceLists = [];
317
- this.reset$ = this.resetSubj$.asObservable();
318
- this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), map(priceList => priceList ?? null));
319
- this.isInitializedSubj$
320
- .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
321
- .subscribe();
322
- }
323
- reset() {
324
- this.resetSubj$.next(true);
325
- this.quoteSubj$.next(null);
326
- this.hasUnsavedChanges = false;
327
- }
328
- init(quoteId, params) {
329
- return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
330
- this.allPriceLists = allPriceLists;
331
- this.quoteSubj$.next(quote);
332
- this.context.update(quote.context);
338
+ return {
339
+ ...lineItem,
340
+ lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo, skipCardinalityCalculation)),
341
+ };
342
+ };
343
+ const collectCardinalityComputations = (portDomains) => {
344
+ const cardinalityComputations = new Map();
345
+ entries(portDomains).forEach(([key, portDomain]) => {
346
+ cardinalityComputations.set(key, portDomain.properties['cardinalityComputation'] === 'true');
347
+ });
348
+ return cardinalityComputations;
349
+ };
350
+ const calculateCardinalityVariables = (lineItems, cardinalityComputations) => {
351
+ const cardVars = new Map();
352
+ lineItems
353
+ .filter(({ port, type }) => !!port && !!type)
354
+ .forEach(li => {
355
+ if (cardinalityComputations.get(`${li.port}`)) {
356
+ const cardinalityVariableName = `#CV-${li.type}@${li.port}`;
357
+ cardVars.set(cardinalityVariableName, (cardVars.get(cardinalityVariableName) ?? 0) + li.qty);
358
+ }
359
+ });
360
+ return cardVars;
361
+ };
362
+ const cardinalityRegexp = new RegExp('#CV-[a-zA-Z0-9_]+@(?<portName>[a-zA-Z0-9_]+)');
363
+ const recalculateCardinalityVariables = (original, updated) => {
364
+ const cardinalityComputations = collectCardinalityComputations(updated.portDomains ?? original.portDomains ?? {});
365
+ const cardinalityVariables = calculateCardinalityVariables(updated.lineItems, cardinalityComputations);
366
+ const originalCardinalityVariables = calculateCardinalityVariables(original.lineItems, cardinalityComputations);
367
+ originalCardinalityVariables.forEach((value, key) => {
368
+ const execArray = cardinalityRegexp.exec(key);
369
+ const portName = execArray?.groups?.['portName'];
370
+ if (!portName || cardinalityComputations.get(portName)) {
371
+ if (cardinalityVariables.get(key) === value) {
372
+ // no need to update cardinality if no changes
373
+ cardinalityVariables.delete(key);
374
+ }
375
+ else if (!cardinalityVariables.has(key)) {
376
+ // remove last item from port
377
+ cardinalityVariables.set(key, 0);
378
+ }
379
+ }
380
+ });
381
+ return {
382
+ ...updated,
383
+ attributes: upsertAttributes(updated.attributes, [...cardinalityVariables].map(([name, value]) => ({ name, value, cfgStatus: 'Changed' }))),
384
+ };
385
+ };
386
+ const mapAttributes = (attributes) => {
387
+ return attributes.reduce((acc, { name, value }) => ({ ...acc, [name]: value }), {});
388
+ };
389
+ const getAttributes = (attributes, names = []) => {
390
+ const filtered = attributes.filter(({ name }) => names.includes(name));
391
+ return sortBy(filtered, [({ name }) => names.indexOf(name)]);
392
+ };
393
+ const upsertAttributes = (originalAttributes, attributesToUpsert) => {
394
+ return attributesToUpsert.reduce((acc, { name, value }) => {
395
+ const [origAttr] = getAttributes(acc, [name]);
396
+ return [
397
+ ...acc.filter(attr => attr.name !== name),
398
+ { ...(origAttr ?? { name, type: '' }), cfgStatus: origAttr ? 'Changed' : 'User', value },
399
+ ];
400
+ }, originalAttributes);
401
+ };
402
+ const patchAttributes = (rootLineItem, id, attrs, skipCardinalityCalculation = false) => {
403
+ const lineItem = findLineItem(id, [rootLineItem]);
404
+ if (!lineItem) {
405
+ return rootLineItem;
406
+ }
407
+ const attributes = upsertAttributes(lineItem.attributes, attrs);
408
+ return replaceLineItem(rootLineItem, { ...lineItem, attributes }, skipCardinalityCalculation);
409
+ };
410
+ const getAttributeValue = (attributes, name) => attributes.find(attr => attr.name === name)?.value;
411
+ const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
412
+ return {
413
+ id: UUID.UUID(),
414
+ port,
415
+ type,
416
+ actionCode: 'ADD',
417
+ cfgStatus: 'New',
418
+ attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
419
+ lineItems,
420
+ parentId,
421
+ qty: 1,
422
+ };
423
+ };
424
+ const getRecommendedPrices = (portDomain, type) => {
425
+ const domainType = portDomain.domainTypes.find(({ name }) => name === type);
426
+ const [net, list] = domainType?.recommendedPrices
427
+ ?.filter(({ chargeMethod }) => chargeMethod === 'ONE_TIME')
428
+ .reduce((acc, rp) => {
429
+ const [netPrice, listPrice] = acc;
430
+ return [netPrice + rp.netPrice, listPrice + rp.listPrice];
431
+ }, [0, 0]) ?? [0, 0];
432
+ return { net, list };
433
+ };
434
+ const generateModifiedAssetsMap = (lineItems) => {
435
+ return lineItems.reduce((acc, li) => {
436
+ const isModified = isLineItemModified(li);
437
+ if (!isModified) {
438
+ return acc;
439
+ }
440
+ const target = getOriginParent(lineItems, li);
441
+ const id = target?.assetId ?? target?.openOrderLineItemId;
442
+ if (id) {
443
+ acc[id] = true;
444
+ }
445
+ return acc;
446
+ }, {});
447
+ };
448
+ const getOriginParent = (lineItems, currentLineItem) => {
449
+ let target = currentLineItem;
450
+ while (target && target.rampInstanceId) {
451
+ target = lineItems.find(sub => sub.id === currentLineItem.rampInstanceId);
452
+ }
453
+ return target;
454
+ };
455
+ const isLineItemModified = (lineItem) => {
456
+ if (lineItem.actionCode === 'EXIST' && lineItem.status === 'PENDING') {
457
+ return false;
458
+ }
459
+ return lineItem.actionCode !== 'EXIST';
460
+ };
461
+ const multiplyLineItems = (lineItem, qty, split) => {
462
+ if (split) {
463
+ const unifyIds = (lineItem) => ({
464
+ ...lineItem,
465
+ id: UUID.UUID(),
466
+ lineItems: lineItem.lineItems.map(unifyIds),
467
+ });
468
+ return map$2(new Array(qty), () => unifyIds(lineItem));
469
+ }
470
+ else {
471
+ return [
472
+ {
473
+ ...lineItem,
474
+ qty: qty,
475
+ },
476
+ ];
477
+ }
478
+ };
479
+ const isTechnicalAttribute = (name) => {
480
+ return name.startsWith('#') || name.startsWith('$');
481
+ };
482
+ const filterOutTechnicalAttributes = (attributes) => {
483
+ return attributes.filter(({ name }) => !isTechnicalAttribute(name));
484
+ };
485
+
486
+ var lineItem_utils = /*#__PURE__*/Object.freeze({
487
+ __proto__: null,
488
+ filterOutTechnicalAttributes: filterOutTechnicalAttributes,
489
+ findLineItem: findLineItem,
490
+ findLineItemWithComparator: findLineItemWithComparator,
491
+ generateLineItem: generateLineItem,
492
+ generateModifiedAssetsMap: generateModifiedAssetsMap,
493
+ getAttributeValue: getAttributeValue,
494
+ getAttributes: getAttributes,
495
+ getOriginParent: getOriginParent,
496
+ getRecommendedPrices: getRecommendedPrices,
497
+ insertLineItem: insertLineItem,
498
+ isLineItemModified: isLineItemModified,
499
+ isTechnicalAttribute: isTechnicalAttribute,
500
+ mapAttributes: mapAttributes,
501
+ multiplyLineItems: multiplyLineItems,
502
+ patchAttributes: patchAttributes,
503
+ recalculateCardinalityVariables: recalculateCardinalityVariables,
504
+ removeLineItem: removeLineItem,
505
+ replaceLineItem: replaceLineItem,
506
+ upsertAttributes: upsertAttributes
507
+ });
508
+
509
+ class LineItemWorker {
510
+ constructor(src) {
511
+ this.li = { ...src };
512
+ }
513
+ insert(parentId, toInsert) {
514
+ return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
515
+ }
516
+ remove(id) {
517
+ return new LineItemWorker(removeLineItem(this.li, id));
518
+ }
519
+ replace(toReplace, skipCardinalityCalculation = false) {
520
+ return new LineItemWorker(replaceLineItem(this.li, toReplace, skipCardinalityCalculation));
521
+ }
522
+ patchAttribute(attrs, id, skipCardinalityCalculation = false) {
523
+ return new LineItemWorker(patchAttributes(this.li, id ?? this.li.id, attrs, skipCardinalityCalculation));
524
+ }
525
+ }
526
+
527
+ function extractMetadata(uiDefinition) {
528
+ return omit(uiDefinition, [
529
+ 'children',
530
+ 'pages',
531
+ 'components',
532
+ ]);
533
+ }
534
+
535
+ class IntegrationState {
536
+ constructor() {
537
+ this.stateSubj$ = new BehaviorSubject({});
538
+ this.action$ = new Subject();
539
+ }
540
+ get state$() {
541
+ return this.stateSubj$.asObservable();
542
+ }
543
+ get state() {
544
+ return this.stateSubj$.getValue();
545
+ }
546
+ patchState(update) {
547
+ this.stateSubj$.next({ ...this.stateSubj$.getValue(), ...update });
548
+ }
549
+ dispatch(action) {
550
+ this.action$.next(action);
551
+ }
552
+ listen$(actionType) {
553
+ return this.action$.pipe(filter$1(action => action.type === actionType), map$1(action => action.payload));
554
+ }
555
+ listenAll$() {
556
+ return this.action$.asObservable();
557
+ }
558
+ clear() {
559
+ this.stateSubj$.next({});
560
+ }
561
+ }
562
+ IntegrationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
563
+ IntegrationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState });
564
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState, decorators: [{
565
+ type: Injectable
566
+ }] });
567
+
568
+ class QuoteDraftService {
569
+ get isInitialized$() {
570
+ return this.isInitializedSubj$.asObservable();
571
+ }
572
+ get isInitialized() {
573
+ return this.isInitializedSubj$.getValue();
574
+ }
575
+ set isInitialized(value) {
576
+ if (this.isInitialized !== value) {
577
+ this.isInitializedSubj$.next(value);
578
+ }
579
+ }
580
+ get hasUnsavedChanges() {
581
+ return this._hasUnsavedChanges;
582
+ }
583
+ set hasUnsavedChanges(value) {
584
+ this._hasUnsavedChanges = value;
585
+ if (!this._hasUnsavedChanges) {
586
+ this.initialCurrentState = this.quoteDraft?.currentState ?? [];
587
+ }
588
+ }
589
+ get hasProducts$() {
590
+ return this.quoteSubj$.pipe(map(() => this.hasProducts));
591
+ }
592
+ get hasProducts() {
593
+ const quoteDraft = this.quoteSubj$.value;
594
+ return this.filterByActivePriceList(quoteDraft?.currentState || []).some(li => !li.assetId && !li.openOrderLineItemId);
595
+ }
596
+ get hasAssets$() {
597
+ return this.quoteSubj$.pipe(map(() => this.hasAssets));
598
+ }
599
+ get hasAssets() {
600
+ const quoteDraft = this.quoteSubj$.value;
601
+ return this.filterByActivePriceList(quoteDraft?.currentState || []).some(li => li.assetId || li.openOrderLineItemId);
602
+ }
603
+ constructor(context, quoteApiService, priceApiService, integrationState) {
604
+ this.context = context;
605
+ this.quoteApiService = quoteApiService;
606
+ this.priceApiService = priceApiService;
607
+ this.integrationState = integrationState;
608
+ this.quoteSubj$ = new BehaviorSubject(null);
609
+ this.resetSubj$ = new BehaviorSubject(true);
610
+ this.isInitializedSubj$ = new BehaviorSubject(false);
611
+ this.initialCurrentState = [];
612
+ this._hasUnsavedChanges = false;
613
+ this.allPriceLists = [];
614
+ this.assetPriceLists = [];
615
+ this.reset$ = this.resetSubj$.asObservable();
616
+ this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), map(priceList => priceList ?? null));
617
+ this.isInitializedSubj$
618
+ .pipe(filter(isInitialized => isInitialized), switchMap$1(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
619
+ .subscribe();
620
+ }
621
+ reset() {
622
+ this.resetSubj$.next(true);
623
+ this.quoteSubj$.next(null);
624
+ this.isInitialized = false;
625
+ this.hasUnsavedChanges = false;
626
+ }
627
+ init(quoteId, params) {
628
+ return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
629
+ this.allPriceLists = allPriceLists;
630
+ this.quoteSubj$.next(quote);
631
+ this.context.update(quote.context);
333
632
  this.populateActivePriceLists$();
334
633
  }), map(() => noop()), take(1));
335
634
  }
635
+ finalizeInit() {
636
+ this.initializeModifiedAssetsMap();
637
+ this.isInitialized = true;
638
+ this.hasUnsavedChanges = false;
639
+ }
336
640
  setCurrentLineItemState(lineItems) {
337
641
  const quoteDraft = this.quoteSubj$.value;
338
642
  if (!quoteDraft) {
@@ -492,252 +796,619 @@ class QuoteDraftService {
492
796
  this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote?.currentState);
493
797
  }
494
798
  }
799
+ initializeModifiedAssetsMap() {
800
+ this.integrationState.patchState({
801
+ modifiedAssets: generateModifiedAssetsMap(this.currentState),
802
+ });
803
+ }
495
804
  }
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' });
805
+ QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }, { token: IntegrationState }], target: i0.ɵɵFactoryTarget.Injectable });
806
+ QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService });
498
807
  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 }]; } });
808
+ type: Injectable
809
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }, { type: IntegrationState }]; } });
502
810
 
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));
811
+ class FlowStateService {
812
+ constructor(contextService, quoteDraftService, flowInfoService, flowConfiguration, processorsApiService, flowStateApiService, quoteApiService, toastService, customizationService) {
813
+ this.contextService = contextService;
814
+ this.quoteDraftService = quoteDraftService;
815
+ this.flowInfoService = flowInfoService;
816
+ this.flowConfiguration = flowConfiguration;
817
+ this.processorsApiService = processorsApiService;
818
+ this.flowStateApiService = flowStateApiService;
819
+ this.quoteApiService = quoteApiService;
820
+ this.toastService = toastService;
821
+ this.customizationService = customizationService;
822
+ this.NOT_INITIALIZED = Symbol();
823
+ this.EXECUTION_BUFFER_TIME = 100;
824
+ this.executedFunctions = {};
825
+ this.stateId$ = new BehaviorSubject(null);
826
+ this._hasStatefulUnsavedChanges = true;
827
+ this.processors = {};
828
+ this.subscriptions = {};
829
+ this.flowStore = {};
830
+ this.statefulExecutionInProgress$ = new BehaviorSubject(false);
831
+ this.statefulRequestStream$ = new Subject();
832
+ this.cleanup$ = new Subject();
833
+ this.statefulExecutionRequest$ = this.initBufferedRequest$();
834
+ /*
835
+ In stateless mode watch QuoteDraft changes and call executeRequest so that
836
+ all subscriptions get their updates according to updated QuoteDraft
837
+ */
838
+ this.isInitialized$()
839
+ .pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.flowConfiguration.updated$), switchMap(() => this.executeRequest$({}, true)))
840
+ .subscribe();
841
+ this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
842
+ if (!flow.properties.stateful) {
843
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.charges));
844
+ }
845
+ else {
846
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'CHARGES', null, {
847
+ cold: true,
848
+ }).pipe(map$1(response => (response.success ? response.result : {})));
849
+ }
850
+ }), filter$1(isDefined), shareReplay$1());
851
+ this.charges$.subscribe();
852
+ this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
853
+ if (!flow.properties.stateful) {
854
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.pricePlans));
855
+ }
856
+ else {
857
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'PRICE_PLANS', null, {
858
+ cold: true,
859
+ }).pipe(map$1(response => (response.success ? response.result : {})));
860
+ }
861
+ }), filter$1(isDefined), shareReplay$1());
862
+ this.pricePlans$.subscribe();
863
+ this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
864
+ if (!flow.properties.stateful) {
865
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.activeMetrics));
866
+ }
867
+ else {
868
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'ACTIVE_METRICS', null, {
869
+ cold: true,
870
+ }).pipe(map$1(response => (response.success ? response.result : [])));
871
+ }
872
+ }), filter$1(isDefined), shareReplay$1());
873
+ this.activeMetrics$.subscribe();
514
874
  }
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;
875
+ init$() {
876
+ return this.initProcessors$().pipe(switchMap(() => {
877
+ if (this.getFlowSafe().properties.stateful) {
878
+ return this.initStateful$();
536
879
  }
537
- else if (li.lineItems.length) {
538
- return removeLineItem(li, idToRemove);
880
+ else {
881
+ return this.initStateless$();
882
+ }
883
+ }));
884
+ }
885
+ cleanup() {
886
+ Object.values(this.subscriptions).forEach(({ data$ }) => data$.complete());
887
+ this.subscriptions = {};
888
+ if (this.stateId$.value) {
889
+ this.flowStateApiService.cancel(this.stateId$.value).subscribe();
890
+ this.stateId$.next(null);
891
+ }
892
+ this.processors = {};
893
+ this.flowStore = {};
894
+ this.cleanup$.next();
895
+ }
896
+ get hasUnsavedChanges() {
897
+ return this.getFlowSafe().properties.stateful
898
+ ? this._hasStatefulUnsavedChanges
899
+ : this.quoteDraftService.hasUnsavedChanges;
900
+ }
901
+ get stateId() {
902
+ return this.stateId$.value;
903
+ }
904
+ get isExecutionInProgress$() {
905
+ return this.statefulExecutionInProgress$.asObservable();
906
+ }
907
+ isInitialized$() {
908
+ return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
909
+ }
910
+ isInitialized() {
911
+ return Boolean(this.stateId$.value) || this.quoteDraftService.isInitialized;
912
+ }
913
+ execute$(scope, exec) {
914
+ const request = this.execToRequest(scope, exec);
915
+ return this.executeRequest$(request).pipe(map$1(result => {
916
+ // Keep only requested results
917
+ const actualSelectors = Object.entries(result.selectors).reduce((trunk, [requestId, result]) => {
918
+ if (exec.selectors?.[requestId]) {
919
+ trunk[requestId] = result;
920
+ }
921
+ return trunk;
922
+ }, {});
923
+ return actualSelectors;
924
+ }));
925
+ }
926
+ dispatch$(scope, action, inputData) {
927
+ const exec = {
928
+ actions: [{ name: action, inputData }],
929
+ };
930
+ const request = this.execToRequest(scope, exec);
931
+ return this.executeRequest$(request).pipe(map$1(noop));
932
+ }
933
+ select$(scope, selectorName, inputData) {
934
+ const requestId = this.generateRequestId(scope, selectorName, inputData);
935
+ const request = this.execToRequest(scope, {
936
+ selectors: {
937
+ [requestId]: {
938
+ name: selectorName,
939
+ inputData,
940
+ },
941
+ },
942
+ });
943
+ return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
944
+ }
945
+ subscribe$(scope, selectorName, inputData, options) {
946
+ const requestId = this.generateRequestId(scope, selectorName, inputData);
947
+ let subscription = this.subscriptions[requestId];
948
+ if (!subscription) {
949
+ const request = this.execToRequest(scope, {
950
+ selectors: {
951
+ [requestId]: {
952
+ name: selectorName,
953
+ inputData,
954
+ },
955
+ },
956
+ });
957
+ subscription = {
958
+ request,
959
+ data$: new BehaviorSubject(this.NOT_INITIALIZED),
960
+ };
961
+ this.subscriptions[requestId] = subscription;
962
+ if (!options?.cold) {
963
+ this.executeRequest$(request).subscribe();
964
+ }
965
+ }
966
+ return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
967
+ if (!this.subscriptions[requestId]?.data$.observed) {
968
+ delete this.subscriptions[requestId];
969
+ }
970
+ }));
971
+ }
972
+ save$() {
973
+ if (this.getFlowSafe().properties.stateful) {
974
+ if (this.stateId$.value) {
975
+ return this.flowStateApiService.save(this.stateId$.value);
539
976
  }
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
977
  }
550
978
  else {
551
- return { ...replaceTo };
979
+ const quoteDraft = this.quoteDraftService.quoteDraftForActivePriceList;
980
+ if (quoteDraft) {
981
+ return this.quoteApiService.upsertQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
982
+ this.contextService.update({ properties: { ConfigurationId: configurationId } });
983
+ }));
984
+ }
552
985
  }
986
+ return of({ quoteId: '' });
553
987
  }
554
- return {
555
- ...lineItem,
556
- lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo, skipCardinalityCalculation)),
557
- };
558
- };
559
- const calculateCardinalityVariables = (lineItems) => {
560
- const cardVars = new Map();
561
- lineItems
562
- .filter(({ port, type }) => !!port && !!type)
563
- .forEach(li => {
564
- const cardinalityVariableName = `#CV-${li.type}@${li.port}`;
565
- cardVars.set(cardinalityVariableName, (cardVars.get(cardinalityVariableName) ?? 0) + li.qty);
566
- });
567
- return cardVars;
568
- };
569
- const recalculateCardinalityVariables = (original, updated) => {
570
- const cardinalityVariables = calculateCardinalityVariables(updated.lineItems);
571
- const originalCardinalityVariables = calculateCardinalityVariables(original.lineItems);
572
- originalCardinalityVariables.forEach((value, key) => {
573
- if (cardinalityVariables.get(key) === value) {
574
- // no need to update cardinality if no changes
575
- cardinalityVariables.delete(key);
988
+ submit$() {
989
+ if (this.getFlowSafe().properties.stateful) {
990
+ if (this.stateId$.value) {
991
+ return this.flowStateApiService.submit(this.stateId$.value);
992
+ }
576
993
  }
577
- else if (!cardinalityVariables.has(key)) {
578
- // remove last item from port
579
- cardinalityVariables.set(key, 0);
994
+ else {
995
+ const quoteDraft = this.quoteDraftService.quoteDraftForActivePriceList;
996
+ if (quoteDraft) {
997
+ return this.quoteApiService.submitQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
998
+ this.contextService.update({ properties: { ConfigurationId: configurationId } });
999
+ }));
1000
+ }
580
1001
  }
581
- });
582
- return {
583
- ...updated,
584
- attributes: upsertAttributes(updated.attributes, [...cardinalityVariables].map(([name, value]) => ({ name, value, cfgStatus: 'Changed' }))),
585
- };
586
- };
587
- const mapAttributes = (attributes) => {
588
- return attributes.reduce((acc, { name, value }) => ({ ...acc, [name]: value }), {});
589
- };
590
- const getAttributes = (attributes, names = []) => {
591
- const filtered = attributes.filter(({ name }) => names.includes(name));
592
- return sortBy(filtered, [({ name }) => names.indexOf(name)]);
593
- };
594
- const upsertAttributes = (originalAttributes, attributesToUpsert) => {
595
- return attributesToUpsert.reduce((acc, { name, value }) => {
596
- const [origAttr] = getAttributes(acc, [name]);
597
- return [
598
- ...acc.filter(attr => attr.name !== name),
599
- { ...(origAttr ?? { name }), cfgStatus: origAttr ? 'Changed' : 'User', value },
600
- ];
601
- }, originalAttributes);
602
- };
603
- const patchAttributes = (rootLineItem, id, attrs, skipCardinalityCalculation = false) => {
604
- const lineItem = findLineItem(id, [rootLineItem]);
605
- if (!lineItem) {
606
- return rootLineItem;
1002
+ return of({ quoteId: '' });
607
1003
  }
608
- const attributes = upsertAttributes(lineItem.attributes, attrs);
609
- return replaceLineItem(rootLineItem, { ...lineItem, attributes }, skipCardinalityCalculation);
610
- };
611
- const getAttributeValue = (attributes, name) => attributes.find(attr => attr.name === name)?.value;
612
- const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
613
- return {
614
- id: UUID.UUID(),
615
- port,
616
- type,
617
- actionCode: 'ADD',
618
- cfgStatus: 'New',
619
- attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
620
- lineItems,
621
- parentId,
622
- qty: 1,
623
- };
624
- };
625
- const getRecommendedPrices = (portDomain, type) => {
626
- const domainType = portDomain.domainTypes.find(({ name }) => name === type);
627
- const [net, list] = domainType?.recommendedPrices
628
- ?.filter(({ chargeMethod }) => chargeMethod === 'ONE_TIME')
629
- .reduce((acc, rp) => {
630
- const [netPrice, listPrice] = acc;
631
- return [netPrice + rp.netPrice, listPrice + rp.listPrice];
632
- }, [0, 0]) ?? [0, 0];
633
- return { net, list };
634
- };
635
- const generateModifiedAssetsMap = (lineItems) => {
636
- return lineItems.reduce((acc, li) => {
637
- const isModified = isLineItemModified(li);
638
- if (!isModified) {
639
- return acc;
1004
+ getFlowStore() {
1005
+ return this.flowStore;
1006
+ }
1007
+ getOwnerIdByScope(scope) {
1008
+ const ownerId = this.flowInfoService.templates[scope]?.id;
1009
+ if (!ownerId) {
1010
+ throw `OwnerId is not found for scope ${scope}`;
640
1011
  }
641
- const target = getOriginParent(lineItems, li);
642
- const id = target?.assetId ?? target?.openOrderLineItemId;
643
- if (id) {
644
- acc[id] = true;
1012
+ return ownerId;
1013
+ }
1014
+ getScopeByOwnerId(id) {
1015
+ for (const template of Object.values(this.flowInfoService.templates)) {
1016
+ if (template.id === id) {
1017
+ return template.type;
1018
+ }
645
1019
  }
646
- return acc;
647
- }, {});
648
- };
649
- const getOriginParent = (lineItems, currentLineItem) => {
650
- let target = currentLineItem;
651
- while (target && target.rampInstanceId) {
652
- target = lineItems.find(sub => sub.id === currentLineItem.rampInstanceId);
1020
+ return;
653
1021
  }
654
- return target;
655
- };
656
- const isLineItemModified = (lineItem) => {
657
- if (lineItem.actionCode === 'EXIST' && lineItem.status === 'PENDING') {
658
- return false;
1022
+ execToRequest(scope, exec) {
1023
+ const ownerId = this.getOwnerIdByScope(scope);
1024
+ return {
1025
+ actions: exec.actions?.map(action => ({ apiName: action.name, ownerId, inputData: action.inputData ?? {} })),
1026
+ selectors: exec.selectors &&
1027
+ Object.entries(exec.selectors).reduce((trunk, [key, selector]) => ({
1028
+ ...trunk,
1029
+ [key]: { apiName: selector.name, ownerId, inputData: selector.inputData ?? {} },
1030
+ }), {}),
1031
+ };
659
1032
  }
660
- return lineItem.actionCode !== 'EXIST';
661
- };
662
- const multiplyLineItems = (lineItem, qty, split) => {
663
- if (split) {
664
- const unifyIds = (lineItem) => ({
665
- ...lineItem,
666
- id: UUID.UUID(),
667
- lineItems: lineItem.lineItems.map(unifyIds),
1033
+ executeRequest$(request, forceSubscriptions = false) {
1034
+ const fullRequest = cloneDeep(request);
1035
+ if (fullRequest.actions?.length || forceSubscriptions) {
1036
+ for (const subscription of Object.values(this.subscriptions)) {
1037
+ fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
1038
+ }
1039
+ }
1040
+ const execution$ = this.getFlowSafe().properties.stateful
1041
+ ? this.executeStateful$(fullRequest)
1042
+ : this.executeStateless$(fullRequest);
1043
+ return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
1044
+ }
1045
+ handleSelectorsResponse(selectors) {
1046
+ Object.entries(selectors).forEach(([requestId, selectorResult]) => {
1047
+ if (!selectorResult.success) {
1048
+ this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
1049
+ }
1050
+ const subscription$ = this.subscriptions[requestId]?.data$;
1051
+ if (subscription$ && subscription$.value !== selectorResult) {
1052
+ subscription$.next(selectorResult);
1053
+ }
668
1054
  });
669
- return map$1(new Array(qty), () => unifyIds(lineItem));
670
1055
  }
671
- else {
672
- return [
673
- {
674
- ...lineItem,
675
- qty: qty,
676
- },
677
- ];
1056
+ initStateful$() {
1057
+ // Subscriptions
1058
+ this.subscribe$(UITemplateType.FLOW_ENGINE, 'CONTEXT', null, { cold: true })
1059
+ .pipe(tap$1(response => {
1060
+ if (response.success) {
1061
+ this.contextService.update(response.result);
1062
+ }
1063
+ }), takeUntil(this.cleanup$))
1064
+ .subscribe();
1065
+ const processorsList = flatten(Object.values(this.processors).map(ownerMap => Object.values(ownerMap ?? {})));
1066
+ const processors = processorsList.length ? processorsList : undefined;
1067
+ const selectors = Object.values(this.subscriptions)
1068
+ .map(({ request }) => request.selectors)
1069
+ .filter(isDefined)
1070
+ .reduce((trunk, selectors) => ({ ...trunk, ...selectors }), {});
1071
+ const request = this.getDefaultExecutionRequestDTO();
1072
+ return this.flowStateApiService
1073
+ .init({
1074
+ quoteId: this.contextService.resolve().headerId,
1075
+ params: this.flowInfoService.params ?? {},
1076
+ actionsOverride: processors?.filter(processor => processor.type === ConfigurationProcessorTypes.ACTION),
1077
+ selectorsOverride: processors?.filter(processor => processor.type === ConfigurationProcessorTypes.SELECTOR),
1078
+ selectors: { ...selectors, ...request.selectors },
1079
+ actions: request.actions,
1080
+ })
1081
+ .pipe(map$1(({ stateId, selectors }) => {
1082
+ this.handleSelectorsResponse(selectors);
1083
+ this.stateId$.next(stateId);
1084
+ }));
678
1085
  }
679
- };
680
- const isTechnicalAttribute = (name) => {
681
- return name.startsWith('#') || name.startsWith('$');
682
- };
683
- const filterOutTechnicalAttributes = (attributes) => {
684
- return attributes.filter(({ name }) => !isTechnicalAttribute(name));
685
- };
686
-
687
- var lineItem_utils = /*#__PURE__*/Object.freeze({
688
- __proto__: null,
689
- calculateCardinalityVariables: calculateCardinalityVariables,
690
- filterOutTechnicalAttributes: filterOutTechnicalAttributes,
691
- findLineItem: findLineItem,
692
- findLineItemWithComparator: findLineItemWithComparator,
693
- generateLineItem: generateLineItem,
694
- generateModifiedAssetsMap: generateModifiedAssetsMap,
695
- getAttributeValue: getAttributeValue,
696
- getAttributes: getAttributes,
697
- getOriginParent: getOriginParent,
698
- getRecommendedPrices: getRecommendedPrices,
699
- insertLineItem: insertLineItem,
700
- isLineItemModified: isLineItemModified,
701
- isTechnicalAttribute: isTechnicalAttribute,
702
- mapAttributes: mapAttributes,
703
- multiplyLineItems: multiplyLineItems,
704
- patchAttributes: patchAttributes,
705
- recalculateCardinalityVariables: recalculateCardinalityVariables,
706
- removeLineItem: removeLineItem,
707
- replaceLineItem: replaceLineItem,
708
- upsertAttributes: upsertAttributes
709
- });
1086
+ initBufferedRequest$() {
1087
+ return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap(requests => {
1088
+ if (!this.stateId$.value) {
1089
+ throw 'Stateful session is not initialized';
1090
+ }
1091
+ // merge buffered requests
1092
+ const request = {
1093
+ actions: requests.flatMap(({ actions }) => actions).filter(isDefined),
1094
+ selectors: requests
1095
+ .map(({ selectors }) => selectors)
1096
+ .filter(isDefined)
1097
+ .reduce((acc, selectorsMap) => Object.assign(acc, selectorsMap), {}),
1098
+ };
1099
+ this.statefulExecutionInProgress$.next(true);
1100
+ return this.flowStateApiService.execute(this.stateId$.value, request);
1101
+ }), tap$1(({ stateId }) => this.stateId$.next(stateId)), share(), tap$1(() => this.statefulExecutionInProgress$.next(false)), catchError(e => {
1102
+ this.statefulExecutionInProgress$.next(false);
1103
+ return throwError(() => e);
1104
+ }));
1105
+ }
1106
+ executeStateful$(request) {
1107
+ return this.statefulExecutionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
1108
+ // make sure stream switches to statefulExecutionRequest$ before pushing an execution request
1109
+ combineLatest([
1110
+ this.statefulExecutionRequest$,
1111
+ of(undefined).pipe(tap$1(() => this.statefulRequestStream$.next(request))),
1112
+ ])), map$1(([response]) => response), take$1(1));
1113
+ }
1114
+ initStateless$() {
1115
+ const { headerId } = this.contextService.resolve();
1116
+ return this.quoteDraftService.init(headerId, this.flowInfoService.params ?? {}).pipe(switchMap(() => this.executeRequest$(this.getDefaultExecutionRequestDTO())), switchMap(() => this.calculate$()), tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
1117
+ }
1118
+ calculate$() {
1119
+ const flowState = this.quoteDraftService.quoteDraft;
1120
+ if (!flowState) {
1121
+ return of(undefined);
1122
+ }
1123
+ /*
1124
+ Don't execute procedures when:
1125
+ * Initializing a standalone product configuration UI, as procedure is execute in /price call
1126
+ * Initializing an empty account (account with no assets)
1127
+ */
1128
+ const isEmptyAccountMode = this.contextService.mode === ConfigurationContextMode.ACCOUNT &&
1129
+ !this.quoteDraftService.hasProducts &&
1130
+ !this.quoteDraftService.hasAssets &&
1131
+ !this.quoteDraftService.quoteDraft?.initialState.length;
1132
+ if (this.quoteDraftService.isStandalone || isEmptyAccountMode) {
1133
+ return of(undefined);
1134
+ }
1135
+ return this.flowConfiguration.calculate$(flowState);
1136
+ }
1137
+ executeStateless$(request) {
1138
+ return of(undefined).pipe(tap$1(() => this.executeStatelessActions(request)), switchMap(() => {
1139
+ /*
1140
+ Skip price calculation in case
1141
+ 1. No actions in the request
1142
+ 2. Initialization process execution (state not initialized yet)
1143
+ */
1144
+ if (!request.actions?.length || !this.isInitialized()) {
1145
+ return of(undefined);
1146
+ }
1147
+ else {
1148
+ return this.calculate$();
1149
+ }
1150
+ }), map$1(() => this.executeStatelessSelectors(request)));
1151
+ }
1152
+ executeStatelessActions(request) {
1153
+ if (!this.quoteDraftService.quoteDraft || !request.actions?.length) {
1154
+ return;
1155
+ }
1156
+ let flowState = this.quoteDraftService.quoteDraft;
1157
+ request.actions.forEach(action => {
1158
+ try {
1159
+ flowState = this.executeActionScript(flowState, action) ?? flowState;
1160
+ }
1161
+ catch (e) {
1162
+ console.error(e);
1163
+ this.toastService.add({ severity: ToastType.error, summary: String(e) });
1164
+ throw e;
1165
+ }
1166
+ });
1167
+ this.quoteDraftService.updateQuoteDraft(flowState);
1168
+ }
1169
+ executeStatelessSelectors(request) {
1170
+ if (!this.quoteDraftService.quoteDraft) {
1171
+ throw 'QuoteDraft is not initialized';
1172
+ }
1173
+ const flowState = this.quoteDraftService.quoteDraft;
1174
+ return EntityUtil.entries(request.selectors ?? {}).reduce((result, [key, selector]) => {
1175
+ try {
1176
+ result.selectors[key] = {
1177
+ success: true,
1178
+ result: this.executeSelectorScript(flowState, selector),
1179
+ };
1180
+ }
1181
+ catch (e) {
1182
+ console.error(e);
1183
+ result.selectors[key] = {
1184
+ success: false,
1185
+ errorMessage: String(e),
1186
+ };
1187
+ }
1188
+ return result;
1189
+ }, { stateId: '', selectors: {} });
1190
+ }
1191
+ getFlowSafe() {
1192
+ if (!this.flowInfoService.flow) {
1193
+ throw 'Flow is not defined';
1194
+ }
1195
+ return this.flowInfoService.flow;
1196
+ }
1197
+ initProcessors$() {
1198
+ const hasOverrides = Boolean(this.customizationService?.getTemplateConfigurationProcessors);
1199
+ const flow = this.getFlowSafe();
1200
+ if (flow.properties.stateful && !hasOverrides) {
1201
+ // Skip initialization as backend will take processors from SF
1202
+ return of(undefined);
1203
+ }
1204
+ const owners$ = Object.values(this.flowInfoService.templates)
1205
+ .map(template => {
1206
+ if (!template) {
1207
+ return;
1208
+ }
1209
+ const localProcessors$ = this.customizationService?.getTemplateConfigurationProcessors?.(template.name) ?? of(null);
1210
+ return localProcessors$.pipe(switchMap(processors => processors ? of(processors) : this.processorsApiService.fetchConfigurationProcessors$(template.id)), tap$1(processors => {
1211
+ const processorsMap = processors.reduce((acc, p) => {
1212
+ acc[p.apiName] = p;
1213
+ return acc;
1214
+ }, {});
1215
+ this.processors[template.id] = processorsMap;
1216
+ }));
1217
+ })
1218
+ .filter(isDefined);
1219
+ if (!owners$.length) {
1220
+ return of(undefined);
1221
+ }
1222
+ return forkJoin(owners$).pipe(map$1(noop));
1223
+ }
1224
+ executeActionScript(request, executable) {
1225
+ const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
1226
+ if (!configurationProcessor?.script) {
1227
+ const scope = this.getScopeByOwnerId(executable.ownerId);
1228
+ const scopeText = scope ? ` in ${scope}` : '';
1229
+ throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1230
+ }
1231
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1232
+ }
1233
+ executeSelectorScript(request, executable) {
1234
+ const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
1235
+ if (!configurationProcessor?.script) {
1236
+ const scope = this.getScopeByOwnerId(executable.ownerId);
1237
+ const scopeText = scope ? ` in ${scope}` : '';
1238
+ throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1239
+ }
1240
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1241
+ }
1242
+ executeProcessorScript(request, configurationProcessor, inputData) {
1243
+ const scope = this.getScopeByOwnerId(configurationProcessor.ownerId ?? '');
1244
+ let functionToExecute = this.executedFunctions[scope + configurationProcessor.apiName];
1245
+ if (!functionToExecute) {
1246
+ const script = `${configurationProcessor.script}\nreturn transform;`;
1247
+ const sourceMap = `\n//# sourceURL=${scope ? scope + '/' : ''}${configurationProcessor.apiName}.js`;
1248
+ functionToExecute = new Function(script + sourceMap)();
1249
+ this.executedFunctions[scope + configurationProcessor.apiName] = functionToExecute;
1250
+ }
1251
+ return functionToExecute({
1252
+ request,
1253
+ inputData,
1254
+ flowStore: this.flowStore,
1255
+ });
1256
+ }
1257
+ generateRequestId(scope, selectorName, inputData) {
1258
+ const inputDataHash = UUID.hex(JSON.stringify(inputData) || '').slice(0, 8);
1259
+ return `${scope}/${selectorName}/${inputDataHash}`;
1260
+ }
1261
+ getDefaultExecutionRequestDTO() {
1262
+ const request = {
1263
+ actions: [],
1264
+ selectors: {},
1265
+ };
1266
+ if (this.getFlowSafe().properties.standalone) {
1267
+ return request;
1268
+ }
1269
+ const ownerId = this.getOwnerIdByScope(UITemplateType.FLOW_ENGINE);
1270
+ request.actions?.push({
1271
+ apiName: 'UPDATE_PRICE_LIST',
1272
+ ownerId,
1273
+ inputData: {},
1274
+ });
1275
+ request.actions?.push({
1276
+ apiName: 'UPDATE_ASSET_IDS',
1277
+ ownerId,
1278
+ inputData: {},
1279
+ });
1280
+ request.actions?.push({
1281
+ apiName: 'UPDATE_CONTEXT_PROPERTIES',
1282
+ ownerId,
1283
+ inputData: this.contextService.resolve().properties,
1284
+ });
1285
+ return request;
1286
+ }
1287
+ }
1288
+ 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 });
1289
+ FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService });
1290
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, decorators: [{
1291
+ type: Injectable
1292
+ }], 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: [{
1293
+ type: Optional
1294
+ }, {
1295
+ type: Inject,
1296
+ args: [FLOW_CUSTOMIZATION]
1297
+ }] }]; } });
710
1298
 
711
- class LineItemWorker {
712
- constructor(src) {
713
- this.li = { ...src };
1299
+ class RuntimeSettingsService {
1300
+ constructor(configurationSettingsApiService) {
1301
+ this.configurationSettingsApiService = configurationSettingsApiService;
1302
+ this.configurationSettings$ = new BehaviorSubject({});
1303
+ this.currencySettings$ = new BehaviorSubject({
1304
+ iso: DEFAULT_CURRENCY_ISO_CODE,
1305
+ symbol: DEFAULT_CURRENCY_SYMBOL,
1306
+ });
1307
+ this.shoppingCartSettings$ = new BehaviorSubject([]);
1308
+ this.getCurrencySymbol = (locale, currency) => {
1309
+ return (0)
1310
+ .toLocaleString(locale, { style: 'currency', currency, minimumFractionDigits: 0, maximumFractionDigits: 0 })
1311
+ .replace(/\d/g, '')
1312
+ .trim();
1313
+ };
714
1314
  }
715
- insert(parentId, toInsert) {
716
- return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
1315
+ create() {
1316
+ return this.configurationSettingsApiService.fetchSettings().pipe(map$1(settings => this.parseConfigurationSettings(settings)), tap$1(configurationSettings => {
1317
+ this.configurationSettings$.next(configurationSettings);
1318
+ this.addShoppingCartSettings(configurationSettings['shopping-cart'] ?? []);
1319
+ this.formattingSettings = this.getFormattingSettings();
1320
+ }), map$1(() => undefined));
717
1321
  }
718
- remove(id) {
719
- return new LineItemWorker(removeLineItem(this.li, id));
1322
+ initCurrency(iso) {
1323
+ if (iso) {
1324
+ const symbol = this.getCurrencySymbol('en-US', iso);
1325
+ this.currencySettings$.next({ iso, symbol });
1326
+ }
720
1327
  }
721
- replace(toReplace, skipCardinalityCalculation = false) {
722
- return new LineItemWorker(replaceLineItem(this.li, toReplace, skipCardinalityCalculation));
1328
+ getFormattingSettings() {
1329
+ if (this.formattingSettings) {
1330
+ return this.formattingSettings;
1331
+ }
1332
+ const shoppingCartSettings = this.getConfigurationSettings()['shopping-cart']?.reduce((acc, setting) => {
1333
+ return { ...acc, [setting.id]: setting.properties };
1334
+ }, {});
1335
+ const currencySettings = this.getCurrencySettings();
1336
+ const dateFormat = (validateDateFormat(shoppingCartSettings?.DATE_FORMAT ?? '') && shoppingCartSettings?.DATE_FORMAT) ||
1337
+ DEFAULT_DATE_FORMAT;
1338
+ const decimalSeparator = shoppingCartSettings?.DECIMAL_SEPARATOR;
1339
+ const thousandsSeparator = shoppingCartSettings?.THOUSANDS_SEPARATOR;
1340
+ // the number of decimal places can be 0
1341
+ const priceScale = shoppingCartSettings?.PRICE_SCALE;
1342
+ const decimalsCount = priceScale !== null && priceScale !== '' && !isNaN(Number(priceScale)) && Number(priceScale) >= 0
1343
+ ? Number(priceScale)
1344
+ : DEFAULT_DECIMALS_COUNT;
1345
+ const actionCodeSettings = shoppingCartSettings?.STATUS_LABEL;
1346
+ return {
1347
+ currencySymbol: currencySettings.symbol,
1348
+ dateFormats: getSupportedDateFormats(dateFormat),
1349
+ decimalsCount,
1350
+ decimalSeparator: decimalSeparator !== undefined && ['.', ','].includes(decimalSeparator)
1351
+ ? decimalSeparator
1352
+ : DEFAULT_DECIMAL_SEPARATOR,
1353
+ // thousands separator can be a blank value, so it can also be null
1354
+ thousandsSeparator: thousandsSeparator !== undefined && ['.', ',', '', null].includes(thousandsSeparator)
1355
+ ? thousandsSeparator || ''
1356
+ : DEFAULT_THOUSANDS_SEPARATOR,
1357
+ actionCodeLabels: actionCodeSettings?.length
1358
+ ? actionCodeSettings.reduce((result, setting) => ({ ...result, [setting.status_label]: setting.custom_label }), {})
1359
+ : DEFAULT_ACTION_CODE_LABELS,
1360
+ };
723
1361
  }
724
- patchAttribute(attrs, id, skipCardinalityCalculation = false) {
725
- return new LineItemWorker(patchAttributes(this.li, id ?? this.li.id, attrs, skipCardinalityCalculation));
1362
+ getConfigurationSettings() {
1363
+ return this.configurationSettings$.value;
1364
+ }
1365
+ getShoppingCartSettings() {
1366
+ return this.shoppingCartSettings$.value;
1367
+ }
1368
+ getCurrencySettings() {
1369
+ return this.currencySettings$.value;
1370
+ }
1371
+ parseConfigurationSettings(settings) {
1372
+ return settings.reduce((acc, setting) => {
1373
+ switch (setting.key) {
1374
+ case 'shopping-cart':
1375
+ acc['shopping-cart'] = parseJsonSafely(setting.value, []);
1376
+ break;
1377
+ case 'navigation':
1378
+ acc.navigation = parseJsonSafely(setting.value, {});
1379
+ break;
1380
+ case 'flows':
1381
+ acc.flows = parseJsonSafely(setting.value, []);
1382
+ break;
1383
+ default:
1384
+ acc[setting.key] = setting.value;
1385
+ }
1386
+ return acc;
1387
+ }, {});
1388
+ }
1389
+ addShoppingCartSettings(settings) {
1390
+ // uniqBy removes items with the biggest index
1391
+ const newSettings = uniqBy([...settings, ...this.shoppingCartSettings$.value], 'id');
1392
+ this.shoppingCartSettings$.next(newSettings);
726
1393
  }
727
1394
  }
1395
+ RuntimeSettingsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, deps: [{ token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1396
+ RuntimeSettingsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService });
1397
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeSettingsService, decorators: [{
1398
+ type: Injectable
1399
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
728
1400
 
729
1401
  class ConfigurationService {
730
- constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
1402
+ constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService, runtimeSettings) {
731
1403
  this.quoteDraftService = quoteDraftService;
732
1404
  this.runtimeService = runtimeService;
733
1405
  this.contextService = contextService;
734
1406
  this.configurationApiService = configurationApiService;
735
1407
  this.messageService = messageService;
736
1408
  this.dialogService = dialogService;
1409
+ this.runtimeSettings = runtimeSettings;
737
1410
  this.mode = ConfigurationMode.SEARCH;
738
- this.lineItem = new BehaviorSubject(undefined);
739
- this.charges = new BehaviorSubject({});
740
- this.pricePlans = new BehaviorSubject({});
1411
+ this.configurationState = new BehaviorSubject(null);
741
1412
  this.isLoadingSubj$ = new BehaviorSubject(false);
742
1413
  this.isLoading$ = this.isLoadingSubj$.asObservable();
743
1414
  this.hasUnsavedChanges = false;
@@ -746,23 +1417,23 @@ class ConfigurationService {
746
1417
  this.hasUnsavedChanges = false;
747
1418
  this.runtimeService.reset();
748
1419
  this.configurableRamp = undefined;
749
- this.lineItem.next(undefined);
750
- this.charges.next({});
751
- this.pricePlans.next({});
1420
+ this.configurationState.next(null);
752
1421
  }
753
1422
  patch$(lineItem, options) {
754
- if (!this.lineItem.value) {
1423
+ const source = this.getSnapshot();
1424
+ if (!source) {
755
1425
  return throwError(() => new Error(`Source LineItem not found`));
756
1426
  }
757
1427
  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 => {
1428
+ this.configurableRamp = new LineItemWorker(source).replace(lineItem, skipCardinalityCalculation).li;
1429
+ return this.configure().pipe(catchError$1(error => {
760
1430
  console.error(error);
761
1431
  if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
762
1432
  this.messageService.add({ severity: 'error', summary: error });
763
1433
  }
764
1434
  // bounce back if configuration call has failed
765
- this.lineItem.next(this.lineItem.value ? { ...this.lineItem.value } : undefined);
1435
+ const prevState = this.configurationState.value;
1436
+ this.configurationState.next(prevState ? { ...prevState } : null);
766
1437
  return throwError(() => error);
767
1438
  }), tap(() => {
768
1439
  if (!this.hasUnsavedChanges) {
@@ -777,10 +1448,10 @@ class ConfigurationService {
777
1448
  this.configurableRamp = lineItem;
778
1449
  }
779
1450
  get() {
780
- return this.lineItem.asObservable().pipe(shareReplay$1());
1451
+ return this.configurationState.pipe(map(state => state?.lineItem), shareReplay$1());
781
1452
  }
782
1453
  getSnapshot() {
783
- return this.lineItem.value ? { ...this.lineItem.value } : undefined;
1454
+ return this.configurationState.value?.lineItem ? { ...this.configurationState.value?.lineItem } : undefined;
784
1455
  }
785
1456
  getRuntimeModel() {
786
1457
  const runtimeModel = this.runtimeService.runtimeModel;
@@ -796,6 +1467,12 @@ class ConfigurationService {
796
1467
  }
797
1468
  return runtimeContext;
798
1469
  }
1470
+ get state$() {
1471
+ return this.configurationState.asObservable();
1472
+ }
1473
+ get stateSnapshot() {
1474
+ return this.configurationState.value;
1475
+ }
799
1476
  get contextSnapshot() {
800
1477
  return this.contextService.resolve();
801
1478
  }
@@ -803,16 +1480,22 @@ class ConfigurationService {
803
1480
  return this.contextService.resolve$();
804
1481
  }
805
1482
  get charges$() {
806
- return this.charges.asObservable();
1483
+ return this.configurationState.pipe(map(state => state?.charges ?? {}));
807
1484
  }
808
1485
  get chargesSnapshot() {
809
- return this.charges.value;
1486
+ return this.configurationState.value?.charges ?? {};
810
1487
  }
811
1488
  get pricePlans$() {
812
- return this.pricePlans.asObservable();
1489
+ return this.configurationState.pipe(map(state => state?.pricePlans ?? {}));
813
1490
  }
814
1491
  get pricePlansSnapshot() {
815
- return this.pricePlans.value;
1492
+ return this.configurationState.value?.pricePlans ?? {};
1493
+ }
1494
+ get procedureContext$() {
1495
+ return this.configurationState.pipe(map(state => state?.procedureContext ?? {}));
1496
+ }
1497
+ get procedureContextSnapshot() {
1498
+ return this.configurationState.value?.procedureContext ?? {};
816
1499
  }
817
1500
  configure() {
818
1501
  return this.configureRequest$(this.generateRequest());
@@ -823,245 +1506,118 @@ class ConfigurationService {
823
1506
  const uiDefinitionProperties = this.getUIDefinitionProperties();
824
1507
  const mainPricingEnabled = runtimeContext.properties?.PricingEnabled;
825
1508
  const pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
1509
+ const customPriceApi = this.runtimeSettings.getConfigurationSettings()['CUSTOM_PRICE_API'];
826
1510
  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) {
1511
+ const configure$ = pricingEnabled && customPriceApi
1512
+ ? this.configurationApiService.customConfigurePrice({ url: customPriceApi, configurationRequest, runtimeModel })
1513
+ : this.configurationApiService.configureLineItem({
1514
+ configurationRequest,
1515
+ runtimeModel,
1516
+ pricingEnabled,
1517
+ });
1518
+ return configure$.pipe(tap(result => {
1519
+ this.contextService.update(result.context);
1520
+ this.configurationState.next(result);
1521
+ if (result.deletedLineItems?.length) {
835
1522
  this.showInactiveProductsConfirmation();
836
1523
  }
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)));
1524
+ this.configurableRamp = result.lineItem;
1525
+ }), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => new Error(error.error?.message || error.message || JSON.stringify(error)))), finalize$1(() => this.isLoadingSubj$.next(false)));
839
1526
  }
840
1527
  configureExternal$(props) {
841
1528
  return this.runtimeService
842
1529
  .init({ productId: props.productId, defaultQty: props.qty, attributesMap: props.attributesMap })
843
- .pipe(switchMap(() => this.configure()), first(), catchError(error => {
1530
+ .pipe(switchMap$1(() => this.configure()), first(), catchError$1(error => {
844
1531
  this.messageService.add({ severity: ToastType.error, summary: error });
845
1532
  throw error;
846
- }), finalize(() => this.reset()));
1533
+ }), finalize$1(() => this.reset()));
847
1534
  }
848
1535
  configureGuidedSelling$(data) {
849
1536
  return this.configurationApiService
850
1537
  .configureLineItem({
851
- configurationRequest: getGuidedSellingConfigurationRequest(data),
1538
+ configurationRequest: getGuidedSellingConfigurationRequest(data, this.contextService.resolve()),
852
1539
  })
853
- .pipe(catchError(error => {
1540
+ .pipe(catchError$1(error => {
854
1541
  if (error instanceof HttpErrorResponse) {
855
- this.messageService.add({ severity: ToastType.error, summary: error.error.message || error.error });
856
- }
857
- throw error;
858
- }));
859
- }
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
- }
873
- let request = {
874
- lineItem,
875
- mode: this.mode,
876
- step: !this.lineItem.value ? RuntimeStep.START : RuntimeStep.UPDATE,
877
- attributeDomainMode: 'ALL',
878
- context: this.contextService.resolve(),
879
- lineItems: this.quoteDraftService.quoteDraft?.currentState || [],
880
- asset: this.getAsset(),
881
- };
882
- request = ConfigurationTranslatorUtils.lightenConfigurationRequest(request);
883
- return request;
884
- }
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;
917
- 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;
997
- }
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));
1542
+ this.messageService.add({ severity: ToastType.error, summary: error.error.message || error.error });
1543
+ }
1544
+ throw error;
1545
+ }));
1009
1546
  }
1010
- executeStateful$(request) {
1011
- if (!this.stateId) {
1012
- return of(undefined);
1547
+ generateRequest(lightMode = true) {
1548
+ const lineItem = this.generateLineItem();
1549
+ let request = {
1550
+ lineItem,
1551
+ mode: this.mode,
1552
+ step: !this.configurationState.value?.lineItem ? RuntimeStep.START : RuntimeStep.UPDATE,
1553
+ attributeDomainMode: 'ALL',
1554
+ context: this.contextService.resolve(),
1555
+ lineItems: this.quoteDraftService.quoteDraft?.currentState || [],
1556
+ asset: this.getAsset(),
1557
+ };
1558
+ if (lightMode) {
1559
+ request = ConfigurationTranslatorUtils.lightenConfigurationRequest(request);
1013
1560
  }
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));
1561
+ return request;
1028
1562
  }
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;
1563
+ generateLineItem() {
1564
+ const runtimeContext = this.getRuntimeContext();
1565
+ const uiDefinitionProperties = this.getUIDefinitionProperties();
1566
+ let lineItem = cloneDeep(this.configurableRamp);
1567
+ if (!lineItem) {
1568
+ const { initializationProps } = this.runtimeService ?? {};
1569
+ lineItem = getDefaultLineItem(runtimeContext, uiDefinitionProperties, initializationProps?.defaultQty);
1570
+ // Set default attributes
1571
+ if (initializationProps?.attributesMap) {
1572
+ const attributes = transform(initializationProps?.attributesMap, (acc, value, name) => acc.push({ name, value }), []);
1573
+ lineItem = new LineItemWorker(lineItem).patchAttribute(attributes).li;
1574
+ }
1034
1575
  }
1035
- return this.executeProcessorScript(request, script, processor.inputData);
1576
+ return lineItem;
1036
1577
  }
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);
1578
+ getUIDefinitionProperties() {
1579
+ return {
1580
+ ...(this.getRuntimeContext().uiDefinitionContainer?.source.properties ?? {}),
1581
+ ...(this.runtimeService.uiDefinitionProperties ?? {}),
1582
+ };
1044
1583
  }
1045
- executeProcessorScript(request, script, inputData) {
1046
- return new Function(`${script}\nreturn transform;`)()({
1047
- request,
1048
- inputData: inputData,
1584
+ showInactiveProductsConfirmation() {
1585
+ const confirmationConfig = {
1586
+ title: ' ',
1587
+ description: 'This quote contains inactive products. Do you want to remove them?',
1588
+ primaryButtonLabel: 'Remove products',
1589
+ secondaryButtonLabel: 'Back to Quote',
1590
+ };
1591
+ this.dialogService
1592
+ .open(ConfirmationComponent, {
1593
+ dismissableMask: false,
1594
+ closeOnEscape: false,
1595
+ closable: false,
1596
+ showHeader: true,
1597
+ header: `Inactive Products in Quote`,
1598
+ width: '440px',
1599
+ data: { confirmationConfig },
1600
+ })
1601
+ .onClose.subscribe(result => {
1602
+ if (!result) {
1603
+ const context = this.contextService.resolve();
1604
+ window['VELO_BACK_FN'].apply(null, [context.headerId]);
1605
+ }
1049
1606
  });
1050
1607
  }
1608
+ getAsset() {
1609
+ const lineItem = this.configurableRamp;
1610
+ if (!lineItem) {
1611
+ return;
1612
+ }
1613
+ return this.quoteDraftService.quoteDraft?.initialState.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
1614
+ }
1051
1615
  }
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: [{
1616
+ 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 });
1617
+ ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService });
1618
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService, decorators: [{
1055
1619
  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
- }
1620
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6$1.DialogService }, { type: RuntimeSettingsService }]; } });
1065
1621
 
1066
1622
  class FlowUpdateService {
1067
1623
  update(rootLineItems, updates, charges) {
@@ -1202,6 +1758,8 @@ class FlowConfigurationService {
1202
1758
  this.quoteDraftService = quoteDraftService;
1203
1759
  this.updateService = updateService;
1204
1760
  this.configurationService = configurationService;
1761
+ this.updatedSubj$ = new Subject();
1762
+ this.updated$ = this.updatedSubj$.asObservable();
1205
1763
  }
1206
1764
  calculate$(quoteDraft) {
1207
1765
  return this.proceduresApiService.apply$(quoteDraft).pipe(tap$1(result => {
@@ -1211,7 +1769,7 @@ class FlowConfigurationService {
1211
1769
  .slice()
1212
1770
  .sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
1213
1771
  this.quoteDraftService.updateQuoteDraft(result);
1214
- }), map$2(noop));
1772
+ }), map$1(noop));
1215
1773
  }
1216
1774
  calculate(quoteDraft) {
1217
1775
  this.calculate$(quoteDraft).subscribe();
@@ -1221,11 +1779,11 @@ class FlowConfigurationService {
1221
1779
  if (!quoteDraft) {
1222
1780
  return of(null);
1223
1781
  }
1224
- return of([]).pipe(map$2(() => {
1782
+ return of([]).pipe(map$1(() => {
1225
1783
  const updatedState = cloneDeep(quoteDraft.currentState);
1226
1784
  this.updateService.update(updatedState, updates, quoteDraft.charges);
1227
1785
  return updatedState;
1228
- }), switchMap$1(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1786
+ }), switchMap(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1229
1787
  }
1230
1788
  update(updates) {
1231
1789
  this.update$(updates).subscribe();
@@ -1244,7 +1802,7 @@ class FlowConfigurationService {
1244
1802
  updatedState.splice(currentLineItemIndex, 1, initialLineItem);
1245
1803
  return of([]).pipe(tap$1(() => {
1246
1804
  this.quoteDraftService.setCurrentLineItemState(updatedState);
1247
- }), switchMap$1(() => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1805
+ }), switchMap(() => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1248
1806
  }
1249
1807
  revert(lineItemId) {
1250
1808
  this.revert$(lineItemId).subscribe();
@@ -1255,7 +1813,7 @@ class FlowConfigurationService {
1255
1813
  if (!quoteDraft) {
1256
1814
  return of(null);
1257
1815
  }
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());
1816
+ 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
1817
  }
1260
1818
  delete(ids) {
1261
1819
  this.delete$(ids).subscribe();
@@ -1266,34 +1824,34 @@ class FlowConfigurationService {
1266
1824
  return of(null);
1267
1825
  }
1268
1826
  const updatedState = [...quoteDraft.currentState, term];
1269
- return of([]).pipe(switchMap$1(() => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1827
+ return of([]).pipe(switchMap(() => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1270
1828
  }
1271
1829
  addToCart$(props) {
1272
1830
  const quoteDraft = this.quoteDraftService.quoteDraft;
1273
1831
  if (!quoteDraft) {
1274
1832
  return of(null);
1275
1833
  }
1276
- return this.configurationService.configureExternal$(props).pipe(map$2(lineItem => {
1834
+ return this.configurationService.configureExternal$(props).pipe(map$1(lineItem => {
1277
1835
  const model = this.configurationService.getRuntimeModel();
1278
1836
  const split = model?.types.find(type => type.name === lineItem.type)?.split ?? false;
1279
1837
  const lineItems = multiplyLineItems(lineItem, props.qty ?? 1, split);
1280
1838
  return [...quoteDraft.currentState, ...lineItems];
1281
- }), switchMap$1(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1839
+ }), switchMap(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1282
1840
  }
1283
1841
  get() {
1284
- return this.quoteDraftService.quoteDraft$.pipe(map$2(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
1842
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
1285
1843
  }
1286
1844
  getSnapshot() {
1287
1845
  return this.quoteDraftService?.currentState.slice() ?? [];
1288
1846
  }
1289
1847
  get charges$() {
1290
- return this.quoteDraftService.quoteDraft$.pipe(map$2(({ charges }) => charges));
1848
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(({ charges }) => charges));
1291
1849
  }
1292
1850
  get pricePlans$() {
1293
- return this.quoteDraftService.quoteDraft$.pipe(map$2(({ pricePlans }) => pricePlans));
1851
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(({ pricePlans }) => pricePlans));
1294
1852
  }
1295
1853
  get activeMetrics$() {
1296
- return this.quoteDraftService.quoteDraft$.pipe(map$2(({ activeMetrics }) => activeMetrics));
1854
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(({ activeMetrics }) => activeMetrics));
1297
1855
  }
1298
1856
  get chargesSnapshot() {
1299
1857
  return this.quoteDraftService.quoteDraft?.charges ?? {};
@@ -1307,301 +1865,544 @@ class FlowConfigurationService {
1307
1865
  get contextSnapshot() {
1308
1866
  return this.contextService.resolve();
1309
1867
  }
1310
- get context$() {
1311
- return this.contextService.resolve$();
1868
+ get context$() {
1869
+ return this.contextService.resolve$();
1870
+ }
1871
+ handleErrorAndBounceBack() {
1872
+ return (source$) => {
1873
+ return source$.pipe(catchError(error => {
1874
+ console.error(error);
1875
+ // bounce back if configuration call has failed
1876
+ const quoteDraft = this.quoteDraftService.quoteDraft;
1877
+ if (quoteDraft) {
1878
+ this.quoteDraftService.updateQuoteDraft(quoteDraft);
1879
+ this.updatedSubj$.next();
1880
+ }
1881
+ return throwError(() => error);
1882
+ }));
1883
+ };
1884
+ }
1885
+ }
1886
+ 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 });
1887
+ FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService });
1888
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationService, decorators: [{
1889
+ type: Injectable
1890
+ }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1891
+
1892
+ class FlowConfigurationModule {
1893
+ }
1894
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1895
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, imports: [ApiModule] });
1896
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService], imports: [ApiModule] });
1897
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1898
+ type: NgModule,
1899
+ args: [{
1900
+ imports: [ApiModule],
1901
+ providers: [FlowConfigurationService, FlowUpdateService],
1902
+ }]
1903
+ }] });
1904
+
1905
+ class FlowStateConfigurationService {
1906
+ constructor(flowInfoService, flowConfigurationService, flowStateApiService, flowStateService) {
1907
+ this.flowInfoService = flowInfoService;
1908
+ this.flowConfigurationService = flowConfigurationService;
1909
+ this.flowStateApiService = flowStateApiService;
1910
+ this.flowStateService = flowStateService;
1911
+ this.configurationStateId$ = new BehaviorSubject(null);
1912
+ }
1913
+ get configurationStateId() {
1914
+ return this.configurationStateId$.value;
1915
+ }
1916
+ addToCart$(props) {
1917
+ let request$;
1918
+ const stateful = this.flowInfoService.flow?.properties.stateful;
1919
+ if (stateful) {
1920
+ const stateId = this.flowStateService.stateId;
1921
+ if (!stateId) {
1922
+ request$ = of();
1923
+ }
1924
+ else {
1925
+ const lineItem = generateConfigurationLineItem(props, props.qty);
1926
+ request$ = this.flowStateApiService.newConfiguration(stateId, { lineItem }).pipe(tap$1(r => this.configurationStateId$.next(r.stateId)), switchMap(() => {
1927
+ if (!this.configurationStateId) {
1928
+ return of();
1929
+ }
1930
+ return this.flowStateApiService.saveConfiguration(stateId, this.configurationStateId).pipe(tap$1(() => this.configurationStateId$.next(null)), map$1(noop));
1931
+ }));
1932
+ }
1933
+ }
1934
+ else {
1935
+ request$ = this.flowConfigurationService.addToCart$(props).pipe(map$1(noop));
1936
+ }
1937
+ return request$.pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), map$1(noop));
1938
+ }
1939
+ }
1940
+ 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 });
1941
+ FlowStateConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService });
1942
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, decorators: [{
1943
+ type: Injectable
1944
+ }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: FlowConfigurationService }, { type: i1.FlowStateApiService }, { type: FlowStateService }]; } });
1945
+
1946
+ class ProductImagesService {
1947
+ constructor(productApiService) {
1948
+ this.productApiService = productApiService;
1949
+ this.imagesMap$ = new BehaviorSubject({});
1950
+ }
1951
+ getImageUrl$(productId) {
1952
+ if (this.imagesMap$.value[productId] == null) {
1953
+ this.imagesMap$.next({ ...this.imagesMap$.value, [productId]: '' });
1954
+ this.fetchProductImage(productId);
1955
+ }
1956
+ return this.imagesMap$.pipe(map$1(imagesMap => imagesMap[productId] ?? null), distinctUntilChanged());
1957
+ }
1958
+ fetchProductImage(productId) {
1959
+ this.productApiService
1960
+ .fetchImage$(productId)
1961
+ .pipe(map$1(file => URL.createObjectURL(file)), catchError(() => of('')), tap$1(url => this.imagesMap$.next({ ...this.imagesMap$.value, [productId]: url })))
1962
+ .subscribe();
1963
+ }
1964
+ }
1965
+ ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1966
+ ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService });
1967
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductImagesService, decorators: [{
1968
+ type: Injectable
1969
+ }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
1970
+
1971
+ class RuntimeContextService {
1972
+ constructor(configurationApiService) {
1973
+ this.configurationApiService = configurationApiService;
1974
+ }
1975
+ getRuntimeContext(productId, offeringId) {
1976
+ return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(map(runtimeData => {
1977
+ const uiDefinitionContainer = this.getUIDefinitionContainer(runtimeData);
1978
+ const runtimeModel = RuntimeModel.create(runtimeData.types, runtimeData.products);
1979
+ const { productName, properties } = Array.from(runtimeModel.components.values()).find(c => c.productId === productId) ?? {};
1980
+ const uiDefinitionProperties = uiDefinitionContainer?.source.properties;
1981
+ return {
1982
+ modelId: runtimeData.modelId,
1983
+ uiDefinitionContainer: uiDefinitionContainer,
1984
+ runtimeModel: runtimeModel,
1985
+ runtimeMode: RuntimeMode.PROD,
1986
+ productId: productId,
1987
+ productType: properties?.['displayName'] || productName,
1988
+ offeringId: offeringId,
1989
+ properties: {
1990
+ PricingEnabled: uiDefinitionProperties?.pricingEnabled ? 'true' : 'false',
1991
+ PriceListId: uiDefinitionProperties?.priceList,
1992
+ },
1993
+ };
1994
+ }));
1995
+ }
1996
+ getUIDefinitionContainer(runtimeData) {
1997
+ const containers = runtimeData.uiDefinitions.filter(container => isNotLegacyUIDefinition(container.source));
1998
+ return containers.find(container => container.source.primary) ?? containers[0];
1999
+ }
2000
+ }
2001
+ RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
2002
+ RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService });
2003
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService, decorators: [{
2004
+ type: Injectable
2005
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
2006
+
2007
+ class ConfigurationRuntimeService {
2008
+ constructor(apiService, contextService, runtimeContextService) {
2009
+ this.apiService = apiService;
2010
+ this.contextService = contextService;
2011
+ this.runtimeContextService = runtimeContextService;
2012
+ this._isInitialized = false;
2013
+ this.uiDefinitionProperties = {};
2014
+ }
2015
+ reset() {
2016
+ this._isInitialized = false;
2017
+ this._runtimeContext = undefined;
2018
+ this.initializationProps = undefined;
2019
+ this.uiDefinitionProperties = {};
2020
+ }
2021
+ initTestMode(uiDefinitionContainer) {
2022
+ this.uiDefinitionProperties = uiDefinitionContainer.source.properties ?? {};
2023
+ const uiDefinitionExternals = uiDefinitionContainer.source.externals ?? {};
2024
+ return combineLatest([
2025
+ this.apiService.getRuntimeDataByModelId(uiDefinitionContainer.modelId),
2026
+ this.contextService.initTestMode(),
2027
+ ]).pipe(first(), map(([runtimeData, context]) => {
2028
+ this.contextService.update({
2029
+ properties: {
2030
+ ...this.runtimeContext?.properties,
2031
+ ...context.properties,
2032
+ ModelId: uiDefinitionContainer.modelId,
2033
+ PricingEnabled: this.uiDefinitionProperties.pricingEnabled ? 'true' : 'false',
2034
+ PriceListId: this.uiDefinitionProperties.priceList,
2035
+ offeringId: this.uiDefinitionProperties.offeringId,
2036
+ ...uiDefinitionExternals,
2037
+ },
2038
+ });
2039
+ this._runtimeContext = {
2040
+ modelId: uiDefinitionContainer.modelId,
2041
+ runtimeModel: RuntimeModel.create(runtimeData.types, runtimeData.products),
2042
+ runtimeMode: RuntimeMode.TEST,
2043
+ uiDefinitionContainer,
2044
+ };
2045
+ return this._runtimeContext;
2046
+ }), tap(() => (this._isInitialized = true)));
2047
+ }
2048
+ init(props) {
2049
+ this.initializationProps = props;
2050
+ const context = this.contextService.resolve();
2051
+ return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
2052
+ this.uiDefinitionProperties = runtimeContext.uiDefinitionContainer?.source.properties ?? {};
2053
+ const { PriceListId } = context.properties ?? {};
2054
+ const mergeContext = {
2055
+ ...runtimeContext,
2056
+ properties: {
2057
+ ...runtimeContext.properties,
2058
+ ...context.properties,
2059
+ PricingEnabled: PriceListId ? 'true' : 'false',
2060
+ },
2061
+ };
2062
+ this.id15to18('AccountId', mergeContext.properties);
2063
+ this._runtimeContext = mergeContext;
2064
+ if (context.properties && this._runtimeContext.properties?.StartDate) {
2065
+ this.contextService.update({
2066
+ properties: {
2067
+ ...this._runtimeContext.properties,
2068
+ ...context.properties,
2069
+ },
2070
+ });
2071
+ }
2072
+ return this._runtimeContext;
2073
+ }), tap(() => (this._isInitialized = true)));
2074
+ }
2075
+ overrideUIDefinition(uiDefinitionContainer) {
2076
+ if (!this._runtimeContext) {
2077
+ return;
2078
+ }
2079
+ this._runtimeContext.uiDefinitionContainer = uiDefinitionContainer;
2080
+ this.uiDefinitionProperties = uiDefinitionContainer.source.properties ?? {};
2081
+ }
2082
+ id15to18(propertyName, source) {
2083
+ if (!source) {
2084
+ return;
2085
+ }
2086
+ const value = source[propertyName];
2087
+ if (typeof value === 'string' && value.length === 15) {
2088
+ source[propertyName] = SalesforceIdUtils.generateId18FromId15(value);
2089
+ }
2090
+ }
2091
+ get isInitialized() {
2092
+ return this._isInitialized;
1312
2093
  }
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
- };
2094
+ get runtimeModel() {
2095
+ return this.runtimeContext?.runtimeModel;
2096
+ }
2097
+ get runtimeContext() {
2098
+ return this._runtimeContext;
1325
2099
  }
1326
2100
  }
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: [{
2101
+ 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 });
2102
+ ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService });
2103
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
1330
2104
  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
- }] });
2105
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
1374
2106
 
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)]);
2107
+ class ConfigurationStateService {
2108
+ constructor(configurationRuntimeService, configurationService, quoteDraftService, toastService, flowStateService, flowInfoService, flowConfigurationService, flowStateApiService, quoteApiService) {
2109
+ this.configurationRuntimeService = configurationRuntimeService;
2110
+ this.configurationService = configurationService;
2111
+ this.quoteDraftService = quoteDraftService;
2112
+ this.toastService = toastService;
2113
+ this.flowStateService = flowStateService;
2114
+ this.flowInfoService = flowInfoService;
2115
+ this.flowConfigurationService = flowConfigurationService;
2116
+ this.flowStateApiService = flowStateApiService;
2117
+ this.quoteApiService = quoteApiService;
2118
+ this.isInitialized$ = new BehaviorSubject(false);
2119
+ this.canceledConfiguration$ = new Subject();
2120
+ this.NOT_INITIALIZED = Symbol();
2121
+ this.executedFunctions = {};
2122
+ this.stateId = null;
2123
+ this.ownerId = '';
2124
+ this.subscriptions = {};
2125
+ this.configurationStore = {};
2126
+ }
2127
+ init$() {
2128
+ let request$;
2129
+ if (this.flowStateService.stateId && this.isStatefulConfiguration) {
2130
+ request$ = this.initStateful$();
1404
2131
  }
1405
- case 'sum': {
1406
- return lineItems.map(item => [item]);
2132
+ else {
2133
+ request$ = this.initStateless$();
1407
2134
  }
1408
- default: {
1409
- return lineItems.map(item => [item]);
2135
+ return request$.pipe(finalize(() => {
2136
+ this.isInitialized$.next(true);
2137
+ this.canceledConfiguration$ = new Subject();
2138
+ }));
2139
+ }
2140
+ cleanup() {
2141
+ Object.values(this.subscriptions).forEach(({ data$ }) => data$.complete());
2142
+ this.subscriptions = {};
2143
+ if (this.stateId) {
2144
+ this.cancelConfiguration();
1410
2145
  }
2146
+ this.configurationStore = {};
2147
+ this.executedFunctions = {};
2148
+ this.configurationService.reset();
1411
2149
  }
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();
2150
+ execute$(req, forceSubscriptions) {
2151
+ const fullRequest = cloneDeep(req);
2152
+ if (fullRequest.actions?.length || forceSubscriptions) {
2153
+ for (const subscription of Object.values(this.subscriptions)) {
2154
+ fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
2155
+ }
2156
+ }
2157
+ let execution$;
2158
+ if (this.isStatefulConfiguration) {
2159
+ execution$ = this.executeStateful$(fullRequest);
2160
+ }
2161
+ else {
2162
+ execution$ = this.executeStateless$(fullRequest);
2163
+ }
2164
+ return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
1420
2165
  }
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 || '{}');
2166
+ handleSelectorsResponse(selectors) {
2167
+ Object.entries(selectors).forEach(([requestId, selectorResult]) => {
2168
+ if (!selectorResult.success) {
2169
+ this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
1438
2170
  }
1439
- catch (error) {
1440
- settingsData = {};
2171
+ const subscription$ = this.subscriptions[requestId]?.data$;
2172
+ if (subscription$) {
2173
+ subscription$.next(selectorResult);
1441
2174
  }
1442
- this.quoteMetricsSettings = settingsData;
1443
- this.updateMetrics(lineItems);
1444
2175
  });
1445
2176
  }
1446
- getMetricValue(metric) {
1447
- return this.metricsData[metric] || 0;
2177
+ dispatch$(actionName, inputData = {}) {
2178
+ return this.execute$({ actions: [{ apiName: actionName, inputData, ownerId: this.ownerId }] });
1448
2179
  }
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();
1454
- }
1455
- calculateMetric(lineItems, metric) {
1456
- return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
2180
+ select$(selectorName, inputData = {}) {
2181
+ const requestId = UUID.UUID();
2182
+ return this.execute$({
2183
+ selectors: {
2184
+ [requestId]: {
2185
+ apiName: selectorName,
2186
+ inputData,
2187
+ ownerId: this.ownerId,
2188
+ },
2189
+ },
2190
+ }).pipe(map$1(response => response.selectors[requestId]));
1457
2191
  }
1458
- buildMetricsCalculationMethods(metricKeys, initial) {
1459
- return metricKeys.reduce((acc, name) => {
1460
- if (acc[name]) {
1461
- return acc;
2192
+ subscribe$(selectorName, inputData = {}, options) {
2193
+ const requestId = UUID.UUID();
2194
+ let subscription = this.subscriptions[requestId];
2195
+ if (!subscription) {
2196
+ const request = {
2197
+ selectors: {
2198
+ [requestId]: {
2199
+ apiName: selectorName,
2200
+ inputData,
2201
+ ownerId: this.ownerId,
2202
+ },
2203
+ },
2204
+ };
2205
+ subscription = {
2206
+ request,
2207
+ data$: new BehaviorSubject(this.NOT_INITIALIZED),
2208
+ };
2209
+ this.subscriptions[requestId] = subscription;
2210
+ if (!options?.cold) {
2211
+ this.execute$(request).subscribe();
1462
2212
  }
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] };
2213
+ }
2214
+ return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), distinctUntilChanged(), finalize(() => {
2215
+ if (!this.subscriptions[requestId]?.data$.observed) {
2216
+ delete this.subscriptions[requestId];
1468
2217
  }
1469
- return acc;
1470
- }, initial);
2218
+ }), takeUntil(this.canceledConfiguration$));
1471
2219
  }
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);
2220
+ saveConfiguration(quoteId, flow) {
2221
+ if (this.isStatefulConfiguration) {
2222
+ return this.flowStateApiService
2223
+ .saveConfiguration(this.flowStateService.stateId ?? '', this.stateId ?? '')
2224
+ .pipe(switchMap(r => this.flowStateService.executeRequest$({}, true).pipe(map$1(() => r))));
2225
+ }
2226
+ else {
2227
+ if (!flow) {
2228
+ if (!quoteId) {
2229
+ return of({ quoteId: '' });
2230
+ }
2231
+ const rootLineItem = this.configurationService.getSnapshot();
2232
+ const currentState = rootLineItem ? [rootLineItem] : [];
2233
+ return this.quoteApiService
2234
+ .getQuoteDraft(quoteId)
2235
+ .pipe(switchMap(quoteDraft => this.quoteApiService.upsertQuote({ ...quoteDraft, currentState })));
2236
+ }
2237
+ else {
2238
+ const quoteDraft = this.quoteDraftService.quoteDraft;
2239
+ const lineItem = this.configurationService.getSnapshot();
2240
+ if (!quoteDraft || !lineItem) {
2241
+ return of({ quoteId: '' });
2242
+ }
2243
+ const isNewLineItem = quoteDraft.currentState.every(li => li.id !== lineItem.id);
2244
+ let updatedState;
2245
+ if (isNewLineItem) {
2246
+ updatedState = [...quoteDraft.currentState, lineItem];
2247
+ }
2248
+ else {
2249
+ updatedState = quoteDraft.currentState.map(li => (li.id === lineItem.id ? lineItem : li));
2250
+ }
2251
+ return this.flowConfigurationService
2252
+ .calculate$({ ...quoteDraft, currentState: updatedState })
2253
+ .pipe(map$1(() => ({ quoteId: '' })));
2254
+ }
2255
+ }
1479
2256
  }
1480
- getMetricRuleByTotalMetricName(name) {
1481
- return this.activeMetricRules.find(metricRule => metricRule.metrics.find(metric => metric.totalName === name));
2257
+ cancelConfiguration() {
2258
+ if (!this.isInitialized$.value) {
2259
+ return of(undefined);
2260
+ }
2261
+ this.canceledConfiguration$.next();
2262
+ this.canceledConfiguration$.complete();
2263
+ this.subscriptions = {};
2264
+ this.isInitialized$.next(false);
2265
+ if (!this.isInitialized$.value || !this.isStatefulConfiguration) {
2266
+ return of(undefined);
2267
+ }
2268
+ return this.flowStateApiService.cancelConfiguration(this.flowStateService.stateId ?? '', this.stateId ?? '');
1482
2269
  }
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({});
2270
+ get isStatefulConfiguration() {
2271
+ return this.flowInfoService.flow?.properties.stateful ?? false;
1495
2272
  }
1496
- getImageUrl$(productId) {
1497
- if (this.imagesMap$.value[productId] == null) {
1498
- this.imagesMap$.next({ ...this.imagesMap$.value, [productId]: '' });
1499
- this.fetchProductImage(productId);
2273
+ initStateful$() {
2274
+ this.ownerId = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer?.id ?? '';
2275
+ const lineItemId = this.configurationRuntimeService.runtimeContext?.properties?.lineItemId;
2276
+ if (!this.flowStateService.stateId) {
2277
+ return of(undefined);
1500
2278
  }
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();
2279
+ const container = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer;
2280
+ const lineItem = this.configurationService.generateLineItem();
2281
+ let request$;
2282
+ if (!lineItemId) {
2283
+ request$ = this.flowStateApiService.newConfiguration(this.flowStateService.stateId, {
2284
+ lineItem,
2285
+ actionsOverride: container?.actions?.map(processor => ({ ...processor, ownerId: this.ownerId })),
2286
+ selectorsOverride: container?.selectors?.map(processor => ({ ...processor, ownerId: this.ownerId })),
2287
+ });
2288
+ }
2289
+ else {
2290
+ request$ = this.flowStateApiService.startConfiguration(this.flowStateService.stateId, {
2291
+ lineItemId,
2292
+ actionsOverride: container?.actions?.map(processor => ({ ...processor, ownerId: this.ownerId })),
2293
+ selectorsOverride: container?.selectors?.map(processor => ({ ...processor, ownerId: this.ownerId })),
2294
+ });
2295
+ }
2296
+ return request$.pipe(map$1(r => {
2297
+ this.stateId = r.stateId;
2298
+ return undefined;
2299
+ }));
1508
2300
  }
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
- };
2301
+ initStateless$() {
2302
+ return this.configurationService.configure().pipe(map$1(() => undefined));
1531
2303
  }
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));
2304
+ executeStateless$(request) {
2305
+ return of(undefined).pipe(switchMap(() => {
2306
+ // Apply actions and execute configuration/price call
2307
+ // No need to run configuration if no actions in the request
2308
+ if (!request.actions?.length) {
2309
+ return of(undefined);
2310
+ }
2311
+ let configurationRequest = this.configurationService.generateRequest();
2312
+ request.actions.forEach(action => {
2313
+ try {
2314
+ configurationRequest = this.executeActionScript(configurationRequest, action) ?? configurationRequest;
2315
+ }
2316
+ catch (e) {
2317
+ console.error(e);
2318
+ this.toastService.add({ severity: ToastType.error, summary: String(e) });
2319
+ throw e;
2320
+ }
2321
+ });
2322
+ return this.configurationService.configureRequest$(configurationRequest);
2323
+ }), map$1(() => {
2324
+ // Run selectors and apply them to the state
2325
+ const configurationState = cloneDeep(this.configurationService.stateSnapshot);
2326
+ if (!configurationState) {
2327
+ return { stateId: '', selectors: {} };
2328
+ }
2329
+ const selectorsResult = EntityUtil.entries(request.selectors ?? {}).reduce((result, [key, selector]) => {
2330
+ try {
2331
+ result.selectors[key] = {
2332
+ success: true,
2333
+ result: this.executeSelectorScript(configurationState, selector),
2334
+ };
2335
+ }
2336
+ catch (e) {
2337
+ console.error(e);
2338
+ result.selectors[key] = {
2339
+ success: false,
2340
+ errorMessage: String(e),
2341
+ };
2342
+ }
2343
+ return result;
2344
+ }, { stateId: '', selectors: {} });
2345
+ return selectorsResult;
2346
+ }));
1537
2347
  }
1538
- initCurrency(iso) {
1539
- if (iso) {
1540
- const symbol = this.getCurrencySymbol('en-US', iso);
1541
- this.currencySettings$.next({ iso, symbol });
2348
+ executeStateful$(request) {
2349
+ if (!this.flowStateService.stateId || !this.stateId) {
2350
+ return of();
1542
2351
  }
2352
+ return this.flowStateApiService.executeConfiguration(this.flowStateService.stateId, this.stateId, request).pipe(tap$1(response => {
2353
+ this.stateId = response.stateId;
2354
+ }));
1543
2355
  }
1544
- getFormattingSettings() {
1545
- if (this.formattingSettings) {
1546
- return this.formattingSettings;
2356
+ executeActionScript(request, processor) {
2357
+ const { actions } = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer ?? {};
2358
+ const configurationProcessor = actions?.find(action => action.apiName === processor.apiName);
2359
+ if (!configurationProcessor?.script) {
2360
+ throw `ConfigurationProcessor ${processor.apiName} not found`;
1547
2361
  }
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;
2362
+ return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
1579
2363
  }
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
- }, {});
2364
+ executeSelectorScript(request, processor) {
2365
+ const { selectors } = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer ?? {};
2366
+ const configurationProcessor = selectors?.find(selector => selector.apiName === processor.apiName);
2367
+ if (!configurationProcessor?.script) {
2368
+ throw `ConfigurationProcessor ${processor.apiName} not found`;
2369
+ }
2370
+ return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
2371
+ }
2372
+ executeProcessorScript(request, configurationProcessor, inputData) {
2373
+ let functionToExecute = this.executedFunctions[configurationProcessor.apiName];
2374
+ if (!functionToExecute) {
2375
+ const script = `${configurationProcessor.script}\nreturn transform;`;
2376
+ const sourceMap = `\n//# sourceURL=${configurationProcessor.apiName}.js`;
2377
+ functionToExecute = new Function(script + sourceMap)();
2378
+ this.executedFunctions[configurationProcessor.apiName] = functionToExecute;
2379
+ }
2380
+ return functionToExecute({
2381
+ request,
2382
+ inputData,
2383
+ flowStore: this.flowStateService.getFlowStore(),
2384
+ configurationStore: this.configurationStore,
2385
+ });
1597
2386
  }
1598
2387
  }
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 }]; } });
2388
+ 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 });
2389
+ ConfigurationStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService });
2390
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationStateService, decorators: [{
2391
+ type: Injectable
2392
+ }], ctorParameters: function () { return [{ type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: QuoteDraftService }, { type: i6.ToastService }, { type: FlowStateService }, { type: FlowInfoService }, { type: FlowConfigurationService }, { type: i1.FlowStateApiService }, { type: i1.QuoteApiService }]; } });
2393
+
2394
+ class ConfigurationModule {
2395
+ }
2396
+ ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2397
+ ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule, ApiModule] });
2398
+ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, providers: [ConfigurationRuntimeService, RuntimeContextService, ConfigurationService, ConfigurationStateService], imports: [ConfirmationDialogModule, ApiModule] });
2399
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, decorators: [{
2400
+ type: NgModule,
2401
+ args: [{
2402
+ imports: [ConfirmationDialogModule, ApiModule],
2403
+ providers: [ConfigurationRuntimeService, RuntimeContextService, ConfigurationService, ConfigurationStateService],
2404
+ }]
2405
+ }] });
1605
2406
 
1606
2407
  const DEFAULT_FORMATTING_SETTINGS = {
1607
2408
  currencySymbol: DEFAULT_CURRENCY_SYMBOL,
@@ -1609,6 +2410,7 @@ const DEFAULT_FORMATTING_SETTINGS = {
1609
2410
  dateFormats: getSupportedDateFormats(DEFAULT_DATE_FORMAT),
1610
2411
  decimalSeparator: DEFAULT_DECIMAL_SEPARATOR,
1611
2412
  thousandsSeparator: DEFAULT_THOUSANDS_SEPARATOR,
2413
+ actionCodeLabels: DEFAULT_ACTION_CODE_LABELS,
1612
2414
  };
1613
2415
  class SdkCoreModule {
1614
2416
  }
@@ -1616,9 +2418,12 @@ SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
1616
2418
  SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1617
2419
  SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkCoreModule, providers: [
1618
2420
  ContextService,
2421
+ FlowInfoService,
1619
2422
  QuoteDraftService,
1620
2423
  ProductImagesService,
1621
- MetricsCalculationService,
2424
+ IntegrationState,
2425
+ FlowStateService,
2426
+ FlowStateConfigurationService,
1622
2427
  RuntimeSettingsService,
1623
2428
  {
1624
2429
  provide: FORMATTING_SETTINGS_TOKEN,
@@ -1631,9 +2436,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1631
2436
  imports: [ConfigurationModule, FlowConfigurationModule],
1632
2437
  providers: [
1633
2438
  ContextService,
2439
+ FlowInfoService,
1634
2440
  QuoteDraftService,
1635
2441
  ProductImagesService,
1636
- MetricsCalculationService,
2442
+ IntegrationState,
2443
+ FlowStateService,
2444
+ FlowStateConfigurationService,
1637
2445
  RuntimeSettingsService,
1638
2446
  {
1639
2447
  provide: FORMATTING_SETTINGS_TOKEN,
@@ -1701,12 +2509,18 @@ class DatePipe {
1701
2509
  this.destroy$.next();
1702
2510
  this.destroy$.complete();
1703
2511
  }
1704
- transform(date) {
2512
+ transform(date, type = 'date') {
1705
2513
  if (!date) {
1706
2514
  return '';
1707
2515
  }
2516
+ const dateFormat = this.formattingSettings?.dateFormats.datePipeFormat || DEFAULT_DATE_FORMAT;
2517
+ const formatMap = {
2518
+ date: dateFormat,
2519
+ time: DEFAULT_TIME_FORMAT,
2520
+ datetime: `${dateFormat} ${DEFAULT_TIME_FORMAT}`,
2521
+ };
1708
2522
  try {
1709
- return formatDate(date, this.formattingSettings?.dateFormats.datePipeFormat || DEFAULT_DATE_FORMAT, this.locale, this.defaultOptions?.timezone);
2523
+ return formatDate(date, formatMap[type], this.locale, this.defaultOptions?.timezone);
1710
2524
  }
1711
2525
  catch (error) {
1712
2526
  return new Date(date).toString();
@@ -1769,16 +2583,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1769
2583
  }]
1770
2584
  }] });
1771
2585
 
2586
+ class ActionCodePipe {
2587
+ constructor() {
2588
+ this.formattingSettings = inject(FORMATTING_SETTINGS_TOKEN, { optional: true })?.getFormattingSettings();
2589
+ }
2590
+ transform(actionCode) {
2591
+ return this.formattingSettings?.actionCodeLabels[actionCode] ?? actionCode;
2592
+ }
2593
+ }
2594
+ ActionCodePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionCodePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2595
+ ActionCodePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: ActionCodePipe, name: "vlActionCode" });
2596
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ActionCodePipe, decorators: [{
2597
+ type: Pipe,
2598
+ args: [{
2599
+ name: 'vlActionCode',
2600
+ }]
2601
+ }] });
2602
+
1772
2603
  class SdkPipesModule {
1773
2604
  }
1774
2605
  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] });
2606
+ 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
2607
  SdkPipesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkPipesModule });
1777
2608
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SdkPipesModule, decorators: [{
1778
2609
  type: NgModule,
1779
2610
  args: [{
1780
- declarations: [NumberPipe, PricePipe, DatePipe],
1781
- exports: [NumberPipe, PricePipe, DatePipe],
2611
+ declarations: [NumberPipe, PricePipe, DatePipe, ActionCodePipe],
2612
+ exports: [NumberPipe, PricePipe, DatePipe, ActionCodePipe],
1782
2613
  }]
1783
2614
  }] });
1784
2615
 
@@ -1786,5 +2617,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1786
2617
  * Generated bundle index. Do not edit.
1787
2618
  */
1788
2619
 
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 };
2620
+ 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, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateConfigurationLineItem, generateLineItem, generateModifiedAssetsMap, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isLineItemModified, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
1790
2621
  //# sourceMappingURL=veloceapps-sdk-core.mjs.map