type AuthToken = string | undefined; interface Auth { /** * Which part of the request do we use to send the auth? * * @default 'header' */ in?: 'header' | 'query' | 'cookie'; /** * Header or query parameter name. * * @default 'Authorization' */ name?: string; scheme?: 'basic' | 'bearer'; type: 'apiKey' | 'http'; } interface SerializerOptions { /** * @default true */ explode: boolean; style: T; } type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; type ObjectStyle = 'form' | 'deepObject'; type QuerySerializer = (query: Record) => string; type BodySerializer = (body: any) => any; type QuerySerializerOptionsObject = { allowReserved?: boolean; array?: Partial>; object?: Partial>; }; type QuerySerializerOptions = QuerySerializerOptionsObject & { /** * Per-parameter serialization overrides. When provided, these settings * override the global array/object settings for specific parameter names. */ parameters?: Record; }; type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace'; type Client$1 = { /** * Returns the final request URL. */ buildUrl: BuildUrlFn; getConfig: () => Config; request: RequestFn; setConfig: (config: Config) => Config; } & { [K in HttpMethod]: MethodFn; } & ([SseFn] extends [never] ? { sse?: never; } : { sse: { [K in HttpMethod]: SseFn; }; }); interface Config$1 { /** * Auth token or a function returning auth token. The resolved value will be * added to the request payload as defined by its `security` array. */ auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; /** * A function for serializing request body parameter. By default, * {@link JSON.stringify()} will be used. */ bodySerializer?: BodySerializer | null; /** * An object containing any HTTP headers that you want to pre-populate your * `Headers` object with. * * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} */ headers?: RequestInit['headers'] | Record; /** * The request method. * * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} */ method?: Uppercase; /** * A function for serializing request query parameters. By default, arrays * will be exploded in form style, objects will be exploded in deepObject * style, and reserved characters are percent-encoded. * * This method will have no effect if the native `paramsSerializer()` Axios * API function is used. * * {@link https://swagger.io/docs/specification/serialization/#query View examples} */ querySerializer?: QuerySerializer | QuerySerializerOptions; /** * A function validating request data. This is useful if you want to ensure * the request conforms to the desired shape, so it can be safely sent to * the server. */ requestValidator?: (data: unknown) => Promise; /** * A function transforming response data before it's returned. This is useful * for post-processing data, e.g. converting ISO strings into Date objects. */ responseTransformer?: (data: unknown) => Promise; /** * A function validating response data. This is useful if you want to ensure * the response conforms to the desired shape, so it can be safely passed to * the transformers and returned to the user. */ responseValidator?: (data: unknown) => Promise; } type ServerSentEventsOptions = Omit & Pick & { /** * Fetch API implementation. You can use this option to provide a custom * fetch instance. * * @default globalThis.fetch */ fetch?: typeof fetch; /** * Implementing clients can call request interceptors inside this hook. */ onRequest?: (url: string, init: RequestInit) => Promise; /** * Callback invoked when a network or parsing error occurs during streaming. * * This option applies only if the endpoint returns a stream of events. * * @param error The error that occurred. */ onSseError?: (error: unknown) => void; /** * Callback invoked when an event is streamed from the server. * * This option applies only if the endpoint returns a stream of events. * * @param event Event streamed from the server. * @returns Nothing (void). */ onSseEvent?: (event: StreamEvent) => void; serializedBody?: RequestInit['body']; /** * Default retry delay in milliseconds. * * This option applies only if the endpoint returns a stream of events. * * @default 3000 */ sseDefaultRetryDelay?: number; /** * Maximum number of retry attempts before giving up. */ sseMaxRetryAttempts?: number; /** * Maximum retry delay in milliseconds. * * Applies only when exponential backoff is used. * * This option applies only if the endpoint returns a stream of events. * * @default 30000 */ sseMaxRetryDelay?: number; /** * Optional sleep function for retry backoff. * * Defaults to using `setTimeout`. */ sseSleepFn?: (ms: number) => Promise; url: string; }; interface StreamEvent { data: TData; event?: string; id?: string; retry?: number; } type ServerSentEventsResult = { stream: AsyncGenerator ? TData[keyof TData] : TData, TReturn, TNext>; }; type ErrInterceptor = (error: Err, response: Res, request: Req, options: Options) => Err | Promise; type ReqInterceptor = (request: Req, options: Options) => Req | Promise; type ResInterceptor = (response: Res, request: Req, options: Options) => Res | Promise; declare class Interceptors { fns: Array; clear(): void; eject(id: number | Interceptor): void; exists(id: number | Interceptor): boolean; getInterceptorIndex(id: number | Interceptor): number; update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false; use(fn: Interceptor): number; } interface Middleware { error: Interceptors>; request: Interceptors>; response: Interceptors>; } type ResponseStyle = 'data' | 'fields'; interface Config extends Omit, Config$1 { /** * Base URL for all requests made by this client. */ baseUrl?: T['baseUrl']; /** * Fetch API implementation. You can use this option to provide a custom * fetch instance. * * @default globalThis.fetch */ fetch?: typeof fetch; /** * Please don't use the Fetch client for Next.js applications. The `next` * options won't have any effect. * * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. */ next?: never; /** * Return the response data parsed in a specified format. By default, `auto` * will infer the appropriate method from the `Content-Type` response header. * You can override this behavior with any of the {@link Body} methods. * Select `stream` if you don't want to parse response data at all. * * @default 'auto' */ parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text'; /** * Should we return only data or multiple fields (data, error, response, etc.)? * * @default 'fields' */ responseStyle?: ResponseStyle; /** * Throw an error instead of returning it in the response? * * @default false */ throwOnError?: T['throwOnError']; } interface RequestOptions extends Config<{ responseStyle: TResponseStyle; throwOnError: ThrowOnError; }>, Pick, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> { /** * Any body that you want to add to your request. * * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} */ body?: unknown; path?: Record; query?: Record; /** * Security mechanism(s) to use for the request. */ security?: ReadonlyArray; url: Url; } interface ResolvedRequestOptions extends RequestOptions { serializedBody?: string; } type RequestResult = ThrowOnError extends true ? Promise ? TData[keyof TData] : TData : { data: TData extends Record ? TData[keyof TData] : TData; request: Request; response: Response; }> : Promise ? TData[keyof TData] : TData) | undefined : ({ data: TData extends Record ? TData[keyof TData] : TData; error: undefined; } | { data: undefined; error: TError extends Record ? TError[keyof TError] : TError; }) & { request: Request; response: Response; }>; interface ClientOptions { baseUrl?: string; responseStyle?: ResponseStyle; throwOnError?: boolean; } type MethodFn = (options: Omit, 'method'>) => RequestResult; type SseFn = (options: Omit, 'method'>) => Promise>; type RequestFn = (options: Omit, 'method'> & Pick>, 'method'>) => RequestResult; type BuildUrlFn = ; query?: Record; url: string; }>(options: TData & Options) => string; type Client = Client$1 & { interceptors: Middleware; }; interface TDataShape { body?: unknown; headers?: unknown; path?: unknown; query?: unknown; url: string; } type OmitKeys = Pick>; type Options = OmitKeys, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit); type ReverseGeocodeSuccess = { place?: { id?: string | number; distance_within_meters?: number; address?: string; area?: string; city?: string; postCode?: string; address_bn?: string; area_bn?: string; city_bn?: string; country?: string; division?: string; district?: string; sub_district?: string; pauroshova?: string | null; union?: string | null; location_type?: string; address_components?: { place_name?: string | null; house?: string | null; road?: string | null; } | null; area_components?: { area?: string | null; sub_area?: string | null; } | null; thana?: string; thana_bn?: string; }; status?: number; }; type AutocompleteSuccess = { places?: Array<{ id?: number; longitude?: string | number; latitude?: string | number; address?: string; address_bn?: string; city?: string; city_bn?: string; area?: string; area_bn?: string; postCode?: string | number; pType?: string; uCode?: string; }>; status?: number; }; type GeocodeSuccess = { given_address?: string; fixed_address?: string; bangla_address?: string; address_status?: 'complete' | 'incomplete'; geocoded_address?: { id?: string | number; Address?: string; address?: string; address_bn?: string; alternate_address?: string; area?: string; area_bn?: string; bounds?: string | null; business_name?: string | null; city?: string; city_bn?: string; created_at?: string; district?: string; geo_location?: Array; holding_number?: string | null; latitude?: string; location?: string; location_shape?: string; longitude?: string; match_freq?: number; match_fuzzy?: number; matching_diff?: number; new_address?: string; pType?: string; place_code?: string; place_name?: string | null; popularity_ranking?: number; postCode?: string | number; postcode?: string | number; road_name_number?: string | null; score?: number; subType?: string; sub_area?: string | null; sub_district?: string; sub_type?: string; super_sub_area?: string | null; thana?: string; type?: string; uCode?: string; union?: string | number | null; unions?: string | number | null; updated_at?: string; user_id?: number; }; confidence_score_percentage?: number; status?: number; }; type RouteOverviewSuccess = { code?: string; routes?: Array<{ /** * Encoded polyline (string) or GeoJSON (object) */ geometry?: string | { [key: string]: unknown; }; legs?: Array<{ steps?: Array<{ [key: string]: unknown; }>; /** * Distance in meters */ distance?: number; /** * Duration in seconds */ duration?: number; summary?: string; weight?: number; }>; distance?: number; duration?: number; weight_name?: string; weight?: number; }>; waypoints?: Array<{ hint?: string; distance?: number; name?: string | null; location?: [number, number]; }>; }; type SearchPlaceSuccess = { places?: Array<{ address?: string; place_code?: string; }>; session_id?: string; status?: number; }; type PlaceDetailsSuccess = { place?: { address?: string; place_code?: string; latitude?: string; longitude?: string; }; session_id?: string; status?: number; }; type SnapToRoadSuccess = { coordinates?: [number, number]; /** * Distance in meters */ distance?: number; type?: 'Point'; }; type NearbySuccess = { places?: Array<{ id?: number; name?: string; distance_in_meters?: string | number; longitude?: string; latitude?: string; pType?: string; Address?: string; area?: string; city?: string; postCode?: string; subType?: string; uCode?: string; }>; status?: number; }; type CalculateRouteSuccess = { hints?: { 'visited_nodes.sum'?: number; 'visited_nodes.average'?: number; }; info?: { copyrights?: Array; took?: number; road_data_timestamp?: string; }; paths?: Array<{ /** * Distance in meters */ distance?: number; weight?: number; /** * Time in milliseconds */ time?: number; transfers?: number; points_encoded?: boolean; bbox?: [number, number, number, number]; /** * GeoJSON LineString with route coordinates */ points?: { type?: 'LineString'; coordinates?: Array<[number, number]>; }; instructions?: Array<{ distance?: number; heading?: number; sign?: number; interval?: [number, number]; text?: string; time?: number; street_name?: string; }>; legs?: Array<{ [key: string]: unknown; }>; details?: Array<{ [key: string]: unknown; }>; ascend?: number; descend?: number; snapped_waypoints?: { type?: 'LineString'; coordinates?: Array<[number, number]>; }; }>; }; type CheckNearbySuccess = { message?: string; status?: number; data?: { id?: string; name?: string; radius?: string; latitude?: string; longitude?: string; user_id?: number; }; }; type MissingParameter = { message?: string; status?: number; }; type NoRegisteredKey = { message?: string; status?: number; }; type PaymentException = { message?: string; status?: number; }; type ApiLimitExceeded = { message?: string; status?: number; }; /** * Reverse Geocoding Parameters * Convert coordinates to address */ type ReverseGeocodeParams = { /** Longitude coordinate (required) * @minimum -180 * @maximum 180 */ longitude: number; /** Latitude coordinate (required) * @minimum -90 * @maximum 90 */ latitude: number; /** Country code (ISO Alpha-2 format, e.g., 'BD') * @default 'BD' */ country_code?: string; country?: boolean; district?: boolean; post_code?: boolean; sub_district?: boolean; union?: boolean; pauroshova?: boolean; location_type?: boolean; division?: boolean; address?: boolean; area?: boolean; bangla?: boolean; thana?: boolean; }; /** * Autocomplete Parameters * Search for places with autocomplete suggestions */ type AutocompleteParams = { /** Search query string (required) * @minLength 1 */ q: string; /** Include Bangla language fields * @default true */ bangla?: boolean; }; /** * Geocode (Rupantor) Parameters * Format and geocode addresses */ type GeocodeParams = { /** Address to geocode (required) * @minLength 1 */ q: string; thana?: 'yes' | 'no'; district?: 'yes' | 'no'; bangla?: 'yes' | 'no'; }; /** * Search Place Parameters * Search for places and get session IDs */ type SearchPlaceParams = { /** Search query string (required) * @minLength 1 */ q: string; }; /** * Place Details Parameters * Get detailed information about a specific place */ type PlaceDetailsParams = { /** Place code from search place results (required) * @minLength 1 */ place_code: string; /** Session ID from search place results (required) * @minLength 1 */ session_id: string; }; /** * Nearby Parameters * Find places within a specified radius */ type NearbyParams = { /** Longitude coordinate (required) * @minimum -180 * @maximum 180 */ longitude: number; /** Latitude coordinate (required) * @minimum -90 * @maximum 90 */ latitude: number; /** Search radius in kilometers * @minimum 0.1 * @maximum 100 * @default 0.5 */ radius?: number; /** Maximum number of results * @minimum 1 * @maximum 100 * @default 10 */ limit?: number; }; /** * Check Nearby Parameters * Verify if a destination is within a specified radius of current location */ type CheckNearbyParams = { /** Destination latitude coordinate (required) * @minimum -90 * @maximum 90 */ destination_latitude: number; /** Destination longitude coordinate (required) * @minimum -180 * @maximum 180 */ destination_longitude: number; /** Radius in meters (required) * @minimum 1 * @maximum 1000 */ radius: number; /** Current latitude coordinate (required) * @minimum -90 * @maximum 90 */ current_latitude: number; /** Current longitude coordinate (required) * @minimum -180 * @maximum 180 */ current_longitude: number; }; /** * Snap to Road Parameters * Snap GPS coordinates to the nearest road segment */ type SnapToRoadParams = { /** Point coordinates in format "latitude,longitude" (required) * @format "latitude,longitude" * @example "23.8103,90.4125" */ point: string; }; /** * Route Overview Parameters * Get basic route information between two points */ type RouteOverviewParams = { /** Coordinates in format "lon,lat;lon,lat" (required) * @format "lon,lat;lon,lat" * @example "90.4125,23.8103;90.3742,23.7461" */ coordinates: string; /** Geometry format for the route * @default 'polyline' */ geometries?: 'polyline' | 'polyline6' | 'geojson'; /** Transportation profile * @default 'car' */ profile?: 'car' | 'foot'; }; /** * Calculate Route Parameters * Calculate detailed route between two points */ type CalculateRouteParams = { /** Start point coordinates (required) */ start: { /** Start latitude * @minimum -90 * @maximum 90 */ latitude: number; /** Start longitude * @minimum -180 * @maximum 180 */ longitude: number; }; /** Destination point coordinates (required) */ destination: { /** Destination latitude * @minimum -90 * @maximum 90 */ latitude: number; /** Destination longitude * @minimum -180 * @maximum 180 */ longitude: number; }; /** Route calculation type * @default 'gh' */ type: 'gh'; /** Transportation profile */ profile?: 'car' | 'motorcycle' | 'bike'; }; interface BarikoiConfig { apiKey: string; baseUrl?: string; timeout?: number; } /** * Barikoi API Client * A TypeScript SDK for Barikoi Location APIs */ declare class BarikoiClient { private apiKey; private timeout; constructor(config: BarikoiConfig); /** * Creates a fetch function with timeout support */ private createFetchWithTimeout; /** * Set API key */ setApiKey(apiKey: string): void; /** * Get current API key */ getApiKey(): string; /** * Set timeout for API requests * @param timeout - Timeout in milliseconds */ setTimeout(timeout: number): void; /** * Get current timeout setting */ getTimeout(): number; /** * Reverse Geocoding - Convert coordinates to address */ reverseGeocode(params: ReverseGeocodeParams): Promise<({ data: ReverseGeocodeSuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Autocomplete - Search for places */ autocomplete(params: AutocompleteParams): Promise<({ data: AutocompleteSuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Geocode - Format and geocode addresses */ geocode(params: GeocodeParams): Promise<({ data: GeocodeSuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Search Place */ searchPlace(params: SearchPlaceParams): Promise<({ data: SearchPlaceSuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Place Details - get place info */ placeDetails(params: PlaceDetailsParams): Promise<({ data: PlaceDetailsSuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Nearby - Find nearby places */ nearby(params: NearbyParams): Promise<({ data: NearbySuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Check nearby - verify proximity */ checkNearby(params: CheckNearbyParams): Promise<({ data: CheckNearbySuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Calculate Route */ calculateRoute(params: CalculateRouteParams): Promise<({ data: CalculateRouteSuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Snap to Road */ snapToRoad(params: SnapToRoadParams): Promise<({ data: SnapToRoadSuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Optimize Route - optimize waypoints */ /** * Route Overview - basic route info */ routeOverview(params: RouteOverviewParams): Promise<({ data: RouteOverviewSuccess; error: undefined; } | { data: undefined; error: MissingParameter | NoRegisteredKey | PaymentException | ApiLimitExceeded; }) & { request: Request; response: Response; }>; /** * Get client instance with API key pre-configured */ getConfiguredClient(): Client; } /** * Create a new Barikoi client instance * * @example * ```typescript * const barikoi = createBarikoiClient({ * apiKey: 'your-api-key' * }) * * const result = await barikoi.autocomplete({ * q: 'Dhaka', * bangla: true * }) * ``` */ declare function createBarikoiClient(config: BarikoiConfig): BarikoiClient; declare class BarikoiError extends Error { readonly statusCode?: number | undefined; readonly code?: string | undefined; readonly details?: unknown | undefined; constructor(message: string, statusCode?: number | undefined, code?: string | undefined, details?: unknown | undefined); isAuthError(): boolean; isRateLimitError(): boolean; isServerError(): boolean; } declare class ValidationError extends BarikoiError { constructor(message: string, details?: unknown); } declare class TimeoutError extends BarikoiError { constructor(message?: string); } export { BarikoiClient, BarikoiError, TimeoutError, ValidationError, createBarikoiClient }; export type { AutocompleteParams, BarikoiConfig, CalculateRouteParams, CheckNearbyParams, GeocodeParams, NearbyParams, PlaceDetailsParams, ReverseGeocodeParams, RouteOverviewParams, SearchPlaceParams, SnapToRoadParams };