@orpc/server 0.0.0-next.9e880d7 → 0.0.0-next.9f1bc8b

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 (59) hide show
  1. package/README.md +26 -22
  2. package/dist/adapters/aws-lambda/index.d.mts +45 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +45 -0
  4. package/dist/adapters/aws-lambda/index.mjs +41 -0
  5. package/dist/adapters/bun-ws/index.d.mts +35 -0
  6. package/dist/adapters/bun-ws/index.d.ts +35 -0
  7. package/dist/adapters/bun-ws/index.mjs +46 -0
  8. package/dist/adapters/crossws/index.d.mts +30 -0
  9. package/dist/adapters/crossws/index.d.ts +30 -0
  10. package/dist/adapters/crossws/index.mjs +46 -0
  11. package/dist/adapters/fetch/index.d.mts +61 -11
  12. package/dist/adapters/fetch/index.d.ts +61 -11
  13. package/dist/adapters/fetch/index.mjs +109 -8
  14. package/dist/adapters/message-port/index.d.mts +28 -0
  15. package/dist/adapters/message-port/index.d.ts +28 -0
  16. package/dist/adapters/message-port/index.mjs +41 -0
  17. package/dist/adapters/node/index.d.mts +63 -22
  18. package/dist/adapters/node/index.d.ts +63 -22
  19. package/dist/adapters/node/index.mjs +87 -24
  20. package/dist/adapters/standard/index.d.mts +6 -6
  21. package/dist/adapters/standard/index.d.ts +6 -6
  22. package/dist/adapters/standard/index.mjs +4 -3
  23. package/dist/adapters/websocket/index.d.mts +27 -0
  24. package/dist/adapters/websocket/index.d.ts +27 -0
  25. package/dist/adapters/websocket/index.mjs +39 -0
  26. package/dist/adapters/ws/index.d.mts +28 -0
  27. package/dist/adapters/ws/index.d.ts +28 -0
  28. package/dist/adapters/ws/index.mjs +39 -0
  29. package/dist/index.d.mts +603 -47
  30. package/dist/index.d.ts +603 -47
  31. package/dist/index.mjs +163 -17
  32. package/dist/plugins/index.d.mts +141 -16
  33. package/dist/plugins/index.d.ts +141 -16
  34. package/dist/plugins/index.mjs +164 -14
  35. package/dist/shared/server.-ACo36I0.d.ts +74 -0
  36. package/dist/shared/server.BPAWobQg.d.ts +12 -0
  37. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  38. package/dist/shared/server.Bd52nNaH.d.mts +12 -0
  39. package/dist/shared/server.BliFSTnG.d.mts +10 -0
  40. package/dist/shared/{server.jG7ZuX3S.mjs → server.CHvOkcM3.mjs} +57 -29
  41. package/dist/shared/{server.BYTulgUc.d.mts → server.DD2C4ujN.d.mts} +64 -16
  42. package/dist/shared/{server.BYTulgUc.d.ts → server.DD2C4ujN.d.ts} +64 -16
  43. package/dist/shared/{server.BtxZnWJ9.mjs → server.DG7Tamti.mjs} +22 -29
  44. package/dist/shared/server.DZ5BIITo.mjs +9 -0
  45. package/dist/shared/server.Dq8xr7PQ.d.mts +74 -0
  46. package/dist/shared/server.IG2MjhrD.d.ts +10 -0
  47. package/package.json +54 -20
  48. package/dist/adapters/hono/index.d.mts +0 -21
  49. package/dist/adapters/hono/index.d.ts +0 -21
  50. package/dist/adapters/hono/index.mjs +0 -32
  51. package/dist/adapters/next/index.d.mts +0 -28
  52. package/dist/adapters/next/index.d.ts +0 -28
  53. package/dist/adapters/next/index.mjs +0 -29
  54. package/dist/shared/server.B3Tm0IXY.d.ts +0 -75
  55. package/dist/shared/server.BeJithK4.d.mts +0 -75
  56. package/dist/shared/server.Bz_xNBjz.d.mts +0 -8
  57. package/dist/shared/server.DoP20NVH.mjs +0 -29
  58. package/dist/shared/server.EhgR_5_I.d.ts +0 -8
  59. package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
package/dist/index.mjs CHANGED
@@ -1,9 +1,11 @@
1
- import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
1
+ import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
2
2
  export { ValidationError, eventIterator, type } from '@orpc/contract';
3
- import { P as Procedure, d as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, f as isLazy, h as createAssertedLazyProcedure, g as getRouter } from './shared/server.BtxZnWJ9.mjs';
4
- export { L as LAZY_SYMBOL, q as call, w as createAccessibleLazyRouter, b as createContractedProcedure, j as createORPCErrorConstructorMap, r as getHiddenRouterContract, k as getLazyMeta, o as isStartWithMiddlewares, m as mergeCurrentContext, p as mergeMiddlewares, n as middlewareOutputFn, x as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, y as unlazyRouter, v as validateORPCError } from './shared/server.BtxZnWJ9.mjs';
3
+ import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.DG7Tamti.mjs';
4
+ export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, x as unlazyRouter, v as validateORPCError } from './shared/server.DG7Tamti.mjs';
5
+ import { toORPCError } from '@orpc/client';
5
6
  export { ORPCError, isDefinedError, safe } from '@orpc/client';
6
- export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
7
+ import { resolveMaybeOptionalOptions } from '@orpc/shared';
8
+ export { EventPublisher, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
7
9
  export { getEventMeta, withEventMeta } from '@orpc/standard-server';
8
10
 
9
11
  const DEFAULT_CONFIG = {
@@ -44,19 +46,53 @@ function decorateMiddleware(middleware) {
44
46
  return decorated;
45
47
  }
46
48
 
49
+ function createActionableClient(client) {
50
+ const action = async (input) => {
51
+ try {
52
+ return [null, await client(input)];
53
+ } catch (error) {
54
+ if (error instanceof Error && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_")) {
55
+ throw error;
56
+ }
57
+ return [toORPCError(error).toJSON(), void 0];
58
+ }
59
+ };
60
+ return action;
61
+ }
62
+
47
63
  class DecoratedProcedure extends Procedure {
64
+ /**
65
+ * Adds type-safe custom errors.
66
+ * The provided errors are spared-merged with any existing errors.
67
+ *
68
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
69
+ */
48
70
  errors(errors) {
49
71
  return new DecoratedProcedure({
50
72
  ...this["~orpc"],
51
73
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
52
74
  });
53
75
  }
76
+ /**
77
+ * Sets or updates the metadata.
78
+ * The provided metadata is spared-merged with any existing metadata.
79
+ *
80
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
81
+ */
54
82
  meta(meta) {
55
83
  return new DecoratedProcedure({
56
84
  ...this["~orpc"],
57
85
  meta: mergeMeta(this["~orpc"].meta, meta)
58
86
  });
59
87
  }
88
+ /**
89
+ * Sets or updates the route definition.
90
+ * The provided route is spared-merged with any existing route.
91
+ * This option is typically relevant when integrating with OpenAPI.
92
+ *
93
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
94
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
95
+ */
60
96
  route(route) {
61
97
  return new DecoratedProcedure({
62
98
  ...this["~orpc"],
@@ -72,9 +108,12 @@ class DecoratedProcedure extends Procedure {
72
108
  }
73
109
  /**
74
110
  * Make this procedure callable (works like a function while still being a procedure).
111
+ *
112
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
75
113
  */
76
114
  callable(...rest) {
77
- return new Proxy(createProcedureClient(this, ...rest), {
115
+ const client = createProcedureClient(this, ...rest);
116
+ return new Proxy(client, {
78
117
  get: (target, key) => {
79
118
  return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
80
119
  },
@@ -84,20 +123,36 @@ class DecoratedProcedure extends Procedure {
84
123
  });
85
124
  }
86
125
  /**
87
- * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
126
+ * Make this procedure compatible with server action.
127
+ *
128
+ * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
88
129
  */
89
130
  actionable(...rest) {
90
- return this.callable(...rest);
131
+ const action = createActionableClient(createProcedureClient(this, ...rest));
132
+ return new Proxy(action, {
133
+ get: (target, key) => {
134
+ return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
135
+ },
136
+ has: (target, key) => {
137
+ return Reflect.has(this, key) || Reflect.has(target, key);
138
+ }
139
+ });
91
140
  }
92
141
  }
93
142
 
94
143
  class Builder {
144
+ /**
145
+ * This property holds the defined options.
146
+ */
95
147
  "~orpc";
96
148
  constructor(def) {
97
149
  this["~orpc"] = def;
98
150
  }
99
151
  /**
100
- * Reset config
152
+ * Sets or overrides the config.
153
+ *
154
+ * @see {@link https://orpc.unnoq.com/docs/lifecycle#middlewares-order Middlewares Order Docs}
155
+ * @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
101
156
  */
102
157
  $config(config) {
103
158
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
@@ -111,7 +166,9 @@ class Builder {
111
166
  });
112
167
  }
113
168
  /**
114
- * Reset initial context
169
+ * Set or override the initial context.
170
+ *
171
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
115
172
  */
116
173
  $context() {
117
174
  return new Builder({
@@ -122,7 +179,9 @@ class Builder {
122
179
  });
123
180
  }
124
181
  /**
125
- * Reset initial meta
182
+ * Sets or overrides the initial meta.
183
+ *
184
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
126
185
  */
127
186
  $meta(initialMeta) {
128
187
  return new Builder({
@@ -131,7 +190,11 @@ class Builder {
131
190
  });
132
191
  }
133
192
  /**
134
- * Reset initial route
193
+ * Sets or overrides the initial route.
194
+ * This option is typically relevant when integrating with OpenAPI.
195
+ *
196
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
197
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
135
198
  */
136
199
  $route(initialRoute) {
137
200
  return new Builder({
@@ -139,15 +202,31 @@ class Builder {
139
202
  route: initialRoute
140
203
  });
141
204
  }
205
+ /**
206
+ * Sets or overrides the initial input schema.
207
+ *
208
+ * @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
209
+ */
142
210
  $input(initialInputSchema) {
143
211
  return new Builder({
144
212
  ...this["~orpc"],
145
213
  inputSchema: initialInputSchema
146
214
  });
147
215
  }
216
+ /**
217
+ * Creates a middleware.
218
+ *
219
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
220
+ */
148
221
  middleware(middleware) {
149
222
  return decorateMiddleware(middleware);
150
223
  }
224
+ /**
225
+ * Adds type-safe custom errors.
226
+ * The provided errors are spared-merged with any existing errors.
227
+ *
228
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
229
+ */
151
230
  errors(errors) {
152
231
  return new Builder({
153
232
  ...this["~orpc"],
@@ -161,18 +240,37 @@ class Builder {
161
240
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
162
241
  });
163
242
  }
243
+ /**
244
+ * Sets or updates the metadata.
245
+ * The provided metadata is spared-merged with any existing metadata.
246
+ *
247
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
248
+ */
164
249
  meta(meta) {
165
250
  return new Builder({
166
251
  ...this["~orpc"],
167
252
  meta: mergeMeta(this["~orpc"].meta, meta)
168
253
  });
169
254
  }
255
+ /**
256
+ * Sets or updates the route definition.
257
+ * The provided route is spared-merged with any existing route.
258
+ * This option is typically relevant when integrating with OpenAPI.
259
+ *
260
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
261
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
262
+ */
170
263
  route(route) {
171
264
  return new Builder({
172
265
  ...this["~orpc"],
173
266
  route: mergeRoute(this["~orpc"].route, route)
174
267
  });
175
268
  }
269
+ /**
270
+ * Defines the input validation schema.
271
+ *
272
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
273
+ */
176
274
  input(schema) {
177
275
  return new Builder({
178
276
  ...this["~orpc"],
@@ -180,6 +278,11 @@ class Builder {
180
278
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
181
279
  });
182
280
  }
281
+ /**
282
+ * Defines the output validation schema.
283
+ *
284
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
285
+ */
183
286
  output(schema) {
184
287
  return new Builder({
185
288
  ...this["~orpc"],
@@ -187,27 +290,57 @@ class Builder {
187
290
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
188
291
  });
189
292
  }
293
+ /**
294
+ * Defines the handler of the procedure.
295
+ *
296
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
297
+ */
190
298
  handler(handler) {
191
299
  return new DecoratedProcedure({
192
300
  ...this["~orpc"],
193
301
  handler
194
302
  });
195
303
  }
304
+ /**
305
+ * Prefixes all procedures in the router.
306
+ * The provided prefix is post-appended to any existing router prefix.
307
+ *
308
+ * @note This option does not affect procedures that do not define a path in their route definition.
309
+ *
310
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
311
+ */
196
312
  prefix(prefix) {
197
313
  return new Builder({
198
314
  ...this["~orpc"],
199
315
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
200
316
  });
201
317
  }
318
+ /**
319
+ * Adds tags to all procedures in the router.
320
+ * This helpful when you want to group procedures together in the OpenAPI specification.
321
+ *
322
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
323
+ */
202
324
  tag(...tags) {
203
325
  return new Builder({
204
326
  ...this["~orpc"],
205
327
  tags: mergeTags(this["~orpc"].tags, tags)
206
328
  });
207
329
  }
330
+ /**
331
+ * Applies all of the previously defined options to the specified router.
332
+ *
333
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
334
+ */
208
335
  router(router) {
209
336
  return enhanceRouter(router, this["~orpc"]);
210
337
  }
338
+ /**
339
+ * Create a lazy router
340
+ * And applies all of the previously defined options to the specified router.
341
+ *
342
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
343
+ */
211
344
  lazy(loader) {
212
345
  return enhanceRouter(lazy(loader), this["~orpc"]);
213
346
  }
@@ -315,12 +448,25 @@ function implement(contract, config = {}) {
315
448
  return impl;
316
449
  }
317
450
 
318
- function createRouterClient(router, ...[options]) {
451
+ function inferRPCMethodFromRouter(router) {
452
+ return async (_, path) => {
453
+ const { default: procedure } = await unlazy(getRouter(router, path));
454
+ if (!isProcedure(procedure)) {
455
+ throw new Error(
456
+ `[inferRPCMethodFromRouter] No valid procedure found at path "${path.join(".")}". This may happen when the router is not properly configured.`
457
+ );
458
+ }
459
+ const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
460
+ return method === "HEAD" ? "GET" : method;
461
+ };
462
+ }
463
+
464
+ function createRouterClient(router, ...rest) {
319
465
  if (isProcedure(router)) {
320
- const caller = createProcedureClient(router, options);
466
+ const caller = createProcedureClient(router, resolveMaybeOptionalOptions(rest));
321
467
  return caller;
322
468
  }
323
- const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
469
+ const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), resolveMaybeOptionalOptions(rest)) : {};
324
470
  const recursive = new Proxy(procedureCaller, {
325
471
  get(target, key) {
326
472
  if (typeof key !== "string") {
@@ -331,12 +477,12 @@ function createRouterClient(router, ...[options]) {
331
477
  return Reflect.get(target, key);
332
478
  }
333
479
  return createRouterClient(next, {
334
- ...options,
335
- path: [...options?.path ?? [], key]
480
+ ...rest[0],
481
+ path: [...rest[0]?.path ?? [], key]
336
482
  });
337
483
  }
338
484
  });
339
485
  return recursive;
340
486
  }
341
487
 
342
- export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
488
+ export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isLazy, isProcedure, lazy, os, setHiddenRouterContract, unlazy };
@@ -1,31 +1,156 @@
1
- import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.BeJithK4.mjs';
2
- export { C as CompositePlugin } from '../shared/server.BeJithK4.mjs';
3
- import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.BYTulgUc.mjs';
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 { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.Dq8xr7PQ.mjs';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DD2C4ujN.mjs';
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;
22
70
  }
23
71
 
24
72
  interface ResponseHeadersPluginContext {
25
73
  resHeaders?: Headers;
26
74
  }
27
- declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
- init(options: StandardHandlerOptions<TContext>): void;
75
+ /**
76
+ * The Response Headers Plugin allows you to set response headers in oRPC.
77
+ * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
78
+ *
79
+ * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
80
+ */
81
+ declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
82
+ init(options: StandardHandlerOptions<T>): void;
83
+ }
84
+
85
+ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
86
+ /**
87
+ * The name of the header to check.
88
+ *
89
+ * @default 'x-csrf-token'
90
+ */
91
+ headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
92
+ /**
93
+ * The value of the header to check.
94
+ *
95
+ * @default 'orpc'
96
+ *
97
+ */
98
+ headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
99
+ /**
100
+ * Exclude a procedure from the plugin.
101
+ *
102
+ * @default false
103
+ *
104
+ */
105
+ exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>]>;
106
+ /**
107
+ * The error thrown when the CSRF token is invalid.
108
+ *
109
+ * @default new ORPCError('CSRF_TOKEN_MISMATCH', {
110
+ * status: 403,
111
+ * message: 'Invalid CSRF token',
112
+ * })
113
+ */
114
+ error?: InstanceType<typeof ORPCError>;
115
+ }
116
+ /**
117
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
118
+ * It helps ensure that requests to your procedures originate from JavaScript code,
119
+ * not from other sources like standard HTML forms or direct browser navigation.
120
+ *
121
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
122
+ */
123
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
124
+ private readonly headerName;
125
+ private readonly headerValue;
126
+ private readonly exclude;
127
+ private readonly error;
128
+ constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
129
+ order: number;
130
+ init(options: StandardHandlerOptions<T>): void;
131
+ }
132
+
133
+ interface StrictGetMethodPluginOptions {
134
+ /**
135
+ * The error thrown when a GET request is made to a procedure that doesn't allow GET.
136
+ *
137
+ * @default new ORPCError('METHOD_NOT_SUPPORTED')
138
+ */
139
+ error?: InstanceType<typeof ORPCError$1>;
140
+ }
141
+ /**
142
+ * This plugin enhances security by ensuring only procedures explicitly marked to accept GET requests
143
+ * can be called using the HTTP GET method for RPC Protocol. This helps prevent certain types of
144
+ * Cross-Site Request Forgery (CSRF) attacks.
145
+ *
146
+ * @see {@link https://orpc.unnoq.com/docs/plugins/strict-get-method Strict Get Method Plugin Docs}
147
+ */
148
+ declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
149
+ private readonly error;
150
+ order: number;
151
+ constructor(options?: StrictGetMethodPluginOptions);
152
+ init(options: StandardHandlerOptions<T>): void;
29
153
  }
30
154
 
31
- export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
155
+ export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin, StrictGetMethodPlugin };
156
+ export type { BatchHandlerOptions, CORSOptions, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions, StrictGetMethodPluginOptions };