@@ -29,8 +29,7 @@ import type {
29
29
30
30
export type Agent = HttpsAgent | HttpAgent | ClientHttp2Session
31
31
32
- export type BatchPackageFetchResultType =
33
- SocketSdkResultType < 'batchPackageFetch' >
32
+ export type BatchPackageFetchResultType = SocketSdkResult < 'batchPackageFetch' >
34
33
35
34
export type BatchPackageStreamOptions = {
36
35
chunkSize : number
@@ -50,21 +49,20 @@ export type RequestOptions =
50
49
51
50
export type SocketSdkOperations = keyof operations
52
51
53
- export type SocketSdkReturnType < T extends SocketSdkOperations > = OpReturnType <
54
- operations [ T ]
55
- >
52
+ export type SocketSdkSuccessResult < T extends SocketSdkOperations > =
53
+ OpReturnType < operations [ T ] >
56
54
57
- export type SocketSdkErrorType < T extends SocketSdkOperations > = Omit <
55
+ export type SocketSdkErrorResult < T extends SocketSdkOperations > = Omit <
58
56
OpErrorType < operations [ T ] > ,
59
57
'error'
60
58
> & {
61
59
error : string
62
- cause ?: unknown
60
+ cause ?: string | undefined
63
61
}
64
62
65
- export type SocketSdkResultType < T extends SocketSdkOperations > =
66
- | SocketSdkReturnType < T >
67
- | SocketSdkErrorType < T >
63
+ export type SocketSdkResult < T extends SocketSdkOperations > =
64
+ | SocketSdkSuccessResult < T >
65
+ | SocketSdkErrorResult < T >
68
66
69
67
export interface SocketSdkOptions {
70
68
agent ?: Agent | GotOptions | undefined
@@ -541,7 +539,7 @@ export class SocketSdk {
541
539
542
540
async #handleApiError< T extends SocketSdkOperations > (
543
541
error : unknown
544
- ) : Promise < SocketSdkErrorType < T > > {
542
+ ) : Promise < SocketSdkErrorResult < T > > {
545
543
if ( ! ( error instanceof ResponseError ) ) {
546
544
throw new Error ( 'Unexpected Socket API error' , {
547
545
cause : error
@@ -568,21 +566,21 @@ export class SocketSdk {
568
566
body = bodyStr
569
567
}
570
568
return {
571
- success : false as const ,
569
+ success : false ,
572
570
status : statusCode ! ,
573
571
error : error . message ?? '' ,
574
572
cause : body
575
- } as unknown as SocketSdkErrorType < T >
573
+ } as SocketSdkErrorResult < T >
576
574
}
577
575
578
576
#handleApiSuccess< T extends SocketSdkOperations > (
579
577
data : unknown
580
- ) : SocketSdkReturnType < T > {
578
+ ) : SocketSdkSuccessResult < T > {
581
579
return {
582
580
success : true ,
583
581
status : 200 ,
584
- data : data as SocketSdkReturnType < T > [ 'data' ]
585
- } satisfies SocketSdkReturnType < T >
582
+ data : data as SocketSdkSuccessResult < T > [ 'data' ]
583
+ } satisfies SocketSdkSuccessResult < T >
586
584
}
587
585
588
586
async batchPackageFetch (
@@ -708,7 +706,7 @@ export class SocketSdk {
708
706
params : Record < string , string > ,
709
707
filepaths : string [ ] ,
710
708
pathsRelativeTo = '.'
711
- ) : Promise < SocketSdkResultType < 'createDependenciesSnapshot' > > {
709
+ ) : Promise < SocketSdkResult < 'createDependenciesSnapshot' > > {
712
710
const basePath = resolveBasePath ( pathsRelativeTo )
713
711
const absFilepaths = resolveAbsPaths ( filepaths , basePath )
714
712
try {
@@ -731,7 +729,7 @@ export class SocketSdk {
731
729
queryParams : Record < string , string > | null | undefined ,
732
730
filepaths : string [ ] ,
733
731
pathsRelativeTo : string = '.'
734
- ) : Promise < SocketSdkResultType < 'CreateOrgFullScan' > > {
732
+ ) : Promise < SocketSdkResult < 'CreateOrgFullScan' > > {
735
733
const basePath = resolveBasePath ( pathsRelativeTo )
736
734
const absFilepaths = resolveAbsPaths ( filepaths , basePath )
737
735
try {
@@ -752,7 +750,7 @@ export class SocketSdk {
752
750
async createOrgRepo (
753
751
orgSlug : string ,
754
752
params : Record < string , string >
755
- ) : Promise < SocketSdkResultType < 'createOrgRepo' > > {
753
+ ) : Promise < SocketSdkResult < 'createOrgRepo' > > {
756
754
try {
757
755
const data = await getResponseJson (
758
756
await createPostRequest (
@@ -772,7 +770,7 @@ export class SocketSdk {
772
770
filepaths : string [ ] ,
773
771
pathsRelativeTo : string = '.' ,
774
772
issueRules ?: Record < string , boolean >
775
- ) : Promise < SocketSdkResultType < 'createReport' > > {
773
+ ) : Promise < SocketSdkResult < 'createReport' > > {
776
774
const basePath = resolveBasePath ( pathsRelativeTo )
777
775
const absFilepaths = resolveAbsPaths ( filepaths , basePath )
778
776
try {
@@ -799,7 +797,7 @@ export class SocketSdk {
799
797
async deleteOrgFullScan (
800
798
orgSlug : string ,
801
799
fullScanId : string
802
- ) : Promise < SocketSdkResultType < 'deleteOrgFullScan' > > {
800
+ ) : Promise < SocketSdkResult < 'deleteOrgFullScan' > > {
803
801
try {
804
802
const data = await getResponseJson (
805
803
await createDeleteRequest (
@@ -817,7 +815,7 @@ export class SocketSdk {
817
815
async deleteOrgRepo (
818
816
orgSlug : string ,
819
817
repoSlug : string
820
- ) : Promise < SocketSdkResultType < 'deleteOrgRepo' > > {
818
+ ) : Promise < SocketSdkResult < 'deleteOrgRepo' > > {
821
819
try {
822
820
const data = await getResponseJson (
823
821
await createDeleteRequest (
@@ -835,7 +833,7 @@ export class SocketSdk {
835
833
async getAuditLogEvents (
836
834
orgSlug : string ,
837
835
queryParams ?: Record < string , string > | null | undefined
838
- ) : Promise < SocketSdkResultType < 'getAuditLogEvents' > > {
836
+ ) : Promise < SocketSdkResult < 'getAuditLogEvents' > > {
839
837
try {
840
838
const data = await getResponseJson (
841
839
await createGetRequest (
@@ -853,7 +851,7 @@ export class SocketSdk {
853
851
async getIssuesByNPMPackage (
854
852
pkgName : string ,
855
853
version : string
856
- ) : Promise < SocketSdkResultType < 'getIssuesByNPMPackage' > > {
854
+ ) : Promise < SocketSdkResult < 'getIssuesByNPMPackage' > > {
857
855
try {
858
856
const data = await getResponseJson (
859
857
await createGetRequest (
@@ -870,7 +868,7 @@ export class SocketSdk {
870
868
871
869
async getOrgAnalytics (
872
870
time : string
873
- ) : Promise < SocketSdkResultType < 'getOrgAnalytics' > > {
871
+ ) : Promise < SocketSdkResult < 'getOrgAnalytics' > > {
874
872
try {
875
873
const data = await getResponseJson (
876
874
await createGetRequest (
@@ -885,7 +883,7 @@ export class SocketSdk {
885
883
}
886
884
}
887
885
888
- async getOrganizations ( ) : Promise < SocketSdkResultType < 'getOrganizations' > > {
886
+ async getOrganizations ( ) : Promise < SocketSdkResult < 'getOrganizations' > > {
889
887
try {
890
888
const data = await getResponseJson (
891
889
await createGetRequest ( this . #baseUrl, 'organizations' , this . #reqOptions)
@@ -900,7 +898,7 @@ export class SocketSdk {
900
898
orgSlug : string ,
901
899
fullScanId : string ,
902
900
file ?: string
903
- ) : Promise < SocketSdkResultType < 'getOrgFullScan' > > {
901
+ ) : Promise < SocketSdkResult < 'getOrgFullScan' > > {
904
902
try {
905
903
const req = getHttpModule ( this . #baseUrl)
906
904
. request (
@@ -926,7 +924,7 @@ export class SocketSdk {
926
924
async getOrgFullScanList (
927
925
orgSlug : string ,
928
926
queryParams ?: Record < string , string > | null | undefined
929
- ) : Promise < SocketSdkResultType < 'getOrgFullScanList' > > {
927
+ ) : Promise < SocketSdkResult < 'getOrgFullScanList' > > {
930
928
try {
931
929
const data = await getResponseJson (
932
930
await createGetRequest (
@@ -944,7 +942,7 @@ export class SocketSdk {
944
942
async getOrgFullScanMetadata (
945
943
orgSlug : string ,
946
944
fullScanId : string
947
- ) : Promise < SocketSdkResultType < 'getOrgFullScanMetadata' > > {
945
+ ) : Promise < SocketSdkResult < 'getOrgFullScanMetadata' > > {
948
946
try {
949
947
const data = await getResponseJson (
950
948
await createGetRequest (
@@ -961,7 +959,7 @@ export class SocketSdk {
961
959
962
960
async getOrgLicensePolicy (
963
961
orgSlug : string
964
- ) : Promise < SocketSdkResultType < 'getOrgLicensePolicy' > > {
962
+ ) : Promise < SocketSdkResult < 'getOrgLicensePolicy' > > {
965
963
try {
966
964
const data = await getResponseJson (
967
965
await createGetRequest (
@@ -979,7 +977,7 @@ export class SocketSdk {
979
977
async getOrgRepo (
980
978
orgSlug : string ,
981
979
repoSlug : string
982
- ) : Promise < SocketSdkResultType < 'getOrgRepo' > > {
980
+ ) : Promise < SocketSdkResult < 'getOrgRepo' > > {
983
981
const orgSlugParam = encodeURIComponent ( orgSlug )
984
982
const repoSlugParam = encodeURIComponent ( repoSlug )
985
983
@@ -1000,7 +998,7 @@ export class SocketSdk {
1000
998
async getOrgRepoList (
1001
999
orgSlug : string ,
1002
1000
queryParams ?: Record < string , string > | null | undefined
1003
- ) : Promise < SocketSdkResultType < 'getOrgRepoList' > > {
1001
+ ) : Promise < SocketSdkResult < 'getOrgRepoList' > > {
1004
1002
try {
1005
1003
const data = await getResponseJson (
1006
1004
await createGetRequest (
@@ -1017,7 +1015,7 @@ export class SocketSdk {
1017
1015
1018
1016
async getOrgSecurityPolicy (
1019
1017
orgSlug : string
1020
- ) : Promise < SocketSdkResultType < 'getOrgSecurityPolicy' > > {
1018
+ ) : Promise < SocketSdkResult < 'getOrgSecurityPolicy' > > {
1021
1019
try {
1022
1020
const data = await getResponseJson (
1023
1021
await createGetRequest (
@@ -1032,7 +1030,7 @@ export class SocketSdk {
1032
1030
}
1033
1031
}
1034
1032
1035
- async getQuota ( ) : Promise < SocketSdkResultType < 'getQuota' > > {
1033
+ async getQuota ( ) : Promise < SocketSdkResult < 'getQuota' > > {
1036
1034
try {
1037
1035
const data = await getResponseJson (
1038
1036
await createGetRequest ( this . #baseUrl, 'quota' , this . #reqOptions)
@@ -1046,7 +1044,7 @@ export class SocketSdk {
1046
1044
async getRepoAnalytics (
1047
1045
repo : string ,
1048
1046
time : string
1049
- ) : Promise < SocketSdkResultType < 'getRepoAnalytics' > > {
1047
+ ) : Promise < SocketSdkResult < 'getRepoAnalytics' > > {
1050
1048
try {
1051
1049
const data = await getResponseJson (
1052
1050
await createGetRequest (
@@ -1061,7 +1059,7 @@ export class SocketSdk {
1061
1059
}
1062
1060
}
1063
1061
1064
- async getScan ( id : string ) : Promise < SocketSdkResultType < 'getReport' > > {
1062
+ async getScan ( id : string ) : Promise < SocketSdkResult < 'getReport' > > {
1065
1063
try {
1066
1064
const data = await getResponseJson (
1067
1065
await createGetRequest (
@@ -1076,7 +1074,7 @@ export class SocketSdk {
1076
1074
}
1077
1075
}
1078
1076
1079
- async getScanList ( ) : Promise < SocketSdkResultType < 'getReportList' > > {
1077
+ async getScanList ( ) : Promise < SocketSdkResult < 'getReportList' > > {
1080
1078
try {
1081
1079
const data = await getResponseJson (
1082
1080
await createGetRequest ( this . #baseUrl, 'report/list' , this . #reqOptions)
@@ -1088,7 +1086,7 @@ export class SocketSdk {
1088
1086
}
1089
1087
1090
1088
async getSupportedScanFiles ( ) : Promise <
1091
- SocketSdkResultType < 'getReportSupportedFiles' >
1089
+ SocketSdkResult < 'getReportSupportedFiles' >
1092
1090
> {
1093
1091
try {
1094
1092
const data = await getResponseJson (
@@ -1107,7 +1105,7 @@ export class SocketSdk {
1107
1105
async getScoreByNpmPackage (
1108
1106
pkgName : string ,
1109
1107
version : string
1110
- ) : Promise < SocketSdkResultType < 'getScoreByNPMPackage' > > {
1108
+ ) : Promise < SocketSdkResult < 'getScoreByNPMPackage' > > {
1111
1109
try {
1112
1110
const data = await getResponseJson (
1113
1111
await createGetRequest (
@@ -1124,7 +1122,7 @@ export class SocketSdk {
1124
1122
1125
1123
async postSettings (
1126
1124
selectors : Array < { organization ?: string } >
1127
- ) : Promise < SocketSdkResultType < 'postSettings' > > {
1125
+ ) : Promise < SocketSdkResult < 'postSettings' > > {
1128
1126
try {
1129
1127
const data = await getResponseJson (
1130
1128
await createPostRequest (
@@ -1142,7 +1140,7 @@ export class SocketSdk {
1142
1140
1143
1141
async searchDependencies (
1144
1142
params : Record < string , number >
1145
- ) : Promise < SocketSdkResultType < 'searchDependencies' > > {
1143
+ ) : Promise < SocketSdkResult < 'searchDependencies' > > {
1146
1144
try {
1147
1145
const data = await getResponseJson (
1148
1146
await createPostRequest (
@@ -1162,7 +1160,7 @@ export class SocketSdk {
1162
1160
orgSlug : string ,
1163
1161
repoSlug : string ,
1164
1162
params : Record < string , string >
1165
- ) : Promise < SocketSdkResultType < 'updateOrgRepo' > > {
1163
+ ) : Promise < SocketSdkResult < 'updateOrgRepo' > > {
1166
1164
try {
1167
1165
const data = await getResponseJson (
1168
1166
await createPostRequest (
0 commit comments