@veloceapps/sdk 6.0.0-9 → 6.0.0-91

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. package/README.md +10 -2
  2. package/bundles/veloceapps-sdk-cms.umd.js +1268 -798
  3. package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
  4. package/bundles/veloceapps-sdk-core.umd.js +821 -713
  5. package/bundles/veloceapps-sdk-core.umd.js.map +1 -1
  6. package/bundles/veloceapps-sdk-runtime.umd.js +216 -150
  7. package/bundles/veloceapps-sdk-runtime.umd.js.map +1 -1
  8. package/bundles/veloceapps-sdk.umd.js +385 -302
  9. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  10. package/cms/cms.actions.d.ts +2 -4
  11. package/cms/components/element-children/element-children.component.d.ts +13 -3
  12. package/cms/components/element-children/element-children.module.d.ts +4 -2
  13. package/cms/components/element-drop-handle/element-drop-handle.component.d.ts +12 -0
  14. package/cms/components/element-drop-handle/element-drop-handle.module.d.ts +9 -0
  15. package/cms/components/element-renderer/element-renderer.component.d.ts +3 -3
  16. package/cms/components/preview/index.d.ts +1 -0
  17. package/cms/components/preview/preview.component.d.ts +9 -8
  18. package/cms/components/preview/preview.module.d.ts +2 -1
  19. package/cms/components/preview/preview.types.d.ts +11 -0
  20. package/cms/index.d.ts +2 -0
  21. package/cms/launcher.module.d.ts +3 -1
  22. package/cms/modules/migrations/index.d.ts +2 -0
  23. package/cms/modules/migrations/migrations.d.ts +2 -0
  24. package/cms/modules/migrations/migrations.module.d.ts +6 -0
  25. package/cms/modules/migrations/services/migrations.service.d.ts +10 -0
  26. package/cms/modules/migrations/types/migrations.types.d.ts +2 -0
  27. package/cms/modules/runtime/index.d.ts +2 -0
  28. package/cms/modules/runtime/runtime.module.d.ts +8 -0
  29. package/cms/modules/runtime/services/compilation.service.d.ts +18 -0
  30. package/cms/modules/runtime/services/runtime-editor.service.d.ts +18 -0
  31. package/cms/modules/runtime/services/runtime.service.d.ts +27 -0
  32. package/cms/modules/runtime/tokens.d.ts +3 -0
  33. package/cms/{types → modules/runtime/types}/compilation.types.d.ts +1 -1
  34. package/cms/modules/runtime/types/runtime.actions.d.ts +9 -0
  35. package/cms/services/index.d.ts +1 -1
  36. package/cms/services/io-provider.service.d.ts +3 -3
  37. package/cms/services/resources.service.d.ts +10 -0
  38. package/cms/types/common.types.d.ts +1 -1
  39. package/cms/types/configuration.types.d.ts +1 -0
  40. package/cms/types/index.d.ts +1 -1
  41. package/cms/utils/elements-resolver.d.ts +3 -2
  42. package/cms/utils/index.d.ts +1 -0
  43. package/cms/utils/path.utils.d.ts +0 -1
  44. package/cms/utils/ui-definition.utils.d.ts +6 -0
  45. package/cms/vendor-map.d.ts +50 -31
  46. package/core/modules/configuration/services/configuration-runtime.service.d.ts +2 -4
  47. package/core/modules/configuration/services/configuration.service.d.ts +6 -4
  48. package/core/modules/configuration/types/configuration-runtime.types.d.ts +0 -2
  49. package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +3 -2
  50. package/core/modules/flow-configuration/services/flow-update.service.d.ts +3 -2
  51. package/core/services/metric-calculation/metric-calculation.service.d.ts +5 -1
  52. package/core/services/quote-draft.service.d.ts +2 -2
  53. package/core/types/index.d.ts +0 -1
  54. package/core/types/ui-definition.types.d.ts +19 -4
  55. package/core/utils/index.d.ts +1 -0
  56. package/core/utils/line-item.utils.d.ts +2 -0
  57. package/core/utils/ui-definition.utils.d.ts +2 -0
  58. package/esm2015/cms/cms.actions.js +1 -6
  59. package/esm2015/cms/components/element-children/element-children.component.js +24 -8
  60. package/esm2015/cms/components/element-children/element-children.module.js +8 -6
  61. package/esm2015/cms/components/element-drop-handle/element-drop-handle.component.js +32 -0
  62. package/esm2015/cms/components/element-drop-handle/element-drop-handle.module.js +19 -0
  63. package/esm2015/cms/components/element-renderer/element-renderer.component.js +9 -9
  64. package/esm2015/cms/components/element-renderer/element-renderer.module.js +4 -4
  65. package/esm2015/cms/components/plugin.component.js +3 -3
  66. package/esm2015/cms/components/preview/index.js +2 -1
  67. package/esm2015/cms/components/preview/preview.component.js +21 -36
  68. package/esm2015/cms/components/preview/preview.module.js +7 -6
  69. package/esm2015/cms/components/preview/preview.types.js +2 -0
  70. package/esm2015/cms/directives/custom-template.directive.js +3 -3
  71. package/esm2015/cms/index.js +3 -1
  72. package/esm2015/cms/launcher.module.js +11 -10
  73. package/esm2015/cms/modules/federated/federated.component.js +3 -3
  74. package/esm2015/cms/modules/federated/federated.module.js +4 -4
  75. package/esm2015/cms/modules/migrations/index.js +3 -0
  76. package/esm2015/cms/modules/migrations/migrations.js +11 -0
  77. package/esm2015/cms/modules/migrations/migrations.module.js +15 -0
  78. package/esm2015/cms/modules/migrations/services/migrations.service.js +43 -0
  79. package/esm2015/cms/modules/migrations/types/migrations.types.js +2 -0
  80. package/esm2015/cms/modules/runtime/index.js +3 -0
  81. package/esm2015/cms/modules/runtime/runtime.module.js +32 -0
  82. package/esm2015/cms/modules/runtime/services/compilation.service.js +84 -0
  83. package/esm2015/cms/modules/runtime/services/runtime-editor.service.js +27 -0
  84. package/esm2015/cms/modules/runtime/services/runtime.service.js +74 -0
  85. package/esm2015/cms/modules/runtime/tokens.js +3 -0
  86. package/esm2015/cms/modules/runtime/types/compilation.types.js +2 -0
  87. package/esm2015/cms/modules/runtime/types/runtime.actions.js +2 -0
  88. package/esm2015/cms/plugins/configuration.plugin.js +12 -4
  89. package/esm2015/cms/plugins/io.plugin.js +3 -3
  90. package/esm2015/cms/plugins/script.plugin.js +3 -3
  91. package/esm2015/cms/services/element-context.service.js +3 -3
  92. package/esm2015/cms/services/index.js +2 -2
  93. package/esm2015/cms/services/integration.state.js +3 -3
  94. package/esm2015/cms/services/io-provider.service.js +9 -9
  95. package/esm2015/cms/services/resources.service.js +50 -0
  96. package/esm2015/cms/services/templates.service.js +3 -3
  97. package/esm2015/cms/types/common.types.js +1 -1
  98. package/esm2015/cms/types/configuration.types.js +1 -1
  99. package/esm2015/cms/types/index.js +2 -2
  100. package/esm2015/cms/utils/elements-resolver.js +18 -8
  101. package/esm2015/cms/utils/index.js +2 -1
  102. package/esm2015/cms/utils/path.utils.js +2 -13
  103. package/esm2015/cms/utils/ui-definition.utils.js +82 -0
  104. package/esm2015/cms/vendor-map.js +25 -10
  105. package/esm2015/core/core.module.js +4 -4
  106. package/esm2015/core/modules/configuration/configuration.module.js +4 -4
  107. package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +5 -10
  108. package/esm2015/core/modules/configuration/services/configuration.service.js +38 -34
  109. package/esm2015/core/modules/configuration/services/runtime-context.service.js +3 -3
  110. package/esm2015/core/modules/configuration/types/configuration-runtime.types.js +1 -1
  111. package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +4 -4
  112. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +11 -10
  113. package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +9 -9
  114. package/esm2015/core/services/context.service.js +3 -3
  115. package/esm2015/core/services/metric-calculation/metric-calculation.service.js +18 -9
  116. package/esm2015/core/services/product-images.service.js +3 -3
  117. package/esm2015/core/services/quote-draft.service.js +7 -7
  118. package/esm2015/core/types/index.js +1 -2
  119. package/esm2015/core/types/ui-definition.types.js +2 -2
  120. package/esm2015/core/utils/index.js +2 -1
  121. package/esm2015/core/utils/line-item.utils.js +27 -11
  122. package/esm2015/core/utils/ui-definition.utils.js +9 -0
  123. package/esm2015/runtime/components/component-preview/component-preview.component.js +4 -4
  124. package/esm2015/runtime/components/section-renderer/section-renderer.component.js +3 -3
  125. package/esm2015/runtime/components/ui-runtime/runtime.component.js +3 -3
  126. package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
  127. package/esm2015/runtime/execution/components/children-placeholder/children-placeholder.component.js +6 -6
  128. package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +3 -3
  129. package/esm2015/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.js +3 -3
  130. package/esm2015/runtime/execution/components/federated/federated.component.js +3 -3
  131. package/esm2015/runtime/execution/components/velo-attribute/velo-attribute.component.js +3 -3
  132. package/esm2015/runtime/execution/components/velo-multiselect/velo-multiselect.component.js +3 -3
  133. package/esm2015/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.js +3 -3
  134. package/esm2015/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.js +3 -3
  135. package/esm2015/runtime/execution/components/velo-port-radio/velo-port-radio.component.js +3 -3
  136. package/esm2015/runtime/execution/components/velo-type/velo-type.component.js +3 -3
  137. package/esm2015/runtime/execution/directives/section-script.directive.js +3 -3
  138. package/esm2015/runtime/execution/directives/sf-query.directive.js +3 -3
  139. package/esm2015/runtime/execution/directives/velo-attribute.directive.js +3 -3
  140. package/esm2015/runtime/execution/directives/velo-port.directive.js +18 -18
  141. package/esm2015/runtime/execution/directives/vl-approval.directive.js +3 -3
  142. package/esm2015/runtime/execution/directives/vl-document-attachments.directive.js +3 -3
  143. package/esm2015/runtime/execution/directives/vl-document-templates.directive.js +3 -3
  144. package/esm2015/runtime/execution/directives/vl-quote.directive.js +4 -4
  145. package/esm2015/runtime/execution/directives/vl-ramp.directive.js +3 -3
  146. package/esm2015/runtime/execution/runtime-execution.module.js +4 -4
  147. package/esm2015/runtime/runtime.module.js +4 -4
  148. package/esm2015/runtime/services/cart.service.js +3 -3
  149. package/esm2015/runtime/services/collapsible-state.service.js +3 -3
  150. package/esm2015/runtime/services/configuration.service.js +11 -12
  151. package/esm2015/runtime/services/current-state.service.js +3 -3
  152. package/esm2015/runtime/services/form-scope.service.js +3 -3
  153. package/esm2015/runtime/services/product-model-cache.service.js +3 -3
  154. package/esm2015/runtime/services/runtime-context.service.js +3 -3
  155. package/esm2015/runtime/services/runtime-form.service.js +3 -3
  156. package/esm2015/runtime/services/runtime.service.js +4 -4
  157. package/esm2015/runtime/services/section-helper.service.js +3 -3
  158. package/esm2015/runtime/services/section-scope.service.js +3 -3
  159. package/esm2015/runtime/services/section-store.service.js +3 -3
  160. package/esm2015/runtime/services/section.service.js +6 -6
  161. package/esm2015/runtime/types/index.js +2 -1
  162. package/esm2015/runtime/types/quote-states.types.js +2 -0
  163. package/esm2015/src/components/dialog/dialog.component.js +16 -6
  164. package/esm2015/src/components/dialog/dialog.module.js +4 -4
  165. package/esm2015/src/components/dialog/dialog.types.js +1 -1
  166. package/esm2015/src/components/doc-gen/doc-gen.component.js +3 -3
  167. package/esm2015/src/components/doc-gen/doc-gen.module.js +4 -4
  168. package/esm2015/src/components/header/cart-overlay/cart-preview.component.js +3 -3
  169. package/esm2015/src/components/header/cart-overlay/cart-preview.module.js +4 -4
  170. package/esm2015/src/components/header/header.component.js +20 -12
  171. package/esm2015/src/components/header/header.module.js +4 -4
  172. package/esm2015/src/components/header/metrics/metrics.component.js +79 -67
  173. package/esm2015/src/components/header/metrics/metrics.definitions.js +1 -8
  174. package/esm2015/src/components/header/metrics/metrics.module.js +4 -4
  175. package/esm2015/src/flow-routing.module.js +4 -4
  176. package/esm2015/src/flow.component.js +3 -3
  177. package/esm2015/src/flow.module.js +4 -4
  178. package/esm2015/src/guards/context.guard.js +3 -3
  179. package/esm2015/src/guards/product-unload.guard.js +5 -5
  180. package/esm2015/src/guards/root.guard.js +3 -3
  181. package/esm2015/src/pages/catalog/catalog.component.js +3 -3
  182. package/esm2015/src/pages/catalog/catalog.module.js +4 -4
  183. package/esm2015/src/pages/debug/debug.component.js +3 -3
  184. package/esm2015/src/pages/debug/debug.module.js +4 -4
  185. package/esm2015/src/pages/empty-account/empty-account.component.js +3 -3
  186. package/esm2015/src/pages/empty-account/empty-account.module.js +4 -4
  187. package/esm2015/src/pages/legacy-product/legacy-product.component.js +4 -4
  188. package/esm2015/src/pages/legacy-product/legacy-product.module.js +4 -4
  189. package/esm2015/src/pages/product/product.component.js +5 -12
  190. package/esm2015/src/pages/product/product.module.js +4 -4
  191. package/esm2015/src/pages/record-not-found/record-not-found.component.js +3 -3
  192. package/esm2015/src/pages/record-not-found/record-not-found.module.js +4 -4
  193. package/esm2015/src/pages/remote/remote.component.js +5 -8
  194. package/esm2015/src/pages/remote/remote.module.js +4 -4
  195. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +3 -3
  196. package/esm2015/src/pages/shopping-cart/shopping-cart.module.js +4 -4
  197. package/esm2015/src/resolvers/flow.resolver.js +3 -3
  198. package/esm2015/src/resolvers/quote.resolver.js +8 -8
  199. package/esm2015/src/services/doc-gen.service.js +3 -3
  200. package/esm2015/src/services/flow-dialog.service.js +5 -4
  201. package/esm2015/src/services/flow-router.service.js +3 -3
  202. package/esm2015/src/services/flow.service.js +3 -3
  203. package/esm2015/src/utils/flow.utils.js +3 -3
  204. package/fesm2015/veloceapps-sdk-cms.js +1072 -718
  205. package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
  206. package/fesm2015/veloceapps-sdk-core.js +568 -534
  207. package/fesm2015/veloceapps-sdk-core.js.map +1 -1
  208. package/fesm2015/veloceapps-sdk-runtime.js +145 -146
  209. package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
  210. package/fesm2015/veloceapps-sdk.js +270 -255
  211. package/fesm2015/veloceapps-sdk.js.map +1 -1
  212. package/package.json +5 -3
  213. package/runtime/services/configuration.service.d.ts +2 -1
  214. package/runtime/services/runtime.service.d.ts +2 -1
  215. package/runtime/types/index.d.ts +1 -0
  216. package/src/components/dialog/dialog.types.d.ts +1 -0
  217. package/src/components/header/header.component.d.ts +4 -2
  218. package/src/components/header/metrics/metrics.component.d.ts +15 -6
  219. package/src/components/header/metrics/metrics.definitions.d.ts +0 -3
  220. package/src/pages/product/product.component.d.ts +0 -1
  221. package/cms/services/dynamic-module.service.d.ts +0 -15
  222. package/cms/services/launcher.service.d.ts +0 -18
  223. package/esm2015/cms/services/dynamic-module.service.js +0 -33
  224. package/esm2015/cms/services/launcher.service.js +0 -58
  225. package/esm2015/cms/types/compilation.types.js +0 -2
  226. package/esm2015/core/types/quote-states.types.js +0 -2
  227. /package/{core → runtime}/types/quote-states.types.d.ts +0 -0
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@veloceapps/core'), require('rxjs'), require('rxjs/operators'), require('@veloceapps/api'), require('lodash'), require('@veloceapps/components'), require('primeng/api'), require('primeng/dynamicdialog'), require('moment')) :
3
3
  typeof define === 'function' && define.amd ? define('@veloceapps/sdk/core', ['exports', '@angular/core', '@veloceapps/core', 'rxjs', 'rxjs/operators', '@veloceapps/api', 'lodash', '@veloceapps/components', 'primeng/api', 'primeng/dynamicdialog', 'moment'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.veloceapps = global.veloceapps || {}, global.veloceapps.sdk = global.veloceapps.sdk || {}, global.veloceapps.sdk.core = {}), global.ng.core, global["@veloceapps/core"], global.rxjs, global.rxjs.operators, global["@veloceapps/api"], global.lodash, global["@veloceapps/components"], global["primeng/api"], global["primeng/dynamicdialog"], global.moment));
5
- })(this, (function (exports, i0, core, rxjs, operators, i1, lodash, components, i4, i5, moment) { 'use strict';
5
+ })(this, (function (exports, i0, core, rxjs, operators, i1, lodash, components, i5, i6, moment) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -26,8 +26,8 @@
26
26
 
27
27
  var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
28
  var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
29
- var i4__namespace = /*#__PURE__*/_interopNamespace(i4);
30
29
  var i5__namespace = /*#__PURE__*/_interopNamespace(i5);
30
+ var i6__namespace = /*#__PURE__*/_interopNamespace(i6);
31
31
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
32
32
 
33
33
  var getDefaultLineItem = function (context, uiDefinitionProperties, qty) {
@@ -40,7 +40,7 @@
40
40
  return lineItem;
41
41
  };
42
42
 
43
- /*! *****************************************************************************
43
+ /******************************************************************************
44
44
  Copyright (c) Microsoft Corporation.
45
45
 
46
46
  Permission to use, copy, modify, and/or distribute this software for any
@@ -107,6 +107,64 @@
107
107
  function __param(paramIndex, decorator) {
108
108
  return function (target, key) { decorator(target, key, paramIndex); };
109
109
  }
110
+ function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
111
+ function accept(f) { if (f !== void 0 && typeof f !== "function")
112
+ throw new TypeError("Function expected"); return f; }
113
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
114
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
115
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
116
+ var _, done = false;
117
+ for (var i = decorators.length - 1; i >= 0; i--) {
118
+ var context = {};
119
+ for (var p in contextIn)
120
+ context[p] = p === "access" ? {} : contextIn[p];
121
+ for (var p in contextIn.access)
122
+ context.access[p] = contextIn.access[p];
123
+ context.addInitializer = function (f) { if (done)
124
+ throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
125
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
126
+ if (kind === "accessor") {
127
+ if (result === void 0)
128
+ continue;
129
+ if (result === null || typeof result !== "object")
130
+ throw new TypeError("Object expected");
131
+ if (_ = accept(result.get))
132
+ descriptor.get = _;
133
+ if (_ = accept(result.set))
134
+ descriptor.set = _;
135
+ if (_ = accept(result.init))
136
+ initializers.push(_);
137
+ }
138
+ else if (_ = accept(result)) {
139
+ if (kind === "field")
140
+ initializers.push(_);
141
+ else
142
+ descriptor[key] = _;
143
+ }
144
+ }
145
+ if (target)
146
+ Object.defineProperty(target, contextIn.name, descriptor);
147
+ done = true;
148
+ }
149
+ ;
150
+ function __runInitializers(thisArg, initializers, value) {
151
+ var useValue = arguments.length > 2;
152
+ for (var i = 0; i < initializers.length; i++) {
153
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
154
+ }
155
+ return useValue ? value : void 0;
156
+ }
157
+ ;
158
+ function __propKey(x) {
159
+ return typeof x === "symbol" ? x : "".concat(x);
160
+ }
161
+ ;
162
+ function __setFunctionName(f, name, prefix) {
163
+ if (typeof name === "symbol")
164
+ name = name.description ? "[".concat(name.description, "]") : "";
165
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
166
+ }
167
+ ;
110
168
  function __metadata(metadataKey, metadataValue) {
111
169
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
112
170
  return Reflect.metadata(metadataKey, metadataValue);
@@ -138,7 +196,7 @@
138
196
  function step(op) {
139
197
  if (f)
140
198
  throw new TypeError("Generator is already executing.");
141
- while (_)
199
+ while (g && (g = 0, op[0] && (_ = 0)), _)
142
200
  try {
143
201
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
144
202
  return t;
@@ -202,7 +260,11 @@
202
260
  var __createBinding = Object.create ? (function (o, m, k, k2) {
203
261
  if (k2 === undefined)
204
262
  k2 = k;
205
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
263
+ var desc = Object.getOwnPropertyDescriptor(m, k);
264
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
265
+ desc = { enumerable: true, get: function () { return m[k]; } };
266
+ }
267
+ Object.defineProperty(o, k2, desc);
206
268
  }) : (function (o, m, k, k2) {
207
269
  if (k2 === undefined)
208
270
  k2 = k;
@@ -302,7 +364,7 @@
302
364
  function __asyncDelegator(o) {
303
365
  var i, p;
304
366
  return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
305
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
367
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
306
368
  }
307
369
  function __asyncValues(o) {
308
370
  if (!Symbol.asyncIterator)
@@ -357,6 +419,11 @@
357
419
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
358
420
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
359
421
  }
422
+ function __classPrivateFieldIn(state, receiver) {
423
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
424
+ throw new TypeError("Cannot use 'in' operator on non-object");
425
+ return typeof state === "function" ? receiver === state : state.has(receiver);
426
+ }
360
427
 
361
428
  exports.RuntimeMode = void 0;
362
429
  (function (RuntimeMode) {
@@ -374,6 +441,8 @@
374
441
  RuntimeStep["UPDATE"] = "UPDATE";
375
442
  })(exports.RuntimeStep || (exports.RuntimeStep = {}));
376
443
 
444
+ var UI_DEFINITION_VERSION = 3;
445
+
377
446
  var ContextService = /** @class */ (function () {
378
447
  function ContextService(contextApiService) {
379
448
  this.contextApiService = contextApiService;
@@ -416,758 +485,620 @@
416
485
  };
417
486
  return ContextService;
418
487
  }());
419
- ContextService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ContextService, deps: [{ token: i1__namespace.ContextApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
420
- ContextService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ContextService, providedIn: 'root' });
421
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ContextService, decorators: [{
488
+ ContextService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ContextService, deps: [{ token: i1__namespace.ContextApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
489
+ ContextService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ContextService, providedIn: 'root' });
490
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ContextService, decorators: [{
422
491
  type: i0.Injectable,
423
492
  args: [{ providedIn: 'root' }]
424
493
  }], ctorParameters: function () { return [{ type: i1__namespace.ContextApiService }]; } });
425
494
 
426
- function calculateMetricByMethod(lineItems, metric, method) {
427
- var items = getLineItemsByMethod(lineItems, method);
428
- return items.reduce(function (acc, li) {
429
- var value = li.reduce(function (accProduct, item) { return accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0); }, 0);
430
- if (method === 'avg' && li.length > 0) {
431
- value /= li.length;
432
- }
433
- return acc + value;
434
- }, 0);
435
- }
436
- function getLineItemsByMethod(lineItems, method) {
437
- switch (method) {
438
- case 'first': {
439
- return lineItems.filter(function (li) { return !li.rampInstanceId; }).map(function (item) { return [item]; });
440
- }
441
- case 'last': {
442
- var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
443
- var products = rootTermItems.map(function (lineItem) { return __spreadArray([
444
- lineItem
445
- ], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
446
- return products
447
- .map(function (items) { return __spreadArray([], __read(items)).sort(function (a, b) { return getDateValue(a.endDate || '') - getDateValue(b.endDate || ''); }).pop(); })
448
- .filter(function (li) { return Boolean(li); })
449
- .map(function (item) { return [item]; });
450
- }
451
- case 'avg': {
452
- var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
453
- return rootTermItems.map(function (lineItem) { return __spreadArray([lineItem], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
454
- }
455
- case 'sum': {
456
- return lineItems.map(function (item) { return [item]; });
495
+ var RuntimeContextService = /** @class */ (function () {
496
+ function RuntimeContextService(configurationApiService) {
497
+ this.configurationApiService = configurationApiService;
498
+ }
499
+ RuntimeContextService.prototype.getRuntimeContext = function (productId, offeringId) {
500
+ var _this = this;
501
+ return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(operators.map(function (runtimeData) {
502
+ var _a, _b, _c;
503
+ var uiDefinition = _this.getUIDefinition(runtimeData);
504
+ var runtimeModel = core.RuntimeModel.create(runtimeData.types, runtimeData.products);
505
+ var _d = (_a = Array.from(runtimeModel.components.values()).find(function (c) { return c.productId === productId; })) !== null && _a !== void 0 ? _a : {}, productName = _d.productName, properties = _d.properties;
506
+ return {
507
+ modelId: runtimeData.modelId,
508
+ uiDefinition: uiDefinition,
509
+ runtimeModel: runtimeModel,
510
+ runtimeMode: exports.RuntimeMode.PROD,
511
+ productId: productId,
512
+ productType: (properties === null || properties === void 0 ? void 0 : properties.displayName) || productName,
513
+ offeringId: offeringId,
514
+ properties: {
515
+ PricingEnabled: ((_b = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _b === void 0 ? void 0 : _b.pricingEnabled) ? 'true' : 'false',
516
+ PriceListId: (_c = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _c === void 0 ? void 0 : _c.priceList,
517
+ },
518
+ };
519
+ }));
520
+ };
521
+ RuntimeContextService.prototype.getUIDefinition = function (runtimeData) {
522
+ var _a;
523
+ var rawUiDefinitions;
524
+ try {
525
+ rawUiDefinitions = JSON.parse(runtimeData.uiDefinitionsSource);
457
526
  }
458
- default: {
459
- return lineItems.map(function (item) { return [item]; });
527
+ catch (e) {
528
+ return;
460
529
  }
461
- }
462
- }
463
- function getDateValue(date) {
464
- return date ? new Date(date).getTime() : 0;
465
- }
530
+ var uiDefinitions = rawUiDefinitions.filter(function (uiDef) { return uiDef.version; });
531
+ var uiDefinition = (_a = uiDefinitions.find(function (uiDef) { return uiDef.primary; })) !== null && _a !== void 0 ? _a : uiDefinitions[0];
532
+ return uiDefinition;
533
+ };
534
+ return RuntimeContextService;
535
+ }());
536
+ RuntimeContextService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RuntimeContextService, deps: [{ token: i1__namespace.ConfigurationApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
537
+ RuntimeContextService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RuntimeContextService });
538
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RuntimeContextService, decorators: [{
539
+ type: i0.Injectable
540
+ }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }]; } });
466
541
 
467
- var QuoteDraftService = /** @class */ (function () {
468
- function QuoteDraftService(context, quoteApiService, priceApiService) {
469
- var _this = this;
470
- this.context = context;
471
- this.quoteApiService = quoteApiService;
472
- this.priceApiService = priceApiService;
473
- this.quoteSubj$ = new rxjs.BehaviorSubject(null);
474
- this.resetSubj$ = new rxjs.BehaviorSubject(true);
475
- this.isInitializedSubj$ = new rxjs.BehaviorSubject(false);
476
- this.initialCurrentState = [];
477
- this._hasUnsavedChanges = false;
478
- this.allPriceLists = [];
479
- this.assetPriceLists = [];
480
- this.reset$ = this.resetSubj$.asObservable();
481
- this.activePriceList$ = this.context.resolve$().pipe(operators.map(function (ctx) { return _this.allPriceLists.find(function (priceList) { return priceList.id === ctx.properties.PriceListId; }); }), operators.map(function (priceList) { return priceList !== null && priceList !== void 0 ? priceList : null; }));
482
- this.isInitializedSubj$
483
- .pipe(operators.filter(function (isInitialized) { return isInitialized; }), operators.switchMap(function () { return _this.quoteSubj$.asObservable(); }), operators.skip(1), operators.tap(function (quote) { return _this.markAsUpdated(quote); }))
484
- .subscribe();
542
+ var ConfigurationRuntimeService = /** @class */ (function () {
543
+ function ConfigurationRuntimeService(apiService, contextService, runtimeContextService) {
544
+ this.apiService = apiService;
545
+ this.contextService = contextService;
546
+ this.runtimeContextService = runtimeContextService;
547
+ this._isInitialized = false;
548
+ this.uiDefinitionProperties = {};
485
549
  }
486
- Object.defineProperty(QuoteDraftService.prototype, "isInitialized", {
487
- get: function () {
488
- return this.isInitializedSubj$.getValue();
489
- },
490
- set: function (value) {
491
- if (this.isInitialized !== value) {
492
- this.isInitializedSubj$.next(value);
493
- }
494
- },
495
- enumerable: false,
496
- configurable: true
497
- });
498
- Object.defineProperty(QuoteDraftService.prototype, "hasUnsavedChanges", {
499
- get: function () {
500
- return this._hasUnsavedChanges;
501
- },
502
- set: function (value) {
503
- var _a, _b;
504
- this._hasUnsavedChanges = value;
505
- if (!this._hasUnsavedChanges) {
506
- this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
507
- }
508
- },
509
- enumerable: false,
510
- configurable: true
511
- });
512
- Object.defineProperty(QuoteDraftService.prototype, "hasAssets$", {
513
- get: function () {
514
- var _this = this;
515
- return this.quoteSubj$.pipe(operators.map(function () { return _this.hasAssets; }));
516
- },
517
- enumerable: false,
518
- configurable: true
519
- });
520
- Object.defineProperty(QuoteDraftService.prototype, "hasAssets", {
521
- get: function () {
522
- var quoteDraft = this.quoteSubj$.value;
523
- return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
524
- },
525
- enumerable: false,
526
- configurable: true
527
- });
528
- QuoteDraftService.prototype.reset = function () {
529
- this.resetSubj$.next(true);
530
- this.quoteSubj$.next(null);
531
- this.hasUnsavedChanges = false;
550
+ ConfigurationRuntimeService.prototype.reset = function () {
551
+ this._isInitialized = false;
552
+ this._runtimeContext = undefined;
553
+ this.initializationProps = undefined;
554
+ this.uiDefinitionProperties = {};
532
555
  };
533
- QuoteDraftService.prototype.init = function (quoteId, params) {
556
+ ConfigurationRuntimeService.prototype.initTestMode = function (modelId, uiDefinition) {
534
557
  var _this = this;
535
- return rxjs.zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(operators.tap(function (_c) {
536
- var _d = __read(_c, 2), quote = _d[0], allPriceLists = _d[1];
537
- _this.allPriceLists = allPriceLists;
538
- _this.quoteSubj$.next(quote);
539
- _this.context.update(quote.context);
540
- _this.populateActivePriceLists$();
541
- }), operators.map(function () { return rxjs.noop(); }), operators.take(1));
558
+ var _a, _b;
559
+ this.uiDefinitionProperties = (_a = uiDefinition.properties) !== null && _a !== void 0 ? _a : {};
560
+ var uiDefinitionExternals = (_b = uiDefinition.externals) !== null && _b !== void 0 ? _b : {};
561
+ return rxjs.combineLatest([
562
+ this.apiService.getRuntimeDataByModelId(modelId),
563
+ this.contextService.create('TestId', core.ConfigurationContextMode.TEST),
564
+ ]).pipe(operators.first(), operators.tap(function (_e) {
565
+ var _f = __read(_e, 2), runtimeData = _f[0], context = _f[1];
566
+ var _a;
567
+ _this._runtimeContext = {
568
+ modelId: modelId,
569
+ runtimeModel: core.RuntimeModel.create(runtimeData.types, runtimeData.products),
570
+ runtimeMode: exports.RuntimeMode.TEST,
571
+ };
572
+ _this.contextService.update({
573
+ properties: Object.assign(Object.assign(Object.assign(Object.assign({}, (_a = _this.runtimeContext) === null || _a === void 0 ? void 0 : _a.properties), context.properties), { ModelId: modelId, RuntimeMode: core.ConfigurationContextMode.TEST, PricingEnabled: _this.uiDefinitionProperties.pricingEnabled ? 'true' : 'false', StartDate: new Date().toISOString().substring(0, 10), PriceListId: _this.uiDefinitionProperties.priceList, standalone: 'true' }), uiDefinitionExternals),
574
+ });
575
+ _this._isInitialized = true;
576
+ }));
542
577
  };
543
- QuoteDraftService.prototype.setCurrentLineItemState = function (lineItems) {
544
- var quoteDraft = this.quoteSubj$.value;
545
- if (!quoteDraft) {
546
- return;
547
- }
548
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
578
+ ConfigurationRuntimeService.prototype.init = function (props) {
579
+ var _this = this;
580
+ this.initializationProps = props;
581
+ var context = this.contextService.resolve();
582
+ return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(operators.tap(function (runtimeContext) {
583
+ var _a, _b, _c, _d;
584
+ _this.uiDefinitionProperties = (_b = (_a = runtimeContext.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {};
585
+ var PriceListId = ((_c = context.properties) !== null && _c !== void 0 ? _c : {}).PriceListId;
586
+ var mergeContext = Object.assign(Object.assign({}, runtimeContext), { properties: Object.assign(Object.assign(Object.assign({}, runtimeContext.properties), context.properties), { PricingEnabled: PriceListId ? 'true' : 'false' }) });
587
+ _this.id15to18('AccountId', mergeContext.properties);
588
+ _this._runtimeContext = mergeContext;
589
+ if (context.properties && ((_d = _this._runtimeContext.properties) === null || _d === void 0 ? void 0 : _d.StartDate)) {
590
+ _this.contextService.update({
591
+ properties: Object.assign(Object.assign({}, _this._runtimeContext.properties), context.properties),
592
+ });
593
+ }
594
+ _this._isInitialized = true;
595
+ }));
549
596
  };
550
- QuoteDraftService.prototype.updateQuoteDraft = function (update) {
551
- var quoteDraft = this.quoteSubj$.value;
552
- if (!quoteDraft) {
597
+ ConfigurationRuntimeService.prototype.id15to18 = function (propertyName, source) {
598
+ if (!source) {
553
599
  return;
554
600
  }
555
- if (update.context) {
556
- this.context.set(update.context);
557
- }
558
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
559
- };
560
- QuoteDraftService.prototype.updateByPriceSummary = function (priceSummary) {
561
- var quoteDraft = this.quoteSubj$.value;
562
- if (!quoteDraft) {
563
- return;
601
+ var value = source[propertyName];
602
+ if (typeof value === 'string' && value.length === 15) {
603
+ source[propertyName] = core.SalesforceIdUtils.generateId18FromId15(value);
564
604
  }
565
- var updatedCurrentState = this.currentState.map(function (lineItem) {
566
- var updated = priceSummary.lineItems.find(function (li) { return li.id === lineItem.id; });
567
- return updated !== null && updated !== void 0 ? updated : lineItem;
568
- });
569
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
570
605
  };
571
- Object.defineProperty(QuoteDraftService.prototype, "quoteDraft$", {
606
+ Object.defineProperty(ConfigurationRuntimeService.prototype, "isInitialized", {
572
607
  get: function () {
573
- var _this = this;
574
- return rxjs.combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(operators.map(function () { return _this.quoteDraft; }), operators.filter(function (quote) { return Boolean(quote); }), operators.shareReplay());
608
+ return this._isInitialized;
575
609
  },
576
610
  enumerable: false,
577
611
  configurable: true
578
612
  });
579
- Object.defineProperty(QuoteDraftService.prototype, "quoteDraft", {
613
+ Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeModel", {
580
614
  get: function () {
581
- var quote = this.quoteSubj$.value;
582
- if (!quote) {
583
- return null;
584
- }
585
- return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
615
+ var _a;
616
+ return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
586
617
  },
587
618
  enumerable: false,
588
619
  configurable: true
589
620
  });
590
- Object.defineProperty(QuoteDraftService.prototype, "quoteDraftForActivePriceList", {
621
+ Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeContext", {
591
622
  get: function () {
592
- var quoteDraft = this.quoteDraft;
593
- if (!quoteDraft) {
594
- return null;
595
- }
596
- return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
623
+ return this._runtimeContext;
597
624
  },
598
625
  enumerable: false,
599
626
  configurable: true
600
627
  });
601
- Object.defineProperty(QuoteDraftService.prototype, "currentState$", {
602
- get: function () {
603
- return this.quoteDraft$.pipe(operators.map(function (quote) { return quote.currentState; }));
604
- },
605
- enumerable: false,
606
- configurable: true
628
+ return ConfigurationRuntimeService;
629
+ }());
630
+ ConfigurationRuntimeService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationRuntimeService, deps: [{ token: i1__namespace.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
631
+ ConfigurationRuntimeService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationRuntimeService });
632
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationRuntimeService, decorators: [{
633
+ type: i0.Injectable
634
+ }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
635
+
636
+ var findLineItem = function (id, lineItems) {
637
+ return findLineItemWithComparator(lineItems, function (li) { return li.id === id; });
638
+ };
639
+ var findLineItemWithComparator = function (lineItems, comparator) {
640
+ var currentLevel = lineItems;
641
+ while (currentLevel.length) {
642
+ var found = currentLevel.find(comparator);
643
+ if (found) {
644
+ return found;
645
+ }
646
+ currentLevel = lodash.flatten(currentLevel.map(function (parent) { return parent.lineItems; }));
647
+ }
648
+ return;
649
+ };
650
+ var insertLineItem = function (lineItem, parentId, toInsert) {
651
+ var insertData = lineItem.id === parentId ? [toInsert] : [];
652
+ return Object.assign(Object.assign({}, lineItem), { lineItems: __spreadArray(__spreadArray([], __read(insertData)), __read(lineItem.lineItems.map(function (li) {
653
+ return insertLineItem(li, parentId, toInsert);
654
+ }))) });
655
+ };
656
+ var removeLineItem = function (lineItem, idToRemove) {
657
+ return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems
658
+ .map(function (li) {
659
+ if (li.id === idToRemove) {
660
+ return;
661
+ }
662
+ else if (li.lineItems.length) {
663
+ return removeLineItem(li, idToRemove);
664
+ }
665
+ return li;
666
+ })
667
+ .filter(function (r) { return !!r; }) });
668
+ };
669
+ var replaceLineItem = function (lineItem, replaceTo) {
670
+ if (lineItem.id === replaceTo.id) {
671
+ return Object.assign({}, recalculateCardinalityVariables(lineItem, replaceTo));
672
+ }
673
+ return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(function (li) { return replaceLineItem(li, replaceTo); }) });
674
+ };
675
+ var calculateCardinalityVariables = function (lineItems) {
676
+ var cardVars = new Map();
677
+ lineItems.forEach(function (li) {
678
+ var _a;
679
+ var cardinalityVariableName = "#CV-" + li.type + "@" + li.port;
680
+ cardVars.set(cardinalityVariableName, ((_a = cardVars.get(cardinalityVariableName)) !== null && _a !== void 0 ? _a : 0) + li.qty);
607
681
  });
608
- Object.defineProperty(QuoteDraftService.prototype, "currentState", {
609
- get: function () {
610
- var _a, _b;
611
- return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
612
- },
613
- enumerable: false,
614
- configurable: true
682
+ return cardVars;
683
+ };
684
+ var recalculateCardinalityVariables = function (original, updated) {
685
+ var cardinalityVariables = calculateCardinalityVariables(updated.lineItems);
686
+ var originalCardinalityVariables = calculateCardinalityVariables(original.lineItems);
687
+ originalCardinalityVariables.forEach(function (value, key) {
688
+ if (cardinalityVariables.get(key) === value) {
689
+ // no need to update cardinality if no changes
690
+ cardinalityVariables.delete(key);
691
+ }
692
+ else if (!cardinalityVariables.has(key)) {
693
+ // remove last item from port
694
+ cardinalityVariables.set(key, 0);
695
+ }
615
696
  });
616
- Object.defineProperty(QuoteDraftService.prototype, "activeCurrentState$", {
617
- /**
618
- * Stream of activeCurrentState
619
- */
697
+ return Object.assign(Object.assign({}, updated), { attributes: upsertAttributes(updated.attributes, __spreadArray([], __read(cardinalityVariables)).map(function (_c) {
698
+ var _d = __read(_c, 2), name = _d[0], value = _d[1];
699
+ return ({ name: name, value: value });
700
+ })) });
701
+ };
702
+ var mapAttributes = function (attributes) {
703
+ return attributes.reduce(function (acc, _c) {
704
+ var _d;
705
+ var name = _c.name, value = _c.value;
706
+ return (Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = value, _d)));
707
+ }, {});
708
+ };
709
+ var getAttributes = function (attributes, names) {
710
+ if (names === void 0) { names = []; }
711
+ var filtered = attributes.filter(function (_c) {
712
+ var name = _c.name;
713
+ return names.includes(name);
714
+ });
715
+ return lodash.sortBy(filtered, [function (_c) {
716
+ var name = _c.name;
717
+ return names.indexOf(name);
718
+ }]);
719
+ };
720
+ var upsertAttributes = function (originalAttributes, attributesToUpsert) {
721
+ return attributesToUpsert.reduce(function (acc, _c) {
722
+ var name = _c.name, value = _c.value;
723
+ var _d = __read(getAttributes(acc, [name]), 1), origAttr = _d[0];
724
+ return __spreadArray(__spreadArray([], __read(acc.filter(function (attr) { return attr.name !== name; }))), [
725
+ Object.assign(Object.assign({}, (origAttr !== null && origAttr !== void 0 ? origAttr : { name: name })), { cfgStatus: 'User', value: value }),
726
+ ]);
727
+ }, originalAttributes);
728
+ };
729
+ var patchAttributes = function (rootLineItem, id, attrs) {
730
+ var lineItem = findLineItem(id, [rootLineItem]);
731
+ if (!lineItem) {
732
+ return rootLineItem;
733
+ }
734
+ var attributes = upsertAttributes(lineItem.attributes, attrs);
735
+ return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes: attributes }));
736
+ };
737
+ var getAttributeValue = function (attributes, name) { var _a; return (_a = attributes.find(function (attr) { return attr.name === name; })) === null || _a === void 0 ? void 0 : _a.value; };
738
+ var generateLineItem = function (port, type, parentId, attributes, lineItems) {
739
+ if (attributes === void 0) { attributes = []; }
740
+ if (lineItems === void 0) { lineItems = []; }
741
+ return {
742
+ id: core.UUID.UUID(),
743
+ port: port,
744
+ type: type,
745
+ actionCode: 'ADD',
746
+ cfgStatus: 'New',
747
+ attributes: attributes.map(function (_c) {
748
+ var name = _c.name, value = _c.value;
749
+ return ({ cfgStatus: 'User', name: name, value: value });
750
+ }),
751
+ lineItems: lineItems,
752
+ parentId: parentId,
753
+ qty: 1,
754
+ };
755
+ };
756
+ var getRecommendedPrices = function (portDomain, type) {
757
+ var _a, _b;
758
+ var domainType = portDomain.domainTypes.find(function (_c) {
759
+ var name = _c.name;
760
+ return name === type;
761
+ });
762
+ var _c = __read((_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(function (_c) {
763
+ var chargeMethod = _c.chargeMethod;
764
+ return chargeMethod === 'ONE_TIME';
765
+ }).reduce(function (acc, rp) {
766
+ var _c = __read(acc, 2), netPrice = _c[0], listPrice = _c[1];
767
+ return [netPrice + rp.netPrice, listPrice + rp.listPrice];
768
+ }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0], 2), net = _c[0], list = _c[1];
769
+ return { net: net, list: list };
770
+ };
771
+ var multiplyLineItems = function (lineItem, qty, split) {
772
+ if (split) {
773
+ var unifyIds_1 = function (lineItem) { return (Object.assign(Object.assign({}, lineItem), { id: core.UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds_1) })); };
774
+ return lodash.map(new Array(qty), function () { return unifyIds_1(lineItem); });
775
+ }
776
+ else {
777
+ return [
778
+ Object.assign(Object.assign({}, lineItem), { qty: qty }),
779
+ ];
780
+ }
781
+ };
782
+
783
+ var lineItem_utils = /*#__PURE__*/Object.freeze({
784
+ __proto__: null,
785
+ findLineItem: findLineItem,
786
+ findLineItemWithComparator: findLineItemWithComparator,
787
+ insertLineItem: insertLineItem,
788
+ removeLineItem: removeLineItem,
789
+ replaceLineItem: replaceLineItem,
790
+ calculateCardinalityVariables: calculateCardinalityVariables,
791
+ recalculateCardinalityVariables: recalculateCardinalityVariables,
792
+ mapAttributes: mapAttributes,
793
+ getAttributes: getAttributes,
794
+ upsertAttributes: upsertAttributes,
795
+ patchAttributes: patchAttributes,
796
+ getAttributeValue: getAttributeValue,
797
+ generateLineItem: generateLineItem,
798
+ getRecommendedPrices: getRecommendedPrices,
799
+ multiplyLineItems: multiplyLineItems
800
+ });
801
+
802
+ var LineItemWorker = /** @class */ (function () {
803
+ function LineItemWorker(src) {
804
+ this.li = Object.assign({}, src);
805
+ }
806
+ LineItemWorker.prototype.insert = function (parentId, toInsert) {
807
+ return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
808
+ };
809
+ LineItemWorker.prototype.remove = function (id) {
810
+ return new LineItemWorker(removeLineItem(this.li, id));
811
+ };
812
+ LineItemWorker.prototype.replace = function (toReplace) {
813
+ return new LineItemWorker(replaceLineItem(this.li, toReplace));
814
+ };
815
+ LineItemWorker.prototype.patchAttribute = function (attrs, id) {
816
+ return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
817
+ };
818
+ return LineItemWorker;
819
+ }());
820
+
821
+ var QuoteDraftService = /** @class */ (function () {
822
+ function QuoteDraftService(context, quoteApiService, priceApiService) {
823
+ var _this = this;
824
+ this.context = context;
825
+ this.quoteApiService = quoteApiService;
826
+ this.priceApiService = priceApiService;
827
+ this.quoteSubj$ = new rxjs.BehaviorSubject(null);
828
+ this.resetSubj$ = new rxjs.BehaviorSubject(true);
829
+ this.isInitializedSubj$ = new rxjs.BehaviorSubject(false);
830
+ this.initialCurrentState = [];
831
+ this._hasUnsavedChanges = false;
832
+ this.allPriceLists = [];
833
+ this.assetPriceLists = [];
834
+ this.reset$ = this.resetSubj$.asObservable();
835
+ this.activePriceList$ = this.context.resolve$().pipe(operators.map(function (ctx) { return _this.allPriceLists.find(function (priceList) { return priceList.id === ctx.properties.PriceListId; }); }), operators.map(function (priceList) { return priceList !== null && priceList !== void 0 ? priceList : null; }));
836
+ this.isInitializedSubj$
837
+ .pipe(operators.filter(function (isInitialized) { return isInitialized; }), operators.switchMap(function () { return _this.quoteSubj$.asObservable(); }), operators.skip(1), operators.tap(function (quote) { return _this.markAsUpdated(quote); }))
838
+ .subscribe();
839
+ }
840
+ Object.defineProperty(QuoteDraftService.prototype, "isInitialized", {
620
841
  get: function () {
621
- var _this = this;
622
- return this.quoteDraft$.pipe(operators.map(function () { return _this.activeCurrentState; }));
842
+ return this.isInitializedSubj$.getValue();
843
+ },
844
+ set: function (value) {
845
+ if (this.isInitialized !== value) {
846
+ this.isInitializedSubj$.next(value);
847
+ }
623
848
  },
624
849
  enumerable: false,
625
850
  configurable: true
626
851
  });
627
- Object.defineProperty(QuoteDraftService.prototype, "activeCurrentState", {
628
- /**
629
- * activeCurrentState is currentState passed through additional filters
630
- */
852
+ Object.defineProperty(QuoteDraftService.prototype, "hasUnsavedChanges", {
631
853
  get: function () {
854
+ return this._hasUnsavedChanges;
855
+ },
856
+ set: function (value) {
632
857
  var _a, _b;
633
- var currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
634
- currentState = this.filterByActivePriceList(currentState);
635
- return currentState;
858
+ this._hasUnsavedChanges = value;
859
+ if (!this._hasUnsavedChanges) {
860
+ this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
861
+ }
636
862
  },
637
863
  enumerable: false,
638
864
  configurable: true
639
865
  });
640
- Object.defineProperty(QuoteDraftService.prototype, "activeInitialState$", {
641
- /**
642
- * Stream of activeInitialState
643
- */
866
+ Object.defineProperty(QuoteDraftService.prototype, "hasProducts$", {
644
867
  get: function () {
645
868
  var _this = this;
646
- return this.quoteDraft$.pipe(operators.map(function () { return _this.activeInitialState; }));
647
- },
648
- enumerable: false,
649
- configurable: true
650
- });
651
- Object.defineProperty(QuoteDraftService.prototype, "activeInitialState", {
652
- /**
653
- * activeInitialState is initialState passed through additional filters
654
- */
655
- get: function () {
656
- var _a, _b;
657
- var ctx = this.context.resolve();
658
- var initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
659
- if (ctx.mode === core.ConfigurationContextMode.ACCOUNT) {
660
- initialState = this.filterByActivePriceList(initialState);
661
- }
662
- return initialState;
869
+ return this.quoteSubj$.pipe(operators.map(function () { return _this.hasProducts; }));
663
870
  },
664
871
  enumerable: false,
665
872
  configurable: true
666
873
  });
667
- Object.defineProperty(QuoteDraftService.prototype, "isStandalone", {
874
+ Object.defineProperty(QuoteDraftService.prototype, "hasProducts", {
668
875
  get: function () {
669
- return this.context.resolve().properties.standalone === 'true';
876
+ var quoteDraft = this.quoteSubj$.value;
877
+ return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
670
878
  },
671
879
  enumerable: false,
672
880
  configurable: true
673
881
  });
674
- Object.defineProperty(QuoteDraftService.prototype, "isStandalone$", {
675
- get: function () {
676
- var _this = this;
677
- return this.context.resolve$().pipe(operators.map(function () { return _this.isStandalone; }));
678
- },
679
- enumerable: false,
680
- configurable: true
681
- });
682
- QuoteDraftService.prototype.getInitialCurrentState = function () {
683
- return this.initialCurrentState;
882
+ QuoteDraftService.prototype.reset = function () {
883
+ this.resetSubj$.next(true);
884
+ this.quoteSubj$.next(null);
885
+ this.hasUnsavedChanges = false;
684
886
  };
685
- QuoteDraftService.prototype.isEditMode$ = function () {
887
+ QuoteDraftService.prototype.init = function (quoteId, params) {
686
888
  var _this = this;
687
- return this.context.resolve$().pipe(operators.map(function () { return _this.isEditMode(); }));
889
+ return rxjs.zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(operators.tap(function (_c) {
890
+ var _d = __read(_c, 2), quote = _d[0], allPriceLists = _d[1];
891
+ _this.allPriceLists = allPriceLists;
892
+ _this.quoteSubj$.next(quote);
893
+ _this.context.update(quote.context);
894
+ _this.populateActivePriceLists$();
895
+ }), operators.map(function () { return rxjs.noop(); }), operators.take(1));
688
896
  };
689
- QuoteDraftService.prototype.isEditMode = function () {
690
- var context = this.context.resolve();
691
- if (context.mode === core.ConfigurationContextMode.ACCOUNT) {
692
- return true;
693
- }
694
- if (context.mode === core.ConfigurationContextMode.QUOTE) {
695
- return context.properties.Status === 'Draft';
897
+ QuoteDraftService.prototype.setCurrentLineItemState = function (lineItems) {
898
+ var quoteDraft = this.quoteSubj$.value;
899
+ if (!quoteDraft) {
900
+ return;
696
901
  }
697
- return false;
698
- };
699
- QuoteDraftService.prototype.updateActivePriceList = function (priceListId) {
700
- this.context.update({ properties: { PriceListId: priceListId } });
902
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
701
903
  };
702
- QuoteDraftService.prototype.populateActivePriceLists$ = function () {
703
- var _this = this;
704
- var ctx = this.context.resolve();
705
- var quoteDraft = this.quoteDraft;
904
+ QuoteDraftService.prototype.updateQuoteDraft = function (update) {
905
+ var quoteDraft = this.quoteSubj$.value;
706
906
  if (!quoteDraft) {
707
907
  return;
708
908
  }
709
- // In ACCOUNT mode populate price lists from related assets
710
- if (ctx.mode === core.ConfigurationContextMode.ACCOUNT) {
711
- // Populate list of price lists
712
- this.assetPriceLists = quoteDraft.currentState
713
- .map(function (_c) {
714
- var priceListId = _c.priceListId;
715
- return priceListId;
716
- })
717
- .reduce(function (trunk, priceListId) {
718
- var _a, _b;
719
- if (!priceListId || trunk.some(function (item) { return item.id === priceListId; })) {
720
- return trunk;
721
- }
722
- return __spreadArray(__spreadArray([], __read(trunk)), [
723
- { id: priceListId, name: (_b = (_a = _this.allPriceLists.find(function (item) { return item.id === priceListId; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '' },
724
- ]);
725
- }, []);
909
+ if (update.context) {
910
+ this.context.set(update.context);
726
911
  }
912
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
727
913
  };
728
- QuoteDraftService.prototype.filterByActivePriceList = function (lineItems) {
729
- var ctx = this.context.resolve();
730
- return lineItems.filter(function (li) { return !li.priceListId || li.priceListId === ctx.properties.PriceListId; });
731
- };
732
- QuoteDraftService.prototype.markAsUpdated = function (quote) {
733
- if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === core.ConfigurationContextMode.ACCOUNT) {
734
- this.hasUnsavedChanges = !!quote && !quote.currentState.every(function (li) { return li.actionCode === 'EXIST'; });
735
- }
736
- else {
737
- this.hasUnsavedChanges = !lodash.isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
914
+ QuoteDraftService.prototype.updateByPriceSummary = function (priceSummary) {
915
+ var quoteDraft = this.quoteSubj$.value;
916
+ if (!quoteDraft) {
917
+ return;
738
918
  }
919
+ var updatedCurrentState = this.currentState.map(function (lineItem) {
920
+ var updated = priceSummary.lineItems.find(function (li) { return li.id === lineItem.id; });
921
+ return updated !== null && updated !== void 0 ? updated : lineItem;
922
+ });
923
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
739
924
  };
740
- return QuoteDraftService;
741
- }());
742
- QuoteDraftService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1__namespace.QuoteApiService }, { token: i1__namespace.PriceApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
743
- QuoteDraftService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: QuoteDraftService, providedIn: 'root' });
744
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: QuoteDraftService, decorators: [{
745
- type: i0.Injectable,
746
- args: [{ providedIn: 'root' }]
747
- }], ctorParameters: function () { return [{ type: ContextService }, { type: i1__namespace.QuoteApiService }, { type: i1__namespace.PriceApiService }]; } });
748
-
749
- var MetricsCalculationService = /** @class */ (function () {
750
- function MetricsCalculationService(quoteDraftService, settingsService) {
751
- var _this = this;
752
- this.quoteDraftService = quoteDraftService;
753
- this.settingsService = settingsService;
754
- this.metricsUpdated$ = new rxjs.Subject();
755
- this.quoteMetricsSettings = {};
756
- this.metricsCalculationMethodMap = {};
757
- this.metricsData = {};
758
- rxjs.combineLatest([
759
- this.quoteDraftService.currentState$,
760
- this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(rxjs.take(1)),
761
- ]).subscribe(function (_a) {
762
- var _b = __read(_a, 2), lineItems = _b[0], setting = _b[1];
763
- var settingsData = {};
764
- try {
765
- settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
925
+ Object.defineProperty(QuoteDraftService.prototype, "quoteDraft$", {
926
+ get: function () {
927
+ var _this = this;
928
+ return rxjs.combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(operators.map(function () { return _this.quoteDraft; }), operators.filter(function (quote) { return Boolean(quote); }), operators.shareReplay());
929
+ },
930
+ enumerable: false,
931
+ configurable: true
932
+ });
933
+ Object.defineProperty(QuoteDraftService.prototype, "quoteDraft", {
934
+ get: function () {
935
+ var quote = this.quoteSubj$.value;
936
+ if (!quote) {
937
+ return null;
766
938
  }
767
- catch (error) {
768
- settingsData = {};
939
+ return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
940
+ },
941
+ enumerable: false,
942
+ configurable: true
943
+ });
944
+ Object.defineProperty(QuoteDraftService.prototype, "quoteDraftForActivePriceList", {
945
+ get: function () {
946
+ var quoteDraft = this.quoteDraft;
947
+ if (!quoteDraft) {
948
+ return null;
769
949
  }
770
- _this.quoteMetricsSettings = settingsData;
771
- _this.updateMetrics(lineItems);
772
- });
773
- }
774
- Object.defineProperty(MetricsCalculationService.prototype, "onMetricsUpdate$", {
950
+ return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
951
+ },
952
+ enumerable: false,
953
+ configurable: true
954
+ });
955
+ Object.defineProperty(QuoteDraftService.prototype, "currentState$", {
775
956
  get: function () {
776
- return this.metricsUpdated$.asObservable();
957
+ return this.quoteDraft$.pipe(operators.map(function (quote) { return quote.currentState; }));
777
958
  },
778
959
  enumerable: false,
779
960
  configurable: true
780
961
  });
781
- MetricsCalculationService.prototype.getMetricValue = function (metric) {
782
- return this.metricsData[metric] || 0;
783
- };
784
- MetricsCalculationService.prototype.updateMetrics = function (lineItems) {
785
- var _this = this;
786
- var metricKeys = this.collectMetricKeys(lineItems).filter(function (key) { return !key.includes('Effective_'); });
787
- this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
788
- this.metricsData = metricKeys.reduce(function (acc, key) {
789
- var _a;
790
- return (Object.assign(Object.assign({}, acc), (_a = {}, _a[key] = _this.calculateMetric(lineItems, key), _a)));
791
- }, {});
792
- this.metricsUpdated$.next();
793
- };
794
- MetricsCalculationService.prototype.calculateMetric = function (lineItems, metric) {
795
- return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
796
- };
797
- MetricsCalculationService.prototype.buildMetricsCalculationMethods = function (metricKeys, initial) {
798
- var _this = this;
799
- return metricKeys.reduce(function (acc, name) {
962
+ Object.defineProperty(QuoteDraftService.prototype, "currentState", {
963
+ get: function () {
800
964
  var _a, _b;
801
- if (acc[name]) {
802
- return acc;
803
- }
804
- acc = Object.assign(Object.assign({}, acc), (_a = {}, _a[name] = 'sum', _a));
805
- var settingKey = name.replace(/VDM_|Total_/g, '');
806
- if (_this.quoteMetricsSettings[settingKey]) {
807
- acc = Object.assign(Object.assign({}, acc), (_b = {}, _b[name] = _this.quoteMetricsSettings[settingKey], _b));
808
- }
809
- return acc;
810
- }, initial);
811
- };
812
- MetricsCalculationService.prototype.collectMetricKeys = function (lineItems) {
813
- var _this = this;
814
- var keys = [];
815
- lineItems.forEach(function (lineItem) {
816
- keys.push.apply(keys, __spreadArray([], __read(Object.keys(lineItem.totalMetrics || {}))));
817
- keys.push.apply(keys, __spreadArray([], __read(_this.collectMetricKeys(lineItem.lineItems))));
818
- });
819
- return lodash.uniq(keys);
820
- };
821
- return MetricsCalculationService;
822
- }());
823
- MetricsCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: i1__namespace.ConfigurationSettingsApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
824
- MetricsCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, providedIn: 'root' });
825
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, decorators: [{
826
- type: i0.Injectable,
827
- args: [{ providedIn: 'root' }]
828
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: i1__namespace.ConfigurationSettingsApiService }]; } });
829
-
830
- var ProductImagesService = /** @class */ (function () {
831
- function ProductImagesService(productApiService) {
832
- this.productApiService = productApiService;
833
- this.imagesMap$ = new rxjs.BehaviorSubject({});
834
- }
835
- ProductImagesService.prototype.getImageUrl$ = function (productId) {
836
- var _a;
837
- if (this.imagesMap$.value[productId] == null) {
838
- this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
839
- this.fetchProductImage(productId);
840
- }
841
- return this.imagesMap$.pipe(rxjs.map(function (imagesMap) { return imagesMap[productId]; }), rxjs.distinctUntilChanged());
842
- };
843
- ProductImagesService.prototype.fetchProductImage = function (productId) {
844
- var _this = this;
845
- this.productApiService
846
- .fetchImage$(productId)
847
- .pipe(rxjs.map(function (file) { return URL.createObjectURL(file); }), rxjs.catchError(function () { return rxjs.of(''); }), rxjs.tap(function (url) {
848
- var _a;
849
- return _this.imagesMap$.next(Object.assign(Object.assign({}, _this.imagesMap$.value), (_a = {}, _a[productId] = url, _a)));
850
- }))
851
- .subscribe();
852
- };
853
- return ProductImagesService;
854
- }());
855
- ProductImagesService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, deps: [{ token: i1__namespace.ProductApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
856
- ProductImagesService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, providedIn: 'root' });
857
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, decorators: [{
858
- type: i0.Injectable,
859
- args: [{ providedIn: 'root' }]
860
- }], ctorParameters: function () { return [{ type: i1__namespace.ProductApiService }]; } });
861
-
862
- var RuntimeContextService = /** @class */ (function () {
863
- function RuntimeContextService(configurationApiService) {
864
- this.configurationApiService = configurationApiService;
865
- }
866
- RuntimeContextService.prototype.getRuntimeContext = function (productId, offeringId) {
867
- var _this = this;
868
- return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(operators.map(function (runtimeData) {
869
- var _a, _b, _c;
870
- var uiDefinition = _this.getUIDefinition(runtimeData);
871
- var runtimeModel = core.RuntimeModel.create(runtimeData.types, runtimeData.products);
872
- var _d = (_a = Array.from(runtimeModel.components.values()).find(function (c) { return c.productId === productId; })) !== null && _a !== void 0 ? _a : {}, productName = _d.productName, properties = _d.properties;
873
- return {
874
- modelId: runtimeData.modelId,
875
- uiDefinition: uiDefinition,
876
- runtimeModel: runtimeModel,
877
- runtimeMode: exports.RuntimeMode.PROD,
878
- productId: productId,
879
- productType: (properties === null || properties === void 0 ? void 0 : properties.displayName) || productName,
880
- offeringId: offeringId,
881
- properties: {
882
- PricingEnabled: ((_b = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _b === void 0 ? void 0 : _b.pricingEnabled) ? 'true' : 'false',
883
- PriceListId: (_c = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _c === void 0 ? void 0 : _c.priceList,
884
- },
885
- };
886
- }));
887
- };
888
- RuntimeContextService.prototype.getUIDefinition = function (runtimeData) {
889
- var _a;
890
- var rawUiDefinitions;
891
- try {
892
- rawUiDefinitions = JSON.parse(runtimeData.uiDefinitionsSource);
893
- }
894
- catch (e) {
895
- return;
896
- }
897
- var uiDefinitions = rawUiDefinitions.filter(function (uiDef) { return uiDef.version; });
898
- var uiDefinition = (_a = uiDefinitions.find(function (uiDef) { return uiDef.primary; })) !== null && _a !== void 0 ? _a : uiDefinitions[0];
899
- return uiDefinition;
900
- };
901
- return RuntimeContextService;
902
- }());
903
- RuntimeContextService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: RuntimeContextService, deps: [{ token: i1__namespace.ConfigurationApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
904
- RuntimeContextService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: RuntimeContextService });
905
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: RuntimeContextService, decorators: [{
906
- type: i0.Injectable
907
- }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }]; } });
908
-
909
- var ConfigurationRuntimeService = /** @class */ (function () {
910
- function ConfigurationRuntimeService(apiService, contextService, runtimeContextService) {
911
- this.apiService = apiService;
912
- this.contextService = contextService;
913
- this.runtimeContextService = runtimeContextService;
914
- this._isInitialized = false;
915
- this.uiDefinitionProperties = {};
916
- }
917
- ConfigurationRuntimeService.prototype.reset = function () {
918
- this._isInitialized = false;
919
- this._runtimeContext = undefined;
920
- this._assets = undefined;
921
- this.initializationProps = undefined;
922
- this.uiDefinitionProperties = {};
923
- };
924
- ConfigurationRuntimeService.prototype.initTestMode = function (modelId, uiDefinition) {
925
- var _this = this;
926
- var _a, _b;
927
- this.uiDefinitionProperties = (_a = uiDefinition.properties) !== null && _a !== void 0 ? _a : {};
928
- var uiDefinitionExternals = (_b = uiDefinition.externals) !== null && _b !== void 0 ? _b : {};
929
- return rxjs.combineLatest([
930
- this.apiService.getRuntimeDataByModelId(modelId),
931
- this.contextService.create('TestId', core.ConfigurationContextMode.TEST),
932
- ]).pipe(operators.first(), operators.tap(function (_e) {
933
- var _f = __read(_e, 2), runtimeData = _f[0], context = _f[1];
934
- var _a;
935
- _this._runtimeContext = {
936
- modelId: modelId,
937
- runtimeModel: core.RuntimeModel.create(runtimeData.types, runtimeData.products),
938
- runtimeMode: exports.RuntimeMode.TEST,
939
- };
940
- _this.contextService.update({
941
- properties: Object.assign(Object.assign(Object.assign(Object.assign({}, (_a = _this.runtimeContext) === null || _a === void 0 ? void 0 : _a.properties), context.properties), { ModelId: modelId, RuntimeMode: core.ConfigurationContextMode.TEST, PricingEnabled: _this.uiDefinitionProperties.pricingEnabled ? 'true' : 'false', StartDate: new Date().toISOString().substring(0, 10), PriceListId: _this.uiDefinitionProperties.priceList, standalone: 'true' }), uiDefinitionExternals),
942
- });
943
- _this._isInitialized = true;
944
- }));
945
- };
946
- ConfigurationRuntimeService.prototype.init = function (props) {
947
- var _this = this;
948
- this.initializationProps = props;
949
- this._assets = props.assets;
950
- var context = this.contextService.resolve();
951
- return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(operators.tap(function (runtimeContext) {
952
- var _a, _b, _c, _d;
953
- _this.uiDefinitionProperties = (_b = (_a = runtimeContext.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {};
954
- var PriceListId = ((_c = context.properties) !== null && _c !== void 0 ? _c : {}).PriceListId;
955
- var mergeContext = Object.assign(Object.assign({}, runtimeContext), { properties: Object.assign(Object.assign(Object.assign({}, runtimeContext.properties), context.properties), { PricingEnabled: PriceListId ? 'true' : 'false' }) });
956
- _this.id15to18('AccountId', mergeContext.properties);
957
- _this._runtimeContext = mergeContext;
958
- if (context.properties && ((_d = _this._runtimeContext.properties) === null || _d === void 0 ? void 0 : _d.StartDate)) {
959
- _this.contextService.update({
960
- properties: Object.assign(Object.assign({}, _this._runtimeContext.properties), context.properties),
961
- });
962
- }
963
- _this._isInitialized = true;
964
- }));
965
- };
966
- ConfigurationRuntimeService.prototype.id15to18 = function (propertyName, source) {
967
- if (!source) {
968
- return;
969
- }
970
- var value = source[propertyName];
971
- if (typeof value === 'string' && value.length === 15) {
972
- source[propertyName] = core.SalesforceIdUtils.generateId18FromId15(value);
973
- }
974
- };
975
- ConfigurationRuntimeService.prototype.getAsset = function (lineItem) {
976
- return this._assets && this._assets.find(function (a) { return a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId; });
977
- };
978
- Object.defineProperty(ConfigurationRuntimeService.prototype, "isInitialized", {
965
+ return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
966
+ },
967
+ enumerable: false,
968
+ configurable: true
969
+ });
970
+ Object.defineProperty(QuoteDraftService.prototype, "activeCurrentState$", {
971
+ /**
972
+ * Stream of activeCurrentState
973
+ */
979
974
  get: function () {
980
- return this._isInitialized;
975
+ var _this = this;
976
+ return this.quoteDraft$.pipe(operators.map(function () { return _this.activeCurrentState; }));
981
977
  },
982
978
  enumerable: false,
983
979
  configurable: true
984
980
  });
985
- Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeModel", {
981
+ Object.defineProperty(QuoteDraftService.prototype, "activeCurrentState", {
982
+ /**
983
+ * activeCurrentState is currentState passed through additional filters
984
+ */
986
985
  get: function () {
987
- var _a;
988
- return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
986
+ var _a, _b;
987
+ var currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
988
+ currentState = this.filterByActivePriceList(currentState);
989
+ return currentState;
989
990
  },
990
991
  enumerable: false,
991
992
  configurable: true
992
993
  });
993
- Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeContext", {
994
+ Object.defineProperty(QuoteDraftService.prototype, "activeInitialState$", {
995
+ /**
996
+ * Stream of activeInitialState
997
+ */
994
998
  get: function () {
995
- return this._runtimeContext;
999
+ var _this = this;
1000
+ return this.quoteDraft$.pipe(operators.map(function () { return _this.activeInitialState; }));
996
1001
  },
997
1002
  enumerable: false,
998
1003
  configurable: true
999
1004
  });
1000
- return ConfigurationRuntimeService;
1001
- }());
1002
- ConfigurationRuntimeService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationRuntimeService, deps: [{ token: i1__namespace.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1003
- ConfigurationRuntimeService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationRuntimeService });
1004
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationRuntimeService, decorators: [{
1005
- type: i0.Injectable
1006
- }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
1007
-
1008
- var findLineItem = function (id, lineItems) {
1009
- return findLineItemWithComparator(lineItems, function (li) { return li.id === id; });
1010
- };
1011
- var findLineItemWithComparator = function (lineItems, comparator) {
1012
- var currentLevel = lineItems;
1013
- while (currentLevel.length) {
1014
- var found = currentLevel.find(comparator);
1015
- if (found) {
1016
- return found;
1017
- }
1018
- currentLevel = lodash.flatten(currentLevel.map(function (parent) { return parent.lineItems; }));
1019
- }
1020
- return;
1021
- };
1022
- var insertLineItem = function (lineItem, parentId, toInsert) {
1023
- var insertData = lineItem.id === parentId ? [toInsert] : [];
1024
- return Object.assign(Object.assign({}, lineItem), { lineItems: __spreadArray(__spreadArray([], __read(insertData)), __read(lineItem.lineItems.map(function (li) {
1025
- return insertLineItem(li, parentId, toInsert);
1026
- }))) });
1027
- };
1028
- var removeLineItem = function (lineItem, idToRemove) {
1029
- return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems
1030
- .map(function (li) {
1031
- if (li.id === idToRemove) {
1032
- return;
1033
- }
1034
- else if (li.lineItems.length) {
1035
- return removeLineItem(li, idToRemove);
1036
- }
1037
- return li;
1038
- })
1039
- .filter(function (r) { return !!r; }) });
1040
- };
1041
- var replaceLineItem = function (lineItem, replaceTo) {
1042
- if (lineItem.id === replaceTo.id) {
1043
- return Object.assign({}, replaceTo);
1044
- }
1045
- return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(function (li) {
1046
- if (li.id === replaceTo.id) {
1047
- return replaceTo;
1048
- }
1049
- else if (li.lineItems.length) {
1050
- return replaceLineItem(li, replaceTo);
1005
+ Object.defineProperty(QuoteDraftService.prototype, "activeInitialState", {
1006
+ /**
1007
+ * activeInitialState is initialState passed through additional filters
1008
+ */
1009
+ get: function () {
1010
+ var _a, _b;
1011
+ var ctx = this.context.resolve();
1012
+ var initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
1013
+ if (ctx.mode === core.ConfigurationContextMode.ACCOUNT) {
1014
+ initialState = this.filterByActivePriceList(initialState);
1051
1015
  }
1052
- return li;
1053
- }) });
1054
- };
1055
- var mapAttributes = function (attributes) {
1056
- return attributes.reduce(function (acc, _c) {
1057
- var _d;
1058
- var name = _c.name, value = _c.value;
1059
- return (Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = value, _d)));
1060
- }, {});
1061
- };
1062
- var getAttributes = function (attributes, names) {
1063
- if (names === void 0) { names = []; }
1064
- var filtered = attributes.filter(function (_c) {
1065
- var name = _c.name;
1066
- return names.includes(name);
1016
+ return initialState;
1017
+ },
1018
+ enumerable: false,
1019
+ configurable: true
1067
1020
  });
1068
- return lodash.sortBy(filtered, [function (_c) {
1069
- var name = _c.name;
1070
- return names.indexOf(name);
1071
- }]);
1072
- };
1073
- var upsertAttributes = function (originalAttributes, attributesToUpsert) {
1074
- return attributesToUpsert.reduce(function (acc, _c) {
1075
- var name = _c.name, value = _c.value;
1076
- var _d = __read(getAttributes(acc, [name]), 1), origAttr = _d[0];
1077
- return __spreadArray(__spreadArray([], __read(acc.filter(function (attr) { return attr.name !== name; }))), [
1078
- Object.assign(Object.assign({}, (origAttr !== null && origAttr !== void 0 ? origAttr : { name: name })), { cfgStatus: 'User', value: value }),
1079
- ]);
1080
- }, originalAttributes);
1081
- };
1082
- var patchAttributes = function (rootLineItem, id, attrs) {
1083
- var lineItem = findLineItem(id, [rootLineItem]);
1084
- if (!lineItem) {
1085
- return rootLineItem;
1086
- }
1087
- var attributes = upsertAttributes(lineItem.attributes, attrs);
1088
- return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes: attributes }));
1089
- };
1090
- var getAttributeValue = function (attributes, name) { var _a; return (_a = attributes.find(function (attr) { return attr.name === name; })) === null || _a === void 0 ? void 0 : _a.value; };
1091
- var generateLineItem = function (port, type, parentId, attributes, lineItems) {
1092
- if (attributes === void 0) { attributes = []; }
1093
- if (lineItems === void 0) { lineItems = []; }
1094
- return {
1095
- id: core.UUID.UUID(),
1096
- port: port,
1097
- type: type,
1098
- actionCode: 'ADD',
1099
- cfgStatus: 'New',
1100
- attributes: attributes.map(function (_c) {
1101
- var name = _c.name, value = _c.value;
1102
- return ({ cfgStatus: 'User', name: name, value: value });
1103
- }),
1104
- lineItems: lineItems,
1105
- parentId: parentId,
1106
- qty: 1,
1021
+ Object.defineProperty(QuoteDraftService.prototype, "isStandalone", {
1022
+ get: function () {
1023
+ return this.context.resolve().properties.standalone === 'true';
1024
+ },
1025
+ enumerable: false,
1026
+ configurable: true
1027
+ });
1028
+ Object.defineProperty(QuoteDraftService.prototype, "isStandalone$", {
1029
+ get: function () {
1030
+ var _this = this;
1031
+ return this.context.resolve$().pipe(operators.map(function () { return _this.isStandalone; }));
1032
+ },
1033
+ enumerable: false,
1034
+ configurable: true
1035
+ });
1036
+ QuoteDraftService.prototype.getInitialCurrentState = function () {
1037
+ return this.initialCurrentState;
1038
+ };
1039
+ QuoteDraftService.prototype.isEditMode$ = function () {
1040
+ var _this = this;
1041
+ return this.context.resolve$().pipe(operators.map(function () { return _this.isEditMode(); }));
1042
+ };
1043
+ QuoteDraftService.prototype.isEditMode = function () {
1044
+ var context = this.context.resolve();
1045
+ if (context.mode === core.ConfigurationContextMode.ACCOUNT) {
1046
+ return true;
1047
+ }
1048
+ if (context.mode === core.ConfigurationContextMode.QUOTE) {
1049
+ return context.properties.Status === 'Draft';
1050
+ }
1051
+ return false;
1107
1052
  };
1108
- };
1109
- var getRecommendedPrices = function (portDomain, type) {
1110
- var _a, _b;
1111
- var domainType = portDomain.domainTypes.find(function (_c) {
1112
- var name = _c.name;
1113
- return name === type;
1114
- });
1115
- var _c = __read((_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(function (_c) {
1116
- var chargeMethod = _c.chargeMethod;
1117
- return chargeMethod === 'ONE_TIME';
1118
- }).reduce(function (acc, rp) {
1119
- var _c = __read(acc, 2), netPrice = _c[0], listPrice = _c[1];
1120
- return [netPrice + rp.netPrice, listPrice + rp.listPrice];
1121
- }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0], 2), net = _c[0], list = _c[1];
1122
- return { net: net, list: list };
1123
- };
1124
- var multiplyLineItems = function (lineItem, qty, split) {
1125
- if (split) {
1126
- var unifyIds_1 = function (lineItem) { return (Object.assign(Object.assign({}, lineItem), { id: core.UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds_1) })); };
1127
- return lodash.map(new Array(qty), function () { return unifyIds_1(lineItem); });
1128
- }
1129
- else {
1130
- return [
1131
- Object.assign(Object.assign({}, lineItem), { qty: qty }),
1132
- ];
1133
- }
1134
- };
1135
-
1136
- var lineItem_utils = /*#__PURE__*/Object.freeze({
1137
- __proto__: null,
1138
- findLineItem: findLineItem,
1139
- findLineItemWithComparator: findLineItemWithComparator,
1140
- insertLineItem: insertLineItem,
1141
- removeLineItem: removeLineItem,
1142
- replaceLineItem: replaceLineItem,
1143
- mapAttributes: mapAttributes,
1144
- getAttributes: getAttributes,
1145
- upsertAttributes: upsertAttributes,
1146
- patchAttributes: patchAttributes,
1147
- getAttributeValue: getAttributeValue,
1148
- generateLineItem: generateLineItem,
1149
- getRecommendedPrices: getRecommendedPrices,
1150
- multiplyLineItems: multiplyLineItems
1151
- });
1152
-
1153
- var LineItemWorker = /** @class */ (function () {
1154
- function LineItemWorker(src) {
1155
- this.li = Object.assign({}, src);
1156
- }
1157
- LineItemWorker.prototype.insert = function (parentId, toInsert) {
1158
- return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
1053
+ QuoteDraftService.prototype.updateActivePriceList = function (priceListId) {
1054
+ this.context.update({ properties: { PriceListId: priceListId } });
1159
1055
  };
1160
- LineItemWorker.prototype.remove = function (id) {
1161
- return new LineItemWorker(removeLineItem(this.li, id));
1056
+ QuoteDraftService.prototype.populateActivePriceLists$ = function () {
1057
+ var _this = this;
1058
+ var ctx = this.context.resolve();
1059
+ var quoteDraft = this.quoteDraft;
1060
+ if (!quoteDraft) {
1061
+ return;
1062
+ }
1063
+ // In ACCOUNT mode populate price lists from related assets
1064
+ if (ctx.mode === core.ConfigurationContextMode.ACCOUNT) {
1065
+ // Populate list of price lists
1066
+ this.assetPriceLists = quoteDraft.currentState
1067
+ .map(function (_c) {
1068
+ var priceListId = _c.priceListId;
1069
+ return priceListId;
1070
+ })
1071
+ .reduce(function (trunk, priceListId) {
1072
+ var _a, _b;
1073
+ if (!priceListId || trunk.some(function (item) { return item.id === priceListId; })) {
1074
+ return trunk;
1075
+ }
1076
+ return __spreadArray(__spreadArray([], __read(trunk)), [
1077
+ { id: priceListId, name: (_b = (_a = _this.allPriceLists.find(function (item) { return item.id === priceListId; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '' },
1078
+ ]);
1079
+ }, []);
1080
+ }
1162
1081
  };
1163
- LineItemWorker.prototype.replace = function (toReplace) {
1164
- return new LineItemWorker(replaceLineItem(this.li, toReplace));
1082
+ QuoteDraftService.prototype.filterByActivePriceList = function (lineItems) {
1083
+ var ctx = this.context.resolve();
1084
+ return lineItems.filter(function (li) { return !li.priceListId || li.priceListId === ctx.properties.PriceListId; });
1165
1085
  };
1166
- LineItemWorker.prototype.patchAttribute = function (attrs, id) {
1167
- return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
1086
+ QuoteDraftService.prototype.markAsUpdated = function (quote) {
1087
+ if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === core.ConfigurationContextMode.ACCOUNT) {
1088
+ this.hasUnsavedChanges = !!quote && !quote.currentState.every(function (li) { return li.actionCode === 'EXIST'; });
1089
+ }
1090
+ else {
1091
+ this.hasUnsavedChanges = !lodash.isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
1092
+ }
1168
1093
  };
1169
- return LineItemWorker;
1094
+ return QuoteDraftService;
1170
1095
  }());
1096
+ QuoteDraftService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1__namespace.QuoteApiService }, { token: i1__namespace.PriceApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1097
+ QuoteDraftService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: QuoteDraftService, providedIn: 'root' });
1098
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: QuoteDraftService, decorators: [{
1099
+ type: i0.Injectable,
1100
+ args: [{ providedIn: 'root' }]
1101
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1__namespace.QuoteApiService }, { type: i1__namespace.PriceApiService }]; } });
1171
1102
 
1172
1103
  var ConfigurationService = /** @class */ (function () {
1173
1104
  function ConfigurationService(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
@@ -1178,7 +1109,6 @@
1178
1109
  this.messageService = messageService;
1179
1110
  this.dialogService = dialogService;
1180
1111
  this.mode = core.ConfigurationMode.SEARCH;
1181
- this.states = {};
1182
1112
  this.lineItem = new rxjs.BehaviorSubject(undefined);
1183
1113
  this.charges = new rxjs.BehaviorSubject({});
1184
1114
  this.pricePlans = new rxjs.BehaviorSubject({});
@@ -1187,7 +1117,7 @@
1187
1117
  ConfigurationService.prototype.reset = function () {
1188
1118
  this.hasUnsavedChanges = false;
1189
1119
  this.runtimeService.reset();
1190
- this.states = {};
1120
+ this.configurableRamp = undefined;
1191
1121
  this.lineItem.next(undefined);
1192
1122
  this.charges.next({});
1193
1123
  this.pricePlans.next({});
@@ -1197,10 +1127,7 @@
1197
1127
  if (!this.lineItem.value) {
1198
1128
  return rxjs.throwError(function () { return new Error("Source LineItem not found"); });
1199
1129
  }
1200
- this.states.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem).li;
1201
- this.states.asset = this.states.configurableRamp
1202
- ? this.runtimeService.getAsset(this.states.configurableRamp)
1203
- : undefined;
1130
+ this.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem).li;
1204
1131
  return this.configure().pipe(operators.catchError(function (error) {
1205
1132
  console.error(error);
1206
1133
  if (!_this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
@@ -1218,8 +1145,8 @@
1218
1145
  ConfigurationService.prototype.patch = function (lineItem) {
1219
1146
  this.patch$(lineItem).subscribe();
1220
1147
  };
1221
- ConfigurationService.prototype.updateCurrentStates = function (update) {
1222
- this.states = Object.assign(Object.assign({}, this.states), update);
1148
+ ConfigurationService.prototype.setConfigurableRamp = function (lineItem) {
1149
+ this.configurableRamp = lineItem;
1223
1150
  };
1224
1151
  ConfigurationService.prototype.get = function () {
1225
1152
  return this.lineItem.asObservable().pipe(rxjs.shareReplay());
@@ -1285,7 +1212,7 @@
1285
1212
  }
1286
1213
  var uiDefinitionProperties = Object.assign(Object.assign({}, ((_b = (_a = runtimeContext.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {})), ((_c = this.runtimeService.uiDefinitionProperties) !== null && _c !== void 0 ? _c : {}));
1287
1214
  var qty = (_d = this.runtimeService.initializationProps) === null || _d === void 0 ? void 0 : _d.defaultQty;
1288
- var lineItem = (_e = this.states.configurableRamp) !== null && _e !== void 0 ? _e : getDefaultLineItem(runtimeContext, uiDefinitionProperties, qty);
1215
+ var lineItem = (_e = this.configurableRamp) !== null && _e !== void 0 ? _e : getDefaultLineItem(runtimeContext, uiDefinitionProperties, qty);
1289
1216
  var configurationRequest = this.createRequest(lineItem);
1290
1217
  var mainPricingEnabled = (_f = runtimeContext.properties) === null || _f === void 0 ? void 0 : _f.PricingEnabled;
1291
1218
  var pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
@@ -1305,27 +1232,33 @@
1305
1232
  };
1306
1233
  ConfigurationService.prototype.configureExternal$ = function (productId, qty) {
1307
1234
  var _this = this;
1308
- this.updateCurrentStates({
1309
- currentState: this.quoteDraftService.currentState,
1310
- });
1311
1235
  return this.runtimeService.init({ productId: productId, defaultQty: qty }).pipe(operators.switchMap(function () { return _this.configure(); }), operators.first(), operators.catchError(function (error) {
1312
1236
  _this.messageService.add({ severity: components.ToastType.error, summary: error });
1313
1237
  throw error;
1314
1238
  }), operators.finalize(function () { return _this.reset(); }));
1315
1239
  };
1316
1240
  ConfigurationService.prototype.createRequest = function (lineItem) {
1317
- return {
1241
+ var _a;
1242
+ var request = {
1318
1243
  lineItem: lineItem,
1319
1244
  mode: this.mode,
1320
1245
  step: !this.lineItem.value ? exports.RuntimeStep.START : exports.RuntimeStep.UPDATE,
1321
1246
  attributeDomainMode: 'ALL',
1322
1247
  context: this.contextService.resolve(),
1323
- lineItems: this.states.currentState || [],
1324
- asset: this.states.asset,
1248
+ lineItems: ((_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) || [],
1249
+ asset: this.getAsset(),
1325
1250
  };
1251
+ request = core.ConfigurationTranslatorUtils.lightenConfigurationRequest(request);
1252
+ return request;
1326
1253
  };
1327
1254
  ConfigurationService.prototype.showInactiveProductsConfirmation = function () {
1328
1255
  var _this = this;
1256
+ var confirmationConfig = {
1257
+ title: ' ',
1258
+ description: 'This quote contains inactive products. Do you want to remove them?',
1259
+ primaryButtonLabel: 'Remove products',
1260
+ secondaryButtonLabel: 'Back to Quote',
1261
+ };
1329
1262
  this.dialogService
1330
1263
  .open(components.ConfirmationComponent, {
1331
1264
  dismissableMask: false,
@@ -1334,14 +1267,7 @@
1334
1267
  showHeader: true,
1335
1268
  header: "Inactive Products in Quote",
1336
1269
  width: '440px',
1337
- data: {
1338
- confirmationConfig: {
1339
- title: ' ',
1340
- description: 'This quote contains inactive products. Do you want to remove them?',
1341
- submitBtn: 'Remove products',
1342
- cancelBtn: 'Back to Quote',
1343
- },
1344
- },
1270
+ data: { confirmationConfig: confirmationConfig },
1345
1271
  })
1346
1272
  .onClose.subscribe(function (result) {
1347
1273
  if (!result) {
@@ -1350,18 +1276,34 @@
1350
1276
  }
1351
1277
  });
1352
1278
  };
1279
+ ConfigurationService.prototype.getAsset = function () {
1280
+ var _a;
1281
+ var lineItem = this.configurableRamp;
1282
+ if (!lineItem) {
1283
+ return;
1284
+ }
1285
+ return (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState.find(function (a) { return a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId; });
1286
+ };
1353
1287
  return ConfigurationService;
1354
1288
  }());
1355
- ConfigurationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1__namespace.ConfigurationApiService }, { token: i4__namespace.MessageService }, { token: i5__namespace.DialogService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1356
- ConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationService });
1357
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationService, decorators: [{
1289
+ ConfigurationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1__namespace.ConfigurationApiService }, { token: i5__namespace.MessageService }, { token: i6__namespace.DialogService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1290
+ ConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationService });
1291
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationService, decorators: [{
1358
1292
  type: i0.Injectable
1359
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1__namespace.ConfigurationApiService }, { type: i4__namespace.MessageService }, { type: i5__namespace.DialogService }]; } });
1293
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1__namespace.ConfigurationApiService }, { type: i5__namespace.MessageService }, { type: i6__namespace.DialogService }]; } });
1294
+
1295
+ function extractMetadata(uiDefinition) {
1296
+ return lodash.omit(uiDefinition, [
1297
+ 'children',
1298
+ 'pages',
1299
+ 'components',
1300
+ ]);
1301
+ }
1360
1302
 
1361
1303
  var FlowUpdateService = /** @class */ (function () {
1362
1304
  function FlowUpdateService() {
1363
1305
  }
1364
- FlowUpdateService.prototype.update = function (rootLineItems, updates) {
1306
+ FlowUpdateService.prototype.update = function (rootLineItems, updates, charges) {
1365
1307
  var _this = this;
1366
1308
  var remainingUpdates = __spreadArray([], __read(updates));
1367
1309
  var currentLevel = rootLineItems;
@@ -1372,7 +1314,7 @@
1372
1314
  var updated = false;
1373
1315
  switch (update.dataType) {
1374
1316
  case 'LINEITEM':
1375
- updated = _this.applyLineItemUpdate(li, update);
1317
+ updated = _this.applyLineItemUpdate(li, update, charges);
1376
1318
  break;
1377
1319
  case 'CHARGE':
1378
1320
  updated = _this.applyChargeUpdate(li, update);
@@ -1410,7 +1352,7 @@
1410
1352
  var filtered = lineItems.filter(function (lineItem) { return !idsToRemove.includes(lineItem.id); });
1411
1353
  return filtered.map(function (lineItem) { return new LineItemWorker(lineItem).remove(id).li; });
1412
1354
  };
1413
- FlowUpdateService.prototype.applyLineItemUpdate = function (lineItem, update) {
1355
+ FlowUpdateService.prototype.applyLineItemUpdate = function (lineItem, update, charges) {
1414
1356
  if (lineItem.id !== update.id) {
1415
1357
  return false;
1416
1358
  }
@@ -1426,7 +1368,7 @@
1426
1368
  break;
1427
1369
  case 'PRICE_ADJUSTMENT':
1428
1370
  {
1429
- var _a = __read(lineItem.chargeItems, 1), charge = _a[0];
1371
+ var charge = lineItem.chargeItems.find(function (charge) { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
1430
1372
  if (charge) {
1431
1373
  charge.priceAdjustment = update.newValue;
1432
1374
  }
@@ -1434,7 +1376,7 @@
1434
1376
  break;
1435
1377
  case 'LIST_PRICE_ADJUSTMENT':
1436
1378
  {
1437
- var _b = __read(lineItem.chargeItems, 1), charge = _b[0];
1379
+ var charge = lineItem.chargeItems.find(function (charge) { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
1438
1380
  if (charge) {
1439
1381
  charge.listPriceAdjustment = update.newValue;
1440
1382
  }
@@ -1446,8 +1388,8 @@
1446
1388
  return true;
1447
1389
  };
1448
1390
  FlowUpdateService.prototype.applyChargeUpdate = function (lineItem, update) {
1449
- var foundCharge = lineItem.chargeItems.find(function (_a) {
1450
- var id = _a.id;
1391
+ var foundCharge = lineItem.chargeItems.find(function (_b) {
1392
+ var id = _b.id;
1451
1393
  return id === update.id;
1452
1394
  });
1453
1395
  if (!foundCharge) {
@@ -1482,9 +1424,9 @@
1482
1424
  };
1483
1425
  return FlowUpdateService;
1484
1426
  }());
1485
- FlowUpdateService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowUpdateService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1486
- FlowUpdateService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowUpdateService });
1487
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowUpdateService, decorators: [{
1427
+ FlowUpdateService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1428
+ FlowUpdateService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService });
1429
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService, decorators: [{
1488
1430
  type: i0.Injectable
1489
1431
  }] });
1490
1432
 
@@ -1518,7 +1460,7 @@
1518
1460
  }
1519
1461
  return rxjs.of([]).pipe(rxjs.map(function () {
1520
1462
  var updatedState = lodash.cloneDeep(quoteDraft.currentState);
1521
- _this.updateService.update(updatedState, updates);
1463
+ _this.updateService.update(updatedState, updates, quoteDraft.charges);
1522
1464
  return updatedState;
1523
1465
  }), rxjs.switchMap(function (updatedState) { return _this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState })); }), rxjs.map(function () { return _this.quoteDraftService.quoteDraft; }), this.handleErrorAndBounceBack());
1524
1466
  };
@@ -1678,9 +1620,9 @@
1678
1620
  };
1679
1621
  return FlowConfigurationService;
1680
1622
  }());
1681
- FlowConfigurationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationService, deps: [{ token: i1__namespace.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1682
- FlowConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationService });
1683
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationService, decorators: [{
1623
+ FlowConfigurationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationService, deps: [{ token: i1__namespace.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1624
+ FlowConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationService });
1625
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationService, decorators: [{
1684
1626
  type: i0.Injectable
1685
1627
  }], ctorParameters: function () { return [{ type: i1__namespace.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1686
1628
 
@@ -1689,10 +1631,10 @@
1689
1631
  }
1690
1632
  return FlowConfigurationModule;
1691
1633
  }());
1692
- FlowConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1693
- FlowConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule });
1694
- FlowConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, i1.PriceApiService], imports: [[]] });
1695
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule, decorators: [{
1634
+ FlowConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1635
+ FlowConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule });
1636
+ FlowConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, i1.PriceApiService], imports: [[]] });
1637
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, decorators: [{
1696
1638
  type: i0.NgModule,
1697
1639
  args: [{
1698
1640
  imports: [],
@@ -1705,9 +1647,9 @@
1705
1647
  }
1706
1648
  return ConfigurationModule;
1707
1649
  }());
1708
- ConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1709
- ConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, imports: [components.ConfirmationDialogModule] });
1710
- ConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, providers: [
1650
+ ConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1651
+ ConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, imports: [components.ConfirmationDialogModule] });
1652
+ ConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, providers: [
1711
1653
  i1.ContextApiService,
1712
1654
  i1.ProductModelApiService,
1713
1655
  i1.ConfigurationApiService,
@@ -1715,7 +1657,7 @@
1715
1657
  RuntimeContextService,
1716
1658
  ConfigurationService,
1717
1659
  ], imports: [[components.ConfirmationDialogModule]] });
1718
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, decorators: [{
1660
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, decorators: [{
1719
1661
  type: i0.NgModule,
1720
1662
  args: [{
1721
1663
  imports: [components.ConfirmationDialogModule],
@@ -1730,15 +1672,177 @@
1730
1672
  }]
1731
1673
  }] });
1732
1674
 
1675
+ function calculateMetricByMethod(lineItems, metric, method) {
1676
+ var items = getLineItemsByMethod(lineItems, method);
1677
+ return items.reduce(function (acc, li) {
1678
+ var value = li.reduce(function (accProduct, item) { return accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0); }, 0);
1679
+ if (method === 'avg' && li.length > 0) {
1680
+ value /= li.length;
1681
+ }
1682
+ return acc + value;
1683
+ }, 0);
1684
+ }
1685
+ function getLineItemsByMethod(lineItems, method) {
1686
+ switch (method) {
1687
+ case 'first': {
1688
+ return lineItems.filter(function (li) { return !li.rampInstanceId; }).map(function (item) { return [item]; });
1689
+ }
1690
+ case 'last': {
1691
+ var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
1692
+ var products = rootTermItems.map(function (lineItem) { return __spreadArray([
1693
+ lineItem
1694
+ ], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
1695
+ return products
1696
+ .map(function (items) { return __spreadArray([], __read(items)).sort(function (a, b) { return getDateValue(a.endDate || '') - getDateValue(b.endDate || ''); }).pop(); })
1697
+ .filter(function (li) { return Boolean(li); })
1698
+ .map(function (item) { return [item]; });
1699
+ }
1700
+ case 'avg': {
1701
+ var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
1702
+ return rootTermItems.map(function (lineItem) { return __spreadArray([lineItem], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
1703
+ }
1704
+ case 'sum': {
1705
+ return lineItems.map(function (item) { return [item]; });
1706
+ }
1707
+ default: {
1708
+ return lineItems.map(function (item) { return [item]; });
1709
+ }
1710
+ }
1711
+ }
1712
+ function getDateValue(date) {
1713
+ return date ? new Date(date).getTime() : 0;
1714
+ }
1715
+
1716
+ var MetricsCalculationService = /** @class */ (function () {
1717
+ function MetricsCalculationService(quoteDraftService, flowConfiguration, settingsService) {
1718
+ var _this = this;
1719
+ this.quoteDraftService = quoteDraftService;
1720
+ this.flowConfiguration = flowConfiguration;
1721
+ this.settingsService = settingsService;
1722
+ this.metricsUpdated$ = new rxjs.Subject();
1723
+ this.quoteMetricsSettings = {};
1724
+ this.metricsCalculationMethodMap = {};
1725
+ this.metricsData = {};
1726
+ this.activeMetricRules = [];
1727
+ this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(function (metricRule) { return metricRule.metrics.some(function (metric) { return !!metric.totalName; }); });
1728
+ rxjs.combineLatest([
1729
+ this.quoteDraftService.currentState$,
1730
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(rxjs.take(1)),
1731
+ ]).subscribe(function (_c) {
1732
+ var _d = __read(_c, 2), lineItems = _d[0], setting = _d[1];
1733
+ var settingsData = {};
1734
+ try {
1735
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
1736
+ }
1737
+ catch (error) {
1738
+ settingsData = {};
1739
+ }
1740
+ _this.quoteMetricsSettings = settingsData;
1741
+ _this.updateMetrics(lineItems);
1742
+ });
1743
+ }
1744
+ Object.defineProperty(MetricsCalculationService.prototype, "onMetricsUpdate$", {
1745
+ get: function () {
1746
+ return this.metricsUpdated$.asObservable();
1747
+ },
1748
+ enumerable: false,
1749
+ configurable: true
1750
+ });
1751
+ MetricsCalculationService.prototype.getMetricValue = function (metric) {
1752
+ return this.metricsData[metric] || 0;
1753
+ };
1754
+ MetricsCalculationService.prototype.updateMetrics = function (lineItems) {
1755
+ var _this = this;
1756
+ var metricKeys = this.collectMetricKeys(lineItems).filter(function (key) { return !key.includes('Effective_'); });
1757
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
1758
+ this.metricsData = metricKeys.reduce(function (acc, key) {
1759
+ var _c;
1760
+ return (Object.assign(Object.assign({}, acc), (_c = {}, _c[key] = _this.calculateMetric(lineItems, key), _c)));
1761
+ }, {});
1762
+ this.metricsUpdated$.next();
1763
+ };
1764
+ MetricsCalculationService.prototype.calculateMetric = function (lineItems, metric) {
1765
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
1766
+ };
1767
+ MetricsCalculationService.prototype.buildMetricsCalculationMethods = function (metricKeys, initial) {
1768
+ var _this = this;
1769
+ return metricKeys.reduce(function (acc, name) {
1770
+ var _c, _d;
1771
+ var _a, _b;
1772
+ if (acc[name]) {
1773
+ return acc;
1774
+ }
1775
+ acc = Object.assign(Object.assign({}, acc), (_c = {}, _c[name] = 'sum', _c));
1776
+ var metricRule = _this.getMetricRuleByTotalMetricName(name);
1777
+ var settingKey = ((_b = (_a = metricRule === null || metricRule === void 0 ? void 0 : metricRule.metrics) === null || _a === void 0 ? void 0 : _a.find(function (metric) { return metric.totalName === name; })) === null || _b === void 0 ? void 0 : _b.name) || name;
1778
+ if (_this.quoteMetricsSettings[settingKey]) {
1779
+ acc = Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = _this.quoteMetricsSettings[settingKey], _d));
1780
+ }
1781
+ return acc;
1782
+ }, initial);
1783
+ };
1784
+ MetricsCalculationService.prototype.collectMetricKeys = function (lineItems) {
1785
+ var _this = this;
1786
+ var keys = [];
1787
+ lineItems.forEach(function (lineItem) {
1788
+ keys.push.apply(keys, __spreadArray([], __read(Object.keys(lineItem.totalMetrics || {}))));
1789
+ keys.push.apply(keys, __spreadArray([], __read(_this.collectMetricKeys(lineItem.lineItems))));
1790
+ });
1791
+ return lodash.uniq(keys);
1792
+ };
1793
+ MetricsCalculationService.prototype.getMetricRuleByTotalMetricName = function (name) {
1794
+ return this.activeMetricRules.find(function (metricRule) { return metricRule.metrics.find(function (metric) { return metric.totalName === name; }); });
1795
+ };
1796
+ return MetricsCalculationService;
1797
+ }());
1798
+ MetricsCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: FlowConfigurationService }, { token: i1__namespace.ConfigurationSettingsApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1799
+ MetricsCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: MetricsCalculationService, providedIn: 'root' });
1800
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: MetricsCalculationService, decorators: [{
1801
+ type: i0.Injectable,
1802
+ args: [{ providedIn: 'root' }]
1803
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1__namespace.ConfigurationSettingsApiService }]; } });
1804
+
1805
+ var ProductImagesService = /** @class */ (function () {
1806
+ function ProductImagesService(productApiService) {
1807
+ this.productApiService = productApiService;
1808
+ this.imagesMap$ = new rxjs.BehaviorSubject({});
1809
+ }
1810
+ ProductImagesService.prototype.getImageUrl$ = function (productId) {
1811
+ var _a;
1812
+ if (this.imagesMap$.value[productId] == null) {
1813
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
1814
+ this.fetchProductImage(productId);
1815
+ }
1816
+ return this.imagesMap$.pipe(rxjs.map(function (imagesMap) { return imagesMap[productId]; }), rxjs.distinctUntilChanged());
1817
+ };
1818
+ ProductImagesService.prototype.fetchProductImage = function (productId) {
1819
+ var _this = this;
1820
+ this.productApiService
1821
+ .fetchImage$(productId)
1822
+ .pipe(rxjs.map(function (file) { return URL.createObjectURL(file); }), rxjs.catchError(function () { return rxjs.of(''); }), rxjs.tap(function (url) {
1823
+ var _a;
1824
+ return _this.imagesMap$.next(Object.assign(Object.assign({}, _this.imagesMap$.value), (_a = {}, _a[productId] = url, _a)));
1825
+ }))
1826
+ .subscribe();
1827
+ };
1828
+ return ProductImagesService;
1829
+ }());
1830
+ ProductImagesService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ProductImagesService, deps: [{ token: i1__namespace.ProductApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1831
+ ProductImagesService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ProductImagesService, providedIn: 'root' });
1832
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ProductImagesService, decorators: [{
1833
+ type: i0.Injectable,
1834
+ args: [{ providedIn: 'root' }]
1835
+ }], ctorParameters: function () { return [{ type: i1__namespace.ProductApiService }]; } });
1836
+
1733
1837
  var SdkCoreModule = /** @class */ (function () {
1734
1838
  function SdkCoreModule() {
1735
1839
  }
1736
1840
  return SdkCoreModule;
1737
1841
  }());
1738
- SdkCoreModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1739
- SdkCoreModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1740
- SdkCoreModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1741
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, decorators: [{
1842
+ SdkCoreModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1843
+ SdkCoreModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1844
+ SdkCoreModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1845
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, decorators: [{
1742
1846
  type: i0.NgModule,
1743
1847
  args: [{
1744
1848
  imports: [ConfigurationModule, FlowConfigurationModule],
@@ -1761,6 +1865,9 @@
1761
1865
  exports.ProductImagesService = ProductImagesService;
1762
1866
  exports.QuoteDraftService = QuoteDraftService;
1763
1867
  exports.SdkCoreModule = SdkCoreModule;
1868
+ exports.UI_DEFINITION_VERSION = UI_DEFINITION_VERSION;
1869
+ exports.calculateCardinalityVariables = calculateCardinalityVariables;
1870
+ exports.extractMetadata = extractMetadata;
1764
1871
  exports.findLineItem = findLineItem;
1765
1872
  exports.findLineItemWithComparator = findLineItemWithComparator;
1766
1873
  exports.generateLineItem = generateLineItem;
@@ -1773,6 +1880,7 @@
1773
1880
  exports.mapAttributes = mapAttributes;
1774
1881
  exports.multiplyLineItems = multiplyLineItems;
1775
1882
  exports.patchAttributes = patchAttributes;
1883
+ exports.recalculateCardinalityVariables = recalculateCardinalityVariables;
1776
1884
  exports.removeLineItem = removeLineItem;
1777
1885
  exports.replaceLineItem = replaceLineItem;
1778
1886
  exports.upsertAttributes = upsertAttributes;