nylas
Version:
A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.
55 lines (54 loc) • 2.21 kB
JavaScript
import { makePathParams } from '../utils.js';
import { Resource } from './resource.js';
/**
* Nylas Attachments API
*
* The Nylas Attachments API allows you to retrieve metadata and download attachments.
*/
export class Attachments extends Resource {
/**
* Returns an attachment by ID.
* @return The Attachment metadata
*/
find({ identifier, attachmentId, queryParams, overrides, }) {
return super._find({
path: makePathParams('/v3/grants/{identifier}/attachments/{attachmentId}', { identifier, attachmentId }),
queryParams,
overrides,
});
}
/**
* Download the attachment data
*
* This method returns a NodeJS.ReadableStream which can be used to stream the attachment data.
* This is particularly useful for handling large attachments efficiently, as it avoids loading
* the entire file into memory. The stream can be piped to a file stream or used in any other way
* that Node.js streams are typically used.
*
* @param identifier Grant ID or email account to query
* @param attachmentId The id of the attachment to download.
* @param queryParams The query parameters to include in the request
* @returns {NodeJS.ReadableStream} The ReadableStream containing the file data.
*/
download({ identifier, attachmentId, queryParams, overrides, }) {
return this._getStream({
path: makePathParams('/v3/grants/{identifier}/attachments/{attachmentId}/download', { identifier, attachmentId }),
queryParams,
overrides,
});
}
/**
* Download the attachment as a byte array
* @param identifier Grant ID or email account to query
* @param attachmentId The id of the attachment to download.
* @param queryParams The query parameters to include in the request
* @return The raw file data
*/
downloadBytes({ identifier, attachmentId, queryParams, overrides, }) {
return super._getRaw({
path: makePathParams('/v3/grants/{identifier}/attachments/{attachmentId}/download', { identifier, attachmentId }),
queryParams,
overrides,
});
}
}