"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x64/node_modules/npm/node_modules/libnpmhook/README.md" (14 Feb 2020, 8168 Bytes) of package /windows/www/node-v12.18.4-win-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

libnpmhook npm version license Travis AppVeyor Coverage Status

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.

Example

const hooks = require('libnpmhook')

console.log(await hooks.ls('mypkg', {token: 'deadbeef'}))
// array of hook objects on `mypkg`.

Install

$ npm install libnpmhook

Table of Contents

API

opts for libnpmhook commands

libnpmhook 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:

> hooks.add(name, endpoint, secret, [opts]) -> Promise

name 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

Example
await hooks.add('~zkat', 'https://zkat.tech/api/added', 'supersekrit', {
  token: 'myregistrytoken',
  otp: '694207'
})

=>

{ id: '16f7xoal',
  username: 'zkat',
  name: 'zkat',
  endpoint: 'https://zkat.tech/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]) -> Promise

Returns 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

Example
await hooks.find('16f7xoal', {token: 'myregistrytoken'})

=>

{ id: '16f7xoal',
  username: 'zkat',
  name: 'zkat',
  endpoint: 'https://zkat.tech/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]) -> Promise

Removes 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

Example
await hooks.rm('16f7xoal', {
  token: 'myregistrytoken',
  otp: '694207'
})

=>

{ id: '16f7xoal',
  username: 'zkat',
  name: 'zkat',
  endpoint: 'https://zkat.tech/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]) -> Promise

The 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

Example
await hooks.update('16fxoal', 'https://zkat.tech/api/other', 'newsekrit', {
  token: 'myregistrytoken',
  otp: '694207'
})

=>

{ id: '16f7xoal',
  username: 'zkat',
  name: 'zkat',
  endpoint: 'https://zkat.tech/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]) -> Promise

Resolves 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:

See also: * hooks.ls.stream() * GET /v1/hooks

Example
await hooks.ls({token: 'myregistrytoken'})

=>
[
  { id: '16f7xoal', ... },
  { id: 'wnyf98a1', ... },
  ...
]

> hooks.ls.stream([opts]) -> Stream

Returns 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:

See also: * hooks.ls() * GET /v1/hooks

Example
for await (let hook of hooks.ls.stream({token: 'myregistrytoken'})) {
  console.log('found hook:', hook.id)
}

=>
// outputs:
// found hook: 16f7xoal
// found hook: wnyf98a1