@veloceapps/sdk 8.0.0-19 → 8.0.0-191

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