@veloceapps/sdk 6.0.0-19 → 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 (130) hide show
  1. package/bundles/veloceapps-sdk-cms.umd.js +133 -66
  2. package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
  3. package/bundles/veloceapps-sdk-core.umd.js +689 -622
  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 +200 -133
  8. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  9. package/cms/vendor-map.d.ts +15 -12
  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 +3 -2
  13. package/core/services/metric-calculation/metric-calculation.service.d.ts +1 -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 +3 -3
  33. package/esm2015/cms/services/templates.service.js +3 -3
  34. package/esm2015/core/core.module.js +4 -4
  35. package/esm2015/core/modules/configuration/configuration.module.js +4 -4
  36. package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +5 -5
  37. package/esm2015/core/modules/configuration/services/configuration.service.js +11 -10
  38. package/esm2015/core/modules/configuration/services/runtime-context.service.js +3 -3
  39. package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +4 -4
  40. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +10 -9
  41. package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +3 -3
  42. package/esm2015/core/services/context.service.js +3 -3
  43. package/esm2015/core/services/metric-calculation/metric-calculation.service.js +5 -5
  44. package/esm2015/core/services/product-images.service.js +3 -3
  45. package/esm2015/core/services/quote-draft.service.js +3 -3
  46. package/esm2015/runtime/components/component-preview/component-preview.component.js +4 -4
  47. package/esm2015/runtime/components/section-renderer/section-renderer.component.js +3 -3
  48. package/esm2015/runtime/components/ui-runtime/runtime.component.js +3 -3
  49. package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
  50. package/esm2015/runtime/execution/components/children-placeholder/children-placeholder.component.js +6 -6
  51. package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +3 -3
  52. package/esm2015/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.js +3 -3
  53. package/esm2015/runtime/execution/components/federated/federated.component.js +3 -3
  54. package/esm2015/runtime/execution/components/velo-attribute/velo-attribute.component.js +3 -3
  55. package/esm2015/runtime/execution/components/velo-multiselect/velo-multiselect.component.js +3 -3
  56. package/esm2015/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.js +3 -3
  57. package/esm2015/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.js +3 -3
  58. package/esm2015/runtime/execution/components/velo-port-radio/velo-port-radio.component.js +3 -3
  59. package/esm2015/runtime/execution/components/velo-type/velo-type.component.js +3 -3
  60. package/esm2015/runtime/execution/directives/section-script.directive.js +3 -3
  61. package/esm2015/runtime/execution/directives/sf-query.directive.js +3 -3
  62. package/esm2015/runtime/execution/directives/velo-attribute.directive.js +3 -3
  63. package/esm2015/runtime/execution/directives/velo-port.directive.js +18 -18
  64. package/esm2015/runtime/execution/directives/vl-approval.directive.js +3 -3
  65. package/esm2015/runtime/execution/directives/vl-document-attachments.directive.js +3 -3
  66. package/esm2015/runtime/execution/directives/vl-document-templates.directive.js +3 -3
  67. package/esm2015/runtime/execution/directives/vl-quote.directive.js +3 -3
  68. package/esm2015/runtime/execution/directives/vl-ramp.directive.js +3 -3
  69. package/esm2015/runtime/execution/runtime-execution.module.js +4 -4
  70. package/esm2015/runtime/runtime.module.js +4 -4
  71. package/esm2015/runtime/services/cart.service.js +3 -3
  72. package/esm2015/runtime/services/collapsible-state.service.js +3 -3
  73. package/esm2015/runtime/services/configuration.service.js +3 -3
  74. package/esm2015/runtime/services/current-state.service.js +3 -3
  75. package/esm2015/runtime/services/form-scope.service.js +3 -3
  76. package/esm2015/runtime/services/product-model-cache.service.js +3 -3
  77. package/esm2015/runtime/services/runtime-context.service.js +3 -3
  78. package/esm2015/runtime/services/runtime-form.service.js +3 -3
  79. package/esm2015/runtime/services/runtime.service.js +3 -3
  80. package/esm2015/runtime/services/section-helper.service.js +3 -3
  81. package/esm2015/runtime/services/section-scope.service.js +3 -3
  82. package/esm2015/runtime/services/section-store.service.js +3 -3
  83. package/esm2015/runtime/services/section.service.js +6 -6
  84. package/esm2015/src/components/dialog/dialog.component.js +3 -3
  85. package/esm2015/src/components/dialog/dialog.module.js +4 -4
  86. package/esm2015/src/components/doc-gen/doc-gen.component.js +3 -3
  87. package/esm2015/src/components/doc-gen/doc-gen.module.js +4 -4
  88. package/esm2015/src/components/header/cart-overlay/cart-preview.component.js +3 -3
  89. package/esm2015/src/components/header/cart-overlay/cart-preview.module.js +4 -4
  90. package/esm2015/src/components/header/header.component.js +3 -3
  91. package/esm2015/src/components/header/header.module.js +4 -4
  92. package/esm2015/src/components/header/metrics/metrics.component.js +3 -3
  93. package/esm2015/src/components/header/metrics/metrics.module.js +4 -4
  94. package/esm2015/src/flow-routing.module.js +4 -4
  95. package/esm2015/src/flow.component.js +3 -3
  96. package/esm2015/src/flow.module.js +4 -4
  97. package/esm2015/src/guards/context.guard.js +3 -3
  98. package/esm2015/src/guards/product-unload.guard.js +3 -3
  99. package/esm2015/src/guards/root.guard.js +3 -3
  100. package/esm2015/src/pages/catalog/catalog.component.js +3 -3
  101. package/esm2015/src/pages/catalog/catalog.module.js +4 -4
  102. package/esm2015/src/pages/debug/debug.component.js +3 -3
  103. package/esm2015/src/pages/debug/debug.module.js +4 -4
  104. package/esm2015/src/pages/empty-account/empty-account.component.js +3 -3
  105. package/esm2015/src/pages/empty-account/empty-account.module.js +4 -4
  106. package/esm2015/src/pages/legacy-product/legacy-product.component.js +3 -3
  107. package/esm2015/src/pages/legacy-product/legacy-product.module.js +4 -4
  108. package/esm2015/src/pages/product/product.component.js +3 -3
  109. package/esm2015/src/pages/product/product.module.js +4 -4
  110. package/esm2015/src/pages/record-not-found/record-not-found.component.js +3 -3
  111. package/esm2015/src/pages/record-not-found/record-not-found.module.js +4 -4
  112. package/esm2015/src/pages/remote/remote.component.js +3 -3
  113. package/esm2015/src/pages/remote/remote.module.js +4 -4
  114. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +3 -3
  115. package/esm2015/src/pages/shopping-cart/shopping-cart.module.js +4 -4
  116. package/esm2015/src/resolvers/flow.resolver.js +3 -3
  117. package/esm2015/src/resolvers/quote.resolver.js +3 -3
  118. package/esm2015/src/services/doc-gen.service.js +3 -3
  119. package/esm2015/src/services/flow-dialog.service.js +3 -3
  120. package/esm2015/src/services/flow-router.service.js +3 -3
  121. package/esm2015/src/services/flow.service.js +3 -3
  122. package/fesm2015/veloceapps-sdk-cms.js +62 -62
  123. package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
  124. package/fesm2015/veloceapps-sdk-core.js +487 -487
  125. package/fesm2015/veloceapps-sdk-core.js.map +1 -1
  126. package/fesm2015/veloceapps-sdk-runtime.js +138 -138
  127. package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
  128. package/fesm2015/veloceapps-sdk.js +129 -129
  129. package/fesm2015/veloceapps-sdk.js.map +1 -1
  130. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
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('moment'), require('@veloceapps/components'), require('primeng/api'), require('primeng/dynamicdialog')) :
3
- typeof define === 'function' && define.amd ? define('@veloceapps/sdk/core', ['exports', '@angular/core', '@veloceapps/core', 'rxjs', 'rxjs/operators', '@veloceapps/api', 'lodash', 'moment', '@veloceapps/components', 'primeng/api', 'primeng/dynamicdialog'], factory) :
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.moment, global["@veloceapps/components"], global["primeng/api"], global["primeng/dynamicdialog"]));
5
- })(this, (function (exports, i0, core, rxjs, operators, i1, lodash, moment, components, i4, i5) { 'use strict';
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
+ 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
+ (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, 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,9 +26,9 @@
26
26
 
27
27
  var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
28
  var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
29
- var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
30
- var i4__namespace = /*#__PURE__*/_interopNamespace(i4);
31
29
  var i5__namespace = /*#__PURE__*/_interopNamespace(i5);
30
+ var i6__namespace = /*#__PURE__*/_interopNamespace(i6);
31
+ var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
32
32
 
33
33
  var getDefaultLineItem = function (context, uiDefinitionProperties, qty) {
34
34
  if (qty === void 0) { qty = 1; }
@@ -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,144 +483,413 @@
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;
648
+ }
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);
557
893
  }
558
894
  this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
559
895
  };
@@ -694,488 +1030,57 @@
694
1030
  if (context.mode === core.ConfigurationContextMode.QUOTE) {
695
1031
  return context.properties.Status === 'Draft';
696
1032
  }
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, flowConfiguration, settingsService) {
751
- var _this = this;
752
- this.quoteDraftService = quoteDraftService;
753
- this.flowConfiguration = flowConfiguration;
754
- this.settingsService = settingsService;
755
- this.metricsUpdated$ = new rxjs.Subject();
756
- this.quoteMetricsSettings = {};
757
- this.metricsCalculationMethodMap = {};
758
- this.metricsData = {};
759
- this.activeMetricRules = [];
760
- this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(function (metricRule) { return metricRule.metrics.some(function (metric) { return !!metric.totalName; }); });
761
- rxjs.combineLatest([
762
- this.quoteDraftService.currentState$,
763
- this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(rxjs.take(1)),
764
- ]).subscribe(function (_c) {
765
- var _d = __read(_c, 2), lineItems = _d[0], setting = _d[1];
766
- var settingsData = {};
767
- try {
768
- settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
769
- }
770
- catch (error) {
771
- settingsData = {};
772
- }
773
- _this.quoteMetricsSettings = settingsData;
774
- _this.updateMetrics(lineItems);
775
- });
776
- }
777
- Object.defineProperty(MetricsCalculationService.prototype, "onMetricsUpdate$", {
778
- get: function () {
779
- return this.metricsUpdated$.asObservable();
780
- },
781
- enumerable: false,
782
- configurable: true
783
- });
784
- MetricsCalculationService.prototype.getMetricValue = function (metric) {
785
- return this.metricsData[metric] || 0;
786
- };
787
- MetricsCalculationService.prototype.updateMetrics = function (lineItems) {
788
- var _this = this;
789
- var metricKeys = this.collectMetricKeys(lineItems).filter(function (key) { return !key.includes('Effective_'); });
790
- this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
791
- this.metricsData = metricKeys.reduce(function (acc, key) {
792
- var _c;
793
- return (Object.assign(Object.assign({}, acc), (_c = {}, _c[key] = _this.calculateMetric(lineItems, key), _c)));
794
- }, {});
795
- this.metricsUpdated$.next();
796
- };
797
- MetricsCalculationService.prototype.calculateMetric = function (lineItems, metric) {
798
- return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
799
- };
800
- MetricsCalculationService.prototype.buildMetricsCalculationMethods = function (metricKeys, initial) {
801
- var _this = this;
802
- return metricKeys.reduce(function (acc, name) {
803
- var _c, _d;
804
- var _a, _b;
805
- if (acc[name]) {
806
- return acc;
807
- }
808
- acc = Object.assign(Object.assign({}, acc), (_c = {}, _c[name] = 'sum', _c));
809
- var metricRule = _this.getMetricRuleByTotalMetricName(name);
810
- 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;
811
- if (_this.quoteMetricsSettings[settingKey]) {
812
- acc = Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = _this.quoteMetricsSettings[settingKey], _d));
813
- }
814
- return acc;
815
- }, initial);
816
- };
817
- MetricsCalculationService.prototype.collectMetricKeys = function (lineItems) {
818
- var _this = this;
819
- var keys = [];
820
- lineItems.forEach(function (lineItem) {
821
- keys.push.apply(keys, __spreadArray([], __read(Object.keys(lineItem.totalMetrics || {}))));
822
- keys.push.apply(keys, __spreadArray([], __read(_this.collectMetricKeys(lineItem.lineItems))));
823
- });
824
- return lodash.uniq(keys);
825
- };
826
- MetricsCalculationService.prototype.getMetricRuleByTotalMetricName = function (name) {
827
- return this.activeMetricRules.find(function (metricRule) { return metricRule.metrics.find(function (metric) { return metric.totalName === name; }); });
828
- };
829
- return MetricsCalculationService;
830
- }());
831
- MetricsCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: FlowConfigurationService }, { token: i1__namespace.ConfigurationSettingsApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
832
- MetricsCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, providedIn: 'root' });
833
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, decorators: [{
834
- type: i0.Injectable,
835
- args: [{ providedIn: 'root' }]
836
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1__namespace.ConfigurationSettingsApiService }]; } });
837
-
838
- var ProductImagesService = /** @class */ (function () {
839
- function ProductImagesService(productApiService) {
840
- this.productApiService = productApiService;
841
- this.imagesMap$ = new rxjs.BehaviorSubject({});
842
- }
843
- ProductImagesService.prototype.getImageUrl$ = function (productId) {
844
- var _a;
845
- if (this.imagesMap$.value[productId] == null) {
846
- this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
847
- this.fetchProductImage(productId);
848
- }
849
- return this.imagesMap$.pipe(rxjs.map(function (imagesMap) { return imagesMap[productId]; }), rxjs.distinctUntilChanged());
850
- };
851
- ProductImagesService.prototype.fetchProductImage = function (productId) {
852
- var _this = this;
853
- this.productApiService
854
- .fetchImage$(productId)
855
- .pipe(rxjs.map(function (file) { return URL.createObjectURL(file); }), rxjs.catchError(function () { return rxjs.of(''); }), rxjs.tap(function (url) {
856
- var _a;
857
- return _this.imagesMap$.next(Object.assign(Object.assign({}, _this.imagesMap$.value), (_a = {}, _a[productId] = url, _a)));
858
- }))
859
- .subscribe();
860
- };
861
- return ProductImagesService;
862
- }());
863
- 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 });
864
- ProductImagesService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, providedIn: 'root' });
865
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, decorators: [{
866
- type: i0.Injectable,
867
- args: [{ providedIn: 'root' }]
868
- }], ctorParameters: function () { return [{ type: i1__namespace.ProductApiService }]; } });
869
-
870
- var RuntimeContextService = /** @class */ (function () {
871
- function RuntimeContextService(configurationApiService) {
872
- this.configurationApiService = configurationApiService;
873
- }
874
- RuntimeContextService.prototype.getRuntimeContext = function (productId, offeringId) {
875
- var _this = this;
876
- return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(operators.map(function (runtimeData) {
877
- var _a, _b, _c;
878
- var uiDefinition = _this.getUIDefinition(runtimeData);
879
- var runtimeModel = core.RuntimeModel.create(runtimeData.types, runtimeData.products);
880
- 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;
881
- return {
882
- modelId: runtimeData.modelId,
883
- uiDefinition: uiDefinition,
884
- runtimeModel: runtimeModel,
885
- runtimeMode: exports.RuntimeMode.PROD,
886
- productId: productId,
887
- productType: (properties === null || properties === void 0 ? void 0 : properties.displayName) || productName,
888
- offeringId: offeringId,
889
- properties: {
890
- PricingEnabled: ((_b = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _b === void 0 ? void 0 : _b.pricingEnabled) ? 'true' : 'false',
891
- PriceListId: (_c = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _c === void 0 ? void 0 : _c.priceList,
892
- },
893
- };
894
- }));
895
- };
896
- RuntimeContextService.prototype.getUIDefinition = function (runtimeData) {
897
- var _a;
898
- var rawUiDefinitions;
899
- try {
900
- rawUiDefinitions = JSON.parse(runtimeData.uiDefinitionsSource);
901
- }
902
- catch (e) {
903
- return;
904
- }
905
- var uiDefinitions = rawUiDefinitions.filter(function (uiDef) { return uiDef.version; });
906
- var uiDefinition = (_a = uiDefinitions.find(function (uiDef) { return uiDef.primary; })) !== null && _a !== void 0 ? _a : uiDefinitions[0];
907
- return uiDefinition;
908
- };
909
- return RuntimeContextService;
910
- }());
911
- 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 });
912
- RuntimeContextService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: RuntimeContextService });
913
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: RuntimeContextService, decorators: [{
914
- type: i0.Injectable
915
- }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }]; } });
916
-
917
- var ConfigurationRuntimeService = /** @class */ (function () {
918
- function ConfigurationRuntimeService(apiService, contextService, runtimeContextService) {
919
- this.apiService = apiService;
920
- this.contextService = contextService;
921
- this.runtimeContextService = runtimeContextService;
922
- this._isInitialized = false;
923
- this.uiDefinitionProperties = {};
924
- }
925
- ConfigurationRuntimeService.prototype.reset = function () {
926
- this._isInitialized = false;
927
- this._runtimeContext = undefined;
928
- this._assets = undefined;
929
- this.initializationProps = undefined;
930
- this.uiDefinitionProperties = {};
931
- };
932
- ConfigurationRuntimeService.prototype.initTestMode = function (modelId, uiDefinition) {
933
- var _this = this;
934
- var _a, _b;
935
- this.uiDefinitionProperties = (_a = uiDefinition.properties) !== null && _a !== void 0 ? _a : {};
936
- var uiDefinitionExternals = (_b = uiDefinition.externals) !== null && _b !== void 0 ? _b : {};
937
- return rxjs.combineLatest([
938
- this.apiService.getRuntimeDataByModelId(modelId),
939
- this.contextService.create('TestId', core.ConfigurationContextMode.TEST),
940
- ]).pipe(operators.first(), operators.tap(function (_e) {
941
- var _f = __read(_e, 2), runtimeData = _f[0], context = _f[1];
942
- var _a;
943
- _this._runtimeContext = {
944
- modelId: modelId,
945
- runtimeModel: core.RuntimeModel.create(runtimeData.types, runtimeData.products),
946
- runtimeMode: exports.RuntimeMode.TEST,
947
- };
948
- _this.contextService.update({
949
- 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),
950
- });
951
- _this._isInitialized = true;
952
- }));
953
- };
954
- ConfigurationRuntimeService.prototype.init = function (props) {
955
- var _this = this;
956
- this.initializationProps = props;
957
- this._assets = props.assets;
958
- var context = this.contextService.resolve();
959
- return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(operators.tap(function (runtimeContext) {
960
- var _a, _b, _c, _d;
961
- _this.uiDefinitionProperties = (_b = (_a = runtimeContext.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {};
962
- var PriceListId = ((_c = context.properties) !== null && _c !== void 0 ? _c : {}).PriceListId;
963
- var mergeContext = Object.assign(Object.assign({}, runtimeContext), { properties: Object.assign(Object.assign(Object.assign({}, runtimeContext.properties), context.properties), { PricingEnabled: PriceListId ? 'true' : 'false' }) });
964
- _this.id15to18('AccountId', mergeContext.properties);
965
- _this._runtimeContext = mergeContext;
966
- if (context.properties && ((_d = _this._runtimeContext.properties) === null || _d === void 0 ? void 0 : _d.StartDate)) {
967
- _this.contextService.update({
968
- properties: Object.assign(Object.assign({}, _this._runtimeContext.properties), context.properties),
969
- });
970
- }
971
- _this._isInitialized = true;
972
- }));
973
- };
974
- ConfigurationRuntimeService.prototype.id15to18 = function (propertyName, source) {
975
- if (!source) {
976
- return;
977
- }
978
- var value = source[propertyName];
979
- if (typeof value === 'string' && value.length === 15) {
980
- source[propertyName] = core.SalesforceIdUtils.generateId18FromId15(value);
981
- }
982
- };
983
- ConfigurationRuntimeService.prototype.getAsset = function (lineItem) {
984
- return this._assets && this._assets.find(function (a) { return a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId; });
985
- };
986
- Object.defineProperty(ConfigurationRuntimeService.prototype, "isInitialized", {
987
- get: function () {
988
- return this._isInitialized;
989
- },
990
- enumerable: false,
991
- configurable: true
992
- });
993
- Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeModel", {
994
- get: function () {
995
- var _a;
996
- return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
997
- },
998
- enumerable: false,
999
- configurable: true
1000
- });
1001
- Object.defineProperty(ConfigurationRuntimeService.prototype, "runtimeContext", {
1002
- get: function () {
1003
- return this._runtimeContext;
1004
- },
1005
- enumerable: false,
1006
- configurable: true
1007
- });
1008
- return ConfigurationRuntimeService;
1009
- }());
1010
- 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 });
1011
- ConfigurationRuntimeService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationRuntimeService });
1012
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationRuntimeService, decorators: [{
1013
- type: i0.Injectable
1014
- }], ctorParameters: function () { return [{ type: i1__namespace.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
1015
-
1016
- var findLineItem = function (id, lineItems) {
1017
- return findLineItemWithComparator(lineItems, function (li) { return li.id === id; });
1018
- };
1019
- var findLineItemWithComparator = function (lineItems, comparator) {
1020
- var currentLevel = lineItems;
1021
- while (currentLevel.length) {
1022
- var found = currentLevel.find(comparator);
1023
- if (found) {
1024
- return found;
1025
- }
1026
- currentLevel = lodash.flatten(currentLevel.map(function (parent) { return parent.lineItems; }));
1027
- }
1028
- return;
1029
- };
1030
- var insertLineItem = function (lineItem, parentId, toInsert) {
1031
- var insertData = lineItem.id === parentId ? [toInsert] : [];
1032
- return Object.assign(Object.assign({}, lineItem), { lineItems: __spreadArray(__spreadArray([], __read(insertData)), __read(lineItem.lineItems.map(function (li) {
1033
- return insertLineItem(li, parentId, toInsert);
1034
- }))) });
1035
- };
1036
- var removeLineItem = function (lineItem, idToRemove) {
1037
- return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems
1038
- .map(function (li) {
1039
- if (li.id === idToRemove) {
1040
- return;
1041
- }
1042
- else if (li.lineItems.length) {
1043
- return removeLineItem(li, idToRemove);
1044
- }
1045
- return li;
1046
- })
1047
- .filter(function (r) { return !!r; }) });
1048
- };
1049
- var replaceLineItem = function (lineItem, replaceTo) {
1050
- if (lineItem.id === replaceTo.id) {
1051
- return Object.assign({}, replaceTo);
1052
- }
1053
- return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(function (li) {
1054
- if (li.id === replaceTo.id) {
1055
- return replaceTo;
1056
- }
1057
- else if (li.lineItems.length) {
1058
- return replaceLineItem(li, replaceTo);
1059
- }
1060
- return li;
1061
- }) });
1062
- };
1063
- var mapAttributes = function (attributes) {
1064
- return attributes.reduce(function (acc, _c) {
1065
- var _d;
1066
- var name = _c.name, value = _c.value;
1067
- return (Object.assign(Object.assign({}, acc), (_d = {}, _d[name] = value, _d)));
1068
- }, {});
1069
- };
1070
- var getAttributes = function (attributes, names) {
1071
- if (names === void 0) { names = []; }
1072
- var filtered = attributes.filter(function (_c) {
1073
- var name = _c.name;
1074
- return names.includes(name);
1075
- });
1076
- return lodash.sortBy(filtered, [function (_c) {
1077
- var name = _c.name;
1078
- return names.indexOf(name);
1079
- }]);
1080
- };
1081
- var upsertAttributes = function (originalAttributes, attributesToUpsert) {
1082
- return attributesToUpsert.reduce(function (acc, _c) {
1083
- var name = _c.name, value = _c.value;
1084
- var _d = __read(getAttributes(acc, [name]), 1), origAttr = _d[0];
1085
- return __spreadArray(__spreadArray([], __read(acc.filter(function (attr) { return attr.name !== name; }))), [
1086
- Object.assign(Object.assign({}, (origAttr !== null && origAttr !== void 0 ? origAttr : { name: name })), { cfgStatus: 'User', value: value }),
1087
- ]);
1088
- }, originalAttributes);
1089
- };
1090
- var patchAttributes = function (rootLineItem, id, attrs) {
1091
- var lineItem = findLineItem(id, [rootLineItem]);
1092
- if (!lineItem) {
1093
- return rootLineItem;
1094
- }
1095
- var attributes = upsertAttributes(lineItem.attributes, attrs);
1096
- return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes: attributes }));
1097
- };
1098
- 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; };
1099
- var generateLineItem = function (port, type, parentId, attributes, lineItems) {
1100
- if (attributes === void 0) { attributes = []; }
1101
- if (lineItems === void 0) { lineItems = []; }
1102
- return {
1103
- id: core.UUID.UUID(),
1104
- port: port,
1105
- type: type,
1106
- actionCode: 'ADD',
1107
- cfgStatus: 'New',
1108
- attributes: attributes.map(function (_c) {
1109
- var name = _c.name, value = _c.value;
1110
- return ({ cfgStatus: 'User', name: name, value: value });
1111
- }),
1112
- lineItems: lineItems,
1113
- parentId: parentId,
1114
- qty: 1,
1033
+ return false;
1115
1034
  };
1116
- };
1117
- var getRecommendedPrices = function (portDomain, type) {
1118
- var _a, _b;
1119
- var domainType = portDomain.domainTypes.find(function (_c) {
1120
- var name = _c.name;
1121
- return name === type;
1122
- });
1123
- var _c = __read((_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(function (_c) {
1124
- var chargeMethod = _c.chargeMethod;
1125
- return chargeMethod === 'ONE_TIME';
1126
- }).reduce(function (acc, rp) {
1127
- var _c = __read(acc, 2), netPrice = _c[0], listPrice = _c[1];
1128
- return [netPrice + rp.netPrice, listPrice + rp.listPrice];
1129
- }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0], 2), net = _c[0], list = _c[1];
1130
- return { net: net, list: list };
1131
- };
1132
- var multiplyLineItems = function (lineItem, qty, split) {
1133
- if (split) {
1134
- var unifyIds_1 = function (lineItem) { return (Object.assign(Object.assign({}, lineItem), { id: core.UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds_1) })); };
1135
- return lodash.map(new Array(qty), function () { return unifyIds_1(lineItem); });
1136
- }
1137
- else {
1138
- return [
1139
- Object.assign(Object.assign({}, lineItem), { qty: qty }),
1140
- ];
1141
- }
1142
- };
1143
-
1144
- var lineItem_utils = /*#__PURE__*/Object.freeze({
1145
- __proto__: null,
1146
- findLineItem: findLineItem,
1147
- findLineItemWithComparator: findLineItemWithComparator,
1148
- insertLineItem: insertLineItem,
1149
- removeLineItem: removeLineItem,
1150
- replaceLineItem: replaceLineItem,
1151
- mapAttributes: mapAttributes,
1152
- getAttributes: getAttributes,
1153
- upsertAttributes: upsertAttributes,
1154
- patchAttributes: patchAttributes,
1155
- getAttributeValue: getAttributeValue,
1156
- generateLineItem: generateLineItem,
1157
- getRecommendedPrices: getRecommendedPrices,
1158
- multiplyLineItems: multiplyLineItems
1159
- });
1160
-
1161
- var LineItemWorker = /** @class */ (function () {
1162
- function LineItemWorker(src) {
1163
- this.li = Object.assign({}, src);
1164
- }
1165
- LineItemWorker.prototype.insert = function (parentId, toInsert) {
1166
- return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
1035
+ QuoteDraftService.prototype.updateActivePriceList = function (priceListId) {
1036
+ this.context.update({ properties: { PriceListId: priceListId } });
1167
1037
  };
1168
- LineItemWorker.prototype.remove = function (id) {
1169
- 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
+ }
1170
1063
  };
1171
- LineItemWorker.prototype.replace = function (toReplace) {
1172
- 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; });
1173
1067
  };
1174
- LineItemWorker.prototype.patchAttribute = function (attrs, id) {
1175
- 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
+ }
1176
1075
  };
1177
- return LineItemWorker;
1076
+ return QuoteDraftService;
1178
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 }]; } });
1179
1084
 
1180
1085
  var ConfigurationService = /** @class */ (function () {
1181
1086
  function ConfigurationService(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
@@ -1360,11 +1265,11 @@
1360
1265
  };
1361
1266
  return ConfigurationService;
1362
1267
  }());
1363
- 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 });
1364
- ConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationService });
1365
- 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: [{
1366
1271
  type: i0.Injectable
1367
- }], 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 }]; } });
1368
1273
 
1369
1274
  var FlowUpdateService = /** @class */ (function () {
1370
1275
  function FlowUpdateService() {
@@ -1490,9 +1395,9 @@
1490
1395
  };
1491
1396
  return FlowUpdateService;
1492
1397
  }());
1493
- FlowUpdateService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowUpdateService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1494
- FlowUpdateService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowUpdateService });
1495
- 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: [{
1496
1401
  type: i0.Injectable
1497
1402
  }] });
1498
1403
 
@@ -1686,9 +1591,9 @@
1686
1591
  };
1687
1592
  return FlowConfigurationService;
1688
1593
  }());
1689
- 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 });
1690
- FlowConfigurationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationService });
1691
- 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: [{
1692
1597
  type: i0.Injectable
1693
1598
  }], ctorParameters: function () { return [{ type: i1__namespace.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1694
1599
 
@@ -1697,10 +1602,10 @@
1697
1602
  }
1698
1603
  return FlowConfigurationModule;
1699
1604
  }());
1700
- FlowConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1701
- FlowConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule });
1702
- FlowConfigurationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, i1.PriceApiService], imports: [[]] });
1703
- 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: [{
1704
1609
  type: i0.NgModule,
1705
1610
  args: [{
1706
1611
  imports: [],
@@ -1713,9 +1618,9 @@
1713
1618
  }
1714
1619
  return ConfigurationModule;
1715
1620
  }());
1716
- ConfigurationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1717
- ConfigurationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ConfigurationModule, imports: [components.ConfirmationDialogModule] });
1718
- 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: [
1719
1624
  i1.ContextApiService,
1720
1625
  i1.ProductModelApiService,
1721
1626
  i1.ConfigurationApiService,
@@ -1723,7 +1628,7 @@
1723
1628
  RuntimeContextService,
1724
1629
  ConfigurationService,
1725
1630
  ], imports: [[components.ConfirmationDialogModule]] });
1726
- 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: [{
1727
1632
  type: i0.NgModule,
1728
1633
  args: [{
1729
1634
  imports: [components.ConfirmationDialogModule],
@@ -1738,15 +1643,177 @@
1738
1643
  }]
1739
1644
  }] });
1740
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
+
1741
1808
  var SdkCoreModule = /** @class */ (function () {
1742
1809
  function SdkCoreModule() {
1743
1810
  }
1744
1811
  return SdkCoreModule;
1745
1812
  }());
1746
- SdkCoreModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1747
- SdkCoreModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1748
- 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]] });
1749
- 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: [{
1750
1817
  type: i0.NgModule,
1751
1818
  args: [{
1752
1819
  imports: [ConfigurationModule, FlowConfigurationModule],