@veloceapps/sdk 8.0.0-135 → 8.0.0-137

Sign up to get free protection for your applications and to get access to all the features.
@@ -171,6 +171,10 @@ class FlowInfoService {
171
171
  var _a;
172
172
  return !!this.flow && ((_a = this.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful) == null;
173
173
  }
174
+ get isStateful() {
175
+ var _a;
176
+ return !!((_a = this.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful);
177
+ }
174
178
  constructor(flowsApiService, templatesApiService, customizationService) {
175
179
  this.flowsApiService = flowsApiService;
176
180
  this.templatesApiService = templatesApiService;
@@ -743,6 +747,7 @@ class FlowStateService {
743
747
  this.toastService = toastService;
744
748
  this.customizationService = customizationService;
745
749
  this.NOT_INITIALIZED = Symbol();
750
+ this.executedFunctions = {};
746
751
  this._hasStatefulUnsavedChanges = false;
747
752
  this.stateId$ = new BehaviorSubject(null);
748
753
  this.processors = {};
@@ -1115,29 +1120,34 @@ class FlowStateService {
1115
1120
  return forkJoin(owners$).pipe(map$1(noop));
1116
1121
  }
1117
1122
  executeActionScript(request, executable) {
1118
- var _a, _b;
1119
- const script = (_b = (_a = this.processors[executable.ownerId]) === null || _a === void 0 ? void 0 : _a[executable.apiName]) === null || _b === void 0 ? void 0 : _b.script;
1120
- if (!script) {
1123
+ var _a;
1124
+ const configurationProcessor = (_a = this.processors[executable.ownerId]) === null || _a === void 0 ? void 0 : _a[executable.apiName];
1125
+ if (!(configurationProcessor === null || configurationProcessor === void 0 ? void 0 : configurationProcessor.script)) {
1121
1126
  const scope = this.getScopeByOwnerId(executable.ownerId);
1122
1127
  const scopeText = scope ? ` in ${scope}` : '';
1123
1128
  throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1124
1129
  }
1125
- return this.executeProcessorScript(request, script, executable.inputData);
1130
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1126
1131
  }
1127
1132
  executeSelectorScript(request, executable) {
1128
- var _a, _b;
1129
- const script = (_b = (_a = this.processors[executable.ownerId]) === null || _a === void 0 ? void 0 : _a[executable.apiName]) === null || _b === void 0 ? void 0 : _b.script;
1130
- if (!script) {
1133
+ var _a;
1134
+ const configurationProcessor = (_a = this.processors[executable.ownerId]) === null || _a === void 0 ? void 0 : _a[executable.apiName];
1135
+ if (!(configurationProcessor === null || configurationProcessor === void 0 ? void 0 : configurationProcessor.script)) {
1131
1136
  const scope = this.getScopeByOwnerId(executable.ownerId);
1132
1137
  const scopeText = scope ? ` in ${scope}` : '';
1133
1138
  throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1134
1139
  }
1135
- return this.executeProcessorScript(request, script, executable.inputData);
1140
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1136
1141
  }
1137
- executeProcessorScript(request, script, inputData) {
1138
- return new Function(`${script}\nreturn transform;`)()({
1142
+ executeProcessorScript(request, configurationProcessor, inputData) {
1143
+ let functionToExecute = this.executedFunctions[configurationProcessor.apiName];
1144
+ if (!functionToExecute) {
1145
+ functionToExecute = new Function(`${configurationProcessor.script}\nreturn transform;`)();
1146
+ this.executedFunctions[configurationProcessor.apiName] = functionToExecute;
1147
+ }
1148
+ return functionToExecute({
1139
1149
  request,
1140
- inputData: inputData,
1150
+ inputData,
1141
1151
  });
1142
1152
  }
1143
1153
  generateRequestId(scope, selectorName, inputData) {
@@ -2122,10 +2132,12 @@ class ConfigurationStateService {
2122
2132
  this.flowStateApiService = flowStateApiService;
2123
2133
  this.quoteApiService = quoteApiService;
2124
2134
  this.NOT_INITIALIZED = Symbol();
2135
+ this.executedFunctions = {};
2125
2136
  this.stateId = null;
2126
2137
  this.ownerId = '';
2127
2138
  this.subscriptions = {};
2128
2139
  this.isInitialized$ = new BehaviorSubject(false);
2140
+ this.canceledConfiguration$ = new Subject();
2129
2141
  }
2130
2142
  init$() {
2131
2143
  let request$;
@@ -2135,7 +2147,10 @@ class ConfigurationStateService {
2135
2147
  else {
2136
2148
  request$ = this.initStateless$();
2137
2149
  }
2138
- return request$.pipe(finalize(() => this.isInitialized$.next(true)));
2150
+ return request$.pipe(finalize(() => {
2151
+ this.isInitialized$.next(true);
2152
+ this.canceledConfiguration$ = new Subject();
2153
+ }));
2139
2154
  }
2140
2155
  cleanup() {
2141
2156
  this.stateId = null;
@@ -2206,10 +2221,13 @@ class ConfigurationStateService {
2206
2221
  }
2207
2222
  }
2208
2223
  return this.subscriptions[requestId].data$.pipe(filter$1(data => data != this.NOT_INITIALIZED), map$1(data => data), finalize(() => {
2224
+ if (!this.subscriptions[requestId]) {
2225
+ return;
2226
+ }
2209
2227
  if (!this.subscriptions[requestId].data$.observed) {
2210
2228
  delete this.subscriptions[requestId];
2211
2229
  }
2212
- }));
2230
+ }), takeUntil(this.canceledConfiguration$));
2213
2231
  }
2214
2232
  saveConfiguration(quoteId, flow) {
2215
2233
  var _a, _b;
@@ -2254,6 +2272,9 @@ class ConfigurationStateService {
2254
2272
  if (!this.isInitialized$.value) {
2255
2273
  return of(undefined);
2256
2274
  }
2275
+ this.canceledConfiguration$.next();
2276
+ this.canceledConfiguration$.complete();
2277
+ this.subscriptions = {};
2257
2278
  this.isInitialized$.next(false);
2258
2279
  if (!this.isInitialized$.value || !this.isStatefulConfiguration) {
2259
2280
  return of(undefined);
@@ -2341,27 +2362,32 @@ class ConfigurationStateService {
2341
2362
  }));
2342
2363
  }
2343
2364
  executeActionScript(request, processor) {
2344
- var _a, _b, _c;
2365
+ var _a, _b;
2345
2366
  const { actions } = (_b = (_a = this.configurationRuntimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
2346
- const script = (_c = actions === null || actions === void 0 ? void 0 : actions.find(action => action.apiName === processor.apiName)) === null || _c === void 0 ? void 0 : _c.script;
2347
- if (!script) {
2367
+ const configurationProcessor = actions === null || actions === void 0 ? void 0 : actions.find(action => action.apiName === processor.apiName);
2368
+ if (!(configurationProcessor === null || configurationProcessor === void 0 ? void 0 : configurationProcessor.script)) {
2348
2369
  return request;
2349
2370
  }
2350
- return this.executeProcessorScript(request, script, processor.inputData);
2371
+ return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
2351
2372
  }
2352
2373
  executeSelectorScript(request, processor) {
2353
- var _a, _b, _c;
2374
+ var _a, _b;
2354
2375
  const { selectors } = (_b = (_a = this.configurationRuntimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
2355
- const script = (_c = selectors === null || selectors === void 0 ? void 0 : selectors.find(selector => selector.apiName === processor.apiName)) === null || _c === void 0 ? void 0 : _c.script;
2356
- if (!script) {
2376
+ const configurationProcessor = selectors === null || selectors === void 0 ? void 0 : selectors.find(selector => selector.apiName === processor.apiName);
2377
+ if (!(configurationProcessor === null || configurationProcessor === void 0 ? void 0 : configurationProcessor.script)) {
2357
2378
  return null;
2358
2379
  }
2359
- return this.executeProcessorScript(request, script, processor.inputData);
2380
+ return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
2360
2381
  }
2361
- executeProcessorScript(request, script, inputData) {
2362
- return new Function(`${script}\nreturn transform;`)()({
2382
+ executeProcessorScript(request, configurationProcessor, inputData) {
2383
+ let functionToExecute = this.executedFunctions[configurationProcessor.apiName];
2384
+ if (!functionToExecute) {
2385
+ functionToExecute = new Function(`${configurationProcessor.script}\nreturn transform;`)();
2386
+ this.executedFunctions[configurationProcessor.apiName] = functionToExecute;
2387
+ }
2388
+ return functionToExecute({
2363
2389
  request,
2364
- inputData: inputData,
2390
+ inputData,
2365
2391
  });
2366
2392
  }
2367
2393
  }