@encatch/schema 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/schemas/fields/answer-schema.js +103 -0
- package/dist/cjs/schemas/fields/answer-schema.js.map +1 -0
- package/dist/cjs/schemas/fields/auto-trigger-schema.js +49 -0
- package/dist/cjs/schemas/fields/auto-trigger-schema.js.map +1 -0
- package/dist/cjs/schemas/fields/field-schema.js +678 -0
- package/dist/cjs/schemas/fields/field-schema.js.map +1 -0
- package/dist/cjs/schemas/fields/form-properties-schema.js +136 -0
- package/dist/cjs/schemas/fields/form-properties-schema.js.map +1 -0
- package/dist/cjs/schemas/fields/form-schema.js +123 -0
- package/dist/cjs/schemas/fields/form-schema.js.map +1 -0
- package/dist/cjs/schemas/fields/other-screen-schema.js +169 -0
- package/dist/cjs/schemas/fields/other-screen-schema.js.map +1 -0
- package/dist/cjs/schemas/fields/theme-schema.js +85 -0
- package/dist/cjs/schemas/fields/theme-schema.js.map +1 -0
- package/dist/cjs/schemas/fields/translations-example.js +187 -0
- package/dist/cjs/schemas/fields/translations-example.js.map +1 -0
- package/dist/cjs/schemas/fields/translations-schema.js +198 -0
- package/dist/cjs/schemas/fields/translations-schema.js.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/schemas/fields/answer-schema.js +100 -0
- package/dist/esm/schemas/fields/answer-schema.js.map +1 -0
- package/dist/esm/schemas/fields/auto-trigger-schema.js +46 -0
- package/dist/esm/schemas/fields/auto-trigger-schema.js.map +1 -0
- package/dist/esm/schemas/fields/field-schema.js +675 -0
- package/dist/esm/schemas/fields/field-schema.js.map +1 -0
- package/dist/esm/schemas/fields/form-properties-schema.js +133 -0
- package/dist/esm/schemas/fields/form-properties-schema.js.map +1 -0
- package/dist/esm/schemas/fields/form-schema.js +120 -0
- package/dist/esm/schemas/fields/form-schema.js.map +1 -0
- package/dist/esm/schemas/fields/other-screen-schema.js +166 -0
- package/dist/esm/schemas/fields/other-screen-schema.js.map +1 -0
- package/dist/esm/schemas/fields/theme-schema.js +82 -0
- package/dist/esm/schemas/fields/theme-schema.js.map +1 -0
- package/dist/esm/schemas/fields/translations-example.js +181 -0
- package/dist/esm/schemas/fields/translations-example.js.map +1 -0
- package/dist/esm/schemas/fields/translations-schema.js +193 -0
- package/dist/esm/schemas/fields/translations-schema.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/schemas/fields/answer-schema.d.ts +77 -0
- package/dist/types/schemas/fields/auto-trigger-schema.d.ts +21 -0
- package/dist/types/schemas/fields/field-schema.d.ts +1114 -0
- package/dist/types/schemas/fields/form-properties-schema.d.ts +1035 -0
- package/dist/types/schemas/fields/form-schema.d.ts +68 -0
- package/dist/types/schemas/fields/other-screen-schema.d.ts +58 -0
- package/dist/types/schemas/fields/theme-schema.d.ts +91 -0
- package/dist/types/schemas/fields/translations-example.d.ts +10 -0
- package/dist/types/schemas/fields/translations-schema.d.ts +863 -0
- package/package.json +33 -0
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combinedQuestionSchema = exports.nestedDropdownQuestionSchema = exports.longAnswerQuestionSchema = exports.shortAnswerQuestionSchema = exports.npsQuestionSchema = exports.multipleChoiceMultipleQuestionSchema = exports.multipleChoiceSingleQuestionSchema = exports.nestedOptionSchema = exports.questionOptionSchema = exports.annotationQuestionSchema = exports.ratingQuestionSchema = exports.questionSchema = exports.choiceOrderOptionSchema = exports.multipleChoiceMultipleDisplayStyleSchema = exports.multipleChoiceDisplayStyleSchema = exports.ratingRepresentationSizeSchema = exports.ratingDisplayStyleSchema = exports.questionStatusSchema = exports.sectionSchema = exports.visibilityConditionSchema = exports.validationRuleSchema = exports.questionTypeSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
// Question type enum for different form field types
|
|
6
|
+
exports.questionTypeSchema = zod_1.z
|
|
7
|
+
.enum([
|
|
8
|
+
"rating",
|
|
9
|
+
"single_choice",
|
|
10
|
+
"nps",
|
|
11
|
+
"nested_selection",
|
|
12
|
+
"multiple_choice_multiple",
|
|
13
|
+
"short_answer",
|
|
14
|
+
"long_text",
|
|
15
|
+
"annotation",
|
|
16
|
+
])
|
|
17
|
+
.describe("Enumeration of all supported question types for form fields");
|
|
18
|
+
// Validation rule schema for question validations
|
|
19
|
+
exports.validationRuleSchema = zod_1.z
|
|
20
|
+
.object({
|
|
21
|
+
type: zod_1.z
|
|
22
|
+
.enum([
|
|
23
|
+
"required",
|
|
24
|
+
"min",
|
|
25
|
+
"max",
|
|
26
|
+
"minLength",
|
|
27
|
+
"maxLength",
|
|
28
|
+
"pattern",
|
|
29
|
+
"email",
|
|
30
|
+
"url",
|
|
31
|
+
"custom",
|
|
32
|
+
])
|
|
33
|
+
.describe("Type of validation rule to apply"),
|
|
34
|
+
value: zod_1.z
|
|
35
|
+
.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()])
|
|
36
|
+
.optional()
|
|
37
|
+
.describe("Value for the validation rule (string, number, or boolean)"),
|
|
38
|
+
message: zod_1.z
|
|
39
|
+
.string()
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Custom error message when validation fails"),
|
|
42
|
+
describe: zod_1.z
|
|
43
|
+
.string()
|
|
44
|
+
.max(500)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("LLM tool call description for this validation rule"),
|
|
47
|
+
})
|
|
48
|
+
.describe("Schema defining validation rules for question responses");
|
|
49
|
+
// Visibility condition schema for conditional visibility
|
|
50
|
+
exports.visibilityConditionSchema = zod_1.z
|
|
51
|
+
.object({
|
|
52
|
+
field: zod_1.z.string().describe("ID of the field to check against"),
|
|
53
|
+
operator: zod_1.z
|
|
54
|
+
.enum([
|
|
55
|
+
"equals",
|
|
56
|
+
"not_equals",
|
|
57
|
+
"contains",
|
|
58
|
+
"not_contains",
|
|
59
|
+
"greater_than",
|
|
60
|
+
"less_than",
|
|
61
|
+
"is_empty",
|
|
62
|
+
"is_not_empty",
|
|
63
|
+
])
|
|
64
|
+
.describe("Comparison operator for the condition"),
|
|
65
|
+
value: zod_1.z
|
|
66
|
+
.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()])
|
|
67
|
+
.optional()
|
|
68
|
+
.describe("Value to compare against (string, number, or boolean)"),
|
|
69
|
+
describe: zod_1.z
|
|
70
|
+
.string()
|
|
71
|
+
.max(500)
|
|
72
|
+
.optional()
|
|
73
|
+
.describe("LLM tool call description for this visibility condition"),
|
|
74
|
+
})
|
|
75
|
+
.describe("Schema defining conditions that control when questions are visible");
|
|
76
|
+
// Section schema for organizing questions
|
|
77
|
+
exports.sectionSchema = zod_1.z
|
|
78
|
+
.object({
|
|
79
|
+
id: zod_1.z
|
|
80
|
+
.uuid()
|
|
81
|
+
.describe("Unique identifier for the section"),
|
|
82
|
+
title: zod_1.z
|
|
83
|
+
.string()
|
|
84
|
+
.min(1)
|
|
85
|
+
.max(200)
|
|
86
|
+
.describe("Display title for the section"),
|
|
87
|
+
question_ids: zod_1.z
|
|
88
|
+
.array(zod_1.z.uuid())
|
|
89
|
+
.min(1)
|
|
90
|
+
.describe("Array of question IDs that belong to this section"),
|
|
91
|
+
})
|
|
92
|
+
.describe("Schema defining sections that organize questions into logical groups");
|
|
93
|
+
// Question status enum
|
|
94
|
+
exports.questionStatusSchema = zod_1.z.enum(["D", "P", "A", "S"]); // Draft, Published, Archived, Suspended
|
|
95
|
+
// Display style enum for rating questions
|
|
96
|
+
exports.ratingDisplayStyleSchema = zod_1.z.enum([
|
|
97
|
+
"star",
|
|
98
|
+
"heart",
|
|
99
|
+
"thumbs-up",
|
|
100
|
+
"diamond",
|
|
101
|
+
"emoji",
|
|
102
|
+
"emoji-exp",
|
|
103
|
+
]);
|
|
104
|
+
// Representation size enum for rating questions
|
|
105
|
+
exports.ratingRepresentationSizeSchema = zod_1.z.enum([
|
|
106
|
+
"small",
|
|
107
|
+
"medium",
|
|
108
|
+
"large",
|
|
109
|
+
]);
|
|
110
|
+
// Display style enum for multiple choice questions
|
|
111
|
+
exports.multipleChoiceDisplayStyleSchema = zod_1.z.enum([
|
|
112
|
+
"radio",
|
|
113
|
+
"list",
|
|
114
|
+
"chip",
|
|
115
|
+
"dropdown",
|
|
116
|
+
]);
|
|
117
|
+
// Display style enum for multiple choice multiple questions
|
|
118
|
+
exports.multipleChoiceMultipleDisplayStyleSchema = zod_1.z.enum([
|
|
119
|
+
"checkbox",
|
|
120
|
+
"list",
|
|
121
|
+
"chip",
|
|
122
|
+
]);
|
|
123
|
+
// Choice order options for nested selection questions
|
|
124
|
+
exports.choiceOrderOptionSchema = zod_1.z.enum([
|
|
125
|
+
"randomize",
|
|
126
|
+
"flip",
|
|
127
|
+
"rotate",
|
|
128
|
+
"ascending",
|
|
129
|
+
"none",
|
|
130
|
+
]);
|
|
131
|
+
// Main Question schema
|
|
132
|
+
exports.questionSchema = zod_1.z
|
|
133
|
+
.object({
|
|
134
|
+
id: zod_1.z.uuid().describe("Unique identifier for the question"),
|
|
135
|
+
type: exports.questionTypeSchema.describe("The type of question (rating, single_choice, etc.)"),
|
|
136
|
+
title: zod_1.z
|
|
137
|
+
.string()
|
|
138
|
+
.min(1)
|
|
139
|
+
.max(200)
|
|
140
|
+
.describe("The main title/question text displayed to users"),
|
|
141
|
+
description: zod_1.z
|
|
142
|
+
.string()
|
|
143
|
+
.max(1000)
|
|
144
|
+
.optional()
|
|
145
|
+
.describe("Optional detailed description or help text"),
|
|
146
|
+
describe: zod_1.z
|
|
147
|
+
.string()
|
|
148
|
+
.max(2000)
|
|
149
|
+
.optional()
|
|
150
|
+
.describe("LLM tool call description for better AI understanding and context"),
|
|
151
|
+
required: zod_1.z
|
|
152
|
+
.boolean()
|
|
153
|
+
.default(false)
|
|
154
|
+
.describe("Whether this question must be answered"),
|
|
155
|
+
errorMessage: zod_1.z
|
|
156
|
+
.string()
|
|
157
|
+
.max(500)
|
|
158
|
+
.optional()
|
|
159
|
+
.describe("Custom error message when validation fails"),
|
|
160
|
+
validations: zod_1.z
|
|
161
|
+
.array(exports.validationRuleSchema)
|
|
162
|
+
.optional()
|
|
163
|
+
.default([])
|
|
164
|
+
.describe("Array of validation rules to apply"),
|
|
165
|
+
visibility: zod_1.z
|
|
166
|
+
.array(exports.visibilityConditionSchema)
|
|
167
|
+
.optional()
|
|
168
|
+
.default([])
|
|
169
|
+
.describe("Conditions that control when this question is shown"),
|
|
170
|
+
isFixed: zod_1.z
|
|
171
|
+
.boolean()
|
|
172
|
+
.describe("Whether this question position is fixed or can be reordered"),
|
|
173
|
+
sectionId: zod_1.z
|
|
174
|
+
.string()
|
|
175
|
+
.uuid()
|
|
176
|
+
.optional()
|
|
177
|
+
.describe("ID of the section this question belongs to"),
|
|
178
|
+
status: exports.questionStatusSchema.describe("Current status of the question (Draft, Published, etc.)"),
|
|
179
|
+
})
|
|
180
|
+
.describe("Base schema for all question types with common properties");
|
|
181
|
+
// Rating question schema (extends base question with specific rating properties)
|
|
182
|
+
exports.ratingQuestionSchema = exports.questionSchema
|
|
183
|
+
.extend({
|
|
184
|
+
type: zod_1.z
|
|
185
|
+
.literal(exports.questionTypeSchema.enum.rating)
|
|
186
|
+
.describe("Must be exactly 'rating'"),
|
|
187
|
+
showLabels: zod_1.z
|
|
188
|
+
.boolean()
|
|
189
|
+
.optional()
|
|
190
|
+
.describe("Whether to show min/max labels"),
|
|
191
|
+
minLabel: zod_1.z
|
|
192
|
+
.string()
|
|
193
|
+
.max(100)
|
|
194
|
+
.optional()
|
|
195
|
+
.describe("Label for the minimum rating value"),
|
|
196
|
+
maxLabel: zod_1.z
|
|
197
|
+
.string()
|
|
198
|
+
.max(100)
|
|
199
|
+
.optional()
|
|
200
|
+
.describe("Label for the maximum rating value"),
|
|
201
|
+
displayStyle: exports.ratingDisplayStyleSchema
|
|
202
|
+
.optional()
|
|
203
|
+
.describe("Visual style for rating display"),
|
|
204
|
+
numberOfRatings: zod_1.z
|
|
205
|
+
.number()
|
|
206
|
+
.int()
|
|
207
|
+
.min(1)
|
|
208
|
+
.max(10)
|
|
209
|
+
.describe("Number of rating options (1-10)"),
|
|
210
|
+
representationSize: exports.ratingRepresentationSizeSchema
|
|
211
|
+
.optional()
|
|
212
|
+
.describe("Size of rating visual elements"),
|
|
213
|
+
color: zod_1.z
|
|
214
|
+
.string()
|
|
215
|
+
.regex(/^#[0-9A-F]{6}$/i, "Must be a valid hex color")
|
|
216
|
+
.optional()
|
|
217
|
+
.describe("Hex color for rating elements"),
|
|
218
|
+
})
|
|
219
|
+
.describe("Schema for rating questions with customizable display options");
|
|
220
|
+
// Annotation question schema (extends base question with annotation properties)
|
|
221
|
+
exports.annotationQuestionSchema = exports.questionSchema
|
|
222
|
+
.extend({
|
|
223
|
+
type: zod_1.z
|
|
224
|
+
.literal(exports.questionTypeSchema.enum.annotation)
|
|
225
|
+
.describe("Must be exactly 'annotation'"),
|
|
226
|
+
annotationText: zod_1.z
|
|
227
|
+
.string()
|
|
228
|
+
.max(1000)
|
|
229
|
+
.optional()
|
|
230
|
+
.describe("Text to display when annotation is provided"),
|
|
231
|
+
noAnnotationText: zod_1.z
|
|
232
|
+
.string()
|
|
233
|
+
.max(500)
|
|
234
|
+
.optional()
|
|
235
|
+
.describe("Text to display when no annotation is provided"),
|
|
236
|
+
})
|
|
237
|
+
.describe("Schema for annotation questions that provide additional context or instructions");
|
|
238
|
+
// Question option schema for choice-based questions
|
|
239
|
+
exports.questionOptionSchema = zod_1.z
|
|
240
|
+
.object({
|
|
241
|
+
id: zod_1.z.uuid().describe("Unique identifier for this option"),
|
|
242
|
+
value: zod_1.z
|
|
243
|
+
.string()
|
|
244
|
+
.min(1)
|
|
245
|
+
.max(100)
|
|
246
|
+
.describe("The internal value used for this option"),
|
|
247
|
+
label: zod_1.z
|
|
248
|
+
.string()
|
|
249
|
+
.min(1)
|
|
250
|
+
.max(200)
|
|
251
|
+
.describe("The display text shown to users for this option"),
|
|
252
|
+
describe: zod_1.z
|
|
253
|
+
.string()
|
|
254
|
+
.max(500)
|
|
255
|
+
.optional()
|
|
256
|
+
.describe("LLM tool call description providing context about this option"),
|
|
257
|
+
imageUrl: zod_1.z
|
|
258
|
+
.string()
|
|
259
|
+
.url()
|
|
260
|
+
.optional()
|
|
261
|
+
.describe("Optional image URL to display with this option"),
|
|
262
|
+
})
|
|
263
|
+
.describe("Schema for individual options in choice-based questions");
|
|
264
|
+
// Nested option schema for hierarchical choice structures (recursive)
|
|
265
|
+
exports.nestedOptionSchema = zod_1.z.lazy(() => zod_1.z
|
|
266
|
+
.object({
|
|
267
|
+
id: zod_1.z
|
|
268
|
+
.string()
|
|
269
|
+
.uuid()
|
|
270
|
+
.describe("Unique identifier for this nested option"),
|
|
271
|
+
value: zod_1.z
|
|
272
|
+
.string()
|
|
273
|
+
.min(1)
|
|
274
|
+
.max(100)
|
|
275
|
+
.describe("The internal value used for this nested option"),
|
|
276
|
+
label: zod_1.z
|
|
277
|
+
.string()
|
|
278
|
+
.min(1)
|
|
279
|
+
.max(200)
|
|
280
|
+
.describe("The display text shown for this nested option"),
|
|
281
|
+
describe: zod_1.z
|
|
282
|
+
.string()
|
|
283
|
+
.max(500)
|
|
284
|
+
.optional()
|
|
285
|
+
.describe("LLM tool call description for this nested option context"),
|
|
286
|
+
imageUrl: zod_1.z
|
|
287
|
+
.string()
|
|
288
|
+
.url()
|
|
289
|
+
.optional()
|
|
290
|
+
.describe("Optional image URL for this nested option"),
|
|
291
|
+
hint: zod_1.z
|
|
292
|
+
.string()
|
|
293
|
+
.max(500)
|
|
294
|
+
.optional()
|
|
295
|
+
.describe("Optional hint text to help users understand this nested option"),
|
|
296
|
+
children: zod_1.z
|
|
297
|
+
.array(exports.nestedOptionSchema)
|
|
298
|
+
.optional()
|
|
299
|
+
.default([])
|
|
300
|
+
.describe("Array of child options for hierarchical structure"),
|
|
301
|
+
})
|
|
302
|
+
.describe("Schema for nested options with hierarchical structure support"));
|
|
303
|
+
// Multiple choice single question schema (extends base question with choice-specific properties)
|
|
304
|
+
exports.multipleChoiceSingleQuestionSchema = exports.questionSchema
|
|
305
|
+
.extend({
|
|
306
|
+
type: zod_1.z
|
|
307
|
+
.literal(exports.questionTypeSchema.enum.single_choice)
|
|
308
|
+
.describe("Must be exactly 'single_choice'"),
|
|
309
|
+
displayStyle: exports.multipleChoiceDisplayStyleSchema
|
|
310
|
+
.optional()
|
|
311
|
+
.describe("Visual style for displaying options"),
|
|
312
|
+
randomizeOptions: zod_1.z
|
|
313
|
+
.boolean()
|
|
314
|
+
.optional()
|
|
315
|
+
.default(false)
|
|
316
|
+
.describe("Whether to randomize the order of options"),
|
|
317
|
+
options: zod_1.z
|
|
318
|
+
.array(exports.questionOptionSchema)
|
|
319
|
+
.min(1)
|
|
320
|
+
.max(50)
|
|
321
|
+
.describe("Array of options for user selection (1-50 options)"),
|
|
322
|
+
})
|
|
323
|
+
.describe("Schema for single-choice multiple selection questions");
|
|
324
|
+
// Multiple choice multiple question schema (extends base question with multiple choice properties)
|
|
325
|
+
exports.multipleChoiceMultipleQuestionSchema = exports.questionSchema
|
|
326
|
+
.extend({
|
|
327
|
+
type: zod_1.z
|
|
328
|
+
.literal(exports.questionTypeSchema.enum.multiple_choice_multiple)
|
|
329
|
+
.describe("Must be exactly 'multiple_choice_multiple'"),
|
|
330
|
+
displayStyle: exports.multipleChoiceMultipleDisplayStyleSchema
|
|
331
|
+
.optional()
|
|
332
|
+
.describe("Visual style for displaying multiple options"),
|
|
333
|
+
minSelections: zod_1.z
|
|
334
|
+
.number()
|
|
335
|
+
.int()
|
|
336
|
+
.min(0)
|
|
337
|
+
.optional()
|
|
338
|
+
.describe("Minimum number of options that must be selected"),
|
|
339
|
+
maxSelections: zod_1.z
|
|
340
|
+
.number()
|
|
341
|
+
.int()
|
|
342
|
+
.min(1)
|
|
343
|
+
.optional()
|
|
344
|
+
.describe("Maximum number of options that can be selected"),
|
|
345
|
+
randomizeOptions: zod_1.z
|
|
346
|
+
.boolean()
|
|
347
|
+
.optional()
|
|
348
|
+
.default(false)
|
|
349
|
+
.describe("Whether to randomize the order of options"),
|
|
350
|
+
options: zod_1.z
|
|
351
|
+
.array(exports.questionOptionSchema)
|
|
352
|
+
.min(1)
|
|
353
|
+
.max(50)
|
|
354
|
+
.describe("Array of options for user selection (1-50 options)"),
|
|
355
|
+
})
|
|
356
|
+
.refine((data) => {
|
|
357
|
+
// If both minSelections and maxSelections are provided, minSelections should be <= maxSelections
|
|
358
|
+
if (data.minSelections !== undefined &&
|
|
359
|
+
data.maxSelections !== undefined) {
|
|
360
|
+
return data.minSelections <= data.maxSelections;
|
|
361
|
+
}
|
|
362
|
+
return true;
|
|
363
|
+
}, {
|
|
364
|
+
message: "minSelections cannot be greater than maxSelections",
|
|
365
|
+
path: ["minSelections"], // Point to minSelections field for the error
|
|
366
|
+
})
|
|
367
|
+
.describe("Schema for multiple-choice questions allowing multiple selections");
|
|
368
|
+
// NPS question schema (extends base question with NPS-specific properties)
|
|
369
|
+
exports.npsQuestionSchema = exports.questionSchema
|
|
370
|
+
.extend({
|
|
371
|
+
type: zod_1.z
|
|
372
|
+
.literal(exports.questionTypeSchema.enum.nps)
|
|
373
|
+
.describe("Must be exactly 'nps'"),
|
|
374
|
+
min: zod_1.z.literal(0).describe("NPS always starts at 0"),
|
|
375
|
+
max: zod_1.z.literal(10).describe("NPS always ends at 10"),
|
|
376
|
+
minLabel: zod_1.z
|
|
377
|
+
.string()
|
|
378
|
+
.max(100)
|
|
379
|
+
.optional()
|
|
380
|
+
.describe("Label for the minimum NPS value (0)"),
|
|
381
|
+
maxLabel: zod_1.z
|
|
382
|
+
.string()
|
|
383
|
+
.max(100)
|
|
384
|
+
.optional()
|
|
385
|
+
.describe("Label for the maximum NPS value (10)"),
|
|
386
|
+
scaleLabels: zod_1.z
|
|
387
|
+
.record(zod_1.z.string().regex(/^\d+$/).transform(Number).refine(val => val >= 0 && val <= 10), zod_1.z.string().max(50))
|
|
388
|
+
.optional()
|
|
389
|
+
.describe("Custom labels for specific NPS values (0-10)"),
|
|
390
|
+
prepopulatedValue: zod_1.z
|
|
391
|
+
.number()
|
|
392
|
+
.int()
|
|
393
|
+
.min(0)
|
|
394
|
+
.max(10)
|
|
395
|
+
.optional()
|
|
396
|
+
.describe("Default value to pre-select (0-10)"),
|
|
397
|
+
})
|
|
398
|
+
.refine((data) => {
|
|
399
|
+
// If scaleLabels is provided, validate that all keys are within the 0-10 range
|
|
400
|
+
if (data.scaleLabels) {
|
|
401
|
+
const keys = Object.keys(data.scaleLabels).map(Number);
|
|
402
|
+
return keys.every((key) => key >= 0 && key <= 10);
|
|
403
|
+
}
|
|
404
|
+
return true;
|
|
405
|
+
}, {
|
|
406
|
+
message: "scaleLabels keys must be between 0 and 10 (inclusive)",
|
|
407
|
+
path: ["scaleLabels"],
|
|
408
|
+
})
|
|
409
|
+
.describe("Schema for Net Promoter Score questions with 0-10 scale");
|
|
410
|
+
// Short answer question schema (extends base question with text input properties)
|
|
411
|
+
exports.shortAnswerQuestionSchema = exports.questionSchema
|
|
412
|
+
.extend({
|
|
413
|
+
type: zod_1.z
|
|
414
|
+
.literal(exports.questionTypeSchema.enum.short_answer)
|
|
415
|
+
.describe("Must be exactly 'short_answer'"),
|
|
416
|
+
maxCharacters: zod_1.z
|
|
417
|
+
.number()
|
|
418
|
+
.int()
|
|
419
|
+
.min(1)
|
|
420
|
+
.max(10000)
|
|
421
|
+
.optional()
|
|
422
|
+
.describe("Maximum number of characters allowed"),
|
|
423
|
+
minCharacters: zod_1.z
|
|
424
|
+
.number()
|
|
425
|
+
.int()
|
|
426
|
+
.min(0)
|
|
427
|
+
.optional()
|
|
428
|
+
.describe("Minimum number of characters required"),
|
|
429
|
+
placeholder: zod_1.z
|
|
430
|
+
.string()
|
|
431
|
+
.max(200)
|
|
432
|
+
.optional()
|
|
433
|
+
.describe("Placeholder text shown in the input field"),
|
|
434
|
+
enableRegexValidation: zod_1.z
|
|
435
|
+
.boolean()
|
|
436
|
+
.optional()
|
|
437
|
+
.default(false)
|
|
438
|
+
.describe("Whether to enable regex pattern validation"),
|
|
439
|
+
regexPattern: zod_1.z
|
|
440
|
+
.string()
|
|
441
|
+
.optional()
|
|
442
|
+
.describe("Regular expression pattern for validation"),
|
|
443
|
+
enableEnhanceWithAi: zod_1.z
|
|
444
|
+
.boolean()
|
|
445
|
+
.optional()
|
|
446
|
+
.default(false)
|
|
447
|
+
.describe("Whether to enable AI enhancement features"),
|
|
448
|
+
promptTemplate: zod_1.z
|
|
449
|
+
.string()
|
|
450
|
+
.max(2000)
|
|
451
|
+
.optional()
|
|
452
|
+
.describe("Template for AI enhancement prompts"),
|
|
453
|
+
cooldownSeconds: zod_1.z
|
|
454
|
+
.number()
|
|
455
|
+
.int()
|
|
456
|
+
.min(0)
|
|
457
|
+
.max(3600)
|
|
458
|
+
.optional()
|
|
459
|
+
.describe("Cooldown period between AI enhancements (0-3600 seconds)"),
|
|
460
|
+
maxEnhancements: zod_1.z
|
|
461
|
+
.number()
|
|
462
|
+
.int()
|
|
463
|
+
.min(1)
|
|
464
|
+
.max(10)
|
|
465
|
+
.optional()
|
|
466
|
+
.describe("Maximum number of AI enhancements allowed"),
|
|
467
|
+
maxTokenAllowed: zod_1.z
|
|
468
|
+
.number()
|
|
469
|
+
.int()
|
|
470
|
+
.min(1)
|
|
471
|
+
.max(10000)
|
|
472
|
+
.optional()
|
|
473
|
+
.describe("Maximum tokens allowed for AI processing"),
|
|
474
|
+
minCharactersToEnhance: zod_1.z
|
|
475
|
+
.number()
|
|
476
|
+
.int()
|
|
477
|
+
.min(1)
|
|
478
|
+
.optional()
|
|
479
|
+
.describe("Minimum characters needed to trigger AI enhancement"),
|
|
480
|
+
})
|
|
481
|
+
.refine((data) => {
|
|
482
|
+
// If both minCharacters and maxCharacters are provided, minCharacters should be <= maxCharacters
|
|
483
|
+
if (data.minCharacters !== undefined &&
|
|
484
|
+
data.maxCharacters !== undefined) {
|
|
485
|
+
return data.minCharacters <= data.maxCharacters;
|
|
486
|
+
}
|
|
487
|
+
return true;
|
|
488
|
+
}, {
|
|
489
|
+
message: "minCharacters cannot be greater than maxCharacters",
|
|
490
|
+
path: ["minCharacters"],
|
|
491
|
+
})
|
|
492
|
+
.refine((data) => {
|
|
493
|
+
// If enableRegexValidation is true, regexPattern should be provided
|
|
494
|
+
if (data.enableRegexValidation && !data.regexPattern) {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
return true;
|
|
498
|
+
}, {
|
|
499
|
+
message: "regexPattern is required when enableRegexValidation is true",
|
|
500
|
+
path: ["regexPattern"],
|
|
501
|
+
})
|
|
502
|
+
.refine((data) => {
|
|
503
|
+
// If enableEnhanceWithAi is true, promptTemplate should be provided
|
|
504
|
+
if (data.enableEnhanceWithAi && !data.promptTemplate) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
return true;
|
|
508
|
+
}, {
|
|
509
|
+
message: "promptTemplate is required when enableEnhanceWithAi is true",
|
|
510
|
+
path: ["promptTemplate"],
|
|
511
|
+
})
|
|
512
|
+
.describe("Schema for short answer questions with optional AI enhancement");
|
|
513
|
+
// Long answer question schema (extends base question with rich text input properties)
|
|
514
|
+
exports.longAnswerQuestionSchema = exports.questionSchema
|
|
515
|
+
.extend({
|
|
516
|
+
type: zod_1.z
|
|
517
|
+
.literal(exports.questionTypeSchema.enum.long_text)
|
|
518
|
+
.describe("Must be exactly 'long_text'"),
|
|
519
|
+
maxCharacters: zod_1.z
|
|
520
|
+
.number()
|
|
521
|
+
.int()
|
|
522
|
+
.min(1)
|
|
523
|
+
.max(50000)
|
|
524
|
+
.optional()
|
|
525
|
+
.describe("Maximum number of characters allowed (higher limit for long text)"),
|
|
526
|
+
minCharacters: zod_1.z
|
|
527
|
+
.number()
|
|
528
|
+
.int()
|
|
529
|
+
.min(0)
|
|
530
|
+
.optional()
|
|
531
|
+
.describe("Minimum number of characters required"),
|
|
532
|
+
rows: zod_1.z
|
|
533
|
+
.number()
|
|
534
|
+
.int()
|
|
535
|
+
.min(1)
|
|
536
|
+
.max(20)
|
|
537
|
+
.optional()
|
|
538
|
+
.describe("Number of textarea rows to display (1-20)"),
|
|
539
|
+
placeholder: zod_1.z
|
|
540
|
+
.string()
|
|
541
|
+
.max(500)
|
|
542
|
+
.optional()
|
|
543
|
+
.describe("Placeholder text for the textarea (longer for long text)"),
|
|
544
|
+
enableEnhanceWithAi: zod_1.z
|
|
545
|
+
.boolean()
|
|
546
|
+
.optional()
|
|
547
|
+
.default(false)
|
|
548
|
+
.describe("Whether to enable AI enhancement features"),
|
|
549
|
+
promptTemplate: zod_1.z
|
|
550
|
+
.string()
|
|
551
|
+
.max(2000)
|
|
552
|
+
.optional()
|
|
553
|
+
.describe("Template for AI enhancement prompts"),
|
|
554
|
+
cooldownSeconds: zod_1.z
|
|
555
|
+
.number()
|
|
556
|
+
.int()
|
|
557
|
+
.min(0)
|
|
558
|
+
.max(3600)
|
|
559
|
+
.optional()
|
|
560
|
+
.describe("Cooldown period between AI enhancements (0-3600 seconds)"),
|
|
561
|
+
maxEnhancements: zod_1.z
|
|
562
|
+
.number()
|
|
563
|
+
.int()
|
|
564
|
+
.min(1)
|
|
565
|
+
.max(10)
|
|
566
|
+
.optional()
|
|
567
|
+
.describe("Maximum number of AI enhancements allowed"),
|
|
568
|
+
maxTokenAllowed: zod_1.z
|
|
569
|
+
.number()
|
|
570
|
+
.int()
|
|
571
|
+
.min(1)
|
|
572
|
+
.max(25000)
|
|
573
|
+
.optional()
|
|
574
|
+
.describe("Maximum tokens allowed for AI processing (higher for long text)"),
|
|
575
|
+
})
|
|
576
|
+
.refine((data) => {
|
|
577
|
+
// If both minCharacters and maxCharacters are provided, minCharacters should be <= maxCharacters
|
|
578
|
+
if (data.minCharacters !== undefined &&
|
|
579
|
+
data.maxCharacters !== undefined) {
|
|
580
|
+
return data.minCharacters <= data.maxCharacters;
|
|
581
|
+
}
|
|
582
|
+
return true;
|
|
583
|
+
}, {
|
|
584
|
+
message: "minCharacters cannot be greater than maxCharacters",
|
|
585
|
+
path: ["minCharacters"],
|
|
586
|
+
})
|
|
587
|
+
.refine((data) => {
|
|
588
|
+
// If enableEnhanceWithAi is true, promptTemplate should be provided
|
|
589
|
+
if (data.enableEnhanceWithAi && !data.promptTemplate) {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
return true;
|
|
593
|
+
}, {
|
|
594
|
+
message: "promptTemplate is required when enableEnhanceWithAi is true",
|
|
595
|
+
path: ["promptTemplate"],
|
|
596
|
+
})
|
|
597
|
+
.describe("Schema for long answer questions with rich text support and AI enhancement");
|
|
598
|
+
// Nested dropdown question schema (extends base question with hierarchical selection properties)
|
|
599
|
+
exports.nestedDropdownQuestionSchema = exports.questionSchema
|
|
600
|
+
.extend({
|
|
601
|
+
type: zod_1.z
|
|
602
|
+
.literal(exports.questionTypeSchema.enum.nested_selection)
|
|
603
|
+
.describe("Must be exactly 'nested_selection'"),
|
|
604
|
+
placeholder: zod_1.z
|
|
605
|
+
.string()
|
|
606
|
+
.max(200)
|
|
607
|
+
.optional()
|
|
608
|
+
.describe("Placeholder text for the nested dropdown"),
|
|
609
|
+
options: zod_1.z
|
|
610
|
+
.array(exports.nestedOptionSchema)
|
|
611
|
+
.min(1)
|
|
612
|
+
.max(100)
|
|
613
|
+
.describe("Array of nested options for hierarchical selection (1-100 options)"),
|
|
614
|
+
displayStyle: zod_1.z
|
|
615
|
+
.literal("list")
|
|
616
|
+
.describe("Fixed display style for nested dropdowns"),
|
|
617
|
+
choiceOrderOption: exports.choiceOrderOptionSchema
|
|
618
|
+
.optional()
|
|
619
|
+
.default("none")
|
|
620
|
+
.describe("How to order the nested choices"),
|
|
621
|
+
preserveLastChoices: zod_1.z
|
|
622
|
+
.number()
|
|
623
|
+
.int()
|
|
624
|
+
.min(0)
|
|
625
|
+
.max(10)
|
|
626
|
+
.optional()
|
|
627
|
+
.describe("Number of choice levels to preserve (0-10)"),
|
|
628
|
+
prepopulatedValue: zod_1.z
|
|
629
|
+
.string()
|
|
630
|
+
.max(1000)
|
|
631
|
+
.optional()
|
|
632
|
+
.describe("Default value to pre-populate"),
|
|
633
|
+
allowOther: zod_1.z
|
|
634
|
+
.boolean()
|
|
635
|
+
.optional()
|
|
636
|
+
.default(false)
|
|
637
|
+
.describe('Whether to allow custom "other" options'),
|
|
638
|
+
otherColumnName: zod_1.z
|
|
639
|
+
.string()
|
|
640
|
+
.max(100)
|
|
641
|
+
.optional()
|
|
642
|
+
.describe('Column name for storing custom "other" values'),
|
|
643
|
+
maxDepth: zod_1.z
|
|
644
|
+
.number()
|
|
645
|
+
.int()
|
|
646
|
+
.min(1)
|
|
647
|
+
.max(10)
|
|
648
|
+
.optional()
|
|
649
|
+
.describe("Maximum nesting depth allowed (1-10)"),
|
|
650
|
+
cascadeLabels: zod_1.z
|
|
651
|
+
.boolean()
|
|
652
|
+
.optional()
|
|
653
|
+
.default(false)
|
|
654
|
+
.describe("Whether to cascade labels from parent options"),
|
|
655
|
+
})
|
|
656
|
+
.refine((data) => {
|
|
657
|
+
// If allowOther is true, otherColumnName should be provided
|
|
658
|
+
if (data.allowOther && !data.otherColumnName) {
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
return true;
|
|
662
|
+
}, {
|
|
663
|
+
message: "otherColumnName is required when allowOther is true",
|
|
664
|
+
path: ["otherColumnName"],
|
|
665
|
+
})
|
|
666
|
+
.describe("Schema for nested dropdown questions with hierarchical option structure");
|
|
667
|
+
// Combined question schema using discriminated union for proper type safety
|
|
668
|
+
exports.combinedQuestionSchema = zod_1.z.discriminatedUnion("type", [
|
|
669
|
+
exports.ratingQuestionSchema,
|
|
670
|
+
exports.annotationQuestionSchema,
|
|
671
|
+
exports.multipleChoiceSingleQuestionSchema,
|
|
672
|
+
exports.multipleChoiceMultipleQuestionSchema,
|
|
673
|
+
exports.npsQuestionSchema,
|
|
674
|
+
exports.shortAnswerQuestionSchema,
|
|
675
|
+
exports.longAnswerQuestionSchema,
|
|
676
|
+
exports.nestedDropdownQuestionSchema,
|
|
677
|
+
]);
|
|
678
|
+
//# sourceMappingURL=field-schema.js.map
|