@socketsecurity/sdk v1.4.44
@socketsecurity/sdk
SDK for the Socket API client, generated by api.
Usage
npm install @socketsecurity/sdkESM / TypeScript
import { SocketSdk } from '@socketsecurity/sdk'
const client = new SocketSdk('yourApiKeyHere')
const res = await client.getQuota()
if (res.success) {
// Will output { quota: 123 } if the quota you have left is 123
console.log(res.data)
}CommonJS
const { SocketSdk } = require('@socketsecurity/sdk')SocketSdk Methods
Package methods
getIssuesByNPMPackage(packageName, version)packageName: Astringrepresenting the name of the npm package you want the issues forversion: Astringrepresenting the version of the npm package to return the issues for
getScoreByNPMPackage(packageName, version)packageName: Astringrepresenting the name of the npm package you want the score forversion: Astringrepresenting the version of the npm package to return the score for
Report methods
createReportFromFilepaths(filePaths, pathsRelativeTo=., [issueRules])filePaths: Anarrayof absolute or relativestringpaths topackage.jsonand any correspondingpackage-lock.jsonfilespathsRelativeTo: Astringpath that the absolute pathsfilePathsare relative to. This to calculate where in your project thepackage.json/package-lock.jsonfiles livesissueRules: An object that follows the format of thesocket.ymlissue rules. Keys being issue names, values being a boolean that activates or deactivates it. Is applied on top of default config and organization config.
getReportList()getReportSupportedFiles()getReport(id)id: Astringrepresenting the id of a created report
Utility methods
getQuota()getOrganizations()postSettings(selectors)selectors: An array of settings selectors, e.g.[{ organization: 'id' }]
getOrgSecurityPolicy(orgSlug)orgSlug: the slug of the organization
Additional exports
createUserAgentFromPkgJson(pkgJson)pkgJson: The content of thepackage.jsonyou want to create aUser-Agentstring for
Advanced
Specifying custom user agent
The SocketSdk constructor accepts an options object as its second argument and there a userAgent key with a string value can be specified. If specified then that user agent will be prepended to the SDK user agent. See this example:
const client = new SocketSdk('yourApiKeyHere', {
userAgent: 'example/1.2.3 (http://example.com/)'
})Which results in the HTTP User-Agent header:
User-Agent: example/1.2.3 (http://example.com/) socketsecurity-sdk/0.5.2 (https://github.com/SocketDev/socket-sdk-js)To easily create a user agent for your code you can use the additional export createUserAgentFromPkgJson() like this, assuming pkgJson contains your parsed package.json:
const client = new SocketSdk('yourApiKeyHere', {
userAgent: createUserAgentFromPkgJson(pkgJson)
})Specifying a custom user agent is good practice when shipping a piece of code that others can use to make requests. Eg. our CLI uses this option to identify requests coming from it + mentioning which version of it that is used.
See also
8 months ago
10 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago