@aemforms/af-core 0.22.110 → 0.22.112

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.
@@ -1874,6 +1874,9 @@ class Scriptable extends BaseNode {
1874
1874
  let updates;
1875
1875
  if (node) {
1876
1876
  updates = this.ruleEngine.execute(node, this.getExpressionScope(), context, false, eString);
1877
+ if (updates instanceof Promise) {
1878
+ this.form.addPromises(updates);
1879
+ }
1877
1880
  }
1878
1881
  if (typeof updates !== 'undefined' && updates != null) {
1879
1882
  this.applyUpdates(updates);
@@ -3069,8 +3072,7 @@ class FunctionRuntimeImpl {
3069
3072
  success = valueOf(args[4]);
3070
3073
  error = valueOf(args[5]);
3071
3074
  }
3072
- request(interpreter.globals, uri, httpVerb, payload, success, error, headers);
3073
- return {};
3075
+ return request(interpreter.globals, uri, httpVerb, payload, success, error, headers);
3074
3076
  },
3075
3077
  _signature: []
3076
3078
  },
@@ -3226,6 +3228,7 @@ class Form extends Container {
3226
3228
  _ids;
3227
3229
  _invalidFields = [];
3228
3230
  _exportDataAttachmentMap = {};
3231
+ promises = [];
3229
3232
  _captcha = null;
3230
3233
  constructor(n, fieldFactory, _ruleEngine, _eventQueue = new EventQueue(), logLevel = 'off', mode = 'create') {
3231
3234
  super(n, { fieldFactory: fieldFactory, mode });
@@ -3249,6 +3252,17 @@ class Form extends Container {
3249
3252
  this.queueEvent(new FormLoad());
3250
3253
  }
3251
3254
  }
3255
+ addPromises(updates) {
3256
+ this.promises.push(updates);
3257
+ }
3258
+ async waitForPromises() {
3259
+ let length = 0;
3260
+ while (this.promises.length > length) {
3261
+ length = this.promises.length;
3262
+ await Promise.all(this.promises);
3263
+ }
3264
+ this.promises = [];
3265
+ }
3252
3266
  _applyDefaultsInModel() {
3253
3267
  const current = this.specVersion;
3254
3268
  this._jsonModel.properties = this._jsonModel.properties || {};
@@ -4735,7 +4749,7 @@ class Captcha extends Field {
4735
4749
  super(params, _options);
4736
4750
  this._captchaDisplayMode = params.captchaDisplayMode;
4737
4751
  this._captchaProvider = params.captchaProvider;
4738
- this._captchaSiteKey = params.siteKey;
4752
+ this._captchaSiteKey = params.captchaSiteKey;
4739
4753
  }
4740
4754
  getDataNode() {
4741
4755
  return undefined;
@@ -4847,23 +4861,40 @@ class FormFieldFactoryImpl {
4847
4861
  }
4848
4862
  const FormFieldFactory = new FormFieldFactoryImpl();
4849
4863
 
4864
+ const createFormInstanceHelper = (formModel, logLevel, fModel) => {
4865
+ let f = fModel;
4866
+ if (f == null) {
4867
+ formModel = sitesModelToFormModel(formModel);
4868
+ f = new Form({ ...formModel }, FormFieldFactory, new RuleEngine(), new EventQueue(new Logger(logLevel)), logLevel);
4869
+ }
4870
+ const formData = formModel?.data;
4871
+ if (formData) {
4872
+ f.importData(formData);
4873
+ }
4874
+ return f;
4875
+ };
4850
4876
  const createFormInstance = (formModel, callback, logLevel = 'error', fModel = undefined) => {
4851
4877
  try {
4852
- let f = fModel;
4853
- {
4854
- if (f == null) {
4855
- formModel = sitesModelToFormModel(formModel);
4856
- f = new Form({ ...formModel }, FormFieldFactory, new RuleEngine(), new EventQueue(new Logger(logLevel)), logLevel);
4857
- }
4858
- }
4859
- const formData = formModel?.data;
4860
- if (formData) {
4861
- f.importData(formData);
4878
+ const f = createFormInstanceHelper(formModel, logLevel, fModel);
4879
+ if (typeof callback === 'function') {
4880
+ callback(f);
4862
4881
  }
4882
+ f.getEventQueue().runPendingQueue();
4883
+ return f;
4884
+ }
4885
+ catch (e) {
4886
+ console.error(`Unable to create an instance of the Form ${e}`);
4887
+ throw new Error(e);
4888
+ }
4889
+ };
4890
+ const createFormInstanceSync = async (formModel, callback, logLevel = 'error', fModel = undefined) => {
4891
+ try {
4892
+ const f = createFormInstanceHelper(formModel, logLevel, fModel);
4863
4893
  if (typeof callback === 'function') {
4864
4894
  callback(f);
4865
4895
  }
4866
4896
  f.getEventQueue().runPendingQueue();
4897
+ await f.waitForPromises();
4867
4898
  return f;
4868
4899
  }
4869
4900
  catch (e) {
@@ -4943,4 +4974,4 @@ const registerFunctions = (functions) => {
4943
4974
  FunctionRuntime.registerFunctions(functions);
4944
4975
  };
4945
4976
 
4946
- export { createFormInstance, fetchForm, registerFunctions, restoreFormInstance, validateFormData, validateFormInstance };
4977
+ export { createFormInstance, createFormInstanceSync, fetchForm, registerFunctions, restoreFormInstance, validateFormData, validateFormInstance };
@@ -0,0 +1,20 @@
1
+ export declare const FIELD_TYPE: {
2
+ TEXT_INPUT: string;
3
+ EMAIL: string;
4
+ CAPTCHA: string;
5
+ MULTILINE_INPUT: string;
6
+ NUMBER_INPUT: string;
7
+ DATE_INPUT: string;
8
+ FILE_INPUT: string;
9
+ DROP_DOWN: string;
10
+ RADIO_GROUP: string;
11
+ PLAIN_TEXT: string;
12
+ CHECKBOX: string;
13
+ BUTTON: string;
14
+ PANEL: string;
15
+ FORM: string;
16
+ CHECKBOX_GROUP: string;
17
+ IMAGE: string;
18
+ TELEPHONE: string;
19
+ PASSWORD: string;
20
+ };
@@ -16,8 +16,11 @@ declare class Form extends Container<FormJson> implements FormModel {
16
16
  _ids: Generator<string, void, string>;
17
17
  private _invalidFields;
18
18
  _exportDataAttachmentMap: Record<string, any>;
19
+ private promises;
19
20
  private _captcha;
20
21
  constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
22
+ addPromises(updates: Promise<any>): void;
23
+ waitForPromises(): Promise<void>;
21
24
  protected _applyDefaultsInModel(): void;
22
25
  private _logger;
23
26
  get activeField(): FieldModel;
@@ -5,6 +5,7 @@ export declare const createFormInstance: {
5
5
  (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any): FormModel;
6
6
  currentVersion: import("./utils/Version").Version;
7
7
  };
8
+ export declare const createFormInstanceSync: (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any) => Promise<FormModel>;
8
9
  export declare const restoreFormInstance: (formModel: any, data?: any, { logLevel }?: {
9
10
  logLevel: LogLevel;
10
11
  }) => FormModel;
@@ -4,6 +4,7 @@ export * from './controller/Events';
4
4
  export * from './utils/TranslationUtils';
5
5
  export * from './utils/JsonUtils';
6
6
  export * from './utils/SchemaUtils';
7
+ export * from './Constant';
7
8
  import { getFileSizeInBytes, extractFileInfo, isEmpty, readAttachments } from './utils/FormUtils';
8
9
  import { BaseNode } from './BaseNode';
9
10
  import Checkbox from './Checkbox';
@@ -45,7 +45,7 @@ declare class FunctionRuntimeImpl {
45
45
  _signature: never[];
46
46
  };
47
47
  request: {
48
- _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
48
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<void>;
49
49
  _signature: never[];
50
50
  };
51
51
  awaitFn: {
@@ -104,7 +104,7 @@ export type FieldJson = BaseJson & TranslationFieldJson & {
104
104
  export type CaptchaJson = FieldJson & {
105
105
  captchaDisplayMode?: CaptchaDisplayMode | undefined;
106
106
  captchaProvider?: string | undefined;
107
- siteKey?: string | undefined;
107
+ captchaSiteKey?: string | undefined;
108
108
  };
109
109
  export type ContainerJson = BaseJson & {
110
110
  items: Array<FieldJson | ContainerJson>;
@@ -132,6 +132,8 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
132
132
  resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
133
133
  fieldAdded(field: FieldModel | FieldsetModel): void;
134
134
  readonly changeEventBehaviour: 'deps' | 'self';
135
+ addPromises(updates: Promise<any>): void;
136
+ waitForPromises(): any;
135
137
  }
136
138
  export interface IFormFieldFactory {
137
139
  createField(child: FieldsetJson | FieldJson, options: {
package/lib/Captcha.js CHANGED
@@ -9,7 +9,7 @@ class Captcha extends Field_1.default {
9
9
  super(params, _options);
10
10
  this._captchaDisplayMode = params.captchaDisplayMode;
11
11
  this._captchaProvider = params.captchaProvider;
12
- this._captchaSiteKey = params.siteKey;
12
+ this._captchaSiteKey = params.captchaSiteKey;
13
13
  }
14
14
  getDataNode() {
15
15
  return undefined;
@@ -0,0 +1,20 @@
1
+ export declare const FIELD_TYPE: {
2
+ TEXT_INPUT: string;
3
+ EMAIL: string;
4
+ CAPTCHA: string;
5
+ MULTILINE_INPUT: string;
6
+ NUMBER_INPUT: string;
7
+ DATE_INPUT: string;
8
+ FILE_INPUT: string;
9
+ DROP_DOWN: string;
10
+ RADIO_GROUP: string;
11
+ PLAIN_TEXT: string;
12
+ CHECKBOX: string;
13
+ BUTTON: string;
14
+ PANEL: string;
15
+ FORM: string;
16
+ CHECKBOX_GROUP: string;
17
+ IMAGE: string;
18
+ TELEPHONE: string;
19
+ PASSWORD: string;
20
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FIELD_TYPE = void 0;
4
+ exports.FIELD_TYPE = {
5
+ TEXT_INPUT: 'text-input',
6
+ EMAIL: 'email',
7
+ CAPTCHA: 'captcha',
8
+ MULTILINE_INPUT: 'multiline-input',
9
+ NUMBER_INPUT: 'number-input',
10
+ DATE_INPUT: 'date-input',
11
+ FILE_INPUT: 'file-input',
12
+ DROP_DOWN: 'drop-down',
13
+ RADIO_GROUP: 'radio-group',
14
+ PLAIN_TEXT: 'plain-text',
15
+ CHECKBOX: 'checkbox',
16
+ BUTTON: 'button',
17
+ PANEL: 'panel',
18
+ FORM: 'form',
19
+ CHECKBOX_GROUP: 'checkbox-group',
20
+ IMAGE: 'image',
21
+ TELEPHONE: 'tel',
22
+ PASSWORD: 'password'
23
+ };
package/lib/Form.d.ts CHANGED
@@ -16,8 +16,11 @@ declare class Form extends Container<FormJson> implements FormModel {
16
16
  _ids: Generator<string, void, string>;
17
17
  private _invalidFields;
18
18
  _exportDataAttachmentMap: Record<string, any>;
19
+ private promises;
19
20
  private _captcha;
20
21
  constructor(n: FormJson, fieldFactory: IFormFieldFactory, _ruleEngine: RuleEngine, _eventQueue?: EventQueue, logLevel?: LogLevel, mode?: FormCreationMode);
22
+ addPromises(updates: Promise<any>): void;
23
+ waitForPromises(): Promise<void>;
21
24
  protected _applyDefaultsInModel(): void;
22
25
  private _logger;
23
26
  get activeField(): FieldModel;
package/lib/Form.js CHANGED
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
12
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
13
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
@@ -33,6 +42,7 @@ class Form extends Container_1.default {
33
42
  this._fields = {};
34
43
  this._invalidFields = [];
35
44
  this._exportDataAttachmentMap = {};
45
+ this.promises = [];
36
46
  this._captcha = null;
37
47
  this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
38
48
  this._logger = new Logger_1.Logger(logLevel);
@@ -53,6 +63,19 @@ class Form extends Container_1.default {
53
63
  this.queueEvent(new Events_1.FormLoad());
54
64
  }
55
65
  }
66
+ addPromises(updates) {
67
+ this.promises.push(updates);
68
+ }
69
+ waitForPromises() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ let length = 0;
72
+ while (this.promises.length > length) {
73
+ length = this.promises.length;
74
+ yield Promise.all(this.promises);
75
+ }
76
+ this.promises = [];
77
+ });
78
+ }
56
79
  _applyDefaultsInModel() {
57
80
  const current = this.specVersion;
58
81
  this._jsonModel.properties = this._jsonModel.properties || {};
@@ -5,6 +5,7 @@ export declare const createFormInstance: {
5
5
  (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any): FormModel;
6
6
  currentVersion: import("./utils/Version").Version;
7
7
  };
8
+ export declare const createFormInstanceSync: (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any) => Promise<FormModel>;
8
9
  export declare const restoreFormInstance: (formModel: any, data?: any, { logLevel }?: {
9
10
  logLevel: LogLevel;
10
11
  }) => FormModel;
@@ -22,11 +22,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
36
  };
28
37
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.registerFunctions = exports.fetchForm = exports.validateFormData = exports.validateFormInstance = exports.restoreFormInstance = exports.createFormInstance = void 0;
38
+ exports.registerFunctions = exports.fetchForm = exports.validateFormData = exports.validateFormInstance = exports.restoreFormInstance = exports.createFormInstanceSync = exports.createFormInstance = void 0;
30
39
  const Form_1 = __importStar(require("./Form"));
31
40
  const JsonUtils_1 = require("./utils/JsonUtils");
32
41
  const Fetch_1 = require("./utils/Fetch");
@@ -37,19 +46,21 @@ const FormCreationUtils_1 = require("./utils/FormCreationUtils");
37
46
  const FunctionRuntime_1 = require("./rules/FunctionRuntime");
38
47
  const FormUtils_1 = require("./utils/FormUtils");
39
48
  const DataGroup_1 = __importDefault(require("./data/DataGroup"));
49
+ const createFormInstanceHelper = (formModel, logLevel, fModel) => {
50
+ let f = fModel;
51
+ if (f == null) {
52
+ formModel = (0, FormUtils_1.sitesModelToFormModel)(formModel);
53
+ f = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default(), new EventQueue_1.default(new Logger_1.Logger(logLevel)), logLevel);
54
+ }
55
+ const formData = formModel === null || formModel === void 0 ? void 0 : formModel.data;
56
+ if (formData) {
57
+ f.importData(formData);
58
+ }
59
+ return f;
60
+ };
40
61
  const createFormInstance = (formModel, callback, logLevel = 'error', fModel = undefined) => {
41
62
  try {
42
- let f = fModel;
43
- {
44
- if (f == null) {
45
- formModel = (0, FormUtils_1.sitesModelToFormModel)(formModel);
46
- f = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default(), new EventQueue_1.default(new Logger_1.Logger(logLevel)), logLevel);
47
- }
48
- }
49
- const formData = formModel === null || formModel === void 0 ? void 0 : formModel.data;
50
- if (formData) {
51
- f.importData(formData);
52
- }
63
+ const f = createFormInstanceHelper(formModel, logLevel, fModel);
53
64
  if (typeof callback === 'function') {
54
65
  callback(f);
55
66
  }
@@ -62,6 +73,22 @@ const createFormInstance = (formModel, callback, logLevel = 'error', fModel = un
62
73
  }
63
74
  };
64
75
  exports.createFormInstance = createFormInstance;
76
+ const createFormInstanceSync = (formModel, callback, logLevel = 'error', fModel = undefined) => __awaiter(void 0, void 0, void 0, function* () {
77
+ try {
78
+ const f = createFormInstanceHelper(formModel, logLevel, fModel);
79
+ if (typeof callback === 'function') {
80
+ callback(f);
81
+ }
82
+ f.getEventQueue().runPendingQueue();
83
+ yield f.waitForPromises();
84
+ return f;
85
+ }
86
+ catch (e) {
87
+ console.error(`Unable to create an instance of the Form ${e}`);
88
+ throw new Error(e);
89
+ }
90
+ });
91
+ exports.createFormInstanceSync = createFormInstanceSync;
65
92
  exports.createFormInstance.currentVersion = Form_1.currentVersion;
66
93
  const defaultOptions = {
67
94
  logLevel: 'error'
package/lib/Scriptable.js CHANGED
@@ -141,6 +141,9 @@ class Scriptable extends BaseNode_1.BaseNode {
141
141
  let updates;
142
142
  if (node) {
143
143
  updates = this.ruleEngine.execute(node, this.getExpressionScope(), context, false, eString);
144
+ if (updates instanceof Promise) {
145
+ this.form.addPromises(updates);
146
+ }
144
147
  }
145
148
  if (typeof updates !== 'undefined' && updates != null) {
146
149
  this.applyUpdates(updates);
package/lib/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './controller/Events';
4
4
  export * from './utils/TranslationUtils';
5
5
  export * from './utils/JsonUtils';
6
6
  export * from './utils/SchemaUtils';
7
+ export * from './Constant';
7
8
  import { getFileSizeInBytes, extractFileInfo, isEmpty, readAttachments } from './utils/FormUtils';
8
9
  import { BaseNode } from './BaseNode';
9
10
  import Checkbox from './Checkbox';
package/lib/index.js CHANGED
@@ -24,6 +24,7 @@ __exportStar(require("./controller/Events"), exports);
24
24
  __exportStar(require("./utils/TranslationUtils"), exports);
25
25
  __exportStar(require("./utils/JsonUtils"), exports);
26
26
  __exportStar(require("./utils/SchemaUtils"), exports);
27
+ __exportStar(require("./Constant"), exports);
27
28
  const FormUtils_1 = require("./utils/FormUtils");
28
29
  Object.defineProperty(exports, "getFileSizeInBytes", { enumerable: true, get: function () { return FormUtils_1.getFileSizeInBytes; } });
29
30
  Object.defineProperty(exports, "extractFileInfo", { enumerable: true, get: function () { return FormUtils_1.extractFileInfo; } });
@@ -45,7 +45,7 @@ declare class FunctionRuntimeImpl {
45
45
  _signature: never[];
46
46
  };
47
47
  request: {
48
- _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
48
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<void>;
49
49
  _signature: never[];
50
50
  };
51
51
  awaitFn: {
@@ -447,8 +447,7 @@ class FunctionRuntimeImpl {
447
447
  success = valueOf(args[4]);
448
448
  error = valueOf(args[5]);
449
449
  }
450
- (0, exports.request)(interpreter.globals, uri, httpVerb, payload, success, error, headers);
451
- return {};
450
+ return (0, exports.request)(interpreter.globals, uri, httpVerb, payload, success, error, headers);
452
451
  },
453
452
  _signature: []
454
453
  },
@@ -104,7 +104,7 @@ export declare type FieldJson = BaseJson & TranslationFieldJson & {
104
104
  export declare type CaptchaJson = FieldJson & {
105
105
  captchaDisplayMode?: CaptchaDisplayMode | undefined;
106
106
  captchaProvider?: string | undefined;
107
- siteKey?: string | undefined;
107
+ captchaSiteKey?: string | undefined;
108
108
  };
109
109
  export declare type ContainerJson = BaseJson & {
110
110
  items: Array<FieldJson | ContainerJson>;
@@ -132,6 +132,8 @@ export interface FormModel extends ContainerModel, WithState<FormJson> {
132
132
  resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
133
133
  fieldAdded(field: FieldModel | FieldsetModel): void;
134
134
  readonly changeEventBehaviour: 'deps' | 'self';
135
+ addPromises(updates: Promise<any>): void;
136
+ waitForPromises(): any;
135
137
  }
136
138
  export interface IFormFieldFactory {
137
139
  createField(child: FieldsetJson | FieldJson, options: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.110",
3
+ "version": "0.22.112",
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.110"
40
+ "@aemforms/af-formatters": "^0.22.112"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",