@socketsecurity/sdk 1.9.1 → 1.10.0
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 +29 -0
- package/README.md +29 -5
- package/dist/constants.js +0 -3
- package/dist/file-upload.js +2 -2
- package/dist/http-client.d.ts +37 -2
- package/dist/http-client.js +86 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +13 -13
- package/dist/promise-queue.d.ts +35 -0
- package/dist/promise-queue.js +91 -0
- package/dist/quota-utils.d.ts +20 -20
- package/dist/quota-utils.js +63 -60
- package/dist/socket-sdk-class.d.ts +148 -148
- package/dist/socket-sdk-class.js +574 -510
- package/dist/types.d.ts +32 -10
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +2 -2
- package/package.json +13 -12
- package/requirements.json +232 -0
- package/types/api.d.ts +871 -767
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,35 @@ 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.10.0](https://github.com/SocketDev/socket-sdk-js/releases/tag/v1.10.0) - 2025-10-04
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Added `PromiseQueue` utility for controlled concurrency in async operations
|
|
11
|
+
- HTTP retry logic with exponential backoff for improved reliability on transient failures
|
|
12
|
+
- Added option type interfaces: `CreateDependenciesSnapshotOptions`, `CreateOrgFullScanOptions`, `CreateScanFromFilepathsOptions`, `StreamOrgFullScanOptions`, `UploadManifestFilesOptions`
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- **BREAKING**: Refactored SDK methods to use options objects instead of positional parameters for better API clarity:
|
|
16
|
+
- `createDependenciesSnapshot(filepaths, options)` - replaced `repo` and `branch` positional parameters with options object
|
|
17
|
+
- `createOrgFullScan(orgSlug, filepaths, options)` - replaced positional parameters with options object
|
|
18
|
+
- `createScanFromFilepaths(filepaths, options)` - replaced positional parameters with options object
|
|
19
|
+
- `streamOrgFullScan(orgSlug, fullScanId, options)` - replaced positional parameters with options object
|
|
20
|
+
- `uploadManifestFiles(orgSlug, filepaths, options)` - replaced positional parameters with options object
|
|
21
|
+
- Improved type safety by replacing `any` types with `unknown` or `never` where appropriate
|
|
22
|
+
- Enhanced code style with numeric separators for better readability of large numbers
|
|
23
|
+
- Improved coverage reporting accuracy with c8 ignore comments
|
|
24
|
+
- Updated `@socketsecurity/registry` dependency to 1.4.0
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
- Fixed import assertion syntax for JSON imports to use standard import syntax
|
|
28
|
+
- Fixed HTTP retry test mocks to correctly match PUT method requests
|
|
29
|
+
- Fixed critical issues in type handling and URL search parameter conversions
|
|
30
|
+
|
|
31
|
+
## [1.9.2](https://github.com/SocketDev/socket-sdk-js/releases/tag/v1.9.2) - 2025-10-04
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
- Improved TypeScript type definitions - All optional properties now include explicit `| undefined` type annotations for better type narrowing and null safety
|
|
35
|
+
|
|
7
36
|
## [1.9.1](https://github.com/SocketDev/socket-sdk-js/releases/tag/v1.9.1) - 2025-10-03
|
|
8
37
|
|
|
9
38
|
### 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
|
|
|
@@ -20,7 +19,11 @@ pnpm add @socketsecurity/sdk
|
|
|
20
19
|
```javascript
|
|
21
20
|
import { SocketSdk } from '@socketsecurity/sdk'
|
|
22
21
|
|
|
23
|
-
const client = new SocketSdk('yourApiKeyHere'
|
|
22
|
+
const client = new SocketSdk('yourApiKeyHere', {
|
|
23
|
+
retries: 3, // Retry failed requests up to 3 times (default: 3)
|
|
24
|
+
retryDelay: 1000, // Start with 1s delay, exponential backoff (default: 1000ms)
|
|
25
|
+
timeout: 30000, // Request timeout in milliseconds (optional)
|
|
26
|
+
})
|
|
24
27
|
|
|
25
28
|
const res = await client.getQuota()
|
|
26
29
|
|
|
@@ -30,6 +33,27 @@ if (res.success) {
|
|
|
30
33
|
}
|
|
31
34
|
```
|
|
32
35
|
|
|
36
|
+
### Configuration Options
|
|
37
|
+
|
|
38
|
+
The SDK constructor accepts the following options:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
interface SocketSdkOptions {
|
|
42
|
+
baseUrl?: string // API base URL (default: 'https://api.socket.dev/v0/')
|
|
43
|
+
timeout?: number // Request timeout in milliseconds
|
|
44
|
+
retries?: number // Number of retry attempts for failed requests (default: 3)
|
|
45
|
+
retryDelay?: number // Initial retry delay in ms, with exponential backoff (default: 1000)
|
|
46
|
+
userAgent?: string // Custom user agent string
|
|
47
|
+
agent?: Agent // Custom HTTP agent for advanced networking
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Retry Logic:**
|
|
52
|
+
- Automatically retries transient network errors and 5xx server responses
|
|
53
|
+
- Uses exponential backoff: 1s, 2s, 4s, 8s... (configurable via `retryDelay`)
|
|
54
|
+
- Does NOT retry 401/403 authentication errors (immediate failure)
|
|
55
|
+
- Set `retries: 0` to disable retry logic entirely
|
|
56
|
+
|
|
33
57
|
### Quota Management Example
|
|
34
58
|
|
|
35
59
|
```javascript
|
package/dist/constants.js
CHANGED
|
@@ -8,9 +8,6 @@ exports.publicPolicy = exports.httpAgentNames = exports.DEFAULT_USER_AGENT = voi
|
|
|
8
8
|
* @fileoverview Configuration constants and enums for the Socket SDK.
|
|
9
9
|
* Provides default values, HTTP agents, and public policy configurations for API interactions.
|
|
10
10
|
*/
|
|
11
|
-
// Import attributes are only supported when the '--module' option is set to
|
|
12
|
-
// 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
|
|
13
|
-
// @ts-ignore: Avoid TS import attributes error.
|
|
14
11
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
15
12
|
const user_agent_1 = require("./user-agent");
|
|
16
13
|
exports.DEFAULT_USER_AGENT = (0, user_agent_1.createUserAgentFromPkgJson)(package_json_1.default);
|
package/dist/file-upload.js
CHANGED
|
@@ -24,7 +24,7 @@ function createRequestBodyForFilepaths(filepaths, basePath) {
|
|
|
24
24
|
const filename = node_path_1.default.basename(absPath);
|
|
25
25
|
requestBody.push([
|
|
26
26
|
`Content-Disposition: form-data; name="${relPath}"; filename="${filename}"\r\n`,
|
|
27
|
-
|
|
27
|
+
'Content-Type: application/octet-stream\r\n\r\n',
|
|
28
28
|
(0, node_fs_1.createReadStream)(absPath, { highWaterMark: 1024 * 1024 }),
|
|
29
29
|
]);
|
|
30
30
|
}
|
|
@@ -39,7 +39,7 @@ function createRequestBodyForJson(jsonData, basename = 'data.json') {
|
|
|
39
39
|
const name = node_path_1.default.basename(basename, ext);
|
|
40
40
|
return [
|
|
41
41
|
`Content-Disposition: form-data; name="${name}"; filename="${basename}"\r\n` +
|
|
42
|
-
|
|
42
|
+
'Content-Type: application/json\r\n\r\n',
|
|
43
43
|
node_stream_1.Readable.from(JSON.stringify(jsonData), { highWaterMark: 1024 * 1024 }),
|
|
44
44
|
'\r\n',
|
|
45
45
|
];
|
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,39 @@ 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,
|
|
78
|
+
export declare function reshapeArtifactForPublicPolicy<T extends Record<string, unknown>>(data: T, isAuthenticated: boolean, actions?: string | undefined): T;
|
|
79
|
+
/**
|
|
80
|
+
* Retry helper for HTTP requests with exponential backoff.
|
|
81
|
+
* Wraps any async HTTP function and retries on failure.
|
|
82
|
+
*
|
|
83
|
+
* @param fn - Async function to retry
|
|
84
|
+
* @param retries - Number of retry attempts (default: 3)
|
|
85
|
+
* @param retryDelay - Initial delay in ms (default: 1000)
|
|
86
|
+
* @returns Result of the function call
|
|
87
|
+
* @throws {Error} Last error if all retries exhausted
|
|
88
|
+
*/
|
|
89
|
+
export declare function withRetry<T>(fn: () => Promise<T>, retries?: number, retryDelay?: number): Promise<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Create GET request with automatic retry logic.
|
|
92
|
+
* Retries on network errors and 5xx responses.
|
|
93
|
+
*
|
|
94
|
+
* @param retries - Number of retry attempts (default: 3)
|
|
95
|
+
* @param retryDelay - Initial delay in ms (default: 1000)
|
|
96
|
+
*/
|
|
97
|
+
export declare function createGetRequestWithRetry(baseUrl: string, urlPath: string, options: RequestOptions, retries?: number, retryDelay?: number): Promise<IncomingMessage>;
|
|
98
|
+
/**
|
|
99
|
+
* Create DELETE request with automatic retry logic.
|
|
100
|
+
* Retries on network errors and 5xx responses.
|
|
101
|
+
*
|
|
102
|
+
* @param retries - Number of retry attempts (default: 3)
|
|
103
|
+
* @param retryDelay - Initial delay in ms (default: 1000)
|
|
104
|
+
*/
|
|
105
|
+
export declare function createDeleteRequestWithRetry(baseUrl: string, urlPath: string, options: RequestOptions, retries?: number, retryDelay?: number): Promise<IncomingMessage>;
|
|
106
|
+
/**
|
|
107
|
+
* Create request with JSON payload and automatic retry logic.
|
|
108
|
+
* Retries on network errors and 5xx responses.
|
|
109
|
+
*
|
|
110
|
+
* @param retries - Number of retry attempts (default: 3)
|
|
111
|
+
* @param retryDelay - Initial delay in ms (default: 1000)
|
|
112
|
+
*/
|
|
113
|
+
export declare function createRequestWithJsonAndRetry(method: SendMethod, baseUrl: string, urlPath: string, json: unknown, options: RequestOptions, retries?: number, retryDelay?: number): Promise<IncomingMessage>;
|
package/dist/http-client.js
CHANGED
|
@@ -13,6 +13,10 @@ exports.getResponse = getResponse;
|
|
|
13
13
|
exports.getResponseJson = getResponseJson;
|
|
14
14
|
exports.isResponseOk = isResponseOk;
|
|
15
15
|
exports.reshapeArtifactForPublicPolicy = reshapeArtifactForPublicPolicy;
|
|
16
|
+
exports.withRetry = withRetry;
|
|
17
|
+
exports.createGetRequestWithRetry = createGetRequestWithRetry;
|
|
18
|
+
exports.createDeleteRequestWithRetry = createDeleteRequestWithRetry;
|
|
19
|
+
exports.createRequestWithJsonAndRetry = createRequestWithJsonAndRetry;
|
|
16
20
|
/**
|
|
17
21
|
* @fileoverview HTTP client utilities for Socket API communication.
|
|
18
22
|
* Provides low-level HTTP request handling with proper error management and response parsing.
|
|
@@ -248,12 +252,15 @@ function reshapeArtifactForPublicPolicy(data, isAuthenticated, actions) {
|
|
|
248
252
|
// Handle both single artifacts and objects with artifacts arrays.
|
|
249
253
|
if (data['artifacts']) {
|
|
250
254
|
// Object with artifacts array.
|
|
255
|
+
const artifacts = data['artifacts'];
|
|
251
256
|
return {
|
|
252
257
|
...data,
|
|
253
|
-
artifacts:
|
|
258
|
+
artifacts: Array.isArray(artifacts)
|
|
259
|
+
? artifacts.map(reshapeArtifact)
|
|
260
|
+
: artifacts,
|
|
254
261
|
};
|
|
255
262
|
}
|
|
256
|
-
|
|
263
|
+
if (data['alerts']) {
|
|
257
264
|
// Single artifact with alerts.
|
|
258
265
|
return reshapeArtifact(data);
|
|
259
266
|
}
|
|
@@ -261,3 +268,80 @@ function reshapeArtifactForPublicPolicy(data, isAuthenticated, actions) {
|
|
|
261
268
|
return data;
|
|
262
269
|
/* c8 ignore stop */
|
|
263
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Retry helper for HTTP requests with exponential backoff.
|
|
273
|
+
* Wraps any async HTTP function and retries on failure.
|
|
274
|
+
*
|
|
275
|
+
* @param fn - Async function to retry
|
|
276
|
+
* @param retries - Number of retry attempts (default: 3)
|
|
277
|
+
* @param retryDelay - Initial delay in ms (default: 1000)
|
|
278
|
+
* @returns Result of the function call
|
|
279
|
+
* @throws {Error} Last error if all retries exhausted
|
|
280
|
+
*/
|
|
281
|
+
async function withRetry(fn, retries = 3, retryDelay = 1000) {
|
|
282
|
+
let lastError;
|
|
283
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
284
|
+
try {
|
|
285
|
+
// eslint-disable-next-line no-await-in-loop
|
|
286
|
+
return await fn();
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
lastError = error;
|
|
290
|
+
// Last attempt - throw error with retry context.
|
|
291
|
+
if (attempt === retries) {
|
|
292
|
+
const enhancedError = new Error(`Request failed after ${retries + 1} attempts`, { cause: lastError });
|
|
293
|
+
throw enhancedError;
|
|
294
|
+
}
|
|
295
|
+
// Check if error is retryable (network errors, 5xx responses).
|
|
296
|
+
if (error instanceof ResponseError) {
|
|
297
|
+
const status = error.response.statusCode;
|
|
298
|
+
// Don't retry client errors (4xx).
|
|
299
|
+
if (status && status >= 400 && status < 500) {
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
(0, debug_1.debugLog)('withRetry', `Retrying after ${status} error (attempt ${attempt + 1}/${retries + 1})`);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
(0, debug_1.debugLog)('withRetry', `Retrying after network error (attempt ${attempt + 1}/${retries + 1})`);
|
|
306
|
+
}
|
|
307
|
+
// Exponential backoff.
|
|
308
|
+
const delayMs = retryDelay * 2 ** attempt;
|
|
309
|
+
(0, debug_1.debugLog)('withRetry', `Waiting ${delayMs}ms before retry`);
|
|
310
|
+
// eslint-disable-next-line no-await-in-loop
|
|
311
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Fallback error if lastError is somehow undefined.
|
|
315
|
+
/* c8 ignore next - Defensive fallback for undefined lastError */
|
|
316
|
+
throw lastError || new Error('Request failed after retries');
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Create GET request with automatic retry logic.
|
|
320
|
+
* Retries on network errors and 5xx responses.
|
|
321
|
+
*
|
|
322
|
+
* @param retries - Number of retry attempts (default: 3)
|
|
323
|
+
* @param retryDelay - Initial delay in ms (default: 1000)
|
|
324
|
+
*/
|
|
325
|
+
async function createGetRequestWithRetry(baseUrl, urlPath, options, retries = 3, retryDelay = 1000) {
|
|
326
|
+
return await withRetry(() => createGetRequest(baseUrl, urlPath, options), retries, retryDelay);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Create DELETE request with automatic retry logic.
|
|
330
|
+
* Retries on network errors and 5xx responses.
|
|
331
|
+
*
|
|
332
|
+
* @param retries - Number of retry attempts (default: 3)
|
|
333
|
+
* @param retryDelay - Initial delay in ms (default: 1000)
|
|
334
|
+
*/
|
|
335
|
+
async function createDeleteRequestWithRetry(baseUrl, urlPath, options, retries = 3, retryDelay = 1000) {
|
|
336
|
+
return await withRetry(() => createDeleteRequest(baseUrl, urlPath, options), retries, retryDelay);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Create request with JSON payload and automatic retry logic.
|
|
340
|
+
* Retries on network errors and 5xx responses.
|
|
341
|
+
*
|
|
342
|
+
* @param retries - Number of retry attempts (default: 3)
|
|
343
|
+
* @param retryDelay - Initial delay in ms (default: 1000)
|
|
344
|
+
*/
|
|
345
|
+
async function createRequestWithJsonAndRetry(method, baseUrl, urlPath, json, options, retries = 3, retryDelay = 1000) {
|
|
346
|
+
return await withRetry(() => createRequestWithJson(method, baseUrl, urlPath, json, options), retries, retryDelay);
|
|
347
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { DEFAULT_USER_AGENT, httpAgentNames, publicPolicy } from './constants';
|
|
6
6
|
import { normalizeBaseUrl, promiseWithResolvers, queryToSearchParams, resolveAbsPaths, resolveBasePath } from './utils';
|
|
7
|
-
export type * from './types';
|
|
8
|
-
export { createUserAgentFromPkgJson } from './user-agent';
|
|
9
|
-
export { createDeleteRequest, createGetRequest, createRequestWithJson, getErrorResponseBody, getHttpModule, getResponse, getResponseJson, isResponseOk, reshapeArtifactForPublicPolicy, ResponseError, } from './http-client';
|
|
10
7
|
export { createRequestBodyForFilepaths, createRequestBodyForJson, createUploadRequest, } from './file-upload';
|
|
11
|
-
export {
|
|
8
|
+
export { createDeleteRequest, createGetRequest, createRequestWithJson, getErrorResponseBody, getHttpModule, getResponse, getResponseJson, isResponseOk, ResponseError, reshapeArtifactForPublicPolicy, } from './http-client';
|
|
12
9
|
export { calculateTotalQuotaCost, getAllMethodRequirements, getMethodRequirements, getMethodsByPermissions, getMethodsByQuotaCost, getQuotaCost, getQuotaUsageSummary, getRequiredPermissions, hasQuotaForMethods, } from './quota-utils';
|
|
10
|
+
export { SocketSdk } from './socket-sdk-class';
|
|
11
|
+
export type * from './types';
|
|
12
|
+
export { createUserAgentFromPkgJson } from './user-agent';
|
|
13
13
|
export { normalizeBaseUrl, promiseWithResolvers, queryToSearchParams, resolveAbsPaths, resolveBasePath, };
|
|
14
14
|
export { DEFAULT_USER_AGENT, httpAgentNames, publicPolicy };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicPolicy = exports.httpAgentNames = exports.DEFAULT_USER_AGENT = exports.resolveBasePath = exports.resolveAbsPaths = exports.queryToSearchParams = exports.promiseWithResolvers = exports.normalizeBaseUrl = exports.
|
|
3
|
+
exports.publicPolicy = exports.httpAgentNames = exports.DEFAULT_USER_AGENT = exports.resolveBasePath = exports.resolveAbsPaths = exports.queryToSearchParams = exports.promiseWithResolvers = exports.normalizeBaseUrl = exports.createUserAgentFromPkgJson = exports.SocketSdk = exports.hasQuotaForMethods = exports.getRequiredPermissions = exports.getQuotaUsageSummary = exports.getQuotaCost = exports.getMethodsByQuotaCost = exports.getMethodsByPermissions = exports.getMethodRequirements = exports.getAllMethodRequirements = exports.calculateTotalQuotaCost = exports.reshapeArtifactForPublicPolicy = exports.ResponseError = exports.isResponseOk = exports.getResponseJson = exports.getResponse = exports.getHttpModule = exports.getErrorResponseBody = exports.createRequestWithJson = exports.createGetRequest = exports.createDeleteRequest = exports.createUploadRequest = exports.createRequestBodyForJson = exports.createRequestBodyForFilepaths = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @fileoverview Main entry point for the Socket SDK.
|
|
6
6
|
* Provides the SocketSdk class and utility functions for Socket security analysis API interactions.
|
|
@@ -16,9 +16,11 @@ Object.defineProperty(exports, "promiseWithResolvers", { enumerable: true, get:
|
|
|
16
16
|
Object.defineProperty(exports, "queryToSearchParams", { enumerable: true, get: function () { return utils_1.queryToSearchParams; } });
|
|
17
17
|
Object.defineProperty(exports, "resolveAbsPaths", { enumerable: true, get: function () { return utils_1.resolveAbsPaths; } });
|
|
18
18
|
Object.defineProperty(exports, "resolveBasePath", { enumerable: true, get: function () { return utils_1.resolveBasePath; } });
|
|
19
|
-
// Re-export
|
|
20
|
-
const
|
|
21
|
-
Object.defineProperty(exports, "
|
|
19
|
+
// Re-export file upload functions
|
|
20
|
+
const file_upload_1 = require("./file-upload");
|
|
21
|
+
Object.defineProperty(exports, "createRequestBodyForFilepaths", { enumerable: true, get: function () { return file_upload_1.createRequestBodyForFilepaths; } });
|
|
22
|
+
Object.defineProperty(exports, "createRequestBodyForJson", { enumerable: true, get: function () { return file_upload_1.createRequestBodyForJson; } });
|
|
23
|
+
Object.defineProperty(exports, "createUploadRequest", { enumerable: true, get: function () { return file_upload_1.createUploadRequest; } });
|
|
22
24
|
// Re-export HTTP client functions
|
|
23
25
|
const http_client_1 = require("./http-client");
|
|
24
26
|
Object.defineProperty(exports, "createDeleteRequest", { enumerable: true, get: function () { return http_client_1.createDeleteRequest; } });
|
|
@@ -29,16 +31,8 @@ Object.defineProperty(exports, "getHttpModule", { enumerable: true, get: functio
|
|
|
29
31
|
Object.defineProperty(exports, "getResponse", { enumerable: true, get: function () { return http_client_1.getResponse; } });
|
|
30
32
|
Object.defineProperty(exports, "getResponseJson", { enumerable: true, get: function () { return http_client_1.getResponseJson; } });
|
|
31
33
|
Object.defineProperty(exports, "isResponseOk", { enumerable: true, get: function () { return http_client_1.isResponseOk; } });
|
|
32
|
-
Object.defineProperty(exports, "reshapeArtifactForPublicPolicy", { enumerable: true, get: function () { return http_client_1.reshapeArtifactForPublicPolicy; } });
|
|
33
34
|
Object.defineProperty(exports, "ResponseError", { enumerable: true, get: function () { return http_client_1.ResponseError; } });
|
|
34
|
-
|
|
35
|
-
const file_upload_1 = require("./file-upload");
|
|
36
|
-
Object.defineProperty(exports, "createRequestBodyForFilepaths", { enumerable: true, get: function () { return file_upload_1.createRequestBodyForFilepaths; } });
|
|
37
|
-
Object.defineProperty(exports, "createRequestBodyForJson", { enumerable: true, get: function () { return file_upload_1.createRequestBodyForJson; } });
|
|
38
|
-
Object.defineProperty(exports, "createUploadRequest", { enumerable: true, get: function () { return file_upload_1.createUploadRequest; } });
|
|
39
|
-
// Re-export the main SocketSdk class
|
|
40
|
-
const socket_sdk_class_1 = require("./socket-sdk-class");
|
|
41
|
-
Object.defineProperty(exports, "SocketSdk", { enumerable: true, get: function () { return socket_sdk_class_1.SocketSdk; } });
|
|
35
|
+
Object.defineProperty(exports, "reshapeArtifactForPublicPolicy", { enumerable: true, get: function () { return http_client_1.reshapeArtifactForPublicPolicy; } });
|
|
42
36
|
// Re-export quota utility functions
|
|
43
37
|
const quota_utils_1 = require("./quota-utils");
|
|
44
38
|
Object.defineProperty(exports, "calculateTotalQuotaCost", { enumerable: true, get: function () { return quota_utils_1.calculateTotalQuotaCost; } });
|
|
@@ -50,3 +44,9 @@ Object.defineProperty(exports, "getQuotaCost", { enumerable: true, get: function
|
|
|
50
44
|
Object.defineProperty(exports, "getQuotaUsageSummary", { enumerable: true, get: function () { return quota_utils_1.getQuotaUsageSummary; } });
|
|
51
45
|
Object.defineProperty(exports, "getRequiredPermissions", { enumerable: true, get: function () { return quota_utils_1.getRequiredPermissions; } });
|
|
52
46
|
Object.defineProperty(exports, "hasQuotaForMethods", { enumerable: true, get: function () { return quota_utils_1.hasQuotaForMethods; } });
|
|
47
|
+
// Re-export the main SocketSdk class
|
|
48
|
+
const socket_sdk_class_1 = require("./socket-sdk-class");
|
|
49
|
+
Object.defineProperty(exports, "SocketSdk", { enumerable: true, get: function () { return socket_sdk_class_1.SocketSdk; } });
|
|
50
|
+
// Re-export functions from modules
|
|
51
|
+
const user_agent_1 = require("./user-agent");
|
|
52
|
+
Object.defineProperty(exports, "createUserAgentFromPkgJson", { enumerable: true, get: function () { return user_agent_1.createUserAgentFromPkgJson; } });
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare class PromiseQueue {
|
|
2
|
+
private queue;
|
|
3
|
+
private running;
|
|
4
|
+
private readonly maxConcurrency;
|
|
5
|
+
private readonly maxQueueLength;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new PromiseQueue
|
|
8
|
+
* @param maxConcurrency - Maximum number of promises that can run concurrently
|
|
9
|
+
* @param maxQueueLength - Maximum queue size (older tasks are dropped if exceeded)
|
|
10
|
+
*/
|
|
11
|
+
constructor(maxConcurrency: number, maxQueueLength?: number | undefined);
|
|
12
|
+
/**
|
|
13
|
+
* Add a task to the queue
|
|
14
|
+
* @param fn - Async function to execute
|
|
15
|
+
* @returns Promise that resolves with the function's result
|
|
16
|
+
*/
|
|
17
|
+
add<T>(fn: () => Promise<T>): Promise<T>;
|
|
18
|
+
private runNext;
|
|
19
|
+
/**
|
|
20
|
+
* Wait for all queued and running tasks to complete
|
|
21
|
+
*/
|
|
22
|
+
onIdle(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the number of tasks currently running
|
|
25
|
+
*/
|
|
26
|
+
get activeCount(): number;
|
|
27
|
+
/**
|
|
28
|
+
* Get the number of tasks waiting in the queue
|
|
29
|
+
*/
|
|
30
|
+
get pendingCount(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Clear all pending tasks from the queue (does not affect running tasks)
|
|
33
|
+
*/
|
|
34
|
+
clear(): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromiseQueue = void 0;
|
|
4
|
+
class PromiseQueue {
|
|
5
|
+
queue = [];
|
|
6
|
+
running = 0;
|
|
7
|
+
maxConcurrency;
|
|
8
|
+
maxQueueLength;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new PromiseQueue
|
|
11
|
+
* @param maxConcurrency - Maximum number of promises that can run concurrently
|
|
12
|
+
* @param maxQueueLength - Maximum queue size (older tasks are dropped if exceeded)
|
|
13
|
+
*/
|
|
14
|
+
constructor(maxConcurrency, maxQueueLength) {
|
|
15
|
+
this.maxConcurrency = maxConcurrency;
|
|
16
|
+
this.maxQueueLength = maxQueueLength;
|
|
17
|
+
if (maxConcurrency < 1) {
|
|
18
|
+
throw new Error('maxConcurrency must be at least 1');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Add a task to the queue
|
|
23
|
+
* @param fn - Async function to execute
|
|
24
|
+
* @returns Promise that resolves with the function's result
|
|
25
|
+
*/
|
|
26
|
+
async add(fn) {
|
|
27
|
+
return await new Promise((resolve, reject) => {
|
|
28
|
+
const task = { fn, resolve, reject };
|
|
29
|
+
if (this.maxQueueLength && this.queue.length >= this.maxQueueLength) {
|
|
30
|
+
// Drop oldest task to prevent memory buildup
|
|
31
|
+
this.queue.shift();
|
|
32
|
+
}
|
|
33
|
+
this.queue.push(task);
|
|
34
|
+
this.runNext();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
runNext() {
|
|
38
|
+
if (this.running >= this.maxConcurrency || this.queue.length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const task = this.queue.shift();
|
|
42
|
+
/* c8 ignore next 3 - Defensive check; unreachable since we verify queue.length above */
|
|
43
|
+
if (!task) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.running++;
|
|
47
|
+
task
|
|
48
|
+
.fn()
|
|
49
|
+
.then(task.resolve)
|
|
50
|
+
.catch(task.reject)
|
|
51
|
+
.finally(() => {
|
|
52
|
+
this.running--;
|
|
53
|
+
this.runNext();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Wait for all queued and running tasks to complete
|
|
58
|
+
*/
|
|
59
|
+
async onIdle() {
|
|
60
|
+
return await new Promise(resolve => {
|
|
61
|
+
const check = () => {
|
|
62
|
+
if (this.running === 0 && this.queue.length === 0) {
|
|
63
|
+
resolve();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
setImmediate(check);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
check();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the number of tasks currently running
|
|
74
|
+
*/
|
|
75
|
+
get activeCount() {
|
|
76
|
+
return this.running;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the number of tasks waiting in the queue
|
|
80
|
+
*/
|
|
81
|
+
get pendingCount() {
|
|
82
|
+
return this.queue.length;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Clear all pending tasks from the queue (does not affect running tasks)
|
|
86
|
+
*/
|
|
87
|
+
clear() {
|
|
88
|
+
this.queue = [];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.PromiseQueue = PromiseQueue;
|
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 {};
|