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.
@@ -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
- try {
35
- if (alias) {
36
- const { data } = await this.client.get(this.API_URL, {
37
- params: {
38
- f: 'set_email_user',
39
- email_user: alias,
40
- ip: this.ip,
41
- agent: this.agent,
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
- catch (error) {
59
- if (error.code === 'ECONNABORTED' || error.response?.status === 504) {
60
- throw new Error(`Guerrilla Mail API timeout: ${error.message}`);
61
- }
62
- throw new Error(`Failed to create mail: ${error.message}`);
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
- try {
76
- const { data } = await this.client.get(this.API_URL, {
77
- params: {
78
- f: 'check_email',
79
- seq: this.seq,
80
- ip: this.ip,
81
- agent: this.agent,
82
- },
83
- });
84
- this.seq = data.seq ?? this.seq;
85
- const list = data.list ?? [];
86
- // Filtrar emails que matchean el subject
87
- const matches = list.filter(m => subjectRegex.test(m.mail_subject));
88
- if (matches.length > 0) {
89
- // Ordenar por timestamp descendente (más reciente primero)
90
- matches.sort((a, b) => b.mail_timestamp - a.mail_timestamp);
91
- // Tomar el más reciente
92
- const mostRecent = matches[0];
93
- const full = await this.fetchEmail(mostRecent.mail_id);
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
- try {
125
- const { data } = await this.client.get(this.API_URL, {
126
- params: {
127
- f: 'fetch_email',
128
- email_id: mailId,
129
- ip: this.ip,
130
- agent: this.agent,
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "external-services-automation",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "External services automation library for Playwright and Cucumber",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",