-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript migration #113
Typescript migration #113
Changes from 8 commits
7976676
13f9b8f
39d0497
4caaf78
64174e4
3a136b0
df81262
5d91128
00ac3ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ logs.json | |
server/public/main.min.* | ||
coverage | ||
.vscode | ||
index.js | ||
*.d.ts | ||
*.tsbuildinfo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
index.ts | ||
tsconfig.json | ||
tsconfig.tsbuildinfo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
const validator = require('validator') | ||
const EventSource = require('eventsource') | ||
const superagent = require('superagent') | ||
const url = require('url') | ||
const querystring = require('querystring') | ||
import validator = require('validator') | ||
import EventSource = require('eventsource') | ||
import superagent = require('superagent') | ||
import url = require('url') | ||
import querystring = require('querystring') | ||
|
||
class Client { | ||
constructor ({ source, target, logger = console }) { | ||
source: string; | ||
target: string; | ||
logger: Console; | ||
events!: EventSource; | ||
|
||
constructor ({ source, target, logger = console }: { source: string, target: string, logger?: Console }) { | ||
this.source = source | ||
this.target = target | ||
this.logger = logger | ||
|
@@ -15,7 +20,13 @@ class Client { | |
} | ||
} | ||
|
||
onmessage (msg) { | ||
static async createChannel () { | ||
return superagent.head('https://smee.io/new').redirects(0).catch((err) => { | ||
return err.response.headers.location | ||
}) | ||
} | ||
|
||
onmessage (msg: any) { | ||
const data = JSON.parse(msg.data) | ||
|
||
const target = url.parse(this.target, true) | ||
|
@@ -24,7 +35,7 @@ class Client { | |
|
||
delete data.query | ||
|
||
const req = superagent.post(target).send(data.body) | ||
const req = superagent.post(url.format(target)).send(data.body) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you recall why you did this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember exactly.
|
||
|
||
delete data.body | ||
|
||
|
@@ -36,7 +47,7 @@ class Client { | |
if (err) { | ||
this.logger.error(err) | ||
} else { | ||
this.logger.info(`${req.method} ${req.url} - ${res.statusCode}`) | ||
this.logger.info(`${req.method} ${req.url} - ${res.status}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you recall why you did this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above.
|
||
} | ||
}) | ||
} | ||
|
@@ -45,15 +56,15 @@ class Client { | |
this.logger.info('Connected', this.events.url) | ||
} | ||
|
||
onerror (err) { | ||
onerror (err: any) { | ||
this.logger.error(err) | ||
} | ||
|
||
start () { | ||
const events = new EventSource(this.source) | ||
const events = new EventSource(this.source); | ||
|
||
// Reconnect immediately | ||
events.reconnectInterval = 0 | ||
(events as any).reconnectInterval = 0 // This isn't a valid property of EventSource | ||
|
||
events.addEventListener('message', this.onmessage.bind(this)) | ||
events.addEventListener('open', this.onopen.bind(this)) | ||
|
@@ -66,10 +77,4 @@ class Client { | |
} | ||
} | ||
|
||
Client.createChannel = async () => { | ||
return superagent.head('https://smee.io/new').redirects(0).catch((err, res) => { | ||
return err.response.headers.location | ||
}) | ||
} | ||
|
||
module.exports = Client | ||
export = Client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In probot we are more precise about this type:
https://github.com/probot/probot/blob/589f891feb51d18660db6b06707d886486b7d975/src/%40types/smee-client/index.d.ts#L4-L10
Shall we do the same here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed. they should be updated to those ones