@veloceapps/sdk 6.0.0-5 → 6.0.0-51

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. package/bundles/veloceapps-sdk-cms.umd.js +1248 -823
  2. package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
  3. package/bundles/veloceapps-sdk-core.umd.js +735 -610
  4. package/bundles/veloceapps-sdk-core.umd.js.map +1 -1
  5. package/bundles/veloceapps-sdk-runtime.umd.js +209 -142
  6. package/bundles/veloceapps-sdk-runtime.umd.js.map +1 -1
  7. package/bundles/veloceapps-sdk.umd.js +371 -299
  8. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  9. package/cms/components/element-children/element-children.component.d.ts +13 -3
  10. package/cms/components/element-children/element-children.module.d.ts +4 -2
  11. package/cms/components/element-drop-handle/element-drop-handle.component.d.ts +12 -0
  12. package/cms/components/element-drop-handle/element-drop-handle.module.d.ts +9 -0
  13. package/cms/components/element-renderer/element-renderer.component.d.ts +3 -3
  14. package/cms/components/preview/index.d.ts +1 -0
  15. package/cms/components/preview/preview.component.d.ts +9 -8
  16. package/cms/components/preview/preview.module.d.ts +2 -1
  17. package/cms/components/preview/preview.types.d.ts +11 -0
  18. package/cms/index.d.ts +2 -0
  19. package/cms/launcher.module.d.ts +3 -1
  20. package/cms/modules/migrations/index.d.ts +2 -0
  21. package/cms/modules/migrations/migrations.d.ts +2 -0
  22. package/cms/modules/migrations/migrations.module.d.ts +6 -0
  23. package/cms/modules/migrations/services/migrations.service.d.ts +10 -0
  24. package/cms/modules/migrations/types/migrations.types.d.ts +2 -0
  25. package/cms/modules/runtime/index.d.ts +2 -0
  26. package/cms/modules/runtime/runtime.module.d.ts +8 -0
  27. package/cms/modules/runtime/services/compilation.service.d.ts +18 -0
  28. package/cms/modules/runtime/services/runtime-editor.service.d.ts +18 -0
  29. package/cms/modules/runtime/services/runtime.service.d.ts +27 -0
  30. package/cms/modules/runtime/tokens.d.ts +3 -0
  31. package/cms/{types → modules/runtime/types}/compilation.types.d.ts +1 -1
  32. package/cms/modules/runtime/types/runtime.actions.d.ts +9 -0
  33. package/cms/services/index.d.ts +0 -1
  34. package/cms/services/io-provider.service.d.ts +3 -3
  35. package/cms/types/common.types.d.ts +1 -1
  36. package/cms/types/configuration.types.d.ts +1 -0
  37. package/cms/types/index.d.ts +1 -1
  38. package/cms/utils/elements-resolver.d.ts +3 -2
  39. package/cms/utils/index.d.ts +1 -0
  40. package/cms/utils/path.utils.d.ts +0 -1
  41. package/cms/utils/ui-definition.utils.d.ts +6 -0
  42. package/cms/vendor-map.d.ts +40 -25
  43. package/core/modules/configuration/services/configuration-runtime.service.d.ts +2 -4
  44. package/core/modules/configuration/services/configuration.service.d.ts +6 -4
  45. package/core/modules/configuration/types/configuration-runtime.types.d.ts +0 -2
  46. package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +6 -3
  47. package/core/services/metric-calculation/metric-calculation.service.d.ts +5 -1
  48. package/core/services/quote-draft.service.d.ts +2 -2
  49. package/core/types/index.d.ts +0 -1
  50. package/core/types/ui-definition.types.d.ts +19 -4
  51. package/core/utils/index.d.ts +1 -0
  52. package/core/utils/line-item.utils.d.ts +2 -0
  53. package/core/utils/ui-definition.utils.d.ts +2 -0
  54. package/esm2015/cms/components/element-children/element-children.component.js +24 -8
  55. package/esm2015/cms/components/element-children/element-children.module.js +8 -6
  56. package/esm2015/cms/components/element-drop-handle/element-drop-handle.component.js +32 -0
  57. package/esm2015/cms/components/element-drop-handle/element-drop-handle.module.js +19 -0
  58. package/esm2015/cms/components/element-renderer/element-renderer.component.js +9 -9
  59. package/esm2015/cms/components/element-renderer/element-renderer.module.js +4 -4
  60. package/esm2015/cms/components/plugin.component.js +3 -3
  61. package/esm2015/cms/components/preview/index.js +2 -1
  62. package/esm2015/cms/components/preview/preview.component.js +21 -36
  63. package/esm2015/cms/components/preview/preview.module.js +7 -6
  64. package/esm2015/cms/components/preview/preview.types.js +2 -0
  65. package/esm2015/cms/directives/custom-template.directive.js +3 -3
  66. package/esm2015/cms/index.js +3 -1
  67. package/esm2015/cms/launcher.module.js +10 -9
  68. package/esm2015/cms/modules/federated/federated.component.js +3 -3
  69. package/esm2015/cms/modules/federated/federated.module.js +4 -4
  70. package/esm2015/cms/modules/migrations/index.js +3 -0
  71. package/esm2015/cms/modules/migrations/migrations.js +11 -0
  72. package/esm2015/cms/modules/migrations/migrations.module.js +15 -0
  73. package/esm2015/cms/modules/migrations/services/migrations.service.js +43 -0
  74. package/esm2015/cms/modules/migrations/types/migrations.types.js +2 -0
  75. package/esm2015/cms/modules/runtime/index.js +3 -0
  76. package/esm2015/cms/modules/runtime/runtime.module.js +32 -0
  77. package/esm2015/cms/modules/runtime/services/compilation.service.js +84 -0
  78. package/esm2015/cms/modules/runtime/services/runtime-editor.service.js +27 -0
  79. package/esm2015/cms/modules/runtime/services/runtime.service.js +74 -0
  80. package/esm2015/cms/modules/runtime/tokens.js +3 -0
  81. package/esm2015/cms/modules/runtime/types/compilation.types.js +2 -0
  82. package/esm2015/cms/modules/runtime/types/runtime.actions.js +2 -0
  83. package/esm2015/cms/plugins/configuration.plugin.js +12 -4
  84. package/esm2015/cms/plugins/io.plugin.js +3 -3
  85. package/esm2015/cms/plugins/script.plugin.js +3 -3
  86. package/esm2015/cms/services/element-context.service.js +3 -3
  87. package/esm2015/cms/services/index.js +1 -2
  88. package/esm2015/cms/services/integration.state.js +3 -3
  89. package/esm2015/cms/services/io-provider.service.js +9 -9
  90. package/esm2015/cms/services/templates.service.js +3 -3
  91. package/esm2015/cms/types/common.types.js +1 -1
  92. package/esm2015/cms/types/configuration.types.js +1 -1
  93. package/esm2015/cms/types/index.js +2 -2
  94. package/esm2015/cms/utils/elements-resolver.js +18 -8
  95. package/esm2015/cms/utils/index.js +2 -1
  96. package/esm2015/cms/utils/path.utils.js +2 -13
  97. package/esm2015/cms/utils/ui-definition.utils.js +82 -0
  98. package/esm2015/cms/vendor-map.js +21 -10
  99. package/esm2015/core/core.module.js +4 -4
  100. package/esm2015/core/modules/configuration/configuration.module.js +4 -4
  101. package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +5 -10
  102. package/esm2015/core/modules/configuration/services/configuration.service.js +27 -24
  103. package/esm2015/core/modules/configuration/services/runtime-context.service.js +3 -3
  104. package/esm2015/core/modules/configuration/types/configuration-runtime.types.js +1 -1
  105. package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +4 -4
  106. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +17 -9
  107. package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +3 -3
  108. package/esm2015/core/services/context.service.js +3 -3
  109. package/esm2015/core/services/metric-calculation/metric-calculation.service.js +18 -9
  110. package/esm2015/core/services/product-images.service.js +3 -3
  111. package/esm2015/core/services/quote-draft.service.js +7 -7
  112. package/esm2015/core/types/index.js +1 -2
  113. package/esm2015/core/types/ui-definition.types.js +2 -2
  114. package/esm2015/core/utils/index.js +2 -1
  115. package/esm2015/core/utils/line-item.utils.js +27 -11
  116. package/esm2015/core/utils/ui-definition.utils.js +9 -0
  117. package/esm2015/runtime/components/component-preview/component-preview.component.js +4 -4
  118. package/esm2015/runtime/components/section-renderer/section-renderer.component.js +3 -3
  119. package/esm2015/runtime/components/ui-runtime/runtime.component.js +3 -3
  120. package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
  121. package/esm2015/runtime/execution/components/children-placeholder/children-placeholder.component.js +6 -6
  122. package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +3 -3
  123. package/esm2015/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.js +3 -3
  124. package/esm2015/runtime/execution/components/federated/federated.component.js +3 -3
  125. package/esm2015/runtime/execution/components/velo-attribute/velo-attribute.component.js +3 -3
  126. package/esm2015/runtime/execution/components/velo-multiselect/velo-multiselect.component.js +3 -3
  127. package/esm2015/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.js +3 -3
  128. package/esm2015/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.js +3 -3
  129. package/esm2015/runtime/execution/components/velo-port-radio/velo-port-radio.component.js +3 -3
  130. package/esm2015/runtime/execution/components/velo-type/velo-type.component.js +3 -3
  131. package/esm2015/runtime/execution/directives/section-script.directive.js +3 -3
  132. package/esm2015/runtime/execution/directives/sf-query.directive.js +3 -3
  133. package/esm2015/runtime/execution/directives/velo-attribute.directive.js +3 -3
  134. package/esm2015/runtime/execution/directives/velo-port.directive.js +18 -18
  135. package/esm2015/runtime/execution/directives/vl-approval.directive.js +3 -3
  136. package/esm2015/runtime/execution/directives/vl-document-attachments.directive.js +3 -3
  137. package/esm2015/runtime/execution/directives/vl-document-templates.directive.js +3 -3
  138. package/esm2015/runtime/execution/directives/vl-quote.directive.js +4 -4
  139. package/esm2015/runtime/execution/directives/vl-ramp.directive.js +3 -3
  140. package/esm2015/runtime/execution/runtime-execution.module.js +4 -4
  141. package/esm2015/runtime/runtime.module.js +4 -4
  142. package/esm2015/runtime/services/cart.service.js +3 -3
  143. package/esm2015/runtime/services/collapsible-state.service.js +3 -3
  144. package/esm2015/runtime/services/configuration.service.js +4 -4
  145. package/esm2015/runtime/services/current-state.service.js +3 -3
  146. package/esm2015/runtime/services/form-scope.service.js +3 -3
  147. package/esm2015/runtime/services/product-model-cache.service.js +3 -3
  148. package/esm2015/runtime/services/runtime-context.service.js +3 -3
  149. package/esm2015/runtime/services/runtime-form.service.js +3 -3
  150. package/esm2015/runtime/services/runtime.service.js +4 -4
  151. package/esm2015/runtime/services/section-helper.service.js +3 -3
  152. package/esm2015/runtime/services/section-scope.service.js +3 -3
  153. package/esm2015/runtime/services/section-store.service.js +3 -3
  154. package/esm2015/runtime/services/section.service.js +6 -6
  155. package/esm2015/runtime/types/index.js +2 -1
  156. package/esm2015/runtime/types/quote-states.types.js +2 -0
  157. package/esm2015/src/components/dialog/dialog.component.js +3 -3
  158. package/esm2015/src/components/dialog/dialog.module.js +4 -4
  159. package/esm2015/src/components/doc-gen/doc-gen.component.js +3 -3
  160. package/esm2015/src/components/doc-gen/doc-gen.module.js +4 -4
  161. package/esm2015/src/components/header/cart-overlay/cart-preview.component.js +3 -3
  162. package/esm2015/src/components/header/cart-overlay/cart-preview.module.js +4 -4
  163. package/esm2015/src/components/header/header.component.js +20 -12
  164. package/esm2015/src/components/header/header.module.js +4 -4
  165. package/esm2015/src/components/header/metrics/metrics.component.js +79 -67
  166. package/esm2015/src/components/header/metrics/metrics.definitions.js +1 -8
  167. package/esm2015/src/components/header/metrics/metrics.module.js +4 -4
  168. package/esm2015/src/flow-routing.module.js +4 -4
  169. package/esm2015/src/flow.component.js +3 -3
  170. package/esm2015/src/flow.module.js +4 -4
  171. package/esm2015/src/guards/context.guard.js +3 -3
  172. package/esm2015/src/guards/product-unload.guard.js +3 -3
  173. package/esm2015/src/guards/root.guard.js +3 -3
  174. package/esm2015/src/pages/catalog/catalog.component.js +3 -3
  175. package/esm2015/src/pages/catalog/catalog.module.js +4 -4
  176. package/esm2015/src/pages/debug/debug.component.js +3 -3
  177. package/esm2015/src/pages/debug/debug.module.js +4 -4
  178. package/esm2015/src/pages/empty-account/empty-account.component.js +3 -3
  179. package/esm2015/src/pages/empty-account/empty-account.module.js +4 -4
  180. package/esm2015/src/pages/legacy-product/legacy-product.component.js +4 -4
  181. package/esm2015/src/pages/legacy-product/legacy-product.module.js +4 -4
  182. package/esm2015/src/pages/product/product.component.js +5 -12
  183. package/esm2015/src/pages/product/product.module.js +4 -4
  184. package/esm2015/src/pages/record-not-found/record-not-found.component.js +3 -3
  185. package/esm2015/src/pages/record-not-found/record-not-found.module.js +4 -4
  186. package/esm2015/src/pages/remote/remote.component.js +5 -8
  187. package/esm2015/src/pages/remote/remote.module.js +4 -4
  188. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +3 -3
  189. package/esm2015/src/pages/shopping-cart/shopping-cart.module.js +4 -4
  190. package/esm2015/src/resolvers/flow.resolver.js +3 -3
  191. package/esm2015/src/resolvers/quote.resolver.js +8 -8
  192. package/esm2015/src/services/doc-gen.service.js +3 -3
  193. package/esm2015/src/services/flow-dialog.service.js +3 -3
  194. package/esm2015/src/services/flow-router.service.js +3 -3
  195. package/esm2015/src/services/flow.service.js +3 -3
  196. package/esm2015/src/utils/flow.utils.js +3 -3
  197. package/fesm2015/veloceapps-sdk-cms.js +1041 -731
  198. package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
  199. package/fesm2015/veloceapps-sdk-core.js +557 -517
  200. package/fesm2015/veloceapps-sdk-core.js.map +1 -1
  201. package/fesm2015/veloceapps-sdk-runtime.js +138 -138
  202. package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
  203. package/fesm2015/veloceapps-sdk.js +256 -252
  204. package/fesm2015/veloceapps-sdk.js.map +1 -1
  205. package/package.json +5 -3
  206. package/runtime/services/configuration.service.d.ts +2 -1
  207. package/runtime/services/runtime.service.d.ts +2 -1
  208. package/runtime/types/index.d.ts +1 -0
  209. package/src/components/header/header.component.d.ts +4 -2
  210. package/src/components/header/metrics/metrics.component.d.ts +15 -6
  211. package/src/components/header/metrics/metrics.definitions.d.ts +0 -3
  212. package/src/pages/product/product.component.d.ts +0 -1
  213. package/cms/services/dynamic-module.service.d.ts +0 -15
  214. package/cms/services/launcher.service.d.ts +0 -18
  215. package/esm2015/cms/services/dynamic-module.service.js +0 -33
  216. package/esm2015/cms/services/launcher.service.js +0 -58
  217. package/esm2015/cms/types/compilation.types.js +0 -2
  218. package/esm2015/core/types/quote-states.types.js +0 -2
  219. /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,576 +485,135 @@
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() });
586
- },
587
- enumerable: false,
588
- configurable: true
589
- });
590
- Object.defineProperty(QuoteDraftService.prototype, "quoteDraftForActivePriceList", {
591
- 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) });
597
- },
598
- enumerable: false,
599
- configurable: true
600
- });
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
607
- });
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
615
- });
616
- Object.defineProperty(QuoteDraftService.prototype, "activeCurrentState$", {
617
- /**
618
- * Stream of activeCurrentState
619
- */
620
- get: function () {
621
- var _this = this;
622
- return this.quoteDraft$.pipe(operators.map(function () { return _this.activeCurrentState; }));
623
- },
624
- enumerable: false,
625
- configurable: true
626
- });
627
- Object.defineProperty(QuoteDraftService.prototype, "activeCurrentState", {
628
- /**
629
- * activeCurrentState is currentState passed through additional filters
630
- */
631
- get: function () {
632
- 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;
636
- },
637
- enumerable: false,
638
- configurable: true
639
- });
640
- Object.defineProperty(QuoteDraftService.prototype, "activeInitialState$", {
641
- /**
642
- * Stream of activeInitialState
643
- */
644
- get: function () {
645
- 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;
663
- },
664
- enumerable: false,
665
- configurable: true
666
- });
667
- Object.defineProperty(QuoteDraftService.prototype, "isStandalone", {
668
- get: function () {
669
- return this.context.resolve().properties.standalone === 'true';
670
- },
671
- enumerable: false,
672
- configurable: true
673
- });
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;
684
- };
685
- QuoteDraftService.prototype.isEditMode$ = function () {
686
- var _this = this;
687
- return this.context.resolve$().pipe(operators.map(function () { return _this.isEditMode(); }));
688
- };
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';
696
- }
697
- return false;
698
- };
699
- QuoteDraftService.prototype.updateActivePriceList = function (priceListId) {
700
- this.context.update({ properties: { PriceListId: priceListId } });
701
- };
702
- QuoteDraftService.prototype.populateActivePriceLists$ = function () {
703
- var _this = this;
704
- var ctx = this.context.resolve();
705
- var quoteDraft = this.quoteDraft;
706
- if (!quoteDraft) {
707
- return;
708
- }
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
- }, []);
726
- }
727
- };
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);
738
- }
739
- };
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) || '{}');
766
- }
767
- catch (error) {
768
- settingsData = {};
769
- }
770
- _this.quoteMetricsSettings = settingsData;
771
- _this.updateMetrics(lineItems);
772
- });
773
- }
774
- Object.defineProperty(MetricsCalculationService.prototype, "onMetricsUpdate$", {
775
- get: function () {
776
- return this.metricsUpdated$.asObservable();
777
- },
778
- enumerable: false,
779
- configurable: true
780
- });
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) {
800
- 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", {
979
- get: function () {
980
- return this._isInitialized;
981
- },
982
- enumerable: false,
983
- configurable: true
984
- });
985
- Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeModel", {
986
- get: function () {
987
- var _a;
988
- return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
615
+ var _a;
616
+ return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
989
617
  },
990
618
  enumerable: false,
991
619
  configurable: true
@@ -999,9 +627,9 @@
999
627
  });
1000
628
  return ConfigurationRuntimeService;
1001
629
  }());
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: [{
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: [{
1005
633
  type: i0.Injectable
1006
634
  }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
1007
635
 
@@ -1040,17 +668,36 @@
1040
668
  };
1041
669
  var replaceLineItem = function (lineItem, replaceTo) {
1042
670
  if (lineItem.id === replaceTo.id) {
1043
- return Object.assign({}, replaceTo);
671
+ return Object.assign({}, recalculateCardinalityVariables(lineItem, replaceTo));
1044
672
  }
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);
1051
- }
1052
- return li;
1053
- }) });
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);
681
+ });
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
+ }
696
+ });
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
+ })) });
1054
701
  };
1055
702
  var mapAttributes = function (attributes) {
1056
703
  return attributes.reduce(function (acc, _c) {
@@ -1140,6 +787,8 @@
1140
787
  insertLineItem: insertLineItem,
1141
788
  removeLineItem: removeLineItem,
1142
789
  replaceLineItem: replaceLineItem,
790
+ calculateCardinalityVariables: calculateCardinalityVariables,
791
+ recalculateCardinalityVariables: recalculateCardinalityVariables,
1143
792
  mapAttributes: mapAttributes,
1144
793
  getAttributes: getAttributes,
1145
794
  upsertAttributes: upsertAttributes,
@@ -1157,17 +806,299 @@
1157
806
  LineItemWorker.prototype.insert = function (parentId, toInsert) {
1158
807
  return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
1159
808
  };
1160
- LineItemWorker.prototype.remove = function (id) {
1161
- return new LineItemWorker(removeLineItem(this.li, id));
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", {
841
+ get: function () {
842
+ return this.isInitializedSubj$.getValue();
843
+ },
844
+ set: function (value) {
845
+ if (this.isInitialized !== value) {
846
+ this.isInitializedSubj$.next(value);
847
+ }
848
+ },
849
+ enumerable: false,
850
+ configurable: true
851
+ });
852
+ Object.defineProperty(QuoteDraftService.prototype, "hasUnsavedChanges", {
853
+ get: function () {
854
+ return this._hasUnsavedChanges;
855
+ },
856
+ set: function (value) {
857
+ var _a, _b;
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
+ }
862
+ },
863
+ enumerable: false,
864
+ configurable: true
865
+ });
866
+ Object.defineProperty(QuoteDraftService.prototype, "hasProducts$", {
867
+ get: function () {
868
+ var _this = this;
869
+ return this.quoteSubj$.pipe(operators.map(function () { return _this.hasProducts; }));
870
+ },
871
+ enumerable: false,
872
+ configurable: true
873
+ });
874
+ Object.defineProperty(QuoteDraftService.prototype, "hasProducts", {
875
+ get: function () {
876
+ var quoteDraft = this.quoteSubj$.value;
877
+ return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
878
+ },
879
+ enumerable: false,
880
+ configurable: true
881
+ });
882
+ QuoteDraftService.prototype.reset = function () {
883
+ this.resetSubj$.next(true);
884
+ this.quoteSubj$.next(null);
885
+ this.hasUnsavedChanges = false;
886
+ };
887
+ QuoteDraftService.prototype.init = function (quoteId, params) {
888
+ var _this = this;
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));
896
+ };
897
+ QuoteDraftService.prototype.setCurrentLineItemState = function (lineItems) {
898
+ var quoteDraft = this.quoteSubj$.value;
899
+ if (!quoteDraft) {
900
+ return;
901
+ }
902
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
903
+ };
904
+ QuoteDraftService.prototype.updateQuoteDraft = function (update) {
905
+ var quoteDraft = this.quoteSubj$.value;
906
+ if (!quoteDraft) {
907
+ return;
908
+ }
909
+ if (update.context) {
910
+ this.context.set(update.context);
911
+ }
912
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
913
+ };
914
+ QuoteDraftService.prototype.updateByPriceSummary = function (priceSummary) {
915
+ var quoteDraft = this.quoteSubj$.value;
916
+ if (!quoteDraft) {
917
+ return;
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 }));
924
+ };
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;
938
+ }
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;
949
+ }
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$", {
956
+ get: function () {
957
+ return this.quoteDraft$.pipe(operators.map(function (quote) { return quote.currentState; }));
958
+ },
959
+ enumerable: false,
960
+ configurable: true
961
+ });
962
+ Object.defineProperty(QuoteDraftService.prototype, "currentState", {
963
+ get: function () {
964
+ var _a, _b;
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
+ */
974
+ get: function () {
975
+ var _this = this;
976
+ return this.quoteDraft$.pipe(operators.map(function () { return _this.activeCurrentState; }));
977
+ },
978
+ enumerable: false,
979
+ configurable: true
980
+ });
981
+ Object.defineProperty(QuoteDraftService.prototype, "activeCurrentState", {
982
+ /**
983
+ * activeCurrentState is currentState passed through additional filters
984
+ */
985
+ get: function () {
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;
990
+ },
991
+ enumerable: false,
992
+ configurable: true
993
+ });
994
+ Object.defineProperty(QuoteDraftService.prototype, "activeInitialState$", {
995
+ /**
996
+ * Stream of activeInitialState
997
+ */
998
+ get: function () {
999
+ var _this = this;
1000
+ return this.quoteDraft$.pipe(operators.map(function () { return _this.activeInitialState; }));
1001
+ },
1002
+ enumerable: false,
1003
+ configurable: true
1004
+ });
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);
1015
+ }
1016
+ return initialState;
1017
+ },
1018
+ enumerable: false,
1019
+ configurable: true
1020
+ });
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(); }));
1162
1042
  };
1163
- LineItemWorker.prototype.replace = function (toReplace) {
1164
- return new LineItemWorker(replaceLineItem(this.li, toReplace));
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;
1165
1052
  };
1166
- LineItemWorker.prototype.patchAttribute = function (attrs, id) {
1167
- return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
1053
+ QuoteDraftService.prototype.updateActivePriceList = function (priceListId) {
1054
+ this.context.update({ properties: { PriceListId: priceListId } });
1168
1055
  };
1169
- return LineItemWorker;
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
+ }
1081
+ };
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; });
1085
+ };
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
+ }
1093
+ };
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,23 +1232,21 @@
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) {
1241
+ var _a;
1317
1242
  return {
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
  };
1326
1251
  };
1327
1252
  ConfigurationService.prototype.showInactiveProductsConfirmation = function () {
@@ -1350,13 +1275,29 @@
1350
1275
  }
1351
1276
  });
1352
1277
  };
1278
+ ConfigurationService.prototype.getAsset = function () {
1279
+ var _a;
1280
+ var lineItem = this.configurableRamp;
1281
+ if (!lineItem) {
1282
+ return;
1283
+ }
1284
+ 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; });
1285
+ };
1353
1286
  return ConfigurationService;
1354
1287
  }());
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: [{
1288
+ 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 });
1289
+ ConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationService });
1290
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationService, decorators: [{
1358
1291
  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 }]; } });
1292
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1__namespace.ConfigurationApiService }, { type: i5__namespace.MessageService }, { type: i6__namespace.DialogService }]; } });
1293
+
1294
+ function extractMetadata(uiDefinition) {
1295
+ return lodash.omit(uiDefinition, [
1296
+ 'children',
1297
+ 'pages',
1298
+ 'components',
1299
+ ]);
1300
+ }
1360
1301
 
1361
1302
  var FlowUpdateService = /** @class */ (function () {
1362
1303
  function FlowUpdateService() {
@@ -1482,9 +1423,9 @@
1482
1423
  };
1483
1424
  return FlowUpdateService;
1484
1425
  }());
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: [{
1426
+ FlowUpdateService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1427
+ FlowUpdateService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService });
1428
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService, decorators: [{
1488
1429
  type: i0.Injectable
1489
1430
  }] });
1490
1431
 
@@ -1614,6 +1555,16 @@
1614
1555
  enumerable: false,
1615
1556
  configurable: true
1616
1557
  });
1558
+ Object.defineProperty(FlowConfigurationService.prototype, "activeMetrics$", {
1559
+ get: function () {
1560
+ return this.quoteDraftService.quoteDraft$.pipe(rxjs.map(function (_c) {
1561
+ var activeMetrics = _c.activeMetrics;
1562
+ return activeMetrics;
1563
+ }));
1564
+ },
1565
+ enumerable: false,
1566
+ configurable: true
1567
+ });
1617
1568
  Object.defineProperty(FlowConfigurationService.prototype, "chargesSnapshot", {
1618
1569
  get: function () {
1619
1570
  var _a, _b;
@@ -1630,6 +1581,14 @@
1630
1581
  enumerable: false,
1631
1582
  configurable: true
1632
1583
  });
1584
+ Object.defineProperty(FlowConfigurationService.prototype, "activeMetricsSnapshot", {
1585
+ get: function () {
1586
+ var _a, _b;
1587
+ return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.activeMetrics) !== null && _b !== void 0 ? _b : [];
1588
+ },
1589
+ enumerable: false,
1590
+ configurable: true
1591
+ });
1633
1592
  Object.defineProperty(FlowConfigurationService.prototype, "contextSnapshot", {
1634
1593
  get: function () {
1635
1594
  return this.contextService.resolve();
@@ -1660,9 +1619,9 @@
1660
1619
  };
1661
1620
  return FlowConfigurationService;
1662
1621
  }());
1663
- 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 });
1664
- FlowConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationService });
1665
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationService, decorators: [{
1622
+ 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 });
1623
+ FlowConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationService });
1624
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationService, decorators: [{
1666
1625
  type: i0.Injectable
1667
1626
  }], ctorParameters: function () { return [{ type: i1__namespace.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1668
1627
 
@@ -1671,10 +1630,10 @@
1671
1630
  }
1672
1631
  return FlowConfigurationModule;
1673
1632
  }());
1674
- FlowConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1675
- FlowConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule });
1676
- FlowConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, i1.PriceApiService], imports: [[]] });
1677
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule, decorators: [{
1633
+ FlowConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1634
+ FlowConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule });
1635
+ FlowConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, i1.PriceApiService], imports: [[]] });
1636
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, decorators: [{
1678
1637
  type: i0.NgModule,
1679
1638
  args: [{
1680
1639
  imports: [],
@@ -1687,9 +1646,9 @@
1687
1646
  }
1688
1647
  return ConfigurationModule;
1689
1648
  }());
1690
- ConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1691
- ConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, imports: [components.ConfirmationDialogModule] });
1692
- ConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, providers: [
1649
+ ConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1650
+ ConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, imports: [components.ConfirmationDialogModule] });
1651
+ ConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, providers: [
1693
1652
  i1.ContextApiService,
1694
1653
  i1.ProductModelApiService,
1695
1654
  i1.ConfigurationApiService,
@@ -1697,7 +1656,7 @@
1697
1656
  RuntimeContextService,
1698
1657
  ConfigurationService,
1699
1658
  ], imports: [[components.ConfirmationDialogModule]] });
1700
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, decorators: [{
1659
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, decorators: [{
1701
1660
  type: i0.NgModule,
1702
1661
  args: [{
1703
1662
  imports: [components.ConfirmationDialogModule],
@@ -1712,15 +1671,177 @@
1712
1671
  }]
1713
1672
  }] });
1714
1673
 
1674
+ function calculateMetricByMethod(lineItems, metric, method) {
1675
+ var items = getLineItemsByMethod(lineItems, method);
1676
+ return items.reduce(function (acc, li) {
1677
+ var value = li.reduce(function (accProduct, item) { return accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0); }, 0);
1678
+ if (method === 'avg' && li.length > 0) {
1679
+ value /= li.length;
1680
+ }
1681
+ return acc + value;
1682
+ }, 0);
1683
+ }
1684
+ function getLineItemsByMethod(lineItems, method) {
1685
+ switch (method) {
1686
+ case 'first': {
1687
+ return lineItems.filter(function (li) { return !li.rampInstanceId; }).map(function (item) { return [item]; });
1688
+ }
1689
+ case 'last': {
1690
+ var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
1691
+ var products = rootTermItems.map(function (lineItem) { return __spreadArray([
1692
+ lineItem
1693
+ ], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
1694
+ return products
1695
+ .map(function (items) { return __spreadArray([], __read(items)).sort(function (a, b) { return getDateValue(a.endDate || '') - getDateValue(b.endDate || ''); }).pop(); })
1696
+ .filter(function (li) { return Boolean(li); })
1697
+ .map(function (item) { return [item]; });
1698
+ }
1699
+ case 'avg': {
1700
+ var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
1701
+ return rootTermItems.map(function (lineItem) { return __spreadArray([lineItem], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
1702
+ }
1703
+ case 'sum': {
1704
+ return lineItems.map(function (item) { return [item]; });
1705
+ }
1706
+ default: {
1707
+ return lineItems.map(function (item) { return [item]; });
1708
+ }
1709
+ }
1710
+ }
1711
+ function getDateValue(date) {
1712
+ return date ? new Date(date).getTime() : 0;
1713
+ }
1714
+
1715
+ var MetricsCalculationService = /** @class */ (function () {
1716
+ function MetricsCalculationService(quoteDraftService, flowConfiguration, settingsService) {
1717
+ var _this = this;
1718
+ this.quoteDraftService = quoteDraftService;
1719
+ this.flowConfiguration = flowConfiguration;
1720
+ this.settingsService = settingsService;
1721
+ this.metricsUpdated$ = new rxjs.Subject();
1722
+ this.quoteMetricsSettings = {};
1723
+ this.metricsCalculationMethodMap = {};
1724
+ this.metricsData = {};
1725
+ this.activeMetricRules = [];
1726
+ this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(function (metricRule) { return metricRule.metrics.some(function (metric) { return !!metric.totalName; }); });
1727
+ rxjs.combineLatest([
1728
+ this.quoteDraftService.currentState$,
1729
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(rxjs.take(1)),
1730
+ ]).subscribe(function (_c) {
1731
+ var _d = __read(_c, 2), lineItems = _d[0], setting = _d[1];
1732
+ var settingsData = {};
1733
+ try {
1734
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
1735
+ }
1736
+ catch (error) {
1737
+ settingsData = {};
1738
+ }
1739
+ _this.quoteMetricsSettings = settingsData;
1740
+ _this.updateMetrics(lineItems);
1741
+ });
1742
+ }
1743
+ Object.defineProperty(MetricsCalculationService.prototype, "onMetricsUpdate$", {
1744
+ get: function () {
1745
+ return this.metricsUpdated$.asObservable();
1746
+ },
1747
+ enumerable: false,
1748
+ configurable: true
1749
+ });
1750
+ MetricsCalculationService.prototype.getMetricValue = function (metric) {
1751
+ return this.metricsData[metric] || 0;
1752
+ };
1753
+ MetricsCalculationService.prototype.updateMetrics = function (lineItems) {
1754
+ var _this = this;
1755
+ var metricKeys = this.collectMetricKeys(lineItems).filter(function (key) { return !key.includes('Effective_'); });
1756
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
1757
+ this.metricsData = metricKeys.reduce(function (acc, key) {
1758
+ var _c;
1759
+ return (Object.assign(Object.assign({}, acc), (_c = {}, _c[key] = _this.calculateMetric(lineItems, key), _c)));
1760
+ }, {});
1761
+ this.metricsUpdated$.next();
1762
+ };
1763
+ MetricsCalculationService.prototype.calculateMetric = function (lineItems, metric) {
1764
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
1765
+ };
1766
+ MetricsCalculationService.prototype.buildMetricsCalculationMethods = function (metricKeys, initial) {
1767
+ var _this = this;
1768
+ return metricKeys.reduce(function (acc, name) {
1769
+ var _c, _d;
1770
+ var _a, _b;
1771
+ if (acc[name]) {
1772
+ return acc;
1773
+ }
1774
+ acc = Object.assign(Object.assign({}, acc), (_c = {}, _c[name] = 'sum', _c));
1775
+ var metricRule = _this.getMetricRuleByTotalMetricName(name);
1776
+ 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;
1777
+ if (_this.quoteMetricsSettings[settingKey]) {
1778
+ acc = Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = _this.quoteMetricsSettings[settingKey], _d));
1779
+ }
1780
+ return acc;
1781
+ }, initial);
1782
+ };
1783
+ MetricsCalculationService.prototype.collectMetricKeys = function (lineItems) {
1784
+ var _this = this;
1785
+ var keys = [];
1786
+ lineItems.forEach(function (lineItem) {
1787
+ keys.push.apply(keys, __spreadArray([], __read(Object.keys(lineItem.totalMetrics || {}))));
1788
+ keys.push.apply(keys, __spreadArray([], __read(_this.collectMetricKeys(lineItem.lineItems))));
1789
+ });
1790
+ return lodash.uniq(keys);
1791
+ };
1792
+ MetricsCalculationService.prototype.getMetricRuleByTotalMetricName = function (name) {
1793
+ return this.activeMetricRules.find(function (metricRule) { return metricRule.metrics.find(function (metric) { return metric.totalName === name; }); });
1794
+ };
1795
+ return MetricsCalculationService;
1796
+ }());
1797
+ 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 });
1798
+ MetricsCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: MetricsCalculationService, providedIn: 'root' });
1799
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: MetricsCalculationService, decorators: [{
1800
+ type: i0.Injectable,
1801
+ args: [{ providedIn: 'root' }]
1802
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1__namespace.ConfigurationSettingsApiService }]; } });
1803
+
1804
+ var ProductImagesService = /** @class */ (function () {
1805
+ function ProductImagesService(productApiService) {
1806
+ this.productApiService = productApiService;
1807
+ this.imagesMap$ = new rxjs.BehaviorSubject({});
1808
+ }
1809
+ ProductImagesService.prototype.getImageUrl$ = function (productId) {
1810
+ var _a;
1811
+ if (this.imagesMap$.value[productId] == null) {
1812
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
1813
+ this.fetchProductImage(productId);
1814
+ }
1815
+ return this.imagesMap$.pipe(rxjs.map(function (imagesMap) { return imagesMap[productId]; }), rxjs.distinctUntilChanged());
1816
+ };
1817
+ ProductImagesService.prototype.fetchProductImage = function (productId) {
1818
+ var _this = this;
1819
+ this.productApiService
1820
+ .fetchImage$(productId)
1821
+ .pipe(rxjs.map(function (file) { return URL.createObjectURL(file); }), rxjs.catchError(function () { return rxjs.of(''); }), rxjs.tap(function (url) {
1822
+ var _a;
1823
+ return _this.imagesMap$.next(Object.assign(Object.assign({}, _this.imagesMap$.value), (_a = {}, _a[productId] = url, _a)));
1824
+ }))
1825
+ .subscribe();
1826
+ };
1827
+ return ProductImagesService;
1828
+ }());
1829
+ 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 });
1830
+ ProductImagesService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ProductImagesService, providedIn: 'root' });
1831
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ProductImagesService, decorators: [{
1832
+ type: i0.Injectable,
1833
+ args: [{ providedIn: 'root' }]
1834
+ }], ctorParameters: function () { return [{ type: i1__namespace.ProductApiService }]; } });
1835
+
1715
1836
  var SdkCoreModule = /** @class */ (function () {
1716
1837
  function SdkCoreModule() {
1717
1838
  }
1718
1839
  return SdkCoreModule;
1719
1840
  }());
1720
- SdkCoreModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1721
- SdkCoreModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1722
- 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]] });
1723
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, decorators: [{
1841
+ SdkCoreModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1842
+ SdkCoreModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1843
+ 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]] });
1844
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, decorators: [{
1724
1845
  type: i0.NgModule,
1725
1846
  args: [{
1726
1847
  imports: [ConfigurationModule, FlowConfigurationModule],
@@ -1743,6 +1864,9 @@
1743
1864
  exports.ProductImagesService = ProductImagesService;
1744
1865
  exports.QuoteDraftService = QuoteDraftService;
1745
1866
  exports.SdkCoreModule = SdkCoreModule;
1867
+ exports.UI_DEFINITION_VERSION = UI_DEFINITION_VERSION;
1868
+ exports.calculateCardinalityVariables = calculateCardinalityVariables;
1869
+ exports.extractMetadata = extractMetadata;
1746
1870
  exports.findLineItem = findLineItem;
1747
1871
  exports.findLineItemWithComparator = findLineItemWithComparator;
1748
1872
  exports.generateLineItem = generateLineItem;
@@ -1755,6 +1879,7 @@
1755
1879
  exports.mapAttributes = mapAttributes;
1756
1880
  exports.multiplyLineItems = multiplyLineItems;
1757
1881
  exports.patchAttributes = patchAttributes;
1882
+ exports.recalculateCardinalityVariables = recalculateCardinalityVariables;
1758
1883
  exports.removeLineItem = removeLineItem;
1759
1884
  exports.replaceLineItem = replaceLineItem;
1760
1885
  exports.upsertAttributes = upsertAttributes;