@aemforms/af-core 0.22.19 → 0.22.22

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.
Files changed (124) hide show
  1. package/LICENSE +18 -4
  2. package/lib/cjs/index.cjs +7277 -0
  3. package/lib/{BaseNode.js → esm/BaseNode-dc59ab07.js} +108 -184
  4. package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +10 -69
  5. package/lib/esm/BaseNode.js +26 -0
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +63 -0
  8. package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
  9. package/lib/esm/CheckboxGroup.js +60 -0
  10. package/lib/{Container.d.ts → esm/Container.d.ts} +12 -59
  11. package/lib/{Container.js → esm/Container.js} +81 -122
  12. package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
  13. package/lib/esm/DateField.js +57 -0
  14. package/lib/{Field.d.ts → esm/Field.d.ts} +41 -106
  15. package/lib/{Field.js → esm/Field.js} +186 -216
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +78 -0
  18. package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
  19. package/lib/esm/FileObject.js +48 -0
  20. package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
  21. package/lib/esm/FileUpload.js +141 -0
  22. package/lib/{Form.d.ts → esm/Form.d.ts} +20 -86
  23. package/lib/esm/Form.js +208 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +129 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +35 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +58 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +40 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/{Scriptable.js → esm/Scriptable.js} +38 -54
  34. package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
  35. package/lib/{controller → esm/controller}/EventQueue.js +32 -26
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +171 -0
  38. package/lib/{controller → esm/controller}/Logger.d.ts +2 -8
  39. package/lib/esm/controller/Logger.js +52 -0
  40. package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
  41. package/lib/{data → esm/data}/DataGroup.js +38 -34
  42. package/lib/{data → esm/data}/DataValue.d.ts +1 -7
  43. package/lib/esm/data/DataValue.js +68 -0
  44. package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
  45. package/lib/esm/data/EmptyDataValue.js +51 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +55 -0
  48. package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +3 -25
  49. package/lib/{rules → esm/rules}/FunctionRuntime.js +66 -117
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +76 -0
  52. package/lib/esm/types/Json.d.ts +119 -0
  53. package/lib/esm/types/Json.js +29 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +30 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +22 -0
  58. package/lib/{utils → esm/utils}/DataRefParser.d.ts +4 -7
  59. package/lib/{utils → esm/utils}/DataRefParser.js +42 -44
  60. package/lib/{utils → esm/utils}/Fetch.d.ts +1 -7
  61. package/lib/esm/utils/Fetch.js +83 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +112 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +212 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +99 -0
  68. package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
  69. package/lib/esm/utils/LogUtils.js +28 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +93 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +138 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/{utils → esm/utils}/ValidationUtils.js +55 -187
  76. package/package.json +18 -10
  77. package/lib/Checkbox.d.ts +0 -88
  78. package/lib/Checkbox.js +0 -49
  79. package/lib/CheckboxGroup.js +0 -43
  80. package/lib/DateField.js +0 -35
  81. package/lib/Fieldset.d.ts +0 -24
  82. package/lib/Fieldset.js +0 -74
  83. package/lib/FileObject.js +0 -39
  84. package/lib/FileUpload.js +0 -155
  85. package/lib/Form.js +0 -252
  86. package/lib/FormInstance.d.ts +0 -38
  87. package/lib/FormInstance.js +0 -127
  88. package/lib/FormMetaData.d.ts +0 -11
  89. package/lib/FormMetaData.js +0 -28
  90. package/lib/InstanceManager.d.ts +0 -16
  91. package/lib/InstanceManager.js +0 -53
  92. package/lib/Node.d.ts +0 -12
  93. package/lib/Node.js +0 -27
  94. package/lib/Scriptable.d.ts +0 -31
  95. package/lib/controller/Controller.d.ts +0 -255
  96. package/lib/controller/Controller.js +0 -328
  97. package/lib/controller/Logger.js +0 -36
  98. package/lib/controller/index.d.ts +0 -1
  99. package/lib/controller/index.js +0 -24
  100. package/lib/data/DataValue.js +0 -56
  101. package/lib/data/EmptyDataValue.js +0 -46
  102. package/lib/index.d.ts +0 -28
  103. package/lib/index.js +0 -63
  104. package/lib/rules/RuleEngine.d.ts +0 -23
  105. package/lib/rules/RuleEngine.js +0 -62
  106. package/lib/types/Json.d.ts +0 -138
  107. package/lib/types/Json.js +0 -19
  108. package/lib/types/Model.d.ts +0 -393
  109. package/lib/types/Model.js +0 -20
  110. package/lib/types/index.d.ts +0 -2
  111. package/lib/types/index.js +0 -25
  112. package/lib/utils/Fetch.js +0 -87
  113. package/lib/utils/FormCreationUtils.d.ts +0 -11
  114. package/lib/utils/FormCreationUtils.js +0 -83
  115. package/lib/utils/FormUtils.d.ts +0 -47
  116. package/lib/utils/FormUtils.js +0 -257
  117. package/lib/utils/JsonUtils.d.ts +0 -63
  118. package/lib/utils/JsonUtils.js +0 -157
  119. package/lib/utils/LogUtils.js +0 -17
  120. package/lib/utils/SchemaUtils.d.ts +0 -16
  121. package/lib/utils/SchemaUtils.js +0 -92
  122. package/lib/utils/TranslationUtils.d.ts +0 -41
  123. package/lib/utils/TranslationUtils.js +0 -185
  124. package/lib/utils/ValidationUtils.d.ts +0 -170
@@ -1,31 +1,31 @@
1
- "use strict";
2
- /*
3
- * Copyright 2022 Adobe, Inc.
4
- *
5
- * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
6
- *
7
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
- */
9
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
- return new (P || (P = Promise))(function (resolve, reject) {
12
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15
- step((generator = generator.apply(thisArg, _arguments || [])).next());
16
- });
17
- };
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.FunctionRuntime = exports.submit = exports.request = void 0;
20
- /**
21
- * Implementation of function runtime in rule engine
22
- */
23
- //import {jsonString} from '../utils/JsonUtils';
24
- const Controller_1 = require("../controller/Controller");
25
- const Fetch_1 = require("../utils/Fetch");
26
- const FileObject_1 = require("../FileObject");
27
- const FormUtils_1 = require("../utils/FormUtils");
28
- const JsonUtils_1 = require("../utils/JsonUtils");
1
+ /*************************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * ___________________
4
+ *
5
+ * Copyright 2022 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+
17
+ * Adobe permits you to use and modify this file solely in accordance with
18
+ * the terms of the Adobe license agreement accompanying it.
19
+ *************************************************************************/
20
+
21
+ import { CustomEvent, Submit, RemoveInstance, AddInstance, Reset, RemoveItem, AddItem, Click, Change } from '../controller/Events.js';
22
+ import { request as request$1 } from '../utils/Fetch.js';
23
+ import { FileObject } from '../FileObject.js';
24
+ import { getAttachments } from '../utils/FormUtils.js';
25
+ import { jsonString } from '../utils/JsonUtils.js';
26
+ import '../types/Json.js';
27
+ import '../utils/SchemaUtils.js';
28
+
29
29
  const getCustomEventName = (name) => {
30
30
  const eName = name;
31
31
  if (eName.length > 0 && eName.startsWith('custom:')) {
@@ -33,19 +33,7 @@ const getCustomEventName = (name) => {
33
33
  }
34
34
  return eName;
35
35
  };
36
- /**
37
- * Implementation of generic request API. This API can be used to make external web request
38
- * @param context expression execution context(consists of current form, current field, current event)
39
- * @param uri request URI
40
- * @param httpVerb http verb (for example, GET or POST)
41
- * @param payload request payload
42
- * @param success success handler
43
- * @param error error handler
44
- * @param headers headers
45
- * @private
46
- */
47
- const request = (context, uri, httpVerb, payload, success, error, headers) => __awaiter(void 0, void 0, void 0, function* () {
48
- var _a;
36
+ const request = async (context, uri, httpVerb, payload, success, error, headers) => {
49
37
  const endpoint = uri;
50
38
  const requestOptions = {
51
39
  method: httpVerb
@@ -53,8 +41,7 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
53
41
  let result;
54
42
  let inputPayload;
55
43
  try {
56
- if (payload && payload instanceof FileObject_1.FileObject && payload.data instanceof File) {
57
- // todo: have to implement array type
44
+ if (payload && payload instanceof FileObject && payload.data instanceof File) {
58
45
  const formData = new FormData();
59
46
  formData.append(payload.name, payload.data);
60
47
  inputPayload = formData;
@@ -65,13 +52,15 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
65
52
  else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
66
53
  const headerNames = Object.keys(headers);
67
54
  if (headerNames.length > 0) {
68
- requestOptions.headers = Object.assign(Object.assign({}, headers), (headerNames.indexOf('Content-Type') === -1 ? { 'Content-Type': 'application/json' } : {}) // this should match content type of the payload
69
- );
55
+ requestOptions.headers = {
56
+ ...headers,
57
+ ...(headerNames.indexOf('Content-Type') === -1 ? { 'Content-Type': 'application/json' } : {})
58
+ };
70
59
  }
71
60
  else {
72
61
  requestOptions.headers = { 'Content-Type': 'application/json' };
73
62
  }
74
- const contentType = ((_a = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) || 'application/json';
63
+ const contentType = requestOptions?.headers?.['Content-Type'] || 'application/json';
75
64
  if (contentType === 'application/json') {
76
65
  inputPayload = JSON.stringify(payload);
77
66
  }
@@ -82,24 +71,22 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
82
71
  inputPayload = urlEncoded(payload);
83
72
  }
84
73
  }
85
- result = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
74
+ result = await request$1(endpoint, inputPayload, requestOptions);
86
75
  }
87
76
  catch (e) {
88
- //todo: define error payload
89
77
  context.form.logger.error('Error invoking a rest API');
90
78
  const eName = getCustomEventName(error);
91
- context.form.dispatch(new Controller_1.CustomEvent(eName, {}, true));
79
+ context.form.dispatch(new CustomEvent(eName, {}, true));
92
80
  return;
93
81
  }
94
82
  const eName = getCustomEventName(success);
95
- context.form.dispatch(new Controller_1.CustomEvent(eName, result, true));
96
- });
97
- exports.request = request;
83
+ context.form.dispatch(new CustomEvent(eName, result, true));
84
+ };
98
85
  const urlEncoded = (data) => {
99
86
  const formData = new URLSearchParams();
100
87
  Object.entries(data).forEach(([key, value]) => {
101
88
  if (value != null && typeof value === 'object') {
102
- formData.append(key, (0, JsonUtils_1.jsonString)(value));
89
+ formData.append(key, jsonString(value));
103
90
  }
104
91
  else {
105
92
  formData.append(key, value);
@@ -107,26 +94,19 @@ const urlEncoded = (data) => {
107
94
  });
108
95
  return formData;
109
96
  };
110
- /**
111
- * Create multi part form data using form data and form attachments
112
- * @param data form data
113
- * @param attachments form events
114
- * @private
115
- */
116
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
117
97
  const multipartFormData = (data, attachments) => {
118
98
  const formData = new FormData();
119
99
  Object.entries(data).forEach(([key, value]) => {
120
100
  if (value != null && typeof value === 'object') {
121
- formData.append(key, (0, JsonUtils_1.jsonString)(value));
101
+ formData.append(key, jsonString(value));
122
102
  }
123
103
  else {
124
104
  formData.append(key, value);
125
105
  }
126
106
  });
127
107
  const addAttachmentToFormData = (objValue, formData) => {
128
- if ((objValue === null || objValue === void 0 ? void 0 : objValue.data) instanceof File) {
129
- let attIdentifier = `${objValue === null || objValue === void 0 ? void 0 : objValue.dataRef}/${objValue === null || objValue === void 0 ? void 0 : objValue.name}`;
108
+ if (objValue?.data instanceof File) {
109
+ let attIdentifier = `${objValue?.dataRef}/${objValue?.name}`;
130
110
  if (!attIdentifier.startsWith('/')) {
131
111
  attIdentifier = `/${attIdentifier}`;
132
112
  }
@@ -134,7 +114,6 @@ const multipartFormData = (data, attachments) => {
134
114
  }
135
115
  };
136
116
  if (attachments) {
137
- // @ts-ignore
138
117
  Object.keys(attachments).reduce((acc, curr) => {
139
118
  const objValue = attachments[curr];
140
119
  if (objValue && objValue instanceof Array) {
@@ -147,75 +126,54 @@ const multipartFormData = (data, attachments) => {
147
126
  }
148
127
  return formData;
149
128
  };
150
- const submit = (context, success, error, submitAs = 'multipart/form-data', input_data = null) => __awaiter(void 0, void 0, void 0, function* () {
129
+ const submit = async (context, success, error, submitAs = 'multipart/form-data', input_data = null) => {
151
130
  const endpoint = context.form.action;
152
131
  let data = input_data;
153
132
  if (typeof data != 'object' || data == null) {
154
133
  data = context.form.exportData();
155
134
  }
156
- // todo: have to implement sending of attachments here
157
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
158
- const attachments = (0, FormUtils_1.getAttachments)(context.form);
135
+ const attachments = getAttachments(context.form);
159
136
  let submitContentType = submitAs;
160
- let formData;
137
+ const submitDataAndMetaData = { 'data': data, 'submitMetadata': { 'lang': context.form.lang } };
138
+ let formData = submitDataAndMetaData;
161
139
  if (Object.keys(attachments).length > 0 || submitAs === 'multipart/form-data') {
162
- formData = multipartFormData({ 'data': data }, attachments);
140
+ formData = multipartFormData(submitDataAndMetaData, attachments);
163
141
  submitContentType = 'multipart/form-data';
164
142
  }
165
- else {
166
- formData = { 'data': data };
167
- }
168
- // submitContentType = submitAs;
169
- // note: don't send multipart/form-data let browser decide on the content type
170
- yield (0, exports.request)(context, endpoint, 'POST', formData, success, error, {
143
+ await request(context, endpoint, 'POST', formData, success, error, {
171
144
  'Content-Type': submitContentType
172
145
  });
173
- });
174
- exports.submit = submit;
175
- /**
176
- * Helper function to create an action
177
- * @param name name of the event
178
- * @param payload event payload
179
- * @param dispatch true to trigger the event on all the fields in DFS order starting from the top level form element, false otherwise
180
- * @private
181
- */
146
+ };
182
147
  const createAction = (name, payload = {}) => {
183
148
  switch (name) {
184
149
  case 'change':
185
- return new Controller_1.Change(payload);
150
+ return new Change(payload);
186
151
  case 'submit':
187
- return new Controller_1.Submit(payload);
152
+ return new Submit(payload);
188
153
  case 'click':
189
- return new Controller_1.Click(payload);
154
+ return new Click(payload);
190
155
  case 'addItem':
191
- return new Controller_1.AddItem(payload);
156
+ return new AddItem(payload);
192
157
  case 'removeItem':
193
- return new Controller_1.RemoveItem(payload);
158
+ return new RemoveItem(payload);
194
159
  case 'reset':
195
- return new Controller_1.Reset(payload);
160
+ return new Reset(payload);
196
161
  case 'addInstance':
197
- return new Controller_1.AddInstance(payload);
162
+ return new AddInstance(payload);
198
163
  case 'removeInstance':
199
- return new Controller_1.RemoveInstance(payload);
164
+ return new RemoveInstance(payload);
200
165
  default:
201
166
  console.error('invalid action');
202
167
  }
203
168
  };
204
- /**
205
- * Implementation of function runtime
206
- * @private
207
- */
208
169
  class FunctionRuntimeImpl {
209
- constructor() {
210
- this.customFunctions = {};
211
- }
170
+ customFunctions = {};
212
171
  registerFunctions(functions) {
213
172
  Object.entries(functions).forEach(([name, funcDef]) => {
214
173
  let finalFunction = funcDef;
215
174
  if (typeof funcDef === 'function') {
216
175
  finalFunction = {
217
176
  _func: (args) => {
218
- // eslint-disable-next-line @typescript-eslint/ban-types
219
177
  return funcDef(...args);
220
178
  },
221
179
  _signature: []
@@ -236,7 +194,6 @@ class FunctionRuntimeImpl {
236
194
  });
237
195
  }
238
196
  getFunctions() {
239
- // todo: remove these once json-formula exposes a way to call them from custom functions
240
197
  function isArray(obj) {
241
198
  if (obj !== null) {
242
199
  return Object.prototype.toString.call(obj) === '[object Array]';
@@ -291,7 +248,6 @@ class FunctionRuntimeImpl {
291
248
  },
292
249
  getData: {
293
250
  _func: (args, data, interpreter) => {
294
- // deprecated. left for backward compatability.
295
251
  interpreter.globals.form.logger.warn('The `getData` function is depricated. Use `exportData` instead.');
296
252
  return interpreter.globals.form.exportData();
297
253
  },
@@ -315,12 +271,11 @@ class FunctionRuntimeImpl {
315
271
  },
316
272
  submitForm: {
317
273
  _func: (args, data, interpreter) => {
318
- // success: string, error: string, submit_as: 'json' | 'multipart' = 'json', data: any = null
319
274
  const success = toString(args[0]);
320
275
  const error = toString(args[1]);
321
276
  const submit_as = args.length > 2 ? toString(args[2]) : 'multipart/form-data';
322
277
  const submit_data = args.length > 3 ? valueOf(args[3]) : null;
323
- interpreter.globals.form.dispatch(new Controller_1.Submit({
278
+ interpreter.globals.form.dispatch(new Submit({
324
279
  success,
325
280
  error,
326
281
  submit_as,
@@ -330,7 +285,6 @@ class FunctionRuntimeImpl {
330
285
  },
331
286
  _signature: []
332
287
  },
333
- // todo: only supports application/json for now
334
288
  request: {
335
289
  _func: (args, data, interpreter) => {
336
290
  const uri = toString(args[0]);
@@ -347,18 +301,11 @@ class FunctionRuntimeImpl {
347
301
  success = valueOf(args[4]);
348
302
  error = valueOf(args[5]);
349
303
  }
350
- (0, exports.request)(interpreter.globals, uri, httpVerb, payload, success, error, headers);
304
+ request(interpreter.globals, uri, httpVerb, payload, success, error, headers);
351
305
  return {};
352
306
  },
353
307
  _signature: []
354
308
  },
355
- /**
356
- *
357
- * @name dispatchEvent
358
- * @param [element] element on which to trigger the event. If not defined the event will be triggered on entire form
359
- * @param eventName name of the event to trigger
360
- * @param payload payload to pass in the event
361
- */
362
309
  dispatchEvent: {
363
310
  _func: (args, data, interpreter) => {
364
311
  const element = args[0];
@@ -372,7 +319,7 @@ class FunctionRuntimeImpl {
372
319
  }
373
320
  let event;
374
321
  if (eventName.startsWith('custom:')) {
375
- event = new Controller_1.CustomEvent(eventName.substring('custom:'.length), payload, dispatch);
322
+ event = new CustomEvent(eventName.substring('custom:'.length), payload, dispatch);
376
323
  }
377
324
  else {
378
325
  event = createAction(eventName, payload);
@@ -390,7 +337,9 @@ class FunctionRuntimeImpl {
390
337
  _signature: []
391
338
  }
392
339
  };
393
- return Object.assign(Object.assign({}, defaultFunctions), this.customFunctions);
340
+ return { ...defaultFunctions, ...this.customFunctions };
394
341
  }
395
342
  }
396
- exports.FunctionRuntime = new FunctionRuntimeImpl();
343
+ const FunctionRuntime = new FunctionRuntimeImpl();
344
+
345
+ export { FunctionRuntime, request, submit };
@@ -0,0 +1,12 @@
1
+ import { BaseModel } from '../types/index.js';
2
+ declare class RuleEngine {
3
+ private _context;
4
+ private _globalNames;
5
+ private formulaEngine;
6
+ private debugInfo;
7
+ constructor();
8
+ compileRule(rule: string): any;
9
+ execute(node: any, data: any, globals: any, useValueOf?: boolean): any;
10
+ trackDependency(subscriber: BaseModel): void;
11
+ }
12
+ export default RuleEngine;
@@ -0,0 +1,76 @@
1
+ /*************************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * ___________________
4
+ *
5
+ * Copyright 2022 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+
17
+ * Adobe permits you to use and modify this file solely in accordance with
18
+ * the terms of the Adobe license agreement accompanying it.
19
+ *************************************************************************/
20
+
21
+ import Formula from '@adobe/json-formula';
22
+ import { FunctionRuntime } from './FunctionRuntime.js';
23
+ import '../controller/Events.js';
24
+ import '../utils/Fetch.js';
25
+ import '../FileObject.js';
26
+ import '../utils/FormUtils.js';
27
+ import '../utils/JsonUtils.js';
28
+ import '../types/Json.js';
29
+ import '../utils/SchemaUtils.js';
30
+
31
+ class RuleEngine {
32
+ _context;
33
+ _globalNames = [
34
+ '$form',
35
+ '$field',
36
+ '$event'
37
+ ];
38
+ formulaEngine;
39
+ debugInfo = [];
40
+ constructor() {
41
+ const customFunctions = FunctionRuntime.getFunctions();
42
+ this.formulaEngine = new Formula(customFunctions, undefined, this.debugInfo);
43
+ }
44
+ compileRule(rule) {
45
+ return this.formulaEngine.compile(rule, this._globalNames);
46
+ }
47
+ execute(node, data, globals, useValueOf = false) {
48
+ const oldContext = this._context;
49
+ this._context = globals;
50
+ let res = undefined;
51
+ try {
52
+ res = this.formulaEngine.run(node, data, 'en-US', globals);
53
+ }
54
+ catch (err) {
55
+ this._context?.form?.logger?.error(err);
56
+ }
57
+ while (this.debugInfo.length > 0) {
58
+ this._context?.form?.logger?.debug(this.debugInfo.pop());
59
+ }
60
+ let finalRes = res;
61
+ if (useValueOf) {
62
+ if (typeof res === 'object' && res !== null) {
63
+ finalRes = Object.getPrototypeOf(res).valueOf.call(res);
64
+ }
65
+ }
66
+ this._context = oldContext;
67
+ return finalRes;
68
+ }
69
+ trackDependency(subscriber) {
70
+ if (this._context && this._context.field !== undefined && this._context.field !== subscriber) {
71
+ subscriber._addDependent(this._context.field);
72
+ }
73
+ }
74
+ }
75
+
76
+ export { RuleEngine as default };
@@ -0,0 +1,119 @@
1
+ export type Items<T> = {
2
+ [key: string]: T;
3
+ };
4
+ export type Primitives = string | number | boolean | null | undefined;
5
+ export type Label = {
6
+ value: string;
7
+ richText?: boolean;
8
+ visible?: boolean;
9
+ };
10
+ type TranslationConstraintsJson = {
11
+ enumNames?: string[];
12
+ enum?: any[];
13
+ };
14
+ export type ConstraintsJson = TranslationConstraintsJson & {
15
+ accept?: string[];
16
+ enforceEnum?: boolean;
17
+ exclusiveMinimum?: number;
18
+ exclusiveMaximum?: number;
19
+ format?: string;
20
+ maxFileSize?: number | string;
21
+ maxLength?: number;
22
+ maximum?: number;
23
+ maxItems?: number;
24
+ minOccur?: number;
25
+ maxOccur?: number;
26
+ minLength?: number;
27
+ minimum?: number;
28
+ minItems?: number;
29
+ pattern?: string;
30
+ required?: boolean;
31
+ step?: number;
32
+ type?: string;
33
+ validationExpression?: string;
34
+ uniqueItems?: boolean;
35
+ };
36
+ export type ConstraintsMessages = {
37
+ accept?: string;
38
+ enum?: string;
39
+ exclusiveMinimum?: string;
40
+ exclusiveMaximum?: string;
41
+ format?: string;
42
+ maxFileSize?: string;
43
+ maxLength?: string;
44
+ maximum?: string;
45
+ maxItems?: string;
46
+ minLength?: string;
47
+ minimum?: string;
48
+ minItems?: string;
49
+ uniqueItems?: string;
50
+ pattern?: string;
51
+ required?: string;
52
+ step?: string;
53
+ type?: string;
54
+ validationExpression?: string;
55
+ };
56
+ export type RulesJson = {
57
+ rules?: Items<string>;
58
+ events?: Items<string[] | string | undefined>;
59
+ };
60
+ type TranslationBaseJson = {
61
+ description?: string;
62
+ };
63
+ export type BaseJson = TranslationBaseJson & RulesJson & ConstraintsJson & {
64
+ dataRef?: string | null;
65
+ ':type'?: string;
66
+ label?: Label;
67
+ enabled?: boolean;
68
+ visible?: boolean;
69
+ name?: string;
70
+ constraintMessages?: ConstraintsMessages;
71
+ fieldType?: string;
72
+ errorMessage?: string;
73
+ properties?: {
74
+ [key: string]: any;
75
+ };
76
+ repeatable?: boolean;
77
+ screenReaderText?: string;
78
+ tooltip?: string;
79
+ altText?: string;
80
+ viewType?: string;
81
+ };
82
+ type TranslationFieldJson = {
83
+ placeholder?: string;
84
+ };
85
+ export type FieldJson = BaseJson & TranslationFieldJson & {
86
+ readOnly?: boolean;
87
+ valid?: boolean;
88
+ default?: any;
89
+ value?: any;
90
+ displayFormat?: string;
91
+ editFormat?: string;
92
+ editValue?: string;
93
+ displayValue?: string;
94
+ emptyValue?: 'null' | 'undefined' | '';
95
+ };
96
+ export type ContainerJson = BaseJson & {
97
+ items: Array<FieldJson | ContainerJson>;
98
+ initialItems?: number;
99
+ activeChild?: string;
100
+ };
101
+ export type MetaDataJson = {
102
+ version?: string;
103
+ grammar?: string;
104
+ };
105
+ export type FieldsetJson = ContainerJson & {
106
+ 'type'?: 'array' | 'object';
107
+ };
108
+ export type FormJson = ContainerJson & {
109
+ metadata?: MetaDataJson;
110
+ data?: any;
111
+ title?: string;
112
+ action?: string;
113
+ adaptiveForm?: string;
114
+ lang?: string;
115
+ };
116
+ export type TranslationJson = TranslationBaseJson & TranslationFieldJson & TranslationConstraintsJson;
117
+ export declare const translationProps: string[];
118
+ export declare const constraintProps: string[];
119
+ export {};
@@ -0,0 +1,29 @@
1
+ /*************************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * ___________________
4
+ *
5
+ * Copyright 2022 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+
17
+ * Adobe permits you to use and modify this file solely in accordance with
18
+ * the terms of the Adobe license agreement accompanying it.
19
+ *************************************************************************/
20
+
21
+ const translationProps = ['description', 'placeholder', 'enum', 'enumNames', 'label.value', 'constraintMessages.accept',
22
+ 'constraintMessages.enum', 'constraintMessages.exclusiveMinimum', 'constraintMessages.exclusiveMaximum', 'constraintMessages.format', 'constraintMessages.maxFileSize', 'constraintMessages.maxLength',
23
+ 'constraintMessages.maximum', 'constraintMessages.maxItems', 'constraintMessages.minLength', 'constraintMessages.minimum', 'constraintMessages.minItems', 'constraintMessages.pattern', 'constraintMessages.required',
24
+ 'constraintMessages.step', 'constraintMessages.type', 'constraintMessages.validationExpression'];
25
+ const constraintProps = ['accept', 'enum', 'exclusiveMinimum', 'exclusiveMaximum',
26
+ 'format', 'maxFileSize', 'maxLength', 'maximum', 'maxItems',
27
+ 'minLength', 'minimum', 'minItems', 'pattern', 'required', 'step', 'validationExpression', 'enumNames'];
28
+
29
+ export { constraintProps, translationProps };