@@ -419,6 +419,30 @@ function promiseWithResolvers<T>(): ReturnType<
419
419
return obj
420
420
}
421
421
422
+ function queryToSearchParams (
423
+ init ?:
424
+ | URLSearchParams
425
+ | string
426
+ | Record < string , string | readonly string [ ] >
427
+ | Iterable < [ string , string ] >
428
+ | ReadonlyArray < [ string , string ] >
429
+ | null
430
+ | undefined
431
+ ) : URLSearchParams {
432
+ const params = new URLSearchParams ( init ?? '' )
433
+ const normalized : Record < string , string > = { }
434
+ for ( const entry of params . entries ( ) ) {
435
+ let key = entry [ 0 ]
436
+ if ( key === 'defaultBranch' ) {
437
+ key = 'default_branch'
438
+ } else if ( key === 'perPage' ) {
439
+ key = 'per_page'
440
+ }
441
+ normalized [ key ] = entry [ 1 ]
442
+ }
443
+ return new URLSearchParams ( normalized )
444
+ }
445
+
422
446
function resolveAbsPaths (
423
447
filepaths : string [ ] ,
424
448
pathsRelativeTo ?: string
@@ -491,13 +515,10 @@ export class SocketSdk {
491
515
) : Promise < IncomingMessage > {
492
516
// Adds the first 'abort' listener to abortSignal.
493
517
const req = getHttpModule ( this . #baseUrl)
494
- . request (
495
- `${ this . #baseUrl} purl?${ new URLSearchParams ( queryParams ?? '' ) } ` ,
496
- {
497
- method : 'POST' ,
498
- ...this . #reqOptions
499
- }
500
- )
518
+ . request ( `${ this . #baseUrl} purl?${ queryToSearchParams ( queryParams ) } ` , {
519
+ method : 'POST' ,
520
+ ...this . #reqOptions
521
+ } )
501
522
. end ( JSON . stringify ( componentsObj ) )
502
523
return await getResponse ( req )
503
524
}
@@ -703,7 +724,7 @@ export class SocketSdk {
703
724
}
704
725
705
726
async createDependenciesSnapshot (
706
- params : Record < string , string > ,
727
+ queryParams : Record < string , string > ,
707
728
filepaths : string [ ] ,
708
729
pathsRelativeTo = '.'
709
730
) : Promise < SocketSdkResult < 'createDependenciesSnapshot' > > {
@@ -713,7 +734,7 @@ export class SocketSdk {
713
734
const data = await getResponseJson (
714
735
await createUploadRequest (
715
736
this . #baseUrl,
716
- `dependencies/upload?${ new URLSearchParams ( params ) } ` ,
737
+ `dependencies/upload?${ queryToSearchParams ( queryParams ) } ` ,
717
738
createRequestBodyForFilepaths ( absFilepaths , basePath ) ,
718
739
this . #reqOptions
719
740
)
@@ -736,7 +757,7 @@ export class SocketSdk {
736
757
const data = await getResponseJson (
737
758
await createUploadRequest (
738
759
this . #baseUrl,
739
- `orgs/${ encodeURIComponent ( orgSlug ) } /full-scans?${ new URLSearchParams ( queryParams ?? '' ) } ` ,
760
+ `orgs/${ encodeURIComponent ( orgSlug ) } /full-scans?${ queryToSearchParams ( queryParams ) } ` ,
740
761
createRequestBodyForFilepaths ( absFilepaths , basePath ) ,
741
762
this . #reqOptions
742
763
)
@@ -749,14 +770,14 @@ export class SocketSdk {
749
770
750
771
async createOrgRepo (
751
772
orgSlug : string ,
752
- params : Record < string , string >
773
+ queryParams : Record < string , string >
753
774
) : Promise < SocketSdkResult < 'createOrgRepo' > > {
754
775
try {
755
776
const data = await getResponseJson (
756
777
await createPostRequest (
757
778
this . #baseUrl,
758
779
`orgs/${ encodeURIComponent ( orgSlug ) } /repos` ,
759
- params ,
780
+ queryParams ,
760
781
this . #reqOptions
761
782
)
762
783
)
@@ -838,7 +859,7 @@ export class SocketSdk {
838
859
const data = await getResponseJson (
839
860
await createGetRequest (
840
861
this . #baseUrl,
841
- `orgs/${ encodeURIComponent ( orgSlug ) } /audit-log?${ new URLSearchParams ( queryParams ?? '' ) } ` ,
862
+ `orgs/${ encodeURIComponent ( orgSlug ) } /audit-log?${ queryToSearchParams ( queryParams ) } ` ,
842
863
this . #reqOptions
843
864
)
844
865
)
@@ -929,7 +950,7 @@ export class SocketSdk {
929
950
const data = await getResponseJson (
930
951
await createGetRequest (
931
952
this . #baseUrl,
932
- `orgs/${ encodeURIComponent ( orgSlug ) } /full-scans?${ new URLSearchParams ( queryParams ?? '' ) } ` ,
953
+ `orgs/${ encodeURIComponent ( orgSlug ) } /full-scans?${ queryToSearchParams ( queryParams ) } ` ,
933
954
this . #reqOptions
934
955
)
935
956
)
@@ -1003,7 +1024,7 @@ export class SocketSdk {
1003
1024
const data = await getResponseJson (
1004
1025
await createGetRequest (
1005
1026
this . #baseUrl,
1006
- `orgs/${ encodeURIComponent ( orgSlug ) } /repos?${ new URLSearchParams ( queryParams ?? '' ) } ` ,
1027
+ `orgs/${ encodeURIComponent ( orgSlug ) } /repos?${ queryToSearchParams ( queryParams ) } ` ,
1007
1028
this . #reqOptions
1008
1029
)
1009
1030
)
@@ -1139,14 +1160,14 @@ export class SocketSdk {
1139
1160
}
1140
1161
1141
1162
async searchDependencies (
1142
- params : Record < string , number >
1163
+ queryParams : Record < string , number >
1143
1164
) : Promise < SocketSdkResult < 'searchDependencies' > > {
1144
1165
try {
1145
1166
const data = await getResponseJson (
1146
1167
await createPostRequest (
1147
1168
this . #baseUrl,
1148
1169
'dependencies/search' ,
1149
- params ,
1170
+ queryParams ,
1150
1171
this . #reqOptions
1151
1172
)
1152
1173
)
@@ -1159,14 +1180,14 @@ export class SocketSdk {
1159
1180
async updateOrgRepo (
1160
1181
orgSlug : string ,
1161
1182
repoSlug : string ,
1162
- params : Record < string , string >
1183
+ queryParams : Record < string , string >
1163
1184
) : Promise < SocketSdkResult < 'updateOrgRepo' > > {
1164
1185
try {
1165
1186
const data = await getResponseJson (
1166
1187
await createPostRequest (
1167
1188
this . #baseUrl,
1168
1189
`orgs/${ encodeURIComponent ( orgSlug ) } /repos/${ encodeURIComponent ( repoSlug ) } ` ,
1169
- params ,
1190
+ queryParams ,
1170
1191
this . #reqOptions
1171
1192
)
1172
1193
)
0 commit comments