File tree Expand file tree Collapse file tree 4 files changed +55
-8
lines changed
Expand file tree Collapse file tree 4 files changed +55
-8
lines changed Original file line number Diff line number Diff line change 2525 "author" : " Gregor Martynus (https://github.com/gr2m)" ,
2626 "license" : " MIT" ,
2727 "dependencies" : {
28- "@octokit/endpoint" : " ^11.0.2 " ,
28+ "@octokit/endpoint" : " ^11.0.3 " ,
2929 "@octokit/request-error" : " ^7.0.2" ,
3030 "@octokit/types" : " ^16.0.0" ,
3131 "fast-content-type-parse" : " ^3.0.0" ,
32+ "json-with-bigint" : " ^3.5.3" ,
3233 "universal-user-agent" : " ^7.0.2"
3334 },
3435 "devDependencies" : {
3839 "@vitest/coverage-v8" : " ^4.0.0" ,
3940 "esbuild" : " ^0.27.0" ,
4041 "fetch-mock" : " ^12.0.0" ,
41- "tinyglobby" : " ^0.2.15" ,
4242 "prettier" : " 3.6.2" ,
4343 "semantic-release-plugin-update-version-in-files" : " ^2.0.0" ,
44+ "tinyglobby" : " ^0.2.15" ,
4445 "typescript" : " ^5.0.0" ,
4546 "undici" : " ^7.0.0" ,
4647 "vitest" : " ^4.0.0"
Original file line number Diff line number Diff line change 11import { safeParse } from "fast-content-type-parse" ;
2+ import { JSONParse , JSONStringify } from "json-with-bigint" ;
23import { isPlainObject } from "./is-plain-object.js" ;
34import { RequestError } from "@octokit/request-error" ;
45import type { EndpointInterface , OctokitResponse } from "@octokit/types" ;
@@ -26,7 +27,7 @@ export default async function fetchWrapper(
2627
2728 const body =
2829 isPlainObject ( requestOptions . body ) || Array . isArray ( requestOptions . body )
29- ? JSON . stringify ( requestOptions . body )
30+ ? JSONStringify ( requestOptions . body )
3031 : requestOptions . body ;
3132
3233 // Header values must be `string`
@@ -167,7 +168,7 @@ async function getResponseData(response: Response): Promise<any> {
167168 let text = "" ;
168169 try {
169170 text = await response . text ( ) ;
170- return JSON . parse ( text ) ;
171+ return JSONParse ( text ) ;
171172 } catch ( err ) {
172173 return text ;
173174 }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import type {
1414} from "@octokit/types" ;
1515
1616import { request } from "../src/index.ts" ;
17+ import { JSONStringify } from "json-with-bigint" ;
1718
1819const userAgent = `octokit-request.js/0.0.0-development ${ getUserAgent ( ) } ` ;
1920const __filename = new URL ( import . meta. url ) ;
@@ -1328,4 +1329,41 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
13281329 ] ,
13291330 } ) ;
13301331 } ) ;
1332+
1333+ it ( "parses JSON response bodies that contain int64 (BigInt)" , async ( ) => {
1334+ expect . assertions ( 2 ) ;
1335+
1336+ const mock = fetchMock . createInstance ( ) ;
1337+ mock . get ( "https://api.github.com/app/hook/deliveries" , {
1338+ status : 200 ,
1339+ headers : {
1340+ "Content-Type" : "application/json; charset=utf-8" ,
1341+ } ,
1342+ body : [
1343+ {
1344+ id : Number . MAX_SAFE_INTEGER + 9 ,
1345+ guid : "0b989ba4-242f-11e5-81e1-c7b6966d2516" ,
1346+ delivered_at : "2019-06-03T00:57:16Z" ,
1347+ redelivery : false ,
1348+ duration : 0.27 ,
1349+ status : "OK" ,
1350+ status_code : 200 ,
1351+ event : "issues" ,
1352+ action : "opened" ,
1353+ installation_id : 123 ,
1354+ repository_id : 456 ,
1355+ throttled_at : "2019-06-03T00:57:16Z" ,
1356+ } ,
1357+ ] ,
1358+ } ) ;
1359+
1360+ const response = await request ( "GET /app/hook/deliveries" , {
1361+ request : {
1362+ fetch : mock . fetchHandler ,
1363+ } ,
1364+ } ) ;
1365+
1366+ expect ( response . status ) . toEqual ( 200 ) ;
1367+ expect ( response . data [ 0 ] . id ) . toEqual ( BigInt ( Number . MAX_SAFE_INTEGER ) + 9n ) ;
1368+ } ) ;
13311369} ) ;
You can’t perform that action at this time.
0 commit comments