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

@guildedts/ws

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

@guildedts/ws - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

25

CHANGELOG.md
# @guildedts/ws
## 0.1.0
### Minor Changes
- Added support for message embeds and a few events.
## New events
- `memberAdd`
- `memberRemove`
- `memberBan`
- `memberUnban`
- `memberEdit`
- `serverRolesEdit`
## Features
- Message embeds
## Fixes
- Completed `fetch` function that have been left uncomnplete.
> **Note:** There have been a few other changes regarding managing imports and more.
## 0.0.2

@@ -4,0 +29,0 @@

58

lib/index.js

@@ -1,39 +0,21 @@

'use strict';
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = {
enumerable: true,
get: function () {
return m[k];
},
};
}
Object.defineProperty(o, k2, desc);
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __exportStar =
(this && this.__exportStar) ||
function (m, exports) {
for (var p in m)
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
__createBinding(exports, m, p);
};
Object.defineProperty(exports, '__esModule', { value: true });
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = void 0;
var WebsocketManager_1 = require('./WebsocketManager');
Object.defineProperty(exports, 'default', {
enumerable: true,
get: function () {
return WebsocketManager_1.WebsocketManager;
},
});
__exportStar(require('./WebsocketManager'), exports);
//# sourceMappingURL=index.js.map
var WebsocketManager_1 = require("./WebsocketManager");
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return WebsocketManager_1.WebsocketManager; } });
__exportStar(require("./WebsocketManager"), exports);
//# sourceMappingURL=index.js.map

@@ -1,84 +0,83 @@

'use strict';
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, '__esModule', { value: true });
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebsocketManager = void 0;
const ws_1 = __importDefault(require('ws'));
const events_1 = __importDefault(require('events'));
const ws_1 = __importDefault(require("ws"));
const events_1 = __importDefault(require("events"));
/** The Websocket manager for the Guilded API. */
class WebsocketManager extends events_1.default {
version;
/** The authoization token for the websocket. */
token;
/** The websocket. */
socket;
/** Whether the websocket is connected. */
connected = false;
/** The time of when the websocket connected. */
connectedAt;
/** @param version The API version for the websocket. */
constructor(version) {
super();
this.version = version;
}
/** The timestamp of when the websocket connected. */
get connectedTimestamp() {
return this.connectedAt?.getTime();
}
/** How long the websocket has been connected. (in MS) */
get uptime() {
return this.connected ? Date.now() - this.connectedTimestamp : undefined;
}
/** The URL for the websocket. */
get url() {
return `wss://api.guilded.gg/v${this.version}/websocket`;
}
/**
* Connect to the websocket.
* @param token The authorization token.
* @returns The websocket manager.
*/
connect(token) {
this.token = token;
this.socket = new ws_1.default(this.url, {
headers: {
Authorization: `Bearer ${this.token}`,
},
});
this.socket.on('close', () => {
this.token = undefined;
this.socket = undefined;
this.connected = false;
this.connectedAt = undefined;
this.emit('disconnect');
});
this.socket.on('message', (data) => {
const { op, t, d } = JSON.parse(data.toString());
switch (op) {
case 0:
this.emit('data', t, d);
break;
case 1:
this.connected = true;
this.connectedAt = new Date();
this.emit('connect', d.user);
break;
}
});
return this;
}
/**
* Disconnect from the websocket.
* @returns The websocket manager.
*/
disconnect() {
if (!this.socket || !this.socket.OPEN) throw new Error('Websocket is not connected.');
this.socket.close();
return this;
}
version;
/** The authoization token for the websocket. */
token;
/** The websocket. */
socket;
/** Whether the websocket is connected. */
connected = false;
/** The time of when the websocket connected. */
connectedAt;
/** @param version The API version for the websocket. */
constructor(version) {
super();
this.version = version;
}
/** The timestamp of when the websocket connected. */
get connectedTimestamp() {
return this.connectedAt?.getTime();
}
/** How long the websocket has been connected. (in MS) */
get uptime() {
return this.connected ? Date.now() - this.connectedTimestamp : undefined;
}
/** The URL for the websocket. */
get url() {
return `wss://api.guilded.gg/v${this.version}/websocket`;
}
/**
* Connect to the websocket.
* @param token The authorization token.
* @returns The websocket manager.
*/
connect(token) {
this.token = token;
this.socket = new ws_1.default(this.url, {
headers: {
Authorization: `Bearer ${this.token}`,
},
});
this.socket.on('close', () => {
this.token = undefined;
this.socket = undefined;
this.connected = false;
this.connectedAt = undefined;
this.emit('disconnect');
});
this.socket.on('message', (data) => {
const { op, t, d } = JSON.parse(data.toString());
switch (op) {
case 0:
this.emit('data', t, d);
break;
case 1:
this.connected = true;
this.connectedAt = new Date();
this.emit('connect', d.user);
break;
}
});
return this;
}
/**
* Disconnect from the websocket.
* @returns The websocket manager.
*/
disconnect() {
if (!this.socket || !this.socket.OPEN)
throw new Error('Websocket is not connected.');
this.socket.close();
return this;
}
}
exports.WebsocketManager = WebsocketManager;
//# sourceMappingURL=WebsocketManager.js.map
//# sourceMappingURL=WebsocketManager.js.map
{
"name": "@guildedts/ws",
"version": "0.0.2",
"version": "0.1.0",
"description": "The Websocket API manager for Guilded.TS.",

@@ -23,3 +23,4 @@ "main": "lib/index.js",

"contributors": [
"Gamertike <contact@gamertike.com> (https://gamertike.com)"
"Gamertike <contact@gamertike.com> (https://gamertike.com)",
"Bruno Lepis (https://brunolepis.xyz)"
],

@@ -40,5 +41,5 @@ "repository": {

"devDependencies": {
"guilded-api-typings": "^0.0.1",
"guilded-api-typings": "^0.1.0",
"typescript": "^4.6.3"
}
}

@@ -15,5 +15,5 @@ <div align="center">

- [Github](https://github.com/GuildedTS/Guilded.TS)
- [NPM](https://www.npmjs.com/package/@guildedts/ws)
- [Guilded.TS Guilded Server](https://www.guilded.gg/GuildedTS)
- [GitHub](https://github.com/guildedts/guilded.ts)
- [NPM](https://www.npmjs.com/package/guilded.ts)
- [Guilded.TS Guilded Server](https://www.guilded.gg/guildedts)
- [Guilded API Guilded server](https://www.guilded.gg/API-Official)

@@ -32,5 +32,5 @@ - [Documentation](https://guildedts.js.org)

Contributing helps us maintain Guilded.TS. All contributes are greatly appreciated.
Contributing helps us maintain Guilded.TS. All contributions are greatly appreciated.
We utilize [Yarn](https://yarnpkg.com) and [Turbo](https://turborepo.org) to manage our Monorepo. If you want to contribute we highly recommend knowing the basics of thes two.
We utilize [Yarn](https://yarnpkg.com) and [Turbo](https://turborepo.org) to manage our Monorepo. If you want to contribute, we highly recommend knowing the basics of these two.

@@ -48,5 +48,5 @@ ## Getting started

## Commiting your changes
## Committing your changes
After you have made your desired changes, Make sure you run the following script before commiting your changes:
After you have made your desired changes, make sure you run the following script before committing your changes:

@@ -53,0 +53,0 @@ ```

export { WebsocketManager as default } from './WebsocketManager';
export * from './WebsocketManager';
//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map

@@ -7,73 +7,61 @@ /// <reference types="node" />

export declare class WebsocketManager extends EventEmitter {
readonly version: number;
/** The authoization token for the websocket. */
token?: string;
/** The websocket. */
socket?: Websocket;
/** Whether the websocket is connected. */
connected: boolean;
/** The time of when the websocket connected. */
connectedAt?: Date;
/** @param version The API version for the websocket. */
constructor(version: number);
/** The timestamp of when the websocket connected. */
get connectedTimestamp(): number | undefined;
/** How long the websocket has been connected. (in MS) */
get uptime(): number | undefined;
/** The URL for the websocket. */
get url(): `wss://api.guilded.gg/v${number}/websocket`;
/**
* Connect to the websocket.
* @param token The authorization token.
* @returns The websocket manager.
*/
connect(token: string): this;
/**
* Disconnect from the websocket.
* @returns The websocket manager.
*/
disconnect(): this;
readonly version: number;
/** The authoization token for the websocket. */
token?: string;
/** The websocket. */
socket?: Websocket;
/** Whether the websocket is connected. */
connected: boolean;
/** The time of when the websocket connected. */
connectedAt?: Date;
/** @param version The API version for the websocket. */
constructor(version: number);
/** The timestamp of when the websocket connected. */
get connectedTimestamp(): number | undefined;
/** How long the websocket has been connected. (in MS) */
get uptime(): number | undefined;
/** The URL for the websocket. */
get url(): `wss://api.guilded.gg/v${number}/websocket`;
/**
* Connect to the websocket.
* @param token The authorization token.
* @returns The websocket manager.
*/
connect(token: string): this;
/**
* Disconnect from the websocket.
* @returns The websocket manager.
*/
disconnect(): this;
}
export interface WebsocketManager {
/** @ignore */
on<Event extends keyof WSManagerEvents>(
event: Event,
listener: (...args: WSManagerEvents[Event]) => any,
): this;
/** @ignore */
once<Event extends keyof WSManagerEvents>(
event: Event,
listener: (...args: WSManagerEvents[Event]) => any,
): this;
/** @ignore */
off<Event extends keyof WSManagerEvents>(
event: Event,
listener: (...args: WSManagerEvents[Event]) => any,
): this;
/** @ignore */
emit<Event extends keyof WSManagerEvents>(
event: Event,
...args: WSManagerEvents[Event]
): boolean;
/** @ignore */
on<Event extends keyof WSManagerEvents>(event: Event, listener: (...args: WSManagerEvents[Event]) => any): this;
/** @ignore */
once<Event extends keyof WSManagerEvents>(event: Event, listener: (...args: WSManagerEvents[Event]) => any): this;
/** @ignore */
off<Event extends keyof WSManagerEvents>(event: Event, listener: (...args: WSManagerEvents[Event]) => any): this;
/** @ignore */
emit<Event extends keyof WSManagerEvents>(event: Event, ...args: WSManagerEvents[Event]): boolean;
}
/** The websocket manager events. */
export interface WSManagerEvents {
/** Emitted when the websocket is connected. */
connect: [user: APIUser];
/** Emitted when the websocket is disconnected. */
disconnect: [];
/** Emitted when data is received from the websocket. */
data: {
[K in keyof WSEvents]: [type: K, data: WSEvents[K]];
}[keyof WSEvents];
/** Emitted when the websocket is connected. */
connect: [user: APIUser];
/** Emitted when the websocket is disconnected. */
disconnect: [];
/** Emitted when data is received from the websocket. */
data: {
[K in keyof WSEvents]: [type: K, data: WSEvents[K]];
}[keyof WSEvents];
}
/** The websocket data. */
export interface WSData {
/** The operation code. */
op: number;
/** The event type. */
t: any;
/** The event data. */
d: any;
/** The operation code. */
op: number;
/** The event type. */
t: any;
/** The event data. */
d: any;
}
//# sourceMappingURL=WebsocketManager.d.ts.map
//# sourceMappingURL=WebsocketManager.d.ts.map
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