@socketsecurity/cli 0.14.39 → 0.14.41
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/README.md +1 -1
- package/bin/cli.js +12 -6
- package/dist/{module-sync/constants.d.ts → constants.d.ts} +13 -2
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -10
- package/dist/module-sync/cli.js +455 -404
- package/dist/module-sync/debug.d.ts +3 -0
- package/dist/module-sync/errors.d.ts +3 -1
- package/dist/module-sync/logging.d.ts +16 -0
- package/dist/module-sync/npm-injection.js +1119 -1095
- package/dist/module-sync/path-resolve.d.ts +1 -1
- package/dist/module-sync/path-resolve.js +50 -5
- package/dist/module-sync/settings.d.ts +6 -1
- package/dist/module-sync/shadow-bin.d.ts +2 -2
- package/dist/module-sync/shadow-bin.js +23 -40
- package/dist/module-sync/socket-url.d.ts +40 -0
- package/dist/module-sync/socket-url.js +301 -0
- package/dist/require/cli.js +454 -401
- package/dist/require/npm-injection.js +2 -1511
- package/dist/require/path-resolve.js +2 -200
- package/dist/require/shadow-bin.js +2 -102
- package/dist/require/socket-url.js +3 -0
- package/dist/require/vendor.js +53 -400
- package/package.json +39 -31
- package/dist/module-sync/color-or-markdown.d.ts +0 -23
- package/dist/module-sync/constants.d.ts.map +0 -1
- package/dist/module-sync/sdk.d.ts +0 -8
- package/dist/module-sync/sdk.js +0 -214
- package/dist/require/constants.d.ts.map +0 -1
- package/dist/require/sdk.js +0 -212
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socketsecurity/cli",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.41",
|
|
4
4
|
"description": "CLI tool for Socket.dev",
|
|
5
5
|
"homepage": "http://github.com/SocketDev/socket-cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"check:lint": "eslint --report-unused-disable-directives .",
|
|
44
44
|
"check:tsc": "tsc",
|
|
45
45
|
"check:type-coverage": "type-coverage --detail --strict --at-least 95 --ignore-files 'test/*'",
|
|
46
|
+
"clean": "run-p --aggregate-output clean:*",
|
|
47
|
+
"clean:dist": "del-cli 'dist' 'test/dist'",
|
|
48
|
+
"clean:node_modules": "del-cli '**/node_modules'",
|
|
46
49
|
"knip:dependencies": "knip --dependencies",
|
|
47
50
|
"knip:exports": "knip --include exports,duplicates",
|
|
48
51
|
"lint": "oxlint -c=./.oxlintrc.json --ignore-path=./.prettierignore --tsconfig=./tsconfig.json .",
|
|
@@ -53,36 +56,38 @@
|
|
|
53
56
|
"test-ci": "run-s build:* test:*",
|
|
54
57
|
"test:unit": "tap-run",
|
|
55
58
|
"test:coverage:c8": "c8 --reporter=none node --test 'test/socket-npm.test.cjs'",
|
|
56
|
-
"test:coverage:merge": "cp -r .tap/coverage/*.json coverage/tmp && c8 --reporter=lcov --reporter=text --include 'dist/{module-sync,require}/*.js' --exclude 'dist/require/vendor.js' report"
|
|
59
|
+
"test:coverage:merge": "cp -r .tap/coverage/*.json coverage/tmp && c8 --reporter=lcov --reporter=text --include 'dist/{module-sync,require}/*.js' --exclude 'dist/require/vendor.js' report",
|
|
60
|
+
"update": "run-p --aggregate-output update:**",
|
|
61
|
+
"update:deps": "npx npm-check-updates"
|
|
57
62
|
},
|
|
58
63
|
"dependencies": {
|
|
59
64
|
"@apideck/better-ajv-errors": "^0.3.6",
|
|
60
|
-
"@cyclonedx/cdxgen": "^11.
|
|
65
|
+
"@cyclonedx/cdxgen": "^11.1.5",
|
|
61
66
|
"@npmcli/promise-spawn": "^8.0.2",
|
|
62
|
-
"@socketregistry/hyrious__bun.lockb": "1.0.
|
|
63
|
-
"@socketregistry/
|
|
67
|
+
"@socketregistry/hyrious__bun.lockb": "^1.0.12",
|
|
68
|
+
"@socketregistry/indent-string": "^1.0.9",
|
|
69
|
+
"@socketregistry/is-interactive": "^1.0.1",
|
|
70
|
+
"@socketregistry/is-unicode-supported": "^1.0.0",
|
|
64
71
|
"@socketsecurity/config": "^2.1.3",
|
|
65
|
-
"@socketsecurity/registry": "^1.0.
|
|
66
|
-
"@socketsecurity/sdk": "^1.
|
|
72
|
+
"@socketsecurity/registry": "^1.0.78",
|
|
73
|
+
"@socketsecurity/sdk": "^1.4.5",
|
|
67
74
|
"blessed": "^0.1.81",
|
|
68
75
|
"blessed-contrib": "^4.11.0",
|
|
69
|
-
"browserslist": "4.24.
|
|
76
|
+
"browserslist": "4.24.4",
|
|
70
77
|
"chalk-table": "^1.0.2",
|
|
71
78
|
"cmd-shim": "^7.0.0",
|
|
72
|
-
"has-flag": "
|
|
79
|
+
"has-flag": "4.0.0",
|
|
73
80
|
"hpagent": "^1.2.0",
|
|
74
|
-
"ignore": "^7.0.
|
|
75
|
-
"is-interactive": "^2.0.0",
|
|
76
|
-
"is-unicode-supported": "^2.1.0",
|
|
81
|
+
"ignore": "^7.0.3",
|
|
77
82
|
"meow": "^13.2.0",
|
|
78
83
|
"micromatch": "^4.0.8",
|
|
79
84
|
"npm-package-arg": "^12.0.1",
|
|
80
85
|
"open": "^10.1.0",
|
|
81
86
|
"pony-cause": "^2.1.11",
|
|
82
|
-
"semver": "^7.
|
|
87
|
+
"semver": "^7.7.0",
|
|
83
88
|
"synp": "^1.9.14",
|
|
84
|
-
"terminal-link": "
|
|
85
|
-
"tiny-updater": "^3.5.
|
|
89
|
+
"terminal-link": "2.1.1",
|
|
90
|
+
"tiny-updater": "^3.5.3",
|
|
86
91
|
"tinyglobby": "^0.2.10",
|
|
87
92
|
"which": "^5.0.0",
|
|
88
93
|
"yaml": "^2.7.0",
|
|
@@ -90,16 +95,16 @@
|
|
|
90
95
|
"yoctocolors-cjs": "^2.1.2"
|
|
91
96
|
},
|
|
92
97
|
"devDependencies": {
|
|
93
|
-
"@babel/core": "^7.26.
|
|
98
|
+
"@babel/core": "^7.26.7",
|
|
94
99
|
"@babel/plugin-proposal-export-default-from": "^7.25.9",
|
|
95
100
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
96
101
|
"@babel/plugin-transform-export-namespace-from": "^7.25.9",
|
|
97
102
|
"@babel/plugin-transform-runtime": "^7.25.9",
|
|
98
|
-
"@babel/preset-env": "^7.26.
|
|
103
|
+
"@babel/preset-env": "^7.26.7",
|
|
99
104
|
"@babel/preset-typescript": "^7.26.0",
|
|
100
|
-
"@babel/runtime": "^7.26.
|
|
101
|
-
"@eslint/compat": "^1.2.
|
|
102
|
-
"@eslint/js": "^9.
|
|
105
|
+
"@babel/runtime": "^7.26.7",
|
|
106
|
+
"@eslint/compat": "^1.2.5",
|
|
107
|
+
"@eslint/js": "^9.19.0",
|
|
103
108
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
104
109
|
"@rollup/plugin-json": "^6.1.0",
|
|
105
110
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
@@ -111,39 +116,40 @@
|
|
|
111
116
|
"@types/micromatch": "^4.0.9",
|
|
112
117
|
"@types/mocha": "^10.0.10",
|
|
113
118
|
"@types/mock-fs": "^4.13.4",
|
|
114
|
-
"@types/node": "^22.
|
|
115
|
-
"@types/npmcli__arborist": "^
|
|
119
|
+
"@types/node": "^22.12.0",
|
|
120
|
+
"@types/npmcli__arborist": "^6.3.0",
|
|
116
121
|
"@types/npmcli__promise-spawn": "^6.0.3",
|
|
117
122
|
"@types/proc-log": "^3.0.4",
|
|
118
123
|
"@types/semver": "^7.5.8",
|
|
119
124
|
"@types/update-notifier": "^6.0.8",
|
|
120
125
|
"@types/which": "^3.0.4",
|
|
121
126
|
"@types/yargs-parser": "^21.0.3",
|
|
122
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
123
|
-
"@typescript-eslint/parser": "^8.
|
|
127
|
+
"@typescript-eslint/eslint-plugin": "^8.22.0",
|
|
128
|
+
"@typescript-eslint/parser": "^8.22.0",
|
|
124
129
|
"c8": "^10.1.3",
|
|
125
130
|
"custompatch": "^1.1.4",
|
|
126
|
-
"
|
|
127
|
-
"eslint
|
|
131
|
+
"del-cli": "^6.0.0",
|
|
132
|
+
"eslint": "^9.19.0",
|
|
133
|
+
"eslint-import-resolver-oxc": "^0.10.1",
|
|
128
134
|
"eslint-plugin-depend": "^0.12.0",
|
|
129
135
|
"eslint-plugin-import-x": "^4.6.1",
|
|
130
136
|
"eslint-plugin-n": "^17.15.1",
|
|
131
137
|
"eslint-plugin-sort-destructure-keys": "^2.0.0",
|
|
132
138
|
"eslint-plugin-unicorn": "^56.0.1",
|
|
133
139
|
"husky": "^9.1.7",
|
|
134
|
-
"knip": "^5.
|
|
140
|
+
"knip": "^5.43.6",
|
|
135
141
|
"magic-string": "^0.30.17",
|
|
136
142
|
"mock-fs": "^5.4.1",
|
|
137
|
-
"nock": "^
|
|
143
|
+
"nock": "^14.0.0",
|
|
138
144
|
"npm-run-all2": "^7.0.2",
|
|
139
|
-
"oxlint": "0.15.
|
|
145
|
+
"oxlint": "0.15.8",
|
|
140
146
|
"prettier": "3.4.2",
|
|
141
147
|
"read-package-up": "^11.0.0",
|
|
142
|
-
"rollup": "4.
|
|
148
|
+
"rollup": "4.32.1",
|
|
143
149
|
"rollup-plugin-ts": "^3.4.5",
|
|
144
150
|
"type-coverage": "^2.29.7",
|
|
145
151
|
"typescript": "5.4.5",
|
|
146
|
-
"typescript-eslint": "^8.
|
|
152
|
+
"typescript-eslint": "^8.22.0",
|
|
147
153
|
"unplugin-purge-polyfills": "^0.0.7"
|
|
148
154
|
},
|
|
149
155
|
"overrides": {
|
|
@@ -166,6 +172,7 @@
|
|
|
166
172
|
"safer-buffer": "npm:@socketregistry/safer-buffer@^1",
|
|
167
173
|
"semver": "$semver",
|
|
168
174
|
"set-function-length": "npm:@socketregistry/set-function-length@^1",
|
|
175
|
+
"shell-quote": "npm:shell-quote@^1",
|
|
169
176
|
"side-channel": "npm:@socketregistry/side-channel@^1",
|
|
170
177
|
"tiny-colors": "$yoctocolors-cjs",
|
|
171
178
|
"typedarray": "npm:@socketregistry/typedarray@^1",
|
|
@@ -191,6 +198,7 @@
|
|
|
191
198
|
"safer-buffer": "npm:@socketregistry/safer-buffer@^1",
|
|
192
199
|
"semver": "^7.6.3",
|
|
193
200
|
"set-function-length": "npm:@socketregistry/set-function-length@^1",
|
|
201
|
+
"shell-quote": "npm:shell-quote@^1",
|
|
194
202
|
"side-channel": "npm:@socketregistry/side-channel@^1",
|
|
195
203
|
"tiny-colors": "npm:yoctocolors-cjs@^2.1.2",
|
|
196
204
|
"typedarray": "npm:@socketregistry/typedarray@^1",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
declare const logSymbols: {
|
|
2
|
-
__proto__: null;
|
|
3
|
-
info: string;
|
|
4
|
-
success: string;
|
|
5
|
-
warning: string;
|
|
6
|
-
error: string;
|
|
7
|
-
};
|
|
8
|
-
declare class ColorOrMarkdown {
|
|
9
|
-
useMarkdown: boolean;
|
|
10
|
-
constructor(useMarkdown: boolean);
|
|
11
|
-
header(text: string, level?: number): string;
|
|
12
|
-
bold(text: string): string;
|
|
13
|
-
italic(text: string): string;
|
|
14
|
-
hyperlink(text: string, url: string | undefined, { fallback, fallbackToUrl }?: {
|
|
15
|
-
fallback?: boolean;
|
|
16
|
-
fallbackToUrl?: boolean;
|
|
17
|
-
}): string;
|
|
18
|
-
list(items: string[]): string;
|
|
19
|
-
get logSymbols(): typeof logSymbols;
|
|
20
|
-
indent(text: string, level?: number): string;
|
|
21
|
-
json(value: unknown): string;
|
|
22
|
-
}
|
|
23
|
-
export { logSymbols, ColorOrMarkdown };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,MAAM,wCAAwC,CAAA;AAEtE,KAAK,WAAW,GAAG,OAAO,iBAAiB,CAAC,GAAG,CAAA;AAE/C,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAA;IAChD,QAAQ,CAAC,aAAa,EAAE,gBAAgB,CAAA;IACxC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAA;IAClC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG;QAC1B,4CAA4C,EAAE,OAAO,CAAA;KACtD,CAAA;IACD,QAAQ,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,CAAA;IAC7C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAA;IACvD,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,qBAAqB,EAAE,gDAAgD,CAAA;IAChF,QAAQ,CAAC,4CAA4C,EAAE,8CAA8C,CAAA;IACrG,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAA;IACjC,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAA;IACrC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B,GAAG,OAAO,iBAAiB,CAAA;AAwE5B,QAAA,MAAM,SAAS,WA4Cd,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { SocketSdk } from '@socketsecurity/sdk';
|
|
3
|
-
declare function createDebugLogger(printDebugLogs?: boolean): typeof console.error;
|
|
4
|
-
declare function isErrnoException(value: unknown): value is NodeJS.ErrnoException;
|
|
5
|
-
declare function stringJoinWithSeparateFinalSeparator(list: (string | undefined)[], separator?: string): string;
|
|
6
|
-
declare function getDefaultKey(): string | undefined;
|
|
7
|
-
declare function setupSdk(apiKey?: string | undefined, apiBaseUrl?: string | undefined, proxy?: string | undefined): Promise<SocketSdk>;
|
|
8
|
-
export { createDebugLogger, isErrnoException, stringJoinWithSeparateFinalSeparator, getDefaultKey, setupSdk };
|
package/dist/module-sync/sdk.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _socketInterop(e) {
|
|
4
|
-
let c = 0
|
|
5
|
-
for (const k in e ?? {}) {
|
|
6
|
-
c = c === 0 && k === 'default' ? 1 : 0
|
|
7
|
-
if (!c && k !== '__esModule') break
|
|
8
|
-
}
|
|
9
|
-
return c ? e.default : e
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
13
|
-
var isUnicodeSupported = _socketInterop(require('is-unicode-supported'));
|
|
14
|
-
var terminalLink = _socketInterop(require('terminal-link'));
|
|
15
|
-
var hpagent = _socketInterop(require('hpagent'));
|
|
16
|
-
var isInteractive = _socketInterop(require('is-interactive'));
|
|
17
|
-
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
18
|
-
var strings = require('@socketsecurity/registry/lib/strings');
|
|
19
|
-
var sdk = require('@socketsecurity/sdk');
|
|
20
|
-
var constants = require('./constants.js');
|
|
21
|
-
var fs = require('node:fs');
|
|
22
|
-
var homedir = require('node:os');
|
|
23
|
-
var path = require('node:path');
|
|
24
|
-
var yoctoSpinner = require('@socketregistry/yocto-spinner');
|
|
25
|
-
|
|
26
|
-
class AuthError extends Error {}
|
|
27
|
-
class InputError extends Error {
|
|
28
|
-
constructor(message, body) {
|
|
29
|
-
super(message);
|
|
30
|
-
this.body = body;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// From the 'log-symbols' module
|
|
35
|
-
const unicodeLogSymbols = {
|
|
36
|
-
__proto__: null,
|
|
37
|
-
info: colors.blue('ℹ'),
|
|
38
|
-
success: colors.green('✔'),
|
|
39
|
-
warning: colors.yellow('⚠'),
|
|
40
|
-
error: colors.red('✖')
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// From the 'log-symbols' module
|
|
44
|
-
const fallbackLogSymbols = {
|
|
45
|
-
__proto__: null,
|
|
46
|
-
info: colors.blue('i'),
|
|
47
|
-
success: colors.green('√'),
|
|
48
|
-
warning: colors.yellow('‼'),
|
|
49
|
-
error: colors.red('×')
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// From the 'log-symbols' module
|
|
53
|
-
const logSymbols = isUnicodeSupported() ? unicodeLogSymbols : fallbackLogSymbols;
|
|
54
|
-
const markdownLogSymbols = {
|
|
55
|
-
__proto__: null,
|
|
56
|
-
info: ':information_source:',
|
|
57
|
-
error: ':stop_sign:',
|
|
58
|
-
success: ':white_check_mark:',
|
|
59
|
-
warning: ':warning:'
|
|
60
|
-
};
|
|
61
|
-
class ColorOrMarkdown {
|
|
62
|
-
constructor(useMarkdown) {
|
|
63
|
-
this.useMarkdown = !!useMarkdown;
|
|
64
|
-
}
|
|
65
|
-
header(text, level = 1) {
|
|
66
|
-
return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` : colors.underline(`\n${level === 1 ? colors.bold(text) : text}\n`);
|
|
67
|
-
}
|
|
68
|
-
bold(text) {
|
|
69
|
-
return this.useMarkdown ? `**${text}**` : colors.bold(`${text}`);
|
|
70
|
-
}
|
|
71
|
-
italic(text) {
|
|
72
|
-
return this.useMarkdown ? `_${text}_` : colors.italic(`${text}`);
|
|
73
|
-
}
|
|
74
|
-
hyperlink(text, url, {
|
|
75
|
-
fallback = true,
|
|
76
|
-
fallbackToUrl
|
|
77
|
-
} = {}) {
|
|
78
|
-
if (!url) return text;
|
|
79
|
-
return this.useMarkdown ? `[${text}](${url})` : terminalLink(text, url, {
|
|
80
|
-
fallback: fallbackToUrl ? (_text, url) => url : fallback
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
list(items) {
|
|
84
|
-
const indentedContent = items.map(item => this.indent(item).trimStart());
|
|
85
|
-
return this.useMarkdown ? `* ${indentedContent.join('\n* ')}\n` : `${indentedContent.join('\n')}\n`;
|
|
86
|
-
}
|
|
87
|
-
get logSymbols() {
|
|
88
|
-
return this.useMarkdown ? markdownLogSymbols : logSymbols;
|
|
89
|
-
}
|
|
90
|
-
indent(text, level = 1) {
|
|
91
|
-
const indent = ''.padStart(level * 2, ' ');
|
|
92
|
-
return indent + text.split('\n').join('\n' + indent);
|
|
93
|
-
}
|
|
94
|
-
json(value) {
|
|
95
|
-
return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function createDebugLogger(printDebugLogs) {
|
|
100
|
-
return printDebugLogs ? (...params) => console.error(logSymbols.info, ...params) : () => {};
|
|
101
|
-
}
|
|
102
|
-
function isErrnoException(value) {
|
|
103
|
-
if (!(value instanceof Error)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
return value.code !== undefined;
|
|
107
|
-
}
|
|
108
|
-
function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
109
|
-
const values = list.filter(value => !!value);
|
|
110
|
-
if (values.length < 2) {
|
|
111
|
-
return values[0] || '';
|
|
112
|
-
}
|
|
113
|
-
const finalValue = values.pop();
|
|
114
|
-
return values.join(', ') + separator + finalValue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let dataHome = process.platform === 'win32' ? process.env['LOCALAPPDATA'] : process.env['XDG_DATA_HOME'];
|
|
118
|
-
if (!dataHome) {
|
|
119
|
-
if (process.platform === 'win32') throw new Error('missing %LOCALAPPDATA%');
|
|
120
|
-
const home = homedir.homedir();
|
|
121
|
-
dataHome = path.join(home, ...(process.platform === 'darwin' ? ['Library', 'Application Support'] : ['.local', 'share']));
|
|
122
|
-
}
|
|
123
|
-
const settingsPath = path.join(dataHome, 'socket', 'settings');
|
|
124
|
-
let settings = {};
|
|
125
|
-
if (fs.existsSync(settingsPath)) {
|
|
126
|
-
const raw = fs.readFileSync(settingsPath, 'utf8');
|
|
127
|
-
try {
|
|
128
|
-
settings = JSON.parse(Buffer.from(raw, 'base64').toString());
|
|
129
|
-
} catch {
|
|
130
|
-
yoctoSpinner().warning(`Failed to parse settings at ${settingsPath}`);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
fs.mkdirSync(path.dirname(settingsPath), {
|
|
134
|
-
recursive: true
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
function getSetting(key) {
|
|
138
|
-
return settings[key];
|
|
139
|
-
}
|
|
140
|
-
let pendingSave = false;
|
|
141
|
-
function updateSetting(key, value) {
|
|
142
|
-
settings[key] = value;
|
|
143
|
-
if (!pendingSave) {
|
|
144
|
-
pendingSave = true;
|
|
145
|
-
process.nextTick(() => {
|
|
146
|
-
pendingSave = false;
|
|
147
|
-
fs.writeFileSync(settingsPath, Buffer.from(JSON.stringify(settings)).toString('base64'));
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const {
|
|
153
|
-
rootPkgJsonPath
|
|
154
|
-
} = constants;
|
|
155
|
-
|
|
156
|
-
// This API key should be stored globally for the duration of the CLI execution.
|
|
157
|
-
let defaultKey;
|
|
158
|
-
function getDefaultKey() {
|
|
159
|
-
const key = process.env['SOCKET_SECURITY_API_KEY'] || getSetting('apiKey') || defaultKey;
|
|
160
|
-
defaultKey = strings.isNonEmptyString(key) ? key : undefined;
|
|
161
|
-
return defaultKey;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// The API server that should be used for operations.
|
|
165
|
-
function getDefaultAPIBaseUrl() {
|
|
166
|
-
const baseUrl = process.env['SOCKET_SECURITY_API_BASE_URL'] || getSetting('apiBaseUrl');
|
|
167
|
-
return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// The API server that should be used for operations.
|
|
171
|
-
function getDefaultHTTPProxy() {
|
|
172
|
-
const apiProxy = process.env['SOCKET_SECURITY_API_PROXY'] || getSetting('apiProxy');
|
|
173
|
-
return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined;
|
|
174
|
-
}
|
|
175
|
-
async function setupSdk(apiKey = getDefaultKey(), apiBaseUrl = getDefaultAPIBaseUrl(), proxy = getDefaultHTTPProxy()) {
|
|
176
|
-
if (typeof apiKey !== 'string' && isInteractive()) {
|
|
177
|
-
apiKey = await prompts.password({
|
|
178
|
-
message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
|
|
179
|
-
});
|
|
180
|
-
defaultKey = apiKey;
|
|
181
|
-
}
|
|
182
|
-
if (!apiKey) {
|
|
183
|
-
throw new AuthError('You need to provide an API key');
|
|
184
|
-
}
|
|
185
|
-
let agent;
|
|
186
|
-
if (proxy) {
|
|
187
|
-
agent = {
|
|
188
|
-
http: new hpagent.HttpProxyAgent({
|
|
189
|
-
proxy
|
|
190
|
-
}),
|
|
191
|
-
https: new hpagent.HttpsProxyAgent({
|
|
192
|
-
proxy
|
|
193
|
-
})
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
const sdkOptions = {
|
|
197
|
-
agent,
|
|
198
|
-
baseUrl: apiBaseUrl,
|
|
199
|
-
userAgent: sdk.createUserAgentFromPkgJson(require(rootPkgJsonPath))
|
|
200
|
-
};
|
|
201
|
-
return new sdk.SocketSdk(apiKey || '', sdkOptions);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
exports.AuthError = AuthError;
|
|
205
|
-
exports.ColorOrMarkdown = ColorOrMarkdown;
|
|
206
|
-
exports.InputError = InputError;
|
|
207
|
-
exports.createDebugLogger = createDebugLogger;
|
|
208
|
-
exports.getDefaultKey = getDefaultKey;
|
|
209
|
-
exports.getSetting = getSetting;
|
|
210
|
-
exports.isErrnoException = isErrnoException;
|
|
211
|
-
exports.logSymbols = logSymbols;
|
|
212
|
-
exports.setupSdk = setupSdk;
|
|
213
|
-
exports.stringJoinWithSeparateFinalSeparator = stringJoinWithSeparateFinalSeparator;
|
|
214
|
-
exports.updateSetting = updateSetting;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,MAAM,wCAAwC,CAAA;AAEtE,KAAK,WAAW,GAAG,OAAO,iBAAiB,CAAC,GAAG,CAAA;AAE/C,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAA;IAChD,QAAQ,CAAC,aAAa,EAAE,gBAAgB,CAAA;IACxC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAA;IAClC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG;QAC1B,4CAA4C,EAAE,OAAO,CAAA;KACtD,CAAA;IACD,QAAQ,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,CAAA;IAC7C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAA;IACvD,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,qBAAqB,EAAE,gDAAgD,CAAA;IAChF,QAAQ,CAAC,4CAA4C,EAAE,8CAA8C,CAAA;IACrG,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAA;IACjC,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAA;IACrC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B,GAAG,OAAO,iBAAiB,CAAA;AAwE5B,QAAA,MAAM,SAAS,WA4Cd,CAAA"}
|
package/dist/require/sdk.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _socketInterop(e) {
|
|
4
|
-
let c = 0
|
|
5
|
-
for (const k in e ?? {}) {
|
|
6
|
-
c = c === 0 && k === 'default' ? 1 : 0
|
|
7
|
-
if (!c && k !== '__esModule') break
|
|
8
|
-
}
|
|
9
|
-
return c ? e.default : e
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
13
|
-
var vendor = require('./vendor.js');
|
|
14
|
-
var hpagent = _socketInterop(require('hpagent'));
|
|
15
|
-
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
16
|
-
var strings = require('@socketsecurity/registry/lib/strings');
|
|
17
|
-
var sdk = require('@socketsecurity/sdk');
|
|
18
|
-
var constants = require('./constants.js');
|
|
19
|
-
var fs = require('node:fs');
|
|
20
|
-
var os = require('node:os');
|
|
21
|
-
var path = require('node:path');
|
|
22
|
-
var yoctoSpinner = require('@socketregistry/yocto-spinner');
|
|
23
|
-
|
|
24
|
-
class AuthError extends Error {}
|
|
25
|
-
class InputError extends Error {
|
|
26
|
-
constructor(message, body) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.body = body;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// From the 'log-symbols' module
|
|
33
|
-
const unicodeLogSymbols = {
|
|
34
|
-
__proto__: null,
|
|
35
|
-
info: colors.blue('ℹ'),
|
|
36
|
-
success: colors.green('✔'),
|
|
37
|
-
warning: colors.yellow('⚠'),
|
|
38
|
-
error: colors.red('✖')
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// From the 'log-symbols' module
|
|
42
|
-
const fallbackLogSymbols = {
|
|
43
|
-
__proto__: null,
|
|
44
|
-
info: colors.blue('i'),
|
|
45
|
-
success: colors.green('√'),
|
|
46
|
-
warning: colors.yellow('‼'),
|
|
47
|
-
error: colors.red('×')
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// From the 'log-symbols' module
|
|
51
|
-
const logSymbols = vendor.isUnicodeSupported() ? unicodeLogSymbols : fallbackLogSymbols;
|
|
52
|
-
const markdownLogSymbols = {
|
|
53
|
-
__proto__: null,
|
|
54
|
-
info: ':information_source:',
|
|
55
|
-
error: ':stop_sign:',
|
|
56
|
-
success: ':white_check_mark:',
|
|
57
|
-
warning: ':warning:'
|
|
58
|
-
};
|
|
59
|
-
class ColorOrMarkdown {
|
|
60
|
-
constructor(useMarkdown) {
|
|
61
|
-
this.useMarkdown = !!useMarkdown;
|
|
62
|
-
}
|
|
63
|
-
header(text, level = 1) {
|
|
64
|
-
return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` : colors.underline(`\n${level === 1 ? colors.bold(text) : text}\n`);
|
|
65
|
-
}
|
|
66
|
-
bold(text) {
|
|
67
|
-
return this.useMarkdown ? `**${text}**` : colors.bold(`${text}`);
|
|
68
|
-
}
|
|
69
|
-
italic(text) {
|
|
70
|
-
return this.useMarkdown ? `_${text}_` : colors.italic(`${text}`);
|
|
71
|
-
}
|
|
72
|
-
hyperlink(text, url, {
|
|
73
|
-
fallback = true,
|
|
74
|
-
fallbackToUrl
|
|
75
|
-
} = {}) {
|
|
76
|
-
if (!url) return text;
|
|
77
|
-
return this.useMarkdown ? `[${text}](${url})` : vendor.terminalLink(text, url, {
|
|
78
|
-
fallback: fallbackToUrl ? (_text, url) => url : fallback
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
list(items) {
|
|
82
|
-
const indentedContent = items.map(item => this.indent(item).trimStart());
|
|
83
|
-
return this.useMarkdown ? `* ${indentedContent.join('\n* ')}\n` : `${indentedContent.join('\n')}\n`;
|
|
84
|
-
}
|
|
85
|
-
get logSymbols() {
|
|
86
|
-
return this.useMarkdown ? markdownLogSymbols : logSymbols;
|
|
87
|
-
}
|
|
88
|
-
indent(text, level = 1) {
|
|
89
|
-
const indent = ''.padStart(level * 2, ' ');
|
|
90
|
-
return indent + text.split('\n').join('\n' + indent);
|
|
91
|
-
}
|
|
92
|
-
json(value) {
|
|
93
|
-
return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function createDebugLogger(printDebugLogs) {
|
|
98
|
-
return printDebugLogs ? (...params) => console.error(logSymbols.info, ...params) : () => {};
|
|
99
|
-
}
|
|
100
|
-
function isErrnoException(value) {
|
|
101
|
-
if (!(value instanceof Error)) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
return value.code !== undefined;
|
|
105
|
-
}
|
|
106
|
-
function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
107
|
-
const values = list.filter(value => !!value);
|
|
108
|
-
if (values.length < 2) {
|
|
109
|
-
return values[0] || '';
|
|
110
|
-
}
|
|
111
|
-
const finalValue = values.pop();
|
|
112
|
-
return values.join(', ') + separator + finalValue;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
let dataHome = process.platform === 'win32' ? process.env['LOCALAPPDATA'] : process.env['XDG_DATA_HOME'];
|
|
116
|
-
if (!dataHome) {
|
|
117
|
-
if (process.platform === 'win32') throw new Error('missing %LOCALAPPDATA%');
|
|
118
|
-
const home = os.homedir();
|
|
119
|
-
dataHome = path.join(home, ...(process.platform === 'darwin' ? ['Library', 'Application Support'] : ['.local', 'share']));
|
|
120
|
-
}
|
|
121
|
-
const settingsPath = path.join(dataHome, 'socket', 'settings');
|
|
122
|
-
let settings = {};
|
|
123
|
-
if (fs.existsSync(settingsPath)) {
|
|
124
|
-
const raw = fs.readFileSync(settingsPath, 'utf8');
|
|
125
|
-
try {
|
|
126
|
-
settings = JSON.parse(Buffer.from(raw, 'base64').toString());
|
|
127
|
-
} catch {
|
|
128
|
-
yoctoSpinner().warning(`Failed to parse settings at ${settingsPath}`);
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
fs.mkdirSync(path.dirname(settingsPath), {
|
|
132
|
-
recursive: true
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
function getSetting(key) {
|
|
136
|
-
return settings[key];
|
|
137
|
-
}
|
|
138
|
-
let pendingSave = false;
|
|
139
|
-
function updateSetting(key, value) {
|
|
140
|
-
settings[key] = value;
|
|
141
|
-
if (!pendingSave) {
|
|
142
|
-
pendingSave = true;
|
|
143
|
-
process.nextTick(() => {
|
|
144
|
-
pendingSave = false;
|
|
145
|
-
fs.writeFileSync(settingsPath, Buffer.from(JSON.stringify(settings)).toString('base64'));
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const {
|
|
151
|
-
rootPkgJsonPath
|
|
152
|
-
} = constants;
|
|
153
|
-
|
|
154
|
-
// This API key should be stored globally for the duration of the CLI execution.
|
|
155
|
-
let defaultKey;
|
|
156
|
-
function getDefaultKey() {
|
|
157
|
-
const key = process.env['SOCKET_SECURITY_API_KEY'] || getSetting('apiKey') || defaultKey;
|
|
158
|
-
defaultKey = strings.isNonEmptyString(key) ? key : undefined;
|
|
159
|
-
return defaultKey;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// The API server that should be used for operations.
|
|
163
|
-
function getDefaultAPIBaseUrl() {
|
|
164
|
-
const baseUrl = process.env['SOCKET_SECURITY_API_BASE_URL'] || getSetting('apiBaseUrl');
|
|
165
|
-
return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// The API server that should be used for operations.
|
|
169
|
-
function getDefaultHTTPProxy() {
|
|
170
|
-
const apiProxy = process.env['SOCKET_SECURITY_API_PROXY'] || getSetting('apiProxy');
|
|
171
|
-
return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined;
|
|
172
|
-
}
|
|
173
|
-
async function setupSdk(apiKey = getDefaultKey(), apiBaseUrl = getDefaultAPIBaseUrl(), proxy = getDefaultHTTPProxy()) {
|
|
174
|
-
if (typeof apiKey !== 'string' && vendor.isInteractive()) {
|
|
175
|
-
apiKey = await prompts.password({
|
|
176
|
-
message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
|
|
177
|
-
});
|
|
178
|
-
defaultKey = apiKey;
|
|
179
|
-
}
|
|
180
|
-
if (!apiKey) {
|
|
181
|
-
throw new AuthError('You need to provide an API key');
|
|
182
|
-
}
|
|
183
|
-
let agent;
|
|
184
|
-
if (proxy) {
|
|
185
|
-
agent = {
|
|
186
|
-
http: new hpagent.HttpProxyAgent({
|
|
187
|
-
proxy
|
|
188
|
-
}),
|
|
189
|
-
https: new hpagent.HttpsProxyAgent({
|
|
190
|
-
proxy
|
|
191
|
-
})
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
const sdkOptions = {
|
|
195
|
-
agent,
|
|
196
|
-
baseUrl: apiBaseUrl,
|
|
197
|
-
userAgent: sdk.createUserAgentFromPkgJson(require(rootPkgJsonPath))
|
|
198
|
-
};
|
|
199
|
-
return new sdk.SocketSdk(apiKey || '', sdkOptions);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
exports.AuthError = AuthError;
|
|
203
|
-
exports.ColorOrMarkdown = ColorOrMarkdown;
|
|
204
|
-
exports.InputError = InputError;
|
|
205
|
-
exports.createDebugLogger = createDebugLogger;
|
|
206
|
-
exports.getDefaultKey = getDefaultKey;
|
|
207
|
-
exports.getSetting = getSetting;
|
|
208
|
-
exports.isErrnoException = isErrnoException;
|
|
209
|
-
exports.logSymbols = logSymbols;
|
|
210
|
-
exports.setupSdk = setupSdk;
|
|
211
|
-
exports.stringJoinWithSeparateFinalSeparator = stringJoinWithSeparateFinalSeparator;
|
|
212
|
-
exports.updateSetting = updateSetting;
|