import ConversionParameters from './conversion-parameters' import Parameters, { StorageOptions } from './parameters' type Optional = T|null|undefined export default class MergeParameters implements Parameters { private documents: ConversionParameters[] = [] private params: { [key: string]: any } = {} /** * Add a document to the PDF. */ addDocument(document: ConversionParameters) { this.documents.push(document) return this } /** * Add multiple documents to the PDF. */ addDocuments(documents: ConversionParameters[]) { this.documents.push(...documents) return this } /** * Secure the PDF with an owner password. */ ownerPassword(password: Optional) { this.params.ownerPassword = password return this } /** * Secure the PDF with a user password. */ userPassword(password: Optional) { this.params.userPassword = password return this } /** * Secure the PDF with an owner and a user password. */ passwords(owner: Optional, user: Optional) { return this.ownerPassword(owner).userPassword(user) } /** * Serve the PDF via the CDN. */ cdn(cdn: Optional = true) { this.params.cdn = cdn return this } /** * Upload the PDF directly to the user's configured storage disk. */ storage(options?: Partial|boolean) { this.params.storage = options ? options : true return this } all() { return { documents: this.documents.map(doc => doc.all()), ...this.params, } as { [key: string]: any } } }