@frt-platform/report-core 1.1.0 → 1.2.1

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/dist/index.d.ts CHANGED
@@ -1,169 +1,28 @@
1
- import { z, ZodTypeAny } from 'zod';
1
+ import { z, ZodTypeAny, ZodIssue } from 'zod';
2
2
 
3
3
  declare const REPORT_TEMPLATE_VERSION = 1;
4
- declare const REPORT_TEMPLATE_FIELD_TYPES: readonly ["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"];
4
+ declare const REPORT_TEMPLATE_FIELD_TYPES: readonly ["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect", "repeatGroup"];
5
5
  type ReportTemplateFieldType = (typeof REPORT_TEMPLATE_FIELD_TYPES)[number];
6
- declare const ReportTemplateFieldSchema: z.ZodObject<{
7
- id: z.ZodString;
8
- type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
9
- label: z.ZodString;
10
- required: z.ZodOptional<z.ZodBoolean>;
11
- description: z.ZodOptional<z.ZodString>;
12
- placeholder: z.ZodOptional<z.ZodString>;
13
- options: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
14
- allowOther: z.ZodOptional<z.ZodBoolean>;
15
- defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodNull]>>;
16
- minLength: z.ZodOptional<z.ZodNumber>;
17
- maxLength: z.ZodOptional<z.ZodNumber>;
18
- minValue: z.ZodOptional<z.ZodNumber>;
19
- maxValue: z.ZodOptional<z.ZodNumber>;
20
- step: z.ZodOptional<z.ZodNumber>;
21
- minSelections: z.ZodOptional<z.ZodNumber>;
22
- maxSelections: z.ZodOptional<z.ZodNumber>;
23
- dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
24
- }, "strip", z.ZodTypeAny, {
25
- id: string;
26
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
27
- label: string;
28
- options?: string[] | undefined;
29
- required?: boolean | undefined;
30
- description?: string | undefined;
31
- placeholder?: string | undefined;
32
- allowOther?: boolean | undefined;
33
- defaultValue?: string | number | boolean | string[] | null | undefined;
34
- minLength?: number | undefined;
35
- maxLength?: number | undefined;
36
- minValue?: number | undefined;
37
- maxValue?: number | undefined;
38
- step?: number | undefined;
39
- minSelections?: number | undefined;
40
- maxSelections?: number | undefined;
41
- dataClassification?: "none" | "personal" | "special" | undefined;
42
- }, {
43
- id: string;
44
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
45
- label: string;
46
- options?: string[] | undefined;
47
- required?: boolean | undefined;
48
- description?: string | undefined;
49
- placeholder?: string | undefined;
50
- allowOther?: boolean | undefined;
51
- defaultValue?: string | number | boolean | string[] | null | undefined;
52
- minLength?: number | undefined;
53
- maxLength?: number | undefined;
54
- minValue?: number | undefined;
55
- maxValue?: number | undefined;
56
- step?: number | undefined;
57
- minSelections?: number | undefined;
58
- maxSelections?: number | undefined;
59
- dataClassification?: "none" | "personal" | "special" | undefined;
60
- }>;
6
+ declare const Condition: z.ZodType<any>;
7
+ type SimpleCondition = z.infer<typeof Condition>;
8
+ declare const RepeatGroupFieldSchema: z.ZodType<any>;
9
+ declare const ReportTemplateFieldSchema: z.ZodType<any>;
61
10
  type ReportTemplateField = z.infer<typeof ReportTemplateFieldSchema>;
62
11
  declare const ReportTemplateSectionSchema: z.ZodObject<{
63
12
  id: z.ZodString;
64
13
  title: z.ZodOptional<z.ZodString>;
65
14
  description: z.ZodOptional<z.ZodString>;
66
- fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
67
- id: z.ZodString;
68
- type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
69
- label: z.ZodString;
70
- required: z.ZodOptional<z.ZodBoolean>;
71
- description: z.ZodOptional<z.ZodString>;
72
- placeholder: z.ZodOptional<z.ZodString>;
73
- options: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
74
- allowOther: z.ZodOptional<z.ZodBoolean>;
75
- defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodNull]>>;
76
- minLength: z.ZodOptional<z.ZodNumber>;
77
- maxLength: z.ZodOptional<z.ZodNumber>;
78
- minValue: z.ZodOptional<z.ZodNumber>;
79
- maxValue: z.ZodOptional<z.ZodNumber>;
80
- step: z.ZodOptional<z.ZodNumber>;
81
- minSelections: z.ZodOptional<z.ZodNumber>;
82
- maxSelections: z.ZodOptional<z.ZodNumber>;
83
- dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
84
- }, "strip", z.ZodTypeAny, {
85
- id: string;
86
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
87
- label: string;
88
- options?: string[] | undefined;
89
- required?: boolean | undefined;
90
- description?: string | undefined;
91
- placeholder?: string | undefined;
92
- allowOther?: boolean | undefined;
93
- defaultValue?: string | number | boolean | string[] | null | undefined;
94
- minLength?: number | undefined;
95
- maxLength?: number | undefined;
96
- minValue?: number | undefined;
97
- maxValue?: number | undefined;
98
- step?: number | undefined;
99
- minSelections?: number | undefined;
100
- maxSelections?: number | undefined;
101
- dataClassification?: "none" | "personal" | "special" | undefined;
102
- }, {
103
- id: string;
104
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
105
- label: string;
106
- options?: string[] | undefined;
107
- required?: boolean | undefined;
108
- description?: string | undefined;
109
- placeholder?: string | undefined;
110
- allowOther?: boolean | undefined;
111
- defaultValue?: string | number | boolean | string[] | null | undefined;
112
- minLength?: number | undefined;
113
- maxLength?: number | undefined;
114
- minValue?: number | undefined;
115
- maxValue?: number | undefined;
116
- step?: number | undefined;
117
- minSelections?: number | undefined;
118
- maxSelections?: number | undefined;
119
- dataClassification?: "none" | "personal" | "special" | undefined;
120
- }>, "many">>;
15
+ fields: z.ZodDefault<z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">>;
121
16
  }, "strip", z.ZodTypeAny, {
122
17
  id: string;
123
- fields: {
124
- id: string;
125
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
126
- label: string;
127
- options?: string[] | undefined;
128
- required?: boolean | undefined;
129
- description?: string | undefined;
130
- placeholder?: string | undefined;
131
- allowOther?: boolean | undefined;
132
- defaultValue?: string | number | boolean | string[] | null | undefined;
133
- minLength?: number | undefined;
134
- maxLength?: number | undefined;
135
- minValue?: number | undefined;
136
- maxValue?: number | undefined;
137
- step?: number | undefined;
138
- minSelections?: number | undefined;
139
- maxSelections?: number | undefined;
140
- dataClassification?: "none" | "personal" | "special" | undefined;
141
- }[];
18
+ fields: any[];
142
19
  description?: string | undefined;
143
20
  title?: string | undefined;
144
21
  }, {
145
22
  id: string;
146
23
  description?: string | undefined;
24
+ fields?: any[] | undefined;
147
25
  title?: string | undefined;
148
- fields?: {
149
- id: string;
150
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
151
- label: string;
152
- options?: string[] | undefined;
153
- required?: boolean | undefined;
154
- description?: string | undefined;
155
- placeholder?: string | undefined;
156
- allowOther?: boolean | undefined;
157
- defaultValue?: string | number | boolean | string[] | null | undefined;
158
- minLength?: number | undefined;
159
- maxLength?: number | undefined;
160
- minValue?: number | undefined;
161
- maxValue?: number | undefined;
162
- step?: number | undefined;
163
- minSelections?: number | undefined;
164
- maxSelections?: number | undefined;
165
- dataClassification?: "none" | "personal" | "special" | undefined;
166
- }[] | undefined;
167
26
  }>;
168
27
  type ReportTemplateSection = z.infer<typeof ReportTemplateSectionSchema>;
169
28
  declare const ReportTemplateSchemaValidator: z.ZodObject<{
@@ -174,131 +33,23 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
174
33
  id: z.ZodString;
175
34
  title: z.ZodOptional<z.ZodString>;
176
35
  description: z.ZodOptional<z.ZodString>;
177
- fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
178
- id: z.ZodString;
179
- type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
180
- label: z.ZodString;
181
- required: z.ZodOptional<z.ZodBoolean>;
182
- description: z.ZodOptional<z.ZodString>;
183
- placeholder: z.ZodOptional<z.ZodString>;
184
- options: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
185
- allowOther: z.ZodOptional<z.ZodBoolean>;
186
- defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodNull]>>;
187
- minLength: z.ZodOptional<z.ZodNumber>;
188
- maxLength: z.ZodOptional<z.ZodNumber>;
189
- minValue: z.ZodOptional<z.ZodNumber>;
190
- maxValue: z.ZodOptional<z.ZodNumber>;
191
- step: z.ZodOptional<z.ZodNumber>;
192
- minSelections: z.ZodOptional<z.ZodNumber>;
193
- maxSelections: z.ZodOptional<z.ZodNumber>;
194
- dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
195
- }, "strip", z.ZodTypeAny, {
196
- id: string;
197
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
198
- label: string;
199
- options?: string[] | undefined;
200
- required?: boolean | undefined;
201
- description?: string | undefined;
202
- placeholder?: string | undefined;
203
- allowOther?: boolean | undefined;
204
- defaultValue?: string | number | boolean | string[] | null | undefined;
205
- minLength?: number | undefined;
206
- maxLength?: number | undefined;
207
- minValue?: number | undefined;
208
- maxValue?: number | undefined;
209
- step?: number | undefined;
210
- minSelections?: number | undefined;
211
- maxSelections?: number | undefined;
212
- dataClassification?: "none" | "personal" | "special" | undefined;
213
- }, {
214
- id: string;
215
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
216
- label: string;
217
- options?: string[] | undefined;
218
- required?: boolean | undefined;
219
- description?: string | undefined;
220
- placeholder?: string | undefined;
221
- allowOther?: boolean | undefined;
222
- defaultValue?: string | number | boolean | string[] | null | undefined;
223
- minLength?: number | undefined;
224
- maxLength?: number | undefined;
225
- minValue?: number | undefined;
226
- maxValue?: number | undefined;
227
- step?: number | undefined;
228
- minSelections?: number | undefined;
229
- maxSelections?: number | undefined;
230
- dataClassification?: "none" | "personal" | "special" | undefined;
231
- }>, "many">>;
36
+ fields: z.ZodDefault<z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">>;
232
37
  }, "strip", z.ZodTypeAny, {
233
38
  id: string;
234
- fields: {
235
- id: string;
236
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
237
- label: string;
238
- options?: string[] | undefined;
239
- required?: boolean | undefined;
240
- description?: string | undefined;
241
- placeholder?: string | undefined;
242
- allowOther?: boolean | undefined;
243
- defaultValue?: string | number | boolean | string[] | null | undefined;
244
- minLength?: number | undefined;
245
- maxLength?: number | undefined;
246
- minValue?: number | undefined;
247
- maxValue?: number | undefined;
248
- step?: number | undefined;
249
- minSelections?: number | undefined;
250
- maxSelections?: number | undefined;
251
- dataClassification?: "none" | "personal" | "special" | undefined;
252
- }[];
39
+ fields: any[];
253
40
  description?: string | undefined;
254
41
  title?: string | undefined;
255
42
  }, {
256
43
  id: string;
257
44
  description?: string | undefined;
45
+ fields?: any[] | undefined;
258
46
  title?: string | undefined;
259
- fields?: {
260
- id: string;
261
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
262
- label: string;
263
- options?: string[] | undefined;
264
- required?: boolean | undefined;
265
- description?: string | undefined;
266
- placeholder?: string | undefined;
267
- allowOther?: boolean | undefined;
268
- defaultValue?: string | number | boolean | string[] | null | undefined;
269
- minLength?: number | undefined;
270
- maxLength?: number | undefined;
271
- minValue?: number | undefined;
272
- maxValue?: number | undefined;
273
- step?: number | undefined;
274
- minSelections?: number | undefined;
275
- maxSelections?: number | undefined;
276
- dataClassification?: "none" | "personal" | "special" | undefined;
277
- }[] | undefined;
278
47
  }>, "many">>;
279
48
  }, "strip", z.ZodTypeAny, {
280
49
  version: number;
281
50
  sections: {
282
51
  id: string;
283
- fields: {
284
- id: string;
285
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
286
- label: string;
287
- options?: string[] | undefined;
288
- required?: boolean | undefined;
289
- description?: string | undefined;
290
- placeholder?: string | undefined;
291
- allowOther?: boolean | undefined;
292
- defaultValue?: string | number | boolean | string[] | null | undefined;
293
- minLength?: number | undefined;
294
- maxLength?: number | undefined;
295
- minValue?: number | undefined;
296
- maxValue?: number | undefined;
297
- step?: number | undefined;
298
- minSelections?: number | undefined;
299
- maxSelections?: number | undefined;
300
- dataClassification?: "none" | "personal" | "special" | undefined;
301
- }[];
52
+ fields: any[];
302
53
  description?: string | undefined;
303
54
  title?: string | undefined;
304
55
  }[];
@@ -311,26 +62,8 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
311
62
  sections?: {
312
63
  id: string;
313
64
  description?: string | undefined;
65
+ fields?: any[] | undefined;
314
66
  title?: string | undefined;
315
- fields?: {
316
- id: string;
317
- type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
318
- label: string;
319
- options?: string[] | undefined;
320
- required?: boolean | undefined;
321
- description?: string | undefined;
322
- placeholder?: string | undefined;
323
- allowOther?: boolean | undefined;
324
- defaultValue?: string | number | boolean | string[] | null | undefined;
325
- minLength?: number | undefined;
326
- maxLength?: number | undefined;
327
- minValue?: number | undefined;
328
- maxValue?: number | undefined;
329
- step?: number | undefined;
330
- minSelections?: number | undefined;
331
- maxSelections?: number | undefined;
332
- dataClassification?: "none" | "personal" | "special" | undefined;
333
- }[] | undefined;
334
67
  }[] | undefined;
335
68
  }>;
336
69
  type ReportTemplateSchema = z.infer<typeof ReportTemplateSchemaValidator>;
@@ -342,34 +75,214 @@ declare function createUniqueId(prefix: string, existing: Iterable<string>): str
342
75
 
343
76
  declare function migrateLegacySchema(raw: unknown): unknown;
344
77
 
345
- declare function parseReportTemplateSchema(raw: unknown): ReportTemplateSchema;
346
78
  declare function normalizeReportTemplateSchema(schema: ReportTemplateSchema): ReportTemplateSchema;
79
+ declare function parseReportTemplateSchema(raw: unknown): ReportTemplateSchema;
347
80
  declare function parseReportTemplateSchemaFromString(raw: string): ReportTemplateSchema;
348
81
  declare function serializeReportTemplateSchema(schema: ReportTemplateSchema): string;
349
82
 
83
+ declare function buildBaseFieldSchema(field: ReportTemplateField): ZodTypeAny;
84
+ declare function buildResponseSchemaWithConditions(template: ReportTemplateSchema, response: Record<string, any>): z.ZodObject<Record<string, ZodTypeAny>>;
85
+ declare function validateReportResponse(template: ReportTemplateSchema, data: unknown): Record<string, unknown>;
86
+ type FieldErrorCode = "response.invalid_root" | "field.required" | "field.invalid_type" | "field.too_small" | "field.too_big" | "field.invalid_option" | "field.custom";
87
+ interface ResponseFieldError {
88
+ /** field id (template-level id) */
89
+ fieldId: string;
90
+ /** section id that owns this field (if known) */
91
+ sectionId?: string;
92
+ /** section title (if available in template) */
93
+ sectionTitle?: string;
94
+ /** human label of the field */
95
+ label?: string;
96
+ /** normalized error code */
97
+ code: FieldErrorCode;
98
+ /** human-readable message (already enriched with section / label) */
99
+ message: string;
100
+ /** original Zod issue (for debugging / logging) */
101
+ rawIssue?: ZodIssue;
102
+ }
350
103
  /**
351
- * Build a Zod schema for a single field's response value.
104
+ * Validates a response against a template, but instead of throwing,
105
+ * returns a structured error object with:
106
+ * - section title
107
+ * - field label
108
+ * - normalized error code
352
109
  *
353
- * The response object shape is:
354
- * { [fieldId: string]: unknown }
110
+ * Ideal for UI error display.
355
111
  */
356
- declare function buildFieldResponseSchema(field: ReportTemplateField): ZodTypeAny;
112
+ declare function validateReportResponseDetailed(template: ReportTemplateSchema, data: unknown): {
113
+ success: true;
114
+ value: Record<string, unknown>;
115
+ } | {
116
+ success: false;
117
+ errors: ResponseFieldError[];
118
+ };
119
+ type TemplateFieldUnion<TTemplate> = TTemplate extends {
120
+ sections: readonly (infer S)[];
121
+ } ? S extends {
122
+ fields: readonly (infer F)[];
123
+ } ? F : never : never;
124
+ type BaseFieldValue<TField extends {
125
+ type: ReportTemplateFieldType;
126
+ required?: boolean;
127
+ options?: readonly string[] | string[];
128
+ }> = TField["type"] extends "shortText" | "longText" ? string : TField["type"] extends "number" ? number : TField["type"] extends "date" ? string : TField["type"] extends "checkbox" ? boolean : TField["type"] extends "singleSelect" ? (TField["options"] extends readonly (infer O)[] ? O : TField["options"] extends (infer O)[] ? O : string) : TField["type"] extends "multiSelect" ? (TField["options"] extends readonly (infer O)[] ? O[] : TField["options"] extends (infer O)[] ? O[] : string[]) : unknown;
129
+ type FieldResponseValue<TField extends {
130
+ type: ReportTemplateFieldType;
131
+ required?: boolean;
132
+ }> = TField["required"] extends true ? BaseFieldValue<TField> : BaseFieldValue<TField> | undefined;
133
+ type InferResponse<TTemplate extends {
134
+ sections: readonly {
135
+ fields: readonly {
136
+ id: string;
137
+ type: ReportTemplateFieldType;
138
+ required?: boolean;
139
+ options?: readonly string[] | string[];
140
+ }[];
141
+ }[];
142
+ }> = {
143
+ [F in TemplateFieldUnion<TTemplate> as F["id"]]: FieldResponseValue<F>;
144
+ };
145
+
146
+ interface TemplateDiff {
147
+ addedSections: Array<{
148
+ sectionId: string;
149
+ index: number;
150
+ }>;
151
+ removedSections: Array<{
152
+ sectionId: string;
153
+ index: number;
154
+ }>;
155
+ reorderedSections: Array<{
156
+ sectionId: string;
157
+ from: number;
158
+ to: number;
159
+ }>;
160
+ modifiedSections: Array<{
161
+ sectionId: string;
162
+ changes: Array<{
163
+ key: string;
164
+ before: any;
165
+ after: any;
166
+ }>;
167
+ }>;
168
+ addedFields: Array<{
169
+ sectionId: string;
170
+ fieldId: string;
171
+ index: number;
172
+ }>;
173
+ removedFields: Array<{
174
+ sectionId: string;
175
+ fieldId: string;
176
+ index: number;
177
+ }>;
178
+ reorderedFields: Array<{
179
+ sectionId: string;
180
+ fieldId: string;
181
+ from: number;
182
+ to: number;
183
+ }>;
184
+ modifiedFields: Array<{
185
+ sectionId: string;
186
+ fieldId: string;
187
+ before: Record<string, any>;
188
+ after: Record<string, any>;
189
+ changes: Array<{
190
+ key: string;
191
+ before: any;
192
+ after: any;
193
+ }>;
194
+ }>;
195
+ /** NEW: repeatGroup nested diffs */
196
+ nestedFieldDiffs: Array<{
197
+ sectionId: string;
198
+ groupId: string;
199
+ diffs: TemplateDiff;
200
+ }>;
201
+ }
202
+ declare function diffTemplates(before: ReportTemplateSchema, after: ReportTemplateSchema): TemplateDiff;
203
+
204
+ /** -------------------------------------------------------------
205
+ * FieldRegistryEntry
206
+ * --------------------------------------------------------------
207
+ * Represents metadata + behavior for a single field type.
208
+ * -------------------------------------------------------------- */
209
+ interface FieldRegistryEntry {
210
+ /** Default field-level properties merged when creating new fields */
211
+ defaults?: Record<string, unknown>;
212
+ /**
213
+ * Build a Zod schema for validating the *response value* of this field.
214
+ * If not provided, the core engine falls back to the built-in handler.
215
+ */
216
+ buildResponseSchema?: (field: ReportTemplateField) => ZodTypeAny;
217
+ /**
218
+ * Optional UI metadata for @frt/report-react
219
+ * (icon, color, description, grouping, etc.)
220
+ */
221
+ ui?: Record<string, any>;
222
+ }
223
+ /** -------------------------------------------------------------
224
+ * FieldRegistry
225
+ * --------------------------------------------------------------
226
+ * Central store of all field types (built-in + custom).
227
+ * -------------------------------------------------------------- */
228
+ declare class FieldRegistryClass {
229
+ private registry;
230
+ /** Register or override a field type. */
231
+ register(type: string, entry: FieldRegistryEntry): void;
232
+ /** Get registry entry for a field type. */
233
+ get(type: string): FieldRegistryEntry | undefined;
234
+ /** Check if field type is registered. */
235
+ has(type: string): boolean;
236
+ /** Return all field types currently registered. */
237
+ list(): string[];
238
+ }
239
+ /** Singleton instance */
240
+ declare const FieldRegistry: FieldRegistryClass;
241
+
357
242
  /**
358
- * Build a Zod schema for an entire report response.
243
+ * Evaluate a conditional rule against a submitted response object.
359
244
  *
360
- * Shape:
361
- * {
362
- * [fieldId: string]: value
363
- * }
364
- *
365
- * Where each fieldId corresponds to a field from the template.
245
+ * Supported forms:
246
+ * { equals: { fieldId: value } }
247
+ * { any: [cond, cond] }
248
+ * { all: [cond, cond] }
249
+ * { not: cond }
366
250
  */
367
- declare function buildResponseSchema(template: ReportTemplateSchema): z.ZodObject<Record<string, ZodTypeAny>>;
251
+ declare function evaluateCondition(condition: SimpleCondition, response: Record<string, any>): boolean;
252
+
368
253
  /**
369
- * Convenience helper: validate a response object against a template.
254
+ * Minimal JSON Schema type for our purposes.
255
+ * Flexible, with an index signature to allow vendor extensions (x-frt-*).
256
+ */
257
+ interface JSONSchema {
258
+ $schema?: string;
259
+ $id?: string;
260
+ type?: "object" | "string" | "number" | "boolean" | "array" | "null";
261
+ properties?: Record<string, JSONSchema>;
262
+ items?: JSONSchema;
263
+ required?: string[];
264
+ enum?: any[];
265
+ minLength?: number;
266
+ maxLength?: number;
267
+ minimum?: number;
268
+ maximum?: number;
269
+ minItems?: number;
270
+ maxItems?: number;
271
+ description?: string;
272
+ title?: string;
273
+ default?: any;
274
+ format?: string;
275
+ additionalProperties?: boolean;
276
+ [key: string]: any;
277
+ }
278
+ /**
279
+ * Export a report template as a JSON Schema "object" definition.
370
280
  *
371
- * Throws ZodError on failure.
281
+ * - Each field becomes a property keyed by its `id`
282
+ * - Unconditional `required: true` fields are added to the JSON Schema `required` array
283
+ * - Conditional logic is preserved via `x-frt-visibleIf` / `x-frt-requiredIf`
284
+ * but NOT enforced in the core JSON Schema (since it's beyond standard JSON Schema).
372
285
  */
373
- declare function validateReportResponse(template: ReportTemplateSchema, data: unknown): Record<string, unknown>;
286
+ declare function exportJSONSchema(template: ReportTemplateSchema): JSONSchema;
374
287
 
375
- export { CORE_FIELD_DEFAULTS, DEFAULT_FIELD_LABEL, REPORT_TEMPLATE_FIELD_TYPES, REPORT_TEMPLATE_VERSION, type ReportTemplateField, ReportTemplateFieldSchema, type ReportTemplateFieldType, type ReportTemplateSchema, ReportTemplateSchemaValidator, type ReportTemplateSection, ReportTemplateSectionSchema, buildFieldResponseSchema, buildResponseSchema, createUniqueId, migrateLegacySchema, normalizeReportTemplateSchema, parseReportTemplateSchema, parseReportTemplateSchemaFromString, serializeReportTemplateSchema, validateReportResponse };
288
+ export { CORE_FIELD_DEFAULTS, Condition, DEFAULT_FIELD_LABEL, type FieldErrorCode, FieldRegistry, type FieldRegistryEntry, type InferResponse, type JSONSchema, REPORT_TEMPLATE_FIELD_TYPES, REPORT_TEMPLATE_VERSION, RepeatGroupFieldSchema, type ReportTemplateField, ReportTemplateFieldSchema, type ReportTemplateFieldType, type ReportTemplateSchema, ReportTemplateSchemaValidator, type ReportTemplateSection, ReportTemplateSectionSchema, type ResponseFieldError, type SimpleCondition, type TemplateDiff, buildBaseFieldSchema, buildResponseSchemaWithConditions, createUniqueId, diffTemplates, evaluateCondition, exportJSONSchema, migrateLegacySchema, normalizeReportTemplateSchema, parseReportTemplateSchema, parseReportTemplateSchemaFromString, serializeReportTemplateSchema, validateReportResponse, validateReportResponseDetailed };