@zero-server/fetch 0.9.2 → 0.9.3

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/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // AUTO-GENERATED by .tools/generate-package-stubs.js — edit .tools/scope-manifest.js and re-run `npm run packages:generate`.
2
- export { fetch } from "@zero-server/sdk";
2
+ export * from './types/fetch';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zero-server/fetch",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Server-side fetch with mTLS, timeouts, AbortSignal.",
5
5
  "keywords": [
6
6
  "zero-server",
@@ -21,6 +21,7 @@
21
21
  },
22
22
  "files": [
23
23
  "lib",
24
+ "types",
24
25
  "index.js",
25
26
  "index.d.ts",
26
27
  "README.md",
@@ -44,7 +45,7 @@
44
45
  },
45
46
  "sideEffects": false,
46
47
  "peerDependencies": {
47
- "@zero-server/sdk": ">=0.9.2"
48
+ "@zero-server/sdk": ">=0.9.3"
48
49
  },
49
50
  "peerDependenciesMeta": {
50
51
  "@zero-server/sdk": {
package/types/app.d.ts ADDED
@@ -0,0 +1,223 @@
1
+ /// <reference types="node" />
2
+
3
+ import { Server as HttpServer } from 'http';
4
+ import { Server as HttpsServer, ServerOptions as TlsOptions } from 'https';
5
+ import { Http2Server, Http2SecureServer } from 'http2';
6
+ import { Request } from './request';
7
+ import { Response } from './response';
8
+ import { RouterInstance, RouteChain, RouteInfo, RouteOptions, RouteHandler } from './router';
9
+ import { MiddlewareFunction, ErrorHandlerFunction, NextFunction } from './middleware';
10
+ import { WebSocketHandler, WebSocketOptions, WebSocketPool } from './websocket';
11
+ import { SSEStream } from './sse';
12
+ import { LifecycleState } from './lifecycle';
13
+ import { MetricsRegistry, HealthCheckResult } from './observe';
14
+ import { ProtoSchema, GrpcServiceOptions, GrpcInterceptor, GrpcHandler } from './grpc';
15
+
16
+ export interface ListenOptions {
17
+ /** Create an HTTP/2 server. Combined with TLS options for h2 over TLS, or h2c (cleartext) otherwise. */
18
+ http2?: boolean;
19
+ /** Allow HTTP/1.1 fallback on HTTP/2 TLS servers (ALPN negotiation). Default: true. */
20
+ allowHTTP1?: boolean;
21
+ }
22
+
23
+ export interface App {
24
+ /** Internal router instance. */
25
+ router: RouterInstance;
26
+ /** Middleware stack. */
27
+ middlewares: MiddlewareFunction[];
28
+ /** Application-level locals, merged into every request/response locals. */
29
+ locals: Record<string, any>;
30
+
31
+ /**
32
+ * Register middleware or mount a sub-router.
33
+ */
34
+ use(fn: MiddlewareFunction): App;
35
+ use(path: string, fn: MiddlewareFunction): App;
36
+ use(path: string, router: RouterInstance): App;
37
+
38
+ /**
39
+ * Register a global error handler.
40
+ */
41
+ onError(fn: ErrorHandlerFunction): void;
42
+
43
+ /**
44
+ * Core request handler for use with `http.createServer()`.
45
+ */
46
+ handler(req: import('http').IncomingMessage, res: import('http').ServerResponse): void;
47
+
48
+ /**
49
+ * Start listening for connections.
50
+ * Pass `{ http2: true }` to create an HTTP/2 server (h2c cleartext or TLS with ALPN).
51
+ */
52
+ listen(port?: number, cb?: () => void): HttpServer;
53
+ listen(port: number, opts: TlsOptions, cb?: () => void): HttpsServer;
54
+ listen(port: number, opts: ListenOptions & { http2: true } & TlsOptions, cb?: () => void): Http2SecureServer;
55
+ listen(port: number, opts: ListenOptions & { http2: true }, cb?: () => void): Http2Server;
56
+ listen(port: number, opts: ListenOptions, cb?: () => void): HttpServer | HttpsServer | Http2Server | Http2SecureServer;
57
+
58
+ /**
59
+ * Gracefully close the server.
60
+ */
61
+ close(cb?: (err?: Error) => void): void;
62
+
63
+ /**
64
+ * Perform a full graceful shutdown.
65
+ */
66
+ shutdown(opts?: { timeout?: number }): Promise<void>;
67
+
68
+ /**
69
+ * Register a lifecycle event listener.
70
+ */
71
+ on(event: 'beforeShutdown' | 'shutdown', fn: () => void | Promise<void>): App;
72
+
73
+ /**
74
+ * Remove a lifecycle event listener.
75
+ */
76
+ off(event: 'beforeShutdown' | 'shutdown', fn: () => void | Promise<void>): App;
77
+
78
+ /**
79
+ * Register a WebSocket pool for graceful shutdown.
80
+ */
81
+ registerPool(pool: WebSocketPool): App;
82
+
83
+ /**
84
+ * Unregister a WebSocket pool from lifecycle management.
85
+ */
86
+ unregisterPool(pool: WebSocketPool): App;
87
+
88
+ /**
89
+ * Track an SSE stream for graceful shutdown.
90
+ */
91
+ trackSSE(stream: SSEStream): App;
92
+
93
+ /**
94
+ * Register an ORM Database for graceful shutdown.
95
+ */
96
+ registerDatabase(db: { close(): Promise<void> }): App;
97
+
98
+ /**
99
+ * Unregister an ORM Database from lifecycle management.
100
+ */
101
+ unregisterDatabase(db: { close(): Promise<void> }): App;
102
+
103
+ /**
104
+ * Configure the shutdown timeout in milliseconds.
105
+ */
106
+ shutdownTimeout(ms: number): App;
107
+
108
+ /**
109
+ * Current lifecycle state.
110
+ */
111
+ readonly lifecycleState: LifecycleState;
112
+
113
+ /**
114
+ * Register a liveness health check endpoint.
115
+ */
116
+ health(path?: string, checks?: Record<string, () => HealthCheckResult | boolean | Promise<HealthCheckResult | boolean>>): App;
117
+ health(checks?: Record<string, () => HealthCheckResult | boolean | Promise<HealthCheckResult | boolean>>): App;
118
+
119
+ /**
120
+ * Register a readiness health check endpoint.
121
+ */
122
+ ready(path?: string, checks?: Record<string, () => HealthCheckResult | boolean | Promise<HealthCheckResult | boolean>>): App;
123
+ ready(checks?: Record<string, () => HealthCheckResult | boolean | Promise<HealthCheckResult | boolean>>): App;
124
+
125
+ /**
126
+ * Register a custom health check.
127
+ */
128
+ addHealthCheck(name: string, fn: () => HealthCheckResult | boolean | Promise<HealthCheckResult | boolean>): App;
129
+
130
+ /**
131
+ * Get the application metrics registry.
132
+ */
133
+ metrics(): MetricsRegistry;
134
+
135
+ /**
136
+ * Mount a Prometheus metrics endpoint.
137
+ */
138
+ metricsEndpoint(path?: string, opts?: { registry?: MetricsRegistry }): App;
139
+
140
+ /**
141
+ * Register a WebSocket upgrade handler.
142
+ */
143
+ ws(path: string, handler: WebSocketHandler): void;
144
+ ws(path: string, opts: WebSocketOptions, handler: WebSocketHandler): void;
145
+
146
+ /**
147
+ * Register a gRPC service with handlers.
148
+ */
149
+ grpc(schema: ProtoSchema, serviceName: string, handlers: Record<string, GrpcHandler>, opts?: GrpcServiceOptions): App;
150
+
151
+ /**
152
+ * Add a global gRPC interceptor.
153
+ */
154
+ grpcInterceptor(fn: GrpcInterceptor): App;
155
+
156
+ /**
157
+ * Return a flat list of all registered routes.
158
+ */
159
+ routes(): RouteInfo[];
160
+
161
+ /**
162
+ * Register a route with a specific HTTP method.
163
+ */
164
+ route(method: string, path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
165
+
166
+ /**
167
+ * Get a setting value (1 arg) or set a setting value (2 args).
168
+ */
169
+ set(key: string): any;
170
+ set(key: string, val: any): App;
171
+
172
+ /**
173
+ * Get a setting value, or register a GET route.
174
+ * With 1 string arg: returns the setting value.
175
+ * With path + handlers: registers a GET route.
176
+ */
177
+ get(key: string): any;
178
+ get(path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
179
+
180
+ /**
181
+ * Enable a boolean setting (set to `true`).
182
+ */
183
+ enable(key: string): App;
184
+
185
+ /**
186
+ * Disable a boolean setting (set to `false`).
187
+ */
188
+ disable(key: string): App;
189
+
190
+ /**
191
+ * Check if a setting is truthy.
192
+ */
193
+ enabled(key: string): boolean;
194
+
195
+ /**
196
+ * Check if a setting is falsy.
197
+ */
198
+ disabled(key: string): boolean;
199
+
200
+ /**
201
+ * Register a parameter pre-processing handler.
202
+ */
203
+ param(name: string, fn: (req: Request, res: Response, next: NextFunction, value: string) => void): App;
204
+
205
+ /**
206
+ * Create a route group under a prefix with shared middleware.
207
+ */
208
+ group(prefix: string, ...args: [...MiddlewareFunction[], (router: RouterInstance) => void]): App;
209
+
210
+ /**
211
+ * Create a chainable route builder for the given path.
212
+ */
213
+ chain(path: string): RouteChain;
214
+
215
+ // HTTP method shortcuts
216
+ post(path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
217
+ put(path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
218
+ delete(path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
219
+ patch(path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
220
+ options(path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
221
+ head(path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
222
+ all(path: string, ...handlers: (RouteOptions | RouteHandler)[]): App;
223
+ }