///
declare type ReportData = any;
declare type Query = string;
declare type QueryResolver = (query: Query | undefined, queryVars: any) => ReportData | Promise;
declare type ErrorHandler = (e: Error, raw_code?: string) => any;
declare type RunJSFunc = (o: {
sandbox: Object;
ctx: Object;
}) => {
modifiedSandbox: Object;
result: any;
};
declare type UserOptions = {
/**
* Docx file template as a NodeJS Buffer or Buffer-like object in Browsers.
*/
template: Buffer;
/**
* Object of data to be injected or a (async) function that resolves to the data. The function gets as an argument the contents of the QUERY command as a string.
*/
data?: ReportData | QueryResolver;
/**
* Gets injected into data function as second argument.
*/
queryVars?: any;
/**
* Defines a custom command delimiter. This can be a String e.g. '+++' or an Array of Strings with length 2: ['{', '}'] in which the first element serves as the start delimiter and the second as the end delimiter.
*/
cmdDelimiter?: string | [string, string];
/**
* Can be used to change the delimiter in generated XML.
*/
literalXmlDelimiter?: string;
/**
* Handle linebreaks in result of commands as actual linebreaks (Default: true)
*/
processLineBreaks?: boolean;
/**
* INSECURE: Set this option to true to disable running all commands in a new JS-VM. USE ONLY WITH TRUSTED TEMPLATES. Beware of arbitrary code injection risks. Can slightly improve performance on complex templates.
*/
noSandbox?: boolean;
/**
* Custom sandbox. See documentation for details.
*/
runJs?: RunJSFunc;
/**
* Add functions or other static data to this option to have access to it in your commands.
*
* ```js
* additionalJsContext: {
* qrCode: url => {
* const dataUrl = createQrImage(url, { size: 500 });
* const data = dataUrl.slice('data:image/gif;base64,'.length);
* return { width: 6, height: 6, data, extension: '.gif' };
* },
* }
* ```
*/
additionalJsContext?: Object;
/**
* Whether to fail on the first error encountered in the template. Defaults to true. Can be used to collect all errors in a template (e.g. misspelled commands) before failing.
*/
failFast?: boolean;
/**
* When set to `true`, this setting ensures `createReport` throws a `NullishCommandResultError` when the result of an INS, HTML, IMAGE, or LINK command is `null` or `undefined`. This is useful as nullish return values usually indicate a mistake in the template or the invoking code. Defaults to `false`.
*/
rejectNullish?: boolean;
/**
* Custom error handler to catch any errors that may occur evaluating commands in the template. The value returned from this handler will be inserted into the template instead.
*/
errorHandler?: ErrorHandler;
/**
* MS Word usually autocorrects JS string literal quotes with unicode 'smart' quotes ('curly' quotes). E.g. 'aubergine' -> ‘aubergine’.
* This causes an error when evaluating commands containing these smart quotes, as they are not valid JavaScript.
* If you set fixSmartQuotes to 'true', these smart quotes will automatically get replaced with straight quotes (') before command evaluation.
* Defaults to false.
*/
fixSmartQuotes?: boolean;
};
declare type config = Omit;
declare type DATA = Record;
declare type Template = UserOptions["template"];
declare class Gotenberg {
protected url: string;
constructor(url: string);
fillDocToPdf(file: Template, data: DATA[], config?: config): Promise;
fillDocToPdf(file: Template, data: [DATA], config: config, onlyDocx: true): Promise;
}
export { Gotenberg };