@orpc/server 0.0.0-next.a8e421c → 0.0.0-next.a910d34

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 (71) hide show
  1. package/README.md +27 -23
  2. package/dist/adapters/aws-lambda/index.d.mts +46 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +46 -0
  4. package/dist/adapters/aws-lambda/index.mjs +42 -0
  5. package/dist/adapters/bun-ws/index.d.mts +36 -0
  6. package/dist/adapters/bun-ws/index.d.ts +36 -0
  7. package/dist/adapters/bun-ws/index.mjs +47 -0
  8. package/dist/adapters/crossws/index.d.mts +33 -0
  9. package/dist/adapters/crossws/index.d.ts +33 -0
  10. package/dist/adapters/crossws/index.mjs +47 -0
  11. package/dist/adapters/fetch/index.d.mts +62 -11
  12. package/dist/adapters/fetch/index.d.ts +62 -11
  13. package/dist/adapters/fetch/index.mjs +109 -8
  14. package/dist/adapters/message-port/index.d.mts +31 -0
  15. package/dist/adapters/message-port/index.d.ts +31 -0
  16. package/dist/adapters/message-port/index.mjs +41 -0
  17. package/dist/adapters/node/index.d.mts +64 -22
  18. package/dist/adapters/node/index.d.ts +64 -22
  19. package/dist/adapters/node/index.mjs +88 -24
  20. package/dist/adapters/standard/index.d.mts +8 -13
  21. package/dist/adapters/standard/index.d.ts +8 -13
  22. package/dist/adapters/standard/index.mjs +5 -3
  23. package/dist/adapters/standard-peer/index.d.mts +14 -0
  24. package/dist/adapters/standard-peer/index.d.ts +14 -0
  25. package/dist/adapters/standard-peer/index.mjs +7 -0
  26. package/dist/adapters/websocket/index.d.mts +54 -0
  27. package/dist/adapters/websocket/index.d.ts +54 -0
  28. package/dist/adapters/websocket/index.mjs +69 -0
  29. package/dist/adapters/ws/index.d.mts +31 -0
  30. package/dist/adapters/ws/index.d.ts +31 -0
  31. package/dist/adapters/ws/index.mjs +39 -0
  32. package/dist/helpers/index.d.mts +130 -0
  33. package/dist/helpers/index.d.ts +130 -0
  34. package/dist/helpers/index.mjs +182 -0
  35. package/dist/hibernation/index.d.mts +44 -0
  36. package/dist/hibernation/index.d.ts +44 -0
  37. package/dist/hibernation/index.mjs +65 -0
  38. package/dist/index.d.mts +609 -84
  39. package/dist/index.d.ts +609 -84
  40. package/dist/index.mjs +162 -15
  41. package/dist/plugins/index.d.mts +154 -16
  42. package/dist/plugins/index.d.ts +154 -16
  43. package/dist/plugins/index.mjs +189 -16
  44. package/dist/shared/server.B7b2w3_i.d.ts +12 -0
  45. package/dist/shared/server.BEFBl-Cb.d.mts +12 -0
  46. package/dist/shared/server.BU4WI18A.d.mts +32 -0
  47. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  48. package/dist/shared/server.Bmh5xd4n.d.ts +74 -0
  49. package/dist/shared/server.C6Q5sqYw.mjs +20 -0
  50. package/dist/shared/{server.BY9sDlwl.mjs → server.CIL9uKTN.mjs} +66 -30
  51. package/dist/shared/{server.BYTulgUc.d.mts → server.CYNGeoCm.d.mts} +66 -16
  52. package/dist/shared/{server.BYTulgUc.d.ts → server.CYNGeoCm.d.ts} +66 -16
  53. package/dist/shared/server.D0H-iaY3.d.ts +32 -0
  54. package/dist/shared/server.DZ5BIITo.mjs +9 -0
  55. package/dist/shared/server.DhJj-1X9.d.mts +42 -0
  56. package/dist/shared/{server.BtxZnWJ9.mjs → server.NeumLVdS.mjs} +34 -38
  57. package/dist/shared/server.gqRxT-yN.d.mts +74 -0
  58. package/dist/shared/server.jMTkVNIb.d.ts +42 -0
  59. package/package.json +70 -20
  60. package/dist/adapters/hono/index.d.mts +0 -21
  61. package/dist/adapters/hono/index.d.ts +0 -21
  62. package/dist/adapters/hono/index.mjs +0 -32
  63. package/dist/adapters/next/index.d.mts +0 -28
  64. package/dist/adapters/next/index.d.ts +0 -28
  65. package/dist/adapters/next/index.mjs +0 -29
  66. package/dist/shared/server.B52eKaNe.d.mts +0 -8
  67. package/dist/shared/server.BA-onDGB.d.ts +0 -8
  68. package/dist/shared/server.CDzXh8DM.d.mts +0 -75
  69. package/dist/shared/server.CkGvC2T0.d.ts +0 -75
  70. package/dist/shared/server.Dba3Iiyp.mjs +0 -12
  71. package/dist/shared/server.Del5OmaY.mjs +0 -29
@@ -1,31 +1,169 @@
1
- import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.CkGvC2T0.js';
2
- export { C as CompositeHandlerPlugin } from '../shared/server.CkGvC2T0.js';
3
- import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.BYTulgUc.js';
5
- import '@orpc/contract';
6
- import '@orpc/standard-server';
7
- import '@orpc/client';
1
+ import { Value, Promisable } from '@orpc/shared';
2
+ import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
+ import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
+ import { d as StandardHandlerInterceptorOptions, g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.Bmh5xd4n.js';
5
+ import { C as Context, d as ProcedureClientInterceptorOptions } from '../shared/server.CYNGeoCm.js';
6
+ import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
+ import { ORPCError } from '@orpc/client';
8
8
 
9
- interface CORSOptions<TContext extends Context> {
10
- origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
- timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
9
+ interface BatchHandlerOptions<T extends Context> {
10
+ /**
11
+ * The max size of the batch allowed.
12
+ *
13
+ * @default 10
14
+ */
15
+ maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
16
+ /**
17
+ * Map the request before processing it.
18
+ *
19
+ * @default merged back batch request headers into the request
20
+ */
21
+ mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
22
+ /**
23
+ * Success batch response status code.
24
+ *
25
+ * @default 207
26
+ */
27
+ successStatus?: Value<Promisable<number>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
28
+ /**
29
+ * success batch response headers.
30
+ *
31
+ * @default {}
32
+ */
33
+ headers?: Value<Promisable<StandardHeaders>, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
+ }
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.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
40
+ */
41
+ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
42
+ private readonly maxSize;
43
+ private readonly mapRequestItem;
44
+ private readonly successStatus;
45
+ private readonly headers;
46
+ order: number;
47
+ constructor(options?: BatchHandlerOptions<T>);
48
+ init(options: StandardHandlerOptions<T>): void;
49
+ }
50
+
51
+ interface CORSOptions<T extends Context> {
52
+ origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
53
+ timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
12
54
  allowMethods?: readonly string[];
13
55
  allowHeaders?: readonly string[];
14
56
  maxAge?: number;
15
57
  credentials?: boolean;
16
58
  exposeHeaders?: readonly string[];
17
59
  }
18
- declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
60
+ /**
61
+ * CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
62
+ *
63
+ * @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
64
+ */
65
+ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
66
  private readonly options;
20
- constructor(options?: CORSOptions<TContext>);
21
- init(options: StandardHandlerOptions<TContext>): void;
67
+ order: number;
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.unnoq.com/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;
22
83
  }
23
84
 
24
85
  interface ResponseHeadersPluginContext {
25
86
  resHeaders?: Headers;
26
87
  }
27
- declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
- init(options: StandardHandlerOptions<TContext>): void;
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.unnoq.com/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 SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
99
+ /**
100
+ * The name of the header to check.
101
+ *
102
+ * @default 'x-csrf-token'
103
+ */
104
+ headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
105
+ /**
106
+ * The value of the header to check.
107
+ *
108
+ * @default 'orpc'
109
+ *
110
+ */
111
+ headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
112
+ /**
113
+ * Exclude a procedure from the plugin.
114
+ *
115
+ * @default false
116
+ *
117
+ */
118
+ exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
119
+ /**
120
+ * The error thrown when the CSRF token is invalid.
121
+ *
122
+ * @default new ORPCError('CSRF_TOKEN_MISMATCH', {
123
+ * status: 403,
124
+ * message: 'Invalid CSRF token',
125
+ * })
126
+ */
127
+ error?: InstanceType<typeof ORPCError>;
128
+ }
129
+ /**
130
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
131
+ * It helps ensure that requests to your procedures originate from JavaScript code,
132
+ * not from other sources like standard HTML forms or direct browser navigation.
133
+ *
134
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
135
+ */
136
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
137
+ private readonly headerName;
138
+ private readonly headerValue;
139
+ private readonly exclude;
140
+ private readonly error;
141
+ constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
142
+ order: number;
143
+ init(options: StandardHandlerOptions<T>): void;
144
+ }
145
+
146
+ interface StrictGetMethodPluginOptions {
147
+ /**
148
+ * The error thrown when a GET request is made to a procedure that doesn't allow GET.
149
+ *
150
+ * @default new ORPCError('METHOD_NOT_SUPPORTED')
151
+ */
152
+ error?: InstanceType<typeof ORPCError$1>;
153
+ }
154
+ /**
155
+ * This plugin enhances security by ensuring only procedures explicitly marked to accept GET requests
156
+ * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
157
+ * Cross-Site Request Forgery (CSRF) attacks.
158
+ *
159
+ * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
160
+ */
161
+ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
162
+ private readonly error;
163
+ order: number;
164
+ constructor(options?: StrictGetMethodPluginOptions);
165
+ init(options: StandardHandlerOptions<T>): void;
29
166
  }
30
167
 
31
- export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
168
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
169
+ export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };
@@ -1,8 +1,113 @@
1
- export { C as CompositeHandlerPlugin } from '../shared/server.Dba3Iiyp.mjs';
2
- import { value } from '@orpc/shared';
1
+ import { value, isAsyncIteratorObject, clone } from '@orpc/shared';
2
+ import { flattenHeader } from '@orpc/standard-server';
3
+ import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
4
+ import { toFetchHeaders } from '@orpc/standard-server-fetch';
5
+ import { ORPCError } from '@orpc/client';
6
+ export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
7
+ import '@orpc/contract';
8
+
9
+ class BatchHandlerPlugin {
10
+ maxSize;
11
+ mapRequestItem;
12
+ successStatus;
13
+ headers;
14
+ order = 5e6;
15
+ constructor(options = {}) {
16
+ this.maxSize = options.maxSize ?? 10;
17
+ this.mapRequestItem = options.mapRequestItem ?? ((request, { request: batchRequest }) => ({
18
+ ...request,
19
+ headers: {
20
+ ...batchRequest.headers,
21
+ ...request.headers
22
+ }
23
+ }));
24
+ this.successStatus = options.successStatus ?? 207;
25
+ this.headers = options.headers ?? {};
26
+ }
27
+ init(options) {
28
+ options.rootInterceptors ??= [];
29
+ options.rootInterceptors.unshift(async (options2) => {
30
+ const xHeader = flattenHeader(options2.request.headers["x-orpc-batch"]);
31
+ if (xHeader === void 0) {
32
+ return options2.next();
33
+ }
34
+ let isParsing = false;
35
+ try {
36
+ isParsing = true;
37
+ const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
38
+ isParsing = false;
39
+ const maxSize = await value(this.maxSize, options2);
40
+ if (parsed.length > maxSize) {
41
+ return {
42
+ matched: true,
43
+ response: {
44
+ status: 413,
45
+ headers: {},
46
+ body: "Batch request size exceeds the maximum allowed size"
47
+ }
48
+ };
49
+ }
50
+ const responses = parsed.map(
51
+ (request, index) => {
52
+ const mapped = this.mapRequestItem(request, options2);
53
+ return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
54
+ if (matched) {
55
+ if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
56
+ return {
57
+ index,
58
+ status: 500,
59
+ headers: {},
60
+ body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
61
+ };
62
+ }
63
+ return { ...response2, index };
64
+ }
65
+ return { index, status: 404, headers: {}, body: "No procedure matched" };
66
+ }).catch(() => {
67
+ return { index, status: 500, headers: {}, body: "Internal server error" };
68
+ });
69
+ }
70
+ );
71
+ await Promise.race(responses);
72
+ const status = await value(this.successStatus, responses, options2);
73
+ const headers = await value(this.headers, responses, options2);
74
+ const response = await toBatchResponse({
75
+ status,
76
+ headers,
77
+ mode: xHeader === "buffered" ? "buffered" : "streaming",
78
+ body: async function* () {
79
+ const promises = [...responses];
80
+ while (true) {
81
+ const handling = promises.filter((p) => p !== void 0);
82
+ if (handling.length === 0) {
83
+ return;
84
+ }
85
+ const result = await Promise.race(handling);
86
+ promises[result.index] = void 0;
87
+ yield result;
88
+ }
89
+ }()
90
+ });
91
+ return {
92
+ matched: true,
93
+ response
94
+ };
95
+ } catch (cause) {
96
+ if (isParsing) {
97
+ return {
98
+ matched: true,
99
+ response: { status: 400, headers: {}, body: "Invalid batch request, this could be caused by a malformed request body or a missing header" }
100
+ };
101
+ }
102
+ throw cause;
103
+ }
104
+ });
105
+ }
106
+ }
3
107
 
4
108
  class CORSPlugin {
5
109
  options;
110
+ order = 9e6;
6
111
  constructor(options = {}) {
7
112
  const defaults = {
8
113
  origin: (origin) => origin,
@@ -22,13 +127,11 @@ class CORSPlugin {
22
127
  resHeaders["access-control-max-age"] = this.options.maxAge.toString();
23
128
  }
24
129
  if (this.options.allowMethods?.length) {
25
- resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
130
+ resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
26
131
  }
27
132
  const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
28
- if (Array.isArray(allowHeaders) && allowHeaders.length) {
29
- resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
30
- } else if (typeof allowHeaders === "string") {
31
- resHeaders["access-control-allow-headers"] = allowHeaders;
133
+ if (typeof allowHeaders === "string" || allowHeaders?.length) {
134
+ resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
32
135
  }
33
136
  return {
34
137
  matched: true,
@@ -46,7 +149,7 @@ class CORSPlugin {
46
149
  if (!result.matched) {
47
150
  return result;
48
151
  }
49
- const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
152
+ const origin = flattenHeader(interceptorOptions.request.headers.origin) ?? "";
50
153
  const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
51
154
  const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
52
155
  if (allowedOriginArr.includes("*")) {
@@ -68,25 +171,46 @@ class CORSPlugin {
68
171
  result.response.headers["access-control-allow-credentials"] = "true";
69
172
  }
70
173
  if (this.options.exposeHeaders?.length) {
71
- result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
174
+ result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
72
175
  }
73
176
  return result;
74
177
  });
75
178
  }
76
179
  }
77
180
 
181
+ class RequestHeadersPlugin {
182
+ init(options) {
183
+ options.rootInterceptors ??= [];
184
+ options.rootInterceptors.push((interceptorOptions) => {
185
+ const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
186
+ return interceptorOptions.next({
187
+ ...interceptorOptions,
188
+ context: {
189
+ ...interceptorOptions.context,
190
+ reqHeaders
191
+ }
192
+ });
193
+ });
194
+ }
195
+ }
196
+
78
197
  class ResponseHeadersPlugin {
79
198
  init(options) {
80
199
  options.rootInterceptors ??= [];
81
200
  options.rootInterceptors.push(async (interceptorOptions) => {
82
- const headers = new Headers();
83
- interceptorOptions.context.resHeaders = headers;
84
- const result = await interceptorOptions.next();
201
+ const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
202
+ const result = await interceptorOptions.next({
203
+ ...interceptorOptions,
204
+ context: {
205
+ ...interceptorOptions.context,
206
+ resHeaders
207
+ }
208
+ });
85
209
  if (!result.matched) {
86
210
  return result;
87
211
  }
88
- const responseHeaders = result.response.headers;
89
- for (const [key, value] of headers) {
212
+ const responseHeaders = clone(result.response.headers);
213
+ for (const [key, value] of resHeaders) {
90
214
  if (Array.isArray(responseHeaders[key])) {
91
215
  responseHeaders[key].push(value);
92
216
  } else if (responseHeaders[key] !== void 0) {
@@ -95,9 +219,58 @@ class ResponseHeadersPlugin {
95
219
  responseHeaders[key] = value;
96
220
  }
97
221
  }
98
- return result;
222
+ return {
223
+ ...result,
224
+ response: {
225
+ ...result.response,
226
+ headers: responseHeaders
227
+ }
228
+ };
229
+ });
230
+ }
231
+ }
232
+
233
+ const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
234
+ class SimpleCsrfProtectionHandlerPlugin {
235
+ headerName;
236
+ headerValue;
237
+ exclude;
238
+ error;
239
+ constructor(options = {}) {
240
+ this.headerName = options.headerName ?? "x-csrf-token";
241
+ this.headerValue = options.headerValue ?? "orpc";
242
+ this.exclude = options.exclude ?? false;
243
+ this.error = options.error ?? new ORPCError("CSRF_TOKEN_MISMATCH", {
244
+ status: 403,
245
+ message: "Invalid CSRF token"
246
+ });
247
+ }
248
+ order = 8e6;
249
+ init(options) {
250
+ options.rootInterceptors ??= [];
251
+ options.clientInterceptors ??= [];
252
+ options.rootInterceptors.unshift(async (options2) => {
253
+ const headerName = await value(this.headerName, options2);
254
+ const headerValue = await value(this.headerValue, options2);
255
+ return options2.next({
256
+ ...options2,
257
+ context: {
258
+ ...options2.context,
259
+ [SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
260
+ }
261
+ });
262
+ });
263
+ options.clientInterceptors.unshift(async (options2) => {
264
+ if (typeof options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL] !== "boolean") {
265
+ throw new TypeError("[SimpleCsrfProtectionHandlerPlugin] CSRF protection context has been corrupted or modified by another plugin or interceptor");
266
+ }
267
+ const excluded = await value(this.exclude, options2);
268
+ if (!excluded && !options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]) {
269
+ throw this.error;
270
+ }
271
+ return options2.next();
99
272
  });
100
273
  }
101
274
  }
102
275
 
103
- export { CORSPlugin, ResponseHeadersPlugin };
276
+ export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
@@ -0,0 +1,12 @@
1
+ import { C as Context } from './server.CYNGeoCm.js';
2
+ import { b as StandardHandleOptions } from './server.Bmh5xd4n.js';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+ declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
10
+
11
+ export { resolveFriendlyStandardHandleOptions as r };
12
+ export type { FriendlyStandardHandleOptions as F };
@@ -0,0 +1,12 @@
1
+ import { C as Context } from './server.CYNGeoCm.mjs';
2
+ import { b as StandardHandleOptions } from './server.gqRxT-yN.mjs';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+ declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
10
+
11
+ export { resolveFriendlyStandardHandleOptions as r };
12
+ export type { FriendlyStandardHandleOptions as F };
@@ -0,0 +1,32 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { b as AnyRouter, C as Context, R as Router } from './server.CYNGeoCm.mjs';
3
+ import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.gqRxT-yN.mjs';
4
+ import { HTTPPath } from '@orpc/client';
5
+ import { Value } from '@orpc/shared';
6
+ import { T as TraverseContractProcedureCallbackOptions } from './server.DhJj-1X9.mjs';
7
+
8
+ interface StandardRPCMatcherOptions {
9
+ /**
10
+ * Filter procedures. Return `false` to exclude a procedure from matching.
11
+ *
12
+ * @default true
13
+ */
14
+ filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
15
+ }
16
+ declare class StandardRPCMatcher implements StandardMatcher {
17
+ private readonly filter;
18
+ private readonly tree;
19
+ private pendingRouters;
20
+ constructor(options?: StandardRPCMatcherOptions);
21
+ init(router: AnyRouter, path?: readonly string[]): void;
22
+ match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
23
+ }
24
+
25
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions, StandardRPCMatcherOptions {
26
+ }
27
+ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
28
+ constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
29
+ }
30
+
31
+ export { StandardRPCHandler as a, StandardRPCMatcher as c };
32
+ export type { StandardRPCHandlerOptions as S, StandardRPCMatcherOptions as b };
@@ -0,0 +1,36 @@
1
+ import { ORPCError, fallbackContractConfig } from '@orpc/contract';
2
+
3
+ const STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL = Symbol("STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT");
4
+ class StrictGetMethodPlugin {
5
+ error;
6
+ order = 7e6;
7
+ constructor(options = {}) {
8
+ this.error = options.error ?? new ORPCError("METHOD_NOT_SUPPORTED");
9
+ }
10
+ init(options) {
11
+ options.rootInterceptors ??= [];
12
+ options.clientInterceptors ??= [];
13
+ options.rootInterceptors.unshift((options2) => {
14
+ const isGetMethod = options2.request.method === "GET";
15
+ return options2.next({
16
+ ...options2,
17
+ context: {
18
+ ...options2.context,
19
+ [STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL]: isGetMethod
20
+ }
21
+ });
22
+ });
23
+ options.clientInterceptors.unshift((options2) => {
24
+ if (typeof options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] !== "boolean") {
25
+ throw new TypeError("[StrictGetMethodPlugin] strict GET method context has been corrupted or modified by another plugin or interceptor");
26
+ }
27
+ const procedureMethod = fallbackContractConfig("defaultMethod", options2.procedure["~orpc"].route.method);
28
+ if (options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] && procedureMethod !== "GET") {
29
+ throw this.error;
30
+ }
31
+ return options2.next();
32
+ });
33
+ }
34
+ }
35
+
36
+ export { StrictGetMethodPlugin as S };
@@ -0,0 +1,74 @@
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta } from '@orpc/contract';
3
+ import { Interceptor } from '@orpc/shared';
4
+ import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
+ import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.CYNGeoCm.js';
6
+
7
+ interface StandardHandlerPlugin<T extends Context> {
8
+ order?: number;
9
+ init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
10
+ }
11
+ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
12
+ protected readonly plugins: TPlugin[];
13
+ constructor(plugins?: readonly TPlugin[]);
14
+ init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
15
+ }
16
+
17
+ type StandardParams = Record<string, string>;
18
+ type StandardMatchResult = {
19
+ path: readonly string[];
20
+ procedure: AnyProcedure;
21
+ params?: StandardParams;
22
+ } | undefined;
23
+ interface StandardMatcher {
24
+ init(router: AnyRouter): void;
25
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
26
+ }
27
+ interface StandardCodec {
28
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
29
+ encodeError(error: ORPCError<any, any>): StandardResponse;
30
+ decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
31
+ }
32
+
33
+ interface StandardHandleOptions<T extends Context> {
34
+ prefix?: HTTPPath;
35
+ context: T;
36
+ }
37
+ type StandardHandleResult = {
38
+ matched: true;
39
+ response: StandardResponse;
40
+ } | {
41
+ matched: false;
42
+ response: undefined;
43
+ };
44
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
45
+ request: StandardLazyRequest;
46
+ }
47
+ interface StandardHandlerOptions<TContext extends Context> {
48
+ plugins?: StandardHandlerPlugin<TContext>[];
49
+ /**
50
+ * Interceptors at the request level, helpful when you want catch errors
51
+ */
52
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
53
+ /**
54
+ * Interceptors at the root level, helpful when you want override the request/response
55
+ */
56
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
57
+ /**
58
+ *
59
+ * Interceptors for procedure client.
60
+ */
61
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
62
+ }
63
+ declare class StandardHandler<T extends Context> {
64
+ private readonly matcher;
65
+ private readonly codec;
66
+ private readonly interceptors;
67
+ private readonly clientInterceptors;
68
+ private readonly rootInterceptors;
69
+ constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
70
+ handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
71
+ }
72
+
73
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as f };
74
+ export type { StandardCodec as S, StandardParams as a, StandardHandleOptions as b, StandardHandleResult as c, StandardHandlerInterceptorOptions as d, StandardHandlerOptions as e, StandardHandlerPlugin as g, StandardMatchResult as h, StandardMatcher as i };
@@ -0,0 +1,20 @@
1
+ import '@orpc/client';
2
+ import '@orpc/shared';
3
+ import '@orpc/standard-server';
4
+ import '@orpc/contract';
5
+ import '@orpc/client/standard';
6
+ import { r as resolveFriendlyStandardHandleOptions } from './server.DZ5BIITo.mjs';
7
+
8
+ async function handleStandardServerPeerMessage(handler, peer, message, options) {
9
+ const [id, request] = await peer.message(message);
10
+ if (!request) {
11
+ return;
12
+ }
13
+ const { response } = await handler.handle(
14
+ { ...request, body: () => Promise.resolve(request.body) },
15
+ resolveFriendlyStandardHandleOptions(options)
16
+ );
17
+ await peer.response(id, response ?? { status: 404, headers: {}, body: "No procedure matched" });
18
+ }
19
+
20
+ export { handleStandardServerPeerMessage as h };