@perkos/schema-validation 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.
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # @perkos/schema-validation
2
+
3
+ Zod validation schemas for AI and payment services.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @perkos/schema-validation
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### AI Validators
14
+
15
+ ```typescript
16
+ import {
17
+ imageAnalyzeSchema,
18
+ imageGenerateSchema,
19
+ textSummarizeSchema,
20
+ validate,
21
+ safeValidate,
22
+ } from "@perkos/schema-validation";
23
+
24
+ // Or import specifically from ai subpath
25
+ import { codeGenerateSchema } from "@perkos/schema-validation/ai";
26
+
27
+ // Validate with parse (throws on error)
28
+ const input = validate(imageAnalyzeSchema, {
29
+ image: "https://example.com/image.jpg",
30
+ question: "What is in this image?",
31
+ });
32
+
33
+ // Safe validate (returns result object)
34
+ const result = safeValidate(imageGenerateSchema, requestBody);
35
+ if (result.success) {
36
+ console.log(result.data.prompt);
37
+ } else {
38
+ console.error(result.error.errors);
39
+ }
40
+ ```
41
+
42
+ ### Payment Validators
43
+
44
+ ```typescript
45
+ import {
46
+ paymentEnvelopeSchema,
47
+ ethereumAddressSchema,
48
+ networkSchema,
49
+ } from "@perkos/schema-validation";
50
+
51
+ // Or import from payment subpath
52
+ import { paymentConfigSchema } from "@perkos/schema-validation/payment";
53
+
54
+ // Validate Ethereum address
55
+ const address = ethereumAddressSchema.parse("0x1234...");
56
+
57
+ // Validate payment envelope
58
+ const envelope = paymentEnvelopeSchema.parse({
59
+ payload: {
60
+ from: "0x...",
61
+ to: "0x...",
62
+ value: "1000000",
63
+ validAfter: 0,
64
+ validBefore: Date.now() + 3600000,
65
+ nonce: "abc123",
66
+ network: "eip155:43114",
67
+ },
68
+ signature: "0x...",
69
+ });
70
+ ```
71
+
72
+ ## AI Schemas
73
+
74
+ ### Vision & Image
75
+
76
+ - `imageAnalyzeSchema` - Image analysis requests
77
+ - `imageGenerateSchema` - Image generation (DALL-E, SDXL)
78
+ - `ocrExtractSchema` - OCR text extraction
79
+
80
+ ### Audio
81
+
82
+ - `textSynthesizeSchema` - Text-to-speech
83
+ - `audioTranscribeSchema` - Speech-to-text
84
+
85
+ ### Text Processing
86
+
87
+ - `textSummarizeSchema` - Text summarization
88
+ - `textTranslateSchema` - Translation
89
+ - `sentimentAnalyzeSchema` - Sentiment analysis
90
+ - `contentModerateSchema` - Content moderation
91
+ - `textSimplifySchema` - Text simplification
92
+ - `entityExtractSchema` - Named entity extraction
93
+
94
+ ### Content Generation
95
+
96
+ - `emailGenerateSchema` - Email generation
97
+ - `productDescriptionSchema` - Product descriptions
98
+ - `seoOptimizeSchema` - SEO optimization
99
+
100
+ ### Code & Technical
101
+
102
+ - `codeGenerateSchema` - Code generation
103
+ - `codeReviewSchema` - Code review
104
+ - `sqlQuerySchema` - SQL query generation
105
+ - `regexGenerateSchema` - Regex generation
106
+ - `apiDocsSchema` - API documentation
107
+
108
+ ### Educational
109
+
110
+ - `quizGenerateSchema` - Quiz generation
111
+
112
+ ## Payment Schemas
113
+
114
+ ### Network & Chain
115
+
116
+ - `networkSchema` - Supported networks enum
117
+ - `caip2NetworkSchema` - CAIP-2 network format
118
+ - `ethereumAddressSchema` - Ethereum address validation
119
+ - `transactionHashSchema` - Transaction hash validation
120
+ - `signatureSchema` - Signature format validation
121
+
122
+ ### Payment
123
+
124
+ - `paymentEnvelopeSchema` - x402 payment envelope
125
+ - `paymentConfigSchema` - Payment configuration
126
+ - `paymentRequestSchema` - Payment request
127
+ - `paymentVerificationSchema` - Payment verification
128
+
129
+ ### Token
130
+
131
+ - `tokenInfoSchema` - ERC20 token info
132
+ - `eip712DomainSchema` - EIP-712 domain
133
+
134
+ ### Settlement
135
+
136
+ - `settlementRequestSchema` - Settlement request
137
+ - `settlementResultSchema` - Settlement result
138
+
139
+ ## Utility Functions
140
+
141
+ ### `validate(schema, data)`
142
+
143
+ Parse and validate data, throwing on errors.
144
+
145
+ ### `safeValidate(schema, data)`
146
+
147
+ Safely validate, returning `{ success, data }` or `{ success, error }`.
148
+
149
+ ### `formatZodErrors(error)`
150
+
151
+ Format Zod errors for API responses.
152
+
153
+ ```typescript
154
+ import { formatZodErrors } from "@perkos/schema-validation";
155
+
156
+ try {
157
+ schema.parse(data);
158
+ } catch (error) {
159
+ if (error instanceof z.ZodError) {
160
+ const formatted = formatZodErrors(error);
161
+ // [{ path: "email", message: "Invalid email", code: "invalid_string" }]
162
+ }
163
+ }
164
+ ```
165
+
166
+ ## Type Inference
167
+
168
+ All schemas export inferred TypeScript types:
169
+
170
+ ```typescript
171
+ import type {
172
+ ImageAnalyzeInput,
173
+ PaymentEnvelope,
174
+ Network,
175
+ } from "@perkos/schema-validation";
176
+ ```
177
+
178
+ ## License
179
+
180
+ MIT
package/dist/ai.d.mts ADDED
@@ -0,0 +1,307 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * @perkos/validators/ai
5
+ * AI endpoint request validators using Zod
6
+ */
7
+
8
+ declare const imageAnalyzeSchema: z.ZodObject<{
9
+ image: z.ZodString;
10
+ question: z.ZodOptional<z.ZodString>;
11
+ maxTokens: z.ZodOptional<z.ZodNumber>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ image: string;
14
+ question?: string | undefined;
15
+ maxTokens?: number | undefined;
16
+ }, {
17
+ image: string;
18
+ question?: string | undefined;
19
+ maxTokens?: number | undefined;
20
+ }>;
21
+ declare const imageGenerateSchema: z.ZodObject<{
22
+ prompt: z.ZodString;
23
+ size: z.ZodDefault<z.ZodOptional<z.ZodEnum<["1024x1024", "1792x1024", "1024x1792"]>>>;
24
+ quality: z.ZodDefault<z.ZodOptional<z.ZodEnum<["standard", "hd"]>>>;
25
+ style: z.ZodDefault<z.ZodOptional<z.ZodEnum<["vivid", "natural"]>>>;
26
+ n: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ prompt: string;
29
+ size: "1024x1024" | "1792x1024" | "1024x1792";
30
+ quality: "standard" | "hd";
31
+ style: "vivid" | "natural";
32
+ n: number;
33
+ }, {
34
+ prompt: string;
35
+ size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
36
+ quality?: "standard" | "hd" | undefined;
37
+ style?: "vivid" | "natural" | undefined;
38
+ n?: number | undefined;
39
+ }>;
40
+ declare const ocrExtractSchema: z.ZodObject<{
41
+ image: z.ZodString;
42
+ language: z.ZodOptional<z.ZodString>;
43
+ }, "strip", z.ZodTypeAny, {
44
+ image: string;
45
+ language?: string | undefined;
46
+ }, {
47
+ image: string;
48
+ language?: string | undefined;
49
+ }>;
50
+ declare const textSynthesizeSchema: z.ZodObject<{
51
+ text: z.ZodString;
52
+ voice: z.ZodDefault<z.ZodOptional<z.ZodEnum<["alloy", "echo", "fable", "onyx", "nova", "shimmer"]>>>;
53
+ speed: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
54
+ }, "strip", z.ZodTypeAny, {
55
+ text: string;
56
+ voice: "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer";
57
+ speed: number;
58
+ }, {
59
+ text: string;
60
+ voice?: "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer" | undefined;
61
+ speed?: number | undefined;
62
+ }>;
63
+ declare const audioTranscribeSchema: z.ZodObject<{
64
+ audio: z.ZodString;
65
+ language: z.ZodOptional<z.ZodString>;
66
+ prompt: z.ZodOptional<z.ZodString>;
67
+ }, "strip", z.ZodTypeAny, {
68
+ audio: string;
69
+ prompt?: string | undefined;
70
+ language?: string | undefined;
71
+ }, {
72
+ audio: string;
73
+ prompt?: string | undefined;
74
+ language?: string | undefined;
75
+ }>;
76
+ declare const textSummarizeSchema: z.ZodObject<{
77
+ text: z.ZodString;
78
+ length: z.ZodDefault<z.ZodOptional<z.ZodEnum<["short", "medium", "long"]>>>;
79
+ format: z.ZodDefault<z.ZodOptional<z.ZodEnum<["paragraph", "bullets"]>>>;
80
+ }, "strip", z.ZodTypeAny, {
81
+ length: "short" | "medium" | "long";
82
+ text: string;
83
+ format: "paragraph" | "bullets";
84
+ }, {
85
+ text: string;
86
+ length?: "short" | "medium" | "long" | undefined;
87
+ format?: "paragraph" | "bullets" | undefined;
88
+ }>;
89
+ declare const textTranslateSchema: z.ZodObject<{
90
+ text: z.ZodString;
91
+ sourceLang: z.ZodString;
92
+ targetLang: z.ZodString;
93
+ formality: z.ZodOptional<z.ZodEnum<["formal", "informal", "neutral"]>>;
94
+ }, "strip", z.ZodTypeAny, {
95
+ text: string;
96
+ sourceLang: string;
97
+ targetLang: string;
98
+ formality?: "formal" | "informal" | "neutral" | undefined;
99
+ }, {
100
+ text: string;
101
+ sourceLang: string;
102
+ targetLang: string;
103
+ formality?: "formal" | "informal" | "neutral" | undefined;
104
+ }>;
105
+ declare const sentimentAnalyzeSchema: z.ZodObject<{
106
+ text: z.ZodString;
107
+ detailed: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
108
+ }, "strip", z.ZodTypeAny, {
109
+ text: string;
110
+ detailed: boolean;
111
+ }, {
112
+ text: string;
113
+ detailed?: boolean | undefined;
114
+ }>;
115
+ declare const contentModerateSchema: z.ZodObject<{
116
+ content: z.ZodString;
117
+ categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
118
+ }, "strip", z.ZodTypeAny, {
119
+ content: string;
120
+ categories?: string[] | undefined;
121
+ }, {
122
+ content: string;
123
+ categories?: string[] | undefined;
124
+ }>;
125
+ declare const textSimplifySchema: z.ZodObject<{
126
+ text: z.ZodString;
127
+ targetLevel: z.ZodDefault<z.ZodOptional<z.ZodEnum<["elementary", "middle", "high", "college"]>>>;
128
+ }, "strip", z.ZodTypeAny, {
129
+ text: string;
130
+ targetLevel: "elementary" | "middle" | "high" | "college";
131
+ }, {
132
+ text: string;
133
+ targetLevel?: "elementary" | "middle" | "high" | "college" | undefined;
134
+ }>;
135
+ declare const entityExtractSchema: z.ZodObject<{
136
+ text: z.ZodString;
137
+ types: z.ZodOptional<z.ZodArray<z.ZodEnum<["person", "organization", "location", "date", "money", "product"]>, "many">>;
138
+ }, "strip", z.ZodTypeAny, {
139
+ text: string;
140
+ types?: ("date" | "person" | "organization" | "location" | "money" | "product")[] | undefined;
141
+ }, {
142
+ text: string;
143
+ types?: ("date" | "person" | "organization" | "location" | "money" | "product")[] | undefined;
144
+ }>;
145
+ declare const emailGenerateSchema: z.ZodObject<{
146
+ context: z.ZodString;
147
+ tone: z.ZodDefault<z.ZodOptional<z.ZodEnum<["professional", "friendly", "formal", "casual"]>>>;
148
+ length: z.ZodDefault<z.ZodOptional<z.ZodEnum<["short", "medium", "long"]>>>;
149
+ }, "strip", z.ZodTypeAny, {
150
+ length: "short" | "medium" | "long";
151
+ context: string;
152
+ tone: "formal" | "professional" | "friendly" | "casual";
153
+ }, {
154
+ context: string;
155
+ length?: "short" | "medium" | "long" | undefined;
156
+ tone?: "formal" | "professional" | "friendly" | "casual" | undefined;
157
+ }>;
158
+ declare const productDescriptionSchema: z.ZodObject<{
159
+ product: z.ZodString;
160
+ features: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
161
+ audience: z.ZodOptional<z.ZodString>;
162
+ tone: z.ZodDefault<z.ZodOptional<z.ZodEnum<["professional", "casual", "luxury", "technical"]>>>;
163
+ }, "strip", z.ZodTypeAny, {
164
+ product: string;
165
+ tone: "professional" | "casual" | "luxury" | "technical";
166
+ features?: string[] | undefined;
167
+ audience?: string | undefined;
168
+ }, {
169
+ product: string;
170
+ tone?: "professional" | "casual" | "luxury" | "technical" | undefined;
171
+ features?: string[] | undefined;
172
+ audience?: string | undefined;
173
+ }>;
174
+ declare const seoOptimizeSchema: z.ZodObject<{
175
+ content: z.ZodString;
176
+ keywords: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
177
+ targetUrl: z.ZodOptional<z.ZodString>;
178
+ }, "strip", z.ZodTypeAny, {
179
+ content: string;
180
+ keywords?: string[] | undefined;
181
+ targetUrl?: string | undefined;
182
+ }, {
183
+ content: string;
184
+ keywords?: string[] | undefined;
185
+ targetUrl?: string | undefined;
186
+ }>;
187
+ declare const codeGenerateSchema: z.ZodObject<{
188
+ prompt: z.ZodString;
189
+ language: z.ZodString;
190
+ framework: z.ZodOptional<z.ZodString>;
191
+ style: z.ZodDefault<z.ZodOptional<z.ZodEnum<["concise", "documented", "verbose"]>>>;
192
+ }, "strip", z.ZodTypeAny, {
193
+ prompt: string;
194
+ style: "concise" | "documented" | "verbose";
195
+ language: string;
196
+ framework?: string | undefined;
197
+ }, {
198
+ prompt: string;
199
+ language: string;
200
+ style?: "concise" | "documented" | "verbose" | undefined;
201
+ framework?: string | undefined;
202
+ }>;
203
+ declare const codeReviewSchema: z.ZodObject<{
204
+ code: z.ZodString;
205
+ language: z.ZodOptional<z.ZodString>;
206
+ focus: z.ZodOptional<z.ZodArray<z.ZodEnum<["security", "performance", "readability", "bugs", "best-practices"]>, "many">>;
207
+ }, "strip", z.ZodTypeAny, {
208
+ code: string;
209
+ language?: string | undefined;
210
+ focus?: ("security" | "performance" | "readability" | "bugs" | "best-practices")[] | undefined;
211
+ }, {
212
+ code: string;
213
+ language?: string | undefined;
214
+ focus?: ("security" | "performance" | "readability" | "bugs" | "best-practices")[] | undefined;
215
+ }>;
216
+ declare const sqlQuerySchema: z.ZodObject<{
217
+ description: z.ZodString;
218
+ schema: z.ZodOptional<z.ZodString>;
219
+ dialect: z.ZodDefault<z.ZodOptional<z.ZodEnum<["postgresql", "mysql", "sqlite", "mssql"]>>>;
220
+ }, "strip", z.ZodTypeAny, {
221
+ description: string;
222
+ dialect: "postgresql" | "mysql" | "sqlite" | "mssql";
223
+ schema?: string | undefined;
224
+ }, {
225
+ description: string;
226
+ schema?: string | undefined;
227
+ dialect?: "postgresql" | "mysql" | "sqlite" | "mssql" | undefined;
228
+ }>;
229
+ declare const regexGenerateSchema: z.ZodObject<{
230
+ description: z.ZodString;
231
+ examples: z.ZodOptional<z.ZodArray<z.ZodObject<{
232
+ input: z.ZodString;
233
+ shouldMatch: z.ZodBoolean;
234
+ }, "strip", z.ZodTypeAny, {
235
+ input: string;
236
+ shouldMatch: boolean;
237
+ }, {
238
+ input: string;
239
+ shouldMatch: boolean;
240
+ }>, "many">>;
241
+ flavor: z.ZodDefault<z.ZodOptional<z.ZodEnum<["javascript", "python", "pcre"]>>>;
242
+ }, "strip", z.ZodTypeAny, {
243
+ description: string;
244
+ flavor: "javascript" | "python" | "pcre";
245
+ examples?: {
246
+ input: string;
247
+ shouldMatch: boolean;
248
+ }[] | undefined;
249
+ }, {
250
+ description: string;
251
+ examples?: {
252
+ input: string;
253
+ shouldMatch: boolean;
254
+ }[] | undefined;
255
+ flavor?: "javascript" | "python" | "pcre" | undefined;
256
+ }>;
257
+ declare const apiDocsSchema: z.ZodObject<{
258
+ code: z.ZodString;
259
+ format: z.ZodDefault<z.ZodOptional<z.ZodEnum<["openapi", "markdown", "jsdoc"]>>>;
260
+ includeExamples: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
261
+ }, "strip", z.ZodTypeAny, {
262
+ code: string;
263
+ format: "openapi" | "markdown" | "jsdoc";
264
+ includeExamples: boolean;
265
+ }, {
266
+ code: string;
267
+ format?: "openapi" | "markdown" | "jsdoc" | undefined;
268
+ includeExamples?: boolean | undefined;
269
+ }>;
270
+ declare const quizGenerateSchema: z.ZodObject<{
271
+ topic: z.ZodString;
272
+ questionCount: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
273
+ difficulty: z.ZodDefault<z.ZodOptional<z.ZodEnum<["easy", "medium", "hard"]>>>;
274
+ type: z.ZodDefault<z.ZodOptional<z.ZodEnum<["multiple-choice", "true-false", "mixed"]>>>;
275
+ }, "strip", z.ZodTypeAny, {
276
+ type: "multiple-choice" | "true-false" | "mixed";
277
+ topic: string;
278
+ questionCount: number;
279
+ difficulty: "medium" | "easy" | "hard";
280
+ }, {
281
+ topic: string;
282
+ type?: "multiple-choice" | "true-false" | "mixed" | undefined;
283
+ questionCount?: number | undefined;
284
+ difficulty?: "medium" | "easy" | "hard" | undefined;
285
+ }>;
286
+ type ImageAnalyzeInput = z.infer<typeof imageAnalyzeSchema>;
287
+ type ImageGenerateInput = z.infer<typeof imageGenerateSchema>;
288
+ type OCRExtractInput = z.infer<typeof ocrExtractSchema>;
289
+ type TextSynthesizeInput = z.infer<typeof textSynthesizeSchema>;
290
+ type AudioTranscribeInput = z.infer<typeof audioTranscribeSchema>;
291
+ type TextSummarizeInput = z.infer<typeof textSummarizeSchema>;
292
+ type TextTranslateInput = z.infer<typeof textTranslateSchema>;
293
+ type SentimentAnalyzeInput = z.infer<typeof sentimentAnalyzeSchema>;
294
+ type ContentModerateInput = z.infer<typeof contentModerateSchema>;
295
+ type TextSimplifyInput = z.infer<typeof textSimplifySchema>;
296
+ type EntityExtractInput = z.infer<typeof entityExtractSchema>;
297
+ type EmailGenerateInput = z.infer<typeof emailGenerateSchema>;
298
+ type ProductDescriptionInput = z.infer<typeof productDescriptionSchema>;
299
+ type SEOOptimizeInput = z.infer<typeof seoOptimizeSchema>;
300
+ type CodeGenerateInput = z.infer<typeof codeGenerateSchema>;
301
+ type CodeReviewInput = z.infer<typeof codeReviewSchema>;
302
+ type SQLQueryInput = z.infer<typeof sqlQuerySchema>;
303
+ type RegexGenerateInput = z.infer<typeof regexGenerateSchema>;
304
+ type APIDocsInput = z.infer<typeof apiDocsSchema>;
305
+ type QuizGenerateInput = z.infer<typeof quizGenerateSchema>;
306
+
307
+ export { type APIDocsInput, type AudioTranscribeInput, type CodeGenerateInput, type CodeReviewInput, type ContentModerateInput, type EmailGenerateInput, type EntityExtractInput, type ImageAnalyzeInput, type ImageGenerateInput, type OCRExtractInput, type ProductDescriptionInput, type QuizGenerateInput, type RegexGenerateInput, type SEOOptimizeInput, type SQLQueryInput, type SentimentAnalyzeInput, type TextSimplifyInput, type TextSummarizeInput, type TextSynthesizeInput, type TextTranslateInput, apiDocsSchema, audioTranscribeSchema, codeGenerateSchema, codeReviewSchema, contentModerateSchema, emailGenerateSchema, entityExtractSchema, imageAnalyzeSchema, imageGenerateSchema, ocrExtractSchema, productDescriptionSchema, quizGenerateSchema, regexGenerateSchema, sentimentAnalyzeSchema, seoOptimizeSchema, sqlQuerySchema, textSimplifySchema, textSummarizeSchema, textSynthesizeSchema, textTranslateSchema };