mailisk 2.0.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test.yml +31 -0
- package/README.md +122 -22
- package/dist/index.d.ts +169 -11
- package/dist/index.js +49 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -6
- package/dist/index.mjs.map +1 -1
- package/jest.config.js +13 -0
- package/package.json +11 -3
- package/private/dist/private/index.js +28 -0
- package/private/dist/private/index.js.map +1 -0
- package/private/dist/src/mailisk.interfaces.js +3 -0
- package/private/dist/src/mailisk.interfaces.js.map +1 -0
- package/private/dist/src/mailisk.js +168 -0
- package/private/dist/src/mailisk.js.map +1 -0
- package/private/index.ts +17 -0
- package/private/node_modules/.package-lock.json +44 -0
- package/private/node_modules/typescript/LICENSE.txt +55 -0
- package/private/node_modules/typescript/README.md +50 -0
- package/private/node_modules/typescript/SECURITY.md +41 -0
- package/private/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
- package/private/node_modules/typescript/bin/tsc +2 -0
- package/private/node_modules/typescript/bin/tsserver +2 -0
- package/private/node_modules/typescript/lib/_tsc.js +133818 -0
- package/private/node_modules/typescript/lib/_tsserver.js +659 -0
- package/private/node_modules/typescript/lib/_typingsInstaller.js +222 -0
- package/private/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/lib.d.ts +22 -0
- package/private/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
- package/private/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
- package/private/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
- package/private/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
- package/private/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
- package/private/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
- package/private/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
- package/private/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
- package/private/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
- package/private/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
- package/private/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
- package/private/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
- package/private/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
- package/private/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
- package/private/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/private/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
- package/private/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
- package/private/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
- package/private/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/private/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
- package/private/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
- package/private/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
- package/private/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
- package/private/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/private/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
- package/private/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
- package/private/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/private/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
- package/private/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
- package/private/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
- package/private/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
- package/private/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
- package/private/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
- package/private/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
- package/private/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
- package/private/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
- package/private/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
- package/private/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
- package/private/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
- package/private/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
- package/private/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/private/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
- package/private/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/private/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
- package/private/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
- package/private/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
- package/private/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
- package/private/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
- package/private/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
- package/private/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
- package/private/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
- package/private/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
- package/private/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
- package/private/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
- package/private/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
- package/private/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
- package/private/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
- package/private/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
- package/private/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/private/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
- package/private/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
- package/private/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
- package/private/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
- package/private/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
- package/private/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/private/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
- package/private/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
- package/private/node_modules/typescript/lib/lib.es6.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
- package/private/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
- package/private/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
- package/private/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
- package/private/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
- package/private/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
- package/private/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
- package/private/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
- package/private/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
- package/private/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
- package/private/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/private/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
- package/private/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
- package/private/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
- package/private/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
- package/private/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
- package/private/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/tsc.js +8 -0
- package/private/node_modules/typescript/lib/tsserver.js +8 -0
- package/private/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
- package/private/node_modules/typescript/lib/tsserverlibrary.js +21 -0
- package/private/node_modules/typescript/lib/typesMap.json +497 -0
- package/private/node_modules/typescript/lib/typescript.d.ts +11437 -0
- package/private/node_modules/typescript/lib/typescript.js +200276 -0
- package/private/node_modules/typescript/lib/typingsInstaller.js +8 -0
- package/private/node_modules/typescript/lib/watchGuard.js +53 -0
- package/private/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
- package/private/node_modules/typescript/package.json +120 -0
- package/private/package-lock.json +53 -0
- package/private/package.json +17 -0
- package/private/tsconfig.json +103 -0
- package/src/mailisk.interfaces.ts +123 -6
- package/src/mailisk.ts +120 -11
- package/tests/mocks/axios-mocks.ts +108 -0
- package/tests/setup.ts +21 -0
- package/tests/unit/mailisk.test.ts +480 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Build and Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Test
|
|
12
|
+
needs: build
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v3
|
|
17
|
+
|
|
18
|
+
- name: Use Node.js 18.x
|
|
19
|
+
uses: actions/setup-node@v3
|
|
20
|
+
with:
|
|
21
|
+
node-version: 18.x
|
|
22
|
+
cache: "npm"
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: npm ci
|
|
26
|
+
|
|
27
|
+
- name: Build
|
|
28
|
+
run: npm run build
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: npm test
|
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# Mailisk Node Client
|
|
2
2
|
|
|
3
|
-
Mailisk is an end-to-end email testing platform. It allows you to receive emails with code
|
|
3
|
+
Mailisk is an end-to-end email and SMS testing platform. It allows you to receive emails and SMS messages with code to automate tests.
|
|
4
4
|
|
|
5
5
|
- Get a unique subdomain and unlimited email addresses for free.
|
|
6
6
|
- Easily automate E2E password reset and account verification by catching emails.
|
|
7
|
-
-
|
|
7
|
+
- Receive SMS messages and automate SMS tests.
|
|
8
|
+
- Virtual SMTP and SMS support to test without 3rd party clients.
|
|
8
9
|
|
|
9
10
|
## Get started
|
|
10
11
|
|
|
@@ -35,7 +36,7 @@ const { MailiskClient } = require("mailisk");
|
|
|
35
36
|
const mailisk = new MailiskClient({ apiKey: "YOUR_API_KEY" });
|
|
36
37
|
|
|
37
38
|
// send email (using virtual SMTP)
|
|
38
|
-
await
|
|
39
|
+
await mailisk.sendVirtualEmail(namespace, {
|
|
39
40
|
from: "test@example.com",
|
|
40
41
|
to: `john@${namespace}.mailisk.net`,
|
|
41
42
|
subject: "Testing",
|
|
@@ -43,7 +44,7 @@ await client.sendVirtualEmail(namespace, {
|
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
// receive email
|
|
46
|
-
const result = await
|
|
47
|
+
const result = await mailisk.searchInbox(namespace);
|
|
47
48
|
|
|
48
49
|
console.log(result);
|
|
49
50
|
```
|
|
@@ -52,37 +53,44 @@ console.log(result);
|
|
|
52
53
|
|
|
53
54
|
This library wraps the REST API endpoints. Find out more in the [API Reference](https://docs.mailisk.com/api-reference/).
|
|
54
55
|
|
|
55
|
-
## Client functions
|
|
56
|
+
## Client functions (Email)
|
|
57
|
+
|
|
58
|
+
### `searchInbox(namespace, params?, requestOptions?)`
|
|
59
|
+
|
|
60
|
+
Use `searchInbox` to fetch messages that arrived in a given namespace, optionally waiting until the first new mail shows up.
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
For the full parameter options see the [endpoint reference](https://docs.mailisk.com/api-reference/search-inbox.html#request-1).
|
|
58
63
|
|
|
59
|
-
|
|
64
|
+
Default behaviour:
|
|
60
65
|
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
66
|
+
- Waits until at least one new email arrives (override with `wait: false`).
|
|
67
|
+
- Times out after 5 minutes if nothing shows up (adjust via `requestOptions.timeout`).
|
|
68
|
+
- Ignores messages older than 15 minutes to avoid picking up leftovers from previous tests (change via `from_timestamp`).
|
|
69
|
+
|
|
70
|
+
#### Quick examples
|
|
64
71
|
|
|
65
72
|
```js
|
|
66
|
-
//
|
|
73
|
+
// wait up to the default 5 min for *any* new mail
|
|
67
74
|
await mailisk.searchInbox(namespace);
|
|
68
|
-
//
|
|
75
|
+
// custom 60-second timeout
|
|
69
76
|
await mailisk.searchInbox(namespace, {}, { timeout: 1000 * 60 });
|
|
70
|
-
//
|
|
77
|
+
// polling pattern — return immediately, even if inbox is empty
|
|
71
78
|
await mailisk.searchInbox(namespace, { wait: false });
|
|
79
|
+
// returns the last 20 emails in the namespace immediately
|
|
80
|
+
await mailisk.searchInbox(namespace, { wait: false, from_timestamp: 0, limit: 20 });
|
|
72
81
|
```
|
|
73
82
|
|
|
74
83
|
#### Filter by destination address
|
|
75
84
|
|
|
76
|
-
A common
|
|
85
|
+
A common pattern is to wait for the email your UI just triggered (e.g. password-reset).
|
|
86
|
+
Pass `to_addr_prefix` so you don’t pick up stale messages:
|
|
77
87
|
|
|
78
88
|
```js
|
|
79
89
|
const { data: emails } = await mailisk.searchInbox(namespace, {
|
|
80
|
-
to_addr_prefix:
|
|
90
|
+
to_addr_prefix: `john@${namespace}.mailisk.net`,
|
|
81
91
|
});
|
|
82
92
|
```
|
|
83
93
|
|
|
84
|
-
For more parameter options see the [endpoint reference](https://docs.mailisk.com/api-reference/search-inbox.html#request-1).
|
|
85
|
-
|
|
86
94
|
### sendVirtualEmail(namespace, params)
|
|
87
95
|
|
|
88
96
|
Send an email using [Virtual SMTP](https://docs.mailisk.com/smtp.html). This will fetch the SMTP settings for the selected namespace and send an email. These emails can only be sent to an address that ends in `@{namespace}.mailisk.net`.
|
|
@@ -98,15 +106,107 @@ await mailisk.sendVirtualEmail(namespace, {
|
|
|
98
106
|
});
|
|
99
107
|
```
|
|
100
108
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
### listNamespaces()
|
|
109
|
+
### `listNamespaces()`
|
|
104
110
|
|
|
105
111
|
List all namespaces associated with the current API Key.
|
|
106
112
|
|
|
107
113
|
```js
|
|
108
|
-
const
|
|
114
|
+
const { data: namespaces } = await mailisk.listNamespaces();
|
|
109
115
|
|
|
110
116
|
// will be ['namespace1', 'namespace2']
|
|
111
|
-
const
|
|
117
|
+
const namespacesList = namespaces.map((nr) => nr.namespace);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### `getAttachment(attachmentId)`
|
|
121
|
+
|
|
122
|
+
Get information about an attachment.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const attachment = await mailisk.getAttachment(attachmentId);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### `downloadAttachment(attachmentId)`
|
|
129
|
+
|
|
130
|
+
Retrieve the raw bytes of a file attached to an email message.
|
|
131
|
+
Typically you call this after `searchInbox` → iterate over `email.attachments[]` → pass the desired `attachment.id`.
|
|
132
|
+
|
|
133
|
+
#### Quick examples
|
|
134
|
+
|
|
135
|
+
```js
|
|
136
|
+
import fs from "node:fs";
|
|
137
|
+
import path from "node:path";
|
|
138
|
+
|
|
139
|
+
// assume 'email' was fetched via searchInbox()
|
|
140
|
+
const { id, filename } = email.attachments[0];
|
|
141
|
+
|
|
142
|
+
// download the attachment
|
|
143
|
+
const buffer = await mailisk.downloadAttachment(id);
|
|
144
|
+
|
|
145
|
+
// save to disk (preserve original filename)
|
|
146
|
+
fs.writeFileSync(filename, buffer);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Streaming large files
|
|
150
|
+
|
|
151
|
+
downloadAttachment returns the entire file as a single Buffer.
|
|
152
|
+
If you expect very large attachments and want to avoid holding them fully in memory, use getAttachment(attachmentId).download_url and stream with fetch / axios instead:
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
const meta = await mailisk.getAttachment(id);
|
|
156
|
+
const res = await fetch(meta.download_url);
|
|
157
|
+
const fileStream = fs.createWriteStream(filename);
|
|
158
|
+
await new Promise((ok, err) => res.body.pipe(fileStream).on("finish", ok).on("error", err));
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Client functions (SMS)
|
|
162
|
+
|
|
163
|
+
### `searchSmsMessages(phoneNumber, params?, requestOptions?)`
|
|
164
|
+
|
|
165
|
+
Fetch recent SMS messages that were delivered to one of your Mailisk phone numbers.
|
|
166
|
+
For the full parameter list see the [Search SMS reference](https://docs.mailisk.com/api-reference/search-sms-messages.html#request).
|
|
167
|
+
|
|
168
|
+
Default behaviour:
|
|
169
|
+
|
|
170
|
+
- Waits until at least one SMS matches the filters (override with `wait: false`).
|
|
171
|
+
- Times out after 5 minutes if nothing shows up (adjust via `requestOptions.timeout`).
|
|
172
|
+
- Ignores messages older than 15 minutes (change via `from_date`).
|
|
173
|
+
|
|
174
|
+
#### Quick examples
|
|
175
|
+
|
|
176
|
+
```js
|
|
177
|
+
// get or wait for SMS messages sent to ths number
|
|
178
|
+
const { data: sms } = await mailisk.searchSmsMessages(phoneNumber);
|
|
179
|
+
|
|
180
|
+
// look for a verification code coming from a known sender
|
|
181
|
+
await mailisk.searchSmsMessages(phoneNumber, {
|
|
182
|
+
from_number: "+1800555",
|
|
183
|
+
body: "Your code",
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// polling pattern — return immediately even if nothing matched
|
|
187
|
+
await mailisk.searchSmsMessages(
|
|
188
|
+
phoneNumber,
|
|
189
|
+
{ wait: false, limit: 10, from_date: new Date(Date.now() - 1000 * 60 * 5).toISOString() },
|
|
190
|
+
{ timeout: 10_000 }
|
|
191
|
+
);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### `listSmsNumbers()`
|
|
195
|
+
|
|
196
|
+
List all SMS phone numbers associated with the current account.
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
const { data: phoneNumbers } = await mailisk.listSmsNumbers();
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### `sendVirtualSms(params)`
|
|
203
|
+
|
|
204
|
+
Send a virtual SMS message to a phone number you have access to.
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
await mailisk.sendVirtualSms({
|
|
208
|
+
from_number: "15551234567",
|
|
209
|
+
to_number: "15557654321",
|
|
210
|
+
body: "Test message",
|
|
211
|
+
});
|
|
112
212
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
1
|
+
import { AxiosBasicCredentials, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Attachment } from 'nodemailer/lib/mailer';
|
|
2
3
|
|
|
3
4
|
interface EmailAddress {
|
|
4
5
|
/** Email address */
|
|
@@ -6,6 +7,16 @@ interface EmailAddress {
|
|
|
6
7
|
/** Display name, if one is specified */
|
|
7
8
|
name?: string;
|
|
8
9
|
}
|
|
10
|
+
interface EmailAttachment {
|
|
11
|
+
/** Unique identifier for the attachment */
|
|
12
|
+
id: string;
|
|
13
|
+
/** Filename of the attachment */
|
|
14
|
+
filename: string;
|
|
15
|
+
/** Content type of the attachment */
|
|
16
|
+
content_type: string;
|
|
17
|
+
/** Size in bytes of the attachment */
|
|
18
|
+
size: number;
|
|
19
|
+
}
|
|
9
20
|
interface Email {
|
|
10
21
|
/** Namespace scoped ID */
|
|
11
22
|
id: string;
|
|
@@ -31,6 +42,44 @@ interface Email {
|
|
|
31
42
|
expires_timestamp: number;
|
|
32
43
|
/** The spam score as reported by SpamAssassin */
|
|
33
44
|
spam_score?: number;
|
|
45
|
+
/** The headers of the email */
|
|
46
|
+
headers?: Record<string, string>;
|
|
47
|
+
/** The attachments of the email */
|
|
48
|
+
attachments?: EmailAttachment[];
|
|
49
|
+
}
|
|
50
|
+
interface SmsMessage {
|
|
51
|
+
/** Unique identifier for the message */
|
|
52
|
+
id: string;
|
|
53
|
+
/** Unique identifier for the SMS phone number */
|
|
54
|
+
sms_phone_number_id: string;
|
|
55
|
+
/** Body of the message */
|
|
56
|
+
body: string;
|
|
57
|
+
/** From number of the message */
|
|
58
|
+
from_number: string;
|
|
59
|
+
/** To number of the message */
|
|
60
|
+
to_number: string;
|
|
61
|
+
/** Provider message ID */
|
|
62
|
+
provider_message_id?: string;
|
|
63
|
+
/** Date and time the message was created */
|
|
64
|
+
created_at: string;
|
|
65
|
+
/** Direction of the message */
|
|
66
|
+
direction: "inbound" | "outbound";
|
|
67
|
+
}
|
|
68
|
+
interface SmsNumber {
|
|
69
|
+
/** Unique identifier for the SMS number */
|
|
70
|
+
id: string;
|
|
71
|
+
/** Unique identifier for the organisation */
|
|
72
|
+
organisation_id: string;
|
|
73
|
+
/** Status of the SMS number */
|
|
74
|
+
status: "requested" | "active" | "disabled";
|
|
75
|
+
/** Country of the SMS number */
|
|
76
|
+
country: string;
|
|
77
|
+
/** SMS Phone number */
|
|
78
|
+
phone_number?: string;
|
|
79
|
+
/** Date and time the SMS number was created */
|
|
80
|
+
created_at: string;
|
|
81
|
+
/** Date and time the SMS number was updated */
|
|
82
|
+
updated_at: string;
|
|
34
83
|
}
|
|
35
84
|
interface SearchInboxParams {
|
|
36
85
|
/**
|
|
@@ -96,13 +145,22 @@ interface SmtpSettings {
|
|
|
96
145
|
password: string;
|
|
97
146
|
};
|
|
98
147
|
}
|
|
148
|
+
interface GetAttachmentResponse {
|
|
149
|
+
data: {
|
|
150
|
+
id: string;
|
|
151
|
+
filename: string;
|
|
152
|
+
content_type: string;
|
|
153
|
+
size: number;
|
|
154
|
+
expires_at: string | null;
|
|
155
|
+
download_url: string;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
99
158
|
interface ListNamespacesResponse {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
];
|
|
159
|
+
total_count: number;
|
|
160
|
+
data: {
|
|
161
|
+
id: string;
|
|
162
|
+
namespace: string;
|
|
163
|
+
}[];
|
|
106
164
|
}
|
|
107
165
|
interface SendVirtualEmailParams {
|
|
108
166
|
/** Sender of email */
|
|
@@ -119,14 +177,89 @@ interface SendVirtualEmailParams {
|
|
|
119
177
|
text?: string | undefined;
|
|
120
178
|
/** The HTML version of the message */
|
|
121
179
|
html?: string | undefined;
|
|
180
|
+
/** Custom headers for the email */
|
|
181
|
+
headers?: Record<string, string>;
|
|
182
|
+
/** Attachments to the email */
|
|
183
|
+
attachments?: Attachment[];
|
|
184
|
+
}
|
|
185
|
+
interface SearchSmsMessagesParams {
|
|
186
|
+
/**
|
|
187
|
+
* The maximum number of SMS messages returned (1-100), used alongside `offset` for pagination.
|
|
188
|
+
*/
|
|
189
|
+
limit?: number;
|
|
190
|
+
/**
|
|
191
|
+
* The number of SMS messages to skip/ignore, used alongside `limit` for pagination.
|
|
192
|
+
*/
|
|
193
|
+
offset?: number;
|
|
194
|
+
/**
|
|
195
|
+
* Filter messages by body contents (case insensitive).
|
|
196
|
+
*/
|
|
197
|
+
body?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Filter messages by sender phone number prefix.
|
|
200
|
+
*/
|
|
201
|
+
from_number?: string;
|
|
202
|
+
/**
|
|
203
|
+
* Filter messages created on or after this date.
|
|
204
|
+
* Provide an ISO 8601 timestamp string.
|
|
205
|
+
*/
|
|
206
|
+
from_date?: string;
|
|
207
|
+
/**
|
|
208
|
+
* Filter messages created on or before this date.
|
|
209
|
+
* Provide an ISO 8601 timestamp string.
|
|
210
|
+
*/
|
|
211
|
+
to_date?: string;
|
|
212
|
+
/**
|
|
213
|
+
* When true, keep the request open until at least one SMS is returned.
|
|
214
|
+
*/
|
|
215
|
+
wait?: boolean;
|
|
216
|
+
}
|
|
217
|
+
interface SearchSmsMessagesResponse {
|
|
218
|
+
total_count: number;
|
|
219
|
+
options: SearchSmsMessagesParams;
|
|
220
|
+
data: SmsMessage[];
|
|
221
|
+
}
|
|
222
|
+
interface ListSmsNumbersResponse {
|
|
223
|
+
total_count: number;
|
|
224
|
+
data: SmsNumber[];
|
|
225
|
+
}
|
|
226
|
+
interface SendVirtualSmsParams {
|
|
227
|
+
/** The phone number to send the SMS from */
|
|
228
|
+
from_number: string;
|
|
229
|
+
/** The phone number to send the SMS to */
|
|
230
|
+
to_number: string;
|
|
231
|
+
/** The body of the SMS message */
|
|
232
|
+
body: string;
|
|
122
233
|
}
|
|
123
234
|
|
|
124
235
|
declare class MailiskClient {
|
|
125
|
-
constructor({ apiKey, baseUrl }: {
|
|
236
|
+
constructor({ apiKey, baseUrl, auth }: {
|
|
126
237
|
apiKey: string;
|
|
127
238
|
baseUrl?: string;
|
|
239
|
+
auth?: AxiosBasicCredentials;
|
|
128
240
|
});
|
|
129
241
|
private readonly axiosInstance;
|
|
242
|
+
/**
|
|
243
|
+
* Search SMS messages sent to a phone number.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* Search for SMS messages sent to a phone number
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const { data: smsMessages } = await client.searchSmsMessages("1234567890");
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
searchSmsMessages(phoneNumber: string, params?: SearchSmsMessagesParams, config?: AxiosRequestConfig): Promise<SearchSmsMessagesResponse>;
|
|
252
|
+
/**
|
|
253
|
+
* List all SMS phone numbers associated with the current account.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* List all SMS phone numbers
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const { data: smsNumbers } = await client.listSmsNumbers();
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
listSmsNumbers(): Promise<ListSmsNumbersResponse>;
|
|
262
|
+
sendVirtualSms(params: SendVirtualSmsParams): Promise<void>;
|
|
130
263
|
/**
|
|
131
264
|
* List all namespaces that belong to the current account (API key).
|
|
132
265
|
*/
|
|
@@ -152,12 +285,12 @@ declare class MailiskClient {
|
|
|
152
285
|
* Search inbox of a namespace.
|
|
153
286
|
*
|
|
154
287
|
* By default, this calls the api using the `wait` flag. This means the call won't timeout until at least one email is received or 5 minutes pass.
|
|
155
|
-
* It also uses a default `from_timestamp` of **current timestamp -
|
|
288
|
+
* It also uses a default `from_timestamp` of **current timestamp - 15 minutes**. This means that older emails will be ignored.
|
|
156
289
|
*
|
|
157
290
|
* Both of these settings can be overriden by passing them in the `params` object.
|
|
158
291
|
*
|
|
159
292
|
* @example
|
|
160
|
-
* Get the latest emails
|
|
293
|
+
* Get the latest emails
|
|
161
294
|
* ```typescript
|
|
162
295
|
* const { data: emails } = await client.searchInbox(namespace);
|
|
163
296
|
* ```
|
|
@@ -166,7 +299,17 @@ declare class MailiskClient {
|
|
|
166
299
|
* Get the latest emails for a specific email address
|
|
167
300
|
* ```typescript
|
|
168
301
|
* const { data: emails } = await client.searchInbox(namespace, {
|
|
169
|
-
*
|
|
302
|
+
* to_addr_prefix: 'john@mynamespace.mailisk.net'
|
|
303
|
+
* });
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* Get the last 20 emails in the namespace
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const { data: emails } = await mailisk.searchInbox(namespace, {
|
|
310
|
+
* wait: false,
|
|
311
|
+
* from_timestamp: 0,
|
|
312
|
+
* limit: 20
|
|
170
313
|
* });
|
|
171
314
|
* ```
|
|
172
315
|
*/
|
|
@@ -175,6 +318,21 @@ declare class MailiskClient {
|
|
|
175
318
|
* Get the SMTP settings for a namespace.
|
|
176
319
|
*/
|
|
177
320
|
getSmtpSettings(namespace: string): Promise<SmtpSettings>;
|
|
321
|
+
getAttachment(attachmentId: string): Promise<GetAttachmentResponse>;
|
|
322
|
+
/**
|
|
323
|
+
* Download an attachment from an attachment ID.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* Download an attachment from an email
|
|
327
|
+
* ```typescript
|
|
328
|
+
* const attachment = email.attachments[0];
|
|
329
|
+
* const attachmentBuffer = await client.downloadAttachment(attachment.id);
|
|
330
|
+
*
|
|
331
|
+
* // save to file
|
|
332
|
+
* fs.writeFileSync(attachment.filename, attachmentBuffer);
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
downloadAttachment(attachmentId: string): Promise<Buffer>;
|
|
178
336
|
}
|
|
179
337
|
|
|
180
338
|
export { MailiskClient };
|
package/dist/index.js
CHANGED
|
@@ -35,15 +35,47 @@ module.exports = __toCommonJS(src_exports);
|
|
|
35
35
|
var import_axios = __toESM(require("axios"));
|
|
36
36
|
var import_nodemailer = __toESM(require("nodemailer"));
|
|
37
37
|
var MailiskClient = class {
|
|
38
|
-
constructor({ apiKey, baseUrl }) {
|
|
38
|
+
constructor({ apiKey, baseUrl, auth }) {
|
|
39
39
|
this.axiosInstance = import_axios.default.create({
|
|
40
40
|
headers: {
|
|
41
41
|
"X-Api-Key": apiKey
|
|
42
42
|
},
|
|
43
|
-
baseURL: baseUrl || "https://api.mailisk.com/"
|
|
43
|
+
baseURL: baseUrl || "https://api.mailisk.com/",
|
|
44
|
+
auth
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
axiosInstance;
|
|
48
|
+
async searchSmsMessages(phoneNumber, params, config) {
|
|
49
|
+
let _params = { ...params };
|
|
50
|
+
if (params?.from_date === void 0 || params?.from_date === null) {
|
|
51
|
+
_params.from_date = new Date(Date.now() - 15 * 60 * 1e3).toISOString();
|
|
52
|
+
}
|
|
53
|
+
if (params?.wait !== false) {
|
|
54
|
+
_params.wait = true;
|
|
55
|
+
}
|
|
56
|
+
let _config = { ...config };
|
|
57
|
+
if (config?.maxRedirects === void 0) {
|
|
58
|
+
_config.maxRedirects = 99999;
|
|
59
|
+
}
|
|
60
|
+
if (_params.wait && config?.timeout === void 0) {
|
|
61
|
+
_config.timeout = 1e3 * 60 * 5;
|
|
62
|
+
}
|
|
63
|
+
const requestParams = {
|
|
64
|
+
..._params,
|
|
65
|
+
from_date: _params.from_date ?? void 0,
|
|
66
|
+
to_date: _params.to_date ?? void 0
|
|
67
|
+
};
|
|
68
|
+
return (await this.axiosInstance.get(`api/sms/${phoneNumber}/messages`, {
|
|
69
|
+
..._config,
|
|
70
|
+
params: requestParams
|
|
71
|
+
})).data;
|
|
72
|
+
}
|
|
73
|
+
async listSmsNumbers() {
|
|
74
|
+
return (await this.axiosInstance.get("api/sms/numbers")).data;
|
|
75
|
+
}
|
|
76
|
+
async sendVirtualSms(params) {
|
|
77
|
+
return (await this.axiosInstance.post("api/sms/virtual", params)).data;
|
|
78
|
+
}
|
|
47
79
|
async listNamespaces() {
|
|
48
80
|
return (await this.axiosInstance.get("api/namespaces")).data;
|
|
49
81
|
}
|
|
@@ -58,13 +90,15 @@ var MailiskClient = class {
|
|
|
58
90
|
pass: smtpSettings.data.password
|
|
59
91
|
}
|
|
60
92
|
});
|
|
61
|
-
const { from, to, subject, text, html } = params;
|
|
93
|
+
const { from, to, subject, text, html, headers, attachments } = params;
|
|
62
94
|
await transport.sendMail({
|
|
63
95
|
from,
|
|
64
96
|
to,
|
|
65
97
|
subject,
|
|
66
98
|
text,
|
|
67
|
-
html
|
|
99
|
+
html,
|
|
100
|
+
headers,
|
|
101
|
+
attachments
|
|
68
102
|
});
|
|
69
103
|
transport.close();
|
|
70
104
|
}
|
|
@@ -77,10 +111,10 @@ var MailiskClient = class {
|
|
|
77
111
|
_params.wait = true;
|
|
78
112
|
}
|
|
79
113
|
let _config = { ...config };
|
|
80
|
-
if (
|
|
114
|
+
if (config?.maxRedirects === void 0) {
|
|
81
115
|
_config.maxRedirects = 99999;
|
|
82
116
|
}
|
|
83
|
-
if (_params.wait &&
|
|
117
|
+
if (_params.wait && config?.timeout === void 0) {
|
|
84
118
|
_config.timeout = 1e3 * 60 * 5;
|
|
85
119
|
}
|
|
86
120
|
return (await this.axiosInstance.get(`api/emails/${namespace}/inbox`, {
|
|
@@ -92,6 +126,15 @@ var MailiskClient = class {
|
|
|
92
126
|
const result = await this.axiosInstance.get(`api/smtp/${namespace}`);
|
|
93
127
|
return result.data;
|
|
94
128
|
}
|
|
129
|
+
async getAttachment(attachmentId) {
|
|
130
|
+
const result = await this.axiosInstance.get(`api/attachments/${attachmentId}`);
|
|
131
|
+
return result.data;
|
|
132
|
+
}
|
|
133
|
+
async downloadAttachment(attachmentId) {
|
|
134
|
+
const result = await this.getAttachment(attachmentId);
|
|
135
|
+
const response = await import_axios.default.get(result.data.download_url, { responseType: "arraybuffer" });
|
|
136
|
+
return Buffer.from(response.data);
|
|
137
|
+
}
|
|
95
138
|
};
|
|
96
139
|
__name(MailiskClient, "MailiskClient");
|
|
97
140
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/mailisk.ts"],"sourcesContent":["export * from \"./mailisk\";\n","import axios, { AxiosRequestConfig } from \"axios\";\nimport {\n ListNamespacesResponse,\n SearchInboxParams,\n SearchInboxResponse,\n SendVirtualEmailParams,\n SmtpSettings,\n} from \"./mailisk.interfaces\";\nimport nodemailer from \"nodemailer\";\n\nexport class MailiskClient {\n constructor({ apiKey, baseUrl }: { apiKey: string; baseUrl?: string }) {\n this.axiosInstance = axios.create({\n headers: {\n \"X-Api-Key\": apiKey,\n },\n baseURL: baseUrl || \"https://api.mailisk.com/\",\n });\n }\n\n private readonly axiosInstance;\n\n /**\n * List all namespaces that belong to the current account (API key).\n */\n async listNamespaces(): Promise<ListNamespacesResponse> {\n return (await this.axiosInstance.get(\"api/namespaces\")).data;\n }\n\n /**\n * Send an email using the Virtual SMTP.\n *\n * These emails can only be sent to valid Mailisk namespaces, i.e. emails that end in @mynamespace.mailisk.net\n *\n * @example\n * For example, sending a test email:\n * ```typescript\n * client.sendVirtualEmail(namespace, {\n * from: \"test@example.com\",\n * to: `john@${namespace}.mailisk.net`,\n * subject: \"This is a test\",\n * text: \"Testing\",\n * });\n * ```\n */\n async sendVirtualEmail(namespace: string, params: SendVirtualEmailParams): Promise<void> {\n const smtpSettings = await this.getSmtpSettings(namespace);\n\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/mailisk.ts"],"sourcesContent":["export * from \"./mailisk\";\n","import axios, { AxiosBasicCredentials, AxiosInstance, AxiosRequestConfig } from \"axios\";\nimport {\n GetAttachmentResponse,\n ListNamespacesResponse,\n ListSmsNumbersResponse,\n SearchInboxParams,\n SearchInboxResponse,\n SearchSmsMessagesParams,\n SearchSmsMessagesResponse,\n SendVirtualEmailParams,\n SendVirtualSmsParams,\n SmtpSettings,\n} from \"./mailisk.interfaces\";\nimport nodemailer from \"nodemailer\";\n\nexport class MailiskClient {\n constructor({ apiKey, baseUrl, auth }: { apiKey: string; baseUrl?: string; auth?: AxiosBasicCredentials }) {\n this.axiosInstance = axios.create({\n headers: {\n \"X-Api-Key\": apiKey,\n },\n baseURL: baseUrl || \"https://api.mailisk.com/\",\n auth,\n });\n }\n\n private readonly axiosInstance: AxiosInstance;\n\n /**\n * Search SMS messages sent to a phone number.\n *\n * @example\n * Search for SMS messages sent to a phone number\n * ```typescript\n * const { data: smsMessages } = await client.searchSmsMessages(\"1234567890\");\n * ```\n */\n async searchSmsMessages(\n phoneNumber: string,\n params?: SearchSmsMessagesParams,\n config?: AxiosRequestConfig\n ): Promise<SearchSmsMessagesResponse> {\n let _params: SearchSmsMessagesParams = { ...params };\n\n // default from timestamp, 15 minutes before starting this request\n if (params?.from_date === undefined || params?.from_date === null) {\n _params.from_date = new Date(Date.now() - 15 * 60 * 1000).toISOString();\n }\n\n // by default wait for sms\n if (params?.wait !== false) {\n _params.wait = true;\n }\n\n let _config = { ...config };\n\n if (config?.maxRedirects === undefined) {\n _config.maxRedirects = 99999;\n }\n\n // by default, wait 5 minutes for emails before timing out\n if (_params.wait && config?.timeout === undefined) {\n _config.timeout = 1000 * 60 * 5;\n }\n\n const requestParams = {\n ..._params,\n from_date: _params.from_date ?? undefined,\n to_date: _params.to_date ?? undefined,\n };\n\n return (\n await this.axiosInstance.get(`api/sms/${phoneNumber}/messages`, {\n ..._config,\n params: requestParams,\n })\n ).data;\n }\n\n /**\n * List all SMS phone numbers associated with the current account.\n *\n * @example\n * List all SMS phone numbers\n * ```typescript\n * const { data: smsNumbers } = await client.listSmsNumbers();\n * ```\n */\n async listSmsNumbers(): Promise<ListSmsNumbersResponse> {\n return (await this.axiosInstance.get(\"api/sms/numbers\")).data;\n }\n\n async sendVirtualSms(params: SendVirtualSmsParams): Promise<void> {\n return (await this.axiosInstance.post(\"api/sms/virtual\", params)).data;\n }\n\n /**\n * List all namespaces that belong to the current account (API key).\n */\n async listNamespaces(): Promise<ListNamespacesResponse> {\n return (await this.axiosInstance.get(\"api/namespaces\")).data;\n }\n\n /**\n * Send an email using the Virtual SMTP.\n *\n * These emails can only be sent to valid Mailisk namespaces, i.e. emails that end in @mynamespace.mailisk.net\n *\n * @example\n * For example, sending a test email:\n * ```typescript\n * client.sendVirtualEmail(namespace, {\n * from: \"test@example.com\",\n * to: `john@${namespace}.mailisk.net`,\n * subject: \"This is a test\",\n * text: \"Testing\",\n * });\n * ```\n */\n async sendVirtualEmail(namespace: string, params: SendVirtualEmailParams): Promise<void> {\n const smtpSettings = await this.getSmtpSettings(namespace);\n\n const transport = nodemailer.createTransport({\n host: smtpSettings.data.host,\n port: smtpSettings.data.port,\n secure: false,\n auth: {\n user: smtpSettings.data.username,\n pass: smtpSettings.data.password,\n },\n });\n\n const { from, to, subject, text, html, headers, attachments } = params;\n\n await transport.sendMail({\n from,\n to,\n subject,\n text,\n html,\n headers,\n attachments,\n });\n\n transport.close();\n }\n\n /**\n * Search inbox of a namespace.\n *\n * By default, this calls the api using the `wait` flag. This means the call won't timeout until at least one email is received or 5 minutes pass.\n * It also uses a default `from_timestamp` of **current timestamp - 15 minutes**. This means that older emails will be ignored.\n *\n * Both of these settings can be overriden by passing them in the `params` object.\n *\n * @example\n * Get the latest emails\n * ```typescript\n * const { data: emails } = await client.searchInbox(namespace);\n * ```\n *\n * @example\n * Get the latest emails for a specific email address\n * ```typescript\n * const { data: emails } = await client.searchInbox(namespace, {\n * to_addr_prefix: 'john@mynamespace.mailisk.net'\n * });\n * ```\n *\n * @example\n * Get the last 20 emails in the namespace\n * ```typescript\n * const { data: emails } = await mailisk.searchInbox(namespace, {\n * wait: false,\n * from_timestamp: 0,\n * limit: 20\n * });\n * ```\n */\n async searchInbox(\n namespace: string,\n params?: SearchInboxParams,\n config?: AxiosRequestConfig\n ): Promise<SearchInboxResponse> {\n let _params = { ...params };\n\n // default from timestamp, 15 minutes before starting this request\n if (params?.from_timestamp === undefined || params?.from_timestamp === null) {\n _params.from_timestamp = Math.floor(new Date().getTime() / 1000) - 15 * 60;\n }\n\n // by default wait for email\n if (params?.wait !== false) {\n _params.wait = true;\n }\n\n let _config = { ...config };\n\n if (config?.maxRedirects === undefined) {\n _config.maxRedirects = 99999;\n }\n\n // by default, wait 5 minutes for emails before timing out\n if (_params.wait && config?.timeout === undefined) {\n _config.timeout = 1000 * 60 * 5;\n }\n\n return (\n await this.axiosInstance.get(`api/emails/${namespace}/inbox`, {\n ..._config,\n params: _params,\n })\n ).data;\n }\n\n /**\n * Get the SMTP settings for a namespace.\n */\n async getSmtpSettings(namespace: string): Promise<SmtpSettings> {\n const result = await this.axiosInstance.get(`api/smtp/${namespace}`);\n return result.data;\n }\n\n async getAttachment(attachmentId: string): Promise<GetAttachmentResponse> {\n const result = await this.axiosInstance.get(`api/attachments/${attachmentId}`);\n return result.data;\n }\n\n /**\n * Download an attachment from an attachment ID.\n *\n * @example\n * Download an attachment from an email\n * ```typescript\n * const attachment = email.attachments[0];\n * const attachmentBuffer = await client.downloadAttachment(attachment.id);\n *\n * // save to file\n * fs.writeFileSync(attachment.filename, attachmentBuffer);\n * ```\n */\n async downloadAttachment(attachmentId: string): Promise<Buffer> {\n const result = await this.getAttachment(attachmentId);\n\n const response = await axios.get(result.data.download_url, { responseType: \"arraybuffer\" });\n return Buffer.from(response.data);\n }\n}\n"],"mappings":"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","names":["axios","nodemailer"]}
|