@frt-platform/report-core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,350 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const REPORT_TEMPLATE_VERSION = 1;
4
+ declare const REPORT_TEMPLATE_FIELD_TYPES: readonly ["shortText", "longText", "number", "date", "checkbox", "singleSelect", "multiSelect", "starRating"];
5
+ type ReportTemplateFieldType = (typeof REPORT_TEMPLATE_FIELD_TYPES)[number];
6
+ declare const ReportTemplateFieldSchema: z.ZodObject<{
7
+ id: z.ZodString;
8
+ type: z.ZodString;
9
+ label: z.ZodString;
10
+ required: z.ZodOptional<z.ZodBoolean>;
11
+ description: z.ZodOptional<z.ZodString>;
12
+ placeholder: z.ZodOptional<z.ZodString>;
13
+ options: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
14
+ allowOther: z.ZodOptional<z.ZodBoolean>;
15
+ defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodNull]>>;
16
+ minLength: z.ZodOptional<z.ZodNumber>;
17
+ maxLength: z.ZodOptional<z.ZodNumber>;
18
+ minValue: z.ZodOptional<z.ZodNumber>;
19
+ maxValue: z.ZodOptional<z.ZodNumber>;
20
+ step: z.ZodOptional<z.ZodNumber>;
21
+ minSelections: z.ZodOptional<z.ZodNumber>;
22
+ maxSelections: z.ZodOptional<z.ZodNumber>;
23
+ dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ id: string;
26
+ type: string;
27
+ label: string;
28
+ required?: boolean | undefined;
29
+ description?: string | undefined;
30
+ placeholder?: string | undefined;
31
+ options?: string[] | undefined;
32
+ allowOther?: boolean | undefined;
33
+ defaultValue?: string | number | boolean | string[] | null | undefined;
34
+ minLength?: number | undefined;
35
+ maxLength?: number | undefined;
36
+ minValue?: number | undefined;
37
+ maxValue?: number | undefined;
38
+ step?: number | undefined;
39
+ minSelections?: number | undefined;
40
+ maxSelections?: number | undefined;
41
+ dataClassification?: "none" | "personal" | "special" | undefined;
42
+ }, {
43
+ id: string;
44
+ type: string;
45
+ label: string;
46
+ required?: boolean | undefined;
47
+ description?: string | undefined;
48
+ placeholder?: string | undefined;
49
+ options?: string[] | undefined;
50
+ allowOther?: boolean | undefined;
51
+ defaultValue?: string | number | boolean | string[] | null | undefined;
52
+ minLength?: number | undefined;
53
+ maxLength?: number | undefined;
54
+ minValue?: number | undefined;
55
+ maxValue?: number | undefined;
56
+ step?: number | undefined;
57
+ minSelections?: number | undefined;
58
+ maxSelections?: number | undefined;
59
+ dataClassification?: "none" | "personal" | "special" | undefined;
60
+ }>;
61
+ type ReportTemplateField = z.infer<typeof ReportTemplateFieldSchema>;
62
+ declare const ReportTemplateSectionSchema: z.ZodObject<{
63
+ id: z.ZodString;
64
+ title: z.ZodOptional<z.ZodString>;
65
+ description: z.ZodOptional<z.ZodString>;
66
+ fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
67
+ id: z.ZodString;
68
+ type: z.ZodString;
69
+ label: z.ZodString;
70
+ required: z.ZodOptional<z.ZodBoolean>;
71
+ description: z.ZodOptional<z.ZodString>;
72
+ placeholder: z.ZodOptional<z.ZodString>;
73
+ options: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
74
+ allowOther: z.ZodOptional<z.ZodBoolean>;
75
+ defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodNull]>>;
76
+ minLength: z.ZodOptional<z.ZodNumber>;
77
+ maxLength: z.ZodOptional<z.ZodNumber>;
78
+ minValue: z.ZodOptional<z.ZodNumber>;
79
+ maxValue: z.ZodOptional<z.ZodNumber>;
80
+ step: z.ZodOptional<z.ZodNumber>;
81
+ minSelections: z.ZodOptional<z.ZodNumber>;
82
+ maxSelections: z.ZodOptional<z.ZodNumber>;
83
+ dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ id: string;
86
+ type: string;
87
+ label: string;
88
+ required?: boolean | undefined;
89
+ description?: string | undefined;
90
+ placeholder?: string | undefined;
91
+ options?: string[] | undefined;
92
+ allowOther?: boolean | undefined;
93
+ defaultValue?: string | number | boolean | string[] | null | undefined;
94
+ minLength?: number | undefined;
95
+ maxLength?: number | undefined;
96
+ minValue?: number | undefined;
97
+ maxValue?: number | undefined;
98
+ step?: number | undefined;
99
+ minSelections?: number | undefined;
100
+ maxSelections?: number | undefined;
101
+ dataClassification?: "none" | "personal" | "special" | undefined;
102
+ }, {
103
+ id: string;
104
+ type: string;
105
+ label: string;
106
+ required?: boolean | undefined;
107
+ description?: string | undefined;
108
+ placeholder?: string | undefined;
109
+ options?: string[] | undefined;
110
+ allowOther?: boolean | undefined;
111
+ defaultValue?: string | number | boolean | string[] | null | undefined;
112
+ minLength?: number | undefined;
113
+ maxLength?: number | undefined;
114
+ minValue?: number | undefined;
115
+ maxValue?: number | undefined;
116
+ step?: number | undefined;
117
+ minSelections?: number | undefined;
118
+ maxSelections?: number | undefined;
119
+ dataClassification?: "none" | "personal" | "special" | undefined;
120
+ }>, "many">>;
121
+ }, "strip", z.ZodTypeAny, {
122
+ id: string;
123
+ fields: {
124
+ id: string;
125
+ type: string;
126
+ label: string;
127
+ required?: boolean | undefined;
128
+ description?: string | undefined;
129
+ placeholder?: string | undefined;
130
+ options?: string[] | undefined;
131
+ allowOther?: boolean | undefined;
132
+ defaultValue?: string | number | boolean | string[] | null | undefined;
133
+ minLength?: number | undefined;
134
+ maxLength?: number | undefined;
135
+ minValue?: number | undefined;
136
+ maxValue?: number | undefined;
137
+ step?: number | undefined;
138
+ minSelections?: number | undefined;
139
+ maxSelections?: number | undefined;
140
+ dataClassification?: "none" | "personal" | "special" | undefined;
141
+ }[];
142
+ description?: string | undefined;
143
+ title?: string | undefined;
144
+ }, {
145
+ id: string;
146
+ description?: string | undefined;
147
+ title?: string | undefined;
148
+ fields?: {
149
+ id: string;
150
+ type: string;
151
+ label: string;
152
+ required?: boolean | undefined;
153
+ description?: string | undefined;
154
+ placeholder?: string | undefined;
155
+ options?: string[] | undefined;
156
+ allowOther?: boolean | undefined;
157
+ defaultValue?: string | number | boolean | string[] | null | undefined;
158
+ minLength?: number | undefined;
159
+ maxLength?: number | undefined;
160
+ minValue?: number | undefined;
161
+ maxValue?: number | undefined;
162
+ step?: number | undefined;
163
+ minSelections?: number | undefined;
164
+ maxSelections?: number | undefined;
165
+ dataClassification?: "none" | "personal" | "special" | undefined;
166
+ }[] | undefined;
167
+ }>;
168
+ type ReportTemplateSection = z.infer<typeof ReportTemplateSectionSchema>;
169
+ declare const ReportTemplateSchemaValidator: z.ZodObject<{
170
+ version: z.ZodDefault<z.ZodNumber>;
171
+ title: z.ZodOptional<z.ZodString>;
172
+ description: z.ZodOptional<z.ZodString>;
173
+ sections: z.ZodDefault<z.ZodArray<z.ZodObject<{
174
+ id: z.ZodString;
175
+ title: z.ZodOptional<z.ZodString>;
176
+ description: z.ZodOptional<z.ZodString>;
177
+ fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
178
+ id: z.ZodString;
179
+ type: z.ZodString;
180
+ label: z.ZodString;
181
+ required: z.ZodOptional<z.ZodBoolean>;
182
+ description: z.ZodOptional<z.ZodString>;
183
+ placeholder: z.ZodOptional<z.ZodString>;
184
+ options: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
185
+ allowOther: z.ZodOptional<z.ZodBoolean>;
186
+ defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodNull]>>;
187
+ minLength: z.ZodOptional<z.ZodNumber>;
188
+ maxLength: z.ZodOptional<z.ZodNumber>;
189
+ minValue: z.ZodOptional<z.ZodNumber>;
190
+ maxValue: z.ZodOptional<z.ZodNumber>;
191
+ step: z.ZodOptional<z.ZodNumber>;
192
+ minSelections: z.ZodOptional<z.ZodNumber>;
193
+ maxSelections: z.ZodOptional<z.ZodNumber>;
194
+ dataClassification: z.ZodOptional<z.ZodEnum<["none", "personal", "special"]>>;
195
+ }, "strip", z.ZodTypeAny, {
196
+ id: string;
197
+ type: string;
198
+ label: string;
199
+ required?: boolean | undefined;
200
+ description?: string | undefined;
201
+ placeholder?: string | undefined;
202
+ options?: string[] | undefined;
203
+ allowOther?: boolean | undefined;
204
+ defaultValue?: string | number | boolean | string[] | null | undefined;
205
+ minLength?: number | undefined;
206
+ maxLength?: number | undefined;
207
+ minValue?: number | undefined;
208
+ maxValue?: number | undefined;
209
+ step?: number | undefined;
210
+ minSelections?: number | undefined;
211
+ maxSelections?: number | undefined;
212
+ dataClassification?: "none" | "personal" | "special" | undefined;
213
+ }, {
214
+ id: string;
215
+ type: string;
216
+ label: string;
217
+ required?: boolean | undefined;
218
+ description?: string | undefined;
219
+ placeholder?: string | undefined;
220
+ options?: string[] | undefined;
221
+ allowOther?: boolean | undefined;
222
+ defaultValue?: string | number | boolean | string[] | null | undefined;
223
+ minLength?: number | undefined;
224
+ maxLength?: number | undefined;
225
+ minValue?: number | undefined;
226
+ maxValue?: number | undefined;
227
+ step?: number | undefined;
228
+ minSelections?: number | undefined;
229
+ maxSelections?: number | undefined;
230
+ dataClassification?: "none" | "personal" | "special" | undefined;
231
+ }>, "many">>;
232
+ }, "strip", z.ZodTypeAny, {
233
+ id: string;
234
+ fields: {
235
+ id: string;
236
+ type: string;
237
+ label: string;
238
+ required?: boolean | undefined;
239
+ description?: string | undefined;
240
+ placeholder?: string | undefined;
241
+ options?: string[] | undefined;
242
+ allowOther?: boolean | undefined;
243
+ defaultValue?: string | number | boolean | string[] | null | undefined;
244
+ minLength?: number | undefined;
245
+ maxLength?: number | undefined;
246
+ minValue?: number | undefined;
247
+ maxValue?: number | undefined;
248
+ step?: number | undefined;
249
+ minSelections?: number | undefined;
250
+ maxSelections?: number | undefined;
251
+ dataClassification?: "none" | "personal" | "special" | undefined;
252
+ }[];
253
+ description?: string | undefined;
254
+ title?: string | undefined;
255
+ }, {
256
+ id: string;
257
+ description?: string | undefined;
258
+ title?: string | undefined;
259
+ fields?: {
260
+ id: string;
261
+ type: string;
262
+ label: string;
263
+ required?: boolean | undefined;
264
+ description?: string | undefined;
265
+ placeholder?: string | undefined;
266
+ options?: string[] | undefined;
267
+ allowOther?: boolean | undefined;
268
+ defaultValue?: string | number | boolean | string[] | null | undefined;
269
+ minLength?: number | undefined;
270
+ maxLength?: number | undefined;
271
+ minValue?: number | undefined;
272
+ maxValue?: number | undefined;
273
+ step?: number | undefined;
274
+ minSelections?: number | undefined;
275
+ maxSelections?: number | undefined;
276
+ dataClassification?: "none" | "personal" | "special" | undefined;
277
+ }[] | undefined;
278
+ }>, "many">>;
279
+ }, "strip", z.ZodTypeAny, {
280
+ version: number;
281
+ sections: {
282
+ id: string;
283
+ fields: {
284
+ id: string;
285
+ type: string;
286
+ label: string;
287
+ required?: boolean | undefined;
288
+ description?: string | undefined;
289
+ placeholder?: string | undefined;
290
+ options?: string[] | undefined;
291
+ allowOther?: boolean | undefined;
292
+ defaultValue?: string | number | boolean | string[] | null | undefined;
293
+ minLength?: number | undefined;
294
+ maxLength?: number | undefined;
295
+ minValue?: number | undefined;
296
+ maxValue?: number | undefined;
297
+ step?: number | undefined;
298
+ minSelections?: number | undefined;
299
+ maxSelections?: number | undefined;
300
+ dataClassification?: "none" | "personal" | "special" | undefined;
301
+ }[];
302
+ description?: string | undefined;
303
+ title?: string | undefined;
304
+ }[];
305
+ description?: string | undefined;
306
+ title?: string | undefined;
307
+ }, {
308
+ description?: string | undefined;
309
+ title?: string | undefined;
310
+ version?: number | undefined;
311
+ sections?: {
312
+ id: string;
313
+ description?: string | undefined;
314
+ title?: string | undefined;
315
+ fields?: {
316
+ id: string;
317
+ type: string;
318
+ label: string;
319
+ required?: boolean | undefined;
320
+ description?: string | undefined;
321
+ placeholder?: string | undefined;
322
+ options?: string[] | undefined;
323
+ allowOther?: boolean | undefined;
324
+ defaultValue?: string | number | boolean | string[] | null | undefined;
325
+ minLength?: number | undefined;
326
+ maxLength?: number | undefined;
327
+ minValue?: number | undefined;
328
+ maxValue?: number | undefined;
329
+ step?: number | undefined;
330
+ minSelections?: number | undefined;
331
+ maxSelections?: number | undefined;
332
+ dataClassification?: "none" | "personal" | "special" | undefined;
333
+ }[] | undefined;
334
+ }[] | undefined;
335
+ }>;
336
+ type ReportTemplateSchema = z.infer<typeof ReportTemplateSchemaValidator>;
337
+
338
+ declare const DEFAULT_FIELD_LABEL = "Untitled question";
339
+ declare const CORE_FIELD_DEFAULTS: Record<ReportTemplateFieldType, Record<string, unknown>>;
340
+
341
+ declare function createUniqueId(prefix: string, existing: Iterable<string>): string;
342
+
343
+ declare function parseReportTemplateSchema(raw: unknown): ReportTemplateSchema;
344
+ declare function normalizeReportTemplateSchema(schema: ReportTemplateSchema): ReportTemplateSchema;
345
+ declare function parseReportTemplateSchemaFromString(raw: string): ReportTemplateSchema;
346
+ declare function serializeReportTemplateSchema(schema: ReportTemplateSchema): string;
347
+
348
+ declare function migrateLegacySchema(raw: unknown): unknown;
349
+
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 };
package/dist/index.js ADDED
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CORE_FIELD_DEFAULTS: () => CORE_FIELD_DEFAULTS,
24
+ DEFAULT_FIELD_LABEL: () => DEFAULT_FIELD_LABEL,
25
+ REPORT_TEMPLATE_FIELD_TYPES: () => REPORT_TEMPLATE_FIELD_TYPES,
26
+ REPORT_TEMPLATE_VERSION: () => REPORT_TEMPLATE_VERSION,
27
+ ReportTemplateFieldSchema: () => ReportTemplateFieldSchema,
28
+ ReportTemplateSchemaValidator: () => ReportTemplateSchemaValidator,
29
+ ReportTemplateSectionSchema: () => ReportTemplateSectionSchema,
30
+ createUniqueId: () => createUniqueId,
31
+ migrateLegacySchema: () => migrateLegacySchema,
32
+ normalizeReportTemplateSchema: () => normalizeReportTemplateSchema,
33
+ parseReportTemplateSchema: () => parseReportTemplateSchema,
34
+ parseReportTemplateSchemaFromString: () => parseReportTemplateSchemaFromString,
35
+ serializeReportTemplateSchema: () => serializeReportTemplateSchema
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/schema.ts
40
+ var import_zod = require("zod");
41
+ var REPORT_TEMPLATE_VERSION = 1;
42
+ var REPORT_TEMPLATE_FIELD_TYPES = [
43
+ "shortText",
44
+ "longText",
45
+ "number",
46
+ "date",
47
+ "checkbox",
48
+ "singleSelect",
49
+ "multiSelect",
50
+ "starRating"
51
+ ];
52
+ var ReportTemplateFieldSchema = import_zod.z.object({
53
+ id: import_zod.z.string().min(1).max(60).regex(/^[a-z0-9_-]+$/),
54
+ type: import_zod.z.string(),
55
+ label: import_zod.z.string().min(1).max(200),
56
+ 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(import_zod.z.string().min(1).max(120)).optional(),
60
+ 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
+ minLength: import_zod.z.number().int().min(0).optional(),
69
+ maxLength: import_zod.z.number().int().min(0).optional(),
70
+ minValue: import_zod.z.number().optional(),
71
+ maxValue: import_zod.z.number().optional(),
72
+ step: import_zod.z.number().nonnegative().optional(),
73
+ minSelections: import_zod.z.number().int().min(0).optional(),
74
+ maxSelections: import_zod.z.number().int().min(0).optional(),
75
+ dataClassification: import_zod.z.enum(["none", "personal", "special"]).optional()
76
+ });
77
+ var ReportTemplateSectionSchema = import_zod.z.object({
78
+ id: import_zod.z.string().min(1).max(60).regex(/^[a-z0-9_-]+$/),
79
+ title: import_zod.z.string().max(200).optional(),
80
+ description: import_zod.z.string().max(500).optional(),
81
+ fields: import_zod.z.array(ReportTemplateFieldSchema).default([])
82
+ });
83
+ 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
+ });
89
+
90
+ // src/fields.ts
91
+ var DEFAULT_FIELD_LABEL = "Untitled question";
92
+ var CORE_FIELD_DEFAULTS = {
93
+ shortText: { label: DEFAULT_FIELD_LABEL, placeholder: "Short answer text" },
94
+ longText: { label: DEFAULT_FIELD_LABEL, placeholder: "Long answer text" },
95
+ number: { label: DEFAULT_FIELD_LABEL, placeholder: "123" },
96
+ date: { label: DEFAULT_FIELD_LABEL },
97
+ checkbox: { label: DEFAULT_FIELD_LABEL, placeholder: "Check to confirm" },
98
+ singleSelect: {
99
+ label: DEFAULT_FIELD_LABEL,
100
+ options: ["Option 1", "Option 2", "Option 3"]
101
+ },
102
+ multiSelect: {
103
+ label: DEFAULT_FIELD_LABEL,
104
+ options: ["Option 1", "Option 2", "Option 3"],
105
+ allowOther: false
106
+ },
107
+ starRating: {
108
+ label: DEFAULT_FIELD_LABEL,
109
+ minValue: 1,
110
+ maxValue: 5
111
+ }
112
+ };
113
+
114
+ // src/ids.ts
115
+ function createUniqueId(prefix, existing) {
116
+ const used = new Set(existing);
117
+ let attempt = used.size + 1;
118
+ let candidate = `${prefix}-${attempt}`;
119
+ while (used.has(candidate)) {
120
+ attempt++;
121
+ candidate = `${prefix}-${attempt}`;
122
+ }
123
+ return candidate;
124
+ }
125
+
126
+ // src/migrate.ts
127
+ var LEGACY_FIELD_TYPE_MAP = {
128
+ shorttext: "shortText",
129
+ text: "shortText",
130
+ longtext: "longText",
131
+ textarea: "longText",
132
+ number: "number",
133
+ numeric: "number",
134
+ date: "date",
135
+ checkbox: "checkbox",
136
+ boolean: "checkbox",
137
+ select: "singleSelect",
138
+ dropdown: "singleSelect",
139
+ radio: "singleSelect",
140
+ multiselect: "multiSelect",
141
+ checkboxes: "multiSelect"
142
+ };
143
+ function migrateLegacySchema(raw) {
144
+ if (!raw || typeof raw !== "object") return raw;
145
+ const obj = structuredClone(raw);
146
+ if (obj.fields) {
147
+ obj.sections = [
148
+ {
149
+ id: "section-1",
150
+ title: obj.title,
151
+ description: obj.description,
152
+ fields: obj.fields.map((f, i) => ({
153
+ ...f,
154
+ id: f.id || `field-${i + 1}`,
155
+ type: LEGACY_FIELD_TYPE_MAP[f.type?.toLowerCase()] ?? f.type
156
+ }))
157
+ }
158
+ ];
159
+ delete obj.fields;
160
+ return obj;
161
+ }
162
+ if (Array.isArray(obj.sections)) {
163
+ obj.sections = obj.sections.map((sec, i) => ({
164
+ ...sec,
165
+ id: sec.id || `section-${i + 1}`,
166
+ fields: (sec.fields || []).map((f, idx) => ({
167
+ ...f,
168
+ id: f.id || `field-${idx + 1}`,
169
+ type: LEGACY_FIELD_TYPE_MAP[f.type?.toLowerCase()] ?? f.type
170
+ }))
171
+ }));
172
+ }
173
+ return obj;
174
+ }
175
+
176
+ // src/normalize.ts
177
+ function parseReportTemplateSchema(raw) {
178
+ const migrated = migrateLegacySchema(raw);
179
+ const parsed = ReportTemplateSchemaValidator.parse(migrated);
180
+ return normalizeReportTemplateSchema(parsed);
181
+ }
182
+ function normalizeReportTemplateSchema(schema) {
183
+ const sections = schema.sections.length > 0 ? schema.sections : [
184
+ {
185
+ id: "section-1",
186
+ title: "",
187
+ description: "",
188
+ fields: []
189
+ }
190
+ ];
191
+ const normalizedSections = sections.map((sec, i) => {
192
+ const seen = /* @__PURE__ */ new Set();
193
+ const safeSectionId = sec.id.trim() || `section-${i + 1}`;
194
+ const fields = sec.fields.map((field, idx) => {
195
+ const trimmed = field.id.trim() || `field-${idx + 1}`;
196
+ const safeId = seen.has(trimmed) ? `field-${idx + 1}` : trimmed;
197
+ seen.add(safeId);
198
+ return {
199
+ ...field,
200
+ id: safeId
201
+ };
202
+ });
203
+ return {
204
+ ...sec,
205
+ id: safeSectionId,
206
+ fields
207
+ };
208
+ });
209
+ return {
210
+ ...schema,
211
+ sections: normalizedSections
212
+ };
213
+ }
214
+ function parseReportTemplateSchemaFromString(raw) {
215
+ const obj = JSON.parse(raw);
216
+ return parseReportTemplateSchema(obj);
217
+ }
218
+ function serializeReportTemplateSchema(schema) {
219
+ return JSON.stringify(schema, null, 2);
220
+ }
221
+ // Annotate the CommonJS export names for ESM import in node:
222
+ 0 && (module.exports = {
223
+ CORE_FIELD_DEFAULTS,
224
+ DEFAULT_FIELD_LABEL,
225
+ REPORT_TEMPLATE_FIELD_TYPES,
226
+ REPORT_TEMPLATE_VERSION,
227
+ ReportTemplateFieldSchema,
228
+ ReportTemplateSchemaValidator,
229
+ ReportTemplateSectionSchema,
230
+ createUniqueId,
231
+ migrateLegacySchema,
232
+ normalizeReportTemplateSchema,
233
+ parseReportTemplateSchema,
234
+ parseReportTemplateSchemaFromString,
235
+ serializeReportTemplateSchema
236
+ });