UNPKG

@flyyer/flyyer-lite

Version:

Flyyer.io helper classes and methods to generate smart URL to render images.

89 lines (88 loc) 3.56 kB
import type { IStringifyOptions } from "qs"; import type { FlyyerCommonParams } from "./common"; import type { FlyyerExtension } from "./ext"; import type { FlyyerMetaVariables } from "./meta"; import type { FlyyerVariables } from "./variables"; /** * These are the parameters required (some are optional) to create an URL that will render Flyyer images. * * Required is: `tenant`, `deck`, `template`. * * Set and override the variables of the template by using the `variables` object. * * Example: https://cdn.flyyer.io/r/v2/flyyer/default/main.jpeg?title=Thanks+for+reading+this * @example * const flyyer = new FlyyerRender({ * tenant: "flyyer", * deck: "default", * template: "main", * variables: { title: "Thanks for reading this" }, * }); * console.log(flyyer.href()) * // https://cdn.flyyer.io/r/v2/flyyer/default/main.jpeg?title=Thanks+for+reading+this */ export interface FlyyerRenderParams<T extends FlyyerVariables> extends FlyyerCommonParams<T> { /** * Your tenant's `slug`. Lowercase and no spaces. * Visit https://flyyer.io/dashboard to get this value for your project */ tenant: string; /** * Your deck's `slug`. Lowercase and no spaces. * Visit https://flyyer.io/dashboard to get this value for your project */ deck: string; /** * Your template's `slug`. Lowercase and no spaces. * Visit https://flyyer.io/dashboard to get this value for your project */ template: string; } /** * This class helps you creating URLs that will render Flyyer images. * * Required is: `tenant`, `deck`, `template`. * * Set and override the variables of the template by using the `variables` object. * * Example: https://cdn.flyyer.io/r/v2/flyyer/default/main.jpeg?title=Thanks+for+reading+this * @example * const flyyer = new FlyyerRender({ * tenant: "flyyer", * deck: "default", * template: "main", * variables: { title: "Thanks for reading this" }, * }); * console.log(flyyer.href()) * // https://cdn.flyyer.io/r/v2/flyyer/default/main.jpeg?title=Thanks+for+reading+this */ export declare class FlyyerRender<T extends FlyyerVariables = FlyyerVariables> implements FlyyerRenderParams<T> { tenant: string; deck: string; template: string; version?: string | number | undefined | null; extension?: FlyyerExtension | undefined | null; variables: T; meta: FlyyerMetaVariables; secret?: string | undefined | null; strategy?: "JWT" | "HMAC" | undefined | null; constructor(args: FlyyerRenderParams<T>); /** * Override this method to implement signatures. Must be synchronous (no `Promise` allowed). */ sign(deck: FlyyerRenderParams<T>["deck"], template: FlyyerRenderParams<T>["template"], version: FlyyerRenderParams<T>["version"], extension: FlyyerRenderParams<T>["extension"], variables: FlyyerRenderParams<T>["variables"], meta: NonNullable<FlyyerRenderParams<T>["meta"]>, strategy: FlyyerRenderParams<T>["strategy"], secret: FlyyerRenderParams<T>["secret"]): string | undefined | void; querystring(extra?: any, options?: IStringifyOptions): string; /** * Generate final URL you can use in your og:images. * @example * <meta property="og:image" content={flyyer.href()} /> * @example * const flyyer = new FlyyerRender({ meta: { v: null } }); * <img src={flyyer.href()} /> */ href(): string; /** * Alias of `.href()` */ toString(): string; }