next-api-og-image-sparticuz
Version:
Easy way to generate open-graph images dynamically using Next.js API Routes.
36 lines (35 loc) • 1.84 kB
TypeScript
/// <reference types="node" />
import type { NextApiRequest, NextApiResponse } from 'next';
import type { RequireExactlyOne } from 'type-fest';
import type { ReactElement } from 'react';
declare const STRATEGY_OPTIONS: readonly ["body", "query"];
declare type StrategyOption = typeof STRATEGY_OPTIONS[number];
declare type ImageType = 'png' | 'jpeg' | 'webp';
declare type StrategyAwareParams<T extends StrategyOption = 'query', StrategyDetails extends string | object = string> = T extends 'body' ? StrategyDetails : Record<StrategyDetails extends string ? StrategyDetails : string, NonNullable<string>>;
declare type NextApiRequestWithOgImage = {
image: string | Buffer;
};
declare type ChromeOptions = {
args?: string[];
executable?: string;
};
export declare type NextApiOgImageConfig<Strategy extends StrategyOption, StrategyDetails extends string | object = string> = {
template: RequireExactlyOne<Partial<{
html: (params: StrategyAwareParams<Strategy, StrategyDetails>) => string | Promise<string>;
react: (params: StrategyAwareParams<Strategy, StrategyDetails>) => ReactElement | Promise<ReactElement>;
}>, 'html' | 'react'>;
strategy?: StrategyOption;
cacheControl?: string;
width?: number;
height?: number;
type?: ImageType;
quality?: number;
hook?: (request: NextApiRequestWithOgImage) => Map<string, string> | Promise<Map<string, string>>;
chrome?: ChromeOptions;
dev?: Partial<{
inspectHtml: boolean;
errorsInResponse: boolean;
}>;
};
export declare function withOGImage<Strategy extends StrategyOption = 'query', StrategyDetails extends string | object = string>(options: NextApiOgImageConfig<Strategy, StrategyDetails>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
export {};