@orpc/server 2.0.0-beta.46 → 2.0.0-beta.48
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 +6 -4
- package/dist/adapters/aws-lambda/handler.d.mts +25 -0
- package/dist/adapters/aws-lambda/handler.mjs +21 -0
- package/dist/adapters/aws-lambda/index.d.mts +14 -49
- package/dist/adapters/aws-lambda/index.mjs +2 -39
- package/dist/adapters/aws-lambda/rpc-handler.d.mts +18 -0
- package/dist/adapters/aws-lambda/rpc-handler.mjs +10 -0
- package/dist/adapters/crossws/handler.d.mts +41 -0
- package/dist/adapters/crossws/handler.mjs +38 -0
- package/dist/adapters/crossws/index.d.mts +2 -63
- package/dist/adapters/crossws/index.mjs +2 -68
- package/dist/adapters/crossws/rpc-handler.d.mts +15 -0
- package/dist/adapters/crossws/rpc-handler.mjs +10 -0
- package/dist/adapters/fastify/handler.d.mts +21 -0
- package/dist/adapters/fastify/handler.mjs +20 -0
- package/dist/adapters/fastify/index.d.mts +2 -42
- package/dist/adapters/fastify/index.mjs +2 -39
- package/dist/adapters/fastify/rpc-handler.d.mts +14 -0
- package/dist/adapters/fastify/rpc-handler.mjs +10 -0
- package/dist/adapters/fetch/handler.d.mts +23 -0
- package/dist/adapters/fetch/handler.mjs +22 -0
- package/dist/adapters/fetch/index.d.mts +6 -46
- package/dist/adapters/fetch/index.mjs +4 -41
- package/dist/adapters/fetch/rpc-handler.d.mts +16 -0
- package/dist/adapters/fetch/rpc-handler.mjs +10 -0
- package/dist/adapters/message-port/handler.d.mts +57 -0
- package/dist/adapters/message-port/handler.mjs +62 -0
- package/dist/adapters/message-port/index.d.mts +2 -77
- package/dist/adapters/message-port/index.mjs +2 -87
- package/dist/adapters/message-port/rpc-handler.d.mts +15 -0
- package/dist/adapters/message-port/rpc-handler.mjs +10 -0
- package/dist/adapters/node/handler.d.mts +21 -0
- package/dist/adapters/node/handler.mjs +20 -0
- package/dist/adapters/node/index.d.mts +6 -43
- package/dist/adapters/node/index.mjs +4 -40
- package/dist/adapters/node/rpc-handler.d.mts +15 -0
- package/dist/adapters/node/rpc-handler.mjs +10 -0
- package/dist/adapters/standard/codec.d.mts +16 -0
- package/dist/adapters/standard/codec.mjs +1 -0
- package/dist/adapters/standard/handler.d.mts +68 -0
- package/dist/adapters/standard/handler.mjs +185 -0
- package/dist/adapters/standard/index.d.mts +6 -95
- package/dist/adapters/standard/index.mjs +5 -8
- package/dist/adapters/standard/plugin.d.mts +32 -0
- package/dist/adapters/standard/plugin.mjs +16 -0
- package/dist/adapters/standard/rpc-handler-codec.d.mts +42 -0
- package/dist/adapters/standard/rpc-handler-codec.mjs +51 -0
- package/dist/adapters/standard/rpc-matcher.d.mts +53 -0
- package/dist/adapters/standard/rpc-matcher.mjs +140 -0
- package/dist/adapters/standard/utils.d.mts +10 -0
- package/dist/adapters/standard/utils.mjs +6 -0
- package/dist/adapters/standard-peer/index.d.mts +1 -11
- package/dist/adapters/standard-peer/index.mjs +1 -10
- package/dist/adapters/standard-peer/utils.d.mts +4 -0
- package/dist/adapters/standard-peer/utils.mjs +11 -0
- package/dist/adapters/websocket/handler.d.mts +55 -0
- package/dist/adapters/websocket/handler.mjs +55 -0
- package/dist/adapters/websocket/index.d.mts +2 -77
- package/dist/adapters/websocket/index.mjs +2 -87
- package/dist/adapters/websocket/rpc-handler.d.mts +15 -0
- package/dist/adapters/websocket/rpc-handler.mjs +10 -0
- package/dist/builder-variants.d.mts +267 -0
- package/dist/builder-variants.mjs +1 -0
- package/dist/builder.d.mts +141 -0
- package/dist/builder.mjs +145 -0
- package/dist/constants.d.mts +2 -0
- package/dist/constants.mjs +2 -0
- package/dist/context.d.mts +13 -0
- package/dist/context.mjs +1 -0
- package/dist/extensions/callable.d.mts +16 -9
- package/dist/extensions/callable.mjs +5 -9
- package/dist/helpers/base64url.d.mts +31 -0
- package/dist/helpers/base64url.mjs +25 -0
- package/dist/helpers/cookie.d.mts +50 -0
- package/dist/helpers/cookie.mjs +35 -0
- package/dist/helpers/encryption.d.mts +28 -0
- package/dist/helpers/encryption.mjs +62 -0
- package/dist/helpers/index.d.mts +4 -167
- package/dist/helpers/index.mjs +4 -200
- package/dist/helpers/signing.d.mts +50 -0
- package/dist/helpers/signing.mjs +43 -0
- package/dist/implementer-procedure.d.mts +36 -0
- package/dist/implementer-procedure.mjs +38 -0
- package/dist/implementer-router.d.mts +78 -0
- package/dist/implementer-router.mjs +77 -0
- package/dist/implementer.d.mts +22 -0
- package/dist/implementer.mjs +30 -0
- package/dist/index.d.mts +57 -476
- package/dist/index.mjs +25 -458
- package/dist/lazy.d.mts +20 -0
- package/dist/lazy.mjs +22 -0
- package/dist/middleware-decorated.d.mts +27 -0
- package/dist/middleware-decorated.mjs +65 -0
- package/dist/middleware.d.mts +70 -0
- package/dist/middleware.mjs +1 -0
- package/dist/plugins/batch.d.mts +104 -0
- package/dist/plugins/batch.mjs +373 -0
- package/dist/plugins/cors.d.mts +67 -0
- package/dist/plugins/cors.mjs +134 -0
- package/dist/plugins/get-method-csrf-protection.d.mts +23 -0
- package/dist/plugins/get-method-csrf-protection.mjs +45 -0
- package/dist/plugins/head-method.d.mts +23 -0
- package/dist/plugins/head-method.mjs +95 -0
- package/dist/plugins/index.d.mts +39 -432
- package/dist/plugins/index.mjs +23 -967
- package/dist/plugins/method-override.d.mts +38 -0
- package/dist/plugins/method-override.mjs +50 -0
- package/dist/plugins/request-compression.d.mts +16 -0
- package/dist/plugins/request-compression.mjs +67 -0
- package/dist/plugins/request-headers.d.mts +22 -0
- package/dist/plugins/request-headers.mjs +21 -0
- package/dist/plugins/request-limit.d.mts +30 -0
- package/dist/plugins/request-limit.mjs +53 -0
- package/dist/plugins/response-compression.d.mts +59 -0
- package/dist/plugins/response-compression.mjs +172 -0
- package/dist/plugins/response-headers.d.mts +30 -0
- package/dist/plugins/response-headers.mjs +34 -0
- package/dist/plugins/rethrow.d.mts +33 -0
- package/dist/plugins/rethrow.mjs +46 -0
- package/dist/plugins/signal-sync.d.mts +13 -0
- package/dist/plugins/signal-sync.mjs +84 -0
- package/dist/plugins/timeout.d.mts +37 -0
- package/dist/plugins/timeout.mjs +56 -0
- package/dist/procedure-client.d.mts +41 -0
- package/dist/procedure-client.mjs +157 -0
- package/dist/procedure-decorated.d.mts +20 -0
- package/dist/procedure-decorated.mjs +41 -0
- package/dist/procedure-utils.d.mts +52 -0
- package/dist/procedure-utils.mjs +33 -0
- package/dist/procedure.d.mts +93 -0
- package/dist/procedure.mjs +20 -0
- package/dist/router-client.d.mts +27 -0
- package/dist/router-client.mjs +35 -0
- package/dist/router-hidden.d.mts +5 -0
- package/dist/router-hidden.mjs +12 -0
- package/dist/router-utils.d.mts +59 -0
- package/dist/router-utils.mjs +191 -0
- package/dist/router.d.mts +61 -0
- package/dist/router.mjs +1 -0
- package/package.json +11 -11
- package/dist/adapters/aws-lambda/index.d.ts +0 -51
- package/dist/adapters/crossws/index.d.ts +0 -63
- package/dist/adapters/fastify/index.d.ts +0 -42
- package/dist/adapters/fetch/index.d.ts +0 -47
- package/dist/adapters/message-port/index.d.ts +0 -77
- package/dist/adapters/node/index.d.ts +0 -44
- package/dist/adapters/standard/index.d.ts +0 -95
- package/dist/adapters/standard-peer/index.d.ts +0 -11
- package/dist/adapters/websocket/index.d.ts +0 -77
- package/dist/extensions/callable.d.ts +0 -10
- package/dist/helpers/index.d.ts +0 -167
- package/dist/index.d.ts +0 -476
- package/dist/plugins/index.d.ts +0 -432
- package/dist/shared/server.1ExWFMze.mjs +0 -69
- package/dist/shared/server.9B1jEm5a.d.mts +0 -105
- package/dist/shared/server.BB464y-6.mjs +0 -207
- package/dist/shared/server.BC5BIu02.d.mts +0 -73
- package/dist/shared/server.BSYGskId.d.ts +0 -14
- package/dist/shared/server.BvG3boBj.d.mts +0 -14
- package/dist/shared/server.CTV_mC2P.d.mts +0 -34
- package/dist/shared/server.CYbIpHbH.mjs +0 -239
- package/dist/shared/server.CgBF3Vj1.d.ts +0 -34
- package/dist/shared/server.Chq5FpXf.mjs +0 -353
- package/dist/shared/server.DFPxP2v3.d.mts +0 -166
- package/dist/shared/server.DFPxP2v3.d.ts +0 -166
- package/dist/shared/server.DOg7ke6y.d.ts +0 -105
- package/dist/shared/server.Dz7j9BEh.d.ts +0 -73
- package/dist/shared/server.W91HSRkE.mjs +0 -9
- package/dist/shared/server.sBQSgqK3.mjs +0 -41
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ORPCError } from "@orpc/client";
|
|
2
|
+
import { toArray } from "@orpc/shared";
|
|
3
|
+
import { flattenStandardHeader } from "@standard-server/core";
|
|
4
|
+
|
|
5
|
+
export class GetMethodCsrfProtectionHandlerPlugin {
|
|
6
|
+
name = "~get-method-csrf-protection";
|
|
7
|
+
init(options) {
|
|
8
|
+
|
|
9
|
+
const interceptor = (interceptorOptions) => {
|
|
10
|
+
if (this.isAllowed(interceptorOptions)) {
|
|
11
|
+
return interceptorOptions.next();
|
|
12
|
+
}
|
|
13
|
+
throw new ORPCError("FORBIDDEN", { message: "Request blocked by CSRF protection." });
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
...options,
|
|
17
|
+
interceptors: [interceptor, ...toArray(options.interceptors)]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
isAllowed({ request }) {
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if (request.method !== "GET") {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
const site = flattenStandardHeader(request.headers["sec-fetch-site"])?.toLowerCase();
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if (site === undefined || site === "same-origin" || site === "same-site") {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const mode = flattenStandardHeader(request.headers["sec-fetch-mode"])?.toLowerCase();
|
|
39
|
+
const dest = flattenStandardHeader(request.headers["sec-fetch-dest"])?.toLowerCase();
|
|
40
|
+
if (mode === undefined || dest === undefined) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return mode !== "navigate" || dest !== "document";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StandardHandlerOptions, StandardHandlerPlugin } from "../adapters/standard/index.mjs";
|
|
2
|
+
import type { Context } from "../context.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Answers `HEAD` requests with the headers of the matching `GET` procedure, like Fastify's
|
|
5
|
+
* `exposeHeadRoutes`, so clients can check a resource's existence, type, and size without
|
|
6
|
+
* downloading it. A procedure routed as `HEAD` itself takes precedence over the `GET` one.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* - `HEAD` responses never carry a body: the plugin discards it, cancelling streams and
|
|
10
|
+
* event iterators, and keeps the headers it implies, such as `Content-Type`, and
|
|
11
|
+
* `Content-Length` when its size is known up front.
|
|
12
|
+
* - `GET` procedures still need to be reachable, so with `RPCHandler`, `GET` must be in `allowMethods`.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://orpc.dev/docs/plugins/head-method | HEAD Method Plugin}
|
|
15
|
+
*/
|
|
16
|
+
export declare class HeadMethodHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Discard the body after response compression, so `HEAD` reports the same `Content-Encoding` as `GET`.
|
|
20
|
+
*/
|
|
21
|
+
after: string[];
|
|
22
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { isAsyncIteratorObject, toArray } from "@orpc/shared";
|
|
2
|
+
import { cancelStandardBody, getRequiredStandardBodyHint } from "@standard-server/core";
|
|
3
|
+
import { toFetchBody } from "@standard-server/fetch";
|
|
4
|
+
const textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
5
|
+
|
|
6
|
+
export class HeadMethodHandlerPlugin {
|
|
7
|
+
name = "~head-method";
|
|
8
|
+
|
|
9
|
+
after = ["~response-compression"];
|
|
10
|
+
init(options) {
|
|
11
|
+
const bodyInterceptor = async ({ next, request }) => {
|
|
12
|
+
if (request.method !== "HEAD") {
|
|
13
|
+
return next();
|
|
14
|
+
}
|
|
15
|
+
const result = await next();
|
|
16
|
+
if (!result.matched) {
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
...result,
|
|
21
|
+
response: toHeadResponse(result.response)
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const fallbackInterceptor = async (interceptorOptions) => {
|
|
26
|
+
const { next, request } = interceptorOptions;
|
|
27
|
+
if (request.method !== "HEAD") {
|
|
28
|
+
return next();
|
|
29
|
+
}
|
|
30
|
+
const result = await next();
|
|
31
|
+
if (result.matched) {
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
return next({
|
|
35
|
+
...interceptorOptions,
|
|
36
|
+
request: {
|
|
37
|
+
...request,
|
|
38
|
+
method: "GET"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
...options,
|
|
44
|
+
routingInterceptors: [
|
|
45
|
+
bodyInterceptor,
|
|
46
|
+
...toArray(options.routingInterceptors),
|
|
47
|
+
fallbackInterceptor
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function toHeadResponse(response) {
|
|
54
|
+
const { body } = response;
|
|
55
|
+
if (body === undefined) {
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
if (isAsyncIteratorObject(body)) {
|
|
59
|
+
discardBody(body);
|
|
60
|
+
const headers = {
|
|
61
|
+
...response.headers,
|
|
62
|
+
"content-length": undefined
|
|
63
|
+
};
|
|
64
|
+
headers["content-type"] ??= "text/event-stream";
|
|
65
|
+
headers["standard-server"] = getRequiredStandardBodyHint("event-stream", headers) ?? [];
|
|
66
|
+
return {
|
|
67
|
+
...response,
|
|
68
|
+
headers,
|
|
69
|
+
body: createEmptyStream()
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const [encoded, headers] = toFetchBody(body, response.headers);
|
|
73
|
+
if (encoded instanceof ReadableStream) {
|
|
74
|
+
discardBody(encoded);
|
|
75
|
+
} else if (encoded instanceof FormData) {
|
|
76
|
+
|
|
77
|
+
headers["standard-server"] = [];
|
|
78
|
+
headers["content-type"] = new Response(encoded).headers.get("content-type");
|
|
79
|
+
} else if (typeof encoded === "string" || encoded instanceof URLSearchParams) {
|
|
80
|
+
headers["standard-server"] ??= [];
|
|
81
|
+
headers["content-length"] = textEncoder.encode(encoded.toString()).byteLength.toString();
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
...response,
|
|
85
|
+
headers,
|
|
86
|
+
body: createEmptyStream()
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function createEmptyStream() {
|
|
90
|
+
return new ReadableStream({ start: (controller) => controller.close() });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function discardBody(body) {
|
|
94
|
+
cancelStandardBody(body).catch(() => {});
|
|
95
|
+
}
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,432 +1,39 @@
|
|
|
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
|
-
mapSubresponse?: ((subresponse: StandardResponse, partialBatchResponse: Pick<StandardResponse, 'status' | 'headers'>, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardResponse) | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* Success batch response status code.
|
|
43
|
-
*
|
|
44
|
-
* @default 207
|
|
45
|
-
*/
|
|
46
|
-
successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* Success batch response headers.
|
|
49
|
-
*
|
|
50
|
-
* The batch response also gets the cookies its sub-responses set, and the headers they all share.
|
|
51
|
-
* Headers set here win, and setting one to `undefined` keeps it off, except `set-cookie` and `vary`, which merge.
|
|
52
|
-
*
|
|
53
|
-
* @default {}
|
|
54
|
-
*/
|
|
55
|
-
headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Keep-alive settings for batch responses that stream.
|
|
58
|
-
*
|
|
59
|
-
* When enabled, a zero-length length-prefixed frame is sent periodically while the
|
|
60
|
-
* stream is idle (no message sent for `interval` ms). Clients ignore these frames.
|
|
61
|
-
*
|
|
62
|
-
* @default { enabled: true, interval: 15000 }
|
|
63
|
-
*/
|
|
64
|
-
keepAlive?: {
|
|
65
|
-
/**
|
|
66
|
-
* If true, a keep-alive frame is sent periodically while the stream is idle.
|
|
67
|
-
*
|
|
68
|
-
* @default true
|
|
69
|
-
*/
|
|
70
|
-
enabled: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Interval (in milliseconds) between keep-alive frames after the last message.
|
|
73
|
-
*
|
|
74
|
-
* @default 15000
|
|
75
|
-
*/
|
|
76
|
-
interval?: number | undefined;
|
|
77
|
-
} | undefined;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Handles batch requests sent by the client Batch Link Plugin, splitting each
|
|
81
|
-
* batch into sub-requests and sending their responses back together.
|
|
82
|
-
*
|
|
83
|
-
* @remarks
|
|
84
|
-
* The batch starts the response once every sub-response is ready, so it carries the cookies sub-requests
|
|
85
|
-
* set and the headers every sub-response shares. It streams when a sub-response is a stream.
|
|
86
|
-
*
|
|
87
|
-
* **Note**: HTTP/2 and later already multiplex requests over a single connection, which often makes this plugin unnecessary.
|
|
88
|
-
*
|
|
89
|
-
* @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
|
|
90
|
-
*/
|
|
91
|
-
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
92
|
-
name: string;
|
|
93
|
-
/**
|
|
94
|
-
* Run batch interceptors inside the tracing interceptors
|
|
95
|
-
* so each subrequest gets its own span instead of sharing one batch-level span.
|
|
96
|
-
*/
|
|
97
|
-
after: string[];
|
|
98
|
-
private readonly maxSize;
|
|
99
|
-
private readonly mapSubrequest;
|
|
100
|
-
private readonly mapSubresponse;
|
|
101
|
-
private readonly successStatus;
|
|
102
|
-
private readonly headers;
|
|
103
|
-
private readonly keepAliveEnabled;
|
|
104
|
-
private readonly keepAliveInterval;
|
|
105
|
-
constructor(options?: BatchHandlerPluginOptions<T>);
|
|
106
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
interface CORSHandlerPluginOptions<T extends Context> {
|
|
110
|
-
/**
|
|
111
|
-
* Configures the `Access-Control-Allow-Origin` header.
|
|
112
|
-
* Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
|
|
113
|
-
*
|
|
114
|
-
* A function must only return origins it has validated: returning the incoming origin
|
|
115
|
-
* unchecked allows every origin.
|
|
116
|
-
*
|
|
117
|
-
* @default '*'
|
|
118
|
-
*/
|
|
119
|
-
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
120
|
-
/**
|
|
121
|
-
* Configures the `Timing-Allow-Origin` header.
|
|
122
|
-
* Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
|
|
123
|
-
*/
|
|
124
|
-
timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
125
|
-
/**
|
|
126
|
-
* Configures the `Access-Control-Allow-Methods` header for preflight requests.
|
|
127
|
-
*
|
|
128
|
-
* @default ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'QUERY']
|
|
129
|
-
*/
|
|
130
|
-
allowMethods?: readonly string[] | undefined;
|
|
131
|
-
/**
|
|
132
|
-
* Configures the `Access-Control-Allow-Headers` header for preflight requests.
|
|
133
|
-
* Falls back to the request's `Access-Control-Request-Headers` if not set.
|
|
134
|
-
* When set, it replaces that fallback, so include every non-safelisted header
|
|
135
|
-
* clients send, such as `Content-Type`.
|
|
136
|
-
*/
|
|
137
|
-
allowHeaders?: readonly string[] | undefined;
|
|
138
|
-
/**
|
|
139
|
-
* Configures the `Access-Control-Max-Age` header (in seconds) for preflight requests.
|
|
140
|
-
*/
|
|
141
|
-
maxAge?: number | undefined;
|
|
142
|
-
/**
|
|
143
|
-
* Configures the `Access-Control-Allow-Credentials` header.
|
|
144
|
-
*
|
|
145
|
-
* When enabled, `origin` must allow trusted origins only: every allowed origin can send
|
|
146
|
-
* authenticated requests as your users and read the responses.
|
|
147
|
-
*/
|
|
148
|
-
credentials?: boolean | undefined;
|
|
149
|
-
/**
|
|
150
|
-
* Configures the `Access-Control-Expose-Headers` header.
|
|
151
|
-
*/
|
|
152
|
-
exposeHeaders?: readonly string[] | undefined;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Configures the [CORS Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
|
|
156
|
-
* for your API, including preflight requests.
|
|
157
|
-
*
|
|
158
|
-
* @see {@link https://orpc.dev/docs/plugins/cors | CORS Handler Plugin}
|
|
159
|
-
*/
|
|
160
|
-
declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
161
|
-
private readonly options;
|
|
162
|
-
name: string;
|
|
163
|
-
/**
|
|
164
|
-
* - Do not create spans for CORS preflight requests.
|
|
165
|
-
* - Run CORS interceptors before batch interceptors so headers are applied to
|
|
166
|
-
* the actual response rather than sub-responses.
|
|
167
|
-
*/
|
|
168
|
-
after: string[];
|
|
169
|
-
constructor(options?: CORSHandlerPluginOptions<T>);
|
|
170
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
171
|
-
private resolveOrigin;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Adds Cross-Site Request Forgery (CSRF) protection that makes the safe `GET` method as
|
|
176
|
-
* secure as unsafe ones such as `POST`. It rejects `GET` requests arriving as top-level
|
|
177
|
-
* navigations initiated cross-site or from outside the browser, the only context where
|
|
178
|
-
* another site can make a browser attach `SameSite=Lax` cookies to a safe-method request.
|
|
179
|
-
* Requests matching no procedure stay unmatched, so they can fall through to whatever
|
|
180
|
-
* serves the rest of the site.
|
|
181
|
-
*
|
|
182
|
-
* @remarks
|
|
183
|
-
* **Note**: Requests browsers send without `SameSite=Lax` cookies, such as cross-site `fetch`
|
|
184
|
-
* and `<img>`, pass through, so procedures stay reachable from other sites. This safeguard
|
|
185
|
-
* requires authentication cookies explicitly marked `SameSite=Lax` or `SameSite=Strict`,
|
|
186
|
-
* since browsers may attach other cookies to the requests that pass.
|
|
187
|
-
*
|
|
188
|
-
* @see {@link https://orpc.dev/docs/plugins/get-method-csrf-protection | GET Method CSRF Protection Plugin}
|
|
189
|
-
*/
|
|
190
|
-
declare class GetMethodCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
191
|
-
name: string;
|
|
192
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
193
|
-
private isAllowed;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
interface MethodOverrideHandlerPluginOptions {
|
|
197
|
-
/**
|
|
198
|
-
* The query parameter carrying the override method.
|
|
199
|
-
*
|
|
200
|
-
* @default 'method'
|
|
201
|
-
*/
|
|
202
|
-
param?: string | undefined;
|
|
203
|
-
/**
|
|
204
|
-
* The methods a POST request may be overridden to.
|
|
205
|
-
*
|
|
206
|
-
* GET and HEAD are excluded by default because they switch input decoding
|
|
207
|
-
* from the request body to the query string and widen the CSRF surface.
|
|
208
|
-
*
|
|
209
|
-
* @default ['PUT', 'PATCH', 'DELETE']
|
|
210
|
-
*/
|
|
211
|
-
methods?: readonly StandardMethod[] | undefined;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Overrides the HTTP method of a POST request based on a query parameter,
|
|
215
|
-
* so HTML forms (which only support GET and POST) can invoke procedures
|
|
216
|
-
* routed as PUT, PATCH, or DELETE.
|
|
217
|
-
*
|
|
218
|
-
* @see {@link https://orpc.dev/docs/plugins/method-override | Method Override Plugin}
|
|
219
|
-
*/
|
|
220
|
-
declare class MethodOverrideHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
221
|
-
name: string;
|
|
222
|
-
/**
|
|
223
|
-
* Should override batch sub-request methods, not the original batch request.
|
|
224
|
-
*/
|
|
225
|
-
before: string[];
|
|
226
|
-
private readonly param;
|
|
227
|
-
private readonly methods;
|
|
228
|
-
constructor(options?: MethodOverrideHandlerPluginOptions);
|
|
229
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Decompresses incoming request bodies based on the Content-Encoding header,
|
|
234
|
-
* supporting gzip, deflate, and deflate-raw.
|
|
235
|
-
*
|
|
236
|
-
* @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
|
|
237
|
-
*/
|
|
238
|
-
declare class RequestCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
239
|
-
name: string;
|
|
240
|
-
/**
|
|
241
|
-
* Should decompress the original batch request body instead of sub-requests.
|
|
242
|
-
*/
|
|
243
|
-
after: string[];
|
|
244
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* The context shape into which the Request Headers Plugin injects `reqHeaders`.
|
|
249
|
-
*
|
|
250
|
-
* @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
|
|
251
|
-
*/
|
|
252
|
-
interface RequestHeadersHandlerPluginContext {
|
|
253
|
-
/**
|
|
254
|
-
* Request headers as a Headers instance. This is injected by the Request Headers Plugin.
|
|
255
|
-
*/
|
|
256
|
-
reqHeaders?: Headers | undefined;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
260
|
-
* allowing access to request headers in oRPC.
|
|
261
|
-
*
|
|
262
|
-
* @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
|
|
263
|
-
*/
|
|
264
|
-
declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
|
|
265
|
-
name: string;
|
|
266
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
interface ResponseCompressionHandlerPluginOptions<T extends Context> {
|
|
270
|
-
/**
|
|
271
|
-
* The compression schemes to use for response compression.
|
|
272
|
-
* Schemes are prioritized by their order in this array and
|
|
273
|
-
* only applied if the client supports them (via Accept-Encoding).
|
|
274
|
-
*
|
|
275
|
-
* @default ['gzip', 'deflate']
|
|
276
|
-
*/
|
|
277
|
-
encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[] | undefined;
|
|
278
|
-
/**
|
|
279
|
-
* The minimum response size in bytes required to trigger compression.
|
|
280
|
-
* Responses smaller than this threshold will not be compressed to avoid overhead.
|
|
281
|
-
* If the response size cannot be determined, compression will still be applied.
|
|
282
|
-
*
|
|
283
|
-
* @default 1024 (1KB)
|
|
284
|
-
*/
|
|
285
|
-
threshold?: number | undefined;
|
|
286
|
-
/**
|
|
287
|
-
* Determines whether a response with the given Content-Type should be compressed.
|
|
288
|
-
* Only consulted for binary transfers (streams, files, and file form-data parts).
|
|
289
|
-
* Also receives the routing interceptor options for per-request decisions.
|
|
290
|
-
*
|
|
291
|
-
* @default isCompressibleContentType (covers common text-based formats)
|
|
292
|
-
*/
|
|
293
|
-
isCompressibleContentType?: ((contentType: string | null | undefined, options: StandardHandlerRoutingInterceptorOptions<T>) => boolean) | undefined;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Compresses response bodies based on the client's Accept-Encoding header.
|
|
297
|
-
* Works at the standard handler level, so it supports all adapters.
|
|
298
|
-
*
|
|
299
|
-
* @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
|
|
300
|
-
*/
|
|
301
|
-
declare class ResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
302
|
-
name: string;
|
|
303
|
-
/**
|
|
304
|
-
* Compression should be done after batching, to compress the final response.
|
|
305
|
-
* Compression should also be done after response headers are set, to access final headers like Content-Type and Cache-Control.
|
|
306
|
-
*/
|
|
307
|
-
after: string[];
|
|
308
|
-
private readonly encodings;
|
|
309
|
-
private readonly threshold;
|
|
310
|
-
private readonly isCompressibleContentType;
|
|
311
|
-
constructor(options?: ResponseCompressionHandlerPluginOptions<T>);
|
|
312
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Picks the first of `encodings` the client accepts, or `undefined` when the response
|
|
316
|
-
* must be sent as is because it is already encoded, partial, or forbids transforms.
|
|
317
|
-
* Shared by the response compression plugins so they agree on when to compress.
|
|
318
|
-
*/
|
|
319
|
-
declare function negotiateResponseCompressionEncoding<TEncoding extends string>(response: StandardResponse, requestHeaders: StandardHeaders, encodings: readonly TEncoding[]): TEncoding | undefined;
|
|
320
|
-
/**
|
|
321
|
-
* The headers of a response whose body is compressed with `encoding`.
|
|
322
|
-
* Shared by the response compression plugins so compressed responses carry the same headers.
|
|
323
|
-
*/
|
|
324
|
-
declare function toCompressedHeaders(headers: StandardHeaders, encoding: string): StandardHeaders;
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* The context shape into which the Response Headers Plugin injects `resHeaders`.
|
|
328
|
-
*
|
|
329
|
-
* @see {@link https://orpc.dev/docs/plugins/response-headers | Response Headers Plugin}
|
|
330
|
-
*/
|
|
331
|
-
interface ResponseHeadersHandlerPluginContext {
|
|
332
|
-
/**
|
|
333
|
-
* Response headers as a Headers instance. This is injected by the Response Headers Plugin.
|
|
334
|
-
* When set before the response is sent, these headers will be included in the response. If not set, no additional headers will be added.
|
|
335
|
-
*/
|
|
336
|
-
resHeaders?: Headers | undefined;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
340
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
341
|
-
*
|
|
342
|
-
* @see {@link https://orpc.dev/docs/plugins/response-headers | Response Headers Plugin}
|
|
343
|
-
*/
|
|
344
|
-
declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
|
|
345
|
-
name: string;
|
|
346
|
-
/**
|
|
347
|
-
* Interceptors should run after batch interceptors so headers are applied to each sub-response.
|
|
348
|
-
*/
|
|
349
|
-
before: string[];
|
|
350
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
interface RethrowHandlerPluginOptions<T extends Context> {
|
|
354
|
-
/**
|
|
355
|
-
* Decide which errors should be rethrown.
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```ts
|
|
359
|
-
* const rethrowPlugin = new RethrowHandlerPlugin({
|
|
360
|
-
* filter: (error) => {
|
|
361
|
-
* // Rethrow all non-ORPCError errors
|
|
362
|
-
* return !(error instanceof ORPCError)
|
|
363
|
-
* }
|
|
364
|
-
* })
|
|
365
|
-
* ```
|
|
366
|
-
*/
|
|
367
|
-
filter: (error: ThrowableError, options: StandardHandlerInterceptorOptions<T>) => boolean;
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* The plugin can bypass oRPC's built-in error handling
|
|
371
|
-
* and rethrow matching errors directly to your framework's error handling mechanism
|
|
372
|
-
* (e.g., NestJS exception filters, Express error middleware).
|
|
373
|
-
*
|
|
374
|
-
* @see {@link https://orpc.dev/docs/plugins/rethrow | Rethrow Handler Plugin}
|
|
375
|
-
*/
|
|
376
|
-
declare class RethrowHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
377
|
-
name: string;
|
|
378
|
-
private readonly filter;
|
|
379
|
-
private readonly CONTEXT_SYMBOL;
|
|
380
|
-
constructor(options: RethrowHandlerPluginOptions<T>);
|
|
381
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* Keeps the request signal and a streaming output (async iterator object or readable stream) in sync:
|
|
386
|
-
* cancelling the output aborts the signal with an `AbortError`,
|
|
387
|
-
* and aborting the signal ends the output with the abort reason and cancels it.
|
|
388
|
-
*
|
|
389
|
-
* @see {@link https://orpc.dev/docs/plugins/signal-sync | Signal Sync Plugin}
|
|
390
|
-
*/
|
|
391
|
-
declare class SignalSyncHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
392
|
-
name: string;
|
|
393
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
interface TimeoutHandlerPluginOptions<T extends Context> {
|
|
397
|
-
/**
|
|
398
|
-
* Timeout in milliseconds before the request signal is aborted.
|
|
399
|
-
* This only covers producing the response, use `streamingTimeout`
|
|
400
|
-
* to limit streaming response bodies.
|
|
401
|
-
* Use `null` or `undefined` to disable the timeout.
|
|
402
|
-
*/
|
|
403
|
-
timeout: Value<number | null | undefined, [options: StandardHandlerInterceptorOptions<T>]>;
|
|
404
|
-
/**
|
|
405
|
-
* Timeout in milliseconds for the full duration of a streaming response body
|
|
406
|
-
* (async iterator object or readable stream), measured from when the response is produced.
|
|
407
|
-
* When exceeded, the request signal is aborted and the body ends
|
|
408
|
-
* once its producer honors the signal.
|
|
409
|
-
* Usually higher than `timeout`.
|
|
410
|
-
* Use `null` or `undefined` to disable the timeout.
|
|
411
|
-
*
|
|
412
|
-
* @default undefined (streaming responses run without limit)
|
|
413
|
-
*/
|
|
414
|
-
streamingTimeout?: Value<number | null | undefined, [options: StandardHandlerInterceptorOptions<T>]> | undefined;
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* The Timeout Handler Plugin aborts the request signal with an `AbortError`
|
|
418
|
-
* when handling exceeds a configured timeout. It only aborts the signal,
|
|
419
|
-
* the procedure must honor it to stop early and produce the response.
|
|
420
|
-
*
|
|
421
|
-
* @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
|
|
422
|
-
*/
|
|
423
|
-
declare class TimeoutHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
424
|
-
private readonly timeout;
|
|
425
|
-
private readonly streamingTimeout;
|
|
426
|
-
name: string;
|
|
427
|
-
constructor(options: NoInfer<TimeoutHandlerPluginOptions<T>>);
|
|
428
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, GetMethodCsrfProtectionHandlerPlugin, MethodOverrideHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin, SignalSyncHandlerPlugin, TimeoutHandlerPlugin, negotiateResponseCompressionEncoding, toCompressedHeaders };
|
|
432
|
-
export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, MethodOverrideHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, RethrowHandlerPluginOptions, TimeoutHandlerPluginOptions };
|
|
1
|
+
export * from "./batch.mjs";
|
|
2
|
+
export * from "./cors.mjs";
|
|
3
|
+
export {
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `CORSHandlerPlugin` instead.
|
|
6
|
+
*/
|
|
7
|
+
CORSHandlerPlugin as CORSPlugin } from "./cors.mjs";
|
|
8
|
+
export * from "./get-method-csrf-protection.mjs";
|
|
9
|
+
export * from "./head-method.mjs";
|
|
10
|
+
export * from "./method-override.mjs";
|
|
11
|
+
export * from "./request-compression.mjs";
|
|
12
|
+
export * from "./request-headers.mjs";
|
|
13
|
+
export {
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `RequestHeadersHandlerPlugin` instead.
|
|
16
|
+
*/
|
|
17
|
+
RequestHeadersHandlerPlugin as RequestHeadersPlugin } from "./request-headers.mjs";
|
|
18
|
+
export type {
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use `RequestHeadersHandlerPluginContext` instead.
|
|
21
|
+
*/
|
|
22
|
+
RequestHeadersHandlerPluginContext as RequestHeadersPluginContext } from "./request-headers.mjs";
|
|
23
|
+
export * from "./request-limit.mjs";
|
|
24
|
+
export * from "./response-compression.mjs";
|
|
25
|
+
export * from "./response-headers.mjs";
|
|
26
|
+
export {
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use `ResponseHeadersHandlerPlugin` instead.
|
|
29
|
+
*/
|
|
30
|
+
ResponseHeadersHandlerPlugin as ResponseHeadersPlugin } from "./response-headers.mjs";
|
|
31
|
+
export type {
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use `ResponseHeadersHandlerPluginContext` instead.
|
|
34
|
+
*/
|
|
35
|
+
ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext } from "./response-headers.mjs";
|
|
36
|
+
export * from "./rethrow.mjs";
|
|
37
|
+
export * from "./signal-sync.mjs";
|
|
38
|
+
export * from "./timeout.mjs";
|
|
39
|
+
export { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from "@orpc/client/plugins";
|