@veloceapps/sdk 8.0.0-135 → 8.0.0-136

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