getnada 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/getinbox.js +19 -0
- package/index.js +66 -0
- package/package.json +16 -0
- package/pynada.js +105 -0
package/getinbox.js
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
const Pynada = require('./pynada');
|
2
|
+
const nada = new Pynada();
|
3
|
+
const myEmail = "147vienami@getnada.com";
|
4
|
+
|
5
|
+
nada.inbox(myEmail)
|
6
|
+
.getEmails()
|
7
|
+
.then(emails => {
|
8
|
+
for (const email of emails) {
|
9
|
+
console.log("From:", email.fromName);
|
10
|
+
console.log("Email:", email.fromEmail);
|
11
|
+
console.log("Subject:", email.subject);
|
12
|
+
console.log("Timestamp:", email.timestamp);
|
13
|
+
console.log("Contents:", email.contents);
|
14
|
+
console.log("---------------------");
|
15
|
+
}
|
16
|
+
})
|
17
|
+
.catch(error => {
|
18
|
+
console.error("Error:", error);
|
19
|
+
});
|
package/index.js
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
const axios = require('axios');
|
2
|
+
|
3
|
+
const BASE_API_URL = 'https://getnada.com/api/v1';
|
4
|
+
const GET_INBOX_URL_TEMPLATE = `${BASE_API_URL}/inboxes/{email}`;
|
5
|
+
const DELETE_EMAIL_URL_TEMPLATE = `${BASE_API_URL}/messages/{uid}`;
|
6
|
+
|
7
|
+
class Pynada {
|
8
|
+
constructor() {
|
9
|
+
this.inboxes = new Map();
|
10
|
+
}
|
11
|
+
|
12
|
+
async inbox(email) {
|
13
|
+
if (!this.inboxes.has(email)) {
|
14
|
+
const inbox = new PynadaInbox(email);
|
15
|
+
await inbox.getEmails();
|
16
|
+
this.inboxes.set(email, inbox);
|
17
|
+
}
|
18
|
+
|
19
|
+
return this.inboxes.get(email);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
class PynadaInbox {
|
24
|
+
constructor(email) {
|
25
|
+
this.inboxEmail = email;
|
26
|
+
this.emails = [];
|
27
|
+
}
|
28
|
+
|
29
|
+
async getEmails() {
|
30
|
+
const response = await axios.get(GET_INBOX_URL_TEMPLATE.replace('{email}', this.inboxEmail));
|
31
|
+
if (response.status !== 200) {
|
32
|
+
throw new Error(`Can't get inbox ${this.inboxEmail}`);
|
33
|
+
}
|
34
|
+
const emailsData = response.data.msgs;
|
35
|
+
for (const emailData of emailsData) {
|
36
|
+
this.emails.push(emailData);
|
37
|
+
}
|
38
|
+
return this.emails; // Return the emails array
|
39
|
+
}
|
40
|
+
|
41
|
+
async deleteEmail(uid) {
|
42
|
+
const response = await axios.delete(DELETE_EMAIL_URL_TEMPLATE.replace('{uid}', uid));
|
43
|
+
console.log(response.data);
|
44
|
+
console.log(response.status);
|
45
|
+
if (response.status !== 201) {
|
46
|
+
throw new Error(`Couldn't delete email: ${uid}`);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
// Usage example
|
52
|
+
const pynada = new Pynada();
|
53
|
+
const email = '147vienami@getnada.com';
|
54
|
+
let uids = []; // Declare an empty array to store UIDs
|
55
|
+
|
56
|
+
pynada.inbox(email)
|
57
|
+
.then(inbox => {
|
58
|
+
return inbox.getEmails();
|
59
|
+
})
|
60
|
+
.then(emails => {
|
61
|
+
uids = emails.map(email => email.uid); // Store the UIDs in the uids array
|
62
|
+
console.log(uids); // Output the UIDs
|
63
|
+
})
|
64
|
+
.catch(error => {
|
65
|
+
console.error(error);
|
66
|
+
});
|
package/package.json
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"name": "getnada",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
8
|
+
},
|
9
|
+
"keywords": [],
|
10
|
+
"author": "",
|
11
|
+
"license": "ISC",
|
12
|
+
"dependencies": {
|
13
|
+
"axios": "^1.4.0",
|
14
|
+
"re": "^0.1.4"
|
15
|
+
}
|
16
|
+
}
|
package/pynada.js
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
const axios = require('axios');
|
2
|
+
|
3
|
+
const BASE_API_URL = 'https://getnada.com/api/v1';
|
4
|
+
const GET_DOMAINS_URL = `${BASE_API_URL}/domains`;
|
5
|
+
const GET_INBOX_URL_TEMPLATE = `${BASE_API_URL}/inboxes/{email}`;
|
6
|
+
const GET_EMAIL_URL_TEMPLATE = `${BASE_API_URL}/messages/html/{uid}`;
|
7
|
+
const DELETE_EMAIL_URL_TEMPLATE = `${BASE_API_URL}/messages/{uid}`;
|
8
|
+
|
9
|
+
class Pynada {
|
10
|
+
constructor() {
|
11
|
+
this.domainNames = null;
|
12
|
+
this.inboxes = null;
|
13
|
+
}
|
14
|
+
|
15
|
+
async getDomains() {
|
16
|
+
if (this.domainNames === null) {
|
17
|
+
const response = await axios.get(GET_DOMAINS_URL);
|
18
|
+
if (response.status !== 200) {
|
19
|
+
throw new Error("Can't get domains");
|
20
|
+
}
|
21
|
+
this.domainNames = response.data.map(item => item.name);
|
22
|
+
}
|
23
|
+
return this.domainNames;
|
24
|
+
}
|
25
|
+
|
26
|
+
isValidEmail(email) {
|
27
|
+
return email.slice(email.indexOf('@') + 1) in this.getDomains();
|
28
|
+
}
|
29
|
+
|
30
|
+
inbox(email) {
|
31
|
+
if (this.inboxes !== null) {
|
32
|
+
const existingInbox = this.inboxes.find(ibx => ibx.email === email);
|
33
|
+
if (existingInbox) {
|
34
|
+
return existingInbox;
|
35
|
+
}
|
36
|
+
} else {
|
37
|
+
this.inboxes = [];
|
38
|
+
}
|
39
|
+
|
40
|
+
const newInbox = new PynadaInbox(email);
|
41
|
+
this.inboxes.push(newInbox);
|
42
|
+
return newInbox;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
class PynadaInbox {
|
47
|
+
constructor(email) {
|
48
|
+
this.inboxEmail = email;
|
49
|
+
this.emails = null;
|
50
|
+
}
|
51
|
+
|
52
|
+
async getEmails() {
|
53
|
+
if (this.emails === null) {
|
54
|
+
this.emails = [];
|
55
|
+
const response = await axios.get(GET_INBOX_URL_TEMPLATE.replace('{email}', this.inboxEmail));
|
56
|
+
if (response.status !== 200) {
|
57
|
+
throw new Error(`Can't get inbox ${this.inboxEmail}`);
|
58
|
+
}
|
59
|
+
const emailsData = response.data.msgs;
|
60
|
+
for (const emailData of emailsData) {
|
61
|
+
this.emails.push(new PynadaEmail(
|
62
|
+
emailData.uid,
|
63
|
+
emailData.f,
|
64
|
+
emailData.fe,
|
65
|
+
emailData.s,
|
66
|
+
emailData.r
|
67
|
+
));
|
68
|
+
}
|
69
|
+
}
|
70
|
+
return this.emails;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
class PynadaEmail {
|
75
|
+
constructor(uid, fromName, fromEmail, subject, timestamp) {
|
76
|
+
this.uid = uid;
|
77
|
+
this.fromName = fromName;
|
78
|
+
this.fromEmail = fromEmail;
|
79
|
+
this.subject = subject;
|
80
|
+
this.timestamp = timestamp;
|
81
|
+
this.contents = null;
|
82
|
+
}
|
83
|
+
|
84
|
+
async getContents() {
|
85
|
+
if (this.contents === null) {
|
86
|
+
const response = await axios.get(GET_EMAIL_URL_TEMPLATE.replace('{uid}', this.uid));
|
87
|
+
if (response.status !== 200) {
|
88
|
+
throw new Error(`Can't get email contents: ${this.uid}`);
|
89
|
+
}
|
90
|
+
this.contents = response.data.html;
|
91
|
+
}
|
92
|
+
return this.contents;
|
93
|
+
}
|
94
|
+
|
95
|
+
async delete() {
|
96
|
+
const response = await axios.delete(DELETE_EMAIL_URL_TEMPLATE.replace('{uid}', this.uid));
|
97
|
+
console.log(response.data);
|
98
|
+
console.log(response.status);
|
99
|
+
if (response.status !== 201) {
|
100
|
+
throw new Error(`Couldn't delete email: ${this.uid}`);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
module.exports = Pynada;
|