pocketsmith-ts
Version:
TypeScript client library for PocketSmith API
202 lines • 7.25 kB
TypeScript
import type { paths } from './types';
export type PocketSmithAPIConfig = {
/**
* API base URL (defaults to https://api.pocketsmith.com/v2)
*/
baseUrl?: string;
/**
* Developer API key for authentication
*/
apiKey?: string;
/**
* OAuth2 bearer token for authentication
*/
accessToken?: string;
};
/**
* Serializes error objects for better debugging
*/
export declare function serializeError(error: unknown): string;
/**
* Creates a PocketSmith API client with convenience methods
*
* @example
* ```typescript
* // Using API Key
* const client = createPocketSmithClient({
* apiKey: 'your-developer-key'
* });
*
* // Using OAuth2
* const client = createPocketSmithClient({
* accessToken: 'your-oauth-token'
* });
*
* // Fetch current user (standard openapi-fetch method)
* const { data: user, error } = await client.GET('/me');
* if (error) {
* console.error('API Error:', serializeError(error)); // Properly serialized error
* }
*
* // Use convenience methods
* const { data: transactions } = await client.transactions.getByAccount(123, {
* start_date: '2024-01-01',
* end_date: '2024-12-31'
* });
* ```
*/
export declare function createPocketSmithClient(config?: PocketSmithAPIConfig): {
transactions: {
/**
* Get transactions for a specific account (high-level account grouping)
*
* @param accountId - The account ID
* @param options - Query parameters for filtering transactions
* @example
* ```typescript
* const { data: transactions } = await client.transactions.getByAccount(123, {
* start_date: '2024-01-01',
* end_date: '2024-12-31'
* });
* ```
*/
getByAccount: (accountId: number, options?: {
start_date?: string;
end_date?: string;
search?: string;
type?: "credit" | "debit";
needs_review?: boolean;
uncategorised?: boolean;
page?: number;
}) => Promise<import("openapi-fetch").FetchResponse<{
parameters: {
query?: {
start_date?: string;
end_date?: string;
updated_since?: string;
uncategorised?: number;
type?: "debit" | "credit";
needs_review?: number;
search?: string;
page?: number;
};
header?: never;
path: {
id: number;
};
cookie?: never;
};
requestBody?: never;
responses: {
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": import("./types").components["schemas"]["Transaction"][];
};
};
400: import("./types").components["responses"]["400"];
403: import("./types").components["responses"]["403"];
404: import("./types").components["responses"]["404"];
};
}, {
params: {
path: {
id: number;
};
query: {
start_date?: string;
end_date?: string;
search?: string;
type?: "credit" | "debit";
needs_review?: boolean;
uncategorised?: boolean;
page?: number;
};
};
}, `${string}/${string}`>>;
/**
* Get transactions for a specific transaction account (individual account where transactions are posted)
*
* @param transactionAccountId - The transaction account ID
* @param options - Query parameters for filtering transactions
* @example
* ```typescript
* const { data: transactions } = await client.transactions.getByTransactionAccount(456, {
* start_date: '2024-01-01',
* end_date: '2024-12-31'
* });
* ```
*/
getByTransactionAccount: (transactionAccountId: number, options?: {
start_date?: string;
end_date?: string;
search?: string;
type?: "credit" | "debit";
needs_review?: boolean;
uncategorised?: boolean;
page?: number;
}) => Promise<import("openapi-fetch").FetchResponse<{
parameters: {
query?: {
start_date?: string;
end_date?: string;
updated_since?: string;
uncategorised?: number;
type?: "debit" | "credit";
needs_review?: number;
search?: string;
page?: number;
};
header?: never;
path: {
id: number;
};
cookie?: never;
};
requestBody?: never;
responses: {
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": import("./types").components["schemas"]["Transaction"][];
};
};
400: import("./types").components["responses"]["400"];
403: import("./types").components["responses"]["403"];
404: import("./types").components["responses"]["404"];
};
}, {
params: {
path: {
id: number;
};
query: {
start_date?: string;
end_date?: string;
search?: string;
type?: "credit" | "debit";
needs_review?: boolean;
uncategorised?: boolean;
page?: number;
};
};
}, `${string}/${string}`>>;
};
GET: import("openapi-fetch").ClientMethod<paths, "get", `${string}/${string}`>;
PUT: import("openapi-fetch").ClientMethod<paths, "put", `${string}/${string}`>;
POST: import("openapi-fetch").ClientMethod<paths, "post", `${string}/${string}`>;
DELETE: import("openapi-fetch").ClientMethod<paths, "delete", `${string}/${string}`>;
OPTIONS: import("openapi-fetch").ClientMethod<paths, "options", `${string}/${string}`>;
HEAD: import("openapi-fetch").ClientMethod<paths, "head", `${string}/${string}`>;
PATCH: import("openapi-fetch").ClientMethod<paths, "patch", `${string}/${string}`>;
TRACE: import("openapi-fetch").ClientMethod<paths, "trace", `${string}/${string}`>;
use(...middleware: import("openapi-fetch").Middleware[]): void;
eject(...middleware: import("openapi-fetch").Middleware[]): void;
};
export type * from './types';
export default createPocketSmithClient;
//# sourceMappingURL=index.d.ts.map