@aemforms/af-core 0.22.122 → 0.22.123
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
CHANGED
|
@@ -2413,7 +2413,7 @@ class Container extends Scriptable {
|
|
|
2413
2413
|
for (const change of action.payload.changes) {
|
|
2414
2414
|
if (change.propertyName !== undefined && notifyChildrenAttributes.includes(change.propertyName)) {
|
|
2415
2415
|
this.items.forEach((child) => {
|
|
2416
|
-
if (change.currentValue !== child.
|
|
2416
|
+
if (change.currentValue !== child._jsonModel[change.propertyName]) {
|
|
2417
2417
|
child._jsonModel[change.propertyName] = change.currentValue;
|
|
2418
2418
|
this.notifyDependents.call(child, propertyChange(change.propertyName, child.getState()[change.propertyName], null));
|
|
2419
2419
|
}
|
|
@@ -2722,6 +2722,14 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
|
|
|
2722
2722
|
method: httpVerb,
|
|
2723
2723
|
...encryptOutput
|
|
2724
2724
|
};
|
|
2725
|
+
const targetField = context.$field || null;
|
|
2726
|
+
const targetEvent = context.$event || null;
|
|
2727
|
+
const enhancedPayload = {
|
|
2728
|
+
request: response.originalRequest,
|
|
2729
|
+
response,
|
|
2730
|
+
targetField,
|
|
2731
|
+
targetEvent
|
|
2732
|
+
};
|
|
2725
2733
|
if (response?.status >= 200 && response?.status <= 299) {
|
|
2726
2734
|
const eName = getCustomEventName(success);
|
|
2727
2735
|
if (success === 'submitSuccess') {
|
|
@@ -2730,7 +2738,7 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
|
|
|
2730
2738
|
else {
|
|
2731
2739
|
context.form.dispatch(new CustomEvent(eName, response, true));
|
|
2732
2740
|
}
|
|
2733
|
-
context.form.dispatch(new RequestSuccess(
|
|
2741
|
+
context.form.dispatch(new RequestSuccess(enhancedPayload, false));
|
|
2734
2742
|
}
|
|
2735
2743
|
else {
|
|
2736
2744
|
context.form.logger.error('Error invoking a rest API');
|
|
@@ -2742,8 +2750,9 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
|
|
|
2742
2750
|
else {
|
|
2743
2751
|
context.form.dispatch(new CustomEvent(eName, response, true));
|
|
2744
2752
|
}
|
|
2745
|
-
context.form.dispatch(new RequestFailure(
|
|
2753
|
+
context.form.dispatch(new RequestFailure(enhancedPayload, false));
|
|
2746
2754
|
}
|
|
2755
|
+
return response;
|
|
2747
2756
|
};
|
|
2748
2757
|
const urlEncoded = (data) => {
|
|
2749
2758
|
const formData = new URLSearchParams();
|
|
@@ -3128,6 +3137,65 @@ class FunctionRuntimeImpl {
|
|
|
3128
3137
|
},
|
|
3129
3138
|
_signature: []
|
|
3130
3139
|
},
|
|
3140
|
+
requestWithRetry: {
|
|
3141
|
+
_func: (args, data, interpreter) => {
|
|
3142
|
+
const uri = toString(args[0]);
|
|
3143
|
+
const httpVerb = toString(args[1]);
|
|
3144
|
+
let success;
|
|
3145
|
+
let errorFn;
|
|
3146
|
+
let payload = valueOf(args[2]);
|
|
3147
|
+
if (typeof (args[3]) === 'string') {
|
|
3148
|
+
success = valueOf(args[3]);
|
|
3149
|
+
errorFn = valueOf(args[4]);
|
|
3150
|
+
}
|
|
3151
|
+
return async (retryOptions) => {
|
|
3152
|
+
try {
|
|
3153
|
+
if (payload instanceof Promise) {
|
|
3154
|
+
payload = await payload;
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
catch (error) {
|
|
3158
|
+
console.error('Error resolving payload Promise:', error);
|
|
3159
|
+
throw error;
|
|
3160
|
+
}
|
|
3161
|
+
let finalHeaders = payload.headers || {};
|
|
3162
|
+
let finalBody = payload.body || {};
|
|
3163
|
+
if (retryOptions) {
|
|
3164
|
+
if (retryOptions.body) {
|
|
3165
|
+
finalBody = {
|
|
3166
|
+
...finalBody,
|
|
3167
|
+
...retryOptions.body
|
|
3168
|
+
};
|
|
3169
|
+
}
|
|
3170
|
+
if (retryOptions.headers) {
|
|
3171
|
+
finalHeaders = {
|
|
3172
|
+
...finalHeaders,
|
|
3173
|
+
...retryOptions.headers
|
|
3174
|
+
};
|
|
3175
|
+
}
|
|
3176
|
+
}
|
|
3177
|
+
const finalPayload = { 'body': finalBody, 'headers': finalHeaders };
|
|
3178
|
+
try {
|
|
3179
|
+
const response = await request(interpreter.globals, uri, httpVerb, finalPayload, success, errorFn, finalHeaders);
|
|
3180
|
+
return response;
|
|
3181
|
+
}
|
|
3182
|
+
catch (error) {
|
|
3183
|
+
if (error && typeof error === 'object' && 'status' in error && error.status >= 400) {
|
|
3184
|
+
throw error;
|
|
3185
|
+
}
|
|
3186
|
+
throw new Error('Request failed');
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
3189
|
+
},
|
|
3190
|
+
_signature: []
|
|
3191
|
+
},
|
|
3192
|
+
retryHandler: {
|
|
3193
|
+
_func: (args, data, interpreter) => {
|
|
3194
|
+
const requestFn = valueOf(args[0]);
|
|
3195
|
+
return requestFn();
|
|
3196
|
+
},
|
|
3197
|
+
_signature: []
|
|
3198
|
+
},
|
|
3131
3199
|
awaitFn: {
|
|
3132
3200
|
_func: async (args, data, interpreter) => {
|
|
3133
3201
|
const success = args[1];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type HTTP_VERB = 'GET' | 'POST';
|
|
2
|
-
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<
|
|
2
|
+
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<any>;
|
|
3
3
|
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded', input_data?: any, action?: string, metadata?: any) => Promise<void>;
|
|
4
4
|
export type CustomFunction = Function;
|
|
5
5
|
export type FunctionDefinition = {
|
|
@@ -45,7 +45,18 @@ declare class FunctionRuntimeImpl {
|
|
|
45
45
|
_signature: never[];
|
|
46
46
|
};
|
|
47
47
|
request: {
|
|
48
|
-
_func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<
|
|
48
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<any>;
|
|
49
|
+
_signature: never[];
|
|
50
|
+
};
|
|
51
|
+
requestWithRetry: {
|
|
52
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => (retryOptions?: {
|
|
53
|
+
headers?: Record<string, string>;
|
|
54
|
+
body?: any;
|
|
55
|
+
}) => Promise<any>;
|
|
56
|
+
_signature: never[];
|
|
57
|
+
};
|
|
58
|
+
retryHandler: {
|
|
59
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
|
|
49
60
|
_signature: never[];
|
|
50
61
|
};
|
|
51
62
|
awaitFn: {
|
package/lib/Container.js
CHANGED
|
@@ -463,7 +463,7 @@ class Container extends Scriptable_1.default {
|
|
|
463
463
|
for (const change of action.payload.changes) {
|
|
464
464
|
if (change.propertyName !== undefined && notifyChildrenAttributes.includes(change.propertyName)) {
|
|
465
465
|
this.items.forEach((child) => {
|
|
466
|
-
if (change.currentValue !== child.
|
|
466
|
+
if (change.currentValue !== child._jsonModel[change.propertyName]) {
|
|
467
467
|
child._jsonModel[change.propertyName] = change.currentValue;
|
|
468
468
|
this.notifyDependents.call(child, (0, Events_1.propertyChange)(change.propertyName, child.getState()[change.propertyName], null));
|
|
469
469
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare type HTTP_VERB = 'GET' | 'POST';
|
|
2
|
-
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<
|
|
2
|
+
export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, headers: any) => Promise<any>;
|
|
3
3
|
export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded', input_data?: any, action?: string, metadata?: any) => Promise<void>;
|
|
4
4
|
export declare type CustomFunction = Function;
|
|
5
5
|
export declare type FunctionDefinition = {
|
|
@@ -45,7 +45,18 @@ declare class FunctionRuntimeImpl {
|
|
|
45
45
|
_signature: never[];
|
|
46
46
|
};
|
|
47
47
|
request: {
|
|
48
|
-
_func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<
|
|
48
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<any>;
|
|
49
|
+
_signature: never[];
|
|
50
|
+
};
|
|
51
|
+
requestWithRetry: {
|
|
52
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => (retryOptions?: {
|
|
53
|
+
headers?: Record<string, string>;
|
|
54
|
+
body?: any;
|
|
55
|
+
}) => Promise<any>;
|
|
56
|
+
_signature: never[];
|
|
57
|
+
};
|
|
58
|
+
retryHandler: {
|
|
59
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
|
|
49
60
|
_signature: never[];
|
|
50
61
|
};
|
|
51
62
|
awaitFn: {
|
|
@@ -80,6 +80,14 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
80
80
|
}
|
|
81
81
|
const response = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
|
|
82
82
|
response.originalRequest = Object.assign({ url: endpoint, method: httpVerb }, encryptOutput);
|
|
83
|
+
const targetField = context.$field || null;
|
|
84
|
+
const targetEvent = context.$event || null;
|
|
85
|
+
const enhancedPayload = {
|
|
86
|
+
request: response.originalRequest,
|
|
87
|
+
response,
|
|
88
|
+
targetField,
|
|
89
|
+
targetEvent
|
|
90
|
+
};
|
|
83
91
|
if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) <= 299) {
|
|
84
92
|
const eName = getCustomEventName(success);
|
|
85
93
|
if (success === 'submitSuccess') {
|
|
@@ -88,7 +96,7 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
88
96
|
else {
|
|
89
97
|
context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
|
|
90
98
|
}
|
|
91
|
-
context.form.dispatch(new Events_1.RequestSuccess(
|
|
99
|
+
context.form.dispatch(new Events_1.RequestSuccess(enhancedPayload, false));
|
|
92
100
|
}
|
|
93
101
|
else {
|
|
94
102
|
context.form.logger.error('Error invoking a rest API');
|
|
@@ -100,8 +108,9 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
100
108
|
else {
|
|
101
109
|
context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
|
|
102
110
|
}
|
|
103
|
-
context.form.dispatch(new Events_1.RequestFailure(
|
|
111
|
+
context.form.dispatch(new Events_1.RequestFailure(enhancedPayload, false));
|
|
104
112
|
}
|
|
113
|
+
return response;
|
|
105
114
|
});
|
|
106
115
|
exports.request = request;
|
|
107
116
|
const urlEncoded = (data) => {
|
|
@@ -489,6 +498,59 @@ class FunctionRuntimeImpl {
|
|
|
489
498
|
},
|
|
490
499
|
_signature: []
|
|
491
500
|
},
|
|
501
|
+
requestWithRetry: {
|
|
502
|
+
_func: (args, data, interpreter) => {
|
|
503
|
+
const uri = toString(args[0]);
|
|
504
|
+
const httpVerb = toString(args[1]);
|
|
505
|
+
let success;
|
|
506
|
+
let errorFn;
|
|
507
|
+
let payload = valueOf(args[2]);
|
|
508
|
+
if (typeof (args[3]) === 'string') {
|
|
509
|
+
success = valueOf(args[3]);
|
|
510
|
+
errorFn = valueOf(args[4]);
|
|
511
|
+
}
|
|
512
|
+
return (retryOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
513
|
+
try {
|
|
514
|
+
if (payload instanceof Promise) {
|
|
515
|
+
payload = yield payload;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
console.error('Error resolving payload Promise:', error);
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
let finalHeaders = payload.headers || {};
|
|
523
|
+
let finalBody = payload.body || {};
|
|
524
|
+
if (retryOptions) {
|
|
525
|
+
if (retryOptions.body) {
|
|
526
|
+
finalBody = Object.assign(Object.assign({}, finalBody), retryOptions.body);
|
|
527
|
+
}
|
|
528
|
+
if (retryOptions.headers) {
|
|
529
|
+
finalHeaders = Object.assign(Object.assign({}, finalHeaders), retryOptions.headers);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
const finalPayload = { 'body': finalBody, 'headers': finalHeaders };
|
|
533
|
+
try {
|
|
534
|
+
const response = yield (0, exports.request)(interpreter.globals, uri, httpVerb, finalPayload, success, errorFn, finalHeaders);
|
|
535
|
+
return response;
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
if (error && typeof error === 'object' && 'status' in error && error.status >= 400) {
|
|
539
|
+
throw error;
|
|
540
|
+
}
|
|
541
|
+
throw new Error('Request failed');
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
},
|
|
545
|
+
_signature: []
|
|
546
|
+
},
|
|
547
|
+
retryHandler: {
|
|
548
|
+
_func: (args, data, interpreter) => {
|
|
549
|
+
const requestFn = valueOf(args[0]);
|
|
550
|
+
return requestFn();
|
|
551
|
+
},
|
|
552
|
+
_signature: []
|
|
553
|
+
},
|
|
492
554
|
awaitFn: {
|
|
493
555
|
_func: (args, data, interpreter) => __awaiter(this, void 0, void 0, function* () {
|
|
494
556
|
const success = args[1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.123",
|
|
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.123"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|