@orpc/server 0.0.0-next.df486d6 → 0.0.0-next.e000d9a

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 (39) hide show
  1. package/README.md +14 -17
  2. package/dist/adapters/bun-ws/index.d.mts +35 -0
  3. package/dist/adapters/bun-ws/index.d.ts +35 -0
  4. package/dist/adapters/bun-ws/index.mjs +51 -0
  5. package/dist/adapters/crossws/index.d.mts +30 -0
  6. package/dist/adapters/crossws/index.d.ts +30 -0
  7. package/dist/adapters/crossws/index.mjs +51 -0
  8. package/dist/adapters/fetch/index.d.mts +25 -6
  9. package/dist/adapters/fetch/index.d.ts +25 -6
  10. package/dist/adapters/fetch/index.mjs +8 -3
  11. package/dist/adapters/node/index.d.mts +25 -6
  12. package/dist/adapters/node/index.d.ts +25 -6
  13. package/dist/adapters/node/index.mjs +8 -3
  14. package/dist/adapters/standard/index.d.mts +4 -4
  15. package/dist/adapters/standard/index.d.ts +4 -4
  16. package/dist/adapters/standard/index.mjs +4 -5
  17. package/dist/adapters/websocket/index.d.mts +27 -0
  18. package/dist/adapters/websocket/index.d.ts +27 -0
  19. package/dist/adapters/websocket/index.mjs +38 -0
  20. package/dist/adapters/ws/index.d.mts +28 -0
  21. package/dist/adapters/ws/index.d.ts +28 -0
  22. package/dist/adapters/ws/index.mjs +38 -0
  23. package/dist/index.d.mts +545 -8
  24. package/dist/index.d.ts +545 -8
  25. package/dist/index.mjs +117 -6
  26. package/dist/plugins/index.d.mts +33 -2
  27. package/dist/plugins/index.d.ts +33 -2
  28. package/dist/plugins/index.mjs +6 -7
  29. package/dist/shared/{server.DFuJLDuo.mjs → server.4FnxLwwr.mjs} +11 -15
  30. package/dist/shared/{server.BuLPHTX1.d.mts → server.BRoxSiSC.d.mts} +3 -9
  31. package/dist/shared/{server.DMhSfHk1.d.ts → server.BjiJH9Vo.d.ts} +2 -2
  32. package/dist/shared/{server.D_vpYits.d.ts → server.Cy1vfSiG.d.ts} +3 -9
  33. package/dist/shared/{server.C37gDhSZ.mjs → server.DG7Tamti.mjs} +3 -0
  34. package/dist/shared/{server.BVHsfJ99.d.mts → server.DPWk5pjW.d.mts} +51 -3
  35. package/dist/shared/{server.BVHsfJ99.d.ts → server.DPWk5pjW.d.ts} +51 -3
  36. package/dist/shared/{server.Dwnm6cSk.d.mts → server.QUe9N8P4.d.mts} +2 -2
  37. package/dist/shared/{server.B1oIHH_j.d.mts → server.YZzrREz9.d.ts} +4 -4
  38. package/dist/shared/{server.CaWivVk3.d.ts → server.eWLxY3lq.d.mts} +4 -4
  39. package/package.json +45 -8
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
2
2
  export { ValidationError, eventIterator, type } from '@orpc/contract';
3
- import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure, g as getRouter } from './shared/server.C37gDhSZ.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, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.C37gDhSZ.mjs';
3
+ import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure, g as getRouter } 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, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.DG7Tamti.mjs';
5
5
  import { toORPCError } from '@orpc/client';
6
6
  export { ORPCError, isDefinedError, safe } from '@orpc/client';
7
7
  export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
@@ -50,6 +50,9 @@ function createActionableClient(client) {
50
50
  try {
51
51
  return [null, await client(input)];
52
52
  } catch (error) {
53
+ if (error instanceof Error && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_")) {
54
+ throw error;
55
+ }
53
56
  return [toORPCError(error).toJSON(), void 0];
54
57
  }
55
58
  };
@@ -57,18 +60,38 @@ function createActionableClient(client) {
57
60
  }
58
61
 
59
62
  class DecoratedProcedure extends Procedure {
63
+ /**
64
+ * Adds type-safe custom errors.
65
+ * The provided errors are spared-merged with any existing errors.
66
+ *
67
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
68
+ */
60
69
  errors(errors) {
61
70
  return new DecoratedProcedure({
62
71
  ...this["~orpc"],
63
72
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
64
73
  });
65
74
  }
75
+ /**
76
+ * Sets or updates the metadata.
77
+ * The provided metadata is spared-merged with any existing metadata.
78
+ *
79
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
80
+ */
66
81
  meta(meta) {
67
82
  return new DecoratedProcedure({
68
83
  ...this["~orpc"],
69
84
  meta: mergeMeta(this["~orpc"].meta, meta)
70
85
  });
71
86
  }
87
+ /**
88
+ * Sets or updates the route definition.
89
+ * The provided route is spared-merged with any existing route.
90
+ * This option is typically relevant when integrating with OpenAPI.
91
+ *
92
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
93
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
94
+ */
72
95
  route(route) {
73
96
  return new DecoratedProcedure({
74
97
  ...this["~orpc"],
@@ -84,6 +107,8 @@ class DecoratedProcedure extends Procedure {
84
107
  }
85
108
  /**
86
109
  * Make this procedure callable (works like a function while still being a procedure).
110
+ *
111
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
87
112
  */
88
113
  callable(...rest) {
89
114
  const client = createProcedureClient(this, ...rest);
@@ -98,6 +123,8 @@ class DecoratedProcedure extends Procedure {
98
123
  }
99
124
  /**
100
125
  * Make this procedure compatible with server action.
126
+ *
127
+ * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
101
128
  */
102
129
  actionable(...rest) {
103
130
  const action = createActionableClient(createProcedureClient(this, ...rest));
@@ -113,12 +140,18 @@ class DecoratedProcedure extends Procedure {
113
140
  }
114
141
 
115
142
  class Builder {
143
+ /**
144
+ * This property holds the defined options.
145
+ */
116
146
  "~orpc";
117
147
  constructor(def) {
118
148
  this["~orpc"] = def;
119
149
  }
120
150
  /**
121
- * Reset config
151
+ * Sets or overrides the config.
152
+ *
153
+ * @see {@link https://orpc.unnoq.com/docs/lifecycle#middlewares-order Middlewares Order Docs}
154
+ * @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
122
155
  */
123
156
  $config(config) {
124
157
  const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
@@ -132,7 +165,9 @@ class Builder {
132
165
  });
133
166
  }
134
167
  /**
135
- * Reset initial context
168
+ * Set or override the initial context.
169
+ *
170
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
136
171
  */
137
172
  $context() {
138
173
  return new Builder({
@@ -143,7 +178,9 @@ class Builder {
143
178
  });
144
179
  }
145
180
  /**
146
- * Reset initial meta
181
+ * Sets or overrides the initial meta.
182
+ *
183
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
147
184
  */
148
185
  $meta(initialMeta) {
149
186
  return new Builder({
@@ -152,7 +189,11 @@ class Builder {
152
189
  });
153
190
  }
154
191
  /**
155
- * Reset initial route
192
+ * Sets or overrides the initial route.
193
+ * This option is typically relevant when integrating with OpenAPI.
194
+ *
195
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
196
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
156
197
  */
157
198
  $route(initialRoute) {
158
199
  return new Builder({
@@ -160,15 +201,31 @@ class Builder {
160
201
  route: initialRoute
161
202
  });
162
203
  }
204
+ /**
205
+ * Sets or overrides the initial input schema.
206
+ *
207
+ * @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
208
+ */
163
209
  $input(initialInputSchema) {
164
210
  return new Builder({
165
211
  ...this["~orpc"],
166
212
  inputSchema: initialInputSchema
167
213
  });
168
214
  }
215
+ /**
216
+ * Creates a middleware.
217
+ *
218
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
219
+ */
169
220
  middleware(middleware) {
170
221
  return decorateMiddleware(middleware);
171
222
  }
223
+ /**
224
+ * Adds type-safe custom errors.
225
+ * The provided errors are spared-merged with any existing errors.
226
+ *
227
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
228
+ */
172
229
  errors(errors) {
173
230
  return new Builder({
174
231
  ...this["~orpc"],
@@ -182,18 +239,37 @@ class Builder {
182
239
  middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
183
240
  });
184
241
  }
242
+ /**
243
+ * Sets or updates the metadata.
244
+ * The provided metadata is spared-merged with any existing metadata.
245
+ *
246
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
247
+ */
185
248
  meta(meta) {
186
249
  return new Builder({
187
250
  ...this["~orpc"],
188
251
  meta: mergeMeta(this["~orpc"].meta, meta)
189
252
  });
190
253
  }
254
+ /**
255
+ * Sets or updates the route definition.
256
+ * The provided route is spared-merged with any existing route.
257
+ * This option is typically relevant when integrating with OpenAPI.
258
+ *
259
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
260
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
261
+ */
191
262
  route(route) {
192
263
  return new Builder({
193
264
  ...this["~orpc"],
194
265
  route: mergeRoute(this["~orpc"].route, route)
195
266
  });
196
267
  }
268
+ /**
269
+ * Defines the input validation schema.
270
+ *
271
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
272
+ */
197
273
  input(schema) {
198
274
  return new Builder({
199
275
  ...this["~orpc"],
@@ -201,6 +277,11 @@ class Builder {
201
277
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
202
278
  });
203
279
  }
280
+ /**
281
+ * Defines the output validation schema.
282
+ *
283
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
284
+ */
204
285
  output(schema) {
205
286
  return new Builder({
206
287
  ...this["~orpc"],
@@ -208,27 +289,57 @@ class Builder {
208
289
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
209
290
  });
210
291
  }
292
+ /**
293
+ * Defines the handler of the procedure.
294
+ *
295
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
296
+ */
211
297
  handler(handler) {
212
298
  return new DecoratedProcedure({
213
299
  ...this["~orpc"],
214
300
  handler
215
301
  });
216
302
  }
303
+ /**
304
+ * Prefixes all procedures in the router.
305
+ * The provided prefix is post-appended to any existing router prefix.
306
+ *
307
+ * @note This option does not affect procedures that do not define a path in their route definition.
308
+ *
309
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
310
+ */
217
311
  prefix(prefix) {
218
312
  return new Builder({
219
313
  ...this["~orpc"],
220
314
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
221
315
  });
222
316
  }
317
+ /**
318
+ * Adds tags to all procedures in the router.
319
+ * This helpful when you want to group procedures together in the OpenAPI specification.
320
+ *
321
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
322
+ */
223
323
  tag(...tags) {
224
324
  return new Builder({
225
325
  ...this["~orpc"],
226
326
  tags: mergeTags(this["~orpc"].tags, tags)
227
327
  });
228
328
  }
329
+ /**
330
+ * Applies all of the previously defined options to the specified router.
331
+ *
332
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
333
+ */
229
334
  router(router) {
230
335
  return enhanceRouter(router, this["~orpc"]);
231
336
  }
337
+ /**
338
+ * Create a lazy router
339
+ * And applies all of the previously defined options to the specified router.
340
+ *
341
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
342
+ */
232
343
  lazy(loader) {
233
344
  return enhanceRouter(lazy(loader), this["~orpc"]);
234
345
  }
@@ -1,8 +1,8 @@
1
1
  import { Value } from '@orpc/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
3
  import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.B1oIHH_j.mjs';
5
- import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.BVHsfJ99.mjs';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.eWLxY3lq.mjs';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DPWk5pjW.mjs';
6
6
  import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
7
  import { ORPCError } from '@orpc/client';
8
8
 
@@ -32,6 +32,12 @@ interface BatchHandlerOptions<T extends Context> {
32
32
  */
33
33
  headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
34
  }
35
+ /**
36
+ * The Batch Request/Response 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-request-response Batch Request/Response Plugin Docs}
40
+ */
35
41
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
42
  private readonly maxSize;
37
43
  private readonly mapRequestItem;
@@ -51,6 +57,11 @@ interface CORSOptions<T extends Context> {
51
57
  credentials?: boolean;
52
58
  exposeHeaders?: readonly string[];
53
59
  }
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
+ */
54
65
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
55
66
  private readonly options;
56
67
  order: number;
@@ -61,6 +72,12 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
61
72
  interface ResponseHeadersPluginContext {
62
73
  resHeaders?: Headers;
63
74
  }
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
+ */
64
81
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
65
82
  init(options: StandardHandlerOptions<T>): void;
66
83
  }
@@ -96,6 +113,13 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
96
113
  */
97
114
  error?: InstanceType<typeof ORPCError>;
98
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
+ */
99
123
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
124
  private readonly headerName;
101
125
  private readonly headerValue;
@@ -114,6 +138,13 @@ interface StrictGetMethodPluginOptions {
114
138
  */
115
139
  error?: InstanceType<typeof ORPCError$1>;
116
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
+ */
117
148
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
149
  private readonly error;
119
150
  order: number;
@@ -1,8 +1,8 @@
1
1
  import { Value } from '@orpc/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@orpc/standard-server';
3
3
  import { BatchResponseBodyItem } from '@orpc/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CaWivVk3.js';
5
- import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.BVHsfJ99.js';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.YZzrREz9.js';
5
+ import { C as Context, F as ProcedureClientInterceptorOptions } from '../shared/server.DPWk5pjW.js';
6
6
  import { Meta, ORPCError as ORPCError$1 } from '@orpc/contract';
7
7
  import { ORPCError } from '@orpc/client';
8
8
 
@@ -32,6 +32,12 @@ interface BatchHandlerOptions<T extends Context> {
32
32
  */
33
33
  headers?: Value<StandardHeaders, [responses: Promise<BatchResponseBodyItem>[], batchOptions: StandardHandlerInterceptorOptions<T>]>;
34
34
  }
35
+ /**
36
+ * The Batch Request/Response 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-request-response Batch Request/Response Plugin Docs}
40
+ */
35
41
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
42
  private readonly maxSize;
37
43
  private readonly mapRequestItem;
@@ -51,6 +57,11 @@ interface CORSOptions<T extends Context> {
51
57
  credentials?: boolean;
52
58
  exposeHeaders?: readonly string[];
53
59
  }
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
+ */
54
65
  declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
55
66
  private readonly options;
56
67
  order: number;
@@ -61,6 +72,12 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
61
72
  interface ResponseHeadersPluginContext {
62
73
  resHeaders?: Headers;
63
74
  }
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
+ */
64
81
  declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
65
82
  init(options: StandardHandlerOptions<T>): void;
66
83
  }
@@ -96,6 +113,13 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
96
113
  */
97
114
  error?: InstanceType<typeof ORPCError>;
98
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
+ */
99
123
  declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
100
124
  private readonly headerName;
101
125
  private readonly headerValue;
@@ -114,6 +138,13 @@ interface StrictGetMethodPluginOptions {
114
138
  */
115
139
  error?: InstanceType<typeof ORPCError$1>;
116
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
+ */
117
148
  declare class StrictGetMethodPlugin<T extends Context> implements StandardHandlerPlugin<T> {
118
149
  private readonly error;
119
150
  order: number;
@@ -1,5 +1,6 @@
1
1
  import { value, isAsyncIteratorObject } from '@orpc/shared';
2
2
  import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
3
+ import { flattenHeader } from '@orpc/standard-server';
3
4
  import { ORPCError } from '@orpc/client';
4
5
  export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
5
6
  import '@orpc/contract';
@@ -123,13 +124,11 @@ class CORSPlugin {
123
124
  resHeaders["access-control-max-age"] = this.options.maxAge.toString();
124
125
  }
125
126
  if (this.options.allowMethods?.length) {
126
- resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
127
+ resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
127
128
  }
128
129
  const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
129
- if (Array.isArray(allowHeaders) && allowHeaders.length) {
130
- resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
131
- } else if (typeof allowHeaders === "string") {
132
- resHeaders["access-control-allow-headers"] = allowHeaders;
130
+ if (typeof allowHeaders === "string" || allowHeaders?.length) {
131
+ resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
133
132
  }
134
133
  return {
135
134
  matched: true,
@@ -147,7 +146,7 @@ class CORSPlugin {
147
146
  if (!result.matched) {
148
147
  return result;
149
148
  }
150
- const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
149
+ const origin = flattenHeader(interceptorOptions.request.headers.origin) ?? "";
151
150
  const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
152
151
  const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
153
152
  if (allowedOriginArr.includes("*")) {
@@ -169,7 +168,7 @@ class CORSPlugin {
169
168
  result.response.headers["access-control-allow-credentials"] = "true";
170
169
  }
171
170
  if (this.options.exposeHeaders?.length) {
172
- result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
171
+ result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
173
172
  }
174
173
  return result;
175
174
  });
@@ -1,18 +1,17 @@
1
1
  import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
2
- import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
3
- import '@orpc/standard-server/batch';
4
2
  import { ORPCError, toORPCError } from '@orpc/client';
5
- import { S as StrictGetMethodPlugin } from './server.BW-nUGgA.mjs';
6
- import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.C37gDhSZ.mjs';
3
+ import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
4
+ import { flattenHeader } from '@orpc/standard-server';
5
+ import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.DG7Tamti.mjs';
7
6
 
8
7
  class CompositeStandardHandlerPlugin {
9
8
  plugins;
10
9
  constructor(plugins = []) {
11
10
  this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
12
11
  }
13
- init(options) {
12
+ init(options, router) {
14
13
  for (const plugin of this.plugins) {
15
- plugin.init?.(options);
14
+ plugin.init?.(options, router);
16
15
  }
17
16
  }
18
17
  }
@@ -22,7 +21,7 @@ class StandardHandler {
22
21
  this.matcher = matcher;
23
22
  this.codec = codec;
24
23
  const plugins = new CompositeStandardHandlerPlugin(options.plugins);
25
- plugins.init(options);
24
+ plugins.init(options, router);
26
25
  this.interceptors = toArray(options.interceptors);
27
26
  this.clientInterceptors = toArray(options.clientInterceptors);
28
27
  this.rootInterceptors = toArray(options.rootInterceptors);
@@ -61,8 +60,10 @@ class StandardHandler {
61
60
  isDecoding = true;
62
61
  const input = await this.codec.decode(request2, match.params, match.procedure);
63
62
  isDecoding = false;
64
- const lastEventId = Array.isArray(request2.headers["last-event-id"]) ? request2.headers["last-event-id"].at(-1) : request2.headers["last-event-id"];
65
- const output = await client(input, { signal: request2.signal, lastEventId });
63
+ const output = await client(input, {
64
+ signal: request2.signal,
65
+ lastEventId: flattenHeader(request2.headers["last-event-id"])
66
+ });
66
67
  const response = this.codec.encode(output, match.procedure);
67
68
  return {
68
69
  matched: true,
@@ -173,12 +174,7 @@ class StandardRPCMatcher {
173
174
  }
174
175
 
175
176
  class StandardRPCHandler extends StandardHandler {
176
- constructor(router, options) {
177
- options.plugins ??= [];
178
- const strictGetMethodPluginEnabled = options.strictGetMethodPluginEnabled ?? true;
179
- if (strictGetMethodPluginEnabled) {
180
- options.plugins.push(new StrictGetMethodPlugin());
181
- }
177
+ constructor(router, options = {}) {
182
178
  const jsonSerializer = new StandardRPCJsonSerializer(options);
183
179
  const serializer = new StandardRPCSerializer(jsonSerializer);
184
180
  const matcher = new StandardRPCMatcher();
@@ -1,17 +1,11 @@
1
1
  import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
- import { C as Context, R as Router } from './server.BVHsfJ99.mjs';
3
- import { b as StandardHandlerOptions, i as StandardHandler } from './server.B1oIHH_j.mjs';
2
+ import { C as Context, R as Router } from './server.DPWk5pjW.mjs';
3
+ import { b as StandardHandlerOptions, i as StandardHandler } from './server.eWLxY3lq.mjs';
4
4
 
5
5
  interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
- /**
7
- * Enables or disables the StrictGetMethodPlugin.
8
- *
9
- * @default true
10
- */
11
- strictGetMethodPluginEnabled?: boolean;
12
6
  }
13
7
  declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
14
- constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
8
+ constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
15
9
  }
16
10
 
17
11
  export { StandardRPCHandler as a };
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.BVHsfJ99.js';
2
- import { g as StandardHandleOptions } from './server.CaWivVk3.js';
1
+ import { C as Context } from './server.DPWk5pjW.js';
2
+ import { g as StandardHandleOptions } from './server.YZzrREz9.js';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
@@ -1,17 +1,11 @@
1
1
  import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
- import { C as Context, R as Router } from './server.BVHsfJ99.js';
3
- import { b as StandardHandlerOptions, i as StandardHandler } from './server.CaWivVk3.js';
2
+ import { C as Context, R as Router } from './server.DPWk5pjW.js';
3
+ import { b as StandardHandlerOptions, i as StandardHandler } from './server.YZzrREz9.js';
4
4
 
5
5
  interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
- /**
7
- * Enables or disables the StrictGetMethodPlugin.
8
- *
9
- * @default true
10
- */
11
- strictGetMethodPluginEnabled?: boolean;
12
6
  }
13
7
  declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
14
- constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
8
+ constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
15
9
  }
16
10
 
17
11
  export { StandardRPCHandler as a };
@@ -46,6 +46,9 @@ function addMiddleware(middlewares, addition) {
46
46
  }
47
47
 
48
48
  class Procedure {
49
+ /**
50
+ * This property holds the defined options.
51
+ */
49
52
  "~orpc";
50
53
  constructor(def) {
51
54
  this["~orpc"] = def;