
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
libnpmhook
Advanced tools
libnpmhook is a Node.js library for
programmatically managing the npm registry's server-side hooks.
For a more general introduction to managing hooks, see the introductory blog post.
const hooks = require('libnpmhook')
console.log(await hooks.ls('mypkg', {token: 'deadbeef'}))
// array of hook objects on `mypkg`.
$ npm install libnpmhook
opts for libnpmhook commandslibnpmhook uses npm-registry-fetch.
All options are passed through directly to that library, so please refer to its
own opts
documentation
for options that can be passed in.
A couple of options of note for those in a hurry:
opts.token - can be passed in and will be used as the authentication token for the registry. For other ways to pass in auth details, see the n-r-f docs.opts.otp - certain operations will require an OTP token to be passed in. If a libnpmhook command fails with err.code === EOTP, please retry the request with {otp: <2fa token>}> hooks.add(name, endpoint, secret, [opts]) -> Promisename is the name of the package, org, or user/org scope to watch. The type is
determined by the name syntax: '@foo/bar' and 'foo' are treated as packages,
@foo is treated as a scope, and ~user is treated as an org name or scope.
Each type will attach to different events.
The endpoint should be a fully-qualified http URL for the endpoint the hook
will send its payload to when it fires. secret is a shared secret that the
hook will send to that endpoint to verify that it's actually coming from the
registry hook.
The returned Promise resolves to the full hook object that was created,
including its generated id.
See also: POST /v1/hooks/hook
await hooks.add('~zkat', 'https://example.com/api/added', 'supersekrit', {
token: 'myregistrytoken',
otp: '694207'
})
=>
{ id: '16f7xoal',
username: 'zkat',
name: 'zkat',
endpoint: 'https://example.com/api/added',
secret: 'supersekrit',
type: 'owner',
created: '2018-08-21T20:05:25.125Z',
updated: '2018-08-21T20:05:25.125Z',
deleted: false,
delivered: false,
last_delivery: null,
response_code: 0,
status: 'active' }
> hooks.find(id, [opts]) -> PromiseReturns the hook identified by id.
The returned Promise resolves to the full hook object that was found, or error
with err.code of 'E404' if it didn't exist.
See also: GET /v1/hooks/hook/:id
await hooks.find('16f7xoal', {token: 'myregistrytoken'})
=>
{ id: '16f7xoal',
username: 'zkat',
name: 'zkat',
endpoint: 'https://example.com/api/added',
secret: 'supersekrit',
type: 'owner',
created: '2018-08-21T20:05:25.125Z',
updated: '2018-08-21T20:05:25.125Z',
deleted: false,
delivered: false,
last_delivery: null,
response_code: 0,
status: 'active' }
> hooks.rm(id, [opts]) -> PromiseRemoves the hook identified by id.
The returned Promise resolves to the full hook object that was removed, if it
existed, or null if no such hook was there (instead of erroring).
See also: DELETE /v1/hooks/hook/:id
await hooks.rm('16f7xoal', {
token: 'myregistrytoken',
otp: '694207'
})
=>
{ id: '16f7xoal',
username: 'zkat',
name: 'zkat',
endpoint: 'https://example.com/api/added',
secret: 'supersekrit',
type: 'owner',
created: '2018-08-21T20:05:25.125Z',
updated: '2018-08-21T20:05:25.125Z',
deleted: true,
delivered: false,
last_delivery: null,
response_code: 0,
status: 'active' }
// Repeat it...
await hooks.rm('16f7xoal', {
token: 'myregistrytoken',
otp: '694207'
})
=> null
> hooks.update(id, endpoint, secret, [opts]) -> PromiseThe id should be a hook ID from a previously-created hook.
The endpoint should be a fully-qualified http URL for the endpoint the hook
will send its payload to when it fires. secret is a shared secret that the
hook will send to that endpoint to verify that it's actually coming from the
registry hook.
The returned Promise resolves to the full hook object that was updated, if it
existed. Otherwise, it will error with an 'E404' error code.
See also: PUT /v1/hooks/hook/:id
await hooks.update('16fxoal', 'https://example.com/api/other', 'newsekrit', {
token: 'myregistrytoken',
otp: '694207'
})
=>
{ id: '16f7xoal',
username: 'zkat',
name: 'zkat',
endpoint: 'https://example.com/api/other',
secret: 'newsekrit',
type: 'owner',
created: '2018-08-21T20:05:25.125Z',
updated: '2018-08-21T20:14:41.964Z',
deleted: false,
delivered: false,
last_delivery: null,
response_code: 0,
status: 'active' }
> hooks.ls([opts]) -> PromiseResolves to an array of hook objects associated with the account you're authenticated as.
Results can be further filtered with three values that can be passed in through
opts:
opts.package - filter results by package nameopts.limit - maximum number of hooks to returnopts.offset - pagination offset for results (use with opts.limit)See also:
await hooks.ls({token: 'myregistrytoken'})
=>
[
{ id: '16f7xoal', ... },
{ id: 'wnyf98a1', ... },
...
]
> hooks.ls.stream([opts]) -> StreamReturns a stream of hook objects associated with the account you're
authenticated as. The returned stream is a valid Symbol.asyncIterator on
node@>=10.
Results can be further filtered with three values that can be passed in through
opts:
opts.package - filter results by package nameopts.limit - maximum number of hooks to returnopts.offset - pagination offset for results (use with opts.limit)See also:
for await (let hook of hooks.ls.stream({token: 'myregistrytoken'})) {
console.log('found hook:', hook.id)
}
=>
// outputs:
// found hook: 16f7xoal
// found hook: wnyf98a1
11.0.0 (2024-12-16)
5319e48 #7973 remove unnecessary sprintf-js files in node_modules (#7973)d369c77 #7976 socks-proxy-agent@8.0.53b2951a #7976 https-proxy-agent@7.0.6a598b7b #7976 agent-base@7.1.352bcaf6 #7976 debug@4.4.0aabf345 #7976 p-map@7.0.328e8761 #7976 npm-package-arg@12.0.1ecd7190 #7976 dev dependency updates (@wraithgar)a07f4e0 #7976 @npmcli/template-oss@4.23.6 (@wraithgar)687ab12 #7970 remove pre-release mode from npm 11 and workspaces (#7970) (@wraithgar)@npmcli/arborist@9.0.0@npmcli/config@10.0.0libnpmaccess@10.0.0libnpmdiff@8.0.0libnpmexec@10.0.0libnpmfund@7.0.0libnpmorg@8.0.0libnpmpack@9.0.0libnpmpublish@11.0.0libnpmsearch@9.0.0libnpmteam@8.0.0libnpmversion@8.0.0Octokit is a library for interacting with GitHub's REST API. While it is not specifically for npm hooks, it provides similar functionality for managing webhooks in GitHub repositories. It offers a broader range of features for GitHub integration compared to libnpmhook, which is focused solely on npm hooks.
Node-GitHub is another library for interacting with GitHub's API. It allows you to manage webhooks, issues, repositories, and more. Similar to Octokit, it provides webhook management but is not limited to npm packages, offering a wider scope of GitHub-related functionalities.
Webhooks.js is a lightweight library for creating and managing webhooks. It is not specific to npm or GitHub but can be used to handle webhooks for various services. It provides a more general approach to webhook management compared to the specialized npm hook management offered by libnpmhook.
FAQs
programmatic API for managing npm registry hooks
The npm package libnpmhook receives a total of 745,465 weekly downloads. As such, libnpmhook popularity was classified as popular.
We found that libnpmhook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.