@aemforms/af-core 0.22.121 → 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-events.js CHANGED
@@ -182,5 +182,15 @@ class RemoveInstance extends ActionImpl {
182
182
  super(payload, 'removeInstance');
183
183
  }
184
184
  }
185
+ class RequestSuccess extends ActionImpl {
186
+ constructor(payload, dispatch = false) {
187
+ super(payload, 'requestSuccess', { dispatch });
188
+ }
189
+ }
190
+ class RequestFailure extends ActionImpl {
191
+ constructor(payload, dispatch = false) {
192
+ super(payload, 'requestFailure', { dispatch });
193
+ }
194
+ }
185
195
 
186
- export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, Reset, Save, Submit, SubmitError, SubmitFailure, SubmitSuccess, UIChange, Valid, ValidationComplete, propertyChange };
196
+ export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, RequestFailure, RequestSuccess, Reset, Save, Submit, SubmitError, SubmitFailure, SubmitSuccess, UIChange, Valid, ValidationComplete, propertyChange };
@@ -1,4 +1,4 @@
1
- import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, SubmitError, SubmitFailure, 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, SubmitError, SubmitFailure, RequestFailure, Submit, Save, 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
 
@@ -156,6 +156,10 @@ const isEmailInput = function (item) {
156
156
  const fieldType = item?.fieldType || defaultFieldTypes(item);
157
157
  return (fieldType === 'text-input' && item?.format === 'email') || fieldType === 'email';
158
158
  };
159
+ const isDateTimeField = function (item) {
160
+ const fieldType = item?.fieldType || defaultFieldTypes(item);
161
+ return (fieldType === 'text-input' && item?.format === 'date-time') || fieldType === 'datetime-input';
162
+ };
159
163
  const isDateField = function (item) {
160
164
  const fieldType = item?.fieldType || defaultFieldTypes(item);
161
165
  return (fieldType === 'text-input' && item?.format === 'date') || fieldType === 'date-input';
@@ -1030,7 +1034,8 @@ const ValidConstraints = {
1030
1034
  number: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'],
1031
1035
  array: ['minItems', 'maxItems', 'uniqueItems'],
1032
1036
  file: ['accept', 'maxFileSize'],
1033
- email: ['minLength', 'maxLength', 'format', 'pattern']
1037
+ email: ['minLength', 'maxLength', 'format', 'pattern'],
1038
+ datetime: ['minimum', 'maximum']
1034
1039
  };
1035
1040
  const validationConstraintsList = ['type', 'format', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'minItems',
1036
1041
  'maxItems', 'uniqueItems', 'minLength', 'maxLength', 'pattern', 'required', 'enum', 'accept', 'maxFileSize'];
@@ -1914,6 +1919,7 @@ class Scriptable extends BaseNode {
1914
1919
  target: this.getRuleNode()
1915
1920
  }
1916
1921
  };
1922
+ this.ruleEngine.setDependencyTracking(['change', 'executeRule'].includes(action.type));
1917
1923
  const eventName = action.isCustomEvent ? `custom:${action.type}` : action.type;
1918
1924
  const funcName = action.isCustomEvent ? `custom_${action.type}` : action.type;
1919
1925
  const node = this.getCompiledEvent(eventName);
@@ -2407,7 +2413,7 @@ class Container extends Scriptable {
2407
2413
  for (const change of action.payload.changes) {
2408
2414
  if (change.propertyName !== undefined && notifyChildrenAttributes.includes(change.propertyName)) {
2409
2415
  this.items.forEach((child) => {
2410
- if (change.currentValue !== child.getState()[change.propertyName]) {
2416
+ if (change.currentValue !== child._jsonModel[change.propertyName]) {
2411
2417
  child._jsonModel[change.propertyName] = change.currentValue;
2412
2418
  this.notifyDependents.call(child, propertyChange(change.propertyName, child.getState()[change.propertyName], null));
2413
2419
  }
@@ -2716,6 +2722,14 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2716
2722
  method: httpVerb,
2717
2723
  ...encryptOutput
2718
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
+ };
2719
2733
  if (response?.status >= 200 && response?.status <= 299) {
2720
2734
  const eName = getCustomEventName(success);
2721
2735
  if (success === 'submitSuccess') {
@@ -2724,6 +2738,7 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2724
2738
  else {
2725
2739
  context.form.dispatch(new CustomEvent(eName, response, true));
2726
2740
  }
2741
+ context.form.dispatch(new RequestSuccess(enhancedPayload, false));
2727
2742
  }
2728
2743
  else {
2729
2744
  context.form.logger.error('Error invoking a rest API');
@@ -2735,7 +2750,9 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2735
2750
  else {
2736
2751
  context.form.dispatch(new CustomEvent(eName, response, true));
2737
2752
  }
2753
+ context.form.dispatch(new RequestFailure(enhancedPayload, false));
2738
2754
  }
2755
+ return response;
2739
2756
  };
2740
2757
  const urlEncoded = (data) => {
2741
2758
  const formData = new URLSearchParams();
@@ -3120,6 +3137,65 @@ class FunctionRuntimeImpl {
3120
3137
  },
3121
3138
  _signature: []
3122
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
+ },
3123
3199
  awaitFn: {
3124
3200
  _func: async (args, data, interpreter) => {
3125
3201
  const success = args[1];
@@ -3870,6 +3946,7 @@ class Field extends Scriptable {
3870
3946
  'multiline-input': 'string',
3871
3947
  'number-input': 'number',
3872
3948
  'date-input': 'string',
3949
+ 'date-time': 'string',
3873
3950
  'email': 'string',
3874
3951
  'plain-text': 'string',
3875
3952
  'image': 'string',
@@ -3944,7 +4021,7 @@ class Field extends Scriptable {
3944
4021
  }
3945
4022
  this.coerceParam('minLength', 'number');
3946
4023
  this.coerceParam('maxLength', 'number');
3947
- if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date' && this._jsonModel.type !== 'integer') {
4024
+ if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date' && this._jsonModel.format !== 'date-time' && this._jsonModel.type !== 'integer') {
3948
4025
  this.unset('step', ...props);
3949
4026
  }
3950
4027
  props.forEach(c => {
@@ -4047,22 +4124,22 @@ class Field extends Scriptable {
4047
4124
  this._setProperty('required', r);
4048
4125
  }
4049
4126
  get maximum() {
4050
- if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
4127
+ if (this.type === 'number' || this.format === 'date' || this.format === 'date-time' || this.type === 'integer') {
4051
4128
  return this._jsonModel.maximum;
4052
4129
  }
4053
4130
  }
4054
4131
  set maximum(m) {
4055
- if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
4132
+ if (this.type === 'number' || this.format === 'date' || this.format === 'date-time' || this.type === 'integer') {
4056
4133
  this._setProperty('maximum', m);
4057
4134
  }
4058
4135
  }
4059
4136
  get minimum() {
4060
- if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
4137
+ if (this.type === 'number' || this.format === 'date' || this.format === 'date-time' || this.type === 'integer') {
4061
4138
  return this._jsonModel.minimum;
4062
4139
  }
4063
4140
  }
4064
4141
  set minimum(m) {
4065
- if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
4142
+ if (this.type === 'number' || this.format === 'date' || this.format === 'date-time' || this.type === 'integer') {
4066
4143
  this._setProperty('minimum', m);
4067
4144
  }
4068
4145
  }
@@ -4307,6 +4384,8 @@ class Field extends Scriptable {
4307
4384
  switch (this.format) {
4308
4385
  case 'date':
4309
4386
  return ValidConstraints.date;
4387
+ case 'date-time':
4388
+ return ValidConstraints.datetime;
4310
4389
  case 'email':
4311
4390
  return ValidConstraints.email;
4312
4391
  case 'binary':
@@ -4337,6 +4416,9 @@ class Field extends Scriptable {
4337
4416
  case 'file-input':
4338
4417
  this._jsonModel.format = 'data-url';
4339
4418
  break;
4419
+ case 'date-time':
4420
+ this._jsonModel.format = 'date-time';
4421
+ break;
4340
4422
  }
4341
4423
  }
4342
4424
  }
@@ -4557,7 +4639,7 @@ __decorate([
4557
4639
  dependencyTracked()
4558
4640
  ], Field.prototype, "errorMessage", null);
4559
4641
  __decorate([
4560
- include('text-input', 'date-input', 'file-input', 'email')
4642
+ include('text-input', 'date-input', 'file-input', 'email', 'datetime-input')
4561
4643
  ], Field.prototype, "format", null);
4562
4644
  __decorate([
4563
4645
  include('text-input')
@@ -4848,6 +4930,19 @@ class DateField extends Field {
4848
4930
  }
4849
4931
  }
4850
4932
 
4933
+ class DateTimeField extends DateField {
4934
+ _dataFormat = 'yyyy-MM-ddTHH:mm';
4935
+ _applyDefaults() {
4936
+ super._applyDefaults();
4937
+ }
4938
+ get value() {
4939
+ return super.value;
4940
+ }
4941
+ set value(value) {
4942
+ super.value = value;
4943
+ }
4944
+ }
4945
+
4851
4946
  class EmailInput extends Field {
4852
4947
  _getDefaults() {
4853
4948
  return {
@@ -4962,6 +5057,9 @@ class FormFieldFactoryImpl {
4962
5057
  else if (isDateField(child)) {
4963
5058
  retVal = new DateField(child, options);
4964
5059
  }
5060
+ else if (isDateTimeField(child)) {
5061
+ retVal = new DateTimeField(child, options);
5062
+ }
4965
5063
  else if (isCaptcha(child)) {
4966
5064
  retVal = new Captcha(child, options);
4967
5065
  }
@@ -2,7 +2,7 @@ import Field from './Field';
2
2
  declare class DateField extends Field {
3
3
  #private;
4
4
  private locale?;
5
- private _dataFormat;
5
+ protected _dataFormat: string;
6
6
  protected _applyDefaults(): void;
7
7
  get value(): any;
8
8
  set value(value: any);
@@ -0,0 +1,8 @@
1
+ import DateField from './DateField';
2
+ declare class DateTimeField extends DateField {
3
+ protected _dataFormat: string;
4
+ protected _applyDefaults(): void;
5
+ get value(): any;
6
+ set value(value: any);
7
+ }
8
+ export default DateTimeField;
@@ -108,4 +108,10 @@ export declare class AddInstance extends ActionImpl {
108
108
  export declare class RemoveInstance extends ActionImpl {
109
109
  constructor(payload?: number);
110
110
  }
111
+ export declare class RequestSuccess extends ActionImpl {
112
+ constructor(payload?: any, dispatch?: boolean);
113
+ }
114
+ export declare class RequestFailure extends ActionImpl {
115
+ constructor(payload?: any, dispatch?: boolean);
116
+ }
111
117
  export {};
@@ -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<void>;
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<void>;
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: {
@@ -5,6 +5,7 @@ export declare const checkIfConstraintsArePresent: (item: FieldsetJson | FieldJs
5
5
  export declare const isCheckbox: (item: FieldsetJson | FieldJson) => boolean;
6
6
  export declare const isCheckboxGroup: (item: FieldsetJson | FieldJson) => boolean;
7
7
  export declare const isEmailInput: (item: FieldsetJson | FieldJson) => boolean;
8
+ export declare const isDateTimeField: (item: FieldsetJson | FieldJson) => boolean;
8
9
  export declare const isDateField: (item: FieldsetJson | FieldJson) => boolean;
9
10
  export declare const isCaptcha: (item: FieldsetJson | FieldJson) => boolean;
10
11
  export declare const isButton: (item: FieldsetJson | FieldJson) => boolean;
@@ -10,6 +10,7 @@ type ValidConstraintsType = {
10
10
  array: ValidationConstraints[];
11
11
  file: ValidationConstraints[];
12
12
  email: ValidationConstraints[];
13
+ datetime: ValidationConstraints[];
13
14
  };
14
15
  export declare const ValidConstraints: ValidConstraintsType;
15
16
  export declare const validationConstraintsList: readonly ["type", "format", "minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "minItems", "maxItems", "uniqueItems", "minLength", "maxLength", "pattern", "required", "enum", "accept", "maxFileSize"];
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.getState()[change.propertyName]) {
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
  }
@@ -2,7 +2,7 @@ import Field from './Field';
2
2
  declare class DateField extends Field {
3
3
  #private;
4
4
  private locale?;
5
- private _dataFormat;
5
+ protected _dataFormat: string;
6
6
  protected _applyDefaults(): void;
7
7
  get value(): any;
8
8
  set value(value: any);
@@ -0,0 +1,8 @@
1
+ import DateField from './DateField';
2
+ declare class DateTimeField extends DateField {
3
+ protected _dataFormat: string;
4
+ protected _applyDefaults(): void;
5
+ get value(): any;
6
+ set value(value: any);
7
+ }
8
+ export default DateTimeField;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const DateField_1 = __importDefault(require("./DateField"));
7
+ class DateTimeField extends DateField_1.default {
8
+ constructor() {
9
+ super(...arguments);
10
+ this._dataFormat = 'yyyy-MM-ddTHH:mm';
11
+ }
12
+ _applyDefaults() {
13
+ super._applyDefaults();
14
+ }
15
+ get value() {
16
+ return super.value;
17
+ }
18
+ set value(value) {
19
+ super.value = value;
20
+ }
21
+ }
22
+ exports.default = DateTimeField;
package/lib/Field.js CHANGED
@@ -89,6 +89,7 @@ class Field extends Scriptable_1.default {
89
89
  'multiline-input': 'string',
90
90
  'number-input': 'number',
91
91
  'date-input': 'string',
92
+ 'date-time': 'string',
92
93
  'email': 'string',
93
94
  'plain-text': 'string',
94
95
  'image': 'string',
@@ -164,7 +165,7 @@ class Field extends Scriptable_1.default {
164
165
  }
165
166
  this.coerceParam('minLength', 'number');
166
167
  this.coerceParam('maxLength', 'number');
167
- if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date' && this._jsonModel.type !== 'integer') {
168
+ if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date' && this._jsonModel.format !== 'date-time' && this._jsonModel.type !== 'integer') {
168
169
  this.unset('step', ...props);
169
170
  }
170
171
  props.forEach(c => {
@@ -266,22 +267,22 @@ class Field extends Scriptable_1.default {
266
267
  this._setProperty('required', r);
267
268
  }
268
269
  get maximum() {
269
- if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
270
+ if (this.type === 'number' || this.format === 'date' || this.format === 'date-time' || this.type === 'integer') {
270
271
  return this._jsonModel.maximum;
271
272
  }
272
273
  }
273
274
  set maximum(m) {
274
- if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
275
+ if (this.type === 'number' || this.format === 'date' || this.format === 'date-time' || this.type === 'integer') {
275
276
  this._setProperty('maximum', m);
276
277
  }
277
278
  }
278
279
  get minimum() {
279
- if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
280
+ if (this.type === 'number' || this.format === 'date' || this.format === 'date-time' || this.type === 'integer') {
280
281
  return this._jsonModel.minimum;
281
282
  }
282
283
  }
283
284
  set minimum(m) {
284
- if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
285
+ if (this.type === 'number' || this.format === 'date' || this.format === 'date-time' || this.type === 'integer') {
285
286
  this._setProperty('minimum', m);
286
287
  }
287
288
  }
@@ -527,6 +528,8 @@ class Field extends Scriptable_1.default {
527
528
  switch (this.format) {
528
529
  case 'date':
529
530
  return ValidationUtils_1.ValidConstraints.date;
531
+ case 'date-time':
532
+ return ValidationUtils_1.ValidConstraints.datetime;
530
533
  case 'email':
531
534
  return ValidationUtils_1.ValidConstraints.email;
532
535
  case 'binary':
@@ -557,6 +560,9 @@ class Field extends Scriptable_1.default {
557
560
  case 'file-input':
558
561
  this._jsonModel.format = 'data-url';
559
562
  break;
563
+ case 'date-time':
564
+ this._jsonModel.format = 'date-time';
565
+ break;
560
566
  }
561
567
  }
562
568
  }
@@ -760,7 +766,7 @@ __decorate([
760
766
  (0, BaseNode_1.dependencyTracked)()
761
767
  ], Field.prototype, "errorMessage", null);
762
768
  __decorate([
763
- (0, BaseNode_1.include)('text-input', 'date-input', 'file-input', 'email')
769
+ (0, BaseNode_1.include)('text-input', 'date-input', 'file-input', 'email', 'datetime-input')
764
770
  ], Field.prototype, "format", null);
765
771
  __decorate([
766
772
  (0, BaseNode_1.include)('text-input')
package/lib/Scriptable.js CHANGED
@@ -182,6 +182,7 @@ class Scriptable extends BaseNode_1.BaseNode {
182
182
  target: this.getRuleNode()
183
183
  }
184
184
  };
185
+ this.ruleEngine.setDependencyTracking(['change', 'executeRule'].includes(action.type));
185
186
  const eventName = action.isCustomEvent ? `custom:${action.type}` : action.type;
186
187
  const funcName = action.isCustomEvent ? `custom_${action.type}` : action.type;
187
188
  const node = this.getCompiledEvent(eventName);
@@ -108,4 +108,10 @@ export declare class AddInstance extends ActionImpl {
108
108
  export declare class RemoveInstance extends ActionImpl {
109
109
  constructor(payload?: number);
110
110
  }
111
+ export declare class RequestSuccess extends ActionImpl {
112
+ constructor(payload?: any, dispatch?: boolean);
113
+ }
114
+ export declare class RequestFailure extends ActionImpl {
115
+ constructor(payload?: any, dispatch?: boolean);
116
+ }
111
117
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.SubmitError = exports.SubmitFailure = exports.SubmitSuccess = exports.Save = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.UIChange = exports.Change = void 0;
3
+ exports.RequestFailure = exports.RequestSuccess = exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.SubmitError = exports.SubmitFailure = exports.SubmitSuccess = exports.Save = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.UIChange = exports.Change = void 0;
4
4
  var EventSource;
5
5
  (function (EventSource) {
6
6
  EventSource["CODE"] = "code";
@@ -204,3 +204,15 @@ class RemoveInstance extends ActionImpl {
204
204
  }
205
205
  }
206
206
  exports.RemoveInstance = RemoveInstance;
207
+ class RequestSuccess extends ActionImpl {
208
+ constructor(payload, dispatch = false) {
209
+ super(payload, 'requestSuccess', { dispatch });
210
+ }
211
+ }
212
+ exports.RequestSuccess = RequestSuccess;
213
+ class RequestFailure extends ActionImpl {
214
+ constructor(payload, dispatch = false) {
215
+ super(payload, 'requestFailure', { dispatch });
216
+ }
217
+ }
218
+ exports.RequestFailure = RequestFailure;
@@ -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<void>;
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<void>;
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,6 +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
  }
99
+ context.form.dispatch(new Events_1.RequestSuccess(enhancedPayload, false));
91
100
  }
92
101
  else {
93
102
  context.form.logger.error('Error invoking a rest API');
@@ -99,7 +108,9 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
99
108
  else {
100
109
  context.form.dispatch(new Events_1.CustomEvent(eName, response, true));
101
110
  }
111
+ context.form.dispatch(new Events_1.RequestFailure(enhancedPayload, false));
102
112
  }
113
+ return response;
103
114
  });
104
115
  exports.request = request;
105
116
  const urlEncoded = (data) => {
@@ -487,6 +498,59 @@ class FunctionRuntimeImpl {
487
498
  },
488
499
  _signature: []
489
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
+ },
490
554
  awaitFn: {
491
555
  _func: (args, data, interpreter) => __awaiter(this, void 0, void 0, function* () {
492
556
  const success = args[1];
@@ -11,6 +11,7 @@ const FileUpload_1 = __importDefault(require("../FileUpload"));
11
11
  const Checkbox_1 = __importDefault(require("../Checkbox"));
12
12
  const CheckboxGroup_1 = __importDefault(require("../CheckboxGroup"));
13
13
  const DateField_1 = __importDefault(require("../DateField"));
14
+ const DateTimeField_1 = __importDefault(require("../DateTimeField"));
14
15
  const Field_1 = __importDefault(require("../Field"));
15
16
  const EmailInput_1 = __importDefault(require("../EmailInput"));
16
17
  const Captcha_1 = __importDefault(require("../Captcha"));
@@ -66,6 +67,9 @@ class FormFieldFactoryImpl {
66
67
  else if ((0, JsonUtils_1.isDateField)(child)) {
67
68
  retVal = new DateField_1.default(child, options);
68
69
  }
70
+ else if ((0, JsonUtils_1.isDateTimeField)(child)) {
71
+ retVal = new DateTimeField_1.default(child, options);
72
+ }
69
73
  else if ((0, JsonUtils_1.isCaptcha)(child)) {
70
74
  retVal = new Captcha_1.default(child, options);
71
75
  }
@@ -5,6 +5,7 @@ export declare const checkIfConstraintsArePresent: (item: FieldsetJson | FieldJs
5
5
  export declare const isCheckbox: (item: FieldsetJson | FieldJson) => boolean;
6
6
  export declare const isCheckboxGroup: (item: FieldsetJson | FieldJson) => boolean;
7
7
  export declare const isEmailInput: (item: FieldsetJson | FieldJson) => boolean;
8
+ export declare const isDateTimeField: (item: FieldsetJson | FieldJson) => boolean;
8
9
  export declare const isDateField: (item: FieldsetJson | FieldJson) => boolean;
9
10
  export declare const isCaptcha: (item: FieldsetJson | FieldJson) => boolean;
10
11
  export declare const isButton: (item: FieldsetJson | FieldJson) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRepeatable = exports.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isButton = exports.isCaptcha = exports.isDateField = exports.isEmailInput = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
3
+ exports.isRepeatable = exports.jsonString = exports.checkIfKeyAdded = exports.deepClone = exports.isButton = exports.isCaptcha = exports.isDateField = exports.isDateTimeField = exports.isEmailInput = exports.isCheckboxGroup = exports.isCheckbox = exports.checkIfConstraintsArePresent = exports.isFile = exports.getProperty = void 0;
4
4
  const index_1 = require("../types/index");
5
5
  const SchemaUtils_1 = require("./SchemaUtils");
6
6
  const getProperty = (data, key, def) => {
@@ -42,6 +42,11 @@ const isEmailInput = function (item) {
42
42
  return (fieldType === 'text-input' && (item === null || item === void 0 ? void 0 : item.format) === 'email') || fieldType === 'email';
43
43
  };
44
44
  exports.isEmailInput = isEmailInput;
45
+ const isDateTimeField = function (item) {
46
+ const fieldType = (item === null || item === void 0 ? void 0 : item.fieldType) || (0, SchemaUtils_1.defaultFieldTypes)(item);
47
+ return (fieldType === 'text-input' && (item === null || item === void 0 ? void 0 : item.format) === 'date-time') || fieldType === 'datetime-input';
48
+ };
49
+ exports.isDateTimeField = isDateTimeField;
45
50
  const isDateField = function (item) {
46
51
  const fieldType = (item === null || item === void 0 ? void 0 : item.fieldType) || (0, SchemaUtils_1.defaultFieldTypes)(item);
47
52
  return (fieldType === 'text-input' && (item === null || item === void 0 ? void 0 : item.format) === 'date') || fieldType === 'date-input';
@@ -10,6 +10,7 @@ declare type ValidConstraintsType = {
10
10
  array: ValidationConstraints[];
11
11
  file: ValidationConstraints[];
12
12
  email: ValidationConstraints[];
13
+ datetime: ValidationConstraints[];
13
14
  };
14
15
  export declare const ValidConstraints: ValidConstraintsType;
15
16
  export declare const validationConstraintsList: readonly ["type", "format", "minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "minItems", "maxItems", "uniqueItems", "minLength", "maxLength", "pattern", "required", "enum", "accept", "maxFileSize"];
@@ -116,7 +116,8 @@ exports.ValidConstraints = {
116
116
  number: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'],
117
117
  array: ['minItems', 'maxItems', 'uniqueItems'],
118
118
  file: ['accept', 'maxFileSize'],
119
- email: ['minLength', 'maxLength', 'format', 'pattern']
119
+ email: ['minLength', 'maxLength', 'format', 'pattern'],
120
+ datetime: ['minimum', 'maximum']
120
121
  };
121
122
  exports.validationConstraintsList = ['type', 'format', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'minItems',
122
123
  'maxItems', 'uniqueItems', 'minLength', 'maxLength', 'pattern', 'required', 'enum', 'accept', 'maxFileSize'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.121",
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.121"
40
+ "@aemforms/af-formatters": "^0.22.123"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",