/** * Used to isolate the type of content to retrieve from the message. * @typedef {Object} MessageContent * @public * @property {string} [type] - Message content type. Valid types: from, date, subject, body, archive, file. * @property {string} [name] - A custom description for the content type. * @property {RegExp|string} [archive] - Identifier to isolate the desired attachment when type is 'archive'. * Use a regular expression for pattern matching or a string for a literal match. Required if type is 'archive'. * @property {RegExp|string} [file] - Identifier to isolate the desired attachment when type is 'file' or 'archive'. * Use a regular expression for pattern matching or a string for a literal match. Required if type is 'file' or 'archive'. * @property {number?} [maxLength] - Maximum number of characters to retrieve from the content. */ /** * Configurable options provided to the Gmail adaptor. * @typedef {Object} Options * @public * @property {string?} [query] - Gmail search query string. * @property {Array} [contents=['from', 'date', 'subject']] * An array of strings or MessageContent objects used to specify which parts of the message to retrieve. * @property {Array} [processedIds] - Ignore message ids which have already been processed. * @property {string?} [email] - The user account to retrieve messages from. Defaults to the authenticated user. * @property {int?} [maxResults] - Maximum number of messages to process per request. Default is 1000. * @property {boolean} [fetchAttachments=true] - Whether to download file and archive attachments. * When false, matched attachments are returned as filename-only objects without content. */ /** * Downloads contents from messages of a Gmail account. * @public * @function * @param {Options} options - Customized options including desired contents and query. * @state {Array} data - The returned message objects, of the form `{ messageId, ...contents } ` * @state {Array} processedIds - An array of string ids processed by this request * @returns {Operation} * @example Get a message with a specific subject * getContentsFromMessages( * { * query: 'subject:my+test+message' * } * ) * @example Get messages after a specific date, with subject and report.txt attachment * getContentsFromMessages( * { * query: 'after:15/01/2025', * contents: [ * 'subject', * { type: 'file', name: 'metadata', file: 'report.txt'} * ] * } * ) * @example Get metadata without downloading requested attachments * getContentsFromMessages( * { * query: 'after:2026/07/01', * contents: [ * 'body', * { type: 'file', name: 'report', file: /\.xlsx$/ } * ], * fetchAttachments: false * } * ) */ export function getContentsFromMessages(options: Options): Operation; /** * Configurable fields for composing an outbound Gmail message. * @typedef {Object} SendMessageOptions * @property {string} to - Recipient email address. * @property {string} subject - Subject line of the email. * @property {string} body - Email body content. * @property {Array<{ filename: string, content: string|Buffer }>} [attachments] - Optional list of files to attach. */ /** * Sends a Gmail message using the provided configuration. * Supports attachments and standard email fields like subject, body, and recipients. * * @public * @function * @param {SendMessageOptions|SendMessageOptions[]} message - The message configuration object or array of objects. * @state {Object} data - The Gmail API response from sending the message. * @returns {Operation} * @example * sendMessage({ * to: 'recipient@example.org', * subject: 'Test Message', * body: 'Hello from OpenFn!', * attachments: [ * { filename: 'test.txt', content: 'Some text content' } * ] * }) */ export function sendMessage(message: SendMessageOptions | SendMessageOptions[]): Operation; /** * Configurable options provided to getMessageById. * @typedef {Object} MessageIdOptions * @public * @property {Array} [contents=['from', 'date', 'subject']] * An array of strings or MessageContent objects used to specify which parts of the message to retrieve. * @property {string?} [email] - The user account to retrieve messages from. Defaults to the authenticated user. * @property {boolean} [fetchAttachments=true] - Whether to download file and archive attachments. * When false, matched attachments are returned as filename-only objects without content. */ /** * Downloads contents from a single message of a Gmail account, identified by * its Gmail API message id. * @public * @function * @param {string} messageId - Gmail API message id to fetch. * @param {MessageIdOptions} [options] - Customized options including desired contents. * @state {Object} data - The returned message object, of the form `{ messageId, ...contents } ` * @returns {Operation} * @example Download attachments for a specific message identified by an earlier step * getMessageById( * $.data.messageId, * { * contents: [ * { type: 'file', name: 'report', file: /\.xlsx$/ } * ] * } * ) */ export function getMessageById(messageId: string, options?: MessageIdOptions): Operation; /** * Execute a sequence of operations. * Wraps `language-common/execute`, and prepends initial state for http. * @private * @param {...Function} operations - Operations to be performed. * @returns {Operation} */ export function execute(...operations: Function[]): Operation; /** * Used to isolate the type of content to retrieve from the message. */ export type MessageContent = any; /** * Configurable options provided to the Gmail adaptor. */ export type Options = any; /** * Configurable fields for composing an outbound Gmail message. */ export type SendMessageOptions = { /** * - Recipient email address. */ to: string; /** * - Subject line of the email. */ subject: string; /** * - Email body content. */ body: string; /** * - Optional list of files to attach. */ attachments?: Array<{ filename: string; content: string | Buffer; }>; }; /** * Configurable options provided to getMessageById. */ export type MessageIdOptions = any; export { alterState, combine, cursor, dataPath, dataValue, each, field, fields, fn, fnIf, lastReferenceValue, log, merge, sourceValue } from "@openfn/language-common";