UNPKG

kutt

Version:

Node.js & browser (TypeScript) client for Kutt url shortener

142 lines (141 loc) 3.11 kB
import API from "#src/API"; /** * * @see {@link https://docs.kutt.it/#tag/links} * @example * const links = new Link(config); */ export default class Link extends API { /** * * @protected */ protected readonly prefix = "/links"; /** * Creates a short link. * * @param link * @example * const link = await links.create({ * target: "string", * description: "string", * expire_in: "2 minutes/hours/days", * password: "string", * customurl: "string", * reuse: false, * domain: "string", * }); */ create(link: NewLinkT): Promise<LinkI>; /** * Gets list of links. * * @param params * @param [params.skip=0] * @param [params.limit=10] * @param [params.all=false] * @example * const list = await links.list(); * @example * const list = await links.list({ * skip: 0, * limit: 10, * all: 10, * }); */ list(params?: ListLinkParamsI): Promise<ListLinkResultI>; /** * Deletes a link. * * @param id * @example * const message = await links.remove(link.id); */ remove(id: string): Promise<string>; /** * Gets link stats. * * @param id * @example * const stats = await links.stats(link.id); */ stats(id: string): Promise<LinkStatsI>; /** * Updates a link. * * @param id * @param link * @example * const updatedLink = await links.update(link.id, { * target: "string", * address: "string", * description: "string", * expire_in: "2 minutes/hours/days", * }); */ update(id: string, link: UpdateLinkT): Promise<LinkI>; } export interface ListLinkParamsI { all?: boolean; limit?: number; skip?: number; } export interface ListLinkResultI { data: LinkI[]; limit: number; skip: number; total: number; } export interface LinkI { address: string; banned: boolean; created_at: Date; description: string; id: string; link: string; password: boolean; target: string; updated_at: Date; visit_count: number; } export declare type NewLinkT = { customurl?: string; description?: string; domain?: string; expire_in?: string; password?: string; reuse?: boolean; target: string; }; export declare type UpdateLinkT = { address: string; description?: string; expire_in?: string; target: string; }; export interface LinkStatsI { address: string; banned: boolean; created_at: Date; id: string; link: string; password: boolean; target: string; updatedAt: string; updated_at: Date; visit_count: number; } export interface LinkDurationStatsI { stats: LinkStatDetailsI[]; views: number[]; } export interface LinkStatDetailsI { browser: LinkStatDetailI[]; country: LinkStatDetailI[]; os: LinkStatDetailI[]; referrer: LinkStatDetailI[]; } export interface LinkStatDetailI { name: string; value: number; }