Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smee-client

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smee-client - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

18

bin/smee.js
#!/usr/bin/env node
const program = require('commander')
const Client = require('..')

@@ -8,3 +9,3 @@

.usage('[options]')
.option('-u, --url <url>', 'URL of the webhook proxy service', 'https://smee.io/new')
.option('-u, --url <url>', 'URL of the webhook proxy service. Default: https://smee.io/new')
.option('-p, --port <n>', 'Local HTTP server port', process.env.PORT || 3000)

@@ -14,6 +15,15 @@ .option('-P, --path <path>', 'URL path to post proxied requests to`', '/')

const source = program.url
const target = `http://127.0.0.1:${program.port}${program.path}`
const client = new Client({source, target})
client.start()
async function setup () {
let source = program.url
if (!source) {
source = await Client.createChannel()
}
const client = new Client({source, target})
client.start()
}
setup()

@@ -1,3 +0,1 @@

{"/Users/bkeepers/projects/probot/webhooks/client/lib/channel.js": {"path":"/Users/bkeepers/projects/probot/webhooks/client/lib/channel.js","statementMap":{"0":{"start":{"line":1,"column":20},"end":{"line":1,"column":42}},"1":{"start":{"line":2,"column":19},"end":{"line":2,"column":40}},"2":{"start":{"line":4,"column":0},"end":{"line":55,"column":1}},"3":{"start":{"line":6,"column":4},"end":{"line":6,"column":24}},"4":{"start":{"line":7,"column":4},"end":{"line":7,"column":24}},"5":{"start":{"line":8,"column":4},"end":{"line":8,"column":24}},"6":{"start":{"line":12,"column":17},"end":{"line":12,"column":37}},"7":{"start":{"line":14,"column":16},"end":{"line":14,"column":60}},"8":{"start":{"line":16,"column":4},"end":{"line":16,"column":20}},"9":{"start":{"line":18,"column":4},"end":{"line":20,"column":6}},"10":{"start":{"line":19,"column":6},"end":{"line":19,"column":29}},"11":{"start":{"line":22,"column":4},"end":{"line":28,"column":6}},"12":{"start":{"line":23,"column":6},"end":{"line":27,"column":7}},"13":{"start":{"line":24,"column":8},"end":{"line":24,"column":30}},"14":{"start":{"line":26,"column":8},"end":{"line":26,"column":72}},"15":{"start":{"line":32,"column":4},"end":{"line":32,"column":50}},"16":{"start":{"line":36,"column":4},"end":{"line":36,"column":26}},"17":{"start":{"line":40,"column":19},"end":{"line":40,"column":47}},"18":{"start":{"line":43,"column":4},"end":{"line":43,"column":32}},"19":{"start":{"line":45,"column":4},"end":{"line":45,"column":65}},"20":{"start":{"line":46,"column":4},"end":{"line":46,"column":59}},"21":{"start":{"line":47,"column":4},"end":{"line":47,"column":61}},"22":{"start":{"line":49,"column":4},"end":{"line":49,"column":79}},"23":{"start":{"line":51,"column":4},"end":{"line":51,"column":24}},"24":{"start":{"line":53,"column":4},"end":{"line":53,"column":17}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":5,"column":2},"end":{"line":5,"column":3}},"loc":{"start":{"line":5,"column":51},"end":{"line":9,"column":3}},"line":5},"1":{"name":"(anonymous_1)","decl":{"start":{"line":11,"column":2},"end":{"line":11,"column":3}},"loc":{"start":{"line":11,"column":18},"end":{"line":29,"column":3}},"line":11},"2":{"name":"(anonymous_2)","decl":{"start":{"line":18,"column":30},"end":{"line":18,"column":31}},"loc":{"start":{"line":18,"column":37},"end":{"line":20,"column":5}},"line":18},"3":{"name":"(anonymous_3)","decl":{"start":{"line":22,"column":12},"end":{"line":22,"column":13}},"loc":{"start":{"line":22,"column":26},"end":{"line":28,"column":5}},"line":22},"4":{"name":"(anonymous_4)","decl":{"start":{"line":31,"column":2},"end":{"line":31,"column":3}},"loc":{"start":{"line":31,"column":12},"end":{"line":33,"column":3}},"line":31},"5":{"name":"(anonymous_5)","decl":{"start":{"line":35,"column":2},"end":{"line":35,"column":3}},"loc":{"start":{"line":35,"column":16},"end":{"line":37,"column":3}},"line":35},"6":{"name":"(anonymous_6)","decl":{"start":{"line":39,"column":2},"end":{"line":39,"column":3}},"loc":{"start":{"line":39,"column":11},"end":{"line":54,"column":3}},"line":39}},"branchMap":{"0":{"loc":{"start":{"line":5,"column":32},"end":{"line":5,"column":48}},"type":"default-arg","locations":[{"start":{"line":5,"column":41},"end":{"line":5,"column":48}}],"line":5},"1":{"loc":{"start":{"line":23,"column":6},"end":{"line":27,"column":7}},"type":"if","locations":[{"start":{"line":23,"column":6},"end":{"line":27,"column":7}},{"start":{"line":23,"column":6},"end":{"line":27,"column":7}}],"line":23}},"s":{"0":2,"1":2,"2":2,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":7,"11":1,"12":1,"13":0,"14":1,"15":1,"16":0,"17":1,"18":1,"19":1,"20":1,"21":1,"22":1,"23":1,"24":1},"f":{"0":1,"1":1,"2":7,"3":1,"4":1,"5":0,"6":1},"b":{"0":[0],"1":[0,1]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"8cf741b2ab4a58a1c0501103deec7d317bb1f926"}
,"/Users/bkeepers/projects/probot/webhooks/client/lib/config.js": {"path":"/Users/bkeepers/projects/probot/webhooks/client/lib/config.js","statementMap":{"0":{"start":{"line":1,"column":16},"end":{"line":1,"column":36}},"1":{"start":{"line":5,"column":4},"end":{"line":5,"column":26}},"2":{"start":{"line":6,"column":4},"end":{"line":6,"column":22}},"3":{"start":{"line":8,"column":4},"end":{"line":13,"column":6}},"4":{"start":{"line":9,"column":6},"end":{"line":12,"column":9}},"5":{"start":{"line":17,"column":4},"end":{"line":17,"column":49}},"6":{"start":{"line":21,"column":0},"end":{"line":24,"column":1}},"7":{"start":{"line":22,"column":17},"end":{"line":22,"column":34}},"8":{"start":{"line":23,"column":2},"end":{"line":23,"column":64}},"9":{"start":{"line":26,"column":0},"end":{"line":26,"column":23}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":4,"column":2},"end":{"line":4,"column":3}},"loc":{"start":{"line":4,"column":29},"end":{"line":14,"column":3}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":8,"column":48},"end":{"line":8,"column":49}},"loc":{"start":{"line":8,"column":59},"end":{"line":13,"column":5}},"line":8},"2":{"name":"(anonymous_2)","decl":{"start":{"line":16,"column":2},"end":{"line":16,"column":3}},"loc":{"start":{"line":16,"column":14},"end":{"line":18,"column":3}},"line":16},"3":{"name":"(anonymous_3)","decl":{"start":{"line":21,"column":14},"end":{"line":21,"column":15}},"loc":{"start":{"line":21,"column":33},"end":{"line":24,"column":1}},"line":21}},"branchMap":{"0":{"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":27}},"type":"default-arg","locations":[{"start":{"line":4,"column":25},"end":{"line":4,"column":27}}],"line":4},"1":{"loc":{"start":{"line":8,"column":16},"end":{"line":8,"column":38}},"type":"binary-expr","locations":[{"start":{"line":8,"column":16},"end":{"line":8,"column":32}},{"start":{"line":8,"column":36},"end":{"line":8,"column":38}}],"line":8},"2":{"loc":{"start":{"line":17,"column":11},"end":{"line":17,"column":49}},"type":"binary-expr","locations":[{"start":{"line":17,"column":11},"end":{"line":17,"column":28}},{"start":{"line":17,"column":32},"end":{"line":17,"column":49}}],"line":17},"3":{"loc":{"start":{"line":21,"column":15},"end":{"line":21,"column":28}},"type":"default-arg","locations":[{"start":{"line":21,"column":26},"end":{"line":21,"column":28}}],"line":21}},"s":{"0":1,"1":5,"2":5,"3":5,"4":0,"5":5,"6":1,"7":3,"8":3,"9":1},"f":{"0":5,"1":0,"2":5,"3":3},"b":{"0":[1],"1":[5,5],"2":[5,1],"3":[3]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"8a70c24aea1b235ff7aded735d29852d5a52720f"}
}
{}
const EventSource = require('eventsource')
const superagent = require('superagent')
module.exports = class Client {
class Client {
constructor ({source, target, logger = console}) {

@@ -49,3 +49,3 @@ this.source = source

this.logger.info(`Proxying requests from ${this.source} to ${this.target}`)
this.logger.info(`Forwarding ${this.source} to ${this.target}`)

@@ -57,1 +57,9 @@ this.events = events

}
Client.createChannel = async () => {
return superagent.head('https://smee.io/new').redirects(0).catch((err, res) => {
return err.response.headers.location
})
}
module.exports = Client
{
"name": "smee-client",
"version": "1.0.0",
"version": "1.0.1",
"description": "Client to proxy webhooks to local host",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,11 +0,11 @@

# smee-cli
# smee-client
Command-line client for smee.io, a service that delivers webhooks to your local development environment.
Client and CLI for smee.io, a service that delivers webhooks to your local development environment.
## Installation
Install the `smee` command line client with:
Install the client with:
```
$ npm install -g smee-cli
$ npm install -g smee-client
```

@@ -15,2 +15,4 @@

### CLI
The `smee` command will forward webhooks from smee.io to your local development environment.

@@ -24,2 +26,18 @@

- `smee -u`
### Node Client
```js
const SmeeClient = require('smee-client')
const smee = new SmeeClient({
source: 'https://smee.io/abc123',
target: 'http://localhost:3000/events',
logger: console
})
const events = smee.start()
// Stop forwarding events
events.close()
```

@@ -15,17 +15,10 @@ const createServer = require('../..')

describe('client', () => {
let proxyApp, proxyServer, sourceUrl, events
let proxy, host, client, channel
const targetUrl = 'http://example.com/foo/bar'
const channel = '/fake-channel'
beforeEach((done) => {
proxyApp = createServer()
proxyServer = proxyApp.listen(0, () => {
sourceUrl = `http://127.0.0.1:${proxyServer.address().port}${channel}`
const client = new Client({source: sourceUrl, target: targetUrl, logger})
events = client.start()
// Wait for event source to be ready
events.addEventListener('ready', () => done())
proxy = createServer().listen(0, () => {
host = `http://127.0.0.1:${proxy.address().port}`
done()
})

@@ -35,21 +28,46 @@ })

afterEach(() => {
proxyServer && proxyServer.close()
events && events.close()
proxy && proxy.close()
client && client.close()
})
it('POST /:channel forwards to target url', async (done) => {
const payload = {payload: true}
describe('connecting to a channel', () => {
beforeEach((done) => {
channel = '/fake-channel'
client = new Client({
source: `${host}${channel}`,
target: targetUrl,
logger
}).start()
// Wait for event source to be ready
client.addEventListener('ready', () => done())
})
// Expect request to target
const forward = nock('http://example.com').post('/foo/bar', payload).reply(200)
test('POST /:channel forwards to target url', async (done) => {
const payload = {payload: true}
// Test is done when this is called
events.addEventListener('message', (msg) => {
expect(forward.isDone()).toBe(true)
done()
// Expect request to target
const forward = nock('http://example.com').post('/foo/bar', payload).reply(200)
// Test is done when this is called
client.addEventListener('message', (msg) => {
expect(forward.isDone()).toBe(true)
done()
})
// Send request to proxy server
await request(proxy).post(channel).send(payload).expect(200)
})
})
// Send request to proxy server
await request(proxyServer).post(channel).send(payload).expect(200)
describe('createChannel', () => {
test('returns a new channel', async () => {
const req = nock('https://smee.io').head('/new').reply(302, '', {
Location: 'https://smee.io/abc123'
})
const channel = await Client.createChannel()
expect(channel).toEqual('https://smee.io/abc123')
expect(req.isDone()).toBe(true)
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc