@tempyemail/e2e-testing 1.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/LICENSE +21 -0
- package/README.md +695 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +50 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/mailbox.d.ts +46 -0
- package/dist/mailbox.d.ts.map +1 -0
- package/dist/mailbox.js +146 -0
- package/dist/mailbox.js.map +1 -0
- package/dist/parsers/links.d.ts +20 -0
- package/dist/parsers/links.d.ts.map +1 -0
- package/dist/parsers/links.js +77 -0
- package/dist/parsers/links.js.map +1 -0
- package/dist/parsers/otp.d.ts +28 -0
- package/dist/parsers/otp.d.ts.map +1 -0
- package/dist/parsers/otp.js +71 -0
- package/dist/parsers/otp.js.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/polling.d.ts +11 -0
- package/dist/utils/polling.d.ts.map +1 -0
- package/dist/utils/polling.js +36 -0
- package/dist/utils/polling.js.map +1 -0
- package/package.json +52 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TempyEmailConfig, CreateMailboxOptions } from './types';
|
|
2
|
+
import { Mailbox } from './mailbox';
|
|
3
|
+
/**
|
|
4
|
+
* Main client for interacting with the tempy.email API
|
|
5
|
+
*/
|
|
6
|
+
export declare class TempyEmail {
|
|
7
|
+
private readonly baseUrl;
|
|
8
|
+
private readonly timeout;
|
|
9
|
+
constructor(config?: TempyEmailConfig);
|
|
10
|
+
/**
|
|
11
|
+
* Create a new temporary mailbox
|
|
12
|
+
*/
|
|
13
|
+
createMailbox(options?: CreateMailboxOptions): Promise<Mailbox>;
|
|
14
|
+
/**
|
|
15
|
+
* Get an existing mailbox by email address
|
|
16
|
+
*/
|
|
17
|
+
getMailbox(address: string): Promise<Mailbox>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAwC,MAAM,SAAS,CAAC;AACvG,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,GAAE,gBAAqB;IAKzC;;OAEG;IACG,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC;IAiCzE;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAsBpD"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TempyEmail = void 0;
|
|
4
|
+
const mailbox_1 = require("./mailbox");
|
|
5
|
+
/**
|
|
6
|
+
* Main client for interacting with the tempy.email API
|
|
7
|
+
*/
|
|
8
|
+
class TempyEmail {
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
this.baseUrl = config.baseUrl || 'https://tempy.email/api/v1';
|
|
11
|
+
this.timeout = config.timeout || 30000;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a new temporary mailbox
|
|
15
|
+
*/
|
|
16
|
+
async createMailbox(options = {}) {
|
|
17
|
+
const { webhookUrl, webhookFormat } = options;
|
|
18
|
+
const params = new URLSearchParams();
|
|
19
|
+
if (webhookUrl) {
|
|
20
|
+
params.append('webhookUrl', webhookUrl);
|
|
21
|
+
params.append('webhookFormat', webhookFormat || 'json');
|
|
22
|
+
}
|
|
23
|
+
const url = `${this.baseUrl}/mailbox${params.toString() ? `?${params.toString()}` : ''}`;
|
|
24
|
+
const response = await fetch(url, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: { Accept: 'application/json' },
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error(`Failed to create mailbox: ${response.status} ${response.statusText}`);
|
|
30
|
+
}
|
|
31
|
+
const data = await response.json();
|
|
32
|
+
return new mailbox_1.Mailbox(data.email, data.expiresAt, data.webhookUrl, this.baseUrl, this.timeout);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get an existing mailbox by email address
|
|
36
|
+
*/
|
|
37
|
+
async getMailbox(address) {
|
|
38
|
+
const response = await fetch(`${this.baseUrl}/mailbox/${address}`, {
|
|
39
|
+
method: 'GET',
|
|
40
|
+
headers: { Accept: 'application/json' },
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`Failed to get mailbox: ${response.status} ${response.statusText}`);
|
|
44
|
+
}
|
|
45
|
+
const data = await response.json();
|
|
46
|
+
return new mailbox_1.Mailbox(data.email, data.expiresAt, data.webhookUrl, this.baseUrl, this.timeout);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.TempyEmail = TempyEmail;
|
|
50
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AACA,uCAAoC;AAEpC;;GAEG;AACH,MAAa,UAAU;IAIrB,YAAY,SAA2B,EAAE;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,4BAA4B,CAAC;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC;IACzC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EAAE,MAAM,EAAE,kBAAkB,EAAE;SACxC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,0BAA0B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CACnE,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAmB,CAAC;QAEpD,OAAO,IAAI,iBAAO,CAChB,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,OAAO,CACb,CAAC;IACJ,CAAC;CACF;AAtED,gCAsEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tempyemail/e2e-testing - JavaScript client for tempy.email
|
|
3
|
+
* Temporary email addresses for automated testing
|
|
4
|
+
*/
|
|
5
|
+
export { TempyEmail } from './client';
|
|
6
|
+
export { Mailbox } from './mailbox';
|
|
7
|
+
export type { Email, MailboxStatus, CreateMailboxResponse, CreateMailboxOptions, WaitForEmailOptions, WaitForOTPOptions, WaitForLinkOptions, TempyEmailConfig, PollOptions, } from './types';
|
|
8
|
+
export { extract6DigitOTP, extractNumericOTP, extractAlphanumericOTP, extractUUID, extractByPattern, extractOTP, } from './parsers/otp';
|
|
9
|
+
export { extractLinks, extractVerificationLink, extractLinksByDomain, extractFirstLink, } from './parsers/links';
|
|
10
|
+
export { pollUntil, wait } from './utils/polling';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,YAAY,EACV,KAAK,EACL,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,GACZ,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,gBAAgB,EAChB,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @tempyemail/e2e-testing - JavaScript client for tempy.email
|
|
4
|
+
* Temporary email addresses for automated testing
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.wait = exports.pollUntil = exports.extractFirstLink = exports.extractLinksByDomain = exports.extractVerificationLink = exports.extractLinks = exports.extractOTP = exports.extractByPattern = exports.extractUUID = exports.extractAlphanumericOTP = exports.extractNumericOTP = exports.extract6DigitOTP = exports.Mailbox = exports.TempyEmail = void 0;
|
|
8
|
+
var client_1 = require("./client");
|
|
9
|
+
Object.defineProperty(exports, "TempyEmail", { enumerable: true, get: function () { return client_1.TempyEmail; } });
|
|
10
|
+
var mailbox_1 = require("./mailbox");
|
|
11
|
+
Object.defineProperty(exports, "Mailbox", { enumerable: true, get: function () { return mailbox_1.Mailbox; } });
|
|
12
|
+
// Export parsers for advanced use cases
|
|
13
|
+
var otp_1 = require("./parsers/otp");
|
|
14
|
+
Object.defineProperty(exports, "extract6DigitOTP", { enumerable: true, get: function () { return otp_1.extract6DigitOTP; } });
|
|
15
|
+
Object.defineProperty(exports, "extractNumericOTP", { enumerable: true, get: function () { return otp_1.extractNumericOTP; } });
|
|
16
|
+
Object.defineProperty(exports, "extractAlphanumericOTP", { enumerable: true, get: function () { return otp_1.extractAlphanumericOTP; } });
|
|
17
|
+
Object.defineProperty(exports, "extractUUID", { enumerable: true, get: function () { return otp_1.extractUUID; } });
|
|
18
|
+
Object.defineProperty(exports, "extractByPattern", { enumerable: true, get: function () { return otp_1.extractByPattern; } });
|
|
19
|
+
Object.defineProperty(exports, "extractOTP", { enumerable: true, get: function () { return otp_1.extractOTP; } });
|
|
20
|
+
var links_1 = require("./parsers/links");
|
|
21
|
+
Object.defineProperty(exports, "extractLinks", { enumerable: true, get: function () { return links_1.extractLinks; } });
|
|
22
|
+
Object.defineProperty(exports, "extractVerificationLink", { enumerable: true, get: function () { return links_1.extractVerificationLink; } });
|
|
23
|
+
Object.defineProperty(exports, "extractLinksByDomain", { enumerable: true, get: function () { return links_1.extractLinksByDomain; } });
|
|
24
|
+
Object.defineProperty(exports, "extractFirstLink", { enumerable: true, get: function () { return links_1.extractFirstLink; } });
|
|
25
|
+
// Export utilities
|
|
26
|
+
var polling_1 = require("./utils/polling");
|
|
27
|
+
Object.defineProperty(exports, "pollUntil", { enumerable: true, get: function () { return polling_1.pollUntil; } });
|
|
28
|
+
Object.defineProperty(exports, "wait", { enumerable: true, get: function () { return polling_1.wait; } });
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mCAAsC;AAA7B,oGAAA,UAAU,OAAA;AACnB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAehB,wCAAwC;AACxC,qCAOuB;AANrB,uGAAA,gBAAgB,OAAA;AAChB,wGAAA,iBAAiB,OAAA;AACjB,6GAAA,sBAAsB,OAAA;AACtB,kGAAA,WAAW,OAAA;AACX,uGAAA,gBAAgB,OAAA;AAChB,iGAAA,UAAU,OAAA;AAGZ,yCAKyB;AAJvB,qGAAA,YAAY,OAAA;AACZ,gHAAA,uBAAuB,OAAA;AACvB,6GAAA,oBAAoB,OAAA;AACpB,yGAAA,gBAAgB,OAAA;AAGlB,mBAAmB;AACnB,2CAAkD;AAAzC,oGAAA,SAAS,OAAA;AAAE,+FAAA,IAAI,OAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Email, MailboxStatus, WaitForEmailOptions, WaitForOTPOptions, WaitForLinkOptions } from './types';
|
|
2
|
+
export declare class Mailbox {
|
|
3
|
+
readonly address: string;
|
|
4
|
+
readonly expiresAt: Date;
|
|
5
|
+
readonly webhookUrl?: string;
|
|
6
|
+
private readonly baseUrl;
|
|
7
|
+
private readonly timeout;
|
|
8
|
+
constructor(address: string, expiresAt: string, webhookUrl: string | undefined, baseUrl: string, timeout: number);
|
|
9
|
+
/**
|
|
10
|
+
* Get all messages in the mailbox
|
|
11
|
+
*/
|
|
12
|
+
getMessages(): Promise<Email[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Wait for a new email matching the specified criteria
|
|
15
|
+
*/
|
|
16
|
+
waitForEmail(options?: WaitForEmailOptions): Promise<Email>;
|
|
17
|
+
/**
|
|
18
|
+
* Wait for an email and extract an OTP code from it
|
|
19
|
+
*/
|
|
20
|
+
waitForOTP(options?: WaitForOTPOptions): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Wait for an email and extract a verification link from it
|
|
23
|
+
*/
|
|
24
|
+
waitForLink(options?: WaitForLinkOptions): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Mark emails as read
|
|
27
|
+
*/
|
|
28
|
+
markAsRead(emailIds: string[]): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Delete the mailbox
|
|
31
|
+
*/
|
|
32
|
+
delete(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Get mailbox status
|
|
35
|
+
*/
|
|
36
|
+
getStatus(): Promise<MailboxStatus>;
|
|
37
|
+
/**
|
|
38
|
+
* Check if the mailbox has expired
|
|
39
|
+
*/
|
|
40
|
+
isExpired(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Get seconds remaining until expiration
|
|
43
|
+
*/
|
|
44
|
+
secondsRemaining(): number;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=mailbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailbox.d.ts","sourceRoot":"","sources":["../src/mailbox.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAKjB,qBAAa,OAAO;IAClB,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,SAAS,EAAE,IAAI,CAAC;IAChC,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAG/B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM;IASjB;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAgBrC;;OAEG;IACG,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,KAAK,CAAC;IA0CrE;;OAEG;IACG,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAmBlE;;OAEG;IACG,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBpE;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBnD;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAa7B;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC;IAezC;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,gBAAgB,IAAI,MAAM;CAM3B"}
|
package/dist/mailbox.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mailbox = void 0;
|
|
4
|
+
const polling_1 = require("./utils/polling");
|
|
5
|
+
const otp_1 = require("./parsers/otp");
|
|
6
|
+
const links_1 = require("./parsers/links");
|
|
7
|
+
class Mailbox {
|
|
8
|
+
constructor(address, expiresAt, webhookUrl, baseUrl, timeout) {
|
|
9
|
+
this.address = address;
|
|
10
|
+
this.expiresAt = new Date(expiresAt);
|
|
11
|
+
this.webhookUrl = webhookUrl;
|
|
12
|
+
this.baseUrl = baseUrl;
|
|
13
|
+
this.timeout = timeout;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get all messages in the mailbox
|
|
17
|
+
*/
|
|
18
|
+
async getMessages() {
|
|
19
|
+
const response = await fetch(`${this.baseUrl}/mailbox/${this.address}`, {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
headers: { Accept: 'application/json' },
|
|
22
|
+
});
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw new Error(`Failed to get messages: ${response.status} ${response.statusText}`);
|
|
25
|
+
}
|
|
26
|
+
const data = await response.json();
|
|
27
|
+
return data.emails || [];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Wait for a new email matching the specified criteria
|
|
31
|
+
*/
|
|
32
|
+
async waitForEmail(options = {}) {
|
|
33
|
+
const { timeout = this.timeout, subject, from, pollInterval = 1000, } = options;
|
|
34
|
+
const email = await (0, polling_1.pollUntil)(async () => {
|
|
35
|
+
const messages = await this.getMessages();
|
|
36
|
+
for (const message of messages) {
|
|
37
|
+
// Check subject filter
|
|
38
|
+
if (subject) {
|
|
39
|
+
const subjectMatches = typeof subject === 'string'
|
|
40
|
+
? message.subject.includes(subject)
|
|
41
|
+
: subject.test(message.subject);
|
|
42
|
+
if (!subjectMatches)
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// Check from filter
|
|
46
|
+
if (from) {
|
|
47
|
+
const fromMatches = typeof from === 'string'
|
|
48
|
+
? message.from.includes(from)
|
|
49
|
+
: from.test(message.from);
|
|
50
|
+
if (!fromMatches)
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
return message;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}, { timeout, interval: pollInterval, backoff: true });
|
|
57
|
+
return email;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Wait for an email and extract an OTP code from it
|
|
61
|
+
*/
|
|
62
|
+
async waitForOTP(options = {}) {
|
|
63
|
+
const { timeout = this.timeout, pattern, from } = options;
|
|
64
|
+
const email = await this.waitForEmail({ timeout, from });
|
|
65
|
+
// Extract OTP from email body
|
|
66
|
+
const otp = pattern
|
|
67
|
+
? (0, otp_1.extractByPattern)(email.bodyText, pattern)
|
|
68
|
+
: (0, otp_1.extractOTP)(email.bodyText);
|
|
69
|
+
if (!otp) {
|
|
70
|
+
throw new Error(`No OTP code found in email. Subject: "${email.subject}"`);
|
|
71
|
+
}
|
|
72
|
+
return otp;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Wait for an email and extract a verification link from it
|
|
76
|
+
*/
|
|
77
|
+
async waitForLink(options = {}) {
|
|
78
|
+
const { timeout = this.timeout, pattern, from } = options;
|
|
79
|
+
const email = await this.waitForEmail({ timeout, from });
|
|
80
|
+
// Extract link from email body (prefer HTML, fallback to text)
|
|
81
|
+
const body = email.bodyHtml || email.bodyText;
|
|
82
|
+
const link = (0, links_1.extractVerificationLink)(body, pattern);
|
|
83
|
+
if (!link) {
|
|
84
|
+
throw new Error(`No verification link found in email. Subject: "${email.subject}"`);
|
|
85
|
+
}
|
|
86
|
+
return link;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Mark emails as read
|
|
90
|
+
*/
|
|
91
|
+
async markAsRead(emailIds) {
|
|
92
|
+
for (const id of emailIds) {
|
|
93
|
+
const response = await fetch(`${this.baseUrl}/mailbox/${this.address}/${id}`, {
|
|
94
|
+
method: 'PATCH',
|
|
95
|
+
headers: {
|
|
96
|
+
'Content-Type': 'application/json',
|
|
97
|
+
Accept: 'application/json',
|
|
98
|
+
},
|
|
99
|
+
body: JSON.stringify({ isRead: true }),
|
|
100
|
+
});
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
throw new Error(`Failed to mark email as read: ${response.status} ${response.statusText}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Delete the mailbox
|
|
108
|
+
*/
|
|
109
|
+
async delete() {
|
|
110
|
+
const response = await fetch(`${this.baseUrl}/mailbox/${this.address}`, {
|
|
111
|
+
method: 'DELETE',
|
|
112
|
+
headers: { Accept: 'application/json' },
|
|
113
|
+
});
|
|
114
|
+
if (!response.ok) {
|
|
115
|
+
throw new Error(`Failed to delete mailbox: ${response.status} ${response.statusText}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get mailbox status
|
|
120
|
+
*/
|
|
121
|
+
async getStatus() {
|
|
122
|
+
const response = await fetch(`${this.baseUrl}/mailbox/${this.address}`, {
|
|
123
|
+
method: 'GET',
|
|
124
|
+
headers: { Accept: 'application/json' },
|
|
125
|
+
});
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
throw new Error(`Failed to get mailbox status: ${response.status} ${response.statusText}`);
|
|
128
|
+
}
|
|
129
|
+
return await response.json();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check if the mailbox has expired
|
|
133
|
+
*/
|
|
134
|
+
isExpired() {
|
|
135
|
+
return Date.now() > this.expiresAt.getTime();
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get seconds remaining until expiration
|
|
139
|
+
*/
|
|
140
|
+
secondsRemaining() {
|
|
141
|
+
const remaining = Math.floor((this.expiresAt.getTime() - Date.now()) / 1000);
|
|
142
|
+
return Math.max(0, remaining);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.Mailbox = Mailbox;
|
|
146
|
+
//# sourceMappingURL=mailbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailbox.js","sourceRoot":"","sources":["../src/mailbox.ts"],"names":[],"mappings":";;;AAOA,6CAA4C;AAC5C,uCAA6D;AAC7D,2CAA0D;AAE1D,MAAa,OAAO;IAOlB,YACE,OAAe,EACf,SAAiB,EACjB,UAA8B,EAC9B,OAAe,EACf,OAAe;QAEf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,YAAY,IAAI,CAAC,OAAO,EAAE,EAAE;YACtE,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;SACxC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,2BAA2B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CACpE,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAyB,CAAC;QAC1D,OAAO,IAAI,CAAC,MAAM,IAAI,EA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AAC;QACJ,CAAC;QAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAmB,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAC1B,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAC/C,CAAC;QACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAChC,CAAC;CACF;AA3MD,0BA2MC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Link extraction utilities for verification and magic links
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Extract all URLs from text (both plain text and HTML)
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractLinks(text: string): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Extract a verification or magic link by pattern
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractVerificationLink(text: string, pattern?: RegExp): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Extract links from a specific domain
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractLinksByDomain(text: string, domain: string): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Extract the first link from text
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractFirstLink(text: string): string | null;
|
|
20
|
+
//# sourceMappingURL=links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/parsers/links.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAuBnD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CA8Bf;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAG3E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG5D"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Link extraction utilities for verification and magic links
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractLinks = extractLinks;
|
|
7
|
+
exports.extractVerificationLink = extractVerificationLink;
|
|
8
|
+
exports.extractLinksByDomain = extractLinksByDomain;
|
|
9
|
+
exports.extractFirstLink = extractFirstLink;
|
|
10
|
+
/**
|
|
11
|
+
* Extract all URLs from text (both plain text and HTML)
|
|
12
|
+
*/
|
|
13
|
+
function extractLinks(text) {
|
|
14
|
+
// Match URLs in plain text and href attributes
|
|
15
|
+
const urlPattern = /https?:\/\/[^\s<>"]+/gi;
|
|
16
|
+
const hrefPattern = /href=["']([^"']+)["']/gi;
|
|
17
|
+
const urls = new Set();
|
|
18
|
+
// Extract plain URLs
|
|
19
|
+
const plainUrls = text.match(urlPattern);
|
|
20
|
+
if (plainUrls) {
|
|
21
|
+
plainUrls.forEach((url) => urls.add(url.replace(/[.,;!?)]$/, '')));
|
|
22
|
+
}
|
|
23
|
+
// Extract href URLs
|
|
24
|
+
let hrefMatch;
|
|
25
|
+
while ((hrefMatch = hrefPattern.exec(text)) !== null) {
|
|
26
|
+
const url = hrefMatch[1];
|
|
27
|
+
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
28
|
+
urls.add(url);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return Array.from(urls);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extract a verification or magic link by pattern
|
|
35
|
+
*/
|
|
36
|
+
function extractVerificationLink(text, pattern) {
|
|
37
|
+
const links = extractLinks(text);
|
|
38
|
+
if (!pattern) {
|
|
39
|
+
// Default patterns for common verification links
|
|
40
|
+
const defaultPatterns = [
|
|
41
|
+
/verify/i,
|
|
42
|
+
/confirm/i,
|
|
43
|
+
/activate/i,
|
|
44
|
+
/token=/i,
|
|
45
|
+
/reset/i,
|
|
46
|
+
/magic/i,
|
|
47
|
+
];
|
|
48
|
+
for (const link of links) {
|
|
49
|
+
if (defaultPatterns.some((p) => p.test(link))) {
|
|
50
|
+
return link;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
// Use custom pattern
|
|
56
|
+
for (const link of links) {
|
|
57
|
+
if (pattern.test(link)) {
|
|
58
|
+
return link;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Extract links from a specific domain
|
|
65
|
+
*/
|
|
66
|
+
function extractLinksByDomain(text, domain) {
|
|
67
|
+
const links = extractLinks(text);
|
|
68
|
+
return links.filter((link) => link.includes(domain));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Extract the first link from text
|
|
72
|
+
*/
|
|
73
|
+
function extractFirstLink(text) {
|
|
74
|
+
const links = extractLinks(text);
|
|
75
|
+
return links.length > 0 ? links[0] : null;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../src/parsers/links.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAKH,oCAuBC;AAKD,0DAiCC;AAKD,oDAGC;AAKD,4CAGC;AAhFD;;GAEG;AACH,SAAgB,YAAY,CAAC,IAAY;IACvC,+CAA+C;IAC/C,MAAM,UA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AAC,EAAE,CAAC;gBAC9C,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qBAAqB;IACrB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,IAAY,EAAE,MAAc;IAC/D,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTP extraction utilities for common verification code patterns
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Extract a 6-digit OTP code from text
|
|
6
|
+
*/
|
|
7
|
+
export declare function extract6DigitOTP(text: string): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Extract a numeric OTP code of specified length (default: 4-8 digits)
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractNumericOTP(text: string, minLength?: number, maxLength?: number): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Extract an alphanumeric OTP code (e.g., ABC123, XY7Z9K)
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractAlphanumericOTP(text: string, length?: number): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Extract a UUID token (e.g., 550e8400-e29b-41d4-a716-446655440000)
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractUUID(text: string): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* Extract a code by custom pattern
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractByPattern(text: string, pattern: RegExp): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Try multiple common OTP patterns in order of likelihood
|
|
26
|
+
*/
|
|
27
|
+
export declare function extractOTP(text: string): string | null;
|
|
28
|
+
//# sourceMappingURL=otp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp.d.ts","sourceRoot":"","sources":["../../src/parsers/otp.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG5D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,SAAS,SAAI,EACb,SAAS,SAAI,GACZ,MAAM,GAAG,IAAI,CAIf;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,MAAM,SAAI,GACT,MAAM,GAAG,IAAI,CAIf;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG7E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkBtD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OTP extraction utilities for common verification code patterns
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extract6DigitOTP = extract6DigitOTP;
|
|
7
|
+
exports.extractNumericOTP = extractNumericOTP;
|
|
8
|
+
exports.extractAlphanumericOTP = extractAlphanumericOTP;
|
|
9
|
+
exports.extractUUID = extractUUID;
|
|
10
|
+
exports.extractByPattern = extractByPattern;
|
|
11
|
+
exports.extractOTP = extractOTP;
|
|
12
|
+
/**
|
|
13
|
+
* Extract a 6-digit OTP code from text
|
|
14
|
+
*/
|
|
15
|
+
function extract6DigitOTP(text) {
|
|
16
|
+
const match = text.match(/\b(\d{6})\b/);
|
|
17
|
+
return match ? match[1] : null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extract a numeric OTP code of specified length (default: 4-8 digits)
|
|
21
|
+
*/
|
|
22
|
+
function extractNumericOTP(text, minLength = 4, maxLength = 8) {
|
|
23
|
+
const pattern = new RegExp(`\\b(\\d{${minLength},${maxLength}})\\b`);
|
|
24
|
+
const match = text.match(pattern);
|
|
25
|
+
return match ? match[1] : null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extract an alphanumeric OTP code (e.g., ABC123, XY7Z9K)
|
|
29
|
+
*/
|
|
30
|
+
function extractAlphanumericOTP(text, length = 6) {
|
|
31
|
+
const pattern = new RegExp(`\\b([A-Z0-9]{${length}})\\b`, 'i');
|
|
32
|
+
const match = text.match(pattern);
|
|
33
|
+
return match ? match[1] : null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extract a UUID token (e.g., 550e8400-e29b-41d4-a716-446655440000)
|
|
37
|
+
*/
|
|
38
|
+
function extractUUID(text) {
|
|
39
|
+
const match = text.match(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/i);
|
|
40
|
+
return match ? match[0] : null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extract a code by custom pattern
|
|
44
|
+
*/
|
|
45
|
+
function extractByPattern(text, pattern) {
|
|
46
|
+
const match = text.match(pattern);
|
|
47
|
+
return match ? match[1] || match[0] : null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Try multiple common OTP patterns in order of likelihood
|
|
51
|
+
*/
|
|
52
|
+
function extractOTP(text) {
|
|
53
|
+
// Try 6-digit first (most common)
|
|
54
|
+
let code = extract6DigitOTP(text);
|
|
55
|
+
if (code)
|
|
56
|
+
return code;
|
|
57
|
+
// Try other numeric lengths
|
|
58
|
+
code = extractNumericOTP(text, 4, 8);
|
|
59
|
+
if (code)
|
|
60
|
+
return code;
|
|
61
|
+
// Try alphanumeric
|
|
62
|
+
code = extractAlphanumericOTP(text);
|
|
63
|
+
if (code)
|
|
64
|
+
return code;
|
|
65
|
+
// Try UUID
|
|
66
|
+
code = extractUUID(text);
|
|
67
|
+
if (code)
|
|
68
|
+
return code;
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=otp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp.js","sourceRoot":"","sources":["../../src/parsers/otp.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAKH,4CAGC;AAKD,8CAQC;AAKD,wDAOC;AAKD,kCAKC;AAKD,4CAGC;AAKD,gCAkBC;AAxED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACxC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,IAAY,EACZ,SAAS,GAAG,CAAC,EACb,SAAS,GAAG,CAAC;IAEb,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,WAAW,SAAS,IAAI,SAAS,OAAO,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,IA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mBAAmB;IACnB,IAAI,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAEtB,WAAW;IACX,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACzB,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAEtB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for tempy.email API
|
|
3
|
+
*/
|
|
4
|
+
export interface Email {
|
|
5
|
+
id: string;
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
subject: string;
|
|
9
|
+
bodyText: string;
|
|
10
|
+
bodyHtml?: string;
|
|
11
|
+
receivedAt: string;
|
|
12
|
+
messageId?: string;
|
|
13
|
+
direction: 'inbound' | 'outbound';
|
|
14
|
+
isRead: boolean;
|
|
15
|
+
allowReply: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface MailboxStatus {
|
|
18
|
+
email: string;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
expiresAt: string;
|
|
21
|
+
secondsRemaining: number;
|
|
22
|
+
isExpired: boolean;
|
|
23
|
+
webhookUrl?: string;
|
|
24
|
+
webhookFormat?: 'json' | 'xml';
|
|
25
|
+
}
|
|
26
|
+
export interface CreateMailboxResponse {
|
|
27
|
+
email: string;
|
|
28
|
+
webUrl: string;
|
|
29
|
+
expiresAt: string;
|
|
30
|
+
secondsRemaining: number;
|
|
31
|
+
webhookUrl?: string;
|
|
32
|
+
webhookFormat?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface CreateMailboxOptions {
|
|
35
|
+
webhookUrl?: string;
|
|
36
|
+
webhookFormat?: 'json' | 'xml';
|
|
37
|
+
}
|
|
38
|
+
export interface WaitForEmailOptions {
|
|
39
|
+
timeout?: number;
|
|
40
|
+
subject?: string | RegExp;
|
|
41
|
+
from?: string | RegExp;
|
|
42
|
+
pollInterval?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface WaitForOTPOptions {
|
|
45
|
+
timeout?: number;
|
|
46
|
+
pattern?: RegExp;
|
|
47
|
+
from?: string | RegExp;
|
|
48
|
+
}
|
|
49
|
+
export interface WaitForLinkOptions {
|
|
50
|
+
timeout?: number;
|
|
51
|
+
pattern?: RegExp;
|
|
52
|
+
from?: string | RegExp;
|
|
53
|
+
}
|
|
54
|
+
export interface TempyEmailConfig {
|
|
55
|
+
baseUrl?: string;
|
|
56
|
+
timeout?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface PollOptions {
|
|
59
|
+
timeout?: number;
|
|
60
|
+
interval?: number;
|
|
61
|
+
maxInterval?: number;
|
|
62
|
+
backoff?: boolean;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;IAClC,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;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
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PollOptions } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Poll a function until it returns a non-null value or timeout is reached
|
|
4
|
+
* Supports exponential backoff for efficient polling
|
|
5
|
+
*/
|
|
6
|
+
export declare function pollUntil<T>(fn: () => Promise<T | null>, options?: PollOptions): Promise<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Wait for a specific amount of time
|
|
9
|
+
*/
|
|
10
|
+
export declare function wait(ms: number): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=polling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/utils/polling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,EAC3B,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,CAAC,CAAC,CA8BZ;AAED;;GAEG;AACH,wBAAsB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpD"}
|