@form-engine-ts/core 5.1.0 → 6.0.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
@@ -56,6 +56,11 @@ translation adapter runs.
56
56
  `ja_JP`, and returns `null` for invalid tags. Schema validation, sanitization, locale policy checks, and translation
57
57
  slot lookup use this same normalization so equivalent locale spellings cannot bypass constraints.
58
58
 
59
+ Submissions use `values` as their canonical answer property. `toFormSubmissionWire` and
60
+ `fromFormSubmissionWire` preserve the optional submission `locale` across validated wire payloads. Legacy payloads with
61
+ `answers` are isolated under `LegacyFormSubmission` and `fromLegacyFormSubmission` in the compatibility namespace.
62
+ `serializeSubmissionError` and `deserializeSubmissionError` provide the JSON boundary for `FormSubmissionError`.
63
+
59
64
  Fields can use a `displayRule` with nested `all`/`any` condition groups and `show` or `hide` actions. Supported
60
65
  operators include equality, containment, emptiness, and numeric comparisons; the legacy `displayCondition` and
61
66
  `not_empty` forms remain supported. `submissionSettings` can enable pre-submit confirmation and select its
package/dist/index.cjs CHANGED
@@ -51,6 +51,7 @@ __export(index_exports, {
51
51
  decodeSubmissionCursor: () => decodeSubmissionCursor,
52
52
  decodeTextAnswerCursor: () => decodeTextAnswerCursor,
53
53
  deleteDraft: () => deleteDraft,
54
+ deserializeSubmissionError: () => deserializeSubmissionError,
54
55
  dispatchWebhook: () => dispatchWebhook,
55
56
  encodeStorageSubmissionCursor: () => encodeStorageSubmissionCursor,
56
57
  encodeStorageTextAnswerCursor: () => encodeStorageTextAnswerCursor,
@@ -59,6 +60,8 @@ __export(index_exports, {
59
60
  escapeCsvCell: () => escapeCsvCell,
60
61
  exportResponsesToCsv: () => exportResponsesToCsv,
61
62
  exportResponsesToCsvStream: () => exportResponsesToCsvStream,
63
+ fromFormSubmissionWire: () => fromFormSubmissionWire,
64
+ fromLegacyFormSubmission: () => fromLegacyFormSubmission,
62
65
  getTranslationStatus: () => getTranslationStatus,
63
66
  isDisplayConditionGroupSatisfied: () => isDisplayConditionGroupSatisfied,
64
67
  isDisplayConditionSatisfied: () => isDisplayConditionSatisfied,
@@ -80,6 +83,7 @@ __export(index_exports, {
80
83
  resolveLocalizedSchema: () => resolveLocalizedSchema,
81
84
  sanitizeSchema: () => sanitizeSchema,
82
85
  selectVisibleAnswers: () => selectVisibleAnswers,
86
+ serializeSubmissionError: () => serializeSubmissionError,
83
87
  toFormSubmissionWire: () => toFormSubmissionWire,
84
88
  transformFieldType: () => transformFieldType,
85
89
  validateAnswers: () => validateAnswers,
@@ -1478,7 +1482,7 @@ function aggregateResponses(schema, submissions) {
1478
1482
  function responseValues(submission) {
1479
1483
  if (typeof submission !== "object" || submission === null) return void 0;
1480
1484
  if ("values" in submission) return submission.values;
1481
- return "answers" in submission ? submission.answers : void 0;
1485
+ return submission.answers;
1482
1486
  }
1483
1487
  function responseIdentifier(submission) {
1484
1488
  if (typeof submission !== "object" || submission === null) return "<unknown>";
@@ -1674,14 +1678,17 @@ function serializeValue(value) {
1674
1678
  }
1675
1679
  function asFormResponse(submission) {
1676
1680
  if (!("values" in submission)) return submission;
1681
+ const metadata = submission.metadata === void 0 ? void 0 : Object.fromEntries(
1682
+ Object.entries(submission.metadata).filter((entry) => entry[1] !== void 0)
1683
+ );
1677
1684
  return {
1678
1685
  responseId: submission.id,
1679
1686
  formId: submission.formId,
1680
- sourceLocale: submission.locale,
1687
+ ...submission.locale === void 0 ? {} : { sourceLocale: submission.locale },
1681
1688
  formVersion: submission.formVersion,
1682
1689
  answers: submission.values,
1683
1690
  submittedAt: submission.submittedAt,
1684
- ...submission.metadata === void 0 ? {} : { metadata: submission.metadata },
1691
+ ...metadata === void 0 ? {} : { metadata },
1685
1692
  ...submission.translationMetadata === void 0 ? {} : { translationMetadata: submission.translationMetadata }
1686
1693
  };
1687
1694
  }
@@ -1826,6 +1833,21 @@ function exportResponsesToCsv(schema, responses, options = {}) {
1826
1833
  return options.useBom ?? options.withBom ?? true ? `\uFEFF${csv}` : csv;
1827
1834
  }
1828
1835
 
1836
+ // src/compat/legacy.ts
1837
+ var fromLegacyFormSubmission = (legacy) => {
1838
+ const { id, formId, formVersion, answers, locale, metadata, submittedAt, schemaRevision } = legacy;
1839
+ return {
1840
+ id,
1841
+ formId,
1842
+ formVersion,
1843
+ values: { ...answers },
1844
+ ...locale === void 0 ? {} : { locale },
1845
+ metadata,
1846
+ submittedAt,
1847
+ ...schemaRevision === void 0 ? {} : { schemaRevision }
1848
+ };
1849
+ };
1850
+
1829
1851
  // src/errors.ts
1830
1852
  var FormSubmissionError = class extends Error {
1831
1853
  payload;
@@ -1838,6 +1860,8 @@ var FormSubmissionError = class extends Error {
1838
1860
  return this.payload;
1839
1861
  }
1840
1862
  };
1863
+ var serializeSubmissionError = (error) => error.toJSON();
1864
+ var deserializeSubmissionError = (json) => new FormSubmissionError(json);
1841
1865
 
1842
1866
  // src/events.ts
1843
1867
  function bytesToHex(bytes) {
@@ -2421,14 +2445,17 @@ async function paginateWithFilter(params) {
2421
2445
  return { items: collected, hasMore: false, totalScannedCount };
2422
2446
  }
2423
2447
  function asFormResponse2(submission) {
2448
+ const metadata = submission.metadata === void 0 ? void 0 : Object.fromEntries(
2449
+ Object.entries(submission.metadata).filter((entry) => entry[1] !== void 0)
2450
+ );
2424
2451
  return {
2425
2452
  responseId: submission.id,
2426
2453
  formId: submission.formId,
2427
2454
  formVersion: submission.formVersion,
2428
- sourceLocale: submission.locale,
2455
+ ...submission.locale === void 0 ? {} : { sourceLocale: submission.locale },
2429
2456
  answers: submission.values,
2430
2457
  submittedAt: submission.submittedAt,
2431
- ...submission.metadata === void 0 ? {} : { metadata: submission.metadata }
2458
+ ...metadata === void 0 ? {} : { metadata }
2432
2459
  };
2433
2460
  }
2434
2461
  async function* iterateSubmissionPages(adapter, formId, queryOptions = {}, options = {}) {
@@ -2656,6 +2683,7 @@ var FormSubmissionWireSchema = import_zod.z.object({
2656
2683
  formId: import_zod.z.string().min(1),
2657
2684
  formVersion: import_zod.z.number().int().positive(),
2658
2685
  values: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()),
2686
+ locale: import_zod.z.string().min(1).optional(),
2659
2687
  metadata: FormSubmissionMetadataSchema,
2660
2688
  submittedAt: import_zod.z.string().datetime(),
2661
2689
  schemaRevision: import_zod.z.number().int().optional()
@@ -2842,18 +2870,32 @@ function isFormValue(value) {
2842
2870
  return value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || Array.isArray(value) && value.every((item) => typeof item === "string");
2843
2871
  }
2844
2872
  function toFormSubmissionWire(submission) {
2845
- const { id, formId, formVersion, values, answers, metadata, submittedAt, schemaRevision } = submission;
2846
- const targetValues = values ?? answers ?? {};
2873
+ const { id, formId, formVersion, values, locale, metadata, submittedAt, schemaRevision } = submission;
2847
2874
  return {
2848
2875
  id,
2849
2876
  formId,
2850
2877
  formVersion,
2851
- values: { ...targetValues },
2878
+ values: { ...values },
2879
+ ...locale === void 0 ? {} : { locale },
2852
2880
  metadata: { ...metadata ?? {} },
2853
2881
  submittedAt,
2854
2882
  ...schemaRevision === void 0 ? {} : { schemaRevision }
2855
2883
  };
2856
2884
  }
2885
+ function fromFormSubmissionWire(wire) {
2886
+ const { id, formId, formVersion, values, locale, metadata, submittedAt, schemaRevision } = wire;
2887
+ const canonicalMetadata = { ...metadata };
2888
+ return {
2889
+ id,
2890
+ formId,
2891
+ formVersion,
2892
+ values: { ...values },
2893
+ ...locale === void 0 ? {} : { locale },
2894
+ metadata: canonicalMetadata,
2895
+ submittedAt,
2896
+ ...schemaRevision === void 0 ? {} : { schemaRevision }
2897
+ };
2898
+ }
2857
2899
  function createSubmission(schemaOrInput, values, options) {
2858
2900
  if ("answers" in schemaOrInput) {
2859
2901
  const input = schemaOrInput;
@@ -2873,7 +2915,6 @@ function createSubmission(schemaOrInput, values, options) {
2873
2915
  formVersion: input.formVersion,
2874
2916
  locale: "",
2875
2917
  values: Object.freeze(cloneValues(toFormValues(answers))),
2876
- answers,
2877
2918
  metadata: input.metadata,
2878
2919
  submittedAt,
2879
2920
  ...input.schemaRevision === void 0 ? {} : { schemaRevision: input.schemaRevision }
@@ -2900,7 +2941,6 @@ function createSubmission(schemaOrInput, values, options) {
2900
2941
  formVersion: schema.version,
2901
2942
  locale: options.locale,
2902
2943
  values: Object.freeze(cloneValues(visibleValues)),
2903
- answers: Object.freeze({ ...visibleValues }),
2904
2944
  submittedAt: options.submittedAt,
2905
2945
  ...options.metadata === void 0 ? {} : { metadata: Object.freeze({ ...options.metadata }) },
2906
2946
  ...options.translationMetadata === void 0 ? {} : { translationMetadata: Object.freeze({ ...options.translationMetadata }) }
@@ -3793,6 +3833,7 @@ async function commitVersionTransition(options) {
3793
3833
  decodeSubmissionCursor,
3794
3834
  decodeTextAnswerCursor,
3795
3835
  deleteDraft,
3836
+ deserializeSubmissionError,
3796
3837
  dispatchWebhook,
3797
3838
  encodeStorageSubmissionCursor,
3798
3839
  encodeStorageTextAnswerCursor,
@@ -3801,6 +3842,8 @@ async function commitVersionTransition(options) {
3801
3842
  escapeCsvCell,
3802
3843
  exportResponsesToCsv,
3803
3844
  exportResponsesToCsvStream,
3845
+ fromFormSubmissionWire,
3846
+ fromLegacyFormSubmission,
3804
3847
  getTranslationStatus,
3805
3848
  isDisplayConditionGroupSatisfied,
3806
3849
  isDisplayConditionSatisfied,
@@ -3822,6 +3865,7 @@ async function commitVersionTransition(options) {
3822
3865
  resolveLocalizedSchema,
3823
3866
  sanitizeSchema,
3824
3867
  selectVisibleAnswers,
3868
+ serializeSubmissionError,
3825
3869
  toFormSubmissionWire,
3826
3870
  transformFieldType,
3827
3871
  validateAnswers,
package/dist/index.d.cts CHANGED
@@ -370,14 +370,12 @@ type AnswerValidationResult = {
370
370
  readonly valid: false;
371
371
  readonly issues: readonly ValidationIssue[];
372
372
  };
373
- interface FormSubmissionBase extends ExtensibleNode {
373
+ interface FormSubmissionBase extends Pick<ExtensibleNode, "translationMetadata"> {
374
374
  readonly id: string;
375
375
  readonly formId: string;
376
376
  readonly formVersion: number;
377
- readonly locale: string;
377
+ readonly locale?: string;
378
378
  readonly values: FormValues;
379
- /** Alias used by API-facing consumers; values remains the canonical v4 field. */
380
- readonly answers?: Readonly<Record<string, unknown>>;
381
379
  readonly submittedAt: string;
382
380
  readonly schemaRevision?: number;
383
381
  }
@@ -391,7 +389,8 @@ interface FormSubmissionWire<TMeta extends BaseSubmissionMetadata = BaseSubmissi
391
389
  readonly id: string;
392
390
  readonly formId: string;
393
391
  readonly formVersion: number;
394
- readonly values: Record<string, unknown>;
392
+ readonly values: Readonly<Record<string, unknown>>;
393
+ readonly locale?: string;
395
394
  readonly metadata: TMeta;
396
395
  readonly submittedAt: string;
397
396
  readonly schemaRevision?: number;
@@ -677,6 +676,19 @@ interface NodeWritableStream {
677
676
  declare function pipeResponsesToCsvStream(schema: FormSchema, submissions: AsyncIterable<AccumulatorResponse>, writable: WritableStream<Uint8Array> | NodeWritableStream, options?: StreamCsvOptions): Promise<void>;
678
677
  declare function exportResponsesToCsv(schema: FormSchema, responses: readonly FormSubmission[], options?: CsvExportOptions): string;
679
678
 
679
+ /** Submission shape used by pre-v4 clients and migration-only code. */
680
+ interface LegacyFormSubmission<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata> {
681
+ readonly id: string;
682
+ readonly formId: string;
683
+ readonly formVersion: number;
684
+ readonly answers: Readonly<Record<string, unknown>>;
685
+ readonly locale?: string;
686
+ readonly metadata: TMeta;
687
+ readonly submittedAt: string;
688
+ readonly schemaRevision?: number;
689
+ }
690
+ declare const fromLegacyFormSubmission: <TMeta extends BaseSubmissionMetadata>(legacy: LegacyFormSubmission<TMeta>) => FormSubmission<TMeta>;
691
+
680
692
  interface SensitiveDataFinding {
681
693
  readonly fieldId: string;
682
694
  readonly type: string;
@@ -715,6 +727,8 @@ declare class FormSubmissionError extends Error {
715
727
  constructor(payload: FormSubmissionSerializedError);
716
728
  toJSON(): FormSubmissionSerializedError;
717
729
  }
730
+ declare const serializeSubmissionError: (error: FormSubmissionError) => FormSubmissionSerializedError;
731
+ declare const deserializeSubmissionError: (json: FormSubmissionSerializedError) => FormSubmissionError;
718
732
 
719
733
  type FormEventType = "response.submitted" | "schema.updated";
720
734
  interface FormEvent<T = unknown> {
@@ -867,6 +881,7 @@ declare const FormSubmissionWireSchema: z.ZodObject<{
867
881
  formId: z.ZodString;
868
882
  formVersion: z.ZodNumber;
869
883
  values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
884
+ locale: z.ZodOptional<z.ZodString>;
870
885
  metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
871
886
  submittedAt: z.ZodString;
872
887
  schemaRevision: z.ZodOptional<z.ZodNumber>;
@@ -881,6 +896,9 @@ interface CreateSubmissionOptions<TMeta extends BaseSubmissionMetadata = BaseSub
881
896
  }
882
897
  declare function toFormSubmissionWire<TMeta extends BaseSubmissionMetadata>(submission: FormSubmission<TMeta>): FormSubmissionWire<TMeta>;
883
898
  declare function toFormSubmissionWire(submission: FormSubmission): FormSubmissionWire;
899
+ declare function fromFormSubmissionWire<TMeta extends BaseSubmissionMetadata>(wire: FormSubmissionWire<TMeta>): FormSubmission<TMeta>;
900
+ declare function fromFormSubmissionWire(wire: FormSubmissionWireSchemaType): FormSubmission;
901
+ declare function fromFormSubmissionWire(wire: FormSubmissionWire): FormSubmission;
884
902
  declare function createSubmission(schema: FormSchema, values: FormValues, options: CreateSubmissionOptions): FormSubmission;
885
903
  declare function createSubmission<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata>(schema: FormSchema, values: FormValues, options: CreateSubmissionOptions<TMeta>): FormSubmission<TMeta>;
886
904
  declare function createSubmission<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata>(input: CreateSubmissionInput<TMeta>): FormSubmission<TMeta>;
@@ -1007,4 +1025,4 @@ declare function calculatePageVisibility(schema: FormSchema, currentAnswers: Rea
1007
1025
  declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
1008
1026
  declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
1009
1027
 
1010
- export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AggregationReport, type AggregationSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BaseFieldConstraintRule, type BaseSubmissionMetadata, type BuilderTranslationKey, type CanonicalTranslationMetadata, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceFieldConstraintRule, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type CommitVersionTransitionOptions, type ConditionOperator, type ConditionValue, type CreateSubmissionInput, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvColumnDefinition, type CsvExportOptions, type CursorPagingOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type DisplayConditionGroup, type DisplayRule, EN_MESSAGES, type ExtensibleNode, type FieldConstraintRule, type FieldDisplayCondition, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEngineMessages, type FormEngineTranslationKey, type FormEngineTranslator, type FormEngineTranslatorOptions, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, FormSubmissionError, FormSubmissionMetadataSchema, type FormSubmissionSerializedError, type FormSubmissionSettings, type FormSubmissionWire, FormSubmissionWireSchema, type FormSubmissionWireSchemaType, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type FormVersionTransitionPlan, JA_MESSAGES, type JsonValue, type KnownBuilderTranslationKey, type LegacyTranslationMetadata, type LocaleOption, type LocalizedText, type MigrateSchemaTranslationMetadataOptions, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginatedResult, type PaginationIteratorOptions, type PopulateTranslationOptions, type PopulateTranslationsOptions, type PrivacyEngine, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type RatingFieldConstraintRule, type RendererTranslationKey, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SanitizeSchemaOptions, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type SensitiveDataFinding, type StorageAdapter, type StorageCommitError, type StorageCursor, type StorageFilterCriteria, type StreamCsvOptions, type SubmissionCursorPayload, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type SubmissionValidationResult, type TextAnswerCursorPayload, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextFieldConstraintRule, type TextQuestionAggregate, type TranslationAdapter, type TranslationMetadataMigrator, type TranslationMigrationContext, type TranslationProviderError, type TranslationReport, type TranslationSlot, type TranslationStatus, type TranslationWorkspaceDetailedKey, type TranslationWorkspaceTranslationKey, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionContext, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, applyTransitionPlan, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, collectTranslationSlots, commitVersionTransition, computeSourceTextHash, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createFormEngineTranslator, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeStorageSubmissionCursor, decodeStorageTextAnswerCursor, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeStorageSubmissionCursor, encodeStorageTextAnswerCursor, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, getTranslationStatus, isDisplayConditionGroupSatisfied, isDisplayConditionSatisfied, isManualTranslationMetadata, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, migrateSchemaTranslationMetadata, normalizeLocale, normalizeSubmissionPageSize, paginateWithFilter, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, removeLocaleFromSchema, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, toFormSubmissionWire, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure, validateSubmission };
1028
+ export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AggregationReport, type AggregationSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BaseFieldConstraintRule, type BaseSubmissionMetadata, type BuilderTranslationKey, type CanonicalTranslationMetadata, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceFieldConstraintRule, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type CommitVersionTransitionOptions, type ConditionOperator, type ConditionValue, type CreateSubmissionInput, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvColumnDefinition, type CsvExportOptions, type CursorPagingOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type DisplayConditionGroup, type DisplayRule, EN_MESSAGES, type ExtensibleNode, type FieldConstraintRule, type FieldDisplayCondition, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEngineMessages, type FormEngineTranslationKey, type FormEngineTranslator, type FormEngineTranslatorOptions, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, FormSubmissionError, FormSubmissionMetadataSchema, type FormSubmissionSerializedError, type FormSubmissionSettings, type FormSubmissionWire, FormSubmissionWireSchema, type FormSubmissionWireSchemaType, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type FormVersionTransitionPlan, JA_MESSAGES, type JsonValue, type KnownBuilderTranslationKey, type LegacyFormSubmission, type LegacyTranslationMetadata, type LocaleOption, type LocalizedText, type MigrateSchemaTranslationMetadataOptions, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginatedResult, type PaginationIteratorOptions, type PopulateTranslationOptions, type PopulateTranslationsOptions, type PrivacyEngine, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type RatingFieldConstraintRule, type RendererTranslationKey, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SanitizeSchemaOptions, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type SensitiveDataFinding, type StorageAdapter, type StorageCommitError, type StorageCursor, type StorageFilterCriteria, type StreamCsvOptions, type SubmissionCursorPayload, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type SubmissionValidationResult, type TextAnswerCursorPayload, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextFieldConstraintRule, type TextQuestionAggregate, type TranslationAdapter, type TranslationMetadataMigrator, type TranslationMigrationContext, type TranslationProviderError, type TranslationReport, type TranslationSlot, type TranslationStatus, type TranslationWorkspaceDetailedKey, type TranslationWorkspaceTranslationKey, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionContext, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, applyTransitionPlan, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, collectTranslationSlots, commitVersionTransition, computeSourceTextHash, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createFormEngineTranslator, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeStorageSubmissionCursor, decodeStorageTextAnswerCursor, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, deserializeSubmissionError, dispatchWebhook, encodeStorageSubmissionCursor, encodeStorageTextAnswerCursor, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, fromFormSubmissionWire, fromLegacyFormSubmission, getTranslationStatus, isDisplayConditionGroupSatisfied, isDisplayConditionSatisfied, isManualTranslationMetadata, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, migrateSchemaTranslationMetadata, normalizeLocale, normalizeSubmissionPageSize, paginateWithFilter, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, removeLocaleFromSchema, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, serializeSubmissionError, toFormSubmissionWire, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure, validateSubmission };
package/dist/index.d.ts CHANGED
@@ -370,14 +370,12 @@ type AnswerValidationResult = {
370
370
  readonly valid: false;
371
371
  readonly issues: readonly ValidationIssue[];
372
372
  };
373
- interface FormSubmissionBase extends ExtensibleNode {
373
+ interface FormSubmissionBase extends Pick<ExtensibleNode, "translationMetadata"> {
374
374
  readonly id: string;
375
375
  readonly formId: string;
376
376
  readonly formVersion: number;
377
- readonly locale: string;
377
+ readonly locale?: string;
378
378
  readonly values: FormValues;
379
- /** Alias used by API-facing consumers; values remains the canonical v4 field. */
380
- readonly answers?: Readonly<Record<string, unknown>>;
381
379
  readonly submittedAt: string;
382
380
  readonly schemaRevision?: number;
383
381
  }
@@ -391,7 +389,8 @@ interface FormSubmissionWire<TMeta extends BaseSubmissionMetadata = BaseSubmissi
391
389
  readonly id: string;
392
390
  readonly formId: string;
393
391
  readonly formVersion: number;
394
- readonly values: Record<string, unknown>;
392
+ readonly values: Readonly<Record<string, unknown>>;
393
+ readonly locale?: string;
395
394
  readonly metadata: TMeta;
396
395
  readonly submittedAt: string;
397
396
  readonly schemaRevision?: number;
@@ -677,6 +676,19 @@ interface NodeWritableStream {
677
676
  declare function pipeResponsesToCsvStream(schema: FormSchema, submissions: AsyncIterable<AccumulatorResponse>, writable: WritableStream<Uint8Array> | NodeWritableStream, options?: StreamCsvOptions): Promise<void>;
678
677
  declare function exportResponsesToCsv(schema: FormSchema, responses: readonly FormSubmission[], options?: CsvExportOptions): string;
679
678
 
679
+ /** Submission shape used by pre-v4 clients and migration-only code. */
680
+ interface LegacyFormSubmission<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata> {
681
+ readonly id: string;
682
+ readonly formId: string;
683
+ readonly formVersion: number;
684
+ readonly answers: Readonly<Record<string, unknown>>;
685
+ readonly locale?: string;
686
+ readonly metadata: TMeta;
687
+ readonly submittedAt: string;
688
+ readonly schemaRevision?: number;
689
+ }
690
+ declare const fromLegacyFormSubmission: <TMeta extends BaseSubmissionMetadata>(legacy: LegacyFormSubmission<TMeta>) => FormSubmission<TMeta>;
691
+
680
692
  interface SensitiveDataFinding {
681
693
  readonly fieldId: string;
682
694
  readonly type: string;
@@ -715,6 +727,8 @@ declare class FormSubmissionError extends Error {
715
727
  constructor(payload: FormSubmissionSerializedError);
716
728
  toJSON(): FormSubmissionSerializedError;
717
729
  }
730
+ declare const serializeSubmissionError: (error: FormSubmissionError) => FormSubmissionSerializedError;
731
+ declare const deserializeSubmissionError: (json: FormSubmissionSerializedError) => FormSubmissionError;
718
732
 
719
733
  type FormEventType = "response.submitted" | "schema.updated";
720
734
  interface FormEvent<T = unknown> {
@@ -867,6 +881,7 @@ declare const FormSubmissionWireSchema: z.ZodObject<{
867
881
  formId: z.ZodString;
868
882
  formVersion: z.ZodNumber;
869
883
  values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
884
+ locale: z.ZodOptional<z.ZodString>;
870
885
  metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
871
886
  submittedAt: z.ZodString;
872
887
  schemaRevision: z.ZodOptional<z.ZodNumber>;
@@ -881,6 +896,9 @@ interface CreateSubmissionOptions<TMeta extends BaseSubmissionMetadata = BaseSub
881
896
  }
882
897
  declare function toFormSubmissionWire<TMeta extends BaseSubmissionMetadata>(submission: FormSubmission<TMeta>): FormSubmissionWire<TMeta>;
883
898
  declare function toFormSubmissionWire(submission: FormSubmission): FormSubmissionWire;
899
+ declare function fromFormSubmissionWire<TMeta extends BaseSubmissionMetadata>(wire: FormSubmissionWire<TMeta>): FormSubmission<TMeta>;
900
+ declare function fromFormSubmissionWire(wire: FormSubmissionWireSchemaType): FormSubmission;
901
+ declare function fromFormSubmissionWire(wire: FormSubmissionWire): FormSubmission;
884
902
  declare function createSubmission(schema: FormSchema, values: FormValues, options: CreateSubmissionOptions): FormSubmission;
885
903
  declare function createSubmission<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata>(schema: FormSchema, values: FormValues, options: CreateSubmissionOptions<TMeta>): FormSubmission<TMeta>;
886
904
  declare function createSubmission<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata>(input: CreateSubmissionInput<TMeta>): FormSubmission<TMeta>;
@@ -1007,4 +1025,4 @@ declare function calculatePageVisibility(schema: FormSchema, currentAnswers: Rea
1007
1025
  declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
1008
1026
  declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
1009
1027
 
1010
- export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AggregationReport, type AggregationSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BaseFieldConstraintRule, type BaseSubmissionMetadata, type BuilderTranslationKey, type CanonicalTranslationMetadata, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceFieldConstraintRule, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type CommitVersionTransitionOptions, type ConditionOperator, type ConditionValue, type CreateSubmissionInput, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvColumnDefinition, type CsvExportOptions, type CursorPagingOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type DisplayConditionGroup, type DisplayRule, EN_MESSAGES, type ExtensibleNode, type FieldConstraintRule, type FieldDisplayCondition, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEngineMessages, type FormEngineTranslationKey, type FormEngineTranslator, type FormEngineTranslatorOptions, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, FormSubmissionError, FormSubmissionMetadataSchema, type FormSubmissionSerializedError, type FormSubmissionSettings, type FormSubmissionWire, FormSubmissionWireSchema, type FormSubmissionWireSchemaType, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type FormVersionTransitionPlan, JA_MESSAGES, type JsonValue, type KnownBuilderTranslationKey, type LegacyTranslationMetadata, type LocaleOption, type LocalizedText, type MigrateSchemaTranslationMetadataOptions, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginatedResult, type PaginationIteratorOptions, type PopulateTranslationOptions, type PopulateTranslationsOptions, type PrivacyEngine, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type RatingFieldConstraintRule, type RendererTranslationKey, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SanitizeSchemaOptions, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type SensitiveDataFinding, type StorageAdapter, type StorageCommitError, type StorageCursor, type StorageFilterCriteria, type StreamCsvOptions, type SubmissionCursorPayload, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type SubmissionValidationResult, type TextAnswerCursorPayload, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextFieldConstraintRule, type TextQuestionAggregate, type TranslationAdapter, type TranslationMetadataMigrator, type TranslationMigrationContext, type TranslationProviderError, type TranslationReport, type TranslationSlot, type TranslationStatus, type TranslationWorkspaceDetailedKey, type TranslationWorkspaceTranslationKey, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionContext, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, applyTransitionPlan, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, collectTranslationSlots, commitVersionTransition, computeSourceTextHash, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createFormEngineTranslator, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeStorageSubmissionCursor, decodeStorageTextAnswerCursor, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeStorageSubmissionCursor, encodeStorageTextAnswerCursor, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, getTranslationStatus, isDisplayConditionGroupSatisfied, isDisplayConditionSatisfied, isManualTranslationMetadata, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, migrateSchemaTranslationMetadata, normalizeLocale, normalizeSubmissionPageSize, paginateWithFilter, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, removeLocaleFromSchema, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, toFormSubmissionWire, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure, validateSubmission };
1028
+ export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AggregationReport, type AggregationSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BaseFieldConstraintRule, type BaseSubmissionMetadata, type BuilderTranslationKey, type CanonicalTranslationMetadata, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceFieldConstraintRule, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type CommitVersionTransitionOptions, type ConditionOperator, type ConditionValue, type CreateSubmissionInput, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvColumnDefinition, type CsvExportOptions, type CursorPagingOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type DisplayConditionGroup, type DisplayRule, EN_MESSAGES, type ExtensibleNode, type FieldConstraintRule, type FieldDisplayCondition, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEngineMessages, type FormEngineTranslationKey, type FormEngineTranslator, type FormEngineTranslatorOptions, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, FormSubmissionError, FormSubmissionMetadataSchema, type FormSubmissionSerializedError, type FormSubmissionSettings, type FormSubmissionWire, FormSubmissionWireSchema, type FormSubmissionWireSchemaType, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type FormVersionTransitionPlan, JA_MESSAGES, type JsonValue, type KnownBuilderTranslationKey, type LegacyFormSubmission, type LegacyTranslationMetadata, type LocaleOption, type LocalizedText, type MigrateSchemaTranslationMetadataOptions, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginatedResult, type PaginationIteratorOptions, type PopulateTranslationOptions, type PopulateTranslationsOptions, type PrivacyEngine, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type RatingFieldConstraintRule, type RendererTranslationKey, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SanitizeSchemaOptions, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type SensitiveDataFinding, type StorageAdapter, type StorageCommitError, type StorageCursor, type StorageFilterCriteria, type StreamCsvOptions, type SubmissionCursorPayload, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type SubmissionValidationResult, type TextAnswerCursorPayload, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextFieldConstraintRule, type TextQuestionAggregate, type TranslationAdapter, type TranslationMetadataMigrator, type TranslationMigrationContext, type TranslationProviderError, type TranslationReport, type TranslationSlot, type TranslationStatus, type TranslationWorkspaceDetailedKey, type TranslationWorkspaceTranslationKey, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionContext, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, applyTransitionPlan, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, collectTranslationSlots, commitVersionTransition, computeSourceTextHash, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createFormEngineTranslator, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeStorageSubmissionCursor, decodeStorageTextAnswerCursor, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, deserializeSubmissionError, dispatchWebhook, encodeStorageSubmissionCursor, encodeStorageTextAnswerCursor, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, fromFormSubmissionWire, fromLegacyFormSubmission, getTranslationStatus, isDisplayConditionGroupSatisfied, isDisplayConditionSatisfied, isManualTranslationMetadata, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, migrateSchemaTranslationMetadata, normalizeLocale, normalizeSubmissionPageSize, paginateWithFilter, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, removeLocaleFromSchema, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, serializeSubmissionError, toFormSubmissionWire, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure, validateSubmission };
package/dist/index.js CHANGED
@@ -1386,7 +1386,7 @@ function aggregateResponses(schema, submissions) {
1386
1386
  function responseValues(submission) {
1387
1387
  if (typeof submission !== "object" || submission === null) return void 0;
1388
1388
  if ("values" in submission) return submission.values;
1389
- return "answers" in submission ? submission.answers : void 0;
1389
+ return submission.answers;
1390
1390
  }
1391
1391
  function responseIdentifier(submission) {
1392
1392
  if (typeof submission !== "object" || submission === null) return "<unknown>";
@@ -1582,14 +1582,17 @@ function serializeValue(value) {
1582
1582
  }
1583
1583
  function asFormResponse(submission) {
1584
1584
  if (!("values" in submission)) return submission;
1585
+ const metadata = submission.metadata === void 0 ? void 0 : Object.fromEntries(
1586
+ Object.entries(submission.metadata).filter((entry) => entry[1] !== void 0)
1587
+ );
1585
1588
  return {
1586
1589
  responseId: submission.id,
1587
1590
  formId: submission.formId,
1588
- sourceLocale: submission.locale,
1591
+ ...submission.locale === void 0 ? {} : { sourceLocale: submission.locale },
1589
1592
  formVersion: submission.formVersion,
1590
1593
  answers: submission.values,
1591
1594
  submittedAt: submission.submittedAt,
1592
- ...submission.metadata === void 0 ? {} : { metadata: submission.metadata },
1595
+ ...metadata === void 0 ? {} : { metadata },
1593
1596
  ...submission.translationMetadata === void 0 ? {} : { translationMetadata: submission.translationMetadata }
1594
1597
  };
1595
1598
  }
@@ -1734,6 +1737,21 @@ function exportResponsesToCsv(schema, responses, options = {}) {
1734
1737
  return options.useBom ?? options.withBom ?? true ? `\uFEFF${csv}` : csv;
1735
1738
  }
1736
1739
 
1740
+ // src/compat/legacy.ts
1741
+ var fromLegacyFormSubmission = (legacy) => {
1742
+ const { id, formId, formVersion, answers, locale, metadata, submittedAt, schemaRevision } = legacy;
1743
+ return {
1744
+ id,
1745
+ formId,
1746
+ formVersion,
1747
+ values: { ...answers },
1748
+ ...locale === void 0 ? {} : { locale },
1749
+ metadata,
1750
+ submittedAt,
1751
+ ...schemaRevision === void 0 ? {} : { schemaRevision }
1752
+ };
1753
+ };
1754
+
1737
1755
  // src/errors.ts
1738
1756
  var FormSubmissionError = class extends Error {
1739
1757
  payload;
@@ -1746,6 +1764,8 @@ var FormSubmissionError = class extends Error {
1746
1764
  return this.payload;
1747
1765
  }
1748
1766
  };
1767
+ var serializeSubmissionError = (error) => error.toJSON();
1768
+ var deserializeSubmissionError = (json) => new FormSubmissionError(json);
1749
1769
 
1750
1770
  // src/events.ts
1751
1771
  function bytesToHex(bytes) {
@@ -2329,14 +2349,17 @@ async function paginateWithFilter(params) {
2329
2349
  return { items: collected, hasMore: false, totalScannedCount };
2330
2350
  }
2331
2351
  function asFormResponse2(submission) {
2352
+ const metadata = submission.metadata === void 0 ? void 0 : Object.fromEntries(
2353
+ Object.entries(submission.metadata).filter((entry) => entry[1] !== void 0)
2354
+ );
2332
2355
  return {
2333
2356
  responseId: submission.id,
2334
2357
  formId: submission.formId,
2335
2358
  formVersion: submission.formVersion,
2336
- sourceLocale: submission.locale,
2359
+ ...submission.locale === void 0 ? {} : { sourceLocale: submission.locale },
2337
2360
  answers: submission.values,
2338
2361
  submittedAt: submission.submittedAt,
2339
- ...submission.metadata === void 0 ? {} : { metadata: submission.metadata }
2362
+ ...metadata === void 0 ? {} : { metadata }
2340
2363
  };
2341
2364
  }
2342
2365
  async function* iterateSubmissionPages(adapter, formId, queryOptions = {}, options = {}) {
@@ -2564,6 +2587,7 @@ var FormSubmissionWireSchema = z.object({
2564
2587
  formId: z.string().min(1),
2565
2588
  formVersion: z.number().int().positive(),
2566
2589
  values: z.record(z.string(), z.unknown()),
2590
+ locale: z.string().min(1).optional(),
2567
2591
  metadata: FormSubmissionMetadataSchema,
2568
2592
  submittedAt: z.string().datetime(),
2569
2593
  schemaRevision: z.number().int().optional()
@@ -2750,18 +2774,32 @@ function isFormValue(value) {
2750
2774
  return value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || Array.isArray(value) && value.every((item) => typeof item === "string");
2751
2775
  }
2752
2776
  function toFormSubmissionWire(submission) {
2753
- const { id, formId, formVersion, values, answers, metadata, submittedAt, schemaRevision } = submission;
2754
- const targetValues = values ?? answers ?? {};
2777
+ const { id, formId, formVersion, values, locale, metadata, submittedAt, schemaRevision } = submission;
2755
2778
  return {
2756
2779
  id,
2757
2780
  formId,
2758
2781
  formVersion,
2759
- values: { ...targetValues },
2782
+ values: { ...values },
2783
+ ...locale === void 0 ? {} : { locale },
2760
2784
  metadata: { ...metadata ?? {} },
2761
2785
  submittedAt,
2762
2786
  ...schemaRevision === void 0 ? {} : { schemaRevision }
2763
2787
  };
2764
2788
  }
2789
+ function fromFormSubmissionWire(wire) {
2790
+ const { id, formId, formVersion, values, locale, metadata, submittedAt, schemaRevision } = wire;
2791
+ const canonicalMetadata = { ...metadata };
2792
+ return {
2793
+ id,
2794
+ formId,
2795
+ formVersion,
2796
+ values: { ...values },
2797
+ ...locale === void 0 ? {} : { locale },
2798
+ metadata: canonicalMetadata,
2799
+ submittedAt,
2800
+ ...schemaRevision === void 0 ? {} : { schemaRevision }
2801
+ };
2802
+ }
2765
2803
  function createSubmission(schemaOrInput, values, options) {
2766
2804
  if ("answers" in schemaOrInput) {
2767
2805
  const input = schemaOrInput;
@@ -2781,7 +2819,6 @@ function createSubmission(schemaOrInput, values, options) {
2781
2819
  formVersion: input.formVersion,
2782
2820
  locale: "",
2783
2821
  values: Object.freeze(cloneValues(toFormValues(answers))),
2784
- answers,
2785
2822
  metadata: input.metadata,
2786
2823
  submittedAt,
2787
2824
  ...input.schemaRevision === void 0 ? {} : { schemaRevision: input.schemaRevision }
@@ -2808,7 +2845,6 @@ function createSubmission(schemaOrInput, values, options) {
2808
2845
  formVersion: schema.version,
2809
2846
  locale: options.locale,
2810
2847
  values: Object.freeze(cloneValues(visibleValues)),
2811
- answers: Object.freeze({ ...visibleValues }),
2812
2848
  submittedAt: options.submittedAt,
2813
2849
  ...options.metadata === void 0 ? {} : { metadata: Object.freeze({ ...options.metadata }) },
2814
2850
  ...options.translationMetadata === void 0 ? {} : { translationMetadata: Object.freeze({ ...options.translationMetadata }) }
@@ -3700,6 +3736,7 @@ export {
3700
3736
  decodeSubmissionCursor,
3701
3737
  decodeTextAnswerCursor,
3702
3738
  deleteDraft,
3739
+ deserializeSubmissionError,
3703
3740
  dispatchWebhook,
3704
3741
  encodeStorageSubmissionCursor,
3705
3742
  encodeStorageTextAnswerCursor,
@@ -3708,6 +3745,8 @@ export {
3708
3745
  escapeCsvCell,
3709
3746
  exportResponsesToCsv,
3710
3747
  exportResponsesToCsvStream,
3748
+ fromFormSubmissionWire,
3749
+ fromLegacyFormSubmission,
3711
3750
  getTranslationStatus,
3712
3751
  isDisplayConditionGroupSatisfied,
3713
3752
  isDisplayConditionSatisfied,
@@ -3729,6 +3768,7 @@ export {
3729
3768
  resolveLocalizedSchema,
3730
3769
  sanitizeSchema,
3731
3770
  selectVisibleAnswers,
3771
+ serializeSubmissionError,
3732
3772
  toFormSubmissionWire,
3733
3773
  transformFieldType,
3734
3774
  validateAnswers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-engine-ts/core",
3
- "version": "5.1.0",
3
+ "version": "6.0.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },