Collection of utils
To deploy the utils, you need to configurate your AWS CLI, then follow the next steps:
npm inpm run buildnpm run deploy
Request and Response payloads are limited to 5Mb and 30s by API Gateway.
Exceeding the limits may result in 413, 500, 502 errors.
-
POST /crop-image-
General
Operations that will be used on image are determined by fields passed in input's
config.
The order of operations is alwayscrop=>resize=>convert=>compress.-
Crop
Crop operation allows you to extract selected region of image by specifying starting point and region's size.
Region must not go out of image's bounds. -
Resize
Resize operation allows you to rescale your image and\or change it's aspect ratio.
If only one of dimensions is specified, original aspect ratio is preserved;
otherwise, image is cropped to fit the specified dimensions. -
Convert
Convert allows you to select output image's format.
Do not specify it to retain original format. -
Compress
Compress operation attempts applying compression options to an image.
Only supported by output format options will be applied (i.e. don't expectjpegto belossless).
Ifconvertisn't specified, compression is attempted using source image's format.
-
-
Input
type Input = { config: { crop?: { top: number; // non-negative integer left: number; // non-negative integer height: number; // positive integer width: number; // positive integer }; resize?: { height?: number; // positive integer width?: number; // positive integer }; convert?: { format: "jpeg" | "png" | "webp"; }; compress?: { quality?: number; // [1-100] range lossless?: boolean; }; }; image: File; };
Input must be passed as
multipart/form-data;
configobject must be JSON-stringified.
Only one file per request is supported. -
Output
type Output = string;
Result image is returned as
base64-encoded string, it gets decoded back into image by browsers automatically.
-
-
POST /generate-pdf-
Input
type Input = { source: URL | string | Buffer; pdfOptions?: { scale?: number; // Must be in [0.1 - 2] range displayHeaderFooter?: boolean; printBackground?: boolean; landscape?: boolean; pageRanges?: string; format?: "letter" | "legal" | "tabloid" | "ledger" | "a0" | "a1" | "a2" | "a3" | "a4" | "a5" | "a6"; // case-insensitive width?: string | number; height?: string | number; preferCSSPageSize?: boolean; margin?: { top?: string | number; bottom?: string | number; left?: string | number; right?: string | number; }; omitBackground?: boolean; timeout?: number; }; browserOptions?: { secondaryRenderAwait?: boolean; adBlocker?: boolean; width?: number; // Must be in [240-1920] range height?: number; // Must be in [240-1920] range }; };
-
source- Link to webpage or HTML string to be converted topdf.
⚠️ Invalid links will be resolved as HTML. -
pdfOptions-
scale- Scales the rendering of the web page.
Amount must be between0.1and2.
Default:1 -
displayHeaderFooter- Whether to show the header and footer.
Default:false -
headerTemplate,footerTemplate- HTML template for the print header\footer.
Should be valid HTML with the following classes used to inject values into them:-
date- formatted print date. -
title- document title. -
url- document location. -
pageNumber- current page number. -
totalPages- total pages in the document.
⚠️ marginmust be set for them to not be overlayed by main content. -
-
printBackground- Whether to print background graphics.
Default:true -
landscape- Whether to print in landscape orientation.
Default:false -
pageRanges- Paper ranges to print, e.g.1-5, 8, 11-13.
Empty value means all pages are printed.
Default:undefined -
format- Paper format ofpdf.
⚠️ If set, this takes priority over thewidthandheightoptions.
Default:'letter' -
width- Sets the width of paper.
⚠️ You can pass in a number or a string with a unit.
Default:undefined -
height- Sets the height of paper.
⚠️ You can pass in a number or a string with a unit.
Default:undefined -
preferCSSPageSize- Give any CSS@pagesize declared in the page priority over what is declared in thewidthorheightorformatoptions.
Default:undefined -
margin- Set the PDF margins.
⚠️ You can pass in numbers or strings with units.
Default:undefined -
omitBackground- Hides default white background and allows generating pdfs with transparency.
Default:false -
timeout- Timeout in milliseconds.
⚠️ Pass0to disable timeout.
Default:30_000
-
-
browserOptions-
secondaryRenderAwait- Whether to attempt to await for additional renders on a page.
Default:false -
adBlocker- Whether to attempt to block ads and cookie consent popups.
Default:false -
width,height- Custom viewport dimensions.
💬It is recommended to match viewport dimensiont topdfoutput dimensions.
Default:1920,1080
-
-
-
Output
type Output = string;
Result document is returned as
base64-encoded string, it gets decoded back intopdfby browsers automatically.
-
-
POST /send-mail-
Input
type Input = { credentials: { user: string; pass: string; }; mail: { to: string; subject?: string; text?: string; html?: string; }; };
-
credentials- Credentials of aGmailaccount you want to send a message from.-
user- Email -
pass- Application password
-
-
mail-
to- Recipient of the e-mail. -
subject- The subject of the e-mail. -
text- Theplaintextversion of the message. -
html- TheHTMLversion of the message.
-
-
-
Output
type Output = { message: string; };
-