Skip to content

Commit af589cb

Browse files
authored
Create index.js
1 parent a2ec8b4 commit af589cb

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

NodeJS/index.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* TempMail.so API SDK
3+
* A Node.js client for interacting with TempMail.so API
4+
*
5+
* @link https://tempmail.so/temp-mail-api
6+
*
7+
* Features:
8+
* - Create temporary mailboxes
9+
* - Manage mailbox lifecycle
10+
* - Receive and manage emails
11+
*
12+
* @author TempMail.so
13+
*/
14+
15+
const axios = require('axios');
16+
17+
class TempMailSo {
18+
/**
19+
* @param {string} rapidApiKey - RapidAPI Key
20+
* @param {string} authToken - TempMail.so Authorization Token
21+
*/
22+
constructor(rapidApiKey, authToken) {
23+
this.baseURL = 'https://tempmail-so.p.rapidapi.com';
24+
this.client = axios.create({
25+
baseURL: this.baseURL,
26+
headers: {
27+
'x-rapidapi-key': rapidApiKey,
28+
'Authorization': `Bearer ${authToken}`,
29+
'Content-Type': 'application/x-www-form-urlencoded'
30+
}
31+
});
32+
}
33+
34+
/**
35+
* Get list of available domains
36+
* @returns {Promise<Array>} List of available domains
37+
*/
38+
async getDomains() {
39+
const response = await this.client.get('/domains');
40+
return response.data.data;
41+
}
42+
43+
/**
44+
* Create a new temporary inbox
45+
* @param {string} address - Email prefix
46+
* @param {string} domain - Domain name
47+
* @param {number} lifespan - Lifetime in seconds, available values: 0, 300, 600, 900, 1200, 1800
48+
* @returns {Promise<Object>} Created inbox information
49+
*/
50+
async createInbox(address, domain, lifespan) {
51+
const params = new URLSearchParams();
52+
params.append('name', address);
53+
params.append('domain', domain);
54+
params.append('lifespan', lifespan);
55+
56+
const response = await this.client.post('/inboxes', params);
57+
return response.data.data;
58+
}
59+
60+
/**
61+
* Get list of all inboxes
62+
* @returns {Promise<Array>} List of inboxes
63+
*/
64+
async listInboxes() {
65+
const response = await this.client.get('/inboxes');
66+
return response.data.data;
67+
}
68+
69+
/**
70+
* Delete specified inbox
71+
* @param {string} inboxId - Inbox ID
72+
* @returns {Promise<Object>} Delete result
73+
*/
74+
async deleteInbox(inboxId) {
75+
const response = await this.client.delete(`/inboxes/${inboxId}`);
76+
return response.data.data;
77+
}
78+
79+
/**
80+
* Get all emails from specified inbox
81+
* @param {string} inboxId - Inbox ID
82+
* @returns {Promise<Array>} List of emails
83+
*/
84+
async listMails(inboxId) {
85+
const response = await this.client.get(`/inboxes/${inboxId}/mails`);
86+
return response.data.data;
87+
}
88+
89+
/**
90+
* Get detailed content of specified email
91+
* @param {string} inboxId - Inbox ID
92+
* @param {string} mailId - Email ID
93+
* @returns {Promise<Object>} Detailed email content
94+
*/
95+
async getMail(inboxId, mailId) {
96+
const response = await this.client.get(`/inboxes/${inboxId}/mails/${mailId}`);
97+
return response.data.data;
98+
}
99+
100+
/**
101+
* Delete specified email
102+
* @param {string} inboxId - Inbox ID
103+
* @param {string} mailId - Email ID
104+
* @returns {Promise<Object>} Delete result
105+
*/
106+
async deleteMail(inboxId, mailId) {
107+
const response = await this.client.delete(`/inboxes/${inboxId}/mails/${mailId}`);
108+
return response.data.data;
109+
}
110+
}
111+
112+
module.exports = TempMailSo;

0 commit comments

Comments
 (0)