external-services-automation 1.0.39 → 1.0.40

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.
@@ -15,7 +15,6 @@ export declare class TigrmailService {
15
15
  private client;
16
16
  constructor(apiKey: string, baseUrl?: string);
17
17
  createMail(): Promise<string>;
18
- readMailBySubject(inbox: string, subject: string, timeoutMs?: number, pollMs?: number): Promise<TigrmailMessage>;
18
+ readMailBySubject(inbox: string, subject: string, timeoutMs?: number, pollMs?: number): Promise<string>;
19
19
  static createIsolatedClient(apiKey: string, baseUrl?: string): TigrmailService;
20
- private isNoMessageYetError;
21
20
  }
@@ -30,81 +30,35 @@ class TigrmailService {
30
30
  return data.inbox;
31
31
  }
32
32
  async readMailBySubject(inbox, subject, timeoutMs = 180000, pollMs = 3000) {
33
- if (!inbox) {
34
- throw new Error('Inbox is required');
35
- }
36
33
  if (!subject) {
37
34
  throw new Error('Subject is required');
38
35
  }
36
+ const url = 'https://api.tigrmail.com/v1/messages';
39
37
  const startTime = Date.now();
40
- let attempt = 0;
41
- console.log('[TigrmailService] Waiting for email with subject:', subject);
38
+ console.log('[TigrmailService] Polling inbox:', inbox);
39
+ console.log('[TigrmailService] Waiting for subject containing:', subject);
42
40
  while (Date.now() - startTime < timeoutMs) {
43
- attempt++;
44
- const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
45
- const remainingTime = timeoutMs - (Date.now() - startTime);
46
- try {
47
- const { data } = await this.client.get(`${this.API_URL}/messages`, {
48
- params: {
49
- inbox,
50
- subjectEquals: subject,
51
- },
52
- timeout: Math.max(remainingTime + 2000, 10000),
41
+ const { data } = await this.client.get(url, {
42
+ params: { inbox },
43
+ });
44
+ const message = data?.message;
45
+ if (message) {
46
+ console.log('[TigrmailService] Message received:', {
47
+ subject: message.subject,
48
+ from: message.from,
53
49
  });
54
- if (data?.message) {
55
- console.log(`[TigrmailService] Attempt ${attempt} (${elapsed}s) - Message received:`, {
56
- subject: data.message.subject,
57
- from: data.message.from,
58
- to: data.message.to,
59
- matchesSubject: data.message.subject.toLowerCase() === subject.toLowerCase(),
60
- });
61
- console.log('[TigrmailService] Match found!', {
62
- subject: data.message.subject,
63
- from: data.message.from,
64
- });
65
- return data.message;
66
- }
67
- console.log(`[TigrmailService] Attempt ${attempt} (${elapsed}s) - No message in response`);
68
- }
69
- catch (error) {
70
- const axiosError = error;
71
- if (!this.isNoMessageYetError(axiosError)) {
72
- throw error;
50
+ if (message.subject.toLowerCase().includes(subject.toLowerCase())) {
51
+ console.log('[TigrmailService] Subject matched. Returning email body.');
52
+ return message.body;
73
53
  }
74
- console.log(`[TigrmailService] Attempt ${attempt} (${elapsed}s) - No match yet`, {
75
- statusCode: axiosError.response?.status,
76
- });
77
- }
78
- if (Date.now() - startTime >= timeoutMs) {
79
- break;
80
54
  }
81
55
  console.log(`[TigrmailService] No match yet, waiting ${pollMs}ms...`);
82
56
  await new Promise(resolve => setTimeout(resolve, pollMs));
83
57
  }
84
- console.log('[TigrmailService] Timeout after', attempt, 'attempts');
85
58
  throw new Error(`Timeout (${timeoutMs} ms) waiting for an email with subject "${subject}" in inbox ${inbox}`);
86
59
  }
87
60
  static createIsolatedClient(apiKey, baseUrl) {
88
61
  return new TigrmailService(apiKey, baseUrl);
89
62
  }
90
- isNoMessageYetError(error) {
91
- const status = error.response?.status;
92
- const responseData = error.response?.data;
93
- if (status === 404 || status === 408 || status === 422 || status === 429) {
94
- return true;
95
- }
96
- if (typeof responseData === 'string') {
97
- const msg = responseData.toLowerCase();
98
- return msg.includes('no message') || msg.includes('timeout');
99
- }
100
- if (responseData && typeof responseData === 'object') {
101
- const maybeMessage = responseData.message;
102
- if (maybeMessage) {
103
- const msg = maybeMessage.toLowerCase();
104
- return msg.includes('no message') || msg.includes('timeout');
105
- }
106
- }
107
- return false;
108
- }
109
63
  }
110
64
  exports.TigrmailService = TigrmailService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "external-services-automation",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "description": "External services automation library for Playwright and Cucumber",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",