@socketsecurity/sdk 1.8.1 → 1.8.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 CHANGED
@@ -4,6 +4,12 @@ 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.8.2](https://github.com/SocketDev/socket-sdk-js/releases/tag/v1.8.2) - 2025-09-29
8
+
9
+ ### Fixed
10
+ - Fixed publishing workflow to ensure dist folder is built before npm publish
11
+ - Changed prepublishOnly script to prevent accidental local publishing
12
+
7
13
  ## [1.8.1](https://github.com/SocketDev/socket-sdk-js/releases/tag/v1.8.1) - 2025-09-29
8
14
 
9
15
  ### Changed
@@ -0,0 +1,5 @@
1
+ import type { ALERT_ACTION } from './types';
2
+ export declare const DEFAULT_USER_AGENT: string;
3
+ export declare const httpAgentNames: Set<string>;
4
+ export declare const publicPolicy: Map<"ambiguousClassifier" | "badEncoding" | "badSemver" | "badSemverDependency" | "bidi" | "binScriptConfusion" | "chromeContentScript" | "chromeHostPermission" | "chromePermission" | "chromeWildcardHostPermission" | "chronoAnomaly" | "compromisedSSHKey" | "copyleftLicense" | "criticalCVE" | "cve" | "debugAccess" | "deprecated" | "deprecatedException" | "deprecatedLicense" | "didYouMean" | "dynamicRequire" | "emptyPackage" | "envVars" | "explicitlyUnlicensedItem" | "extraneousDependency" | "fileDependency" | "filesystemAccess" | "floatingDependency" | "generic" | "gitDependency" | "gitHubDependency" | "gptAnomaly" | "gptDidYouMean" | "gptMalware" | "gptSecurity" | "hasNativeCode" | "highEntropyStrings" | "homoglyphs" | "httpDependency" | "installScripts" | "invalidPackageJSON" | "invisibleChars" | "licenseChange" | "licenseException" | "licenseSpdxDisj" | "longStrings" | "majorRefactor" | "malware" | "manifestConfusion" | "mediumCVE" | "mildCVE" | "minifiedFile" | "miscLicenseIssues" | "missingAuthor" | "missingDependency" | "missingLicense" | "missingTarball" | "mixedLicense" | "modifiedException" | "modifiedLicense" | "networkAccess" | "newAuthor" | "noAuthorData" | "noBugTracker" | "noLicenseFound" | "noREADME" | "noRepository" | "noTests" | "noV1" | "noWebsite" | "nonOSILicense" | "nonSPDXLicense" | "nonpermissiveLicense" | "notice" | "obfuscatedFile" | "obfuscatedRequire" | "peerDependency" | "potentialVulnerability" | "semverAnomaly" | "shellAccess" | "shellScriptOverride" | "shrinkwrap" | "socketUpgradeAvailable" | "suspiciousStarActivity" | "suspiciousString" | "telemetry" | "trivialPackage" | "troll" | "typeModuleCompatibility" | "uncaughtOptionalDependency" | "unclearLicense" | "unidentifiedLicense" | "unmaintained" | "unpopularPackage" | "unpublished" | "unresolvedRequire" | "unsafeCopyright" | "unstableOwnership" | "unusedDependency" | "urlStrings" | "usesEval" | "zeroWidth", ALERT_ACTION>;
5
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,SAAS,CAAA;AAEvD,eAAO,MAAM,kBAAkB,QAA0C,CAAA;AAIzE,eAAO,MAAM,cAAc,aAAsC,CAAA;AAGjE,eAAO,MAAM,YAAY,g5DA0GvB,CAAA"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.publicPolicy = exports.httpAgentNames = exports.DEFAULT_USER_AGENT = void 0;
7
+ /**
8
+ * @fileoverview Configuration constants and enums for the Socket SDK.
9
+ * Provides default values, HTTP agents, and public policy configurations for API interactions.
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
+ const package_json_1 = __importDefault(require("../package.json"));
15
+ const user_agent_1 = require("./user-agent");
16
+ exports.DEFAULT_USER_AGENT = (0, user_agent_1.createUserAgentFromPkgJson)(package_json_1.default);
17
+ // https://github.com/sindresorhus/got/blob/v14.4.6/documentation/2-options.md#agent
18
+ // Valid HTTP agent names for Got-style agent configuration compatibility.
19
+ exports.httpAgentNames = new Set(['http', 'https', 'http2']);
20
+ // Public security policy.
21
+ exports.publicPolicy = new Map([
22
+ // error (1):
23
+ ['malware', 'error'],
24
+ // warn (7):
25
+ ['criticalCVE', 'warn'],
26
+ ['didYouMean', 'warn'],
27
+ ['gitDependency', 'warn'],
28
+ ['httpDependency', 'warn'],
29
+ ['licenseSpdxDisj', 'warn'],
30
+ ['obfuscatedFile', 'warn'],
31
+ ['troll', 'warn'],
32
+ // monitor (7):
33
+ ['deprecated', 'monitor'],
34
+ ['mediumCVE', 'monitor'],
35
+ ['mildCVE', 'monitor'],
36
+ ['shrinkwrap', 'monitor'],
37
+ ['telemetry', 'monitor'],
38
+ ['unpopularPackage', 'monitor'],
39
+ ['unstableOwnership', 'monitor'],
40
+ // ignore (85):
41
+ ['ambiguousClassifier', 'ignore'],
42
+ ['badEncoding', 'ignore'],
43
+ ['badSemver', 'ignore'],
44
+ ['badSemverDependency', 'ignore'],
45
+ ['bidi', 'ignore'],
46
+ ['binScriptConfusion', 'ignore'],
47
+ ['chromeContentScript', 'ignore'],
48
+ ['chromeHostPermission', 'ignore'],
49
+ ['chromePermission', 'ignore'],
50
+ ['chromeWildcardHostPermission', 'ignore'],
51
+ ['chronoAnomaly', 'ignore'],
52
+ ['compromisedSSHKey', 'ignore'],
53
+ ['copyleftLicense', 'ignore'],
54
+ ['cve', 'ignore'],
55
+ ['debugAccess', 'ignore'],
56
+ ['deprecatedLicense', 'ignore'],
57
+ ['deprecatedException', 'ignore'],
58
+ ['dynamicRequire', 'ignore'],
59
+ ['emptyPackage', 'ignore'],
60
+ ['envVars', 'ignore'],
61
+ ['explicitlyUnlicensedItem', 'ignore'],
62
+ ['extraneousDependency', 'ignore'],
63
+ ['fileDependency', 'ignore'],
64
+ ['filesystemAccess', 'ignore'],
65
+ ['floatingDependency', 'ignore'],
66
+ ['gitHubDependency', 'ignore'],
67
+ ['gptAnomaly', 'ignore'],
68
+ ['gptDidYouMean', 'ignore'],
69
+ ['gptMalware', 'ignore'],
70
+ ['gptSecurity', 'ignore'],
71
+ ['hasNativeCode', 'ignore'],
72
+ ['highEntropyStrings', 'ignore'],
73
+ ['homoglyphs', 'ignore'],
74
+ ['installScripts', 'ignore'],
75
+ ['invalidPackageJSON', 'ignore'],
76
+ ['invisibleChars', 'ignore'],
77
+ ['licenseChange', 'ignore'],
78
+ ['licenseException', 'ignore'],
79
+ ['longStrings', 'ignore'],
80
+ ['majorRefactor', 'ignore'],
81
+ ['manifestConfusion', 'ignore'],
82
+ ['minifiedFile', 'ignore'],
83
+ ['miscLicenseIssues', 'ignore'],
84
+ ['missingAuthor', 'ignore'],
85
+ ['missingDependency', 'ignore'],
86
+ ['missingLicense', 'ignore'],
87
+ ['missingTarball', 'ignore'],
88
+ ['mixedLicense', 'ignore'],
89
+ ['modifiedException', 'ignore'],
90
+ ['modifiedLicense', 'ignore'],
91
+ ['networkAccess', 'ignore'],
92
+ ['newAuthor', 'ignore'],
93
+ ['noAuthorData', 'ignore'],
94
+ ['noBugTracker', 'ignore'],
95
+ ['noLicenseFound', 'ignore'],
96
+ ['noREADME', 'ignore'],
97
+ ['noRepository', 'ignore'],
98
+ ['noTests', 'ignore'],
99
+ ['noV1', 'ignore'],
100
+ ['noWebsite', 'ignore'],
101
+ ['nonOSILicense', 'ignore'],
102
+ ['nonSPDXLicense', 'ignore'],
103
+ ['nonpermissiveLicense', 'ignore'],
104
+ ['notice', 'ignore'],
105
+ ['obfuscatedRequire', 'ignore'],
106
+ ['peerDependency', 'ignore'],
107
+ ['potentialVulnerability', 'ignore'],
108
+ ['semverAnomaly', 'ignore'],
109
+ ['shellAccess', 'ignore'],
110
+ ['shellScriptOverride', 'ignore'],
111
+ ['socketUpgradeAvailable', 'ignore'],
112
+ ['suspiciousStarActivity', 'ignore'],
113
+ ['suspiciousString', 'ignore'],
114
+ ['trivialPackage', 'ignore'],
115
+ ['typeModuleCompatibility', 'ignore'],
116
+ ['uncaughtOptionalDependency', 'ignore'],
117
+ ['unclearLicense', 'ignore'],
118
+ ['unidentifiedLicense', 'ignore'],
119
+ ['unmaintained', 'ignore'],
120
+ ['unpublished', 'ignore'],
121
+ ['unresolvedRequire', 'ignore'],
122
+ ['unsafeCopyright', 'ignore'],
123
+ ['unusedDependency', 'ignore'],
124
+ ['urlStrings', 'ignore'],
125
+ ['usesEval', 'ignore'],
126
+ ['zeroWidth', 'ignore'],
127
+ ]);
128
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;;;;AAAA;;;GAGG;AAEH,4EAA4E;AAC5E,2DAA2D;AAC3D,gDAAgD;AAChD,mEAA+D;AAC/D,6CAAyD;AAI5C,QAAA,kBAAkB,GAAG,IAAA,uCAA0B,EAAC,sBAAW,CAAC,CAAA;AAEzE,oFAAoF;AACpF,0EAA0E;AAC7D,QAAA,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;AAEjE,0BAA0B;AACb,QAAA,YAAY,GAAG,IAAI,GAAG,CAA2B;IAC5D,aAAa;IACb,CAAC,SAAS,EAAE,OAAO,CAAC;IACpB,YAAY;IACZ,CAAC,aAAa,EAAE,MAAM,CAAC;IACvB,CAAC,YAAY,EAAE,MAAM,CAAC;IACtB,CAAC,eAAe,EAAE,MAAM,CAAC;IACzB,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC1B,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAC3B,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC1B,CAAC,OAAO,EAAE,MA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0 +1,22 @@
1
+ import { Readable } from 'node:stream';
2
+ import type { RequestOptions } from './types';
3
+ import type { ReadStream } from 'node:fs';
4
+ import type { IncomingMessage } from 'node:http';
5
+ /**
6
+ * Create multipart form-data body parts for file uploads.
7
+ * Converts file paths to readable streams with proper multipart headers.
8
+ */
9
+ export declare function createRequestBodyForFilepaths(filepaths: string[], basePath: string): Array<Array<string | ReadStream>>;
10
+ /**
11
+ * Create multipart form-data body part for JSON data.
12
+ * Converts JSON object to readable stream with appropriate headers.
13
+ */
14
+ export declare function createRequestBodyForJson(jsonData: unknown, basename?: string): Array<string | Readable>;
15
+ /**
16
+ * Create and execute a multipart/form-data upload request.
17
+ * Streams large files efficiently with backpressure handling and early server validation.
18
+ *
19
+ * @throws {Error} When network errors occur or stream processing fails
20
+ */
21
+ export declare function createUploadRequest(baseUrl: string, urlPath: string, requestBodyNoBoundaries: Array<string | Readable | Array<string | Readable>>, options: RequestOptions): Promise<IncomingMessage>;
22
+ //# sourceMappingURL=file-upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-upload.d.ts","sourceRoot":"","sources":["../src/file-upload.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAMtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,KAAK,EAAiB,eAAe,EAAE,MAAM,WAAW,CAAA;AAG/D;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EAAE,EACnB,QAAQ,EAAE,MAAM,GACf,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC,CAYnC;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,OAAO,EACjB,QAAQ,SAAc,GACrB,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAS1B;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,uBAAuB,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,EAC5E,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAuG1B"}
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createRequestBodyForFilepaths = createRequestBodyForFilepaths;
7
+ exports.createRequestBodyForJson = createRequestBodyForJson;
8
+ exports.createUploadRequest = createUploadRequest;
9
+ /** @fileoverview File upload utilities for Socket API with multipart form data support. */
10
+ const node_events_1 = __importDefault(require("node:events"));
11
+ const node_fs_1 = require("node:fs");
12
+ const node_path_1 = __importDefault(require("node:path"));
13
+ const node_stream_1 = require("node:stream");
14
+ const path_1 = require("@socketsecurity/registry/lib/path");
15
+ const http_client_1 = require("./http-client");
16
+ /**
17
+ * Create multipart form-data body parts for file uploads.
18
+ * Converts file paths to readable streams with proper multipart headers.
19
+ */
20
+ function createRequestBodyForFilepaths(filepaths, basePath) {
21
+ const requestBody = [];
22
+ for (const absPath of filepaths) {
23
+ const relPath = (0, path_1.normalizePath)(node_path_1.default.relative(basePath, absPath));
24
+ const filename = node_path_1.default.basename(absPath);
25
+ requestBody.push([
26
+ `Content-Disposition: form-data; name="${relPath}"; filename="${filename}"\r\n`,
27
+ `Content-Type: application/octet-stream\r\n\r\n`,
28
+ (0, node_fs_1.createReadStream)(absPath, { highWaterMark: 1024 * 1024 }),
29
+ ]);
30
+ }
31
+ return requestBody;
32
+ }
33
+ /**
34
+ * Create multipart form-data body part for JSON data.
35
+ * Converts JSON object to readable stream with appropriate headers.
36
+ */
37
+ function createRequestBodyForJson(jsonData, basename = 'data.json') {
38
+ const ext = node_path_1.default.extname(basename);
39
+ const name = node_path_1.default.basename(basename, ext);
40
+ return [
41
+ `Content-Disposition: form-data; name="${name}"; filename="${basename}"\r\n` +
42
+ `Content-Type: application/json\r\n\r\n`,
43
+ node_stream_1.Readable.from(JSON.stringify(jsonData), { highWaterMark: 1024 * 1024 }),
44
+ '\r\n',
45
+ ];
46
+ }
47
+ /**
48
+ * Create and execute a multipart/form-data upload request.
49
+ * Streams large files efficiently with backpressure handling and early server validation.
50
+ *
51
+ * @throws {Error} When network errors occur or stream processing fails
52
+ */
53
+ async function createUploadRequest(baseUrl, urlPath, requestBodyNoBoundaries, options) {
54
+ // This function constructs and sends a multipart/form-data HTTP POST request
55
+ // where each part is streamed to the server. It supports string payloads
56
+ // and readable streams (e.g., large file uploads).
57
+ // The body is streamed manually with proper backpressure support to avoid
58
+ // overwhelming Node.js memory (i.e., avoiding out-of-memory crashes for large inputs).
59
+ // We call `flushHeaders()` early to ensure headers are sent before body transmission
60
+ // begins. If the server rejects the request (e.g., bad org or auth), it will likely
61
+ // respond immediately. We listen for that response while still streaming the body.
62
+ //
63
+ // This protects against cases where the server closes the connection (EPIPE/ECONNRESET)
64
+ // mid-stream, which would otherwise cause hard-to-diagnose failures during file upload.
65
+ //
66
+ // Example failure this mitigates: `socket scan create --org badorg`
67
+ // eslint-disable-next-line no-async-promise-executor
68
+ return await new Promise(async (pass, fail) => {
69
+ const boundary = `NodeMultipartBoundary${Date.now()}`;
70
+ const boundarySep = `--${boundary}\r\n`;
71
+ const finalBoundary = `--${boundary}--\r\n`;
72
+ const requestBody = [
73
+ ...requestBodyNoBoundaries.flatMap(part => [
74
+ boundarySep,
75
+ /* c8 ignore next - Array.isArray branch for part is defensive coding for edge cases. */
76
+ ...(Array.isArray(part) ? part : [part]),
77
+ ]),
78
+ finalBoundary,
79
+ ];
80
+ const url = new URL(urlPath, baseUrl);
81
+ const req = (0, http_client_1.getHttpModule)(baseUrl).request(url, {
82
+ method: 'POST',
83
+ ...options,
84
+ headers: {
85
+ ...options?.headers,
86
+ 'Content-Type': `multipart/form-data; boundary=${boundary}`,
87
+ },
88
+ });
89
+ // Send headers early to prompt server validation (auth, URL, quota, etc.).
90
+ req.flushHeaders();
91
+ // Concurrently wait for response while we stream body.
92
+ (0, http_client_1.getResponse)(req).then(pass, fail);
93
+ let aborted = false;
94
+ req.on('error', () => (aborted = true));
95
+ req.on('close', () => (aborted = true));
96
+ try {
97
+ for (const part of requestBody) {
98
+ /* c8 ignore next 3 - aborted state is difficult to test reliably */
99
+ if (aborted) {
100
+ break;
101
+ }
102
+ if (typeof part === 'string') {
103
+ /* c8 ignore next 5 - backpressure handling requires specific stream conditions */
104
+ if (!req.write(part)) {
105
+ // Wait for 'drain' if backpressure is signaled.
106
+ // eslint-disable-next-line no-await-in-loop
107
+ await node_events_1.default.once(req, 'drain');
108
+ }
109
+ }
110
+ else if (typeof part?.pipe === 'function') {
111
+ // Stream data chunk-by-chunk with backpressure support.
112
+ const stream = part;
113
+ // eslint-disable-next-line no-await-in-loop
114
+ for await (const chunk of stream) {
115
+ /* c8 ignore next 3 - aborted state during streaming is difficult to test reliably */
116
+ if (aborted) {
117
+ break;
118
+ }
119
+ /* c8 ignore next 3 - backpressure handling requires specific stream conditions */
120
+ if (!req.write(chunk)) {
121
+ await node_events_1.default.once(req, 'drain');
122
+ }
123
+ }
124
+ // Ensure trailing CRLF after file part.
125
+ /* c8 ignore next 4 - trailing CRLF backpressure handling is edge case */
126
+ if (!aborted && !req.write('\r\n')) {
127
+ // eslint-disable-next-line no-await-in-loop
128
+ await node_events_1.default.once(req, 'drain');
129
+ }
130
+ // Cleanup stream to free memory buffers.
131
+ if (typeof part.destroy === 'function') {
132
+ part.destroy();
133
+ }
134
+ /* c8 ignore next 3 - defensive check for non-string/stream types */
135
+ }
136
+ else {
137
+ throw new TypeError('Expected string or stream');
138
+ }
139
+ }
140
+ }
141
+ catch (e) {
142
+ req.destroy(e);
143
+ fail(e);
144
+ }
145
+ finally {
146
+ if (!aborted) {
147
+ req.end();
148
+ }
149
+ }
150
+ });
151
+ }
152
+ //# sourceMappingURL=file-upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-upload.js","sourceRoot":"","sources":["../src/file-upload.ts"],"names":[],"mappings":";;;;;;;;AAAA,2FAA2F;AAC3F,8DAAgC;AAChC,qCAA0C;AAC1C,0DAA4B;AAC5B,6CAAsC;AAEtC,4DAAiE;AAEjE,+CAA0D;AAO1D;;;GAGG;AACH,uCACE,SAAmB,EACnB,QAAgB,EACmB;IACnC,MAAM,WAAW,GAAsC,EAAE,CAAA;IACzD,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,IAAA,oBAAa,EAAC,mBAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;QAC/D,MAAM,QAAQ,GAAG,mBAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QACvC,WAAW,CAAC,IAAI,CAAC;YACf,yCAAyC,OAAO,gBAAgB,QAAQ,OAAO;YAC/E,gDAAgD;YAChD,IAAA,0BAAgB,EAAC,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;SAC1D,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,WAAW,CAAA;AAAA,CACnB;AAED;;;GAGG;AACH,kCACE,QAAiB,EACjB,QAAQ,GAAG,WAAW,EACI;IAC1B,MAAM,GAAG,GAAG,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,MAAM,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IACzC,OAAO;QACL,yCAAyC,IAAI,gBAAgB,QAAQ,OAAO;YAC1E,wCAAwC;QAC1C,sBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,GAAG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AAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;wBACnC,4CAA4C;wBAC5C,MAAM,qBAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;oBACjC,CAAC;oBACD,yCAAyC;oBACzC,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;wBACvC,IAAI,CAAC,OAAO,EAAE,CAAA;oBAChB,CAAC;oBACD,oEAAoE;gBACtE,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAA;gBAClD,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,OAAO,CAAC,CAAU,CAAC,CAAA;YACvB,IAAI,CAAC,CAAC,CAAC,CAAA;QACT,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,GAAG,CAAC,GAAG,EAAE,CAAA;YACX,CAAC;QACH,CAAC;IAAA,CACF,CAAC,CAAA;AAAA,CACH"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @fileoverview HTTP client utilities for Socket API communication.
3
+ * Provides low-level HTTP request handling with proper error management and response parsing.
4
+ */
5
+ import http from 'node:http';
6
+ import https from 'node:https';
7
+ import type { RequestOptions, SendMethod } from './types';
8
+ import type { ClientRequest, IncomingMessage } from 'node:http';
9
+ /**
10
+ * HTTP response error for Socket API requests.
11
+ * Extends Error with response details for debugging failed API calls.
12
+ */
13
+ export declare class ResponseError extends Error {
14
+ response: IncomingMessage;
15
+ /**
16
+ * Create a new ResponseError from an HTTP response.
17
+ * Automatically formats error message with status code and message.
18
+ */
19
+ constructor(response: IncomingMessage, message?: string);
20
+ }
21
+ /**
22
+ * Create and execute an HTTP DELETE request.
23
+ * Returns the response stream for further processing.
24
+ *
25
+ * @throws {Error} When network or timeout errors occur
26
+ */
27
+ export declare function createDeleteRequest(baseUrl: string, urlPath: string, options: RequestOptions): Promise<IncomingMessage>;
28
+ /**
29
+ * Create and execute an HTTP GET request.
30
+ * Returns the response stream for further processing.
31
+ *
32
+ * @throws {Error} When network or timeout errors occur
33
+ */
34
+ export declare function createGetRequest(baseUrl: string, urlPath: string, options: RequestOptions): Promise<IncomingMessage>;
35
+ /**
36
+ * Create and execute an HTTP request with JSON payload.
37
+ * Automatically sets appropriate content headers and serializes the body.
38
+ *
39
+ * @throws {Error} When network or timeout errors occur
40
+ */
41
+ export declare function createRequestWithJson(method: SendMethod, baseUrl: string, urlPath: string, json: unknown, options: RequestOptions): Promise<IncomingMessage>;
42
+ /**
43
+ * Read the response body from an HTTP error response.
44
+ * Accumulates all chunks into a complete string for error handling.
45
+ *
46
+ * @throws {Error} When stream errors occur during reading
47
+ */
48
+ export declare function getErrorResponseBody(response: IncomingMessage): Promise<string>;
49
+ /**
50
+ * Get the appropriate HTTP module based on URL protocol.
51
+ * Returns http module for http: URLs, https module for https: URLs.
52
+ */
53
+ export declare function getHttpModule(url: string): typeof http | typeof https;
54
+ /**
55
+ * Wait for and return the HTTP response from a request.
56
+ * Handles timeout and error conditions during request processing.
57
+ *
58
+ * @throws {Error} When request times out or network errors occur
59
+ */
60
+ export declare function getResponse(req: ClientRequest): Promise<IncomingMessage>;
61
+ /**
62
+ * Parse HTTP response body as JSON.
63
+ * Validates response status and handles empty responses gracefully.
64
+ *
65
+ * @throws {ResponseError} When response has non-2xx status code
66
+ * @throws {SyntaxError} When response body contains invalid JSON
67
+ */
68
+ export declare function getResponseJson(response: IncomingMessage, method?: string): Promise<import("@socketsecurity/registry/lib/json").JsonValue>;
69
+ /**
70
+ * Check if HTTP response has a successful status code (2xx range).
71
+ * Returns true for status codes between 200-299, false otherwise.
72
+ */
73
+ export declare function isResponseOk(response: IncomingMessage): boolean;
74
+ /**
75
+ * Transform artifact data based on authentication status.
76
+ * Filters and compacts response data for public/free-tier users.
77
+ */
78
+ export declare function reshapeArtifactForPublicPolicy<T extends Record<string, any>>(data: T, isAuthenticated: boolean, actions?: string): T;
79
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,KAAK,MAAM,YAAY,CAAA;AAK9B,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EAGX,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE/D;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,EAAE,eAAe,CAAA;IAEzB;;;OAGG;IACH,YAAY,QAAQ,EAAE,eAAe,EAAE,OAAO,GAAE,MAAW,EAW1D;CACF;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAQ1B;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAQ1B;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAgB1B;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC,CASjB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,IAAI,GAAG,OAAO,KAAK,CAErE;AAED;;;;;GAKG;AACH,w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