@veloceapps/sdk 9.0.0-8 → 10.0.0-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.
@@ -1,11 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, Injectable, Optional, Inject, NgModule, inject, Directive, Input, LOCALE_ID, Pipe } from '@angular/core';
3
- import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, QuoteDraft, isDefined, ConfigurationProcessorTypes, EntityUtil, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, DEFAULT_ACTION_CODE_LABELS, parseJsonSafely, ConfigurationMode, ConfigurationTranslatorUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, DEFAULT_TIME_FORMAT, formatNumber } from '@veloceapps/core';
4
- import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, of, forkJoin, zip, combineLatest, Subject, filter as filter$1, shareReplay as shareReplay$1, finalize, takeUntil, buffer, debounceTime, share, take as take$1, distinctUntilChanged } from 'rxjs';
3
+ import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, QuoteDraft, isDefined, ConfigurationProcessorTypes, EntityUtil, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, DEFAULT_ACTION_CODE_LABELS, parseJsonSafely, ConfigurationMode, extractErrorDetails, ConfigurationTranslatorUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, DEFAULT_TIME_FORMAT, formatNumber } from '@veloceapps/core';
4
+ import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, forkJoin, of, zip, combineLatest, Subject, filter as filter$1, shareReplay as shareReplay$1, finalize, takeUntil, buffer, debounceTime, share, take as take$1, distinctUntilChanged } from 'rxjs';
5
5
  import { map, filter, tap, switchMap as switchMap$1, skip, take, shareReplay, catchError as catchError$1, finalize as finalize$1, first } from 'rxjs/operators';
6
6
  import * as i1 from '@veloceapps/api';
7
7
  import { ApiModule } from '@veloceapps/api';
8
- import { merge, isEmpty, isEqual, cloneDeep, assign, flatten, entries, sortBy, map as map$2, omit, uniqBy, transform } from 'lodash';
8
+ import { merge, isEqual, cloneDeep, assign, flatten, entries, sortBy, map as map$2, omit, uniqBy, transform } from 'lodash';
9
9
  import * as i6 from '@veloceapps/components';
10
10
  import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
11
11
  import moment from 'moment';
@@ -186,9 +186,11 @@ class FlowInfoService {
186
186
  this.flowSubj$ = new BehaviorSubject(null);
187
187
  this.flow$ = this.flowSubj$.asObservable();
188
188
  }
189
- init$(flowId, params) {
190
- this.params = params;
191
- return this.flowsApiService.getFlow(flowId).pipe(switchMap(flow => this.initFlowTemplates$(flow).pipe(map$1(() => flow))), tap$1(flow => this.flowSubj$.next(flow)), map$1(noop), catchError(e => {
189
+ init$(flowId, routeQueryParams) {
190
+ return this.flowsApiService.getFlow(flowId).pipe(switchMap(flow => this.initFlowTemplates$(flow).pipe(map$1(() => flow))), tap$1(flow => {
191
+ this.params = Object.assign(Object.assign({}, routeQueryParams), flow.properties.queryParams);
192
+ this.flowSubj$.next(flow);
193
+ }), map$1(noop), catchError(e => {
192
194
  this.flowSubj$.next(null);
193
195
  return throwError(() => e);
194
196
  }));
@@ -200,9 +202,6 @@ class FlowInfoService {
200
202
  }
201
203
  initFlowTemplates$(flow) {
202
204
  var _a, _b, _c;
203
- if (isEmpty(flow.properties.templates)) {
204
- return of(undefined);
205
- }
206
205
  return forkJoin([
207
206
  this.templatesApiService.fetchTemplates$(),
208
207
  (_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([]),
@@ -295,8 +294,9 @@ class QuoteDraftService {
295
294
  get assetsState() {
296
295
  return this.assetsSubj$.value;
297
296
  }
298
- constructor(context, accountApiService, quoteApiService) {
297
+ constructor(context, flowInfoService, accountApiService, quoteApiService) {
299
298
  this.context = context;
299
+ this.flowInfoService = flowInfoService;
300
300
  this.accountApiService = accountApiService;
301
301
  this.quoteApiService = quoteApiService;
302
302
  this.quoteSubj$ = new BehaviorSubject(null);
@@ -321,7 +321,9 @@ class QuoteDraftService {
321
321
  const ctx = this.context.resolve();
322
322
  const isAccountMode = this.context.mode === ConfigurationContextMode.ACCOUNT;
323
323
  const accountId = isAccountMode ? headerId : ctx.properties.AccountId;
324
- return zip(accountId ? this.accountApiService.getAssetsState(accountId, params) : of(null), isAccountMode ? of(QuoteDraft.emptyQuote(ConfigurationContextMode.ACCOUNT)) : this.quoteApiService.getQuoteState(headerId, params)).pipe(tap(([assets, quote]) => {
324
+ return zip(accountId ? this.accountApiService.getAssetsState(accountId, params) : of(null), isAccountMode
325
+ ? of(QuoteDraft.emptyQuote(ConfigurationContextMode.ACCOUNT))
326
+ : this.quoteApiService.getQuoteState(headerId, params)).pipe(tap(([assets, quote]) => {
325
327
  if (assets) {
326
328
  this.assetsSubj$.next(assets);
327
329
  }
@@ -387,10 +389,11 @@ class QuoteDraftService {
387
389
  return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
388
390
  }
389
391
  get isStandalone() {
390
- return this.context.resolve().properties.standalone === 'true';
392
+ var _a, _b;
393
+ return (_b = (_a = this.flowInfoService.flow) === null || _a === void 0 ? void 0 : _a.properties.standalone) !== null && _b !== void 0 ? _b : false;
391
394
  }
392
395
  get isStandalone$() {
393
- return this.context.resolve$().pipe(map(() => this.isStandalone));
396
+ return this.flowInfoService.flow$.pipe(map(() => this.isStandalone));
394
397
  }
395
398
  getInitialCurrentState() {
396
399
  return this.initialCurrentState;
@@ -417,11 +420,11 @@ class QuoteDraftService {
417
420
  }
418
421
  }
419
422
  }
420
- QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.AccountApiService }, { token: i1.QuoteApiService }], target: i0.ɵɵFactoryTarget.Injectable });
423
+ QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: FlowInfoService }, { token: i1.AccountApiService }, { token: i1.QuoteApiService }], target: i0.ɵɵFactoryTarget.Injectable });
421
424
  QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService });
422
425
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, decorators: [{
423
426
  type: Injectable
424
- }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.AccountApiService }, { type: i1.QuoteApiService }]; } });
427
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: FlowInfoService }, { type: i1.AccountApiService }, { type: i1.QuoteApiService }]; } });
425
428
 
426
429
  class FlowStateService {
427
430
  constructor(contextService, quoteDraftService, flowInfoService, flowConfiguration, processorsApiService, flowStateApiService, quoteApiService, toastService, customizationService) {
@@ -1532,7 +1535,12 @@ class ConfigurationService {
1532
1535
  this.showInactiveProductsConfirmation();
1533
1536
  }
1534
1537
  this.configurableRamp = result.lineItem;
1535
- }), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })), finalize$1(() => this.isLoadingSubj$.next(false)));
1538
+ }), map(({ lineItem }) => lineItem), catchError$1(error => throwError(() => {
1539
+ if (error.error) {
1540
+ return extractErrorDetails(error.error).join('. ');
1541
+ }
1542
+ return error.message || JSON.stringify(error);
1543
+ })), finalize$1(() => this.isLoadingSubj$.next(false)));
1536
1544
  }
1537
1545
  configureExternal$(props) {
1538
1546
  return this.runtimeService
@@ -2062,70 +2070,58 @@ class ConfigurationStateService {
2062
2070
  this.executedFunctions = {};
2063
2071
  this.configurationService.reset();
2064
2072
  }
2065
- execute$(req, forceSubscriptions) {
2066
- var _a;
2067
- const fullRequest = cloneDeep(req);
2068
- if (((_a = fullRequest.actions) === null || _a === void 0 ? void 0 : _a.length) || forceSubscriptions) {
2069
- for (const subscription of Object.values(this.subscriptions)) {
2070
- fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
2071
- }
2072
- }
2073
- let execution$;
2074
- if (this.isStatefulConfiguration) {
2075
- execution$ = this.executeStateful$(fullRequest);
2076
- }
2077
- else {
2078
- execution$ = this.executeStateless$(fullRequest);
2079
- }
2080
- return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
2081
- }
2082
- handleSelectorsResponse(selectors) {
2083
- Object.entries(selectors).forEach(([requestId, selectorResult]) => {
2084
- var _a;
2085
- if (!selectorResult.success) {
2086
- this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
2087
- }
2088
- const subscription$ = (_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$;
2089
- if (subscription$) {
2090
- subscription$.next(selectorResult);
2091
- }
2092
- });
2073
+ execute$(exec) {
2074
+ const request = this.execToRequest(exec);
2075
+ return this.executeRequest$(request).pipe(map$1(result => {
2076
+ // Keep only requested results
2077
+ const actualSelectors = Object.entries(result.selectors).reduce((trunk, [requestId, result]) => {
2078
+ var _a;
2079
+ if ((_a = exec.selectors) === null || _a === void 0 ? void 0 : _a[requestId]) {
2080
+ trunk[requestId] = result;
2081
+ }
2082
+ return trunk;
2083
+ }, {});
2084
+ return actualSelectors;
2085
+ }));
2093
2086
  }
2094
2087
  dispatch$(actionName, inputData = {}) {
2095
- return this.execute$({ actions: [{ apiName: actionName, inputData, ownerId: this.ownerId }] });
2088
+ const exec = {
2089
+ actions: [{ name: actionName, inputData }],
2090
+ };
2091
+ const request = this.execToRequest(exec);
2092
+ return this.executeRequest$(request);
2096
2093
  }
2097
2094
  select$(selectorName, inputData = {}) {
2098
2095
  const requestId = UUID.UUID();
2099
- return this.execute$({
2096
+ const request = this.execToRequest({
2100
2097
  selectors: {
2101
2098
  [requestId]: {
2102
- apiName: selectorName,
2099
+ name: selectorName,
2103
2100
  inputData,
2104
- ownerId: this.ownerId,
2105
2101
  },
2106
2102
  },
2107
- }).pipe(map$1(response => response.selectors[requestId]));
2103
+ });
2104
+ return this.executeRequest$(request).pipe(map$1(response => response.selectors[requestId]));
2108
2105
  }
2109
2106
  subscribe$(selectorName, inputData = {}, options) {
2110
2107
  const requestId = UUID.UUID();
2111
2108
  let subscription = this.subscriptions[requestId];
2112
2109
  if (!subscription) {
2113
- const request = {
2110
+ const request = this.execToRequest({
2114
2111
  selectors: {
2115
2112
  [requestId]: {
2116
- apiName: selectorName,
2113
+ name: selectorName,
2117
2114
  inputData,
2118
- ownerId: this.ownerId,
2119
2115
  },
2120
2116
  },
2121
- };
2117
+ });
2122
2118
  subscription = {
2123
2119
  request,
2124
2120
  data$: new BehaviorSubject(this.NOT_INITIALIZED),
2125
2121
  };
2126
2122
  this.subscriptions[requestId] = subscription;
2127
2123
  if (!(options === null || options === void 0 ? void 0 : options.cold)) {
2128
- this.execute$(request).subscribe();
2124
+ this.executeRequest$(request).subscribe();
2129
2125
  }
2130
2126
  }
2131
2127
  return subscription.data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), distinctUntilChanged(), finalize(() => {
@@ -2232,6 +2228,53 @@ class ConfigurationStateService {
2232
2228
  initStateless$() {
2233
2229
  return this.configurationService.configure().pipe(map$1(() => undefined));
2234
2230
  }
2231
+ execToRequest(exec) {
2232
+ var _a;
2233
+ return {
2234
+ actions: (_a = exec.actions) === null || _a === void 0 ? void 0 : _a.map(action => {
2235
+ var _a;
2236
+ return ({
2237
+ apiName: action.name,
2238
+ ownerId: this.ownerId,
2239
+ inputData: (_a = action.inputData) !== null && _a !== void 0 ? _a : {},
2240
+ });
2241
+ }),
2242
+ selectors: exec.selectors &&
2243
+ Object.entries(exec.selectors).reduce((trunk, [key, selector]) => {
2244
+ var _a;
2245
+ return (Object.assign(Object.assign({}, trunk), { [key]: { apiName: selector.name, ownerId: this.ownerId, inputData: (_a = selector.inputData) !== null && _a !== void 0 ? _a : {} } }));
2246
+ }, {}),
2247
+ };
2248
+ }
2249
+ handleSelectorsResponse(selectors) {
2250
+ Object.entries(selectors).forEach(([requestId, selectorResult]) => {
2251
+ var _a;
2252
+ if (!selectorResult.success) {
2253
+ this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
2254
+ }
2255
+ const subscription$ = (_a = this.subscriptions[requestId]) === null || _a === void 0 ? void 0 : _a.data$;
2256
+ if (subscription$) {
2257
+ subscription$.next(selectorResult);
2258
+ }
2259
+ });
2260
+ }
2261
+ executeRequest$(req, forceSubscriptions) {
2262
+ var _a;
2263
+ const fullRequest = cloneDeep(req);
2264
+ if (((_a = fullRequest.actions) === null || _a === void 0 ? void 0 : _a.length) || forceSubscriptions) {
2265
+ for (const subscription of Object.values(this.subscriptions)) {
2266
+ fullRequest.selectors = assign(fullRequest.selectors, subscription.request.selectors);
2267
+ }
2268
+ }
2269
+ let execution$;
2270
+ if (this.isStatefulConfiguration) {
2271
+ execution$ = this.executeStateful$(fullRequest);
2272
+ }
2273
+ else {
2274
+ execution$ = this.executeStateless$(fullRequest);
2275
+ }
2276
+ return execution$.pipe(tap$1(result => this.handleSelectorsResponse(result.selectors)));
2277
+ }
2235
2278
  executeStateless$(request) {
2236
2279
  this.executionInProgress$.next(true);
2237
2280
  return of(undefined).pipe(switchMap(() => {