@veloceapps/sdk 3.0.15 → 3.1.0

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 (192) hide show
  1. package/bundles/veloce-sdk-cms.umd.js +74 -836
  2. package/bundles/veloce-sdk-cms.umd.js.map +1 -1
  3. package/bundles/veloce-sdk-core.umd.js +1269 -0
  4. package/bundles/veloce-sdk-core.umd.js.map +1 -0
  5. package/bundles/veloce-sdk-runtime.umd.js +53 -166
  6. package/bundles/veloce-sdk-runtime.umd.js.map +1 -1
  7. package/bundles/veloce-sdk.umd.js +322 -155
  8. package/bundles/veloce-sdk.umd.js.map +1 -1
  9. package/cms/cms.default.d.ts +1 -1
  10. package/cms/components/element-renderer/element-renderer.component.d.ts +1 -1
  11. package/cms/components/preview/preview.component.d.ts +1 -3
  12. package/cms/decorators/element.decorator.d.ts +2 -2
  13. package/cms/index.d.ts +1 -1
  14. package/cms/injection-tokens.d.ts +1 -1
  15. package/cms/launcher.module.d.ts +2 -3
  16. package/cms/plugins/script.plugin.d.ts +1 -0
  17. package/cms/services/launcher.service.d.ts +1 -1
  18. package/cms/types/common.types.d.ts +4 -9
  19. package/cms/types/configuration.types.d.ts +0 -5
  20. package/cms/types/index.d.ts +1 -2
  21. package/cms/types/path.types.d.ts +11 -0
  22. package/cms/utils/element.utils.d.ts +6 -5
  23. package/cms/utils/elements-resolver.d.ts +2 -1
  24. package/cms/utils/index.d.ts +3 -1
  25. package/cms/utils/path.utils.d.ts +2 -1
  26. package/cms/vendor-map.d.ts +677 -2
  27. package/core/core.module.d.ts +8 -0
  28. package/core/index.d.ts +6 -0
  29. package/{cms → core}/modules/configuration/configuration.module.d.ts +0 -0
  30. package/{cms → core}/modules/configuration/helpers.d.ts +1 -2
  31. package/{cms → core}/modules/configuration/index.d.ts +0 -1
  32. package/{cms → core}/modules/configuration/services/configuration-runtime.service.d.ts +2 -3
  33. package/{cms → core}/modules/configuration/services/configuration.service.d.ts +2 -2
  34. package/{cms → core}/modules/configuration/services/runtime-context.service.d.ts +1 -1
  35. package/{cms → core}/modules/configuration/types/configuration-runtime.types.d.ts +0 -0
  36. package/{cms → core}/modules/flow-configuration/flow-configuration.module.d.ts +0 -0
  37. package/{cms → core}/modules/flow-configuration/index.d.ts +0 -0
  38. package/{cms → core}/modules/flow-configuration/services/flow-configuration.service.d.ts +7 -4
  39. package/{cms → core}/modules/flow-configuration/services/flow-update.service.d.ts +0 -0
  40. package/{cms → core}/modules/flow-configuration/types/update.types.d.ts +0 -0
  41. package/{cms → core}/modules/index.d.ts +0 -0
  42. package/core/package.json +10 -0
  43. package/{runtime → core}/services/context.service.d.ts +0 -0
  44. package/core/services/index.d.ts +2 -0
  45. package/{runtime/services/quote.service.d.ts → core/services/quote-draft.service.d.ts} +11 -6
  46. package/core/types/index.d.ts +3 -0
  47. package/core/types/quote-states.types.d.ts +6 -0
  48. package/{runtime/types/runtime-context.types.d.ts → core/types/runtime.types.d.ts} +4 -5
  49. package/{cms → core}/types/ui-definition.types.d.ts +0 -4
  50. package/core/utils/index.d.ts +2 -0
  51. package/{cms → core}/utils/line-item.utils.d.ts +0 -2
  52. package/{cms/types/line-item.types.d.ts → core/utils/line-item.worker.d.ts} +0 -0
  53. package/core/veloce-sdk-core.d.ts +5 -0
  54. package/esm2015/cms/cms.default.js +1 -1
  55. package/esm2015/cms/components/element-renderer/element-renderer.component.js +3 -3
  56. package/esm2015/cms/components/preview/preview.component.js +9 -10
  57. package/esm2015/cms/decorators/element.decorator.js +1 -1
  58. package/esm2015/cms/index.js +1 -2
  59. package/esm2015/cms/injection-tokens.js +1 -1
  60. package/esm2015/cms/launcher.module.js +5 -6
  61. package/esm2015/cms/plugins/configuration.plugin.js +3 -4
  62. package/esm2015/cms/plugins/script.plugin.js +27 -14
  63. package/esm2015/cms/services/launcher.service.js +1 -1
  64. package/esm2015/cms/types/common.types.js +1 -1
  65. package/esm2015/cms/types/configuration.types.js +1 -1
  66. package/esm2015/cms/types/index.js +2 -3
  67. package/esm2015/cms/types/path.types.js +2 -0
  68. package/esm2015/cms/utils/element.utils.js +1 -1
  69. package/esm2015/cms/utils/elements-resolver.js +1 -1
  70. package/esm2015/cms/utils/index.js +4 -2
  71. package/esm2015/cms/utils/path.utils.js +11 -1
  72. package/esm2015/cms/vendor-map.js +6 -5
  73. package/esm2015/core/core.module.js +18 -0
  74. package/esm2015/core/index.js +7 -0
  75. package/esm2015/core/modules/configuration/configuration.module.js +34 -0
  76. package/esm2015/core/modules/configuration/helpers.js +10 -0
  77. package/esm2015/core/modules/configuration/index.js +5 -0
  78. package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +93 -0
  79. package/esm2015/core/modules/configuration/services/configuration.service.js +147 -0
  80. package/esm2015/core/modules/configuration/services/runtime-context.service.js +61 -0
  81. package/esm2015/core/modules/configuration/types/configuration-runtime.types.js +2 -0
  82. package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +18 -0
  83. package/esm2015/core/modules/flow-configuration/index.js +5 -0
  84. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +90 -0
  85. package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +114 -0
  86. package/esm2015/core/modules/flow-configuration/types/update.types.js +2 -0
  87. package/esm2015/core/modules/index.js +3 -0
  88. package/esm2015/core/services/context.service.js +41 -0
  89. package/esm2015/core/services/index.js +3 -0
  90. package/esm2015/core/services/quote-draft.service.js +67 -0
  91. package/esm2015/core/types/index.js +4 -0
  92. package/esm2015/core/types/quote-states.types.js +2 -0
  93. package/esm2015/core/types/runtime.types.js +16 -0
  94. package/esm2015/core/types/ui-definition.types.js +2 -0
  95. package/esm2015/core/utils/index.js +3 -0
  96. package/esm2015/core/utils/line-item.utils.js +98 -0
  97. package/esm2015/core/utils/line-item.worker.js +19 -0
  98. package/esm2015/core/veloce-sdk-core.js +5 -0
  99. package/esm2015/runtime/components/component-preview/component-preview.component.js +2 -2
  100. package/esm2015/runtime/components/ui-runtime/runtime.component.js +10 -9
  101. package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
  102. package/esm2015/runtime/execution/directives/section-script.directive.js +19 -20
  103. package/esm2015/runtime/execution/directives/velo-port.directive.js +1 -1
  104. package/esm2015/runtime/execution/directives/vl-quote.directive.js +1 -1
  105. package/esm2015/runtime/execution/directives/vl-ramp.directive.js +2 -2
  106. package/esm2015/runtime/execution/runtime-execution.module.js +6 -8
  107. package/esm2015/runtime/runtime.module.js +7 -9
  108. package/esm2015/runtime/services/cart.service.js +5 -6
  109. package/esm2015/runtime/services/configuration.service.js +9 -9
  110. package/esm2015/runtime/services/index.js +1 -3
  111. package/esm2015/runtime/services/runtime-context.service.js +4 -4
  112. package/esm2015/runtime/services/runtime.service.js +3 -3
  113. package/esm2015/runtime/types/index.js +1 -2
  114. package/esm2015/runtime/types/runtime.types.js +1 -1
  115. package/esm2015/src/components/dialog/dialog.component.js +30 -0
  116. package/esm2015/src/components/dialog/dialog.module.js +19 -0
  117. package/esm2015/src/components/dialog/dialog.types.js +2 -0
  118. package/esm2015/src/components/header/cart-overlay/cart-overlay.component.js +2 -2
  119. package/esm2015/src/components/header/header.component.js +51 -11
  120. package/esm2015/src/flow.component.js +2 -2
  121. package/esm2015/src/flow.module.js +33 -6
  122. package/esm2015/src/pages/debug/debug.component.js +14 -16
  123. package/esm2015/src/pages/legacy-product/legacy-product.component.js +12 -11
  124. package/esm2015/src/pages/product/product.component.js +12 -12
  125. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +1 -1
  126. package/esm2015/src/resolvers/context.resolver.js +2 -2
  127. package/esm2015/src/resolvers/quote.resolver.js +9 -16
  128. package/esm2015/src/services/flow-router.service.js +2 -2
  129. package/esm2015/src/services/fow-dialog.service.js +58 -0
  130. package/esm2015/src/types/flow-customization.types.js +1 -1
  131. package/esm2015/src/utils/flow.utils.js +11 -1
  132. package/fesm2015/veloce-sdk-cms.js +64 -714
  133. package/fesm2015/veloce-sdk-cms.js.map +1 -1
  134. package/fesm2015/veloce-sdk-core.js +785 -0
  135. package/fesm2015/veloce-sdk-core.js.map +1 -0
  136. package/fesm2015/veloce-sdk-runtime.js +48 -144
  137. package/fesm2015/veloce-sdk-runtime.js.map +1 -1
  138. package/fesm2015/veloce-sdk.js +260 -99
  139. package/fesm2015/veloce-sdk.js.map +1 -1
  140. package/package.json +2 -2
  141. package/runtime/components/ui-runtime/runtime.component.d.ts +3 -3
  142. package/runtime/components/ui-runtime-preview/runtime-preview.component.d.ts +1 -1
  143. package/runtime/execution/directives/section-script.directive.d.ts +2 -3
  144. package/runtime/execution/directives/velo-port.directive.d.ts +2 -2
  145. package/runtime/execution/directives/vl-ramp.directive.d.ts +1 -1
  146. package/runtime/execution/runtime-execution.module.d.ts +2 -1
  147. package/runtime/runtime.module.d.ts +2 -1
  148. package/runtime/services/cart.service.d.ts +2 -3
  149. package/runtime/services/configuration.service.d.ts +4 -5
  150. package/runtime/services/index.d.ts +0 -2
  151. package/runtime/services/runtime-context.service.d.ts +3 -3
  152. package/runtime/services/runtime.service.d.ts +5 -6
  153. package/runtime/types/index.d.ts +0 -1
  154. package/runtime/types/runtime.types.d.ts +5 -6
  155. package/src/components/dialog/dialog.component.d.ts +13 -0
  156. package/src/components/dialog/dialog.module.d.ts +9 -0
  157. package/src/components/dialog/dialog.types.d.ts +6 -0
  158. package/src/components/header/cart-overlay/cart-overlay.component.d.ts +1 -1
  159. package/src/components/header/header.component.d.ts +10 -5
  160. package/src/flow.component.d.ts +1 -1
  161. package/src/flow.module.d.ts +3 -1
  162. package/src/pages/debug/debug.component.d.ts +3 -4
  163. package/src/pages/legacy-product/legacy-product.component.d.ts +4 -3
  164. package/src/pages/product/product.component.d.ts +3 -4
  165. package/src/pages/shopping-cart/shopping-cart.component.d.ts +1 -1
  166. package/src/resolvers/context.resolver.d.ts +1 -1
  167. package/src/resolvers/quote.resolver.d.ts +3 -4
  168. package/src/services/flow-router.service.d.ts +1 -1
  169. package/src/services/fow-dialog.service.d.ts +17 -0
  170. package/src/types/flow-customization.types.d.ts +1 -1
  171. package/src/utils/flow.utils.d.ts +2 -0
  172. package/cms/modules/configuration/types/configuration.types.d.ts +0 -15
  173. package/esm2015/cms/modules/configuration/configuration.module.js +0 -37
  174. package/esm2015/cms/modules/configuration/helpers.js +0 -10
  175. package/esm2015/cms/modules/configuration/index.js +0 -6
  176. package/esm2015/cms/modules/configuration/services/configuration-runtime.service.js +0 -93
  177. package/esm2015/cms/modules/configuration/services/configuration.service.js +0 -147
  178. package/esm2015/cms/modules/configuration/services/runtime-context.service.js +0 -61
  179. package/esm2015/cms/modules/configuration/types/configuration-runtime.types.js +0 -2
  180. package/esm2015/cms/modules/configuration/types/configuration.types.js +0 -2
  181. package/esm2015/cms/modules/flow-configuration/flow-configuration.module.js +0 -18
  182. package/esm2015/cms/modules/flow-configuration/index.js +0 -5
  183. package/esm2015/cms/modules/flow-configuration/services/flow-configuration.service.js +0 -83
  184. package/esm2015/cms/modules/flow-configuration/services/flow-update.service.js +0 -114
  185. package/esm2015/cms/modules/flow-configuration/types/update.types.js +0 -2
  186. package/esm2015/cms/modules/index.js +0 -3
  187. package/esm2015/cms/types/line-item.types.js +0 -19
  188. package/esm2015/cms/types/ui-definition.types.js +0 -2
  189. package/esm2015/cms/utils/line-item.utils.js +0 -107
  190. package/esm2015/runtime/services/context.service.js +0 -41
  191. package/esm2015/runtime/services/quote.service.js +0 -53
  192. package/esm2015/runtime/types/runtime-context.types.js +0 -16
@@ -0,0 +1,785 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, NgModule } from '@angular/core';
3
+ import { UUID, ConfigurationContext, RuntimeModel, ConfigurationContextMode, SalesforceIdUtils, ConfigurationMode } from '@veloce/core';
4
+ import { BehaviorSubject, zip, combineLatest, of, throwError, shareReplay, map as map$1, noop, tap as tap$1, switchMap, catchError as catchError$1 } from 'rxjs';
5
+ import { tap, map, filter, take, first, catchError } from 'rxjs/operators';
6
+ import * as i1 from '@veloce/api';
7
+ import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloce/api';
8
+ import { merge, flatten, sortBy, cloneDeep } from 'lodash';
9
+ import * as i2 from 'primeng/api';
10
+ import { ConfirmationComponent, ConfirmationDialogModule } from '@veloce/components';
11
+ import * as i5 from 'primeng/dynamicdialog';
12
+ import moment from 'moment';
13
+
14
+ const getDefaultLineItem = (context, uiDefinitionProperties) => {
15
+ var _a, _b, _c;
16
+ const id = UUID.UUID();
17
+ const lineItem = Object.assign({ id, type: (_a = uiDefinitionProperties.rootType) !== null && _a !== void 0 ? _a : '', cfgStatus: 'Default', actionCode: 'ADD', qty: 1, productName: ((_b = context.properties) === null || _b === void 0 ? void 0 : _b.displayName) || context.productName, productId: (_c = context.productId) !== null && _c !== void 0 ? _c : '' }, (context.offeringId
18
+ ? { offeringId: context.offeringId, offeringInstanceId: context.offeringInstanceId || id }
19
+ : {}));
20
+ return lineItem;
21
+ };
22
+
23
+ var RuntimeMode;
24
+ (function (RuntimeMode) {
25
+ RuntimeMode[RuntimeMode["TEST"] = 0] = "TEST";
26
+ RuntimeMode[RuntimeMode["PROD"] = 1] = "PROD";
27
+ })(RuntimeMode || (RuntimeMode = {}));
28
+ var RuntimeOperation;
29
+ (function (RuntimeOperation) {
30
+ RuntimeOperation["INIT"] = "INIT";
31
+ RuntimeOperation["UPDATE"] = "UPDATE";
32
+ })(RuntimeOperation || (RuntimeOperation = {}));
33
+ var RuntimeStep;
34
+ (function (RuntimeStep) {
35
+ RuntimeStep["START"] = "START";
36
+ RuntimeStep["UPDATE"] = "UPDATE";
37
+ })(RuntimeStep || (RuntimeStep = {}));
38
+
39
+ class ContextService {
40
+ constructor(contextApiService) {
41
+ this.contextApiService = contextApiService;
42
+ this.context = new BehaviorSubject(null);
43
+ this.resolve = () => this.context.value && Object.assign({}, this.context.value);
44
+ this.resolve$ = () => this.context;
45
+ }
46
+ get isStandalone() {
47
+ var _a;
48
+ return ((_a = this.resolve()) === null || _a === void 0 ? void 0 : _a.properties.standalone) === 'true';
49
+ }
50
+ create(headerId, mode) {
51
+ return this.contextApiService.getContext(headerId, mode).pipe(tap(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map(() => this.resolve()));
52
+ }
53
+ update(partialContext) {
54
+ const originalContext = this.resolve();
55
+ if (!originalContext) {
56
+ throw 'Context not initialized yet';
57
+ }
58
+ const updatedContext = Object.assign(Object.assign(Object.assign({}, originalContext), partialContext), { properties: Object.assign(Object.assign({}, originalContext.properties), partialContext.properties) });
59
+ this.context.next(updatedContext);
60
+ return updatedContext;
61
+ }
62
+ delete() {
63
+ this.context.next(null);
64
+ }
65
+ }
66
+ ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
67
+ ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, providedIn: 'root' });
68
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, decorators: [{
69
+ type: Injectable,
70
+ args: [{ providedIn: 'root' }]
71
+ }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
72
+
73
+ class QuoteDraftService {
74
+ constructor(context, quoteApiService, priceApiService) {
75
+ this.context = context;
76
+ this.quoteApiService = quoteApiService;
77
+ this.priceApiService = priceApiService;
78
+ this.quoteSubj$ = new BehaviorSubject(null);
79
+ this.resetSubj$ = new BehaviorSubject(true);
80
+ this.priceLists = [];
81
+ this.isInitialized = false;
82
+ this.hasUnsavedChanges = false;
83
+ this.reset$ = this.resetSubj$.asObservable();
84
+ }
85
+ reset() {
86
+ this.resetSubj$.next(true);
87
+ this.quoteSubj$.next(null);
88
+ }
89
+ init(quoteId, params) {
90
+ return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists(), this.context.resolve$().pipe(filter((context) => Boolean(context)))).pipe(tap(([quote, priceLists, context]) => {
91
+ this.quoteSubj$.next(quote);
92
+ this.priceLists = priceLists;
93
+ this.quotePriceList = priceLists.find(p => p.id === context.properties.PriceListId);
94
+ this.context.update(Object.assign(Object.assign(Object.assign({}, context), quote.context), { properties: Object.assign(Object.assign({}, context.properties), quote.context.properties) }));
95
+ }), map(() => {
96
+ this.isInitialized = true;
97
+ }), take(1));
98
+ }
99
+ setCurrentLineItemState(lineItems) {
100
+ const quote = this.quoteSubj$.value;
101
+ if (!quote) {
102
+ return;
103
+ }
104
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quote), { currentState: lineItems }));
105
+ this.markAsUpdated();
106
+ }
107
+ updateByPriceSummary(priceSummary) {
108
+ const quote = this.quoteSubj$.value;
109
+ if (!quote) {
110
+ return;
111
+ }
112
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quote), { currentState: priceSummary.lineItems, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
113
+ this.markAsUpdated();
114
+ }
115
+ get quote$() {
116
+ return this.quoteSubj$.pipe(filter((quote) => Boolean(quote)), map(quote => quote));
117
+ }
118
+ get quoteSnapshot() {
119
+ return this.quoteSubj$.value;
120
+ }
121
+ markAsUpdated() {
122
+ if (this.isInitialized && !this.hasUnsavedChanges) {
123
+ this.hasUnsavedChanges = true;
124
+ }
125
+ }
126
+ }
127
+ QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
128
+ QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
129
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, decorators: [{
130
+ type: Injectable,
131
+ args: [{ providedIn: 'root' }]
132
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
133
+
134
+ class RuntimeContextService {
135
+ constructor(configurationApiService, messageService) {
136
+ this.configurationApiService = configurationApiService;
137
+ this.messageService = messageService;
138
+ }
139
+ getRuntimeContext(productId, offeringId) {
140
+ return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(map(runtimeData => {
141
+ var _a, _b, _c;
142
+ const uiDefinition = this.getUIDefinition(runtimeData);
143
+ const runtimeModel = RuntimeModel.create(runtimeData.types, runtimeData.products);
144
+ const { productName, properties } = (_a = Array.from(runtimeModel.components.values()).find(c => c.productId === productId)) !== null && _a !== void 0 ? _a : {};
145
+ return {
146
+ modelId: runtimeData.modelId,
147
+ uiDefinition: uiDefinition,
148
+ runtimeModel: runtimeModel,
149
+ runtimeMode: RuntimeMode.PROD,
150
+ productId: productId,
151
+ productType: (properties === null || properties === void 0 ? void 0 : properties.displayName) || productName,
152
+ offeringId: offeringId,
153
+ properties: {
154
+ PricingEnabled: ((_b = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _b === void 0 ? void 0 : _b.pricingEnabled) ? 'true' : 'false',
155
+ PriceListId: (_c = uiDefinition === null || uiDefinition === void 0 ? void 0 : uiDefinition.properties) === null || _c === void 0 ? void 0 : _c.priceList,
156
+ },
157
+ };
158
+ }));
159
+ }
160
+ getUIDefinition(runtimeData) {
161
+ var _a;
162
+ let rawUiDefinitions;
163
+ try {
164
+ rawUiDefinitions = JSON.parse(runtimeData.uiDefinitionsSource);
165
+ }
166
+ catch (e) {
167
+ return;
168
+ }
169
+ const uiDefinitions = rawUiDefinitions.filter(uiDef => uiDef.version);
170
+ const uiDefinition = (_a = uiDefinitions.find(uiDef => uiDef.primary)) !== null && _a !== void 0 ? _a : uiDefinitions[0];
171
+ if (!uiDefinition) {
172
+ const errMsg = `Unable to find Default UI`;
173
+ this.messageService.add({
174
+ severity: 'error',
175
+ summary: 'ERROR',
176
+ });
177
+ throw new Error(errMsg);
178
+ }
179
+ return uiDefinition;
180
+ }
181
+ }
182
+ RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }, { token: i2.MessageService }], target: i0.ɵɵFactoryTarget.Injectable });
183
+ RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService });
184
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService, decorators: [{
185
+ type: Injectable
186
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: i2.MessageService }]; } });
187
+
188
+ class ConfigurationRuntimeService {
189
+ constructor(apiService, contextService, runtimeContextService) {
190
+ this.apiService = apiService;
191
+ this.contextService = contextService;
192
+ this.runtimeContextService = runtimeContextService;
193
+ this._isInitialized = false;
194
+ this.uiDefinitionProperties = {};
195
+ }
196
+ reset() {
197
+ this._isInitialized = false;
198
+ this._runtimeContext = undefined;
199
+ this._assets = undefined;
200
+ this.uiDefinitionProperties = {};
201
+ }
202
+ initTestMode(modelId, uiDefinition) {
203
+ var _a, _b;
204
+ this.uiDefinitionProperties = (_a = uiDefinition.properties) !== null && _a !== void 0 ? _a : {};
205
+ const uiDefinitionExternals = (_b = uiDefinition.externals) !== null && _b !== void 0 ? _b : {};
206
+ return combineLatest([
207
+ this.apiService.getRuntimeDataByModelId(modelId),
208
+ this.contextService.create('TestId', ConfigurationContextMode.TEST),
209
+ ]).pipe(first(), tap(([runtimeData, context]) => {
210
+ var _a;
211
+ this._runtimeContext = {
212
+ modelId: modelId,
213
+ runtimeModel: RuntimeModel.create(runtimeData.types, runtimeData.products),
214
+ runtimeMode: RuntimeMode.TEST,
215
+ };
216
+ this.contextService.update({
217
+ properties: Object.assign(Object.assign(Object.assign(Object.assign({}, (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.properties), context.properties), { ModelId: modelId, RuntimeMode: ConfigurationContextMode.TEST, PricingEnabled: this.uiDefinitionProperties.pricingEnabled ? 'true' : 'false', StartDate: new Date().toISOString().substring(0, 10), PriceListId: this.uiDefinitionProperties.priceList }), uiDefinitionExternals),
218
+ });
219
+ this._isInitialized = true;
220
+ }));
221
+ }
222
+ init(props) {
223
+ this._assets = props.assets;
224
+ const context = this.contextService.resolve();
225
+ if (!context) {
226
+ return of();
227
+ }
228
+ return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
229
+ var _a, _b, _c, _d;
230
+ this.uiDefinitionProperties = (_b = (_a = runtimeContext.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {};
231
+ const { PriceListId } = (_c = context.properties) !== null && _c !== void 0 ? _c : {};
232
+ const mergeContext = Object.assign(Object.assign({}, runtimeContext), { properties: Object.assign(Object.assign(Object.assign({}, runtimeContext.properties), context.properties), { PricingEnabled: PriceListId ? 'true' : 'false' }) });
233
+ this.id15to18('AccountId', mergeContext.properties);
234
+ this._runtimeContext = mergeContext;
235
+ if (context.properties && ((_d = this._runtimeContext.properties) === null || _d === void 0 ? void 0 : _d.StartDate)) {
236
+ this.contextService.update({
237
+ properties: Object.assign(Object.assign({}, this._runtimeContext.properties), context.properties),
238
+ });
239
+ }
240
+ this._isInitialized = true;
241
+ }));
242
+ }
243
+ id15to18(propertyName, source) {
244
+ if (!source) {
245
+ return;
246
+ }
247
+ const value = source[propertyName];
248
+ if (typeof value === 'string' && value.length === 15) {
249
+ source[propertyName] = SalesforceIdUtils.generateId18FromId15(value);
250
+ }
251
+ }
252
+ getAsset(lineItem) {
253
+ return this._assets && this._assets.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
254
+ }
255
+ get isInitialized() {
256
+ return this._isInitialized;
257
+ }
258
+ get runtimeModel() {
259
+ var _a;
260
+ return (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.runtimeModel;
261
+ }
262
+ get runtimeContext() {
263
+ return this._runtimeContext;
264
+ }
265
+ }
266
+ ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
267
+ ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService });
268
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
269
+ type: Injectable
270
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
271
+
272
+ const findLineItem = (id, lineItems) => {
273
+ return findLineItemWithComparator(lineItems, (li) => li.id === id);
274
+ };
275
+ const findLineItemWithComparator = (lineItems, comparator) => {
276
+ let currentLevel = lineItems;
277
+ while (currentLevel.length) {
278
+ const found = currentLevel.find(comparator);
279
+ if (found) {
280
+ return found;
281
+ }
282
+ currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
283
+ }
284
+ return;
285
+ };
286
+ const insertLineItem = (lineItem, parentId, toInsert) => {
287
+ const insertData = lineItem.id === parentId ? [toInsert] : [];
288
+ return Object.assign(Object.assign({}, lineItem), { lineItems: [
289
+ ...insertData,
290
+ ...lineItem.lineItems.map(li => {
291
+ return insertLineItem(li, parentId, toInsert);
292
+ }),
293
+ ] });
294
+ };
295
+ const removeLineItem = (lineItem, idToRemove) => {
296
+ return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems
297
+ .map(li => {
298
+ if (li.id === idToRemove) {
299
+ return;
300
+ }
301
+ else if (li.lineItems.length) {
302
+ return removeLineItem(li, idToRemove);
303
+ }
304
+ return li;
305
+ })
306
+ .filter(r => !!r) });
307
+ };
308
+ const replaceLineItem = (lineItem, replaceTo) => {
309
+ if (lineItem.id === replaceTo.id) {
310
+ return Object.assign({}, replaceTo);
311
+ }
312
+ return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(li => {
313
+ if (li.id === replaceTo.id) {
314
+ return replaceTo;
315
+ }
316
+ else if (li.lineItems.length) {
317
+ return replaceLineItem(li, replaceTo);
318
+ }
319
+ return li;
320
+ }) });
321
+ };
322
+ const mapAttributes = (attributes) => {
323
+ return attributes.reduce((acc, { name, value }) => (Object.assign(Object.assign({}, acc), { [name]: value })), {});
324
+ };
325
+ const getAttributes = (attributes, names = []) => {
326
+ const filtered = attributes.filter(({ name }) => names.includes(name));
327
+ return sortBy(filtered, [({ name }) => names.indexOf(name)]);
328
+ };
329
+ const upsertAttributes = (originalAttributes, attributesToUpsert) => {
330
+ return attributesToUpsert.reduce((acc, { name, value }) => {
331
+ const [origAttr] = getAttributes(acc, [name]);
332
+ return [
333
+ ...acc.filter(attr => attr.name !== name),
334
+ Object.assign(Object.assign({}, (origAttr !== null && origAttr !== void 0 ? origAttr : { name })), { cfgStatus: 'User', value }),
335
+ ];
336
+ }, originalAttributes);
337
+ };
338
+ const patchAttributes = (rootLineItem, id, attrs) => {
339
+ const lineItem = findLineItem(id, [rootLineItem]);
340
+ if (!lineItem) {
341
+ return rootLineItem;
342
+ }
343
+ const attributes = upsertAttributes(lineItem.attributes, attrs);
344
+ return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes }));
345
+ };
346
+ const getAttributeValue = (attributes, name) => { var _a; return (_a = attributes.find(attr => attr.name === name)) === null || _a === void 0 ? void 0 : _a.value; };
347
+ const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
348
+ return {
349
+ port,
350
+ type,
351
+ actionCode: 'ADD',
352
+ cfgStatus: 'New',
353
+ attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
354
+ lineItems,
355
+ parentId,
356
+ qty: 1,
357
+ };
358
+ };
359
+ const getRecommendedPrices = (portDomain, type) => {
360
+ var _a, _b;
361
+ const domainType = portDomain.domainTypes.find(({ name }) => name === type);
362
+ 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) => {
363
+ const [netPrice, listPrice] = acc;
364
+ return [netPrice + rp.netPrice, listPrice + rp.listPrice];
365
+ }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
366
+ return { net, list };
367
+ };
368
+
369
+ var lineItem_utils = /*#__PURE__*/Object.freeze({
370
+ __proto__: null,
371
+ findLineItem: findLineItem,
372
+ findLineItemWithComparator: findLineItemWithComparator,
373
+ insertLineItem: insertLineItem,
374
+ removeLineItem: removeLineItem,
375
+ replaceLineItem: replaceLineItem,
376
+ mapAttributes: mapAttributes,
377
+ getAttributes: getAttributes,
378
+ upsertAttributes: upsertAttributes,
379
+ patchAttributes: patchAttributes,
380
+ getAttributeValue: getAttributeValue,
381
+ generateLineItem: generateLineItem,
382
+ getRecommendedPrices: getRecommendedPrices
383
+ });
384
+
385
+ class LineItemWorker {
386
+ constructor(src) {
387
+ this.li = Object.assign({}, src);
388
+ }
389
+ insert(parentId, toInsert) {
390
+ return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
391
+ }
392
+ remove(id) {
393
+ return new LineItemWorker(removeLineItem(this.li, id));
394
+ }
395
+ replace(toReplace) {
396
+ return new LineItemWorker(replaceLineItem(this.li, toReplace));
397
+ }
398
+ patchAttribute(attrs, id) {
399
+ return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
400
+ }
401
+ }
402
+
403
+ class ConfigurationService {
404
+ constructor(runtimeService, contextService, configurationApiService, messageService, dialogService) {
405
+ this.runtimeService = runtimeService;
406
+ this.contextService = contextService;
407
+ this.configurationApiService = configurationApiService;
408
+ this.messageService = messageService;
409
+ this.dialogService = dialogService;
410
+ this.mode = ConfigurationMode.SEARCH;
411
+ this.states = {};
412
+ this.lineItem = new BehaviorSubject(undefined);
413
+ this.charges = new BehaviorSubject({});
414
+ }
415
+ reset() {
416
+ this.runtimeService.reset();
417
+ this.states = {};
418
+ this.lineItem.next(undefined);
419
+ this.charges.next({});
420
+ }
421
+ patch$(lineItem) {
422
+ if (!this.lineItem.value) {
423
+ return throwError(() => new Error(`Source LineItem not found`));
424
+ }
425
+ this.states.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem).li;
426
+ this.states.asset = this.states.configurableRamp
427
+ ? this.runtimeService.getAsset(this.states.configurableRamp)
428
+ : undefined;
429
+ return this.configure().pipe(catchError(error => {
430
+ console.error(error);
431
+ if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
432
+ this.messageService.add({ severity: 'error', summary: error });
433
+ }
434
+ // bounce back if configuration call has failed
435
+ this.lineItem.next(this.lineItem.value ? Object.assign({}, this.lineItem.value) : undefined);
436
+ return throwError(() => error);
437
+ }));
438
+ }
439
+ patch(lineItem) {
440
+ this.patch$(lineItem).subscribe();
441
+ }
442
+ updateCurrentStates(update) {
443
+ this.states = Object.assign(Object.assign({}, this.states), update);
444
+ }
445
+ get() {
446
+ return this.lineItem.asObservable().pipe(shareReplay());
447
+ }
448
+ getSnapshot() {
449
+ return this.lineItem.value ? Object.assign({}, this.lineItem.value) : undefined;
450
+ }
451
+ getRuntimeModel() {
452
+ return this.runtimeService.runtimeModel;
453
+ }
454
+ getRuntimeContext() {
455
+ return this.runtimeService.runtimeContext;
456
+ }
457
+ get contextSnapshot() {
458
+ return this.contextService.resolve();
459
+ }
460
+ get context$() {
461
+ return this.contextService.resolve$();
462
+ }
463
+ get charges$() {
464
+ return this.charges.asObservable();
465
+ }
466
+ get chargesSnapshot() {
467
+ return this.charges.value;
468
+ }
469
+ configure() {
470
+ var _a, _b, _c, _d, _e;
471
+ const runtimeContext = this.getRuntimeContext();
472
+ const runtimeModel = this.getRuntimeModel();
473
+ if (!runtimeContext || !runtimeModel) {
474
+ return throwError(() => new Error('Runtime context/model not initialized'));
475
+ }
476
+ const uiDefinitionProperties = Object.assign(Object.assign({}, ((_b = (_a = runtimeContext.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {})), ((_c = this.runtimeService.uiDefinitionProperties) !== null && _c !== void 0 ? _c : {}));
477
+ const lineItem = (_d = this.states.configurableRamp) !== null && _d !== void 0 ? _d : getDefaultLineItem(runtimeContext, uiDefinitionProperties);
478
+ const configurationRequest = this.createRequest(lineItem);
479
+ configurationRequest.lineItems = this.states.currentState || [];
480
+ configurationRequest.asset = this.states.asset;
481
+ const mainPricingEnabled = (_e = runtimeContext.properties) === null || _e === void 0 ? void 0 : _e.PricingEnabled;
482
+ const pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
483
+ return this.configurationApiService
484
+ .configureLineItem({ configurationRequest, runtimeModel, pricingEnabled })
485
+ .pipe(map(({ lineItem, context, charges, deletedLineItems }) => {
486
+ this.contextService.update(context !== null && context !== void 0 ? context : {});
487
+ this.charges.next(charges !== null && charges !== void 0 ? charges : {});
488
+ if (deletedLineItems === null || deletedLineItems === void 0 ? void 0 : deletedLineItems.length) {
489
+ this.showInactiveProductsConfirmation();
490
+ }
491
+ return lineItem;
492
+ }))
493
+ .pipe(tap(lineItem => lineItem && this.lineItem.next(lineItem)), catchError(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })));
494
+ }
495
+ createRequest(lineItem) {
496
+ return {
497
+ lineItem,
498
+ mode: this.mode,
499
+ step: !this.lineItem.value ? RuntimeStep.START : RuntimeStep.UPDATE,
500
+ attributeDomainMode: 'ALL',
501
+ context: this.contextService.resolve(),
502
+ };
503
+ }
504
+ showInactiveProductsConfirmation() {
505
+ this.dialogService
506
+ .open(ConfirmationComponent, {
507
+ dismissableMask: false,
508
+ closeOnEscape: false,
509
+ closable: false,
510
+ showHeader: true,
511
+ header: `Inactive Products in Quote`,
512
+ width: '440px',
513
+ data: {
514
+ confirmationConfig: {
515
+ title: ' ',
516
+ description: 'This quote contains inactive products. Do you want to remove them?',
517
+ submitBtn: 'Remove products',
518
+ cancelBtn: 'Back to Quote',
519
+ },
520
+ },
521
+ })
522
+ .onClose.subscribe(result => {
523
+ if (!result) {
524
+ const context = this.contextService.resolve();
525
+ window['VELO_BACK_FN'].apply(null, [(context === null || context === void 0 ? void 0 : context.headerId) || '']);
526
+ }
527
+ });
528
+ }
529
+ }
530
+ ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService, deps: [{ token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i2.MessageService }, { token: i5.DialogService }], target: i0.ɵɵFactoryTarget.Injectable });
531
+ ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService });
532
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService, decorators: [{
533
+ type: Injectable
534
+ }], ctorParameters: function () { return [{ type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i2.MessageService }, { type: i5.DialogService }]; } });
535
+
536
+ class FlowUpdateService {
537
+ update(rootLineItems, updates) {
538
+ let remainingUpdates = [...updates];
539
+ let currentLevel = rootLineItems;
540
+ while (currentLevel.length && remainingUpdates.length) {
541
+ currentLevel.forEach(li => {
542
+ const unhandledUpdates = [];
543
+ remainingUpdates.forEach(update => {
544
+ let updated = false;
545
+ switch (update.dataType) {
546
+ case 'LINEITEM':
547
+ updated = this.applyLineItemUpdate(li, update);
548
+ break;
549
+ case 'CHARGE':
550
+ updated = this.applyChargeUpdate(li, update);
551
+ break;
552
+ case 'GROUP_CHARGE':
553
+ updated = this.applyChargeGroupUpdate(li, update);
554
+ break;
555
+ default:
556
+ // Unknown dataType. Do not try to handle it anymore
557
+ updated = true;
558
+ }
559
+ if (!updated) {
560
+ unhandledUpdates.push(update);
561
+ }
562
+ });
563
+ remainingUpdates = unhandledUpdates;
564
+ });
565
+ currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
566
+ }
567
+ }
568
+ delete(lineItems, id) {
569
+ const idsToRemove = [id];
570
+ const topLevelLineItem = lineItems.find(li => li.id === id);
571
+ if (topLevelLineItem) {
572
+ // find term-related line items (which are only top level)
573
+ // expired term line items won't be deleted
574
+ let foundTermLineItem = topLevelLineItem;
575
+ while (foundTermLineItem) {
576
+ foundTermLineItem = lineItems.find(li => foundTermLineItem && li.rampInstanceId === foundTermLineItem.id);
577
+ if (foundTermLineItem) {
578
+ idsToRemove.push(foundTermLineItem.id);
579
+ }
580
+ }
581
+ }
582
+ const filtered = lineItems.filter(lineItem => !idsToRemove.includes(lineItem.id));
583
+ return filtered.map(lineItem => new LineItemWorker(lineItem).remove(id).li);
584
+ }
585
+ applyLineItemUpdate(lineItem, update) {
586
+ if (lineItem.id !== update.id) {
587
+ return false;
588
+ }
589
+ switch (update.attributeType) {
590
+ case 'QTY':
591
+ lineItem.qty = update.newValue;
592
+ break;
593
+ case 'EFFECTIVE_START_DATE':
594
+ lineItem.effectiveStartDate = moment(update.newValue).format('YYYY-MM-DD');
595
+ break;
596
+ case 'END_DATE':
597
+ lineItem.endDate = moment(update.newValue).format('YYYY-MM-DD');
598
+ break;
599
+ case 'PRICE_ADJUSTMENT':
600
+ {
601
+ const [charge] = lineItem.chargeItems;
602
+ if (charge) {
603
+ charge.priceAdjustment = update.newValue;
604
+ }
605
+ }
606
+ break;
607
+ default:
608
+ throw new Error(`Not suppored AttributeType for LineItem update: ${update.attributeType}`);
609
+ }
610
+ return true;
611
+ }
612
+ applyChargeUpdate(lineItem, update) {
613
+ const foundCharge = lineItem.chargeItems.find(({ id }) => id === update.id);
614
+ if (!foundCharge) {
615
+ return false;
616
+ }
617
+ if (update.attributeType === 'PRICE_ADJUSTMENT') {
618
+ foundCharge.priceAdjustment = update.newValue;
619
+ }
620
+ else {
621
+ throw new Error(`Not suppored AttributeType for Charge Item update: ${update.attributeType}`);
622
+ }
623
+ return true;
624
+ }
625
+ applyChargeGroupUpdate(lineItem, update) {
626
+ const foundChargeGroup = lineItem.chargeGroupItems.find(({ id }) => id === update.id);
627
+ if (!foundChargeGroup) {
628
+ return false;
629
+ }
630
+ if (update.attributeType === 'PRICE_ADJUSTMENT') {
631
+ foundChargeGroup.priceAdjustment = update.newValue;
632
+ }
633
+ else {
634
+ throw new Error(`Not suppored AttributeType for Charge Group Item update: ${update.attributeType}`);
635
+ }
636
+ return true;
637
+ }
638
+ }
639
+ FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
640
+ FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService });
641
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService, decorators: [{
642
+ type: Injectable
643
+ }] });
644
+
645
+ class FlowConfigurationService {
646
+ constructor(priceApiService, contextService, quoteDraftService, messageService, updateService) {
647
+ this.priceApiService = priceApiService;
648
+ this.contextService = contextService;
649
+ this.quoteDraftService = quoteDraftService;
650
+ this.messageService = messageService;
651
+ this.updateService = updateService;
652
+ this.charges = new BehaviorSubject({});
653
+ this.bounceBackUpdate$ = new BehaviorSubject(true);
654
+ }
655
+ reset() {
656
+ this.charges.next({});
657
+ }
658
+ initialize$() {
659
+ var _a;
660
+ (_a = this.resetSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
661
+ this.resetSubscription = this.quoteDraftService.reset$.subscribe(() => this.reset());
662
+ return this.calculate$(this.getSnapshot()).pipe(map$1(noop));
663
+ }
664
+ calculate$(currentState) {
665
+ const context = this.contextService.resolve();
666
+ return this.priceApiService.calculate({ context, currentState }).pipe(tap$1((result) => {
667
+ this.quoteDraftService.updateByPriceSummary(result);
668
+ this.charges.next(result.charges);
669
+ if (context) {
670
+ this.contextService.update({ properties: context.properties });
671
+ }
672
+ }), this.handleError());
673
+ }
674
+ calculate(currentState) {
675
+ this.calculate$(currentState).subscribe();
676
+ }
677
+ update$(updates) {
678
+ const lineItems = cloneDeep(this.getSnapshot());
679
+ return of([]).pipe(tap$1(() => this.updateService.update(lineItems, updates)), this.handleError(), switchMap(() => this.calculate$(lineItems)));
680
+ }
681
+ update(updates) {
682
+ this.update$(updates).subscribe();
683
+ }
684
+ delete$(ids) {
685
+ return of([]).pipe(map$1(() => ids.reduce((result, id) => this.updateService.delete(result, id), this.getSnapshot())), this.handleError(), switchMap(currentState => this.calculate$(currentState)));
686
+ }
687
+ delete(ids) {
688
+ this.delete$(ids).subscribe();
689
+ }
690
+ get() {
691
+ return combineLatest([this.quoteDraftService.quote$, this.bounceBackUpdate$]).pipe(map$1(([quoteDraft]) => quoteDraft.currentState), shareReplay());
692
+ }
693
+ getSnapshot() {
694
+ var _a, _b;
695
+ return (_b = (_a = this.quoteDraftService.quoteSnapshot) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
696
+ }
697
+ get charges$() {
698
+ return this.charges.asObservable();
699
+ }
700
+ get chargesSnapshot() {
701
+ return this.charges.value;
702
+ }
703
+ get contextSnapshot() {
704
+ return this.contextService.resolve();
705
+ }
706
+ get context$() {
707
+ return this.contextService.resolve$();
708
+ }
709
+ handleError() {
710
+ return (source$) => {
711
+ return source$.pipe(catchError$1(error => {
712
+ console.error(error);
713
+ this.messageService.add({ severity: 'error', summary: error });
714
+ // bounce back if configuration call has failed
715
+ this.bounceBackUpdate$.next(true);
716
+ return throwError(() => error);
717
+ }));
718
+ };
719
+ }
720
+ }
721
+ FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.PriceApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: i2.MessageService }, { token: FlowUpdateService }], target: i0.ɵɵFactoryTarget.Injectable });
722
+ FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService });
723
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, decorators: [{
724
+ type: Injectable
725
+ }], ctorParameters: function () { return [{ type: i1.PriceApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: i2.MessageService }, { type: FlowUpdateService }]; } });
726
+
727
+ class FlowConfigurationModule {
728
+ }
729
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
730
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule });
731
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService], imports: [[]] });
732
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, decorators: [{
733
+ type: NgModule,
734
+ args: [{
735
+ imports: [],
736
+ providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
737
+ }]
738
+ }] });
739
+
740
+ class ConfigurationModule {
741
+ }
742
+ ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
743
+ ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
744
+ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, providers: [
745
+ ContextApiService,
746
+ ProductModelApiService,
747
+ ConfigurationApiService,
748
+ ConfigurationRuntimeService,
749
+ RuntimeContextService,
750
+ ConfigurationService,
751
+ ], imports: [[ConfirmationDialogModule]] });
752
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, decorators: [{
753
+ type: NgModule,
754
+ args: [{
755
+ imports: [ConfirmationDialogModule],
756
+ providers: [
757
+ ContextApiService,
758
+ ProductModelApiService,
759
+ ConfigurationApiService,
760
+ ConfigurationRuntimeService,
761
+ RuntimeContextService,
762
+ ConfigurationService,
763
+ ],
764
+ }]
765
+ }] });
766
+
767
+ class SdkCoreModule {
768
+ }
769
+ SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
770
+ SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
771
+ SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
772
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, decorators: [{
773
+ type: NgModule,
774
+ args: [{
775
+ imports: [ConfigurationModule, FlowConfigurationModule],
776
+ providers: [ContextService, QuoteDraftService],
777
+ }]
778
+ }] });
779
+
780
+ /**
781
+ * Generated bundle index. Do not edit.
782
+ */
783
+
784
+ export { ConfigurationRuntimeService, ConfigurationService, ContextService, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeStep, SdkCoreModule, findLineItem, findLineItemWithComparator, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getRecommendedPrices, insertLineItem, lineItem_utils as lineItemUtils, mapAttributes, patchAttributes, removeLineItem, replaceLineItem, upsertAttributes };
785
+ //# sourceMappingURL=veloce-sdk-core.js.map