procode-lowcode-core 1.0.15 → 1.0.17
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 +197 -109
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +197 -109
- package/dist/index.js.map +1 -1
- package/dist/types/Action/helpers/hasFieldValidationErrors.d.ts +2 -0
- package/dist/types/ApplicationStart/AppDependenceyProvider.d.ts +4 -1
- package/dist/types/ApplicationStart/HOC/FieldValidationDispatcher.d.ts +9 -0
- package/dist/types/Constant.d.ts +1 -0
- package/dist/types/DataModel/CoreViewModelHandler.d.ts +2 -0
- package/dist/types/DataModel/SupportiveFunctions/index.d.ts +2 -2
- package/dist/types/Services/CentralService.d.ts +1 -1
- package/dist/types/Services/helpers/defaultFieldErrorMapper.d.ts +4 -0
- package/dist/types/Utils/resolveBoundValue.d.ts +1 -1
- package/package.json +1 -1
- package/src/Action/StandardActions/handleCreateAndNavigate.ts +16 -11
- package/src/Action/StandardActions/handleUpdateAndNavigate.ts +16 -11
- package/src/Action/helpers/hasFieldValidationErrors.ts +16 -0
- package/src/ApplicationStart/AppDependenceyProvider.ts +13 -0
- package/src/ApplicationStart/HOC/FieldValidationDispatcher.ts +21 -0
- package/src/ApplicationStart/helper/setupStoreAction.ts +12 -1
- package/src/Constant.ts +1 -0
- package/src/DataModel/CoreViewModelHandler.ts +221 -241
- package/src/DataModel/SupportiveFunctions/index.ts +12 -8
- package/src/Services/CentralService.ts +66 -57
- package/src/Services/helpers/defaultFieldErrorMapper.ts +40 -0
- package/src/Utils/resolveBoundValue.ts +1 -0
package/dist/index.esm.js
CHANGED
|
@@ -71,6 +71,7 @@ const eventServiceType = {
|
|
|
71
71
|
UI_SCHEMA_ACTION: "UI_SCHEMA_ACTION",
|
|
72
72
|
UISCHEMA: "UISCHEMA",
|
|
73
73
|
DATASTATE: "DATASTATE",
|
|
74
|
+
APP_STATE: "APP_STATE",
|
|
74
75
|
REQUEST_START: "REQUEST_START",
|
|
75
76
|
REQUEST_END: "REQUEST_END",
|
|
76
77
|
};
|
|
@@ -420,6 +421,20 @@ class NotificationService {
|
|
|
420
421
|
}
|
|
421
422
|
}
|
|
422
423
|
|
|
424
|
+
class FieldValidationDispatcher {
|
|
425
|
+
static registerHandler(handler) {
|
|
426
|
+
FieldValidationDispatcher.handler = handler;
|
|
427
|
+
}
|
|
428
|
+
static dispatch(errors) {
|
|
429
|
+
if (FieldValidationDispatcher.handler) {
|
|
430
|
+
FieldValidationDispatcher.handler(errors);
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
console.warn("Field validation dispatcher handler not registered.");
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
423
438
|
function getStatusBaseNotifiType(status) {
|
|
424
439
|
if (status >= 200 && status < 300)
|
|
425
440
|
return "SUCCESS";
|
|
@@ -432,7 +447,7 @@ class CentralService {
|
|
|
432
447
|
enumerable: true,
|
|
433
448
|
configurable: true,
|
|
434
449
|
writable: true,
|
|
435
|
-
value:
|
|
450
|
+
value: void 0
|
|
436
451
|
});
|
|
437
452
|
Object.defineProperty(this, "setHeaders", {
|
|
438
453
|
enumerable: true,
|
|
@@ -445,7 +460,6 @@ class CentralService {
|
|
|
445
460
|
base.headers[key] = customHeaders[key];
|
|
446
461
|
});
|
|
447
462
|
}
|
|
448
|
-
return base;
|
|
449
463
|
}
|
|
450
464
|
});
|
|
451
465
|
Object.defineProperty(this, "getMessage", {
|
|
@@ -453,16 +467,15 @@ class CentralService {
|
|
|
453
467
|
configurable: true,
|
|
454
468
|
writable: true,
|
|
455
469
|
value: (response, responseConfig) => {
|
|
456
|
-
var _a;
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
if (statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.enableMessage)
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
return errorMessage;
|
|
470
|
+
var _a, _b;
|
|
471
|
+
const status = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.status;
|
|
472
|
+
const statusRelatedConfig = (responseConfig !== null && responseConfig !== void 0 ? responseConfig : {})[status];
|
|
473
|
+
if (!(statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.enableMessage))
|
|
474
|
+
return "";
|
|
475
|
+
const payloadMessage = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.message;
|
|
476
|
+
return ((statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.message) ||
|
|
477
|
+
(typeof payloadMessage === "string" ? payloadMessage : "") ||
|
|
478
|
+
ErrorMessageProvider.get(response.config.method, status));
|
|
466
479
|
}
|
|
467
480
|
});
|
|
468
481
|
Object.defineProperty(this, "handleResponseStatus", {
|
|
@@ -470,23 +483,38 @@ class CentralService {
|
|
|
470
483
|
configurable: true,
|
|
471
484
|
writable: true,
|
|
472
485
|
value: (response) => {
|
|
473
|
-
var _a, _b
|
|
474
|
-
|
|
486
|
+
var _a, _b;
|
|
487
|
+
const status = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.status;
|
|
488
|
+
if (status === 401) {
|
|
475
489
|
window.location.href = env.baseLogoutUrl || "/";
|
|
490
|
+
return;
|
|
476
491
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
492
|
+
if (!(status >= 200 && status < 500)) {
|
|
493
|
+
throw new Error("Unhandled response status " + status);
|
|
494
|
+
}
|
|
495
|
+
const customAxiosRequestConfig = response.config;
|
|
496
|
+
const responseConfig = customAxiosRequestConfig === null || customAxiosRequestConfig === void 0 ? void 0 : customAxiosRequestConfig.responseConfig;
|
|
497
|
+
const statusRelatedConfig = (responseConfig !== null && responseConfig !== void 0 ? responseConfig : {})[status];
|
|
498
|
+
const alertType = (statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.alertType) || AlertType.TOAST;
|
|
499
|
+
response.data.alertType = alertType;
|
|
500
|
+
if (alertType === AlertType.FIELDVALIDATION) {
|
|
501
|
+
// Structured payload (default convention {propertyName, message}, or
|
|
502
|
+
// whatever shape the registered fieldErrorMapper recognizes): route to
|
|
503
|
+
// the per-field validation slice. If the mapper finds nothing — e.g.
|
|
504
|
+
// the server returned a plain string — fall through to the toast path
|
|
505
|
+
// below, so the message still surfaces as a notification.
|
|
506
|
+
const fieldErrorMapper = AppDependenceyProvider.getInstance()
|
|
507
|
+
.getFieldErrorMapper();
|
|
508
|
+
const fieldErrors = fieldErrorMapper((_b = response.data) === null || _b === void 0 ? void 0 : _b.message);
|
|
509
|
+
if (Object.keys(fieldErrors).length > 0) {
|
|
510
|
+
response.data.fieldErrors = fieldErrors;
|
|
511
|
+
FieldValidationDispatcher.dispatch(fieldErrors);
|
|
512
|
+
return;
|
|
486
513
|
}
|
|
487
514
|
}
|
|
488
|
-
|
|
489
|
-
|
|
515
|
+
response.data.message = this.getMessage(response, responseConfig);
|
|
516
|
+
if (statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.enableMessage) {
|
|
517
|
+
NotificationService.showNotification(response.data.message, getStatusBaseNotifiType(status));
|
|
490
518
|
}
|
|
491
519
|
}
|
|
492
520
|
});
|
|
@@ -517,15 +545,13 @@ class CentralService {
|
|
|
517
545
|
configurable: true,
|
|
518
546
|
writable: true,
|
|
519
547
|
value: (axiosInstance) => {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
});
|
|
528
|
-
}
|
|
548
|
+
axiosInstance.interceptors.request.use((request) => {
|
|
549
|
+
this.setHeaders(request, AppDependenceyProvider.getInstance().getRequestHeaders());
|
|
550
|
+
return request;
|
|
551
|
+
}, (error) => {
|
|
552
|
+
console.error("Request error:", error);
|
|
553
|
+
throw error;
|
|
554
|
+
});
|
|
529
555
|
}
|
|
530
556
|
});
|
|
531
557
|
Object.defineProperty(this, "getAxioInstance", {
|
|
@@ -869,28 +895,50 @@ const handleFetchRequest = (queryParam, apiConfig, eventService, fetchService, d
|
|
|
869
895
|
|
|
870
896
|
class CoreViewModelHandler {
|
|
871
897
|
constructor() {
|
|
898
|
+
// Resolve & apply the configured "before request" adapter to the input.
|
|
899
|
+
// Order: disable flag wins, then a custom-named adapter from EventService,
|
|
900
|
+
// then the supplied default serializer.
|
|
901
|
+
Object.defineProperty(this, "applyBefore", {
|
|
902
|
+
enumerable: true,
|
|
903
|
+
configurable: true,
|
|
904
|
+
writable: true,
|
|
905
|
+
value: (eventService, opConfig, input, defaultSerializer) => {
|
|
906
|
+
if (opConfig === null || opConfig === void 0 ? void 0 : opConfig.disableBeforeRequest)
|
|
907
|
+
return input;
|
|
908
|
+
const custom = eventService.emit(AdapterType.GET_CUSTOM_ADAPTER_METHOD, opConfig === null || opConfig === void 0 ? void 0 : opConfig.beforeRequestMethodName);
|
|
909
|
+
return (custom !== null && custom !== void 0 ? custom : defaultSerializer)(eventService, input);
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
// Build the "after request" adapter callable. Returns null when disabled,
|
|
913
|
+
// so it can be passed straight to handleFetchRequest (which treats null as
|
|
914
|
+
// "skip deserialization") and re-used directly for create/update flows.
|
|
915
|
+
Object.defineProperty(this, "resolveAfter", {
|
|
916
|
+
enumerable: true,
|
|
917
|
+
configurable: true,
|
|
918
|
+
writable: true,
|
|
919
|
+
value: (eventService, opConfig, defaultDeserializer) => {
|
|
920
|
+
if (opConfig === null || opConfig === void 0 ? void 0 : opConfig.disableAfterRequest)
|
|
921
|
+
return null;
|
|
922
|
+
const custom = eventService.emit(AdapterType.GET_CUSTOM_ADAPTER_METHOD, opConfig === null || opConfig === void 0 ? void 0 : opConfig.afterRequestMethodName);
|
|
923
|
+
return custom !== null && custom !== void 0 ? custom : defaultDeserializer;
|
|
924
|
+
}
|
|
925
|
+
});
|
|
872
926
|
Object.defineProperty(this, "getViewModel", {
|
|
873
927
|
enumerable: true,
|
|
874
928
|
configurable: true,
|
|
875
929
|
writable: true,
|
|
876
930
|
value: (screenDataQueryParams, supportiveQueryParams, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
877
931
|
var _a, _b;
|
|
878
|
-
const viewModel = {
|
|
879
|
-
screenData: null,
|
|
880
|
-
supportiveData: null,
|
|
881
|
-
};
|
|
882
932
|
const [supportiveData, screenData] = yield Promise.all([
|
|
883
933
|
((_a = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData) === null || _a === void 0 ? void 0 : _a.endPoint) &&
|
|
884
934
|
(supportiveQueryParams === null || supportiveQueryParams === void 0 ? void 0 : supportiveQueryParams.length) > 0
|
|
885
|
-
?
|
|
935
|
+
? this.getSupportiveData(supportiveQueryParams, apiConfig, eventService)
|
|
886
936
|
: Promise.resolve(null),
|
|
887
937
|
((_b = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get) === null || _b === void 0 ? void 0 : _b.endPoint)
|
|
888
|
-
?
|
|
938
|
+
? this.getModel(screenDataQueryParams, apiConfig, eventService)
|
|
889
939
|
: Promise.resolve(null),
|
|
890
940
|
]);
|
|
891
|
-
|
|
892
|
-
viewModel.supportiveData = supportiveData;
|
|
893
|
-
return viewModel;
|
|
941
|
+
return { screenData, supportiveData };
|
|
894
942
|
})
|
|
895
943
|
});
|
|
896
944
|
Object.defineProperty(this, "getModel", {
|
|
@@ -898,16 +946,9 @@ class CoreViewModelHandler {
|
|
|
898
946
|
configurable: true,
|
|
899
947
|
writable: true,
|
|
900
948
|
value: (screenDataQueryParams, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
901
|
-
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
const applicableParams = ((_e = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get) === null || _e === void 0 ? void 0 : _e.disableBeforeRequest)
|
|
905
|
-
? screenDataQueryParams
|
|
906
|
-
: (customAdapterBefore !== null && customAdapterBefore !== void 0 ? customAdapterBefore : serializedScreenDataQueryParams)(eventService, screenDataQueryParams);
|
|
907
|
-
const applicableResponse = ((_f = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get) === null || _f === void 0 ? void 0 : _f.disableAfterRequest)
|
|
908
|
-
? null
|
|
909
|
-
: customAdapterAfter !== null && customAdapterAfter !== void 0 ? customAdapterAfter : deserializedModel;
|
|
910
|
-
return handleFetchRequest(applicableParams, apiConfig, eventService, fetchScreenDataService, applicableResponse);
|
|
949
|
+
const params = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get, screenDataQueryParams, serializedScreenDataQueryParams);
|
|
950
|
+
const after = this.resolveAfter(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get, deserializedModel);
|
|
951
|
+
return handleFetchRequest(params, apiConfig, eventService, fetchScreenDataService, after);
|
|
911
952
|
})
|
|
912
953
|
});
|
|
913
954
|
Object.defineProperty(this, "getSupportiveData", {
|
|
@@ -915,16 +956,9 @@ class CoreViewModelHandler {
|
|
|
915
956
|
configurable: true,
|
|
916
957
|
writable: true,
|
|
917
958
|
value: (supportiveQueryParams, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
918
|
-
|
|
919
|
-
const
|
|
920
|
-
|
|
921
|
-
const applicableParams = ((_j = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData) === null || _j === void 0 ? void 0 : _j.disableBeforeRequest)
|
|
922
|
-
? supportiveQueryParams
|
|
923
|
-
: (customAdapterBefore !== null && customAdapterBefore !== void 0 ? customAdapterBefore : serializedSupportiveQueryParams)(eventService, supportiveQueryParams);
|
|
924
|
-
const applicableResponse = ((_k = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData) === null || _k === void 0 ? void 0 : _k.disableAfterRequest)
|
|
925
|
-
? null
|
|
926
|
-
: customAdapterAfter !== null && customAdapterAfter !== void 0 ? customAdapterAfter : deserializedSupportiveData;
|
|
927
|
-
return handleFetchRequest(applicableParams, apiConfig, eventService, fetchSupportiveDataService, applicableResponse);
|
|
959
|
+
const params = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData, supportiveQueryParams, serializedSupportiveQueryParams);
|
|
960
|
+
const after = this.resolveAfter(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData, deserializedSupportiveData);
|
|
961
|
+
return handleFetchRequest(params, apiConfig, eventService, fetchSupportiveDataService, after);
|
|
928
962
|
})
|
|
929
963
|
});
|
|
930
964
|
Object.defineProperty(this, "createModel", {
|
|
@@ -932,19 +966,11 @@ class CoreViewModelHandler {
|
|
|
932
966
|
configurable: true,
|
|
933
967
|
writable: true,
|
|
934
968
|
value: (model, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
935
|
-
|
|
936
|
-
const
|
|
937
|
-
const customAdapterAfter = eventService.emit("GET_CUSTOM_ADAPTER_METHOD", (_m = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create) === null || _m === void 0 ? void 0 : _m.afterRequestMethodName);
|
|
938
|
-
const applicableModel = ((_o = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create) === null || _o === void 0 ? void 0 : _o.disableBeforeRequest)
|
|
939
|
-
? model
|
|
940
|
-
: (customAdapterBefore !== null && customAdapterBefore !== void 0 ? customAdapterBefore : serializedModel)(eventService, model);
|
|
969
|
+
const payload = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create, model, serializedModel);
|
|
970
|
+
const after = this.resolveAfter(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create, deserializedModel);
|
|
941
971
|
return handleRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
const applicableResponse = ((_p = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create) === null || _p === void 0 ? void 0 : _p.disableAfterRequest)
|
|
945
|
-
? servicesResponse
|
|
946
|
-
: (customAdapterAfter !== null && customAdapterAfter !== void 0 ? customAdapterAfter : deserializedModel)(eventService, servicesResponse);
|
|
947
|
-
return applicableResponse;
|
|
972
|
+
const servicesResponse = yield createService(apiConfig, payload, eventService);
|
|
973
|
+
return after ? after(eventService, servicesResponse) : servicesResponse;
|
|
948
974
|
}), eventService);
|
|
949
975
|
})
|
|
950
976
|
});
|
|
@@ -953,22 +979,15 @@ class CoreViewModelHandler {
|
|
|
953
979
|
configurable: true,
|
|
954
980
|
writable: true,
|
|
955
981
|
value: (model, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
956
|
-
var
|
|
957
|
-
const
|
|
958
|
-
|
|
982
|
+
var _c;
|
|
983
|
+
const serviceFn = ((_c = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update) === null || _c === void 0 ? void 0 : _c.isPatchUpdate)
|
|
984
|
+
? patchService
|
|
985
|
+
: updateService;
|
|
986
|
+
const payload = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update, model, serializedModel);
|
|
987
|
+
const after = this.resolveAfter(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update, deserializedModel);
|
|
959
988
|
return handleRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
? patchService
|
|
963
|
-
: updateService;
|
|
964
|
-
const applicableModel = ((_t = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update) === null || _t === void 0 ? void 0 : _t.disableBeforeRequest)
|
|
965
|
-
? model
|
|
966
|
-
: (customAdapterBefore !== null && customAdapterBefore !== void 0 ? customAdapterBefore : serializedModel)(eventService, model);
|
|
967
|
-
const servicesResponse = yield serviceFc(apiConfig, applicableModel, eventService);
|
|
968
|
-
const applicableResponse = ((_u = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update) === null || _u === void 0 ? void 0 : _u.disableAfterRequest)
|
|
969
|
-
? servicesResponse
|
|
970
|
-
: (customAdapterAfter !== null && customAdapterAfter !== void 0 ? customAdapterAfter : deserializedModel)(eventService, servicesResponse);
|
|
971
|
-
return applicableResponse;
|
|
989
|
+
const servicesResponse = yield serviceFn(apiConfig, payload, eventService);
|
|
990
|
+
return after ? after(eventService, servicesResponse) : servicesResponse;
|
|
972
991
|
}), eventService);
|
|
973
992
|
})
|
|
974
993
|
});
|
|
@@ -977,11 +996,7 @@ class CoreViewModelHandler {
|
|
|
977
996
|
configurable: true,
|
|
978
997
|
writable: true,
|
|
979
998
|
value: (screenDataQueryParams, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
980
|
-
|
|
981
|
-
const customAdapter = eventService.emit("GET_CUSTOM_ADAPTER_METHOD", (_v = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.delete) === null || _v === void 0 ? void 0 : _v.beforeRequestMethodName);
|
|
982
|
-
const params = ((_w = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.delete) === null || _w === void 0 ? void 0 : _w.disableBeforeRequest)
|
|
983
|
-
? screenDataQueryParams
|
|
984
|
-
: (customAdapter !== null && customAdapter !== void 0 ? customAdapter : serializedScreenDataQueryParams)(eventService, screenDataQueryParams);
|
|
999
|
+
const params = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.delete, screenDataQueryParams, serializedScreenDataQueryParams);
|
|
985
1000
|
return handleRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
986
1001
|
yield deleteService(apiConfig, params, eventService);
|
|
987
1002
|
}), eventService);
|
|
@@ -1003,6 +1018,34 @@ const coreResponseFormatter = (data, status) => {
|
|
|
1003
1018
|
return Object.assign(Object.assign({}, data), { status: (_a = data.status) !== null && _a !== void 0 ? _a : status });
|
|
1004
1019
|
};
|
|
1005
1020
|
|
|
1021
|
+
// Default mapper assumes the common `{ propertyName, message }` convention.
|
|
1022
|
+
// Accepts either a single object or an array of them, and groups multiple
|
|
1023
|
+
// messages on the same field into one bucket.
|
|
1024
|
+
const defaultFieldErrorMapper = (raw) => {
|
|
1025
|
+
const errors = {};
|
|
1026
|
+
const append = (item) => {
|
|
1027
|
+
var _a;
|
|
1028
|
+
if (item &&
|
|
1029
|
+
typeof item === "object" &&
|
|
1030
|
+
"propertyName" in item &&
|
|
1031
|
+
"message" in item) {
|
|
1032
|
+
const { propertyName, message } = item;
|
|
1033
|
+
if (typeof propertyName === "string" && propertyName.length > 0) {
|
|
1034
|
+
const list = (_a = errors[propertyName]) !== null && _a !== void 0 ? _a : [];
|
|
1035
|
+
list.push(typeof message === "string" ? message : String(message !== null && message !== void 0 ? message : ""));
|
|
1036
|
+
errors[propertyName] = list;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
if (Array.isArray(raw)) {
|
|
1041
|
+
raw.forEach(append);
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
append(raw);
|
|
1045
|
+
}
|
|
1046
|
+
return errors;
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1006
1049
|
const axiosInstance = axios.create();
|
|
1007
1050
|
const getSchemaBySlugService = (slug, appCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1008
1051
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -1025,7 +1068,7 @@ class UninitializedInstanceException extends Error {
|
|
|
1025
1068
|
}
|
|
1026
1069
|
}
|
|
1027
1070
|
class AppDependenceyProvider {
|
|
1028
|
-
constructor({ adapterProvider, viewModelHandler, widgetProvider, templateWidgetProvider, customWidgetProvider, requestHeaders, getSchemaBySlugService: getSchemaBySlugService$1, responseFormatter, }) {
|
|
1071
|
+
constructor({ adapterProvider, viewModelHandler, widgetProvider, templateWidgetProvider, customWidgetProvider, requestHeaders, getSchemaBySlugService: getSchemaBySlugService$1, responseFormatter, fieldErrorMapper, }) {
|
|
1029
1072
|
Object.defineProperty(this, "_adapterProvider", {
|
|
1030
1073
|
enumerable: true,
|
|
1031
1074
|
configurable: true,
|
|
@@ -1074,6 +1117,12 @@ class AppDependenceyProvider {
|
|
|
1074
1117
|
writable: true,
|
|
1075
1118
|
value: void 0
|
|
1076
1119
|
});
|
|
1120
|
+
Object.defineProperty(this, "_fieldErrorMapper", {
|
|
1121
|
+
enumerable: true,
|
|
1122
|
+
configurable: true,
|
|
1123
|
+
writable: true,
|
|
1124
|
+
value: void 0
|
|
1125
|
+
});
|
|
1077
1126
|
Object.defineProperty(this, "getAdapterProvider", {
|
|
1078
1127
|
enumerable: true,
|
|
1079
1128
|
configurable: true,
|
|
@@ -1146,6 +1195,16 @@ class AppDependenceyProvider {
|
|
|
1146
1195
|
return this._responseFormatter;
|
|
1147
1196
|
}
|
|
1148
1197
|
});
|
|
1198
|
+
Object.defineProperty(this, "getFieldErrorMapper", {
|
|
1199
|
+
enumerable: true,
|
|
1200
|
+
configurable: true,
|
|
1201
|
+
writable: true,
|
|
1202
|
+
value: () => {
|
|
1203
|
+
if (!this._fieldErrorMapper)
|
|
1204
|
+
return defaultFieldErrorMapper;
|
|
1205
|
+
return this._fieldErrorMapper;
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1149
1208
|
this._adapterProvider = adapterProvider;
|
|
1150
1209
|
this._viewModelHandler = viewModelHandler;
|
|
1151
1210
|
this._widgetProvider = widgetProvider;
|
|
@@ -1154,13 +1213,14 @@ class AppDependenceyProvider {
|
|
|
1154
1213
|
this._requestHeaders = requestHeaders;
|
|
1155
1214
|
this._getSchemaBySlugService = getSchemaBySlugService$1;
|
|
1156
1215
|
this._responseFormatter = responseFormatter;
|
|
1216
|
+
this._fieldErrorMapper = fieldErrorMapper;
|
|
1157
1217
|
}
|
|
1158
1218
|
}
|
|
1159
1219
|
Object.defineProperty(AppDependenceyProvider, "initInstance", {
|
|
1160
1220
|
enumerable: true,
|
|
1161
1221
|
configurable: true,
|
|
1162
1222
|
writable: true,
|
|
1163
|
-
value: ({ adapterProvider, viewModelHandler, widgetProvider, templateWidgetProvider, customWidgetProvider, requestHeaders, getSchemaBySlugService, responseFormatter, }) => {
|
|
1223
|
+
value: ({ adapterProvider, viewModelHandler, widgetProvider, templateWidgetProvider, customWidgetProvider, requestHeaders, getSchemaBySlugService, responseFormatter, fieldErrorMapper, }) => {
|
|
1164
1224
|
if (!AppDependenceyProvider.instance)
|
|
1165
1225
|
AppDependenceyProvider.instance = new AppDependenceyProvider({
|
|
1166
1226
|
adapterProvider,
|
|
@@ -1171,6 +1231,7 @@ Object.defineProperty(AppDependenceyProvider, "initInstance", {
|
|
|
1171
1231
|
requestHeaders,
|
|
1172
1232
|
getSchemaBySlugService,
|
|
1173
1233
|
responseFormatter,
|
|
1234
|
+
fieldErrorMapper,
|
|
1174
1235
|
});
|
|
1175
1236
|
}
|
|
1176
1237
|
});
|
|
@@ -18673,11 +18734,21 @@ const appSlice = createSlice({
|
|
|
18673
18734
|
const appActions = appSlice.actions;
|
|
18674
18735
|
var appReducer = appSlice.reducer;
|
|
18675
18736
|
|
|
18737
|
+
// Reads the latest `state.app.validation` slice and returns true if any field
|
|
18738
|
+
// currently carries one or more error messages. Used by save/update actions to
|
|
18739
|
+
// skip navigation when server-side field validation has populated errors after
|
|
18740
|
+
// the API call resolved.
|
|
18741
|
+
const hasFieldValidationErrors = (eventService) => {
|
|
18742
|
+
var _a;
|
|
18743
|
+
const appState = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.APP_STATE);
|
|
18744
|
+
const validation = ((_a = appState === null || appState === void 0 ? void 0 : appState.validation) !== null && _a !== void 0 ? _a : {});
|
|
18745
|
+
return Object.values(validation).some((messages) => Array.isArray(messages) && messages.length > 0);
|
|
18746
|
+
};
|
|
18747
|
+
|
|
18676
18748
|
const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18677
18749
|
var _a, _b;
|
|
18678
18750
|
const eventService = actionInvokerProps.eventService;
|
|
18679
18751
|
const dispatch = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.DISPATCH_STORE);
|
|
18680
|
-
// const appActions = eventService?.emit(eventServiceType.DATASTATE_ACTION);
|
|
18681
18752
|
const uiSchema = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.UISCHEMA);
|
|
18682
18753
|
const apiConfig = (_a = actionInvokerProps.actionProps.config.apiConfig) !== null && _a !== void 0 ? _a : _.cloneDeep(uiSchema.apiConfig);
|
|
18683
18754
|
const validationResult = {
|
|
@@ -18690,11 +18761,16 @@ const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
|
|
|
18690
18761
|
validationResult.schemaInvalidMessages = schemaInvalidMessages;
|
|
18691
18762
|
}
|
|
18692
18763
|
dispatch === null || dispatch === void 0 ? void 0 : dispatch(appActions === null || appActions === void 0 ? void 0 : appActions.loadValidation(validationResult.schemaInvalidMessages));
|
|
18693
|
-
if (validationResult.isSchemaValid)
|
|
18694
|
-
|
|
18695
|
-
|
|
18696
|
-
|
|
18697
|
-
|
|
18764
|
+
if (!validationResult.isSchemaValid)
|
|
18765
|
+
return;
|
|
18766
|
+
yield ((_b = AppDependenceyProvider.getInstance()
|
|
18767
|
+
.getViewModelHandler()) === null || _b === void 0 ? void 0 : _b.updateModel(actionInvokerProps.viewModel.screenData, apiConfig, eventService));
|
|
18768
|
+
// The response interceptor pushes server-side field errors into
|
|
18769
|
+
// state.validation via FieldValidationDispatcher. Don't navigate away
|
|
18770
|
+
// from a form the user still has to fix.
|
|
18771
|
+
if (hasFieldValidationErrors(eventService))
|
|
18772
|
+
return;
|
|
18773
|
+
handleNavigation(actionInvokerProps);
|
|
18698
18774
|
});
|
|
18699
18775
|
|
|
18700
18776
|
const replaceEndPointParams = (endPoint, data) => {
|
|
@@ -18743,7 +18819,6 @@ const handleCreateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
|
|
|
18743
18819
|
var _a, _b;
|
|
18744
18820
|
const eventService = actionInvokerProps.eventService;
|
|
18745
18821
|
const dispatch = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.DISPATCH_STORE);
|
|
18746
|
-
// const appActions = eventService?.emit(eventServiceType.DATASTATE_ACTION);
|
|
18747
18822
|
const uiSchema = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.UISCHEMA);
|
|
18748
18823
|
const apiConfig = (_a = actionInvokerProps.actionProps.config.apiConfig) !== null && _a !== void 0 ? _a : _.cloneDeep(uiSchema.apiConfig);
|
|
18749
18824
|
const validationResult = {
|
|
@@ -18756,11 +18831,16 @@ const handleCreateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
|
|
|
18756
18831
|
validationResult.schemaInvalidMessages = schemaInvalidMessages;
|
|
18757
18832
|
}
|
|
18758
18833
|
dispatch === null || dispatch === void 0 ? void 0 : dispatch(appActions === null || appActions === void 0 ? void 0 : appActions.loadValidation(validationResult.schemaInvalidMessages));
|
|
18759
|
-
if (validationResult.isSchemaValid)
|
|
18760
|
-
|
|
18761
|
-
|
|
18762
|
-
|
|
18763
|
-
|
|
18834
|
+
if (!validationResult.isSchemaValid)
|
|
18835
|
+
return;
|
|
18836
|
+
yield ((_b = AppDependenceyProvider.getInstance()
|
|
18837
|
+
.getViewModelHandler()) === null || _b === void 0 ? void 0 : _b.createModel(actionInvokerProps.viewModel.screenData, apiConfig, eventService));
|
|
18838
|
+
// The response interceptor pushes server-side field errors into
|
|
18839
|
+
// state.validation via FieldValidationDispatcher. Don't navigate away
|
|
18840
|
+
// from a form the user still has to fix.
|
|
18841
|
+
if (hasFieldValidationErrors(eventService))
|
|
18842
|
+
return;
|
|
18843
|
+
handleNavigation(actionInvokerProps);
|
|
18764
18844
|
});
|
|
18765
18845
|
|
|
18766
18846
|
const handleAPIGet = (actionInvokerProps, queryParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -18889,6 +18969,7 @@ const BOUND_PROP_NAMES = [
|
|
|
18889
18969
|
"step",
|
|
18890
18970
|
"placeHolder",
|
|
18891
18971
|
"disabled",
|
|
18972
|
+
"format",
|
|
18892
18973
|
];
|
|
18893
18974
|
|
|
18894
18975
|
var StandardValidationType;
|
|
@@ -19690,10 +19771,17 @@ const setupStoreAction = (dispatch, eventService, store) => {
|
|
|
19690
19771
|
[eventServiceType.UI_SCHEMA_ACTION]: metaDataActions,
|
|
19691
19772
|
[eventServiceType.DISPATCH_STORE]: dispatch,
|
|
19692
19773
|
[eventServiceType.DATASTATE]: () => store.getState().app.viewModel,
|
|
19774
|
+
[eventServiceType.APP_STATE]: () => store.getState().app,
|
|
19693
19775
|
};
|
|
19694
19776
|
Object.entries(actions).forEach(([eventType, action]) => {
|
|
19695
19777
|
eventService === null || eventService === void 0 ? void 0 : eventService.subscribe(eventType, () => action);
|
|
19696
19778
|
});
|
|
19779
|
+
// Route server-side field validation errors (alertType=fieldvalidation,
|
|
19780
|
+
// typically 422) into the same redux slice the client validator writes to,
|
|
19781
|
+
// so withValidations can render them under the relevant fields.
|
|
19782
|
+
FieldValidationDispatcher.registerHandler((errors) => {
|
|
19783
|
+
dispatch(appActions.loadValidation(errors));
|
|
19784
|
+
});
|
|
19697
19785
|
// Register loader handlers for external services
|
|
19698
19786
|
eventService === null || eventService === void 0 ? void 0 : eventService.subscribe(eventServiceType.REQUEST_START, () => () => {
|
|
19699
19787
|
dispatch(commonDataActions.updatePendingRequests(LoadingStatus.INPROCESS));
|