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

@relaybox/rest

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@relaybox/rest - npm Package Compare versions

Comparing version 0.1.0 to 1.0.1

LICENSE

38

dist/relaybox.d.ts
import { PublishResponseData, TokenResponse, TokenResponseParams } from './types/response.types';
import { RelayBoxOptions } from './types/config.types';
/**
* The RelayBox class provides methods to generate authentication tokens and publish events
* to a specified service using an API key.
*/
export declare class RelayBox {
private apiKeyParts;
private dsEventsServiceUrl;
/**
* Creates an instance of RelayBox.
* @param {RelayBoxOptions} options - The options for configuring the RelayBox instance.
* @throws {ValidationError} If the API key is not provided or is invalid.
*/
constructor({ apiKey }: RelayBoxOptions);
/**
* Generates a token response with a JWT based on the provided parameters.
* @param {TokenResponseParams} params - Parameters including clientId, expiry time, and permissions.
* @returns {TokenResponse} The generated token and its expiry time.
* @throws {ValidationError} If permissions are invalid.
*/
generateTokenResponse({ clientId, expiresIn, permissions }: TokenResponseParams): TokenResponse;
/**
* Publishes an event to a specified room or rooms with the given data.
* @param {string | string[]} roomId - The room ID or an array of room IDs.
* @param {string} event - The event name.
* @param {any} data - The data to be sent with the event.
* @returns {Promise<PublishResponseData>} The response data from the publish request.
* @throws {ValidationError} If required parameters are missing.
*/
publish(roomId: string | string[], event: string, data: any): Promise<PublishResponseData>;
/**
* Prepares the request parameters including the request body, HMAC signature, and public key.
* @private
* @param {string | string[]} roomId - The room ID or an array of room IDs.
* @param {string} event - The event name.
* @param {any} data - The data to be sent with the event.
* @returns {[string, string, string]} The request body, signature, and public key.
*/
private prepareRequestParams;
/**
* Splits the provided API key into its component parts.
* @private
* @param {string} apiKey - The API key in the format "appId.keyId:secretKey".
* @returns {[string, string]} The public key and secret key as a tuple.
* @throws {ValidationError} If the API key is not in the correct format.
*/
private getApiKeyParts;
}

40

dist/relaybox.js

@@ -17,7 +17,14 @@ "use strict";

const validation_1 = require("./validation");
// const DS_EVENTS_SERVICE_URL = `http://localhost:4004/dev`;
// const DS_EVENTS_SERVICE_URL = `https://events.dev.relaybox-services.net`;
const DS_EVENTS_SERVICE_URL = `https://events.prod.relaybox-services.net`;
const DEFAULT_TOKEN_EXPIRY_SECS = 900;
/**
* The RelayBox class provides methods to generate authentication tokens and publish events
* to a specified service using an API key.
*/
class RelayBox {
/**
* Creates an instance of RelayBox.
* @param {RelayBoxOptions} options - The options for configuring the RelayBox instance.
* @throws {ValidationError} If the API key is not provided or is invalid.
*/
constructor({ apiKey }) {

@@ -28,2 +35,8 @@ this.dsEventsServiceUrl = DS_EVENTS_SERVICE_URL;

}
/**
* Generates a token response with a JWT based on the provided parameters.
* @param {TokenResponseParams} params - Parameters including clientId, expiry time, and permissions.
* @returns {TokenResponse} The generated token and its expiry time.
* @throws {ValidationError} If permissions are invalid.
*/
generateTokenResponse({ clientId, expiresIn = DEFAULT_TOKEN_EXPIRY_SECS, permissions }) {

@@ -41,2 +54,10 @@ (0, validation_1.validatePermissions)(permissions);

}
/**
* Publishes an event to a specified room or rooms with the given data.
* @param {string | string[]} roomId - The room ID or an array of room IDs.
* @param {string} event - The event name.
* @param {any} data - The data to be sent with the event.
* @returns {Promise<PublishResponseData>} The response data from the publish request.
* @throws {ValidationError} If required parameters are missing.
*/
publish(roomId, event, data) {

@@ -58,2 +79,10 @@ return __awaiter(this, void 0, void 0, function* () {

}
/**
* Prepares the request parameters including the request body, HMAC signature, and public key.
* @private
* @param {string | string[]} roomId - The room ID or an array of room IDs.
* @param {string} event - The event name.
* @param {any} data - The data to be sent with the event.
* @returns {[string, string, string]} The request body, signature, and public key.
*/
prepareRequestParams(roomId, event, data) {

@@ -71,2 +100,9 @@ const timestamp = new Date().toISOString();

}
/**
* Splits the provided API key into its component parts.
* @private
* @param {string} apiKey - The API key in the format "appId.keyId:secretKey".
* @returns {[string, string]} The public key and secret key as a tuple.
* @throws {ValidationError} If the API key is not in the correct format.
*/
getApiKeyParts(apiKey) {

@@ -73,0 +109,0 @@ const parts = apiKey.split(':');

2

package.json
{
"name": "@relaybox/rest",
"version": "0.1.0",
"version": "1.0.1",
"description": "A robust and scalable realtime infrastructure service with comprehensive WebSocket support, designed to facilitate live updates, event-driven communication, and seamless data streaming. Ideal for building realtime applications such as chat, multiplayer games, collaboration tools, push notifications, and more. This library includes the server-side programming API, providing a high-performance, low-latency, and reliable framework for all your realtime needs. Supports Node.js, JavaScript, and TypeScript.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -229,1 +229,5 @@ # RelayBox REST SDK

```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
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