From 233a2719c68bf0fd06178a0536e1b9bac413444c Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sat, 1 Jun 2024 16:34:37 -0700 Subject: [PATCH] Add `temp-email` driver implementation to the SDK --- packages/puter-js/src/index.js | 5 ++- packages/puter-js/src/modules/Email.js | 62 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 packages/puter-js/src/modules/Email.js diff --git a/packages/puter-js/src/index.js b/packages/puter-js/src/index.js index df4c55ee..425fb06a 100644 --- a/packages/puter-js/src/index.js +++ b/packages/puter-js/src/index.js @@ -1,6 +1,7 @@ import OS from './modules/OS.js'; import FileSystem from './modules/FileSystem/index.js'; import Hosting from './modules/Hosting.js'; +import Email from './modules/Email.js'; import Apps from './modules/Apps.js'; import UI from './modules/UI.js'; import KV from './modules/KV.js'; @@ -196,6 +197,8 @@ window.puter = (function() { this.ui = new UI(this.appInstanceID, this.parentInstanceID, this.appID, this.env, this.util); // Hosting this.hosting = new Hosting(this.authToken, this.APIOrigin, this.appID, this.env); + // Email + this.email = new Email(this.authToken, this.APIOrigin, this.appID); // Apps this.apps = new Apps(this.authToken, this.APIOrigin, this.appID, this.env); // AI @@ -208,7 +211,7 @@ window.puter = (function() { updateSubmodules() { // Update submodules with new auth token and API origin - [this.os, this.fs, this.hosting, this.apps, this.ai, this.kv].forEach(module => { + [this.os, this.fs, this.hosting, this.email, this.apps, this.ai, this.kv].forEach(module => { if(!module) return; module.setAuthToken(this.authToken); module.setAPIOrigin(this.APIOrigin); diff --git a/packages/puter-js/src/modules/Email.js b/packages/puter-js/src/modules/Email.js new file mode 100644 index 00000000..4f754d33 --- /dev/null +++ b/packages/puter-js/src/modules/Email.js @@ -0,0 +1,62 @@ +import * as utils from '../lib/utils.js' + +class Email{ + /** + * Creates a new instance with the given authentication token, API origin, and app ID, + * + * @class + * @param {string} authToken - Token used to authenticate the user. + * @param {string} APIOrigin - Origin of the API server. Used to build the API endpoint URLs. + * @param {string} appID - ID of the app to use. + */ + constructor (authToken, APIOrigin, appID) { + this.authToken = authToken; + this.APIOrigin = APIOrigin; + this.appID = appID; + } + + /** + * Sets a new authentication token. + * + * @param {string} authToken - The new authentication token. + * @memberof [Email] + * @returns {void} + */ + setAuthToken (authToken) { + this.authToken = authToken; + } + + /** + * Sets the API origin. + * + * @param {string} APIOrigin - The new API origin. + * @memberof [Email] + * @returns {void} + */ + setAPIOrigin (APIOrigin) { + this.APIOrigin = APIOrigin; + } + + send = async(...args) => { + let options = {}; + + // arguments are required + if(!args || args.length === 0){ + throw ({message: 'Arguments are required', code: 'arguments_required'}); + } + + if(typeof args[0] === 'object'){ + options = args[0]; + }else{ + options = { + to: args[0], + subject: args[1], + html: args[2] + } + } + + return utils.make_driver_method(['to', 'subject', 'html'], 'temp-email', 'send').call(this, options); + } +} + +export default Email \ No newline at end of file