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.
Files changed (157) hide show
  1. package/.github/workflows/test.yml +31 -0
  2. package/README.md +122 -22
  3. package/dist/index.d.ts +169 -11
  4. package/dist/index.js +49 -6
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +49 -6
  7. package/dist/index.mjs.map +1 -1
  8. package/jest.config.js +13 -0
  9. package/package.json +11 -3
  10. package/private/dist/private/index.js +28 -0
  11. package/private/dist/private/index.js.map +1 -0
  12. package/private/dist/src/mailisk.interfaces.js +3 -0
  13. package/private/dist/src/mailisk.interfaces.js.map +1 -0
  14. package/private/dist/src/mailisk.js +168 -0
  15. package/private/dist/src/mailisk.js.map +1 -0
  16. package/private/index.ts +17 -0
  17. package/private/node_modules/.package-lock.json +44 -0
  18. package/private/node_modules/typescript/LICENSE.txt +55 -0
  19. package/private/node_modules/typescript/README.md +50 -0
  20. package/private/node_modules/typescript/SECURITY.md +41 -0
  21. package/private/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
  22. package/private/node_modules/typescript/bin/tsc +2 -0
  23. package/private/node_modules/typescript/bin/tsserver +2 -0
  24. package/private/node_modules/typescript/lib/_tsc.js +133818 -0
  25. package/private/node_modules/typescript/lib/_tsserver.js +659 -0
  26. package/private/node_modules/typescript/lib/_typingsInstaller.js +222 -0
  27. package/private/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
  28. package/private/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
  29. package/private/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
  30. package/private/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
  31. package/private/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
  32. package/private/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
  33. package/private/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
  34. package/private/node_modules/typescript/lib/lib.d.ts +22 -0
  35. package/private/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
  36. package/private/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
  37. package/private/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
  38. package/private/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
  39. package/private/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
  40. package/private/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
  41. package/private/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
  42. package/private/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
  43. package/private/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
  44. package/private/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
  45. package/private/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
  46. package/private/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
  47. package/private/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
  48. package/private/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
  49. package/private/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
  50. package/private/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
  51. package/private/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
  52. package/private/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
  53. package/private/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
  54. package/private/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
  55. package/private/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
  56. package/private/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
  57. package/private/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
  58. package/private/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
  59. package/private/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
  60. package/private/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
  61. package/private/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
  62. package/private/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
  63. package/private/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
  64. package/private/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
  65. package/private/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
  66. package/private/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
  67. package/private/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
  68. package/private/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
  69. package/private/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
  70. package/private/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
  71. package/private/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
  72. package/private/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
  73. package/private/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
  74. package/private/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
  75. package/private/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
  76. package/private/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
  77. package/private/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
  78. package/private/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
  79. package/private/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
  80. package/private/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
  81. package/private/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
  82. package/private/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
  83. package/private/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
  84. package/private/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
  85. package/private/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
  86. package/private/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
  87. package/private/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
  88. package/private/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
  89. package/private/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
  90. package/private/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
  91. package/private/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
  92. package/private/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
  93. package/private/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
  94. package/private/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
  95. package/private/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
  96. package/private/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
  97. package/private/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
  98. package/private/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
  99. package/private/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
  100. package/private/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
  101. package/private/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
  102. package/private/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
  103. package/private/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
  104. package/private/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
  105. package/private/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
  106. package/private/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
  107. package/private/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
  108. package/private/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
  109. package/private/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
  110. package/private/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
  111. package/private/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
  112. package/private/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
  113. package/private/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
  114. package/private/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
  115. package/private/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
  116. package/private/node_modules/typescript/lib/lib.es6.d.ts +23 -0
  117. package/private/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
  118. package/private/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
  119. package/private/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
  120. package/private/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
  121. package/private/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
  122. package/private/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
  123. package/private/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
  124. package/private/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
  125. package/private/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
  126. package/private/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
  127. package/private/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
  128. package/private/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
  129. package/private/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
  130. package/private/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
  131. package/private/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
  132. package/private/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
  133. package/private/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
  134. package/private/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
  135. package/private/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
  136. package/private/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
  137. package/private/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
  138. package/private/node_modules/typescript/lib/tsc.js +8 -0
  139. package/private/node_modules/typescript/lib/tsserver.js +8 -0
  140. package/private/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
  141. package/private/node_modules/typescript/lib/tsserverlibrary.js +21 -0
  142. package/private/node_modules/typescript/lib/typesMap.json +497 -0
  143. package/private/node_modules/typescript/lib/typescript.d.ts +11437 -0
  144. package/private/node_modules/typescript/lib/typescript.js +200276 -0
  145. package/private/node_modules/typescript/lib/typingsInstaller.js +8 -0
  146. package/private/node_modules/typescript/lib/watchGuard.js +53 -0
  147. package/private/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
  148. package/private/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
  149. package/private/node_modules/typescript/package.json +120 -0
  150. package/private/package-lock.json +53 -0
  151. package/private/package.json +17 -0
  152. package/private/tsconfig.json +103 -0
  153. package/src/mailisk.interfaces.ts +123 -6
  154. package/src/mailisk.ts +120 -11
  155. package/tests/mocks/axios-mocks.ts +108 -0
  156. package/tests/setup.ts +21 -0
  157. 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 and automate email tests.
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
- - Virtual SMTP support to test outbound email without 3rd party clients.
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 client.sendVirtualEmail(namespace, {
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 client.searchInbox(namespace);
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
- ### searchInbox(namespace, params?)
62
+ For the full parameter options see the [endpoint reference](https://docs.mailisk.com/api-reference/search-inbox.html#request-1).
58
63
 
59
- The `searchInbox` function takes a namespace and call parameters.
64
+ Default behaviour:
60
65
 
61
- - By default it uses the `wait` flag. This means the call won't return until at least one email is received. Disabling this flag via `wait: false` can cause it to return an empty response immediately.
62
- - The request timeout is adjustable by passing `timeout` in the request options. By default it uses a timeout of 5 minutes.
63
- - By default `from_timestamp` is set to **current timestamp - 5 seconds**. This ensures that only new emails are returned. Without this, older emails would also be returned, potentially disrupting you if you were waiting for a specific email. This can be overriden by passing the `from_timestamp` parameter (`from_timestmap: 0` will disable filtering by email age).
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
- // timeout of 5 minutes
73
+ // wait up to the default 5 min for *any* new mail
67
74
  await mailisk.searchInbox(namespace);
68
- // timeout of 1 minute
75
+ // custom 60-second timeout
69
76
  await mailisk.searchInbox(namespace, {}, { timeout: 1000 * 60 });
70
- // returns immediately, even if the result would be empty
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 use case is filtering the returned emails by the destination address, this is done using the `to_addr_prefix` parameter.
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: "john@mynamespace.mailisk.net",
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
- This does not call an API endpoint but rather uses nodemailer to send an email using SMTP.
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 namespacesResponse = await mailisk.listNamespaces();
114
+ const { data: namespaces } = await mailisk.listNamespaces();
109
115
 
110
116
  // will be ['namespace1', 'namespace2']
111
- const namespaces = namespacesResponse.map((nr) => nr.namespace);
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
- data: [
101
- {
102
- id: string;
103
- namespace: string;
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 - 5 seconds**. This means that older emails will be ignored.
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 in the namespace
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
- * to_addr_prefix: 'john@mynamespace.mailisk.net'
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 (!config?.maxRedirects) {
114
+ if (config?.maxRedirects === void 0) {
81
115
  _config.maxRedirects = 99999;
82
116
  }
83
- if (_params.wait && !config?.timeout) {
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 // TODO: to should match 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 } = params;\n\n await transport.sendMail({\n from,\n to,\n subject,\n text,\n html,\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 - 5 seconds**. 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 in the namespace\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 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) {\n _config.maxRedirects = 99999;\n }\n\n // by default, wait 5 minutes for emails before timing out\n if (_params.wait && !config?.timeout) {\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0C;AAQ1C,wBAAuB;AAEhB,IAAM,gBAAN,MAAoB;AAAA,EACzB,YAAY,EAAE,QAAQ,QAAQ,GAAyC;AACrE,SAAK,gBAAgB,aAAAA,QAAM,OAAO;AAAA,MAChC,SAAS;AAAA,QACP,aAAa;AAAA,MACf;AAAA,MACA,SAAS,WAAW;AAAA,IACtB,CAAC;AAAA,EACH;AAAA,EAEiB;AAAA,EAKjB,MAAM,iBAAkD;AACtD,YAAQ,MAAM,KAAK,cAAc,IAAI,gBAAgB,GAAG;AAAA,EAC1D;AAAA,EAkBA,MAAM,iBAAiB,WAAmB,QAA+C;AACvF,UAAM,eAAe,MAAM,KAAK,gBAAgB,SAAS;AAIzD,UAAM,YAAY,kBAAAC,QAAW,gBAAgB;AAAA,MAC3C,MAAM,aAAa,KAAK;AAAA,MACxB,MAAM,aAAa,KAAK;AAAA,MACxB,QAAQ;AAAA,MACR,MAAM;AAAA,QACJ,MAAM,aAAa,KAAK;AAAA,QACxB,MAAM,aAAa,KAAK;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,UAAM,EAAE,MAAM,IAAI,SAAS,MAAM,KAAK,IAAI;AAE1C,UAAM,UAAU,SAAS;AAAA,MACvB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,cAAU,MAAM;AAAA,EAClB;AAAA,EAwBA,MAAM,YACJ,WACA,QACA,QAC8B;AAC9B,QAAI,UAAU,EAAE,GAAG,OAAO;AAG1B,QAAI,QAAQ,mBAAmB,UAAa,QAAQ,mBAAmB,MAAM;AAC3E,cAAQ,iBAAiB,KAAK,MAAM,IAAI,KAAK,EAAE,QAAQ,IAAI,GAAI,IAAI,KAAK;AAAA,IAC1E;AAGA,QAAI,QAAQ,SAAS,OAAO;AAC1B,cAAQ,OAAO;AAAA,IACjB;AAEA,QAAI,UAAU,EAAE,GAAG,OAAO;AAE1B,QAAI,CAAC,QAAQ,cAAc;AACzB,cAAQ,eAAe;AAAA,IACzB;AAGA,QAAI,QAAQ,QAAQ,CAAC,QAAQ,SAAS;AACpC,cAAQ,UAAU,MAAO,KAAK;AAAA,IAChC;AAEA,YACE,MAAM,KAAK,cAAc,IAAI,cAAc,mBAAmB;AAAA,MAC5D,GAAG;AAAA,MACH,QAAQ;AAAA,IACV,CAAC,GACD;AAAA,EACJ;AAAA,EAKA,MAAM,gBAAgB,WAA0C;AAC9D,UAAM,SAAS,MAAM,KAAK,cAAc,IAAI,YAAY,WAAW;AACnE,WAAO,OAAO;AAAA,EAChB;AACF;AAhIa;","names":["axios","nodemailer"]}
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"]}