@frt-platform/report-core 1.0.1 → 1.1.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/dist/index.d.mts +55 -30
- package/dist/index.d.ts +55 -30
- package/dist/index.js +149 -28
- package/dist/index.mjs +145 -27
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z, ZodTypeAny } from 'zod';
|
|
2
2
|
|
|
3
3
|
declare const REPORT_TEMPLATE_VERSION = 1;
|
|
4
4
|
declare const REPORT_TEMPLATE_FIELD_TYPES: readonly ["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"];
|
|
5
5
|
type ReportTemplateFieldType = (typeof REPORT_TEMPLATE_FIELD_TYPES)[number];
|
|
6
6
|
declare const ReportTemplateFieldSchema: z.ZodObject<{
|
|
7
7
|
id: z.ZodString;
|
|
8
|
-
type: z.
|
|
8
|
+
type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
|
|
9
9
|
label: z.ZodString;
|
|
10
10
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
11
11
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -23,12 +23,12 @@ declare const ReportTemplateFieldSchema: z.ZodObject<{
|
|
|
23
23
|
dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
|
|
24
24
|
}, "strip", z.ZodTypeAny, {
|
|
25
25
|
id: string;
|
|
26
|
-
type:
|
|
26
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
27
27
|
label: string;
|
|
28
|
+
options?: string[] | undefined;
|
|
28
29
|
required?: boolean | undefined;
|
|
29
30
|
description?: string | undefined;
|
|
30
31
|
placeholder?: string | undefined;
|
|
31
|
-
options?: string[] | undefined;
|
|
32
32
|
allowOther?: boolean | undefined;
|
|
33
33
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
34
34
|
minLength?: number | undefined;
|
|
@@ -41,12 +41,12 @@ declare const ReportTemplateFieldSchema: z.ZodObject<{
|
|
|
41
41
|
dataClassification?: "none" | "personal" | "special" | undefined;
|
|
42
42
|
}, {
|
|
43
43
|
id: string;
|
|
44
|
-
type:
|
|
44
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
45
45
|
label: string;
|
|
46
|
+
options?: string[] | undefined;
|
|
46
47
|
required?: boolean | undefined;
|
|
47
48
|
description?: string | undefined;
|
|
48
49
|
placeholder?: string | undefined;
|
|
49
|
-
options?: string[] | undefined;
|
|
50
50
|
allowOther?: boolean | undefined;
|
|
51
51
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
52
52
|
minLength?: number | undefined;
|
|
@@ -65,7 +65,7 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
65
65
|
description: z.ZodOptional<z.ZodString>;
|
|
66
66
|
fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
67
67
|
id: z.ZodString;
|
|
68
|
-
type: z.
|
|
68
|
+
type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
|
|
69
69
|
label: z.ZodString;
|
|
70
70
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
71
71
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -83,12 +83,12 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
83
83
|
dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
|
|
84
84
|
}, "strip", z.ZodTypeAny, {
|
|
85
85
|
id: string;
|
|
86
|
-
type:
|
|
86
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
87
87
|
label: string;
|
|
88
|
+
options?: string[] | undefined;
|
|
88
89
|
required?: boolean | undefined;
|
|
89
90
|
description?: string | undefined;
|
|
90
91
|
placeholder?: string | undefined;
|
|
91
|
-
options?: string[] | undefined;
|
|
92
92
|
allowOther?: boolean | undefined;
|
|
93
93
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
94
94
|
minLength?: number | undefined;
|
|
@@ -101,12 +101,12 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
101
101
|
dataClassification?: "none" | "personal" | "special" | undefined;
|
|
102
102
|
}, {
|
|
103
103
|
id: string;
|
|
104
|
-
type:
|
|
104
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
105
105
|
label: string;
|
|
106
|
+
options?: string[] | undefined;
|
|
106
107
|
required?: boolean | undefined;
|
|
107
108
|
description?: string | undefined;
|
|
108
109
|
placeholder?: string | undefined;
|
|
109
|
-
options?: string[] | undefined;
|
|
110
110
|
allowOther?: boolean | undefined;
|
|
111
111
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
112
112
|
minLength?: number | undefined;
|
|
@@ -122,12 +122,12 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
122
122
|
id: string;
|
|
123
123
|
fields: {
|
|
124
124
|
id: string;
|
|
125
|
-
type:
|
|
125
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
126
126
|
label: string;
|
|
127
|
+
options?: string[] | undefined;
|
|
127
128
|
required?: boolean | undefined;
|
|
128
129
|
description?: string | undefined;
|
|
129
130
|
placeholder?: string | undefined;
|
|
130
|
-
options?: string[] | undefined;
|
|
131
131
|
allowOther?: boolean | undefined;
|
|
132
132
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
133
133
|
minLength?: number | undefined;
|
|
@@ -147,12 +147,12 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
147
147
|
title?: string | undefined;
|
|
148
148
|
fields?: {
|
|
149
149
|
id: string;
|
|
150
|
-
type:
|
|
150
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
151
151
|
label: string;
|
|
152
|
+
options?: string[] | undefined;
|
|
152
153
|
required?: boolean | undefined;
|
|
153
154
|
description?: string | undefined;
|
|
154
155
|
placeholder?: string | undefined;
|
|
155
|
-
options?: string[] | undefined;
|
|
156
156
|
allowOther?: boolean | undefined;
|
|
157
157
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
158
158
|
minLength?: number | undefined;
|
|
@@ -176,7 +176,7 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
176
176
|
description: z.ZodOptional<z.ZodString>;
|
|
177
177
|
fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
178
178
|
id: z.ZodString;
|
|
179
|
-
type: z.
|
|
179
|
+
type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
|
|
180
180
|
label: z.ZodString;
|
|
181
181
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
182
182
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -194,12 +194,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
194
194
|
dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
|
|
195
195
|
}, "strip", z.ZodTypeAny, {
|
|
196
196
|
id: string;
|
|
197
|
-
type:
|
|
197
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
198
198
|
label: string;
|
|
199
|
+
options?: string[] | undefined;
|
|
199
200
|
required?: boolean | undefined;
|
|
200
201
|
description?: string | undefined;
|
|
201
202
|
placeholder?: string | undefined;
|
|
202
|
-
options?: string[] | undefined;
|
|
203
203
|
allowOther?: boolean | undefined;
|
|
204
204
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
205
205
|
minLength?: number | undefined;
|
|
@@ -212,12 +212,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
212
212
|
dataClassification?: "none" | "personal" | "special" | undefined;
|
|
213
213
|
}, {
|
|
214
214
|
id: string;
|
|
215
|
-
type:
|
|
215
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
216
216
|
label: string;
|
|
217
|
+
options?: string[] | undefined;
|
|
217
218
|
required?: boolean | undefined;
|
|
218
219
|
description?: string | undefined;
|
|
219
220
|
placeholder?: string | undefined;
|
|
220
|
-
options?: string[] | undefined;
|
|
221
221
|
allowOther?: boolean | undefined;
|
|
222
222
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
223
223
|
minLength?: number | undefined;
|
|
@@ -233,12 +233,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
233
233
|
id: string;
|
|
234
234
|
fields: {
|
|
235
235
|
id: string;
|
|
236
|
-
type:
|
|
236
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
237
237
|
label: string;
|
|
238
|
+
options?: string[] | undefined;
|
|
238
239
|
required?: boolean | undefined;
|
|
239
240
|
description?: string | undefined;
|
|
240
241
|
placeholder?: string | undefined;
|
|
241
|
-
options?: string[] | undefined;
|
|
242
242
|
allowOther?: boolean | undefined;
|
|
243
243
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
244
244
|
minLength?: number | undefined;
|
|
@@ -258,12 +258,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
258
258
|
title?: string | undefined;
|
|
259
259
|
fields?: {
|
|
260
260
|
id: string;
|
|
261
|
-
type:
|
|
261
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
262
262
|
label: string;
|
|
263
|
+
options?: string[] | undefined;
|
|
263
264
|
required?: boolean | undefined;
|
|
264
265
|
description?: string | undefined;
|
|
265
266
|
placeholder?: string | undefined;
|
|
266
|
-
options?: string[] | undefined;
|
|
267
267
|
allowOther?: boolean | undefined;
|
|
268
268
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
269
269
|
minLength?: number | undefined;
|
|
@@ -282,12 +282,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
282
282
|
id: string;
|
|
283
283
|
fields: {
|
|
284
284
|
id: string;
|
|
285
|
-
type:
|
|
285
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
286
286
|
label: string;
|
|
287
|
+
options?: string[] | undefined;
|
|
287
288
|
required?: boolean | undefined;
|
|
288
289
|
description?: string | undefined;
|
|
289
290
|
placeholder?: string | undefined;
|
|
290
|
-
options?: string[] | undefined;
|
|
291
291
|
allowOther?: boolean | undefined;
|
|
292
292
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
293
293
|
minLength?: number | undefined;
|
|
@@ -314,12 +314,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
314
314
|
title?: string | undefined;
|
|
315
315
|
fields?: {
|
|
316
316
|
id: string;
|
|
317
|
-
type:
|
|
317
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
318
318
|
label: string;
|
|
319
|
+
options?: string[] | undefined;
|
|
319
320
|
required?: boolean | undefined;
|
|
320
321
|
description?: string | undefined;
|
|
321
322
|
placeholder?: string | undefined;
|
|
322
|
-
options?: string[] | undefined;
|
|
323
323
|
allowOther?: boolean | undefined;
|
|
324
324
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
325
325
|
minLength?: number | undefined;
|
|
@@ -340,11 +340,36 @@ declare const CORE_FIELD_DEFAULTS: Record<ReportTemplateFieldType, Record<string
|
|
|
340
340
|
|
|
341
341
|
declare function createUniqueId(prefix: string, existing: Iterable<string>): string;
|
|
342
342
|
|
|
343
|
+
declare function migrateLegacySchema(raw: unknown): unknown;
|
|
344
|
+
|
|
343
345
|
declare function parseReportTemplateSchema(raw: unknown): ReportTemplateSchema;
|
|
344
346
|
declare function normalizeReportTemplateSchema(schema: ReportTemplateSchema): ReportTemplateSchema;
|
|
345
347
|
declare function parseReportTemplateSchemaFromString(raw: string): ReportTemplateSchema;
|
|
346
348
|
declare function serializeReportTemplateSchema(schema: ReportTemplateSchema): string;
|
|
347
349
|
|
|
348
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Build a Zod schema for a single field's response value.
|
|
352
|
+
*
|
|
353
|
+
* The response object shape is:
|
|
354
|
+
* { [fieldId: string]: unknown }
|
|
355
|
+
*/
|
|
356
|
+
declare function buildFieldResponseSchema(field: ReportTemplateField): ZodTypeAny;
|
|
357
|
+
/**
|
|
358
|
+
* Build a Zod schema for an entire report response.
|
|
359
|
+
*
|
|
360
|
+
* Shape:
|
|
361
|
+
* {
|
|
362
|
+
* [fieldId: string]: value
|
|
363
|
+
* }
|
|
364
|
+
*
|
|
365
|
+
* Where each fieldId corresponds to a field from the template.
|
|
366
|
+
*/
|
|
367
|
+
declare function buildResponseSchema(template: ReportTemplateSchema): z.ZodObject<Record<string, ZodTypeAny>>;
|
|
368
|
+
/**
|
|
369
|
+
* Convenience helper: validate a response object against a template.
|
|
370
|
+
*
|
|
371
|
+
* Throws ZodError on failure.
|
|
372
|
+
*/
|
|
373
|
+
declare function validateReportResponse(template: ReportTemplateSchema, data: unknown): Record<string, unknown>;
|
|
349
374
|
|
|
350
|
-
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, createUniqueId, migrateLegacySchema, normalizeReportTemplateSchema, parseReportTemplateSchema, parseReportTemplateSchemaFromString, serializeReportTemplateSchema };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z, ZodTypeAny } from 'zod';
|
|
2
2
|
|
|
3
3
|
declare const REPORT_TEMPLATE_VERSION = 1;
|
|
4
4
|
declare const REPORT_TEMPLATE_FIELD_TYPES: readonly ["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"];
|
|
5
5
|
type ReportTemplateFieldType = (typeof REPORT_TEMPLATE_FIELD_TYPES)[number];
|
|
6
6
|
declare const ReportTemplateFieldSchema: z.ZodObject<{
|
|
7
7
|
id: z.ZodString;
|
|
8
|
-
type: z.
|
|
8
|
+
type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
|
|
9
9
|
label: z.ZodString;
|
|
10
10
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
11
11
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -23,12 +23,12 @@ declare const ReportTemplateFieldSchema: z.ZodObject<{
|
|
|
23
23
|
dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
|
|
24
24
|
}, "strip", z.ZodTypeAny, {
|
|
25
25
|
id: string;
|
|
26
|
-
type:
|
|
26
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
27
27
|
label: string;
|
|
28
|
+
options?: string[] | undefined;
|
|
28
29
|
required?: boolean | undefined;
|
|
29
30
|
description?: string | undefined;
|
|
30
31
|
placeholder?: string | undefined;
|
|
31
|
-
options?: string[] | undefined;
|
|
32
32
|
allowOther?: boolean | undefined;
|
|
33
33
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
34
34
|
minLength?: number | undefined;
|
|
@@ -41,12 +41,12 @@ declare const ReportTemplateFieldSchema: z.ZodObject<{
|
|
|
41
41
|
dataClassification?: "none" | "personal" | "special" | undefined;
|
|
42
42
|
}, {
|
|
43
43
|
id: string;
|
|
44
|
-
type:
|
|
44
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
45
45
|
label: string;
|
|
46
|
+
options?: string[] | undefined;
|
|
46
47
|
required?: boolean | undefined;
|
|
47
48
|
description?: string | undefined;
|
|
48
49
|
placeholder?: string | undefined;
|
|
49
|
-
options?: string[] | undefined;
|
|
50
50
|
allowOther?: boolean | undefined;
|
|
51
51
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
52
52
|
minLength?: number | undefined;
|
|
@@ -65,7 +65,7 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
65
65
|
description: z.ZodOptional<z.ZodString>;
|
|
66
66
|
fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
67
67
|
id: z.ZodString;
|
|
68
|
-
type: z.
|
|
68
|
+
type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
|
|
69
69
|
label: z.ZodString;
|
|
70
70
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
71
71
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -83,12 +83,12 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
83
83
|
dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
|
|
84
84
|
}, "strip", z.ZodTypeAny, {
|
|
85
85
|
id: string;
|
|
86
|
-
type:
|
|
86
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
87
87
|
label: string;
|
|
88
|
+
options?: string[] | undefined;
|
|
88
89
|
required?: boolean | undefined;
|
|
89
90
|
description?: string | undefined;
|
|
90
91
|
placeholder?: string | undefined;
|
|
91
|
-
options?: string[] | undefined;
|
|
92
92
|
allowOther?: boolean | undefined;
|
|
93
93
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
94
94
|
minLength?: number | undefined;
|
|
@@ -101,12 +101,12 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
101
101
|
dataClassification?: "none" | "personal" | "special" | undefined;
|
|
102
102
|
}, {
|
|
103
103
|
id: string;
|
|
104
|
-
type:
|
|
104
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
105
105
|
label: string;
|
|
106
|
+
options?: string[] | undefined;
|
|
106
107
|
required?: boolean | undefined;
|
|
107
108
|
description?: string | undefined;
|
|
108
109
|
placeholder?: string | undefined;
|
|
109
|
-
options?: string[] | undefined;
|
|
110
110
|
allowOther?: boolean | undefined;
|
|
111
111
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
112
112
|
minLength?: number | undefined;
|
|
@@ -122,12 +122,12 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
122
122
|
id: string;
|
|
123
123
|
fields: {
|
|
124
124
|
id: string;
|
|
125
|
-
type:
|
|
125
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
126
126
|
label: string;
|
|
127
|
+
options?: string[] | undefined;
|
|
127
128
|
required?: boolean | undefined;
|
|
128
129
|
description?: string | undefined;
|
|
129
130
|
placeholder?: string | undefined;
|
|
130
|
-
options?: string[] | undefined;
|
|
131
131
|
allowOther?: boolean | undefined;
|
|
132
132
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
133
133
|
minLength?: number | undefined;
|
|
@@ -147,12 +147,12 @@ declare const ReportTemplateSectionSchema: z.ZodObject<{
|
|
|
147
147
|
title?: string | undefined;
|
|
148
148
|
fields?: {
|
|
149
149
|
id: string;
|
|
150
|
-
type:
|
|
150
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
151
151
|
label: string;
|
|
152
|
+
options?: string[] | undefined;
|
|
152
153
|
required?: boolean | undefined;
|
|
153
154
|
description?: string | undefined;
|
|
154
155
|
placeholder?: string | undefined;
|
|
155
|
-
options?: string[] | undefined;
|
|
156
156
|
allowOther?: boolean | undefined;
|
|
157
157
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
158
158
|
minLength?: number | undefined;
|
|
@@ -176,7 +176,7 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
176
176
|
description: z.ZodOptional<z.ZodString>;
|
|
177
177
|
fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
178
178
|
id: z.ZodString;
|
|
179
|
-
type: z.
|
|
179
|
+
type: z.ZodEnum<["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect"]>;
|
|
180
180
|
label: z.ZodString;
|
|
181
181
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
182
182
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -194,12 +194,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
194
194
|
dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
|
|
195
195
|
}, "strip", z.ZodTypeAny, {
|
|
196
196
|
id: string;
|
|
197
|
-
type:
|
|
197
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
198
198
|
label: string;
|
|
199
|
+
options?: string[] | undefined;
|
|
199
200
|
required?: boolean | undefined;
|
|
200
201
|
description?: string | undefined;
|
|
201
202
|
placeholder?: string | undefined;
|
|
202
|
-
options?: string[] | undefined;
|
|
203
203
|
allowOther?: boolean | undefined;
|
|
204
204
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
205
205
|
minLength?: number | undefined;
|
|
@@ -212,12 +212,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
212
212
|
dataClassification?: "none" | "personal" | "special" | undefined;
|
|
213
213
|
}, {
|
|
214
214
|
id: string;
|
|
215
|
-
type:
|
|
215
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
216
216
|
label: string;
|
|
217
|
+
options?: string[] | undefined;
|
|
217
218
|
required?: boolean | undefined;
|
|
218
219
|
description?: string | undefined;
|
|
219
220
|
placeholder?: string | undefined;
|
|
220
|
-
options?: string[] | undefined;
|
|
221
221
|
allowOther?: boolean | undefined;
|
|
222
222
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
223
223
|
minLength?: number | undefined;
|
|
@@ -233,12 +233,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
233
233
|
id: string;
|
|
234
234
|
fields: {
|
|
235
235
|
id: string;
|
|
236
|
-
type:
|
|
236
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
237
237
|
label: string;
|
|
238
|
+
options?: string[] | undefined;
|
|
238
239
|
required?: boolean | undefined;
|
|
239
240
|
description?: string | undefined;
|
|
240
241
|
placeholder?: string | undefined;
|
|
241
|
-
options?: string[] | undefined;
|
|
242
242
|
allowOther?: boolean | undefined;
|
|
243
243
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
244
244
|
minLength?: number | undefined;
|
|
@@ -258,12 +258,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
258
258
|
title?: string | undefined;
|
|
259
259
|
fields?: {
|
|
260
260
|
id: string;
|
|
261
|
-
type:
|
|
261
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
262
262
|
label: string;
|
|
263
|
+
options?: string[] | undefined;
|
|
263
264
|
required?: boolean | undefined;
|
|
264
265
|
description?: string | undefined;
|
|
265
266
|
placeholder?: string | undefined;
|
|
266
|
-
options?: string[] | undefined;
|
|
267
267
|
allowOther?: boolean | undefined;
|
|
268
268
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
269
269
|
minLength?: number | undefined;
|
|
@@ -282,12 +282,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
282
282
|
id: string;
|
|
283
283
|
fields: {
|
|
284
284
|
id: string;
|
|
285
|
-
type:
|
|
285
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
286
286
|
label: string;
|
|
287
|
+
options?: string[] | undefined;
|
|
287
288
|
required?: boolean | undefined;
|
|
288
289
|
description?: string | undefined;
|
|
289
290
|
placeholder?: string | undefined;
|
|
290
|
-
options?: string[] | undefined;
|
|
291
291
|
allowOther?: boolean | undefined;
|
|
292
292
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
293
293
|
minLength?: number | undefined;
|
|
@@ -314,12 +314,12 @@ declare const ReportTemplateSchemaValidator: z.ZodObject<{
|
|
|
314
314
|
title?: string | undefined;
|
|
315
315
|
fields?: {
|
|
316
316
|
id: string;
|
|
317
|
-
type:
|
|
317
|
+
type: "number" | "shortText" | "longText" | "date" | "checkbox" | "singleSelect" | "multiSelect";
|
|
318
318
|
label: string;
|
|
319
|
+
options?: string[] | undefined;
|
|
319
320
|
required?: boolean | undefined;
|
|
320
321
|
description?: string | undefined;
|
|
321
322
|
placeholder?: string | undefined;
|
|
322
|
-
options?: string[] | undefined;
|
|
323
323
|
allowOther?: boolean | undefined;
|
|
324
324
|
defaultValue?: string | number | boolean | string[] | null | undefined;
|
|
325
325
|
minLength?: number | undefined;
|
|
@@ -340,11 +340,36 @@ declare const CORE_FIELD_DEFAULTS: Record<ReportTemplateFieldType, Record<string
|
|
|
340
340
|
|
|
341
341
|
declare function createUniqueId(prefix: string, existing: Iterable<string>): string;
|
|
342
342
|
|
|
343
|
+
declare function migrateLegacySchema(raw: unknown): unknown;
|
|
344
|
+
|
|
343
345
|
declare function parseReportTemplateSchema(raw: unknown): ReportTemplateSchema;
|
|
344
346
|
declare function normalizeReportTemplateSchema(schema: ReportTemplateSchema): ReportTemplateSchema;
|
|
345
347
|
declare function parseReportTemplateSchemaFromString(raw: string): ReportTemplateSchema;
|
|
346
348
|
declare function serializeReportTemplateSchema(schema: ReportTemplateSchema): string;
|
|
347
349
|
|
|
348
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Build a Zod schema for a single field's response value.
|
|
352
|
+
*
|
|
353
|
+
* The response object shape is:
|
|
354
|
+
* { [fieldId: string]: unknown }
|
|
355
|
+
*/
|
|
356
|
+
declare function buildFieldResponseSchema(field: ReportTemplateField): ZodTypeAny;
|
|
357
|
+
/**
|
|
358
|
+
* Build a Zod schema for an entire report response.
|
|
359
|
+
*
|
|
360
|
+
* Shape:
|
|
361
|
+
* {
|
|
362
|
+
* [fieldId: string]: value
|
|
363
|
+
* }
|
|
364
|
+
*
|
|
365
|
+
* Where each fieldId corresponds to a field from the template.
|
|
366
|
+
*/
|
|
367
|
+
declare function buildResponseSchema(template: ReportTemplateSchema): z.ZodObject<Record<string, ZodTypeAny>>;
|
|
368
|
+
/**
|
|
369
|
+
* Convenience helper: validate a response object against a template.
|
|
370
|
+
*
|
|
371
|
+
* Throws ZodError on failure.
|
|
372
|
+
*/
|
|
373
|
+
declare function validateReportResponse(template: ReportTemplateSchema, data: unknown): Record<string, unknown>;
|
|
349
374
|
|
|
350
|
-
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, createUniqueId, migrateLegacySchema, normalizeReportTemplateSchema, parseReportTemplateSchema, parseReportTemplateSchemaFromString, serializeReportTemplateSchema };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -27,12 +27,15 @@ __export(index_exports, {
|
|
|
27
27
|
ReportTemplateFieldSchema: () => ReportTemplateFieldSchema,
|
|
28
28
|
ReportTemplateSchemaValidator: () => ReportTemplateSchemaValidator,
|
|
29
29
|
ReportTemplateSectionSchema: () => ReportTemplateSectionSchema,
|
|
30
|
+
buildFieldResponseSchema: () => buildFieldResponseSchema,
|
|
31
|
+
buildResponseSchema: () => buildResponseSchema,
|
|
30
32
|
createUniqueId: () => createUniqueId,
|
|
31
33
|
migrateLegacySchema: () => migrateLegacySchema,
|
|
32
34
|
normalizeReportTemplateSchema: () => normalizeReportTemplateSchema,
|
|
33
35
|
parseReportTemplateSchema: () => parseReportTemplateSchema,
|
|
34
36
|
parseReportTemplateSchemaFromString: () => parseReportTemplateSchemaFromString,
|
|
35
|
-
serializeReportTemplateSchema: () => serializeReportTemplateSchema
|
|
37
|
+
serializeReportTemplateSchema: () => serializeReportTemplateSchema,
|
|
38
|
+
validateReportResponse: () => validateReportResponse
|
|
36
39
|
});
|
|
37
40
|
module.exports = __toCommonJS(index_exports);
|
|
38
41
|
|
|
@@ -49,21 +52,20 @@ var REPORT_TEMPLATE_FIELD_TYPES = [
|
|
|
49
52
|
"multiSelect"
|
|
50
53
|
];
|
|
51
54
|
var ReportTemplateFieldSchema = import_zod.z.object({
|
|
52
|
-
id: import_zod.z.string().min(1).max(60).regex(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
id: import_zod.z.string().min(1, "Field identifiers cannot be empty.").max(60, "Field identifiers must be 60 characters or fewer.").regex(
|
|
56
|
+
/^[a-z0-9_-]+$/,
|
|
57
|
+
"Use lowercase letters, numbers, underscores, or dashes for field identifiers."
|
|
58
|
+
),
|
|
59
|
+
type: import_zod.z.enum(REPORT_TEMPLATE_FIELD_TYPES),
|
|
60
|
+
label: import_zod.z.string().min(1, "Field labels cannot be empty.").max(200, "Field labels must be 200 characters or fewer."),
|
|
55
61
|
required: import_zod.z.boolean().optional(),
|
|
56
|
-
description: import_zod.z.string().max(400).optional(),
|
|
57
|
-
placeholder: import_zod.z.string().max(200).optional(),
|
|
58
|
-
options: import_zod.z.array(
|
|
62
|
+
description: import_zod.z.string().max(400, "Descriptions must be 400 characters or fewer.").optional(),
|
|
63
|
+
placeholder: import_zod.z.string().max(200, "Placeholders must be 200 characters or fewer.").optional(),
|
|
64
|
+
options: import_zod.z.array(
|
|
65
|
+
import_zod.z.string().min(1, "Options cannot be empty.").max(120, "Options must be 120 characters or fewer.")
|
|
66
|
+
).optional(),
|
|
59
67
|
allowOther: import_zod.z.boolean().optional(),
|
|
60
|
-
defaultValue: import_zod.z.union([
|
|
61
|
-
import_zod.z.string(),
|
|
62
|
-
import_zod.z.number(),
|
|
63
|
-
import_zod.z.boolean(),
|
|
64
|
-
import_zod.z.array(import_zod.z.string()),
|
|
65
|
-
import_zod.z.null()
|
|
66
|
-
]).optional(),
|
|
68
|
+
defaultValue: import_zod.z.union([import_zod.z.string(), import_zod.z.number(), import_zod.z.boolean(), import_zod.z.array(import_zod.z.string()), import_zod.z.null()]).optional(),
|
|
67
69
|
minLength: import_zod.z.number().int().min(0).optional(),
|
|
68
70
|
maxLength: import_zod.z.number().int().min(0).optional(),
|
|
69
71
|
minValue: import_zod.z.number().optional(),
|
|
@@ -74,26 +76,43 @@ var ReportTemplateFieldSchema = import_zod.z.object({
|
|
|
74
76
|
dataClassification: import_zod.z.enum(["none", "personal", "special"]).optional()
|
|
75
77
|
});
|
|
76
78
|
var ReportTemplateSectionSchema = import_zod.z.object({
|
|
77
|
-
id: import_zod.z.string().min(1).max(60).regex(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
id: import_zod.z.string().min(1, "Section identifiers cannot be empty.").max(60, "Section identifiers must be 60 characters or fewer.").regex(
|
|
80
|
+
/^[a-z0-9_-]+$/,
|
|
81
|
+
"Use lowercase letters, numbers, underscores, or dashes for section identifiers."
|
|
82
|
+
),
|
|
83
|
+
title: import_zod.z.string().max(200, "Section titles must be 200 characters or fewer.").optional(),
|
|
84
|
+
description: import_zod.z.string().max(500, "Section descriptions must be 500 characters or fewer.").optional(),
|
|
85
|
+
fields: import_zod.z.array(ReportTemplateFieldSchema).max(50, "Sections can include at most 50 fields.").default([])
|
|
81
86
|
});
|
|
82
87
|
var ReportTemplateSchemaValidator = import_zod.z.object({
|
|
83
|
-
version: import_zod.z.number().int().min(1).default(REPORT_TEMPLATE_VERSION),
|
|
84
|
-
title: import_zod.z.string().max(200).optional(),
|
|
85
|
-
description: import_zod.z.string().max(500).optional(),
|
|
86
|
-
sections: import_zod.z.array(ReportTemplateSectionSchema).max(25).default([])
|
|
88
|
+
version: import_zod.z.number().int().min(1).max(REPORT_TEMPLATE_VERSION).default(REPORT_TEMPLATE_VERSION),
|
|
89
|
+
title: import_zod.z.string().max(200, "Template titles must be 200 characters or fewer.").optional(),
|
|
90
|
+
description: import_zod.z.string().max(500, "Template descriptions must be 500 characters or fewer.").optional(),
|
|
91
|
+
sections: import_zod.z.array(ReportTemplateSectionSchema).max(25, "Templates can include at most 25 sections.").default([])
|
|
87
92
|
});
|
|
88
93
|
|
|
89
94
|
// src/fields.ts
|
|
90
95
|
var DEFAULT_FIELD_LABEL = "Untitled question";
|
|
91
96
|
var CORE_FIELD_DEFAULTS = {
|
|
92
|
-
shortText: {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
shortText: {
|
|
98
|
+
label: DEFAULT_FIELD_LABEL,
|
|
99
|
+
placeholder: "Short answer text"
|
|
100
|
+
},
|
|
101
|
+
longText: {
|
|
102
|
+
label: DEFAULT_FIELD_LABEL,
|
|
103
|
+
placeholder: "Long answer text"
|
|
104
|
+
},
|
|
105
|
+
number: {
|
|
106
|
+
label: DEFAULT_FIELD_LABEL,
|
|
107
|
+
placeholder: "123"
|
|
108
|
+
},
|
|
109
|
+
date: {
|
|
110
|
+
label: DEFAULT_FIELD_LABEL
|
|
111
|
+
},
|
|
112
|
+
checkbox: {
|
|
113
|
+
label: DEFAULT_FIELD_LABEL,
|
|
114
|
+
placeholder: "Check to confirm"
|
|
115
|
+
},
|
|
97
116
|
singleSelect: {
|
|
98
117
|
label: DEFAULT_FIELD_LABEL,
|
|
99
118
|
options: ["Option 1", "Option 2", "Option 3"]
|
|
@@ -121,16 +140,20 @@ function createUniqueId(prefix, existing) {
|
|
|
121
140
|
var LEGACY_FIELD_TYPE_MAP = {
|
|
122
141
|
shorttext: "shortText",
|
|
123
142
|
text: "shortText",
|
|
143
|
+
"text-box": "shortText",
|
|
124
144
|
longtext: "longText",
|
|
125
145
|
textarea: "longText",
|
|
146
|
+
paragraph: "longText",
|
|
126
147
|
number: "number",
|
|
127
148
|
numeric: "number",
|
|
128
149
|
date: "date",
|
|
129
150
|
checkbox: "checkbox",
|
|
130
151
|
boolean: "checkbox",
|
|
152
|
+
singleselect: "singleSelect",
|
|
131
153
|
select: "singleSelect",
|
|
132
154
|
dropdown: "singleSelect",
|
|
133
155
|
radio: "singleSelect",
|
|
156
|
+
"multi-select": "multiSelect",
|
|
134
157
|
multiselect: "multiSelect",
|
|
135
158
|
checkboxes: "multiSelect"
|
|
136
159
|
};
|
|
@@ -212,6 +235,101 @@ function parseReportTemplateSchemaFromString(raw) {
|
|
|
212
235
|
function serializeReportTemplateSchema(schema) {
|
|
213
236
|
return JSON.stringify(schema, null, 2);
|
|
214
237
|
}
|
|
238
|
+
|
|
239
|
+
// src/responses.ts
|
|
240
|
+
var import_zod2 = require("zod");
|
|
241
|
+
function buildFieldResponseSchema(field) {
|
|
242
|
+
const isRequired = Boolean(field.required);
|
|
243
|
+
switch (field.type) {
|
|
244
|
+
case "shortText":
|
|
245
|
+
case "longText": {
|
|
246
|
+
let schema = import_zod2.z.string();
|
|
247
|
+
if (typeof field.minLength === "number") {
|
|
248
|
+
schema = schema.min(field.minLength);
|
|
249
|
+
}
|
|
250
|
+
if (typeof field.maxLength === "number") {
|
|
251
|
+
schema = schema.max(field.maxLength);
|
|
252
|
+
}
|
|
253
|
+
return isRequired ? schema : schema.optional();
|
|
254
|
+
}
|
|
255
|
+
case "number": {
|
|
256
|
+
let schema = import_zod2.z.number();
|
|
257
|
+
if (typeof field.minValue === "number") {
|
|
258
|
+
schema = schema.min(field.minValue);
|
|
259
|
+
}
|
|
260
|
+
if (typeof field.maxValue === "number") {
|
|
261
|
+
schema = schema.max(field.maxValue);
|
|
262
|
+
}
|
|
263
|
+
return isRequired ? schema : schema.optional();
|
|
264
|
+
}
|
|
265
|
+
case "date": {
|
|
266
|
+
let schema = import_zod2.z.string();
|
|
267
|
+
return isRequired ? schema : schema.optional();
|
|
268
|
+
}
|
|
269
|
+
case "checkbox": {
|
|
270
|
+
if (isRequired) {
|
|
271
|
+
return import_zod2.z.literal(true);
|
|
272
|
+
}
|
|
273
|
+
return import_zod2.z.boolean().optional();
|
|
274
|
+
}
|
|
275
|
+
case "singleSelect": {
|
|
276
|
+
let schema = import_zod2.z.string();
|
|
277
|
+
if (Array.isArray(field.options) && field.options.length > 0) {
|
|
278
|
+
const allowed = new Set(field.options);
|
|
279
|
+
schema = schema.refine(
|
|
280
|
+
(value) => allowed.has(value),
|
|
281
|
+
"Value must be one of the defined options."
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
return isRequired ? schema : schema.optional();
|
|
285
|
+
}
|
|
286
|
+
case "multiSelect": {
|
|
287
|
+
let schema = import_zod2.z.array(import_zod2.z.string());
|
|
288
|
+
if (Array.isArray(field.options) && field.options.length > 0 && !field.allowOther) {
|
|
289
|
+
const allowed = new Set(field.options);
|
|
290
|
+
schema = schema.refine(
|
|
291
|
+
(values) => values.every((value) => allowed.has(value)),
|
|
292
|
+
"All values must be among the defined options."
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (typeof field.minSelections === "number") {
|
|
296
|
+
schema = schema.min(
|
|
297
|
+
field.minSelections,
|
|
298
|
+
`Select at least ${field.minSelections} option(s).`
|
|
299
|
+
);
|
|
300
|
+
} else if (isRequired) {
|
|
301
|
+
schema = schema.min(
|
|
302
|
+
1,
|
|
303
|
+
"Select at least one option."
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
if (typeof field.maxSelections === "number") {
|
|
307
|
+
schema = schema.max(
|
|
308
|
+
field.maxSelections,
|
|
309
|
+
`Select at most ${field.maxSelections} option(s).`
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
return isRequired ? schema : schema.optional();
|
|
313
|
+
}
|
|
314
|
+
default: {
|
|
315
|
+
const _exhaustive = field.type;
|
|
316
|
+
return import_zod2.z.any();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function buildResponseSchema(template) {
|
|
321
|
+
const shape = {};
|
|
322
|
+
for (const section of template.sections) {
|
|
323
|
+
for (const field of section.fields) {
|
|
324
|
+
shape[field.id] = buildFieldResponseSchema(field);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return import_zod2.z.object(shape);
|
|
328
|
+
}
|
|
329
|
+
function validateReportResponse(template, data) {
|
|
330
|
+
const schema = buildResponseSchema(template);
|
|
331
|
+
return schema.parse(data);
|
|
332
|
+
}
|
|
215
333
|
// Annotate the CommonJS export names for ESM import in node:
|
|
216
334
|
0 && (module.exports = {
|
|
217
335
|
CORE_FIELD_DEFAULTS,
|
|
@@ -221,10 +339,13 @@ function serializeReportTemplateSchema(schema) {
|
|
|
221
339
|
ReportTemplateFieldSchema,
|
|
222
340
|
ReportTemplateSchemaValidator,
|
|
223
341
|
ReportTemplateSectionSchema,
|
|
342
|
+
buildFieldResponseSchema,
|
|
343
|
+
buildResponseSchema,
|
|
224
344
|
createUniqueId,
|
|
225
345
|
migrateLegacySchema,
|
|
226
346
|
normalizeReportTemplateSchema,
|
|
227
347
|
parseReportTemplateSchema,
|
|
228
348
|
parseReportTemplateSchemaFromString,
|
|
229
|
-
serializeReportTemplateSchema
|
|
349
|
+
serializeReportTemplateSchema,
|
|
350
|
+
validateReportResponse
|
|
230
351
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -11,21 +11,20 @@ var REPORT_TEMPLATE_FIELD_TYPES = [
|
|
|
11
11
|
"multiSelect"
|
|
12
12
|
];
|
|
13
13
|
var ReportTemplateFieldSchema = z.object({
|
|
14
|
-
id: z.string().min(1).max(60).regex(
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
id: z.string().min(1, "Field identifiers cannot be empty.").max(60, "Field identifiers must be 60 characters or fewer.").regex(
|
|
15
|
+
/^[a-z0-9_-]+$/,
|
|
16
|
+
"Use lowercase letters, numbers, underscores, or dashes for field identifiers."
|
|
17
|
+
),
|
|
18
|
+
type: z.enum(REPORT_TEMPLATE_FIELD_TYPES),
|
|
19
|
+
label: z.string().min(1, "Field labels cannot be empty.").max(200, "Field labels must be 200 characters or fewer."),
|
|
17
20
|
required: z.boolean().optional(),
|
|
18
|
-
description: z.string().max(400).optional(),
|
|
19
|
-
placeholder: z.string().max(200).optional(),
|
|
20
|
-
options: z.array(
|
|
21
|
+
description: z.string().max(400, "Descriptions must be 400 characters or fewer.").optional(),
|
|
22
|
+
placeholder: z.string().max(200, "Placeholders must be 200 characters or fewer.").optional(),
|
|
23
|
+
options: z.array(
|
|
24
|
+
z.string().min(1, "Options cannot be empty.").max(120, "Options must be 120 characters or fewer.")
|
|
25
|
+
).optional(),
|
|
21
26
|
allowOther: z.boolean().optional(),
|
|
22
|
-
defaultValue: z.union([
|
|
23
|
-
z.string(),
|
|
24
|
-
z.number(),
|
|
25
|
-
z.boolean(),
|
|
26
|
-
z.array(z.string()),
|
|
27
|
-
z.null()
|
|
28
|
-
]).optional(),
|
|
27
|
+
defaultValue: z.union([z.string(), z.number(), z.boolean(), z.array(z.string()), z.null()]).optional(),
|
|
29
28
|
minLength: z.number().int().min(0).optional(),
|
|
30
29
|
maxLength: z.number().int().min(0).optional(),
|
|
31
30
|
minValue: z.number().optional(),
|
|
@@ -36,26 +35,43 @@ var ReportTemplateFieldSchema = z.object({
|
|
|
36
35
|
dataClassification: z.enum(["none", "personal", "special"]).optional()
|
|
37
36
|
});
|
|
38
37
|
var ReportTemplateSectionSchema = z.object({
|
|
39
|
-
id: z.string().min(1).max(60).regex(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
id: z.string().min(1, "Section identifiers cannot be empty.").max(60, "Section identifiers must be 60 characters or fewer.").regex(
|
|
39
|
+
/^[a-z0-9_-]+$/,
|
|
40
|
+
"Use lowercase letters, numbers, underscores, or dashes for section identifiers."
|
|
41
|
+
),
|
|
42
|
+
title: z.string().max(200, "Section titles must be 200 characters or fewer.").optional(),
|
|
43
|
+
description: z.string().max(500, "Section descriptions must be 500 characters or fewer.").optional(),
|
|
44
|
+
fields: z.array(ReportTemplateFieldSchema).max(50, "Sections can include at most 50 fields.").default([])
|
|
43
45
|
});
|
|
44
46
|
var ReportTemplateSchemaValidator = z.object({
|
|
45
|
-
version: z.number().int().min(1).default(REPORT_TEMPLATE_VERSION),
|
|
46
|
-
title: z.string().max(200).optional(),
|
|
47
|
-
description: z.string().max(500).optional(),
|
|
48
|
-
sections: z.array(ReportTemplateSectionSchema).max(25).default([])
|
|
47
|
+
version: z.number().int().min(1).max(REPORT_TEMPLATE_VERSION).default(REPORT_TEMPLATE_VERSION),
|
|
48
|
+
title: z.string().max(200, "Template titles must be 200 characters or fewer.").optional(),
|
|
49
|
+
description: z.string().max(500, "Template descriptions must be 500 characters or fewer.").optional(),
|
|
50
|
+
sections: z.array(ReportTemplateSectionSchema).max(25, "Templates can include at most 25 sections.").default([])
|
|
49
51
|
});
|
|
50
52
|
|
|
51
53
|
// src/fields.ts
|
|
52
54
|
var DEFAULT_FIELD_LABEL = "Untitled question";
|
|
53
55
|
var CORE_FIELD_DEFAULTS = {
|
|
54
|
-
shortText: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
shortText: {
|
|
57
|
+
label: DEFAULT_FIELD_LABEL,
|
|
58
|
+
placeholder: "Short answer text"
|
|
59
|
+
},
|
|
60
|
+
longText: {
|
|
61
|
+
label: DEFAULT_FIELD_LABEL,
|
|
62
|
+
placeholder: "Long answer text"
|
|
63
|
+
},
|
|
64
|
+
number: {
|
|
65
|
+
label: DEFAULT_FIELD_LABEL,
|
|
66
|
+
placeholder: "123"
|
|
67
|
+
},
|
|
68
|
+
date: {
|
|
69
|
+
label: DEFAULT_FIELD_LABEL
|
|
70
|
+
},
|
|
71
|
+
checkbox: {
|
|
72
|
+
label: DEFAULT_FIELD_LABEL,
|
|
73
|
+
placeholder: "Check to confirm"
|
|
74
|
+
},
|
|
59
75
|
singleSelect: {
|
|
60
76
|
label: DEFAULT_FIELD_LABEL,
|
|
61
77
|
options: ["Option 1", "Option 2", "Option 3"]
|
|
@@ -83,16 +99,20 @@ function createUniqueId(prefix, existing) {
|
|
|
83
99
|
var LEGACY_FIELD_TYPE_MAP = {
|
|
84
100
|
shorttext: "shortText",
|
|
85
101
|
text: "shortText",
|
|
102
|
+
"text-box": "shortText",
|
|
86
103
|
longtext: "longText",
|
|
87
104
|
textarea: "longText",
|
|
105
|
+
paragraph: "longText",
|
|
88
106
|
number: "number",
|
|
89
107
|
numeric: "number",
|
|
90
108
|
date: "date",
|
|
91
109
|
checkbox: "checkbox",
|
|
92
110
|
boolean: "checkbox",
|
|
111
|
+
singleselect: "singleSelect",
|
|
93
112
|
select: "singleSelect",
|
|
94
113
|
dropdown: "singleSelect",
|
|
95
114
|
radio: "singleSelect",
|
|
115
|
+
"multi-select": "multiSelect",
|
|
96
116
|
multiselect: "multiSelect",
|
|
97
117
|
checkboxes: "multiSelect"
|
|
98
118
|
};
|
|
@@ -174,6 +194,101 @@ function parseReportTemplateSchemaFromString(raw) {
|
|
|
174
194
|
function serializeReportTemplateSchema(schema) {
|
|
175
195
|
return JSON.stringify(schema, null, 2);
|
|
176
196
|
}
|
|
197
|
+
|
|
198
|
+
// src/responses.ts
|
|
199
|
+
import { z as z2 } from "zod";
|
|
200
|
+
function buildFieldResponseSchema(field) {
|
|
201
|
+
const isRequired = Boolean(field.required);
|
|
202
|
+
switch (field.type) {
|
|
203
|
+
case "shortText":
|
|
204
|
+
case "longText": {
|
|
205
|
+
let schema = z2.string();
|
|
206
|
+
if (typeof field.minLength === "number") {
|
|
207
|
+
schema = schema.min(field.minLength);
|
|
208
|
+
}
|
|
209
|
+
if (typeof field.maxLength === "number") {
|
|
210
|
+
schema = schema.max(field.maxLength);
|
|
211
|
+
}
|
|
212
|
+
return isRequired ? schema : schema.optional();
|
|
213
|
+
}
|
|
214
|
+
case "number": {
|
|
215
|
+
let schema = z2.number();
|
|
216
|
+
if (typeof field.minValue === "number") {
|
|
217
|
+
schema = schema.min(field.minValue);
|
|
218
|
+
}
|
|
219
|
+
if (typeof field.maxValue === "number") {
|
|
220
|
+
schema = schema.max(field.maxValue);
|
|
221
|
+
}
|
|
222
|
+
return isRequired ? schema : schema.optional();
|
|
223
|
+
}
|
|
224
|
+
case "date": {
|
|
225
|
+
let schema = z2.string();
|
|
226
|
+
return isRequired ? schema : schema.optional();
|
|
227
|
+
}
|
|
228
|
+
case "checkbox": {
|
|
229
|
+
if (isRequired) {
|
|
230
|
+
return z2.literal(true);
|
|
231
|
+
}
|
|
232
|
+
return z2.boolean().optional();
|
|
233
|
+
}
|
|
234
|
+
case "singleSelect": {
|
|
235
|
+
let schema = z2.string();
|
|
236
|
+
if (Array.isArray(field.options) && field.options.length > 0) {
|
|
237
|
+
const allowed = new Set(field.options);
|
|
238
|
+
schema = schema.refine(
|
|
239
|
+
(value) => allowed.has(value),
|
|
240
|
+
"Value must be one of the defined options."
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
return isRequired ? schema : schema.optional();
|
|
244
|
+
}
|
|
245
|
+
case "multiSelect": {
|
|
246
|
+
let schema = z2.array(z2.string());
|
|
247
|
+
if (Array.isArray(field.options) && field.options.length > 0 && !field.allowOther) {
|
|
248
|
+
const allowed = new Set(field.options);
|
|
249
|
+
schema = schema.refine(
|
|
250
|
+
(values) => values.every((value) => allowed.has(value)),
|
|
251
|
+
"All values must be among the defined options."
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
if (typeof field.minSelections === "number") {
|
|
255
|
+
schema = schema.min(
|
|
256
|
+
field.minSelections,
|
|
257
|
+
`Select at least ${field.minSelections} option(s).`
|
|
258
|
+
);
|
|
259
|
+
} else if (isRequired) {
|
|
260
|
+
schema = schema.min(
|
|
261
|
+
1,
|
|
262
|
+
"Select at least one option."
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (typeof field.maxSelections === "number") {
|
|
266
|
+
schema = schema.max(
|
|
267
|
+
field.maxSelections,
|
|
268
|
+
`Select at most ${field.maxSelections} option(s).`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return isRequired ? schema : schema.optional();
|
|
272
|
+
}
|
|
273
|
+
default: {
|
|
274
|
+
const _exhaustive = field.type;
|
|
275
|
+
return z2.any();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function buildResponseSchema(template) {
|
|
280
|
+
const shape = {};
|
|
281
|
+
for (const section of template.sections) {
|
|
282
|
+
for (const field of section.fields) {
|
|
283
|
+
shape[field.id] = buildFieldResponseSchema(field);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return z2.object(shape);
|
|
287
|
+
}
|
|
288
|
+
function validateReportResponse(template, data) {
|
|
289
|
+
const schema = buildResponseSchema(template);
|
|
290
|
+
return schema.parse(data);
|
|
291
|
+
}
|
|
177
292
|
export {
|
|
178
293
|
CORE_FIELD_DEFAULTS,
|
|
179
294
|
DEFAULT_FIELD_LABEL,
|
|
@@ -182,10 +297,13 @@ export {
|
|
|
182
297
|
ReportTemplateFieldSchema,
|
|
183
298
|
ReportTemplateSchemaValidator,
|
|
184
299
|
ReportTemplateSectionSchema,
|
|
300
|
+
buildFieldResponseSchema,
|
|
301
|
+
buildResponseSchema,
|
|
185
302
|
createUniqueId,
|
|
186
303
|
migrateLegacySchema,
|
|
187
304
|
normalizeReportTemplateSchema,
|
|
188
305
|
parseReportTemplateSchema,
|
|
189
306
|
parseReportTemplateSchemaFromString,
|
|
190
|
-
serializeReportTemplateSchema
|
|
307
|
+
serializeReportTemplateSchema,
|
|
308
|
+
validateReportResponse
|
|
191
309
|
};
|