UNPKG

@adobe/pdfservices-node-sdk

Version:

The Adobe PDF Services Node.js SDK provides APIs for creating, combining, exporting and manipulating PDFs.

195 lines 9.91 kB
"use strict"; /* * Copyright 2024 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.PDFServices = void 0; const ExecutionContext_1 = require("./internal/ExecutionContext"); const ValidationUtil_1 = require("./internal/util/ValidationUtil"); const PDFServicesHelper_1 = require("./internal/PDFServicesHelper"); /** * This class is the entry point for all the PDF Service utilities. * These utilities can be used to perform various functions such as submitting {@link PDFServicesJob}, * getting status of a {@link PDFServicesJob}, getting result of a {@link PDFServicesJob}, * uploading {@link Asset}, getting content of an {@link Asset}, deleting an {@link Asset} and refreshing an * {@link Asset}. * * <p> * Methods provided by the utility are: * <ul> * <li>Upload {@link Asset Asset(s)}</li> * <li>Submit {@link PDFServicesJob}</li> * <li>Get status of a {@link PDFServicesJob}</li> * <li>Get result of a {@link PDFServicesJob}</li> * <li>Get content of {@link Asset}</li> * <li>Delete {@link Asset}</li> * <li>Refresh {@link Asset}</li> * </ul> */ class PDFServices { /** * Constructs a `PDFServices` instance with the given `Credentials` and `ClientConfig`. * * @param params The parameters for constructing a `PDFServices` instance. * @param params.credentials Credentials to be used for authentication. Cannot be undefined. * @param [params.clientConfig] Client configuration for `PDFServices`. */ constructor(params) { ValidationUtil_1.ValidationUtil.validatePDFServicesParams(params); this._executionContext = new ExecutionContext_1.ExecutionContext(params.credentials, params.clientConfig); } /** * Upload content from read stream and returns an {@link Asset} to be used in PDF Services SDK. * * Method will not close the read stream, responsibility of closing the read stream lies with the client. * * @param params The parameters for uploading an asset. * @param params.readStream The read stream to be uploaded. Cannot be undefined. * @param params.mimeType The mime type of the read stream. Cannot be undefined. * * @returns A Promise that resolves to an {@link Asset} representing the uploaded content. * * @throws {@link ServiceApiError} Thrown if an error is encountered while submitting the job. * @throws {@link SDKError} Thrown for client-side or network errors. * @throws {@link ServiceUsageError} Thrown if service usage limits have been reached or credentials quota * has been exhausted. */ async upload(params) { ValidationUtil_1.ValidationUtil.validateUploadParams(params); return PDFServicesHelper_1.PDFServicesHelper.upload(this._executionContext, params.readStream, params.mimeType); } /** * Uploads content from read streams and returns a list of {@link Asset} to be used in PDF Services SDK. * * Method will not close the read stream, responsibility of closing the read stream lies with the client. * * @param params The parameters for uploading assets. * @param params.streamAssets The list of object containing read stream and mime type. Cannot be undefined. */ async uploadAssets(params) { ValidationUtil_1.ValidationUtil.validateUploadAssetsParams(params); return Promise.all(params.streamAssets.map((streamAsset) => { return PDFServicesHelper_1.PDFServicesHelper.upload(this._executionContext, streamAsset.readStream, streamAsset.mimeType); })); } /** * Submits the {@link PDFServicesJob} with the given {@link NotifierConfig} and returns the polling URL. * * @param params - The parameters for the submission. * @param params.job - The {@link PDFServicesJob} to be submitted. Cannot be undefined. * @param [params.notifiers] - List of {@link NotifierConfig} to be used for notification. * * @returns A Promise that resolves to a string representing polling URL that can be used to get the status * and result of the job. * * @throws {@link ServiceApiError} Thrown if an error is encountered while submitting the job. * @throws {@link SDKError} Thrown for client-side or network errors. * @throws {@link ServiceUsageError} Thrown if service usage limits have been reached or credentials quota has * been exhausted. */ async submit(params) { ValidationUtil_1.ValidationUtil.validateSubmitParams(params); return params.job.process(this._executionContext, params.notifiers); } /** * Returns {@link PDFServicesResponse} for the submitted {@link PDFServicesJob} result. * * @typeParam T - Type of result in {@link PDFServicesResponse}. It will be an implementation of * {@link PDFServicesJobResult}. * * @param params - The parameters for getting the job result. * @param params.pollingURL - The URL to be polled to get the job result. Cannot be undefined. * @param params.resultType - result class for {@link PDFServicesJob}, it will be an implementation of * {@link PDFServicesJobResult}. Cannot be undefined. * * @returns A Promise that resolves to a {@link PDFServicesResponse} encapsulating the result of the job. * * @throws {@link ServiceApiError} Thrown if an error is encountered while submitting the job. * @throws {@link SDKError} Thrown for client-side or network errors. * @throws {@link ServiceUsageError} Thrown if service usage limits have been reached or credentials quota has * been exhausted. */ async getJobResult(params) { ValidationUtil_1.ValidationUtil.validateGetJobResultParams(params); return PDFServicesHelper_1.PDFServicesHelper.getJobResult(this._executionContext, params.pollingURL, params.resultType); } /** * Returns {@link StreamAsset} for the submitted {@link Asset}. * * @param params - The parameters for getting the content. * @param params.asset - The {@link Asset} for which to retrieve the content. Cannot be undefined. * * @returns A Promise that resolves to a {@link StreamAsset} encapsulating the stream * content along with the media type. * * @throws {@link ServiceApiError} Thrown if an error is encountered while getting the content. * @throws {@link SDKError} Thrown for client-side or network errors. * @throws {@link ServiceUsageError} Thrown if service usage limits have been reached or credentials quota has * been exhausted. */ async getContent(params) { ValidationUtil_1.ValidationUtil.validateGetContentParams(params); return PDFServicesHelper_1.PDFServicesHelper.getContent(this._executionContext, params.asset); } /** * Deletes asset from PDF Services storage. * * @param params - The parameters for deleting the asset. * @param params.asset {@link Asset} asset to be deleted. Cannot be undefined. * * @returns A promise that resolves when the asset is deleted. * * @throws {@link ServiceApiError} Thrown if an error is encountered while getting the content. * @throws {@link SDKError} Thrown for client-side or network errors. * @throws {@link ServiceUsageError} Thrown if service usage limits have been reached or credentials quota has * been exhausted. */ async deleteAsset(params) { ValidationUtil_1.ValidationUtil.validateDeleteAssetParams(params); return PDFServicesHelper_1.PDFServicesHelper.deleteAsset(this._executionContext, params.asset); } /** * Returns {@link PDFServicesJobStatusResponse} for the submitted {@link PDFServicesJob}. * * @param params The parameters for getting the job status. * @param params.pollingURL URL to be polled to get the job status. Cannot be undefined. * * @returns A Promise that resolves to a {@link PDFServicesJobStatusResponse} encapsulating the job status * and retry interval. * * @throws {@link ServiceApiError} Thrown if an error is encountered while getting the content. * @throws {@link SDKError} Thrown for client-side or network errors. * @throws {@link ServiceUsageError} Thrown if service usage limits have been reached or credentials quota has * been exhausted. */ async getJobStatus(params) { ValidationUtil_1.ValidationUtil.validateGetJobStatusParams(params); return PDFServicesHelper_1.PDFServicesHelper.getJobStatus(this._executionContext, params.pollingURL); } /** * Returns a new {@link Asset} with a new valid download URI. * * @param params - The parameters for refreshing the download URI. * @param params.asset - The {@link Asset} to be refreshed. Cannot be undefined. * * @returns A Promise that resolves to an {@link Asset} with new valid download URI. * * @throws {@link ServiceApiError} Thrown if an error is encountered while getting the content. * @throws {@link SDKError} Thrown for client-side or network errors. * @throws {@link ServiceUsageError} Thrown if service usage limits have been reached or credentials quota has * been exhausted. */ async refreshDownloadURI(params) { ValidationUtil_1.ValidationUtil.validateRefreshDownloadURIParams(params); return PDFServicesHelper_1.PDFServicesHelper.refreshDownloadURI(this._executionContext, params.asset); } } exports.PDFServices = PDFServices; //# sourceMappingURL=PDFServices.js.map