procode-lowcode-core 1.0.17 → 1.0.19

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.
package/dist/index.esm.js CHANGED
@@ -435,6 +435,20 @@ class FieldValidationDispatcher {
435
435
  }
436
436
  }
437
437
 
438
+ class ApiResultDispatcher {
439
+ static registerHandler(handler) {
440
+ ApiResultDispatcher.handler = handler;
441
+ }
442
+ static dispatch(result) {
443
+ if (ApiResultDispatcher.handler) {
444
+ ApiResultDispatcher.handler(result);
445
+ }
446
+ else {
447
+ console.warn("Api result dispatcher handler not registered.");
448
+ }
449
+ }
450
+ }
451
+
438
452
  function getStatusBaseNotifiType(status) {
439
453
  if (status >= 200 && status < 300)
440
454
  return "SUCCESS";
@@ -497,6 +511,14 @@ class CentralService {
497
511
  const statusRelatedConfig = (responseConfig !== null && responseConfig !== void 0 ? responseConfig : {})[status];
498
512
  const alertType = (statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.alertType) || AlertType.TOAST;
499
513
  response.data.alertType = alertType;
514
+ // Record the response outcome so post-request flow (e.g. navigation)
515
+ // can short-circuit when the server reported failure regardless of
516
+ // alertType. Success is derived from the HTTP-ish status set by the
517
+ // response formatter (2xx = success).
518
+ ApiResultDispatcher.dispatch({
519
+ success: status >= 200 && status < 300,
520
+ alertType,
521
+ });
500
522
  if (alertType === AlertType.FIELDVALIDATION) {
501
523
  // Structured payload (default convention {propertyName, message}, or
502
524
  // whatever shape the registered fieldErrorMapper recognizes): route to
@@ -18696,6 +18718,7 @@ const initialState$1 = {
18696
18718
  viewModel: { supportiveData: null, screenData: null },
18697
18719
  inProgressCount: 0,
18698
18720
  validation: {},
18721
+ lastApiResult: null,
18699
18722
  };
18700
18723
  const appSlice = createSlice({
18701
18724
  name: "appState",
@@ -18729,6 +18752,9 @@ const appSlice = createSlice({
18729
18752
  const { fieldName, invalidMessages } = action.payload;
18730
18753
  state.validation = Object.assign(Object.assign({}, state.validation), { [fieldName]: invalidMessages || [] });
18731
18754
  },
18755
+ setLastApiResult: (state, action) => {
18756
+ state.lastApiResult = action.payload;
18757
+ },
18732
18758
  },
18733
18759
  });
18734
18760
  const appActions = appSlice.actions;
@@ -18745,6 +18771,17 @@ const hasFieldValidationErrors = (eventService) => {
18745
18771
  return Object.values(validation).some((messages) => Array.isArray(messages) && messages.length > 0);
18746
18772
  };
18747
18773
 
18774
+ // Reads `state.app.lastApiResult` written by CentralService's response
18775
+ // interceptor and returns true if the most recent request failed. Used by
18776
+ // save/update actions to skip navigation when the server reported a
18777
+ // non-success status under any alertType (FIELDVALIDATION already populates
18778
+ // state.validation, but TOAST leaves no trace there).
18779
+ const hasLastApiCallFailed = (eventService) => {
18780
+ const appState = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.APP_STATE);
18781
+ const lastApiResult = appState === null || appState === void 0 ? void 0 : appState.lastApiResult;
18782
+ return lastApiResult ? lastApiResult.success === false : false;
18783
+ };
18784
+
18748
18785
  const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0, void 0, function* () {
18749
18786
  var _a, _b;
18750
18787
  const eventService = actionInvokerProps.eventService;
@@ -18770,6 +18807,11 @@ const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
18770
18807
  // from a form the user still has to fix.
18771
18808
  if (hasFieldValidationErrors(eventService))
18772
18809
  return;
18810
+ // TOAST-alert failures don't populate state.validation, so check the
18811
+ // last API call's success flag too — a toast-only error should still
18812
+ // keep the user on the current screen.
18813
+ if (hasLastApiCallFailed(eventService))
18814
+ return;
18773
18815
  handleNavigation(actionInvokerProps);
18774
18816
  });
18775
18817
 
@@ -18840,6 +18882,11 @@ const handleCreateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
18840
18882
  // from a form the user still has to fix.
18841
18883
  if (hasFieldValidationErrors(eventService))
18842
18884
  return;
18885
+ // TOAST-alert failures don't populate state.validation, so check the
18886
+ // last API call's success flag too — a toast-only error should still
18887
+ // keep the user on the current screen.
18888
+ if (hasLastApiCallFailed(eventService))
18889
+ return;
18843
18890
  handleNavigation(actionInvokerProps);
18844
18891
  });
18845
18892
 
@@ -18985,6 +19032,7 @@ var StandardValidationType;
18985
19032
  StandardValidationType["LESS_THAN_EQUAL"] = "LESS_THAN_EQUAL";
18986
19033
  StandardValidationType["BETWEEN"] = "BETWEEN";
18987
19034
  StandardValidationType["NOT_BETWEEN"] = "NOT_BETWEEN";
19035
+ StandardValidationType["ALPHANUMERIC_SPACE"] = "ALPHANUMERIC_SPACE";
18988
19036
  })(StandardValidationType || (StandardValidationType = {}));
18989
19037
 
18990
19038
  /**
@@ -19295,6 +19343,20 @@ const requiredValidation = ({ validation, viewModel, eventService, value, }) =>
19295
19343
  };
19296
19344
  };
19297
19345
 
19346
+ const alphanumericSpaceValidation = ({ validation, value, }) => {
19347
+ if (value === null || value === undefined || value === "") {
19348
+ return { isValid: true, message: "" };
19349
+ }
19350
+ const regex = /^[A-Za-z0-9 ]+$/;
19351
+ const isValid = regex.test(String(value));
19352
+ return {
19353
+ isValid,
19354
+ message: isValid
19355
+ ? ""
19356
+ : validation.message || "Only letters, numbers and spaces are allowed",
19357
+ };
19358
+ };
19359
+
19298
19360
  class StandardValidationFactory {
19299
19361
  constructor() {
19300
19362
  Object.defineProperty(this, "validationMap", {
@@ -19313,6 +19375,7 @@ class StandardValidationFactory {
19313
19375
  [StandardValidationType.LESS_THAN_EQUAL]: lessThanEqualValidation,
19314
19376
  [StandardValidationType.BETWEEN]: betweenValidation,
19315
19377
  [StandardValidationType.NOT_BETWEEN]: notBetweenValidation,
19378
+ [StandardValidationType.ALPHANUMERIC_SPACE]: alphanumericSpaceValidation,
19316
19379
  }
19317
19380
  });
19318
19381
  }
@@ -19782,6 +19845,12 @@ const setupStoreAction = (dispatch, eventService, store) => {
19782
19845
  FieldValidationDispatcher.registerHandler((errors) => {
19783
19846
  dispatch(appActions.loadValidation(errors));
19784
19847
  });
19848
+ // Record the latest server response's success/alertType so flow-control
19849
+ // helpers (e.g. hasLastApiCallFailed) can decide whether to continue with
19850
+ // post-request actions like navigation.
19851
+ ApiResultDispatcher.registerHandler((result) => {
19852
+ dispatch(appActions.setLastApiResult(result));
19853
+ });
19785
19854
  // Register loader handlers for external services
19786
19855
  eventService === null || eventService === void 0 ? void 0 : eventService.subscribe(eventServiceType.REQUEST_START, () => () => {
19787
19856
  dispatch(commonDataActions.updatePendingRequests(LoadingStatus.INPROCESS));
@@ -20682,6 +20751,7 @@ const useCoreInitialization = (coreProps) => {
20682
20751
  requestHeaders: coreProps.requestHeaders,
20683
20752
  getSchemaBySlugService: coreProps.getSchemaBySlugService,
20684
20753
  responseFormatter: coreProps.responseFormatter,
20754
+ fieldErrorMapper: coreProps.fieldErrorMapper,
20685
20755
  });
20686
20756
  };
20687
20757
  const initCustomStorages = () => {