@socketsecurity/sdk 3.4.0 → 3.5.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 +25 -0
- package/README.md +1 -1
- package/dist/constants.d.ts +3 -1
- package/dist/http-client.d.ts +1 -36
- package/dist/index.d.ts +1 -1
- package/dist/index.js +262 -152
- package/dist/socket-sdk-class.d.ts +35 -31
- package/dist/types.d.ts +28 -8
- package/package.json +9 -6
- package/types/api.d.ts +162 -21
package/dist/index.js
CHANGED
|
@@ -71,7 +71,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
71
71
|
// package.json
|
|
72
72
|
var package_default = {
|
|
73
73
|
name: "@socketsecurity/sdk",
|
|
74
|
-
version: "3.
|
|
74
|
+
version: "3.5.0",
|
|
75
75
|
description: "SDK for the Socket API client",
|
|
76
76
|
homepage: "https://github.com/SocketDev/socket-sdk-js",
|
|
77
77
|
license: "MIT",
|
|
@@ -130,16 +130,18 @@ var package_default = {
|
|
|
130
130
|
publish: "node scripts/publish.mjs",
|
|
131
131
|
"publish:ci": "node scripts/publish.mjs --tag ${DIST_TAG:-latest}",
|
|
132
132
|
claude: "node scripts/claude.mjs",
|
|
133
|
+
security: "agentshield scan && { command -v zizmor >/dev/null && zizmor .github/ || echo 'zizmor not installed \u2014 run pnpm run setup to install'; }",
|
|
133
134
|
test: "node scripts/test.mjs",
|
|
134
135
|
type: "tsgo --noEmit -p .config/tsconfig.check.json",
|
|
135
136
|
update: "node scripts/update.mjs"
|
|
136
137
|
},
|
|
137
138
|
dependencies: {
|
|
138
|
-
"@socketregistry/packageurl-js": "1.
|
|
139
|
-
"@socketsecurity/lib": "5.
|
|
139
|
+
"@socketregistry/packageurl-js": "1.4.1",
|
|
140
|
+
"@socketsecurity/lib": "5.11.4",
|
|
140
141
|
"form-data": "4.0.5"
|
|
141
142
|
},
|
|
142
143
|
devDependencies: {
|
|
144
|
+
"@anthropic-ai/claude-code": "2.1.89",
|
|
143
145
|
"@babel/generator": "7.28.5",
|
|
144
146
|
"@babel/parser": "7.26.3",
|
|
145
147
|
"@babel/traverse": "7.26.4",
|
|
@@ -154,6 +156,7 @@ var package_default = {
|
|
|
154
156
|
acorn: "8.15.0",
|
|
155
157
|
del: "8.0.1",
|
|
156
158
|
"dev-null-cli": "2.0.0",
|
|
159
|
+
"ecc-agentshield": "1.4.0",
|
|
157
160
|
esbuild: "0.25.11",
|
|
158
161
|
"fast-glob": "3.3.3",
|
|
159
162
|
"http2-wrapper": "2.2.1",
|
|
@@ -180,10 +183,10 @@ var package_default = {
|
|
|
180
183
|
strict: true
|
|
181
184
|
},
|
|
182
185
|
engines: {
|
|
183
|
-
node: ">=18",
|
|
184
|
-
pnpm: ">=10.
|
|
186
|
+
node: ">=18.20.8",
|
|
187
|
+
pnpm: ">=10.33.0"
|
|
185
188
|
},
|
|
186
|
-
packageManager: "pnpm@10.
|
|
189
|
+
packageManager: "pnpm@10.33.0",
|
|
187
190
|
pnpm: {
|
|
188
191
|
ignoredBuiltDependencies: [
|
|
189
192
|
"esbuild",
|
|
@@ -216,6 +219,8 @@ var MIN_HTTP_TIMEOUT = 5e3;
|
|
|
216
219
|
var MAX_RESPONSE_SIZE = 10 * 1024 * 1024;
|
|
217
220
|
var MAX_STREAM_SIZE = 100 * 1024 * 1024;
|
|
218
221
|
var SOCKET_PUBLIC_BLOB_STORE_URL = "https://socketusercontent.com";
|
|
222
|
+
var MAX_FIREWALL_COMPONENTS = 8;
|
|
223
|
+
var SOCKET_FIREWALL_API_URL = "https://firewall-api.socket.dev/purl";
|
|
219
224
|
var httpAgentNames = /* @__PURE__ */ new Set(["http", "https", "http2"]);
|
|
220
225
|
var publicPolicy = /* @__PURE__ */ new Map([
|
|
221
226
|
// error (1):
|
|
@@ -327,6 +332,7 @@ var publicPolicy = /* @__PURE__ */ new Map([
|
|
|
327
332
|
|
|
328
333
|
// src/utils.ts
|
|
329
334
|
var import_node_path = __toESM(require("node:path"));
|
|
335
|
+
var import_node_process = __toESM(require("node:process"));
|
|
330
336
|
var import_memoization = require("@socketsecurity/lib/memoization");
|
|
331
337
|
var import_normalize = require("@socketsecurity/lib/paths/normalize");
|
|
332
338
|
function normalizeToWordSet(s) {
|
|
@@ -405,7 +411,7 @@ function resolveAbsPaths(filepaths, pathsRelativeTo) {
|
|
|
405
411
|
return filepaths.map((p) => (0, import_normalize.normalizePath)(import_node_path.default.resolve(basePath, p)));
|
|
406
412
|
}
|
|
407
413
|
function resolveBasePath(pathsRelativeTo = ".") {
|
|
408
|
-
return (0, import_normalize.normalizePath)(import_node_path.default.resolve(
|
|
414
|
+
return (0, import_normalize.normalizePath)(import_node_path.default.resolve(import_node_process.default.cwd(), pathsRelativeTo));
|
|
409
415
|
}
|
|
410
416
|
function shouldOmitReason(errorMessage, reason, threshold = 0.6) {
|
|
411
417
|
if (!reason || !reason.trim()) {
|
|
@@ -803,9 +809,10 @@ function isResponseOk(response) {
|
|
|
803
809
|
const { statusCode } = response;
|
|
804
810
|
return statusCode ? statusCode >= 200 && statusCode < 300 : false;
|
|
805
811
|
}
|
|
806
|
-
function reshapeArtifactForPublicPolicy(data, isAuthenticated, actions) {
|
|
812
|
+
function reshapeArtifactForPublicPolicy(data, isAuthenticated, actions, policy) {
|
|
807
813
|
if (!isAuthenticated) {
|
|
808
814
|
const allowedActions = actions?.trim() ? actions.split(",") : void 0;
|
|
815
|
+
const resolvedPolicy = policy ?? publicPolicy;
|
|
809
816
|
const reshapeArtifact = (artifact) => ({
|
|
810
817
|
name: artifact.name,
|
|
811
818
|
version: artifact.version,
|
|
@@ -818,17 +825,19 @@ function reshapeArtifactForPublicPolicy(data, isAuthenticated, actions) {
|
|
|
818
825
|
// Compact the alerts array to reduce response size for non-authenticated
|
|
819
826
|
// requests.
|
|
820
827
|
alerts: artifact.alerts?.filter((alert) => {
|
|
828
|
+
const action = resolvedPolicy.get(alert.type);
|
|
821
829
|
if (alert.severity === "low") {
|
|
822
830
|
return false;
|
|
823
831
|
}
|
|
824
|
-
if (allowedActions &&
|
|
832
|
+
if (allowedActions && action && !allowedActions.includes(action)) {
|
|
825
833
|
return false;
|
|
826
834
|
}
|
|
827
835
|
return true;
|
|
828
836
|
}).map((alert) => ({
|
|
829
|
-
|
|
837
|
+
action: resolvedPolicy.get(alert.type),
|
|
838
|
+
key: alert.key,
|
|
830
839
|
severity: alert.severity,
|
|
831
|
-
|
|
840
|
+
type: alert.type
|
|
832
841
|
}))
|
|
833
842
|
});
|
|
834
843
|
if (data["artifacts"]) {
|
|
@@ -1064,6 +1073,7 @@ function hasQuotaForMethods(availableQuota, methodNames) {
|
|
|
1064
1073
|
var import_node_events = __toESM(require("node:events"));
|
|
1065
1074
|
var import_node_fs3 = require("node:fs");
|
|
1066
1075
|
var import_node_path4 = __toESM(require("node:path"));
|
|
1076
|
+
var import_node_process2 = __toESM(require("node:process"));
|
|
1067
1077
|
var import_node_readline = __toESM(require("node:readline"));
|
|
1068
1078
|
var import_cache_with_ttl = require("@socketsecurity/lib/cache-with-ttl");
|
|
1069
1079
|
var import_core = require("@socketsecurity/lib/constants/core");
|
|
@@ -1077,7 +1087,7 @@ var import_promises = require("@socketsecurity/lib/promises");
|
|
|
1077
1087
|
var import_suppress_warnings = require("@socketsecurity/lib/suppress-warnings");
|
|
1078
1088
|
var import_url = require("@socketsecurity/lib/url");
|
|
1079
1089
|
var abortSignal = (0, import_process.getAbortSignal)();
|
|
1080
|
-
var SocketSdk = class {
|
|
1090
|
+
var SocketSdk = class _SocketSdk {
|
|
1081
1091
|
#apiToken;
|
|
1082
1092
|
#baseUrl;
|
|
1083
1093
|
#cache;
|
|
@@ -1191,11 +1201,12 @@ var SocketSdk = class {
|
|
|
1191
1201
|
);
|
|
1192
1202
|
if ((0, import_objects.isObjectObject)(artifact)) {
|
|
1193
1203
|
yield this.#handleApiSuccess(
|
|
1194
|
-
/* c8 ignore next
|
|
1204
|
+
/* c8 ignore next 8 - Public token artifact reshaping branch for policy compliance. */
|
|
1195
1205
|
isPublicToken ? reshapeArtifactForPublicPolicy(
|
|
1196
1206
|
artifact,
|
|
1197
1207
|
false,
|
|
1198
|
-
queryParams?.["actions"]
|
|
1208
|
+
queryParams?.["actions"],
|
|
1209
|
+
publicPolicy
|
|
1199
1210
|
) : artifact
|
|
1200
1211
|
);
|
|
1201
1212
|
}
|
|
@@ -1336,7 +1347,6 @@ var SocketSdk = class {
|
|
|
1336
1347
|
* Extract text content from HTTP response stream.
|
|
1337
1348
|
* Internal method with size limits to prevent memory exhaustion.
|
|
1338
1349
|
*/
|
|
1339
|
-
/* c8 ignore start - unused utility method reserved for future text response handling */
|
|
1340
1350
|
async #getResponseText(response) {
|
|
1341
1351
|
const chunks = [];
|
|
1342
1352
|
let size = 0;
|
|
@@ -1350,7 +1360,6 @@ var SocketSdk = class {
|
|
|
1350
1360
|
}
|
|
1351
1361
|
return Buffer.concat(chunks).toString("utf8");
|
|
1352
1362
|
}
|
|
1353
|
-
/* c8 ignore stop */
|
|
1354
1363
|
/**
|
|
1355
1364
|
* Handle API error responses and convert to standardized error result.
|
|
1356
1365
|
* Internal error handling with status code analysis and message formatting.
|
|
@@ -1547,14 +1556,17 @@ var SocketSdk = class {
|
|
|
1547
1556
|
const url = `${this.#baseUrl}orgs/${encodeURIComponent(orgSlug)}/purl?${queryToSearchParams(queryParams)}`;
|
|
1548
1557
|
let res;
|
|
1549
1558
|
try {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1559
|
+
res = await this.#executeWithRetry(async () => {
|
|
1560
|
+
const req = getHttpModule(this.#baseUrl).request(url, {
|
|
1561
|
+
method: "POST",
|
|
1562
|
+
...this.#reqOptions
|
|
1563
|
+
}).end(JSON.stringify(componentsObj));
|
|
1564
|
+
const response = await getResponse(req);
|
|
1565
|
+
if (!isResponseOk(response)) {
|
|
1566
|
+
throw new ResponseError(response, "POST Request failed", url);
|
|
1567
|
+
}
|
|
1568
|
+
return response;
|
|
1569
|
+
});
|
|
1558
1570
|
} catch (e) {
|
|
1559
1571
|
return await this.#handleApiError(e);
|
|
1560
1572
|
}
|
|
@@ -1620,11 +1632,12 @@ var SocketSdk = class {
|
|
|
1620
1632
|
);
|
|
1621
1633
|
if ((0, import_objects.isObjectObject)(artifact)) {
|
|
1622
1634
|
results.push(
|
|
1623
|
-
/* c8 ignore next
|
|
1635
|
+
/* c8 ignore next 8 - Public token artifact reshaping for policy compliance. */
|
|
1624
1636
|
isPublicToken ? reshapeArtifactForPublicPolicy(
|
|
1625
1637
|
artifact,
|
|
1626
1638
|
false,
|
|
1627
|
-
queryParams?.["actions"]
|
|
1639
|
+
queryParams?.["actions"],
|
|
1640
|
+
publicPolicy
|
|
1628
1641
|
) : artifact
|
|
1629
1642
|
);
|
|
1630
1643
|
}
|
|
@@ -1713,6 +1726,111 @@ var SocketSdk = class {
|
|
|
1713
1726
|
}
|
|
1714
1727
|
}
|
|
1715
1728
|
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Check packages for malware and security alerts.
|
|
1731
|
+
*
|
|
1732
|
+
* For small sets (≤ MAX_FIREWALL_COMPONENTS), uses parallel firewall API
|
|
1733
|
+
* requests which return full artifact data including score and alert details.
|
|
1734
|
+
*
|
|
1735
|
+
* For larger sets, uses the batch PURL API for efficiency.
|
|
1736
|
+
*
|
|
1737
|
+
* Both paths normalize alerts through publicPolicy and only return
|
|
1738
|
+
* malware-relevant results.
|
|
1739
|
+
*
|
|
1740
|
+
* @param components - Array of package URLs to check
|
|
1741
|
+
* @returns Normalized results with policy-filtered alerts per package
|
|
1742
|
+
*/
|
|
1743
|
+
async checkMalware(components) {
|
|
1744
|
+
if (components.length <= MAX_FIREWALL_COMPONENTS) {
|
|
1745
|
+
return this.#checkMalwareFirewall(components);
|
|
1746
|
+
}
|
|
1747
|
+
return this.#checkMalwareBatch(components);
|
|
1748
|
+
}
|
|
1749
|
+
// Small-set path: parallel firewall API requests per PURL.
|
|
1750
|
+
// Returns full artifact data (score, alert props, categories, fix info).
|
|
1751
|
+
async #checkMalwareFirewall(components) {
|
|
1752
|
+
const packages = [];
|
|
1753
|
+
const results = await Promise.allSettled(
|
|
1754
|
+
components.map(async ({ purl }) => {
|
|
1755
|
+
const urlPath = `/${encodeURIComponent(purl)}`;
|
|
1756
|
+
const response = await createGetRequest(
|
|
1757
|
+
SOCKET_FIREWALL_API_URL,
|
|
1758
|
+
urlPath,
|
|
1759
|
+
this.#reqOptions
|
|
1760
|
+
);
|
|
1761
|
+
if (!isResponseOk(response)) return void 0;
|
|
1762
|
+
const json = await getResponseJson(response);
|
|
1763
|
+
return json;
|
|
1764
|
+
})
|
|
1765
|
+
);
|
|
1766
|
+
for (const settled of results) {
|
|
1767
|
+
if (settled.status === "rejected" || !settled.value) continue;
|
|
1768
|
+
packages.push(_SocketSdk.#normalizeArtifact(settled.value, publicPolicy));
|
|
1769
|
+
}
|
|
1770
|
+
return {
|
|
1771
|
+
cause: void 0,
|
|
1772
|
+
data: packages,
|
|
1773
|
+
error: void 0,
|
|
1774
|
+
status: 200,
|
|
1775
|
+
success: true
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
// Multi-component path: batch PURL API request, normalized to publicPolicy.
|
|
1779
|
+
async #checkMalwareBatch(components) {
|
|
1780
|
+
const result = await this.batchPackageFetch(
|
|
1781
|
+
{ components },
|
|
1782
|
+
{ alerts: true, cachedResultsOnly: true }
|
|
1783
|
+
);
|
|
1784
|
+
if (!result.success) {
|
|
1785
|
+
return {
|
|
1786
|
+
cause: result.cause,
|
|
1787
|
+
data: void 0,
|
|
1788
|
+
error: result.error,
|
|
1789
|
+
status: result.status,
|
|
1790
|
+
success: false
|
|
1791
|
+
};
|
|
1792
|
+
}
|
|
1793
|
+
const packages = [];
|
|
1794
|
+
for (const artifact of result.data) {
|
|
1795
|
+
packages.push(_SocketSdk.#normalizeArtifact(artifact, publicPolicy));
|
|
1796
|
+
}
|
|
1797
|
+
return {
|
|
1798
|
+
cause: void 0,
|
|
1799
|
+
data: packages,
|
|
1800
|
+
error: void 0,
|
|
1801
|
+
status: 200,
|
|
1802
|
+
success: true
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
// Normalize an artifact into MalwareCheckPackage.
|
|
1806
|
+
// When policy is provided, derive action from the map.
|
|
1807
|
+
// When policy is undefined, use server-assigned alert.action.
|
|
1808
|
+
static #normalizeArtifact(artifact, policy) {
|
|
1809
|
+
const alerts = [];
|
|
1810
|
+
if (artifact.alerts) {
|
|
1811
|
+
for (const alert of artifact.alerts) {
|
|
1812
|
+
const action = policy ? policy.get(alert.type) ?? "ignore" : alert.action ?? "ignore";
|
|
1813
|
+
if (action === "error" || action === "warn") {
|
|
1814
|
+
alerts.push({
|
|
1815
|
+
category: alert.category,
|
|
1816
|
+
fix: alert.fix ? { description: alert.fix.description, type: alert.fix.type } : void 0,
|
|
1817
|
+
key: alert.key,
|
|
1818
|
+
props: alert.props,
|
|
1819
|
+
severity: alert.severity,
|
|
1820
|
+
type: alert.type
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
return {
|
|
1826
|
+
alerts,
|
|
1827
|
+
name: artifact.name,
|
|
1828
|
+
namespace: artifact.namespace,
|
|
1829
|
+
score: artifact.score,
|
|
1830
|
+
type: artifact.type,
|
|
1831
|
+
version: artifact.version
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1716
1834
|
/**
|
|
1717
1835
|
* Create a snapshot of project dependencies by uploading manifest files.
|
|
1718
1836
|
* Analyzes dependency files to generate a comprehensive security report.
|
|
@@ -2367,41 +2485,31 @@ var SocketSdk = class {
|
|
|
2367
2485
|
}
|
|
2368
2486
|
}
|
|
2369
2487
|
/**
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
* @param options.baseUrl - Override blob store URL (for testing)
|
|
2382
|
-
* @returns Promise<string> - The patch file content as UTF-8 string
|
|
2383
|
-
* @throws Error if blob not found (404) or download fails
|
|
2384
|
-
*
|
|
2385
|
-
* @example
|
|
2386
|
-
* ```typescript
|
|
2387
|
-
* const sdk = new SocketSdk('your-api-token')
|
|
2388
|
-
* // First get patch metadata
|
|
2389
|
-
* const patch = await sdk.viewPatch('my-org', 'patch-uuid')
|
|
2390
|
-
* // Then download the actual patched file
|
|
2391
|
-
* const fileContent = await sdk.downloadPatch(patch.files['index.js'].socketBlob)
|
|
2392
|
-
* ```
|
|
2393
|
-
*/
|
|
2488
|
+
* Download full scan files as a tar archive.
|
|
2489
|
+
*
|
|
2490
|
+
* Streams the full scan file contents to the specified output path as a tar file.
|
|
2491
|
+
* Includes size limit enforcement to prevent excessive disk usage.
|
|
2492
|
+
*
|
|
2493
|
+
* @param orgSlug - Organization identifier
|
|
2494
|
+
* @param fullScanId - Full scan identifier
|
|
2495
|
+
* @param outputPath - Local file path to write the tar archive
|
|
2496
|
+
* @returns Download result with success/error status
|
|
2497
|
+
* @throws {Error} When server returns 5xx status codes
|
|
2498
|
+
*/
|
|
2394
2499
|
async downloadOrgFullScanFilesAsTar(orgSlug, fullScanId, outputPath) {
|
|
2395
2500
|
const url = `${this.#baseUrl}orgs/${encodeURIComponent(orgSlug)}/full-scans/${encodeURIComponent(fullScanId)}/files.tar`;
|
|
2396
2501
|
try {
|
|
2397
|
-
const
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2502
|
+
const res = await this.#executeWithRetry(async () => {
|
|
2503
|
+
const req = getHttpModule(this.#baseUrl).request(url, {
|
|
2504
|
+
method: "GET",
|
|
2505
|
+
...this.#reqOptions
|
|
2506
|
+
}).end();
|
|
2507
|
+
const response = await getResponse(req);
|
|
2508
|
+
if (!isResponseOk(response)) {
|
|
2509
|
+
throw new ResponseError(response, "", url);
|
|
2510
|
+
}
|
|
2511
|
+
return response;
|
|
2512
|
+
});
|
|
2405
2513
|
const writeStream = (0, import_node_fs3.createWriteStream)(outputPath);
|
|
2406
2514
|
let bytesWritten = 0;
|
|
2407
2515
|
res.on("data", (chunk) => {
|
|
@@ -2637,26 +2745,16 @@ var SocketSdk = class {
|
|
|
2637
2745
|
};
|
|
2638
2746
|
const url = `${this.#baseUrl}${urlPath}`;
|
|
2639
2747
|
try {
|
|
2640
|
-
const response = await
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
if (
|
|
2646
|
-
throw new ResponseError(
|
|
2748
|
+
const response = await this.#executeWithRetry(async () => {
|
|
2749
|
+
const res = await createGetRequest(this.#baseUrl, urlPath, {
|
|
2750
|
+
...this.#reqOptions,
|
|
2751
|
+
hooks: this.#hooks
|
|
2752
|
+
});
|
|
2753
|
+
if (!isResponseOk(res)) {
|
|
2754
|
+
throw new ResponseError(res, "", url);
|
|
2647
2755
|
}
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
);
|
|
2651
|
-
return {
|
|
2652
|
-
cause: errorResult.cause,
|
|
2653
|
-
data: void 0,
|
|
2654
|
-
error: errorResult.error,
|
|
2655
|
-
status: errorResult.status,
|
|
2656
|
-
success: false,
|
|
2657
|
-
url: errorResult.url
|
|
2658
|
-
};
|
|
2659
|
-
}
|
|
2756
|
+
return res;
|
|
2757
|
+
});
|
|
2660
2758
|
const data = await this.#handleQueryResponseData(
|
|
2661
2759
|
response,
|
|
2662
2760
|
responseType
|
|
@@ -2683,7 +2781,8 @@ var SocketSdk = class {
|
|
|
2683
2781
|
data: void 0,
|
|
2684
2782
|
error: errorResult.error,
|
|
2685
2783
|
status: errorResult.status,
|
|
2686
|
-
success: false
|
|
2784
|
+
success: false,
|
|
2785
|
+
url: errorResult.url
|
|
2687
2786
|
};
|
|
2688
2787
|
}
|
|
2689
2788
|
return this.#createQueryErrorResult(e);
|
|
@@ -2800,7 +2899,7 @@ var SocketSdk = class {
|
|
|
2800
2899
|
/**
|
|
2801
2900
|
* Retrieve the enabled entitlements for an organization.
|
|
2802
2901
|
*
|
|
2803
|
-
* This method fetches the organization's entitlements and filters for only
|
|
2902
|
+
* This method fetches the organization's entitlements and filters for only the enabled ones, returning their keys. Entitlements represent Socket
|
|
2804
2903
|
* Products that the organization has access to use.
|
|
2805
2904
|
*/
|
|
2806
2905
|
async getEnabledEntitlements(orgSlug) {
|
|
@@ -3086,7 +3185,8 @@ var SocketSdk = class {
|
|
|
3086
3185
|
}
|
|
3087
3186
|
}
|
|
3088
3187
|
/**
|
|
3089
|
-
* Get organization's license policy configuration
|
|
3188
|
+
* Get organization's license policy configuration.
|
|
3189
|
+
* Returns allowed, restricted, and monitored license types.
|
|
3090
3190
|
*
|
|
3091
3191
|
* @throws {Error} When server returns 5xx status codes
|
|
3092
3192
|
*/
|
|
@@ -3107,7 +3207,8 @@ var SocketSdk = class {
|
|
|
3107
3207
|
}
|
|
3108
3208
|
}
|
|
3109
3209
|
/**
|
|
3110
|
-
* Get organization's security policy configuration
|
|
3210
|
+
* Get organization's security policy configuration.
|
|
3211
|
+
* Returns alert rules, severity thresholds, and enforcement settings.
|
|
3111
3212
|
*
|
|
3112
3213
|
* @throws {Error} When server returns 5xx status codes
|
|
3113
3214
|
*/
|
|
@@ -3272,36 +3373,32 @@ var SocketSdk = class {
|
|
|
3272
3373
|
}
|
|
3273
3374
|
}
|
|
3274
3375
|
/**
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
* @quota 0 units
|
|
3302
|
-
* @scopes repo:read
|
|
3303
|
-
* @throws {Error} When server returns 5xx status codes
|
|
3304
|
-
*/
|
|
3376
|
+
* Get details for a specific repository.
|
|
3377
|
+
*
|
|
3378
|
+
* Returns repository configuration, monitoring status, and metadata.
|
|
3379
|
+
*
|
|
3380
|
+
* @param orgSlug - Organization identifier
|
|
3381
|
+
* @param repoSlug - Repository slug/name
|
|
3382
|
+
* @param options - Optional parameters including workspace
|
|
3383
|
+
* @returns Repository details with configuration
|
|
3384
|
+
*
|
|
3385
|
+
* @example
|
|
3386
|
+
* ```typescript
|
|
3387
|
+
* const result = await sdk.getRepository('my-org', 'my-repo')
|
|
3388
|
+
*
|
|
3389
|
+
* if (result.success) {
|
|
3390
|
+
* console.log('Repository:', result.data.name)
|
|
3391
|
+
* console.log('Visibility:', result.data.visibility)
|
|
3392
|
+
* console.log('Default branch:', result.data.default_branch)
|
|
3393
|
+
* }
|
|
3394
|
+
* ```
|
|
3395
|
+
*
|
|
3396
|
+
* @see https://docs.socket.dev/reference/getorgrepo
|
|
3397
|
+
* @apiEndpoint GET /orgs/{org_slug}/repos/{repo_slug}
|
|
3398
|
+
* @quota 0 units
|
|
3399
|
+
* @scopes repo:read
|
|
3400
|
+
* @throws {Error} When server returns 5xx status codes
|
|
3401
|
+
*/
|
|
3305
3402
|
async getRepository(orgSlug, repoSlug, options) {
|
|
3306
3403
|
const orgSlugParam = encodeURIComponent(orgSlug);
|
|
3307
3404
|
const repoSlugParam = encodeURIComponent(repoSlug);
|
|
@@ -3860,7 +3957,7 @@ var SocketSdk = class {
|
|
|
3860
3957
|
success: true
|
|
3861
3958
|
};
|
|
3862
3959
|
} catch (e) {
|
|
3863
|
-
return this.#
|
|
3960
|
+
return await this.#handleApiError(e);
|
|
3864
3961
|
}
|
|
3865
3962
|
}
|
|
3866
3963
|
/**
|
|
@@ -3977,14 +4074,21 @@ var SocketSdk = class {
|
|
|
3977
4074
|
method = "POST",
|
|
3978
4075
|
throws = true
|
|
3979
4076
|
} = { __proto__: null, ...options };
|
|
4077
|
+
const url = `${this.#baseUrl}${urlPath}`;
|
|
3980
4078
|
try {
|
|
3981
|
-
const response = await
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
4079
|
+
const response = await this.#executeWithRetry(async () => {
|
|
4080
|
+
const res = await createRequestWithJson(
|
|
4081
|
+
method,
|
|
4082
|
+
this.#baseUrl,
|
|
4083
|
+
urlPath,
|
|
4084
|
+
body,
|
|
4085
|
+
{ ...this.#reqOptions, hooks: this.#hooks }
|
|
4086
|
+
);
|
|
4087
|
+
if (!isResponseOk(res)) {
|
|
4088
|
+
throw new ResponseError(res, "", url);
|
|
4089
|
+
}
|
|
4090
|
+
return res;
|
|
4091
|
+
});
|
|
3988
4092
|
const data = await getResponseJson(response);
|
|
3989
4093
|
if (throws) {
|
|
3990
4094
|
return data;
|
|
@@ -4008,17 +4112,11 @@ var SocketSdk = class {
|
|
|
4008
4112
|
data: void 0,
|
|
4009
4113
|
error: errorResult.error,
|
|
4010
4114
|
status: errorResult.status,
|
|
4011
|
-
success: false
|
|
4115
|
+
success: false,
|
|
4116
|
+
url: errorResult.url
|
|
4012
4117
|
};
|
|
4013
4118
|
}
|
|
4014
|
-
|
|
4015
|
-
return {
|
|
4016
|
-
cause: errStr || import_core.UNKNOWN_ERROR,
|
|
4017
|
-
data: void 0,
|
|
4018
|
-
error: "API request failed",
|
|
4019
|
-
status: 0,
|
|
4020
|
-
success: false
|
|
4021
|
-
};
|
|
4119
|
+
return this.#createQueryErrorResult(e);
|
|
4022
4120
|
}
|
|
4023
4121
|
}
|
|
4024
4122
|
/**
|
|
@@ -4061,14 +4159,17 @@ var SocketSdk = class {
|
|
|
4061
4159
|
};
|
|
4062
4160
|
const url = `${this.#baseUrl}orgs/${encodeURIComponent(orgSlug)}/full-scans/${encodeURIComponent(scanId)}`;
|
|
4063
4161
|
try {
|
|
4064
|
-
const
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4162
|
+
const res = await this.#executeWithRetry(async () => {
|
|
4163
|
+
const req = getHttpModule(this.#baseUrl).request(url, {
|
|
4164
|
+
method: "GET",
|
|
4165
|
+
...this.#reqOptions
|
|
4166
|
+
}).end();
|
|
4167
|
+
const response = await getResponse(req);
|
|
4168
|
+
if (!isResponseOk(response)) {
|
|
4169
|
+
throw new ResponseError(response, "", url);
|
|
4170
|
+
}
|
|
4171
|
+
return response;
|
|
4172
|
+
});
|
|
4072
4173
|
if (typeof output === "string") {
|
|
4073
4174
|
const writeStream = (0, import_node_fs3.createWriteStream)(output);
|
|
4074
4175
|
let bytesWritten = 0;
|
|
@@ -4103,15 +4204,15 @@ var SocketSdk = class {
|
|
|
4103
4204
|
});
|
|
4104
4205
|
const stdoutErrorHandler = (_error) => {
|
|
4105
4206
|
res.destroy();
|
|
4106
|
-
|
|
4207
|
+
import_node_process2.default.stdout.removeListener("error", stdoutErrorHandler);
|
|
4107
4208
|
};
|
|
4108
|
-
|
|
4109
|
-
res.pipe(
|
|
4209
|
+
import_node_process2.default.stdout.on("error", stdoutErrorHandler);
|
|
4210
|
+
res.pipe(import_node_process2.default.stdout);
|
|
4110
4211
|
res.on("end", () => {
|
|
4111
|
-
|
|
4212
|
+
import_node_process2.default.stdout.removeListener("error", stdoutErrorHandler);
|
|
4112
4213
|
});
|
|
4113
4214
|
res.on("error", () => {
|
|
4114
|
-
|
|
4215
|
+
import_node_process2.default.stdout.removeListener("error", stdoutErrorHandler);
|
|
4115
4216
|
});
|
|
4116
4217
|
}
|
|
4117
4218
|
return this.#handleApiSuccess(res);
|
|
@@ -4196,7 +4297,8 @@ var SocketSdk = class {
|
|
|
4196
4297
|
}
|
|
4197
4298
|
}
|
|
4198
4299
|
/**
|
|
4199
|
-
* Update organization's license policy configuration
|
|
4300
|
+
* Update organization's license policy configuration.
|
|
4301
|
+
* Modifies allowed, restricted, and monitored license types.
|
|
4200
4302
|
*
|
|
4201
4303
|
* @throws {Error} When server returns 5xx status codes
|
|
4202
4304
|
*/
|
|
@@ -4219,7 +4321,8 @@ var SocketSdk = class {
|
|
|
4219
4321
|
}
|
|
4220
4322
|
}
|
|
4221
4323
|
/**
|
|
4222
|
-
* Update organization's security policy configuration
|
|
4324
|
+
* Update organization's security policy configuration.
|
|
4325
|
+
* Modifies alert rules, severity thresholds, and enforcement settings.
|
|
4223
4326
|
*
|
|
4224
4327
|
* @throws {Error} When server returns 5xx status codes
|
|
4225
4328
|
*/
|
|
@@ -4514,18 +4617,25 @@ var SocketSdk = class {
|
|
|
4514
4617
|
* vulnerabilities, description, license, and tier information.
|
|
4515
4618
|
*/
|
|
4516
4619
|
async viewPatch(orgSlug, uuid) {
|
|
4517
|
-
|
|
4518
|
-
await
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4620
|
+
try {
|
|
4621
|
+
const data = await this.#executeWithRetry(
|
|
4622
|
+
async () => await getResponseJson(
|
|
4623
|
+
await createGetRequest(
|
|
4624
|
+
this.#baseUrl,
|
|
4625
|
+
`orgs/${encodeURIComponent(orgSlug)}/patches/view/${encodeURIComponent(uuid)}`,
|
|
4626
|
+
{ ...this.#reqOptions, hooks: this.#hooks }
|
|
4627
|
+
)
|
|
4628
|
+
)
|
|
4629
|
+
);
|
|
4630
|
+
return data;
|
|
4631
|
+
} catch (e) {
|
|
4632
|
+
const result = await this.#handleApiError(e);
|
|
4633
|
+
throw new Error(result.error, { cause: result.cause });
|
|
4634
|
+
}
|
|
4525
4635
|
}
|
|
4526
4636
|
};
|
|
4527
4637
|
if ((0, import_debug2.isDebugNs)("heap")) {
|
|
4528
|
-
const used =
|
|
4638
|
+
const used = import_node_process2.default.memoryUsage();
|
|
4529
4639
|
(0, import_debug2.debugLog)("heap", `heap used: ${Math.round(used.heapUsed / 1024 / 1024)}MB`);
|
|
4530
4640
|
}
|
|
4531
4641
|
// Annotate the CommonJS export names for ESM import in node:
|