@mochabug/adapt-web
Version:
Browser client library for Adapt automation platform
47 lines (46 loc) • 2.09 kB
TypeScript
declare global {
interface Window {
CAP_CUSTOM_WASM_URL?: string;
}
}
import type { AutomationClient } from "@mochabug/adapt-core";
import type { ChallengeInfo, RedeemChallengeOptions, RedeemedChallenge } from "./types.js";
/**
* Create a challenge for an automation that requires proof-of-work.
*
* @param client - The automation client
* @param id - The automation ID
* @returns Challenge information including the token to solve
*/
export declare function createChallenge(client: AutomationClient, id: string): Promise<ChallengeInfo>;
/**
* Redeem solved challenge solutions for a token that can be used to start a session.
*
* @param client - The automation client
* @param id - The automation ID
* @param verificationToken - The encrypted verification token from createChallenge
* @param solutions - Array of nonce solutions found by Cap.js solver
* @returns Redeemed challenge with token to use for session start
*/
export declare function redeemChallenge(client: AutomationClient, id: string, verificationToken: string, solutions: bigint[], options?: RedeemChallengeOptions): Promise<RedeemedChallenge>;
/**
* Read and clear the expiration captured from the most recent successful redeem.
*
* Cap.js solve events expose the redeemed token but not its expiry timestamp, so
* the wrapper needs to carry that value across from the redeem response.
*/
export declare function takeRedeemedChallengeExpiration(automationId: string): Date | null;
/**
* Set up the Cap.js adapter with the client and automation ID.
* Must be called before the Cap.js widget is activated.
*
* @param client - The automation client to use for API calls
* @param automationId - The automation ID to use for challenge endpoints
*/
export declare function setupCapAdapter(client: AutomationClient, automationId: string): void;
/**
* Clean up the Cap.js adapter state.
* The CAP_CUSTOM_FETCH handler remains in place but will error if called
* without being set up again via setupCapAdapter().
*/
export declare function cleanupCapAdapter(automationId?: string): void;