@adobe/pdftools-extract-node-sdk
Version:
The Document Services PDF Tools Extract Node.js SDK provides APIs for extracting elements and renditions from PDF
69 lines (59 loc) • 2.16 kB
JavaScript
/*
* Copyright 2019 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it. If you have received this file from a source other than Adobe,
* then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
*/
const InternalExecutionContext = require('./internal/internal-execution-context');
/**
*
* Represents the execution context of an Operation. An execution context typically consists of the desired
* authentication credentials and client configurations such as timeouts.
* <p>
* For each set of credentials, a ExecutionContext instance can be reused across operations.
*
* Sample Usage:
* <pre class="prettyprint">
* <code>
* const executionContext = PDFToolsSdk.ExecutionContext.createFromFile('pdftools-api-credentials.json'),
* extractPDFOperation = PDFToolsSdk.ExtractPDF.Operation.createNew(),
* input = PDFToolsSdk.FileRef.createFromLocalFile('files/resources/extractPDFInput.pdf');
*
* extractPDFOperation.setInput(input);
*
* extractPDFOperation.execute(executionContext)
* .then(result => result.saveAsFile('output/extractPdf.zip'))
* .catch(err => console.log(err));
* </pre>
* </code>
* @hideconstructor
*
*/
class ExecutionContext {
constructor() {
}
/**
*
* Creates a context instance using the provided {@link Credentials} and {@link ClientConfig}.
* @memberOf ExecutionContext
* @function
* @param {!Credentials} credentials - A {@link Credentials} instance
* @param {ClientConfig=} clientConfig - A {@link ClientConfig} instance for providing custom http timeouts
* @returns {ExecutionContext} A new ExecutionContext instance.
*
*/
static create(credentials, clientConfig) {
if(!credentials){
new Error("Credentials cannot be null")
}
let internalExecutionContext = new InternalExecutionContext(credentials, clientConfig);
Object.freeze(internalExecutionContext);
return internalExecutionContext;
}
}
Object.freeze(ExecutionContext);
module.exports = ExecutionContext;