@veloceapps/sdk 8.0.0-185 → 8.0.0-187

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 (29) hide show
  1. package/cms/vendor-map.d.ts +3 -4
  2. package/core/modules/configuration/services/configuration-state.service.d.ts +2 -4
  3. package/core/modules/configuration/services/configuration.service.d.ts +1 -1
  4. package/core/services/flow-state.service.d.ts +1 -0
  5. package/core/services/quote-draft.service.d.ts +8 -31
  6. package/core/types/flow-state.types.d.ts +5 -0
  7. package/core/types/integration.types.d.ts +0 -1
  8. package/core/utils/line-item.utils.d.ts +1 -2
  9. package/esm2020/core/modules/configuration/services/configuration-state.service.mjs +16 -7
  10. package/esm2020/core/modules/configuration/services/configuration.service.mjs +10 -8
  11. package/esm2020/core/modules/flow-configuration/services/flow-configuration.service.mjs +3 -3
  12. package/esm2020/core/services/flow-state.service.mjs +31 -25
  13. package/esm2020/core/services/quote-draft.service.mjs +27 -100
  14. package/esm2020/core/types/flow-state.types.mjs +1 -1
  15. package/esm2020/core/types/integration.types.mjs +1 -1
  16. package/esm2020/core/utils/line-item.utils.mjs +4 -18
  17. package/esm2020/src/pages/product/product.component.mjs +15 -12
  18. package/esm2020/src/services/flow.service.mjs +38 -18
  19. package/fesm2015/veloceapps-sdk-core.mjs +455 -522
  20. package/fesm2015/veloceapps-sdk-core.mjs.map +1 -1
  21. package/fesm2015/veloceapps-sdk.mjs +47 -28
  22. package/fesm2015/veloceapps-sdk.mjs.map +1 -1
  23. package/fesm2020/veloceapps-sdk-core.mjs +418 -487
  24. package/fesm2020/veloceapps-sdk-core.mjs.map +1 -1
  25. package/fesm2020/veloceapps-sdk.mjs +50 -27
  26. package/fesm2020/veloceapps-sdk.mjs.map +1 -1
  27. package/package.json +1 -1
  28. package/src/pages/product/product.component.d.ts +1 -1
  29. package/src/services/flow.service.d.ts +1 -0
@@ -3,9 +3,9 @@ import { Injectable, InjectionToken, Optional, Inject, NgModule, inject, Directi
3
3
  import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, isDefined, ConfigurationProcessorTypes, EntityUtil, 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, ChargeGroupUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, DEFAULT_TIME_FORMAT, formatNumber } from '@veloceapps/core';
4
4
  import * as i1 from '@veloceapps/api';
5
5
  import { ApiModule } from '@veloceapps/api';
6
- import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, of, forkJoin, Subject, filter as filter$1, zip, combineLatest, shareReplay as shareReplay$1, finalize, takeUntil, buffer, debounceTime, share, take as take$1, distinctUntilChanged } from 'rxjs';
6
+ 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';
7
7
  import { map, filter, tap, switchMap as switchMap$1, skip, take, shareReplay, catchError as catchError$1, finalize as finalize$1, first } from 'rxjs/operators';
8
- import { merge, isEmpty, flatten, entries, sortBy, map as map$2, omit, isEqual, cloneDeep, assign, uniqBy, transform } from 'lodash';
8
+ import { merge, isEmpty, isEqual, cloneDeep, assign, flatten, entries, sortBy, map as map$2, uniqBy, omit, transform } from 'lodash';
9
9
  import * as i6 from '@veloceapps/components';
10
10
  import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
11
11
  import { HttpErrorResponse } from '@angular/common/http';
@@ -284,287 +284,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
284
284
  args: [FLOW_CUSTOMIZATION]
285
285
  }] }]; } });
286
286
 
287
- const findLineItem = (id, lineItems) => {
288
- return findLineItemWithComparator(lineItems, (li) => li.id === id);
289
- };
290
- const findLineItemWithComparator = (lineItems, comparator) => {
291
- let currentLevel = lineItems;
292
- while (currentLevel.length) {
293
- const found = currentLevel.find(comparator);
294
- if (found) {
295
- return found;
296
- }
297
- currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
298
- }
299
- return;
300
- };
301
- const insertLineItem = (lineItem, parentId, toInsert) => {
302
- const insertData = lineItem.id === parentId ? [toInsert] : [];
303
- return {
304
- ...lineItem,
305
- lineItems: [
306
- ...insertData,
307
- ...lineItem.lineItems.map(li => {
308
- return insertLineItem(li, parentId, toInsert);
309
- }),
310
- ],
311
- };
312
- };
313
- const removeLineItem = (lineItem, idToRemove) => {
314
- return {
315
- ...lineItem,
316
- lineItems: lineItem.lineItems
317
- .map(li => {
318
- if (li.id === idToRemove) {
319
- return;
320
- }
321
- else if (li.lineItems.length) {
322
- return removeLineItem(li, idToRemove);
323
- }
324
- return li;
325
- })
326
- .filter(r => !!r),
327
- };
328
- };
329
- const replaceLineItem = (lineItem, replaceTo, skipCardinalityCalculation = false) => {
330
- if (lineItem.id === replaceTo.id) {
331
- if (!skipCardinalityCalculation) {
332
- return { ...recalculateCardinalityVariables(lineItem, replaceTo) };
333
- }
334
- else {
335
- return { ...replaceTo };
336
- }
337
- }
338
- return {
339
- ...lineItem,
340
- lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo, skipCardinalityCalculation)),
341
- };
342
- };
343
- const collectCardinalityComputations = (portDomains) => {
344
- const cardinalityComputations = new Map();
345
- entries(portDomains).forEach(([key, portDomain]) => {
346
- cardinalityComputations.set(key, portDomain.properties['cardinalityComputation'] === 'true');
347
- });
348
- return cardinalityComputations;
349
- };
350
- const calculateCardinalityVariables = (lineItems, cardinalityComputations) => {
351
- const cardVars = new Map();
352
- lineItems
353
- .filter(({ port, type }) => !!port && !!type)
354
- .forEach(li => {
355
- if (cardinalityComputations.get(`${li.port}`)) {
356
- const cardinalityVariableName = `#CV-${li.type}@${li.port}`;
357
- cardVars.set(cardinalityVariableName, (cardVars.get(cardinalityVariableName) ?? 0) + li.qty);
358
- }
359
- });
360
- return cardVars;
361
- };
362
- const cardinalityRegexp = new RegExp('#CV-[a-zA-Z0-9_]+@(?<portName>[a-zA-Z0-9_]+)');
363
- const recalculateCardinalityVariables = (original, updated) => {
364
- const cardinalityComputations = collectCardinalityComputations(updated.portDomains ?? original.portDomains ?? {});
365
- const cardinalityVariables = calculateCardinalityVariables(updated.lineItems, cardinalityComputations);
366
- const originalCardinalityVariables = calculateCardinalityVariables(original.lineItems, cardinalityComputations);
367
- originalCardinalityVariables.forEach((value, key) => {
368
- const execArray = cardinalityRegexp.exec(key);
369
- const portName = execArray?.groups?.['portName'];
370
- if (!portName || cardinalityComputations.get(portName)) {
371
- if (cardinalityVariables.get(key) === value) {
372
- // no need to update cardinality if no changes
373
- cardinalityVariables.delete(key);
374
- }
375
- else if (!cardinalityVariables.has(key)) {
376
- // remove last item from port
377
- cardinalityVariables.set(key, 0);
378
- }
379
- }
380
- });
381
- return {
382
- ...updated,
383
- attributes: upsertAttributes(updated.attributes, [...cardinalityVariables].map(([name, value]) => ({ name, value, cfgStatus: 'Changed' }))),
384
- };
385
- };
386
- const mapAttributes = (attributes) => {
387
- return attributes.reduce((acc, { name, value }) => ({ ...acc, [name]: value }), {});
388
- };
389
- const getAttributes = (attributes, names = []) => {
390
- const filtered = attributes.filter(({ name }) => names.includes(name));
391
- return sortBy(filtered, [({ name }) => names.indexOf(name)]);
392
- };
393
- const upsertAttributes = (originalAttributes, attributesToUpsert) => {
394
- return attributesToUpsert.reduce((acc, { name, value }) => {
395
- const [origAttr] = getAttributes(acc, [name]);
396
- return [
397
- ...acc.filter(attr => attr.name !== name),
398
- { ...(origAttr ?? { name, type: '' }), cfgStatus: origAttr ? 'Changed' : 'User', value },
399
- ];
400
- }, originalAttributes);
401
- };
402
- const patchAttributes = (rootLineItem, id, attrs, skipCardinalityCalculation = false) => {
403
- const lineItem = findLineItem(id, [rootLineItem]);
404
- if (!lineItem) {
405
- return rootLineItem;
406
- }
407
- const attributes = upsertAttributes(lineItem.attributes, attrs);
408
- return replaceLineItem(rootLineItem, { ...lineItem, attributes }, skipCardinalityCalculation);
409
- };
410
- const getAttributeValue = (attributes, name) => attributes.find(attr => attr.name === name)?.value;
411
- const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
412
- return {
413
- id: UUID.UUID(),
414
- port,
415
- type,
416
- actionCode: 'ADD',
417
- cfgStatus: 'New',
418
- attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
419
- lineItems,
420
- parentId,
421
- qty: 1,
422
- };
423
- };
424
- const getRecommendedPrices = (portDomain, type) => {
425
- const domainType = portDomain.domainTypes.find(({ name }) => name === type);
426
- const [net, list] = domainType?.recommendedPrices
427
- ?.filter(({ chargeMethod }) => chargeMethod === 'ONE_TIME')
428
- .reduce((acc, rp) => {
429
- const [netPrice, listPrice] = acc;
430
- return [netPrice + rp.netPrice, listPrice + rp.listPrice];
431
- }, [0, 0]) ?? [0, 0];
432
- return { net, list };
433
- };
434
- const generateModifiedAssetsMap = (lineItems) => {
435
- return lineItems.reduce((acc, li) => {
436
- const isModified = isLineItemModified(li);
437
- if (!isModified) {
438
- return acc;
439
- }
440
- const target = getOriginParent(lineItems, li);
441
- const id = target?.assetId ?? target?.openOrderLineItemId;
442
- if (id) {
443
- acc[id] = true;
444
- }
445
- return acc;
446
- }, {});
447
- };
448
- const getOriginParent = (lineItems, currentLineItem) => {
449
- let target = currentLineItem;
450
- while (target && target.rampInstanceId) {
451
- target = lineItems.find(sub => sub.id === currentLineItem.rampInstanceId);
452
- }
453
- return target;
454
- };
455
- const isLineItemModified = (lineItem) => {
456
- if (lineItem.actionCode === 'EXIST' && lineItem.status === 'PENDING') {
457
- return false;
458
- }
459
- return lineItem.actionCode !== 'EXIST';
460
- };
461
- const multiplyLineItems = (lineItem, qty, split) => {
462
- if (split) {
463
- const unifyIds = (lineItem) => ({
464
- ...lineItem,
465
- id: UUID.UUID(),
466
- lineItems: lineItem.lineItems.map(unifyIds),
467
- });
468
- return map$2(new Array(qty), () => unifyIds(lineItem));
469
- }
470
- else {
471
- return [
472
- {
473
- ...lineItem,
474
- qty: qty,
475
- },
476
- ];
477
- }
478
- };
479
- const isTechnicalAttribute = (name) => {
480
- return name.startsWith('#') || name.startsWith('$');
481
- };
482
- const filterOutTechnicalAttributes = (attributes) => {
483
- return attributes.filter(({ name }) => !isTechnicalAttribute(name));
484
- };
485
-
486
- var lineItem_utils = /*#__PURE__*/Object.freeze({
487
- __proto__: null,
488
- filterOutTechnicalAttributes: filterOutTechnicalAttributes,
489
- findLineItem: findLineItem,
490
- findLineItemWithComparator: findLineItemWithComparator,
491
- generateLineItem: generateLineItem,
492
- generateModifiedAssetsMap: generateModifiedAssetsMap,
493
- getAttributeValue: getAttributeValue,
494
- getAttributes: getAttributes,
495
- getOriginParent: getOriginParent,
496
- getRecommendedPrices: getRecommendedPrices,
497
- insertLineItem: insertLineItem,
498
- isLineItemModified: isLineItemModified,
499
- isTechnicalAttribute: isTechnicalAttribute,
500
- mapAttributes: mapAttributes,
501
- multiplyLineItems: multiplyLineItems,
502
- patchAttributes: patchAttributes,
503
- recalculateCardinalityVariables: recalculateCardinalityVariables,
504
- removeLineItem: removeLineItem,
505
- replaceLineItem: replaceLineItem,
506
- upsertAttributes: upsertAttributes
507
- });
508
-
509
- class LineItemWorker {
510
- constructor(src) {
511
- this.li = { ...src };
512
- }
513
- insert(parentId, toInsert) {
514
- return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
515
- }
516
- remove(id) {
517
- return new LineItemWorker(removeLineItem(this.li, id));
518
- }
519
- replace(toReplace, skipCardinalityCalculation = false) {
520
- return new LineItemWorker(replaceLineItem(this.li, toReplace, skipCardinalityCalculation));
521
- }
522
- patchAttribute(attrs, id, skipCardinalityCalculation = false) {
523
- return new LineItemWorker(patchAttributes(this.li, id ?? this.li.id, attrs, skipCardinalityCalculation));
524
- }
525
- }
526
-
527
- function extractMetadata(uiDefinition) {
528
- return omit(uiDefinition, [
529
- 'children',
530
- 'pages',
531
- 'components',
532
- ]);
533
- }
534
-
535
- class IntegrationState {
536
- constructor() {
537
- this.stateSubj$ = new BehaviorSubject({});
538
- this.action$ = new Subject();
539
- }
540
- get state$() {
541
- return this.stateSubj$.asObservable();
542
- }
543
- get state() {
544
- return this.stateSubj$.getValue();
545
- }
546
- patchState(update) {
547
- this.stateSubj$.next({ ...this.stateSubj$.getValue(), ...update });
548
- }
549
- dispatch(action) {
550
- this.action$.next(action);
551
- }
552
- listen$(actionType) {
553
- return this.action$.pipe(filter$1(action => action.type === actionType), map$1(action => action.payload));
554
- }
555
- listenAll$() {
556
- return this.action$.asObservable();
557
- }
558
- clear() {
559
- this.stateSubj$.next({});
560
- }
561
- }
562
- IntegrationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
563
- IntegrationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState });
564
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState, decorators: [{
565
- type: Injectable
566
- }] });
567
-
568
287
  class QuoteDraftService {
569
288
  get isInitialized$() {
570
289
  return this.isInitializedSubj$.asObservable();
@@ -590,30 +309,28 @@ class QuoteDraftService {
590
309
  return this.quoteSubj$.pipe(map(() => this.hasProducts));
591
310
  }
592
311
  get hasProducts() {
593
- const quoteDraft = this.quoteSubj$.value;
594
- return this.filterByActivePriceList(quoteDraft?.currentState || []).some(li => !li.assetId && !li.openOrderLineItemId);
312
+ return Boolean(this.quoteSubj$.value?.currentState.length);
595
313
  }
596
314
  get hasAssets$() {
597
- return this.quoteSubj$.pipe(map(() => this.hasAssets));
315
+ return this.assetsSubj$.pipe(map(() => this.hasAssets));
598
316
  }
599
317
  get hasAssets() {
600
- const quoteDraft = this.quoteSubj$.value;
601
- return this.filterByActivePriceList(quoteDraft?.currentState || []).some(li => li.assetId || li.openOrderLineItemId);
318
+ return Boolean(this.assetsSubj$.value?.currentState.length);
319
+ }
320
+ get assetsState() {
321
+ return this.assetsSubj$.value;
602
322
  }
603
- constructor(context, quoteApiService, priceApiService, integrationState) {
323
+ constructor(context, accountApiService, quoteApiService) {
604
324
  this.context = context;
325
+ this.accountApiService = accountApiService;
605
326
  this.quoteApiService = quoteApiService;
606
- this.priceApiService = priceApiService;
607
- this.integrationState = integrationState;
608
327
  this.quoteSubj$ = new BehaviorSubject(null);
328
+ this.assetsSubj$ = new BehaviorSubject(null);
609
329
  this.resetSubj$ = new BehaviorSubject(true);
610
330
  this.isInitializedSubj$ = new BehaviorSubject(false);
611
331
  this.initialCurrentState = [];
612
332
  this._hasUnsavedChanges = false;
613
- this.allPriceLists = [];
614
- this.assetPriceLists = [];
615
333
  this.reset$ = this.resetSubj$.asObservable();
616
- this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), map(priceList => priceList ?? null));
617
334
  this.isInitializedSubj$
618
335
  .pipe(filter(isInitialized => isInitialized), switchMap$1(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
619
336
  .subscribe();
@@ -621,19 +338,24 @@ class QuoteDraftService {
621
338
  reset() {
622
339
  this.resetSubj$.next(true);
623
340
  this.quoteSubj$.next(null);
341
+ this.assetsSubj$.next(null);
624
342
  this.isInitialized = false;
625
343
  this.hasUnsavedChanges = false;
626
344
  }
627
- init(quoteId, params) {
628
- return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
629
- this.allPriceLists = allPriceLists;
345
+ init(headerId, params) {
346
+ const { mode } = this.context.resolve();
347
+ const assets$ = mode === ConfigurationContextMode.ACCOUNT
348
+ ? this.accountApiService.getAssetsState(headerId, params)
349
+ : of(undefined);
350
+ return zip(assets$, this.quoteApiService.getQuoteState(headerId, params)).pipe(tap(([assets, quote]) => {
351
+ if (assets) {
352
+ this.assetsSubj$.next(assets);
353
+ }
630
354
  this.quoteSubj$.next(quote);
631
355
  this.context.update(quote.context);
632
- this.populateActivePriceLists$();
633
356
  }), map(() => noop()), take(1));
634
357
  }
635
358
  finalizeInit() {
636
- this.initializeModifiedAssetsMap();
637
359
  this.isInitialized = true;
638
360
  this.hasUnsavedChanges = false;
639
361
  }
@@ -676,6 +398,9 @@ class QuoteDraftService {
676
398
  approvalItems: priceSummary.approvalItems,
677
399
  });
678
400
  }
401
+ setAssetsState(assetsState) {
402
+ this.assetsSubj$.next(assetsState);
403
+ }
679
404
  get quoteDraft$() {
680
405
  return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
681
406
  }
@@ -689,54 +414,12 @@ class QuoteDraftService {
689
414
  context: this.context.resolve(),
690
415
  };
691
416
  }
692
- get quoteDraftForActivePriceList() {
693
- const quoteDraft = this.quoteDraft;
694
- if (!quoteDraft) {
695
- return null;
696
- }
697
- return {
698
- ...quoteDraft,
699
- initialState: this.filterByActivePriceList(quoteDraft.initialState),
700
- currentState: this.filterByActivePriceList(quoteDraft.currentState),
701
- };
702
- }
703
417
  get currentState$() {
704
418
  return this.quoteDraft$.pipe(map(quote => quote.currentState));
705
419
  }
706
420
  get currentState() {
707
421
  return this.quoteDraft?.currentState ?? [];
708
422
  }
709
- /**
710
- * Stream of activeCurrentState
711
- */
712
- get activeCurrentState$() {
713
- return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
714
- }
715
- /**
716
- * activeCurrentState is currentState passed through additional filters
717
- */
718
- get activeCurrentState() {
719
- let currentState = this.quoteDraft?.currentState ?? [];
720
- currentState = this.filterByActivePriceList(currentState);
721
- return currentState;
722
- }
723
- /**
724
- * Stream of activeInitialState
725
- */
726
- get activeInitialState$() {
727
- return this.quoteDraft$.pipe(map(() => this.activeInitialState));
728
- }
729
- /**
730
- * activeInitialState is initialState passed through additional filters
731
- */
732
- get activeInitialState() {
733
- const ctx = this.context.resolve();
734
- let initialState = this.quoteDraft?.initialState ?? [];
735
- if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
736
- initialState = this.filterByActivePriceList(initialState);
737
- }
738
- return initialState;
739
- }
740
423
  get isStandalone() {
741
424
  return this.context.resolve().properties.standalone === 'true';
742
425
  }
@@ -759,35 +442,6 @@ class QuoteDraftService {
759
442
  }
760
443
  return false;
761
444
  }
762
- updateActivePriceList(priceListId) {
763
- this.context.update({ properties: { PriceListId: priceListId } });
764
- }
765
- populateActivePriceLists$() {
766
- const ctx = this.context.resolve();
767
- const quoteDraft = this.quoteDraft;
768
- if (!quoteDraft) {
769
- return;
770
- }
771
- // In ACCOUNT mode populate price lists from related assets
772
- if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
773
- // Populate list of price lists
774
- this.assetPriceLists = quoteDraft.currentState
775
- .map(({ priceListId }) => priceListId)
776
- .reduce((trunk, priceListId) => {
777
- if (!priceListId || trunk.some(item => item.id === priceListId)) {
778
- return trunk;
779
- }
780
- return [
781
- ...trunk,
782
- { id: priceListId, name: this.allPriceLists.find(item => item.id === priceListId)?.name ?? '' },
783
- ];
784
- }, []);
785
- }
786
- }
787
- filterByActivePriceList(lineItems) {
788
- const ctx = this.context.resolve();
789
- return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
790
- }
791
445
  markAsUpdated(quote) {
792
446
  if (quote?.context.properties.mode === ConfigurationContextMode.ACCOUNT) {
793
447
  this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
@@ -796,17 +450,12 @@ class QuoteDraftService {
796
450
  this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote?.currentState);
797
451
  }
798
452
  }
799
- initializeModifiedAssetsMap() {
800
- this.integrationState.patchState({
801
- modifiedAssets: generateModifiedAssetsMap(this.currentState),
802
- });
803
- }
804
453
  }
805
- QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }, { token: IntegrationState }], target: i0.ɵɵFactoryTarget.Injectable });
454
+ 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 });
806
455
  QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService });
807
456
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: QuoteDraftService, decorators: [{
808
457
  type: Injectable
809
- }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }, { type: IntegrationState }]; } });
458
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.AccountApiService }, { type: i1.QuoteApiService }]; } });
810
459
 
811
460
  class FlowStateService {
812
461
  constructor(contextService, quoteDraftService, flowInfoService, flowConfiguration, processorsApiService, flowStateApiService, quoteApiService, toastService, customizationService) {
@@ -838,8 +487,8 @@ class FlowStateService {
838
487
  this.isInitialized$()
839
488
  .pipe(filter$1(Boolean), filter$1(() => !this.getFlowSafe().properties.stateful), switchMap(() => this.flowConfiguration.updated$), switchMap(() => this.executeRequest$({}, true)))
840
489
  .subscribe();
841
- this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
842
- if (!flow.properties.stateful) {
490
+ this.charges$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
491
+ if (this.flowInfoService.isLegacy) {
843
492
  return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.charges));
844
493
  }
845
494
  else {
@@ -847,10 +496,10 @@ class FlowStateService {
847
496
  cold: true,
848
497
  }).pipe(map$1(response => (response.success ? response.result : {})));
849
498
  }
850
- }), filter$1(isDefined), shareReplay$1());
499
+ }), shareReplay$1(1));
851
500
  this.charges$.subscribe();
852
- this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
853
- if (!flow.properties.stateful) {
501
+ this.pricePlans$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
502
+ if (this.flowInfoService.isLegacy) {
854
503
  return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.pricePlans));
855
504
  }
856
505
  else {
@@ -858,10 +507,10 @@ class FlowStateService {
858
507
  cold: true,
859
508
  }).pipe(map$1(response => (response.success ? response.result : {})));
860
509
  }
861
- }), filter$1(isDefined), shareReplay$1());
510
+ }), shareReplay$1(1));
862
511
  this.pricePlans$.subscribe();
863
- this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(flow => {
864
- if (!flow.properties.stateful) {
512
+ this.activeMetrics$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
513
+ if (this.flowInfoService.isLegacy) {
865
514
  return this.quoteDraftService.quoteDraft$.pipe(map$1(quoteDraft => quoteDraft.activeMetrics));
866
515
  }
867
516
  else {
@@ -869,8 +518,19 @@ class FlowStateService {
869
518
  cold: true,
870
519
  }).pipe(map$1(response => (response.success ? response.result : [])));
871
520
  }
872
- }), filter$1(isDefined), shareReplay$1());
521
+ }), shareReplay$1(1));
873
522
  this.activeMetrics$.subscribe();
523
+ this.isPriceListLocked$ = this.flowInfoService.flow$.pipe(filter$1(isDefined), switchMap(() => {
524
+ if (this.flowInfoService.isLegacy) {
525
+ return of(false);
526
+ }
527
+ else {
528
+ return this.subscribe$(UITemplateType.FLOW_ENGINE, 'IS_PRICE_LIST_LOCKED', null, {
529
+ cold: true,
530
+ }).pipe(map$1(response => (response.success ? response.result : false)));
531
+ }
532
+ }), shareReplay$1(1));
533
+ this.isPriceListLocked$.subscribe();
874
534
  }
875
535
  init$() {
876
536
  return this.initProcessors$().pipe(switchMap(() => {
@@ -976,7 +636,7 @@ class FlowStateService {
976
636
  }
977
637
  }
978
638
  else {
979
- const quoteDraft = this.quoteDraftService.quoteDraftForActivePriceList;
639
+ const quoteDraft = this.quoteDraftService.quoteDraft;
980
640
  if (quoteDraft) {
981
641
  return this.quoteApiService.upsertQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
982
642
  this.contextService.update({ properties: { ConfigurationId: configurationId } });
@@ -992,7 +652,7 @@ class FlowStateService {
992
652
  }
993
653
  }
994
654
  else {
995
- const quoteDraft = this.quoteDraftService.quoteDraftForActivePriceList;
655
+ const quoteDraft = this.quoteDraftService.quoteDraft;
996
656
  if (quoteDraft) {
997
657
  return this.quoteApiService.submitQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
998
658
  this.contextService.update({ properties: { ConfigurationId: configurationId } });
@@ -1113,7 +773,12 @@ class FlowStateService {
1113
773
  }
1114
774
  initStateless$() {
1115
775
  const { headerId } = this.contextService.resolve();
1116
- return this.quoteDraftService.init(headerId, this.flowInfoService.params ?? {}).pipe(switchMap(() => this.executeRequest$(this.getDefaultExecutionRequestDTO())), switchMap(() => this.calculate$()), tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
776
+ return this.quoteDraftService.init(headerId, this.flowInfoService.params ?? {}).pipe(tap$1(() => {
777
+ const assets = this.quoteDraftService.assetsState;
778
+ if (assets) {
779
+ this.flowStore = { ...this.flowStore, assets };
780
+ }
781
+ }), switchMap(() => this.executeRequest$(this.getDefaultExecutionRequestDTO())), switchMap(() => this.calculate$()), tap$1(() => this.quoteDraftService.finalizeInit()), map$1(noop));
1117
782
  }
1118
783
  calculate$() {
1119
784
  const flowState = this.quoteDraftService.quoteDraft;
@@ -1206,95 +871,292 @@ class FlowStateService {
1206
871
  if (!template) {
1207
872
  return;
1208
873
  }
1209
- const localProcessors$ = this.customizationService?.getTemplateConfigurationProcessors?.(template.name) ?? of(null);
1210
- return localProcessors$.pipe(switchMap(processors => processors ? of(processors) : this.processorsApiService.fetchConfigurationProcessors$(template.id)), tap$1(processors => {
1211
- const processorsMap = processors.reduce((acc, p) => {
1212
- acc[p.apiName] = p;
1213
- return acc;
1214
- }, {});
1215
- this.processors[template.id] = processorsMap;
1216
- }));
1217
- })
1218
- .filter(isDefined);
1219
- if (!owners$.length) {
1220
- return of(undefined);
874
+ const localProcessors$ = this.customizationService?.getTemplateConfigurationProcessors?.(template.name) ?? of(null);
875
+ return localProcessors$.pipe(switchMap(processors => processors ? of(processors) : this.processorsApiService.fetchConfigurationProcessors$(template.id)), tap$1(processors => {
876
+ const processorsMap = processors.reduce((acc, p) => {
877
+ acc[p.apiName] = p;
878
+ return acc;
879
+ }, {});
880
+ this.processors[template.id] = processorsMap;
881
+ }));
882
+ })
883
+ .filter(isDefined);
884
+ if (!owners$.length) {
885
+ return of(undefined);
886
+ }
887
+ return forkJoin(owners$).pipe(map$1(noop));
888
+ }
889
+ executeActionScript(request, executable) {
890
+ const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
891
+ if (!configurationProcessor?.script) {
892
+ const scope = this.getScopeByOwnerId(executable.ownerId);
893
+ const scopeText = scope ? ` in ${scope}` : '';
894
+ throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
895
+ }
896
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
897
+ }
898
+ executeSelectorScript(request, executable) {
899
+ const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
900
+ if (!configurationProcessor?.script) {
901
+ const scope = this.getScopeByOwnerId(executable.ownerId);
902
+ const scopeText = scope ? ` in ${scope}` : '';
903
+ throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
904
+ }
905
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
906
+ }
907
+ executeProcessorScript(request, configurationProcessor, inputData) {
908
+ const scope = this.getScopeByOwnerId(configurationProcessor.ownerId ?? '');
909
+ let functionToExecute = this.executedFunctions[scope + configurationProcessor.apiName];
910
+ if (!functionToExecute) {
911
+ const script = `${configurationProcessor.script}\nreturn transform;`;
912
+ const sourceMap = `\n//# sourceURL=${scope ? scope + '/' : ''}${configurationProcessor.apiName}.js`;
913
+ functionToExecute = new Function(script + sourceMap)();
914
+ this.executedFunctions[scope + configurationProcessor.apiName] = functionToExecute;
915
+ }
916
+ return functionToExecute({
917
+ request,
918
+ inputData,
919
+ flowStore: this.flowStore,
920
+ });
921
+ }
922
+ generateRequestId(scope, selectorName, inputData) {
923
+ const inputDataHash = UUID.hex(JSON.stringify(inputData) || '').slice(0, 8);
924
+ return `${scope}/${selectorName}/${inputDataHash}`;
925
+ }
926
+ getDefaultExecutionRequestDTO() {
927
+ const request = {
928
+ actions: [],
929
+ selectors: {},
930
+ };
931
+ if (this.getFlowSafe().properties.standalone) {
932
+ return request;
933
+ }
934
+ const flowEngineTemplateId = this.getOwnerIdByScope(UITemplateType.FLOW_ENGINE);
935
+ request.actions?.push({
936
+ apiName: 'UPDATE_CONTEXT_PROPERTIES',
937
+ ownerId: flowEngineTemplateId,
938
+ inputData: this.contextService.resolve().properties,
939
+ });
940
+ return request;
941
+ }
942
+ }
943
+ FlowStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, deps: [{ token: ContextService }, { token: QuoteDraftService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.ConfigurationProcessorsApiService }, { token: i1.FlowStateApiService }, { token: i1.QuoteApiService }, { token: i6.ToastService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
944
+ FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService });
945
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, decorators: [{
946
+ type: Injectable
947
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: QuoteDraftService }, { type: FlowInfoService }, { type: FlowConfigurationService }, { type: i1.ConfigurationProcessorsApiService }, { type: i1.FlowStateApiService }, { type: i1.QuoteApiService }, { type: i6.ToastService }, { type: undefined, decorators: [{
948
+ type: Optional
949
+ }, {
950
+ type: Inject,
951
+ args: [FLOW_CUSTOMIZATION]
952
+ }] }]; } });
953
+
954
+ const findLineItem = (id, lineItems) => {
955
+ return findLineItemWithComparator(lineItems, (li) => li.id === id);
956
+ };
957
+ const findLineItemWithComparator = (lineItems, comparator) => {
958
+ let currentLevel = lineItems;
959
+ while (currentLevel.length) {
960
+ const found = currentLevel.find(comparator);
961
+ if (found) {
962
+ return found;
963
+ }
964
+ currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
965
+ }
966
+ return;
967
+ };
968
+ const insertLineItem = (lineItem, parentId, toInsert) => {
969
+ const insertData = lineItem.id === parentId ? [toInsert] : [];
970
+ return {
971
+ ...lineItem,
972
+ lineItems: [
973
+ ...insertData,
974
+ ...lineItem.lineItems.map(li => {
975
+ return insertLineItem(li, parentId, toInsert);
976
+ }),
977
+ ],
978
+ };
979
+ };
980
+ const removeLineItem = (lineItem, idToRemove) => {
981
+ return {
982
+ ...lineItem,
983
+ lineItems: lineItem.lineItems
984
+ .map(li => {
985
+ if (li.id === idToRemove) {
986
+ return;
987
+ }
988
+ else if (li.lineItems.length) {
989
+ return removeLineItem(li, idToRemove);
990
+ }
991
+ return li;
992
+ })
993
+ .filter(r => !!r),
994
+ };
995
+ };
996
+ const replaceLineItem = (lineItem, replaceTo, skipCardinalityCalculation = false) => {
997
+ if (lineItem.id === replaceTo.id) {
998
+ if (!skipCardinalityCalculation) {
999
+ return { ...recalculateCardinalityVariables(lineItem, replaceTo) };
1000
+ }
1001
+ else {
1002
+ return { ...replaceTo };
1003
+ }
1004
+ }
1005
+ return {
1006
+ ...lineItem,
1007
+ lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo, skipCardinalityCalculation)),
1008
+ };
1009
+ };
1010
+ const collectCardinalityComputations = (portDomains) => {
1011
+ const cardinalityComputations = new Map();
1012
+ entries(portDomains).forEach(([key, portDomain]) => {
1013
+ cardinalityComputations.set(key, portDomain.properties['cardinalityComputation'] === 'true');
1014
+ });
1015
+ return cardinalityComputations;
1016
+ };
1017
+ const calculateCardinalityVariables = (lineItems, cardinalityComputations) => {
1018
+ const cardVars = new Map();
1019
+ lineItems
1020
+ .filter(({ port, type }) => !!port && !!type)
1021
+ .forEach(li => {
1022
+ if (cardinalityComputations.get(`${li.port}`)) {
1023
+ const cardinalityVariableName = `#CV-${li.type}@${li.port}`;
1024
+ cardVars.set(cardinalityVariableName, (cardVars.get(cardinalityVariableName) ?? 0) + li.qty);
1025
+ }
1026
+ });
1027
+ return cardVars;
1028
+ };
1029
+ const cardinalityRegexp = new RegExp('#CV-[a-zA-Z0-9_]+@(?<portName>[a-zA-Z0-9_]+)');
1030
+ const recalculateCardinalityVariables = (original, updated) => {
1031
+ const cardinalityComputations = collectCardinalityComputations(updated.portDomains ?? original.portDomains ?? {});
1032
+ const cardinalityVariables = calculateCardinalityVariables(updated.lineItems, cardinalityComputations);
1033
+ const originalCardinalityVariables = calculateCardinalityVariables(original.lineItems, cardinalityComputations);
1034
+ originalCardinalityVariables.forEach((value, key) => {
1035
+ const execArray = cardinalityRegexp.exec(key);
1036
+ const portName = execArray?.groups?.['portName'];
1037
+ if (!portName || cardinalityComputations.get(portName)) {
1038
+ if (cardinalityVariables.get(key) === value) {
1039
+ // no need to update cardinality if no changes
1040
+ cardinalityVariables.delete(key);
1041
+ }
1042
+ else if (!cardinalityVariables.has(key)) {
1043
+ // remove last item from port
1044
+ cardinalityVariables.set(key, 0);
1045
+ }
1221
1046
  }
1222
- return forkJoin(owners$).pipe(map$1(noop));
1047
+ });
1048
+ return {
1049
+ ...updated,
1050
+ attributes: upsertAttributes(updated.attributes, [...cardinalityVariables].map(([name, value]) => ({ name, value, cfgStatus: 'Changed' }))),
1051
+ };
1052
+ };
1053
+ const mapAttributes = (attributes) => {
1054
+ return attributes.reduce((acc, { name, value }) => ({ ...acc, [name]: value }), {});
1055
+ };
1056
+ const getAttributes = (attributes, names = []) => {
1057
+ const filtered = attributes.filter(({ name }) => names.includes(name));
1058
+ return sortBy(filtered, [({ name }) => names.indexOf(name)]);
1059
+ };
1060
+ const upsertAttributes = (originalAttributes, attributesToUpsert) => {
1061
+ return attributesToUpsert.reduce((acc, { name, value }) => {
1062
+ const [origAttr] = getAttributes(acc, [name]);
1063
+ return [
1064
+ ...acc.filter(attr => attr.name !== name),
1065
+ { ...(origAttr ?? { name, type: '' }), cfgStatus: origAttr ? 'Changed' : 'User', value },
1066
+ ];
1067
+ }, originalAttributes);
1068
+ };
1069
+ const patchAttributes = (rootLineItem, id, attrs, skipCardinalityCalculation = false) => {
1070
+ const lineItem = findLineItem(id, [rootLineItem]);
1071
+ if (!lineItem) {
1072
+ return rootLineItem;
1223
1073
  }
1224
- executeActionScript(request, executable) {
1225
- const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
1226
- if (!configurationProcessor?.script) {
1227
- const scope = this.getScopeByOwnerId(executable.ownerId);
1228
- const scopeText = scope ? ` in ${scope}` : '';
1229
- throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1230
- }
1231
- return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1074
+ const attributes = upsertAttributes(lineItem.attributes, attrs);
1075
+ return replaceLineItem(rootLineItem, { ...lineItem, attributes }, skipCardinalityCalculation);
1076
+ };
1077
+ const getAttributeValue = (attributes, name) => attributes.find(attr => attr.name === name)?.value;
1078
+ const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
1079
+ return {
1080
+ id: UUID.UUID(),
1081
+ port,
1082
+ type,
1083
+ actionCode: 'ADD',
1084
+ cfgStatus: 'New',
1085
+ attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
1086
+ lineItems,
1087
+ parentId,
1088
+ qty: 1,
1089
+ };
1090
+ };
1091
+ const getRecommendedPrices = (portDomain, type) => {
1092
+ const domainType = portDomain.domainTypes.find(({ name }) => name === type);
1093
+ const [net, list] = domainType?.recommendedPrices
1094
+ ?.filter(({ chargeMethod }) => chargeMethod === 'ONE_TIME')
1095
+ .reduce((acc, rp) => {
1096
+ const [netPrice, listPrice] = acc;
1097
+ return [netPrice + rp.netPrice, listPrice + rp.listPrice];
1098
+ }, [0, 0]) ?? [0, 0];
1099
+ return { net, list };
1100
+ };
1101
+ const getOriginParent = (lineItems, currentLineItem) => {
1102
+ let target = currentLineItem;
1103
+ while (target && target.rampInstanceId) {
1104
+ target = lineItems.find(sub => sub.id === currentLineItem.rampInstanceId);
1232
1105
  }
1233
- executeSelectorScript(request, executable) {
1234
- const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
1235
- if (!configurationProcessor?.script) {
1236
- const scope = this.getScopeByOwnerId(executable.ownerId);
1237
- const scopeText = scope ? ` in ${scope}` : '';
1238
- throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1239
- }
1240
- return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1106
+ return target;
1107
+ };
1108
+ const assetPredicateFn = (lineItem, assetId) => {
1109
+ if (!assetId) {
1110
+ return false;
1241
1111
  }
1242
- executeProcessorScript(request, configurationProcessor, inputData) {
1243
- const scope = this.getScopeByOwnerId(configurationProcessor.ownerId ?? '');
1244
- let functionToExecute = this.executedFunctions[scope + configurationProcessor.apiName];
1245
- if (!functionToExecute) {
1246
- const script = `${configurationProcessor.script}\nreturn transform;`;
1247
- const sourceMap = `\n//# sourceURL=${scope ? scope + '/' : ''}${configurationProcessor.apiName}.js`;
1248
- functionToExecute = new Function(script + sourceMap)();
1249
- this.executedFunctions[scope + configurationProcessor.apiName] = functionToExecute;
1250
- }
1251
- return functionToExecute({
1252
- request,
1253
- inputData,
1254
- flowStore: this.flowStore,
1112
+ return lineItem.assetId === assetId || lineItem.openOrderLineItemId === assetId;
1113
+ };
1114
+ const multiplyLineItems = (lineItem, qty, split) => {
1115
+ if (split) {
1116
+ const unifyIds = (lineItem) => ({
1117
+ ...lineItem,
1118
+ id: UUID.UUID(),
1119
+ lineItems: lineItem.lineItems.map(unifyIds),
1255
1120
  });
1121
+ return map$2(new Array(qty), () => unifyIds(lineItem));
1256
1122
  }
1257
- generateRequestId(scope, selectorName, inputData) {
1258
- const inputDataHash = UUID.hex(JSON.stringify(inputData) || '').slice(0, 8);
1259
- return `${scope}/${selectorName}/${inputDataHash}`;
1260
- }
1261
- getDefaultExecutionRequestDTO() {
1262
- const request = {
1263
- actions: [],
1264
- selectors: {},
1265
- };
1266
- if (this.getFlowSafe().properties.standalone) {
1267
- return request;
1268
- }
1269
- const ownerId = this.getOwnerIdByScope(UITemplateType.FLOW_ENGINE);
1270
- request.actions?.push({
1271
- apiName: 'UPDATE_PRICE_LIST',
1272
- ownerId,
1273
- inputData: {},
1274
- });
1275
- request.actions?.push({
1276
- apiName: 'UPDATE_ASSET_IDS',
1277
- ownerId,
1278
- inputData: {},
1279
- });
1280
- request.actions?.push({
1281
- apiName: 'UPDATE_CONTEXT_PROPERTIES',
1282
- ownerId,
1283
- inputData: this.contextService.resolve().properties,
1284
- });
1285
- return request;
1123
+ else {
1124
+ return [
1125
+ {
1126
+ ...lineItem,
1127
+ qty: qty,
1128
+ },
1129
+ ];
1286
1130
  }
1287
- }
1288
- FlowStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, deps: [{ token: ContextService }, { token: QuoteDraftService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.ConfigurationProcessorsApiService }, { token: i1.FlowStateApiService }, { token: i1.QuoteApiService }, { token: i6.ToastService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
1289
- FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService });
1290
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, decorators: [{
1291
- type: Injectable
1292
- }], ctorParameters: function () { return [{ type: ContextService }, { type: QuoteDraftService }, { type: FlowInfoService }, { type: FlowConfigurationService }, { type: i1.ConfigurationProcessorsApiService }, { type: i1.FlowStateApiService }, { type: i1.QuoteApiService }, { type: i6.ToastService }, { type: undefined, decorators: [{
1293
- type: Optional
1294
- }, {
1295
- type: Inject,
1296
- args: [FLOW_CUSTOMIZATION]
1297
- }] }]; } });
1131
+ };
1132
+ const isTechnicalAttribute = (name) => {
1133
+ return name.startsWith('#') || name.startsWith('$');
1134
+ };
1135
+ const filterOutTechnicalAttributes = (attributes) => {
1136
+ return attributes.filter(({ name }) => !isTechnicalAttribute(name));
1137
+ };
1138
+
1139
+ var lineItem_utils = /*#__PURE__*/Object.freeze({
1140
+ __proto__: null,
1141
+ assetPredicateFn: assetPredicateFn,
1142
+ filterOutTechnicalAttributes: filterOutTechnicalAttributes,
1143
+ findLineItem: findLineItem,
1144
+ findLineItemWithComparator: findLineItemWithComparator,
1145
+ generateLineItem: generateLineItem,
1146
+ getAttributeValue: getAttributeValue,
1147
+ getAttributes: getAttributes,
1148
+ getOriginParent: getOriginParent,
1149
+ getRecommendedPrices: getRecommendedPrices,
1150
+ insertLineItem: insertLineItem,
1151
+ isTechnicalAttribute: isTechnicalAttribute,
1152
+ mapAttributes: mapAttributes,
1153
+ multiplyLineItems: multiplyLineItems,
1154
+ patchAttributes: patchAttributes,
1155
+ recalculateCardinalityVariables: recalculateCardinalityVariables,
1156
+ removeLineItem: removeLineItem,
1157
+ replaceLineItem: replaceLineItem,
1158
+ upsertAttributes: upsertAttributes
1159
+ });
1298
1160
 
1299
1161
  class RuntimeSettingsService {
1300
1162
  constructor(configurationSettingsApiService) {
@@ -1398,6 +1260,32 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1398
1260
  type: Injectable
1399
1261
  }], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
1400
1262
 
1263
+ class LineItemWorker {
1264
+ constructor(src) {
1265
+ this.li = { ...src };
1266
+ }
1267
+ insert(parentId, toInsert) {
1268
+ return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
1269
+ }
1270
+ remove(id) {
1271
+ return new LineItemWorker(removeLineItem(this.li, id));
1272
+ }
1273
+ replace(toReplace, skipCardinalityCalculation = false) {
1274
+ return new LineItemWorker(replaceLineItem(this.li, toReplace, skipCardinalityCalculation));
1275
+ }
1276
+ patchAttribute(attrs, id, skipCardinalityCalculation = false) {
1277
+ return new LineItemWorker(patchAttributes(this.li, id ?? this.li.id, attrs, skipCardinalityCalculation));
1278
+ }
1279
+ }
1280
+
1281
+ function extractMetadata(uiDefinition) {
1282
+ return omit(uiDefinition, [
1283
+ 'children',
1284
+ 'pages',
1285
+ 'components',
1286
+ ]);
1287
+ }
1288
+
1401
1289
  class ConfigurationService {
1402
1290
  constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService, runtimeSettings) {
1403
1291
  this.quoteDraftService = quoteDraftService;
@@ -1575,6 +1463,14 @@ class ConfigurationService {
1575
1463
  }
1576
1464
  return lineItem;
1577
1465
  }
1466
+ getAsset() {
1467
+ const lineItem = this.configurableRamp;
1468
+ if (!lineItem) {
1469
+ return;
1470
+ }
1471
+ const assetId = lineItem.assetId ?? lineItem.openOrderLineItemId;
1472
+ return this.quoteDraftService.assetsState?.initialState.find(li => assetPredicateFn(li, assetId));
1473
+ }
1578
1474
  getUIDefinitionProperties() {
1579
1475
  return {
1580
1476
  ...(this.getRuntimeContext().uiDefinitionContainer?.source.properties ?? {}),
@@ -1605,13 +1501,6 @@ class ConfigurationService {
1605
1501
  }
1606
1502
  });
1607
1503
  }
1608
- getAsset() {
1609
- const lineItem = this.configurableRamp;
1610
- if (!lineItem) {
1611
- return;
1612
- }
1613
- return this.quoteDraftService.quoteDraft?.initialState.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
1614
- }
1615
1504
  }
1616
1505
  ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i5.MessageService }, { token: i6$1.DialogService }, { token: RuntimeSettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
1617
1506
  ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationService });
@@ -1791,7 +1680,7 @@ class FlowConfigurationService {
1791
1680
  revert$(lineItemId) {
1792
1681
  const quoteDraft = this.quoteDraftService.quoteDraft;
1793
1682
  const initialCurrentState = this.quoteDraftService.getInitialCurrentState();
1794
- const currentState = this.quoteDraftService.activeCurrentState;
1683
+ const currentState = this.quoteDraftService.currentState;
1795
1684
  const currentLineItemIndex = currentState.findIndex(({ id }) => id === lineItemId);
1796
1685
  const currentLineItem = currentState[currentLineItemIndex];
1797
1686
  const initialLineItem = initialCurrentState.find(({ integrationId }) => integrationId === currentLineItem?.integrationId);
@@ -1839,7 +1728,7 @@ class FlowConfigurationService {
1839
1728
  }), switchMap(updatedState => this.calculate$({ ...quoteDraft, currentState: updatedState })), map$1(() => this.quoteDraftService.quoteDraft), tap$1(() => this.updatedSubj$.next()), this.handleErrorAndBounceBack());
1840
1729
  }
1841
1730
  get() {
1842
- return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
1731
+ return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.currentState), shareReplay$1());
1843
1732
  }
1844
1733
  getSnapshot() {
1845
1734
  return this.quoteDraftService?.currentState.slice() ?? [];
@@ -1943,6 +1832,39 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1943
1832
  type: Injectable
1944
1833
  }], ctorParameters: function () { return [{ type: FlowInfoService }, { type: FlowConfigurationService }, { type: i1.FlowStateApiService }, { type: FlowStateService }]; } });
1945
1834
 
1835
+ class IntegrationState {
1836
+ constructor() {
1837
+ this.stateSubj$ = new BehaviorSubject({});
1838
+ this.action$ = new Subject();
1839
+ }
1840
+ get state$() {
1841
+ return this.stateSubj$.asObservable();
1842
+ }
1843
+ get state() {
1844
+ return this.stateSubj$.getValue();
1845
+ }
1846
+ patchState(update) {
1847
+ this.stateSubj$.next({ ...this.stateSubj$.getValue(), ...update });
1848
+ }
1849
+ dispatch(action) {
1850
+ this.action$.next(action);
1851
+ }
1852
+ listen$(actionType) {
1853
+ return this.action$.pipe(filter$1(action => action.type === actionType), map$1(action => action.payload));
1854
+ }
1855
+ listenAll$() {
1856
+ return this.action$.asObservable();
1857
+ }
1858
+ clear() {
1859
+ this.stateSubj$.next({});
1860
+ }
1861
+ }
1862
+ IntegrationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1863
+ IntegrationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState });
1864
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: IntegrationState, decorators: [{
1865
+ type: Injectable
1866
+ }] });
1867
+
1946
1868
  class ProductImagesService {
1947
1869
  constructor(productApiService) {
1948
1870
  this.productApiService = productApiService;
@@ -2229,10 +2151,12 @@ class ConfigurationStateService {
2229
2151
  return of({ quoteId: '' });
2230
2152
  }
2231
2153
  const rootLineItem = this.configurationService.getSnapshot();
2154
+ const asset = this.configurationService.getAsset();
2232
2155
  const currentState = rootLineItem ? [rootLineItem] : [];
2156
+ const initialState = asset ? [asset] : [];
2233
2157
  return this.quoteApiService
2234
- .getQuoteDraft(quoteId)
2235
- .pipe(switchMap(quoteDraft => this.quoteApiService.upsertQuote({ ...quoteDraft, currentState })));
2158
+ .getQuoteState(quoteId)
2159
+ .pipe(switchMap(quoteDraft => this.quoteApiService.upsertQuote({ ...quoteDraft, currentState, initialState })));
2236
2160
  }
2237
2161
  else {
2238
2162
  const quoteDraft = this.quoteDraftService.quoteDraft;
@@ -2241,15 +2165,22 @@ class ConfigurationStateService {
2241
2165
  return of({ quoteId: '' });
2242
2166
  }
2243
2167
  const isNewLineItem = quoteDraft.currentState.every(li => li.id !== lineItem.id);
2244
- let updatedState;
2168
+ let currentState;
2245
2169
  if (isNewLineItem) {
2246
- updatedState = [...quoteDraft.currentState, lineItem];
2170
+ currentState = [...quoteDraft.currentState, lineItem];
2247
2171
  }
2248
2172
  else {
2249
- updatedState = quoteDraft.currentState.map(li => (li.id === lineItem.id ? lineItem : li));
2173
+ currentState = quoteDraft.currentState.map(li => (li.id === lineItem.id ? lineItem : li));
2174
+ }
2175
+ const asset = this.configurationService.getAsset();
2176
+ const initialState = [...(this.quoteDraftService.quoteDraft?.initialState ?? [])];
2177
+ if (asset) {
2178
+ if (!initialState.some(li => li.id === asset.id)) {
2179
+ initialState.push(asset);
2180
+ }
2250
2181
  }
2251
2182
  return this.flowConfigurationService
2252
- .calculate$({ ...quoteDraft, currentState: updatedState })
2183
+ .calculate$({ ...quoteDraft, currentState, initialState })
2253
2184
  .pipe(map$1(() => ({ quoteId: '' })));
2254
2185
  }
2255
2186
  }
@@ -2617,5 +2548,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2617
2548
  * Generated bundle index. Do not edit.
2618
2549
  */
2619
2550
 
2620
- export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationStateService, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowInfoService, FlowStateConfigurationService, FlowStateService, FlowUpdateService, IntegrationState, LineItemWorker, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, 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 };
2551
+ export { ActionCodePipe, CalendarDirective, ConfigurationRuntimeService, ConfigurationService, ConfigurationStateService, ContextService, DEFAULT_FORMATTING_SETTINGS, DatePipe, FLOW_CUSTOMIZATION, FORMATTING_SETTINGS_TOKEN, FlowConfigurationModule, FlowConfigurationService, FlowInfoService, FlowStateConfigurationService, FlowStateService, FlowUpdateService, IntegrationState, LineItemWorker, NumberPipe, PricePipe, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeSettingsService, RuntimeStep, SdkCoreModule, SdkDirectivesModule, SdkPipesModule, UI_DEFINITION_VERSION, assetPredicateFn, extractMetadata, filterOutTechnicalAttributes, findLineItem, findLineItemWithComparator, generateConfigurationLineItem, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getGuidedSellingConfigurationRequest, getOriginParent, getRecommendedPrices, insertLineItem, isTechnicalAttribute, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
2621
2552
  //# sourceMappingURL=veloceapps-sdk-core.mjs.map