@adobe/pdftools-extract-node-sdk
Version:
The Document Services PDF Tools Extract Node.js SDK provides APIs for extracting elements and renditions from PDF
57 lines (47 loc) • 1.85 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 InternalClientConfig = require('./internal-client-config'),
AuthenticatorFactory = require('./auth/authenticator-factory');
ServiceAccountCredentials = require('../auth/service-account-credentials'),
HttpRequest = require('../internal/http/http-request'),
CPFServiceRequestContext = require('./cpf/cpf-service-request-context');
class InternalExecutionContext{
constructor(credentials,clientConfig){
if (credentials instanceof ServiceAccountCredentials ) {
if (clientConfig instanceof InternalClientConfig)
this.clientConfig = clientConfig;
else
this.clientConfig = new InternalClientConfig();
this.clientConfig.validate();
this.credentials = credentials;
this.credentials.validate();
this.authenticator = AuthenticatorFactory.getAuthenticator(credentials);
this.cpfServiceRequestContext = new CPFServiceRequestContext(this.clientConfig);
} else {
throw new Error("Invalid Credentials provided as argument");
}
}
getClientConfig() {
return this.clientConfig;
}
getBaseRequestFromRequestContext(requestKey) {
let baseRequest = this.cpfServiceRequestContext.getBaseHttpRequest(requestKey);
baseRequest = baseRequest.withAuthenticator(this.authenticator);
return Promise.resolve(baseRequest);
}
validate(){
this.clientConfig.validate();
if (this.authenticator == null) {
throw new Error("Authentication not initialized in the provided context");
}
}
}
module.exports = InternalExecutionContext;