@veloceapps/sdk 6.0.0-2 → 6.0.0-20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/bundles/veloceapps-sdk-cms.umd.js +144 -72
  2. package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
  3. package/bundles/veloceapps-sdk-core.umd.js +708 -615
  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 +354 -280
  8. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  9. package/cms/vendor-map.d.ts +24 -14
  10. package/core/modules/configuration/services/configuration-runtime.service.d.ts +1 -1
  11. package/core/modules/configuration/services/configuration.service.d.ts +2 -1
  12. package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +6 -3
  13. package/core/services/metric-calculation/metric-calculation.service.d.ts +5 -1
  14. package/esm2015/cms/components/element-children/element-children.component.js +3 -3
  15. package/esm2015/cms/components/element-children/element-children.module.js +4 -4
  16. package/esm2015/cms/components/element-renderer/element-renderer.component.js +3 -3
  17. package/esm2015/cms/components/element-renderer/element-renderer.module.js +4 -4
  18. package/esm2015/cms/components/plugin.component.js +3 -3
  19. package/esm2015/cms/components/preview/preview.component.js +3 -3
  20. package/esm2015/cms/components/preview/preview.module.js +4 -4
  21. package/esm2015/cms/directives/custom-template.directive.js +3 -3
  22. package/esm2015/cms/launcher.module.js +4 -4
  23. package/esm2015/cms/modules/federated/federated.component.js +3 -3
  24. package/esm2015/cms/modules/federated/federated.module.js +4 -4
  25. package/esm2015/cms/plugins/configuration.plugin.js +3 -3
  26. package/esm2015/cms/plugins/io.plugin.js +3 -3
  27. package/esm2015/cms/plugins/script.plugin.js +3 -3
  28. package/esm2015/cms/services/dynamic-module.service.js +3 -3
  29. package/esm2015/cms/services/element-context.service.js +3 -3
  30. package/esm2015/cms/services/integration.state.js +3 -3
  31. package/esm2015/cms/services/io-provider.service.js +3 -3
  32. package/esm2015/cms/services/launcher.service.js +6 -5
  33. package/esm2015/cms/services/templates.service.js +3 -3
  34. package/esm2015/cms/vendor-map.js +11 -4
  35. package/esm2015/core/core.module.js +4 -4
  36. package/esm2015/core/modules/configuration/configuration.module.js +4 -4
  37. package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +5 -5
  38. package/esm2015/core/modules/configuration/services/configuration.service.js +11 -10
  39. package/esm2015/core/modules/configuration/services/runtime-context.service.js +3 -3
  40. package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +4 -4
  41. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +17 -9
  42. package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +3 -3
  43. package/esm2015/core/services/context.service.js +3 -3
  44. package/esm2015/core/services/metric-calculation/metric-calculation.service.js +18 -9
  45. package/esm2015/core/services/product-images.service.js +3 -3
  46. package/esm2015/core/services/quote-draft.service.js +3 -3
  47. package/esm2015/runtime/components/component-preview/component-preview.component.js +4 -4
  48. package/esm2015/runtime/components/section-renderer/section-renderer.component.js +3 -3
  49. package/esm2015/runtime/components/ui-runtime/runtime.component.js +3 -3
  50. package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
  51. package/esm2015/runtime/execution/components/children-placeholder/children-placeholder.component.js +6 -6
  52. package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +3 -3
  53. package/esm2015/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.js +3 -3
  54. package/esm2015/runtime/execution/components/federated/federated.component.js +3 -3
  55. package/esm2015/runtime/execution/components/velo-attribute/velo-attribute.component.js +3 -3
  56. package/esm2015/runtime/execution/components/velo-multiselect/velo-multiselect.component.js +3 -3
  57. package/esm2015/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.js +3 -3
  58. package/esm2015/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.js +3 -3
  59. package/esm2015/runtime/execution/components/velo-port-radio/velo-port-radio.component.js +3 -3
  60. package/esm2015/runtime/execution/components/velo-type/velo-type.component.js +3 -3
  61. package/esm2015/runtime/execution/directives/section-script.directive.js +3 -3
  62. package/esm2015/runtime/execution/directives/sf-query.directive.js +3 -3
  63. package/esm2015/runtime/execution/directives/velo-attribute.directive.js +3 -3
  64. package/esm2015/runtime/execution/directives/velo-port.directive.js +18 -18
  65. package/esm2015/runtime/execution/directives/vl-approval.directive.js +3 -3
  66. package/esm2015/runtime/execution/directives/vl-document-attachments.directive.js +3 -3
  67. package/esm2015/runtime/execution/directives/vl-document-templates.directive.js +3 -3
  68. package/esm2015/runtime/execution/directives/vl-quote.directive.js +3 -3
  69. package/esm2015/runtime/execution/directives/vl-ramp.directive.js +3 -3
  70. package/esm2015/runtime/execution/runtime-execution.module.js +4 -4
  71. package/esm2015/runtime/runtime.module.js +4 -4
  72. package/esm2015/runtime/services/cart.service.js +3 -3
  73. package/esm2015/runtime/services/collapsible-state.service.js +3 -3
  74. package/esm2015/runtime/services/configuration.service.js +3 -3
  75. package/esm2015/runtime/services/current-state.service.js +3 -3
  76. package/esm2015/runtime/services/form-scope.service.js +3 -3
  77. package/esm2015/runtime/services/product-model-cache.service.js +3 -3
  78. package/esm2015/runtime/services/runtime-context.service.js +3 -3
  79. package/esm2015/runtime/services/runtime-form.service.js +3 -3
  80. package/esm2015/runtime/services/runtime.service.js +3 -3
  81. package/esm2015/runtime/services/section-helper.service.js +3 -3
  82. package/esm2015/runtime/services/section-scope.service.js +3 -3
  83. package/esm2015/runtime/services/section-store.service.js +3 -3
  84. package/esm2015/runtime/services/section.service.js +6 -6
  85. package/esm2015/src/components/dialog/dialog.component.js +3 -3
  86. package/esm2015/src/components/dialog/dialog.module.js +4 -4
  87. package/esm2015/src/components/doc-gen/doc-gen.component.js +3 -3
  88. package/esm2015/src/components/doc-gen/doc-gen.module.js +4 -4
  89. package/esm2015/src/components/header/cart-overlay/cart-preview.component.js +3 -3
  90. package/esm2015/src/components/header/cart-overlay/cart-preview.module.js +4 -4
  91. package/esm2015/src/components/header/header.component.js +3 -3
  92. package/esm2015/src/components/header/header.module.js +4 -4
  93. package/esm2015/src/components/header/metrics/metrics.component.js +79 -67
  94. package/esm2015/src/components/header/metrics/metrics.definitions.js +1 -8
  95. package/esm2015/src/components/header/metrics/metrics.module.js +4 -4
  96. package/esm2015/src/flow-routing.module.js +4 -4
  97. package/esm2015/src/flow.component.js +3 -3
  98. package/esm2015/src/flow.module.js +4 -4
  99. package/esm2015/src/guards/context.guard.js +3 -3
  100. package/esm2015/src/guards/product-unload.guard.js +3 -3
  101. package/esm2015/src/guards/root.guard.js +3 -3
  102. package/esm2015/src/pages/catalog/catalog.component.js +3 -3
  103. package/esm2015/src/pages/catalog/catalog.module.js +4 -4
  104. package/esm2015/src/pages/debug/debug.component.js +3 -3
  105. package/esm2015/src/pages/debug/debug.module.js +4 -4
  106. package/esm2015/src/pages/empty-account/empty-account.component.js +3 -3
  107. package/esm2015/src/pages/empty-account/empty-account.module.js +4 -4
  108. package/esm2015/src/pages/legacy-product/legacy-product.component.js +3 -3
  109. package/esm2015/src/pages/legacy-product/legacy-product.module.js +4 -4
  110. package/esm2015/src/pages/product/product.component.js +3 -3
  111. package/esm2015/src/pages/product/product.module.js +4 -4
  112. package/esm2015/src/pages/record-not-found/record-not-found.component.js +3 -3
  113. package/esm2015/src/pages/record-not-found/record-not-found.module.js +4 -4
  114. package/esm2015/src/pages/remote/remote.component.js +3 -3
  115. package/esm2015/src/pages/remote/remote.module.js +4 -4
  116. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +3 -3
  117. package/esm2015/src/pages/shopping-cart/shopping-cart.module.js +4 -4
  118. package/esm2015/src/resolvers/flow.resolver.js +3 -3
  119. package/esm2015/src/resolvers/quote.resolver.js +6 -6
  120. package/esm2015/src/services/doc-gen.service.js +3 -3
  121. package/esm2015/src/services/flow-dialog.service.js +3 -3
  122. package/esm2015/src/services/flow-router.service.js +3 -3
  123. package/esm2015/src/services/flow.service.js +3 -3
  124. package/esm2015/src/utils/flow.utils.js +3 -3
  125. package/fesm2015/veloceapps-sdk-cms.js +74 -67
  126. package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
  127. package/fesm2015/veloceapps-sdk-core.js +475 -460
  128. package/fesm2015/veloceapps-sdk-core.js.map +1 -1
  129. package/fesm2015/veloceapps-sdk-runtime.js +138 -138
  130. package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
  131. package/fesm2015/veloceapps-sdk.js +232 -226
  132. package/fesm2015/veloceapps-sdk.js.map +1 -1
  133. package/package.json +1 -1
  134. package/src/components/header/metrics/metrics.component.d.ts +15 -6
  135. package/src/components/header/metrics/metrics.definitions.d.ts +0 -3
@@ -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) {
@@ -416,147 +483,416 @@
416
483
  };
417
484
  return ContextService;
418
485
  }());
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: [{
486
+ 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 });
487
+ ContextService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ContextService, providedIn: 'root' });
488
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ContextService, decorators: [{
422
489
  type: i0.Injectable,
423
490
  args: [{ providedIn: 'root' }]
424
491
  }], ctorParameters: function () { return [{ type: i1__namespace.ContextApiService }]; } });
425
492
 
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]; });
493
+ var RuntimeContextService = /** @class */ (function () {
494
+ function RuntimeContextService(configurationApiService) {
495
+ this.configurationApiService = configurationApiService;
496
+ }
497
+ RuntimeContextService.prototype.getRuntimeContext = function (productId, offeringId) {
498
+ var _this = this;
499
+ return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(operators.map(function (runtimeData) {
500
+ var _a, _b, _c;
501
+ var uiDefinition = _this.getUIDefinition(runtimeData);
502
+ var runtimeModel = core.RuntimeModel.create(runtimeData.types, runtimeData.products);
503
+ 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;
504
+ return {
505
+ modelId: runtimeData.modelId,
506
+ uiDefinition: uiDefinition,
507
+ runtimeModel: runtimeModel,
508
+ runtimeMode: exports.RuntimeMode.PROD,
509
+ productId: productId,
510
+ productType: (properties === null || properties === void 0 ? void 0 : properties.displayName) || productName,
511
+ offeringId: offeringId,
512
+ properties: {
513
+ PricingEnabled: ((_b = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _b === void 0 ? void 0 : _b.pricingEnabled) ? 'true' : 'false',
514
+ PriceListId: (_c = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _c === void 0 ? void 0 : _c.priceList,
515
+ },
516
+ };
517
+ }));
518
+ };
519
+ RuntimeContextService.prototype.getUIDefinition = function (runtimeData) {
520
+ var _a;
521
+ var rawUiDefinitions;
522
+ try {
523
+ rawUiDefinitions = JSON.parse(runtimeData.uiDefinitionsSource);
457
524
  }
458
- default: {
459
- return lineItems.map(function (item) { return [item]; });
525
+ catch (e) {
526
+ return;
460
527
  }
461
- }
462
- }
463
- function getDateValue(date) {
464
- return date ? new Date(date).getTime() : 0;
465
- }
528
+ var uiDefinitions = rawUiDefinitions.filter(function (uiDef) { return uiDef.version; });
529
+ var uiDefinition = (_a = uiDefinitions.find(function (uiDef) { return uiDef.primary; })) !== null && _a !== void 0 ? _a : uiDefinitions[0];
530
+ return uiDefinition;
531
+ };
532
+ return RuntimeContextService;
533
+ }());
534
+ 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 });
535
+ RuntimeContextService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RuntimeContextService });
536
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: RuntimeContextService, decorators: [{
537
+ type: i0.Injectable
538
+ }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }]; } });
466
539
 
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();
540
+ var ConfigurationRuntimeService = /** @class */ (function () {
541
+ function ConfigurationRuntimeService(apiService, contextService, runtimeContextService) {
542
+ this.apiService = apiService;
543
+ this.contextService = contextService;
544
+ this.runtimeContextService = runtimeContextService;
545
+ this._isInitialized = false;
546
+ this.uiDefinitionProperties = {};
485
547
  }
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);
548
+ ConfigurationRuntimeService.prototype.reset = function () {
549
+ this._isInitialized = false;
550
+ this._runtimeContext = undefined;
551
+ this._assets = undefined;
552
+ this.initializationProps = undefined;
553
+ this.uiDefinitionProperties = {};
554
+ };
555
+ ConfigurationRuntimeService.prototype.initTestMode = function (modelId, uiDefinition) {
556
+ var _this = this;
557
+ var _a, _b;
558
+ this.uiDefinitionProperties = (_a = uiDefinition.properties) !== null && _a !== void 0 ? _a : {};
559
+ var uiDefinitionExternals = (_b = uiDefinition.externals) !== null && _b !== void 0 ? _b : {};
560
+ return rxjs.combineLatest([
561
+ this.apiService.getRuntimeDataByModelId(modelId),
562
+ this.contextService.create('TestId', core.ConfigurationContextMode.TEST),
563
+ ]).pipe(operators.first(), operators.tap(function (_e) {
564
+ var _f = __read(_e, 2), runtimeData = _f[0], context = _f[1];
565
+ var _a;
566
+ _this._runtimeContext = {
567
+ modelId: modelId,
568
+ runtimeModel: core.RuntimeModel.create(runtimeData.types, runtimeData.products),
569
+ runtimeMode: exports.RuntimeMode.TEST,
570
+ };
571
+ _this.contextService.update({
572
+ 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),
573
+ });
574
+ _this._isInitialized = true;
575
+ }));
576
+ };
577
+ ConfigurationRuntimeService.prototype.init = function (props) {
578
+ var _this = this;
579
+ this.initializationProps = props;
580
+ this._assets = props.assets;
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
+ });
493
593
  }
494
- },
495
- enumerable: false,
496
- configurable: true
497
- });
498
- Object.defineProperty(QuoteDraftService.prototype, "hasUnsavedChanges", {
594
+ _this._isInitialized = true;
595
+ }));
596
+ };
597
+ ConfigurationRuntimeService.prototype.id15to18 = function (propertyName, source) {
598
+ if (!source) {
599
+ return;
600
+ }
601
+ var value = source[propertyName];
602
+ if (typeof value === 'string' && value.length === 15) {
603
+ source[propertyName] = core.SalesforceIdUtils.generateId18FromId15(value);
604
+ }
605
+ };
606
+ ConfigurationRuntimeService.prototype.getAsset = function (lineItem) {
607
+ return this._assets && this._assets.find(function (a) { return a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId; });
608
+ };
609
+ Object.defineProperty(ConfigurationRuntimeService.prototype, "isInitialized", {
499
610
  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
- }
611
+ return this._isInitialized;
508
612
  },
509
613
  enumerable: false,
510
614
  configurable: true
511
615
  });
512
- Object.defineProperty(QuoteDraftService.prototype, "hasAssets$", {
616
+ Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeModel", {
513
617
  get: function () {
514
- var _this = this;
515
- return this.quoteSubj$.pipe(operators.map(function () { return _this.hasAssets; }));
618
+ var _a;
619
+ return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
516
620
  },
517
621
  enumerable: false,
518
622
  configurable: true
519
623
  });
520
- Object.defineProperty(QuoteDraftService.prototype, "hasAssets", {
624
+ Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeContext", {
521
625
  get: function () {
522
- var quoteDraft = this.quoteSubj$.value;
523
- return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
626
+ return this._runtimeContext;
524
627
  },
525
628
  enumerable: false,
526
629
  configurable: true
527
630
  });
528
- QuoteDraftService.prototype.reset = function () {
529
- this.resetSubj$.next(true);
530
- this.quoteSubj$.next(null);
531
- this.hasUnsavedChanges = false;
532
- };
533
- QuoteDraftService.prototype.init = function (quoteId, params) {
534
- 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));
542
- };
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 }));
549
- };
550
- QuoteDraftService.prototype.updateQuoteDraft = function (update) {
551
- var quoteDraft = this.quoteSubj$.value;
552
- if (!quoteDraft) {
553
- return;
554
- }
555
- if (update.context) {
556
- this.context.set(update.context);
631
+ return ConfigurationRuntimeService;
632
+ }());
633
+ 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 });
634
+ ConfigurationRuntimeService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationRuntimeService });
635
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationRuntimeService, decorators: [{
636
+ type: i0.Injectable
637
+ }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
638
+
639
+ var findLineItem = function (id, lineItems) {
640
+ return findLineItemWithComparator(lineItems, function (li) { return li.id === id; });
641
+ };
642
+ var findLineItemWithComparator = function (lineItems, comparator) {
643
+ var currentLevel = lineItems;
644
+ while (currentLevel.length) {
645
+ var found = currentLevel.find(comparator);
646
+ if (found) {
647
+ return found;
557
648
  }
558
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
559
- };
649
+ currentLevel = lodash.flatten(currentLevel.map(function (parent) { return parent.lineItems; }));
650
+ }
651
+ return;
652
+ };
653
+ var insertLineItem = function (lineItem, parentId, toInsert) {
654
+ var insertData = lineItem.id === parentId ? [toInsert] : [];
655
+ return Object.assign(Object.assign({}, lineItem), { lineItems: __spreadArray(__spreadArray([], __read(insertData)), __read(lineItem.lineItems.map(function (li) {
656
+ return insertLineItem(li, parentId, toInsert);
657
+ }))) });
658
+ };
659
+ var removeLineItem = function (lineItem, idToRemove) {
660
+ return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems
661
+ .map(function (li) {
662
+ if (li.id === idToRemove) {
663
+ return;
664
+ }
665
+ else if (li.lineItems.length) {
666
+ return removeLineItem(li, idToRemove);
667
+ }
668
+ return li;
669
+ })
670
+ .filter(function (r) { return !!r; }) });
671
+ };
672
+ var replaceLineItem = function (lineItem, replaceTo) {
673
+ if (lineItem.id === replaceTo.id) {
674
+ return Object.assign({}, replaceTo);
675
+ }
676
+ return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(function (li) {
677
+ if (li.id === replaceTo.id) {
678
+ return replaceTo;
679
+ }
680
+ else if (li.lineItems.length) {
681
+ return replaceLineItem(li, replaceTo);
682
+ }
683
+ return li;
684
+ }) });
685
+ };
686
+ var mapAttributes = function (attributes) {
687
+ return attributes.reduce(function (acc, _c) {
688
+ var _d;
689
+ var name = _c.name, value = _c.value;
690
+ return (Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = value, _d)));
691
+ }, {});
692
+ };
693
+ var getAttributes = function (attributes, names) {
694
+ if (names === void 0) { names = []; }
695
+ var filtered = attributes.filter(function (_c) {
696
+ var name = _c.name;
697
+ return names.includes(name);
698
+ });
699
+ return lodash.sortBy(filtered, [function (_c) {
700
+ var name = _c.name;
701
+ return names.indexOf(name);
702
+ }]);
703
+ };
704
+ var upsertAttributes = function (originalAttributes, attributesToUpsert) {
705
+ return attributesToUpsert.reduce(function (acc, _c) {
706
+ var name = _c.name, value = _c.value;
707
+ var _d = __read(getAttributes(acc, [name]), 1), origAttr = _d[0];
708
+ return __spreadArray(__spreadArray([], __read(acc.filter(function (attr) { return attr.name !== name; }))), [
709
+ Object.assign(Object.assign({}, (origAttr !== null && origAttr !== void 0 ? origAttr : { name: name })), { cfgStatus: 'User', value: value }),
710
+ ]);
711
+ }, originalAttributes);
712
+ };
713
+ var patchAttributes = function (rootLineItem, id, attrs) {
714
+ var lineItem = findLineItem(id, [rootLineItem]);
715
+ if (!lineItem) {
716
+ return rootLineItem;
717
+ }
718
+ var attributes = upsertAttributes(lineItem.attributes, attrs);
719
+ return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes: attributes }));
720
+ };
721
+ var getAttributeValue = function (attributes, name) { var _a; return (_a = attributes.find(function (attr) { return attr.name === name; })) === null || _a === void 0 ? void 0 : _a.value; };
722
+ var generateLineItem = function (port, type, parentId, attributes, lineItems) {
723
+ if (attributes === void 0) { attributes = []; }
724
+ if (lineItems === void 0) { lineItems = []; }
725
+ return {
726
+ id: core.UUID.UUID(),
727
+ port: port,
728
+ type: type,
729
+ actionCode: 'ADD',
730
+ cfgStatus: 'New',
731
+ attributes: attributes.map(function (_c) {
732
+ var name = _c.name, value = _c.value;
733
+ return ({ cfgStatus: 'User', name: name, value: value });
734
+ }),
735
+ lineItems: lineItems,
736
+ parentId: parentId,
737
+ qty: 1,
738
+ };
739
+ };
740
+ var getRecommendedPrices = function (portDomain, type) {
741
+ var _a, _b;
742
+ var domainType = portDomain.domainTypes.find(function (_c) {
743
+ var name = _c.name;
744
+ return name === type;
745
+ });
746
+ var _c = __read((_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(function (_c) {
747
+ var chargeMethod = _c.chargeMethod;
748
+ return chargeMethod === 'ONE_TIME';
749
+ }).reduce(function (acc, rp) {
750
+ var _c = __read(acc, 2), netPrice = _c[0], listPrice = _c[1];
751
+ return [netPrice + rp.netPrice, listPrice + rp.listPrice];
752
+ }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0], 2), net = _c[0], list = _c[1];
753
+ return { net: net, list: list };
754
+ };
755
+ var multiplyLineItems = function (lineItem, qty, split) {
756
+ if (split) {
757
+ var unifyIds_1 = function (lineItem) { return (Object.assign(Object.assign({}, lineItem), { id: core.UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds_1) })); };
758
+ return lodash.map(new Array(qty), function () { return unifyIds_1(lineItem); });
759
+ }
760
+ else {
761
+ return [
762
+ Object.assign(Object.assign({}, lineItem), { qty: qty }),
763
+ ];
764
+ }
765
+ };
766
+
767
+ var lineItem_utils = /*#__PURE__*/Object.freeze({
768
+ __proto__: null,
769
+ findLineItem: findLineItem,
770
+ findLineItemWithComparator: findLineItemWithComparator,
771
+ insertLineItem: insertLineItem,
772
+ removeLineItem: removeLineItem,
773
+ replaceLineItem: replaceLineItem,
774
+ mapAttributes: mapAttributes,
775
+ getAttributes: getAttributes,
776
+ upsertAttributes: upsertAttributes,
777
+ patchAttributes: patchAttributes,
778
+ getAttributeValue: getAttributeValue,
779
+ generateLineItem: generateLineItem,
780
+ getRecommendedPrices: getRecommendedPrices,
781
+ multiplyLineItems: multiplyLineItems
782
+ });
783
+
784
+ var LineItemWorker = /** @class */ (function () {
785
+ function LineItemWorker(src) {
786
+ this.li = Object.assign({}, src);
787
+ }
788
+ LineItemWorker.prototype.insert = function (parentId, toInsert) {
789
+ return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
790
+ };
791
+ LineItemWorker.prototype.remove = function (id) {
792
+ return new LineItemWorker(removeLineItem(this.li, id));
793
+ };
794
+ LineItemWorker.prototype.replace = function (toReplace) {
795
+ return new LineItemWorker(replaceLineItem(this.li, toReplace));
796
+ };
797
+ LineItemWorker.prototype.patchAttribute = function (attrs, id) {
798
+ return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
799
+ };
800
+ return LineItemWorker;
801
+ }());
802
+
803
+ var QuoteDraftService = /** @class */ (function () {
804
+ function QuoteDraftService(context, quoteApiService, priceApiService) {
805
+ var _this = this;
806
+ this.context = context;
807
+ this.quoteApiService = quoteApiService;
808
+ this.priceApiService = priceApiService;
809
+ this.quoteSubj$ = new rxjs.BehaviorSubject(null);
810
+ this.resetSubj$ = new rxjs.BehaviorSubject(true);
811
+ this.isInitializedSubj$ = new rxjs.BehaviorSubject(false);
812
+ this.initialCurrentState = [];
813
+ this._hasUnsavedChanges = false;
814
+ this.allPriceLists = [];
815
+ this.assetPriceLists = [];
816
+ this.reset$ = this.resetSubj$.asObservable();
817
+ 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; }));
818
+ this.isInitializedSubj$
819
+ .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); }))
820
+ .subscribe();
821
+ }
822
+ Object.defineProperty(QuoteDraftService.prototype, "isInitialized", {
823
+ get: function () {
824
+ return this.isInitializedSubj$.getValue();
825
+ },
826
+ set: function (value) {
827
+ if (this.isInitialized !== value) {
828
+ this.isInitializedSubj$.next(value);
829
+ }
830
+ },
831
+ enumerable: false,
832
+ configurable: true
833
+ });
834
+ Object.defineProperty(QuoteDraftService.prototype, "hasUnsavedChanges", {
835
+ get: function () {
836
+ return this._hasUnsavedChanges;
837
+ },
838
+ set: function (value) {
839
+ var _a, _b;
840
+ this._hasUnsavedChanges = value;
841
+ if (!this._hasUnsavedChanges) {
842
+ this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
843
+ }
844
+ },
845
+ enumerable: false,
846
+ configurable: true
847
+ });
848
+ Object.defineProperty(QuoteDraftService.prototype, "hasAssets$", {
849
+ get: function () {
850
+ var _this = this;
851
+ return this.quoteSubj$.pipe(operators.map(function () { return _this.hasAssets; }));
852
+ },
853
+ enumerable: false,
854
+ configurable: true
855
+ });
856
+ Object.defineProperty(QuoteDraftService.prototype, "hasAssets", {
857
+ get: function () {
858
+ var quoteDraft = this.quoteSubj$.value;
859
+ return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
860
+ },
861
+ enumerable: false,
862
+ configurable: true
863
+ });
864
+ QuoteDraftService.prototype.reset = function () {
865
+ this.resetSubj$.next(true);
866
+ this.quoteSubj$.next(null);
867
+ this.hasUnsavedChanges = false;
868
+ };
869
+ QuoteDraftService.prototype.init = function (quoteId, params) {
870
+ var _this = this;
871
+ return rxjs.zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(operators.tap(function (_c) {
872
+ var _d = __read(_c, 2), quote = _d[0], allPriceLists = _d[1];
873
+ _this.allPriceLists = allPriceLists;
874
+ _this.quoteSubj$.next(quote);
875
+ _this.context.update(quote.context);
876
+ _this.populateActivePriceLists$();
877
+ }), operators.map(function () { return rxjs.noop(); }), operators.take(1));
878
+ };
879
+ QuoteDraftService.prototype.setCurrentLineItemState = function (lineItems) {
880
+ var quoteDraft = this.quoteSubj$.value;
881
+ if (!quoteDraft) {
882
+ return;
883
+ }
884
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
885
+ };
886
+ QuoteDraftService.prototype.updateQuoteDraft = function (update) {
887
+ var quoteDraft = this.quoteSubj$.value;
888
+ if (!quoteDraft) {
889
+ return;
890
+ }
891
+ if (update.context) {
892
+ this.context.set(update.context);
893
+ }
894
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
895
+ };
560
896
  QuoteDraftService.prototype.updateByPriceSummary = function (priceSummary) {
561
897
  var quoteDraft = this.quoteSubj$.value;
562
898
  if (!quoteDraft) {
@@ -691,483 +1027,60 @@
691
1027
  if (context.mode === core.ConfigurationContextMode.ACCOUNT) {
692
1028
  return true;
693
1029
  }
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;
989
- },
990
- enumerable: false,
991
- configurable: true
992
- });
993
- Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeContext", {
994
- get: function () {
995
- return this._runtimeContext;
996
- },
997
- enumerable: false,
998
- configurable: true
999
- });
1000
- return ConfigurationRuntimeService;
1001
- }());
1002
- ConfigurationRuntimeService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationRuntimeService, deps: [{ token: i1__namespace.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1003
- ConfigurationRuntimeService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationRuntimeService });
1004
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationRuntimeService, decorators: [{
1005
- type: i0.Injectable
1006
- }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
1007
-
1008
- var findLineItem = function (id, lineItems) {
1009
- return findLineItemWithComparator(lineItems, function (li) { return li.id === id; });
1010
- };
1011
- var findLineItemWithComparator = function (lineItems, comparator) {
1012
- var currentLevel = lineItems;
1013
- while (currentLevel.length) {
1014
- var found = currentLevel.find(comparator);
1015
- if (found) {
1016
- return found;
1017
- }
1018
- currentLevel = lodash.flatten(currentLevel.map(function (parent) { return parent.lineItems; }));
1019
- }
1020
- return;
1021
- };
1022
- var insertLineItem = function (lineItem, parentId, toInsert) {
1023
- var insertData = lineItem.id === parentId ? [toInsert] : [];
1024
- return Object.assign(Object.assign({}, lineItem), { lineItems: __spreadArray(__spreadArray([], __read(insertData)), __read(lineItem.lineItems.map(function (li) {
1025
- return insertLineItem(li, parentId, toInsert);
1026
- }))) });
1027
- };
1028
- var removeLineItem = function (lineItem, idToRemove) {
1029
- return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems
1030
- .map(function (li) {
1031
- if (li.id === idToRemove) {
1032
- return;
1033
- }
1034
- else if (li.lineItems.length) {
1035
- return removeLineItem(li, idToRemove);
1036
- }
1037
- return li;
1038
- })
1039
- .filter(function (r) { return !!r; }) });
1040
- };
1041
- var replaceLineItem = function (lineItem, replaceTo) {
1042
- if (lineItem.id === replaceTo.id) {
1043
- return Object.assign({}, replaceTo);
1044
- }
1045
- return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(function (li) {
1046
- if (li.id === replaceTo.id) {
1047
- return replaceTo;
1048
- }
1049
- else if (li.lineItems.length) {
1050
- return replaceLineItem(li, replaceTo);
1051
- }
1052
- return li;
1053
- }) });
1054
- };
1055
- var mapAttributes = function (attributes) {
1056
- return attributes.reduce(function (acc, _c) {
1057
- var _d;
1058
- var name = _c.name, value = _c.value;
1059
- return (Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = value, _d)));
1060
- }, {});
1061
- };
1062
- var getAttributes = function (attributes, names) {
1063
- if (names === void 0) { names = []; }
1064
- var filtered = attributes.filter(function (_c) {
1065
- var name = _c.name;
1066
- return names.includes(name);
1067
- });
1068
- return lodash.sortBy(filtered, [function (_c) {
1069
- var name = _c.name;
1070
- return names.indexOf(name);
1071
- }]);
1072
- };
1073
- var upsertAttributes = function (originalAttributes, attributesToUpsert) {
1074
- return attributesToUpsert.reduce(function (acc, _c) {
1075
- var name = _c.name, value = _c.value;
1076
- var _d = __read(getAttributes(acc, [name]), 1), origAttr = _d[0];
1077
- return __spreadArray(__spreadArray([], __read(acc.filter(function (attr) { return attr.name !== name; }))), [
1078
- Object.assign(Object.assign({}, (origAttr !== null && origAttr !== void 0 ? origAttr : { name: name })), { cfgStatus: 'User', value: value }),
1079
- ]);
1080
- }, originalAttributes);
1081
- };
1082
- var patchAttributes = function (rootLineItem, id, attrs) {
1083
- var lineItem = findLineItem(id, [rootLineItem]);
1084
- if (!lineItem) {
1085
- return rootLineItem;
1086
- }
1087
- var attributes = upsertAttributes(lineItem.attributes, attrs);
1088
- return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes: attributes }));
1089
- };
1090
- var getAttributeValue = function (attributes, name) { var _a; return (_a = attributes.find(function (attr) { return attr.name === name; })) === null || _a === void 0 ? void 0 : _a.value; };
1091
- var generateLineItem = function (port, type, parentId, attributes, lineItems) {
1092
- if (attributes === void 0) { attributes = []; }
1093
- if (lineItems === void 0) { lineItems = []; }
1094
- return {
1095
- id: core.UUID.UUID(),
1096
- port: port,
1097
- type: type,
1098
- actionCode: 'ADD',
1099
- cfgStatus: 'New',
1100
- attributes: attributes.map(function (_c) {
1101
- var name = _c.name, value = _c.value;
1102
- return ({ cfgStatus: 'User', name: name, value: value });
1103
- }),
1104
- lineItems: lineItems,
1105
- parentId: parentId,
1106
- qty: 1,
1030
+ if (context.mode === core.ConfigurationContextMode.QUOTE) {
1031
+ return context.properties.Status === 'Draft';
1032
+ }
1033
+ return false;
1107
1034
  };
1108
- };
1109
- var getRecommendedPrices = function (portDomain, type) {
1110
- var _a, _b;
1111
- var domainType = portDomain.domainTypes.find(function (_c) {
1112
- var name = _c.name;
1113
- return name === type;
1114
- });
1115
- var _c = __read((_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(function (_c) {
1116
- var chargeMethod = _c.chargeMethod;
1117
- return chargeMethod === 'ONE_TIME';
1118
- }).reduce(function (acc, rp) {
1119
- var _c = __read(acc, 2), netPrice = _c[0], listPrice = _c[1];
1120
- return [netPrice + rp.netPrice, listPrice + rp.listPrice];
1121
- }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0], 2), net = _c[0], list = _c[1];
1122
- return { net: net, list: list };
1123
- };
1124
- var multiplyLineItems = function (lineItem, qty, split) {
1125
- if (split) {
1126
- var unifyIds_1 = function (lineItem) { return (Object.assign(Object.assign({}, lineItem), { id: core.UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds_1) })); };
1127
- return lodash.map(new Array(qty), function () { return unifyIds_1(lineItem); });
1128
- }
1129
- else {
1130
- return [
1131
- Object.assign(Object.assign({}, lineItem), { qty: qty }),
1132
- ];
1133
- }
1134
- };
1135
-
1136
- var lineItem_utils = /*#__PURE__*/Object.freeze({
1137
- __proto__: null,
1138
- findLineItem: findLineItem,
1139
- findLineItemWithComparator: findLineItemWithComparator,
1140
- insertLineItem: insertLineItem,
1141
- removeLineItem: removeLineItem,
1142
- replaceLineItem: replaceLineItem,
1143
- mapAttributes: mapAttributes,
1144
- getAttributes: getAttributes,
1145
- upsertAttributes: upsertAttributes,
1146
- patchAttributes: patchAttributes,
1147
- getAttributeValue: getAttributeValue,
1148
- generateLineItem: generateLineItem,
1149
- getRecommendedPrices: getRecommendedPrices,
1150
- multiplyLineItems: multiplyLineItems
1151
- });
1152
-
1153
- var LineItemWorker = /** @class */ (function () {
1154
- function LineItemWorker(src) {
1155
- this.li = Object.assign({}, src);
1156
- }
1157
- LineItemWorker.prototype.insert = function (parentId, toInsert) {
1158
- return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
1035
+ QuoteDraftService.prototype.updateActivePriceList = function (priceListId) {
1036
+ this.context.update({ properties: { PriceListId: priceListId } });
1159
1037
  };
1160
- LineItemWorker.prototype.remove = function (id) {
1161
- return new LineItemWorker(removeLineItem(this.li, id));
1038
+ QuoteDraftService.prototype.populateActivePriceLists$ = function () {
1039
+ var _this = this;
1040
+ var ctx = this.context.resolve();
1041
+ var quoteDraft = this.quoteDraft;
1042
+ if (!quoteDraft) {
1043
+ return;
1044
+ }
1045
+ // In ACCOUNT mode populate price lists from related assets
1046
+ if (ctx.mode === core.ConfigurationContextMode.ACCOUNT) {
1047
+ // Populate list of price lists
1048
+ this.assetPriceLists = quoteDraft.currentState
1049
+ .map(function (_c) {
1050
+ var priceListId = _c.priceListId;
1051
+ return priceListId;
1052
+ })
1053
+ .reduce(function (trunk, priceListId) {
1054
+ var _a, _b;
1055
+ if (!priceListId || trunk.some(function (item) { return item.id === priceListId; })) {
1056
+ return trunk;
1057
+ }
1058
+ return __spreadArray(__spreadArray([], __read(trunk)), [
1059
+ { 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 : '' },
1060
+ ]);
1061
+ }, []);
1062
+ }
1162
1063
  };
1163
- LineItemWorker.prototype.replace = function (toReplace) {
1164
- return new LineItemWorker(replaceLineItem(this.li, toReplace));
1064
+ QuoteDraftService.prototype.filterByActivePriceList = function (lineItems) {
1065
+ var ctx = this.context.resolve();
1066
+ return lineItems.filter(function (li) { return !li.priceListId || li.priceListId === ctx.properties.PriceListId; });
1165
1067
  };
1166
- LineItemWorker.prototype.patchAttribute = function (attrs, id) {
1167
- return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
1068
+ QuoteDraftService.prototype.markAsUpdated = function (quote) {
1069
+ if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === core.ConfigurationContextMode.ACCOUNT) {
1070
+ this.hasUnsavedChanges = !!quote && !quote.currentState.every(function (li) { return li.actionCode === 'EXIST'; });
1071
+ }
1072
+ else {
1073
+ this.hasUnsavedChanges = !lodash.isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
1074
+ }
1168
1075
  };
1169
- return LineItemWorker;
1076
+ return QuoteDraftService;
1170
1077
  }());
1078
+ 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 });
1079
+ QuoteDraftService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: QuoteDraftService, providedIn: 'root' });
1080
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: QuoteDraftService, decorators: [{
1081
+ type: i0.Injectable,
1082
+ args: [{ providedIn: 'root' }]
1083
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1__namespace.QuoteApiService }, { type: i1__namespace.PriceApiService }]; } });
1171
1084
 
1172
1085
  var ConfigurationService = /** @class */ (function () {
1173
1086
  function ConfigurationService(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
@@ -1352,11 +1265,11 @@
1352
1265
  };
1353
1266
  return ConfigurationService;
1354
1267
  }());
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: [{
1268
+ 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 });
1269
+ ConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationService });
1270
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationService, decorators: [{
1358
1271
  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 }]; } });
1272
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1__namespace.ConfigurationApiService }, { type: i5__namespace.MessageService }, { type: i6__namespace.DialogService }]; } });
1360
1273
 
1361
1274
  var FlowUpdateService = /** @class */ (function () {
1362
1275
  function FlowUpdateService() {
@@ -1482,9 +1395,9 @@
1482
1395
  };
1483
1396
  return FlowUpdateService;
1484
1397
  }());
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: [{
1398
+ FlowUpdateService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1399
+ FlowUpdateService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService });
1400
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowUpdateService, decorators: [{
1488
1401
  type: i0.Injectable
1489
1402
  }] });
1490
1403
 
@@ -1614,6 +1527,16 @@
1614
1527
  enumerable: false,
1615
1528
  configurable: true
1616
1529
  });
1530
+ Object.defineProperty(FlowConfigurationService.prototype, "activeMetrics$", {
1531
+ get: function () {
1532
+ return this.quoteDraftService.quoteDraft$.pipe(rxjs.map(function (_c) {
1533
+ var activeMetrics = _c.activeMetrics;
1534
+ return activeMetrics;
1535
+ }));
1536
+ },
1537
+ enumerable: false,
1538
+ configurable: true
1539
+ });
1617
1540
  Object.defineProperty(FlowConfigurationService.prototype, "chargesSnapshot", {
1618
1541
  get: function () {
1619
1542
  var _a, _b;
@@ -1630,6 +1553,14 @@
1630
1553
  enumerable: false,
1631
1554
  configurable: true
1632
1555
  });
1556
+ Object.defineProperty(FlowConfigurationService.prototype, "activeMetricsSnapshot", {
1557
+ get: function () {
1558
+ var _a, _b;
1559
+ return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.activeMetrics) !== null && _b !== void 0 ? _b : [];
1560
+ },
1561
+ enumerable: false,
1562
+ configurable: true
1563
+ });
1633
1564
  Object.defineProperty(FlowConfigurationService.prototype, "contextSnapshot", {
1634
1565
  get: function () {
1635
1566
  return this.contextService.resolve();
@@ -1660,9 +1591,9 @@
1660
1591
  };
1661
1592
  return FlowConfigurationService;
1662
1593
  }());
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: [{
1594
+ 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 });
1595
+ FlowConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationService });
1596
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationService, decorators: [{
1666
1597
  type: i0.Injectable
1667
1598
  }], ctorParameters: function () { return [{ type: i1__namespace.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1668
1599
 
@@ -1671,10 +1602,10 @@
1671
1602
  }
1672
1603
  return FlowConfigurationModule;
1673
1604
  }());
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: [{
1605
+ FlowConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1606
+ FlowConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule });
1607
+ FlowConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, i1.PriceApiService], imports: [[]] });
1608
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: FlowConfigurationModule, decorators: [{
1678
1609
  type: i0.NgModule,
1679
1610
  args: [{
1680
1611
  imports: [],
@@ -1687,9 +1618,9 @@
1687
1618
  }
1688
1619
  return ConfigurationModule;
1689
1620
  }());
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: [
1621
+ ConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1622
+ ConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, imports: [components.ConfirmationDialogModule] });
1623
+ ConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, providers: [
1693
1624
  i1.ContextApiService,
1694
1625
  i1.ProductModelApiService,
1695
1626
  i1.ConfigurationApiService,
@@ -1697,7 +1628,7 @@
1697
1628
  RuntimeContextService,
1698
1629
  ConfigurationService,
1699
1630
  ], imports: [[components.ConfirmationDialogModule]] });
1700
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, decorators: [{
1631
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ConfigurationModule, decorators: [{
1701
1632
  type: i0.NgModule,
1702
1633
  args: [{
1703
1634
  imports: [components.ConfirmationDialogModule],
@@ -1712,15 +1643,177 @@
1712
1643
  }]
1713
1644
  }] });
1714
1645
 
1646
+ function calculateMetricByMethod(lineItems, metric, method) {
1647
+ var items = getLineItemsByMethod(lineItems, method);
1648
+ return items.reduce(function (acc, li) {
1649
+ var value = li.reduce(function (accProduct, item) { return accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0); }, 0);
1650
+ if (method === 'avg' && li.length > 0) {
1651
+ value /= li.length;
1652
+ }
1653
+ return acc + value;
1654
+ }, 0);
1655
+ }
1656
+ function getLineItemsByMethod(lineItems, method) {
1657
+ switch (method) {
1658
+ case 'first': {
1659
+ return lineItems.filter(function (li) { return !li.rampInstanceId; }).map(function (item) { return [item]; });
1660
+ }
1661
+ case 'last': {
1662
+ var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
1663
+ var products = rootTermItems.map(function (lineItem) { return __spreadArray([
1664
+ lineItem
1665
+ ], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
1666
+ return products
1667
+ .map(function (items) { return __spreadArray([], __read(items)).sort(function (a, b) { return getDateValue(a.endDate || '') - getDateValue(b.endDate || ''); }).pop(); })
1668
+ .filter(function (li) { return Boolean(li); })
1669
+ .map(function (item) { return [item]; });
1670
+ }
1671
+ case 'avg': {
1672
+ var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
1673
+ return rootTermItems.map(function (lineItem) { return __spreadArray([lineItem], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
1674
+ }
1675
+ case 'sum': {
1676
+ return lineItems.map(function (item) { return [item]; });
1677
+ }
1678
+ default: {
1679
+ return lineItems.map(function (item) { return [item]; });
1680
+ }
1681
+ }
1682
+ }
1683
+ function getDateValue(date) {
1684
+ return date ? new Date(date).getTime() : 0;
1685
+ }
1686
+
1687
+ var MetricsCalculationService = /** @class */ (function () {
1688
+ function MetricsCalculationService(quoteDraftService, flowConfiguration, settingsService) {
1689
+ var _this = this;
1690
+ this.quoteDraftService = quoteDraftService;
1691
+ this.flowConfiguration = flowConfiguration;
1692
+ this.settingsService = settingsService;
1693
+ this.metricsUpdated$ = new rxjs.Subject();
1694
+ this.quoteMetricsSettings = {};
1695
+ this.metricsCalculationMethodMap = {};
1696
+ this.metricsData = {};
1697
+ this.activeMetricRules = [];
1698
+ this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(function (metricRule) { return metricRule.metrics.some(function (metric) { return !!metric.totalName; }); });
1699
+ rxjs.combineLatest([
1700
+ this.quoteDraftService.currentState$,
1701
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(rxjs.take(1)),
1702
+ ]).subscribe(function (_c) {
1703
+ var _d = __read(_c, 2), lineItems = _d[0], setting = _d[1];
1704
+ var settingsData = {};
1705
+ try {
1706
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
1707
+ }
1708
+ catch (error) {
1709
+ settingsData = {};
1710
+ }
1711
+ _this.quoteMetricsSettings = settingsData;
1712
+ _this.updateMetrics(lineItems);
1713
+ });
1714
+ }
1715
+ Object.defineProperty(MetricsCalculationService.prototype, "onMetricsUpdate$", {
1716
+ get: function () {
1717
+ return this.metricsUpdated$.asObservable();
1718
+ },
1719
+ enumerable: false,
1720
+ configurable: true
1721
+ });
1722
+ MetricsCalculationService.prototype.getMetricValue = function (metric) {
1723
+ return this.metricsData[metric] || 0;
1724
+ };
1725
+ MetricsCalculationService.prototype.updateMetrics = function (lineItems) {
1726
+ var _this = this;
1727
+ var metricKeys = this.collectMetricKeys(lineItems).filter(function (key) { return !key.includes('Effective_'); });
1728
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
1729
+ this.metricsData = metricKeys.reduce(function (acc, key) {
1730
+ var _c;
1731
+ return (Object.assign(Object.assign({}, acc), (_c = {}, _c[key] = _this.calculateMetric(lineItems, key), _c)));
1732
+ }, {});
1733
+ this.metricsUpdated$.next();
1734
+ };
1735
+ MetricsCalculationService.prototype.calculateMetric = function (lineItems, metric) {
1736
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
1737
+ };
1738
+ MetricsCalculationService.prototype.buildMetricsCalculationMethods = function (metricKeys, initial) {
1739
+ var _this = this;
1740
+ return metricKeys.reduce(function (acc, name) {
1741
+ var _c, _d;
1742
+ var _a, _b;
1743
+ if (acc[name]) {
1744
+ return acc;
1745
+ }
1746
+ acc = Object.assign(Object.assign({}, acc), (_c = {}, _c[name] = 'sum', _c));
1747
+ var metricRule = _this.getMetricRuleByTotalMetricName(name);
1748
+ 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;
1749
+ if (_this.quoteMetricsSettings[settingKey]) {
1750
+ acc = Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = _this.quoteMetricsSettings[settingKey], _d));
1751
+ }
1752
+ return acc;
1753
+ }, initial);
1754
+ };
1755
+ MetricsCalculationService.prototype.collectMetricKeys = function (lineItems) {
1756
+ var _this = this;
1757
+ var keys = [];
1758
+ lineItems.forEach(function (lineItem) {
1759
+ keys.push.apply(keys, __spreadArray([], __read(Object.keys(lineItem.totalMetrics || {}))));
1760
+ keys.push.apply(keys, __spreadArray([], __read(_this.collectMetricKeys(lineItem.lineItems))));
1761
+ });
1762
+ return lodash.uniq(keys);
1763
+ };
1764
+ MetricsCalculationService.prototype.getMetricRuleByTotalMetricName = function (name) {
1765
+ return this.activeMetricRules.find(function (metricRule) { return metricRule.metrics.find(function (metric) { return metric.totalName === name; }); });
1766
+ };
1767
+ return MetricsCalculationService;
1768
+ }());
1769
+ 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 });
1770
+ MetricsCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: MetricsCalculationService, providedIn: 'root' });
1771
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: MetricsCalculationService, decorators: [{
1772
+ type: i0.Injectable,
1773
+ args: [{ providedIn: 'root' }]
1774
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1__namespace.ConfigurationSettingsApiService }]; } });
1775
+
1776
+ var ProductImagesService = /** @class */ (function () {
1777
+ function ProductImagesService(productApiService) {
1778
+ this.productApiService = productApiService;
1779
+ this.imagesMap$ = new rxjs.BehaviorSubject({});
1780
+ }
1781
+ ProductImagesService.prototype.getImageUrl$ = function (productId) {
1782
+ var _a;
1783
+ if (this.imagesMap$.value[productId] == null) {
1784
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
1785
+ this.fetchProductImage(productId);
1786
+ }
1787
+ return this.imagesMap$.pipe(rxjs.map(function (imagesMap) { return imagesMap[productId]; }), rxjs.distinctUntilChanged());
1788
+ };
1789
+ ProductImagesService.prototype.fetchProductImage = function (productId) {
1790
+ var _this = this;
1791
+ this.productApiService
1792
+ .fetchImage$(productId)
1793
+ .pipe(rxjs.map(function (file) { return URL.createObjectURL(file); }), rxjs.catchError(function () { return rxjs.of(''); }), rxjs.tap(function (url) {
1794
+ var _a;
1795
+ return _this.imagesMap$.next(Object.assign(Object.assign({}, _this.imagesMap$.value), (_a = {}, _a[productId] = url, _a)));
1796
+ }))
1797
+ .subscribe();
1798
+ };
1799
+ return ProductImagesService;
1800
+ }());
1801
+ 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 });
1802
+ ProductImagesService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ProductImagesService, providedIn: 'root' });
1803
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: ProductImagesService, decorators: [{
1804
+ type: i0.Injectable,
1805
+ args: [{ providedIn: 'root' }]
1806
+ }], ctorParameters: function () { return [{ type: i1__namespace.ProductApiService }]; } });
1807
+
1715
1808
  var SdkCoreModule = /** @class */ (function () {
1716
1809
  function SdkCoreModule() {
1717
1810
  }
1718
1811
  return SdkCoreModule;
1719
1812
  }());
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: [{
1813
+ SdkCoreModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1814
+ SdkCoreModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1815
+ 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]] });
1816
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SdkCoreModule, decorators: [{
1724
1817
  type: i0.NgModule,
1725
1818
  args: [{
1726
1819
  imports: [ConfigurationModule, FlowConfigurationModule],