@rafaelsilvadeveloper/temp-mail-tester 1.0.2

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/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # @rafaelsilvadeveloper/temp-mail-tester
2
+
3
+ A strongly typed, zero-dependency TypeScript client for temporary email inboxes, ideal for automated E2E tests.
4
+
5
+ [![NPM Version](https://img.shields.io/npm/v/@rafaelsilvadeveloper/temp-mail-tester.svg?style=flat-square)](https://www.npmjs.com/package/@rafaelsilvadeveloper/temp-mail-tester)
6
+ [![Discord Support](https://img.shields.io/discord/1111111111?color=7289da&label=Discord&logo=discord&style=flat-square)](https://discord.gg/7Fw7snafYS)
7
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-zero-blueviolet.svg?style=flat-square)](https://www.npmjs.com/package/@rafaelsilvadeveloper/temp-mail-tester)
8
+
9
+ ## Features
10
+
11
+ * 🛡️ **TypeScript Definitions**: Complete types mapping the temporary email client API responses.
12
+ * 📦 **Zero Dependencies**: Built entirely using native `fetch`. Runs in Node.js, Bun, Cloudflare Workers, Edge, and Serverless environments.
13
+ * 🚦 **Poller Helper**: Built-in waiting methods designed specifically to retrieve validation links and codes inside E2E tests.
14
+ * 🚀 **Fast Generation**: Instant generation of clean temporary email addresses.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @rafaelsilvadeveloper/temp-mail-tester
20
+ ```
21
+
22
+ ## Getting Started
23
+
24
+ ```typescript
25
+ import { TempMailClient } from '@rafaelsilvadeveloper/temp-mail-tester';
26
+
27
+ const client = new TempMailClient();
28
+
29
+ async function run() {
30
+ // Create a new temporary inbox
31
+ const inbox = await client.createInbox();
32
+ console.log(`Email address created: ${inbox.email}`);
33
+
34
+ // Fetch list of messages
35
+ const messages = await client.getMessages(inbox.login, inbox.domain);
36
+ }
37
+
38
+ run();
39
+ ```
40
+
41
+ ## Pagination / Waiting for Email in Tests
42
+
43
+ Use `waitForEmail` to poll the temporary inbox until a specific email (e.g., matching a subject or containing a code) arrives:
44
+
45
+ ```typescript
46
+ import { TempMailClient } from '@rafaelsilvadeveloper/temp-mail-tester';
47
+
48
+ const client = new TempMailClient();
49
+
50
+ async function run() {
51
+ const inbox = await client.createInbox();
52
+
53
+ // Trigger your user registration here on Playwright / Cypress...
54
+
55
+ // Wait until email arrives containing verification code
56
+ const email = await client.waitForEmail(inbox.login, inbox.domain, {
57
+ subject: 'Verification',
58
+ contains: 'code is',
59
+ timeoutMs: 30000 // 30 seconds timeout
60
+ });
61
+
62
+ console.log(`Received email body: ${email.body}`);
63
+ }
64
+
65
+ run();
66
+ ```
67
+
68
+ ## Error Handling
69
+
70
+ Handles network or API issues by throwing standard exceptions when requests fail.
71
+
72
+ ```typescript
73
+ try {
74
+ await client.readMessage('invalid', '1secmail.com', 999999);
75
+ } catch (error) {
76
+ console.error('Failed to read email message:', error);
77
+ }
78
+ ```
79
+
80
+ ## Support
81
+
82
+ For support, questions, or discussions, join our Discord server:
83
+
84
+ [![Discord Server](https://img.shields.io/discord/1111111111?color=7289da&label=Discord&logo=discord&style=for-the-badge)](https://discord.gg/7Fw7snafYS)
85
+
86
+ ## License
87
+ MIT
@@ -0,0 +1,25 @@
1
+ import type { TempMailInbox, TempMailMessageHeader, TempMailMessage, WaitForEmailOptions } from './types';
2
+ /**
3
+ * TempMailClient
4
+ * A modern, zero-dependency client to interact with temporary inboxes for automated testing.
5
+ */
6
+ export declare class TempMailClient {
7
+ private static readonly BASE_URL;
8
+ private static readonly DOMAINS;
9
+ /**
10
+ * Generates a random temporary email inbox.
11
+ */
12
+ createInbox(): Promise<TempMailInbox>;
13
+ /**
14
+ * Lists all messages currently in the inbox.
15
+ */
16
+ getMessages(login: string, domain: string): Promise<TempMailMessageHeader[]>;
17
+ /**
18
+ * Reads a single email message content by ID.
19
+ */
20
+ readMessage(login: string, domain: string, id: number): Promise<TempMailMessage>;
21
+ /**
22
+ * Wait/Poll until an email matches specific criteria (useful for E2E testing).
23
+ */
24
+ waitForEmail(login: string, domain: string, options?: WaitForEmailOptions): Promise<TempMailMessage>;
25
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TempMailClient = void 0;
4
+ /**
5
+ * TempMailClient
6
+ * A modern, zero-dependency client to interact with temporary inboxes for automated testing.
7
+ */
8
+ class TempMailClient {
9
+ /**
10
+ * Generates a random temporary email inbox.
11
+ */
12
+ async createInbox() {
13
+ const randomName = Math.random().toString(36).substring(2, 12);
14
+ const domain = TempMailClient.DOMAINS[Math.floor(Math.random() * TempMailClient.DOMAINS.length)];
15
+ return {
16
+ email: `${randomName}@${domain}`,
17
+ login: randomName,
18
+ domain,
19
+ };
20
+ }
21
+ /**
22
+ * Lists all messages currently in the inbox.
23
+ */
24
+ async getMessages(login, domain) {
25
+ const url = `${TempMailClient.BASE_URL}?action=getMessages&login=${login}&domain=${domain}`;
26
+ const response = await fetch(url);
27
+ if (!response.ok) {
28
+ throw new Error(`Failed to fetch messages: ${response.statusText}`);
29
+ }
30
+ return response.json();
31
+ }
32
+ /**
33
+ * Reads a single email message content by ID.
34
+ */
35
+ async readMessage(login, domain, id) {
36
+ const url = `${TempMailClient.BASE_URL}?action=readMessage&login=${login}&domain=${domain}&id=${id}`;
37
+ const response = await fetch(url);
38
+ if (!response.ok) {
39
+ throw new Error(`Failed to read message ${id}: ${response.statusText}`);
40
+ }
41
+ return response.json();
42
+ }
43
+ /**
44
+ * Wait/Poll until an email matches specific criteria (useful for E2E testing).
45
+ */
46
+ async waitForEmail(login, domain, options = {}) {
47
+ const timeout = options.timeoutMs ?? 30000;
48
+ const interval = options.intervalMs ?? 2000;
49
+ const startTime = Date.now();
50
+ while (Date.now() - startTime < timeout) {
51
+ const messages = await this.getMessages(login, domain);
52
+ for (const msg of messages) {
53
+ let matches = true;
54
+ if (options.subject && !msg.subject.toLowerCase().includes(options.subject.toLowerCase())) {
55
+ matches = false;
56
+ }
57
+ if (matches) {
58
+ // Read full content to check 'contains' option inside body
59
+ const fullMessage = await this.readMessage(login, domain, msg.id);
60
+ if (options.contains) {
61
+ const bodyContent = (fullMessage.body +
62
+ fullMessage.textBody +
63
+ fullMessage.htmlBody).toLowerCase();
64
+ if (!bodyContent.includes(options.contains.toLowerCase())) {
65
+ matches = false;
66
+ }
67
+ }
68
+ if (matches) {
69
+ return fullMessage;
70
+ }
71
+ }
72
+ }
73
+ await new Promise((resolve) => setTimeout(resolve, interval));
74
+ }
75
+ throw new Error(`Timeout exceeded waiting for email matching options: ${JSON.stringify(options)}`);
76
+ }
77
+ }
78
+ exports.TempMailClient = TempMailClient;
79
+ TempMailClient.BASE_URL = 'https://www.1secmail.com/api/v1/';
80
+ TempMailClient.DOMAINS = ['1secmail.com', '1secmail.org', '1secmail.net'];
@@ -0,0 +1,2 @@
1
+ export { TempMailClient } from './TempMailClient';
2
+ export type * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TempMailClient = void 0;
4
+ var TempMailClient_1 = require("./TempMailClient");
5
+ Object.defineProperty(exports, "TempMailClient", { enumerable: true, get: function () { return TempMailClient_1.TempMailClient; } });
@@ -0,0 +1,22 @@
1
+ export interface TempMailInbox {
2
+ email: string;
3
+ login: string;
4
+ domain: string;
5
+ }
6
+ export interface TempMailMessageHeader {
7
+ id: number;
8
+ from: string;
9
+ subject: string;
10
+ date: string;
11
+ }
12
+ export interface TempMailMessage extends TempMailMessageHeader {
13
+ body: string;
14
+ textBody: string;
15
+ htmlBody: string;
16
+ }
17
+ export interface WaitForEmailOptions {
18
+ subject?: string;
19
+ contains?: string;
20
+ timeoutMs?: number;
21
+ intervalMs?: number;
22
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@rafaelsilvadeveloper/temp-mail-tester",
3
+ "version": "1.0.2",
4
+ "description": "A strongly typed, zero-dependency TypeScript client for temporary email inboxes, ideal for automated E2E tests.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/rafael-packages/temp-mail-tester.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/rafael-packages/temp-mail-tester/issues"
11
+ },
12
+ "homepage": "https://github.com/rafael-packages/temp-mail-tester#readme",
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "type": "module",
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "test": "bun test",
22
+ "prepare": "bun run build",
23
+ "lint": "eslint src/**/*.ts",
24
+ "format": "prettier --write src/**/*.ts tests/**/*.ts"
25
+ },
26
+ "keywords": [
27
+ "temp-mail",
28
+ "temporary-email",
29
+ "testing",
30
+ "e2e",
31
+ "cypress",
32
+ "playwright",
33
+ "typescript"
34
+ ],
35
+ "author": "realkalashnikov",
36
+ "license": "MIT",
37
+ "peerDependencies": {
38
+ "typescript": "^5.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^25.9.1",
42
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
43
+ "@typescript-eslint/parser": "^7.18.0",
44
+ "eslint": "^8.57.0",
45
+ "prettier": "^3.3.3"
46
+ }
47
+ }