minimax-client
Version:
TypeScript client library for the Minimax accounting API (https://moj.minimax.rs/RS/API/)
178 lines (177 loc) • 5.35 kB
TypeScript
/**
* Minimax Client
*
* Main client class for interacting with the Minimax API
*/
import { ReceivedInvoicesModule, CustomersModule, OrganizationsModule, EmployeesModule, JournalsModule, JournalTypesModule } from './resources';
/**
* Minimax client configuration
*/
export interface MinimaxClientConfig {
/**
* Client ID obtained from Minimax application registration
*/
clientId: string;
/**
* Client secret obtained from Minimax application registration
*/
clientSecret: string;
/**
* Username for Minimax account
*/
username: string;
/**
* Password for Minimax account
*/
password: string;
/**
* Base URL for the Minimax API (defaults to https://moj.minimax.rs/RS/API/)
*/
baseUrl?: string;
/**
* Authentication URL for the Minimax API (defaults to https://moj.minimax.rs/RS/AUT/oauth20/token)
*/
authUrl?: string;
/**
* Default organization ID to use for API calls
*/
organizationId?: string;
/**
* Organization identifier (registration number) to automatically select the organization
* If provided, the client will automatically find and select the organization with this registration number
* This takes precedence over organizationId if both are provided
*/
organizationIdentifier?: string;
}
/**
* Main client for interacting with the Minimax API
*/
export declare class MinimaxClient {
private readonly config;
private readonly httpClient;
private token;
private organizationId;
/**
* Resource modules
*/
readonly receivedInvoices: ReceivedInvoicesModule;
readonly customers: CustomersModule;
readonly organizations: OrganizationsModule;
readonly employees: EmployeesModule;
readonly journals: JournalsModule;
readonly journalTypes: JournalTypesModule;
/**
* Default API URLs
*/
private static readonly DEFAULT_BASE_URL;
private static readonly DEFAULT_AUTH_URL;
/**
* Create a new Minimax client
*
* @param config Client configuration
*/
constructor(config: MinimaxClientConfig);
/**
* Authenticate with the Minimax API
*
* @returns Promise that resolves when authentication is complete
*/
authenticate(): Promise<void>;
/**
* Set the organization based on the configuration
* If organizationIdentifier is provided, find and set the organization with that registration number
* Otherwise, use the organizationId if provided
*
* @returns Promise that resolves when the organization is set
*/
private setOrganizationFromConfig;
/**
* Check if the token is expired
*
* @returns True if the token is expired or doesn't exist
*/
private isTokenExpired;
/**
* Refresh the authentication token
*
* @returns Promise that resolves when the token is refreshed
*/
private refreshToken;
/**
* Get a valid access token
*
* @returns Promise that resolves to the access token
*/
getAccessToken(): Promise<string>;
/**
* Set the organization ID for API calls
*
* @param organizationId Organization ID
*/
setOrganizationId(organizationId: string): void;
/**
* Get the current organization ID
*
* @returns Organization ID or null if not set
*/
getOrganizationId(): string | null;
/**
* Make a request to the Minimax API
*
* @param method HTTP method
* @param endpoint API endpoint
* @param options Request options
* @returns Promise that resolves to the response data
*/
request<T = any>(method: string, endpoint: string, options?: {
data?: any;
params?: Record<string, any>;
headers?: Record<string, string>;
}): Promise<T>;
/**
* Make a GET request to the Minimax API
*
* @param endpoint API endpoint
* @param options Request options
* @returns Promise that resolves to the response data
*/
get<T = any>(endpoint: string, options?: {
params?: Record<string, any>;
headers?: Record<string, string>;
}): Promise<T>;
/**
* Make a POST request to the Minimax API
*
* @param endpoint API endpoint
* @param data Request body
* @param options Request options
* @returns Promise that resolves to the response data
*/
post<T = any>(endpoint: string, data?: any, options?: {
params?: Record<string, any>;
headers?: Record<string, string>;
}): Promise<T>;
/**
* Make a PUT request to the Minimax API
*
* @param endpoint API endpoint
* @param data Request body
* @param options Request options
* @returns Promise that resolves to the response data
*/
put<T = any>(endpoint: string, data?: any, options?: {
params?: Record<string, any>;
headers?: Record<string, string>;
}): Promise<T>;
/**
* Make a DELETE request to the Minimax API
*
* @param endpoint API endpoint
* @param options Request options
* @returns Promise that resolves to the response data
*/
delete<T = any>(endpoint: string, options?: {
params?: Record<string, any>;
headers?: Record<string, string>;
}): Promise<T>;
}