@mailhooks/sdk 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -3
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +4 -0
- package/dist/resources/emails.d.ts +11 -1
- package/dist/resources/emails.d.ts.map +1 -1
- package/dist/resources/emails.js +19 -2
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ const emails = await mailhooks.emails.list({
|
|
|
62
62
|
subject: 'Important',
|
|
63
63
|
startDate: '2024-01-01',
|
|
64
64
|
endDate: '2024-12-31',
|
|
65
|
+
read: false, // Filter by read status
|
|
65
66
|
},
|
|
66
67
|
sort: {
|
|
67
68
|
field: 'createdAt',
|
|
@@ -73,7 +74,11 @@ const emails = await mailhooks.emails.list({
|
|
|
73
74
|
#### Get Email
|
|
74
75
|
|
|
75
76
|
```typescript
|
|
77
|
+
// Get email without marking as read
|
|
76
78
|
const email = await mailhooks.emails.getEmail('email-id');
|
|
79
|
+
|
|
80
|
+
// Get email and mark it as read in one call
|
|
81
|
+
const readEmail = await mailhooks.emails.getEmail('email-id', true);
|
|
77
82
|
```
|
|
78
83
|
|
|
79
84
|
#### Get Email Content
|
|
@@ -99,14 +104,29 @@ const attachment = await mailhooks.emails.downloadAttachment('email-id', 'attach
|
|
|
99
104
|
// attachment.contentType contains the MIME type
|
|
100
105
|
```
|
|
101
106
|
|
|
107
|
+
#### Mark Email as Read/Unread
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
// Mark email as read
|
|
111
|
+
const readEmail = await mailhooks.emails.markAsRead('email-id');
|
|
112
|
+
console.log(readEmail.read); // true
|
|
113
|
+
|
|
114
|
+
// Mark email as unread
|
|
115
|
+
const unreadEmail = await mailhooks.emails.markAsUnread('email-id');
|
|
116
|
+
console.log(unreadEmail.read); // false
|
|
117
|
+
```
|
|
118
|
+
|
|
102
119
|
#### Wait for Email
|
|
103
120
|
|
|
104
121
|
Wait for an email that matches specific filters. Useful for testing and automation.
|
|
105
122
|
|
|
106
123
|
```typescript
|
|
107
|
-
// Basic usage - wait for email from specific sender
|
|
124
|
+
// Basic usage - wait for unread email from specific sender
|
|
108
125
|
const email = await mailhooks.emails.waitFor({
|
|
109
|
-
filter: {
|
|
126
|
+
filter: {
|
|
127
|
+
from: 'noreply@example.com',
|
|
128
|
+
read: false // Only wait for unread emails
|
|
129
|
+
},
|
|
110
130
|
timeout: 30000, // 30 seconds
|
|
111
131
|
pollInterval: 2000, // Check every 2 seconds
|
|
112
132
|
});
|
|
@@ -117,6 +137,7 @@ const email = await mailhooks.emails.waitFor({
|
|
|
117
137
|
from: 'noreply@example.com',
|
|
118
138
|
to: 'test@yourdomain.com',
|
|
119
139
|
subject: 'Order Confirmation',
|
|
140
|
+
read: false, // Only unread emails
|
|
120
141
|
},
|
|
121
142
|
lookbackWindow: 10000, // Only consider emails from last 10 seconds
|
|
122
143
|
initialDelay: 5000, // Wait 5 seconds before first check
|
|
@@ -127,7 +148,7 @@ const email = await mailhooks.emails.waitFor({
|
|
|
127
148
|
```
|
|
128
149
|
|
|
129
150
|
**Options:**
|
|
130
|
-
- `filter`: Same filters as `list()` method (from, to, subject, startDate, endDate)
|
|
151
|
+
- `filter`: Same filters as `list()` method (from, to, subject, startDate, endDate, read)
|
|
131
152
|
- `lookbackWindow`: How far back to look for emails on first check (default: 10000ms)
|
|
132
153
|
- `initialDelay`: Delay before starting to poll (default: 0ms)
|
|
133
154
|
- `timeout`: Maximum time to wait before throwing error (default: 30000ms)
|
|
@@ -150,6 +171,7 @@ interface Email {
|
|
|
150
171
|
from: string;
|
|
151
172
|
to: string[];
|
|
152
173
|
subject: string;
|
|
174
|
+
read: boolean;
|
|
153
175
|
createdAt: Date;
|
|
154
176
|
attachments: Attachment[];
|
|
155
177
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class MailhooksClient {
|
|
|
7
7
|
protected get<T>(path: string, params?: Record<string, any>): Promise<T>;
|
|
8
8
|
protected post<T>(path: string, data?: any): Promise<T>;
|
|
9
9
|
protected put<T>(path: string, data?: any): Promise<T>;
|
|
10
|
+
protected patch<T>(path: string, data?: any): Promise<T>;
|
|
10
11
|
protected delete<T>(path: string): Promise<T>;
|
|
11
12
|
protected downloadFile(path: string): Promise<ArrayBuffer>;
|
|
12
13
|
protected getAxiosInstance(): AxiosInstance;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAiB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,eAAe;IAC1B,OAAO,CAAC,IAAI,CAAgB;gBAEhB,MAAM,EAAE,eAAe;IAkBnC,OAAO,CAAC,UAAU;cAkBF,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;cAK9D,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;cAK7C,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;cAK5C,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;cAKnC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAOhE,SAAS,CAAC,gBAAgB,IAAI,aAAa;CAG5C"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAiB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,eAAe;IAC1B,OAAO,CAAC,IAAI,CAAgB;gBAEhB,MAAM,EAAE,eAAe;IAkBnC,OAAO,CAAC,UAAU;cAkBF,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;cAK9D,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;cAK7C,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;cAK5C,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;cAK9C,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;cAKnC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAOhE,SAAS,CAAC,gBAAgB,IAAI,aAAa;CAG5C"}
|
package/dist/client.js
CHANGED
|
@@ -53,6 +53,10 @@ class MailhooksClient {
|
|
|
53
53
|
const response = await this.http.put(path, data);
|
|
54
54
|
return response.data;
|
|
55
55
|
}
|
|
56
|
+
async patch(path, data) {
|
|
57
|
+
const response = await this.http.patch(path, data);
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
56
60
|
async delete(path) {
|
|
57
61
|
const response = await this.http.delete(path);
|
|
58
62
|
return response.data;
|
|
@@ -7,8 +7,10 @@ export declare class EmailsResource extends MailhooksClient {
|
|
|
7
7
|
list(params?: EmailListParams): Promise<EmailsResponse>;
|
|
8
8
|
/**
|
|
9
9
|
* Get a specific email by ID
|
|
10
|
+
* @param emailId - The ID of the email to retrieve
|
|
11
|
+
* @param markAsRead - Optional: Mark the email as read when fetching (default: false)
|
|
10
12
|
*/
|
|
11
|
-
getEmail(emailId: string): Promise<Email>;
|
|
13
|
+
getEmail(emailId: string, markAsRead?: boolean): Promise<Email>;
|
|
12
14
|
/**
|
|
13
15
|
* Get the HTML and text content of an email
|
|
14
16
|
*/
|
|
@@ -21,6 +23,14 @@ export declare class EmailsResource extends MailhooksClient {
|
|
|
21
23
|
* Download a specific attachment from an email
|
|
22
24
|
*/
|
|
23
25
|
downloadAttachment(emailId: string, attachmentId: string): Promise<DownloadResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Mark an email as read
|
|
28
|
+
*/
|
|
29
|
+
markAsRead(emailId: string): Promise<Email>;
|
|
30
|
+
/**
|
|
31
|
+
* Mark an email as unread
|
|
32
|
+
*/
|
|
33
|
+
markAsUnread(emailId: string): Promise<Email>;
|
|
24
34
|
/**
|
|
25
35
|
* Wait for an email that matches the given filters
|
|
26
36
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emails.d.ts","sourceRoot":"","sources":["../../src/resources/emails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,KAAK,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,UAAU,CAAC;AAElB,qBAAa,cAAe,SAAQ,eAAe;IACjD;;OAEG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"emails.d.ts","sourceRoot":"","sources":["../../src/resources/emails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,KAAK,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,UAAU,CAAC;AAElB,qBAAa,cAAe,SAAQ,eAAe;IACjD;;OAEG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IA0B7D;;;;OAIG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,OAAe,GAAG,OAAO,CAAC,KAAK,CAAC;IAK5E;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAIxD;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAS7D;;OAEG;IACG,kBAAkB,CACtB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,gBAAgB,CAAC;IAqB5B;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAIjD;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAInD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,KAAK,CAAC;CA8F5D"}
|
package/dist/resources/emails.js
CHANGED
|
@@ -24,6 +24,8 @@ class EmailsResource extends client_1.MailhooksClient {
|
|
|
24
24
|
queryParams['filter.createdAfter'] = params.filter.startDate;
|
|
25
25
|
if (params.filter.endDate)
|
|
26
26
|
queryParams['filter.createdBefore'] = params.filter.endDate;
|
|
27
|
+
if (params.filter.read !== undefined)
|
|
28
|
+
queryParams['filter.read'] = String(params.filter.read);
|
|
27
29
|
}
|
|
28
30
|
// Handle sort params
|
|
29
31
|
if (params?.sort) {
|
|
@@ -36,9 +38,12 @@ class EmailsResource extends client_1.MailhooksClient {
|
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Get a specific email by ID
|
|
41
|
+
* @param emailId - The ID of the email to retrieve
|
|
42
|
+
* @param markAsRead - Optional: Mark the email as read when fetching (default: false)
|
|
39
43
|
*/
|
|
40
|
-
async getEmail(emailId) {
|
|
41
|
-
|
|
44
|
+
async getEmail(emailId, markAsRead = false) {
|
|
45
|
+
const params = markAsRead ? { markAsRead: 'true' } : undefined;
|
|
46
|
+
return super.get(`/v1/emails/${emailId}`, params);
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
44
49
|
* Get the HTML and text content of an email
|
|
@@ -75,6 +80,18 @@ class EmailsResource extends client_1.MailhooksClient {
|
|
|
75
80
|
contentType: response.headers['content-type'],
|
|
76
81
|
};
|
|
77
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Mark an email as read
|
|
85
|
+
*/
|
|
86
|
+
async markAsRead(emailId) {
|
|
87
|
+
return super.patch(`/v1/emails/${emailId}/read`);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Mark an email as unread
|
|
91
|
+
*/
|
|
92
|
+
async markAsUnread(emailId) {
|
|
93
|
+
return super.patch(`/v1/emails/${emailId}/unread`);
|
|
94
|
+
}
|
|
78
95
|
/**
|
|
79
96
|
* Wait for an email that matches the given filters
|
|
80
97
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface Email {
|
|
|
9
9
|
from: string;
|
|
10
10
|
to: string[];
|
|
11
11
|
subject: string;
|
|
12
|
+
read: boolean;
|
|
12
13
|
createdAt: Date;
|
|
13
14
|
attachments: Attachment[];
|
|
14
15
|
}
|
|
@@ -33,6 +34,7 @@ export interface EmailFilter {
|
|
|
33
34
|
subject?: string;
|
|
34
35
|
startDate?: string;
|
|
35
36
|
endDate?: string;
|
|
37
|
+
read?: boolean;
|
|
36
38
|
}
|
|
37
39
|
export interface EmailSort {
|
|
38
40
|
field?: 'createdAt' | 'from' | 'subject';
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAe,SAAQ,kBAAkB;IACxD,IAAI,EAAE,KAAK,EAAE,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;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