temp-disposable-email 1.16.1 → 2.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/.eslintrc.json +28 -0
- package/.prettierignore +6 -0
- package/.prettierrc.json +10 -0
- package/README.md +40 -6
- package/dist/cjs/api.d.ts +4 -3
- package/dist/cjs/api.d.ts.map +1 -1
- package/dist/cjs/api.js +47 -35
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/cypress.d.ts +20 -0
- package/dist/cjs/cypress.d.ts.map +1 -1
- package/dist/cjs/cypress.js +3 -0
- package/dist/cjs/cypress.js.map +1 -1
- package/dist/cjs/index.d.ts +7 -4
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +54 -39
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/playwright.d.ts +27 -0
- package/dist/cjs/playwright.d.ts.map +1 -0
- package/dist/cjs/playwright.js +29 -0
- package/dist/cjs/playwright.js.map +1 -0
- package/dist/esm/api.d.ts +4 -3
- package/dist/esm/api.d.ts.map +1 -1
- package/dist/esm/api.js +47 -35
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/cypress.d.ts +20 -0
- package/dist/esm/cypress.d.ts.map +1 -1
- package/dist/esm/cypress.js +4 -1
- package/dist/esm/cypress.js.map +1 -1
- package/dist/esm/index.d.ts +7 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +56 -39
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/playwright.d.ts +27 -0
- package/dist/esm/playwright.d.ts.map +1 -0
- package/dist/esm/playwright.js +25 -0
- package/dist/esm/playwright.js.map +1 -0
- package/package.json +14 -1
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"extends": [
|
|
4
|
+
"eslint:recommended",
|
|
5
|
+
"plugin:@typescript-eslint/recommended"
|
|
6
|
+
],
|
|
7
|
+
"parserOptions": {
|
|
8
|
+
"ecmaVersion": 2020,
|
|
9
|
+
"sourceType": "module"
|
|
10
|
+
},
|
|
11
|
+
"env": {
|
|
12
|
+
"node": true,
|
|
13
|
+
"es6": true
|
|
14
|
+
},
|
|
15
|
+
"rules": {
|
|
16
|
+
"no-console": "off",
|
|
17
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
18
|
+
"@typescript-eslint/no-unused-vars": [
|
|
19
|
+
"error",
|
|
20
|
+
{
|
|
21
|
+
"argsIgnorePattern": "^_",
|
|
22
|
+
"varsIgnorePattern": "^_",
|
|
23
|
+
"caughtErrors": "all",
|
|
24
|
+
"caughtErrorsIgnorePattern": "^_"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
package/.prettierignore
ADDED
package/.prettierrc.json
ADDED
package/README.md
CHANGED
|
@@ -101,7 +101,28 @@ console.log('Message received:', message);
|
|
|
101
101
|
|
|
102
102
|
### **Playwright Example**
|
|
103
103
|
|
|
104
|
-
For using temp-disposable-email with Playwright,
|
|
104
|
+
For using temp-disposable-email with Playwright, you can use it directly or with fixtures.
|
|
105
|
+
|
|
106
|
+
#### Using Playwright Fixtures (Recommended)
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { test, expect } from 'temp-disposable-email/playwright';
|
|
110
|
+
|
|
111
|
+
test('sign up flow', async ({ page, emailHelper }) => {
|
|
112
|
+
const { emailAddress, accountId } = await emailHelper.generateEmail();
|
|
113
|
+
|
|
114
|
+
// Your test code...
|
|
115
|
+
|
|
116
|
+
const email = await emailHelper.getRecentEmail({
|
|
117
|
+
accountId,
|
|
118
|
+
maxWaitTime: 50000
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const code = await emailHelper.getVerificationCode(email?.text);
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
For complete examples, see the [Playwright folder](https://github.com/pirasanthan-jesugeevegan/temp-disposable-email/tree/master/examples/playwright).
|
|
105
126
|
|
|
106
127
|
### **Cypress Example**
|
|
107
128
|
|
|
@@ -109,19 +130,29 @@ For using temp-disposable-email with Cypress.
|
|
|
109
130
|
|
|
110
131
|
#### Import package
|
|
111
132
|
|
|
112
|
-
|
|
133
|
+
Import the package in your `support/commands.{ts|js}`:
|
|
113
134
|
|
|
114
135
|
```typescript
|
|
115
136
|
import 'temp-disposable-email/cypress';
|
|
116
137
|
```
|
|
117
138
|
|
|
118
|
-
|
|
139
|
+
#### TypeScript Setup
|
|
140
|
+
|
|
141
|
+
Add the type reference at the top of your test files:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
/// <reference types="temp-disposable-email/cypress" />
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Example Test
|
|
148
|
+
|
|
149
|
+
See the complete example in the [Cypress folder](https://github.com/pirasanthan-jesugeevegan/temp-disposable-email/tree/master/examples/cypress).
|
|
119
150
|
|
|
120
151
|
```typescript
|
|
121
152
|
it('[Custom Command] - Sign up - Check email content and subject', () => {
|
|
122
153
|
// Create a dynamic email address
|
|
123
154
|
cy.generateEmail(`cypress_${Math.random().toString().substr(2, 9)}`).then(
|
|
124
|
-
({ emailAddress }) => {
|
|
155
|
+
({ emailAddress, accountId }) => {
|
|
125
156
|
// Navigate to the sign-up page
|
|
126
157
|
cy.visit('https://app.postdrop.io/signup');
|
|
127
158
|
|
|
@@ -135,6 +166,7 @@ it('[Custom Command] - Sign up - Check email content and subject', () => {
|
|
|
135
166
|
cy.contains('h1', 'Thanks for signing up!').should('be.visible');
|
|
136
167
|
// Fetch the verification email
|
|
137
168
|
cy.getRecentEmail({
|
|
169
|
+
accountId, // Pass accountId for proper cleanup
|
|
138
170
|
maxWaitTime: 80000,
|
|
139
171
|
waitInterval: 1000,
|
|
140
172
|
deleteAfterRead: true,
|
|
@@ -153,7 +185,7 @@ it('[Custom Command] - Sign up - Check email content and subject', () => {
|
|
|
153
185
|
|
|
154
186
|
### **Node Example**
|
|
155
187
|
|
|
156
|
-
Here's a complete example of creating an inbox, retrieving a message, and
|
|
188
|
+
Here's a complete example of creating an inbox, retrieving a message, and cleaning up:
|
|
157
189
|
|
|
158
190
|
```typescript
|
|
159
191
|
import { generateEmail, getRecentEmail } from 'temp-disposable-email';
|
|
@@ -161,11 +193,12 @@ import { generateEmail, getRecentEmail } from 'temp-disposable-email';
|
|
|
161
193
|
async function run() {
|
|
162
194
|
try {
|
|
163
195
|
// Create a new inbox
|
|
164
|
-
const { emailAddress } = await generateEmail();
|
|
196
|
+
const { emailAddress, accountId } = await generateEmail();
|
|
165
197
|
console.log('Created email:', emailAddress);
|
|
166
198
|
|
|
167
199
|
// Get the first available message from the inbox
|
|
168
200
|
const message = await getRecentEmail({
|
|
201
|
+
accountId, // Pass accountId for automatic cleanup
|
|
169
202
|
maxWaitTime: 50000,
|
|
170
203
|
waitInterval: 3000,
|
|
171
204
|
logPolling: true,
|
|
@@ -202,6 +235,7 @@ run();
|
|
|
202
235
|
- **Description**: Retrieves the latest message from the inbox, polling if necessary.
|
|
203
236
|
- **Parameters**:
|
|
204
237
|
- `options` (Optional): Polling configuration for waiting for messages. See GetEmailOptions.
|
|
238
|
+
- `accountId` (Optional): Account ID for cleanup after reading. **Recommended** to prevent resource leaks.
|
|
205
239
|
- `maxWaitTime` (Optional): The maximum time to wait for messages (in milliseconds).
|
|
206
240
|
- `waitInterval` (Optional): The interval between polling attempts (in milliseconds).
|
|
207
241
|
- `logPolling` (Optional): Whether to log each polling attempt for debugging purposes.
|
package/dist/cjs/api.d.ts
CHANGED
|
@@ -79,14 +79,15 @@ export declare const getAuthHeaders: () => {
|
|
|
79
79
|
Authorization: string;
|
|
80
80
|
};
|
|
81
81
|
export declare const getDomains: () => Promise<ListOfDomains[]>;
|
|
82
|
-
export declare const getMessages: () => Promise<EmailObject[]>;
|
|
82
|
+
export declare const getMessages: (maxRetries?: number, retryDelay?: number) => Promise<EmailObject[]>;
|
|
83
83
|
export declare const getMessagesContent: (messageId: string) => Promise<EmailResource>;
|
|
84
|
-
export declare const getMessageAttachments: (messageId: string, attachmentsId: string) => Promise<
|
|
84
|
+
export declare const getMessageAttachments: (messageId: string, attachmentsId: string) => Promise<Buffer>;
|
|
85
85
|
export declare const deleteMessage: (messageId: string) => Promise<number>;
|
|
86
86
|
export declare const createAccount: (payload: {
|
|
87
87
|
address: string;
|
|
88
88
|
password: string;
|
|
89
|
-
},
|
|
89
|
+
}, domain?: string, // Domain to use for fallback email generation
|
|
90
|
+
maxRetries?: number, delayMs?: number, infiniteRetry?: boolean) => Promise<EmailAccount>;
|
|
90
91
|
export declare const deleteAccount: (accountId: string) => Promise<void>;
|
|
91
92
|
export {};
|
|
92
93
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/cjs/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAGA,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,WAAW;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,C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,eAAO,MAAM,UAAU,QAAa,OAAO,CAAC,aAAa,EAAE,CAS1D,CAAC;AAGF,eAAO,MAAM,WAAW,GACtB,mBAAc,EACd,mBAAkB,KACjB,OAAO,CAAC,WAAW,EAAE,CA4BvB,CAAC;AAGF,eAAO,MAAM,kBAAkB,GAC7B,WAAW,MAAM,KAChB,OAAO,CAAC,aAAa,CASvB,CAAC;AAGF,eAAO,MAAM,qBAAqB,GAChC,WAAW,MAAM,EACjB,eAAe,MAAM,KACpB,OAAO,CAAC,MAAM,CAehB,CAAC;AAGF,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,MAAM,CAUrE,CAAC;AAGF,eAAO,MAAM,aAAa,GACxB,SAAS;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC9C,SAAS,MAAM,EAAE,8CAA8C;AAC/D,mBAAe,EACf,gBAAc,EACd,uBAAqB,KACpB,OAAO,CAAC,YAAY,CA2CtB,CAAC;AAGF,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,IAAI,CAQnE,CAAC"}
|
package/dist/cjs/api.js
CHANGED
|
@@ -18,12 +18,7 @@ const apiClient = axios_1.default.create({
|
|
|
18
18
|
const authenticate = async (_email, _password) => {
|
|
19
19
|
email = _email;
|
|
20
20
|
password = _password;
|
|
21
|
-
const response = await apiClient.post('/token', { address: email, password }
|
|
22
|
-
headers: {
|
|
23
|
-
accept: 'application/json',
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
},
|
|
26
|
-
});
|
|
21
|
+
const response = await apiClient.post('/token', { address: email, password });
|
|
27
22
|
token = response.data.token;
|
|
28
23
|
};
|
|
29
24
|
exports.authenticate = authenticate;
|
|
@@ -46,8 +41,7 @@ apiClient.interceptors.response.use((response) => response, async (error) => {
|
|
|
46
41
|
error.config.headers = (0, exports.getAuthHeaders)(); // Update headers with new token
|
|
47
42
|
return apiClient.request(error.config); // Retry request
|
|
48
43
|
}
|
|
49
|
-
catch (
|
|
50
|
-
console.error('Failed to refresh token:', authError);
|
|
44
|
+
catch (_authError) {
|
|
51
45
|
throw new Error('Authentication failed. Please check credentials.');
|
|
52
46
|
}
|
|
53
47
|
}
|
|
@@ -61,31 +55,37 @@ const getDomains = async () => {
|
|
|
61
55
|
});
|
|
62
56
|
return data;
|
|
63
57
|
}
|
|
64
|
-
catch (
|
|
65
|
-
console.error('Error fetching domains:', error.response?.data);
|
|
58
|
+
catch (_error) {
|
|
66
59
|
throw new Error('Failed to fetch domains. Please try again later.');
|
|
67
60
|
}
|
|
68
61
|
};
|
|
69
62
|
exports.getDomains = getDomains;
|
|
70
|
-
// Function to fetch messages
|
|
71
|
-
const getMessages = async () => {
|
|
72
|
-
|
|
63
|
+
// Function to fetch messages with retry logic and timeout
|
|
64
|
+
const getMessages = async (maxRetries = 5, retryDelay = 10000) => {
|
|
65
|
+
let attempt = 0;
|
|
66
|
+
while (attempt < maxRetries) {
|
|
73
67
|
try {
|
|
74
68
|
const { data } = await apiClient.get('/messages?page=1', {
|
|
75
69
|
headers: (0, exports.getAuthHeaders)(),
|
|
76
70
|
});
|
|
77
71
|
return data;
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
73
|
}
|
|
79
74
|
catch (error) {
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
attempt++;
|
|
76
|
+
if (error.response?.status === 429 && attempt < maxRetries) {
|
|
77
|
+
console.warn(`Rate limited. Retrying in ${retryDelay / 1000}s... (Attempt ${attempt}/${maxRetries})`);
|
|
78
|
+
await (0, _1.delay)(retryDelay);
|
|
79
|
+
}
|
|
80
|
+
else if (attempt >= maxRetries) {
|
|
81
|
+
throw new Error(`Failed to fetch messages after ${maxRetries} attempts. Please try again later.`);
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
|
-
console.error('Error fetching messages:', error.response?.data);
|
|
85
84
|
throw new Error('Failed to fetch messages. Please try again later.');
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
}
|
|
88
|
+
throw new Error('Failed to fetch messages after maximum retries.');
|
|
89
89
|
};
|
|
90
90
|
exports.getMessages = getMessages;
|
|
91
91
|
// Function to fetch message content
|
|
@@ -96,8 +96,7 @@ const getMessagesContent = async (messageId) => {
|
|
|
96
96
|
});
|
|
97
97
|
return data;
|
|
98
98
|
}
|
|
99
|
-
catch (
|
|
100
|
-
console.error(`Error fetching message content for ID ${messageId}:`, error.response?.data);
|
|
99
|
+
catch (_error) {
|
|
101
100
|
throw new Error('Failed to fetch message content. Please try again later.');
|
|
102
101
|
}
|
|
103
102
|
};
|
|
@@ -111,8 +110,7 @@ const getMessageAttachments = async (messageId, attachmentsId) => {
|
|
|
111
110
|
});
|
|
112
111
|
return data;
|
|
113
112
|
}
|
|
114
|
-
catch (
|
|
115
|
-
console.error(`Error fetching message attachment for ID ${messageId}:`, error.response?.data);
|
|
113
|
+
catch (_error) {
|
|
116
114
|
throw new Error('Failed to fetch message attachment. Please try again later.');
|
|
117
115
|
}
|
|
118
116
|
};
|
|
@@ -125,35 +123,50 @@ const deleteMessage = async (messageId) => {
|
|
|
125
123
|
});
|
|
126
124
|
return status;
|
|
127
125
|
}
|
|
128
|
-
catch (
|
|
129
|
-
console.warn(`Error deleting message for ID ${messageId}
|
|
126
|
+
catch (_error) {
|
|
127
|
+
console.warn(`Error deleting message for ID ${messageId}`);
|
|
128
|
+
return 0;
|
|
130
129
|
}
|
|
131
130
|
};
|
|
132
131
|
exports.deleteMessage = deleteMessage;
|
|
133
132
|
// Function to create an email account
|
|
134
|
-
const createAccount = async (payload,
|
|
135
|
-
|
|
133
|
+
const createAccount = async (payload, domain, // Domain to use for fallback email generation
|
|
134
|
+
maxRetries = 10, delayMs = 6000, infiniteRetry = false // Optional: Keep retrying forever
|
|
135
|
+
) => {
|
|
136
|
+
let attempt = 1;
|
|
137
|
+
while (attempt <= maxRetries || infiniteRetry) {
|
|
136
138
|
try {
|
|
137
139
|
const { data } = await apiClient.post('/accounts', payload, {
|
|
138
140
|
headers: { accept: 'application/json' },
|
|
139
141
|
});
|
|
140
142
|
return data;
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
144
|
}
|
|
142
145
|
catch (error) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
const status = error.response?.status;
|
|
147
|
+
const isNetworkError = error.code === 'ECONNABORTED' || !error.response;
|
|
148
|
+
if (status === 409 || status === 422) {
|
|
149
|
+
// Use provided domain or extract from original address
|
|
150
|
+
const domainToUse = domain || payload.address.split('@')[1];
|
|
151
|
+
payload.address = `${Date.now()}-${Math.floor(Math.random() * 100000)}@${domainToUse}`;
|
|
152
|
+
console.warn(`Address already exists or invalid. Retrying with: ${payload.address}`);
|
|
153
|
+
}
|
|
154
|
+
else if (status === 429) {
|
|
155
|
+
console.warn(`Rate limited. Waiting 30 seconds before retry... (Attempt ${attempt}/${maxRetries})`);
|
|
156
|
+
await (0, _1.delay)(30000);
|
|
157
|
+
}
|
|
158
|
+
else if (status === 500 || isNetworkError) {
|
|
159
|
+
const waitTime = Math.min(30000, delayMs * attempt);
|
|
160
|
+
console.warn(`Server error or network issue. Waiting ${waitTime / 1000}s... (Attempt ${attempt}/${maxRetries})`);
|
|
161
|
+
await (0, _1.delay)(waitTime);
|
|
151
162
|
}
|
|
152
163
|
else {
|
|
153
|
-
throw error
|
|
164
|
+
throw error;
|
|
154
165
|
}
|
|
166
|
+
attempt++;
|
|
155
167
|
}
|
|
156
168
|
}
|
|
169
|
+
throw new Error('🚨 Max retries reached. Account creation failed.');
|
|
157
170
|
};
|
|
158
171
|
exports.createAccount = createAccount;
|
|
159
172
|
// Function to delete an account
|
|
@@ -162,9 +175,8 @@ const deleteAccount = async (accountId) => {
|
|
|
162
175
|
await apiClient.delete(`/accounts/${accountId}`, {
|
|
163
176
|
headers: (0, exports.getAuthHeaders)(),
|
|
164
177
|
});
|
|
165
|
-
console.log(`Account ${accountId} deleted successfully.`);
|
|
166
178
|
}
|
|
167
|
-
catch (
|
|
179
|
+
catch (_error) {
|
|
168
180
|
console.warn(`Failed to delete account ${accountId}, ignoring error.`);
|
|
169
181
|
}
|
|
170
182
|
};
|
package/dist/cjs/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAkD;AAClD,wBAA0B;AAmF1B,uCAAuC;AACvC,IAAI,KAAK,GAAkB,IAAI,CAAC;AAChC,IAAI,KAAa,CAAC;AAClB,IAAI,QAAgB,CAAC;AAErB,MAAM,SAAS,GAAG,eAAK,CAAC,MAAM,CAAC;IAC7B,OAAO,EAAE,qBAAqB;IAC9B,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;CACxC,CAAC,CAAC;AAEH,+CAA+C;AACxC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAc,EACd,SAAiB,EACF,EAAE;IACjB,KAAK,GAAG,MAAM,CAAC;IACf,QAAQ,GAAG,SAAS,CAAC;IACrB,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAkD;AAClD,wBAA0B;AAmF1B,uCAAuC;AACvC,IAAI,KAAK,GAAkB,IAAI,CAAC;AAChC,IAAI,KAAa,CAAC;AAClB,IAAI,QAAgB,CAAC;AAErB,MAAM,SAAS,GAAG,eAAK,CAAC,MAAM,CAAC;IAC7B,OAAO,EAAE,qBAAqB;IAC9B,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;CACxC,CAAC,CAAC;AAEH,+CAA+C;AACxC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAc,EACd,SAAiB,EACF,EAAE;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@ -21,6 +21,7 @@ declare global {
|
|
|
21
21
|
* Retrieves the latest message from the inbox.
|
|
22
22
|
*
|
|
23
23
|
* @param {GetEmailOptions} [options] - Optional settings for polling and deletion.
|
|
24
|
+
* @param {string} [options.accountId] - Account ID to cleanup after reading.
|
|
24
25
|
* @param {number} [options.maxWaitTime=30000] - Maximum time to wait for messages (in milliseconds). Default is 30 seconds.
|
|
25
26
|
* @param {number} [options.waitInterval=2000] - Time interval between polling attempts (in milliseconds). Default is 2 seconds.
|
|
26
27
|
* @param {boolean} [options.logPolling=false] - Whether to log polling attempts. Default is `false`.
|
|
@@ -56,6 +57,25 @@ declare global {
|
|
|
56
57
|
}
|
|
57
58
|
*/
|
|
58
59
|
getRecentEmail(options: GetEmailOptions): Chainable<MessageContent | null>;
|
|
60
|
+
/**
|
|
61
|
+
* Extracts a verification code from email content.
|
|
62
|
+
*
|
|
63
|
+
* This function scans the given text for a sequence of 5 or more
|
|
64
|
+
* consecutive digits and returns the first valid verification code.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} text - The content of the email, typically the body or HTML.
|
|
67
|
+
* @returns {Promise<string>} The first verification code found.
|
|
68
|
+
*
|
|
69
|
+
* @throws {Error} If no valid verification code is found.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* cy.getRecentEmail().then((email) => {
|
|
73
|
+
* cy.getVerificationCode(email?.text).then((code) => {
|
|
74
|
+
* cy.log(code); // Output: "123456"
|
|
75
|
+
* });
|
|
76
|
+
* });
|
|
77
|
+
*/
|
|
78
|
+
getVerificationCode(text?: string): Chainable<string>;
|
|
59
79
|
}
|
|
60
80
|
}
|
|
61
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cypress.d.ts","sourceRoot":"","sources":["../../src/cypress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,eAAe,
|
|
1
|
+
{"version":3,"file":"cypress.d.ts","sourceRoot":"","sources":["../../src/cypress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,eAAe,EAGf,cAAc,EACf,MAAM,SAAS,CAAC;AAcjB,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO,CAAC;QAChB,UAAU,SAAS;YACjB;;;;;;;;;;;;;eAaG;YACH,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;YAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAsCG;YACH,cAAc,CACZ,OAAO,EAAE,eAAe,GACvB,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;YAEpC;;;;;;;;;;;;;;;;;eAiBG;YACH,mBAAmB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;SACvD;KACF;CACF"}
|
package/dist/cjs/cypress.js
CHANGED
|
@@ -7,4 +7,7 @@ Cypress.Commands.add('generateEmail', function (prefix) {
|
|
|
7
7
|
Cypress.Commands.add('getRecentEmail', function (options) {
|
|
8
8
|
return cy.wrap((0, index_1.getRecentEmail)(options));
|
|
9
9
|
});
|
|
10
|
+
Cypress.Commands.add('getVerificationCode', function (text) {
|
|
11
|
+
return cy.wrap((0, index_1.getVerificationCode)(text));
|
|
12
|
+
});
|
|
10
13
|
//# sourceMappingURL=cypress.js.map
|
package/dist/cjs/cypress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cypress.js","sourceRoot":"","sources":["../../src/cypress.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"cypress.js","sourceRoot":"","sources":["../../src/cypress.ts"],"names":[],"mappings":";;AAAA,mCAOiB;AAEjB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,MAAe;IAC7D,OAAO,EAAE,CAAC,IAAI,CAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,CAAC,CAAC;AACxC,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,OAAwB;IACvE,OAAO,EAAE,CAAC,IAAI,CAAC,IAAA,sBAAc,EAAC,OAAO,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,qBAAqB,EAAE,UAAU,IAAa;IACjE,OAAO,EAAE,CAAC,IAAI,CAAC,IAAA,2BAAmB,EAAC,IAAI,CAAC,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface MessageContent {
|
|
|
17
17
|
updatedAt: string;
|
|
18
18
|
attachments: Attachment[];
|
|
19
19
|
}
|
|
20
|
-
interface Attachment {
|
|
20
|
+
export interface Attachment {
|
|
21
21
|
title: string;
|
|
22
22
|
data: Buffer;
|
|
23
23
|
}
|
|
@@ -26,8 +26,10 @@ export interface GetEmailOptions {
|
|
|
26
26
|
waitInterval?: number;
|
|
27
27
|
logPolling?: boolean;
|
|
28
28
|
deleteAfterRead?: boolean;
|
|
29
|
+
accountId?: string;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
declare const delay: (ms: number) => Promise<void>;
|
|
32
|
+
export { delay };
|
|
31
33
|
/**
|
|
32
34
|
* Creates a new email inbox with a unique address.
|
|
33
35
|
*
|
|
@@ -47,6 +49,7 @@ export declare const generateEmail: (emailPrefix?: string) => Promise<GeneratedE
|
|
|
47
49
|
* Retrieves the latest message from the inbox.
|
|
48
50
|
*
|
|
49
51
|
* @param {GetEmailOptions} [options] - Optional settings for polling and deletion.
|
|
52
|
+
* @param {string} [options.accountId] - Account ID to cleanup after reading. If not provided, account won't be deleted.
|
|
50
53
|
* @param {number} [options.maxWaitTime=30000] - Maximum time to wait for messages (in milliseconds). Default is 30 seconds.
|
|
51
54
|
* @param {number} [options.waitInterval=2000] - Time interval between polling attempts (in milliseconds). Default is 2 seconds.
|
|
52
55
|
* @param {boolean} [options.logPolling=false] - Whether to log polling attempts. Default is `false`.
|
|
@@ -56,7 +59,8 @@ export declare const generateEmail: (emailPrefix?: string) => Promise<GeneratedE
|
|
|
56
59
|
* @throws {Error} If no messages are available within the polling timeout or authentication fails.
|
|
57
60
|
*
|
|
58
61
|
* @example
|
|
59
|
-
* const
|
|
62
|
+
* const { accountId } = await generateEmail();
|
|
63
|
+
* const message = await getRecentEmail({ accountId, maxWaitTime: 5000, waitInterval: 1000, logPolling: true });
|
|
60
64
|
* console.log(message.subject); // Outputs: "Hello!"
|
|
61
65
|
*/
|
|
62
66
|
export declare const getRecentEmail: (options?: GetEmailOptions) => Promise<MessageContent | null>;
|
|
@@ -76,5 +80,4 @@ export declare const getRecentEmail: (options?: GetEmailOptions) => Promise<Mess
|
|
|
76
80
|
* console.log(verificationCode); // Output: "123456"
|
|
77
81
|
*/
|
|
78
82
|
export declare const getVerificationCode: (text: string | undefined) => Promise<string>;
|
|
79
|
-
export {};
|
|
80
83
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AACD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AACD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AACD,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,KAAK,GAAI,IAAI,MAAM,KAAG,OAAO,CAAC,IAAI,CACW,CAAC;AAKpD,OAAO,EAAE,KAAK,EAAE,CAAC;AAEjB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,GACxB,cAAc,MAAM,KACnB,OAAO,CAAC,cAAc,CA+BxB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,eAAe,KACxB,OAAO,CAAC,cAAc,GAAG,IAAI,CA4F/B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,mBAAmB,GAC9B,MAAM,MAAM,GAAG,SAAS,KACvB,OAAO,CAAC,MAAM,CAYhB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getVerificationCode = exports.getRecentEmail = exports.generateEmail = exports.delay = void 0;
|
|
4
4
|
const api_1 = require("./api");
|
|
5
5
|
const api_2 = require("./api");
|
|
6
|
-
let accountId;
|
|
7
6
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
7
|
exports.delay = delay;
|
|
9
8
|
const generateRandomName = () => Math.random().toString(36).substring(2, 15);
|
|
@@ -30,19 +29,21 @@ const generateEmail = async (emailPrefix) => {
|
|
|
30
29
|
throw new Error('No available domains.');
|
|
31
30
|
const emailAddress = `${emailPrefix || generateRandomName()}@${domains[0]}`;
|
|
32
31
|
const password = generateRandomName();
|
|
32
|
+
// eslint-disable-next-line no-constant-condition
|
|
33
33
|
while (true) {
|
|
34
34
|
try {
|
|
35
35
|
const accountResponse = await (0, api_2.createAccount)({
|
|
36
36
|
address: emailAddress,
|
|
37
37
|
password,
|
|
38
|
-
}
|
|
39
|
-
|
|
38
|
+
}, domains[0] // Pass the first active domain for fallback
|
|
39
|
+
);
|
|
40
40
|
await (0, api_1.authenticate)(emailAddress, password);
|
|
41
41
|
return { emailAddress, accountId: accountResponse.id };
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
43
|
}
|
|
43
44
|
catch (error) {
|
|
44
45
|
if (error.response?.status === 429) {
|
|
45
|
-
await
|
|
46
|
+
await delay(5 * 1000);
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
49
|
throw error;
|
|
@@ -55,6 +56,7 @@ exports.generateEmail = generateEmail;
|
|
|
55
56
|
* Retrieves the latest message from the inbox.
|
|
56
57
|
*
|
|
57
58
|
* @param {GetEmailOptions} [options] - Optional settings for polling and deletion.
|
|
59
|
+
* @param {string} [options.accountId] - Account ID to cleanup after reading. If not provided, account won't be deleted.
|
|
58
60
|
* @param {number} [options.maxWaitTime=30000] - Maximum time to wait for messages (in milliseconds). Default is 30 seconds.
|
|
59
61
|
* @param {number} [options.waitInterval=2000] - Time interval between polling attempts (in milliseconds). Default is 2 seconds.
|
|
60
62
|
* @param {boolean} [options.logPolling=false] - Whether to log polling attempts. Default is `false`.
|
|
@@ -64,52 +66,62 @@ exports.generateEmail = generateEmail;
|
|
|
64
66
|
* @throws {Error} If no messages are available within the polling timeout or authentication fails.
|
|
65
67
|
*
|
|
66
68
|
* @example
|
|
67
|
-
* const
|
|
69
|
+
* const { accountId } = await generateEmail();
|
|
70
|
+
* const message = await getRecentEmail({ accountId, maxWaitTime: 5000, waitInterval: 1000, logPolling: true });
|
|
68
71
|
* console.log(message.subject); // Outputs: "Hello!"
|
|
69
72
|
*/
|
|
70
73
|
const getRecentEmail = async (options) => {
|
|
71
|
-
const { maxWaitTime = 30000, waitInterval = 2000, logPolling = false, deleteAfterRead = false, } = options || {};
|
|
74
|
+
const { maxWaitTime = 30000, waitInterval = 2000, logPolling = false, deleteAfterRead = false, accountId, } = options || {};
|
|
72
75
|
const startTime = Date.now();
|
|
73
76
|
const logger = (message) => logPolling && console.log(message);
|
|
74
77
|
logger(`Polling started with a timeout of ${maxWaitTime / 1000}sec and interval of ${waitInterval / 1000}sec.`);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
78
|
+
try {
|
|
79
|
+
while (Date.now() - startTime < maxWaitTime) {
|
|
80
|
+
const messages = await (0, api_2.getMessages)();
|
|
81
|
+
if (messages.length > 0) {
|
|
82
|
+
logger(`Found ${messages.length} message(s), fetching details...`);
|
|
83
|
+
// Sort by newest first (descending order)
|
|
84
|
+
const sortedMessages = messages.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
85
|
+
const messageId = sortedMessages[0].id;
|
|
86
|
+
logger(`Found ${messageId}`);
|
|
87
|
+
const { from, to, subject, intro, text, html, createdAt, updatedAt, hasAttachments, attachments, } = await (0, api_2.getMessagesContent)(messageId);
|
|
88
|
+
const attachmentArray = [];
|
|
89
|
+
if (hasAttachments) {
|
|
90
|
+
for (const { id, filename } of attachments) {
|
|
91
|
+
logger(`Fetching attachment ID: ${id}`);
|
|
92
|
+
const attachmentData = await (0, api_1.getMessageAttachments)(messageId, id);
|
|
93
|
+
attachmentArray.push({ title: filename, data: attachmentData });
|
|
94
|
+
}
|
|
89
95
|
}
|
|
96
|
+
if (deleteAfterRead) {
|
|
97
|
+
await (0, api_2.deleteMessage)(messageId);
|
|
98
|
+
logger(`Deleted message ${messageId}`);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
from: from,
|
|
102
|
+
to: to,
|
|
103
|
+
subject,
|
|
104
|
+
intro,
|
|
105
|
+
text,
|
|
106
|
+
html,
|
|
107
|
+
createdAt,
|
|
108
|
+
updatedAt,
|
|
109
|
+
attachments: attachmentArray,
|
|
110
|
+
};
|
|
90
111
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
112
|
+
await new Promise((resolve) => setTimeout(resolve, waitInterval));
|
|
113
|
+
logger(`No messages found, waiting for ${waitInterval / 1000} seconds...`);
|
|
114
|
+
}
|
|
115
|
+
logger(`Waiting timeout of ${maxWaitTime / 1000} seconds reached. No messages found.`);
|
|
116
|
+
throw new Error(`No messages available within ${maxWaitTime / 1000} seconds timeout`);
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
// Cleanup account if accountId is provided
|
|
120
|
+
if (accountId) {
|
|
94
121
|
await (0, api_2.deleteAccount)(accountId);
|
|
95
|
-
|
|
96
|
-
from: from,
|
|
97
|
-
to: to,
|
|
98
|
-
subject,
|
|
99
|
-
intro,
|
|
100
|
-
text,
|
|
101
|
-
html,
|
|
102
|
-
createdAt,
|
|
103
|
-
updatedAt,
|
|
104
|
-
attachments: attachmentArray,
|
|
105
|
-
};
|
|
122
|
+
logger(`Deleted account ${accountId}`);
|
|
106
123
|
}
|
|
107
|
-
await new Promise((resolve) => setTimeout(resolve, waitInterval));
|
|
108
|
-
logger(`No messages found, waiting for ${waitInterval / 1000} seconds...`);
|
|
109
124
|
}
|
|
110
|
-
logger(`Waiting timeout of ${maxWaitTime / 1000} seconds reached. No messages found.`);
|
|
111
|
-
await (0, api_2.deleteAccount)(accountId);
|
|
112
|
-
throw new Error(`No messages available within ${maxWaitTime / 1000} seconds timeout`);
|
|
113
125
|
};
|
|
114
126
|
exports.getRecentEmail = getRecentEmail;
|
|
115
127
|
/**
|
|
@@ -129,6 +141,9 @@ exports.getRecentEmail = getRecentEmail;
|
|
|
129
141
|
*/
|
|
130
142
|
const getVerificationCode = async (text) => {
|
|
131
143
|
console.log('Extracting the verification code from the email content...');
|
|
144
|
+
if (!text) {
|
|
145
|
+
throw new Error('No text provided to extract verification code from.');
|
|
146
|
+
}
|
|
132
147
|
const matches = text.match(/\b\d{5,}\b/);
|
|
133
148
|
if (matches) {
|
|
134
149
|
return matches[0];
|