-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathendpoint.zod.ts
More file actions
55 lines (45 loc) · 2.05 KB
/
endpoint.zod.ts
File metadata and controls
55 lines (45 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { HttpMethod, RateLimitConfigSchema } from '../shared/http.zod';
/**
* API Mapping Schema
* Transform input/output data.
*/
export const ApiMappingSchema = z.object({
source: z.string().describe('Source field/path'),
target: z.string().describe('Target field/path'),
transform: z.string().optional().describe('Transformation function name'),
});
/**
* API Endpoint Schema
* Defines an external facing API contract.
*/
export const ApiEndpointSchema = z.object({
/** Identity */
name: z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Unique endpoint ID'),
path: z.string().regex(/^\//).describe('URL Path (e.g. /api/v1/customers)'),
method: HttpMethod.describe('HTTP Method'),
/** Documentation */
summary: z.string().optional(),
description: z.string().optional(),
/** Execution Logic */
type: z.enum(['flow', 'script', 'object_operation', 'proxy']).describe('Implementation type'),
target: z.string().describe('Target Flow ID, Script Name, or Proxy URL'),
/** Logic Config */
objectParams: z.object({
object: z.string().optional(),
operation: z.enum(['find', 'get', 'create', 'update', 'delete']).optional(),
}).optional().describe('For object_operation type'),
/** Data Transformation */
inputMapping: z.array(ApiMappingSchema).optional().describe('Map Request Body to Internal Params'),
outputMapping: z.array(ApiMappingSchema).optional().describe('Map Internal Result to Response Body'),
/** Policies */
authRequired: z.boolean().default(true).describe('Require authentication'),
rateLimit: RateLimitConfigSchema.optional().describe('Rate limiting policy'),
cacheTtl: z.number().optional().describe('Response cache TTL in seconds'),
});
export const ApiEndpoint = Object.assign(ApiEndpointSchema, {
create: <T extends z.input<typeof ApiEndpointSchema>>(config: T) => config,
});
export type ApiEndpoint = z.infer<typeof ApiEndpointSchema>;
export type ApiEndpointInput = z.input<typeof ApiEndpointSchema>;