@socketsecurity/sdk 1.11.2 → 2.0.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.
@@ -1,207 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var name = "@socketsecurity/sdk";
6
- var version = "1.11.2";
7
- var license = "MIT";
8
- var description = "SDK for the Socket API client";
9
- var author = {
10
- name: "Socket Inc",
11
- email: "eng@socket.dev",
12
- url: "https://socket.dev"
13
- };
14
- var homepage = "https://github.com/SocketDev/socket-sdk-js";
15
- var repository = {
16
- type: "git",
17
- url: "git://github.com/SocketDev/socket-sdk-js.git"
18
- };
19
- var type = "commonjs";
20
- var main = "./dist/index.js";
21
- var types = "./dist/index.d.ts";
22
- var exports$1 = {
23
- ".": {
24
- types: "./dist/index.d.ts",
25
- "default": "./dist/index.js"
26
- },
27
- "./testing": {
28
- types: "./dist/testing.d.ts",
29
- "default": "./dist/testing.js"
30
- },
31
- "./types/api-helpers": "./types/api-helpers.d.ts",
32
- "./types/api-helpers.d.ts": "./types/api-helpers.d.ts",
33
- "./types/api": "./types/api.d.ts",
34
- "./types/api.d.ts": "./types/api.d.ts",
35
- "./package.json": "./package.json"
36
- };
37
- var scripts = {
38
- build: "node scripts/build.mjs",
39
- "build:dist": "node scripts/build.mjs",
40
- "build:dist:src": "node scripts/build.mjs --src-only",
41
- "build:dist:types": "node scripts/build.mjs --types-only",
42
- check: "node scripts/check.mjs",
43
- "check:lint": "eslint --config .config/eslint.config.mjs --report-unused-disable-directives .",
44
- "check:lint:fix": "pnpm run check:lint -- --fix",
45
- "check:tsc": "tsgo --noEmit -p .config/tsconfig.check.json",
46
- "lint-ci": "pnpm run check:lint",
47
- coverage: "node scripts/coverage.mjs",
48
- "coverage:test": "node scripts/coverage.mjs --code-only",
49
- "coverage:type": "type-coverage",
50
- "coverage:type:verbose": "type-coverage --detail",
51
- "coverage:percent": "node scripts/coverage.mjs --percent",
52
- clean: "node scripts/clean.mjs",
53
- "clean:cache": "node scripts/clean.mjs --cache",
54
- "clean:coverage": "node scripts/clean.mjs --coverage",
55
- "clean:dist": "node scripts/clean.mjs --dist",
56
- "clean:dist:types": "node scripts/clean.mjs --dist-types",
57
- "clean:declarations": "node scripts/clean.mjs --declarations",
58
- "clean:node_modules": "node scripts/clean.mjs --node-modules",
59
- fix: "node scripts/lint-fix.mjs",
60
- "generate-sdk": "node scripts/generate-sdk.mjs",
61
- "generate-sdk:01-prettify": "node scripts/prettify-base-json.mjs",
62
- "generate-sdk:02-generate": "node scripts/generate-types.mjs > types/api.d.ts",
63
- "generate-sdk:03-clean-api": "pnpm run fix && pnpm run fix",
64
- "knip:dependencies": "knip --dependencies",
65
- "knip:exports": "knip --include exports,duplicates",
66
- lint: "oxlint -c=.config/.oxlintrc.json --ignore-path=.config/.oxlintignore --tsconfig=.config/tsconfig.json .",
67
- "lint:fix": "node scripts/lint-fix.mjs",
68
- "lint-staged": "lint-staged",
69
- precommit: "lint-staged",
70
- prepare: "husky",
71
- prepublishOnly: "echo 'ERROR: Use GitHub Actions workflow for publishing' && exit 1",
72
- "pretest:unit": "pnpm run build",
73
- test: "run-s check test:run",
74
- "test:run": "node scripts/test.mjs",
75
- "test:unit": "dotenvx -q run -f .env.test -- vitest --run",
76
- "test:unit:update": "dotenvx -q run -f .env.test -- vitest --run --update",
77
- "test:unit:coverage": "dotenvx -q run -f .env.test -- vitest run --coverage",
78
- "test-ci": "dotenvx -q run -f .env.test -- vitest --run",
79
- "type-ci": "pnpm run check:tsc",
80
- "test-pre-commit": "dotenvx -q run -f .env.precommit -- node scripts/test-with-build.mjs",
81
- update: "run-p --aggregate-output update:*",
82
- "update:deps": "node scripts/taze.mjs",
83
- "update:socket": "pnpm -r update '@socketsecurity/*' --latest"
84
- };
85
- var dependencies = {
86
- "@socketsecurity/registry": "1.5.3"
87
- };
88
- var devDependencies = {
89
- "@babel/core": "7.28.4",
90
- "@babel/plugin-transform-runtime": "7.28.3",
91
- "@babel/preset-typescript": "7.27.1",
92
- "@babel/runtime": "7.28.4",
93
- "@biomejs/biome": "2.2.4",
94
- "@dotenvx/dotenvx": "1.49.0",
95
- "@eslint/compat": "1.3.2",
96
- "@eslint/js": "9.35.0",
97
- "@rollup/plugin-babel": "6.0.4",
98
- "@rollup/plugin-commonjs": "28.0.6",
99
- "@rollup/plugin-json": "6.1.0",
100
- "@rollup/plugin-node-resolve": "16.0.1",
101
- "@types/node": "24.6.2",
102
- "@typescript/native-preview": "7.0.0-dev.20250926.1",
103
- "@vitest/coverage-v8": "3.2.4",
104
- "del-cli": "6.0.0",
105
- "dev-null-cli": "2.0.0",
106
- eslint: "9.35.0",
107
- "eslint-import-resolver-typescript": "4.4.4",
108
- "eslint-plugin-import-x": "4.16.1",
109
- "eslint-plugin-jsdoc": "57.0.8",
110
- "eslint-plugin-n": "17.23.1",
111
- "eslint-plugin-sort-destructure-keys": "2.0.0",
112
- "eslint-plugin-unicorn": "56.0.1",
113
- "fast-glob": "3.3.3",
114
- globals: "16.4.0",
115
- "http2-wrapper": "2.2.1",
116
- husky: "9.1.7",
117
- knip: "5.63.1",
118
- "lint-staged": "16.1.6",
119
- nock: "14.0.10",
120
- "npm-run-all2": "8.0.4",
121
- "openapi-typescript": "6.7.6",
122
- oxlint: "1.15.0",
123
- rollup: "4.50.1",
124
- taze: "19.6.0",
125
- trash: "10.0.0",
126
- "type-coverage": "2.29.7",
127
- "typescript-eslint": "8.44.1",
128
- vitest: "3.2.4",
129
- "yargs-parser": "22.0.0",
130
- "yoctocolors-cjs": "2.1.3"
131
- };
132
- var pnpm = {
133
- overrides: {
134
- vite: "7.1.7"
135
- },
136
- ignoredBuiltDependencies: [
137
- "esbuild",
138
- "unrs-resolver"
139
- ]
140
- };
141
- var engines = {
142
- node: ">=18",
143
- pnpm: ">=10.16.0"
144
- };
145
- var files = [
146
- "dist/**",
147
- "types/**",
148
- "CHANGELOG.md",
149
- "requirements.json"
150
- ];
151
- var typeCoverage = {
152
- cache: true,
153
- atLeast: 99.64,
154
- ignoreAsAssertion: true,
155
- ignoreCatch: true,
156
- ignoreEmptyType: true,
157
- "ignore-non-null-assertion": true,
158
- "ignore-type-assertion": true,
159
- "ignore-files": "test/*",
160
- strict: true
161
- };
162
- var rootPkgJson = {
163
- name: name,
164
- version: version,
165
- license: license,
166
- description: description,
167
- author: author,
168
- homepage: homepage,
169
- repository: repository,
170
- type: type,
171
- main: main,
172
- types: types,
173
- exports: exports$1,
174
- scripts: scripts,
175
- dependencies: dependencies,
176
- devDependencies: devDependencies,
177
- pnpm: pnpm,
178
- engines: engines,
179
- files: files,
180
- "lint-staged": {
181
- "*.{cjs,js,json,md,mjs,mts,ts}": [
182
- "oxlint -c=.config/.oxlintrc.json --ignore-path=.config/.oxlintignore --tsconfig=.config/tsconfig.json --quiet --fix",
183
- "biome format --log-level=none --fix --no-errors-on-unmatched --files-ignore-unknown=true --colors=off"
184
- ]
185
- },
186
- typeCoverage: typeCoverage
187
- };
188
-
189
- exports.author = author;
190
- exports.default = rootPkgJson;
191
- exports.dependencies = dependencies;
192
- exports.description = description;
193
- exports.devDependencies = devDependencies;
194
- exports.engines = engines;
195
- exports.exports = exports$1;
196
- exports.files = files;
197
- exports.homepage = homepage;
198
- exports.license = license;
199
- exports.main = main;
200
- exports.name = name;
201
- exports.pnpm = pnpm;
202
- exports.repository = repository;
203
- exports.scripts = scripts;
204
- exports.type = type;
205
- exports.typeCoverage = typeCoverage;
206
- exports.types = types;
207
- exports.version = version;
@@ -1,175 +0,0 @@
1
- 'use strict';
2
-
3
- var node_fs = require('node:fs');
4
- var path = require('node:path');
5
- var memoization = require('@socketsecurity/registry/lib/memoization');
6
-
7
- /** @fileoverview Quota utility functions for Socket SDK method cost lookup. */
8
- /**
9
- * Load requirements.json data with caching.
10
- * Internal function for lazy loading quota requirements.
11
- * Uses once() memoization to ensure file is only read once.
12
- */
13
- const loadRequirements = memoization.once(() => {
14
- try {
15
- // Resolve path relative to this module file location.
16
- // When compiled, __dirname will point to dist/ directory.
17
- // In source, __dirname points to src/ directory.
18
- // requirements.json is always in the parent directory of dist/ or src/.
19
- const requirementsPath = path.join(__dirname, '..', 'requirements.json');
20
- const data = node_fs.readFileSync(requirementsPath, 'utf8');
21
- return JSON.parse(data);
22
- } catch (e) {
23
- throw new Error('Failed to load "requirements.json"', {
24
- cause: e
25
- });
26
- }
27
- });
28
-
29
- /**
30
- * Calculate total quota cost for multiple SDK method calls.
31
- * Returns sum of quota units for all specified methods.
32
- */
33
- function calculateTotalQuotaCost(methodNames) {
34
- return methodNames.reduce((total, methodName) => {
35
- return total + getQuotaCost(methodName);
36
- }, 0);
37
- }
38
-
39
- /**
40
- * Get all available SDK methods with their requirements.
41
- * Returns complete mapping of methods to quota and permissions.
42
- * Creates a fresh deep copy each time to prevent external mutations.
43
- */
44
- function getAllMethodRequirements() {
45
- const reqs = loadRequirements();
46
- const result = {};
47
- Object.entries(reqs.api).forEach(([methodName, requirement]) => {
48
- result[methodName] = {
49
- permissions: [...requirement.permissions],
50
- quota: requirement.quota
51
- };
52
- });
53
- return result;
54
- }
55
-
56
- /**
57
- * Get complete requirement information for a SDK method.
58
- * Returns both quota cost and required permissions.
59
- * Memoized to avoid repeated lookups for the same method.
60
- */
61
- const getMethodRequirements = memoization.memoize(methodName => {
62
- const reqs = loadRequirements();
63
- const requirement = reqs.api[methodName];
64
- if (!requirement) {
65
- throw new Error(`Unknown SDK method: "${methodName}"`);
66
- }
67
- return {
68
- permissions: [...requirement.permissions],
69
- quota: requirement.quota
70
- };
71
- }, {
72
- name: 'getMethodRequirements'
73
- });
74
-
75
- /**
76
- * Get all methods that require specific permissions.
77
- * Returns methods that need any of the specified permissions.
78
- * Memoized since the same permission queries are often repeated.
79
- */
80
- const getMethodsByPermissions = memoization.memoize(permissions => {
81
- const reqs = loadRequirements();
82
- return Object.entries(reqs.api).filter(([, requirement]) => {
83
- return permissions.some(permission => requirement.permissions.includes(permission));
84
- }).map(([methodName]) => methodName).sort();
85
- }, {
86
- name: 'getMethodsByPermissions'
87
- });
88
-
89
- /**
90
- * Get all methods that consume a specific quota amount.
91
- * Useful for finding high-cost or free operations.
92
- * Memoized to cache results for commonly queried quota costs.
93
- */
94
- const getMethodsByQuotaCost = memoization.memoize(quotaCost => {
95
- const reqs = loadRequirements();
96
- return Object.entries(reqs.api).filter(([, requirement]) => requirement.quota === quotaCost).map(([methodName]) => methodName).sort();
97
- }, {
98
- name: 'getMethodsByQuotaCost'
99
- });
100
-
101
- /**
102
- * Get quota cost for a specific SDK method.
103
- * Returns the number of quota units consumed by the method.
104
- * Memoized since quota costs are frequently queried.
105
- */
106
- const getQuotaCost = memoization.memoize(methodName => {
107
- const reqs = loadRequirements();
108
- const requirement = reqs.api[methodName];
109
- if (!requirement) {
110
- throw new Error(`Unknown SDK method: "${methodName}"`);
111
- }
112
- return requirement.quota;
113
- }, {
114
- name: 'getQuotaCost'
115
- });
116
-
117
- /**
118
- * Get quota usage summary grouped by cost levels.
119
- * Returns methods categorized by their quota consumption.
120
- * Memoized since the summary structure is immutable after load.
121
- */
122
- const getQuotaUsageSummary = memoization.memoize(() => {
123
- const reqs = loadRequirements();
124
- const summary = {};
125
- Object.entries(reqs.api).forEach(([methodName, requirement]) => {
126
- const costKey = `${requirement.quota} units`;
127
- if (!summary[costKey]) {
128
- summary[costKey] = [];
129
- }
130
- summary[costKey].push(methodName);
131
- });
132
-
133
- // Sort methods within each cost level
134
- Object.keys(summary).forEach(costKey => {
135
- summary[costKey]?.sort();
136
- });
137
- return summary;
138
- }, {
139
- name: 'getQuotaUsageSummary'
140
- });
141
-
142
- /**
143
- * Get required permissions for a specific SDK method.
144
- * Returns array of permission strings needed to call the method.
145
- * Memoized to cache permission lookups per method.
146
- */
147
- const getRequiredPermissions = memoization.memoize(methodName => {
148
- const reqs = loadRequirements();
149
- const requirement = reqs.api[methodName];
150
- if (!requirement) {
151
- throw new Error(`Unknown SDK method: "${methodName}"`);
152
- }
153
- return [...requirement.permissions];
154
- }, {
155
- name: 'getRequiredPermissions'
156
- });
157
-
158
- /**
159
- * Check if user has sufficient quota for method calls.
160
- * Returns true if available quota covers the total cost.
161
- */
162
- function hasQuotaForMethods(availableQuota, methodNames) {
163
- const totalCost = calculateTotalQuotaCost(methodNames);
164
- return availableQuota >= totalCost;
165
- }
166
-
167
- exports.calculateTotalQuotaCost = calculateTotalQuotaCost;
168
- exports.getAllMethodRequirements = getAllMethodRequirements;
169
- exports.getMethodRequirements = getMethodRequirements;
170
- exports.getMethodsByPermissions = getMethodsByPermissions;
171
- exports.getMethodsByQuotaCost = getMethodsByQuotaCost;
172
- exports.getQuotaCost = getQuotaCost;
173
- exports.getQuotaUsageSummary = getQuotaUsageSummary;
174
- exports.getRequiredPermissions = getRequiredPermissions;
175
- exports.hasQuotaForMethods = hasQuotaForMethods;