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

smee-client

Package Overview
Dependencies
Maintainers
5
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.2.3 to 1.2.4

13

bin/smee.js

@@ -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;

@@ -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"
}
}
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