@veloceapps/sdk 8.0.0-35 → 8.0.0-37

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, InjectionToken, NgModule, inject, Directive, Input, LOCALE_ID, Pipe } from '@angular/core';
3
- import { UUID, ConfigurationContextMode, ConfigurationContext, RuntimeModel, getUIDefinitionProperties, isLegacyUIDefinition, SalesforceIdUtils, ConfigurationMode, ConfigurationTranslatorUtils, EntityUtil, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, parseJsonSafely, formatNumber } from '@veloceapps/core';
3
+ import { UUID, ConfigurationContextMode, ConfigurationContext, ConfigurationMode, ConfigurationTranslatorUtils, getUIDefinitionProperties, ChargeGroupUtils, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, parseJsonSafely, RuntimeModel, isLegacyUIDefinition, SalesforceIdUtils, EntityUtil, formatNumber } from '@veloceapps/core';
4
4
  import * as i1 from '@veloceapps/api';
5
5
  import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloceapps/api';
6
- import { BehaviorSubject, combineLatest, zip, noop, throwError, shareReplay as shareReplay$1, switchMap as switchMap$1, of, tap as tap$1, map as map$2, catchError as catchError$1, Subject, take as take$1, distinctUntilChanged } from 'rxjs';
7
- import { filter, tap, map, first, switchMap, skip, take, shareReplay, catchError, finalize } from 'rxjs/operators';
6
+ import { BehaviorSubject, zip, noop, combineLatest, throwError, shareReplay as shareReplay$1, tap as tap$1, map as map$2, of, switchMap as switchMap$1, catchError as catchError$1, Subject, take as take$1, distinctUntilChanged } from 'rxjs';
7
+ import { filter, tap, map, switchMap, skip, take, shareReplay, catchError, finalize, first } from 'rxjs/operators';
8
8
  import { merge, isEqual, flatten, sortBy, map as map$1, transform, omit, cloneDeep, uniq } from 'lodash';
9
9
  import { HttpErrorResponse } from '@angular/common/http';
10
10
  import * as i4 from '@veloceapps/components';
@@ -86,6 +86,18 @@ class ContextService {
86
86
  create(headerId, mode) {
87
87
  return this.contextApiService.getContext(headerId, mode).pipe(tap(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map(() => this.resolve()));
88
88
  }
89
+ initTestMode() {
90
+ return this.create('TestId', ConfigurationContextMode.TEST).pipe(map(context => {
91
+ return this.update({
92
+ properties: {
93
+ ...context.properties,
94
+ RuntimeMode: ConfigurationContextMode.TEST,
95
+ StartDate: new Date().toISOString().substring(0, 10),
96
+ standalone: 'true',
97
+ },
98
+ });
99
+ }));
100
+ }
89
101
  update(partialContext) {
90
102
  const originalContext = this.resolve();
91
103
  const updatedContext = {
@@ -119,165 +131,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
119
131
  args: [{ providedIn: 'root' }]
120
132
  }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
121
133
 
122
- const FORMATTING_SETTINGS_TOKEN = new InjectionToken('Summary of formatting settings for variant types of data, e.g. numbers, text, dates, etc');
123
-
124
- var RuntimeMode;
125
- (function (RuntimeMode) {
126
- RuntimeMode[RuntimeMode["TEST"] = 0] = "TEST";
127
- RuntimeMode[RuntimeMode["PROD"] = 1] = "PROD";
128
- })(RuntimeMode || (RuntimeMode = {}));
129
- var RuntimeOperation;
130
- (function (RuntimeOperation) {
131
- RuntimeOperation["INIT"] = "INIT";
132
- RuntimeOperation["UPDATE"] = "UPDATE";
133
- })(RuntimeOperation || (RuntimeOperation = {}));
134
- var RuntimeStep;
135
- (function (RuntimeStep) {
136
- RuntimeStep["START"] = "START";
137
- RuntimeStep["UPDATE"] = "UPDATE";
138
- })(RuntimeStep || (RuntimeStep = {}));
139
-
140
- const UI_DEFINITION_VERSION = 3;
141
-
142
- class RuntimeContextService {
143
- constructor(configurationApiService) {
144
- this.configurationApiService = configurationApiService;
145
- }
146
- getRuntimeContext(productId, offeringId) {
147
- return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(map(runtimeData => {
148
- const uiDefinitionContainer = this.getUIDefinitionContainer(runtimeData);
149
- const runtimeModel = RuntimeModel.create(runtimeData.types, runtimeData.products);
150
- const { productName, properties } = Array.from(runtimeModel.components.values()).find(c => c.productId === productId) ?? {};
151
- const uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
152
- return {
153
- modelId: runtimeData.modelId,
154
- uiDefinitionContainer: uiDefinitionContainer,
155
- runtimeModel: runtimeModel,
156
- runtimeMode: RuntimeMode.PROD,
157
- productId: productId,
158
- productType: properties?.['displayName'] || productName,
159
- offeringId: offeringId,
160
- properties: {
161
- PricingEnabled: uiDefinitionProperties.pricingEnabled ? 'true' : 'false',
162
- PriceListId: uiDefinitionProperties.priceList,
163
- },
164
- };
165
- }));
166
- }
167
- getUIDefinitionContainer(runtimeData) {
168
- const containers = runtimeData.uiDefinitions.filter(container => !isLegacyUIDefinition(container.source));
169
- return containers.find(container => container.source.primary) ?? containers[0];
170
- }
171
- }
172
- RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
173
- RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService });
174
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService, decorators: [{
175
- type: Injectable
176
- }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
177
-
178
- class ConfigurationRuntimeService {
179
- constructor(apiService, contextService, runtimeContextService) {
180
- this.apiService = apiService;
181
- this.contextService = contextService;
182
- this.runtimeContextService = runtimeContextService;
183
- this._isInitialized = false;
184
- this.uiDefinitionProperties = {};
185
- }
186
- reset() {
187
- this._isInitialized = false;
188
- this._runtimeContext = undefined;
189
- this.initializationProps = undefined;
190
- this.uiDefinitionProperties = {};
191
- }
192
- initTestMode(uiDefinitionContainer) {
193
- this.uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
194
- const uiDefinitionExternals = uiDefinitionContainer.source.externals ?? {};
195
- return combineLatest([
196
- this.apiService.getRuntimeDataByModelId(uiDefinitionContainer.modelId),
197
- this.contextService.create('TestId', ConfigurationContextMode.TEST),
198
- ]).pipe(first(), map(([runtimeData, context]) => {
199
- this.contextService.update({
200
- properties: {
201
- ...this.runtimeContext?.properties,
202
- ...context.properties,
203
- ModelId: uiDefinitionContainer.modelId,
204
- RuntimeMode: ConfigurationContextMode.TEST,
205
- PricingEnabled: this.uiDefinitionProperties.pricingEnabled ? 'true' : 'false',
206
- StartDate: new Date().toISOString().substring(0, 10),
207
- PriceListId: this.uiDefinitionProperties.priceList,
208
- offeringId: this.uiDefinitionProperties.offeringId,
209
- standalone: 'true',
210
- ...uiDefinitionExternals,
211
- },
212
- });
213
- this._runtimeContext = {
214
- modelId: uiDefinitionContainer.modelId,
215
- runtimeModel: RuntimeModel.create(runtimeData.types, runtimeData.products),
216
- runtimeMode: RuntimeMode.TEST,
217
- uiDefinitionContainer,
218
- };
219
- return this._runtimeContext;
220
- }), tap(() => (this._isInitialized = true)));
221
- }
222
- init(props) {
223
- this.initializationProps = props;
224
- const context = this.contextService.resolve();
225
- return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
226
- this.uiDefinitionProperties = getUIDefinitionProperties(runtimeContext.uiDefinitionContainer);
227
- const { PriceListId } = context.properties ?? {};
228
- const mergeContext = {
229
- ...runtimeContext,
230
- properties: {
231
- ...runtimeContext.properties,
232
- ...context.properties,
233
- PricingEnabled: PriceListId ? 'true' : 'false',
234
- },
235
- };
236
- this.id15to18('AccountId', mergeContext.properties);
237
- this._runtimeContext = mergeContext;
238
- if (context.properties && this._runtimeContext.properties?.StartDate) {
239
- this.contextService.update({
240
- properties: {
241
- ...this._runtimeContext.properties,
242
- ...context.properties,
243
- },
244
- });
245
- }
246
- return this._runtimeContext;
247
- }), tap(() => (this._isInitialized = true)));
248
- }
249
- overrideUIDefinition(uiDefinitionContainer) {
250
- if (!this._runtimeContext) {
251
- return;
252
- }
253
- this._runtimeContext.uiDefinitionContainer = uiDefinitionContainer;
254
- this.uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
255
- }
256
- id15to18(propertyName, source) {
257
- if (!source) {
258
- return;
259
- }
260
- const value = source[propertyName];
261
- if (typeof value === 'string' && value.length === 15) {
262
- source[propertyName] = SalesforceIdUtils.generateId18FromId15(value);
263
- }
264
- }
265
- get isInitialized() {
266
- return this._isInitialized;
267
- }
268
- get runtimeModel() {
269
- return this.runtimeContext?.runtimeModel;
270
- }
271
- get runtimeContext() {
272
- return this._runtimeContext;
273
- }
274
- }
275
- ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
276
- ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService });
277
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
278
- type: Injectable
279
- }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
280
-
281
134
  class QuoteDraftService {
282
135
  get isInitialized() {
283
136
  return this.isInitializedSubj$.getValue();
@@ -708,6 +561,26 @@ var lineItem_utils = /*#__PURE__*/Object.freeze({
708
561
  upsertAttributes: upsertAttributes
709
562
  });
710
563
 
564
+ const FORMATTING_SETTINGS_TOKEN = new InjectionToken('Summary of formatting settings for variant types of data, e.g. numbers, text, dates, etc');
565
+
566
+ var RuntimeMode;
567
+ (function (RuntimeMode) {
568
+ RuntimeMode[RuntimeMode["TEST"] = 0] = "TEST";
569
+ RuntimeMode[RuntimeMode["PROD"] = 1] = "PROD";
570
+ })(RuntimeMode || (RuntimeMode = {}));
571
+ var RuntimeOperation;
572
+ (function (RuntimeOperation) {
573
+ RuntimeOperation["INIT"] = "INIT";
574
+ RuntimeOperation["UPDATE"] = "UPDATE";
575
+ })(RuntimeOperation || (RuntimeOperation = {}));
576
+ var RuntimeStep;
577
+ (function (RuntimeStep) {
578
+ RuntimeStep["START"] = "START";
579
+ RuntimeStep["UPDATE"] = "UPDATE";
580
+ })(RuntimeStep || (RuntimeStep = {}));
581
+
582
+ const UI_DEFINITION_VERSION = 3;
583
+
711
584
  class LineItemWorker {
712
585
  constructor(src) {
713
586
  this.li = { ...src };
@@ -934,173 +807,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
934
807
  type: Injectable
935
808
  }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6.DialogService }]; } });
936
809
 
937
- class ConfigurationState {
938
- constructor(statefulConfigurationApiService, runtimeService, configurationService, toastService) {
939
- this.statefulConfigurationApiService = statefulConfigurationApiService;
940
- this.runtimeService = runtimeService;
941
- this.configurationService = configurationService;
942
- this.toastService = toastService;
943
- this.stateSubj$ = new BehaviorSubject({});
944
- this.state$ = this.stateSubj$.asObservable();
945
- this.stateId = null;
946
- }
947
- init$() {
948
- return this.configurationService.configure().pipe(switchMap$1(() => {
949
- if (!this.isStatefulConfiguration) {
950
- return of(undefined);
951
- }
952
- const { actions, selectors } = this.runtimeService.runtimeContext?.uiDefinitionContainer ?? {};
953
- return this.statefulConfigurationApiService.init({
954
- request: this.configurationService.generateRequest(),
955
- actions: actions?.map(action => ({ name: action.apiName, script: action.script })),
956
- selectors: selectors?.map(selector => ({ name: selector.apiName, script: selector.script })),
810
+ function extractMetadata(uiDefinition) {
811
+ return omit(uiDefinition, [
812
+ 'children',
813
+ 'pages',
814
+ 'components',
815
+ ]);
816
+ }
817
+
818
+ class FlowUpdateService {
819
+ update(rootLineItems, updates, charges) {
820
+ let remainingUpdates = [...updates];
821
+ let currentLevel = rootLineItems;
822
+ while (currentLevel.length && remainingUpdates.length) {
823
+ currentLevel.forEach(li => {
824
+ const unhandledUpdates = [];
825
+ remainingUpdates.forEach(update => {
826
+ let updated = false;
827
+ switch (update.dataType) {
828
+ case 'LINEITEM':
829
+ updated = this.applyLineItemUpdate(li, update, charges);
830
+ break;
831
+ case 'CHARGE':
832
+ updated = this.applyChargeUpdate(li, update);
833
+ break;
834
+ case 'GROUP_CHARGE':
835
+ updated = this.applyChargeGroupUpdate(li, update);
836
+ break;
837
+ default:
838
+ // Unknown dataType. Do not try to handle it anymore
839
+ updated = true;
840
+ }
841
+ if (!updated) {
842
+ unhandledUpdates.push(update);
843
+ }
844
+ });
845
+ remainingUpdates = unhandledUpdates;
957
846
  });
958
- }), tap$1(stateId => (this.stateId = stateId || null)), map$2(() => undefined));
959
- }
960
- cleanup() {
961
- this.stateId = null;
962
- this.configurationService.reset();
963
- this.stateSubj$.next({});
964
- }
965
- execute$(req) {
966
- if (this.isStatefulConfiguration) {
967
- return this.executeStateful$(req);
968
- }
969
- else {
970
- return this.executeStateless$(req);
971
- }
972
- }
973
- dispatch$(actionName, inputData) {
974
- return this.execute$({ actions: [{ name: actionName, inputData }] });
975
- }
976
- select$(selectorName, inputData) {
977
- const requestId = UUID.UUID();
978
- return this.execute$({
979
- selectors: {
980
- [requestId]: {
981
- name: selectorName,
982
- inputData,
983
- },
984
- },
985
- }).pipe(map$2(() => this.stateSubj$.value[requestId]), tap$1(() => this.stateSubj$.next(omit(this.stateSubj$.value, requestId))));
986
- }
987
- get isStatefulConfiguration() {
988
- return this.runtimeService.uiDefinitionProperties.statefulConfigurationEnabled ?? false;
989
- }
990
- executeStateless$(request) {
991
- return of(undefined).pipe(switchMap$1(() => {
992
- // Apply actions and execute configuration/price call
993
- // No need to run configuration if no actions in the request
994
- if (!request.actions?.length) {
995
- return of(undefined);
996
- }
997
- let configurationRequest = this.configurationService.generateRequest();
998
- request.actions.forEach(action => {
999
- configurationRequest = this.executeActionScript(configurationRequest, action) ?? configurationRequest;
1000
- });
1001
- return this.configurationService.configureRequest$(configurationRequest);
1002
- }), tap$1(() => {
1003
- if (!request.selectors) {
1004
- return;
1005
- }
1006
- // Run selectors and apply them to the state
1007
- const finalConfigurationRequest = this.configurationService.generateRequest();
1008
- const selectorsResult = EntityUtil.entries(request.selectors).reduce((trunk, [key, selector]) => {
1009
- trunk[key] = this.executeSelectorScript(finalConfigurationRequest, selector);
1010
- return trunk;
1011
- }, {});
1012
- this.stateSubj$.next({
1013
- ...this.stateSubj$.value,
1014
- ...selectorsResult,
1015
- });
1016
- }), map$2(() => undefined));
1017
- }
1018
- executeStateful$(request) {
1019
- if (!this.stateId) {
1020
- return of(undefined);
1021
- }
1022
- return this.statefulConfigurationApiService.execute(this.stateId, request).pipe(tap$1(response => {
1023
- this.stateId = response.stateId;
1024
- const updatedState = this.stateSubj$.value;
1025
- EntityUtil.entries(response.selectors).forEach(([key, value]) => {
1026
- if (!value.success) {
1027
- if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
1028
- this.toastService.add({ summary: value.errorMessage, severity: ToastType.error });
1029
- }
1030
- return;
1031
- }
1032
- updatedState[key] = value.result;
1033
- });
1034
- this.stateSubj$.next(updatedState);
1035
- }), map$2(() => undefined));
1036
- }
1037
- executeActionScript(request, processor) {
1038
- const { actions } = this.runtimeService.runtimeContext?.uiDefinitionContainer ?? {};
1039
- const script = actions?.find(action => action.apiName === processor.name)?.script;
1040
- if (!script) {
1041
- return null;
1042
- }
1043
- return this.executeProcessorScript(request, script, processor.inputData);
1044
- }
1045
- executeSelectorScript(request, processor) {
1046
- const { selectors } = this.runtimeService.runtimeContext?.uiDefinitionContainer ?? {};
1047
- const script = selectors?.find(selector => selector.apiName === processor.name)?.script;
1048
- if (!script) {
1049
- return null;
1050
- }
1051
- return this.executeProcessorScript(request, script, processor.inputData);
1052
- }
1053
- executeProcessorScript(request, script, inputData) {
1054
- return new Function(`${script}\nreturn transform;`)()({
1055
- request,
1056
- inputData: inputData,
1057
- });
1058
- }
1059
- }
1060
- ConfigurationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState, deps: [{ token: i1.StatefulConfigurationApiService }, { token: ConfigurationRuntimeService }, { token: ConfigurationService }, { token: i4.ToastService }], target: i0.ɵɵFactoryTarget.Injectable });
1061
- ConfigurationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState });
1062
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState, decorators: [{
1063
- type: Injectable
1064
- }], ctorParameters: function () { return [{ type: i1.StatefulConfigurationApiService }, { type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: i4.ToastService }]; } });
1065
-
1066
- function extractMetadata(uiDefinition) {
1067
- return omit(uiDefinition, [
1068
- 'children',
1069
- 'pages',
1070
- 'components',
1071
- ]);
1072
- }
1073
-
1074
- class FlowUpdateService {
1075
- update(rootLineItems, updates, charges) {
1076
- let remainingUpdates = [...updates];
1077
- let currentLevel = rootLineItems;
1078
- while (currentLevel.length && remainingUpdates.length) {
1079
- currentLevel.forEach(li => {
1080
- const unhandledUpdates = [];
1081
- remainingUpdates.forEach(update => {
1082
- let updated = false;
1083
- switch (update.dataType) {
1084
- case 'LINEITEM':
1085
- updated = this.applyLineItemUpdate(li, update, charges);
1086
- break;
1087
- case 'CHARGE':
1088
- updated = this.applyChargeUpdate(li, update);
1089
- break;
1090
- case 'GROUP_CHARGE':
1091
- updated = this.applyChargeGroupUpdate(li, update);
1092
- break;
1093
- default:
1094
- // Unknown dataType. Do not try to handle it anymore
1095
- updated = true;
1096
- }
1097
- if (!updated) {
1098
- unhandledUpdates.push(update);
1099
- }
1100
- });
1101
- remainingUpdates = unhandledUpdates;
1102
- });
1103
- currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
847
+ currentLevel = flatten(currentLevel.map(parent => parent.lineItems));
1104
848
  }
1105
849
  }
1106
850
  delete(lineItems, id) {
@@ -1338,48 +1082,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1338
1082
  type: Injectable
1339
1083
  }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1340
1084
 
1341
- class FlowConfigurationModule {
1342
- }
1343
- FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1344
- FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
1345
- FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
1346
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1347
- type: NgModule,
1348
- args: [{
1349
- imports: [],
1350
- providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
1351
- }]
1352
- }] });
1353
-
1354
- class ConfigurationModule {
1355
- }
1356
- ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1357
- ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1358
- ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, providers: [
1359
- ContextApiService,
1360
- ProductModelApiService,
1361
- ConfigurationApiService,
1362
- ConfigurationRuntimeService,
1363
- RuntimeContextService,
1364
- ConfigurationService,
1365
- ConfigurationState,
1366
- ], imports: [ConfirmationDialogModule] });
1367
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, decorators: [{
1368
- type: NgModule,
1369
- args: [{
1370
- imports: [ConfirmationDialogModule],
1371
- providers: [
1372
- ContextApiService,
1373
- ProductModelApiService,
1374
- ConfigurationApiService,
1375
- ConfigurationRuntimeService,
1376
- RuntimeContextService,
1377
- ConfigurationService,
1378
- ConfigurationState,
1379
- ],
1380
- }]
1381
- }] });
1382
-
1383
1085
  function calculateMetricByMethod(lineItems, metric, method) {
1384
1086
  const items = getLineItemsByMethod(lineItems, method);
1385
1087
  return items.reduce((acc, li) => {
@@ -1611,6 +1313,313 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1611
1313
  args: [{ providedIn: 'root' }]
1612
1314
  }], ctorParameters: function () { return [{ type: i1.ConfigurationSettingsApiService }]; } });
1613
1315
 
1316
+ class RuntimeContextService {
1317
+ constructor(configurationApiService) {
1318
+ this.configurationApiService = configurationApiService;
1319
+ }
1320
+ getRuntimeContext(productId, offeringId) {
1321
+ return this.configurationApiService.getRuntimeDataByProductId(productId, offeringId).pipe(map(runtimeData => {
1322
+ const uiDefinitionContainer = this.getUIDefinitionContainer(runtimeData);
1323
+ const runtimeModel = RuntimeModel.create(runtimeData.types, runtimeData.products);
1324
+ const { productName, properties } = Array.from(runtimeModel.components.values()).find(c => c.productId === productId) ?? {};
1325
+ const uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
1326
+ return {
1327
+ modelId: runtimeData.modelId,
1328
+ uiDefinitionContainer: uiDefinitionContainer,
1329
+ runtimeModel: runtimeModel,
1330
+ runtimeMode: RuntimeMode.PROD,
1331
+ productId: productId,
1332
+ productType: properties?.['displayName'] || productName,
1333
+ offeringId: offeringId,
1334
+ properties: {
1335
+ PricingEnabled: uiDefinitionProperties.pricingEnabled ? 'true' : 'false',
1336
+ PriceListId: uiDefinitionProperties.priceList,
1337
+ },
1338
+ };
1339
+ }));
1340
+ }
1341
+ getUIDefinitionContainer(runtimeData) {
1342
+ const containers = runtimeData.uiDefinitions.filter(container => !isLegacyUIDefinition(container.source));
1343
+ return containers.find(container => container.source.primary) ?? containers[0];
1344
+ }
1345
+ }
1346
+ RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1347
+ RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService });
1348
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: RuntimeContextService, decorators: [{
1349
+ type: Injectable
1350
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
1351
+
1352
+ class ConfigurationRuntimeService {
1353
+ constructor(apiService, contextService, runtimeContextService) {
1354
+ this.apiService = apiService;
1355
+ this.contextService = contextService;
1356
+ this.runtimeContextService = runtimeContextService;
1357
+ this._isInitialized = false;
1358
+ this.uiDefinitionProperties = {};
1359
+ }
1360
+ reset() {
1361
+ this._isInitialized = false;
1362
+ this._runtimeContext = undefined;
1363
+ this.initializationProps = undefined;
1364
+ this.uiDefinitionProperties = {};
1365
+ }
1366
+ initTestMode(uiDefinitionContainer) {
1367
+ this.uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
1368
+ const uiDefinitionExternals = uiDefinitionContainer.source.externals ?? {};
1369
+ return combineLatest([
1370
+ this.apiService.getRuntimeDataByModelId(uiDefinitionContainer.modelId),
1371
+ this.contextService.initTestMode(),
1372
+ ]).pipe(first(), map(([runtimeData, context]) => {
1373
+ this.contextService.update({
1374
+ properties: {
1375
+ ...this.runtimeContext?.properties,
1376
+ ...context.properties,
1377
+ ModelId: uiDefinitionContainer.modelId,
1378
+ PricingEnabled: this.uiDefinitionProperties.pricingEnabled ? 'true' : 'false',
1379
+ PriceListId: this.uiDefinitionProperties.priceList,
1380
+ offeringId: this.uiDefinitionProperties.offeringId,
1381
+ ...uiDefinitionExternals,
1382
+ },
1383
+ });
1384
+ this._runtimeContext = {
1385
+ modelId: uiDefinitionContainer.modelId,
1386
+ runtimeModel: RuntimeModel.create(runtimeData.types, runtimeData.products),
1387
+ runtimeMode: RuntimeMode.TEST,
1388
+ uiDefinitionContainer,
1389
+ };
1390
+ return this._runtimeContext;
1391
+ }), tap(() => (this._isInitialized = true)));
1392
+ }
1393
+ init(props) {
1394
+ this.initializationProps = props;
1395
+ const context = this.contextService.resolve();
1396
+ return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
1397
+ this.uiDefinitionProperties = getUIDefinitionProperties(runtimeContext.uiDefinitionContainer);
1398
+ const { PriceListId } = context.properties ?? {};
1399
+ const mergeContext = {
1400
+ ...runtimeContext,
1401
+ properties: {
1402
+ ...runtimeContext.properties,
1403
+ ...context.properties,
1404
+ PricingEnabled: PriceListId ? 'true' : 'false',
1405
+ },
1406
+ };
1407
+ this.id15to18('AccountId', mergeContext.properties);
1408
+ this._runtimeContext = mergeContext;
1409
+ if (context.properties && this._runtimeContext.properties?.StartDate) {
1410
+ this.contextService.update({
1411
+ properties: {
1412
+ ...this._runtimeContext.properties,
1413
+ ...context.properties,
1414
+ },
1415
+ });
1416
+ }
1417
+ return this._runtimeContext;
1418
+ }), tap(() => (this._isInitialized = true)));
1419
+ }
1420
+ overrideUIDefinition(uiDefinitionContainer) {
1421
+ if (!this._runtimeContext) {
1422
+ return;
1423
+ }
1424
+ this._runtimeContext.uiDefinitionContainer = uiDefinitionContainer;
1425
+ this.uiDefinitionProperties = getUIDefinitionProperties(uiDefinitionContainer);
1426
+ }
1427
+ id15to18(propertyName, source) {
1428
+ if (!source) {
1429
+ return;
1430
+ }
1431
+ const value = source[propertyName];
1432
+ if (typeof value === 'string' && value.length === 15) {
1433
+ source[propertyName] = SalesforceIdUtils.generateId18FromId15(value);
1434
+ }
1435
+ }
1436
+ get isInitialized() {
1437
+ return this._isInitialized;
1438
+ }
1439
+ get runtimeModel() {
1440
+ return this.runtimeContext?.runtimeModel;
1441
+ }
1442
+ get runtimeContext() {
1443
+ return this._runtimeContext;
1444
+ }
1445
+ }
1446
+ ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
1447
+ ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService });
1448
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
1449
+ type: Injectable
1450
+ }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
1451
+
1452
+ class ConfigurationState {
1453
+ constructor(statefulConfigurationApiService, runtimeService, configurationService, toastService) {
1454
+ this.statefulConfigurationApiService = statefulConfigurationApiService;
1455
+ this.runtimeService = runtimeService;
1456
+ this.configurationService = configurationService;
1457
+ this.toastService = toastService;
1458
+ this.stateSubj$ = new BehaviorSubject({});
1459
+ this.state$ = this.stateSubj$.asObservable();
1460
+ this.stateId = null;
1461
+ }
1462
+ init$() {
1463
+ return this.configurationService.configure().pipe(switchMap$1(() => {
1464
+ if (!this.isStatefulConfiguration) {
1465
+ return of(undefined);
1466
+ }
1467
+ const { actions, selectors } = this.runtimeService.runtimeContext?.uiDefinitionContainer ?? {};
1468
+ return this.statefulConfigurationApiService.init({
1469
+ request: this.configurationService.generateRequest(),
1470
+ actions: actions?.map(action => ({ name: action.apiName, script: action.script })),
1471
+ selectors: selectors?.map(selector => ({ name: selector.apiName, script: selector.script })),
1472
+ });
1473
+ }), tap$1(stateId => (this.stateId = stateId || null)), map$2(() => undefined));
1474
+ }
1475
+ cleanup() {
1476
+ this.stateId = null;
1477
+ this.configurationService.reset();
1478
+ this.stateSubj$.next({});
1479
+ }
1480
+ execute$(req) {
1481
+ if (this.isStatefulConfiguration) {
1482
+ return this.executeStateful$(req);
1483
+ }
1484
+ else {
1485
+ return this.executeStateless$(req);
1486
+ }
1487
+ }
1488
+ dispatch$(actionName, inputData) {
1489
+ return this.execute$({ actions: [{ name: actionName, inputData }] });
1490
+ }
1491
+ select$(selectorName, inputData) {
1492
+ const requestId = UUID.UUID();
1493
+ return this.execute$({
1494
+ selectors: {
1495
+ [requestId]: {
1496
+ name: selectorName,
1497
+ inputData,
1498
+ },
1499
+ },
1500
+ }).pipe(map$2(() => this.stateSubj$.value[requestId]), tap$1(() => this.stateSubj$.next(omit(this.stateSubj$.value, requestId))));
1501
+ }
1502
+ get isStatefulConfiguration() {
1503
+ return this.runtimeService.uiDefinitionProperties.statefulConfigurationEnabled ?? false;
1504
+ }
1505
+ executeStateless$(request) {
1506
+ return of(undefined).pipe(switchMap$1(() => {
1507
+ // Apply actions and execute configuration/price call
1508
+ // No need to run configuration if no actions in the request
1509
+ if (!request.actions?.length) {
1510
+ return of(undefined);
1511
+ }
1512
+ let configurationRequest = this.configurationService.generateRequest();
1513
+ request.actions.forEach(action => {
1514
+ configurationRequest = this.executeActionScript(configurationRequest, action) ?? configurationRequest;
1515
+ });
1516
+ return this.configurationService.configureRequest$(configurationRequest);
1517
+ }), tap$1(() => {
1518
+ if (!request.selectors) {
1519
+ return;
1520
+ }
1521
+ // Run selectors and apply them to the state
1522
+ const finalConfigurationRequest = this.configurationService.generateRequest();
1523
+ const selectorsResult = EntityUtil.entries(request.selectors).reduce((trunk, [key, selector]) => {
1524
+ trunk[key] = this.executeSelectorScript(finalConfigurationRequest, selector);
1525
+ return trunk;
1526
+ }, {});
1527
+ this.stateSubj$.next({
1528
+ ...this.stateSubj$.value,
1529
+ ...selectorsResult,
1530
+ });
1531
+ }), map$2(() => undefined));
1532
+ }
1533
+ executeStateful$(request) {
1534
+ if (!this.stateId) {
1535
+ return of(undefined);
1536
+ }
1537
+ return this.statefulConfigurationApiService.execute(this.stateId, request).pipe(tap$1(response => {
1538
+ this.stateId = response.stateId;
1539
+ const updatedState = this.stateSubj$.value;
1540
+ EntityUtil.entries(response.selectors).forEach(([key, value]) => {
1541
+ if (!value.success) {
1542
+ if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
1543
+ this.toastService.add({ summary: value.errorMessage, severity: ToastType.error });
1544
+ }
1545
+ return;
1546
+ }
1547
+ updatedState[key] = value.result;
1548
+ });
1549
+ this.stateSubj$.next(updatedState);
1550
+ }), map$2(() => undefined));
1551
+ }
1552
+ executeActionScript(request, processor) {
1553
+ const { actions } = this.runtimeService.runtimeContext?.uiDefinitionContainer ?? {};
1554
+ const script = actions?.find(action => action.apiName === processor.name)?.script;
1555
+ if (!script) {
1556
+ return null;
1557
+ }
1558
+ return this.executeProcessorScript(request, script, processor.inputData);
1559
+ }
1560
+ executeSelectorScript(request, processor) {
1561
+ const { selectors } = this.runtimeService.runtimeContext?.uiDefinitionContainer ?? {};
1562
+ const script = selectors?.find(selector => selector.apiName === processor.name)?.script;
1563
+ if (!script) {
1564
+ return null;
1565
+ }
1566
+ return this.executeProcessorScript(request, script, processor.inputData);
1567
+ }
1568
+ executeProcessorScript(request, script, inputData) {
1569
+ return new Function(`${script}\nreturn transform;`)()({
1570
+ request,
1571
+ inputData: inputData,
1572
+ });
1573
+ }
1574
+ }
1575
+ ConfigurationState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState, deps: [{ token: i1.StatefulConfigurationApiService }, { token: ConfigurationRuntimeService }, { token: ConfigurationService }, { token: i4.ToastService }], target: i0.ɵɵFactoryTarget.Injectable });
1576
+ ConfigurationState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState });
1577
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationState, decorators: [{
1578
+ type: Injectable
1579
+ }], ctorParameters: function () { return [{ type: i1.StatefulConfigurationApiService }, { type: ConfigurationRuntimeService }, { type: ConfigurationService }, { type: i4.ToastService }]; } });
1580
+
1581
+ class FlowConfigurationModule {
1582
+ }
1583
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1584
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule });
1585
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService] });
1586
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1587
+ type: NgModule,
1588
+ args: [{
1589
+ imports: [],
1590
+ providers: [FlowConfigurationService, FlowUpdateService, PriceApiService],
1591
+ }]
1592
+ }] });
1593
+
1594
+ class ConfigurationModule {
1595
+ }
1596
+ ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1597
+ ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1598
+ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, providers: [
1599
+ ContextApiService,
1600
+ ProductModelApiService,
1601
+ ConfigurationApiService,
1602
+ ConfigurationRuntimeService,
1603
+ RuntimeContextService,
1604
+ ConfigurationService,
1605
+ ConfigurationState,
1606
+ ], imports: [ConfirmationDialogModule] });
1607
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationModule, decorators: [{
1608
+ type: NgModule,
1609
+ args: [{
1610
+ imports: [ConfirmationDialogModule],
1611
+ providers: [
1612
+ ContextApiService,
1613
+ ProductModelApiService,
1614
+ ConfigurationApiService,
1615
+ ConfigurationRuntimeService,
1616
+ RuntimeContextService,
1617
+ ConfigurationService,
1618
+ ConfigurationState,
1619
+ ],
1620
+ }]
1621
+ }] });
1622
+
1614
1623
  const DEFAULT_FORMATTING_SETTINGS = {
1615
1624
  currencySymbol: DEFAULT_CURRENCY_SYMBOL,
1616
1625
  decimalsCount: DEFAULT_DECIMALS_COUNT,