@veloceapps/sdk 11.0.0-13 → 11.0.0-15

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.
@@ -14,7 +14,8 @@ import * as i3 from 'primeng/button';
14
14
  import { ButtonModule } from 'primeng/button';
15
15
  import * as i1 from 'primeng/dynamicdialog';
16
16
  import * as i1$1 from '@veloceapps/api/v2';
17
- import { BehaviorSubject, Subject, filter, first, tap, takeUntil, catchError, of, map, switchMap, shareReplay, startWith, distinctUntilChanged, from, take, combineLatest, timer, noop } from 'rxjs';
17
+ import { UIDefinitionsApiService } from '@veloceapps/api/v2';
18
+ import { BehaviorSubject, Subject, filter, first, tap, takeUntil, catchError, of, map, switchMap, shareReplay, startWith, distinctUntilChanged, from, take, combineLatest } from 'rxjs';
18
19
  import { DomHandler } from 'primeng/dom';
19
20
  import * as i1$2 from '@angular/router';
20
21
  import { NavigationEnd, NavigationStart, NavigationCancel, NavigationError, RouterModule } from '@angular/router';
@@ -1149,80 +1150,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1149
1150
  }] });
1150
1151
 
1151
1152
  class ProductComponent {
1152
- constructor(
1153
- // private configurationRuntimeService: ConfigurationRuntimeService,
1154
- configurationService, configurationStateService, salesTransactionService, flowInfoService, integrationState, uiDefinitionsApiService, customizationService) {
1155
- this.configurationService = configurationService;
1153
+ constructor(route, configurationStateService) {
1154
+ this.route = route;
1156
1155
  this.configurationStateService = configurationStateService;
1157
- this.salesTransactionService = salesTransactionService;
1158
- this.flowInfoService = flowInfoService;
1159
- this.integrationState = integrationState;
1160
- this.uiDefinitionsApiService = uiDefinitionsApiService;
1161
- this.customizationService = customizationService;
1162
1156
  this.uiDefinitionContainer$ = new BehaviorSubject(null);
1157
+ const uiDefContainer = this.route.snapshot.data['uiDef'];
1158
+ this.uiDefinitionContainer$.next(uiDefContainer);
1163
1159
  this.config = {
1164
1160
  init$: () => this.init$(),
1165
1161
  };
1166
1162
  }
1167
- customizeUI$() {
1168
- const { productId } = this.flowInfoService.context;
1169
- if (!productId || !this.customizationService?.getUiDefinition) {
1170
- return of(undefined);
1171
- }
1172
- return this.customizationService.getUiDefinition(productId).pipe(map(uiDefinitionContainer => {
1173
- this.uiDefinitionContainer$.next(uiDefinitionContainer);
1174
- }));
1175
- }
1176
- fetchUIDefinition$() {
1177
- const flowContext = this.flowInfoService.context;
1178
- if (flowContext.requiredUIDefinitionId) {
1179
- return this.uiDefinitionsApiService
1180
- .fetchUIDefinition$(flowContext.requiredUIDefinitionId)
1181
- .pipe(map((uiDefContainer) => this.uiDefinitionContainer$.next(uiDefContainer)));
1182
- }
1183
- return this.uiDefinitionsApiService
1184
- .fetchUIDefinitions$({
1185
- productId: flowContext.productId,
1186
- defaultUIDefinitionId: flowContext.defaultUIDefinitionId,
1187
- })
1188
- .pipe(map((uiDefinitionContainers) => {
1189
- const uiDefContainer = uiDefinitionContainers[0];
1190
- if (uiDefContainer) {
1191
- this.uiDefinitionContainer$.next(uiDefContainer);
1192
- }
1193
- }));
1194
- }
1195
1163
  init$() {
1196
- let state$;
1197
- if (!this.flowInfoService.isStateful) {
1198
- state$ = this.salesTransactionService.state$;
1199
- }
1200
- else {
1201
- state$ = of(undefined);
1202
- }
1203
- return state$.pipe(first(), tap(() => {
1204
- if (!this.flowInfoService.context.productId) {
1205
- throw new Error(`Unable to start configuration for 'productId == null'`);
1206
- }
1207
- }), switchMap(() => this.customizeUI$()), switchMap(() => (this.uiDefinitionContainer$.value ? of(undefined) : this.fetchUIDefinition$())), tap(() => {
1208
- if (!this.uiDefinitionContainer$.value) {
1209
- throw new Error('Product does not have Configuration UI');
1210
- }
1211
- }), switchMap(() => this.configurationStateService.init$()), switchMap(() => timer(1)), // wait until updates inputs on child components
1212
- map(noop));
1164
+ return this.configurationStateService.init$();
1213
1165
  }
1214
1166
  }
1215
- ProductComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductComponent, deps: [{ token: i2.ConfigurationService }, { token: i2.ConfigurationStateService }, { token: i2.SalesTransactionService }, { token: i2.FlowInfoService }, { token: i2.IntegrationState }, { token: i1$1.UIDefinitionsApiService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Component });
1167
+ ProductComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductComponent, deps: [{ token: i1$2.ActivatedRoute }, { token: i2.ConfigurationStateService }], target: i0.ɵɵFactoryTarget.Component });
1216
1168
  ProductComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.9", type: ProductComponent, selector: "vl-flow-product", ngImport: i0, template: "<vl-cms-preview [uiDefinition]=\"(uiDefinitionContainer$ | async)?.source\" [config]=\"config\"></vl-cms-preview>\n", styles: [""], dependencies: [{ kind: "component", type: i5.PreviewComponent, selector: "vl-cms-preview", inputs: ["uiDefinition", "config"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1217
1169
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ProductComponent, decorators: [{
1218
1170
  type: Component,
1219
1171
  args: [{ selector: 'vl-flow-product', changeDetection: ChangeDetectionStrategy.OnPush, template: "<vl-cms-preview [uiDefinition]=\"(uiDefinitionContainer$ | async)?.source\" [config]=\"config\"></vl-cms-preview>\n" }]
1220
- }], ctorParameters: function () { return [{ type: i2.ConfigurationService }, { type: i2.ConfigurationStateService }, { type: i2.SalesTransactionService }, { type: i2.FlowInfoService }, { type: i2.IntegrationState }, { type: i1$1.UIDefinitionsApiService }, { type: undefined, decorators: [{
1221
- type: Optional
1222
- }, {
1223
- type: Inject,
1224
- args: [FLOW_CUSTOMIZATION]
1225
- }] }]; } });
1172
+ }], ctorParameters: function () { return [{ type: i1$2.ActivatedRoute }, { type: i2.ConfigurationStateService }]; } });
1226
1173
 
1227
1174
  class ProductModule {
1228
1175
  }
@@ -1493,6 +1440,43 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1493
1440
  type: Injectable
1494
1441
  }], ctorParameters: function () { return [{ type: i1$2.Router }, { type: i2.QuoteDraftService }, { type: FlowRouterService }, { type: i2.FlowInfoService }, { type: i2.FlowStateService }]; } });
1495
1442
 
1443
+ const resolveUIDefinition = () => {
1444
+ const customizationService = inject(FLOW_CUSTOMIZATION, { optional: true });
1445
+ const flowInfoService = inject(FlowInfoService);
1446
+ const uiDefinitionsApiService = inject(UIDefinitionsApiService);
1447
+ const { productId } = flowInfoService.context;
1448
+ if (!productId) {
1449
+ throw new Error(`Unable to start configuration for 'productId == null'`);
1450
+ }
1451
+ return of(undefined).pipe(switchMap(() => {
1452
+ // Try resolving via customization service
1453
+ if (!productId || !customizationService?.getUiDefinition) {
1454
+ return of(undefined);
1455
+ }
1456
+ return customizationService.getUiDefinition(productId);
1457
+ }), switchMap(uiDefContainer => {
1458
+ // Resolve UIDefinition from the org
1459
+ if (uiDefContainer) {
1460
+ return of(uiDefContainer);
1461
+ }
1462
+ if (flowInfoService.context.requiredUIDefinitionId) {
1463
+ return uiDefinitionsApiService.fetchUIDefinition$(flowInfoService.context.requiredUIDefinitionId);
1464
+ }
1465
+ return uiDefinitionsApiService
1466
+ .fetchUIDefinitions$({
1467
+ productId,
1468
+ defaultUIDefinitionId: flowInfoService.context.defaultUIDefinitionId,
1469
+ })
1470
+ .pipe(map((uiDefinitionContainers) => {
1471
+ const uiDefContainer = uiDefinitionContainers[0];
1472
+ if (!uiDefContainer) {
1473
+ throw new Error(`UI Definition for productId=${productId} is not resolved`);
1474
+ }
1475
+ return uiDefContainer;
1476
+ }));
1477
+ }));
1478
+ };
1479
+
1496
1480
  const rootRoute = {
1497
1481
  id: VELOCE_FLOW_ROOT_ROUTE,
1498
1482
  path: '',
@@ -1515,7 +1499,7 @@ const rootRoute = {
1515
1499
  path: 'product',
1516
1500
  component: ProductComponent,
1517
1501
  runGuardsAndResolvers: 'paramsOrQueryParamsChange',
1518
- resolve: { quote: QuoteResolver },
1502
+ resolve: { quote: QuoteResolver, uiDef: resolveUIDefinition },
1519
1503
  canDeactivate: [ProductUnloadGuard],
1520
1504
  data: { showHeader: true },
1521
1505
  },