nylas
Version:
A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.
103 lines (102 loc) • 4.99 kB
TypeScript
import { Overrides } from '../config.js';
import { Attachment, AttachmentUploadSession, AttachmentUploadSessionComplete, CreateAttachmentUploadSessionRequest, FindAttachmentQueryParams, DownloadAttachmentQueryParams } from '../models/attachments.js';
import { NylasResponse } from '../models/response.js';
import { Resource } from './resource.js';
/**
* @property identifier The ID of the grant to act upon. Use "me" to refer to the grant associated with an access token.
* @property attachmentId The ID of the attachment to act upon.
* @property queryParams The query parameters to include in the request
*/
interface FindAttachmentParams {
identifier: string;
attachmentId: string;
queryParams: FindAttachmentQueryParams;
}
/**
* @property identifier The ID of the grant to act upon. Use "me" to refer to the grant associated with an access token.
* @property attachmentId The ID of the attachment to act upon.
* @property queryParams The query parameters to include in the request
*/
interface DownloadAttachmentParams {
identifier: string;
attachmentId: string;
queryParams: DownloadAttachmentQueryParams;
}
/**
* @property identifier The ID of the grant to act upon.
* @property requestBody Session details (filename, content type, optional size).
*/
interface CreateAttachmentUploadSessionParams {
identifier: string;
requestBody: CreateAttachmentUploadSessionRequest;
}
/**
* @property identifier The ID of the grant to act upon.
* @property attachmentId The attachment upload session ID.
*/
interface CompleteAttachmentUploadSessionParams {
identifier: string;
attachmentId: string;
}
/**
* Nylas Attachments API
*
* The Nylas Attachments API allows you to retrieve metadata and download attachments.
*/
export declare class Attachments extends Resource {
/**
* Returns an attachment by ID.
* @return The Attachment metadata
*/
find({ identifier, attachmentId, queryParams, overrides, }: FindAttachmentParams & Overrides): Promise<NylasResponse<Attachment>>;
/**
* Download the attachment data
*
* This method returns a Web 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. In Node.js, convert it with Readable.fromWeb() when a
* NodeJS.ReadableStream is required.
*
* @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 {ReadableStream<Uint8Array>} The ReadableStream containing the file data.
*/
download({ identifier, attachmentId, queryParams, overrides, }: DownloadAttachmentParams & Overrides): Promise<ReadableStream<Uint8Array>>;
/**
* Download the attachment data as a Node.js readable stream.
*
* This is a Node.js convenience wrapper around {@link Attachments.download}. Use
* {@link Attachments.download} directly in Fetch-native runtimes, such as Cloudflare Workers,
* where Web ReadableStreams are the standard stream primitive.
*
* @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 Node.js readable stream containing the file data.
*/
downloadNodeStream({ identifier, attachmentId, queryParams, overrides, }: DownloadAttachmentParams & Overrides): Promise<NodeJS.ReadableStream>;
/**
* 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, }: DownloadAttachmentParams & Overrides): Promise<Buffer>;
/**
* Create a resumable upload session for a large attachment (up to 150 MB).
* Upload bytes to the returned `url`, then call {@link Attachments.completeUploadSession}.
*
* @see https://developer.nylas.com/docs/v3/email/send-large-attachments/
* @return Session details including `attachmentId` and pre-signed `url`
*/
createUploadSession({ identifier, requestBody, overrides, }: CreateAttachmentUploadSessionParams & Overrides): Promise<NylasResponse<AttachmentUploadSession>>;
/**
* Complete an upload session after the file has been uploaded to the pre-signed URL.
*
* @see https://developer.nylas.com/docs/v3/email/send-large-attachments/
*/
completeUploadSession({ identifier, attachmentId, overrides, }: CompleteAttachmentUploadSessionParams & Overrides): Promise<NylasResponse<AttachmentUploadSessionComplete>>;
}
export {};