Spaces:
Sleeping
Sleeping
| // tempmail.js | |
| const fetch = require('node-fetch'); | |
| class TempMailCore { | |
| constructor(baseUrl = 'https://api.internal.temp-mail.io/api/v3') { | |
| this.baseUrl = baseUrl; | |
| } | |
| // ambil domain | |
| async listDomains() { | |
| try { | |
| const response = await fetch(`${this.baseUrl}/domains`); | |
| if (!response.ok) throw new Error(`HTTP ${response.status}`); | |
| const data = await response.json(); | |
| return { success: true, domains: data.domains }; | |
| } catch (e) { | |
| return { success: false, error: e.message }; | |
| } | |
| } | |
| // buat email | |
| async generateEmail(username, domain) { | |
| try { | |
| const response = await fetch(`${this.baseUrl}/email/new`, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ name: username, domain }) | |
| }); | |
| if (!response.ok) throw new Error(`HTTP ${response.status}`); | |
| const data = await response.json(); | |
| return { | |
| success: true, | |
| email: data.email, | |
| token: data.token | |
| }; | |
| } catch (e) { | |
| return { success: false, error: e.message }; | |
| } | |
| } | |
| // cek inbox | |
| async checkEmail(emailAddress) { | |
| try { | |
| const response = await fetch( | |
| `${this.baseUrl}/email/${emailAddress}/messages` | |
| ); | |
| if (!response.ok) throw new Error(`HTTP ${response.status}`); | |
| const messages = await response.json(); | |
| return { | |
| success: true, | |
| email: emailAddress, | |
| messages | |
| }; | |
| } catch (e) { | |
| return { | |
| success: false, | |
| email: emailAddress, | |
| error: e.message | |
| }; | |
| } | |
| } | |
| } | |
| module.exports = TempMailCore; |