@aemforms/af-core 0.22.146 → 0.22.147
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/esm/afb-runtime.js +61 -34
- package/lib/FormInstance.js +2 -0
- package/lib/rules/FunctionRuntime.js +44 -29
- package/lib/utils/Fetch.js +4 -1
- package/package.json +2 -2
package/esm/afb-runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, RequestSuccess,
|
|
1
|
+
import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, RequestSuccess, RequestFailure, SubmitError, Submit, Save, SubmitFailure, Focus, Valid, Invalid, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete } from './afb-events.js';
|
|
2
2
|
import Formula from '@adobe/json-formula';
|
|
3
3
|
import { parseDefaultDate, datetimeToNumber, format, parseDateSkeleton, numberToDatetime, formatDate, parseDate } from '@aemforms/af-formatters';
|
|
4
4
|
|
|
@@ -2797,6 +2797,9 @@ const request$1 = (url, data = null, options = {}) => {
|
|
|
2797
2797
|
body,
|
|
2798
2798
|
headers
|
|
2799
2799
|
};
|
|
2800
|
+
}).catch((error) => {
|
|
2801
|
+
console.error(`Network error while fetching from ${url}:`, error);
|
|
2802
|
+
throw error;
|
|
2800
2803
|
});
|
|
2801
2804
|
};
|
|
2802
2805
|
const defaultRequestOptions = {
|
|
@@ -2899,25 +2902,11 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
|
|
|
2899
2902
|
inputPayload = String(payload);
|
|
2900
2903
|
}
|
|
2901
2904
|
}
|
|
2902
|
-
const
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
};
|
|
2908
|
-
const targetField = context.$field || null;
|
|
2909
|
-
const targetEvent = context.$event || null;
|
|
2910
|
-
response.submitter = targetField;
|
|
2911
|
-
const enhancedPayload = {
|
|
2912
|
-
request: response.originalRequest,
|
|
2913
|
-
response,
|
|
2914
|
-
targetField,
|
|
2915
|
-
targetEvent
|
|
2916
|
-
};
|
|
2917
|
-
if (response?.status >= 200 && response?.status <= 299) {
|
|
2918
|
-
const eName = getCustomEventName(success);
|
|
2919
|
-
if (success === 'submitSuccess') {
|
|
2920
|
-
context.form.dispatch(new SubmitSuccess(response, true));
|
|
2905
|
+
const dispatchErrorEvents = (response, errorType, enhancedPayload) => {
|
|
2906
|
+
const eName = getCustomEventName(errorType);
|
|
2907
|
+
if (errorType === 'submitError') {
|
|
2908
|
+
context.form.dispatch(new SubmitError(response, true));
|
|
2909
|
+
context.form.dispatch(new SubmitFailure(response, true));
|
|
2921
2910
|
}
|
|
2922
2911
|
else {
|
|
2923
2912
|
if (context.field) {
|
|
@@ -2927,26 +2916,62 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
|
|
|
2927
2916
|
context.form.dispatch(new CustomEvent(eName, response, true));
|
|
2928
2917
|
}
|
|
2929
2918
|
}
|
|
2930
|
-
context.form.dispatch(new
|
|
2931
|
-
}
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2919
|
+
context.form.dispatch(new RequestFailure(enhancedPayload, false));
|
|
2920
|
+
};
|
|
2921
|
+
const targetField = context.$field || null;
|
|
2922
|
+
const baseEnhancedPayload = {
|
|
2923
|
+
request: { url: endpoint, method: httpVerb, ...encryptOutput },
|
|
2924
|
+
targetField: targetField,
|
|
2925
|
+
targetEvent: context.$event || null
|
|
2926
|
+
};
|
|
2927
|
+
try {
|
|
2928
|
+
const response = await request$1(endpoint, inputPayload, requestOptions);
|
|
2929
|
+
response.originalRequest = {
|
|
2930
|
+
url: endpoint,
|
|
2931
|
+
method: httpVerb,
|
|
2932
|
+
...encryptOutput
|
|
2933
|
+
};
|
|
2934
|
+
response.submitter = targetField;
|
|
2935
|
+
const enhancedPayload = {
|
|
2936
|
+
...baseEnhancedPayload,
|
|
2937
|
+
response,
|
|
2938
|
+
request: response.originalRequest
|
|
2939
|
+
};
|
|
2940
|
+
if (response?.status >= 200 && response?.status <= 299) {
|
|
2941
|
+
const eName = getCustomEventName(success);
|
|
2942
|
+
if (success === 'submitSuccess') {
|
|
2943
|
+
context.form.dispatch(new SubmitSuccess(response, true));
|
|
2942
2944
|
}
|
|
2943
2945
|
else {
|
|
2944
|
-
context.
|
|
2946
|
+
if (context.field) {
|
|
2947
|
+
context.field.dispatch(new CustomEvent(eName, response, true));
|
|
2948
|
+
}
|
|
2949
|
+
else {
|
|
2950
|
+
context.form.dispatch(new CustomEvent(eName, response, true));
|
|
2951
|
+
}
|
|
2945
2952
|
}
|
|
2953
|
+
context.form.dispatch(new RequestSuccess(enhancedPayload, false));
|
|
2954
|
+
}
|
|
2955
|
+
else {
|
|
2956
|
+
context.form.logger.error('Error invoking a rest API');
|
|
2957
|
+
dispatchErrorEvents(response, error, enhancedPayload);
|
|
2946
2958
|
}
|
|
2959
|
+
return response;
|
|
2960
|
+
}
|
|
2961
|
+
catch (error) {
|
|
2962
|
+
context.form.logger.error('Network error while invoking a rest API:', error);
|
|
2963
|
+
const networkErrorResponse = {
|
|
2964
|
+
body: null,
|
|
2965
|
+
headers: {},
|
|
2966
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2967
|
+
};
|
|
2968
|
+
const enhancedPayload = {
|
|
2969
|
+
...baseEnhancedPayload,
|
|
2970
|
+
response: networkErrorResponse
|
|
2971
|
+
};
|
|
2972
|
+
dispatchErrorEvents(networkErrorResponse, error, enhancedPayload);
|
|
2947
2973
|
context.form.dispatch(new RequestFailure(enhancedPayload, false));
|
|
2948
2974
|
}
|
|
2949
|
-
return response;
|
|
2950
2975
|
};
|
|
2951
2976
|
const urlEncoded = (data) => {
|
|
2952
2977
|
const formData = new URLSearchParams();
|
|
@@ -5567,6 +5592,8 @@ const fetchForm = (url, headers = {}) => {
|
|
|
5567
5592
|
}
|
|
5568
5593
|
resolve(jsonString(formObj));
|
|
5569
5594
|
}
|
|
5595
|
+
}).catch((error) => {
|
|
5596
|
+
reject(`Network error: ${error.message || error}`);
|
|
5570
5597
|
});
|
|
5571
5598
|
});
|
|
5572
5599
|
};
|
package/lib/FormInstance.js
CHANGED
|
@@ -85,21 +85,11 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
85
85
|
inputPayload = String(payload);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const enhancedPayload = {
|
|
94
|
-
request: response.originalRequest,
|
|
95
|
-
response,
|
|
96
|
-
targetField,
|
|
97
|
-
targetEvent
|
|
98
|
-
};
|
|
99
|
-
if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) <= 299) {
|
|
100
|
-
const eName = getCustomEventName(success);
|
|
101
|
-
if (success === 'submitSuccess') {
|
|
102
|
-
context.form.dispatch(new Events_1.SubmitSuccess(response, true));
|
|
88
|
+
const dispatchErrorEvents = (response, errorType, enhancedPayload) => {
|
|
89
|
+
const eName = getCustomEventName(errorType);
|
|
90
|
+
if (errorType === 'submitError') {
|
|
91
|
+
context.form.dispatch(new Events_1.SubmitError(response, true));
|
|
92
|
+
context.form.dispatch(new Events_1.SubmitFailure(response, true));
|
|
103
93
|
}
|
|
104
94
|
else {
|
|
105
95
|
if (context.field) {
|
|
@@ -109,26 +99,51 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
109
99
|
context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
|
|
110
100
|
}
|
|
111
101
|
}
|
|
112
|
-
context.form.dispatch(new Events_1.
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
102
|
+
context.form.dispatch(new Events_1.RequestFailure(enhancedPayload, false));
|
|
103
|
+
};
|
|
104
|
+
const targetField = context.$field || null;
|
|
105
|
+
const baseEnhancedPayload = {
|
|
106
|
+
request: Object.assign({ url: endpoint, method: httpVerb }, encryptOutput),
|
|
107
|
+
targetField: targetField,
|
|
108
|
+
targetEvent: context.$event || null
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
const response = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
|
|
112
|
+
response.originalRequest = Object.assign({ url: endpoint, method: httpVerb }, encryptOutput);
|
|
113
|
+
response.submitter = targetField;
|
|
114
|
+
const enhancedPayload = Object.assign(Object.assign({}, baseEnhancedPayload), { response, request: response.originalRequest });
|
|
115
|
+
if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) <= 299) {
|
|
116
|
+
const eName = getCustomEventName(success);
|
|
117
|
+
if (success === 'submitSuccess') {
|
|
118
|
+
context.form.dispatch(new Events_1.SubmitSuccess(response, true));
|
|
124
119
|
}
|
|
125
120
|
else {
|
|
126
|
-
context.
|
|
121
|
+
if (context.field) {
|
|
122
|
+
context.field.dispatch(new Events_1.CustomEvent(eName, response, true));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
|
|
126
|
+
}
|
|
127
127
|
}
|
|
128
|
+
context.form.dispatch(new Events_1.RequestSuccess(enhancedPayload, false));
|
|
128
129
|
}
|
|
130
|
+
else {
|
|
131
|
+
context.form.logger.error('Error invoking a rest API');
|
|
132
|
+
dispatchErrorEvents(response, error, enhancedPayload);
|
|
133
|
+
}
|
|
134
|
+
return response;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
context.form.logger.error('Network error while invoking a rest API:', error);
|
|
138
|
+
const networkErrorResponse = {
|
|
139
|
+
body: null,
|
|
140
|
+
headers: {},
|
|
141
|
+
error: error instanceof Error ? error.message : String(error)
|
|
142
|
+
};
|
|
143
|
+
const enhancedPayload = Object.assign(Object.assign({}, baseEnhancedPayload), { response: networkErrorResponse });
|
|
144
|
+
dispatchErrorEvents(networkErrorResponse, error, enhancedPayload);
|
|
129
145
|
context.form.dispatch(new Events_1.RequestFailure(enhancedPayload, false));
|
|
130
146
|
}
|
|
131
|
-
return response;
|
|
132
147
|
});
|
|
133
148
|
exports.request = request;
|
|
134
149
|
const urlEncoded = (data) => {
|
package/lib/utils/Fetch.js
CHANGED
|
@@ -37,7 +37,10 @@ const request = (url, data = null, options = {}) => {
|
|
|
37
37
|
body,
|
|
38
38
|
headers
|
|
39
39
|
};
|
|
40
|
-
}))
|
|
40
|
+
})).catch((error) => {
|
|
41
|
+
console.error(`Network error while fetching from ${url}:`, error);
|
|
42
|
+
throw error;
|
|
43
|
+
});
|
|
41
44
|
};
|
|
42
45
|
exports.request = request;
|
|
43
46
|
const defaultRequestOptions = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.147",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@adobe/json-formula": "0.1.50",
|
|
40
|
-
"@aemforms/af-formatters": "^0.22.
|
|
40
|
+
"@aemforms/af-formatters": "^0.22.147"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|