@testdog/ai
Version:
SDK for integrating the Testdog AI Video Intelligence API
102 lines (98 loc) • 3.21 kB
text/typescript
/**
* Configuration options for initializing the testdogAI SDK.
*/
interface SdkConfig {
accessKey: string;
secretKey: string;
apiBaseUrl?: string;
iframeBaseUrl?: string;
}
/**
* Input parameters for generating the iframe URL token.
*/
interface GenerateIframeUrlOptions {
studentId: string;
studentName: string;
sourceId: string;
iframeBaseUrl?: string;
}
/**
* Response structure from the backend when requesting an iframe token.
*/
interface IframeTokenResponse {
iframeToken: string;
}
/**
* Response structure from the backend when requesting an API access token.
*/
interface ApiAccessTokenResponse {
token: string;
}
/**
* Decoded payload of the API Access Token (used internally).
*/
interface DecodedApiAccessToken {
clientId: string;
accessKey: string;
iat: number;
exp: number;
}
declare class testdogAI {
private accessKey;
private secretKey;
private apiClient;
private iframeBaseUrl;
private apiAccessToken;
private apiAccessTokenExpiry;
/**
* Initializes the testdogAI SDK.
* @param config - SDK configuration including accessKey and secretKey.
* @param config.accessKey - The access key for API authentication.
* @param config.secretKey - The secret key for API authentication.
* @param config.apiBaseUrl - Optional base URL for the API
*/
constructor(config: SdkConfig);
/**
* Retrieves a valid API Access Token, fetching a new one if necessary.
* @returns The API Access Token.
* @throws {SdkAuthenticationError} If fetching the token fails due to invalid credentials.
* @throws {SdkRequestError} If the API request fails for other reasons.
*/
private getApiAccessToken;
/**
* Generates a secure URL for the AI chat iframe.
* @param options - Options including studentId, studentName, sourceId, and optionally iframeBaseUrl.
* @returns The generated iframe URL containing a short-lived token.
* @throws {SdkInputError} If required options are missing.
* @throws {SdkAuthenticationError} If SDK authentication fails.
* @throws {SdkRequestError} If the API request to generate the iframe token fails.
*/
generateIframeUrl(options: GenerateIframeUrlOptions): Promise<string>;
}
/**
* Base error class for SDK specific errors.
*/
declare class SdkError extends Error {
constructor(message: string);
}
/**
* Error thrown when SDK authentication (obtaining API Access Token) fails.
*/
declare class SdkAuthenticationError extends SdkError {
constructor(message: string);
}
/**
* Error thrown when an SDK request to the backend API fails.
*/
declare class SdkRequestError extends SdkError {
statusCode?: number;
details?: any;
constructor(message: string, statusCode?: number, details?: any);
}
/**
* Error thrown when input validation within the SDK fails.
*/
declare class SdkInputError extends SdkError {
constructor(message: string);
}
export { type ApiAccessTokenResponse, type DecodedApiAccessToken, type GenerateIframeUrlOptions, type IframeTokenResponse, SdkAuthenticationError, type SdkConfig, SdkError, SdkInputError, SdkRequestError, testdogAI };