@orpc/server 2.0.0-beta.30 → 2.0.0-beta.31

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.
@@ -1,7 +1,7 @@
1
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 { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.D9VprDph.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DpUGXBi2.mjs';
5
5
  import '@orpc/client';
6
6
  import '@standardserver/core';
7
7
  import '../../shared/server.CkButhNT.mjs';
@@ -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.D9VprDph.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DpUGXBi2.mjs';
5
5
  import '@orpc/client';
6
6
  import '@standardserver/core';
7
7
  import '../../shared/server.CkButhNT.mjs';
@@ -1,7 +1,7 @@
1
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 { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.D9VprDph.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DpUGXBi2.mjs';
5
5
  import '@orpc/client';
6
6
  import '@standardserver/core';
7
7
  import '../../shared/server.CkButhNT.mjs';
@@ -2,7 +2,7 @@ export { R as BodyLimitPlugin } from '../../shared/server.Cd4Z1hpV.mjs';
2
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 { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.D9VprDph.mjs';
5
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DpUGXBi2.mjs';
6
6
  import '@orpc/client';
7
7
  import '@standardserver/core';
8
8
  import '../../shared/server.CkButhNT.mjs';
@@ -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.D9VprDph.mjs';
5
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DpUGXBi2.mjs';
6
6
  import '@orpc/client';
7
7
  import '@standardserver/core';
8
8
  import '../../shared/server.CkButhNT.mjs';
@@ -2,7 +2,7 @@ export { R as BodyLimitPlugin } from '../../shared/server.Cd4Z1hpV.mjs';
2
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 { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.D9VprDph.mjs';
5
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DpUGXBi2.mjs';
6
6
  import '@orpc/client';
7
7
  import '@standardserver/core';
8
8
  import '@standardserver/fetch';
@@ -1,4 +1,4 @@
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.D9VprDph.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.DpUGXBi2.mjs';
2
2
  export { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
3
3
  import '@orpc/client';
4
4
  import '@orpc/shared';
@@ -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.D9VprDph.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DpUGXBi2.mjs';
5
5
  import '@orpc/client';
6
6
  import '@standardserver/core';
7
7
  import '../../shared/server.CkButhNT.mjs';
package/dist/index.d.mts CHANGED
@@ -314,7 +314,7 @@ declare class Builder<TInitialContext extends Context, TErrorMap extends ErrorMa
314
314
  * Overrides the procedure configuration, such as disabling runtime
315
315
  * input/output validation.
316
316
  *
317
- * @see {@link https://orpc.dev/docs/advanced/validation-customization | Validation Customization}
317
+ * @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
318
318
  */
319
319
  $config(config: ProcedureConfig): Builder<TInitialContext, TErrorMap>;
320
320
  /**
package/dist/index.d.ts CHANGED
@@ -314,7 +314,7 @@ declare class Builder<TInitialContext extends Context, TErrorMap extends ErrorMa
314
314
  * Overrides the procedure configuration, such as disabling runtime
315
315
  * input/output validation.
316
316
  *
317
- * @see {@link https://orpc.dev/docs/advanced/validation-customization | Validation Customization}
317
+ * @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
318
318
  */
319
319
  $config(config: ProcedureConfig): Builder<TInitialContext, TErrorMap>;
320
320
  /**
package/dist/index.mjs CHANGED
@@ -119,7 +119,7 @@ class Builder {
119
119
  * Overrides the procedure configuration, such as disabling runtime
120
120
  * input/output validation.
121
121
  *
122
- * @see {@link https://orpc.dev/docs/advanced/validation-customization | Validation Customization}
122
+ * @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
123
123
  */
124
124
  $config(config) {
125
125
  return new Builder({
@@ -24,7 +24,8 @@ interface BatchHandlerPluginOptions<T extends Context> {
24
24
  /**
25
25
  * Map each subrequest in the batch before it is processed.
26
26
  *
27
- * @default merges the batch request headers into the subrequest and remove `orpc-batch` header to prevent nested batching
27
+ * @default merges the batch request headers into the subrequest, giving them priority over
28
+ * the subrequest headers, and removes the `orpc-batch` header to prevent nested batching
28
29
  */
29
30
  mapSubrequest?: (subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest;
30
31
  /**
@@ -92,18 +93,16 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
92
93
  interface CORSHandlerPluginOptions<T extends Context> {
93
94
  /**
94
95
  * Configures the `Access-Control-Allow-Origin` header.
95
- * Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
96
+ * Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
96
97
  *
97
- * @default (origin) => origin
98
+ * @default '*'
98
99
  */
99
- origin?: Value<string | readonly string[] | null | undefined, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
100
+ origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
100
101
  /**
101
102
  * Configures the `Timing-Allow-Origin` header.
102
- * Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
103
- *
104
- * @default undefined
103
+ * Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
105
104
  */
106
- timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
105
+ timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
107
106
  /**
108
107
  * Configures the `Access-Control-Allow-Methods` header for preflight requests.
109
108
  *
@@ -113,26 +112,18 @@ interface CORSHandlerPluginOptions<T extends Context> {
113
112
  /**
114
113
  * Configures the `Access-Control-Allow-Headers` header for preflight requests.
115
114
  * Falls back to the request's `Access-Control-Request-Headers` if not set.
116
- *
117
- * @default undefined
118
115
  */
119
116
  allowHeaders?: readonly string[];
120
117
  /**
121
118
  * Configures the `Access-Control-Max-Age` header (in seconds) for preflight requests.
122
- *
123
- * @default undefined
124
119
  */
125
120
  maxAge?: number;
126
121
  /**
127
122
  * Configures the `Access-Control-Allow-Credentials` header.
128
- *
129
- * @default undefined
130
123
  */
131
124
  credentials?: boolean;
132
125
  /**
133
126
  * Configures the `Access-Control-Expose-Headers` header.
134
- *
135
- * @default undefined
136
127
  */
137
128
  exposeHeaders?: readonly string[];
138
129
  }
@@ -24,7 +24,8 @@ interface BatchHandlerPluginOptions<T extends Context> {
24
24
  /**
25
25
  * Map each subrequest in the batch before it is processed.
26
26
  *
27
- * @default merges the batch request headers into the subrequest and remove `orpc-batch` header to prevent nested batching
27
+ * @default merges the batch request headers into the subrequest, giving them priority over
28
+ * the subrequest headers, and removes the `orpc-batch` header to prevent nested batching
28
29
  */
29
30
  mapSubrequest?: (subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest;
30
31
  /**
@@ -92,18 +93,16 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
92
93
  interface CORSHandlerPluginOptions<T extends Context> {
93
94
  /**
94
95
  * Configures the `Access-Control-Allow-Origin` header.
95
- * Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
96
+ * Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
96
97
  *
97
- * @default (origin) => origin
98
+ * @default '*'
98
99
  */
99
- origin?: Value<string | readonly string[] | null | undefined, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
100
+ origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
100
101
  /**
101
102
  * Configures the `Timing-Allow-Origin` header.
102
- * Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
103
- *
104
- * @default undefined
103
+ * Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
105
104
  */
106
- timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
105
+ timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
107
106
  /**
108
107
  * Configures the `Access-Control-Allow-Methods` header for preflight requests.
109
108
  *
@@ -113,26 +112,18 @@ interface CORSHandlerPluginOptions<T extends Context> {
113
112
  /**
114
113
  * Configures the `Access-Control-Allow-Headers` header for preflight requests.
115
114
  * Falls back to the request's `Access-Control-Request-Headers` if not set.
116
- *
117
- * @default undefined
118
115
  */
119
116
  allowHeaders?: readonly string[];
120
117
  /**
121
118
  * Configures the `Access-Control-Max-Age` header (in seconds) for preflight requests.
122
- *
123
- * @default undefined
124
119
  */
125
120
  maxAge?: number;
126
121
  /**
127
122
  * Configures the `Access-Control-Allow-Credentials` header.
128
- *
129
- * @default undefined
130
123
  */
131
124
  credentials?: boolean;
132
125
  /**
133
126
  * Configures the `Access-Control-Expose-Headers` header.
134
- *
135
- * @default undefined
136
127
  */
137
128
  exposeHeaders?: readonly string[];
138
129
  }
@@ -24,8 +24,13 @@ class BatchHandlerPlugin {
24
24
  this.mapSubrequest = options.mapSubrequest ?? ((subRequest, { request: batchRequest }) => ({
25
25
  ...subRequest,
26
26
  headers: {
27
- ...batchRequest.headers,
28
27
  ...subRequest.headers,
28
+ /**
29
+ * The batch request headers win over the subrequest ones. They are the only ones the
30
+ * transport actually saw, so headers the browser injects on its own, such as `cookie`
31
+ * or `origin`, cannot be overridden by a subrequest, which is just request payload.
32
+ */
33
+ ...batchRequest.headers,
29
34
  "orpc-batch": void 0
30
35
  // useful in case batch plugin is used multiple times
31
36
  }
@@ -215,7 +220,7 @@ class CORSHandlerPlugin {
215
220
  after = ["~opentelemetry", "~batch"];
216
221
  constructor(options = {}) {
217
222
  const defaults = {
218
- origin: (origin) => origin,
223
+ origin: "*",
219
224
  allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "QUERY"]
220
225
  };
221
226
  this.options = {
@@ -231,7 +236,7 @@ class CORSHandlerPlugin {
231
236
  }
232
237
  const resHeaders = { ...result.response.headers };
233
238
  const origin = flattenStandardHeader(interceptorOptions.request.headers.origin);
234
- const allowedOrigins = toArray(value(this.options.origin, origin, interceptorOptions));
239
+ const allowedOrigins = toArray(await value(this.options.origin, origin, interceptorOptions));
235
240
  if (allowedOrigins.includes("*")) {
236
241
  resHeaders["access-control-allow-origin"] = "*";
237
242
  } else {
@@ -243,7 +248,7 @@ class CORSHandlerPlugin {
243
248
  resHeaders.vary = existingVary ? `${existingVary}, Origin` : "Origin";
244
249
  }
245
250
  }
246
- const allowedTimingOrigins = toArray(value(this.options.timingOrigin, origin, interceptorOptions));
251
+ const allowedTimingOrigins = toArray(await value(this.options.timingOrigin, origin, interceptorOptions));
247
252
  if (allowedTimingOrigins.includes("*")) {
248
253
  resHeaders["timing-allow-origin"] = "*";
249
254
  } else if (origin !== void 0 && allowedTimingOrigins.includes(origin)) {
@@ -1,5 +1,5 @@
1
1
  import { ORPCError, toORPCError, RPCSerializer, COMMON_ERROR_STATUS_MAP } from '@orpc/client';
2
- import { sortPlugins, getOpenTelemetryConfig, runWithSpan, toArray, matchesHttpPathPrefix, intercept, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, recordSpanError, pathToHttpPath, normalizeHttpPath, value, parseEmptyableJSON } from '@orpc/shared';
2
+ import { sortPlugins, getOpenTelemetryConfig, runWithSpan, toArray, matchesHttpPathPrefix, intercept, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, recordSpanError, pathToHttpPath, normalizeHttpPath, value, parseEmptyableJSON, getOwn } from '@orpc/shared';
3
3
  import { flattenStandardHeader, parseStandardUrl } from '@standardserver/core';
4
4
  import { c as createProcedureClient, u as unlazy, P as Procedure } from './server.CkButhNT.mjs';
5
5
  import { w as walkProcedureContractsSync, g as getRouter, c as createContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.Dh77P3ii.mjs';
@@ -292,7 +292,7 @@ class RPCHandlerCodec {
292
292
  };
293
293
  }
294
294
  encodeError(error, _procedure, _path, _options) {
295
- const status = this.errorStatusMap[error.code] ?? DEFAULT_ERROR_STATUS;
295
+ const status = getOwn(this.errorStatusMap, error.code) ?? DEFAULT_ERROR_STATUS;
296
296
  return {
297
297
  headers: {},
298
298
  status,
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.30",
4
+ "version": "2.0.0-beta.31",
5
5
  "description": "Build typesafe APIs with oRPC: RPC and OpenAPI support, middleware, and adapters for Node.js, Bun, Deno, Fetch, Fastify, WebSocket, AWS Lambda, and more",
6
6
  "license": "MIT",
7
7
  "funding": [
@@ -124,9 +124,9 @@
124
124
  "@standardserver/node": "^0.8.0",
125
125
  "@standardserver/peer": "^0.8.0",
126
126
  "cookie": "^2.0.1",
127
- "@orpc/client": "2.0.0-beta.30",
128
- "@orpc/shared": "2.0.0-beta.30",
129
- "@orpc/contract": "2.0.0-beta.30"
127
+ "@orpc/contract": "2.0.0-beta.31",
128
+ "@orpc/client": "2.0.0-beta.31",
129
+ "@orpc/shared": "2.0.0-beta.31"
130
130
  },
131
131
  "devDependencies": {
132
132
  "crossws": "^0.4.6",