@relaybox/rest
Advanced tools
Comparing version 0.1.0 to 1.0.1
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; | ||
} |
@@ -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(':'); |
{ | ||
"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. |
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
30403
29
518
1
233
1