@trpc/server 10.38.0 → 10.38.2

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 (31) hide show
  1. package/dist/adapters/aws-lambda/index.js +1 -1
  2. package/dist/adapters/aws-lambda/index.mjs +1 -1
  3. package/dist/adapters/express.js +2 -2
  4. package/dist/adapters/express.mjs +2 -2
  5. package/dist/adapters/fastify/index.js +1 -1
  6. package/dist/adapters/fastify/index.mjs +1 -1
  7. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  8. package/dist/adapters/fetch/index.js +2 -2
  9. package/dist/adapters/fetch/index.mjs +2 -2
  10. package/dist/adapters/next.js +2 -2
  11. package/dist/adapters/next.mjs +2 -2
  12. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
  13. package/dist/adapters/node-http/content-type/json/index.js +2 -2
  14. package/dist/adapters/node-http/content-type/json/index.mjs +2 -2
  15. package/dist/adapters/node-http/index.js +2 -2
  16. package/dist/adapters/node-http/index.mjs +2 -2
  17. package/dist/adapters/standalone.js +2 -2
  18. package/dist/adapters/standalone.mjs +2 -2
  19. package/dist/http/index.js +1 -1
  20. package/dist/http/index.mjs +1 -1
  21. package/dist/{nodeHTTPRequestHandler-34adf7b8.js → nodeHTTPRequestHandler-4ca02710.js} +1 -1
  22. package/dist/{nodeHTTPRequestHandler-842a1461.mjs → nodeHTTPRequestHandler-a3cc8c22.mjs} +1 -1
  23. package/dist/{nodeHTTPRequestHandler-b7bc691f.js → nodeHTTPRequestHandler-d42348fa.js} +1 -1
  24. package/dist/{resolveHTTPResponse-3aef2178.mjs → resolveHTTPResponse-67085326.mjs} +10 -1
  25. package/dist/{resolveHTTPResponse-d6110ed7.js → resolveHTTPResponse-a885ce7b.js} +10 -1
  26. package/dist/{resolveHTTPResponse-11792475.js → resolveHTTPResponse-d21ca7c2.js} +10 -1
  27. package/package.json +3 -3
  28. package/src/adapters/fetch/fetchRequestHandler.ts +3 -4
  29. package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -1
  30. package/src/adapters/node-http/content-type/json/index.ts +1 -1
  31. package/src/http/resolveHTTPResponse.ts +11 -1
@@ -6,7 +6,7 @@ var TRPCError = require('../../TRPCError-d07099d1.js');
6
6
  require('../../index-784ff647.js');
7
7
  require('../../codes-87f6824b.js');
8
8
  require('../../config-3156a1f1.js');
9
- var resolveHTTPResponse = require('../../resolveHTTPResponse-11792475.js');
9
+ var resolveHTTPResponse = require('../../resolveHTTPResponse-d21ca7c2.js');
10
10
  require('../../transformTRPCResponse-e65f34e9.js');
11
11
  require('../../contentType-5b601838.js');
12
12
 
@@ -2,7 +2,7 @@ import { T as TRPCError } from '../../TRPCError-6a1653a4.mjs';
2
2
  import '../../index-f91d720c.mjs';
3
3
  import '../../codes-c924c3db.mjs';
4
4
  import '../../config-cd32070b.mjs';
5
- import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-3aef2178.mjs';
5
+ import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-67085326.mjs';
6
6
  import '../../transformTRPCResponse-1153b421.mjs';
7
7
  import '../../contentType-53e30af8.mjs';
8
8
 
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-34adf7b8.js');
5
+ var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-4ca02710.js');
6
6
  require('../index-784ff647.js');
7
7
  require('../codes-87f6824b.js');
8
- require('../resolveHTTPResponse-11792475.js');
8
+ require('../resolveHTTPResponse-d21ca7c2.js');
9
9
  require('../config-3156a1f1.js');
10
10
  require('../TRPCError-d07099d1.js');
11
11
  require('../transformTRPCResponse-e65f34e9.js');
@@ -1,7 +1,7 @@
1
- import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-842a1461.mjs';
1
+ import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-a3cc8c22.mjs';
2
2
  import '../index-f91d720c.mjs';
3
3
  import '../codes-c924c3db.mjs';
4
- import '../resolveHTTPResponse-3aef2178.mjs';
4
+ import '../resolveHTTPResponse-67085326.mjs';
5
5
  import '../config-cd32070b.mjs';
6
6
  import '../TRPCError-6a1653a4.mjs';
7
7
  import '../transformTRPCResponse-1153b421.mjs';
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var node_stream = require('node:stream');
6
6
  require('../../index-784ff647.js');
7
- var resolveHTTPResponse = require('../../resolveHTTPResponse-11792475.js');
7
+ var resolveHTTPResponse = require('../../resolveHTTPResponse-d21ca7c2.js');
8
8
  var batchStreamFormatter = require('../../batchStreamFormatter-93cdcdd4.js');
9
9
  var adapters_ws = require('../ws.js');
10
10
  require('../../codes-87f6824b.js');
@@ -1,6 +1,6 @@
1
1
  import { Readable } from 'node:stream';
2
2
  import '../../index-f91d720c.mjs';
3
- import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-3aef2178.mjs';
3
+ import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-67085326.mjs';
4
4
  import { g as getBatchStreamFormatter } from '../../batchStreamFormatter-fc1ffb26.mjs';
5
5
  import { applyWSSHandler } from '../ws.mjs';
6
6
  import '../../codes-c924c3db.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,mBAAmB,CAAC,OAAO,CAAC,GAAG;IAC7B,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEJ,wBAAsB,mBAAmB,CAAC,OAAO,SAAS,SAAS,EACjE,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,GACxC,OAAO,CAAC,QAAQ,CAAC,CAoGnB"}
1
+ {"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,mBAAmB,CAAC,OAAO,CAAC,GAAG;IAC7B,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEJ,wBAAsB,mBAAmB,CAAC,OAAO,SAAS,SAAS,EACjE,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,GACxC,OAAO,CAAC,QAAQ,CAAC,CAmGnB"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('../../index-784ff647.js');
6
- var resolveHTTPResponse = require('../../resolveHTTPResponse-11792475.js');
6
+ var resolveHTTPResponse = require('../../resolveHTTPResponse-d21ca7c2.js');
7
7
  var batchStreamFormatter = require('../../batchStreamFormatter-93cdcdd4.js');
8
8
  require('../../codes-87f6824b.js');
9
9
  require('../../config-3156a1f1.js');
@@ -25,7 +25,7 @@ async function fetchRequestHandler(opts) {
25
25
  query: url.searchParams,
26
26
  method: opts.req.method,
27
27
  headers: Object.fromEntries(opts.req.headers),
28
- body: opts.req.headers.get('content-type') === 'application/json' ? await opts.req.text() : ''
28
+ body: opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : ''
29
29
  };
30
30
  let resolve;
31
31
  const promise = new Promise((r)=>resolve = r);
@@ -1,5 +1,5 @@
1
1
  import '../../index-f91d720c.mjs';
2
- import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-3aef2178.mjs';
2
+ import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-67085326.mjs';
3
3
  import { g as getBatchStreamFormatter } from '../../batchStreamFormatter-fc1ffb26.mjs';
4
4
  import '../../codes-c924c3db.mjs';
5
5
  import '../../config-cd32070b.mjs';
@@ -21,7 +21,7 @@ async function fetchRequestHandler(opts) {
21
21
  query: url.searchParams,
22
22
  method: opts.req.method,
23
23
  headers: Object.fromEntries(opts.req.headers),
24
- body: opts.req.headers.get('content-type') === 'application/json' ? await opts.req.text() : ''
24
+ body: opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : ''
25
25
  };
26
26
  let resolve;
27
27
  const promise = new Promise((r)=>resolve = r);
@@ -4,10 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var TRPCError = require('../TRPCError-d07099d1.js');
6
6
  var transformTRPCResponse = require('../transformTRPCResponse-e65f34e9.js');
7
- var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-34adf7b8.js');
7
+ var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-4ca02710.js');
8
8
  require('../index-784ff647.js');
9
9
  require('../codes-87f6824b.js');
10
- require('../resolveHTTPResponse-11792475.js');
10
+ require('../resolveHTTPResponse-d21ca7c2.js');
11
11
  require('../config-3156a1f1.js');
12
12
  require('../contentType-5b601838.js');
13
13
  require('../batchStreamFormatter-93cdcdd4.js');
@@ -1,9 +1,9 @@
1
1
  import { T as TRPCError } from '../TRPCError-6a1653a4.mjs';
2
2
  import { g as getErrorShape } from '../transformTRPCResponse-1153b421.mjs';
3
- import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-842a1461.mjs';
3
+ import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-a3cc8c22.mjs';
4
4
  import '../index-f91d720c.mjs';
5
5
  import '../codes-c924c3db.mjs';
6
- import '../resolveHTTPResponse-3aef2178.mjs';
6
+ import '../resolveHTTPResponse-67085326.mjs';
7
7
  import '../config-cd32070b.mjs';
8
8
  import '../contentType-53e30af8.mjs';
9
9
  import '../batchStreamFormatter-fc1ffb26.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"getPostBody.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/json/getPostBody.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACtC,GAAG,EAAE,eAAe,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,CAiCtB"}
1
+ {"version":3,"file":"getPostBody.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/json/getPostBody.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACtC,GAAG,EAAE,eAAe,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,CAkCtB"}
@@ -14,7 +14,7 @@ async function getPostBody(opts) {
14
14
  ok: true,
15
15
  data: req.body,
16
16
  // If the request headers specifies a content-type, we assume that the body has been preprocessed
17
- preprocessed: req.headers['content-type'] === 'application/json'
17
+ preprocessed: !!req.headers['content-type']?.startsWith('application/json')
18
18
  });
19
19
  return;
20
20
  }
@@ -45,7 +45,7 @@ async function getPostBody(opts) {
45
45
 
46
46
  const nodeHTTPJSONContentTypeHandler = contentType.createNodeHTTPContentTypeHandler({
47
47
  isMatch (opts) {
48
- return opts.req.headers['content-type'] === 'application/json';
48
+ return !!opts.req.headers['content-type']?.startsWith('application/json');
49
49
  },
50
50
  getBody: getPostBody,
51
51
  getInputs: contentType$1.getJsonContentTypeInputs
@@ -10,7 +10,7 @@ async function getPostBody(opts) {
10
10
  ok: true,
11
11
  data: req.body,
12
12
  // If the request headers specifies a content-type, we assume that the body has been preprocessed
13
- preprocessed: req.headers['content-type'] === 'application/json'
13
+ preprocessed: !!req.headers['content-type']?.startsWith('application/json')
14
14
  });
15
15
  return;
16
16
  }
@@ -41,7 +41,7 @@ async function getPostBody(opts) {
41
41
 
42
42
  const nodeHTTPJSONContentTypeHandler = createNodeHTTPContentTypeHandler({
43
43
  isMatch (opts) {
44
- return opts.req.headers['content-type'] === 'application/json';
44
+ return !!opts.req.headers['content-type']?.startsWith('application/json');
45
45
  },
46
46
  getBody: getPostBody,
47
47
  getInputs: getJsonContentTypeInputs
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var nodeHTTPRequestHandler = require('../../nodeHTTPRequestHandler-34adf7b8.js');
5
+ var nodeHTTPRequestHandler = require('../../nodeHTTPRequestHandler-4ca02710.js');
6
6
  require('../../index-784ff647.js');
7
7
  require('../../codes-87f6824b.js');
8
- require('../../resolveHTTPResponse-11792475.js');
8
+ require('../../resolveHTTPResponse-d21ca7c2.js');
9
9
  require('../../config-3156a1f1.js');
10
10
  require('../../TRPCError-d07099d1.js');
11
11
  require('../../transformTRPCResponse-e65f34e9.js');
@@ -1,7 +1,7 @@
1
- export { n as nodeHTTPRequestHandler } from '../../nodeHTTPRequestHandler-842a1461.mjs';
1
+ export { n as nodeHTTPRequestHandler } from '../../nodeHTTPRequestHandler-a3cc8c22.mjs';
2
2
  import '../../index-f91d720c.mjs';
3
3
  import '../../codes-c924c3db.mjs';
4
- import '../../resolveHTTPResponse-3aef2178.mjs';
4
+ import '../../resolveHTTPResponse-67085326.mjs';
5
5
  import '../../config-cd32070b.mjs';
6
6
  import '../../TRPCError-6a1653a4.mjs';
7
7
  import '../../transformTRPCResponse-1153b421.mjs';
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var http = require('node:http');
6
- var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-34adf7b8.js');
6
+ var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-4ca02710.js');
7
7
  require('../index-784ff647.js');
8
8
  require('../codes-87f6824b.js');
9
- require('../resolveHTTPResponse-11792475.js');
9
+ require('../resolveHTTPResponse-d21ca7c2.js');
10
10
  require('../config-3156a1f1.js');
11
11
  require('../TRPCError-d07099d1.js');
12
12
  require('../transformTRPCResponse-e65f34e9.js');
@@ -1,8 +1,8 @@
1
1
  import http from 'node:http';
2
- import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-842a1461.mjs';
2
+ import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-a3cc8c22.mjs';
3
3
  import '../index-f91d720c.mjs';
4
4
  import '../codes-c924c3db.mjs';
5
- import '../resolveHTTPResponse-3aef2178.mjs';
5
+ import '../resolveHTTPResponse-67085326.mjs';
6
6
  import '../config-cd32070b.mjs';
7
7
  import '../TRPCError-6a1653a4.mjs';
8
8
  import '../transformTRPCResponse-1153b421.mjs';
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var index = require('../index-784ff647.js');
6
- var resolveHTTPResponse = require('../resolveHTTPResponse-11792475.js');
6
+ var resolveHTTPResponse = require('../resolveHTTPResponse-d21ca7c2.js');
7
7
  var batchStreamFormatter = require('../batchStreamFormatter-93cdcdd4.js');
8
8
  require('../codes-87f6824b.js');
9
9
  require('../config-3156a1f1.js');
@@ -1,5 +1,5 @@
1
1
  export { T as TRPC_ERROR_CODES_BY_NUMBER, b as getHTTPStatusCode, g as getHTTPStatusCodeFromError } from '../index-f91d720c.mjs';
2
- export { r as resolveHTTPResponse } from '../resolveHTTPResponse-3aef2178.mjs';
2
+ export { r as resolveHTTPResponse } from '../resolveHTTPResponse-67085326.mjs';
3
3
  export { g as getBatchStreamFormatter } from '../batchStreamFormatter-fc1ffb26.mjs';
4
4
  import '../codes-c924c3db.mjs';
5
5
  import '../config-cd32070b.mjs';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  require('./index-784ff647.js');
4
- var resolveHTTPResponse = require('./resolveHTTPResponse-11792475.js');
4
+ var resolveHTTPResponse = require('./resolveHTTPResponse-d21ca7c2.js');
5
5
  var batchStreamFormatter = require('./batchStreamFormatter-93cdcdd4.js');
6
6
  var adapters_nodeHttp_contentType_json_index = require('./adapters/node-http/content-type/json/index.js');
7
7
 
@@ -1,5 +1,5 @@
1
1
  import './index-f91d720c.mjs';
2
- import { r as resolveHTTPResponse } from './resolveHTTPResponse-3aef2178.mjs';
2
+ import { r as resolveHTTPResponse } from './resolveHTTPResponse-67085326.mjs';
3
3
  import { g as getBatchStreamFormatter } from './batchStreamFormatter-fc1ffb26.mjs';
4
4
  import { nodeHTTPJSONContentTypeHandler } from './adapters/node-http/content-type/json/index.mjs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import './index-46cb3130.js';
2
- import { r as resolveHTTPResponse } from './resolveHTTPResponse-d6110ed7.js';
2
+ import { r as resolveHTTPResponse } from './resolveHTTPResponse-a885ce7b.js';
3
3
  import { g as getBatchStreamFormatter } from './batchStreamFormatter-2c1405a1.js';
4
4
  import { nodeHTTPJSONContentTypeHandler } from './adapters/node-http/content-type/json/index.js';
5
5
 
@@ -129,6 +129,16 @@ async function resolveHTTPResponse(opts) {
129
129
  const isBatchCall = !!req.query.get('batch');
130
130
  const isStreamCall = isBatchCall && unstable_onHead && unstable_onChunk && req.headers['trpc-batch-mode'] === 'stream';
131
131
  try {
132
+ // we create context first so that (unless `createContext()` throws)
133
+ // error handler may access context information
134
+ //
135
+ // this way even if the client sends malformed input that might cause an exception:
136
+ // - `opts.error` has value,
137
+ // - batching is not enabled,
138
+ // - `type` is unknown,
139
+ // - `getInputs` throws because of malformed JSON,
140
+ // context value is still available to the error handler
141
+ ctx = await opts.createContext();
132
142
  if (opts.error) {
133
143
  throw opts.error;
134
144
  }
@@ -156,7 +166,6 @@ async function resolveHTTPResponse(opts) {
156
166
  paths = isBatchCall ? decodeURIComponent(opts.path).split(',') : [
157
167
  opts.path
158
168
  ];
159
- ctx = await opts.createContext();
160
169
  const promises = paths.map((path, index)=>inputToProcedureCall({
161
170
  opts,
162
171
  ctx,
@@ -125,6 +125,16 @@ async function resolveHTTPResponse(opts) {
125
125
  unstable_onChunk &&
126
126
  req.headers['trpc-batch-mode'] === 'stream';
127
127
  try {
128
+ // we create context first so that (unless `createContext()` throws)
129
+ // error handler may access context information
130
+ //
131
+ // this way even if the client sends malformed input that might cause an exception:
132
+ // - `opts.error` has value,
133
+ // - batching is not enabled,
134
+ // - `type` is unknown,
135
+ // - `getInputs` throws because of malformed JSON,
136
+ // context value is still available to the error handler
137
+ ctx = await opts.createContext();
128
138
  if (opts.error) {
129
139
  throw opts.error;
130
140
  }
@@ -153,7 +163,6 @@ async function resolveHTTPResponse(opts) {
153
163
  paths = isBatchCall
154
164
  ? decodeURIComponent(opts.path).split(',')
155
165
  : [opts.path];
156
- ctx = await opts.createContext();
157
166
  const promises = paths.map((path, index) => inputToProcedureCall({ opts, ctx, type, input: inputs[index], path }));
158
167
  if (!isStreamCall) {
159
168
  /**
@@ -131,6 +131,16 @@ async function resolveHTTPResponse(opts) {
131
131
  const isBatchCall = !!req.query.get('batch');
132
132
  const isStreamCall = isBatchCall && unstable_onHead && unstable_onChunk && req.headers['trpc-batch-mode'] === 'stream';
133
133
  try {
134
+ // we create context first so that (unless `createContext()` throws)
135
+ // error handler may access context information
136
+ //
137
+ // this way even if the client sends malformed input that might cause an exception:
138
+ // - `opts.error` has value,
139
+ // - batching is not enabled,
140
+ // - `type` is unknown,
141
+ // - `getInputs` throws because of malformed JSON,
142
+ // context value is still available to the error handler
143
+ ctx = await opts.createContext();
134
144
  if (opts.error) {
135
145
  throw opts.error;
136
146
  }
@@ -158,7 +168,6 @@ async function resolveHTTPResponse(opts) {
158
168
  paths = isBatchCall ? decodeURIComponent(opts.path).split(',') : [
159
169
  opts.path
160
170
  ];
161
- ctx = await opts.createContext();
162
171
  const promises = paths.map((path, index)=>inputToProcedureCall({
163
172
  opts,
164
173
  ctx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "10.38.0",
3
+ "version": "10.38.2",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -32,7 +32,7 @@
32
32
  "scripts": {
33
33
  "build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
34
34
  "dev": "pnpm build --watch",
35
- "codegen:entrypoints": "tsx entrypoints.script.ts",
35
+ "codegen-entrypoints": "tsx entrypoints.script.ts",
36
36
  "benchmark": "tsc --project tsconfig.benchmark.json",
37
37
  "lint": "eslint --cache --ext \".js,.ts,.tsx\" --ignore-path ../../.gitignore --report-unused-disable-directives src",
38
38
  "ts-watch": "tsc --project tsconfig.watch.json"
@@ -174,5 +174,5 @@
174
174
  "funding": [
175
175
  "https://trpc.io/sponsor"
176
176
  ],
177
- "gitHead": "a811287aae324c1e947f9620e9aab4de79c98bed"
177
+ "gitHead": "3ae64cc8b8c73306d6b022dec9eae769b246b0fb"
178
178
  }
@@ -25,10 +25,9 @@ export async function fetchRequestHandler<TRouter extends AnyRouter>(
25
25
  query: url.searchParams,
26
26
  method: opts.req.method,
27
27
  headers: Object.fromEntries(opts.req.headers),
28
- body:
29
- opts.req.headers.get('content-type') === 'application/json'
30
- ? await opts.req.text()
31
- : '',
28
+ body: opts.req.headers.get('content-type')?.startsWith('application/json')
29
+ ? await opts.req.text()
30
+ : '',
32
31
  };
33
32
 
34
33
  let resolve: (value: Response) => void;
@@ -13,7 +13,8 @@ export async function getPostBody(opts: {
13
13
  ok: true,
14
14
  data: req.body,
15
15
  // If the request headers specifies a content-type, we assume that the body has been preprocessed
16
- preprocessed: req.headers['content-type'] === 'application/json',
16
+ preprocessed:
17
+ !!req.headers['content-type']?.startsWith('application/json'),
17
18
  });
18
19
  return;
19
20
  }
@@ -4,7 +4,7 @@ import { getPostBody } from './getPostBody';
4
4
 
5
5
  export const nodeHTTPJSONContentTypeHandler = createNodeHTTPContentTypeHandler({
6
6
  isMatch(opts) {
7
- return opts.req.headers['content-type'] === 'application/json';
7
+ return !!opts.req.headers['content-type']?.startsWith('application/json');
8
8
  },
9
9
  getBody: getPostBody,
10
10
  getInputs: getJsonContentTypeInputs,
@@ -287,6 +287,17 @@ export async function resolveHTTPResponse<
287
287
  req.headers['trpc-batch-mode'] === 'stream';
288
288
 
289
289
  try {
290
+ // we create context first so that (unless `createContext()` throws)
291
+ // error handler may access context information
292
+ //
293
+ // this way even if the client sends malformed input that might cause an exception:
294
+ // - `opts.error` has value,
295
+ // - batching is not enabled,
296
+ // - `type` is unknown,
297
+ // - `getInputs` throws because of malformed JSON,
298
+ // context value is still available to the error handler
299
+ ctx = await opts.createContext();
300
+
290
301
  if (opts.error) {
291
302
  throw opts.error;
292
303
  }
@@ -317,7 +328,6 @@ export async function resolveHTTPResponse<
317
328
  paths = isBatchCall
318
329
  ? decodeURIComponent(opts.path).split(',')
319
330
  : [opts.path];
320
- ctx = await opts.createContext();
321
331
  const promises = paths.map((path, index) =>
322
332
  inputToProcedureCall({ opts, ctx, type, input: inputs[index], path }),
323
333
  );