@aemforms/af-core 0.22.145 → 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.
@@ -1,4 +1,4 @@
1
- import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, RequestSuccess, SubmitError, SubmitFailure, RequestFailure, Submit, Save, Focus, Valid, Invalid, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete } from './afb-events.js';
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
 
@@ -1606,7 +1606,14 @@ class BaseNode {
1606
1606
  };
1607
1607
  }
1608
1608
  _addDependent(dependent, propertyName) {
1609
- if (this._dependents.find(({ node }) => node === dependent) === undefined) {
1609
+ const existingDependency = this._dependents.find(({ node, propertyName: existingProp }) => {
1610
+ let isExistingDependent = node === dependent;
1611
+ if (isExistingDependent && propertyName && propertyName.startsWith('properties.')) {
1612
+ isExistingDependent = existingProp === propertyName;
1613
+ }
1614
+ return isExistingDependent;
1615
+ });
1616
+ if (existingDependency === undefined) {
1610
1617
  const subscription = this.subscribe((change) => {
1611
1618
  const changes = change.payload.changes;
1612
1619
  const propsToLook = [...dynamicProps, 'items'];
@@ -2533,7 +2540,7 @@ class Container extends Scriptable {
2533
2540
  activeChild.activeChild = null;
2534
2541
  activeChild = temp;
2535
2542
  }
2536
- const change = propertyChange('activeChild', c, this._activeChild);
2543
+ const change = propertyChange('activeChild', c?.getState(), this._activeChild?.getState());
2537
2544
  this._activeChild = c;
2538
2545
  if (this.parent && c !== null) {
2539
2546
  this.parent.activeChild = this;
@@ -2790,6 +2797,9 @@ const request$1 = (url, data = null, options = {}) => {
2790
2797
  body,
2791
2798
  headers
2792
2799
  };
2800
+ }).catch((error) => {
2801
+ console.error(`Network error while fetching from ${url}:`, error);
2802
+ throw error;
2793
2803
  });
2794
2804
  };
2795
2805
  const defaultRequestOptions = {
@@ -2892,25 +2902,11 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2892
2902
  inputPayload = String(payload);
2893
2903
  }
2894
2904
  }
2895
- const response = await request$1(endpoint, inputPayload, requestOptions);
2896
- response.originalRequest = {
2897
- url: endpoint,
2898
- method: httpVerb,
2899
- ...encryptOutput
2900
- };
2901
- const targetField = context.$field || null;
2902
- const targetEvent = context.$event || null;
2903
- response.submitter = targetField;
2904
- const enhancedPayload = {
2905
- request: response.originalRequest,
2906
- response,
2907
- targetField,
2908
- targetEvent
2909
- };
2910
- if (response?.status >= 200 && response?.status <= 299) {
2911
- const eName = getCustomEventName(success);
2912
- if (success === 'submitSuccess') {
2913
- 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));
2914
2910
  }
2915
2911
  else {
2916
2912
  if (context.field) {
@@ -2920,26 +2916,62 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2920
2916
  context.form.dispatch(new CustomEvent(eName, response, true));
2921
2917
  }
2922
2918
  }
2923
- context.form.dispatch(new RequestSuccess(enhancedPayload, false));
2924
- }
2925
- else {
2926
- context.form.logger.error('Error invoking a rest API');
2927
- const eName = getCustomEventName(error);
2928
- if (error === 'submitError') {
2929
- context.form.dispatch(new SubmitError(response, true));
2930
- context.form.dispatch(new SubmitFailure(response, true));
2931
- }
2932
- else {
2933
- if (context.field) {
2934
- context.field.dispatch(new CustomEvent(eName, response, true));
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));
2935
2944
  }
2936
2945
  else {
2937
- context.form.dispatch(new CustomEvent(eName, response, true));
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
+ }
2938
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);
2939
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);
2940
2973
  context.form.dispatch(new RequestFailure(enhancedPayload, false));
2941
2974
  }
2942
- return response;
2943
2975
  };
2944
2976
  const urlEncoded = (data) => {
2945
2977
  const formData = new URLSearchParams();
@@ -3554,7 +3586,7 @@ class FunctionRuntimeImpl {
3554
3586
  return '';
3555
3587
  }
3556
3588
  if (interpreter.globals.form?.properties?.queryParams?.[param]) {
3557
- return interpreter.globals.form.properties.queryParams[param];
3589
+ return interpreter.globals.form.properties.queryParams[param.toLowerCase()];
3558
3590
  }
3559
3591
  try {
3560
3592
  const urlParams = new URLSearchParams(window?.location?.search || '');
@@ -5560,6 +5592,8 @@ const fetchForm = (url, headers = {}) => {
5560
5592
  }
5561
5593
  resolve(jsonString(formObj));
5562
5594
  }
5595
+ }).catch((error) => {
5596
+ reject(`Network error: ${error.message || error}`);
5563
5597
  });
5564
5598
  });
5565
5599
  };
package/lib/BaseNode.js CHANGED
@@ -304,7 +304,14 @@ class BaseNode {
304
304
  };
305
305
  }
306
306
  _addDependent(dependent, propertyName) {
307
- if (this._dependents.find(({ node }) => node === dependent) === undefined) {
307
+ const existingDependency = this._dependents.find(({ node, propertyName: existingProp }) => {
308
+ let isExistingDependent = node === dependent;
309
+ if (isExistingDependent && propertyName && propertyName.startsWith('properties.')) {
310
+ isExistingDependent = existingProp === propertyName;
311
+ }
312
+ return isExistingDependent;
313
+ });
314
+ if (existingDependency === undefined) {
308
315
  const subscription = this.subscribe((change) => {
309
316
  const changes = change.payload.changes;
310
317
  const propsToLook = [...exports.dynamicProps, 'items'];
package/lib/Container.js CHANGED
@@ -422,6 +422,7 @@ class Container extends Scriptable_1.default {
422
422
  return this._activeChild;
423
423
  }
424
424
  set activeChild(c) {
425
+ var _a;
425
426
  if (c !== this._activeChild) {
426
427
  let activeChild = this._activeChild;
427
428
  while (activeChild instanceof Container) {
@@ -429,7 +430,7 @@ class Container extends Scriptable_1.default {
429
430
  activeChild.activeChild = null;
430
431
  activeChild = temp;
431
432
  }
432
- const change = (0, Events_1.propertyChange)('activeChild', c, this._activeChild);
433
+ const change = (0, Events_1.propertyChange)('activeChild', c === null || c === void 0 ? void 0 : c.getState(), (_a = this._activeChild) === null || _a === void 0 ? void 0 : _a.getState());
433
434
  this._activeChild = c;
434
435
  if (this.parent && c !== null) {
435
436
  this.parent.activeChild = this;
@@ -157,6 +157,8 @@ const fetchForm = (url, headers = {}) => {
157
157
  }
158
158
  resolve((0, JsonUtils_1.jsonString)(formObj));
159
159
  }
160
+ }).catch((error) => {
161
+ reject(`Network error: ${error.message || error}`);
160
162
  });
161
163
  });
162
164
  };
@@ -85,21 +85,11 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
85
85
  inputPayload = String(payload);
86
86
  }
87
87
  }
88
- const response = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
89
- response.originalRequest = Object.assign({ url: endpoint, method: httpVerb }, encryptOutput);
90
- const targetField = context.$field || null;
91
- const targetEvent = context.$event || null;
92
- response.submitter = targetField;
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.RequestSuccess(enhancedPayload, false));
113
- }
114
- else {
115
- context.form.logger.error('Error invoking a rest API');
116
- const eName = getCustomEventName(error);
117
- if (error === 'submitError') {
118
- context.form.dispatch(new Events_1.SubmitError(response, true));
119
- context.form.dispatch(new Events_1.SubmitFailure(response, true));
120
- }
121
- else {
122
- if (context.field) {
123
- context.field.dispatch(new Events_1.CustomEvent(eName, response, true));
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.form.dispatch(new Events_1.CustomEvent(eName, response, true));
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) => {
@@ -741,7 +756,7 @@ class FunctionRuntimeImpl {
741
756
  return '';
742
757
  }
743
758
  if ((_c = (_b = (_a = interpreter.globals.form) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.queryParams) === null || _c === void 0 ? void 0 : _c[param]) {
744
- return interpreter.globals.form.properties.queryParams[param];
759
+ return interpreter.globals.form.properties.queryParams[param.toLowerCase()];
745
760
  }
746
761
  try {
747
762
  const urlParams = new URLSearchParams(((_d = window === null || window === void 0 ? void 0 : window.location) === null || _d === void 0 ? void 0 : _d.search) || '');
@@ -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.145",
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.145"
40
+ "@aemforms/af-formatters": "^0.22.147"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",