@veloceapps/sdk 8.0.0-117 → 8.0.0-118

Sign up to get free protection for your applications and to get access to all the features.
@@ -781,6 +781,9 @@ class FlowStateService {
781
781
  ? this._hasStatefulUnsavedChanges
782
782
  : this.quoteDraftService.hasUnsavedChanges;
783
783
  }
784
+ get stateId() {
785
+ return this.stateId$.value;
786
+ }
784
787
  isInitialized$() {
785
788
  return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
786
789
  }
@@ -1133,48 +1136,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1133
1136
  }] }];
1134
1137
  } });
1135
1138
 
1136
- function calculateMetricByMethod(lineItems, metric, method) {
1137
- const items = getLineItemsByMethod(lineItems, method);
1138
- return items.reduce((acc, li) => {
1139
- let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
1140
- if (method === 'avg' && li.length > 0) {
1141
- value /= li.length;
1142
- }
1143
- return acc + value;
1144
- }, 0);
1145
- }
1146
- function getLineItemsByMethod(lineItems, method) {
1147
- switch (method) {
1148
- case 'first': {
1149
- return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
1150
- }
1151
- case 'last': {
1152
- const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1153
- const products = rootTermItems.map(lineItem => [
1154
- lineItem,
1155
- ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
1156
- ]);
1157
- return products
1158
- .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
1159
- .filter((li) => Boolean(li))
1160
- .map(item => [item]);
1161
- }
1162
- case 'avg': {
1163
- const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1164
- return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
1165
- }
1166
- case 'sum': {
1167
- return lineItems.map(item => [item]);
1168
- }
1169
- default: {
1170
- return lineItems.map(item => [item]);
1171
- }
1172
- }
1173
- }
1174
- function getDateValue(date) {
1175
- return date ? new Date(date).getTime() : 0;
1176
- }
1177
-
1178
1139
  class FlowUpdateService {
1179
1140
  update(rootLineItems, updates, charges) {
1180
1141
  let remainingUpdates = [...updates];
@@ -1770,6 +1731,102 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1770
1731
  type: Injectable
1771
1732
  }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1772
1733
 
1734
+ class FlowConfigurationModule {
1735
+ }
1736
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1737
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
1738
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
1739
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1740
+ type: NgModule,
1741
+ args: [{
1742
+ imports: [],
1743
+ providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
1744
+ }]
1745
+ }] });
1746
+
1747
+ class FlowStateConfigurationService {
1748
+ constructor(flowStateService, flowInfoService, configurationService, flowConfigurationService, flowStateApiService) {
1749
+ this.flowStateService = flowStateService;
1750
+ this.flowInfoService = flowInfoService;
1751
+ this.configurationService = configurationService;
1752
+ this.flowConfigurationService = flowConfigurationService;
1753
+ this.flowStateApiService = flowStateApiService;
1754
+ this.configurationStateId$ = new BehaviorSubject(null);
1755
+ }
1756
+ get configurationStateId() {
1757
+ return this.configurationStateId$.value;
1758
+ }
1759
+ addToCart$(props) {
1760
+ var _a;
1761
+ const stateful = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful;
1762
+ if (stateful) {
1763
+ const stateId = this.flowStateService.stateId;
1764
+ if (!stateId) {
1765
+ return of();
1766
+ }
1767
+ return this.configurationService.configureExternal$(props).pipe(switchMap(lineItem => this.flowStateApiService
1768
+ .newConfiguration(stateId, { lineItem })
1769
+ .pipe(tap$1(r => this.configurationStateId$.next(r.stateId)))), switchMap(() => {
1770
+ if (!this.configurationStateId) {
1771
+ return of();
1772
+ }
1773
+ return this.flowStateApiService.saveConfiguration(stateId, this.configurationStateId).pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), map$1(noop));
1774
+ }));
1775
+ }
1776
+ else {
1777
+ return this.flowConfigurationService.addToCart$(props).pipe(map$1(noop));
1778
+ }
1779
+ }
1780
+ }
1781
+ FlowStateConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, deps: [{ token: FlowStateService }, { token: FlowInfoService }, { token: ConfigurationService }, { token: FlowConfigurationService }, { token: i1.FlowStateApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1782
+ FlowStateConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, providedIn: 'root' });
1783
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, decorators: [{
1784
+ type: Injectable,
1785
+ args: [{ providedIn: 'root' }]
1786
+ }], ctorParameters: function () { return [{ type: FlowStateService }, { type: FlowInfoService }, { type: ConfigurationService }, { type: FlowConfigurationService }, { type: i1.FlowStateApiService }]; } });
1787
+
1788
+ function calculateMetricByMethod(lineItems, metric, method) {
1789
+ const items = getLineItemsByMethod(lineItems, method);
1790
+ return items.reduce((acc, li) => {
1791
+ let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
1792
+ if (method === 'avg' && li.length > 0) {
1793
+ value /= li.length;
1794
+ }
1795
+ return acc + value;
1796
+ }, 0);
1797
+ }
1798
+ function getLineItemsByMethod(lineItems, method) {
1799
+ switch (method) {
1800
+ case 'first': {
1801
+ return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
1802
+ }
1803
+ case 'last': {
1804
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1805
+ const products = rootTermItems.map(lineItem => [
1806
+ lineItem,
1807
+ ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
1808
+ ]);
1809
+ return products
1810
+ .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
1811
+ .filter((li) => Boolean(li))
1812
+ .map(item => [item]);
1813
+ }
1814
+ case 'avg': {
1815
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1816
+ return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
1817
+ }
1818
+ case 'sum': {
1819
+ return lineItems.map(item => [item]);
1820
+ }
1821
+ default: {
1822
+ return lineItems.map(item => [item]);
1823
+ }
1824
+ }
1825
+ }
1826
+ function getDateValue(date) {
1827
+ return date ? new Date(date).getTime() : 0;
1828
+ }
1829
+
1773
1830
  class MetricsCalculationService {
1774
1831
  get onMetricsUpdate$() {
1775
1832
  return this.metricsUpdated$.asObservable();
@@ -2128,19 +2185,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2128
2185
  type: Injectable
2129
2186
  }], ctorParameters: function () { return [{ type: i1.StatefulConfigurationApiService }, { type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: i6.ToastService }]; } });
2130
2187
 
2131
- class FlowConfigurationModule {
2132
- }
2133
- FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2134
- FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
2135
- FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
2136
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
2137
- type: NgModule,
2138
- args: [{
2139
- imports: [],
2140
- providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
2141
- }]
2142
- }] });
2143
-
2144
2188
  class ConfigurationModule {
2145
2189
  }
2146
2190
  ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -2379,5 +2423,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2379
2423
  * Generated bundle index. Do not edit.
2380
2424
  */
2381
2425
 
2382
- export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationState, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowInfoService, FlowStateService, FlowUpdateService, IntegrationState, LineItemWorker, MetricsCalculationService, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, calculateCardinalityVariables, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateLineItem, generateModifiedAssetsMap, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isLineItemModified, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
2426
+ export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationState, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowInfoService, FlowStateConfigurationService, FlowStateService, FlowUpdateService, IntegrationState, LineItemWorker, MetricsCalculationService, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, calculateCardinalityVariables, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateLineItem, generateModifiedAssetsMap, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isLineItemModified, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
2383
2427
  //# sourceMappingURL=veloceapps-sdk-core.mjs.map