Add temp-email driver implementation to the SDK

This commit is contained in:
Nariman Jelveh 2024-06-01 16:34:37 -07:00
parent 49f61c4782
commit 233a2719c6
2 changed files with 66 additions and 1 deletions

View File

@ -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);

View File

@ -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