@frt-platform/report-core 1.0.0 → 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/README.md +1 -2
- package/dist/index.d.mts +56 -31
- package/dist/index.d.ts +56 -31
- package/dist/index.js +150 -35
- package/dist/index.mjs +146 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,7 +53,6 @@ console.log(REPORT_TEMPLATE_FIELD_TYPES);
|
|
|
53
53
|
// "checkbox",
|
|
54
54
|
// "singleSelect",
|
|
55
55
|
// "multiSelect",
|
|
56
|
-
// "starRating"
|
|
57
56
|
// ]
|
|
58
57
|
```
|
|
59
58
|
|
|
@@ -349,7 +348,7 @@ Things you might add on top (in a separate package, e.g. `@frt/report-react`):
|
|
|
349
348
|
* React components for:
|
|
350
349
|
|
|
351
350
|
* Template builder UI
|
|
352
|
-
* Field editors/renderers (short text, selects,
|
|
351
|
+
* Field editors/renderers (short text, selects, etc.)
|
|
353
352
|
* Response schemas built from templates
|
|
354
353
|
* More advanced field types:
|
|
355
354
|
|
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
|
-
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"];
|
|
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
|
-
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"];
|
|
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
|
|
|
@@ -46,25 +49,23 @@ var REPORT_TEMPLATE_FIELD_TYPES = [
|
|
|
46
49
|
"date",
|
|
47
50
|
"checkbox",
|
|
48
51
|
"singleSelect",
|
|
49
|
-
"multiSelect"
|
|
50
|
-
"starRating"
|
|
52
|
+
"multiSelect"
|
|
51
53
|
];
|
|
52
54
|
var ReportTemplateFieldSchema = import_zod.z.object({
|
|
53
|
-
id: import_zod.z.string().min(1).max(60).regex(
|
|
54
|
-
|
|
55
|
-
|
|
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."),
|
|
56
61
|
required: import_zod.z.boolean().optional(),
|
|
57
|
-
description: import_zod.z.string().max(400).optional(),
|
|
58
|
-
placeholder: import_zod.z.string().max(200).optional(),
|
|
59
|
-
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(),
|
|
60
67
|
allowOther: import_zod.z.boolean().optional(),
|
|
61
|
-
defaultValue: import_zod.z.union([
|
|
62
|
-
import_zod.z.string(),
|
|
63
|
-
import_zod.z.number(),
|
|
64
|
-
import_zod.z.boolean(),
|
|
65
|
-
import_zod.z.array(import_zod.z.string()),
|
|
66
|
-
import_zod.z.null()
|
|
67
|
-
]).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(),
|
|
68
69
|
minLength: import_zod.z.number().int().min(0).optional(),
|
|
69
70
|
maxLength: import_zod.z.number().int().min(0).optional(),
|
|
70
71
|
minValue: import_zod.z.number().optional(),
|
|
@@ -75,26 +76,43 @@ var ReportTemplateFieldSchema = import_zod.z.object({
|
|
|
75
76
|
dataClassification: import_zod.z.enum(["none", "personal", "special"]).optional()
|
|
76
77
|
});
|
|
77
78
|
var ReportTemplateSectionSchema = import_zod.z.object({
|
|
78
|
-
id: import_zod.z.string().min(1).max(60).regex(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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([])
|
|
82
86
|
});
|
|
83
87
|
var ReportTemplateSchemaValidator = import_zod.z.object({
|
|
84
|
-
version: import_zod.z.number().int().min(1).default(REPORT_TEMPLATE_VERSION),
|
|
85
|
-
title: import_zod.z.string().max(200).optional(),
|
|
86
|
-
description: import_zod.z.string().max(500).optional(),
|
|
87
|
-
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([])
|
|
88
92
|
});
|
|
89
93
|
|
|
90
94
|
// src/fields.ts
|
|
91
95
|
var DEFAULT_FIELD_LABEL = "Untitled question";
|
|
92
96
|
var CORE_FIELD_DEFAULTS = {
|
|
93
|
-
shortText: {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
+
},
|
|
98
116
|
singleSelect: {
|
|
99
117
|
label: DEFAULT_FIELD_LABEL,
|
|
100
118
|
options: ["Option 1", "Option 2", "Option 3"]
|
|
@@ -103,11 +121,6 @@ var CORE_FIELD_DEFAULTS = {
|
|
|
103
121
|
label: DEFAULT_FIELD_LABEL,
|
|
104
122
|
options: ["Option 1", "Option 2", "Option 3"],
|
|
105
123
|
allowOther: false
|
|
106
|
-
},
|
|
107
|
-
starRating: {
|
|
108
|
-
label: DEFAULT_FIELD_LABEL,
|
|
109
|
-
minValue: 1,
|
|
110
|
-
maxValue: 5
|
|
111
124
|
}
|
|
112
125
|
};
|
|
113
126
|
|
|
@@ -127,16 +140,20 @@ function createUniqueId(prefix, existing) {
|
|
|
127
140
|
var LEGACY_FIELD_TYPE_MAP = {
|
|
128
141
|
shorttext: "shortText",
|
|
129
142
|
text: "shortText",
|
|
143
|
+
"text-box": "shortText",
|
|
130
144
|
longtext: "longText",
|
|
131
145
|
textarea: "longText",
|
|
146
|
+
paragraph: "longText",
|
|
132
147
|
number: "number",
|
|
133
148
|
numeric: "number",
|
|
134
149
|
date: "date",
|
|
135
150
|
checkbox: "checkbox",
|
|
136
151
|
boolean: "checkbox",
|
|
152
|
+
singleselect: "singleSelect",
|
|
137
153
|
select: "singleSelect",
|
|
138
154
|
dropdown: "singleSelect",
|
|
139
155
|
radio: "singleSelect",
|
|
156
|
+
"multi-select": "multiSelect",
|
|
140
157
|
multiselect: "multiSelect",
|
|
141
158
|
checkboxes: "multiSelect"
|
|
142
159
|
};
|
|
@@ -218,6 +235,101 @@ function parseReportTemplateSchemaFromString(raw) {
|
|
|
218
235
|
function serializeReportTemplateSchema(schema) {
|
|
219
236
|
return JSON.stringify(schema, null, 2);
|
|
220
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
|
+
}
|
|
221
333
|
// Annotate the CommonJS export names for ESM import in node:
|
|
222
334
|
0 && (module.exports = {
|
|
223
335
|
CORE_FIELD_DEFAULTS,
|
|
@@ -227,10 +339,13 @@ function serializeReportTemplateSchema(schema) {
|
|
|
227
339
|
ReportTemplateFieldSchema,
|
|
228
340
|
ReportTemplateSchemaValidator,
|
|
229
341
|
ReportTemplateSectionSchema,
|
|
342
|
+
buildFieldResponseSchema,
|
|
343
|
+
buildResponseSchema,
|
|
230
344
|
createUniqueId,
|
|
231
345
|
migrateLegacySchema,
|
|
232
346
|
normalizeReportTemplateSchema,
|
|
233
347
|
parseReportTemplateSchema,
|
|
234
348
|
parseReportTemplateSchemaFromString,
|
|
235
|
-
serializeReportTemplateSchema
|
|
349
|
+
serializeReportTemplateSchema,
|
|
350
|
+
validateReportResponse
|
|
236
351
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -8,25 +8,23 @@ var REPORT_TEMPLATE_FIELD_TYPES = [
|
|
|
8
8
|
"date",
|
|
9
9
|
"checkbox",
|
|
10
10
|
"singleSelect",
|
|
11
|
-
"multiSelect"
|
|
12
|
-
"starRating"
|
|
11
|
+
"multiSelect"
|
|
13
12
|
];
|
|
14
13
|
var ReportTemplateFieldSchema = z.object({
|
|
15
|
-
id: z.string().min(1).max(60).regex(
|
|
16
|
-
|
|
17
|
-
|
|
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."),
|
|
18
20
|
required: z.boolean().optional(),
|
|
19
|
-
description: z.string().max(400).optional(),
|
|
20
|
-
placeholder: z.string().max(200).optional(),
|
|
21
|
-
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(),
|
|
22
26
|
allowOther: z.boolean().optional(),
|
|
23
|
-
defaultValue: z.union([
|
|
24
|
-
z.string(),
|
|
25
|
-
z.number(),
|
|
26
|
-
z.boolean(),
|
|
27
|
-
z.array(z.string()),
|
|
28
|
-
z.null()
|
|
29
|
-
]).optional(),
|
|
27
|
+
defaultValue: z.union([z.string(), z.number(), z.boolean(), z.array(z.string()), z.null()]).optional(),
|
|
30
28
|
minLength: z.number().int().min(0).optional(),
|
|
31
29
|
maxLength: z.number().int().min(0).optional(),
|
|
32
30
|
minValue: z.number().optional(),
|
|
@@ -37,26 +35,43 @@ var ReportTemplateFieldSchema = z.object({
|
|
|
37
35
|
dataClassification: z.enum(["none", "personal", "special"]).optional()
|
|
38
36
|
});
|
|
39
37
|
var ReportTemplateSectionSchema = z.object({
|
|
40
|
-
id: z.string().min(1).max(60).regex(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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([])
|
|
44
45
|
});
|
|
45
46
|
var ReportTemplateSchemaValidator = z.object({
|
|
46
|
-
version: z.number().int().min(1).default(REPORT_TEMPLATE_VERSION),
|
|
47
|
-
title: z.string().max(200).optional(),
|
|
48
|
-
description: z.string().max(500).optional(),
|
|
49
|
-
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([])
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
// src/fields.ts
|
|
53
54
|
var DEFAULT_FIELD_LABEL = "Untitled question";
|
|
54
55
|
var CORE_FIELD_DEFAULTS = {
|
|
55
|
-
shortText: {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
},
|
|
60
75
|
singleSelect: {
|
|
61
76
|
label: DEFAULT_FIELD_LABEL,
|
|
62
77
|
options: ["Option 1", "Option 2", "Option 3"]
|
|
@@ -65,11 +80,6 @@ var CORE_FIELD_DEFAULTS = {
|
|
|
65
80
|
label: DEFAULT_FIELD_LABEL,
|
|
66
81
|
options: ["Option 1", "Option 2", "Option 3"],
|
|
67
82
|
allowOther: false
|
|
68
|
-
},
|
|
69
|
-
starRating: {
|
|
70
|
-
label: DEFAULT_FIELD_LABEL,
|
|
71
|
-
minValue: 1,
|
|
72
|
-
maxValue: 5
|
|
73
83
|
}
|
|
74
84
|
};
|
|
75
85
|
|
|
@@ -89,16 +99,20 @@ function createUniqueId(prefix, existing) {
|
|
|
89
99
|
var LEGACY_FIELD_TYPE_MAP = {
|
|
90
100
|
shorttext: "shortText",
|
|
91
101
|
text: "shortText",
|
|
102
|
+
"text-box": "shortText",
|
|
92
103
|
longtext: "longText",
|
|
93
104
|
textarea: "longText",
|
|
105
|
+
paragraph: "longText",
|
|
94
106
|
number: "number",
|
|
95
107
|
numeric: "number",
|
|
96
108
|
date: "date",
|
|
97
109
|
checkbox: "checkbox",
|
|
98
110
|
boolean: "checkbox",
|
|
111
|
+
singleselect: "singleSelect",
|
|
99
112
|
select: "singleSelect",
|
|
100
113
|
dropdown: "singleSelect",
|
|
101
114
|
radio: "singleSelect",
|
|
115
|
+
"multi-select": "multiSelect",
|
|
102
116
|
multiselect: "multiSelect",
|
|
103
117
|
checkboxes: "multiSelect"
|
|
104
118
|
};
|
|
@@ -180,6 +194,101 @@ function parseReportTemplateSchemaFromString(raw) {
|
|
|
180
194
|
function serializeReportTemplateSchema(schema) {
|
|
181
195
|
return JSON.stringify(schema, null, 2);
|
|
182
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
|
+
}
|
|
183
292
|
export {
|
|
184
293
|
CORE_FIELD_DEFAULTS,
|
|
185
294
|
DEFAULT_FIELD_LABEL,
|
|
@@ -188,10 +297,13 @@ export {
|
|
|
188
297
|
ReportTemplateFieldSchema,
|
|
189
298
|
ReportTemplateSchemaValidator,
|
|
190
299
|
ReportTemplateSectionSchema,
|
|
300
|
+
buildFieldResponseSchema,
|
|
301
|
+
buildResponseSchema,
|
|
191
302
|
createUniqueId,
|
|
192
303
|
migrateLegacySchema,
|
|
193
304
|
normalizeReportTemplateSchema,
|
|
194
305
|
parseReportTemplateSchema,
|
|
195
306
|
parseReportTemplateSchemaFromString,
|
|
196
|
-
serializeReportTemplateSchema
|
|
307
|
+
serializeReportTemplateSchema,
|
|
308
|
+
validateReportResponse
|
|
197
309
|
};
|