UNPKG

@revmax/agent-sdk

Version:

Official Node.js SDK for RevMax - billing, customer management, and usage tracking

62 lines 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiKeyAuth = void 0; const errors_1 = require("../utils/errors"); // API key prefix that all valid keys must start with const REVX_API_KEY_PREFIX = 'revx_pk_'; /** * API Key authentication method */ class ApiKeyAuth { /** * Create a new API Key authentication method * @param apiKey - API Key for authentication * @throws RevMaxAuthenticationError if the API key is invalid */ constructor(apiKey) { this.verified = false; // Check if the API key is provided if (!apiKey) { throw new errors_1.RevMaxAuthenticationError('REVX_API_KEY is required'); } // Check if the API key is a string if (typeof apiKey !== 'string') { throw new errors_1.RevMaxAuthenticationError('REVX_API_KEY must be a string'); } // Check if the API key has the correct format if (!apiKey.startsWith(REVX_API_KEY_PREFIX)) { throw new errors_1.RevMaxAuthenticationError(`REVX_API_KEY format not valid: it should start with "${REVX_API_KEY_PREFIX}" followed by a unique identifier`); } // Check if the API key has sufficient length (prefix + at least 16 chars) if (apiKey.length < REVX_API_KEY_PREFIX.length + 16) { throw new errors_1.RevMaxAuthenticationError('REVX_API_KEY format not valid: key is too short'); } this.apiKey = apiKey; } /** * Get headers for authentication * @returns Headers for API requests */ getHeaders() { // Only use the header format that works with the API server return { 'revx-api-key': this.apiKey, }; } /** * Set verification status * @param status - Verification status */ setVerified(status) { this.verified = status; } /** * Check if the API key has been verified * @returns Verification status */ isVerified() { return this.verified; } } exports.ApiKeyAuth = ApiKeyAuth; //# sourceMappingURL=apiKey.js.map