New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simple-helix-api

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-helix-api - npm Package Compare versions

Comparing version 3.1.3 to 3.2.0

3

dist/index.js

@@ -29,3 +29,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.EventSubEvent = void 0;
const analytics_1 = __importDefault(require("./lib/requests/analytics"));

@@ -56,4 +55,2 @@ const automod_1 = __importDefault(require("./lib/requests/automod"));

const static_1 = __importDefault(require("./lib/static"));
const event_1 = __importDefault(require("./lib/eventsub/event"));
exports.EventSubEvent = event_1.default;
class Helix extends static_1.default {

@@ -60,0 +57,0 @@ constructor(params) {

43

dist/lib/eventsub/websocket.js

@@ -18,3 +18,3 @@ "use strict";

};
this.subscribedEvents = [];
this.subscribedEvents = {};
this.events = new node_events_1.EventEmitter();

@@ -30,6 +30,3 @@ this.WebsocketEvents = {

}
connect(events) {
if (!events || events.length === 0 || !Array.isArray(events)) {
throw new Error(this.ERRORS.INVALID_EVENTS);
}
connect() {
return new Promise((resolve, reject) => {

@@ -53,3 +50,2 @@ this.client = new reconnecting_websocket_1.default(this.endpoint, [], {

this.onConnect(data);
this.registerEvents(events);
return resolve(this);

@@ -68,9 +64,2 @@ }

}
async registerEvents(events) {
this.subscribedEvents = events;
for (const event of events) {
await this.subscribe(event);
}
return true;
}
onConnect(data) {

@@ -82,32 +71,30 @@ this.transport.session_id = data.payload.session.id;

this.transport.session_id = 0;
this.subscribedEvents = [];
this.subscribedEvents = {};
this.events.emit(this.WebsocketEvents.DISCONNECTED, reason);
}
onMessage(data) {
switch (data.metadata.message_type) {
const messageType = data.metadata.message_type;
switch (messageType) {
case "notification": {
return this.events.emit(data.metadata.subscription_type, data.payload?.event);
const subscriptionType = data.metadata.subscription_type;
return this.subscribedEvents[subscriptionType]?.(data.payload?.event);
}
default: {
return this.events.emit(data.metadata.message_type, data.payload);
return this.subscribedEvents[messageType]?.(data.payload);
}
}
}
async subscribe(event) {
return await this.requestEndpoint("eventsub/subscriptions", "", {
async subscribe(type, condition, listener, version = 1) {
await this.requestEndpoint("eventsub/subscriptions", "", {
method: "POST",
data: {
type: event.type,
version: event.version || 1,
condition: event.condition,
type,
version,
condition,
transport: this.transport
}
});
this.subscribedEvents[type] = listener;
return true;
}
on(event, listener) {
return this.events.on(event, listener);
}
once(event, listener) {
return this.events.once(event, listener);
}
get connected() {

@@ -114,0 +101,0 @@ return Boolean(this.client?.OPEN);

{
"name": "simple-helix-api",
"version": "3.1.3",
"version": "3.2.0",
"description": "The Simple Helix API allows developers to easily develop applications for Twitch",

@@ -17,7 +17,7 @@ "main": "dist/index.js",

"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"dotenv": "^16.0.3",
"eslint": "^8.27.0",
"jest": "^29.2.2",
"jest": "^29.3.1",
"ts-jest": "^29.0.3",

@@ -24,0 +24,0 @@ "typescript": "^4.8.4"

@@ -129,3 +129,3 @@ # About

```javascript
const HelixAPI, { EventSubEvent } = require("simple-helix-api"); // you can use import
const HelixAPI = require("simple-helix-api"); // you can use import

@@ -152,8 +152,2 @@ // Init Helix instance

// List of events
const events = [
new EventSubEvent("channel.update", conditions[0]),
new EventSubEvent("channel.follow", conditions[0])
];
// Create EventSub client

@@ -163,4 +157,4 @@ const EventSubClient = await Helix.EventSub.connect(events);

// Register listeners for events
EventSubClient.on("channel.follow", data => {
console.log(`Thank you for following, ${data.user_name}`);
EventSubClient.subscribe("channel.follow", conditions[0], follow => {
console.log(`Thank you for following, ${follow.user_name}`);
});

@@ -167,0 +161,0 @@ ```

@@ -27,3 +27,2 @@ import { AxiosRequestHeaders } from "axios";

import Static from "./lib/static";
import EventSubEvent from "./lib/eventsub/event";
declare type HelixInitParams = {

@@ -67,2 +66,1 @@ client_id: string;

export default Helix;
export { EventSubEvent };

@@ -5,3 +5,2 @@ /// <reference types="node" />

import Websocket from "reconnecting-websocket";
import EventSubEvent from "./event";
import Static from "../static";

@@ -13,3 +12,3 @@ import { TEventType } from "./types/events";

client: Websocket;
subscribedEvents: EventSubEvent[];
subscribedEvents: Partial<Record<TEventType, (...args: any) => any>>;
readonly events: EventEmitter;

@@ -21,13 +20,10 @@ readonly WebsocketEvents: {

constructor(headers: AxiosRequestHeaders);
connect(events: EventSubEvent[]): Promise<EventSub>;
connect(): Promise<EventSub>;
disconnect(): void;
private registerEvents;
private onConnect;
private onDisconnect;
private onMessage;
subscribe(event: EventSubEvent): Promise<any>;
on(event: TEventType, listener: (...args: any) => void): EventEmitter;
once(event: TEventType, listener: (...args: any) => void): EventEmitter;
subscribe(type: TEventType, condition: Record<string, string>, listener: (...args: any) => any, version?: number): Promise<any>;
get connected(): boolean;
}
export default EventSub;
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