@socketsecurity/cli 0.11.0 → 0.11.1

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.
Files changed (82) hide show
  1. package/README.md +22 -22
  2. package/bin/npm +2 -0
  3. package/bin/npx +2 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +3419 -0
  7. package/dist/errors.d.ts +7 -0
  8. package/dist/link.d.ts +2 -0
  9. package/dist/link.js +45 -0
  10. package/dist/npm-cli.d.ts +2 -0
  11. package/dist/npm-cli.js +84 -0
  12. package/dist/npm-injection.d.ts +1 -0
  13. package/dist/npm-injection.js +913 -0
  14. package/dist/npm-injection2.d.ts +25 -0
  15. package/dist/npm-injection2.js +899 -0
  16. package/dist/npx-cli.d.ts +2 -0
  17. package/dist/npx-cli.js +60 -0
  18. package/dist/path-resolve.d.ts +12 -0
  19. package/dist/path-resolve.js +139 -0
  20. package/dist/sdk.d.ts +27 -0
  21. package/dist/sdk.js +224 -0
  22. package/dist/settings.d.ts +9 -0
  23. package/dist/type-helpers.d.ts +3 -0
  24. package/dist/vendor.js +25421 -0
  25. package/package.json +105 -52
  26. package/{lib/shadow/translations.json → translations.json} +20 -20
  27. package/cli.js +0 -72
  28. package/lib/commands/audit-log/index.js +0 -162
  29. package/lib/commands/cdxgen/index.js +0 -211
  30. package/lib/commands/dependencies/index.js +0 -150
  31. package/lib/commands/index.js +0 -15
  32. package/lib/commands/info/index.js +0 -287
  33. package/lib/commands/login/index.js +0 -170
  34. package/lib/commands/logout/index.js +0 -35
  35. package/lib/commands/npm/index.js +0 -27
  36. package/lib/commands/npx/index.js +0 -22
  37. package/lib/commands/organizations/index.js +0 -81
  38. package/lib/commands/raw-npm/index.js +0 -59
  39. package/lib/commands/raw-npx/index.js +0 -59
  40. package/lib/commands/report/create.js +0 -251
  41. package/lib/commands/report/index.js +0 -24
  42. package/lib/commands/report/view.js +0 -176
  43. package/lib/commands/repos/create.js +0 -166
  44. package/lib/commands/repos/delete.js +0 -93
  45. package/lib/commands/repos/index.js +0 -30
  46. package/lib/commands/repos/list.js +0 -170
  47. package/lib/commands/repos/update.js +0 -166
  48. package/lib/commands/repos/view.js +0 -128
  49. package/lib/commands/scan/create.js +0 -245
  50. package/lib/commands/scan/delete.js +0 -112
  51. package/lib/commands/scan/index.js +0 -30
  52. package/lib/commands/scan/list.js +0 -192
  53. package/lib/commands/scan/metadata.js +0 -113
  54. package/lib/commands/scan/stream.js +0 -115
  55. package/lib/commands/wrapper/index.js +0 -199
  56. package/lib/flags/command.js +0 -14
  57. package/lib/flags/index.js +0 -3
  58. package/lib/flags/output.js +0 -16
  59. package/lib/flags/validation.js +0 -14
  60. package/lib/shadow/bin/npm +0 -2
  61. package/lib/shadow/bin/npx +0 -2
  62. package/lib/shadow/link.cjs +0 -50
  63. package/lib/shadow/npm-cli.cjs +0 -27
  64. package/lib/shadow/npm-injection.cjs +0 -649
  65. package/lib/shadow/npx-cli.cjs +0 -27
  66. package/lib/shadow/package.json +0 -3
  67. package/lib/shadow/tty-server.cjs +0 -222
  68. package/lib/shadow/update-notifier.mjs +0 -3
  69. package/lib/utils/api-helpers.js +0 -42
  70. package/lib/utils/chalk-markdown.js +0 -125
  71. package/lib/utils/errors.js +0 -14
  72. package/lib/utils/flags.js +0 -27
  73. package/lib/utils/format-issues.js +0 -99
  74. package/lib/utils/formatting.js +0 -47
  75. package/lib/utils/issue-rules.cjs +0 -180
  76. package/lib/utils/meow-with-subcommands.js +0 -87
  77. package/lib/utils/misc.js +0 -61
  78. package/lib/utils/path-resolve.js +0 -204
  79. package/lib/utils/sdk.js +0 -99
  80. package/lib/utils/settings.js +0 -69
  81. package/lib/utils/type-helpers.cjs +0 -13
  82. package/lib/utils/update-notifier.js +0 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socketsecurity/cli",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "CLI tool for Socket.dev",
5
5
  "homepage": "http://github.com/SocketDev/socket-cli-js",
6
6
  "repository": {
@@ -14,104 +14,157 @@
14
14
  "url": "https://socket.dev"
15
15
  },
16
16
  "license": "MIT",
17
- "type": "module",
18
17
  "bin": {
19
- "socket": "cli.js",
20
- "socket-npm": "lib/shadow/npm-cli.cjs",
21
- "socket-npx": "lib/shadow/npx-cli.cjs"
18
+ "socket": "dist/cli.js",
19
+ "socket-npm": "dist/npm-cli.js",
20
+ "socket-npx": "dist/npx-cli.js"
22
21
  },
23
22
  "files": [
24
- "cli.js",
25
- "lib/**/*.js",
26
- "lib/**/*.json",
27
- "lib/**/*.cjs",
28
- "lib/shadow/**"
23
+ "bin/**",
24
+ "dist/**",
25
+ "translations.json"
29
26
  ],
30
27
  "dependencies": {
31
28
  "@apideck/better-ajv-errors": "^0.3.6",
32
- "@cyclonedx/cdxgen": "^10.7.0",
33
- "@inquirer/select": "^2.3.5",
29
+ "@cyclonedx/cdxgen": "^10.9.4",
30
+ "@inquirer/prompts": "^5.3.2",
34
31
  "@socketsecurity/config": "^2.1.3",
35
32
  "@socketsecurity/sdk": "^1.2.0",
36
- "chalk": "^5.3.0",
33
+ "ansi-align": "^3.0.1",
37
34
  "chalk-table": "^1.0.2",
38
- "execa": "^9.1.0",
39
- "globby": "^14.0.1",
35
+ "cli-boxes": "^3.0.0",
36
+ "cli-spinners": "^2.9.2",
37
+ "cross-spawn": "^7.0.3",
38
+ "dot-prop": "^9.0.0",
39
+ "eastasianwidth": "^0.2.0",
40
+ "emoji-regex": "^10.3.0",
41
+ "fast-glob": "^3.3.2",
42
+ "graceful-fs": "^4.2.6",
40
43
  "hpagent": "^1.2.0",
41
44
  "ignore": "^5.3.1",
42
- "ignore-by-default": "^2.1.0",
43
- "inquirer": "^9.2.23",
44
- "is-interactive": "^2.0.0",
45
- "is-unicode-supported": "^2.0.0",
46
- "meow": "^13.2.0",
47
- "open": "^10.1.0",
48
- "ora": "^8.0.1",
45
+ "ini": "4.1.3",
46
+ "onetime": "^5.1.0",
47
+ "pacote": "^18.0.6",
49
48
  "pony-cause": "^2.1.11",
50
- "prompts": "^2.4.2",
49
+ "rc": "1.2.8",
50
+ "registry-auth-token": "^5.0.2",
51
+ "semver": "^7.6.2",
52
+ "signal-exit": "^4.1.0",
53
+ "supports-hyperlinks": "^2.2.0",
51
54
  "synp": "^1.9.13",
52
- "terminal-link": "^3.0.0",
53
- "update-notifier": "^7.0.0",
54
55
  "which": "^4.0.0",
56
+ "write-file-atomic": "^5.0.1",
55
57
  "yargs-parser": "^21.1.1"
56
58
  },
57
59
  "devDependencies": {
60
+ "@babel/core": "^7.24.9",
61
+ "@babel/plugin-proposal-export-default-from": "^7.24.7",
62
+ "@babel/plugin-transform-export-namespace-from": "^7.24.7",
63
+ "@babel/plugin-transform-modules-commonjs": "^7.24.8",
64
+ "@babel/plugin-transform-runtime": "^7.24.7",
65
+ "@babel/preset-env": "^7.24.8",
66
+ "@babel/preset-typescript": "^7.24.7",
67
+ "@babel/runtime": "^7.24.8",
68
+ "@eslint/compat": "^1.1.1",
69
+ "@rollup/plugin-commonjs": "^26.0.1",
70
+ "@rollup/plugin-node-resolve": "^15.2.3",
71
+ "@rollup/plugin-replace": "^5.0.7",
72
+ "@rollup/pluginutils": "^5.1.0",
58
73
  "@socketsecurity/eslint-config": "^5.0.1",
59
74
  "@tsconfig/node20": "^20.1.4",
60
- "@types/chai": "^4.3.16",
61
- "@types/chai-as-promised": "^7.1.8",
62
- "@types/inquirer": "^9.0.7",
63
- "@types/micromatch": "^4.0.7",
64
- "@types/mocha": "^10.0.6",
75
+ "@types/micromatch": "^4.0.9",
76
+ "@types/mocha": "^10.0.7",
65
77
  "@types/mock-fs": "^4.13.4",
66
- "@types/node": "^20.12.13",
78
+ "@types/node": "^20.14.12",
67
79
  "@types/npm": "^7.19.3",
68
- "@types/npmcli__arborist": "^5.6.6",
69
- "@types/prompts": "^2.4.9",
80
+ "@types/npmcli__arborist": "^5.6.9",
70
81
  "@types/update-notifier": "^6.0.8",
71
82
  "@types/which": "^3.0.4",
72
83
  "@types/yargs-parser": "^21.0.3",
73
- "@typescript-eslint/eslint-plugin": "^7.11.0",
84
+ "@typescript-eslint/eslint-plugin": "^7.17.0",
74
85
  "@typescript-eslint/parser": "7.10.0",
75
86
  "c8": "^10.1.2",
76
- "dependency-check": "^5.0.0-7",
87
+ "chalk": "^5.3.0",
88
+ "esbuild": "^0.23.0",
77
89
  "eslint": "^8.56.0",
90
+ "eslint-config-prettier": "^9.1.0",
78
91
  "eslint-config-standard": "^17.1.0",
79
92
  "eslint-config-standard-jsx": "^11.0.0",
80
93
  "eslint-import-resolver-typescript": "^3.6.1",
94
+ "eslint-plugin-depend": "^0.10.0",
81
95
  "eslint-plugin-import": "^2.29.1",
82
- "eslint-plugin-jsdoc": "^48.2.7",
83
96
  "eslint-plugin-n": "^16.6.2",
84
- "eslint-plugin-promise": "^6.2.0",
85
- "eslint-plugin-react": "^7.34.2",
86
- "eslint-plugin-react-hooks": "^4.6.2",
97
+ "eslint-plugin-promise": "^6.6.0",
87
98
  "eslint-plugin-unicorn": "^48.0.1",
88
- "husky": "^9.0.11",
89
- "installed-check": "^9.3.0",
99
+ "execa": "^9.3.0",
100
+ "globby": "^14.0.2",
101
+ "husky": "^9.1.4",
102
+ "is-interactive": "^2.0.0",
103
+ "is-unicode-supported": "^2.0.0",
104
+ "knip": "^5.27.0",
105
+ "magic-string": "^0.30.10",
106
+ "meow": "^13.2.0",
90
107
  "mock-fs": "^5.2.0",
91
108
  "nock": "^13.5.4",
92
- "npm-run-all2": "^6.2.0",
93
- "type-coverage": "^2.29.0",
94
- "typescript": "~5.5.2"
109
+ "npm-run-all2": "^6.2.2",
110
+ "open": "^10.1.0",
111
+ "ora": "^8.0.1",
112
+ "prettier": "3.3.3",
113
+ "read-package-up": "^11.0.0",
114
+ "rollup": "4.19.0",
115
+ "rollup-plugin-ts": "^3.4.5",
116
+ "tap": "^21.0.0",
117
+ "terminal-link": "^3.0.0",
118
+ "type-coverage": "^2.29.1",
119
+ "typescript": "~5.4.5",
120
+ "unplugin-purge-polyfills": "^0.0.4",
121
+ "update-notifier": "^7.2.0",
122
+ "validate-npm-package-name": "^5.0.1"
95
123
  },
96
124
  "overrides": {
97
125
  "@cyclonedx/cdxgen": {
98
- "packageurl-js": "https://registry.npmjs.org/@jdalton/packageurl-js/-/packageurl-js-1.2.7.tgz"
99
- }
126
+ "packageurl-js": "https://registry.npmjs.org/@jdalton/packageurl-js/-/packageurl-js-1.5.0.tgz"
127
+ },
128
+ "array-includes": "npm:@nolyfill/array-includes@^1",
129
+ "array.prototype.findlast": "npm:@nolyfill/array.prototype.findlast@^1",
130
+ "array.prototype.findlastindex": "npm:@nolyfill/array.prototype.findlastindex@^1",
131
+ "array.prototype.flat": "npm:@nolyfill/array.prototype.flat@^1",
132
+ "array.prototype.flatmap": "npm:@nolyfill/array.prototype.flatmap@^1",
133
+ "array.prototype.tosorted": "npm:@nolyfill/array.prototype.tosorted@^1",
134
+ "es-iterator-helpers": "npm:@nolyfill/es-iterator-helpers@^1",
135
+ "globalthis": "npm:@nolyfill/globalthis@^1",
136
+ "hasown": "npm:@nolyfill/hasown@^1",
137
+ "is-core-module": "npm:@nolyfill/is-core-module@^1",
138
+ "object.assign": "npm:@nolyfill/object.assign@^1",
139
+ "object.entries": "npm:@nolyfill/object.entries@^1",
140
+ "object.fromentries": "npm:@nolyfill/object.fromentries@^1",
141
+ "object.groupby": "npm:@nolyfill/object.groupby@^1",
142
+ "object.values": "npm:@nolyfill/object.values@^1",
143
+ "side-channel": "npm:@nolyfill/side-channel@^1",
144
+ "string.prototype.matchall": "npm:@nolyfill/string.prototype.matchall@^1",
145
+ "string.prototype.repeat": "npm:@nolyfill/string.prototype.repeat@^1"
100
146
  },
101
147
  "engines": {
102
- "node": "^20.9.0 || >=21.1.0"
148
+ "node": "^20.9.0 || >=22.0.0"
103
149
  },
104
150
  "scripts": {
105
- "check:dependency-check": "dependency-check '*.js' 'lib/shadow/*.cjs' '*.mjs' 'test/*.js' --no-dev --ignore-module node:* --ignore-module @cyclonedx/* --ignore-module synp",
106
- "check:installed-check": "installed-check -i eslint-plugin-jsdoc",
151
+ "//check:knip": "knip",
152
+ "build": "npm run build:dist && npm run build:test",
153
+ "build:dist": "rollup -c .config/rollup.dist.config.mjs",
154
+ "build:test": "rollup -c .config/rollup.test.config.mjs",
107
155
  "check:lint": "eslint --report-unused-disable-directives .",
108
156
  "check:tsc": "tsc",
109
157
  "check:type-coverage": "type-coverage --detail --strict --at-least 95 --ignore-files 'test/*'",
110
158
  "check": "run-p -c --aggregate-output check:*",
111
159
  "prepare": "husky",
112
- "test:unit": "c8 --reporter=lcov --reporter text node --test",
113
- "test-ci": "run-s test:*",
114
- "test": "run-s check test:*",
160
+ "test:c8": "c8 --reporter=none node --test \"test/socket-npm.test.cjs\"",
161
+ "test:unit": "tap",
162
+ "test:coverage": "cp -r .tap/coverage/*.json coverage/tmp && c8 --reporter=lcov --reporter=text --include \"dist/*.js\" --exclude \"dist/vendor.js\" report",
163
+ "test-ci": "run-s build:* test:*",
164
+ "test": "run-s check build:* test:*",
165
+ "lint": "NODE_OPTIONS=--max-old-space-size=10240 eslint --quiet .",
166
+ "lint:fix": "npm run lint:fix:fast && NODE_OPTIONS=--max-old-space-size=10240 eslint --quiet --cache --fix .",
167
+ "lint:fix:fast": "prettier --cache --log-level warn --write .",
115
168
  "//postinstall": "node ./cli.js wrapper --postinstall"
116
169
  }
117
170
  }
@@ -177,11 +177,11 @@
177
177
  "emoji": "⚠️"
178
178
  },
179
179
  "extraneousDependency": {
180
- "description": "Package optionally loads a dependency which is not specified within any of the package.json dependency fields. It may inadvertently be importing dependencies specified by other packages.",
180
+ "description": "Package optionally loads a dependency which is not specified within any of the package.tson dependency fields. It may inadvertently be importing dependencies specified by other packages.",
181
181
  "props": {
182
182
  "name": "Name"
183
183
  },
184
- "suggestion": "Specify all optionally loaded dependencies in optionalDependencies within package.json.",
184
+ "suggestion": "Specify all optionally loaded dependencies in optionalDependencies within package.tson.",
185
185
  "title": "Extraneous dependency",
186
186
  "emoji": "⚠️"
187
187
  },
@@ -191,7 +191,7 @@
191
191
  "filePath": "File path",
192
192
  "packageName": "Package name"
193
193
  },
194
- "suggestion": "Remove the dependency specified by a file resolution string from package.json and update any bare name imports that referenced it before to use relative path strings.",
194
+ "suggestion": "Remove the dependency specified by a file resolution string from package.tson and update any bare name imports that referenced it before to use relative path strings.",
195
195
  "title": "File dependency",
196
196
  "emoji": "⚠️"
197
197
  },
@@ -274,9 +274,9 @@
274
274
  "emoji": "🤖"
275
275
  },
276
276
  "invalidPackageJSON": {
277
- "description": "Package has an invalid package.json and can cause installation problems if you try to use it.",
278
- "suggestion": "Fix syntax errors in the invalid package.json and publish a new version with a valid package.json. Consumers can use npm overrides to force a version that does not have this problem if one exists.",
279
- "title": "Invalid package.json",
277
+ "description": "Package has an invalid package.tson and can cause installation problems if you try to use it.",
278
+ "suggestion": "Fix syntax errors in the invalid package.tson and publish a new version with a valid package.tson. Consumers can use npm overrides to force a version that does not have this problem if one exists.",
279
+ "title": "Invalid package.tson",
280
280
  "emoji": "🤒"
281
281
  },
282
282
  "invisibleChars": {
@@ -367,17 +367,17 @@
367
367
  "emoji": "🫥"
368
368
  },
369
369
  "missingDependency": {
370
- "description": "A required dependency is not declared in package.json and may prevent the package from working.",
370
+ "description": "A required dependency is not declared in package.tson and may prevent the package from working.",
371
371
  "props": {
372
372
  "name": "Name"
373
373
  },
374
- "suggestion": "The package should define the missing dependency inside of package.json and publish a new version. Consumers may have to install the missing dependency themselves as long as the dependency remains missing. If the dependency is optional, add it to optionalDependencies and handle the missing case.",
374
+ "suggestion": "The package should define the missing dependency inside of package.tson and publish a new version. Consumers may have to install the missing dependency themselves as long as the dependency remains missing. If the dependency is optional, add it to optionalDependencies and handle the missing case.",
375
375
  "title": "Missing dependency",
376
376
  "emoji": "⚠️"
377
377
  },
378
378
  "missingLicense": {
379
379
  "description": "Package does not have a license and consumption legal status is unknown.",
380
- "suggestion": "A new version of the package should be published that includes a valid SPDX license in a license file, pacakge.json license field or mentioned in the README.",
380
+ "suggestion": "A new version of the package should be published that includes a valid SPDX license in a license file, pacakge.tson license field or mentioned in the README.",
381
381
  "title": "Missing license",
382
382
  "emoji": "⚠️"
383
383
  },
@@ -386,7 +386,7 @@
386
386
  "props": {
387
387
  "licenseId": "License Id"
388
388
  },
389
- "suggestion": "A new version of the package should be published that includes a single license. Consumers may seek clarification from the package author. Ensure that the license details are consistent across the LICENSE file, package.json license field and license details mentioned in the README.",
389
+ "suggestion": "A new version of the package should be published that includes a single license. Consumers may seek clarification from the package author. Ensure that the license details are consistent across the LICENSE file, package.tson license field and license details mentioned in the README.",
390
390
  "title": "Mixed license",
391
391
  "emoji": "⚠️"
392
392
  },
@@ -431,14 +431,14 @@
431
431
  "emoji": "⚠️"
432
432
  },
433
433
  "noAuthorData": {
434
- "description": "Package does not specify a list of contributors or an author in package.json.",
435
- "suggestion": "Add a author field or contributors array to package.json.",
434
+ "description": "Package does not specify a list of contributors or an author in package.tson.",
435
+ "suggestion": "Add a author field or contributors array to package.tson.",
436
436
  "title": "No contributors or author data",
437
437
  "emoji": "⚠️"
438
438
  },
439
439
  "noBugTracker": {
440
- "description": "Package does not have a linked bug tracker in package.json.",
441
- "suggestion": "Add a bugs field to package.json. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bugs",
440
+ "description": "Package does not have a linked bug tracker in package.tson.",
441
+ "suggestion": "Add a bugs field to package.tson. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bugs",
442
442
  "title": "No bug tracker",
443
443
  "emoji": "⚠️"
444
444
  },
@@ -450,7 +450,7 @@
450
450
  },
451
451
  "noRepository": {
452
452
  "description": "Package does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.",
453
- "suggestion": "Add a repository field to package.json. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#repository",
453
+ "suggestion": "Add a repository field to package.tson. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#repository",
454
454
  "title": "No repository",
455
455
  "emoji": "⚠️"
456
456
  },
@@ -468,7 +468,7 @@
468
468
  },
469
469
  "noWebsite": {
470
470
  "description": "Package does not have a website.",
471
- "suggestion": "Add a homepage field to package.json. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#homepage",
471
+ "suggestion": "Add a homepage field to package.tson. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#homepage",
472
472
  "title": "No website",
473
473
  "emoji": "⚠️"
474
474
  },
@@ -490,7 +490,7 @@
490
490
  },
491
491
  "nonSPDXLicense": {
492
492
  "description": "Package contains a non-standard license somewhere. Please read carefully before using.",
493
- "suggestion": "Package should adopt a standard SPDX license consistently across all license locations (LICENSE files, package.json license fields, and READMEs).",
493
+ "suggestion": "Package should adopt a standard SPDX license consistently across all license locations (LICENSE files, package.tson license fields, and READMEs).",
494
494
  "title": "Non SPDX license",
495
495
  "emoji": "⚠️"
496
496
  },
@@ -515,7 +515,7 @@
515
515
  "emoji": "⚠️"
516
516
  },
517
517
  "peerDependency": {
518
- "description": "Package specifies peer dependencies in package.json.",
518
+ "description": "Package specifies peer dependencies in package.tson.",
519
519
  "props": {
520
520
  "name": "Name"
521
521
  },
@@ -608,7 +608,7 @@
608
608
  "props": {
609
609
  "possibleLicenseId": "Possible license id"
610
610
  },
611
- "suggestion": "Add a LICENSE file that matches the license field in package.json. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#license",
611
+ "suggestion": "Add a LICENSE file that matches the license field in package.tson. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#license",
612
612
  "title": "Unclear license",
613
613
  "emoji": "⚠️"
614
614
  },
@@ -638,7 +638,7 @@
638
638
  },
639
639
  "unsafeCopyright": {
640
640
  "description": "Package contains a copyright but no license. Using this package may expose you to legal risk.",
641
- "suggestion": "Clarify the license type by adding a license field to package.json and a LICENSE file.",
641
+ "suggestion": "Clarify the license type by adding a license field to package.tson and a LICENSE file.",
642
642
  "title": "Unsafe copyright",
643
643
  "emoji": "⚠️"
644
644
  },
package/cli.js DELETED
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable no-console */
3
-
4
- import chalk from 'chalk'
5
- import { messageWithCauses, stackWithCauses } from 'pony-cause'
6
-
7
- import * as cliCommands from './lib/commands/index.js'
8
- import { logSymbols } from './lib/utils/chalk-markdown.js'
9
- import { AuthError, InputError } from './lib/utils/errors.js'
10
- import { meowWithSubcommands } from './lib/utils/meow-with-subcommands.js'
11
- import { initUpdateNotifier } from './lib/utils/update-notifier.js'
12
-
13
- // TODO: Add autocompletion using https://www.npmjs.com/package/omelette
14
-
15
- initUpdateNotifier()
16
-
17
- try {
18
- const formattedCliCommands = Object.fromEntries(Object.entries(cliCommands).map((entry) => {
19
- if (entry[0] === 'rawNpm') {
20
- entry[0] = 'raw-npm'
21
- } else if (entry[0] === 'rawNpx') {
22
- entry[0] = 'raw-npx'
23
- } else if (entry[0] === 'auditlog') {
24
- entry[0] = 'audit-log'
25
- }
26
- return entry
27
- }))
28
-
29
- await meowWithSubcommands(
30
- formattedCliCommands,
31
- {
32
- aliases: {
33
- ci: {
34
- description: 'Alias for "report create --view --strict"',
35
- argv: ['report', 'create', '--view', '--strict']
36
- },
37
- },
38
- argv: process.argv.slice(2),
39
- name: 'socket',
40
- importMeta: import.meta
41
- }
42
- )
43
- } catch (err) {
44
- /** @type {string} */
45
- let errorTitle
46
- /** @type {string} */
47
- let errorMessage = ''
48
- /** @type {string|undefined} */
49
- let errorBody
50
-
51
- if (err instanceof AuthError) {
52
- errorTitle = 'Authentication error'
53
- errorMessage = err.message
54
- } else if (err instanceof InputError) {
55
- errorTitle = 'Invalid input'
56
- errorMessage = err.message
57
- errorBody = err.body
58
- } else if (err instanceof Error) {
59
- errorTitle = 'Unexpected error'
60
- errorMessage = messageWithCauses(err)
61
- errorBody = stackWithCauses(err)
62
- } else {
63
- errorTitle = 'Unexpected error with no details'
64
- }
65
-
66
- console.error(`${logSymbols.error} ${chalk.white.bgRed(errorTitle + ':')} ${errorMessage}`)
67
- if (errorBody) {
68
- console.error('\n' + errorBody)
69
- }
70
-
71
- process.exit(1)
72
- }
@@ -1,162 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { Separator } from '@inquirer/select'
3
- import chalk from 'chalk'
4
- import inquirer from 'inquirer'
5
- import meow from 'meow'
6
- import ora from 'ora'
7
-
8
- import { outputFlags } from '../../flags/index.js'
9
- import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
10
- import { prepareFlags } from '../../utils/flags.js'
11
- import { printFlagList } from '../../utils/formatting.js'
12
- import { FREE_API_KEY, getDefaultKey, setupSdk } from '../../utils/sdk.js'
13
-
14
- /** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
15
- export const auditlog = {
16
- description: 'Look up the audit log for an organization',
17
- async run (argv, importMeta, { parentName }) {
18
- const name = parentName + ' audit-log'
19
-
20
- const input = setupCommand(name, auditlog.description, argv, importMeta)
21
- if (input) {
22
- const spinner = ora(`Looking up audit log for ${input.orgSlug}\n`).start()
23
- await fetchOrgAuditLog(input.orgSlug, input, spinner)
24
- }
25
- }
26
- }
27
-
28
- const auditLogFlags = prepareFlags({
29
- type: {
30
- type: 'string',
31
- shortFlag: 't',
32
- default: '',
33
- description: 'Type of log event',
34
- },
35
- perPage: {
36
- type: 'number',
37
- shortFlag: 'pp',
38
- default: 30,
39
- description: 'Results per page - default is 30',
40
- },
41
- page: {
42
- type: 'number',
43
- shortFlag: 'p',
44
- default: 1,
45
- description: 'Page number - default is 1',
46
- }
47
- })
48
-
49
- // Internal functions
50
-
51
- /**
52
- * @typedef CommandInput
53
- * @property {boolean} outputJson
54
- * @property {boolean} outputMarkdown
55
- * @property {string} orgSlug
56
- * @property {string} type
57
- * @property {number} page
58
- * @property {number} per_page
59
- */
60
-
61
- /**
62
- * @param {string} name
63
- * @param {string} description
64
- * @param {readonly string[]} argv
65
- * @param {ImportMeta} importMeta
66
- * @returns {void|CommandInput}
67
- */
68
- function setupCommand (name, description, argv, importMeta) {
69
- const flags = {
70
- ...auditLogFlags,
71
- ...outputFlags
72
- }
73
-
74
- const cli = meow(`
75
- Usage
76
- $ ${name} <org slug>
77
-
78
- Options
79
- ${printFlagList(flags, 6)}
80
-
81
- Examples
82
- $ ${name} FakeOrg
83
- `, {
84
- argv,
85
- description,
86
- importMeta,
87
- flags
88
- })
89
-
90
- const {
91
- json: outputJson,
92
- markdown: outputMarkdown,
93
- type,
94
- page,
95
- perPage
96
- } = cli.flags
97
-
98
- if (cli.input.length < 1) {
99
- console.error(`${chalk.bgRed('Input error')}: Please provide an organization slug \n`)
100
- cli.showHelp()
101
- return
102
- }
103
- const [orgSlug = ''] = cli.input
104
-
105
- return {
106
- outputJson,
107
- outputMarkdown,
108
- orgSlug,
109
- type: type && type.charAt(0).toUpperCase() + type.slice(1),
110
- page,
111
- per_page: perPage
112
- }
113
- }
114
-
115
- /**
116
- * @typedef AuditLogData
117
- * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getAuditLogEvents'>["data"]} data
118
- */
119
-
120
- /**
121
- * @param {string} orgSlug
122
- * @param {CommandInput} input
123
- * @param {import('ora').Ora} spinner
124
- * @returns {Promise<void|AuditLogData>}
125
- */
126
- async function fetchOrgAuditLog (orgSlug, input, spinner) {
127
- const socketSdk = await setupSdk(getDefaultKey() || FREE_API_KEY)
128
- const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, input), `Looking up audit log for ${orgSlug}\n`)
129
-
130
- if (!result.success) {
131
- return handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner)
132
- }
133
- spinner.stop()
134
-
135
- const /** @type {({name: string} | Separator)[]} */ data = []
136
- const /** @type {{[key: string]: string}} */ logDetails = {}
137
-
138
- result.data.results.map(d => {
139
- data.push({
140
- name: `${d.created_at && new Date(d.created_at).toLocaleDateString('en-us', { year: 'numeric', month: 'numeric', day: 'numeric' })} - ${d.user_email} - ${d.type} - ${d.ip_address} - ${d.user_agent}`
141
- }, new Separator())
142
-
143
- logDetails[`${d.created_at && new Date(d.created_at).toLocaleDateString('en-us', { year: 'numeric', month: 'numeric', day: 'numeric' })} - ${d.user_email} - ${d.type} - ${d.ip_address} - ${d.user_agent}`] = JSON.stringify(d.payload)
144
- return data
145
- })
146
-
147
- inquirer
148
- .prompt(
149
- {
150
- type: 'list',
151
- name: 'log',
152
- message: input.type ? `\n Audit log for: ${orgSlug} with type: ${input.type} \n` : `\n Audit log for: ${orgSlug} \n`,
153
- choices: data,
154
- pageSize: 30
155
- }
156
- )
157
- .then((/** @type {{log: string}} */ answers) => console.log(logDetails[answers.log]))
158
-
159
- return {
160
- data: result.data
161
- }
162
- }