smee-client
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -17,11 +17,10 @@ #!/usr/bin/env node | ||
let target | ||
if (program.target) { | ||
target = program.target | ||
} else { | ||
target = `http://127.0.0.1:${program.port}${program.path}` | ||
} | ||
const opts = program.opts() | ||
const { | ||
target = `http://127.0.0.1:${opts.port}${opts.path}` | ||
} = opts | ||
async function setup () { | ||
let source = program.url | ||
let source = opts.url | ||
@@ -28,0 +27,0 @@ if (!source) { |
@@ -1,3 +0,3 @@ | ||
import EventSource from 'eventsource'; | ||
declare type Severity = 'info' | 'error'; | ||
import EventSource from "eventsource"; | ||
type Severity = "info" | "error"; | ||
interface Options { | ||
@@ -7,2 +7,3 @@ source: string; | ||
logger?: Pick<Console, Severity>; | ||
fetch?: any; | ||
} | ||
@@ -12,7 +13,10 @@ declare class Client { | ||
target: string; | ||
fetch: typeof global.fetch; | ||
logger: Pick<Console, Severity>; | ||
events: EventSource; | ||
constructor({ source, target, logger }: Options); | ||
static createChannel(): Promise<any>; | ||
onmessage(msg: any): void; | ||
constructor({ source, target, logger, fetch, }: Options); | ||
static createChannel({ fetch }?: { | ||
fetch?: typeof globalThis.fetch | undefined; | ||
}): Promise<string>; | ||
onmessage(msg: any): Promise<void>; | ||
onopen(): void; | ||
@@ -19,0 +23,0 @@ onerror(err: any): void; |
60
index.js
@@ -7,41 +7,54 @@ "use strict"; | ||
const eventsource_1 = __importDefault(require("eventsource")); | ||
const superagent_1 = __importDefault(require("superagent")); | ||
const url_1 = __importDefault(require("url")); | ||
const querystring_1 = __importDefault(require("querystring")); | ||
class Client { | ||
constructor({ source, target, logger = console }) { | ||
constructor({ source, target, logger = console, fetch = global.fetch, }) { | ||
this.source = source; | ||
this.target = target; | ||
this.logger = logger; | ||
this.fetch = fetch; | ||
if (!validator_1.default.isURL(this.source)) { | ||
throw new Error('The provided URL is invalid.'); | ||
throw new Error("The provided URL is invalid."); | ||
} | ||
} | ||
static async createChannel() { | ||
return superagent_1.default.head('https://smee.io/new').redirects(0).catch((err) => { | ||
return err.response.headers.location; | ||
static async createChannel({ fetch = global.fetch } = {}) { | ||
const response = await fetch("https://smee.io/new", { | ||
method: "HEAD", | ||
redirect: "manual", | ||
}); | ||
const address = response.headers.get("location"); | ||
if (!address) { | ||
throw new Error("Failed to create channel"); | ||
} | ||
return address; | ||
} | ||
onmessage(msg) { | ||
async onmessage(msg) { | ||
const data = JSON.parse(msg.data); | ||
const target = url_1.default.parse(this.target, true); | ||
const mergedQuery = Object.assign(target.query, data.query); | ||
const mergedQuery = { ...target.query, ...data.query }; | ||
target.search = querystring_1.default.stringify(mergedQuery); | ||
delete data.query; | ||
const req = superagent_1.default.post(url_1.default.format(target)).send(data.body); | ||
const body = JSON.stringify(data.body); | ||
delete data.body; | ||
Object.keys(data).forEach(key => { | ||
req.set(key, data[key]); | ||
const headers = {}; | ||
Object.keys(data).forEach((key) => { | ||
headers[key] = data[key]; | ||
}); | ||
req.end((err, res) => { | ||
if (err) { | ||
this.logger.error(err); | ||
} | ||
else { | ||
this.logger.info(`${req.method} ${req.url} - ${res.status}`); | ||
} | ||
}); | ||
headers["content-length"] = Buffer.byteLength(body); | ||
try { | ||
const response = await this.fetch(url_1.default.format(target), { | ||
method: "POST", | ||
mode: data["sec-fetch-mode"], | ||
cache: "default", | ||
body, | ||
headers, | ||
}); | ||
this.logger.info(`POST ${response.url} - ${response.status}`); | ||
} | ||
catch (err) { | ||
this.logger.error(err); | ||
} | ||
} | ||
onopen() { | ||
this.logger.info('Connected', this.events.url); | ||
this.logger.info("Connected", this.events.url); | ||
} | ||
@@ -55,5 +68,5 @@ onerror(err) { | ||
events.reconnectInterval = 0; // This isn't a valid property of EventSource | ||
events.addEventListener('message', this.onmessage.bind(this)); | ||
events.addEventListener('open', this.onopen.bind(this)); | ||
events.addEventListener('error', this.onerror.bind(this)); | ||
events.addEventListener("message", this.onmessage.bind(this)); | ||
events.addEventListener("open", this.onopen.bind(this)); | ||
events.addEventListener("error", this.onerror.bind(this)); | ||
this.logger.info(`Forwarding ${this.source} to ${this.target}`); | ||
@@ -65,1 +78,2 @@ this.events = events; | ||
module.exports = Client; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "smee-client", | ||
"version": "1.2.3", | ||
"description": "Client to proxy webhooks to local host", | ||
"version": "1.2.4", | ||
"description": "Client to proxy webhooks to localhost", | ||
"main": "index.js", | ||
@@ -12,8 +12,11 @@ "bin": { | ||
"index.d.ts", | ||
"bin", | ||
"lib" | ||
"bin" | ||
], | ||
"scripts": { | ||
"test": "jest --coverage && standard", | ||
"build": "tsc -p tsconfig.json" | ||
"build": "tsc -p tsconfig.json", | ||
"lint": "prettier --check \"index.ts\" \"test/**/*.ts\" package.json tsconfig.json --end-of-line auto", | ||
"lint:fix": "prettier --write \"index.ts\" \"test/**/*.ts\" package.json tsconfig.json --end-of-line auto", | ||
"test": "vitest run", | ||
"test:coverage": "vitest run --coverage", | ||
"test:dev": "vitest --ui --coverage" | ||
}, | ||
@@ -24,33 +27,16 @@ "repository": "github:probot/smee-client", | ||
"dependencies": { | ||
"commander": "^2.19.0", | ||
"eventsource": "^1.1.0", | ||
"morgan": "^1.9.1", | ||
"superagent": "^7.1.3", | ||
"validator": "^13.7.0" | ||
"commander": "^11.1.0", | ||
"eventsource": "^2.0.2", | ||
"validator": "^13.11.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.4.0", | ||
"@types/eventsource": "^1.1.8", | ||
"@types/jest": "^24.0.11", | ||
"@types/nock": "^9.3.1", | ||
"@types/superagent": "^4.1.15", | ||
"@types/validator": "^10.11.0", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^24.5.0", | ||
"connect-sse": "^1.2.0", | ||
"jest": "^24.5.0", | ||
"nock": "^10.0.6", | ||
"standard": "^12.0.1", | ||
"supertest": "^4.0.2", | ||
"ts-jest": "^24.0.1", | ||
"typescript": "^3.4.1" | ||
}, | ||
"standard": { | ||
"env": [ | ||
"jest" | ||
] | ||
}, | ||
"jest": { | ||
"preset": "ts-jest" | ||
"@octokit/tsconfig": "^2.0.0", | ||
"@types/eventsource": "^1.1.15", | ||
"@types/validator": "^13.11.6", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"fastify": "^4.24.3", | ||
"prettier": "^3.1.0", | ||
"typescript": "^5.0.0", | ||
"vitest": "^0.34.6" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7514
3
8
124
37382
3
+ Addedcommander@11.1.0(transitive)
+ Addedeventsource@2.0.2(transitive)
- Removedmorgan@^1.9.1
- Removedsuperagent@^7.1.3
- Removedasap@2.0.6(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedbasic-auth@2.0.1(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcookiejar@2.1.4(transitive)
- Removeddebug@2.6.94.3.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddezalgo@1.0.4(transitive)
- Removedee-first@1.1.1(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedeventsource@1.1.2(transitive)
- Removedfast-safe-stringify@2.1.1(transitive)
- Removedform-data@4.0.1(transitive)
- Removedformidable@2.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhexoid@1.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@2.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedmorgan@1.10.0(transitive)
- Removedms@2.0.02.1.3(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedon-finished@2.3.0(transitive)
- Removedon-headers@1.0.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedqs@6.13.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedsemver@7.6.3(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedsuperagent@7.1.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedcommander@^11.1.0
Updatedeventsource@^2.0.2
Updatedvalidator@^13.11.0