@@ -72,6 +72,24 @@ export interface SocketSdkOptions {
72
72
userAgent ?: string | undefined
73
73
}
74
74
75
+ export type UploadManifestFilesResponse = {
76
+ tarHash : string
77
+ unmatchedFiles : string [ ]
78
+ }
79
+
80
+ export type UploadManifestFilesReturnType = {
81
+ success : true
82
+ status : 200
83
+ data : UploadManifestFilesResponse
84
+ }
85
+
86
+ export type UploadManifestFilesError = {
87
+ success : false
88
+ status : number
89
+ error : string
90
+ cause : string | undefined
91
+ }
92
+
75
93
const DEFAULT_USER_AGENT = createUserAgentFromPkgJson ( rootPkgJson )
76
94
77
95
class ResponseError extends Error {
@@ -317,6 +335,15 @@ async function getErrorResponseBody(
317
335
}
318
336
}
319
337
338
+ function desc ( value : any ) {
339
+ return {
340
+ __proto__ : null ,
341
+ configurable : true ,
342
+ value,
343
+ writable : true
344
+ } as PropertyDescriptor
345
+ }
346
+
320
347
function getHttpModule ( baseUrl : string ) : typeof http | typeof https {
321
348
const { protocol } = new URL ( baseUrl )
322
349
return protocol === 'https:' ? https : http
@@ -377,6 +404,23 @@ function isResponseOk(response: IncomingMessage): boolean {
377
404
)
378
405
}
379
406
407
+ function promiseWithResolvers < T > ( ) : ReturnType <
408
+ typeof Promise . withResolvers < T >
409
+ > {
410
+ if ( Promise . withResolvers ) {
411
+ return Promise . withResolvers < T > ( )
412
+ }
413
+
414
+ // This is what the above does but it's not available in node 20 (it is in node 22)
415
+ // @ts -ignore -- sigh.
416
+ const obj : ReturnType < typeof Promise . withResolvers < T > > = { }
417
+ obj . promise = new Promise < T > ( ( resolver , reject ) => {
418
+ obj . resolve = resolver
419
+ obj . reject = reject
420
+ } )
421
+ return obj
422
+ }
423
+
380
424
function resolveAbsPaths (
381
425
filepaths : string [ ] ,
382
426
pathsRelativeTo ?: string
@@ -512,7 +556,7 @@ export class SocketSdk {
512
556
// The error payload may give a meaningful hint as to what went wrong.
513
557
const bodyStr = await getErrorResponseBody ( error . response )
514
558
// Try to parse the body as JSON, fallback to treating as plain text.
515
- let body
559
+ let body : string | undefined
516
560
try {
517
561
const parsed = JSON . parse ( bodyStr )
518
562
// A 400 should return an actionable message.
@@ -724,7 +768,7 @@ export class SocketSdk {
724
768
}
725
769
}
726
770
727
- async createReportFromFilepaths (
771
+ async createScanFromFilepaths (
728
772
filepaths : string [ ] ,
729
773
pathsRelativeTo : string = '.' ,
730
774
issueRules ?: Record < string , boolean >
@@ -752,19 +796,6 @@ export class SocketSdk {
752
796
}
753
797
}
754
798
755
- // Alias to preserve backwards compatibility.
756
- async createReportFromFilePaths (
757
- filepaths : string [ ] ,
758
- pathsRelativeTo : string = '.' ,
759
- issueRules ?: Record < string , boolean >
760
- ) : Promise < SocketSdkResultType < 'createReport' > > {
761
- return await this . createReportFromFilepaths (
762
- filepaths ,
763
- pathsRelativeTo ,
764
- issueRules
765
- )
766
- }
767
-
768
799
async deleteOrgFullScan (
769
800
orgSlug : string ,
770
801
fullScanId : string
@@ -1030,7 +1061,7 @@ export class SocketSdk {
1030
1061
}
1031
1062
}
1032
1063
1033
- async getReport ( id : string ) : Promise < SocketSdkResultType < 'getReport' > > {
1064
+ async getScan ( id : string ) : Promise < SocketSdkResultType < 'getReport' > > {
1034
1065
try {
1035
1066
const data = await getResponseJson (
1036
1067
await createGetRequest (
@@ -1045,7 +1076,7 @@ export class SocketSdk {
1045
1076
}
1046
1077
}
1047
1078
1048
- async getReportList ( ) : Promise < SocketSdkResultType < 'getReportList' > > {
1079
+ async getScanList ( ) : Promise < SocketSdkResultType < 'getReportList' > > {
1049
1080
try {
1050
1081
const data = await getResponseJson (
1051
1082
await createGetRequest ( this . #baseUrl, 'report/list' , this . #reqOptions)
@@ -1056,7 +1087,7 @@ export class SocketSdk {
1056
1087
}
1057
1088
}
1058
1089
1059
- async getReportSupportedFiles ( ) : Promise <
1090
+ async getSupportedScanFiles ( ) : Promise <
1060
1091
SocketSdkResultType < 'getReportSupportedFiles' >
1061
1092
> {
1062
1093
try {
@@ -1073,7 +1104,7 @@ export class SocketSdk {
1073
1104
}
1074
1105
}
1075
1106
1076
- async getScoreByNPMPackage (
1107
+ async getScoreByNpmPackage (
1077
1108
pkgName : string ,
1078
1109
version : string
1079
1110
) : Promise < SocketSdkResultType < 'getScoreByNPMPackage' > > {
@@ -1146,21 +1177,39 @@ export class SocketSdk {
1146
1177
return await this . #handleApiError< 'updateOrgRepo' > ( e )
1147
1178
}
1148
1179
}
1149
- }
1150
1180
1151
- function promiseWithResolvers < T > ( ) : ReturnType <
1152
- typeof Promise . withResolvers < T >
1153
- > {
1154
- if ( Promise . withResolvers ) {
1155
- return Promise . withResolvers < T > ( )
1181
+ async uploadManifestFiles (
1182
+ orgSlug : string ,
1183
+ filepaths : string [ ] ,
1184
+ pathsRelativeTo : string = '.'
1185
+ ) : Promise < UploadManifestFilesReturnType | UploadManifestFilesError > {
1186
+ const basePath = resolveBasePath ( pathsRelativeTo )
1187
+ const absFilepaths = resolveAbsPaths ( filepaths , basePath )
1188
+ try {
1189
+ const data = await getResponseJson (
1190
+ await createUploadRequest (
1191
+ this . #baseUrl,
1192
+ `orgs/${ encodeURIComponent ( orgSlug ) } /upload-manifest-files` ,
1193
+ createRequestBodyForFilepaths ( absFilepaths , basePath ) ,
1194
+ this . #reqOptions
1195
+ )
1196
+ )
1197
+ return this . #handleApiSuccess< any > (
1198
+ data
1199
+ ) as unknown as UploadManifestFilesReturnType
1200
+ } catch ( e ) {
1201
+ return ( await this . #handleApiError< any > (
1202
+ e
1203
+ ) ) as unknown as UploadManifestFilesError
1204
+ }
1156
1205
}
1157
-
1158
- // This is what the above does but it's not available in node 20 (it is in node 22)
1159
- // @ts -ignore -- sigh.
1160
- const obj : ReturnType < typeof Promise . withResolvers < T > > = { }
1161
- obj . promise = new Promise < T > ( ( resolver , reject ) => {
1162
- obj . resolve = resolver
1163
- obj . reject = reject
1164
- } )
1165
- return obj
1166
1206
}
1207
+ // Add aliases.
1208
+ Object . defineProperties ( SocketSdk . prototype , {
1209
+ createReportFromFilepaths : desc ( SocketSdk . prototype . createScanFromFilepaths ) ,
1210
+ createReportFromFilePaths : desc ( SocketSdk . prototype . createScanFromFilepaths ) ,
1211
+ getReport : desc ( SocketSdk . prototype . getScan ) ,
1212
+ getReportList : desc ( SocketSdk . prototype . getScanList ) ,
1213
+ getReportSupportedFiles : desc ( SocketSdk . prototype . getSupportedScanFiles ) ,
1214
+ getScoreByNPMPackage : desc ( SocketSdk . prototype . getScoreByNpmPackage )
1215
+ } )
0 commit comments