UNPKG

2factor-sdk

Version:

A TypeScript SDK for sending and validating OTPs with support for rate limiting.

168 lines (162 loc) 4.87 kB
import { z } from 'zod'; declare abstract class Base { private baseUrl; constructor(); } declare const constructorSchema: z.ZodEffects<z.ZodObject<{ apiKey: z.ZodString; upstashUrl: z.ZodOptional<z.ZodString>; upstashToken: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { apiKey: string; upstashUrl?: string | undefined; upstashToken?: string | undefined; }, { apiKey: string; upstashUrl?: string | undefined; upstashToken?: string | undefined; }>, { apiKey: string; upstashUrl?: string | undefined; upstashToken?: string | undefined; }, { apiKey: string; upstashUrl?: string | undefined; upstashToken?: string | undefined; }>; declare const sendOTPSchema: z.ZodEffects<z.ZodObject<{ phoneNumber: z.ZodString; templateName: z.ZodOptional<z.ZodString>; otpLength: z.ZodOptional<z.ZodEffects<z.ZodNumber, 4 | 6, number>>; interval: z.ZodOptional<z.ZodString>; limit: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { phoneNumber: string; templateName?: string | undefined; otpLength?: 4 | 6 | undefined; interval?: string | undefined; limit?: number | undefined; }, { phoneNumber: string; templateName?: string | undefined; otpLength?: number | undefined; interval?: string | undefined; limit?: number | undefined; }>, { phoneNumber: string; templateName?: string | undefined; otpLength?: 4 | 6 | undefined; interval?: string | undefined; limit?: number | undefined; }, { phoneNumber: string; templateName?: string | undefined; otpLength?: number | undefined; interval?: string | undefined; limit?: number | undefined; }>; declare const sendAndReturnOTPSchema: z.ZodEffects<z.ZodObject<{ phoneNumber: z.ZodString; templateName: z.ZodOptional<z.ZodString>; interval: z.ZodOptional<z.ZodString>; limit: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { phoneNumber: string; templateName?: string | undefined; interval?: string | undefined; limit?: number | undefined; }, { phoneNumber: string; templateName?: string | undefined; interval?: string | undefined; limit?: number | undefined; }>, { phoneNumber: string; templateName?: string | undefined; interval?: string | undefined; limit?: number | undefined; }, { phoneNumber: string; templateName?: string | undefined; interval?: string | undefined; limit?: number | undefined; }>; declare const sendCustomOTPSchema: z.ZodEffects<z.ZodObject<{ phoneNumber: z.ZodString; templateName: z.ZodOptional<z.ZodString>; otp: z.ZodEffects<z.ZodString, string, string>; interval: z.ZodOptional<z.ZodString>; limit: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { phoneNumber: string; otp: string; templateName?: string | undefined; interval?: string | undefined; limit?: number | undefined; }, { phoneNumber: string; otp: string; templateName?: string | undefined; interval?: string | undefined; limit?: number | undefined; }>, { phoneNumber: string; otp: string; templateName?: string | undefined; interval?: string | undefined; limit?: number | undefined; }, { phoneNumber: string; otp: string; templateName?: string | undefined; interval?: string | undefined; limit?: number | undefined; }>; declare const verifyByUIDSchema: z.ZodObject<{ otp: z.ZodEffects<z.ZodString, string, string>; UID: z.ZodString; }, "strip", z.ZodTypeAny, { otp: string; UID: string; }, { otp: string; UID: string; }>; declare const verifyByPhoneSchema: z.ZodObject<{ otp: z.ZodEffects<z.ZodString, string, string>; phoneNumber: z.ZodString; }, "strip", z.ZodTypeAny, { phoneNumber: string; otp: string; }, { phoneNumber: string; otp: string; }>; declare class TWOFactor extends Base { private apiKey; private upstashUrl?; private upstashToken?; private constructor(); static init(data: z.infer<typeof constructorSchema>): TWOFactor; sendOTP(data: z.infer<typeof sendOTPSchema>): Promise<{ UID: string; } | undefined>; sendAndReturnOTP(data: z.infer<typeof sendAndReturnOTPSchema>): Promise<{ OTP: string; UID: string; } | undefined>; sendCustomOTP(data: z.infer<typeof sendCustomOTPSchema>): Promise<{ UID: string; } | undefined>; verifyByUID(data: z.infer<typeof verifyByUIDSchema>): Promise<true | undefined>; verifyByPhone(data: z.infer<typeof verifyByPhoneSchema>): Promise<true | undefined>; } declare class TFError extends Error { name: string; constructor(message: string); } declare const handleTFError: (error: unknown) => { error: string; name: string; } | undefined; export { TFError, TWOFactor, handleTFError };