UNPKG

@ronnakamoto/inp-middleware

Version:

INP Protocol middleware for Express.js and Next.js applications - API-driven implementation with automatic metrics integration

160 lines 4.34 kB
/** * INP Protocol Types * * Core type definitions for the INP (Internet Native Payments) protocol * These types are based on the INP specification and API responses */ export interface INPEndpointConfig { pricing_model: 'fixed' | 'dynamic'; price?: { amount: string; currency: string; }; base_price?: { amount: string; currency: string; }; bidding_enabled?: boolean; networks: string[]; guaranteed_response_time?: string; availability?: string; } export interface INPDiscoveryEndpoint { version: string; service_info: { name: string; description?: string; base_url: string; }; endpoints: Record<string, INPEndpointConfig>; } export interface INPPayment { amount: number; currency: string; network: string; walletAddress: string; transactionId?: string; proof?: string; } export interface INPClientConfig { baseUrl: string; apiKey?: string; timeout?: number; retries?: number; } export interface INPDiscoveryRequest { projectId: string; baseUrl?: string; } export interface INPPaymentValidationRequest { endpointId: string; payment: INPPayment; validateTransaction?: boolean; } export interface INPServiceInvocationRequest { serviceId: string; method?: string; url?: string; headers?: Record<string, string>; body?: any; auth?: any; payment?: INPPayment; } export interface INPMiddlewareOptions { inpPlatformUrl?: string; projectId?: string; apiKey?: string; discoveryPath?: string; cacheTTL?: number; validatePayment?: (payment: INPPayment, endpointConfig: any) => Promise<INPValidationResult> | INPValidationResult; timeout?: number; retries?: number; strictMode?: boolean; logErrors?: boolean; } export interface INPPaymentMiddlewareOptions extends INPMiddlewareOptions { endpointConfig?: INPEndpointConfig; endpointId?: string; fallbackToDiscovery?: boolean; } export interface INPDiscoveryMiddlewareOptions extends INPMiddlewareOptions { autoGenerate?: boolean; customEndpoints?: Record<string, INPEndpointConfig>; } export interface INPValidationResult { isValid: boolean; error?: string; details?: any; warnings?: string[]; } export interface INPDiscoveryResult { success: boolean; data?: INPDiscoveryEndpoint; error?: string; cached?: boolean; statusCode?: number; } export interface INPPaymentValidationResult extends INPValidationResult { transactionVerified?: boolean; paymentDetails?: { amount: number; currency: string; network: string; timestamp?: string; }; } export interface INPServiceInvocationResult { success: boolean; status: number; statusText: string; data?: any; headers?: Record<string, string>; metadata?: { serviceId: string; serviceName?: string; projectName?: string; invokedAt: string; responseTime: number; }; error?: string; } export interface INPErrorResponse { error: string; code?: string; timestamp?: string; details?: any; } export interface INPValidationError extends INPErrorResponse { code: 'VALIDATION_ERROR'; field?: string; value?: any; expected?: any; } export interface INPPaymentError extends INPErrorResponse { code: 'PAYMENT_ERROR' | 'PAYMENT_REQUIRED' | 'TRANSACTION_VERIFICATION_FAILED'; required?: { amount?: string; currency?: string; networks?: string[]; }; } export interface INPRequest extends Request { inpPayment?: INPPayment; inpDiscovery?: INPDiscoveryEndpoint; inpValidation?: INPValidationResult; } export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'; export type SupportedNetwork = 'algorand' | 'base' | 'ethereum' | 'polygon'; export type SupportedCurrency = 'USDC' | 'USD' | 'EUR' | 'ETH' | 'ALGO'; export interface CacheEntry<T> { data: T; timestamp: number; ttl: number; } export interface INPLogger { info(message: string, data?: any): void; warn(message: string, data?: any): void; error(message: string, error?: Error, data?: any): void; debug(message: string, data?: any): void; } //# sourceMappingURL=index.d.ts.map