@aemforms/af-core 0.22.116 → 0.22.117

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.
@@ -2656,6 +2656,22 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2656
2656
  method: httpVerb
2657
2657
  };
2658
2658
  let inputPayload;
2659
+ let encryptOutput = {};
2660
+ try {
2661
+ if (payload instanceof Promise) {
2662
+ payload = await payload;
2663
+ }
2664
+ }
2665
+ catch (error) {
2666
+ console.error('Error resolving payload Promise:', error);
2667
+ throw error;
2668
+ }
2669
+ if (payload.body && payload.headers) {
2670
+ encryptOutput = { ...payload };
2671
+ headers = { ...payload.headers };
2672
+ payload = payload.body;
2673
+ inputPayload = payload;
2674
+ }
2659
2675
  if (payload && payload instanceof FileObject && payload.data instanceof File) {
2660
2676
  const formData = new FormData();
2661
2677
  formData.append(payload.name, payload.data);
@@ -2664,7 +2680,7 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2664
2680
  else if (payload instanceof FormData) {
2665
2681
  inputPayload = payload;
2666
2682
  }
2667
- else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
2683
+ else if (payload && (typeof payload === 'string' || (typeof payload === 'object' && Object.keys(payload).length > 0))) {
2668
2684
  const headerNames = Object.keys(headers);
2669
2685
  if (headerNames.length > 0) {
2670
2686
  requestOptions.headers = {
@@ -2676,35 +2692,45 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2676
2692
  requestOptions.headers = { 'Content-Type': 'application/json' };
2677
2693
  }
2678
2694
  const contentType = requestOptions?.headers?.['Content-Type'] || 'application/json';
2679
- if (contentType === 'application/json') {
2680
- inputPayload = JSON.stringify(payload);
2681
- }
2682
- else if (contentType.indexOf('multipart/form-data') > -1) {
2683
- inputPayload = multipartFormData(payload);
2695
+ if (typeof payload === 'object') {
2696
+ if (contentType === 'application/json') {
2697
+ inputPayload = JSON.stringify(payload);
2698
+ }
2699
+ else if (contentType.indexOf('multipart/form-data') > -1) {
2700
+ inputPayload = multipartFormData(payload);
2701
+ }
2702
+ else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
2703
+ inputPayload = urlEncoded(payload);
2704
+ }
2684
2705
  }
2685
- else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
2686
- inputPayload = urlEncoded(payload);
2706
+ if (contentType === 'text/plain') {
2707
+ inputPayload = String(payload);
2687
2708
  }
2688
2709
  }
2689
- const result = await request$1(endpoint, inputPayload, requestOptions);
2690
- if (result?.status >= 200 && result?.status <= 299) {
2710
+ const response = await request$1(endpoint, inputPayload, requestOptions);
2711
+ response.originalRequest = {
2712
+ url: endpoint,
2713
+ method: httpVerb,
2714
+ ...encryptOutput
2715
+ };
2716
+ if (response?.status >= 200 && response?.status <= 299) {
2691
2717
  const eName = getCustomEventName(success);
2692
2718
  if (success === 'submitSuccess') {
2693
- context.form.dispatch(new SubmitSuccess(result, true));
2719
+ context.form.dispatch(new SubmitSuccess(response, true));
2694
2720
  }
2695
2721
  else {
2696
- context.form.dispatch(new CustomEvent(eName, result, true));
2722
+ context.form.dispatch(new CustomEvent(eName, response, true));
2697
2723
  }
2698
2724
  }
2699
2725
  else {
2700
2726
  context.form.logger.error('Error invoking a rest API');
2701
2727
  const eName = getCustomEventName(error);
2702
2728
  if (error === 'submitError') {
2703
- context.form.dispatch(new SubmitError(result, true));
2704
- context.form.dispatch(new SubmitFailure(result, true));
2729
+ context.form.dispatch(new SubmitError(response, true));
2730
+ context.form.dispatch(new SubmitFailure(response, true));
2705
2731
  }
2706
2732
  else {
2707
- context.form.dispatch(new CustomEvent(eName, result, true));
2733
+ context.form.dispatch(new CustomEvent(eName, response, true));
2708
2734
  }
2709
2735
  }
2710
2736
  };
@@ -3061,17 +3087,29 @@ class FunctionRuntimeImpl {
3061
3087
  _func: (args, data, interpreter) => {
3062
3088
  const uri = toString(args[0]);
3063
3089
  const httpVerb = toString(args[1]);
3064
- const payload = valueOf(args[2]);
3065
- let success, error, headers = {};
3066
- if (typeof (args[3]) === 'string') {
3067
- interpreter.globals.form.logger.warn('This usage of request is deprecated. Please see the documentation and update');
3090
+ let payload;
3091
+ let success;
3092
+ let error;
3093
+ let headers = {};
3094
+ if (args[2] && typeof args[2] === 'object' && !args[2].then && ('data' in args[2] || 'headers' in args[2])) {
3095
+ const payloadObj = valueOf(args[2]);
3096
+ payload = payloadObj.data;
3097
+ headers = payloadObj.headers || {};
3068
3098
  success = valueOf(args[3]);
3069
3099
  error = valueOf(args[4]);
3070
3100
  }
3071
3101
  else {
3072
- headers = valueOf(args[3]);
3073
- success = valueOf(args[4]);
3074
- error = valueOf(args[5]);
3102
+ payload = valueOf(args[2]);
3103
+ if (typeof (args[3]) === 'string') {
3104
+ interpreter.globals.form.logger.warn('This usage of request is deprecated. Please see the documentation and update');
3105
+ success = valueOf(args[3]);
3106
+ error = valueOf(args[4]);
3107
+ }
3108
+ else {
3109
+ headers = valueOf(args[3]);
3110
+ success = valueOf(args[4]);
3111
+ error = valueOf(args[5]);
3112
+ }
3075
3113
  }
3076
3114
  return request(interpreter.globals, uri, httpVerb, payload, success, error, headers);
3077
3115
  },
@@ -3168,6 +3206,20 @@ class FunctionRuntimeImpl {
3168
3206
  return {};
3169
3207
  },
3170
3208
  _signature: []
3209
+ },
3210
+ encrypt: {
3211
+ _func: async (args, data, interpreter) => {
3212
+ const payload = valueOf(args[0]);
3213
+ return payload;
3214
+ },
3215
+ _signature: []
3216
+ },
3217
+ decrypt: {
3218
+ _func: async (args, data, interpreter) => {
3219
+ const encData = valueOf(args[0]);
3220
+ return encData;
3221
+ },
3222
+ _signature: []
3171
3223
  }
3172
3224
  };
3173
3225
  return { ...defaultFunctions, ...FunctionRuntimeImpl.getInstance().customFunctions };
@@ -64,6 +64,14 @@ declare class FunctionRuntimeImpl {
64
64
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
65
65
  _signature: never[];
66
66
  };
67
+ encrypt: {
68
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<any>;
69
+ _signature: never[];
70
+ };
71
+ decrypt: {
72
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<any>;
73
+ _signature: never[];
74
+ };
67
75
  };
68
76
  }
69
77
  export declare const FunctionRuntime: FunctionRuntimeImpl;
@@ -64,6 +64,14 @@ declare class FunctionRuntimeImpl {
64
64
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
65
65
  _signature: never[];
66
66
  };
67
+ encrypt: {
68
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<any>;
69
+ _signature: never[];
70
+ };
71
+ decrypt: {
72
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<any>;
73
+ _signature: never[];
74
+ };
67
75
  };
68
76
  }
69
77
  export declare const FunctionRuntime: FunctionRuntimeImpl;
@@ -30,6 +30,22 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
30
30
  method: httpVerb
31
31
  };
32
32
  let inputPayload;
33
+ let encryptOutput = {};
34
+ try {
35
+ if (payload instanceof Promise) {
36
+ payload = yield payload;
37
+ }
38
+ }
39
+ catch (error) {
40
+ console.error('Error resolving payload Promise:', error);
41
+ throw error;
42
+ }
43
+ if (payload.body && payload.headers) {
44
+ encryptOutput = Object.assign({}, payload);
45
+ headers = Object.assign({}, payload.headers);
46
+ payload = payload.body;
47
+ inputPayload = payload;
48
+ }
33
49
  if (payload && payload instanceof FileObject_1.FileObject && payload.data instanceof File) {
34
50
  const formData = new FormData();
35
51
  formData.append(payload.name, payload.data);
@@ -38,7 +54,7 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
38
54
  else if (payload instanceof FormData) {
39
55
  inputPayload = payload;
40
56
  }
41
- else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
57
+ else if (payload && (typeof payload === 'string' || (typeof payload === 'object' && Object.keys(payload).length > 0))) {
42
58
  const headerNames = Object.keys(headers);
43
59
  if (headerNames.length > 0) {
44
60
  requestOptions.headers = Object.assign(Object.assign({}, headers), (headerNames.indexOf('Content-Type') === -1 ? { 'Content-Type': 'application/json' } : {}));
@@ -47,35 +63,41 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
47
63
  requestOptions.headers = { 'Content-Type': 'application/json' };
48
64
  }
49
65
  const contentType = ((_a = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) || 'application/json';
50
- if (contentType === 'application/json') {
51
- inputPayload = JSON.stringify(payload);
52
- }
53
- else if (contentType.indexOf('multipart/form-data') > -1) {
54
- inputPayload = multipartFormData(payload);
66
+ if (typeof payload === 'object') {
67
+ if (contentType === 'application/json') {
68
+ inputPayload = JSON.stringify(payload);
69
+ }
70
+ else if (contentType.indexOf('multipart/form-data') > -1) {
71
+ inputPayload = multipartFormData(payload);
72
+ }
73
+ else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
74
+ inputPayload = urlEncoded(payload);
75
+ }
55
76
  }
56
- else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
57
- inputPayload = urlEncoded(payload);
77
+ if (contentType === 'text/plain') {
78
+ inputPayload = String(payload);
58
79
  }
59
80
  }
60
- const result = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
61
- if ((result === null || result === void 0 ? void 0 : result.status) >= 200 && (result === null || result === void 0 ? void 0 : result.status) <= 299) {
81
+ const response = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
82
+ response.originalRequest = Object.assign({ url: endpoint, method: httpVerb }, encryptOutput);
83
+ if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) <= 299) {
62
84
  const eName = getCustomEventName(success);
63
85
  if (success === 'submitSuccess') {
64
- context.form.dispatch(new Events_1.SubmitSuccess(result, true));
86
+ context.form.dispatch(new Events_1.SubmitSuccess(response, true));
65
87
  }
66
88
  else {
67
- context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
89
+ context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
68
90
  }
69
91
  }
70
92
  else {
71
93
  context.form.logger.error('Error invoking a rest API');
72
94
  const eName = getCustomEventName(error);
73
95
  if (error === 'submitError') {
74
- context.form.dispatch(new Events_1.SubmitError(result, true));
75
- context.form.dispatch(new Events_1.SubmitFailure(result, true));
96
+ context.form.dispatch(new Events_1.SubmitError(response, true));
97
+ context.form.dispatch(new Events_1.SubmitFailure(response, true));
76
98
  }
77
99
  else {
78
- context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
100
+ context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
79
101
  }
80
102
  }
81
103
  });
@@ -435,17 +457,29 @@ class FunctionRuntimeImpl {
435
457
  _func: (args, data, interpreter) => {
436
458
  const uri = toString(args[0]);
437
459
  const httpVerb = toString(args[1]);
438
- const payload = valueOf(args[2]);
439
- let success, error, headers = {};
440
- if (typeof (args[3]) === 'string') {
441
- interpreter.globals.form.logger.warn('This usage of request is deprecated. Please see the documentation and update');
460
+ let payload;
461
+ let success;
462
+ let error;
463
+ let headers = {};
464
+ if (args[2] && typeof args[2] === 'object' && !args[2].then && ('data' in args[2] || 'headers' in args[2])) {
465
+ const payloadObj = valueOf(args[2]);
466
+ payload = payloadObj.data;
467
+ headers = payloadObj.headers || {};
442
468
  success = valueOf(args[3]);
443
469
  error = valueOf(args[4]);
444
470
  }
445
471
  else {
446
- headers = valueOf(args[3]);
447
- success = valueOf(args[4]);
448
- error = valueOf(args[5]);
472
+ payload = valueOf(args[2]);
473
+ if (typeof (args[3]) === 'string') {
474
+ interpreter.globals.form.logger.warn('This usage of request is deprecated. Please see the documentation and update');
475
+ success = valueOf(args[3]);
476
+ error = valueOf(args[4]);
477
+ }
478
+ else {
479
+ headers = valueOf(args[3]);
480
+ success = valueOf(args[4]);
481
+ error = valueOf(args[5]);
482
+ }
449
483
  }
450
484
  return (0, exports.request)(interpreter.globals, uri, httpVerb, payload, success, error, headers);
451
485
  },
@@ -542,6 +576,20 @@ class FunctionRuntimeImpl {
542
576
  return {};
543
577
  },
544
578
  _signature: []
579
+ },
580
+ encrypt: {
581
+ _func: (args, data, interpreter) => __awaiter(this, void 0, void 0, function* () {
582
+ const payload = valueOf(args[0]);
583
+ return payload;
584
+ }),
585
+ _signature: []
586
+ },
587
+ decrypt: {
588
+ _func: (args, data, interpreter) => __awaiter(this, void 0, void 0, function* () {
589
+ const encData = valueOf(args[0]);
590
+ return encData;
591
+ }),
592
+ _signature: []
545
593
  }
546
594
  };
547
595
  return Object.assign(Object.assign({}, defaultFunctions), FunctionRuntimeImpl.getInstance().customFunctions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.116",
3
+ "version": "0.22.117",
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.116"
40
+ "@aemforms/af-formatters": "^0.22.117"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",