external-services-automation 1.0.4 → 1.0.5
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/dist/utils/temp-email-utils.js +48 -74
- package/package.json +1 -1
|
@@ -18,7 +18,6 @@ class GuerrillaMailClient {
|
|
|
18
18
|
this.client = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({
|
|
19
19
|
jar,
|
|
20
20
|
withCredentials: true,
|
|
21
|
-
timeout: 30000, // 30 seconds timeout for each HTTP request
|
|
22
21
|
headers: {
|
|
23
22
|
// Recommended to identify politely
|
|
24
23
|
'User-Agent': 'qa-automation-utils/1.0',
|
|
@@ -31,36 +30,28 @@ class GuerrillaMailClient {
|
|
|
31
30
|
* @returns Dirección de email completa.
|
|
32
31
|
*/
|
|
33
32
|
async createMail(alias) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.emailAddress = data.email_addr;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
const { data } = await this.client.get(this.API_URL, {
|
|
48
|
-
params: {
|
|
49
|
-
f: 'get_email_address',
|
|
50
|
-
ip: this.ip,
|
|
51
|
-
agent: this.agent,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
this.emailAddress = data.email_addr;
|
|
55
|
-
}
|
|
56
|
-
return this.emailAddress;
|
|
33
|
+
if (alias) {
|
|
34
|
+
const { data } = await this.client.get(this.API_URL, {
|
|
35
|
+
params: {
|
|
36
|
+
f: 'set_email_user',
|
|
37
|
+
email_user: alias,
|
|
38
|
+
ip: this.ip,
|
|
39
|
+
agent: this.agent,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
this.emailAddress = data.email_addr;
|
|
57
43
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
44
|
+
else {
|
|
45
|
+
const { data } = await this.client.get(this.API_URL, {
|
|
46
|
+
params: {
|
|
47
|
+
f: 'get_email_address',
|
|
48
|
+
ip: this.ip,
|
|
49
|
+
agent: this.agent,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
this.emailAddress = data.email_addr;
|
|
63
53
|
}
|
|
54
|
+
return this.emailAddress;
|
|
64
55
|
}
|
|
65
56
|
/**
|
|
66
57
|
* Function 2: Lee la bandeja y devuelve el email MÁS RECIENTE cuyo subject matchee con subjectRegex.
|
|
@@ -72,34 +63,25 @@ class GuerrillaMailClient {
|
|
|
72
63
|
async readMailBySubject(subjectRegex, timeoutMs = 60000, pollMs = 5000) {
|
|
73
64
|
const start = Date.now();
|
|
74
65
|
while (Date.now() - start < timeoutMs) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return full;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
console.warn(`Error checking email (retrying in ${pollMs}ms):`, error.message);
|
|
99
|
-
if (error.code === 'ECONNABORTED' || error.response?.status === 504) {
|
|
100
|
-
// For timeout errors, continue polling but log the issue
|
|
101
|
-
console.warn('Guerrilla Mail API timeout, retrying...');
|
|
102
|
-
}
|
|
66
|
+
const { data } = await this.client.get(this.API_URL, {
|
|
67
|
+
params: {
|
|
68
|
+
f: 'check_email',
|
|
69
|
+
seq: this.seq,
|
|
70
|
+
ip: this.ip,
|
|
71
|
+
agent: this.agent,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
this.seq = data.seq ?? this.seq;
|
|
75
|
+
const list = data.list ?? [];
|
|
76
|
+
// Filtrar emails que matchean el subject
|
|
77
|
+
const matches = list.filter(m => subjectRegex.test(m.mail_subject));
|
|
78
|
+
if (matches.length > 0) {
|
|
79
|
+
// Ordenar por timestamp descendente (más reciente primero)
|
|
80
|
+
matches.sort((a, b) => b.mail_timestamp - a.mail_timestamp);
|
|
81
|
+
// Tomar el más reciente
|
|
82
|
+
const mostRecent = matches[0];
|
|
83
|
+
const full = await this.fetchEmail(mostRecent.mail_id);
|
|
84
|
+
return full;
|
|
103
85
|
}
|
|
104
86
|
await new Promise(r => setTimeout(r, pollMs));
|
|
105
87
|
}
|
|
@@ -121,23 +103,15 @@ class GuerrillaMailClient {
|
|
|
121
103
|
}
|
|
122
104
|
/** Helper interno para descargar cuerpo completo */
|
|
123
105
|
async fetchEmail(mailId) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return data;
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
if (error.code === 'ECONNABORTED' || error.response?.status === 504) {
|
|
137
|
-
throw new Error(`Guerrilla Mail API timeout while fetching email ${mailId}: ${error.message}`);
|
|
138
|
-
}
|
|
139
|
-
throw new Error(`Failed to fetch email ${mailId}: ${error.message}`);
|
|
140
|
-
}
|
|
106
|
+
const { data } = await this.client.get(this.API_URL, {
|
|
107
|
+
params: {
|
|
108
|
+
f: 'fetch_email',
|
|
109
|
+
email_id: mailId,
|
|
110
|
+
ip: this.ip,
|
|
111
|
+
agent: this.agent,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
return data;
|
|
141
115
|
}
|
|
142
116
|
/**
|
|
143
117
|
* Function 4: Crea una nueva instancia de email client para aislamiento entre escenarios
|