@form-engine-ts/core 2.1.0 → 2.2.0

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 CHANGED
@@ -40,8 +40,9 @@ round-trips. `completionMessage` is localized with the rest of the form text.
40
40
 
41
41
  `transformFieldType` changes a question's type without discarding source text, translations, conditions, or extension
42
42
  metadata. `validateFormSchema(schema, { policy })` applies the framework-independent `FormPolicy`, including field,
43
- option, text, serialized-byte, allowed-type, and required-locale constraints. Required locales cover every source text
44
- that exists on the form, its fields, options, and pages.
43
+ option, text, serialized-byte, allowed-type, and locale constraints. `allowedLocales` constrains the default and supported
44
+ locales, `maxLocales` limits their unique total, and contradictory required/allowed locale policies are reported.
45
+ Required locales cover every source text that exists on the form, its fields, options, and pages.
45
46
 
46
47
  Translation callbacks receive `nodeMetadata` and `existingTranslationMetadata` separately. The deprecated `metadata`
47
48
  slot property remains an alias for `nodeMetadata` during migration.
package/dist/index.cjs CHANGED
@@ -554,6 +554,45 @@ function validatePolicy(schema, policy, issues) {
554
554
  }
555
555
  }
556
556
  }
557
+ const registeredLocales = [
558
+ .../* @__PURE__ */ new Set([
559
+ ...schema.defaultLocale === void 0 ? [] : [schema.defaultLocale],
560
+ ...schema.supportedLocales ?? []
561
+ ])
562
+ ];
563
+ if (policy.allowedLocales !== void 0) {
564
+ if (schema.defaultLocale !== void 0 && !policy.allowedLocales.includes(schema.defaultLocale)) {
565
+ issue(
566
+ issues,
567
+ "defaultLocale",
568
+ "disallowed_locale",
569
+ `Locale ${schema.defaultLocale} is not allowed by the form policy.`
570
+ );
571
+ }
572
+ schema.supportedLocales?.forEach((locale, index) => {
573
+ if (!policy.allowedLocales?.includes(locale)) {
574
+ issue(
575
+ issues,
576
+ `supportedLocales[${index}]`,
577
+ "disallowed_locale",
578
+ `Locale ${locale} is not allowed by the form policy.`
579
+ );
580
+ }
581
+ });
582
+ for (const locale of policy.requiredLocales ?? []) {
583
+ if (!policy.allowedLocales.includes(locale)) {
584
+ issue(
585
+ issues,
586
+ "policy.requiredLocales",
587
+ "required_locale_not_allowed",
588
+ `Required locale ${locale} is not included in allowedLocales.`
589
+ );
590
+ }
591
+ }
592
+ }
593
+ if (policy.maxLocales !== void 0 && registeredLocales.length > policy.maxLocales) {
594
+ issue(issues, "supportedLocales", "max_locales_exceeded", `At most ${policy.maxLocales} locales are allowed.`);
595
+ }
557
596
  for (const locale of policy.requiredLocales ?? []) addRequiredTranslationIssues(schema, locale, issues);
558
597
  if (policy.maxSchemaBytes !== void 0) {
559
598
  try {
package/dist/index.d.cts CHANGED
@@ -4,6 +4,8 @@ interface FormPolicy {
4
4
  readonly maxFields?: number;
5
5
  readonly maxOptionsPerField?: number;
6
6
  readonly requiredLocales?: readonly string[];
7
+ readonly allowedLocales?: readonly string[];
8
+ readonly maxLocales?: number;
7
9
  readonly maxTextLength?: number;
8
10
  readonly maxSchemaBytes?: number;
9
11
  }
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ interface FormPolicy {
4
4
  readonly maxFields?: number;
5
5
  readonly maxOptionsPerField?: number;
6
6
  readonly requiredLocales?: readonly string[];
7
+ readonly allowedLocales?: readonly string[];
8
+ readonly maxLocales?: number;
7
9
  readonly maxTextLength?: number;
8
10
  readonly maxSchemaBytes?: number;
9
11
  }
package/dist/index.js CHANGED
@@ -506,6 +506,45 @@ function validatePolicy(schema, policy, issues) {
506
506
  }
507
507
  }
508
508
  }
509
+ const registeredLocales = [
510
+ .../* @__PURE__ */ new Set([
511
+ ...schema.defaultLocale === void 0 ? [] : [schema.defaultLocale],
512
+ ...schema.supportedLocales ?? []
513
+ ])
514
+ ];
515
+ if (policy.allowedLocales !== void 0) {
516
+ if (schema.defaultLocale !== void 0 && !policy.allowedLocales.includes(schema.defaultLocale)) {
517
+ issue(
518
+ issues,
519
+ "defaultLocale",
520
+ "disallowed_locale",
521
+ `Locale ${schema.defaultLocale} is not allowed by the form policy.`
522
+ );
523
+ }
524
+ schema.supportedLocales?.forEach((locale, index) => {
525
+ if (!policy.allowedLocales?.includes(locale)) {
526
+ issue(
527
+ issues,
528
+ `supportedLocales[${index}]`,
529
+ "disallowed_locale",
530
+ `Locale ${locale} is not allowed by the form policy.`
531
+ );
532
+ }
533
+ });
534
+ for (const locale of policy.requiredLocales ?? []) {
535
+ if (!policy.allowedLocales.includes(locale)) {
536
+ issue(
537
+ issues,
538
+ "policy.requiredLocales",
539
+ "required_locale_not_allowed",
540
+ `Required locale ${locale} is not included in allowedLocales.`
541
+ );
542
+ }
543
+ }
544
+ }
545
+ if (policy.maxLocales !== void 0 && registeredLocales.length > policy.maxLocales) {
546
+ issue(issues, "supportedLocales", "max_locales_exceeded", `At most ${policy.maxLocales} locales are allowed.`);
547
+ }
509
548
  for (const locale of policy.requiredLocales ?? []) addRequiredTranslationIssues(schema, locale, issues);
510
549
  if (policy.maxSchemaBytes !== void 0) {
511
550
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-engine-ts/core",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },