scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
173 lines • 4.81 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var mail_exports = {};
__export(mail_exports, {
MockMail: () => MockMail
});
module.exports = __toCommonJS(mail_exports);
var import_scriptable_abstract = require("scriptable-abstract");
const DEFAULT_STATE = {
toRecipients: [],
ccRecipients: [],
bccRecipients: [],
subject: "",
body: "",
isBodyHTML: false,
preferredSendingEmailAddress: "",
attachments: []
};
const _MockMail = class _MockMail extends import_scriptable_abstract.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;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockMail
});
//# sourceMappingURL=mail.js.map