UNPKG

beckn-typescript

Version:

Beckn Protocol Client & Server Tools for Typescript

104 lines (101 loc) 3.16 kB
import { Context, Env } from 'hono'; export type ExamplePaths = { [K in string | number | symbol]: { post: { requestBody?: { content: { "application/json": any; }; }; responses: { default: { headers: { [name: string]: unknown; }; content: { "application/json": any; }; }; }; }; }; }; export type Prettify<T> = { [K in keyof T]: T[K]; } & {}; export type ExtractBody<B extends ExamplePaths[string]["post"]["requestBody"]> = B extends { content: { "application/json": any; }; } ? B["content"]["application/json"] : never; export type ExtractResponse<B extends ExamplePaths[string]["post"]["responses"]["default"]> = B extends { content: { "application/json": any; }; } ? B["content"]["application/json"] : never; export type ExtractPathWithoutSlash<T extends string | number | symbol> = T extends `/${infer Rest}` ? Rest : T; export type metaPath = typeof import("../type/meta"); export type registryPath = typeof import("../type/registry"); export type transactionPath = typeof import("../type/transaction"); declare const beckn: <P extends ExamplePaths, H extends Env = {}, T extends keyof ExamplePaths = keyof P>(tools: Record<ExtractPathWithoutSlash<T>, (c: Context<H>, body: Prettify<ExtractBody<P[T]["post"]["requestBody"]>>) => Promise<Prettify<ExtractResponse<P[T]["post"]["responses"]["default"]>>>>) => import("hono").MiddlewareHandler<any, string, {}>; /** * Example usage of the `transactionServer` middleware. * * @example * import { Hono } from "hono"; * import { transactionServer } from "beckn-typescript/server/hono"; * * const app = new Hono(); * * // Use the transactionServer middleware * app.use("/:path", transactionServer({ * search: async (c, body) => { * return { * message: { * ack: { * status: "ACK", * }, * }, * }; * } * // more tools * })); * * export default app; */ export declare const transactionServer: <E extends Env>(...args: Parameters<typeof beckn<transactionPath, E>>) => import("hono").MiddlewareHandler<any, string, {}>; /** * Example usage of the `metaServer` middleware. * * @example * import { Hono } from "hono"; * import { metaServer } from "beckn-typescript/server/hono"; * * const app = new Hono(); * * // Use the metaServer middleware * app.use("/:path", metaServer({ * // more tools * })); * * export default app; */ export declare const metaServer: <E extends Env>(...args: Parameters<typeof beckn<metaPath, E>>) => import("hono").MiddlewareHandler<any, string, {}>; /** * Example usage of the `registryServer` middleware. * * @example * import { Hono } from "hono"; * import { registryServer } from "beckn-typescript/server/hono"; * * const app = new Hono(); * * // Use the registryServer middleware * app.use("/:path", registryServer({ * // more tools * })); * * export default app; */ export declare const registryServer: <E extends Env>(...args: Parameters<typeof beckn<registryPath, E>>) => import("hono").MiddlewareHandler<any, string, {}>; export {};