import { MatchResult } from 'path-to-regexp'; import React from 'react'; interface PutRequestObject { [propertyName: string]: any; } interface ListRequestObject { prefix?: string; reverse?: boolean; limit?: number | null; noCache?: boolean; } type StateFn = (objectName?: string, objectId?: string, isCloudflareObjectId?: boolean) => StateMethods; interface StateMethods { get: (propertyName: string) => Promise; put: (putRequestObject: PutRequestObject) => Promise; delete: (propertyName: string | string[]) => Promise; deleteAll: () => Promise; list: (listRequestObject?: ListRequestObject) => Promise; } declare const getStateMethods: (defaultObjectName: string, matches?: MatchResult) => StateFn; declare const parseObjectStateMapping: (objectStateMapping: string, matches?: MatchResult) => string; declare const deleteObjectState: (obj: any, callback: any) => (propertyName: string) => Promise; declare const deleteAllObjectState: (obj: any, callback: any) => () => Promise; declare const getObjectState: (obj: any, callback: any) => (propertyName: string) => Promise; declare const listObjectState: (obj: any, callback: any) => (payload: any) => Promise; declare const putObjectState: (obj: any, callback: any) => (payload: any) => Promise; /** * Retrieves an object instance by its name and derived ID. * @param objectName The name of the durable object Class * @param objectId string that will be used to generate the ID for the object. If undefined, "default" will be used. * @returns */ declare const getEnvObject: (objectName: string, objectId: string | undefined) => any; /** * Retrieves an object instance by its name and Cloudflare-given ID. * The Cloudflare ID for the object instance can be found through getInstanceList() * @param objectName The name of the durable object Class * @param cloudflareObjectId The Cloudflare ID of the object instance. * @returns */ declare const getEnvObjectByCloudflareId: (objectName: string, cloudflareObjectId: string) => any; interface RequestParams { state: StateFn; matches: MatchResult; body: any; headers: Headers; request: Request; } interface ScheduledParams { state: StateFn; event?: any; env?: any; ctx?: any; } type Handler = ((params: RequestParams) => Response | Promise); interface RouteObject { [route: string]: Handler; } type Middleware = (params: RequestParams, handlerFn?: Handler) => Response | Middleware | Promise; declare const forwardToMiddleware: (params: RequestParams, middlewares?: Middleware[]) => Promise; /** * Handles incoming Cloudflare Worker requests */ declare const handleEntryRequest: (request: Request, env: any, ctx: any) => Promise; /** * Handle scheduled worker requests */ declare const handleScheduledRequest: (event: any, env: any, ctx: any, callback: (params: ScheduledParams) => Promise) => Promise; declare const readRequestBody: (request: any) => Promise; interface Routes { [route: string]: any; } interface Controllers { [className: string]: Controller; } interface Options { routes?: Routes; controllers?: Controllers; debug?: boolean; objectVersion?: string; exports?: any; objects?: string[]; objectStateMapping?: ObjectStateMapping; env?: any; ctx?: any; authRoutes?: boolean; requestParams?: RequestParams; firewall?: Firewall | boolean; adminPanel?: boolean; name?: string; email?: EmailOptions; scheduled?: (params: ScheduledParams) => Promise; } type Timings = { [timingName: string]: number; }; type ObjectStateMapping = { [objectName: string]: string; }; interface EmailOptions { name?: string; senderEmail: string; } interface Firewall { limitRequestsPerMinute: number; } type Controller = new (...args: any[]) => any; declare class ResponseParams { errors: string[]; /** * Sets an error response */ setError: (errorMessage: string) => void; /** * Gets the last error response */ getLastError: () => string | null; } /** * Apiker class definition. * ⚠️ Please do not instantiate this class and use the "apiker" exported instance instead. */ declare class Apiker { name: string; routes: Routes; controllers: Controllers; debug: boolean; objectVersion: string; objects: string[]; objectStateMapping: ObjectStateMapping; authRoutes: boolean; env: any; ctx: any; requestParams: RequestParams; responseParams: ResponseParams; responseHeaders: Headers; firewall: Firewall | boolean; adminPanel: boolean; email?: EmailOptions; timings: Timings; defaultObjectName: string; /** * Initialize Apiker, perform basic validation */ init: (options?: Options) => Response | undefined; /** * Set options */ setProps: (options?: Options) => void; /** * Creates a durable object class definition */ getObjectClassDefinition: (objectName: string) => { new (state: any): { state: any; fetch: (request: any) => Promise; }; }; } /** * Instance of the Apiker class */ declare const apiker: Apiker; declare const searchLogsEndpoint: Handler; declare const bansEndpoint: Handler; declare const searchBansEndpoint: Handler; declare const loginEndpoint: Handler; declare const sendEmailEndpoint: Handler; declare const updateUserEndpoint: Handler; /** * Apiker */ declare const getApikerAuthRoutes: () => RouteObject; /** * Github */ declare const getGithubAuthRoutes: () => RouteObject; interface User { id: string; email: string; role?: string; password: string; verified: boolean; createdAt: number; updatedAt: number; } /** * Encodes an input into Base64 * @param inputStr Base64 input to decode */ declare const encodeString: (inputStr: any) => any; /** * Decodes a Base64 input * @param inputStr Base64 input to decode */ declare const decodeString: (inputStr: any) => any; /** * Generates a JWT token * @param data Payload to include in the token * @param expirationInMinutes Expiration of the token (in minutes) */ declare const createJWT: (data: any, expirationInMinutes?: number) => string; /** * Parses a JWT token * @param token JWT token */ declare const parseJWT: (token: string, disableClientIdCheck?: boolean) => any; /** * Generates a bcrypt hash of a given message * @param message Message to hash */ declare const hash_bcrypt: (message: string) => string; /** * Compares a raw value with a bcrypt hash * @param message Raw input to compare * @param hash Hash to compare against */ declare const compare_bcrypt: (message: string, hash: string) => boolean; /** * Creates a Base64 hash signed with the Apiker's installation secret key */ declare const sign: (message: any) => string; /** * Creates a SHA256 hash signed with the Apiker's installation secret key */ declare const sign_sha256: (message: string) => string; /** * Creates a SHA1 hash signed with the Apiker's installation secret key */ declare const sign_sha1: (message: string) => string; /** * Creates a random SHA256 hash */ declare const randomHash: () => any; /** * Creates a random SHA1 hash */ declare const randomHash_SHA1: () => string; /** * Creates SHA256 hash */ declare const stringHash: (content: string) => any; /** * Creates a random SHA1 hash */ declare const stringHash_SHA1: (content: any) => string; /** * Generating a clientId * This value is returned to client and not stored */ declare const getClientId: () => string; /** * Retrieves the auth tokens from the request headers or cookies. */ declare const extractToken: () => string; /** * Fetches the current user by checking for the auth token in the request headers or in the cookies. */ declare const getCurrentUser: (disableClientIdCheck?: boolean) => Promise; /** * Checks whether a given user is an admin */ declare const isUserAdmin: (userId?: string) => Promise; /** * Checks whether the current user is an admin */ declare const isCurrentUserAdmin: () => Promise; /** * Generates auth tokens for a given user * @param userId The user's ID * @param expirationInMinutes The expiration time for the action token. The refresh token does not expire. */ declare const getTokens: (userId: string, expirationInMinutes?: number) => { userId: string; token: string; refreshToken: string; }; /** * Gets the client's IP */ declare const getRawIp: () => string; /** * Gets the client's IP signed in SHA1 format. */ declare const getSignedIp: () => string; declare const deleteUser: Handler; declare const deleteUserAction: (user: User) => Promise; declare const loginUser: Handler; declare const loginUserAction: (email: string, password: string) => Promise<{ userId: string; token: string; refreshToken: string; email: string; } | undefined>; declare const checkUser: (email: string, password: string) => Promise; declare const refreshUser: Handler; declare const registerUser: Handler; declare const registerUserAction: (email: string, password: string, extraParams?: any) => Promise; declare const forgotUser: Handler; declare const forgotUserAction: (email: string) => Promise; /** * Forgot user reset action */ declare const forgotUserReset: Handler; declare const verifyUser: Handler; declare const verifyUserAction: (email: string) => Promise; /** * Verify user action */ declare const verifyUserProcess: Handler; interface LogObject { propertyName: string; time: number; id: string; clientId: string; countryCode: string; pathname: string; issuedBy?: string; } declare const addUniqueLogEntry: (prefix: string, additionalParams?: {}, objectName?: string, signedIp?: string | undefined, clientId?: string | undefined) => Promise; declare const addLogEntry: (prefix: string, additionalParams?: any, objectName?: string, signedIp?: string | undefined, clientId?: string | undefined) => Promise; declare const getLogParams: (propertyName: string, signedIp?: string | undefined, clientId?: string | undefined, additionalParams?: {}) => LogObject; declare const getUserLogPropertyName: (prefix: string, signedIp?: string | null) => string; declare const getUserLogEntries: (prefix: string, limit?: number, objectName?: string, signedIp?: string | undefined, objectId?: string) => Promise; declare const getLogEntries: (prefix: string, limit?: number | null, objectName?: string, objectId?: string, isCloudflareObjectId?: boolean) => Promise; declare const getAllLogEntries: (objectName?: string, limit?: number | null, objectId?: string, isCloudflareObjectId?: boolean) => Promise; declare const deleteAllLogsInObject: (objectName: string, signedIp: string) => Promise; declare const deleteUserLogEntries: (prefix: string, objectName?: string, signedIp?: string | undefined) => Promise; declare const deleteLogEntries: (prefix: string, objectName?: string) => Promise; /** * Bans an entity * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) * @param clientId The user's clientId (defaulting to getClientId()) */ declare const banEntity: (entity: string, clientId?: string) => Promise; /** * Unbans an entity * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) */ declare const unbanEntity: (entity: string) => Promise; /** * Checks whether an entity is banned * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) */ declare const isEntityBanned: (entity: string) => Promise; /** * Get a list of banned entries for a given entity * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) * @param limit The number of results to return */ declare const getBannedEntries: (entity: string, limit?: number) => Promise; /** * Get a list of banned entries (without filtering by entity) * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) * @param limit The number of results to return */ declare const getBannedEntities: (limit?: number) => Promise; declare const bansMiddleware: Middleware; declare const BANS_PREFIX = "bans"; declare const fetchFromCloudflareAPI: (endpoint: string, options?: RequestInit, method?: string) => Promise; /** * Fetches the list of object namespaces in account */ declare const getObjectNamespaces: (requestOptions?: {}) => Promise; /** * Fetches the list of instances for a specific object namespace * @param namespaceId The ID of the object namespace */ declare const getObjectInstancesByNamespaceId: (namespaceId: string, requestOptions?: {}) => Promise; /** * Fetches the list of instances for the object * @param appName The name of the application (script). This is the "name" field in app.toml * @param objectName The name of the object (class) * @param requestOptions Additional options for the request */ declare const getInstanceList: (appName: string, objectName: string, requestOptions?: {}) => Promise; interface EmailActor { name: string; email: string; } declare const sendEmail: (subject: string, content: string, to?: EmailActor[], sender?: EmailActor) => Promise; declare const EMAIL_API_ENDPOINT = "https://api.brevo.com/v3/smtp/email"; declare const forgotPasswordTemplate = "\n \n \n

Email Reset

\n
\n

If you received this email, it means that you've used the Reset Password feature. If so, click the following link to proceed:

\n

Reset User Email

\n

If you have not initiated this request, please disregard this message. The link will expire in 5 minutes.

\n
\n \n "; declare const newPasswordTemplate = "\n \n \n

New Password

\n
\n

Your password has been reset successfully.

\n

New password: {newPassword}

\n

If you have not initiated this request, please reach out to support.

\n
\n \n"; declare const verifyAccountTemplate = "\n \n \n

Verify Account

\n
\n

If you received this email, it means that you've created an account at {appName}. If so, click the following link to activate your account:

\n

Activate account

\n

If you have not initiated this request, please disregard this message. The link will expire in 5 minutes.

\n
\n \n "; declare const verifyAccountSuccessTemplate = "\n \n \n

Account verified

\n
\n

You have verified your account at {appName}.

\n

Have a great day!

\n
\n \n"; declare const firewallBanIP: (ip: string) => Promise; declare const getFirewallBannedEntryId: (ip: string) => Promise; declare const firewallUnbanIP: (ip: string) => Promise; declare const firewallMiddleware: Middleware; declare const FIREWALL_ENDPOINT = "https://api.cloudflare.com/client/v4/user/firewall/access_rules/rules"; declare const FIREWALL_REQUESTS_MINUTE = 100; declare const FIREWALL_RATELIMIT_PREFIX = "firewall"; declare const getCurrentUserGeodata: () => Promise; declare const getUserGeodata: (ip: string) => Promise; declare const OBN: { COMMON: string; USERS: string; EMAILTOUUID: string; RATELIMIT: string; LOGS: string; BANS: string; }; declare const OBMT: { DEFAULT: string; SIGNEDIP: string; CLIENTID: string; IP: string; }; declare const OB_ENDPOINT = "https://durable-object"; declare const pageHeader: (head?: string) => string; declare const pageFooter: (prepend?: string) => string; declare const adminPageHeader: (styles?: string) => string; declare const adminPageFooter: (prepend?: string) => string; declare const wrapPage: (pageContent: string, headHtml?: string, footerHtml?: string) => Response; declare const wrapReactPage: (componentName: string, pageComponent: React.ReactElement, props?: {}, styles?: string) => Response; declare const wrapAdminReactPage: (componentName: string, pageComponent: React.ReactElement, props?: {}, styles?: string) => Response; declare const rateLimitRequest: (prefix: string, params: RequestParams, handlerFn?: Handler, limit?: number, timeLapse?: number, onLimitReached?: any) => Promise; declare const isRateLimitReached: (prefix: string, limit: number, timeLapse: number) => Promise<{ rateLimitReached: boolean | 0; requestCount: number; }>; declare const res_200: (input?: any, options?: null) => Response; declare const res_201: (input?: any, options?: null) => Response; declare const res_204: (input?: any, options?: null) => Response; declare const res_400: (input?: any, options?: null) => Response; declare const res_401: (input?: any, options?: null) => Response; declare const res_404: (input?: any, options?: null) => Response; declare const res_405: (input?: any, options?: null) => Response; declare const res_429: (input?: any, options?: null) => Response; declare const res_500: (input?: any, options?: null) => Response; declare const res: (input: any, options?: any) => Response; declare const resRaw: (htmlContent: string, contentType?: string) => Response; declare const RESPONSE_HEADERS_DEFAULT: { "Access-Control-Allow-Origin": string; "Access-Control-Allow-Headers": string; "Access-Control-Allow-Credentials": string; "Access-Control-Allow-Methods": string; "content-type": string; }; declare const RESPONSE_MESSAGES: { 200: string; 201: string; 204: string; 400: string; 401: string; 404: string; 405: string; 429: string; 500: string; }; declare const measureTiming: (timingName: string) => number; declare const elapsedSinceRequestStart: () => number; declare const isEmail: (email: string) => boolean; declare const isRequiredLength: (str: string, minLegth?: number, maxLength?: number) => boolean; declare const MIN_STR_LEN = 5; declare const MAX_STR_LEN = 20; export { Apiker, BANS_PREFIX, Controller, Controllers, EMAIL_API_ENDPOINT, EmailActor, EmailOptions, FIREWALL_ENDPOINT, FIREWALL_RATELIMIT_PREFIX, FIREWALL_REQUESTS_MINUTE, Firewall, Handler, ListRequestObject, LogObject, MAX_STR_LEN, MIN_STR_LEN, Middleware, OBMT, OBN, OB_ENDPOINT, ObjectStateMapping, Options, PutRequestObject, RESPONSE_HEADERS_DEFAULT, RESPONSE_MESSAGES, RequestParams, ResponseParams, RouteObject, Routes, ScheduledParams, StateFn, StateMethods, Timings, User, addLogEntry, addUniqueLogEntry, adminPageFooter, adminPageHeader, apiker, banEntity, bansEndpoint, bansMiddleware, checkUser, compare_bcrypt, createJWT, decodeString, deleteAllLogsInObject, deleteAllObjectState, deleteLogEntries, deleteObjectState, deleteUser, deleteUserAction, deleteUserLogEntries, elapsedSinceRequestStart, encodeString, extractToken, fetchFromCloudflareAPI, firewallBanIP, firewallMiddleware, firewallUnbanIP, forgotPasswordTemplate, forgotUser, forgotUserAction, forgotUserReset, forwardToMiddleware, getAllLogEntries, getApikerAuthRoutes, getBannedEntities, getBannedEntries, getClientId, getCurrentUser, getCurrentUserGeodata, getEnvObject, getEnvObjectByCloudflareId, getFirewallBannedEntryId, getGithubAuthRoutes, getInstanceList, getLogEntries, getLogParams, getObjectInstancesByNamespaceId, getObjectNamespaces, getObjectState, getRawIp, getSignedIp, getStateMethods, getTokens, getUserGeodata, getUserLogEntries, getUserLogPropertyName, handleEntryRequest, handleScheduledRequest, hash_bcrypt, isCurrentUserAdmin, isEmail, isEntityBanned, isRateLimitReached, isRequiredLength, isUserAdmin, listObjectState, loginEndpoint, loginUser, loginUserAction, measureTiming, newPasswordTemplate, pageFooter, pageHeader, parseJWT, parseObjectStateMapping, putObjectState, randomHash, randomHash_SHA1, rateLimitRequest, readRequestBody, refreshUser, registerUser, registerUserAction, res, resRaw, res_200, res_201, res_204, res_400, res_401, res_404, res_405, res_429, res_500, searchBansEndpoint, searchLogsEndpoint, sendEmail, sendEmailEndpoint, sign, sign_sha1, sign_sha256, stringHash, stringHash_SHA1, unbanEntity, updateUserEndpoint, verifyAccountSuccessTemplate, verifyAccountTemplate, verifyUser, verifyUserAction, verifyUserProcess, wrapAdminReactPage, wrapPage, wrapReactPage };