@orpc/server 2.0.0-beta.24 → 2.0.0-beta.25

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 (32) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +1 -12
  2. package/dist/adapters/aws-lambda/index.d.ts +1 -12
  3. package/dist/adapters/aws-lambda/index.mjs +2 -9
  4. package/dist/adapters/crossws/index.d.mts +1 -1
  5. package/dist/adapters/crossws/index.d.ts +1 -1
  6. package/dist/adapters/crossws/index.mjs +1 -1
  7. package/dist/adapters/fastify/index.d.mts +1 -12
  8. package/dist/adapters/fastify/index.d.ts +1 -12
  9. package/dist/adapters/fastify/index.mjs +2 -9
  10. package/dist/adapters/fetch/index.d.mts +1 -12
  11. package/dist/adapters/fetch/index.d.ts +1 -12
  12. package/dist/adapters/fetch/index.mjs +2 -9
  13. package/dist/adapters/message-port/index.d.mts +1 -1
  14. package/dist/adapters/message-port/index.d.ts +1 -1
  15. package/dist/adapters/message-port/index.mjs +1 -1
  16. package/dist/adapters/node/index.d.mts +1 -12
  17. package/dist/adapters/node/index.d.ts +1 -12
  18. package/dist/adapters/node/index.mjs +2 -9
  19. package/dist/adapters/standard/index.d.mts +1 -1
  20. package/dist/adapters/standard/index.d.ts +1 -1
  21. package/dist/adapters/standard/index.mjs +1 -1
  22. package/dist/adapters/websocket/index.d.mts +1 -1
  23. package/dist/adapters/websocket/index.d.ts +1 -1
  24. package/dist/adapters/websocket/index.mjs +1 -1
  25. package/dist/plugins/index.d.mts +18 -16
  26. package/dist/plugins/index.d.ts +18 -16
  27. package/dist/plugins/index.mjs +27 -3
  28. package/dist/shared/{server.BUvC0G_8.d.ts → server.C2n16pp0.d.ts} +24 -2
  29. package/dist/shared/{server.DEGjTAPW.mjs → server.Cbv46U7N.mjs} +19 -3
  30. package/dist/shared/{server.zySQaS-n.d.mts → server.CkNnZ5F-.d.mts} +24 -2
  31. package/package.json +4 -4
  32. package/dist/shared/server.D_QauotT.mjs +0 -30
@@ -4,7 +4,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.mjs';
4
4
  import { S as StandardHandlerPlugin, b as StandardHandler, c as StandardHandlerHandleOptions, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
5
5
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
6
6
  import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
7
- import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
7
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.CkNnZ5F-.mjs';
8
8
  import '@orpc/client';
9
9
  import '@orpc/contract';
10
10
  import '@standardserver/core';
@@ -75,17 +75,6 @@ declare class AwsLambdaHandler<T extends Context> {
75
75
  }
76
76
 
77
77
  interface RPCHandlerOptions<T extends Context> extends AwsLambdaHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
78
- /**
79
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
80
- */
81
- csrfGuardPlugin?: {
82
- /**
83
- * If `false`, this plugin is disabled.
84
- *
85
- * @default true
86
- */
87
- enabled?: boolean;
88
- };
89
78
  }
90
79
  /**
91
80
  * Serves an oRPC router over the RPC protocol on AWS Lambda,
@@ -4,7 +4,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.js';
4
4
  import { S as StandardHandlerPlugin, b as StandardHandler, c as StandardHandlerHandleOptions, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
5
5
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
6
6
  import { R as Router } from '../../shared/server.DtfwuV6U.js';
7
- import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
7
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.C2n16pp0.js';
8
8
  import '@orpc/client';
9
9
  import '@orpc/contract';
10
10
  import '@standardserver/core';
@@ -75,17 +75,6 @@ declare class AwsLambdaHandler<T extends Context> {
75
75
  }
76
76
 
77
77
  interface RPCHandlerOptions<T extends Context> extends AwsLambdaHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
78
- /**
79
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
80
- */
81
- csrfGuardPlugin?: {
82
- /**
83
- * If `false`, this plugin is disabled.
84
- *
85
- * @default true
86
- */
87
- enabled?: boolean;
88
- };
89
78
  }
90
79
  /**
91
80
  * Serves an oRPC router over the RPC protocol on AWS Lambda,
@@ -1,8 +1,7 @@
1
- import { sortPlugins, intercept, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
1
+ import { sortPlugins, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
2
2
  import { toStandardLazyRequest, sendStandardResponse } from '@standardserver/aws-lambda';
3
3
  import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
4
- import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
5
- import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.Cbv46U7N.mjs';
6
5
  import '@orpc/client';
7
6
  import '@standardserver/core';
8
7
  import '../../shared/server.7T18Khvf.mjs';
@@ -58,12 +57,6 @@ class AwsLambdaHandler {
58
57
 
59
58
  class RPCHandler extends AwsLambdaHandler {
60
59
  constructor(router, options = {}) {
61
- if (options.csrfGuardPlugin?.enabled !== false) {
62
- options = {
63
- ...options,
64
- plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
65
- };
66
- }
67
60
  const codec = new RPCHandlerCodec(router, options);
68
61
  const handler = new StandardHandler(codec, options);
69
62
  super(handler, options);
@@ -5,7 +5,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.mjs';
5
5
  import { b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
6
6
  import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
7
7
  import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.CkNnZ5F-.mjs';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
11
  import '@standardserver/core';
@@ -5,7 +5,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.js';
5
5
  import { b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
6
6
  import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
7
7
  import { R as Router } from '../../shared/server.DtfwuV6U.js';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.C2n16pp0.js';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
11
  import '@standardserver/core';
@@ -1,7 +1,7 @@
1
1
  import { resolveMaybeOptionalOptions } from '@orpc/shared';
2
2
  import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standardserver/peer';
3
3
  import { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
4
- import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.Cbv46U7N.mjs';
5
5
  import '@orpc/client';
6
6
  import '@standardserver/core';
7
7
  import '../../shared/server.7T18Khvf.mjs';
@@ -4,7 +4,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.mjs';
4
4
  import { S as StandardHandlerPlugin, c as StandardHandlerHandleOptions, b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
5
5
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
6
6
  import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
7
- import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
7
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.CkNnZ5F-.mjs';
8
8
  import '@orpc/client';
9
9
  import '@orpc/contract';
10
10
  import '@standardserver/core';
@@ -71,17 +71,6 @@ declare class FastifyHandler<T extends Context> {
71
71
  }
72
72
 
73
73
  interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
74
- /**
75
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
76
- */
77
- csrfGuardPlugin?: {
78
- /**
79
- * If `false`, this plugin is disabled.
80
- *
81
- * @default true
82
- */
83
- enabled?: boolean;
84
- };
85
74
  }
86
75
  /**
87
76
  * Serves an oRPC router over the RPC protocol inside a Fastify server.
@@ -4,7 +4,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.js';
4
4
  import { S as StandardHandlerPlugin, c as StandardHandlerHandleOptions, b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
5
5
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
6
6
  import { R as Router } from '../../shared/server.DtfwuV6U.js';
7
- import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
7
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.C2n16pp0.js';
8
8
  import '@orpc/client';
9
9
  import '@orpc/contract';
10
10
  import '@standardserver/core';
@@ -71,17 +71,6 @@ declare class FastifyHandler<T extends Context> {
71
71
  }
72
72
 
73
73
  interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
74
- /**
75
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
76
- */
77
- csrfGuardPlugin?: {
78
- /**
79
- * If `false`, this plugin is disabled.
80
- *
81
- * @default true
82
- */
83
- enabled?: boolean;
84
- };
85
74
  }
86
75
  /**
87
76
  * Serves an oRPC router over the RPC protocol inside a Fastify server.
@@ -1,8 +1,7 @@
1
- import { sortPlugins, intercept, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
1
+ import { sortPlugins, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
2
2
  import { toStandardLazyRequest, sendStandardResponse } from '@standardserver/fastify';
3
3
  import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
4
- import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
5
- import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.Cbv46U7N.mjs';
6
5
  import '@orpc/client';
7
6
  import '@standardserver/core';
8
7
  import '../../shared/server.7T18Khvf.mjs';
@@ -58,12 +57,6 @@ class FastifyHandler {
58
57
 
59
58
  class RPCHandler extends FastifyHandler {
60
59
  constructor(router, options = {}) {
61
- if (options.csrfGuardPlugin?.enabled !== false) {
62
- options = {
63
- ...options,
64
- plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
65
- };
66
- }
67
60
  const codec = new RPCHandlerCodec(router, options);
68
61
  const handler = new StandardHandler(codec, options);
69
62
  super(handler, options);
@@ -5,7 +5,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.mjs';
5
5
  import { S as StandardHandlerPlugin, c as StandardHandlerHandleOptions, b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
6
6
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
7
7
  import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.CkNnZ5F-.mjs';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
11
  import '@standardserver/core';
@@ -73,17 +73,6 @@ declare class FetchHandler<T extends Context> {
73
73
  }
74
74
 
75
75
  interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
76
- /**
77
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
78
- */
79
- csrfGuardHandlerPlugin?: {
80
- /**
81
- * If `false`, this plugin is disabled.
82
- *
83
- * @default true
84
- */
85
- enabled?: boolean;
86
- };
87
76
  }
88
77
  /**
89
78
  * Serves an oRPC router over the RPC protocol using the Fetch API
@@ -5,7 +5,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.js';
5
5
  import { S as StandardHandlerPlugin, c as StandardHandlerHandleOptions, b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
6
6
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
7
7
  import { R as Router } from '../../shared/server.DtfwuV6U.js';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.C2n16pp0.js';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
11
  import '@standardserver/core';
@@ -73,17 +73,6 @@ declare class FetchHandler<T extends Context> {
73
73
  }
74
74
 
75
75
  interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
76
- /**
77
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
78
- */
79
- csrfGuardHandlerPlugin?: {
80
- /**
81
- * If `false`, this plugin is disabled.
82
- *
83
- * @default true
84
- */
85
- enabled?: boolean;
86
- };
87
76
  }
88
77
  /**
89
78
  * Serves an oRPC router over the RPC protocol using the Fetch API
@@ -1,9 +1,8 @@
1
1
  export { R as BodyLimitPlugin } from '../../shared/server.Cd4Z1hpV.mjs';
2
- import { sortPlugins, intercept, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
2
+ import { sortPlugins, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
3
3
  import { toStandardLazyRequest, toFetchResponse } from '@standardserver/fetch';
4
4
  import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
5
- import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
6
- import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
5
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.Cbv46U7N.mjs';
7
6
  import '@orpc/client';
8
7
  import '@standardserver/core';
9
8
  import '../../shared/server.7T18Khvf.mjs';
@@ -60,12 +59,6 @@ class FetchHandler {
60
59
 
61
60
  class RPCHandler extends FetchHandler {
62
61
  constructor(router, options = {}) {
63
- if (options.csrfGuardHandlerPlugin?.enabled !== false) {
64
- options = {
65
- ...options,
66
- plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
67
- };
68
- }
69
62
  const codec = new RPCHandlerCodec(router, options);
70
63
  const handler = new StandardHandler(codec, options);
71
64
  super(handler, options);
@@ -5,7 +5,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.mjs';
5
5
  import { b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
6
6
  import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
7
7
  import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.CkNnZ5F-.mjs';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
11
  import '@standardserver/core';
@@ -5,7 +5,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.js';
5
5
  import { b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
6
6
  import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
7
7
  import { R as Router } from '../../shared/server.DtfwuV6U.js';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.C2n16pp0.js';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
11
  import '@standardserver/core';
@@ -2,7 +2,7 @@ import { onMessagePortMessage, onMessagePortClose, postMessagePortMessage } from
2
2
  import { value, resolveMaybeOptionalOptions } from '@orpc/shared';
3
3
  import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage, isPeerMessage } from '@standardserver/peer';
4
4
  import { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
5
- import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
5
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.Cbv46U7N.mjs';
6
6
  import '@orpc/client';
7
7
  import '@standardserver/core';
8
8
  import '../../shared/server.7T18Khvf.mjs';
@@ -5,7 +5,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.mjs';
5
5
  import { S as StandardHandlerPlugin, c as StandardHandlerHandleOptions, b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
6
6
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
7
7
  import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.CkNnZ5F-.mjs';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
11
  import '@standardserver/core';
@@ -72,17 +72,6 @@ declare class NodeHttpHandler<T extends Context> {
72
72
  }
73
73
 
74
74
  interface RPCHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
75
- /**
76
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
77
- */
78
- csrfGuardPlugin?: {
79
- /**
80
- * If `false`, this plugin is disabled.
81
- *
82
- * @default true
83
- */
84
- enabled?: boolean;
85
- };
86
75
  }
87
76
  /**
88
77
  * Serves an oRPC router over the RPC protocol using Node.js built-in
@@ -5,7 +5,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.js';
5
5
  import { S as StandardHandlerPlugin, c as StandardHandlerHandleOptions, b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
6
6
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
7
7
  import { R as Router } from '../../shared/server.DtfwuV6U.js';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
8
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.C2n16pp0.js';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
11
  import '@standardserver/core';
@@ -72,17 +72,6 @@ declare class NodeHttpHandler<T extends Context> {
72
72
  }
73
73
 
74
74
  interface RPCHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
75
- /**
76
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
77
- */
78
- csrfGuardPlugin?: {
79
- /**
80
- * If `false`, this plugin is disabled.
81
- *
82
- * @default true
83
- */
84
- enabled?: boolean;
85
- };
86
75
  }
87
76
  /**
88
77
  * Serves an oRPC router over the RPC protocol using Node.js built-in
@@ -1,9 +1,8 @@
1
1
  export { R as BodyLimitPlugin } from '../../shared/server.Cd4Z1hpV.mjs';
2
- import { sortPlugins, intercept, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
2
+ import { sortPlugins, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
3
3
  import { toStandardLazyRequest, sendStandardResponse } from '@standardserver/node';
4
4
  import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
5
- import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
6
- import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
5
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.Cbv46U7N.mjs';
7
6
  import '@orpc/client';
8
7
  import '@standardserver/core';
9
8
  import '@standardserver/fetch';
@@ -60,12 +59,6 @@ class NodeHttpHandler {
60
59
 
61
60
  class RPCHandler extends NodeHttpHandler {
62
61
  constructor(router, options = {}) {
63
- if (options.csrfGuardPlugin?.enabled !== false) {
64
- options = {
65
- ...options,
66
- plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
67
- };
68
- }
69
62
  const codec = new RPCHandlerCodec(router, options);
70
63
  const handler = new StandardHandler(codec, options);
71
64
  super(handler, options);
@@ -1,6 +1,6 @@
1
1
  import { c as StandardHandlerHandleOptions } from '../../shared/server.JbCIPL4P.mjs';
2
2
  export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, b as StandardHandler, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure, h as StandardHandlerHandleResult, i as StandardHandlerInterceptor, g as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, S as StandardHandlerPlugin, j as StandardHandlerRoutingInterceptor, f as StandardHandlerRoutingInterceptorOptions } from '../../shared/server.JbCIPL4P.mjs';
3
- export { a as RPCHandlerCodec, R as RPCHandlerCodecOptions, b as RPCMatcher, c as RPCMatcherOptions } from '../../shared/server.zySQaS-n.mjs';
3
+ export { a as RPCHandlerCodec, R as RPCHandlerCodecOptions, b as RPCMatcher, c as RPCMatcherOptions, d as RPC_DEFAULT_ALLOW_METHODS } from '../../shared/server.CkNnZ5F-.mjs';
4
4
  import { C as Context } from '../../shared/server.CwrYlF72.mjs';
5
5
  export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
6
  import '@orpc/client';
@@ -1,6 +1,6 @@
1
1
  import { c as StandardHandlerHandleOptions } from '../../shared/server.DrN1Pj1-.js';
2
2
  export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, b as StandardHandler, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure, h as StandardHandlerHandleResult, i as StandardHandlerInterceptor, g as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, S as StandardHandlerPlugin, j as StandardHandlerRoutingInterceptor, f as StandardHandlerRoutingInterceptorOptions } from '../../shared/server.DrN1Pj1-.js';
3
- export { a as RPCHandlerCodec, R as RPCHandlerCodecOptions, b as RPCMatcher, c as RPCMatcherOptions } from '../../shared/server.BUvC0G_8.js';
3
+ export { a as RPCHandlerCodec, R as RPCHandlerCodecOptions, b as RPCMatcher, c as RPCMatcherOptions, d as RPC_DEFAULT_ALLOW_METHODS } from '../../shared/server.C2n16pp0.js';
4
4
  import { C as Context } from '../../shared/server.CwrYlF72.js';
5
5
  export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
6
  import '@orpc/client';
@@ -1,4 +1,4 @@
1
- export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, R as RPCHandlerCodec, a as RPCMatcher, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
1
+ export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, R as RPCHandlerCodec, a as RPCMatcher, b as RPC_DEFAULT_ALLOW_METHODS, S as StandardHandler } from '../../shared/server.Cbv46U7N.mjs';
2
2
  export { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
3
3
  import '@orpc/client';
4
4
  import '@orpc/shared';
@@ -4,7 +4,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.mjs';
4
4
  import { b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
5
5
  import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
6
6
  import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
7
- import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
7
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.CkNnZ5F-.mjs';
8
8
  import '@orpc/client';
9
9
  import '@orpc/contract';
10
10
  import '@standardserver/core';
@@ -4,7 +4,7 @@ import { C as Context } from '../../shared/server.CwrYlF72.js';
4
4
  import { b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
5
5
  import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
6
6
  import { R as Router } from '../../shared/server.DtfwuV6U.js';
7
- import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
7
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.C2n16pp0.js';
8
8
  import '@orpc/client';
9
9
  import '@orpc/contract';
10
10
  import '@standardserver/core';
@@ -1,7 +1,7 @@
1
1
  import { toStringOrBytes, resolveMaybeOptionalOptions, sequential, loadBytes } from '@orpc/shared';
2
2
  import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standardserver/peer';
3
3
  import { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
4
- import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.Cbv46U7N.mjs';
5
5
  import '@orpc/client';
6
6
  import '@standardserver/core';
7
7
  import '../../shared/server.7T18Khvf.mjs';
@@ -155,21 +155,6 @@ declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlu
155
155
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
156
156
  }
157
157
 
158
- /**
159
- * Adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
160
- * When a request includes cookies, it helps ensure the request originates from JavaScript
161
- * (for example, fetch/XHR) rather than from standard HTML forms or direct browser navigation.
162
- *
163
- * @remarks
164
- * **Note**: This plugin is enabled by default for `RPCHandler` over HTTP.
165
- *
166
- * @see {@link https://orpc.dev/docs/plugins/csrf-guard | CSRF Guard Plugin}
167
- */
168
- declare class CSRFGuardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
169
- name: string;
170
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
171
- }
172
-
173
158
  /**
174
159
  * Decompresses incoming request bodies based on the Content-Encoding header,
175
160
  * supporting gzip, deflate, and deflate-raw.
@@ -302,5 +287,22 @@ declare class RethrowHandlerPlugin<T extends Context> implements StandardHandler
302
287
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
303
288
  }
304
289
 
305
- export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, CSRFGuardHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin };
290
+ /**
291
+ * Adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
292
+ * When a request includes cookies, it helps ensure the request originates from JavaScript
293
+ * (for example, fetch/XHR) rather than from standard HTML forms or direct browser navigation.
294
+ *
295
+ * @remarks
296
+ * Unlike `SameSite` cookies, this protection also covers cross-site requests that
297
+ * still carry cookies, so it is the recommended safeguard when you enable the `GET`
298
+ * method on RPC handlers or rely on cookie-based authentication.
299
+ *
300
+ * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection | Simple CSRF Protection Plugin}
301
+ */
302
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
303
+ name: string;
304
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
305
+ }
306
+
307
+ export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin, SimpleCsrfProtectionHandlerPlugin };
306
308
  export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, RethrowHandlerPluginOptions };
@@ -155,21 +155,6 @@ declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlu
155
155
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
156
156
  }
157
157
 
158
- /**
159
- * Adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
160
- * When a request includes cookies, it helps ensure the request originates from JavaScript
161
- * (for example, fetch/XHR) rather than from standard HTML forms or direct browser navigation.
162
- *
163
- * @remarks
164
- * **Note**: This plugin is enabled by default for `RPCHandler` over HTTP.
165
- *
166
- * @see {@link https://orpc.dev/docs/plugins/csrf-guard | CSRF Guard Plugin}
167
- */
168
- declare class CSRFGuardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
169
- name: string;
170
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
171
- }
172
-
173
158
  /**
174
159
  * Decompresses incoming request bodies based on the Content-Encoding header,
175
160
  * supporting gzip, deflate, and deflate-raw.
@@ -302,5 +287,22 @@ declare class RethrowHandlerPlugin<T extends Context> implements StandardHandler
302
287
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
303
288
  }
304
289
 
305
- export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, CSRFGuardHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin };
290
+ /**
291
+ * Adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
292
+ * When a request includes cookies, it helps ensure the request originates from JavaScript
293
+ * (for example, fetch/XHR) rather than from standard HTML forms or direct browser navigation.
294
+ *
295
+ * @remarks
296
+ * Unlike `SameSite` cookies, this protection also covers cross-site requests that
297
+ * still carry cookies, so it is the recommended safeguard when you enable the `GET`
298
+ * method on RPC handlers or rely on cookie-based authentication.
299
+ *
300
+ * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection | Simple CSRF Protection Plugin}
301
+ */
302
+ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
303
+ name: string;
304
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
305
+ }
306
+
307
+ export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin, SimpleCsrfProtectionHandlerPlugin };
306
308
  export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, RethrowHandlerPluginOptions };
@@ -1,10 +1,9 @@
1
1
  import { toArray, value, isCompressibleContentType, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
2
2
  import { flattenStandardHeader, parseStandardUrl, generateContentDisposition, mergeStandardHeaders } from '@standardserver/core';
3
3
  import { isClientPeerSendMessage, ServerPeer, encodePeerMessage } from '@standardserver/peer';
4
- export { C as CSRFGuardHandlerPlugin } from '../shared/server.D_QauotT.mjs';
5
4
  import { toFetchHeaders, toStandardBody, toStandardHeaders } from '@standardserver/fetch';
6
5
  export { R as RequestLimitHandlerPlugin } from '../shared/server.Cd4Z1hpV.mjs';
7
- import '@orpc/client';
6
+ import { ORPCError } from '@orpc/client';
8
7
 
9
8
  const BATCH_CONTENT_TYPE = "application/vnd.orpc.batch";
10
9
  class BatchHandlerPlugin {
@@ -633,4 +632,29 @@ class RethrowHandlerPlugin {
633
632
  }
634
633
  }
635
634
 
636
- export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin };
635
+ class SimpleCsrfProtectionHandlerPlugin {
636
+ name = "~simple-csrf-protection";
637
+ init(options) {
638
+ const interceptor = async (interceptorOptions) => {
639
+ const mode = flattenStandardHeader(
640
+ interceptorOptions.request.headers["sec-fetch-mode"]
641
+ )?.toLowerCase();
642
+ if (mode === void 0) {
643
+ return interceptorOptions.next();
644
+ }
645
+ if (mode === "cors" || mode === "same-origin") {
646
+ return interceptorOptions.next();
647
+ }
648
+ throw new ORPCError("FORBIDDEN", {
649
+ message: "Request blocked by CSRF protection."
650
+ });
651
+ };
652
+ return {
653
+ ...options,
654
+ // appended last so user's interceptors can catch ORPCError
655
+ interceptors: [...toArray(options.interceptors), interceptor]
656
+ };
657
+ }
658
+ }
659
+
660
+ export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin, SimpleCsrfProtectionHandlerPlugin };
@@ -6,6 +6,16 @@ import { A as AnyRouter } from './server.DtfwuV6U.js';
6
6
  import { AnyProcedureContract } from '@orpc/contract';
7
7
  import { c as StandardHandlerHandleOptions, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure } from './server.DrN1Pj1-.js';
8
8
 
9
+ /**
10
+ * Methods that can invoke procedures by default. Browsers cannot trigger them
11
+ * cross-site without a CORS preflight or an HTML form, unlike `GET`, which a plain
12
+ * `<a>` click or redirect can trigger with `SameSite=Lax` cookies attached. Other
13
+ * methods (`HEAD`, `OPTIONS`, `QUERY`, ...) have safe semantics that should not
14
+ * invoke a procedure that can modify data.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
17
+ */
18
+ declare const RPC_DEFAULT_ALLOW_METHODS: readonly StandardMethod[];
9
19
  interface RPCMatcherOptions {
10
20
  /**
11
21
  * Filter which procedures are exposed for matching. Return `false` to exclude.
@@ -13,15 +23,27 @@ interface RPCMatcherOptions {
13
23
  * @default true
14
24
  */
15
25
  filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
26
+ /**
27
+ * Restricts which HTTP methods can invoke procedures, either with a list of allowed
28
+ * methods or decided per request via a function. Requests using a disallowed method
29
+ * are treated as unmatched. `GET` is excluded by default because it is exposed to
30
+ * Cross-Site Request Forgery (CSRF) attacks.
31
+ *
32
+ * @default RPC_DEFAULT_ALLOW_METHODS (['POST', 'PUT', 'PATCH', 'DELETE'])
33
+ * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
34
+ */
35
+ allowMethods?: readonly StandardMethod[] | ((method: StandardMethod, procedure: AnyProcedure, path: string[]) => boolean);
16
36
  }
17
37
  declare class RPCMatcher {
18
38
  private readonly filter;
39
+ private readonly allowMethodsSet;
40
+ private readonly allowMethodsFn;
19
41
  private readonly rootRouter;
20
42
  private readonly tree;
21
43
  private readonly pendingLazyRouters;
22
44
  constructor(router: AnyRouter, options?: RPCMatcherOptions);
23
45
  private index;
24
- match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
46
+ match(method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
25
47
  path: string[];
26
48
  procedure: AnyProcedure;
27
49
  } | undefined>;
@@ -65,5 +87,5 @@ declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec
65
87
  encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
66
88
  }
67
89
 
68
- export { RPCHandlerCodec as a, RPCMatcher as b };
90
+ export { RPCHandlerCodec as a, RPCMatcher as b, RPC_DEFAULT_ALLOW_METHODS as d };
69
91
  export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
@@ -121,13 +121,22 @@ class OtelHandlerPlugin {
121
121
  }
122
122
  }
123
123
 
124
+ const RPC_DEFAULT_ALLOW_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
124
125
  class RPCMatcher {
125
126
  filter;
127
+ allowMethodsSet;
128
+ allowMethodsFn;
126
129
  rootRouter;
127
130
  tree = /* @__PURE__ */ new Map();
128
131
  pendingLazyRouters = /* @__PURE__ */ new Map();
129
132
  constructor(router, options = {}) {
130
133
  this.filter = options.filter ?? true;
134
+ const allowMethods = options.allowMethods ?? RPC_DEFAULT_ALLOW_METHODS;
135
+ if (typeof allowMethods !== "function") {
136
+ this.allowMethodsSet = new Set(allowMethods);
137
+ } else {
138
+ this.allowMethodsFn = allowMethods;
139
+ }
131
140
  this.rootRouter = router;
132
141
  this.index(router);
133
142
  }
@@ -147,7 +156,10 @@ class RPCMatcher {
147
156
  this.pendingLazyRouters.set(pathToHttpPath(result.path), result);
148
157
  }
149
158
  }
150
- async match(_method, pathname, prefix) {
159
+ async match(method, pathname, prefix) {
160
+ if (this.allowMethodsSet && !this.allowMethodsSet.has(method)) {
161
+ return void 0;
162
+ }
151
163
  if (pathname.length > 1 && pathname.endsWith("/")) {
152
164
  pathname = pathname.slice(0, -1);
153
165
  }
@@ -182,9 +194,13 @@ class RPCMatcher {
182
194
  if (entry === void 0) {
183
195
  return void 0;
184
196
  }
197
+ const procedure = entry.procedure ?? await this.resolveProcedure(entry);
198
+ if (this.allowMethodsFn && !this.allowMethodsFn(method, procedure, entry.path)) {
199
+ return void 0;
200
+ }
185
201
  return {
186
202
  path: entry.path,
187
- procedure: entry.procedure ?? await this.resolveProcedure(entry)
203
+ procedure
188
204
  };
189
205
  }
190
206
  resolvePendingLazyRouters(pathname) {
@@ -285,4 +301,4 @@ class RPCHandlerCodec {
285
301
  }
286
302
  }
287
303
 
288
- export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, RPCHandlerCodec as R, StandardHandler as S, RPCMatcher as a };
304
+ export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, RPCHandlerCodec as R, StandardHandler as S, RPCMatcher as a, RPC_DEFAULT_ALLOW_METHODS as b };
@@ -6,6 +6,16 @@ import { A as AnyRouter } from './server.Dm0os-OP.mjs';
6
6
  import { AnyProcedureContract } from '@orpc/contract';
7
7
  import { c as StandardHandlerHandleOptions, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure } from './server.JbCIPL4P.mjs';
8
8
 
9
+ /**
10
+ * Methods that can invoke procedures by default. Browsers cannot trigger them
11
+ * cross-site without a CORS preflight or an HTML form, unlike `GET`, which a plain
12
+ * `<a>` click or redirect can trigger with `SameSite=Lax` cookies attached. Other
13
+ * methods (`HEAD`, `OPTIONS`, `QUERY`, ...) have safe semantics that should not
14
+ * invoke a procedure that can modify data.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
17
+ */
18
+ declare const RPC_DEFAULT_ALLOW_METHODS: readonly StandardMethod[];
9
19
  interface RPCMatcherOptions {
10
20
  /**
11
21
  * Filter which procedures are exposed for matching. Return `false` to exclude.
@@ -13,15 +23,27 @@ interface RPCMatcherOptions {
13
23
  * @default true
14
24
  */
15
25
  filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
26
+ /**
27
+ * Restricts which HTTP methods can invoke procedures, either with a list of allowed
28
+ * methods or decided per request via a function. Requests using a disallowed method
29
+ * are treated as unmatched. `GET` is excluded by default because it is exposed to
30
+ * Cross-Site Request Forgery (CSRF) attacks.
31
+ *
32
+ * @default RPC_DEFAULT_ALLOW_METHODS (['POST', 'PUT', 'PATCH', 'DELETE'])
33
+ * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
34
+ */
35
+ allowMethods?: readonly StandardMethod[] | ((method: StandardMethod, procedure: AnyProcedure, path: string[]) => boolean);
16
36
  }
17
37
  declare class RPCMatcher {
18
38
  private readonly filter;
39
+ private readonly allowMethodsSet;
40
+ private readonly allowMethodsFn;
19
41
  private readonly rootRouter;
20
42
  private readonly tree;
21
43
  private readonly pendingLazyRouters;
22
44
  constructor(router: AnyRouter, options?: RPCMatcherOptions);
23
45
  private index;
24
- match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
46
+ match(method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
25
47
  path: string[];
26
48
  procedure: AnyProcedure;
27
49
  } | undefined>;
@@ -65,5 +87,5 @@ declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec
65
87
  encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
66
88
  }
67
89
 
68
- export { RPCHandlerCodec as a, RPCMatcher as b };
90
+ export { RPCHandlerCodec as a, RPCMatcher as b, RPC_DEFAULT_ALLOW_METHODS as d };
69
91
  export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.24",
4
+ "version": "2.0.0-beta.25",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.dev",
7
7
  "repository": {
@@ -106,9 +106,9 @@
106
106
  "@standardserver/node": "^0.7.1",
107
107
  "@standardserver/peer": "^0.7.1",
108
108
  "cookie": "^2.0.1",
109
- "@orpc/client": "2.0.0-beta.24",
110
- "@orpc/contract": "2.0.0-beta.24",
111
- "@orpc/shared": "2.0.0-beta.24"
109
+ "@orpc/client": "2.0.0-beta.25",
110
+ "@orpc/contract": "2.0.0-beta.25",
111
+ "@orpc/shared": "2.0.0-beta.25"
112
112
  },
113
113
  "devDependencies": {
114
114
  "crossws": "^0.4.6",
@@ -1,30 +0,0 @@
1
- import { ORPCError } from '@orpc/client';
2
- import { toArray } from '@orpc/shared';
3
- import { flattenStandardHeader } from '@standardserver/core';
4
-
5
- class CSRFGuardHandlerPlugin {
6
- name = "~csrf-guard";
7
- init(options) {
8
- const interceptor = async (interceptorOptions) => {
9
- const mode = flattenStandardHeader(
10
- interceptorOptions.request.headers["sec-fetch-mode"]
11
- )?.toLowerCase();
12
- if (mode === void 0) {
13
- return interceptorOptions.next();
14
- }
15
- if (mode === "cors" || mode === "same-origin") {
16
- return interceptorOptions.next();
17
- }
18
- throw new ORPCError("FORBIDDEN", {
19
- message: "Request blocked by CSRF protection."
20
- });
21
- };
22
- return {
23
- ...options,
24
- // appended last so user's interceptors can catch ORPCError
25
- interceptors: [...toArray(options.interceptors), interceptor]
26
- };
27
- }
28
- }
29
-
30
- export { CSRFGuardHandlerPlugin as C };