@socketsecurity/sdk 1.9.1 → 1.9.2
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.
- package/CHANGELOG.md +5 -0
- package/README.md +3 -4
- package/dist/http-client.d.ts +2 -2
- package/dist/quota-utils.d.ts +20 -20
- package/dist/quota-utils.js +58 -58
- package/dist/socket-sdk-class.d.ts +144 -144
- package/dist/socket-sdk-class.js +532 -530
- package/dist/types.d.ts +9 -9
- package/package.json +13 -12
- package/requirements.json +232 -0
- package/types/api.d.ts +871 -767
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
6
|
|
|
7
|
+
## [1.9.2](https://github.com/SocketDev/socket-sdk-js/releases/tag/v1.9.2) - 2025-10-04
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- Improved TypeScript type definitions - All optional properties now include explicit `| undefined` type annotations for better type narrowing and null safety
|
|
11
|
+
|
|
7
12
|
## [1.9.1](https://github.com/SocketDev/socket-sdk-js/releases/tag/v1.9.1) - 2025-10-03
|
|
8
13
|
|
|
9
14
|
### Changed
|
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# @socketsecurity/sdk
|
|
2
2
|
|
|
3
3
|
[](https://socket.dev/npm/package/@socketsecurity/sdk)
|
|
4
|
-
[](https://github.com/SocketDev/eslint-config)
|
|
4
|
+
[](https://github.com/SocketDev/socket-sdk-js/actions/workflows/ci.yml)
|
|
5
|
+
|
|
7
6
|
[](https://twitter.com/SocketSecurity)
|
|
8
7
|
[](https://bsky.app/profile/socket.dev)
|
|
9
8
|
|
|
10
|
-
SDK for
|
|
9
|
+
Official SDK for Socket.dev - Programmatic access to security analysis, vulnerability scanning, and compliance monitoring for your software supply chain.
|
|
11
10
|
|
|
12
11
|
## Usage
|
|
13
12
|
|
package/dist/http-client.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export declare function getResponse(req: ClientRequest): Promise<IncomingMessage
|
|
|
65
65
|
* @throws {ResponseError} When response has non-2xx status code
|
|
66
66
|
* @throws {SyntaxError} When response body contains invalid JSON
|
|
67
67
|
*/
|
|
68
|
-
export declare function getResponseJson(response: IncomingMessage, method?: string): Promise<import("@socketsecurity/registry/lib/json").JsonValue | undefined>;
|
|
68
|
+
export declare function getResponseJson(response: IncomingMessage, method?: string | undefined): Promise<import("@socketsecurity/registry/lib/json").JsonValue | undefined>;
|
|
69
69
|
/**
|
|
70
70
|
* Check if HTTP response has a successful status code (2xx range).
|
|
71
71
|
* Returns true for status codes between 200-299, false otherwise.
|
|
@@ -75,4 +75,4 @@ export declare function isResponseOk(response: IncomingMessage): boolean;
|
|
|
75
75
|
* Transform artifact data based on authentication status.
|
|
76
76
|
* Filters and compacts response data for public/free-tier users.
|
|
77
77
|
*/
|
|
78
|
-
export declare function reshapeArtifactForPublicPolicy<T extends Record<string, any>>(data: T, isAuthenticated: boolean, actions?: string): T;
|
|
78
|
+
export declare function reshapeArtifactForPublicPolicy<T extends Record<string, any>>(data: T, isAuthenticated: boolean, actions?: string | undefined): T;
|
package/dist/quota-utils.d.ts
CHANGED
|
@@ -4,48 +4,48 @@ interface ApiRequirement {
|
|
|
4
4
|
permissions: string[];
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* Returns
|
|
7
|
+
* Calculate total quota cost for multiple SDK method calls.
|
|
8
|
+
* Returns sum of quota units for all specified methods.
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function calculateTotalQuotaCost(methodNames: Array<SocketSdkOperations | string>): number;
|
|
11
11
|
/**
|
|
12
|
-
* Get
|
|
13
|
-
* Returns
|
|
12
|
+
* Get all available SDK methods with their requirements.
|
|
13
|
+
* Returns complete mapping of methods to quota and permissions.
|
|
14
14
|
*/
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function getAllMethodRequirements(): Record<string, ApiRequirement>;
|
|
16
16
|
/**
|
|
17
17
|
* Get complete requirement information for a SDK method.
|
|
18
18
|
* Returns both quota cost and required permissions.
|
|
19
19
|
*/
|
|
20
20
|
export declare function getMethodRequirements(methodName: SocketSdkOperations | string): ApiRequirement;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
* Returns
|
|
22
|
+
* Get all methods that require specific permissions.
|
|
23
|
+
* Returns methods that need any of the specified permissions.
|
|
24
24
|
*/
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function getMethodsByPermissions(permissions: string[]): string[];
|
|
26
26
|
/**
|
|
27
27
|
* Get all methods that consume a specific quota amount.
|
|
28
28
|
* Useful for finding high-cost or free operations.
|
|
29
29
|
*/
|
|
30
30
|
export declare function getMethodsByQuotaCost(quotaCost: number): string[];
|
|
31
31
|
/**
|
|
32
|
-
* Get
|
|
33
|
-
* Returns
|
|
34
|
-
*/
|
|
35
|
-
export declare function getMethodsByPermissions(permissions: string[]): string[];
|
|
36
|
-
/**
|
|
37
|
-
* Check if user has sufficient quota for method calls.
|
|
38
|
-
* Returns true if available quota covers the total cost.
|
|
32
|
+
* Get quota cost for a specific SDK method.
|
|
33
|
+
* Returns the number of quota units consumed by the method.
|
|
39
34
|
*/
|
|
40
|
-
export declare function
|
|
35
|
+
export declare function getQuotaCost(methodName: SocketSdkOperations | string): number;
|
|
41
36
|
/**
|
|
42
37
|
* Get quota usage summary grouped by cost levels.
|
|
43
38
|
* Returns methods categorized by their quota consumption.
|
|
44
39
|
*/
|
|
45
40
|
export declare function getQuotaUsageSummary(): Record<string, string[]>;
|
|
46
41
|
/**
|
|
47
|
-
* Get
|
|
48
|
-
* Returns
|
|
42
|
+
* Get required permissions for a specific SDK method.
|
|
43
|
+
* Returns array of permission strings needed to call the method.
|
|
49
44
|
*/
|
|
50
|
-
export declare function
|
|
45
|
+
export declare function getRequiredPermissions(methodName: SocketSdkOperations | string): string[];
|
|
46
|
+
/**
|
|
47
|
+
* Check if user has sufficient quota for method calls.
|
|
48
|
+
* Returns true if available quota covers the total cost.
|
|
49
|
+
*/
|
|
50
|
+
export declare function hasQuotaForMethods(availableQuota: number, methodNames: Array<SocketSdkOperations | string>): boolean;
|
|
51
51
|
export {};
|
package/dist/quota-utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getQuotaCost = getQuotaCost;
|
|
4
|
-
exports.getRequiredPermissions = getRequiredPermissions;
|
|
5
|
-
exports.getMethodRequirements = getMethodRequirements;
|
|
6
3
|
exports.calculateTotalQuotaCost = calculateTotalQuotaCost;
|
|
7
|
-
exports.
|
|
4
|
+
exports.getAllMethodRequirements = getAllMethodRequirements;
|
|
5
|
+
exports.getMethodRequirements = getMethodRequirements;
|
|
8
6
|
exports.getMethodsByPermissions = getMethodsByPermissions;
|
|
9
|
-
exports.
|
|
7
|
+
exports.getMethodsByQuotaCost = getMethodsByQuotaCost;
|
|
8
|
+
exports.getQuotaCost = getQuotaCost;
|
|
10
9
|
exports.getQuotaUsageSummary = getQuotaUsageSummary;
|
|
11
|
-
exports.
|
|
10
|
+
exports.getRequiredPermissions = getRequiredPermissions;
|
|
11
|
+
exports.hasQuotaForMethods = hasQuotaForMethods;
|
|
12
12
|
/** @fileoverview Quota utility functions for Socket SDK method cost lookup. */
|
|
13
13
|
const node_fs_1 = require("node:fs");
|
|
14
14
|
const node_path_1 = require("node:path");
|
|
@@ -33,28 +33,28 @@ function loadRequirements() {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* Returns
|
|
36
|
+
* Calculate total quota cost for multiple SDK method calls.
|
|
37
|
+
* Returns sum of quota units for all specified methods.
|
|
38
38
|
*/
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
throw new Error(`Unknown SDK method: "${methodName}"`);
|
|
44
|
-
}
|
|
45
|
-
return requirement.quota;
|
|
39
|
+
function calculateTotalQuotaCost(methodNames) {
|
|
40
|
+
return methodNames.reduce((total, methodName) => {
|
|
41
|
+
return total + getQuotaCost(methodName);
|
|
42
|
+
}, 0);
|
|
46
43
|
}
|
|
47
44
|
/**
|
|
48
|
-
* Get
|
|
49
|
-
* Returns
|
|
45
|
+
* Get all available SDK methods with their requirements.
|
|
46
|
+
* Returns complete mapping of methods to quota and permissions.
|
|
50
47
|
*/
|
|
51
|
-
function
|
|
48
|
+
function getAllMethodRequirements() {
|
|
52
49
|
const reqs = loadRequirements();
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
const result = {};
|
|
51
|
+
Object.entries(reqs.api).forEach(([methodName, requirement]) => {
|
|
52
|
+
result[methodName] = {
|
|
53
|
+
permissions: [...requirement.permissions],
|
|
54
|
+
quota: requirement.quota,
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
return result;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* Get complete requirement information for a SDK method.
|
|
@@ -67,18 +67,22 @@ function getMethodRequirements(methodName) {
|
|
|
67
67
|
throw new Error(`Unknown SDK method: "${methodName}"`);
|
|
68
68
|
}
|
|
69
69
|
return {
|
|
70
|
-
quota: requirement.quota,
|
|
71
70
|
permissions: [...requirement.permissions],
|
|
71
|
+
quota: requirement.quota,
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
76
|
-
* Returns
|
|
75
|
+
* Get all methods that require specific permissions.
|
|
76
|
+
* Returns methods that need any of the specified permissions.
|
|
77
77
|
*/
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
function getMethodsByPermissions(permissions) {
|
|
79
|
+
const reqs = loadRequirements();
|
|
80
|
+
return Object.entries(reqs.api)
|
|
81
|
+
.filter(([, requirement]) => {
|
|
82
|
+
return permissions.some(permission => requirement.permissions.includes(permission));
|
|
83
|
+
})
|
|
84
|
+
.map(([methodName]) => methodName)
|
|
85
|
+
.sort();
|
|
82
86
|
}
|
|
83
87
|
/**
|
|
84
88
|
* Get all methods that consume a specific quota amount.
|
|
@@ -92,25 +96,16 @@ function getMethodsByQuotaCost(quotaCost) {
|
|
|
92
96
|
.sort();
|
|
93
97
|
}
|
|
94
98
|
/**
|
|
95
|
-
* Get
|
|
96
|
-
* Returns
|
|
99
|
+
* Get quota cost for a specific SDK method.
|
|
100
|
+
* Returns the number of quota units consumed by the method.
|
|
97
101
|
*/
|
|
98
|
-
function
|
|
102
|
+
function getQuotaCost(methodName) {
|
|
99
103
|
const reqs = loadRequirements();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
.sort();
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Check if user has sufficient quota for method calls.
|
|
109
|
-
* Returns true if available quota covers the total cost.
|
|
110
|
-
*/
|
|
111
|
-
function hasQuotaForMethods(availableQuota, methodNames) {
|
|
112
|
-
const totalCost = calculateTotalQuotaCost(methodNames);
|
|
113
|
-
return availableQuota >= totalCost;
|
|
104
|
+
const requirement = reqs.api[methodName];
|
|
105
|
+
if (!requirement) {
|
|
106
|
+
throw new Error(`Unknown SDK method: "${methodName}"`);
|
|
107
|
+
}
|
|
108
|
+
return requirement.quota;
|
|
114
109
|
}
|
|
115
110
|
/**
|
|
116
111
|
* Get quota usage summary grouped by cost levels.
|
|
@@ -133,17 +128,22 @@ function getQuotaUsageSummary() {
|
|
|
133
128
|
return summary;
|
|
134
129
|
}
|
|
135
130
|
/**
|
|
136
|
-
* Get
|
|
137
|
-
* Returns
|
|
131
|
+
* Get required permissions for a specific SDK method.
|
|
132
|
+
* Returns array of permission strings needed to call the method.
|
|
138
133
|
*/
|
|
139
|
-
function
|
|
134
|
+
function getRequiredPermissions(methodName) {
|
|
140
135
|
const reqs = loadRequirements();
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
const requirement = reqs.api[methodName];
|
|
137
|
+
if (!requirement) {
|
|
138
|
+
throw new Error(`Unknown SDK method: "${methodName}"`);
|
|
139
|
+
}
|
|
140
|
+
return [...requirement.permissions];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if user has sufficient quota for method calls.
|
|
144
|
+
* Returns true if available quota covers the total cost.
|
|
145
|
+
*/
|
|
146
|
+
function hasQuotaForMethods(availableQuota, methodNames) {
|
|
147
|
+
const totalCost = calculateTotalQuotaCost(methodNames);
|
|
148
|
+
return availableQuota >= totalCost;
|
|
149
149
|
}
|