@veloceapps/sdk 11.0.0-9 → 11.0.0-91

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