UNPKG

@limitly/limitly-nextjs

Version:

Official Next.js SDK for Limitly - API Key management, plans, users and request validation optimized for server-side

57 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidationModule = void 0; /** * Module for validating requests * Optimized for Next.js server-side rendering */ class ValidationModule { client; constructor(client) { this.client = client; } /** * Validates a user request using their API Key * @param data - Request validation data * @param options - Request options including Next.js cache options * @returns Promise with validation result */ async validateRequest(data, options) { return this.client.post('/validate', data, options); } /** * Convenience method to validate a request with individual parameters * @param apiKey - The API key to validate * @param endpoint - The endpoint being accessed * @param method - The HTTP method * @param options - Request options including Next.js cache options * @returns Promise with validation result */ async validate(apiKey, endpoint, method, options) { return this.validateRequest({ api_key: apiKey, endpoint, method, }, options); } /** * Validates a request with additional context for Next.js * @param apiKey - The API key to validate * @param endpoint - The endpoint being accessed * @param method - The HTTP method * @param context - Additional context (e.g., user ID, session info) * @param options - Request options * @returns Promise with validation result */ async validateWithContext(apiKey, endpoint, method, context, options) { const requestData = { api_key: apiKey, endpoint, method, ...(context && { context }), }; return this.client.post('/validate', requestData, options); } } exports.ValidationModule = ValidationModule; //# sourceMappingURL=validation.js.map