UNPKG

@eldev/business-central-api

Version:

A Dynamics 365 Business Central client for TypeScript

53 lines 2.39 kB
import { ApiPage } from "../pages/api-page.js"; import { ApiQuery } from "../pages/api-query.js"; import type { StandardSchemaV1 } from "../validation/standard-schema.js"; export declare const BC_BASE_URL = "https://api.businesscentral.dynamics.com/v2.0"; export declare const DEFAULT_TIMEOUT = 30000; export declare const BC_DEFAULT_SCOPE = "https://api.businesscentral.dynamics.com/.default"; export type BCConfig = { tenantId: string; environment: string; companyId: string; timeout?: number; baseURL?: string; userAgent?: string; }; /** The options used for an individual request. */ export type RequestOpts = { method?: "GET" | "POST" | "PATCH" | "DELETE"; params?: URLSearchParams; payload?: unknown; timeout?: number; serverPageSize?: number; }; /** Satisfies the \@azure/identity TokenCredential. Can also use MSAL-node. */ export interface AuthClient { getToken(scope: string): Promise<string>; } /** Business Central API client. Use one client per API path. Takes an * AuthClient that is satisfied by \@azure/identity or msal-node. */ export declare class BCClient { readonly auth: AuthClient; readonly apiPath: string; readonly apiURL: string; readonly scope = "https://api.businesscentral.dynamics.com/.default"; readonly userAgent: string; readonly timeout: number; constructor(config: BCConfig, apiPath: string, authClient: AuthClient); /** Gets the auth token. */ getToken(): Promise<string>; /** Makes a request to the BC server. * Returns the raw response body or throws a BCError. */ request(endpoint: string, opts?: RequestOpts): Promise<unknown>; /** Internally calls request and then parses the data against the provided schema. */ requestWithSchema<TSchema extends StandardSchemaV1>(endpoint: string, schema: TSchema, opts?: RequestOpts): Promise<StandardSchemaV1.InferOutput<TSchema>>; /** Returns a typed ApiPage for an endpoint and Standard Schema of a record. * Chain the method withCommands to add types the create, update, and action methods. */ for<T>(endpoint: string, schema: StandardSchemaV1<unknown, T>): ApiPage<T>; /** Returns a typed ApiQuery for an endpoint and Standard Schema of a record. */ forQuery<T>(endpoint: string, schema: StandardSchemaV1<unknown, T>): ApiQuery<T>; } //# sourceMappingURL=client.d.ts.map