@veloceapps/sdk 8.0.0-117 → 8.0.0-119

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,6 +48,27 @@ const getGuidedSellingConfigurationRequest = (data, context) => {
48
48
  },
49
49
  };
50
50
  };
51
+ const generateConfigurationLineItem = (props, qty = 1) => {
52
+ var _a, _b, _c;
53
+ const id = UUID.UUID();
54
+ const attributes = Object.entries((_a = props.attributesMap) !== null && _a !== void 0 ? _a : {}).map(([name, value]) => ({
55
+ name,
56
+ value,
57
+ cfgStatus: 'User',
58
+ }));
59
+ const lineItems = [];
60
+ return {
61
+ id,
62
+ type: (_b = props.product.typeName) !== null && _b !== void 0 ? _b : '',
63
+ cfgStatus: 'Default',
64
+ actionCode: 'ADD',
65
+ qty,
66
+ attributes,
67
+ lineItems,
68
+ productName: props.product.name,
69
+ productId: (_c = props.product.id) !== null && _c !== void 0 ? _c : '',
70
+ };
71
+ };
51
72
 
52
73
  const FLOW_CUSTOMIZATION = new InjectionToken('FLOW_CUSTOMIZATION');
53
74
 
@@ -85,6 +106,18 @@ class ContextService {
85
106
  get mode() {
86
107
  return this.resolve().properties.mode;
87
108
  }
109
+ get isEditMode$() {
110
+ return this.resolve$().pipe(map(() => {
111
+ const context = this.resolve();
112
+ if (context.mode === ConfigurationContextMode.ACCOUNT) {
113
+ return true;
114
+ }
115
+ if (context.mode === ConfigurationContextMode.QUOTE) {
116
+ return context.properties.Status === 'Draft';
117
+ }
118
+ return false;
119
+ }));
120
+ }
88
121
  resolve() {
89
122
  if (!this.context.value) {
90
123
  throw new Error('Context is not initialized yet!');
@@ -781,6 +814,9 @@ class FlowStateService {
781
814
  ? this._hasStatefulUnsavedChanges
782
815
  : this.quoteDraftService.hasUnsavedChanges;
783
816
  }
817
+ get stateId() {
818
+ return this.stateId$.value;
819
+ }
784
820
  isInitialized$() {
785
821
  return combineLatest([this.stateId$, this.quoteDraftService.isInitialized$]).pipe(map$1(values => values.some(Boolean)));
786
822
  }
@@ -1133,48 +1169,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1133
1169
  }] }];
1134
1170
  } });
1135
1171
 
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
1172
  class FlowUpdateService {
1179
1173
  update(rootLineItems, updates, charges) {
1180
1174
  let remainingUpdates = [...updates];
@@ -1770,6 +1764,101 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1770
1764
  type: Injectable
1771
1765
  }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1772
1766
 
1767
+ class FlowConfigurationModule {
1768
+ }
1769
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1770
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
1771
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
1772
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1773
+ type: NgModule,
1774
+ args: [{
1775
+ imports: [],
1776
+ providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
1777
+ }]
1778
+ }] });
1779
+
1780
+ class FlowStateConfigurationService {
1781
+ constructor(flowStateService, flowInfoService, configurationService, flowConfigurationService, flowStateApiService) {
1782
+ this.flowStateService = flowStateService;
1783
+ this.flowInfoService = flowInfoService;
1784
+ this.configurationService = configurationService;
1785
+ this.flowConfigurationService = flowConfigurationService;
1786
+ this.flowStateApiService = flowStateApiService;
1787
+ this.configurationStateId$ = new BehaviorSubject(null);
1788
+ }
1789
+ get configurationStateId() {
1790
+ return this.configurationStateId$.value;
1791
+ }
1792
+ addToCart$(props) {
1793
+ var _a;
1794
+ const stateful = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful;
1795
+ if (stateful) {
1796
+ const stateId = this.flowStateService.stateId;
1797
+ if (!stateId) {
1798
+ return of();
1799
+ }
1800
+ const lineItem = generateConfigurationLineItem(props, props.qty);
1801
+ return this.flowStateApiService.newConfiguration(stateId, { lineItem }).pipe(tap$1(r => this.configurationStateId$.next(r.stateId)), switchMap(() => {
1802
+ if (!this.configurationStateId) {
1803
+ return of();
1804
+ }
1805
+ return this.flowStateApiService.saveConfiguration(stateId, this.configurationStateId).pipe(switchMap(() => this.flowStateService.executeRequest$({}, true)), tap$1(() => this.configurationStateId$.next(null)), map$1(noop));
1806
+ }));
1807
+ }
1808
+ else {
1809
+ return this.flowConfigurationService.addToCart$(props).pipe(map$1(noop));
1810
+ }
1811
+ }
1812
+ }
1813
+ 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 });
1814
+ FlowStateConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, providedIn: 'root' });
1815
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateConfigurationService, decorators: [{
1816
+ type: Injectable,
1817
+ args: [{ providedIn: 'root' }]
1818
+ }], ctorParameters: function () { return [{ type: FlowStateService }, { type: FlowInfoService }, { type: ConfigurationService }, { type: FlowConfigurationService }, { type: i1.FlowStateApiService }]; } });
1819
+
1820
+ function calculateMetricByMethod(lineItems, metric, method) {
1821
+ const items = getLineItemsByMethod(lineItems, method);
1822
+ return items.reduce((acc, li) => {
1823
+ let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
1824
+ if (method === 'avg' && li.length > 0) {
1825
+ value /= li.length;
1826
+ }
1827
+ return acc + value;
1828
+ }, 0);
1829
+ }
1830
+ function getLineItemsByMethod(lineItems, method) {
1831
+ switch (method) {
1832
+ case 'first': {
1833
+ return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
1834
+ }
1835
+ case 'last': {
1836
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1837
+ const products = rootTermItems.map(lineItem => [
1838
+ lineItem,
1839
+ ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
1840
+ ]);
1841
+ return products
1842
+ .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
1843
+ .filter((li) => Boolean(li))
1844
+ .map(item => [item]);
1845
+ }
1846
+ case 'avg': {
1847
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1848
+ return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
1849
+ }
1850
+ case 'sum': {
1851
+ return lineItems.map(item => [item]);
1852
+ }
1853
+ default: {
1854
+ return lineItems.map(item => [item]);
1855
+ }
1856
+ }
1857
+ }
1858
+ function getDateValue(date) {
1859
+ return date ? new Date(date).getTime() : 0;
1860
+ }
1861
+
1773
1862
  class MetricsCalculationService {
1774
1863
  get onMetricsUpdate$() {
1775
1864
  return this.metricsUpdated$.asObservable();
@@ -2128,19 +2217,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2128
2217
  type: Injectable
2129
2218
  }], ctorParameters: function () { return [{ type: i1.StatefulConfigurationApiService }, { type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: i6.ToastService }]; } });
2130
2219
 
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
2220
  class ConfigurationModule {
2145
2221
  }
2146
2222
  ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -2379,5 +2455,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2379
2455
  * Generated bundle index. Do not edit.
2380
2456
  */
2381
2457
 
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 };
2458
+ 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, generateConfigurationLineItem, generateLineItem, generateModifiedAssetsMap, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isLineItemModified, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
2383
2459
  //# sourceMappingURL=veloceapps-sdk-core.mjs.map