temp-disposable-email 1.12.5 → 1.13.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/dist/{esm/utils → cjs}/api.d.ts +1 -11
- package/dist/cjs/api.d.ts.map +1 -0
- package/dist/cjs/{utils/api.js → api.js} +23 -22
- package/dist/cjs/api.js.map +1 -0
- package/dist/cjs/index.d.ts +77 -4
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +138 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/{cjs/utils → esm}/api.d.ts +1 -11
- package/dist/esm/api.d.ts.map +1 -0
- package/dist/esm/{utils/api.js → api.js} +21 -21
- package/dist/esm/api.js.map +1 -0
- package/dist/esm/index.d.ts +77 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +134 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/services/accountService.d.ts +0 -20
- package/dist/cjs/services/accountService.d.ts.map +0 -1
- package/dist/cjs/services/accountService.js +0 -58
- package/dist/cjs/services/accountService.js.map +0 -1
- package/dist/cjs/services/authService.d.ts +0 -3
- package/dist/cjs/services/authService.d.ts.map +0 -1
- package/dist/cjs/services/authService.js +0 -22
- package/dist/cjs/services/authService.js.map +0 -1
- package/dist/cjs/services/messageService.d.ts +0 -60
- package/dist/cjs/services/messageService.d.ts.map +0 -1
- package/dist/cjs/services/messageService.js +0 -99
- package/dist/cjs/services/messageService.js.map +0 -1
- package/dist/cjs/utils/api.d.ts.map +0 -1
- package/dist/cjs/utils/api.js.map +0 -1
- package/dist/cjs/utils/constant.d.ts +0 -2
- package/dist/cjs/utils/constant.d.ts.map +0 -1
- package/dist/cjs/utils/constant.js +0 -5
- package/dist/cjs/utils/constant.js.map +0 -1
- package/dist/cjs/utils/delay.d.ts +0 -2
- package/dist/cjs/utils/delay.d.ts.map +0 -1
- package/dist/cjs/utils/delay.js +0 -6
- package/dist/cjs/utils/delay.js.map +0 -1
- package/dist/cjs/utils/generateRandomName.d.ts +0 -2
- package/dist/cjs/utils/generateRandomName.d.ts.map +0 -1
- package/dist/cjs/utils/generateRandomName.js +0 -6
- package/dist/cjs/utils/generateRandomName.js.map +0 -1
- package/dist/cjs/utils/getVerificationCode.d.ts +0 -17
- package/dist/cjs/utils/getVerificationCode.d.ts.map +0 -1
- package/dist/cjs/utils/getVerificationCode.js +0 -28
- package/dist/cjs/utils/getVerificationCode.js.map +0 -1
- package/dist/esm/services/accountService.d.ts +0 -20
- package/dist/esm/services/accountService.d.ts.map +0 -1
- package/dist/esm/services/accountService.js +0 -54
- package/dist/esm/services/accountService.js.map +0 -1
- package/dist/esm/services/authService.d.ts +0 -3
- package/dist/esm/services/authService.d.ts.map +0 -1
- package/dist/esm/services/authService.js +0 -14
- package/dist/esm/services/authService.js.map +0 -1
- package/dist/esm/services/messageService.d.ts +0 -60
- package/dist/esm/services/messageService.d.ts.map +0 -1
- package/dist/esm/services/messageService.js +0 -91
- package/dist/esm/services/messageService.js.map +0 -1
- package/dist/esm/utils/api.d.ts.map +0 -1
- package/dist/esm/utils/api.js.map +0 -1
- package/dist/esm/utils/constant.d.ts +0 -2
- package/dist/esm/utils/constant.d.ts.map +0 -1
- package/dist/esm/utils/constant.js +0 -2
- package/dist/esm/utils/constant.js.map +0 -1
- package/dist/esm/utils/delay.d.ts +0 -2
- package/dist/esm/utils/delay.d.ts.map +0 -1
- package/dist/esm/utils/delay.js +0 -2
- package/dist/esm/utils/delay.js.map +0 -1
- package/dist/esm/utils/generateRandomName.d.ts +0 -2
- package/dist/esm/utils/generateRandomName.d.ts.map +0 -1
- package/dist/esm/utils/generateRandomName.js +0 -2
- package/dist/esm/utils/generateRandomName.js.map +0 -1
- package/dist/esm/utils/getVerificationCode.d.ts +0 -17
- package/dist/esm/utils/getVerificationCode.d.ts.map +0 -1
- package/dist/esm/utils/getVerificationCode.js +0 -24
- package/dist/esm/utils/getVerificationCode.js.map +0 -1
|
@@ -73,6 +73,7 @@ interface EmailResource {
|
|
|
73
73
|
updatedAt: string;
|
|
74
74
|
accountId: string;
|
|
75
75
|
}
|
|
76
|
+
export declare const authenticate: (email: string, password: string) => Promise<void>;
|
|
76
77
|
export declare const getAuthHeaders: () => {
|
|
77
78
|
accept: string;
|
|
78
79
|
Authorization: string;
|
|
@@ -86,17 +87,6 @@ export declare const createAccount: (payload: {
|
|
|
86
87
|
address: string;
|
|
87
88
|
password: string;
|
|
88
89
|
}) => Promise<EmailAccount>;
|
|
89
|
-
/**
|
|
90
|
-
* Deletes the account created during `generateEmail`.
|
|
91
|
-
*
|
|
92
|
-
* @returns {Promise<number>} status code of 204 when the account is successfully deleted.
|
|
93
|
-
*
|
|
94
|
-
* @throws {Error} If no account is authenticated or deletion fails.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* await deleteAccount();
|
|
98
|
-
* console.log("Account deleted successfully.");
|
|
99
|
-
*/
|
|
100
90
|
export declare const deleteAccount: (accountId: string) => Promise<number>;
|
|
101
91
|
export {};
|
|
102
92
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAEA,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;AACD,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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E,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,eAAO,MAAM,YAAY,UAChB,MAAM,YACH,MAAM,KACf,OAAO,CAAC,IAAI,CAYd,CAAC;AACF,eAAO,MAAM,cAAc;;;CAQ1B,CAAC;AAEF,eAAO,MAAM,UAAU,QAAa,OAAO,CAAC,aAAa,EAAE,CAU1D,CAAC;AAEF,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,WAAW,EAAE,CAUzD,CAAC;AAEF,eAAO,MAAM,kBAAkB,cAClB,MAAM,KAChB,OAAO,CAAC,aAAa,CAUvB,CAAC;AAEF,eAAO,MAAM,qBAAqB,cACrB,MAAM,iBACF,MAAM,KACpB,OAAO,CAAC,GAAG,CAgBb,CAAC;AAEF,eAAO,MAAM,aAAa,cAAqB,MAAM,KAAG,OAAO,CAAC,MAAM,CAUrE,CAAC;AAEF,eAAO,MAAM,aAAa,YAAmB;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,KAAG,OAAO,CAAC,YAAY,CAKvB,CAAC;AAEF,eAAO,MAAM,aAAa,cAAqB,MAAM,KAAG,OAAO,CAAC,MAAM,CAUrE,CAAC"}
|
|
@@ -3,12 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.deleteAccount = exports.createAccount = exports.deleteMessage = exports.getMessageAttachments = exports.getMessagesContent = exports.getMessages = exports.getDomains = exports.getAuthHeaders = void 0;
|
|
6
|
+
exports.deleteAccount = exports.createAccount = exports.deleteMessage = exports.getMessageAttachments = exports.getMessagesContent = exports.getMessages = exports.getDomains = exports.getAuthHeaders = exports.authenticate = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
|
|
9
|
-
const
|
|
8
|
+
let token = null;
|
|
9
|
+
const apiClient = axios_1.default.create({
|
|
10
|
+
baseURL: process.env.BASE_URL || 'https://api.mail.tm',
|
|
11
|
+
headers: { accept: 'application/json' },
|
|
12
|
+
});
|
|
13
|
+
const authenticate = async (email, password) => {
|
|
14
|
+
const response = await apiClient.post('/token', { address: email, password }, {
|
|
15
|
+
headers: {
|
|
16
|
+
accept: 'application/json',
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
token = response.data.token;
|
|
21
|
+
};
|
|
22
|
+
exports.authenticate = authenticate;
|
|
10
23
|
const getAuthHeaders = () => {
|
|
11
|
-
const token = (0, authService_1.getToken)();
|
|
12
24
|
if (!token) {
|
|
13
25
|
throw new Error('Authentication required. Token not found.');
|
|
14
26
|
}
|
|
@@ -20,7 +32,7 @@ const getAuthHeaders = () => {
|
|
|
20
32
|
exports.getAuthHeaders = getAuthHeaders;
|
|
21
33
|
const getDomains = async () => {
|
|
22
34
|
try {
|
|
23
|
-
const { data } = await
|
|
35
|
+
const { data } = await apiClient.get('/domains', {
|
|
24
36
|
headers: { accept: 'application/json' },
|
|
25
37
|
});
|
|
26
38
|
return data;
|
|
@@ -33,7 +45,7 @@ const getDomains = async () => {
|
|
|
33
45
|
exports.getDomains = getDomains;
|
|
34
46
|
const getMessages = async () => {
|
|
35
47
|
try {
|
|
36
|
-
const { data } = await
|
|
48
|
+
const { data } = await apiClient.get('/messages', {
|
|
37
49
|
headers: (0, exports.getAuthHeaders)(),
|
|
38
50
|
});
|
|
39
51
|
return data;
|
|
@@ -46,7 +58,7 @@ const getMessages = async () => {
|
|
|
46
58
|
exports.getMessages = getMessages;
|
|
47
59
|
const getMessagesContent = async (messageId) => {
|
|
48
60
|
try {
|
|
49
|
-
const { data } = await
|
|
61
|
+
const { data } = await apiClient.get(`/messages/${messageId}`, {
|
|
50
62
|
headers: (0, exports.getAuthHeaders)(),
|
|
51
63
|
});
|
|
52
64
|
return data;
|
|
@@ -59,7 +71,7 @@ const getMessagesContent = async (messageId) => {
|
|
|
59
71
|
exports.getMessagesContent = getMessagesContent;
|
|
60
72
|
const getMessageAttachments = async (messageId, attachmentsId) => {
|
|
61
73
|
try {
|
|
62
|
-
const { data } = await
|
|
74
|
+
const { data } = await apiClient.get(`/messages/${messageId}/attachment/${attachmentsId}`, {
|
|
63
75
|
headers: (0, exports.getAuthHeaders)(),
|
|
64
76
|
});
|
|
65
77
|
return data;
|
|
@@ -72,7 +84,7 @@ const getMessageAttachments = async (messageId, attachmentsId) => {
|
|
|
72
84
|
exports.getMessageAttachments = getMessageAttachments;
|
|
73
85
|
const deleteMessage = async (messageId) => {
|
|
74
86
|
try {
|
|
75
|
-
const { status } = await
|
|
87
|
+
const { status } = await apiClient.delete(`/messages/${messageId}`, {
|
|
76
88
|
headers: (0, exports.getAuthHeaders)(),
|
|
77
89
|
});
|
|
78
90
|
return status;
|
|
@@ -84,26 +96,15 @@ const deleteMessage = async (messageId) => {
|
|
|
84
96
|
};
|
|
85
97
|
exports.deleteMessage = deleteMessage;
|
|
86
98
|
const createAccount = async (payload) => {
|
|
87
|
-
const { data } = await
|
|
99
|
+
const { data } = await apiClient.post(`/accounts`, payload, {
|
|
88
100
|
headers: { accept: 'application/json' },
|
|
89
101
|
});
|
|
90
102
|
return data;
|
|
91
103
|
};
|
|
92
104
|
exports.createAccount = createAccount;
|
|
93
|
-
/**
|
|
94
|
-
* Deletes the account created during `generateEmail`.
|
|
95
|
-
*
|
|
96
|
-
* @returns {Promise<number>} status code of 204 when the account is successfully deleted.
|
|
97
|
-
*
|
|
98
|
-
* @throws {Error} If no account is authenticated or deletion fails.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* await deleteAccount();
|
|
102
|
-
* console.log("Account deleted successfully.");
|
|
103
|
-
*/
|
|
104
105
|
const deleteAccount = async (accountId) => {
|
|
105
106
|
try {
|
|
106
|
-
const { status } = await
|
|
107
|
+
const { status } = await apiClient.delete(`/accounts/${accountId}`, {
|
|
107
108
|
headers: (0, exports.getAuthHeaders)(),
|
|
108
109
|
});
|
|
109
110
|
return status;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AA8E1B,IAAI,KAAK,GAAkB,IAAI,CAAC;AAChC,MAAM,SAAS,GAAG,eAAK,CAAC,MAAM,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,qBAAqB;IACtD,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;CACxC,CAAC,CAAC;AACI,MAAM,YAAY,GAAG,KAAK,EAC/B,KAAa,EACb,QAAgB,EACD,EAAE;IACjB,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CACnC,QAAQ,EACR,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;AAfW,QAAA,YAAY,gBAevB;AACK,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO;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IAC1B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE;QAC1D,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;KACxC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB;AAEK,MAAM,aAAa,GAAG,KAAK,EAAE,SAAiB,EAAmB,EAAE;IACxE,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,aAAa,SAAS,EAAE,EAAE;YAClE,OAAO,EAAE,IAAA,sBAAc,GAAE;SAC1B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QACpE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,aAAa,iBAUxB"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export interface GeneratedEmail {
|
|
2
|
+
emailAddress: string;
|
|
3
|
+
accountId: string;
|
|
4
|
+
}
|
|
5
|
+
export interface MessageContent {
|
|
6
|
+
from: {
|
|
7
|
+
address: string;
|
|
8
|
+
};
|
|
9
|
+
to: {
|
|
10
|
+
address: string;
|
|
11
|
+
}[];
|
|
12
|
+
subject: string;
|
|
13
|
+
intro: string;
|
|
14
|
+
text: string;
|
|
15
|
+
html: string[];
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface GetEmailOptions {
|
|
20
|
+
maxWaitTime?: number;
|
|
21
|
+
waitInterval?: number;
|
|
22
|
+
logPolling?: boolean;
|
|
23
|
+
deleteAfterRead?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new email inbox with a unique address.
|
|
27
|
+
*
|
|
28
|
+
* This function generates an temp inbox & email address
|
|
29
|
+
*
|
|
30
|
+
* @param {string} [emailPrefix] - Optional emailPrefix; a random one is generated if not provided.
|
|
31
|
+
* @returns {Promise<GeneratedEmail>} The generated email address & account ID.
|
|
32
|
+
*
|
|
33
|
+
* @throws {Error} If no domains are available or account creation fails.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const email = await generateEmail("customUser");
|
|
37
|
+
* console.log(email); // Outputs: {"emailAddress": "customUser@mail.tm" , "accountId": "1234"}
|
|
38
|
+
*/
|
|
39
|
+
export declare const generateEmail: (emailPrefix?: string) => Promise<GeneratedEmail>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves the latest message from the inbox.
|
|
42
|
+
*
|
|
43
|
+
* If messages are available, this function fetches the first one and
|
|
44
|
+
* returns its details. Polling options can be specified to wait for
|
|
45
|
+
* messages if the inbox is empty. Optionally, the message can be
|
|
46
|
+
* deleted after reading.
|
|
47
|
+
*
|
|
48
|
+
* @param {GetEmailOptions} [options] - Optional settings for polling and deletion.
|
|
49
|
+
* @param {number} [options.maxWaitTime=30000] - Maximum time to wait for messages (in milliseconds). Default is 30 seconds.
|
|
50
|
+
* @param {number} [options.waitInterval=2000] - Time interval between polling attempts (in milliseconds). Default is 2 seconds.
|
|
51
|
+
* @param {boolean} [options.logPolling=false] - Whether to log polling attempts. Default is `false`.
|
|
52
|
+
* @param {boolean} [options.deleteAfterRead=false] - Whether to delete the message after reading. Default is `false`.
|
|
53
|
+
* @returns {Promise<MessageContent | null>} The email content (sender, recipient, subject, text, HTML), or `null` if no messages are found.
|
|
54
|
+
*
|
|
55
|
+
* @throws {Error} If no messages are available within the polling timeout or authentication fails.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const message = await getRecentEmail({ maxWaitTime: 5000, waitInterval: 1000, logPolling: true });
|
|
59
|
+
* console.log(message.subject); // Outputs: "Hello!"
|
|
60
|
+
*/
|
|
61
|
+
export declare const getRecentEmail: (options?: GetEmailOptions) => Promise<MessageContent | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Extracts a verification code from the provided email content.
|
|
64
|
+
*
|
|
65
|
+
* This function scans the given text for a sequence of 5 or more
|
|
66
|
+
* consecutive digits and returns the first valid verification code.
|
|
67
|
+
* If no valid sequence is found, the function returns `null`.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} text - The content of the email, typically the body.
|
|
70
|
+
* @returns {Promise<string | null>} The first verification code found, or `null` if no valid code exists.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const emailContent = "Your code is 123456.";
|
|
74
|
+
* const verificationCode = await getVerificationCode(emailContent);
|
|
75
|
+
* console.log(verificationCode); // Output: "123456"
|
|
76
|
+
*/
|
|
77
|
+
export declare const getVerificationCode: (text: string | undefined) => Promise<string>;
|
|
5
78
|
//# 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":"AAeA,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;CACnB;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;AAOD;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,aAAa,iBACV,MAAM,KACnB,OAAO,CAAC,cAAc,CAmCxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,aACf,eAAe,KACxB,OAAO,CAAC,cAAc,GAAG,IAAI,CA4D/B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,mBAAmB,SACxB,MAAM,GAAG,SAAS,KACvB,OAAO,CAAC,MAAM,CAOhB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -33,16 +33,144 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.getVerificationCode = exports.
|
|
36
|
+
exports.getVerificationCode = exports.getRecentEmail = exports.generateEmail = void 0;
|
|
37
37
|
const dotenv = __importStar(require("dotenv"));
|
|
38
38
|
dotenv.config();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
const api_1 = require("./api");
|
|
40
|
+
const api_2 = require("./api");
|
|
41
|
+
let accountId;
|
|
42
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
43
|
+
const generateRandomName = () => Math.random().toString(36).substring(2, 15);
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new email inbox with a unique address.
|
|
46
|
+
*
|
|
47
|
+
* This function generates an temp inbox & email address
|
|
48
|
+
*
|
|
49
|
+
* @param {string} [emailPrefix] - Optional emailPrefix; a random one is generated if not provided.
|
|
50
|
+
* @returns {Promise<GeneratedEmail>} The generated email address & account ID.
|
|
51
|
+
*
|
|
52
|
+
* @throws {Error} If no domains are available or account creation fails.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const email = await generateEmail("customUser");
|
|
56
|
+
* console.log(email); // Outputs: {"emailAddress": "customUser@mail.tm" , "accountId": "1234"}
|
|
57
|
+
*/
|
|
58
|
+
const generateEmail = async (emailPrefix) => {
|
|
59
|
+
const domainsResponse = await (0, api_2.getDomains)();
|
|
60
|
+
const domains = domainsResponse
|
|
61
|
+
.filter((domain) => domain.isActive)
|
|
62
|
+
.map((domain) => domain.domain);
|
|
63
|
+
if (domains.length === 0)
|
|
64
|
+
throw new Error('No available domains.');
|
|
65
|
+
const emailAddress = `${emailPrefix || generateRandomName()}@${domains[0]}`;
|
|
66
|
+
const password = generateRandomName();
|
|
67
|
+
let attempts = 0;
|
|
68
|
+
const maxRetries = 5;
|
|
69
|
+
while (attempts < maxRetries) {
|
|
70
|
+
try {
|
|
71
|
+
const accountResponse = await (0, api_2.createAccount)({
|
|
72
|
+
address: emailAddress,
|
|
73
|
+
password,
|
|
74
|
+
});
|
|
75
|
+
accountId = accountResponse.id;
|
|
76
|
+
await (0, api_1.authenticate)(emailAddress, password);
|
|
77
|
+
return { emailAddress, accountId: accountResponse.id };
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error.response?.status === 429) {
|
|
81
|
+
attempts++;
|
|
82
|
+
const retryAfter = error.response.headers['retry-after']
|
|
83
|
+
? parseInt(error.response.headers['retry-after'])
|
|
84
|
+
: 5;
|
|
85
|
+
await delay(retryAfter * 1000);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
throw new Error('Failed to create account after multiple retries.');
|
|
93
|
+
};
|
|
94
|
+
exports.generateEmail = generateEmail;
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves the latest message from the inbox.
|
|
97
|
+
*
|
|
98
|
+
* If messages are available, this function fetches the first one and
|
|
99
|
+
* returns its details. Polling options can be specified to wait for
|
|
100
|
+
* messages if the inbox is empty. Optionally, the message can be
|
|
101
|
+
* deleted after reading.
|
|
102
|
+
*
|
|
103
|
+
* @param {GetEmailOptions} [options] - Optional settings for polling and deletion.
|
|
104
|
+
* @param {number} [options.maxWaitTime=30000] - Maximum time to wait for messages (in milliseconds). Default is 30 seconds.
|
|
105
|
+
* @param {number} [options.waitInterval=2000] - Time interval between polling attempts (in milliseconds). Default is 2 seconds.
|
|
106
|
+
* @param {boolean} [options.logPolling=false] - Whether to log polling attempts. Default is `false`.
|
|
107
|
+
* @param {boolean} [options.deleteAfterRead=false] - Whether to delete the message after reading. Default is `false`.
|
|
108
|
+
* @returns {Promise<MessageContent | null>} The email content (sender, recipient, subject, text, HTML), or `null` if no messages are found.
|
|
109
|
+
*
|
|
110
|
+
* @throws {Error} If no messages are available within the polling timeout or authentication fails.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* const message = await getRecentEmail({ maxWaitTime: 5000, waitInterval: 1000, logPolling: true });
|
|
114
|
+
* console.log(message.subject); // Outputs: "Hello!"
|
|
115
|
+
*/
|
|
116
|
+
const getRecentEmail = async (options) => {
|
|
117
|
+
const { maxWaitTime = 30000, waitInterval = 2000, logPolling = false, deleteAfterRead = false, } = options || {};
|
|
118
|
+
const startTime = Date.now();
|
|
119
|
+
const logger = (message) => logPolling && console.log(message);
|
|
120
|
+
logger(`Polling started with a timeout of ${maxWaitTime / 1000}sec and interval of ${waitInterval / 1000}sec.`);
|
|
121
|
+
while (Date.now() - startTime < maxWaitTime) {
|
|
122
|
+
const messages = await (0, api_2.getMessages)();
|
|
123
|
+
if (messages.length > 0) {
|
|
124
|
+
logger(`Found ${messages.length} message(s), fetching details...`);
|
|
125
|
+
const sortedMessages = messages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
126
|
+
const messageId = sortedMessages[0].id;
|
|
127
|
+
logger(`Found ${messageId}`);
|
|
128
|
+
const { from, to, subject, intro, text, html, createdAt, updatedAt } = await (0, api_2.getMessagesContent)(messageId);
|
|
129
|
+
if (deleteAfterRead) {
|
|
130
|
+
await (0, api_2.deleteMessage)(messageId);
|
|
131
|
+
}
|
|
132
|
+
await (0, api_2.deleteAccount)(accountId);
|
|
133
|
+
return {
|
|
134
|
+
from: from,
|
|
135
|
+
to: to,
|
|
136
|
+
subject,
|
|
137
|
+
intro,
|
|
138
|
+
text,
|
|
139
|
+
html,
|
|
140
|
+
createdAt,
|
|
141
|
+
updatedAt,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, waitInterval));
|
|
145
|
+
logger(`No messages found, waiting for ${waitInterval / 1000} seconds...`);
|
|
146
|
+
}
|
|
147
|
+
logger(`Waiting timeout of ${maxWaitTime / 1000} seconds reached. No messages found.`);
|
|
148
|
+
await (0, api_2.deleteAccount)(accountId);
|
|
149
|
+
throw new Error(`No messages available within ${maxWaitTime / 1000} seconds timeout`);
|
|
150
|
+
};
|
|
151
|
+
exports.getRecentEmail = getRecentEmail;
|
|
152
|
+
/**
|
|
153
|
+
* Extracts a verification code from the provided email content.
|
|
154
|
+
*
|
|
155
|
+
* This function scans the given text for a sequence of 5 or more
|
|
156
|
+
* consecutive digits and returns the first valid verification code.
|
|
157
|
+
* If no valid sequence is found, the function returns `null`.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} text - The content of the email, typically the body.
|
|
160
|
+
* @returns {Promise<string | null>} The first verification code found, or `null` if no valid code exists.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* const emailContent = "Your code is 123456.";
|
|
164
|
+
* const verificationCode = await getVerificationCode(emailContent);
|
|
165
|
+
* console.log(verificationCode); // Output: "123456"
|
|
166
|
+
*/
|
|
167
|
+
const getVerificationCode = async (text) => {
|
|
168
|
+
console.log('Extracting the verification code from the email content...');
|
|
169
|
+
const matches = text.match(/\b\d{5,}\b/);
|
|
170
|
+
if (matches) {
|
|
171
|
+
return matches[0];
|
|
172
|
+
}
|
|
173
|
+
throw new Error('No verification code found in the provided email content.');
|
|
174
|
+
};
|
|
175
|
+
exports.getVerificationCode = getVerificationCode;
|
|
48
176
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,+BAAqC;AACrC,+BAOe;AAEf,IAAI,SAAiB,CAAC;AAuBtB,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAC1C,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACpD,MAAM,kBAAkB,GAAG,GAAW,EAAE,CACtC,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AAEI,MAAM,aAAa,GAAG,KAAK,EAChC,WAAoB,EACK,EAAE;IAC3B,MAAM,eAAe,GAAG,MAAM,IAAA,gBAAU,GAAE,CAAC;IAC3C,MAAM,OAAO,GAAG,eAAe;SAC5B,MAAM,CAA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S9B"}
|
|
@@ -73,6 +73,7 @@ interface EmailResource {
|
|
|
73
73
|
updatedAt: string;
|
|
74
74
|
accountId: string;
|
|
75
75
|
}
|
|
76
|
+
export declare const authenticate: (email: string, password: string) => Promise<void>;
|
|
76
77
|
export declare const getAuthHeaders: () => {
|
|
77
78
|
accept: string;
|
|
78
79
|
Authorization: string;
|
|
@@ -86,17 +87,6 @@ export declare const createAccount: (payload: {
|
|
|
86
87
|
address: string;
|
|
87
88
|
password: string;
|
|
88
89
|
}) => Promise<EmailAccount>;
|
|
89
|
-
/**
|
|
90
|
-
* Deletes the account created during `generateEmail`.
|
|
91
|
-
*
|
|
92
|
-
* @returns {Promise<number>} status code of 204 when the account is successfully deleted.
|
|
93
|
-
*
|
|
94
|
-
* @throws {Error} If no account is authenticated or deletion fails.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* await deleteAccount();
|
|
98
|
-
* console.log("Account deleted successfully.");
|
|
99
|
-
*/
|
|
100
90
|
export declare const deleteAccount: (accountId: string) => Promise<number>;
|
|
101
91
|
export {};
|
|
102
92
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAEA,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;AACD,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,SA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.BASE_URL || 'https://api.mail.tm',
|
|
5
|
+
headers: { accept: 'application/json' },
|
|
6
|
+
});
|
|
7
|
+
export const authenticate = async (email, password) => {
|
|
8
|
+
const response = await apiClient.post('/token', { address: email, password }, {
|
|
9
|
+
headers: {
|
|
10
|
+
accept: 'application/json',
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
token = response.data.token;
|
|
15
|
+
};
|
|
4
16
|
export const getAuthHeaders = () => {
|
|
5
|
-
const token = getToken();
|
|
6
17
|
if (!token) {
|
|
7
18
|
throw new Error('Authentication required. Token not found.');
|
|
8
19
|
}
|
|
@@ -13,7 +24,7 @@ export const getAuthHeaders = () => {
|
|
|
13
24
|
};
|
|
14
25
|
export const getDomains = async () => {
|
|
15
26
|
try {
|
|
16
|
-
const { data } = await
|
|
27
|
+
const { data } = await apiClient.get('/domains', {
|
|
17
28
|
headers: { accept: 'application/json' },
|
|
18
29
|
});
|
|
19
30
|
return data;
|
|
@@ -25,7 +36,7 @@ export const getDomains = async () => {
|
|
|
25
36
|
};
|
|
26
37
|
export const getMessages = async () => {
|
|
27
38
|
try {
|
|
28
|
-
const { data } = await
|
|
39
|
+
const { data } = await apiClient.get('/messages', {
|
|
29
40
|
headers: getAuthHeaders(),
|
|
30
41
|
});
|
|
31
42
|
return data;
|
|
@@ -37,7 +48,7 @@ export const getMessages = async () => {
|
|
|
37
48
|
};
|
|
38
49
|
export const getMessagesContent = async (messageId) => {
|
|
39
50
|
try {
|
|
40
|
-
const { data } = await
|
|
51
|
+
const { data } = await apiClient.get(`/messages/${messageId}`, {
|
|
41
52
|
headers: getAuthHeaders(),
|
|
42
53
|
});
|
|
43
54
|
return data;
|
|
@@ -49,7 +60,7 @@ export const getMessagesContent = async (messageId) => {
|
|
|
49
60
|
};
|
|
50
61
|
export const getMessageAttachments = async (messageId, attachmentsId) => {
|
|
51
62
|
try {
|
|
52
|
-
const { data } = await
|
|
63
|
+
const { data } = await apiClient.get(`/messages/${messageId}/attachment/${attachmentsId}`, {
|
|
53
64
|
headers: getAuthHeaders(),
|
|
54
65
|
});
|
|
55
66
|
return data;
|
|
@@ -61,7 +72,7 @@ export const getMessageAttachments = async (messageId, attachmentsId) => {
|
|
|
61
72
|
};
|
|
62
73
|
export const deleteMessage = async (messageId) => {
|
|
63
74
|
try {
|
|
64
|
-
const { status } = await
|
|
75
|
+
const { status } = await apiClient.delete(`/messages/${messageId}`, {
|
|
65
76
|
headers: getAuthHeaders(),
|
|
66
77
|
});
|
|
67
78
|
return status;
|
|
@@ -72,25 +83,14 @@ export const deleteMessage = async (messageId) => {
|
|
|
72
83
|
}
|
|
73
84
|
};
|
|
74
85
|
export const createAccount = async (payload) => {
|
|
75
|
-
const { data } = await
|
|
86
|
+
const { data } = await apiClient.post(`/accounts`, payload, {
|
|
76
87
|
headers: { accept: 'application/json' },
|
|
77
88
|
});
|
|
78
89
|
return data;
|
|
79
90
|
};
|
|
80
|
-
/**
|
|
81
|
-
* Deletes the account created during `generateEmail`.
|
|
82
|
-
*
|
|
83
|
-
* @returns {Promise<number>} status code of 204 when the account is successfully deleted.
|
|
84
|
-
*
|
|
85
|
-
* @throws {Error} If no account is authenticated or deletion fails.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* await deleteAccount();
|
|
89
|
-
* console.log("Account deleted successfully.");
|
|
90
|
-
*/
|
|
91
91
|
export const deleteAccount = async (accountId) => {
|
|
92
92
|
try {
|
|
93
|
-
const { status } = await
|
|
93
|
+
const { status } = await apiClient.delete(`/accounts/${accountId}`, {
|
|
94
94
|
headers: getAuthHeaders(),
|
|
95
95
|
});
|
|
96
96
|
return status;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA8E1B,IAAI,KAAK,GAAkB,IAAI,CAAC;AAChC,MAAM,SAAS,GAAG,KA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 -1,5 +1,78 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export interface GeneratedEmail {
|
|
2
|
+
emailAddress: string;
|
|
3
|
+
accountId: string;
|
|
4
|
+
}
|
|
5
|
+
export interface MessageContent {
|
|
6
|
+
from: {
|
|
7
|
+
address: string;
|
|
8
|
+
};
|
|
9
|
+
to: {
|
|
10
|
+
address: string;
|
|
11
|
+
}[];
|
|
12
|
+
subject: string;
|
|
13
|
+
intro: string;
|
|
14
|
+
text: string;
|
|
15
|
+
html: string[];
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface GetEmailOptions {
|
|
20
|
+
maxWaitTime?: number;
|
|
21
|
+
waitInterval?: number;
|
|
22
|
+
logPolling?: boolean;
|
|
23
|
+
deleteAfterRead?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new email inbox with a unique address.
|
|
27
|
+
*
|
|
28
|
+
* This function generates an temp inbox & email address
|
|
29
|
+
*
|
|
30
|
+
* @param {string} [emailPrefix] - Optional emailPrefix; a random one is generated if not provided.
|
|
31
|
+
* @returns {Promise<GeneratedEmail>} The generated email address & account ID.
|
|
32
|
+
*
|
|
33
|
+
* @throws {Error} If no domains are available or account creation fails.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const email = await generateEmail("customUser");
|
|
37
|
+
* console.log(email); // Outputs: {"emailAddress": "customUser@mail.tm" , "accountId": "1234"}
|
|
38
|
+
*/
|
|
39
|
+
export declare const generateEmail: (emailPrefix?: string) => Promise<GeneratedEmail>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves the latest message from the inbox.
|
|
42
|
+
*
|
|
43
|
+
* If messages are available, this function fetches the first one and
|
|
44
|
+
* returns its details. Polling options can be specified to wait for
|
|
45
|
+
* messages if the inbox is empty. Optionally, the message can be
|
|
46
|
+
* deleted after reading.
|
|
47
|
+
*
|
|
48
|
+
* @param {GetEmailOptions} [options] - Optional settings for polling and deletion.
|
|
49
|
+
* @param {number} [options.maxWaitTime=30000] - Maximum time to wait for messages (in milliseconds). Default is 30 seconds.
|
|
50
|
+
* @param {number} [options.waitInterval=2000] - Time interval between polling attempts (in milliseconds). Default is 2 seconds.
|
|
51
|
+
* @param {boolean} [options.logPolling=false] - Whether to log polling attempts. Default is `false`.
|
|
52
|
+
* @param {boolean} [options.deleteAfterRead=false] - Whether to delete the message after reading. Default is `false`.
|
|
53
|
+
* @returns {Promise<MessageContent | null>} The email content (sender, recipient, subject, text, HTML), or `null` if no messages are found.
|
|
54
|
+
*
|
|
55
|
+
* @throws {Error} If no messages are available within the polling timeout or authentication fails.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const message = await getRecentEmail({ maxWaitTime: 5000, waitInterval: 1000, logPolling: true });
|
|
59
|
+
* console.log(message.subject); // Outputs: "Hello!"
|
|
60
|
+
*/
|
|
61
|
+
export declare const getRecentEmail: (options?: GetEmailOptions) => Promise<MessageContent | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Extracts a verification code from the provided email content.
|
|
64
|
+
*
|
|
65
|
+
* This function scans the given text for a sequence of 5 or more
|
|
66
|
+
* consecutive digits and returns the first valid verification code.
|
|
67
|
+
* If no valid sequence is found, the function returns `null`.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} text - The content of the email, typically the body.
|
|
70
|
+
* @returns {Promise<string | null>} The first verification code found, or `null` if no valid code exists.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const emailContent = "Your code is 123456.";
|
|
74
|
+
* const verificationCode = await getVerificationCode(emailContent);
|
|
75
|
+
* console.log(verificationCode); // Output: "123456"
|
|
76
|
+
*/
|
|
77
|
+
export declare const getVerificationCode: (text: string | undefined) => Promise<string>;
|
|
5
78
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/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":"AAeA,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;CACnB;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;AAOD;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,aAAa,iBACV,MAAM,KACnB,OAAO,CAAC,cAAc,CAmCxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,aACf,eAAe,KACxB,OAAO,CAAC,cAAc,GAAG,IAAI,CA4D/B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,mBAAmB,SACxB,MAAM,GAAG,SAAS,KACvB,OAAO,CAAC,MAAM,CAOhB,CAAC"}
|