@orpc/server 1.14.5 → 2.0.0-beta.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 +75 -136
- package/dist/adapters/crossws/index.d.mts +42 -21
- package/dist/adapters/crossws/index.d.ts +42 -21
- package/dist/adapters/crossws/index.mjs +37 -18
- package/dist/adapters/fetch/index.d.mts +83 -67
- package/dist/adapters/fetch/index.d.ts +83 -67
- package/dist/adapters/fetch/index.mjs +131 -106
- package/dist/adapters/message-port/index.d.mts +51 -34
- package/dist/adapters/message-port/index.d.ts +51 -34
- package/dist/adapters/message-port/index.mjs +73 -38
- package/dist/adapters/node/index.d.mts +82 -60
- package/dist/adapters/node/index.d.ts +82 -60
- package/dist/adapters/node/index.mjs +127 -98
- package/dist/adapters/standard/index.d.mts +16 -18
- package/dist/adapters/standard/index.d.ts +16 -18
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +12 -14
- package/dist/adapters/standard-peer/index.d.ts +12 -14
- package/dist/adapters/standard-peer/index.mjs +2 -21
- package/dist/adapters/websocket/index.d.mts +39 -34
- package/dist/adapters/websocket/index.d.ts +39 -34
- package/dist/adapters/websocket/index.mjs +42 -33
- package/dist/extensions/callable.d.mts +10 -0
- package/dist/extensions/callable.d.ts +10 -0
- package/dist/extensions/callable.mjs +11 -0
- package/dist/helpers/index.d.mts +2 -2
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/index.mjs +1 -1
- package/dist/index.d.mts +163 -770
- package/dist/index.d.ts +163 -770
- package/dist/index.mjs +296 -403
- package/dist/plugins/index.d.mts +105 -143
- package/dist/plugins/index.d.ts +105 -143
- package/dist/plugins/index.mjs +232 -255
- package/dist/shared/server.BB_Ik9Ph.d.mts +104 -0
- package/dist/shared/server.BL22TloH.d.mts +184 -0
- package/dist/shared/server.BL22TloH.d.ts +184 -0
- package/dist/shared/server.B_U9y00a.d.mts +66 -0
- package/dist/shared/server.BsNNjG5J.d.mts +61 -0
- package/dist/shared/server.BwHnWUuN.mjs +222 -0
- package/dist/shared/server.CX4vUnDk.mjs +11 -0
- package/dist/shared/server.CjOb6ItT.mjs +41 -0
- package/dist/shared/server.CrlKQucM.mjs +233 -0
- package/dist/shared/server.D_QauotT.mjs +30 -0
- package/dist/shared/server.EOHJ3NJr.d.ts +104 -0
- package/dist/shared/server.GDpX6Df8.mjs +271 -0
- package/dist/shared/server.Pa0F03f_.d.ts +61 -0
- package/dist/shared/server.T9F3bzZx.d.ts +66 -0
- package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
- package/package.json +26 -55
- package/dist/adapters/aws-lambda/index.d.mts +0 -46
- package/dist/adapters/aws-lambda/index.d.ts +0 -46
- package/dist/adapters/aws-lambda/index.mjs +0 -40
- package/dist/adapters/bun-ws/index.d.mts +0 -36
- package/dist/adapters/bun-ws/index.d.ts +0 -36
- package/dist/adapters/bun-ws/index.mjs +0 -47
- package/dist/adapters/fastify/index.d.mts +0 -53
- package/dist/adapters/fastify/index.d.ts +0 -53
- package/dist/adapters/fastify/index.mjs +0 -52
- package/dist/adapters/ws/index.d.mts +0 -31
- package/dist/adapters/ws/index.d.ts +0 -31
- package/dist/adapters/ws/index.mjs +0 -37
- package/dist/hibernation/index.d.mts +0 -44
- package/dist/hibernation/index.d.ts +0 -44
- package/dist/hibernation/index.mjs +0 -65
- package/dist/shared/server.7cEtMB30.d.ts +0 -74
- package/dist/shared/server.B8gYOD5g.d.mts +0 -12
- package/dist/shared/server.BqadksTP.d.mts +0 -74
- package/dist/shared/server.C8_sRzQB.d.mts +0 -42
- package/dist/shared/server.ChUyt5-i.d.mts +0 -32
- package/dist/shared/server.ChyoA9XY.d.ts +0 -42
- package/dist/shared/server.DEBcqOjg.mjs +0 -418
- package/dist/shared/server.EfTOZ2Q7.d.ts +0 -12
- package/dist/shared/server.TEVCLCFC.mjs +0 -39
- package/dist/shared/server.ZxHCEN1h.mjs +0 -226
- package/dist/shared/server.qKsRrdxW.d.mts +0 -193
- package/dist/shared/server.qKsRrdxW.d.ts +0 -193
- package/dist/shared/server.yoEB3Fx4.d.ts +0 -32
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,204 +1,166 @@
|
|
|
1
|
-
import { Value, Promisable
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { ORPCError } from '@orpc/client';
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardLazyRequest, StandardHeaders } from '@standardserver/core';
|
|
3
|
+
import { C as Context } from '../shared/server.BL22TloH.mjs';
|
|
4
|
+
import { e as StandardHandlerPlugin, f as StandardHandlerRoutingInterceptorOptions, a as StandardHandlerOptions } from '../shared/server.BB_Ik9Ph.mjs';
|
|
5
|
+
import '@orpc/client';
|
|
6
|
+
import '@orpc/contract';
|
|
8
7
|
|
|
9
|
-
interface
|
|
8
|
+
interface BatchHandlerPluginOptions<T extends Context> {
|
|
10
9
|
/**
|
|
11
10
|
* The max size of the batch allowed.
|
|
12
11
|
*
|
|
13
12
|
* @default 10
|
|
14
13
|
*/
|
|
15
|
-
maxSize?: Value<Promisable<number>, [
|
|
14
|
+
maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
16
15
|
/**
|
|
17
|
-
* Map the
|
|
16
|
+
* Map each subrequest in the batch before it is processed.
|
|
18
17
|
*
|
|
19
|
-
* @default
|
|
18
|
+
* @default merges the batch request headers into the subrequest and remove `orpc-batch` header to prevent nested batching
|
|
20
19
|
*/
|
|
21
|
-
|
|
20
|
+
mapSubrequest?: (subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest;
|
|
22
21
|
/**
|
|
23
22
|
* Success batch response status code.
|
|
24
23
|
*
|
|
25
24
|
* @default 207
|
|
26
25
|
*/
|
|
27
|
-
successStatus?: Value<Promisable<number>, [
|
|
26
|
+
successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
28
27
|
/**
|
|
29
|
-
*
|
|
28
|
+
* Success batch response headers.
|
|
30
29
|
*
|
|
31
30
|
* @default {}
|
|
32
31
|
*/
|
|
33
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
32
|
+
headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
34
33
|
}
|
|
35
|
-
/**
|
|
36
|
-
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
37
|
-
* reducing the overhead of sending each one separately.
|
|
38
|
-
*
|
|
39
|
-
* @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
40
|
-
*/
|
|
41
34
|
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* Run batch interceptors before OpenTelemetry interceptors
|
|
38
|
+
* so each subrequest gets its own span instead of sharing one batch-level span.
|
|
39
|
+
*/
|
|
40
|
+
after: string[];
|
|
42
41
|
private readonly maxSize;
|
|
43
|
-
private readonly
|
|
42
|
+
private readonly mapSubrequest;
|
|
44
43
|
private readonly successStatus;
|
|
45
44
|
private readonly headers;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
45
|
+
constructor(options?: BatchHandlerPluginOptions<T>);
|
|
46
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
interface
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
interface CORSHandlerPluginOptions<T extends Context> {
|
|
50
|
+
/**
|
|
51
|
+
* Configures the `Access-Control-Allow-Origin` header.
|
|
52
|
+
* Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
|
|
53
|
+
*
|
|
54
|
+
* @default (origin) => origin
|
|
55
|
+
*/
|
|
56
|
+
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
57
|
+
/**
|
|
58
|
+
* Configures the `Timing-Allow-Origin` header.
|
|
59
|
+
* Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
|
|
60
|
+
*
|
|
61
|
+
* @default undefined
|
|
62
|
+
*/
|
|
63
|
+
timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
64
|
+
/**
|
|
65
|
+
* Configures the `Access-Control-Allow-Methods` header for preflight requests.
|
|
66
|
+
*
|
|
67
|
+
* @default ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']
|
|
68
|
+
*/
|
|
54
69
|
allowMethods?: readonly string[];
|
|
70
|
+
/**
|
|
71
|
+
* Configures the `Access-Control-Allow-Headers` header for preflight requests.
|
|
72
|
+
* Falls back to the request's `Access-Control-Request-Headers` if not set.
|
|
73
|
+
*
|
|
74
|
+
* @default undefined
|
|
75
|
+
*/
|
|
55
76
|
allowHeaders?: readonly string[];
|
|
77
|
+
/**
|
|
78
|
+
* Configures the `Access-Control-Max-Age` header (in seconds) for preflight requests.
|
|
79
|
+
*
|
|
80
|
+
* @default undefined
|
|
81
|
+
*/
|
|
56
82
|
maxAge?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Configures the `Access-Control-Allow-Credentials` header.
|
|
85
|
+
*
|
|
86
|
+
* @default undefined
|
|
87
|
+
*/
|
|
57
88
|
credentials?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Configures the `Access-Control-Expose-Headers` header.
|
|
91
|
+
*
|
|
92
|
+
* @default undefined
|
|
93
|
+
*/
|
|
58
94
|
exposeHeaders?: readonly string[];
|
|
59
95
|
}
|
|
60
96
|
/**
|
|
61
|
-
*
|
|
97
|
+
* CORSHandlerPlugin is a plugin for oRPC that allows you to configure CORS for your API.
|
|
62
98
|
*
|
|
63
99
|
* @see {@link https://orpc.dev/docs/plugins/cors CORS Plugin Docs}
|
|
64
100
|
*/
|
|
65
|
-
declare class
|
|
101
|
+
declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
66
102
|
private readonly options;
|
|
67
|
-
|
|
68
|
-
constructor(options?: CORSOptions<T>);
|
|
69
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
interface RequestHeadersPluginContext {
|
|
73
|
-
reqHeaders?: Headers;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
77
|
-
* allowing access to request headers in oRPC.
|
|
78
|
-
*
|
|
79
|
-
* @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
80
|
-
*/
|
|
81
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
82
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
interface ResponseHeadersPluginContext {
|
|
86
|
-
resHeaders?: Headers;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
90
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
91
|
-
*
|
|
92
|
-
* @see {@link https://orpc.dev/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
93
|
-
*/
|
|
94
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
95
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
interface experimental_RethrowHandlerPluginOptions<T extends Context> {
|
|
103
|
+
name: string;
|
|
99
104
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* return !(error instanceof ORPCError)
|
|
108
|
-
* }
|
|
109
|
-
* })
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
filter: Value<boolean, [error: ThrowableError, options: StandardHandlerInterceptorOptions<T>]>;
|
|
105
|
+
* - Do not create spans for CORS preflight requests.
|
|
106
|
+
* - Run CORS interceptors before batch interceptors so headers are applied to
|
|
107
|
+
* the actual response rather than sub-responses.
|
|
108
|
+
*/
|
|
109
|
+
after: string[];
|
|
110
|
+
constructor(options?: CORSHandlerPluginOptions<T>);
|
|
111
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
113
112
|
}
|
|
113
|
+
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* (
|
|
118
|
-
* and you want certain errors to be processed by that mechanism instead of being handled by the
|
|
119
|
-
* oRPC error handling flow.
|
|
115
|
+
* Adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
|
116
|
+
* When a request includes cookies, it helps ensure the request originates from JavaScript
|
|
117
|
+
* (for example, fetch/XHR) rather than from standard HTML forms or direct browser navigation.
|
|
120
118
|
*
|
|
121
|
-
* @
|
|
119
|
+
* @info This plugin is enabled by default for `RPCHandler` over HTTP.
|
|
122
120
|
*/
|
|
123
|
-
declare class
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
constructor(options: experimental_RethrowHandlerPluginOptions<T>);
|
|
127
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
121
|
+
declare class CSRFGuardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
122
|
+
name: string;
|
|
123
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
128
124
|
}
|
|
129
125
|
|
|
130
|
-
interface
|
|
131
|
-
/**
|
|
132
|
-
* The name of the header to check.
|
|
133
|
-
*
|
|
134
|
-
* @default 'x-csrf-token'
|
|
135
|
-
*/
|
|
136
|
-
headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
|
126
|
+
interface RequestHeadersHandlerPluginContext {
|
|
137
127
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @default 'orpc'
|
|
141
|
-
*
|
|
128
|
+
* Request headers as a Headers instance. This is injected by the Request Headers Plugin.
|
|
142
129
|
*/
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Exclude a procedure from the plugin.
|
|
146
|
-
*
|
|
147
|
-
* @default false
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
|
|
151
|
-
/**
|
|
152
|
-
* The error thrown when the CSRF token is invalid.
|
|
153
|
-
*
|
|
154
|
-
* @default new ORPCError('CSRF_TOKEN_MISMATCH', {
|
|
155
|
-
* status: 403,
|
|
156
|
-
* message: 'Invalid CSRF token',
|
|
157
|
-
* })
|
|
158
|
-
*/
|
|
159
|
-
error?: InstanceType<typeof ORPCError>;
|
|
130
|
+
reqHeaders?: Headers | undefined;
|
|
160
131
|
}
|
|
161
132
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* not from other sources like standard HTML forms or direct browser navigation.
|
|
133
|
+
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
134
|
+
* allowing access to request headers in oRPC.
|
|
165
135
|
*
|
|
166
|
-
* @see {@link https://orpc.dev/docs/plugins/
|
|
136
|
+
* @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
167
137
|
*/
|
|
168
|
-
declare class
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
private readonly exclude;
|
|
172
|
-
private readonly error;
|
|
173
|
-
constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
|
|
174
|
-
order: number;
|
|
175
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
138
|
+
declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
|
|
139
|
+
name: string;
|
|
140
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
176
141
|
}
|
|
177
142
|
|
|
178
|
-
interface
|
|
143
|
+
interface ResponseHeadersHandlerPluginContext {
|
|
179
144
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @default new ORPCError('METHOD_NOT_SUPPORTED')
|
|
145
|
+
* Response headers as a Headers instance. This is injected by the Response Headers Plugin.
|
|
146
|
+
* When set before the response is sent, these headers will be included in the response. If not set, no additional headers will be added.
|
|
183
147
|
*/
|
|
184
|
-
|
|
148
|
+
resHeaders?: Headers | undefined;
|
|
185
149
|
}
|
|
186
150
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* Cross-Site Request Forgery (CSRF) attacks.
|
|
151
|
+
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
152
|
+
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
190
153
|
*
|
|
191
|
-
* @see {@link https://orpc.dev/docs/plugins/
|
|
154
|
+
* @see {@link https://orpc.dev/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
192
155
|
*/
|
|
193
|
-
declare class
|
|
194
|
-
|
|
156
|
+
declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
|
|
157
|
+
name: string;
|
|
195
158
|
/**
|
|
196
|
-
*
|
|
159
|
+
* Interceptors should run after batch interceptors so headers are applied to each sub-response.
|
|
197
160
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
161
|
+
before: string[];
|
|
162
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
201
163
|
}
|
|
202
164
|
|
|
203
|
-
export { BatchHandlerPlugin,
|
|
204
|
-
export type {
|
|
165
|
+
export { BatchHandlerPlugin, CORSHandlerPlugin, CSRFGuardHandlerPlugin, RequestHeadersHandlerPlugin, ResponseHeadersHandlerPlugin };
|
|
166
|
+
export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,204 +1,166 @@
|
|
|
1
|
-
import { Value, Promisable
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { ORPCError } from '@orpc/client';
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardLazyRequest, StandardHeaders } from '@standardserver/core';
|
|
3
|
+
import { C as Context } from '../shared/server.BL22TloH.js';
|
|
4
|
+
import { e as StandardHandlerPlugin, f as StandardHandlerRoutingInterceptorOptions, a as StandardHandlerOptions } from '../shared/server.EOHJ3NJr.js';
|
|
5
|
+
import '@orpc/client';
|
|
6
|
+
import '@orpc/contract';
|
|
8
7
|
|
|
9
|
-
interface
|
|
8
|
+
interface BatchHandlerPluginOptions<T extends Context> {
|
|
10
9
|
/**
|
|
11
10
|
* The max size of the batch allowed.
|
|
12
11
|
*
|
|
13
12
|
* @default 10
|
|
14
13
|
*/
|
|
15
|
-
maxSize?: Value<Promisable<number>, [
|
|
14
|
+
maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
16
15
|
/**
|
|
17
|
-
* Map the
|
|
16
|
+
* Map each subrequest in the batch before it is processed.
|
|
18
17
|
*
|
|
19
|
-
* @default
|
|
18
|
+
* @default merges the batch request headers into the subrequest and remove `orpc-batch` header to prevent nested batching
|
|
20
19
|
*/
|
|
21
|
-
|
|
20
|
+
mapSubrequest?: (subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest;
|
|
22
21
|
/**
|
|
23
22
|
* Success batch response status code.
|
|
24
23
|
*
|
|
25
24
|
* @default 207
|
|
26
25
|
*/
|
|
27
|
-
successStatus?: Value<Promisable<number>, [
|
|
26
|
+
successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
28
27
|
/**
|
|
29
|
-
*
|
|
28
|
+
* Success batch response headers.
|
|
30
29
|
*
|
|
31
30
|
* @default {}
|
|
32
31
|
*/
|
|
33
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
32
|
+
headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
34
33
|
}
|
|
35
|
-
/**
|
|
36
|
-
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
37
|
-
* reducing the overhead of sending each one separately.
|
|
38
|
-
*
|
|
39
|
-
* @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
40
|
-
*/
|
|
41
34
|
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* Run batch interceptors before OpenTelemetry interceptors
|
|
38
|
+
* so each subrequest gets its own span instead of sharing one batch-level span.
|
|
39
|
+
*/
|
|
40
|
+
after: string[];
|
|
42
41
|
private readonly maxSize;
|
|
43
|
-
private readonly
|
|
42
|
+
private readonly mapSubrequest;
|
|
44
43
|
private readonly successStatus;
|
|
45
44
|
private readonly headers;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
45
|
+
constructor(options?: BatchHandlerPluginOptions<T>);
|
|
46
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
interface
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
interface CORSHandlerPluginOptions<T extends Context> {
|
|
50
|
+
/**
|
|
51
|
+
* Configures the `Access-Control-Allow-Origin` header.
|
|
52
|
+
* Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
|
|
53
|
+
*
|
|
54
|
+
* @default (origin) => origin
|
|
55
|
+
*/
|
|
56
|
+
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
57
|
+
/**
|
|
58
|
+
* Configures the `Timing-Allow-Origin` header.
|
|
59
|
+
* Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
|
|
60
|
+
*
|
|
61
|
+
* @default undefined
|
|
62
|
+
*/
|
|
63
|
+
timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]>;
|
|
64
|
+
/**
|
|
65
|
+
* Configures the `Access-Control-Allow-Methods` header for preflight requests.
|
|
66
|
+
*
|
|
67
|
+
* @default ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']
|
|
68
|
+
*/
|
|
54
69
|
allowMethods?: readonly string[];
|
|
70
|
+
/**
|
|
71
|
+
* Configures the `Access-Control-Allow-Headers` header for preflight requests.
|
|
72
|
+
* Falls back to the request's `Access-Control-Request-Headers` if not set.
|
|
73
|
+
*
|
|
74
|
+
* @default undefined
|
|
75
|
+
*/
|
|
55
76
|
allowHeaders?: readonly string[];
|
|
77
|
+
/**
|
|
78
|
+
* Configures the `Access-Control-Max-Age` header (in seconds) for preflight requests.
|
|
79
|
+
*
|
|
80
|
+
* @default undefined
|
|
81
|
+
*/
|
|
56
82
|
maxAge?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Configures the `Access-Control-Allow-Credentials` header.
|
|
85
|
+
*
|
|
86
|
+
* @default undefined
|
|
87
|
+
*/
|
|
57
88
|
credentials?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Configures the `Access-Control-Expose-Headers` header.
|
|
91
|
+
*
|
|
92
|
+
* @default undefined
|
|
93
|
+
*/
|
|
58
94
|
exposeHeaders?: readonly string[];
|
|
59
95
|
}
|
|
60
96
|
/**
|
|
61
|
-
*
|
|
97
|
+
* CORSHandlerPlugin is a plugin for oRPC that allows you to configure CORS for your API.
|
|
62
98
|
*
|
|
63
99
|
* @see {@link https://orpc.dev/docs/plugins/cors CORS Plugin Docs}
|
|
64
100
|
*/
|
|
65
|
-
declare class
|
|
101
|
+
declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
66
102
|
private readonly options;
|
|
67
|
-
|
|
68
|
-
constructor(options?: CORSOptions<T>);
|
|
69
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
interface RequestHeadersPluginContext {
|
|
73
|
-
reqHeaders?: Headers;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
77
|
-
* allowing access to request headers in oRPC.
|
|
78
|
-
*
|
|
79
|
-
* @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
80
|
-
*/
|
|
81
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
82
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
interface ResponseHeadersPluginContext {
|
|
86
|
-
resHeaders?: Headers;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
90
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
91
|
-
*
|
|
92
|
-
* @see {@link https://orpc.dev/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
93
|
-
*/
|
|
94
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
95
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
interface experimental_RethrowHandlerPluginOptions<T extends Context> {
|
|
103
|
+
name: string;
|
|
99
104
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* return !(error instanceof ORPCError)
|
|
108
|
-
* }
|
|
109
|
-
* })
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
filter: Value<boolean, [error: ThrowableError, options: StandardHandlerInterceptorOptions<T>]>;
|
|
105
|
+
* - Do not create spans for CORS preflight requests.
|
|
106
|
+
* - Run CORS interceptors before batch interceptors so headers are applied to
|
|
107
|
+
* the actual response rather than sub-responses.
|
|
108
|
+
*/
|
|
109
|
+
after: string[];
|
|
110
|
+
constructor(options?: CORSHandlerPluginOptions<T>);
|
|
111
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
113
112
|
}
|
|
113
|
+
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* (
|
|
118
|
-
* and you want certain errors to be processed by that mechanism instead of being handled by the
|
|
119
|
-
* oRPC error handling flow.
|
|
115
|
+
* Adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
|
116
|
+
* When a request includes cookies, it helps ensure the request originates from JavaScript
|
|
117
|
+
* (for example, fetch/XHR) rather than from standard HTML forms or direct browser navigation.
|
|
120
118
|
*
|
|
121
|
-
* @
|
|
119
|
+
* @info This plugin is enabled by default for `RPCHandler` over HTTP.
|
|
122
120
|
*/
|
|
123
|
-
declare class
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
constructor(options: experimental_RethrowHandlerPluginOptions<T>);
|
|
127
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
121
|
+
declare class CSRFGuardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
122
|
+
name: string;
|
|
123
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
128
124
|
}
|
|
129
125
|
|
|
130
|
-
interface
|
|
131
|
-
/**
|
|
132
|
-
* The name of the header to check.
|
|
133
|
-
*
|
|
134
|
-
* @default 'x-csrf-token'
|
|
135
|
-
*/
|
|
136
|
-
headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
|
126
|
+
interface RequestHeadersHandlerPluginContext {
|
|
137
127
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @default 'orpc'
|
|
141
|
-
*
|
|
128
|
+
* Request headers as a Headers instance. This is injected by the Request Headers Plugin.
|
|
142
129
|
*/
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Exclude a procedure from the plugin.
|
|
146
|
-
*
|
|
147
|
-
* @default false
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
|
|
151
|
-
/**
|
|
152
|
-
* The error thrown when the CSRF token is invalid.
|
|
153
|
-
*
|
|
154
|
-
* @default new ORPCError('CSRF_TOKEN_MISMATCH', {
|
|
155
|
-
* status: 403,
|
|
156
|
-
* message: 'Invalid CSRF token',
|
|
157
|
-
* })
|
|
158
|
-
*/
|
|
159
|
-
error?: InstanceType<typeof ORPCError>;
|
|
130
|
+
reqHeaders?: Headers | undefined;
|
|
160
131
|
}
|
|
161
132
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* not from other sources like standard HTML forms or direct browser navigation.
|
|
133
|
+
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
134
|
+
* allowing access to request headers in oRPC.
|
|
165
135
|
*
|
|
166
|
-
* @see {@link https://orpc.dev/docs/plugins/
|
|
136
|
+
* @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
167
137
|
*/
|
|
168
|
-
declare class
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
private readonly exclude;
|
|
172
|
-
private readonly error;
|
|
173
|
-
constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
|
|
174
|
-
order: number;
|
|
175
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
138
|
+
declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
|
|
139
|
+
name: string;
|
|
140
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
176
141
|
}
|
|
177
142
|
|
|
178
|
-
interface
|
|
143
|
+
interface ResponseHeadersHandlerPluginContext {
|
|
179
144
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @default new ORPCError('METHOD_NOT_SUPPORTED')
|
|
145
|
+
* Response headers as a Headers instance. This is injected by the Response Headers Plugin.
|
|
146
|
+
* When set before the response is sent, these headers will be included in the response. If not set, no additional headers will be added.
|
|
183
147
|
*/
|
|
184
|
-
|
|
148
|
+
resHeaders?: Headers | undefined;
|
|
185
149
|
}
|
|
186
150
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* Cross-Site Request Forgery (CSRF) attacks.
|
|
151
|
+
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
152
|
+
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
190
153
|
*
|
|
191
|
-
* @see {@link https://orpc.dev/docs/plugins/
|
|
154
|
+
* @see {@link https://orpc.dev/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
192
155
|
*/
|
|
193
|
-
declare class
|
|
194
|
-
|
|
156
|
+
declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
|
|
157
|
+
name: string;
|
|
195
158
|
/**
|
|
196
|
-
*
|
|
159
|
+
* Interceptors should run after batch interceptors so headers are applied to each sub-response.
|
|
197
160
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
161
|
+
before: string[];
|
|
162
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
201
163
|
}
|
|
202
164
|
|
|
203
|
-
export { BatchHandlerPlugin,
|
|
204
|
-
export type {
|
|
165
|
+
export { BatchHandlerPlugin, CORSHandlerPlugin, CSRFGuardHandlerPlugin, RequestHeadersHandlerPlugin, ResponseHeadersHandlerPlugin };
|
|
166
|
+
export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext };
|