UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

151 lines 3.82 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { AbsMail } from "scriptable-abstract"; const DEFAULT_STATE = { toRecipients: [], ccRecipients: [], bccRecipients: [], subject: "", body: "", isBodyHTML: false, preferredSendingEmailAddress: "", attachments: [] }; const _MockMail = class _MockMail extends AbsMail { static get instance() { if (!this._instance) { this._instance = new _MockMail(); } return this._instance; } constructor() { super(DEFAULT_STATE); } get toRecipients() { return [...this.state.toRecipients]; } set toRecipients(value) { this.setState({ toRecipients: [...value] }); } get ccRecipients() { return [...this.state.ccRecipients]; } set ccRecipients(value) { this.setState({ ccRecipients: [...value] }); } get bccRecipients() { return [...this.state.bccRecipients]; } set bccRecipients(value) { this.setState({ bccRecipients: [...value] }); } get subject() { return this.state.subject; } set subject(value) { this.setState({ subject: value }); } get body() { return this.state.body; } set body(value) { this.setState({ body: value }); } get isBodyHTML() { return this.state.isBodyHTML; } set isBodyHTML(value) { this.setState({ isBodyHTML: value }); } get preferredSendingEmailAddress() { return this.state.preferredSendingEmailAddress; } set preferredSendingEmailAddress(value) { this.setState({ preferredSendingEmailAddress: value }); } /** * Send the mail. * @returns A promise that resolves when the mail is sent */ async send() { return Promise.resolve(); } /** * Adds an image attachment to the mail. * @param image - Image to add to the mail */ addImageAttachment(image) { this.setState((state) => ({ attachments: [ ...state.attachments, { type: "image", data: image } ] })); } /** * Adds a file attachment to the mail. * @param filePath - Path of file to add to the mail */ addFileAttachment(filePath) { this.setState((state) => ({ attachments: [ ...state.attachments, { type: "file", data: filePath } ] })); } /** * Adds a data attachment to the mail. * @param data - Data representation of file to add to the mail * @param mimeType - MIME type of file represented by the data * @param filename - Name of the file represented by the data */ addDataAttachment(data, mimeType, filename) { this.setState((state) => ({ attachments: [ ...state.attachments, { type: "data", data, mimeType, filename } ] })); } /** * Get the last composed email details * @returns The details of the last composed email */ getLastComposedEmail() { return { toRecipients: [...this.state.toRecipients], ccRecipients: [...this.state.ccRecipients], bccRecipients: [...this.state.bccRecipients], subject: this.state.subject, body: this.state.body, isBodyHTML: this.state.isBodyHTML, attachments: [...this.state.attachments], preferredSendingEmailAddress: this.state.preferredSendingEmailAddress }; } /** * Clear the last composed email details */ clear() { this.setState(DEFAULT_STATE); } }; __publicField(_MockMail, "_instance", null); let MockMail = _MockMail; export { MockMail }; //# sourceMappingURL=mail.js.map