@mailhooks/sdk 0.1.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/README.md +141 -0
- package/dist/client.d.ts +14 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +71 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/mailhooks.d.ts +11 -0
- package/dist/mailhooks.d.ts.map +1 -0
- package/dist/mailhooks.js +17 -0
- package/dist/mailhooks.js.map +1 -0
- package/dist/resources/emails.d.ts +25 -0
- package/dist/resources/emails.d.ts.map +1 -0
- package/dist/resources/emails.js +55 -0
- package/dist/resources/emails.js.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# @mailhooks/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Mailhooks API. Easily integrate email receiving capabilities into your applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mailhooks/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @mailhooks/sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @mailhooks/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Mailhooks } from '@mailhooks/sdk';
|
|
19
|
+
|
|
20
|
+
// Initialize the SDK with your API key
|
|
21
|
+
const mailhooks = new Mailhooks({
|
|
22
|
+
apiKey: 'your-api-key-here',
|
|
23
|
+
// baseUrl: 'https://custom-url.com/api', // optional, defaults to https://mailhooks.dev/api
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Get all emails
|
|
27
|
+
const emails = await mailhooks.emails.list();
|
|
28
|
+
console.log(emails.data);
|
|
29
|
+
|
|
30
|
+
// Get a specific email
|
|
31
|
+
const email = await mailhooks.emails.getEmail('email-id');
|
|
32
|
+
console.log(email);
|
|
33
|
+
|
|
34
|
+
// Get email content
|
|
35
|
+
const content = await mailhooks.emails.getContent('email-id');
|
|
36
|
+
console.log(content.html, content.text);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## API Reference
|
|
40
|
+
|
|
41
|
+
### Authentication
|
|
42
|
+
|
|
43
|
+
The SDK uses API key authentication. You can create API keys in your Mailhooks dashboard.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const mailhooks = new Mailhooks({
|
|
47
|
+
apiKey: 'your-api-key',
|
|
48
|
+
// baseUrl: 'https://custom-url.com/api', // optional, defaults to https://mailhooks.dev/api
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Emails
|
|
53
|
+
|
|
54
|
+
#### List Emails
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
const emails = await mailhooks.emails.list({
|
|
58
|
+
page: 1,
|
|
59
|
+
perPage: 20,
|
|
60
|
+
from: 'sender@example.com',
|
|
61
|
+
subject: 'Important',
|
|
62
|
+
sortBy: 'createdAt',
|
|
63
|
+
sortOrder: 'desc',
|
|
64
|
+
startDate: '2024-01-01',
|
|
65
|
+
endDate: '2024-12-31',
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Get Email
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const email = await mailhooks.emails.getEmail('email-id');
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Get Email Content
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const content = await mailhooks.emails.getContent('email-id');
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Download Email as EML
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const emlFile = await mailhooks.emails.downloadEml('email-id');
|
|
85
|
+
// emlFile.data contains the ArrayBuffer
|
|
86
|
+
// emlFile.filename contains the suggested filename
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Download Attachment
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const attachment = await mailhooks.emails.downloadAttachment('email-id', 'attachment-id');
|
|
93
|
+
// attachment.data contains the ArrayBuffer
|
|
94
|
+
// attachment.filename contains the original filename
|
|
95
|
+
// attachment.contentType contains the MIME type
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Types
|
|
99
|
+
|
|
100
|
+
The SDK includes comprehensive TypeScript types:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
interface Email {
|
|
104
|
+
id: string;
|
|
105
|
+
from: string;
|
|
106
|
+
to: string[];
|
|
107
|
+
subject: string;
|
|
108
|
+
createdAt: Date;
|
|
109
|
+
attachments: Attachment[];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface EmailContent {
|
|
113
|
+
html?: string;
|
|
114
|
+
text?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface Attachment {
|
|
118
|
+
id: string;
|
|
119
|
+
filename: string;
|
|
120
|
+
contentType: string;
|
|
121
|
+
size: number;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Error Handling
|
|
126
|
+
|
|
127
|
+
The SDK throws standard HTTP errors. Wrap your calls in try-catch blocks:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
try {
|
|
131
|
+
const email = await mailhooks.emails.getEmail('non-existent-id');
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error.response?.status === 404) {
|
|
134
|
+
console.log('Email not found');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { MailhooksConfig } from './types';
|
|
3
|
+
export declare class MailhooksClient {
|
|
4
|
+
private http;
|
|
5
|
+
constructor(config: MailhooksConfig);
|
|
6
|
+
private parseDates;
|
|
7
|
+
protected get<T>(path: string, params?: Record<string, any>): Promise<T>;
|
|
8
|
+
protected post<T>(path: string, data?: any): Promise<T>;
|
|
9
|
+
protected put<T>(path: string, data?: any): Promise<T>;
|
|
10
|
+
protected delete<T>(path: string): Promise<T>;
|
|
11
|
+
protected downloadFile(path: string): Promise<ArrayBuffer>;
|
|
12
|
+
protected getAxiosInstance(): AxiosInstance;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MailhooksClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class MailhooksClient {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.http = axios_1.default.create({
|
|
11
|
+
baseURL: config.baseUrl ?? 'https://mailhooks.dev/api',
|
|
12
|
+
headers: {
|
|
13
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
// Response interceptor to handle date parsing
|
|
18
|
+
this.http.interceptors.response.use((response) => {
|
|
19
|
+
if (response.data) {
|
|
20
|
+
this.parseDates(response.data);
|
|
21
|
+
}
|
|
22
|
+
return response;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
parseDates(obj) {
|
|
26
|
+
if (obj && typeof obj === 'object') {
|
|
27
|
+
if (Array.isArray(obj)) {
|
|
28
|
+
obj.forEach(item => this.parseDates(item));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
Object.keys(obj).forEach(key => {
|
|
32
|
+
if (key === 'createdAt' || key === 'updatedAt') {
|
|
33
|
+
if (typeof obj[key] === 'string') {
|
|
34
|
+
obj[key] = new Date(obj[key]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (typeof obj[key] === 'object') {
|
|
38
|
+
this.parseDates(obj[key]);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async get(path, params) {
|
|
45
|
+
const response = await this.http.get(path, { params });
|
|
46
|
+
return response.data;
|
|
47
|
+
}
|
|
48
|
+
async post(path, data) {
|
|
49
|
+
const response = await this.http.post(path, data);
|
|
50
|
+
return response.data;
|
|
51
|
+
}
|
|
52
|
+
async put(path, data) {
|
|
53
|
+
const response = await this.http.put(path, data);
|
|
54
|
+
return response.data;
|
|
55
|
+
}
|
|
56
|
+
async delete(path) {
|
|
57
|
+
const response = await this.http.delete(path);
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
60
|
+
async downloadFile(path) {
|
|
61
|
+
const response = await this.http.get(path, {
|
|
62
|
+
responseType: 'arraybuffer',
|
|
63
|
+
});
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
getAxiosInstance() {
|
|
67
|
+
return this.http;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.MailhooksClient = MailhooksClient;
|
|
71
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,eAAe,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.EmailsResource = exports.Mailhooks = void 0;
|
|
18
|
+
var mailhooks_1 = require("./mailhooks");
|
|
19
|
+
Object.defineProperty(exports, "Mailhooks", { enumerable: true, get: function () { return mailhooks_1.Mailhooks; } });
|
|
20
|
+
var emails_1 = require("./resources/emails");
|
|
21
|
+
Object.defineProperty(exports, "EmailsResource", { enumerable: true, get: function () { return emails_1.EmailsResource; } });
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
// Default export for convenience
|
|
24
|
+
const mailhooks_2 = require("./mailhooks");
|
|
25
|
+
exports.default = mailhooks_2.Mailhooks;
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,6CAAoD;AAA3C,wGAAA,cAAc,OAAA;AACvB,0CAAwB;AAExB,iCAAiC;AACjC,2CAAwC;AACxC,kBAAe,qBAAS,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MailhooksConfig } from './types';
|
|
2
|
+
import { EmailsResource } from './resources/emails';
|
|
3
|
+
export declare class Mailhooks {
|
|
4
|
+
emails: EmailsResource;
|
|
5
|
+
constructor(config: MailhooksConfig);
|
|
6
|
+
/**
|
|
7
|
+
* Create a new Mailhooks SDK instance
|
|
8
|
+
*/
|
|
9
|
+
static create(config: MailhooksConfig): Mailhooks;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=mailhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailhooks.d.ts","sourceRoot":"","sources":["../src/mailhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,qBAAa,SAAS;IACb,MAAM,EAAE,cAAc,CAAC;gBAElB,MAAM,EAAE,eAAe;IAInC;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS;CAGlD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mailhooks = void 0;
|
|
4
|
+
const emails_1 = require("./resources/emails");
|
|
5
|
+
class Mailhooks {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.emails = new emails_1.EmailsResource(config);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a new Mailhooks SDK instance
|
|
11
|
+
*/
|
|
12
|
+
static create(config) {
|
|
13
|
+
return new Mailhooks(config);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.Mailhooks = Mailhooks;
|
|
17
|
+
//# sourceMappingURL=mailhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailhooks.js","sourceRoot":"","sources":["../src/mailhooks.ts"],"names":[],"mappings":";;;AACA,+CAAoD;AAEpD,MAAa,SAAS;IAGpB,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,uBAAc,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAuB;QACnC,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACF;AAbD,8BAaC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MailhooksClient } from '../client';
|
|
2
|
+
import { Email, EmailContent, EmailsResponse, EmailListParams, DownloadResponse } from '../types';
|
|
3
|
+
export declare class EmailsResource extends MailhooksClient {
|
|
4
|
+
/**
|
|
5
|
+
* Get a paginated list of emails
|
|
6
|
+
*/
|
|
7
|
+
list(params?: EmailListParams): Promise<EmailsResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Get a specific email by ID
|
|
10
|
+
*/
|
|
11
|
+
getEmail(emailId: string): Promise<Email>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the HTML and text content of an email
|
|
14
|
+
*/
|
|
15
|
+
getContent(emailId: string): Promise<EmailContent>;
|
|
16
|
+
/**
|
|
17
|
+
* Download email in EML format
|
|
18
|
+
*/
|
|
19
|
+
downloadEml(emailId: string): Promise<DownloadResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Download a specific attachment from an email
|
|
22
|
+
*/
|
|
23
|
+
downloadAttachment(emailId: string, attachmentId: string): Promise<DownloadResponse>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=emails.d.ts.map
|
|
@@ -0,0 +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,EACjB,MAAM,UAAU,CAAC;AAElB,qBAAa,cAAe,SAAQ,eAAe;IACjD;;OAEG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAI7D;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAI/C;;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;CAoB7B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailsResource = void 0;
|
|
4
|
+
const client_1 = require("../client");
|
|
5
|
+
class EmailsResource extends client_1.MailhooksClient {
|
|
6
|
+
/**
|
|
7
|
+
* Get a paginated list of emails
|
|
8
|
+
*/
|
|
9
|
+
async list(params) {
|
|
10
|
+
return super.get('/v1/emails', params);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get a specific email by ID
|
|
14
|
+
*/
|
|
15
|
+
async getEmail(emailId) {
|
|
16
|
+
return super.get(`/v1/emails/${emailId}`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the HTML and text content of an email
|
|
20
|
+
*/
|
|
21
|
+
async getContent(emailId) {
|
|
22
|
+
return super.get(`/v1/emails/${emailId}/content`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Download email in EML format
|
|
26
|
+
*/
|
|
27
|
+
async downloadEml(emailId) {
|
|
28
|
+
const data = await this.downloadFile(`/v1/emails/${emailId}/eml`);
|
|
29
|
+
return {
|
|
30
|
+
data,
|
|
31
|
+
filename: `email-${emailId}.eml`,
|
|
32
|
+
contentType: 'message/rfc822',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Download a specific attachment from an email
|
|
37
|
+
*/
|
|
38
|
+
async downloadAttachment(emailId, attachmentId) {
|
|
39
|
+
const axios = this.getAxiosInstance();
|
|
40
|
+
const response = await axios.get(`/v1/emails/${emailId}/attachments/${attachmentId}`, {
|
|
41
|
+
responseType: 'arraybuffer',
|
|
42
|
+
});
|
|
43
|
+
const contentDisposition = response.headers['content-disposition'];
|
|
44
|
+
const filename = contentDisposition
|
|
45
|
+
? contentDisposition.split('filename=')[1]?.replace(/['"]/g, '')
|
|
46
|
+
: `attachment-${attachmentId}`;
|
|
47
|
+
return {
|
|
48
|
+
data: response.data,
|
|
49
|
+
filename,
|
|
50
|
+
contentType: response.headers['content-type'],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.EmailsResource = EmailsResource;
|
|
55
|
+
//# sourceMappingURL=emails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emails.js","sourceRoot":"","sources":["../../src/resources/emails.ts"],"names":[],"mappings":";;;AAAA,sCAA4C;AAS5C,MAAa,cAAe,SAAQ,wBAAe;IACjD;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,MAAwB;QACjC,OAAO,KAAK,CAAC,GAAG,CAAiB,YAAY,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,OAAO,KAAK,CAAC,GAAG,CAAQ,cAAc,OAAO,EAAE,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,OAAe;QAC9B,OAAO,KAAK,CAAC,GAAG,CAAe,cAAc,OAAO,UAAU,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,cAAc,OAAO,MAAM,CAAC,CAAC;QAClE,OAAO;YACL,IAAI;YACJ,QAAQ,EAAE,SAAS,OAAO,MAAM;YAChC,WAAW,EAAE,gBAAgB;SAC9B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,kBAAkB,CACtB,OAAe,EACf,YAAoB;QAEpB,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,cAAc,OAAO,gBAAgB,YAAY,EAAE,EACnD;YACE,YAAY,EAAE,aAAa;SAC5B,CACF,CAAC;QAEF,MAAM,kBAAkB,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;QACnE,MAAM,QAAQ,GAAG,kBAAkB;YACjC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAChE,CAAC,CAAC,cAAc,YAAY,EAAE,CAAC;QAEjC,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,QAAQ;YACR,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC;SAC9C,CAAC;IACJ,CAAC;CACF;AA5DD,wCA4DC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface Attachment {
|
|
2
|
+
id: string;
|
|
3
|
+
filename: string;
|
|
4
|
+
contentType: string;
|
|
5
|
+
size: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Email {
|
|
8
|
+
id: string;
|
|
9
|
+
from: string;
|
|
10
|
+
to: string[];
|
|
11
|
+
subject: string;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
attachments: Attachment[];
|
|
14
|
+
}
|
|
15
|
+
export interface EmailContent {
|
|
16
|
+
html?: string;
|
|
17
|
+
text?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PaginationResponse {
|
|
20
|
+
currentPage: number;
|
|
21
|
+
perPage: number;
|
|
22
|
+
totalItems: number;
|
|
23
|
+
totalPages: number;
|
|
24
|
+
hasNextPage: boolean;
|
|
25
|
+
nextCursor?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface EmailsResponse extends PaginationResponse {
|
|
28
|
+
data: Email[];
|
|
29
|
+
}
|
|
30
|
+
export interface EmailListParams {
|
|
31
|
+
page?: number;
|
|
32
|
+
perPage?: number;
|
|
33
|
+
from?: string;
|
|
34
|
+
to?: string;
|
|
35
|
+
subject?: string;
|
|
36
|
+
sortBy?: 'createdAt';
|
|
37
|
+
sortOrder?: 'asc' | 'desc';
|
|
38
|
+
startDate?: string;
|
|
39
|
+
endDate?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface MailhooksConfig {
|
|
42
|
+
apiKey: string;
|
|
43
|
+
baseUrl?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface DownloadResponse {
|
|
46
|
+
data: ArrayBuffer;
|
|
47
|
+
filename?: string;
|
|
48
|
+
contentType?: string;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mailhooks/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for Mailhooks API",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc -p .",
|
|
12
|
+
"dev": "tsc -p . --watch",
|
|
13
|
+
"test": "echo \"No tests yet\"",
|
|
14
|
+
"prepublishOnly": "pnpm build"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mailhooks",
|
|
18
|
+
"email",
|
|
19
|
+
"sdk",
|
|
20
|
+
"typescript",
|
|
21
|
+
"api"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"axios": "^1.6.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.4.5",
|
|
28
|
+
"@types/node": "^20.0.0"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"require": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|