@veloceapps/sdk 8.0.0-134 → 8.0.0-136

Sign up to get free protection for your applications and to get access to all the features.
@@ -103,16 +103,17 @@ class ContextService {
103
103
  return this.resolve().properties.mode;
104
104
  }
105
105
  get isEditMode$() {
106
- return this.resolve$().pipe(map(() => {
107
- const context = this.resolve();
108
- if (context.mode === ConfigurationContextMode.ACCOUNT) {
109
- return true;
110
- }
111
- if (context.mode === ConfigurationContextMode.QUOTE) {
112
- return context.properties.Status === 'Draft';
113
- }
114
- return false;
115
- }));
106
+ return this.resolve$().pipe(map(() => this.isEditMode));
107
+ }
108
+ get isEditMode() {
109
+ const context = this.resolve();
110
+ if (context.mode === ConfigurationContextMode.ACCOUNT) {
111
+ return true;
112
+ }
113
+ if (context.mode === ConfigurationContextMode.QUOTE) {
114
+ return context.properties.Status === 'Draft';
115
+ }
116
+ return false;
116
117
  }
117
118
  resolve() {
118
119
  if (!this.context.value) {
@@ -202,6 +203,9 @@ class FlowInfoService {
202
203
  get isLegacy() {
203
204
  return !!this.flow && this.flow?.properties.stateful == null;
204
205
  }
206
+ get isStateful() {
207
+ return !!this.flow?.properties.stateful;
208
+ }
205
209
  constructor(flowsApiService, templatesApiService, customizationService) {
206
210
  this.flowsApiService = flowsApiService;
207
211
  this.templatesApiService = templatesApiService;
@@ -802,6 +806,7 @@ class FlowStateService {
802
806
  this.toastService = toastService;
803
807
  this.customizationService = customizationService;
804
808
  this.NOT_INITIALIZED = Symbol();
809
+ this.executedFunctions = {};
805
810
  this._hasStatefulUnsavedChanges = false;
806
811
  this.stateId$ = new BehaviorSubject(null);
807
812
  this.processors = {};
@@ -1159,27 +1164,32 @@ class FlowStateService {
1159
1164
  return forkJoin(owners$).pipe(map$1(noop));
1160
1165
  }
1161
1166
  executeActionScript(request, executable) {
1162
- const script = this.processors[executable.ownerId]?.[executable.apiName]?.script;
1163
- if (!script) {
1167
+ const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
1168
+ if (!configurationProcessor?.script) {
1164
1169
  const scope = this.getScopeByOwnerId(executable.ownerId);
1165
1170
  const scopeText = scope ? ` in ${scope}` : '';
1166
1171
  throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1167
1172
  }
1168
- return this.executeProcessorScript(request, script, executable.inputData);
1173
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1169
1174
  }
1170
1175
  executeSelectorScript(request, executable) {
1171
- const script = this.processors[executable.ownerId]?.[executable.apiName]?.script;
1172
- if (!script) {
1176
+ const configurationProcessor = this.processors[executable.ownerId]?.[executable.apiName];
1177
+ if (!configurationProcessor?.script) {
1173
1178
  const scope = this.getScopeByOwnerId(executable.ownerId);
1174
1179
  const scopeText = scope ? ` in ${scope}` : '';
1175
1180
  throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1176
1181
  }
1177
- return this.executeProcessorScript(request, script, executable.inputData);
1182
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1178
1183
  }
1179
- executeProcessorScript(request, script, inputData) {
1180
- return new Function(`${script}\nreturn transform;`)()({
1184
+ executeProcessorScript(request, configurationProcessor, inputData) {
1185
+ let functionToExecute = this.executedFunctions[configurationProcessor.apiName];
1186
+ if (!functionToExecute) {
1187
+ functionToExecute = new Function(`${configurationProcessor.script}\nreturn transform;`)();
1188
+ this.executedFunctions[configurationProcessor.apiName] = functionToExecute;
1189
+ }
1190
+ return functionToExecute({
1181
1191
  request,
1182
- inputData: inputData,
1192
+ inputData,
1183
1193
  });
1184
1194
  }
1185
1195
  generateRequestId(scope, selectorName, inputData) {
@@ -2161,10 +2171,12 @@ class ConfigurationStateService {
2161
2171
  this.flowStateApiService = flowStateApiService;
2162
2172
  this.quoteApiService = quoteApiService;
2163
2173
  this.NOT_INITIALIZED = Symbol();
2174
+ this.executedFunctions = {};
2164
2175
  this.stateId = null;
2165
2176
  this.ownerId = '';
2166
2177
  this.subscriptions = {};
2167
2178
  this.isInitialized$ = new BehaviorSubject(false);
2179
+ this.canceledConfiguration$ = new Subject();
2168
2180
  }
2169
2181
  init$() {
2170
2182
  let request$;
@@ -2174,7 +2186,10 @@ class ConfigurationStateService {
2174
2186
  else {
2175
2187
  request$ = this.initStateless$();
2176
2188
  }
2177
- return request$.pipe(finalize(() => this.isInitialized$.next(true)));
2189
+ return request$.pipe(finalize(() => {
2190
+ this.isInitialized$.next(true);
2191
+ this.canceledConfiguration$ = new Subject();
2192
+ }));
2178
2193
  }
2179
2194
  cleanup() {
2180
2195
  this.stateId = null;
@@ -2243,10 +2258,13 @@ class ConfigurationStateService {
2243
2258
  }
2244
2259
  }
2245
2260
  return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
2261
+ if (!this.subscriptions[requestId]) {
2262
+ return;
2263
+ }
2246
2264
  if (!this.subscriptions[requestId].data$.observed) {
2247
2265
  delete this.subscriptions[requestId];
2248
2266
  }
2249
- }));
2267
+ }), takeUntil(this.canceledConfiguration$));
2250
2268
  }
2251
2269
  saveConfiguration(quoteId, flow) {
2252
2270
  if (this.isStatefulConfiguration) {
@@ -2289,6 +2307,9 @@ class ConfigurationStateService {
2289
2307
  if (!this.isInitialized$.value) {
2290
2308
  return of(undefined);
2291
2309
  }
2310
+ this.canceledConfiguration$.next();
2311
+ this.canceledConfiguration$.complete();
2312
+ this.subscriptions = {};
2292
2313
  this.isInitialized$.next(false);
2293
2314
  if (!this.isInitialized$.value || !this.isStatefulConfiguration) {
2294
2315
  return of(undefined);
@@ -2372,24 +2393,29 @@ class ConfigurationStateService {
2372
2393
  }
2373
2394
  executeActionScript(request, processor) {
2374
2395
  const { actions } = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer ?? {};
2375
- const script = actions?.find(action => action.apiName === processor.apiName)?.script;
2376
- if (!script) {
2396
+ const configurationProcessor = actions?.find(action => action.apiName === processor.apiName);
2397
+ if (!configurationProcessor?.script) {
2377
2398
  return request;
2378
2399
  }
2379
- return this.executeProcessorScript(request, script, processor.inputData);
2400
+ return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
2380
2401
  }
2381
2402
  executeSelectorScript(request, processor) {
2382
2403
  const { selectors } = this.configurationRuntimeService.runtimeContext?.uiDefinitionContainer ?? {};
2383
- const script = selectors?.find(selector => selector.apiName === processor.apiName)?.script;
2384
- if (!script) {
2404
+ const configurationProcessor = selectors?.find(selector => selector.apiName === processor.apiName);
2405
+ if (!configurationProcessor?.script) {
2385
2406
  return null;
2386
2407
  }
2387
- return this.executeProcessorScript(request, script, processor.inputData);
2408
+ return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
2388
2409
  }
2389
- executeProcessorScript(request, script, inputData) {
2390
- return new Function(`${script}\nreturn transform;`)()({
2410
+ executeProcessorScript(request, configurationProcessor, inputData) {
2411
+ let functionToExecute = this.executedFunctions[configurationProcessor.apiName];
2412
+ if (!functionToExecute) {
2413
+ functionToExecute = new Function(`${configurationProcessor.script}\nreturn transform;`)();
2414
+ this.executedFunctions[configurationProcessor.apiName] = functionToExecute;
2415
+ }
2416
+ return functionToExecute({
2391
2417
  request,
2392
- inputData: inputData,
2418
+ inputData,
2393
2419
  });
2394
2420
  }
2395
2421
  }