@aemforms/af-core 0.22.115 → 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.
@@ -2050,6 +2050,7 @@ class Container extends Scriptable {
2050
2050
  return {
2051
2051
  ...super.getState(forRestore),
2052
2052
  ...(forRestore ? {
2053
+ initialItems: this.items.length,
2053
2054
  ':items': undefined,
2054
2055
  ':itemsOrder': undefined
2055
2056
  } : {}),
@@ -2655,6 +2656,22 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2655
2656
  method: httpVerb
2656
2657
  };
2657
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
+ }
2658
2675
  if (payload && payload instanceof FileObject && payload.data instanceof File) {
2659
2676
  const formData = new FormData();
2660
2677
  formData.append(payload.name, payload.data);
@@ -2663,7 +2680,7 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2663
2680
  else if (payload instanceof FormData) {
2664
2681
  inputPayload = payload;
2665
2682
  }
2666
- 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))) {
2667
2684
  const headerNames = Object.keys(headers);
2668
2685
  if (headerNames.length > 0) {
2669
2686
  requestOptions.headers = {
@@ -2675,35 +2692,45 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2675
2692
  requestOptions.headers = { 'Content-Type': 'application/json' };
2676
2693
  }
2677
2694
  const contentType = requestOptions?.headers?.['Content-Type'] || 'application/json';
2678
- if (contentType === 'application/json') {
2679
- inputPayload = JSON.stringify(payload);
2680
- }
2681
- else if (contentType.indexOf('multipart/form-data') > -1) {
2682
- 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
+ }
2683
2705
  }
2684
- else if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
2685
- inputPayload = urlEncoded(payload);
2706
+ if (contentType === 'text/plain') {
2707
+ inputPayload = String(payload);
2686
2708
  }
2687
2709
  }
2688
- const result = await request$1(endpoint, inputPayload, requestOptions);
2689
- 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) {
2690
2717
  const eName = getCustomEventName(success);
2691
2718
  if (success === 'submitSuccess') {
2692
- context.form.dispatch(new SubmitSuccess(result, true));
2719
+ context.form.dispatch(new SubmitSuccess(response, true));
2693
2720
  }
2694
2721
  else {
2695
- context.form.dispatch(new CustomEvent(eName, result, true));
2722
+ context.form.dispatch(new CustomEvent(eName, response, true));
2696
2723
  }
2697
2724
  }
2698
2725
  else {
2699
2726
  context.form.logger.error('Error invoking a rest API');
2700
2727
  const eName = getCustomEventName(error);
2701
2728
  if (error === 'submitError') {
2702
- context.form.dispatch(new SubmitError(result, true));
2703
- context.form.dispatch(new SubmitFailure(result, true));
2729
+ context.form.dispatch(new SubmitError(response, true));
2730
+ context.form.dispatch(new SubmitFailure(response, true));
2704
2731
  }
2705
2732
  else {
2706
- context.form.dispatch(new CustomEvent(eName, result, true));
2733
+ context.form.dispatch(new CustomEvent(eName, response, true));
2707
2734
  }
2708
2735
  }
2709
2736
  };
@@ -3060,17 +3087,29 @@ class FunctionRuntimeImpl {
3060
3087
  _func: (args, data, interpreter) => {
3061
3088
  const uri = toString(args[0]);
3062
3089
  const httpVerb = toString(args[1]);
3063
- const payload = valueOf(args[2]);
3064
- let success, error, headers = {};
3065
- if (typeof (args[3]) === 'string') {
3066
- 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 || {};
3067
3098
  success = valueOf(args[3]);
3068
3099
  error = valueOf(args[4]);
3069
3100
  }
3070
3101
  else {
3071
- headers = valueOf(args[3]);
3072
- success = valueOf(args[4]);
3073
- 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
+ }
3074
3113
  }
3075
3114
  return request(interpreter.globals, uri, httpVerb, payload, success, error, headers);
3076
3115
  },
@@ -3167,6 +3206,20 @@ class FunctionRuntimeImpl {
3167
3206
  return {};
3168
3207
  },
3169
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: []
3170
3223
  }
3171
3224
  };
3172
3225
  return { ...defaultFunctions, ...FunctionRuntimeImpl.getInstance().customFunctions };
@@ -32,6 +32,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
32
32
  items: any[];
33
33
  enabled: boolean | undefined;
34
34
  readOnly: any;
35
+ initialItems?: number | undefined;
35
36
  ':items'?: undefined;
36
37
  ':itemsOrder'?: undefined;
37
38
  _dependents?: string[] | undefined;
@@ -100,6 +100,7 @@ declare class Form extends Container<FormJson> implements FormModel {
100
100
  items: any[];
101
101
  enabled: boolean | undefined;
102
102
  readOnly: any;
103
+ initialItems?: number | undefined;
103
104
  ':items'?: undefined;
104
105
  ':itemsOrder'?: undefined;
105
106
  _dependents?: string[] | undefined;
@@ -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;
@@ -32,6 +32,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
32
32
  items: any[];
33
33
  enabled: boolean | undefined;
34
34
  readOnly: any;
35
+ initialItems?: number | undefined;
35
36
  ':items'?: undefined;
36
37
  ':itemsOrder'?: undefined;
37
38
  _dependents?: string[] | undefined;
package/lib/Container.js CHANGED
@@ -114,6 +114,7 @@ class Container extends Scriptable_1.default {
114
114
  }
115
115
  getState(isRepeatableChild = false, forRestore = false) {
116
116
  return Object.assign(Object.assign(Object.assign({}, super.getState(forRestore)), (forRestore ? {
117
+ initialItems: this.items.length,
117
118
  ':items': undefined,
118
119
  ':itemsOrder': undefined
119
120
  } : {})), { items: this.getItemsState(isRepeatableChild, forRestore), enabled: this.enabled, readOnly: this.readOnly });
package/lib/Form.d.ts CHANGED
@@ -100,6 +100,7 @@ declare class Form extends Container<FormJson> implements FormModel {
100
100
  items: any[];
101
101
  enabled: boolean | undefined;
102
102
  readOnly: any;
103
+ initialItems?: number | undefined;
103
104
  ':items'?: undefined;
104
105
  ':itemsOrder'?: undefined;
105
106
  _dependents?: string[] | undefined;
@@ -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.115",
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.115"
40
+ "@aemforms/af-formatters": "^0.22.117"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",