@trpc/server 11.0.0-next-beta.300 → 11.0.0-next-beta.302

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 +1 @@
1
- {"version":3,"file":"getPostBody.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/json/getPostBody.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,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":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACtC,GAAG,EAAE,eAAe,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,CAgDtB"}
@@ -8,6 +8,16 @@ require('../../../../unstable-core-do-not-import/rootConfig.js');
8
8
  async function getPostBody(opts) {
9
9
  const { req , maxBodySize =Infinity } = opts;
10
10
  return new Promise((resolve)=>{
11
+ if (!req.headers['content-type']?.startsWith('application/json') && req.method !== 'GET' && req.method !== 'OPTIONS' && req.method !== 'HEAD') {
12
+ resolve({
13
+ ok: false,
14
+ error: new TRPCError.TRPCError({
15
+ code: 'BAD_REQUEST',
16
+ message: 'Invalid content-type header (expected application/json)'
17
+ })
18
+ });
19
+ return;
20
+ }
11
21
  if ('body' in req) {
12
22
  resolve({
13
23
  ok: true,
@@ -6,6 +6,16 @@ import '../../../../unstable-core-do-not-import/rootConfig.mjs';
6
6
  async function getPostBody(opts) {
7
7
  const { req , maxBodySize =Infinity } = opts;
8
8
  return new Promise((resolve)=>{
9
+ if (!req.headers['content-type']?.startsWith('application/json') && req.method !== 'GET' && req.method !== 'OPTIONS' && req.method !== 'HEAD') {
10
+ resolve({
11
+ ok: false,
12
+ error: new TRPCError({
13
+ code: 'BAD_REQUEST',
14
+ message: 'Invalid content-type header (expected application/json)'
15
+ })
16
+ });
17
+ return;
18
+ }
9
19
  if ('body' in req) {
10
20
  resolve({
11
21
  ok: true,
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 92290,
3
- "bundleOrigSize": 147464,
4
- "bundleReduction": 37.42,
2
+ "bundleSize": 92734,
3
+ "bundleOrigSize": 147860,
4
+ "bundleReduction": 37.28,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/adapters/ws.ts",
@@ -14,7 +14,7 @@
14
14
  "dependents": [
15
15
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
16
16
  ],
17
- "percent": 10.8,
17
+ "percent": 10.75,
18
18
  "reduction": 0
19
19
  },
20
20
  {
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "removedExports": [],
28
28
  "dependents": [],
29
- "percent": 10.17,
29
+ "percent": 10.12,
30
30
  "reduction": 21.23
31
31
  },
32
32
  {
@@ -45,7 +45,7 @@
45
45
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts",
46
46
  "/src/unstable-core-do-not-import/initTRPC.ts"
47
47
  ],
48
- "percent": 6.58,
48
+ "percent": 6.54,
49
49
  "reduction": 38.58
50
50
  },
51
51
  {
@@ -61,7 +61,7 @@
61
61
  "/src/unstable-core-do-not-import.ts",
62
62
  "/src/unstable-core-do-not-import/initTRPC.ts"
63
63
  ],
64
- "percent": 6.18,
64
+ "percent": 6.15,
65
65
  "reduction": 58.57
66
66
  },
67
67
  {
@@ -77,7 +77,7 @@
77
77
  "dependents": [
78
78
  "/src/adapters/node-http/content-type/form-data/index.ts"
79
79
  ],
80
- "percent": 5.39,
80
+ "percent": 5.37,
81
81
  "reduction": 36.77
82
82
  },
83
83
  {
@@ -91,7 +91,7 @@
91
91
  ],
92
92
  "removedExports": [],
93
93
  "dependents": [],
94
- "percent": 4.79,
94
+ "percent": 4.77,
95
95
  "reduction": 32.71
96
96
  },
97
97
  {
@@ -105,7 +105,7 @@
105
105
  "dependents": [
106
106
  "/src/adapters/node-http/index.ts"
107
107
  ],
108
- "percent": 4.26,
108
+ "percent": 4.24,
109
109
  "reduction": 13.56
110
110
  },
111
111
  {
@@ -119,7 +119,7 @@
119
119
  "dependents": [
120
120
  "/src/adapters/fetch/index.ts"
121
121
  ],
122
- "percent": 3.85,
122
+ "percent": 3.83,
123
123
  "reduction": 9.5
124
124
  },
125
125
  {
@@ -135,7 +135,7 @@
135
135
  "dependents": [
136
136
  "/src/observable/index.ts"
137
137
  ],
138
- "percent": 3.72,
138
+ "percent": 3.7,
139
139
  "reduction": 5.43
140
140
  },
141
141
  {
@@ -154,7 +154,7 @@
154
154
  "dependents": [
155
155
  "/src/adapters/aws-lambda/index.ts"
156
156
  ],
157
- "percent": 3.58,
157
+ "percent": 3.57,
158
158
  "reduction": 36.48
159
159
  },
160
160
  {
@@ -170,7 +170,7 @@
170
170
  "dependents": [
171
171
  "/src/observable/index.ts"
172
172
  ],
173
- "percent": 3.23,
173
+ "percent": 3.21,
174
174
  "reduction": 0
175
175
  },
176
176
  {
@@ -190,7 +190,7 @@
190
190
  "/src/unstable-core-do-not-import/router.ts",
191
191
  "/src/unstable-core-do-not-import/initTRPC.ts"
192
192
  ],
193
- "percent": 2.97,
193
+ "percent": 2.96,
194
194
  "reduction": 45.94
195
195
  },
196
196
  {
@@ -204,7 +204,7 @@
204
204
  "dependents": [
205
205
  "/src/unstable-core-do-not-import.ts"
206
206
  ],
207
- "percent": 2.95,
207
+ "percent": 2.94,
208
208
  "reduction": 39.13
209
209
  },
210
210
  {
@@ -224,7 +224,7 @@
224
224
  "/src/unstable-core-do-not-import/initTRPC.ts",
225
225
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
226
226
  ],
227
- "percent": 2.85,
227
+ "percent": 2.83,
228
228
  "reduction": 55.5
229
229
  },
230
230
  {
@@ -239,7 +239,7 @@
239
239
  "/src/adapters/fastify/index.ts",
240
240
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
241
241
  ],
242
- "percent": 2.81,
242
+ "percent": 2.79,
243
243
  "reduction": 35.33
244
244
  },
245
245
  {
@@ -251,7 +251,7 @@
251
251
  ],
252
252
  "removedExports": [],
253
253
  "dependents": [],
254
- "percent": 2.75,
254
+ "percent": 2.74,
255
255
  "reduction": 31.37
256
256
  },
257
257
  {
@@ -272,7 +272,7 @@
272
272
  "/src/unstable-core-do-not-import/middleware.ts",
273
273
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
274
274
  ],
275
- "percent": 1.88,
275
+ "percent": 1.87,
276
276
  "reduction": 19.47
277
277
  },
278
278
  {
@@ -286,7 +286,7 @@
286
286
  "dependents": [
287
287
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts"
288
288
  ],
289
- "percent": 1.78,
289
+ "percent": 1.77,
290
290
  "reduction": 34.79
291
291
  },
292
292
  {
@@ -300,7 +300,7 @@
300
300
  "dependents": [
301
301
  "/src/adapters/fastify/index.ts"
302
302
  ],
303
- "percent": 1.74,
303
+ "percent": 1.73,
304
304
  "reduction": 31.58
305
305
  },
306
306
  {
@@ -312,7 +312,7 @@
312
312
  ],
313
313
  "removedExports": [],
314
314
  "dependents": [],
315
- "percent": 1.74,
315
+ "percent": 1.73,
316
316
  "reduction": 29.12
317
317
  },
318
318
  {
@@ -324,9 +324,23 @@
324
324
  ],
325
325
  "removedExports": [],
326
326
  "dependents": [],
327
- "percent": 1.71,
327
+ "percent": 1.7,
328
328
  "reduction": 21.04
329
329
  },
330
+ {
331
+ "id": "/src/adapters/node-http/content-type/json/getPostBody.ts",
332
+ "size": 1562,
333
+ "origSize": 1547,
334
+ "renderedExports": [
335
+ "getPostBody"
336
+ ],
337
+ "removedExports": [],
338
+ "dependents": [
339
+ "/src/adapters/node-http/content-type/json/index.ts"
340
+ ],
341
+ "percent": 1.68,
342
+ "reduction": 0
343
+ },
330
344
  {
331
345
  "id": "/src/unstable-core-do-not-import/createProxy.ts",
332
346
  "size": 1507,
@@ -355,7 +369,7 @@
355
369
  "dependents": [
356
370
  "/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts"
357
371
  ],
358
- "percent": 1.51,
372
+ "percent": 1.5,
359
373
  "reduction": 0
360
374
  },
361
375
  {
@@ -371,23 +385,9 @@
371
385
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts",
372
386
  "/src/unstable-core-do-not-import/error/getErrorShape.ts"
373
387
  ],
374
- "percent": 1.34,
388
+ "percent": 1.33,
375
389
  "reduction": 23.32
376
390
  },
377
- {
378
- "id": "/src/adapters/node-http/content-type/json/getPostBody.ts",
379
- "size": 1118,
380
- "origSize": 1151,
381
- "renderedExports": [
382
- "getPostBody"
383
- ],
384
- "removedExports": [],
385
- "dependents": [
386
- "/src/adapters/node-http/content-type/json/index.ts"
387
- ],
388
- "percent": 1.21,
389
- "reduction": 2.87
390
- },
391
391
  {
392
392
  "id": "/src/unstable-core-do-not-import/rpc/codes.ts",
393
393
  "size": 1020,
@@ -398,7 +398,7 @@
398
398
  ],
399
399
  "removedExports": [],
400
400
  "dependents": [],
401
- "percent": 1.11,
401
+ "percent": 1.1,
402
402
  "reduction": 23.02
403
403
  },
404
404
  {
@@ -415,14 +415,14 @@
415
415
  "dependents": [
416
416
  "/src/unstable-core-do-not-import.ts",
417
417
  "/src/unstable-core-do-not-import/rpc/codes.ts",
418
- "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
419
418
  "/src/unstable-core-do-not-import/error/TRPCError.ts",
420
419
  "/src/unstable-core-do-not-import/router.ts",
421
420
  "/src/unstable-core-do-not-import/transformer.ts",
422
421
  "/src/unstable-core-do-not-import/middleware.ts",
422
+ "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
423
423
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
424
424
  ],
425
- "percent": 1.09,
425
+ "percent": 1.08,
426
426
  "reduction": 35.76
427
427
  },
428
428
  {
@@ -457,7 +457,7 @@
457
457
  "/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts",
458
458
  "/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts"
459
459
  ],
460
- "percent": 0.79,
460
+ "percent": 0.78,
461
461
  "reduction": 67.52
462
462
  },
463
463
  {
@@ -471,7 +471,7 @@
471
471
  "dependents": [
472
472
  "/src/adapters/node-http/content-type/form-data/index.ts"
473
473
  ],
474
- "percent": 0.76,
474
+ "percent": 0.75,
475
475
  "reduction": 71.21
476
476
  },
477
477
  {
@@ -498,7 +498,7 @@
498
498
  "/src/unstable-core-do-not-import.ts",
499
499
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts"
500
500
  ],
501
- "percent": 0.68,
501
+ "percent": 0.67,
502
502
  "reduction": 43.49
503
503
  },
504
504
  {
@@ -511,7 +511,7 @@
511
511
  ],
512
512
  "removedExports": [],
513
513
  "dependents": [],
514
- "percent": 0.63,
514
+ "percent": 0.62,
515
515
  "reduction": 65.23
516
516
  },
517
517
  {
@@ -552,7 +552,7 @@
552
552
  "dependents": [
553
553
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts"
554
554
  ],
555
- "percent": 0.32,
555
+ "percent": 0.31,
556
556
  "reduction": 35.11
557
557
  },
558
558
  {
@@ -590,8 +590,8 @@
590
590
  ],
591
591
  "removedExports": [],
592
592
  "dependents": [
593
- "/src/adapters/node-http/content-type/json/index.ts",
594
- "/src/adapters/node-http/content-type/form-data/index.ts"
593
+ "/src/adapters/node-http/content-type/form-data/index.ts",
594
+ "/src/adapters/node-http/content-type/json/index.ts"
595
595
  ],
596
596
  "percent": 0.13,
597
597
  "reduction": 86.68
@@ -638,9 +638,9 @@
638
638
  "reduction": 100
639
639
  },
640
640
  {
641
- "id": "/src/rpc.ts",
641
+ "id": "/src/index.ts",
642
642
  "size": 0,
643
- "origSize": 36,
643
+ "origSize": 32,
644
644
  "renderedExports": [],
645
645
  "removedExports": [],
646
646
  "dependents": [],
@@ -648,9 +648,9 @@
648
648
  "reduction": 100
649
649
  },
650
650
  {
651
- "id": "/src/index.ts",
651
+ "id": "/src/rpc.ts",
652
652
  "size": 0,
653
- "origSize": 32,
653
+ "origSize": 36,
654
654
  "renderedExports": [],
655
655
  "removedExports": [],
656
656
  "dependents": [],
@@ -700,26 +700,26 @@
700
700
  "reduction": 100
701
701
  },
702
702
  {
703
- "id": "/src/adapters/fetch/index.ts",
703
+ "id": "/src/adapters/node-http/index.ts",
704
704
  "size": 0,
705
- "origSize": 64,
705
+ "origSize": 67,
706
706
  "renderedExports": [],
707
707
  "removedExports": [],
708
- "dependents": [],
708
+ "dependents": [
709
+ "/src/adapters/express.ts",
710
+ "/src/adapters/standalone.ts",
711
+ "/src/adapters/next.ts"
712
+ ],
709
713
  "percent": 0,
710
714
  "reduction": 100
711
715
  },
712
716
  {
713
- "id": "/src/adapters/node-http/index.ts",
717
+ "id": "/src/adapters/fetch/index.ts",
714
718
  "size": 0,
715
- "origSize": 67,
719
+ "origSize": 64,
716
720
  "renderedExports": [],
717
721
  "removedExports": [],
718
- "dependents": [
719
- "/src/adapters/express.ts",
720
- "/src/adapters/next.ts",
721
- "/src/adapters/standalone.ts"
722
- ],
722
+ "dependents": [],
723
723
  "percent": 0,
724
724
  "reduction": 100
725
725
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-next-beta.300+2486831f7",
3
+ "version": "11.0.0-next-beta.302+95ed0a569",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -157,5 +157,5 @@
157
157
  "funding": [
158
158
  "https://trpc.io/sponsor"
159
159
  ],
160
- "gitHead": "2486831f7c6b8718c474b152a5396b2d854408b9"
160
+ "gitHead": "95ed0a569aa4ba8a0a5867f7df92f746f0d11f15"
161
161
  }
@@ -9,6 +9,21 @@ export async function getPostBody(opts: {
9
9
  }): Promise<BodyResult> {
10
10
  const { req, maxBodySize = Infinity } = opts;
11
11
  return new Promise((resolve) => {
12
+ if (
13
+ !req.headers['content-type']?.startsWith('application/json') &&
14
+ req.method !== 'GET' &&
15
+ req.method !== 'OPTIONS' &&
16
+ req.method !== 'HEAD'
17
+ ) {
18
+ resolve({
19
+ ok: false,
20
+ error: new TRPCError({
21
+ code: 'BAD_REQUEST',
22
+ message: 'Invalid content-type header (expected application/json)',
23
+ }),
24
+ });
25
+ return;
26
+ }
12
27
  if ('body' in req) {
13
28
  resolve({
14
29
  ok: true,