@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 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
  [![Socket Badge](https://socket.dev/api/badge/npm/package/@socketsecurity/sdk)](https://socket.dev/npm/package/@socketsecurity/sdk)
4
- [![npm version](https://img.shields.io/npm/v/@socketsecurity/sdk.svg?style=flat)](https://www.npmjs.com/package/@socketsecurity/sdk)
5
- [![TypeScript types](https://img.shields.io/npm/types/@socketsecurity/sdk.svg?style=flat)](https://www.npmjs.com/package/@socketsecurity/sdk)
6
- [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/SocketDev/eslint-config)
4
+ [![CI](https://github.com/SocketDev/socket-sdk-js/actions/workflows/ci.yml/badge.svg)](https://github.com/SocketDev/socket-sdk-js/actions/workflows/ci.yml)
5
+
7
6
  [![Follow @SocketSecurity](https://img.shields.io/twitter/follow/SocketSecurity?style=social)](https://twitter.com/SocketSecurity)
8
7
  [![Follow @socket.dev on Bluesky](https://img.shields.io/badge/Follow-@socket.dev-1DA1F2?style=social&logo=bluesky)](https://bsky.app/profile/socket.dev)
9
8
 
10
- SDK for the Socket API client, generated by `api`.
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
 
@@ -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;
@@ -4,48 +4,48 @@ interface ApiRequirement {
4
4
  permissions: string[];
5
5
  }
6
6
  /**
7
- * Get quota cost for a specific SDK method.
8
- * Returns the number of quota units consumed by the method.
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 getQuotaCost(methodName: SocketSdkOperations | string): number;
10
+ export declare function calculateTotalQuotaCost(methodNames: Array<SocketSdkOperations | string>): number;
11
11
  /**
12
- * Get required permissions for a specific SDK method.
13
- * Returns array of permission strings needed to call the method.
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 getRequiredPermissions(methodName: SocketSdkOperations | string): string[];
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
- * Calculate total quota cost for multiple SDK method calls.
23
- * Returns sum of quota units for all specified methods.
22
+ * Get all methods that require specific permissions.
23
+ * Returns methods that need any of the specified permissions.
24
24
  */
25
- export declare function calculateTotalQuotaCost(methodNames: Array<SocketSdkOperations | string>): number;
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 all methods that require specific permissions.
33
- * Returns methods that need any of the specified permissions.
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 hasQuotaForMethods(availableQuota: number, methodNames: Array<SocketSdkOperations | string>): boolean;
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 all available SDK methods with their requirements.
48
- * Returns complete mapping of methods to quota and permissions.
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 getAllMethodRequirements(): Record<string, ApiRequirement>;
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 {};
@@ -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.getMethodsByQuotaCost = getMethodsByQuotaCost;
4
+ exports.getAllMethodRequirements = getAllMethodRequirements;
5
+ exports.getMethodRequirements = getMethodRequirements;
8
6
  exports.getMethodsByPermissions = getMethodsByPermissions;
9
- exports.hasQuotaForMethods = hasQuotaForMethods;
7
+ exports.getMethodsByQuotaCost = getMethodsByQuotaCost;
8
+ exports.getQuotaCost = getQuotaCost;
10
9
  exports.getQuotaUsageSummary = getQuotaUsageSummary;
11
- exports.getAllMethodRequirements = getAllMethodRequirements;
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
- * Get quota cost for a specific SDK method.
37
- * Returns the number of quota units consumed by the method.
36
+ * Calculate total quota cost for multiple SDK method calls.
37
+ * Returns sum of quota units for all specified methods.
38
38
  */
39
- function getQuotaCost(methodName) {
40
- const reqs = loadRequirements();
41
- const requirement = reqs.api[methodName];
42
- if (!requirement) {
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 required permissions for a specific SDK method.
49
- * Returns array of permission strings needed to call the method.
45
+ * Get all available SDK methods with their requirements.
46
+ * Returns complete mapping of methods to quota and permissions.
50
47
  */
51
- function getRequiredPermissions(methodName) {
48
+ function getAllMethodRequirements() {
52
49
  const reqs = loadRequirements();
53
- const requirement = reqs.api[methodName];
54
- if (!requirement) {
55
- throw new Error(`Unknown SDK method: "${methodName}"`);
56
- }
57
- return [...requirement.permissions];
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
- * Calculate total quota cost for multiple SDK method calls.
76
- * Returns sum of quota units for all specified methods.
75
+ * Get all methods that require specific permissions.
76
+ * Returns methods that need any of the specified permissions.
77
77
  */
78
- function calculateTotalQuotaCost(methodNames) {
79
- return methodNames.reduce((total, methodName) => {
80
- return total + getQuotaCost(methodName);
81
- }, 0);
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 all methods that require specific permissions.
96
- * Returns methods that need any of the specified permissions.
99
+ * Get quota cost for a specific SDK method.
100
+ * Returns the number of quota units consumed by the method.
97
101
  */
98
- function getMethodsByPermissions(permissions) {
102
+ function getQuotaCost(methodName) {
99
103
  const reqs = loadRequirements();
100
- return Object.entries(reqs.api)
101
- .filter(([, requirement]) => {
102
- return permissions.some(permission => requirement.permissions.includes(permission));
103
- })
104
- .map(([methodName]) => methodName)
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 all available SDK methods with their requirements.
137
- * Returns complete mapping of methods to quota and permissions.
131
+ * Get required permissions for a specific SDK method.
132
+ * Returns array of permission strings needed to call the method.
138
133
  */
139
- function getAllMethodRequirements() {
134
+ function getRequiredPermissions(methodName) {
140
135
  const reqs = loadRequirements();
141
- const result = {};
142
- Object.entries(reqs.api).forEach(([methodName, requirement]) => {
143
- result[methodName] = {
144
- quota: requirement.quota,
145
- permissions: [...requirement.permissions],
146
- };
147
- });
148
- return result;
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
  }