diff --git a/src/models/drafts.ts b/src/models/drafts.ts index 70d51109..3e6ce47e 100644 --- a/src/models/drafts.ts +++ b/src/models/drafts.ts @@ -1,10 +1,49 @@ -import { BaseMessage, BaseCreateMessage } from './messages.js'; +import { BaseMessage } from './messages.js'; import { ListQueryParams } from './listQueryParams.js'; +import { EmailName } from './events.js'; +import { CreateAttachmentRequest } from './attachments.js'; /** * Interface representing a request to create a draft. */ -export interface CreateDraftRequest extends BaseCreateMessage { +export interface CreateDraftRequest { + /** + * An array of name/email address pairs that the message was sent from. This is usually one pair only, but can be many. + */ + from?: EmailName[]; + /** + * An array of message recipients. + */ + to: EmailName[]; + /** + * An array of bcc recipients. + */ + bcc?: EmailName[]; + /** + * An array of cc recipients. + */ + cc?: EmailName[]; + /** + * An array of name and email pairs that override the sent reply-to headers. + */ + replyTo?: EmailName[]; + /** + * An array of files to attach to the message. + */ + attachments?: CreateAttachmentRequest[]; + /** + * The message subject. + */ + subject?: string; + /** + * The full HTML message body. + * Messages with only plain-text representations are up-converted to HTML. + */ + body?: string; + /** + * Whether or not the message has been starred by the user. + */ + starred?: boolean; /** * Unix timestamp to send the message at. */ @@ -23,6 +62,10 @@ export interface CreateDraftRequest extends BaseCreateMessage { * Interface representing a request to send a message. */ export interface SendMessageRequest extends CreateDraftRequest { + /** + * An array of message senders. + */ + from?: EmailName[]; /** * Whether or not to use draft support. * This is primarily used when dealing with large attachments. diff --git a/src/models/messages.ts b/src/models/messages.ts index a215000d..9765f0aa 100644 --- a/src/models/messages.ts +++ b/src/models/messages.ts @@ -1,11 +1,32 @@ import { EmailName } from './events.js'; import { ListQueryParams } from './listQueryParams.js'; -import { Attachment, CreateAttachmentRequest } from './attachments.js'; +import { Attachment } from './attachments.js'; /** - * @internal Internal interface for creating a message. + * @internal Internal interface for a message. */ -export interface BaseCreateMessage { +export interface BaseMessage { + /** + * The unique identifier for the message. + */ + id: string; + /** + * Grant ID of the Nylas account. + */ + grantId: string; + /** + * Unix timestamp of when the message was received by the mail server. + * This may be different from the unverified Date header in raw message object. + */ + date: number; + /** + * Unix timestamp of when the message was created. + */ + createdAt: number; + /** + * The ID of the folder(s) the message appears in. + */ + folders: string[]; /** * An array of message recipients. */ @@ -22,10 +43,6 @@ export interface BaseCreateMessage { * An array of name and email pairs that override the sent reply-to headers. */ replyTo?: EmailName[]; - /** - * An array of files to attach to the message. - */ - attachments?: CreateAttachmentRequest[]; /** * The message subject. */ @@ -39,33 +56,6 @@ export interface BaseCreateMessage { * Whether or not the message has been starred by the user. */ starred?: boolean; -} - -/** - * @internal Internal interface for a message. - */ -export interface BaseMessage extends Omit { - /** - * The unique identifier for the message. - */ - id: string; - /** - * Grant ID of the Nylas account. - */ - grantId: string; - /** - * Unix timestamp of when the message was received by the mail server. - * This may be different from the unverified Date header in raw message object. - */ - date: number; - /** - * Unix timestamp of when the message was created. - */ - createdAt: number; - /** - * The ID of the folder(s) the message appears in. - */ - folders: string[]; /** * An array of message senders. */ @@ -107,6 +97,19 @@ export interface Message extends BaseMessage { * A list of key-value pairs storing additional data. */ metadata?: Record; + /** + * The unique identifier for the scheduled message. + */ + scheduleId?: string; + /** + * Unix timestamp to send the message at. + */ + sendAt?: number; + /** + * Whether or not to use draft support. + * This is primarily used when dealing with large attachments. + */ + useDraft?: boolean; } /** diff --git a/src/resources/messages.ts b/src/resources/messages.ts index 62748ec1..9310fafb 100644 --- a/src/resources/messages.ts +++ b/src/resources/messages.ts @@ -1,6 +1,5 @@ import { AsyncListResponse, Resource } from './resource.js'; import { - BaseCreateMessage, FindMessageQueryParams, ListMessagesQueryParams, Message, @@ -15,7 +14,11 @@ import { NylasListResponse, NylasResponse, } from '../models/response.js'; -import { SendMessageRequest, UpdateDraftRequest } from '../models/drafts.js'; +import { + CreateDraftRequest, + SendMessageRequest, + UpdateDraftRequest, +} from '../models/drafts.js'; import * as FormData from 'form-data'; import { objKeysToSnakeCase } from '../utils.js'; import { SmartCompose } from './smartCompose.js'; @@ -250,7 +253,7 @@ export class Messages extends Resource { } static _buildFormRequest( - requestBody: BaseCreateMessage | UpdateDraftRequest + requestBody: CreateDraftRequest | UpdateDraftRequest | SendMessageRequest ): FormData { let form: FormData; // FormData imports are funky, cjs needs to use .default, es6 doesn't