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.js
CHANGED
|
@@ -75,6 +75,7 @@ const eventServiceType = {
|
|
|
75
75
|
UI_SCHEMA_ACTION: "UI_SCHEMA_ACTION",
|
|
76
76
|
UISCHEMA: "UISCHEMA",
|
|
77
77
|
DATASTATE: "DATASTATE",
|
|
78
|
+
APP_STATE: "APP_STATE",
|
|
78
79
|
REQUEST_START: "REQUEST_START",
|
|
79
80
|
REQUEST_END: "REQUEST_END",
|
|
80
81
|
};
|
|
@@ -424,6 +425,20 @@ class NotificationService {
|
|
|
424
425
|
}
|
|
425
426
|
}
|
|
426
427
|
|
|
428
|
+
class FieldValidationDispatcher {
|
|
429
|
+
static registerHandler(handler) {
|
|
430
|
+
FieldValidationDispatcher.handler = handler;
|
|
431
|
+
}
|
|
432
|
+
static dispatch(errors) {
|
|
433
|
+
if (FieldValidationDispatcher.handler) {
|
|
434
|
+
FieldValidationDispatcher.handler(errors);
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
console.warn("Field validation dispatcher handler not registered.");
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
427
442
|
function getStatusBaseNotifiType(status) {
|
|
428
443
|
if (status >= 200 && status < 300)
|
|
429
444
|
return "SUCCESS";
|
|
@@ -436,7 +451,7 @@ class CentralService {
|
|
|
436
451
|
enumerable: true,
|
|
437
452
|
configurable: true,
|
|
438
453
|
writable: true,
|
|
439
|
-
value:
|
|
454
|
+
value: void 0
|
|
440
455
|
});
|
|
441
456
|
Object.defineProperty(this, "setHeaders", {
|
|
442
457
|
enumerable: true,
|
|
@@ -449,7 +464,6 @@ class CentralService {
|
|
|
449
464
|
base.headers[key] = customHeaders[key];
|
|
450
465
|
});
|
|
451
466
|
}
|
|
452
|
-
return base;
|
|
453
467
|
}
|
|
454
468
|
});
|
|
455
469
|
Object.defineProperty(this, "getMessage", {
|
|
@@ -457,16 +471,15 @@ class CentralService {
|
|
|
457
471
|
configurable: true,
|
|
458
472
|
writable: true,
|
|
459
473
|
value: (response, responseConfig) => {
|
|
460
|
-
var _a;
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
if (statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.enableMessage)
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return errorMessage;
|
|
474
|
+
var _a, _b;
|
|
475
|
+
const status = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.status;
|
|
476
|
+
const statusRelatedConfig = (responseConfig !== null && responseConfig !== void 0 ? responseConfig : {})[status];
|
|
477
|
+
if (!(statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.enableMessage))
|
|
478
|
+
return "";
|
|
479
|
+
const payloadMessage = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.message;
|
|
480
|
+
return ((statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.message) ||
|
|
481
|
+
(typeof payloadMessage === "string" ? payloadMessage : "") ||
|
|
482
|
+
ErrorMessageProvider.get(response.config.method, status));
|
|
470
483
|
}
|
|
471
484
|
});
|
|
472
485
|
Object.defineProperty(this, "handleResponseStatus", {
|
|
@@ -474,23 +487,38 @@ class CentralService {
|
|
|
474
487
|
configurable: true,
|
|
475
488
|
writable: true,
|
|
476
489
|
value: (response) => {
|
|
477
|
-
var _a, _b
|
|
478
|
-
|
|
490
|
+
var _a, _b;
|
|
491
|
+
const status = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.status;
|
|
492
|
+
if (status === 401) {
|
|
479
493
|
window.location.href = env.baseLogoutUrl || "/";
|
|
494
|
+
return;
|
|
480
495
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
496
|
+
if (!(status >= 200 && status < 500)) {
|
|
497
|
+
throw new Error("Unhandled response status " + status);
|
|
498
|
+
}
|
|
499
|
+
const customAxiosRequestConfig = response.config;
|
|
500
|
+
const responseConfig = customAxiosRequestConfig === null || customAxiosRequestConfig === void 0 ? void 0 : customAxiosRequestConfig.responseConfig;
|
|
501
|
+
const statusRelatedConfig = (responseConfig !== null && responseConfig !== void 0 ? responseConfig : {})[status];
|
|
502
|
+
const alertType = (statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.alertType) || AlertType.TOAST;
|
|
503
|
+
response.data.alertType = alertType;
|
|
504
|
+
if (alertType === AlertType.FIELDVALIDATION) {
|
|
505
|
+
// Structured payload (default convention {propertyName, message}, or
|
|
506
|
+
// whatever shape the registered fieldErrorMapper recognizes): route to
|
|
507
|
+
// the per-field validation slice. If the mapper finds nothing — e.g.
|
|
508
|
+
// the server returned a plain string — fall through to the toast path
|
|
509
|
+
// below, so the message still surfaces as a notification.
|
|
510
|
+
const fieldErrorMapper = AppDependenceyProvider.getInstance()
|
|
511
|
+
.getFieldErrorMapper();
|
|
512
|
+
const fieldErrors = fieldErrorMapper((_b = response.data) === null || _b === void 0 ? void 0 : _b.message);
|
|
513
|
+
if (Object.keys(fieldErrors).length > 0) {
|
|
514
|
+
response.data.fieldErrors = fieldErrors;
|
|
515
|
+
FieldValidationDispatcher.dispatch(fieldErrors);
|
|
516
|
+
return;
|
|
490
517
|
}
|
|
491
518
|
}
|
|
492
|
-
|
|
493
|
-
|
|
519
|
+
response.data.message = this.getMessage(response, responseConfig);
|
|
520
|
+
if (statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.enableMessage) {
|
|
521
|
+
NotificationService.showNotification(response.data.message, getStatusBaseNotifiType(status));
|
|
494
522
|
}
|
|
495
523
|
}
|
|
496
524
|
});
|
|
@@ -521,15 +549,13 @@ class CentralService {
|
|
|
521
549
|
configurable: true,
|
|
522
550
|
writable: true,
|
|
523
551
|
value: (axiosInstance) => {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
});
|
|
532
|
-
}
|
|
552
|
+
axiosInstance.interceptors.request.use((request) => {
|
|
553
|
+
this.setHeaders(request, AppDependenceyProvider.getInstance().getRequestHeaders());
|
|
554
|
+
return request;
|
|
555
|
+
}, (error) => {
|
|
556
|
+
console.error("Request error:", error);
|
|
557
|
+
throw error;
|
|
558
|
+
});
|
|
533
559
|
}
|
|
534
560
|
});
|
|
535
561
|
Object.defineProperty(this, "getAxioInstance", {
|
|
@@ -873,28 +899,50 @@ const handleFetchRequest = (queryParam, apiConfig, eventService, fetchService, d
|
|
|
873
899
|
|
|
874
900
|
class CoreViewModelHandler {
|
|
875
901
|
constructor() {
|
|
902
|
+
// Resolve & apply the configured "before request" adapter to the input.
|
|
903
|
+
// Order: disable flag wins, then a custom-named adapter from EventService,
|
|
904
|
+
// then the supplied default serializer.
|
|
905
|
+
Object.defineProperty(this, "applyBefore", {
|
|
906
|
+
enumerable: true,
|
|
907
|
+
configurable: true,
|
|
908
|
+
writable: true,
|
|
909
|
+
value: (eventService, opConfig, input, defaultSerializer) => {
|
|
910
|
+
if (opConfig === null || opConfig === void 0 ? void 0 : opConfig.disableBeforeRequest)
|
|
911
|
+
return input;
|
|
912
|
+
const custom = eventService.emit(AdapterType.GET_CUSTOM_ADAPTER_METHOD, opConfig === null || opConfig === void 0 ? void 0 : opConfig.beforeRequestMethodName);
|
|
913
|
+
return (custom !== null && custom !== void 0 ? custom : defaultSerializer)(eventService, input);
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
// Build the "after request" adapter callable. Returns null when disabled,
|
|
917
|
+
// so it can be passed straight to handleFetchRequest (which treats null as
|
|
918
|
+
// "skip deserialization") and re-used directly for create/update flows.
|
|
919
|
+
Object.defineProperty(this, "resolveAfter", {
|
|
920
|
+
enumerable: true,
|
|
921
|
+
configurable: true,
|
|
922
|
+
writable: true,
|
|
923
|
+
value: (eventService, opConfig, defaultDeserializer) => {
|
|
924
|
+
if (opConfig === null || opConfig === void 0 ? void 0 : opConfig.disableAfterRequest)
|
|
925
|
+
return null;
|
|
926
|
+
const custom = eventService.emit(AdapterType.GET_CUSTOM_ADAPTER_METHOD, opConfig === null || opConfig === void 0 ? void 0 : opConfig.afterRequestMethodName);
|
|
927
|
+
return custom !== null && custom !== void 0 ? custom : defaultDeserializer;
|
|
928
|
+
}
|
|
929
|
+
});
|
|
876
930
|
Object.defineProperty(this, "getViewModel", {
|
|
877
931
|
enumerable: true,
|
|
878
932
|
configurable: true,
|
|
879
933
|
writable: true,
|
|
880
934
|
value: (screenDataQueryParams, supportiveQueryParams, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
881
935
|
var _a, _b;
|
|
882
|
-
const viewModel = {
|
|
883
|
-
screenData: null,
|
|
884
|
-
supportiveData: null,
|
|
885
|
-
};
|
|
886
936
|
const [supportiveData, screenData] = yield Promise.all([
|
|
887
937
|
((_a = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData) === null || _a === void 0 ? void 0 : _a.endPoint) &&
|
|
888
938
|
(supportiveQueryParams === null || supportiveQueryParams === void 0 ? void 0 : supportiveQueryParams.length) > 0
|
|
889
|
-
?
|
|
939
|
+
? this.getSupportiveData(supportiveQueryParams, apiConfig, eventService)
|
|
890
940
|
: Promise.resolve(null),
|
|
891
941
|
((_b = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get) === null || _b === void 0 ? void 0 : _b.endPoint)
|
|
892
|
-
?
|
|
942
|
+
? this.getModel(screenDataQueryParams, apiConfig, eventService)
|
|
893
943
|
: Promise.resolve(null),
|
|
894
944
|
]);
|
|
895
|
-
|
|
896
|
-
viewModel.supportiveData = supportiveData;
|
|
897
|
-
return viewModel;
|
|
945
|
+
return { screenData, supportiveData };
|
|
898
946
|
})
|
|
899
947
|
});
|
|
900
948
|
Object.defineProperty(this, "getModel", {
|
|
@@ -902,16 +950,9 @@ class CoreViewModelHandler {
|
|
|
902
950
|
configurable: true,
|
|
903
951
|
writable: true,
|
|
904
952
|
value: (screenDataQueryParams, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
905
|
-
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
const applicableParams = ((_e = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get) === null || _e === void 0 ? void 0 : _e.disableBeforeRequest)
|
|
909
|
-
? screenDataQueryParams
|
|
910
|
-
: (customAdapterBefore !== null && customAdapterBefore !== void 0 ? customAdapterBefore : serializedScreenDataQueryParams)(eventService, screenDataQueryParams);
|
|
911
|
-
const applicableResponse = ((_f = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get) === null || _f === void 0 ? void 0 : _f.disableAfterRequest)
|
|
912
|
-
? null
|
|
913
|
-
: customAdapterAfter !== null && customAdapterAfter !== void 0 ? customAdapterAfter : deserializedModel;
|
|
914
|
-
return handleFetchRequest(applicableParams, apiConfig, eventService, fetchScreenDataService, applicableResponse);
|
|
953
|
+
const params = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get, screenDataQueryParams, serializedScreenDataQueryParams);
|
|
954
|
+
const after = this.resolveAfter(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.get, deserializedModel);
|
|
955
|
+
return handleFetchRequest(params, apiConfig, eventService, fetchScreenDataService, after);
|
|
915
956
|
})
|
|
916
957
|
});
|
|
917
958
|
Object.defineProperty(this, "getSupportiveData", {
|
|
@@ -919,16 +960,9 @@ class CoreViewModelHandler {
|
|
|
919
960
|
configurable: true,
|
|
920
961
|
writable: true,
|
|
921
962
|
value: (supportiveQueryParams, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
922
|
-
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
const applicableParams = ((_j = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData) === null || _j === void 0 ? void 0 : _j.disableBeforeRequest)
|
|
926
|
-
? supportiveQueryParams
|
|
927
|
-
: (customAdapterBefore !== null && customAdapterBefore !== void 0 ? customAdapterBefore : serializedSupportiveQueryParams)(eventService, supportiveQueryParams);
|
|
928
|
-
const applicableResponse = ((_k = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData) === null || _k === void 0 ? void 0 : _k.disableAfterRequest)
|
|
929
|
-
? null
|
|
930
|
-
: customAdapterAfter !== null && customAdapterAfter !== void 0 ? customAdapterAfter : deserializedSupportiveData;
|
|
931
|
-
return handleFetchRequest(applicableParams, apiConfig, eventService, fetchSupportiveDataService, applicableResponse);
|
|
963
|
+
const params = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData, supportiveQueryParams, serializedSupportiveQueryParams);
|
|
964
|
+
const after = this.resolveAfter(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.loadSupportiveData, deserializedSupportiveData);
|
|
965
|
+
return handleFetchRequest(params, apiConfig, eventService, fetchSupportiveDataService, after);
|
|
932
966
|
})
|
|
933
967
|
});
|
|
934
968
|
Object.defineProperty(this, "createModel", {
|
|
@@ -936,19 +970,11 @@ class CoreViewModelHandler {
|
|
|
936
970
|
configurable: true,
|
|
937
971
|
writable: true,
|
|
938
972
|
value: (model, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
939
|
-
|
|
940
|
-
const
|
|
941
|
-
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);
|
|
942
|
-
const applicableModel = ((_o = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create) === null || _o === void 0 ? void 0 : _o.disableBeforeRequest)
|
|
943
|
-
? model
|
|
944
|
-
: (customAdapterBefore !== null && customAdapterBefore !== void 0 ? customAdapterBefore : serializedModel)(eventService, model);
|
|
973
|
+
const payload = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create, model, serializedModel);
|
|
974
|
+
const after = this.resolveAfter(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create, deserializedModel);
|
|
945
975
|
return handleRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
const applicableResponse = ((_p = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create) === null || _p === void 0 ? void 0 : _p.disableAfterRequest)
|
|
949
|
-
? servicesResponse
|
|
950
|
-
: (customAdapterAfter !== null && customAdapterAfter !== void 0 ? customAdapterAfter : deserializedModel)(eventService, servicesResponse);
|
|
951
|
-
return applicableResponse;
|
|
976
|
+
const servicesResponse = yield createService(apiConfig, payload, eventService);
|
|
977
|
+
return after ? after(eventService, servicesResponse) : servicesResponse;
|
|
952
978
|
}), eventService);
|
|
953
979
|
})
|
|
954
980
|
});
|
|
@@ -957,22 +983,15 @@ class CoreViewModelHandler {
|
|
|
957
983
|
configurable: true,
|
|
958
984
|
writable: true,
|
|
959
985
|
value: (model, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
960
|
-
var
|
|
961
|
-
const
|
|
962
|
-
|
|
986
|
+
var _c;
|
|
987
|
+
const serviceFn = ((_c = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update) === null || _c === void 0 ? void 0 : _c.isPatchUpdate)
|
|
988
|
+
? patchService
|
|
989
|
+
: updateService;
|
|
990
|
+
const payload = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update, model, serializedModel);
|
|
991
|
+
const after = this.resolveAfter(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update, deserializedModel);
|
|
963
992
|
return handleRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
? patchService
|
|
967
|
-
: updateService;
|
|
968
|
-
const applicableModel = ((_t = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update) === null || _t === void 0 ? void 0 : _t.disableBeforeRequest)
|
|
969
|
-
? model
|
|
970
|
-
: (customAdapterBefore !== null && customAdapterBefore !== void 0 ? customAdapterBefore : serializedModel)(eventService, model);
|
|
971
|
-
const servicesResponse = yield serviceFc(apiConfig, applicableModel, eventService);
|
|
972
|
-
const applicableResponse = ((_u = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.update) === null || _u === void 0 ? void 0 : _u.disableAfterRequest)
|
|
973
|
-
? servicesResponse
|
|
974
|
-
: (customAdapterAfter !== null && customAdapterAfter !== void 0 ? customAdapterAfter : deserializedModel)(eventService, servicesResponse);
|
|
975
|
-
return applicableResponse;
|
|
993
|
+
const servicesResponse = yield serviceFn(apiConfig, payload, eventService);
|
|
994
|
+
return after ? after(eventService, servicesResponse) : servicesResponse;
|
|
976
995
|
}), eventService);
|
|
977
996
|
})
|
|
978
997
|
});
|
|
@@ -981,11 +1000,7 @@ class CoreViewModelHandler {
|
|
|
981
1000
|
configurable: true,
|
|
982
1001
|
writable: true,
|
|
983
1002
|
value: (screenDataQueryParams, apiConfig, eventService) => __awaiter(this, void 0, void 0, function* () {
|
|
984
|
-
|
|
985
|
-
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);
|
|
986
|
-
const params = ((_w = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.delete) === null || _w === void 0 ? void 0 : _w.disableBeforeRequest)
|
|
987
|
-
? screenDataQueryParams
|
|
988
|
-
: (customAdapter !== null && customAdapter !== void 0 ? customAdapter : serializedScreenDataQueryParams)(eventService, screenDataQueryParams);
|
|
1003
|
+
const params = this.applyBefore(eventService, apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.delete, screenDataQueryParams, serializedScreenDataQueryParams);
|
|
989
1004
|
return handleRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
990
1005
|
yield deleteService(apiConfig, params, eventService);
|
|
991
1006
|
}), eventService);
|
|
@@ -1007,6 +1022,34 @@ const coreResponseFormatter = (data, status) => {
|
|
|
1007
1022
|
return Object.assign(Object.assign({}, data), { status: (_a = data.status) !== null && _a !== void 0 ? _a : status });
|
|
1008
1023
|
};
|
|
1009
1024
|
|
|
1025
|
+
// Default mapper assumes the common `{ propertyName, message }` convention.
|
|
1026
|
+
// Accepts either a single object or an array of them, and groups multiple
|
|
1027
|
+
// messages on the same field into one bucket.
|
|
1028
|
+
const defaultFieldErrorMapper = (raw) => {
|
|
1029
|
+
const errors = {};
|
|
1030
|
+
const append = (item) => {
|
|
1031
|
+
var _a;
|
|
1032
|
+
if (item &&
|
|
1033
|
+
typeof item === "object" &&
|
|
1034
|
+
"propertyName" in item &&
|
|
1035
|
+
"message" in item) {
|
|
1036
|
+
const { propertyName, message } = item;
|
|
1037
|
+
if (typeof propertyName === "string" && propertyName.length > 0) {
|
|
1038
|
+
const list = (_a = errors[propertyName]) !== null && _a !== void 0 ? _a : [];
|
|
1039
|
+
list.push(typeof message === "string" ? message : String(message !== null && message !== void 0 ? message : ""));
|
|
1040
|
+
errors[propertyName] = list;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
if (Array.isArray(raw)) {
|
|
1045
|
+
raw.forEach(append);
|
|
1046
|
+
}
|
|
1047
|
+
else {
|
|
1048
|
+
append(raw);
|
|
1049
|
+
}
|
|
1050
|
+
return errors;
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1010
1053
|
const axiosInstance = axios.create();
|
|
1011
1054
|
const getSchemaBySlugService = (slug, appCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1012
1055
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -1029,7 +1072,7 @@ class UninitializedInstanceException extends Error {
|
|
|
1029
1072
|
}
|
|
1030
1073
|
}
|
|
1031
1074
|
class AppDependenceyProvider {
|
|
1032
|
-
constructor({ adapterProvider, viewModelHandler, widgetProvider, templateWidgetProvider, customWidgetProvider, requestHeaders, getSchemaBySlugService: getSchemaBySlugService$1, responseFormatter, }) {
|
|
1075
|
+
constructor({ adapterProvider, viewModelHandler, widgetProvider, templateWidgetProvider, customWidgetProvider, requestHeaders, getSchemaBySlugService: getSchemaBySlugService$1, responseFormatter, fieldErrorMapper, }) {
|
|
1033
1076
|
Object.defineProperty(this, "_adapterProvider", {
|
|
1034
1077
|
enumerable: true,
|
|
1035
1078
|
configurable: true,
|
|
@@ -1078,6 +1121,12 @@ class AppDependenceyProvider {
|
|
|
1078
1121
|
writable: true,
|
|
1079
1122
|
value: void 0
|
|
1080
1123
|
});
|
|
1124
|
+
Object.defineProperty(this, "_fieldErrorMapper", {
|
|
1125
|
+
enumerable: true,
|
|
1126
|
+
configurable: true,
|
|
1127
|
+
writable: true,
|
|
1128
|
+
value: void 0
|
|
1129
|
+
});
|
|
1081
1130
|
Object.defineProperty(this, "getAdapterProvider", {
|
|
1082
1131
|
enumerable: true,
|
|
1083
1132
|
configurable: true,
|
|
@@ -1150,6 +1199,16 @@ class AppDependenceyProvider {
|
|
|
1150
1199
|
return this._responseFormatter;
|
|
1151
1200
|
}
|
|
1152
1201
|
});
|
|
1202
|
+
Object.defineProperty(this, "getFieldErrorMapper", {
|
|
1203
|
+
enumerable: true,
|
|
1204
|
+
configurable: true,
|
|
1205
|
+
writable: true,
|
|
1206
|
+
value: () => {
|
|
1207
|
+
if (!this._fieldErrorMapper)
|
|
1208
|
+
return defaultFieldErrorMapper;
|
|
1209
|
+
return this._fieldErrorMapper;
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1153
1212
|
this._adapterProvider = adapterProvider;
|
|
1154
1213
|
this._viewModelHandler = viewModelHandler;
|
|
1155
1214
|
this._widgetProvider = widgetProvider;
|
|
@@ -1158,13 +1217,14 @@ class AppDependenceyProvider {
|
|
|
1158
1217
|
this._requestHeaders = requestHeaders;
|
|
1159
1218
|
this._getSchemaBySlugService = getSchemaBySlugService$1;
|
|
1160
1219
|
this._responseFormatter = responseFormatter;
|
|
1220
|
+
this._fieldErrorMapper = fieldErrorMapper;
|
|
1161
1221
|
}
|
|
1162
1222
|
}
|
|
1163
1223
|
Object.defineProperty(AppDependenceyProvider, "initInstance", {
|
|
1164
1224
|
enumerable: true,
|
|
1165
1225
|
configurable: true,
|
|
1166
1226
|
writable: true,
|
|
1167
|
-
value: ({ adapterProvider, viewModelHandler, widgetProvider, templateWidgetProvider, customWidgetProvider, requestHeaders, getSchemaBySlugService, responseFormatter, }) => {
|
|
1227
|
+
value: ({ adapterProvider, viewModelHandler, widgetProvider, templateWidgetProvider, customWidgetProvider, requestHeaders, getSchemaBySlugService, responseFormatter, fieldErrorMapper, }) => {
|
|
1168
1228
|
if (!AppDependenceyProvider.instance)
|
|
1169
1229
|
AppDependenceyProvider.instance = new AppDependenceyProvider({
|
|
1170
1230
|
adapterProvider,
|
|
@@ -1175,6 +1235,7 @@ Object.defineProperty(AppDependenceyProvider, "initInstance", {
|
|
|
1175
1235
|
requestHeaders,
|
|
1176
1236
|
getSchemaBySlugService,
|
|
1177
1237
|
responseFormatter,
|
|
1238
|
+
fieldErrorMapper,
|
|
1178
1239
|
});
|
|
1179
1240
|
}
|
|
1180
1241
|
});
|
|
@@ -18677,11 +18738,21 @@ const appSlice = toolkit.createSlice({
|
|
|
18677
18738
|
const appActions = appSlice.actions;
|
|
18678
18739
|
var appReducer = appSlice.reducer;
|
|
18679
18740
|
|
|
18741
|
+
// Reads the latest `state.app.validation` slice and returns true if any field
|
|
18742
|
+
// currently carries one or more error messages. Used by save/update actions to
|
|
18743
|
+
// skip navigation when server-side field validation has populated errors after
|
|
18744
|
+
// the API call resolved.
|
|
18745
|
+
const hasFieldValidationErrors = (eventService) => {
|
|
18746
|
+
var _a;
|
|
18747
|
+
const appState = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.APP_STATE);
|
|
18748
|
+
const validation = ((_a = appState === null || appState === void 0 ? void 0 : appState.validation) !== null && _a !== void 0 ? _a : {});
|
|
18749
|
+
return Object.values(validation).some((messages) => Array.isArray(messages) && messages.length > 0);
|
|
18750
|
+
};
|
|
18751
|
+
|
|
18680
18752
|
const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18681
18753
|
var _a, _b;
|
|
18682
18754
|
const eventService = actionInvokerProps.eventService;
|
|
18683
18755
|
const dispatch = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.DISPATCH_STORE);
|
|
18684
|
-
// const appActions = eventService?.emit(eventServiceType.DATASTATE_ACTION);
|
|
18685
18756
|
const uiSchema = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.UISCHEMA);
|
|
18686
18757
|
const apiConfig = (_a = actionInvokerProps.actionProps.config.apiConfig) !== null && _a !== void 0 ? _a : _.cloneDeep(uiSchema.apiConfig);
|
|
18687
18758
|
const validationResult = {
|
|
@@ -18694,11 +18765,16 @@ const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
|
|
|
18694
18765
|
validationResult.schemaInvalidMessages = schemaInvalidMessages;
|
|
18695
18766
|
}
|
|
18696
18767
|
dispatch === null || dispatch === void 0 ? void 0 : dispatch(appActions === null || appActions === void 0 ? void 0 : appActions.loadValidation(validationResult.schemaInvalidMessages));
|
|
18697
|
-
if (validationResult.isSchemaValid)
|
|
18698
|
-
|
|
18699
|
-
|
|
18700
|
-
|
|
18701
|
-
|
|
18768
|
+
if (!validationResult.isSchemaValid)
|
|
18769
|
+
return;
|
|
18770
|
+
yield ((_b = AppDependenceyProvider.getInstance()
|
|
18771
|
+
.getViewModelHandler()) === null || _b === void 0 ? void 0 : _b.updateModel(actionInvokerProps.viewModel.screenData, apiConfig, eventService));
|
|
18772
|
+
// The response interceptor pushes server-side field errors into
|
|
18773
|
+
// state.validation via FieldValidationDispatcher. Don't navigate away
|
|
18774
|
+
// from a form the user still has to fix.
|
|
18775
|
+
if (hasFieldValidationErrors(eventService))
|
|
18776
|
+
return;
|
|
18777
|
+
handleNavigation(actionInvokerProps);
|
|
18702
18778
|
});
|
|
18703
18779
|
|
|
18704
18780
|
const replaceEndPointParams = (endPoint, data) => {
|
|
@@ -18747,7 +18823,6 @@ const handleCreateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
|
|
|
18747
18823
|
var _a, _b;
|
|
18748
18824
|
const eventService = actionInvokerProps.eventService;
|
|
18749
18825
|
const dispatch = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.DISPATCH_STORE);
|
|
18750
|
-
// const appActions = eventService?.emit(eventServiceType.DATASTATE_ACTION);
|
|
18751
18826
|
const uiSchema = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.UISCHEMA);
|
|
18752
18827
|
const apiConfig = (_a = actionInvokerProps.actionProps.config.apiConfig) !== null && _a !== void 0 ? _a : _.cloneDeep(uiSchema.apiConfig);
|
|
18753
18828
|
const validationResult = {
|
|
@@ -18760,11 +18835,16 @@ const handleCreateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
|
|
|
18760
18835
|
validationResult.schemaInvalidMessages = schemaInvalidMessages;
|
|
18761
18836
|
}
|
|
18762
18837
|
dispatch === null || dispatch === void 0 ? void 0 : dispatch(appActions === null || appActions === void 0 ? void 0 : appActions.loadValidation(validationResult.schemaInvalidMessages));
|
|
18763
|
-
if (validationResult.isSchemaValid)
|
|
18764
|
-
|
|
18765
|
-
|
|
18766
|
-
|
|
18767
|
-
|
|
18838
|
+
if (!validationResult.isSchemaValid)
|
|
18839
|
+
return;
|
|
18840
|
+
yield ((_b = AppDependenceyProvider.getInstance()
|
|
18841
|
+
.getViewModelHandler()) === null || _b === void 0 ? void 0 : _b.createModel(actionInvokerProps.viewModel.screenData, apiConfig, eventService));
|
|
18842
|
+
// The response interceptor pushes server-side field errors into
|
|
18843
|
+
// state.validation via FieldValidationDispatcher. Don't navigate away
|
|
18844
|
+
// from a form the user still has to fix.
|
|
18845
|
+
if (hasFieldValidationErrors(eventService))
|
|
18846
|
+
return;
|
|
18847
|
+
handleNavigation(actionInvokerProps);
|
|
18768
18848
|
});
|
|
18769
18849
|
|
|
18770
18850
|
const handleAPIGet = (actionInvokerProps, queryParams) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -18893,6 +18973,7 @@ const BOUND_PROP_NAMES = [
|
|
|
18893
18973
|
"step",
|
|
18894
18974
|
"placeHolder",
|
|
18895
18975
|
"disabled",
|
|
18976
|
+
"format",
|
|
18896
18977
|
];
|
|
18897
18978
|
|
|
18898
18979
|
var StandardValidationType;
|
|
@@ -19694,10 +19775,17 @@ const setupStoreAction = (dispatch, eventService, store) => {
|
|
|
19694
19775
|
[eventServiceType.UI_SCHEMA_ACTION]: metaDataActions,
|
|
19695
19776
|
[eventServiceType.DISPATCH_STORE]: dispatch,
|
|
19696
19777
|
[eventServiceType.DATASTATE]: () => store.getState().app.viewModel,
|
|
19778
|
+
[eventServiceType.APP_STATE]: () => store.getState().app,
|
|
19697
19779
|
};
|
|
19698
19780
|
Object.entries(actions).forEach(([eventType, action]) => {
|
|
19699
19781
|
eventService === null || eventService === void 0 ? void 0 : eventService.subscribe(eventType, () => action);
|
|
19700
19782
|
});
|
|
19783
|
+
// Route server-side field validation errors (alertType=fieldvalidation,
|
|
19784
|
+
// typically 422) into the same redux slice the client validator writes to,
|
|
19785
|
+
// so withValidations can render them under the relevant fields.
|
|
19786
|
+
FieldValidationDispatcher.registerHandler((errors) => {
|
|
19787
|
+
dispatch(appActions.loadValidation(errors));
|
|
19788
|
+
});
|
|
19701
19789
|
// Register loader handlers for external services
|
|
19702
19790
|
eventService === null || eventService === void 0 ? void 0 : eventService.subscribe(eventServiceType.REQUEST_START, () => () => {
|
|
19703
19791
|
dispatch(commonDataActions.updatePendingRequests(LoadingStatus.INPROCESS));
|