@veloceapps/sdk 8.0.0-134 → 8.0.0-136

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.
@@ -107,16 +107,17 @@ class ContextService {
107
107
  return this.resolve().properties.mode;
108
108
  }
109
109
  get isEditMode$() {
110
- return this.resolve$().pipe(map(() => {
111
- const context = this.resolve();
112
- if (context.mode === ConfigurationContextMode.ACCOUNT) {
113
- return true;
114
- }
115
- if (context.mode === ConfigurationContextMode.QUOTE) {
116
- return context.properties.Status === 'Draft';
117
- }
118
- return false;
119
- }));
110
+ return this.resolve$().pipe(map(() => this.isEditMode));
111
+ }
112
+ get isEditMode() {
113
+ const context = this.resolve();
114
+ if (context.mode === ConfigurationContextMode.ACCOUNT) {
115
+ return true;
116
+ }
117
+ if (context.mode === ConfigurationContextMode.QUOTE) {
118
+ return context.properties.Status === 'Draft';
119
+ }
120
+ return false;
120
121
  }
121
122
  resolve() {
122
123
  if (!this.context.value) {
@@ -170,6 +171,10 @@ class FlowInfoService {
170
171
  var _a;
171
172
  return !!this.flow && ((_a = this.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful) == null;
172
173
  }
174
+ get isStateful() {
175
+ var _a;
176
+ return !!((_a = this.flow) === null || _a === void 0 ? void 0 : _a.properties.stateful);
177
+ }
173
178
  constructor(flowsApiService, templatesApiService, customizationService) {
174
179
  this.flowsApiService = flowsApiService;
175
180
  this.templatesApiService = templatesApiService;
@@ -742,6 +747,7 @@ class FlowStateService {
742
747
  this.toastService = toastService;
743
748
  this.customizationService = customizationService;
744
749
  this.NOT_INITIALIZED = Symbol();
750
+ this.executedFunctions = {};
745
751
  this._hasStatefulUnsavedChanges = false;
746
752
  this.stateId$ = new BehaviorSubject(null);
747
753
  this.processors = {};
@@ -1114,29 +1120,34 @@ class FlowStateService {
1114
1120
  return forkJoin(owners$).pipe(map$1(noop));
1115
1121
  }
1116
1122
  executeActionScript(request, executable) {
1117
- var _a, _b;
1118
- 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;
1119
- 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)) {
1120
1126
  const scope = this.getScopeByOwnerId(executable.ownerId);
1121
1127
  const scopeText = scope ? ` in ${scope}` : '';
1122
1128
  throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1123
1129
  }
1124
- return this.executeProcessorScript(request, script, executable.inputData);
1130
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1125
1131
  }
1126
1132
  executeSelectorScript(request, executable) {
1127
- var _a, _b;
1128
- 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;
1129
- 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)) {
1130
1136
  const scope = this.getScopeByOwnerId(executable.ownerId);
1131
1137
  const scopeText = scope ? ` in ${scope}` : '';
1132
1138
  throw `ConfigurationProcessor ${executable.apiName}${scopeText} not found`;
1133
1139
  }
1134
- return this.executeProcessorScript(request, script, executable.inputData);
1140
+ return this.executeProcessorScript(request, configurationProcessor, executable.inputData);
1135
1141
  }
1136
- executeProcessorScript(request, script, inputData) {
1137
- 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({
1138
1149
  request,
1139
- inputData: inputData,
1150
+ inputData,
1140
1151
  });
1141
1152
  }
1142
1153
  generateRequestId(scope, selectorName, inputData) {
@@ -2121,10 +2132,12 @@ class ConfigurationStateService {
2121
2132
  this.flowStateApiService = flowStateApiService;
2122
2133
  this.quoteApiService = quoteApiService;
2123
2134
  this.NOT_INITIALIZED = Symbol();
2135
+ this.executedFunctions = {};
2124
2136
  this.stateId = null;
2125
2137
  this.ownerId = '';
2126
2138
  this.subscriptions = {};
2127
2139
  this.isInitialized$ = new BehaviorSubject(false);
2140
+ this.canceledConfiguration$ = new Subject();
2128
2141
  }
2129
2142
  init$() {
2130
2143
  let request$;
@@ -2134,7 +2147,10 @@ class ConfigurationStateService {
2134
2147
  else {
2135
2148
  request$ = this.initStateless$();
2136
2149
  }
2137
- return request$.pipe(finalize(() => this.isInitialized$.next(true)));
2150
+ return request$.pipe(finalize(() => {
2151
+ this.isInitialized$.next(true);
2152
+ this.canceledConfiguration$ = new Subject();
2153
+ }));
2138
2154
  }
2139
2155
  cleanup() {
2140
2156
  this.stateId = null;
@@ -2205,10 +2221,13 @@ class ConfigurationStateService {
2205
2221
  }
2206
2222
  }
2207
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
+ }
2208
2227
  if (!this.subscriptions[requestId].data$.observed) {
2209
2228
  delete this.subscriptions[requestId];
2210
2229
  }
2211
- }));
2230
+ }), takeUntil(this.canceledConfiguration$));
2212
2231
  }
2213
2232
  saveConfiguration(quoteId, flow) {
2214
2233
  var _a, _b;
@@ -2253,6 +2272,9 @@ class ConfigurationStateService {
2253
2272
  if (!this.isInitialized$.value) {
2254
2273
  return of(undefined);
2255
2274
  }
2275
+ this.canceledConfiguration$.next();
2276
+ this.canceledConfiguration$.complete();
2277
+ this.subscriptions = {};
2256
2278
  this.isInitialized$.next(false);
2257
2279
  if (!this.isInitialized$.value || !this.isStatefulConfiguration) {
2258
2280
  return of(undefined);
@@ -2340,27 +2362,32 @@ class ConfigurationStateService {
2340
2362
  }));
2341
2363
  }
2342
2364
  executeActionScript(request, processor) {
2343
- var _a, _b, _c;
2365
+ var _a, _b;
2344
2366
  const { actions } = (_b = (_a = this.configurationRuntimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
2345
- 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;
2346
- 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)) {
2347
2369
  return request;
2348
2370
  }
2349
- return this.executeProcessorScript(request, script, processor.inputData);
2371
+ return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
2350
2372
  }
2351
2373
  executeSelectorScript(request, processor) {
2352
- var _a, _b, _c;
2374
+ var _a, _b;
2353
2375
  const { selectors } = (_b = (_a = this.configurationRuntimeService.runtimeContext) === null || _a === void 0 ? void 0 : _a.uiDefinitionContainer) !== null && _b !== void 0 ? _b : {};
2354
- 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;
2355
- 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)) {
2356
2378
  return null;
2357
2379
  }
2358
- return this.executeProcessorScript(request, script, processor.inputData);
2380
+ return this.executeProcessorScript(request, configurationProcessor, processor.inputData);
2359
2381
  }
2360
- executeProcessorScript(request, script, inputData) {
2361
- 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({
2362
2389
  request,
2363
- inputData: inputData,
2390
+ inputData,
2364
2391
  });
2365
2392
  }
2366
2393
  }