UNPKG

@flyyer/flyyer-lite

Version:

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

82 lines (81 loc) 3.24 kB
import type { IStringifyOptions } from "qs"; import type { FlyyerCommonParams } from "./common"; import type { FlyyerExtension } from "./ext"; import type { FlyyerMetaVariables } from "./meta"; import { FlyyerPath } from "./paths"; import type { FlyyerVariables } from "./variables"; /** * This class helps you creating URLs that will render Flyyer images. * * Required is: `project`. * * Set default variables by using the `variables` object. * * Example: https://cdn.flyyer.io/v2/flyyer-com/_/_/marketplace/simple-fade * @example * const flyyer = new Flyyer({ * project: "flyyer-com", * route: "simple-fade", * }); * console.log(flyyer.href()) * // https://cdn.flyyer.io/v2/flyyer-com/_/_/marketplace/templates/simple-fade */ export interface FlyyerParams<T extends FlyyerVariables> extends FlyyerCommonParams<T> { /** * Your project's `slug`. Lowercase and no spaces. * Visit https://flyyer.io/dashboard to get this value for your project */ project: string; /** * Preferred way of declaring the default social image to use along with Flyyer. It will be available as `{{ page.image }}` and `{{ flyyer.default }}`. **Use an absolute URL**, but relative URLs are also supported. * * Alternatively you can set a custom meta-tag but it was worst performance: `<meta property="flyyer:default" content="" />`. * * Values defined here takes precedence over `flyyer:default` meta-tag. */ default?: string | undefined | null; /** * Current page path we will use in conjunction with the base URL defined in the Flyyer's Dashboard of your project. * @example * const flyyer = new Flyyer({ path: "/" }); * @example * const flyyer = new Flyyer({ path: "/about" }); * @example * const flyyer = new Flyyer({ path: "/products/1" }); * @example * const flyyer = new Flyyer({ path: ["products", "1"] }); * @example * const flyyer = new Flyyer({ path: "/page?id=1" }); */ path?: FlyyerPath; } export declare class Flyyer<T extends FlyyerVariables = FlyyerVariables> implements FlyyerParams<T> { project: string; default?: string | undefined | null; path?: FlyyerPath; extension?: FlyyerExtension | undefined | null; variables: T; meta: FlyyerMetaVariables; secret?: string | undefined | null; strategy?: "JWT" | "HMAC" | undefined | null; constructor(args: FlyyerParams<T>); /** * Override this method to implement signatures. Must be synchronous (no `Promise` allowed). */ sign(project: FlyyerParams<T>["project"], path: string, // normalized params: string, strategy: FlyyerParams<T>["strategy"], secret: FlyyerParams<T>["secret"]): string | undefined | void; params(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 Flyyer({ meta: { v: null } }); * <img src={flyyer.href()} /> */ href(): string; /** * Alias of `.href()` */ toString(): string; }