@zero-server/sdk 0.9.1 → 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.
Files changed (128) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +460 -443
  3. package/index.js +414 -412
  4. package/lib/app.js +1172 -1172
  5. package/lib/auth/authorize.js +399 -399
  6. package/lib/auth/enrollment.js +367 -367
  7. package/lib/auth/index.js +57 -57
  8. package/lib/auth/jwt.js +731 -731
  9. package/lib/auth/oauth.js +362 -362
  10. package/lib/auth/session.js +588 -588
  11. package/lib/auth/trustedDevice.js +409 -409
  12. package/lib/auth/twoFactor.js +1150 -1150
  13. package/lib/auth/webauthn.js +946 -946
  14. package/lib/body/index.js +14 -14
  15. package/lib/body/json.js +109 -109
  16. package/lib/body/multipart.js +440 -440
  17. package/lib/body/raw.js +71 -71
  18. package/lib/body/rawBuffer.js +160 -160
  19. package/lib/body/sendError.js +25 -25
  20. package/lib/body/text.js +75 -75
  21. package/lib/body/typeMatch.js +41 -41
  22. package/lib/body/urlencoded.js +235 -235
  23. package/lib/cli.js +845 -845
  24. package/lib/cluster.js +666 -666
  25. package/lib/debug.js +372 -372
  26. package/lib/env/index.js +465 -465
  27. package/lib/errors.js +683 -683
  28. package/lib/fetch/index.js +256 -256
  29. package/lib/grpc/balancer.js +378 -378
  30. package/lib/grpc/call.js +708 -708
  31. package/lib/grpc/client.js +764 -764
  32. package/lib/grpc/codec.js +1221 -1221
  33. package/lib/grpc/credentials.js +398 -398
  34. package/lib/grpc/frame.js +262 -262
  35. package/lib/grpc/health.js +287 -287
  36. package/lib/grpc/index.js +121 -121
  37. package/lib/grpc/metadata.js +461 -461
  38. package/lib/grpc/proto.js +821 -821
  39. package/lib/grpc/reflection.js +590 -590
  40. package/lib/grpc/server.js +445 -445
  41. package/lib/grpc/status.js +118 -118
  42. package/lib/grpc/watch.js +173 -173
  43. package/lib/http/index.js +10 -10
  44. package/lib/http/request.js +727 -727
  45. package/lib/http/response.js +799 -799
  46. package/lib/lifecycle.js +557 -557
  47. package/lib/middleware/compress.js +230 -230
  48. package/lib/middleware/cookieParser.js +237 -237
  49. package/lib/middleware/cors.js +93 -93
  50. package/lib/middleware/csrf.js +137 -137
  51. package/lib/middleware/errorHandler.js +101 -101
  52. package/lib/middleware/helmet.js +175 -175
  53. package/lib/middleware/index.js +19 -17
  54. package/lib/middleware/logger.js +74 -74
  55. package/lib/middleware/rateLimit.js +88 -88
  56. package/lib/middleware/requestId.js +53 -53
  57. package/lib/middleware/static.js +326 -326
  58. package/lib/middleware/timeout.js +71 -71
  59. package/lib/middleware/validator.js +255 -255
  60. package/lib/observe/health.js +326 -326
  61. package/lib/observe/index.js +50 -50
  62. package/lib/observe/logger.js +359 -359
  63. package/lib/observe/metrics.js +805 -805
  64. package/lib/observe/tracing.js +592 -592
  65. package/lib/orm/adapters/json.js +290 -290
  66. package/lib/orm/adapters/memory.js +764 -764
  67. package/lib/orm/adapters/mongo.js +764 -764
  68. package/lib/orm/adapters/mysql.js +933 -933
  69. package/lib/orm/adapters/postgres.js +1144 -1144
  70. package/lib/orm/adapters/redis.js +1534 -1534
  71. package/lib/orm/adapters/sql-base.js +212 -212
  72. package/lib/orm/adapters/sqlite.js +858 -858
  73. package/lib/orm/audit.js +649 -649
  74. package/lib/orm/cache.js +394 -394
  75. package/lib/orm/geo.js +387 -387
  76. package/lib/orm/index.js +784 -784
  77. package/lib/orm/migrate.js +432 -432
  78. package/lib/orm/model.js +1706 -1706
  79. package/lib/orm/plugin.js +375 -375
  80. package/lib/orm/procedures.js +836 -836
  81. package/lib/orm/profiler.js +233 -233
  82. package/lib/orm/query.js +1772 -1772
  83. package/lib/orm/replicas.js +241 -241
  84. package/lib/orm/schema.js +307 -307
  85. package/lib/orm/search.js +380 -380
  86. package/lib/orm/seed/data/commerce.js +136 -136
  87. package/lib/orm/seed/data/internet.js +111 -111
  88. package/lib/orm/seed/data/locations.js +204 -204
  89. package/lib/orm/seed/data/names.js +338 -338
  90. package/lib/orm/seed/data/person.js +128 -128
  91. package/lib/orm/seed/data/phone.js +211 -211
  92. package/lib/orm/seed/data/words.js +134 -134
  93. package/lib/orm/seed/factory.js +178 -178
  94. package/lib/orm/seed/fake.js +1186 -1186
  95. package/lib/orm/seed/index.js +18 -18
  96. package/lib/orm/seed/rng.js +70 -70
  97. package/lib/orm/seed/seeder.js +124 -124
  98. package/lib/orm/seed/unique.js +68 -68
  99. package/lib/orm/snapshot.js +366 -366
  100. package/lib/orm/tenancy.js +605 -605
  101. package/lib/orm/views.js +350 -350
  102. package/lib/router/index.js +436 -436
  103. package/lib/sse/index.js +8 -8
  104. package/lib/sse/stream.js +349 -349
  105. package/lib/ws/connection.js +451 -451
  106. package/lib/ws/handshake.js +125 -125
  107. package/lib/ws/index.js +14 -14
  108. package/lib/ws/room.js +223 -223
  109. package/package.json +73 -73
  110. package/types/app.d.ts +223 -223
  111. package/types/auth.d.ts +520 -520
  112. package/types/body.d.ts +14 -0
  113. package/types/cli.d.ts +2 -0
  114. package/types/cluster.d.ts +75 -75
  115. package/types/env.d.ts +80 -80
  116. package/types/errors.d.ts +316 -316
  117. package/types/fetch.d.ts +43 -43
  118. package/types/grpc.d.ts +432 -432
  119. package/types/index.d.ts +384 -384
  120. package/types/lifecycle.d.ts +60 -60
  121. package/types/middleware.d.ts +320 -320
  122. package/types/observe.d.ts +304 -304
  123. package/types/orm.d.ts +1887 -1887
  124. package/types/request.d.ts +109 -109
  125. package/types/response.d.ts +157 -157
  126. package/types/router.d.ts +78 -78
  127. package/types/sse.d.ts +78 -78
  128. package/types/websocket.d.ts +126 -126
@@ -1,109 +1,109 @@
1
- import { IncomingMessage, IncomingHttpHeaders } from 'http';
2
- import { App } from './app';
3
-
4
- export interface RangeResult {
5
- type: string;
6
- ranges: Array<{ start: number; end: number }>;
7
- }
8
-
9
- export interface Request {
10
- /** Original Node request. */
11
- raw: IncomingMessage;
12
- /** HTTP method (e.g. 'GET'). */
13
- method: string;
14
- /** Full request URL including query string. */
15
- url: string;
16
- /** URL path without query string. */
17
- path: string;
18
- /** Lower-cased request headers. */
19
- headers: IncomingHttpHeaders;
20
- /** Parsed query-string key/value pairs. */
21
- query: Record<string, string>;
22
- /** Route parameters populated by the router. */
23
- params: Record<string, string>;
24
- /** Request body (set by body-parsing middleware). */
25
- body: any;
26
- /** Raw request body as a Buffer (set by body-parsing middleware before parsing). */
27
- rawBody?: Buffer;
28
- /** Remote IP address (trust-proxy-aware). */
29
- readonly ip: string | null;
30
- /** Proxy chain addresses from X-Forwarded-For when trust proxy is enabled. */
31
- readonly ips: string[];
32
- /** `true` when the connection is over TLS (trust-proxy-aware). */
33
- readonly secure: boolean;
34
- /** Protocol string — `'https'` or `'http'` (trust-proxy-aware). */
35
- readonly protocol: 'http' | 'https';
36
- /** HTTP version string (e.g. '1.1', '2.0'). */
37
- httpVersion: string;
38
- /** Whether this request arrived over HTTP/2. */
39
- isHTTP2: boolean;
40
- /** ALPN protocol negotiated on the TLS socket (e.g. 'h2'), or null. */
41
- alpnProtocol: string | null;
42
- /** Parsed cookies (populated by cookieParser middleware). */
43
- cookies: Record<string, string>;
44
- /** Verified signed cookies (populated by cookieParser middleware). */
45
- signedCookies?: Record<string, string>;
46
- /** Request-scoped locals store. */
47
- locals: Record<string, any>;
48
- /** Request ID (populated by requestId middleware). */
49
- id?: string;
50
- /** Whether the request timed out (populated by timeout middleware). */
51
- timedOut?: boolean;
52
- /** The original URL as received — never rewritten by middleware. */
53
- originalUrl: string;
54
- /** The URL path on which the current router was mounted. */
55
- baseUrl: string;
56
- /** Reference to the parent App instance. */
57
- app: App | null;
58
- /** CSRF token (populated by csrf middleware). */
59
- csrfToken?: string;
60
- /** First signing secret (populated by cookieParser middleware). */
61
- secret?: string;
62
- /** All signing secrets (populated by cookieParser middleware). */
63
- secrets?: string[];
64
-
65
- /**
66
- * Get a specific request header (case-insensitive).
67
- */
68
- get(name: string): string | undefined;
69
-
70
- /**
71
- * Check if the request Content-Type matches the given type.
72
- */
73
- is(type: string): boolean;
74
-
75
- /**
76
- * Get the hostname from the Host header.
77
- */
78
- readonly hostname: string;
79
-
80
- /**
81
- * Get the subdomains as an array.
82
- */
83
- subdomains(offset?: number): string[];
84
-
85
- /**
86
- * Content negotiation — check which types the client accepts.
87
- */
88
- accepts(...types: string[]): string | false;
89
-
90
- /**
91
- * Check if the request is "fresh" (client cache valid).
92
- */
93
- readonly fresh: boolean;
94
-
95
- /**
96
- * Inverse of `fresh`.
97
- */
98
- readonly stale: boolean;
99
-
100
- /**
101
- * Check whether this request was made with XMLHttpRequest.
102
- */
103
- readonly xhr: boolean;
104
-
105
- /**
106
- * Parse the Range header.
107
- */
108
- range(size: number): RangeResult | -1 | -2;
109
- }
1
+ import { IncomingMessage, IncomingHttpHeaders } from 'http';
2
+ import { App } from './app';
3
+
4
+ export interface RangeResult {
5
+ type: string;
6
+ ranges: Array<{ start: number; end: number }>;
7
+ }
8
+
9
+ export interface Request {
10
+ /** Original Node request. */
11
+ raw: IncomingMessage;
12
+ /** HTTP method (e.g. 'GET'). */
13
+ method: string;
14
+ /** Full request URL including query string. */
15
+ url: string;
16
+ /** URL path without query string. */
17
+ path: string;
18
+ /** Lower-cased request headers. */
19
+ headers: IncomingHttpHeaders;
20
+ /** Parsed query-string key/value pairs. */
21
+ query: Record<string, string>;
22
+ /** Route parameters populated by the router. */
23
+ params: Record<string, string>;
24
+ /** Request body (set by body-parsing middleware). */
25
+ body: any;
26
+ /** Raw request body as a Buffer (set by body-parsing middleware before parsing). */
27
+ rawBody?: Buffer;
28
+ /** Remote IP address (trust-proxy-aware). */
29
+ readonly ip: string | null;
30
+ /** Proxy chain addresses from X-Forwarded-For when trust proxy is enabled. */
31
+ readonly ips: string[];
32
+ /** `true` when the connection is over TLS (trust-proxy-aware). */
33
+ readonly secure: boolean;
34
+ /** Protocol string — `'https'` or `'http'` (trust-proxy-aware). */
35
+ readonly protocol: 'http' | 'https';
36
+ /** HTTP version string (e.g. '1.1', '2.0'). */
37
+ httpVersion: string;
38
+ /** Whether this request arrived over HTTP/2. */
39
+ isHTTP2: boolean;
40
+ /** ALPN protocol negotiated on the TLS socket (e.g. 'h2'), or null. */
41
+ alpnProtocol: string | null;
42
+ /** Parsed cookies (populated by cookieParser middleware). */
43
+ cookies: Record<string, string>;
44
+ /** Verified signed cookies (populated by cookieParser middleware). */
45
+ signedCookies?: Record<string, string>;
46
+ /** Request-scoped locals store. */
47
+ locals: Record<string, any>;
48
+ /** Request ID (populated by requestId middleware). */
49
+ id?: string;
50
+ /** Whether the request timed out (populated by timeout middleware). */
51
+ timedOut?: boolean;
52
+ /** The original URL as received — never rewritten by middleware. */
53
+ originalUrl: string;
54
+ /** The URL path on which the current router was mounted. */
55
+ baseUrl: string;
56
+ /** Reference to the parent App instance. */
57
+ app: App | null;
58
+ /** CSRF token (populated by csrf middleware). */
59
+ csrfToken?: string;
60
+ /** First signing secret (populated by cookieParser middleware). */
61
+ secret?: string;
62
+ /** All signing secrets (populated by cookieParser middleware). */
63
+ secrets?: string[];
64
+
65
+ /**
66
+ * Get a specific request header (case-insensitive).
67
+ */
68
+ get(name: string): string | undefined;
69
+
70
+ /**
71
+ * Check if the request Content-Type matches the given type.
72
+ */
73
+ is(type: string): boolean;
74
+
75
+ /**
76
+ * Get the hostname from the Host header.
77
+ */
78
+ readonly hostname: string;
79
+
80
+ /**
81
+ * Get the subdomains as an array.
82
+ */
83
+ subdomains(offset?: number): string[];
84
+
85
+ /**
86
+ * Content negotiation — check which types the client accepts.
87
+ */
88
+ accepts(...types: string[]): string | false;
89
+
90
+ /**
91
+ * Check if the request is "fresh" (client cache valid).
92
+ */
93
+ readonly fresh: boolean;
94
+
95
+ /**
96
+ * Inverse of `fresh`.
97
+ */
98
+ readonly stale: boolean;
99
+
100
+ /**
101
+ * Check whether this request was made with XMLHttpRequest.
102
+ */
103
+ readonly xhr: boolean;
104
+
105
+ /**
106
+ * Parse the Range header.
107
+ */
108
+ range(size: number): RangeResult | -1 | -2;
109
+ }
@@ -1,157 +1,157 @@
1
- import { ServerResponse } from 'http';
2
- import { App } from './app';
3
- import { SSEStream, SSEOptions } from './sse';
4
-
5
- export interface SendFileOptions {
6
- headers?: Record<string, string>;
7
- root?: string;
8
- }
9
-
10
- export interface CookieOptions {
11
- domain?: string;
12
- path?: string;
13
- expires?: Date | number;
14
- maxAge?: number;
15
- httpOnly?: boolean;
16
- secure?: boolean;
17
- sameSite?: 'Strict' | 'Lax' | 'None';
18
- /** Auto-sign the cookie value using req.secret. */
19
- signed?: boolean;
20
- /** Cookie priority: 'Low', 'Medium', or 'High'. */
21
- priority?: 'Low' | 'Medium' | 'High';
22
- /** Partitioned attribute (CHIPS). Requires secure: true. */
23
- partitioned?: boolean;
24
- }
25
-
26
- export interface PushOptions {
27
- /** Absolute path to a file to stream as the push body. */
28
- filePath?: string;
29
- /** Additional headers to include in the push promise. */
30
- headers?: Record<string, string>;
31
- }
32
-
33
- export interface Response {
34
- /** Original Node response. */
35
- raw: ServerResponse;
36
- /** Request-scoped locals store. */
37
- locals: Record<string, any>;
38
- /** Reference to the parent App instance. */
39
- app: App | null;
40
- /** Whether this response supports HTTP/2 server push. */
41
- readonly supportsPush: boolean;
42
-
43
- /**
44
- * Set HTTP status code. Chainable.
45
- */
46
- status(code: number): Response;
47
-
48
- /**
49
- * Set a response header. Chainable.
50
- */
51
- set(name: string, value: string): Response;
52
-
53
- /**
54
- * Get a previously-set response header.
55
- */
56
- get(name: string): string | undefined;
57
-
58
- /**
59
- * Append a value to a header.
60
- */
61
- append(name: string, value: string): Response;
62
-
63
- /**
64
- * Add a field to the Vary response header.
65
- */
66
- vary(field: string): Response;
67
-
68
- /**
69
- * Set the Content-Type header. Chainable.
70
- */
71
- type(ct: string): Response;
72
-
73
- /**
74
- * Whether headers have been sent.
75
- */
76
- readonly headersSent: boolean;
77
-
78
- /**
79
- * Send a response body and finalize.
80
- */
81
- send(body?: string | Buffer | object | null): void;
82
-
83
- /**
84
- * Send a JSON response.
85
- */
86
- json(obj: any): void;
87
-
88
- /**
89
- * Send a plain-text response.
90
- */
91
- text(str: string): void;
92
-
93
- /**
94
- * Send an HTML response.
95
- */
96
- html(str: string): void;
97
-
98
- /**
99
- * Send only the status code with reason phrase.
100
- */
101
- sendStatus(code: number): void;
102
-
103
- /**
104
- * Send a file as the response.
105
- */
106
- sendFile(filePath: string, opts?: SendFileOptions, cb?: (err: Error | null) => void): void;
107
- sendFile(filePath: string, cb?: (err: Error | null) => void): void;
108
-
109
- /**
110
- * Prompt a file download.
111
- */
112
- download(filePath: string, filename?: string, cb?: (err: Error | null) => void): void;
113
- download(filePath: string, cb?: (err: Error | null) => void): void;
114
-
115
- /**
116
- * Set a cookie. Objects are auto-serialized as JSON cookies (j: prefix).
117
- */
118
- cookie(name: string, value: string | object, opts?: CookieOptions): Response;
119
-
120
- /**
121
- * Clear a cookie.
122
- */
123
- clearCookie(name: string, opts?: CookieOptions): Response;
124
-
125
- /**
126
- * Redirect to a URL.
127
- */
128
- redirect(url: string): void;
129
- redirect(status: number, url: string): void;
130
-
131
- /**
132
- * Open a Server-Sent Events stream.
133
- */
134
- sse(opts?: SSEOptions): SSEStream;
135
-
136
- /**
137
- * Content-negotiated response based on Accept header.
138
- * Keys are MIME types, values are handler functions.
139
- */
140
- format(types: Record<string, () => void> & { default?: () => void }): void;
141
-
142
- /**
143
- * Set the Link header from a map of rel → URL.
144
- */
145
- links(links: Record<string, string>): Response;
146
-
147
- /**
148
- * Set the Location response header.
149
- */
150
- location(url: string): Response;
151
-
152
- /**
153
- * Initiate an HTTP/2 server push.
154
- * Returns null if the connection is not HTTP/2 or the stream is closed.
155
- */
156
- push(path: string, opts?: PushOptions): any;
157
- }
1
+ import { ServerResponse } from 'http';
2
+ import { App } from './app';
3
+ import { SSEStream, SSEOptions } from './sse';
4
+
5
+ export interface SendFileOptions {
6
+ headers?: Record<string, string>;
7
+ root?: string;
8
+ }
9
+
10
+ export interface CookieOptions {
11
+ domain?: string;
12
+ path?: string;
13
+ expires?: Date | number;
14
+ maxAge?: number;
15
+ httpOnly?: boolean;
16
+ secure?: boolean;
17
+ sameSite?: 'Strict' | 'Lax' | 'None';
18
+ /** Auto-sign the cookie value using req.secret. */
19
+ signed?: boolean;
20
+ /** Cookie priority: 'Low', 'Medium', or 'High'. */
21
+ priority?: 'Low' | 'Medium' | 'High';
22
+ /** Partitioned attribute (CHIPS). Requires secure: true. */
23
+ partitioned?: boolean;
24
+ }
25
+
26
+ export interface PushOptions {
27
+ /** Absolute path to a file to stream as the push body. */
28
+ filePath?: string;
29
+ /** Additional headers to include in the push promise. */
30
+ headers?: Record<string, string>;
31
+ }
32
+
33
+ export interface Response {
34
+ /** Original Node response. */
35
+ raw: ServerResponse;
36
+ /** Request-scoped locals store. */
37
+ locals: Record<string, any>;
38
+ /** Reference to the parent App instance. */
39
+ app: App | null;
40
+ /** Whether this response supports HTTP/2 server push. */
41
+ readonly supportsPush: boolean;
42
+
43
+ /**
44
+ * Set HTTP status code. Chainable.
45
+ */
46
+ status(code: number): Response;
47
+
48
+ /**
49
+ * Set a response header. Chainable.
50
+ */
51
+ set(name: string, value: string): Response;
52
+
53
+ /**
54
+ * Get a previously-set response header.
55
+ */
56
+ get(name: string): string | undefined;
57
+
58
+ /**
59
+ * Append a value to a header.
60
+ */
61
+ append(name: string, value: string): Response;
62
+
63
+ /**
64
+ * Add a field to the Vary response header.
65
+ */
66
+ vary(field: string): Response;
67
+
68
+ /**
69
+ * Set the Content-Type header. Chainable.
70
+ */
71
+ type(ct: string): Response;
72
+
73
+ /**
74
+ * Whether headers have been sent.
75
+ */
76
+ readonly headersSent: boolean;
77
+
78
+ /**
79
+ * Send a response body and finalize.
80
+ */
81
+ send(body?: string | Buffer | object | null): void;
82
+
83
+ /**
84
+ * Send a JSON response.
85
+ */
86
+ json(obj: any): void;
87
+
88
+ /**
89
+ * Send a plain-text response.
90
+ */
91
+ text(str: string): void;
92
+
93
+ /**
94
+ * Send an HTML response.
95
+ */
96
+ html(str: string): void;
97
+
98
+ /**
99
+ * Send only the status code with reason phrase.
100
+ */
101
+ sendStatus(code: number): void;
102
+
103
+ /**
104
+ * Send a file as the response.
105
+ */
106
+ sendFile(filePath: string, opts?: SendFileOptions, cb?: (err: Error | null) => void): void;
107
+ sendFile(filePath: string, cb?: (err: Error | null) => void): void;
108
+
109
+ /**
110
+ * Prompt a file download.
111
+ */
112
+ download(filePath: string, filename?: string, cb?: (err: Error | null) => void): void;
113
+ download(filePath: string, cb?: (err: Error | null) => void): void;
114
+
115
+ /**
116
+ * Set a cookie. Objects are auto-serialized as JSON cookies (j: prefix).
117
+ */
118
+ cookie(name: string, value: string | object, opts?: CookieOptions): Response;
119
+
120
+ /**
121
+ * Clear a cookie.
122
+ */
123
+ clearCookie(name: string, opts?: CookieOptions): Response;
124
+
125
+ /**
126
+ * Redirect to a URL.
127
+ */
128
+ redirect(url: string): void;
129
+ redirect(status: number, url: string): void;
130
+
131
+ /**
132
+ * Open a Server-Sent Events stream.
133
+ */
134
+ sse(opts?: SSEOptions): SSEStream;
135
+
136
+ /**
137
+ * Content-negotiated response based on Accept header.
138
+ * Keys are MIME types, values are handler functions.
139
+ */
140
+ format(types: Record<string, () => void> & { default?: () => void }): void;
141
+
142
+ /**
143
+ * Set the Link header from a map of rel → URL.
144
+ */
145
+ links(links: Record<string, string>): Response;
146
+
147
+ /**
148
+ * Set the Location response header.
149
+ */
150
+ location(url: string): Response;
151
+
152
+ /**
153
+ * Initiate an HTTP/2 server push.
154
+ * Returns null if the connection is not HTTP/2 or the stream is closed.
155
+ */
156
+ push(path: string, opts?: PushOptions): any;
157
+ }