quickbooks-api
Version:
A modular TypeScript SDK for seamless integration with Intuit QuickBooks APIs. Provides robust authentication handling and future-ready foundation for accounting, payments, and commerce operations.
129 lines (128 loc) • 4.42 kB
TypeScript
import { AuthScopes, type Token } from '../../types/types.js';
/**
* The Auth Provider is responsible for handling the OAuth2 flow for the application.
* It is responsible for generating the OAuth2 URL and handling the callback.
*/
export declare class AuthProvider {
private readonly clientId;
private readonly clientSecret;
private readonly redirectUri;
private readonly scopes;
private token?;
readonly serializationHeader = "QBOAUTHTOKEN";
/**
* The Auth Header for the application
*/
readonly authHeader: string;
/**
* The Event Emitter for the Auth Provider
*/
private readonly eventEmitter;
/**
* Wether to automatically refresh the token when it is expired
*/
private autoRefresh;
/**
* Initialize the Auth Provider
* @param clientId The client ID for the application *Required*
* @param clientSecret The client secret for the application *Required*
* @param redirectUri The redirect URI for the application *Required*
* @param scopes The scopes for the application *Required*
* @param token The token for the application (optional)
*/
constructor(clientId: string, clientSecret: string, redirectUri: string, scopes: Array<AuthScopes>, token?: Token | undefined);
/**
* Enable the Auto Refresh
*/
enableAutoRefresh(): void;
/**
* Disable the Auto Refresh
*/
disableAutoRefresh(): void;
/**
* Get the Access Token
* @returns {string} The access token
*/
getToken(): Promise<Token>;
/**
* Set the Token
* @param token The token to set
*/
setToken(newToken: Token | null): Promise<void>;
/**
* Generates the OAuth2 URL to get the auth code from the user
* @returns {URL} The OAuth2 URL to get the auth code from the user
*/
generateAuthUrl(state?: string): URL;
/**
* Exchanges an Auth Code for a Token
* @param authCode The auth code to exchange for a token
* @returns {Promise<Token>} The token
*/
exchangeCode(code: string, realmId: string): Promise<Token>;
/**
* Exchanges a Refresh Token for a Token
* @param refreshToken The refresh token to exchange for a token
* @returns {Promise<Token>} The token
*/
refresh(): Promise<Token>;
/**
* Revokes a Token
* @param token The token to revoke
* @returns {Promise<boolean>} True if the token was revoked, false otherwise
*/
revoke(): Promise<boolean>;
/**
* Validates the Token
* @returns {Promise<boolean>} True if the token is valid, false otherwise
*/
validateToken(): Promise<boolean>;
/**
* Serializes the Token
* @returns {string | undefined} The serialized token
*/
serializeToken(secretKey: string): Promise<string | undefined>;
/**
* Deserializes the Token
* @param serialized The serialized token to deserialize
* @param secretKey The secret key used for decryption
*/
deserializeToken(serialized: string, secretKey: string): Promise<void>;
/**
* Adds a callback to be called when the token is refreshed
* @param callback The callback to call when the token is refreshed
*/
onRefresh(callback: (refreshedToken: Token) => void): void;
/**
* Adds a callback to be called when the token is revoked
* @param callback The callback to call when the token is revoked
*/
onRevoke(callback: (revokedToken: Token) => void): void;
/**
* Derives a Crypto Key
* @param secretKey The secret key to derive the key from
* @param salt The salt to derive the key from
* @param keyUsage The key usage for the derived key
* @returns {Promise<CryptoKey>} The derived key
*/
private deriveKey;
/**
* Parses the Token Response
* @param response The token response to parse
* @param realmId The realm ID for the token
* @returns {Token} The parsed token
*/
private parseTokenResponse;
/**
* Restores the Token Types
* @param parsedToken The parsed token to restore
* @returns {Token} The restored token
*/
private restoreTokenTypes;
/**
* Checks if a value is an ISO date string
* @param value The value to check
* @returns {boolean} True if the value is an ISO date string, false otherwise
*/
private isDateString;
}