@veloceapps/sdk 11.0.0-12 → 11.0.0-121

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