temp-disposable-email 1.5.0 → 1.6.1
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/CHANGELOG.md +11 -21
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/accountService.d.ts +37 -0
- package/dist/cjs/services/accountService.d.ts.map +1 -0
- package/dist/cjs/services/accountService.js +100 -0
- package/dist/cjs/services/accountService.js.map +1 -0
- package/dist/cjs/services/authService.d.ts +3 -0
- package/dist/cjs/services/authService.d.ts.map +1 -0
- package/dist/cjs/services/authService.js +22 -0
- package/dist/cjs/services/authService.js.map +1 -0
- package/dist/cjs/services/messageService.d.ts +54 -0
- package/dist/cjs/services/messageService.d.ts.map +1 -0
- package/dist/cjs/services/messageService.js +122 -0
- package/dist/cjs/services/messageService.js.map +1 -0
- package/dist/cjs/utils/api.d.ts +7 -0
- package/dist/cjs/utils/api.d.ts.map +1 -0
- package/dist/cjs/utils/api.js +48 -0
- package/dist/cjs/utils/api.js.map +1 -0
- package/dist/cjs/utils/constant.d.ts +2 -0
- package/dist/cjs/utils/constant.d.ts.map +1 -0
- package/dist/cjs/utils/constant.js +40 -0
- package/dist/cjs/utils/constant.js.map +1 -0
- package/dist/cjs/utils/delay.d.ts +2 -0
- package/dist/cjs/utils/delay.d.ts.map +1 -0
- package/dist/cjs/utils/delay.js +6 -0
- package/dist/cjs/utils/delay.js.map +1 -0
- package/dist/cjs/utils/generateRandomName.d.ts +2 -0
- package/dist/cjs/utils/generateRandomName.d.ts.map +1 -0
- package/dist/cjs/utils/generateRandomName.js +6 -0
- package/dist/cjs/utils/generateRandomName.js.map +1 -0
- package/dist/cjs/utils/getVerificationCode.d.ts +17 -0
- package/dist/cjs/utils/getVerificationCode.d.ts.map +1 -0
- package/dist/cjs/utils/getVerificationCode.js +29 -0
- package/dist/cjs/utils/getVerificationCode.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/services/accountService.d.ts +37 -0
- package/dist/esm/services/accountService.d.ts.map +1 -0
- package/dist/esm/services/accountService.js +92 -0
- package/dist/esm/services/accountService.js.map +1 -0
- package/dist/esm/services/authService.d.ts +3 -0
- package/dist/esm/services/authService.d.ts.map +1 -0
- package/dist/esm/services/authService.js +14 -0
- package/dist/esm/services/authService.js.map +1 -0
- package/dist/esm/services/messageService.d.ts +54 -0
- package/dist/esm/services/messageService.d.ts.map +1 -0
- package/dist/esm/services/messageService.js +114 -0
- package/dist/esm/services/messageService.js.map +1 -0
- package/dist/esm/utils/api.d.ts +7 -0
- package/dist/esm/utils/api.d.ts.map +1 -0
- package/dist/esm/utils/api.js +39 -0
- package/dist/esm/utils/api.js.map +1 -0
- package/dist/esm/utils/constant.d.ts +2 -0
- package/dist/esm/utils/constant.d.ts.map +1 -0
- package/dist/esm/utils/constant.js +4 -0
- package/dist/esm/utils/constant.js.map +1 -0
- package/dist/esm/utils/delay.d.ts +2 -0
- package/dist/esm/utils/delay.d.ts.map +1 -0
- package/dist/esm/utils/delay.js +2 -0
- package/dist/esm/utils/delay.js.map +1 -0
- package/dist/esm/utils/generateRandomName.d.ts +2 -0
- package/dist/esm/utils/generateRandomName.d.ts.map +1 -0
- package/dist/esm/utils/generateRandomName.js +2 -0
- package/dist/esm/utils/generateRandomName.js.map +1 -0
- package/dist/esm/utils/getVerificationCode.d.ts +17 -0
- package/dist/esm/utils/getVerificationCode.d.ts.map +1 -0
- package/dist/esm/utils/getVerificationCode.js +25 -0
- package/dist/esm/utils/getVerificationCode.js.map +1 -0
- package/package.json +12 -4
- package/src/utils/constant.ts +1 -1
- package/tsconfig.cjs.json +15 -0
- package/tsconfig.json +9 -7
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts a verification code from the provided email content.
|
|
3
|
+
*
|
|
4
|
+
* This function scans the given text for a sequence of 5 or more
|
|
5
|
+
* consecutive digits and returns the first valid verification code.
|
|
6
|
+
* If no valid sequence is found, the function returns `null`.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} text - The content of the email, typically the body.
|
|
9
|
+
* @returns {Promise<string | null>} The first verification code found, or `null` if no valid code exists.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const emailContent = "Your code is 123456.";
|
|
13
|
+
* const verificationCode = await getVerificationCode(emailContent);
|
|
14
|
+
* console.log(verificationCode); // Output: "123456"
|
|
15
|
+
*/
|
|
16
|
+
export declare const getVerificationCode: (text: string) => Promise<string | null>;
|
|
17
|
+
//# sourceMappingURL=getVerificationCode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVerificationCode.d.ts","sourceRoot":"","sources":["../../../src/utils/getVerificationCode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,mBAAmB,SACxB,MAAM,KACX,OAAO,CAAC,MAAM,GAAG,IAAI,CAQvB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts a verification code from the provided email content.
|
|
4
|
+
*
|
|
5
|
+
* This function scans the given text for a sequence of 5 or more
|
|
6
|
+
* consecutive digits and returns the first valid verification code.
|
|
7
|
+
* If no valid sequence is found, the function returns `null`.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} text - The content of the email, typically the body.
|
|
10
|
+
* @returns {Promise<string | null>} The first verification code found, or `null` if no valid code exists.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const emailContent = "Your code is 123456.";
|
|
14
|
+
* const verificationCode = await getVerificationCode(emailContent);
|
|
15
|
+
* console.log(verificationCode); // Output: "123456"
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.getVerificationCode = void 0;
|
|
19
|
+
const getVerificationCode = async (text) => {
|
|
20
|
+
console.log('Extracting the verification code from the email content...');
|
|
21
|
+
const matches = text.match(/\b\d{5,}\b/);
|
|
22
|
+
if (matches) {
|
|
23
|
+
return matches[0];
|
|
24
|
+
}
|
|
25
|
+
console.warn('No verification code found in the provided email content.');
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
28
|
+
exports.getVerificationCode = getVerificationCode;
|
|
29
|
+
//# sourceMappingURL=getVerificationCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVerificationCode.js","sourceRoot":"","sources":["../../../src/utils/getVerificationCode.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEI,MAAM,mBAAmB,GAAG,KAAK,EACtC,IAAY,EACY,EAAE;IAC1B,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACzC,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,2DAA2D,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAVW,QAAA,mBAAmB,uBAU9B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createInbox, deleteAccount } from './services/accountService';
|
|
2
|
+
export { getRecentEmail, deleteMessage, MessageContent, GetEmailOptions, } from './services/messageService';
|
|
3
|
+
export { getVerificationCode } from './utils/getVerificationCode';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EACL,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EACL,cAAc,EACd,aAAa,GAGd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new email inbox with a unique address.
|
|
3
|
+
*
|
|
4
|
+
* This function selects an available domain, generates an email
|
|
5
|
+
* address, and attempts to create an account on the Mail.tm service.
|
|
6
|
+
* If account creation is rate-limited, the function retries with a
|
|
7
|
+
* delay. Upon successful creation, it authenticates the account and
|
|
8
|
+
* stores the token and account ID for future API calls.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} [username] - Optional username; a random one is generated if not provided.
|
|
11
|
+
* @returns {Promise<string>} The generated email address.
|
|
12
|
+
*
|
|
13
|
+
* @throws {Error} If no domains are available or account creation fails.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const email = await createInbox("customUser");
|
|
17
|
+
* console.log(email); // Outputs: "customUser@mail.tm"
|
|
18
|
+
*/
|
|
19
|
+
export declare const createInbox: (username?: string) => Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Deletes the account created during `createInbox`.
|
|
22
|
+
*
|
|
23
|
+
* This function removes the email account from the Mail.tm service
|
|
24
|
+
* and clears the stored authentication token and account ID.
|
|
25
|
+
* Subsequent API calls requiring authentication will fail until a
|
|
26
|
+
* new account is created.
|
|
27
|
+
*
|
|
28
|
+
* @returns {Promise<void>} Resolves when the account is successfully deleted.
|
|
29
|
+
*
|
|
30
|
+
* @throws {Error} If no account is authenticated or deletion fails.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* await deleteAccount();
|
|
34
|
+
* console.log("Account deleted successfully.");
|
|
35
|
+
*/
|
|
36
|
+
export declare const deleteAccount: () => Promise<void>;
|
|
37
|
+
//# sourceMappingURL=accountService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountService.d.ts","sourceRoot":"","sources":["../../../src/services/accountService.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,WAAW,cAAqB,MAAM,KAAG,OAAO,CAAC,MAAM,CA2CnE,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,IAAI,CAelD,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { authenticate, getToken } from './authService';
|
|
3
|
+
import { generateRandomName } from '../utils/generateRandomName';
|
|
4
|
+
import { delay } from '../utils/delay';
|
|
5
|
+
import { BASE_URL } from '../utils/constant';
|
|
6
|
+
let accountId = null;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new email inbox with a unique address.
|
|
9
|
+
*
|
|
10
|
+
* This function selects an available domain, generates an email
|
|
11
|
+
* address, and attempts to create an account on the Mail.tm service.
|
|
12
|
+
* If account creation is rate-limited, the function retries with a
|
|
13
|
+
* delay. Upon successful creation, it authenticates the account and
|
|
14
|
+
* stores the token and account ID for future API calls.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} [username] - Optional username; a random one is generated if not provided.
|
|
17
|
+
* @returns {Promise<string>} The generated email address.
|
|
18
|
+
*
|
|
19
|
+
* @throws {Error} If no domains are available or account creation fails.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const email = await createInbox("customUser");
|
|
23
|
+
* console.log(email); // Outputs: "customUser@mail.tm"
|
|
24
|
+
*/
|
|
25
|
+
export const createInbox = async (username) => {
|
|
26
|
+
const domainsResponse = await axios.get(`${BASE_URL}/domains`, {
|
|
27
|
+
headers: { accept: 'application/ld+json' },
|
|
28
|
+
});
|
|
29
|
+
const domains = domainsResponse.data['hydra:member'].map((domain) => domain.domain);
|
|
30
|
+
if (domains.length === 0)
|
|
31
|
+
throw new Error('No available domains.');
|
|
32
|
+
const emailAddress = `${username || generateRandomName()}@${domains[0]}`;
|
|
33
|
+
const password = generateRandomName();
|
|
34
|
+
let attempts = 0;
|
|
35
|
+
const maxRetries = 5;
|
|
36
|
+
while (attempts < maxRetries) {
|
|
37
|
+
try {
|
|
38
|
+
const accountResponse = await axios.post(`${BASE_URL}/accounts`, { address: emailAddress, password }, {
|
|
39
|
+
headers: {
|
|
40
|
+
accept: 'application/json',
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
accountId = accountResponse.data.id;
|
|
45
|
+
await authenticate(emailAddress, password);
|
|
46
|
+
return emailAddress;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error.response?.status === 429) {
|
|
50
|
+
attempts++;
|
|
51
|
+
const retryAfter = error.response.headers['retry-after']
|
|
52
|
+
? parseInt(error.response.headers['retry-after'])
|
|
53
|
+
: 5;
|
|
54
|
+
await delay(retryAfter * 1000);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw new Error('Failed to create account after multiple retries.');
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Deletes the account created during `createInbox`.
|
|
65
|
+
*
|
|
66
|
+
* This function removes the email account from the Mail.tm service
|
|
67
|
+
* and clears the stored authentication token and account ID.
|
|
68
|
+
* Subsequent API calls requiring authentication will fail until a
|
|
69
|
+
* new account is created.
|
|
70
|
+
*
|
|
71
|
+
* @returns {Promise<void>} Resolves when the account is successfully deleted.
|
|
72
|
+
*
|
|
73
|
+
* @throws {Error} If no account is authenticated or deletion fails.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* await deleteAccount();
|
|
77
|
+
* console.log("Account deleted successfully.");
|
|
78
|
+
*/
|
|
79
|
+
export const deleteAccount = async () => {
|
|
80
|
+
const token = getToken();
|
|
81
|
+
if (!token || !accountId) {
|
|
82
|
+
throw new Error('Account information missing. Create and authenticate an account first.');
|
|
83
|
+
}
|
|
84
|
+
await axios.delete(`${BASE_URL}/accounts/${accountId}`, {
|
|
85
|
+
headers: {
|
|
86
|
+
accept: '*/*',
|
|
87
|
+
Authorization: `Bearer ${token}`,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
accountId = null;
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=accountService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountService.js","sourceRoot":"","sources":["../../../src/services/accountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,IAAI,SAAS,GAAkB,IAAI,CAAC;AACpC;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,QAAiB,EAAmB,EAAE;IACtE,MAAM,eAAe,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,UAAU,EAAE;QAC7D,OAAO,EAAE,EAAE,MAAM,EAAE,qBAAqB,EAAE;KAC3C,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,GAAG,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;YACd,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;AACtE,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,IAAmB,EAAE;IACrD,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IACzB,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,wEAAwE,CACzE,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,QAAQ,aAAa,SAAS,EAAE,EAAE;QACtD,OAAO,EAAE;YACP,MAAM,EAAE,KAAK;YACb,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC;KACF,CAAC,CAAC;IACH,SAAS,GAAG,IAAI,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authService.d.ts","sourceRoot":"","sources":["../../../src/services/authService.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,UAChB,MAAM,YACH,MAAM,KACf,OAAO,CAAC,IAAI,CAYd,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,MAAM,GAAG,IAAa,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { BASE_URL } from '../utils/constant';
|
|
3
|
+
let token = null;
|
|
4
|
+
export const authenticate = async (email, password) => {
|
|
5
|
+
const response = await axios.post(`${BASE_URL}/token`, { address: email, password }, {
|
|
6
|
+
headers: {
|
|
7
|
+
accept: 'application/json',
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
token = response.data.token;
|
|
12
|
+
};
|
|
13
|
+
export const getToken = () => token;
|
|
14
|
+
//# sourceMappingURL=authService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authService.js","sourceRoot":"","sources":["../../../src/services/authService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,IAAI,KAAK,GAAkB,IAAI,CAAC;AAEhC,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,KAAa,EACb,QAAgB,EACD,EAAE;IACjB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAC/B,GAAG,QAAQ,QAAQ,EACnB,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAC5B;QACE,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;SACnC;KACF,CACF,CAAC;IACF,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAkB,EAAE,CAAC,KAAK,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface MessageContent {
|
|
2
|
+
from: {
|
|
3
|
+
address: string;
|
|
4
|
+
};
|
|
5
|
+
to: {
|
|
6
|
+
address: string;
|
|
7
|
+
}[];
|
|
8
|
+
subject: string;
|
|
9
|
+
intro: string;
|
|
10
|
+
text: string;
|
|
11
|
+
html: string;
|
|
12
|
+
}
|
|
13
|
+
export interface GetEmailOptions {
|
|
14
|
+
maxWaitTime?: number;
|
|
15
|
+
waitInterval?: number;
|
|
16
|
+
logPolling?: boolean;
|
|
17
|
+
deleteAfterRead?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the latest message from the inbox.
|
|
21
|
+
*
|
|
22
|
+
* If messages are available, this function fetches the first one and
|
|
23
|
+
* returns its details. Polling options can be specified to wait for
|
|
24
|
+
* messages if the inbox is empty. Optionally, the message can be
|
|
25
|
+
* deleted after reading.
|
|
26
|
+
*
|
|
27
|
+
* @param {GetEmailOptions} [options] - Optional settings for polling and deletion.
|
|
28
|
+
* @returns {Promise<MessageContent | null>} The email content (sender, recipient, subject, text, HTML), or `null` if no messages are found.
|
|
29
|
+
*
|
|
30
|
+
* @throws {Error} If no messages are available within the polling timeout or authentication fails.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const message = await getRecentEmail({ maxWaitTime: 5000, waitInterval: 1000, logPolling: true });
|
|
34
|
+
* console.log(message.subject); // Outputs: "Hello!"
|
|
35
|
+
*/
|
|
36
|
+
export declare const getRecentEmail: (options?: GetEmailOptions) => Promise<MessageContent | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Deletes a message by its unique ID from the Mail.tm inbox.
|
|
39
|
+
*
|
|
40
|
+
* This function requires a valid authentication token. If the
|
|
41
|
+
* token is not set, an error is thrown. The message is deleted
|
|
42
|
+
* using the Mail.tm API, and a success or failure message is logged.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} messageId - The unique ID of the message to delete.
|
|
45
|
+
* @returns {Promise<void>} Resolves after the message is deleted.
|
|
46
|
+
*
|
|
47
|
+
* @throws {Error} If authentication is missing or the deletion fails.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* await deleteMessage("12345");
|
|
51
|
+
* console.log("Message deleted successfully.");
|
|
52
|
+
*/
|
|
53
|
+
export declare const deleteMessage: (messageId: string) => Promise<void>;
|
|
54
|
+
//# sourceMappingURL=messageService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageService.d.ts","sourceRoot":"","sources":["../../../src/services/messageService.ts"],"names":[],"mappings":"AAKA,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,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;CAC3B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,aACf,eAAe,KACxB,OAAO,CAAC,cAAc,GAAG,IAAI,CAkF/B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,cAAqB,MAAM,KAAG,OAAO,CAAC,IAAI,CAenE,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getToken } from './authService';
|
|
3
|
+
import { BASE_URL } from '../utils/constant';
|
|
4
|
+
import { fetchMessageContent, fetchMessages } from '../utils/api';
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the latest message from the inbox.
|
|
7
|
+
*
|
|
8
|
+
* If messages are available, this function fetches the first one and
|
|
9
|
+
* returns its details. Polling options can be specified to wait for
|
|
10
|
+
* messages if the inbox is empty. Optionally, the message can be
|
|
11
|
+
* deleted after reading.
|
|
12
|
+
*
|
|
13
|
+
* @param {GetEmailOptions} [options] - Optional settings for polling and deletion.
|
|
14
|
+
* @returns {Promise<MessageContent | null>} The email content (sender, recipient, subject, text, HTML), or `null` if no messages are found.
|
|
15
|
+
*
|
|
16
|
+
* @throws {Error} If no messages are available within the polling timeout or authentication fails.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const message = await getRecentEmail({ maxWaitTime: 5000, waitInterval: 1000, logPolling: true });
|
|
20
|
+
* console.log(message.subject); // Outputs: "Hello!"
|
|
21
|
+
*/
|
|
22
|
+
export const getRecentEmail = async (options) => {
|
|
23
|
+
const token = getToken();
|
|
24
|
+
const { maxWaitTime = 30000, waitInterval = 2000, logPolling = false, deleteAfterRead = false, } = options || {};
|
|
25
|
+
if (!token)
|
|
26
|
+
throw new Error('Authentication required. Call createInbox() first.');
|
|
27
|
+
if (!options) {
|
|
28
|
+
const messages = await fetchMessages();
|
|
29
|
+
if (messages.length === 0)
|
|
30
|
+
throw new Error('No messages available');
|
|
31
|
+
const messageId = messages[0].id;
|
|
32
|
+
const { from, to, subject, intro, text, html } = await fetchMessageContent(messageId);
|
|
33
|
+
if (deleteAfterRead) {
|
|
34
|
+
await deleteMessage(messageId);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
from: from.address,
|
|
38
|
+
to: to[0].address,
|
|
39
|
+
subject,
|
|
40
|
+
intro,
|
|
41
|
+
text,
|
|
42
|
+
html,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const startTime = Date.now();
|
|
46
|
+
if (logPolling) {
|
|
47
|
+
console.log(`Polling started with a timeout of ${maxWaitTime / 1000}sec and interval of ${waitInterval / 1000}sec.`);
|
|
48
|
+
}
|
|
49
|
+
while (Date.now() - startTime < maxWaitTime) {
|
|
50
|
+
const messages = await fetchMessages();
|
|
51
|
+
if (messages.length > 0) {
|
|
52
|
+
if (logPolling) {
|
|
53
|
+
console.log(`Found ${messages.length} message(s), fetching details...`);
|
|
54
|
+
}
|
|
55
|
+
const messageId = messages[0].id;
|
|
56
|
+
if (logPolling) {
|
|
57
|
+
console.log(`Message retrieved: ${messageId}`);
|
|
58
|
+
}
|
|
59
|
+
const { from, to, subject, intro, text, html } = await fetchMessageContent(messageId);
|
|
60
|
+
if (deleteAfterRead) {
|
|
61
|
+
await deleteMessage(messageId);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
from: from.address,
|
|
65
|
+
to: to[0].address,
|
|
66
|
+
subject,
|
|
67
|
+
intro,
|
|
68
|
+
text,
|
|
69
|
+
html,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
await new Promise((resolve) => setTimeout(resolve, waitInterval));
|
|
73
|
+
if (logPolling) {
|
|
74
|
+
console.log(`No messages found, waiting for ${waitInterval / 1000} seconds...`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (logPolling) {
|
|
78
|
+
console.log(`Waiting timeout of ${maxWaitTime / 1000} seconds reached. No messages found.`);
|
|
79
|
+
}
|
|
80
|
+
throw new Error(`No messages available within ${maxWaitTime / 1000} seconds timeout`);
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Deletes a message by its unique ID from the Mail.tm inbox.
|
|
84
|
+
*
|
|
85
|
+
* This function requires a valid authentication token. If the
|
|
86
|
+
* token is not set, an error is thrown. The message is deleted
|
|
87
|
+
* using the Mail.tm API, and a success or failure message is logged.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} messageId - The unique ID of the message to delete.
|
|
90
|
+
* @returns {Promise<void>} Resolves after the message is deleted.
|
|
91
|
+
*
|
|
92
|
+
* @throws {Error} If authentication is missing or the deletion fails.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* await deleteMessage("12345");
|
|
96
|
+
* console.log("Message deleted successfully.");
|
|
97
|
+
*/
|
|
98
|
+
export const deleteMessage = async (messageId) => {
|
|
99
|
+
const token = getToken();
|
|
100
|
+
if (!token)
|
|
101
|
+
throw new Error('Authentication required. Call createInbox() first.');
|
|
102
|
+
try {
|
|
103
|
+
await axios.delete(`${BASE_URL}/messages/${messageId}`, {
|
|
104
|
+
headers: {
|
|
105
|
+
accept: '*/*',
|
|
106
|
+
Authorization: `Bearer ${token}`,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error(`Failed to delete message with ID ${messageId}: ${error}`);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=messageService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageService.js","sourceRoot":"","sources":["../../../src/services/messageService.ts"],"names":[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C;QACJ,CAAC;IACH,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CACT,sBACE,WAAW,GAAG,IAChB,sCAAsC,CACvC,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,KAAK,CACb,gCAAgC,WAAW,GAAG,IAAI,kBAAkB,CACrE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,SAAiB,EAAiB,EAAE;IACtE,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IACzB,IAAI,CAAC,KAAK;QACR,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IAExE,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,QAAQ,aAAa,SAAS,EAAE,EAAE;YACtD,OAAO,EAAE;gBACP,MAAM,EAAE,KAAK;gBACb,aAAa,EAAE,UAAU,KAAK,EAAE;aACjC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,oCAAoC,SAAS,KAAK,KAAK,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const getAuthHeaders: () => {
|
|
2
|
+
accept: string;
|
|
3
|
+
Authorization: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const fetchMessages: () => Promise<any[]>;
|
|
6
|
+
export declare const fetchMessageContent: (messageId: string) => Promise<any>;
|
|
7
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/utils/api.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc;;;CAS1B,CAAC;AAEF,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,GAAG,EAAE,CAYnD,CAAC;AAEF,eAAO,MAAM,mBAAmB,cAAqB,MAAM,KAAG,OAAO,CAAC,GAAG,CAUxE,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { BASE_URL } from './constant';
|
|
3
|
+
import { getToken } from '../services/authService';
|
|
4
|
+
export const getAuthHeaders = () => {
|
|
5
|
+
const token = getToken();
|
|
6
|
+
if (!token) {
|
|
7
|
+
throw new Error('Authentication required. Token not found.');
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
accept: 'application/json',
|
|
11
|
+
Authorization: `Bearer ${token}`,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export const fetchMessages = async () => {
|
|
15
|
+
try {
|
|
16
|
+
const res = await axios.get(`${BASE_URL}/messages`, {
|
|
17
|
+
headers: getAuthHeaders(),
|
|
18
|
+
});
|
|
19
|
+
console.log(JSON.stringify(res.data));
|
|
20
|
+
return res.data;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error('Error fetching messages:', error);
|
|
24
|
+
throw new Error('Failed to fetch messages. Please try again later.');
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export const fetchMessageContent = async (messageId) => {
|
|
28
|
+
try {
|
|
29
|
+
const res = await axios.get(`${BASE_URL}/messages/${messageId}`, {
|
|
30
|
+
headers: getAuthHeaders(),
|
|
31
|
+
});
|
|
32
|
+
return res.data;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error(`Error fetching message content for ID ${messageId}:`, error);
|
|
36
|
+
throw new Error('Failed to fetch message content. Please try again later.');
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ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,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../src/utils/constant.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,QAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/utils/constant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../src/utils/delay.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,OAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CACI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../src/utils/delay.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CACjD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateRandomName.d.ts","sourceRoot":"","sources":["../../../src/utils/generateRandomName.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,QAAO,MACO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateRandomName.js","sourceRoot":"","sources":["../../../src/utils/generateRandomName.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAW,EAAE,CAC7C,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts a verification code from the provided email content.
|
|
3
|
+
*
|
|
4
|
+
* This function scans the given text for a sequence of 5 or more
|
|
5
|
+
* consecutive digits and returns the first valid verification code.
|
|
6
|
+
* If no valid sequence is found, the function returns `null`.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} text - The content of the email, typically the body.
|
|
9
|
+
* @returns {Promise<string | null>} The first verification code found, or `null` if no valid code exists.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const emailContent = "Your code is 123456.";
|
|
13
|
+
* const verificationCode = await getVerificationCode(emailContent);
|
|
14
|
+
* console.log(verificationCode); // Output: "123456"
|
|
15
|
+
*/
|
|
16
|
+
export declare const getVerificationCode: (text: string) => Promise<string | null>;
|
|
17
|
+
//# sourceMappingURL=getVerificationCode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVerificationCode.d.ts","sourceRoot":"","sources":["../../../src/utils/getVerificationCode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,mBAAmB,SACxB,MAAM,KACX,OAAO,CAAC,MAAM,GAAG,IAAI,CAQvB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts a verification code from the provided email content.
|
|
3
|
+
*
|
|
4
|
+
* This function scans the given text for a sequence of 5 or more
|
|
5
|
+
* consecutive digits and returns the first valid verification code.
|
|
6
|
+
* If no valid sequence is found, the function returns `null`.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} text - The content of the email, typically the body.
|
|
9
|
+
* @returns {Promise<string | null>} The first verification code found, or `null` if no valid code exists.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const emailContent = "Your code is 123456.";
|
|
13
|
+
* const verificationCode = await getVerificationCode(emailContent);
|
|
14
|
+
* console.log(verificationCode); // Output: "123456"
|
|
15
|
+
*/
|
|
16
|
+
export const getVerificationCode = async (text) => {
|
|
17
|
+
console.log('Extracting the verification code from the email content...');
|
|
18
|
+
const matches = text.match(/\b\d{5,}\b/);
|
|
19
|
+
if (matches) {
|
|
20
|
+
return matches[0];
|
|
21
|
+
}
|
|
22
|
+
console.warn('No verification code found in the provided email content.');
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=getVerificationCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVerificationCode.js","sourceRoot":"","sources":["../../../src/utils/getVerificationCode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,IAAY,EACY,EAAE;IAC1B,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACzC,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,2DAA2D,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "temp-disposable-email",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"require": "./dist/cjs/index.js",
|
|
9
|
+
"import": "./dist/esm/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"types": "dist/esm/index.d.ts",
|
|
6
13
|
"scripts": {
|
|
7
|
-
"build": "tsc",
|
|
14
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
|
|
8
15
|
"test": "jest",
|
|
9
16
|
"lint": "eslint src --fix",
|
|
10
17
|
"prepare": "npm run build"
|
|
@@ -31,7 +38,8 @@
|
|
|
31
38
|
"homepage": "https://github.com/pirasanthan-jesugeevegan/temp-disposable-email#readme",
|
|
32
39
|
"dependencies": {
|
|
33
40
|
"axios": "^1.7.8",
|
|
34
|
-
"dotenv": "^16.4.5"
|
|
41
|
+
"dotenv": "^16.4.5",
|
|
42
|
+
"tslib": "^2.8.1"
|
|
35
43
|
},
|
|
36
44
|
"devDependencies": {
|
|
37
45
|
"@types/jest": "^29.5.14",
|
package/src/utils/constant.ts
CHANGED