@aemforms/af-core 0.22.158 → 0.22.162
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/README.md +18 -0
- package/esm/afb-runtime.js +77 -4
- package/esm/types/src/Field.d.ts +1 -0
- package/esm/types/src/rules/FunctionRuntime.d.ts +4 -0
- package/lib/BaseNode.js +2 -1
- package/lib/DateField.js +18 -0
- package/lib/Field.d.ts +1 -0
- package/lib/Field.js +5 -1
- package/lib/rules/FunctionRuntime.d.ts +4 -0
- package/lib/rules/FunctionRuntime.js +52 -1
- package/lib/utils/DataRefParser.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,6 +33,24 @@ const data = {...}
|
|
|
33
33
|
const valid = validateFormInstance(formJson, data)
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
## Testing Local Changes
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Login to download dependencies
|
|
40
|
+
npm login
|
|
41
|
+
|
|
42
|
+
# Build the package
|
|
43
|
+
npm run build
|
|
44
|
+
|
|
45
|
+
# Link it for local testing
|
|
46
|
+
npm link
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
In your project that uses this package:
|
|
50
|
+
```bash
|
|
51
|
+
npm link @aemforms/af-core
|
|
52
|
+
```
|
|
53
|
+
|
|
36
54
|
## License
|
|
37
55
|
|
|
38
56
|
Copyright 2022 Adobe
|
package/esm/afb-runtime.js
CHANGED
|
@@ -545,7 +545,7 @@ const isAlphaNum = function (ch) {
|
|
|
545
545
|
return (ch >= 'a' && ch <= 'z')
|
|
546
546
|
|| (ch >= 'A' && ch <= 'Z')
|
|
547
547
|
|| (ch >= '0' && ch <= '9')
|
|
548
|
-
|| ch === '_';
|
|
548
|
+
|| ch === '_' || ch === '-';
|
|
549
549
|
};
|
|
550
550
|
const isGlobal = (prev, stream, pos) => {
|
|
551
551
|
return prev === null && stream[pos] === globalStartToken;
|
|
@@ -560,7 +560,7 @@ const isIdentifier = (stream, pos) => {
|
|
|
560
560
|
}
|
|
561
561
|
return (ch >= 'a' && ch <= 'z')
|
|
562
562
|
|| (ch >= 'A' && ch <= 'Z')
|
|
563
|
-
|| ch === '_';
|
|
563
|
+
|| ch === '_' || ch === '-';
|
|
564
564
|
};
|
|
565
565
|
const isNum = (ch) => {
|
|
566
566
|
return (ch >= '0' && ch <= '9');
|
|
@@ -1366,7 +1366,8 @@ const editableProperties = [
|
|
|
1366
1366
|
'maxItems',
|
|
1367
1367
|
'minimum',
|
|
1368
1368
|
'minItems',
|
|
1369
|
-
'checked'
|
|
1369
|
+
'checked',
|
|
1370
|
+
'placeholder'
|
|
1370
1371
|
];
|
|
1371
1372
|
const dynamicProps = [
|
|
1372
1373
|
...editableProperties,
|
|
@@ -2934,6 +2935,9 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
|
|
|
2934
2935
|
if (payload.body && payload.headers) {
|
|
2935
2936
|
encryptOutput = { ...payload };
|
|
2936
2937
|
headers = { ...payload.headers };
|
|
2938
|
+
if (payload.options && typeof payload.options === 'object') {
|
|
2939
|
+
Object.assign(requestOptions, payload.options);
|
|
2940
|
+
}
|
|
2937
2941
|
payload = payload.body;
|
|
2938
2942
|
cryptoMetadata = payload.cryptoMetadata;
|
|
2939
2943
|
inputPayload = payload;
|
|
@@ -3226,6 +3230,47 @@ class FunctionRuntimeImpl {
|
|
|
3226
3230
|
filesMap[qualifiedName] = field.serialize();
|
|
3227
3231
|
}
|
|
3228
3232
|
return filesMap;
|
|
3233
|
+
},
|
|
3234
|
+
setVariable: (variableName, variableValue, target) => {
|
|
3235
|
+
const args = [variableName, variableValue, target];
|
|
3236
|
+
return FunctionRuntimeImpl.getInstance().getFunctions().setVariable._func.call(undefined, args, data, interpreter);
|
|
3237
|
+
},
|
|
3238
|
+
getVariable: (variableName, target) => {
|
|
3239
|
+
const args = [variableName, target];
|
|
3240
|
+
return FunctionRuntimeImpl.getInstance().getFunctions().getVariable._func.call(undefined, args, data, interpreter);
|
|
3241
|
+
},
|
|
3242
|
+
request: async (options) => {
|
|
3243
|
+
const { url, method = 'GET', body: requestBody = {}, headers = { 'Content-Type': 'application/json' }, options: fetchOptions } = options;
|
|
3244
|
+
const funcs = FunctionRuntimeImpl.getInstance().getFunctions();
|
|
3245
|
+
const externalizedUrl = funcs.externalize._func.call(undefined, [url], data, interpreter);
|
|
3246
|
+
const random = Math.floor(Math.random() * 1000000);
|
|
3247
|
+
const now = Date.now();
|
|
3248
|
+
const internalSuccess = `custom:__internalSuccess_${random}_${now}`;
|
|
3249
|
+
const internalError = `custom:__internalError_${random}_${now}`;
|
|
3250
|
+
const encryptPayload = { body: requestBody, headers };
|
|
3251
|
+
if (fetchOptions) {
|
|
3252
|
+
encryptPayload.options = fetchOptions;
|
|
3253
|
+
}
|
|
3254
|
+
const payload = await funcs.encrypt._func.call(undefined, [encryptPayload], data, interpreter);
|
|
3255
|
+
const requestArgs = [externalizedUrl, method, payload, internalSuccess, internalError];
|
|
3256
|
+
const requestFn = funcs.requestWithRetry._func.call(undefined, requestArgs, data, interpreter);
|
|
3257
|
+
const response = await funcs.retryHandler._func.call(undefined, [requestFn], data, interpreter);
|
|
3258
|
+
const isSuccess = response?.status >= 200 && response?.status <= 299;
|
|
3259
|
+
if (isSuccess && response?.body) {
|
|
3260
|
+
const decryptedBody = await funcs.decrypt._func.call(undefined, [response.body, response.originalRequest], data, interpreter);
|
|
3261
|
+
return {
|
|
3262
|
+
ok: true,
|
|
3263
|
+
status: response.status,
|
|
3264
|
+
body: decryptedBody,
|
|
3265
|
+
headers: response.headers
|
|
3266
|
+
};
|
|
3267
|
+
}
|
|
3268
|
+
return {
|
|
3269
|
+
ok: isSuccess,
|
|
3270
|
+
status: response?.status,
|
|
3271
|
+
body: response?.body,
|
|
3272
|
+
headers: response?.headers
|
|
3273
|
+
};
|
|
3229
3274
|
}
|
|
3230
3275
|
}
|
|
3231
3276
|
};
|
|
@@ -3549,6 +3594,13 @@ class FunctionRuntimeImpl {
|
|
|
3549
3594
|
},
|
|
3550
3595
|
_signature: []
|
|
3551
3596
|
},
|
|
3597
|
+
externalize: {
|
|
3598
|
+
_func: (args, data, interpreter) => {
|
|
3599
|
+
const url = toString(args[0]);
|
|
3600
|
+
return url;
|
|
3601
|
+
},
|
|
3602
|
+
_signature: []
|
|
3603
|
+
},
|
|
3552
3604
|
awaitFn: {
|
|
3553
3605
|
_func: async (args, data, interpreter) => {
|
|
3554
3606
|
const success = args[1];
|
|
@@ -4628,6 +4680,9 @@ class Field extends Scriptable {
|
|
|
4628
4680
|
get placeholder() {
|
|
4629
4681
|
return this._jsonModel.placeholder;
|
|
4630
4682
|
}
|
|
4683
|
+
set placeholder(value) {
|
|
4684
|
+
this._setProperty('placeholder', value);
|
|
4685
|
+
}
|
|
4631
4686
|
get readOnly() {
|
|
4632
4687
|
if (this.parent.readOnly !== undefined) {
|
|
4633
4688
|
return this.parent.readOnly === true ? true : this._jsonModel.readOnly;
|
|
@@ -4729,7 +4784,7 @@ class Field extends Scriptable {
|
|
|
4729
4784
|
}
|
|
4730
4785
|
get editValue() {
|
|
4731
4786
|
const df = this.editFormat;
|
|
4732
|
-
if (df && this.isNotEmpty(this.value) && this
|
|
4787
|
+
if (df && this.isNotEmpty(this.value) && this?.validity?.typeMismatch !== true) {
|
|
4733
4788
|
try {
|
|
4734
4789
|
return format(this.value, this.lang, df);
|
|
4735
4790
|
}
|
|
@@ -5439,6 +5494,20 @@ class CheckboxGroup extends Field {
|
|
|
5439
5494
|
}
|
|
5440
5495
|
}
|
|
5441
5496
|
|
|
5497
|
+
const warnedPatterns = new Set();
|
|
5498
|
+
function normalizeDatePattern(pattern) {
|
|
5499
|
+
if (!pattern || typeof pattern !== 'string') {
|
|
5500
|
+
return pattern;
|
|
5501
|
+
}
|
|
5502
|
+
const normalized = pattern
|
|
5503
|
+
.replace(/DD/g, 'dd')
|
|
5504
|
+
.replace(/YYYY/g, 'yyyy');
|
|
5505
|
+
if (normalized !== pattern && !warnedPatterns.has(pattern)) {
|
|
5506
|
+
warnedPatterns.add(pattern);
|
|
5507
|
+
console.warn(`[AEM Forms] Date field pattern "${pattern}" uses deprecated format. Auto-corrected to "${normalized}". Please update to use lowercase 'y' for year and 'd' for day.`);
|
|
5508
|
+
}
|
|
5509
|
+
return normalized;
|
|
5510
|
+
}
|
|
5442
5511
|
class DateField extends Field {
|
|
5443
5512
|
locale;
|
|
5444
5513
|
_dataFormat = 'yyyy-MM-dd';
|
|
@@ -5448,9 +5517,13 @@ class DateField extends Field {
|
|
|
5448
5517
|
if (!this._jsonModel.editFormat) {
|
|
5449
5518
|
this._jsonModel.editFormat = 'short';
|
|
5450
5519
|
}
|
|
5520
|
+
this._jsonModel.editFormat = normalizeDatePattern(this._jsonModel.editFormat);
|
|
5451
5521
|
if (!this._jsonModel.displayFormat) {
|
|
5452
5522
|
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
5453
5523
|
}
|
|
5524
|
+
else {
|
|
5525
|
+
this._jsonModel.displayFormat = normalizeDatePattern(this._jsonModel.displayFormat);
|
|
5526
|
+
}
|
|
5454
5527
|
if (!this._jsonModel.placeholder) {
|
|
5455
5528
|
this._jsonModel.placeholder = parseDateSkeleton(this._jsonModel.editFormat, this.locale);
|
|
5456
5529
|
}
|
package/esm/types/src/Field.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
32
32
|
get displayFormat(): string | undefined;
|
|
33
33
|
get displayValueExpression(): string | undefined;
|
|
34
34
|
get placeholder(): string | undefined;
|
|
35
|
+
set placeholder(value: string | undefined);
|
|
35
36
|
get readOnly(): boolean | undefined;
|
|
36
37
|
set readOnly(e: boolean | undefined);
|
|
37
38
|
get enabled(): boolean | undefined;
|
|
@@ -67,6 +67,10 @@ declare class FunctionRuntimeImpl {
|
|
|
67
67
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
|
|
68
68
|
_signature: never[];
|
|
69
69
|
};
|
|
70
|
+
externalize: {
|
|
71
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => string;
|
|
72
|
+
_signature: never[];
|
|
73
|
+
};
|
|
70
74
|
awaitFn: {
|
|
71
75
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<{}>;
|
|
72
76
|
_signature: never[];
|
package/lib/BaseNode.js
CHANGED
package/lib/DateField.js
CHANGED
|
@@ -11,6 +11,20 @@ var _DateField_instances, _DateField_convertNumberToDate;
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const Field_1 = __importDefault(require("./Field"));
|
|
13
13
|
const af_formatters_1 = require("@aemforms/af-formatters");
|
|
14
|
+
const warnedPatterns = new Set();
|
|
15
|
+
function normalizeDatePattern(pattern) {
|
|
16
|
+
if (!pattern || typeof pattern !== 'string') {
|
|
17
|
+
return pattern;
|
|
18
|
+
}
|
|
19
|
+
const normalized = pattern
|
|
20
|
+
.replace(/DD/g, 'dd')
|
|
21
|
+
.replace(/YYYY/g, 'yyyy');
|
|
22
|
+
if (normalized !== pattern && !warnedPatterns.has(pattern)) {
|
|
23
|
+
warnedPatterns.add(pattern);
|
|
24
|
+
console.warn(`[AEM Forms] Date field pattern "${pattern}" uses deprecated format. Auto-corrected to "${normalized}". Please update to use lowercase 'y' for year and 'd' for day.`);
|
|
25
|
+
}
|
|
26
|
+
return normalized;
|
|
27
|
+
}
|
|
14
28
|
class DateField extends Field_1.default {
|
|
15
29
|
constructor() {
|
|
16
30
|
super(...arguments);
|
|
@@ -23,9 +37,13 @@ class DateField extends Field_1.default {
|
|
|
23
37
|
if (!this._jsonModel.editFormat) {
|
|
24
38
|
this._jsonModel.editFormat = 'short';
|
|
25
39
|
}
|
|
40
|
+
this._jsonModel.editFormat = normalizeDatePattern(this._jsonModel.editFormat);
|
|
26
41
|
if (!this._jsonModel.displayFormat) {
|
|
27
42
|
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
28
43
|
}
|
|
44
|
+
else {
|
|
45
|
+
this._jsonModel.displayFormat = normalizeDatePattern(this._jsonModel.displayFormat);
|
|
46
|
+
}
|
|
29
47
|
if (!this._jsonModel.placeholder) {
|
|
30
48
|
this._jsonModel.placeholder = (0, af_formatters_1.parseDateSkeleton)(this._jsonModel.editFormat, this.locale);
|
|
31
49
|
}
|
package/lib/Field.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
32
32
|
get displayFormat(): string | undefined;
|
|
33
33
|
get displayValueExpression(): string | undefined;
|
|
34
34
|
get placeholder(): string | undefined;
|
|
35
|
+
set placeholder(value: string | undefined);
|
|
35
36
|
get readOnly(): boolean | undefined;
|
|
36
37
|
set readOnly(e: boolean | undefined);
|
|
37
38
|
get enabled(): boolean | undefined;
|
package/lib/Field.js
CHANGED
|
@@ -212,6 +212,9 @@ class Field extends Scriptable_1.default {
|
|
|
212
212
|
get placeholder() {
|
|
213
213
|
return this._jsonModel.placeholder;
|
|
214
214
|
}
|
|
215
|
+
set placeholder(value) {
|
|
216
|
+
this._setProperty('placeholder', value);
|
|
217
|
+
}
|
|
215
218
|
get readOnly() {
|
|
216
219
|
if (this.parent.readOnly !== undefined) {
|
|
217
220
|
return this.parent.readOnly === true ? true : this._jsonModel.readOnly;
|
|
@@ -311,8 +314,9 @@ class Field extends Scriptable_1.default {
|
|
|
311
314
|
return df;
|
|
312
315
|
}
|
|
313
316
|
get editValue() {
|
|
317
|
+
var _a;
|
|
314
318
|
const df = this.editFormat;
|
|
315
|
-
if (df && this.isNotEmpty(this.value) && this.
|
|
319
|
+
if (df && this.isNotEmpty(this.value) && ((_a = this === null || this === void 0 ? void 0 : this.validity) === null || _a === void 0 ? void 0 : _a.typeMismatch) !== true) {
|
|
316
320
|
try {
|
|
317
321
|
return (0, af_formatters_1.format)(this.value, this.lang, df);
|
|
318
322
|
}
|
|
@@ -67,6 +67,10 @@ declare class FunctionRuntimeImpl {
|
|
|
67
67
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
|
|
68
68
|
_signature: never[];
|
|
69
69
|
};
|
|
70
|
+
externalize: {
|
|
71
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => string;
|
|
72
|
+
_signature: never[];
|
|
73
|
+
};
|
|
70
74
|
awaitFn: {
|
|
71
75
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<{}>;
|
|
72
76
|
_signature: never[];
|
|
@@ -50,6 +50,9 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
|
|
|
50
50
|
if (payload.body && payload.headers) {
|
|
51
51
|
encryptOutput = Object.assign({}, payload);
|
|
52
52
|
headers = Object.assign({}, payload.headers);
|
|
53
|
+
if (payload.options && typeof payload.options === 'object') {
|
|
54
|
+
Object.assign(requestOptions, payload.options);
|
|
55
|
+
}
|
|
53
56
|
payload = payload.body;
|
|
54
57
|
cryptoMetadata = payload.cryptoMetadata;
|
|
55
58
|
inputPayload = payload;
|
|
@@ -329,7 +332,48 @@ class FunctionRuntimeImpl {
|
|
|
329
332
|
filesMap[qualifiedName] = field.serialize();
|
|
330
333
|
}
|
|
331
334
|
return filesMap;
|
|
332
|
-
}
|
|
335
|
+
},
|
|
336
|
+
setVariable: (variableName, variableValue, target) => {
|
|
337
|
+
const args = [variableName, variableValue, target];
|
|
338
|
+
return FunctionRuntimeImpl.getInstance().getFunctions().setVariable._func.call(undefined, args, data, interpreter);
|
|
339
|
+
},
|
|
340
|
+
getVariable: (variableName, target) => {
|
|
341
|
+
const args = [variableName, target];
|
|
342
|
+
return FunctionRuntimeImpl.getInstance().getFunctions().getVariable._func.call(undefined, args, data, interpreter);
|
|
343
|
+
},
|
|
344
|
+
request: (options) => __awaiter(this, void 0, void 0, function* () {
|
|
345
|
+
const { url, method = 'GET', body: requestBody = {}, headers = { 'Content-Type': 'application/json' }, options: fetchOptions } = options;
|
|
346
|
+
const funcs = FunctionRuntimeImpl.getInstance().getFunctions();
|
|
347
|
+
const externalizedUrl = funcs.externalize._func.call(undefined, [url], data, interpreter);
|
|
348
|
+
const random = Math.floor(Math.random() * 1000000);
|
|
349
|
+
const now = Date.now();
|
|
350
|
+
const internalSuccess = `custom:__internalSuccess_${random}_${now}`;
|
|
351
|
+
const internalError = `custom:__internalError_${random}_${now}`;
|
|
352
|
+
const encryptPayload = { body: requestBody, headers };
|
|
353
|
+
if (fetchOptions) {
|
|
354
|
+
encryptPayload.options = fetchOptions;
|
|
355
|
+
}
|
|
356
|
+
const payload = yield funcs.encrypt._func.call(undefined, [encryptPayload], data, interpreter);
|
|
357
|
+
const requestArgs = [externalizedUrl, method, payload, internalSuccess, internalError];
|
|
358
|
+
const requestFn = funcs.requestWithRetry._func.call(undefined, requestArgs, data, interpreter);
|
|
359
|
+
const response = yield funcs.retryHandler._func.call(undefined, [requestFn], data, interpreter);
|
|
360
|
+
const isSuccess = (response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) <= 299;
|
|
361
|
+
if (isSuccess && (response === null || response === void 0 ? void 0 : response.body)) {
|
|
362
|
+
const decryptedBody = yield funcs.decrypt._func.call(undefined, [response.body, response.originalRequest], data, interpreter);
|
|
363
|
+
return {
|
|
364
|
+
ok: true,
|
|
365
|
+
status: response.status,
|
|
366
|
+
body: decryptedBody,
|
|
367
|
+
headers: response.headers
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
ok: isSuccess,
|
|
372
|
+
status: response === null || response === void 0 ? void 0 : response.status,
|
|
373
|
+
body: response === null || response === void 0 ? void 0 : response.body,
|
|
374
|
+
headers: response === null || response === void 0 ? void 0 : response.headers
|
|
375
|
+
};
|
|
376
|
+
})
|
|
333
377
|
}
|
|
334
378
|
};
|
|
335
379
|
return funcDef(...args, globals);
|
|
@@ -647,6 +691,13 @@ class FunctionRuntimeImpl {
|
|
|
647
691
|
},
|
|
648
692
|
_signature: []
|
|
649
693
|
},
|
|
694
|
+
externalize: {
|
|
695
|
+
_func: (args, data, interpreter) => {
|
|
696
|
+
const url = toString(args[0]);
|
|
697
|
+
return url;
|
|
698
|
+
},
|
|
699
|
+
_signature: []
|
|
700
|
+
},
|
|
650
701
|
awaitFn: {
|
|
651
702
|
_func: (args, data, interpreter) => __awaiter(this, void 0, void 0, function* () {
|
|
652
703
|
const success = args[1];
|
|
@@ -49,7 +49,7 @@ const isAlphaNum = function (ch) {
|
|
|
49
49
|
return (ch >= 'a' && ch <= 'z')
|
|
50
50
|
|| (ch >= 'A' && ch <= 'Z')
|
|
51
51
|
|| (ch >= '0' && ch <= '9')
|
|
52
|
-
|| ch === '_';
|
|
52
|
+
|| ch === '_' || ch === '-';
|
|
53
53
|
};
|
|
54
54
|
const isGlobal = (prev, stream, pos) => {
|
|
55
55
|
return prev === null && stream[pos] === globalStartToken;
|
|
@@ -64,7 +64,7 @@ const isIdentifier = (stream, pos) => {
|
|
|
64
64
|
}
|
|
65
65
|
return (ch >= 'a' && ch <= 'z')
|
|
66
66
|
|| (ch >= 'A' && ch <= 'Z')
|
|
67
|
-
|| ch === '_';
|
|
67
|
+
|| ch === '_' || ch === '-';
|
|
68
68
|
};
|
|
69
69
|
const isNum = (ch) => {
|
|
70
70
|
return (ch >= '0' && ch <= '9');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.162",
|
|
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.
|
|
40
|
+
"@aemforms/af-formatters": "^0.22.162"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|