mailisk 2.2.1 → 2.2.3
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 +0 -1
- package/README.md +4 -0
- package/dist/index.d.mts +338 -0
- package/dist/index.js +96 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -6
- package/private/dist/private/index.js +0 -28
- package/private/dist/private/index.js.map +0 -1
- package/private/dist/src/mailisk.interfaces.js +0 -3
- package/private/dist/src/mailisk.interfaces.js.map +0 -1
- package/private/dist/src/mailisk.js +0 -168
- package/private/dist/src/mailisk.js.map +0 -1
- package/private/index.ts +0 -17
- package/private/node_modules/.package-lock.json +0 -44
- package/private/node_modules/typescript/LICENSE.txt +0 -55
- package/private/node_modules/typescript/README.md +0 -50
- package/private/node_modules/typescript/SECURITY.md +0 -41
- package/private/node_modules/typescript/ThirdPartyNoticeText.txt +0 -193
- package/private/node_modules/typescript/bin/tsc +0 -2
- package/private/node_modules/typescript/bin/tsserver +0 -2
- package/private/node_modules/typescript/lib/_tsc.js +0 -133818
- package/private/node_modules/typescript/lib/_tsserver.js +0 -659
- package/private/node_modules/typescript/lib/_typingsInstaller.js +0 -222
- package/private/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/de/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/es/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/it/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/lib.d.ts +0 -22
- package/private/node_modules/typescript/lib/lib.decorators.d.ts +0 -384
- package/private/node_modules/typescript/lib/lib.decorators.legacy.d.ts +0 -22
- package/private/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +0 -41
- package/private/node_modules/typescript/lib/lib.dom.d.ts +0 -39429
- package/private/node_modules/typescript/lib/lib.dom.iterable.d.ts +0 -571
- package/private/node_modules/typescript/lib/lib.es2015.collection.d.ts +0 -147
- package/private/node_modules/typescript/lib/lib.es2015.core.d.ts +0 -597
- package/private/node_modules/typescript/lib/lib.es2015.d.ts +0 -28
- package/private/node_modules/typescript/lib/lib.es2015.generator.d.ts +0 -77
- package/private/node_modules/typescript/lib/lib.es2015.iterable.d.ts +0 -605
- package/private/node_modules/typescript/lib/lib.es2015.promise.d.ts +0 -81
- package/private/node_modules/typescript/lib/lib.es2015.proxy.d.ts +0 -128
- package/private/node_modules/typescript/lib/lib.es2015.reflect.d.ts +0 -144
- package/private/node_modules/typescript/lib/lib.es2015.symbol.d.ts +0 -46
- package/private/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +0 -326
- package/private/node_modules/typescript/lib/lib.es2016.array.include.d.ts +0 -116
- package/private/node_modules/typescript/lib/lib.es2016.d.ts +0 -21
- package/private/node_modules/typescript/lib/lib.es2016.full.d.ts +0 -23
- package/private/node_modules/typescript/lib/lib.es2016.intl.d.ts +0 -31
- package/private/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +0 -21
- package/private/node_modules/typescript/lib/lib.es2017.d.ts +0 -26
- package/private/node_modules/typescript/lib/lib.es2017.date.d.ts +0 -31
- package/private/node_modules/typescript/lib/lib.es2017.full.d.ts +0 -23
- package/private/node_modules/typescript/lib/lib.es2017.intl.d.ts +0 -44
- package/private/node_modules/typescript/lib/lib.es2017.object.d.ts +0 -49
- package/private/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +0 -135
- package/private/node_modules/typescript/lib/lib.es2017.string.d.ts +0 -45
- package/private/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +0 -53
- package/private/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +0 -77
- package/private/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +0 -53
- package/private/node_modules/typescript/lib/lib.es2018.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2018.full.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2018.intl.d.ts +0 -83
- package/private/node_modules/typescript/lib/lib.es2018.promise.d.ts +0 -30
- package/private/node_modules/typescript/lib/lib.es2018.regexp.d.ts +0 -37
- package/private/node_modules/typescript/lib/lib.es2019.array.d.ts +0 -79
- package/private/node_modules/typescript/lib/lib.es2019.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2019.full.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2019.intl.d.ts +0 -23
- package/private/node_modules/typescript/lib/lib.es2019.object.d.ts +0 -33
- package/private/node_modules/typescript/lib/lib.es2019.string.d.ts +0 -37
- package/private/node_modules/typescript/lib/lib.es2019.symbol.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2020.bigint.d.ts +0 -765
- package/private/node_modules/typescript/lib/lib.es2020.d.ts +0 -27
- package/private/node_modules/typescript/lib/lib.es2020.date.d.ts +0 -42
- package/private/node_modules/typescript/lib/lib.es2020.full.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2020.intl.d.ts +0 -474
- package/private/node_modules/typescript/lib/lib.es2020.number.d.ts +0 -28
- package/private/node_modules/typescript/lib/lib.es2020.promise.d.ts +0 -47
- package/private/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +0 -99
- package/private/node_modules/typescript/lib/lib.es2020.string.d.ts +0 -44
- package/private/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +0 -41
- package/private/node_modules/typescript/lib/lib.es2021.d.ts +0 -23
- package/private/node_modules/typescript/lib/lib.es2021.full.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2021.intl.d.ts +0 -166
- package/private/node_modules/typescript/lib/lib.es2021.promise.d.ts +0 -48
- package/private/node_modules/typescript/lib/lib.es2021.string.d.ts +0 -33
- package/private/node_modules/typescript/lib/lib.es2021.weakref.d.ts +0 -78
- package/private/node_modules/typescript/lib/lib.es2022.array.d.ts +0 -121
- package/private/node_modules/typescript/lib/lib.es2022.d.ts +0 -25
- package/private/node_modules/typescript/lib/lib.es2022.error.d.ts +0 -75
- package/private/node_modules/typescript/lib/lib.es2022.full.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2022.intl.d.ts +0 -145
- package/private/node_modules/typescript/lib/lib.es2022.object.d.ts +0 -26
- package/private/node_modules/typescript/lib/lib.es2022.regexp.d.ts +0 -39
- package/private/node_modules/typescript/lib/lib.es2022.string.d.ts +0 -25
- package/private/node_modules/typescript/lib/lib.es2023.array.d.ts +0 -924
- package/private/node_modules/typescript/lib/lib.es2023.collection.d.ts +0 -21
- package/private/node_modules/typescript/lib/lib.es2023.d.ts +0 -22
- package/private/node_modules/typescript/lib/lib.es2023.full.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2023.intl.d.ts +0 -56
- package/private/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +0 -65
- package/private/node_modules/typescript/lib/lib.es2024.collection.d.ts +0 -29
- package/private/node_modules/typescript/lib/lib.es2024.d.ts +0 -26
- package/private/node_modules/typescript/lib/lib.es2024.full.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.es2024.object.d.ts +0 -29
- package/private/node_modules/typescript/lib/lib.es2024.promise.d.ts +0 -35
- package/private/node_modules/typescript/lib/lib.es2024.regexp.d.ts +0 -25
- package/private/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +0 -68
- package/private/node_modules/typescript/lib/lib.es2024.string.d.ts +0 -29
- package/private/node_modules/typescript/lib/lib.es5.d.ts +0 -4601
- package/private/node_modules/typescript/lib/lib.es6.d.ts +0 -23
- package/private/node_modules/typescript/lib/lib.esnext.array.d.ts +0 -35
- package/private/node_modules/typescript/lib/lib.esnext.collection.d.ts +0 -96
- package/private/node_modules/typescript/lib/lib.esnext.d.ts +0 -29
- package/private/node_modules/typescript/lib/lib.esnext.decorators.d.ts +0 -28
- package/private/node_modules/typescript/lib/lib.esnext.disposable.d.ts +0 -193
- package/private/node_modules/typescript/lib/lib.esnext.error.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.esnext.float16.d.ts +0 -445
- package/private/node_modules/typescript/lib/lib.esnext.full.d.ts +0 -24
- package/private/node_modules/typescript/lib/lib.esnext.intl.d.ts +0 -21
- package/private/node_modules/typescript/lib/lib.esnext.iterator.d.ts +0 -148
- package/private/node_modules/typescript/lib/lib.esnext.promise.d.ts +0 -34
- package/private/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +0 -25
- package/private/node_modules/typescript/lib/lib.scripthost.d.ts +0 -322
- package/private/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +0 -41
- package/private/node_modules/typescript/lib/lib.webworker.d.ts +0 -13150
- package/private/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +0 -23
- package/private/node_modules/typescript/lib/lib.webworker.iterable.d.ts +0 -340
- package/private/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/tsc.js +0 -8
- package/private/node_modules/typescript/lib/tsserver.js +0 -8
- package/private/node_modules/typescript/lib/tsserverlibrary.d.ts +0 -17
- package/private/node_modules/typescript/lib/tsserverlibrary.js +0 -21
- package/private/node_modules/typescript/lib/typesMap.json +0 -497
- package/private/node_modules/typescript/lib/typescript.d.ts +0 -11437
- package/private/node_modules/typescript/lib/typescript.js +0 -200276
- package/private/node_modules/typescript/lib/typingsInstaller.js +0 -8
- package/private/node_modules/typescript/lib/watchGuard.js +0 -53
- package/private/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -2122
- package/private/node_modules/typescript/package.json +0 -120
- package/private/package-lock.json +0 -53
- package/private/package.json +0 -17
- package/private/tsconfig.json +0 -103
package/README.md
CHANGED
|
@@ -11,6 +11,10 @@ Mailisk is an end-to-end email and SMS testing platform. It allows you to receiv
|
|
|
11
11
|
|
|
12
12
|
For a more step-by-step walkthrough see the [NodeJS Guide](https://docs.mailisk.com/guides/nodejs.html).
|
|
13
13
|
|
|
14
|
+
### Requirements
|
|
15
|
+
|
|
16
|
+
- Node.js 18 or newer
|
|
17
|
+
|
|
14
18
|
### Installation
|
|
15
19
|
|
|
16
20
|
#### Install with npm
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { AxiosBasicCredentials, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Attachment } from 'nodemailer/lib/mailer';
|
|
3
|
+
|
|
4
|
+
interface EmailAddress {
|
|
5
|
+
/** Email address */
|
|
6
|
+
address: string;
|
|
7
|
+
/** Display name, if one is specified */
|
|
8
|
+
name?: string;
|
|
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
|
+
}
|
|
20
|
+
interface Email {
|
|
21
|
+
/** Namespace scoped ID */
|
|
22
|
+
id: string;
|
|
23
|
+
/** Sender of email */
|
|
24
|
+
from: EmailAddress;
|
|
25
|
+
/** Recepients of email */
|
|
26
|
+
to: EmailAddress[];
|
|
27
|
+
/** Carbon-copied recipients for email message */
|
|
28
|
+
cc?: EmailAddress[];
|
|
29
|
+
/** Blind carbon-copied recipients for email message */
|
|
30
|
+
bcc?: EmailAddress[];
|
|
31
|
+
/** Subject of email */
|
|
32
|
+
subject?: string;
|
|
33
|
+
/** Email content that was sent in HTML format */
|
|
34
|
+
html?: string;
|
|
35
|
+
/** Email content that was sent in plain text format */
|
|
36
|
+
text?: string;
|
|
37
|
+
/** The datetime that this email was received */
|
|
38
|
+
received_date: Date;
|
|
39
|
+
/** The unix timestamp (s) that this email was received */
|
|
40
|
+
received_timestamp: number;
|
|
41
|
+
/** The unix timestamp (s) when this email will be deleted */
|
|
42
|
+
expires_timestamp: number;
|
|
43
|
+
/** The spam score as reported by SpamAssassin */
|
|
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;
|
|
83
|
+
}
|
|
84
|
+
interface SearchInboxParams {
|
|
85
|
+
/**
|
|
86
|
+
* The maximum number of emails that can be returned in this request, used alongside `offset` for pagination.
|
|
87
|
+
*/
|
|
88
|
+
limit?: number;
|
|
89
|
+
/**
|
|
90
|
+
* The number of emails to skip/ignore, used alongside `limit` for pagination.
|
|
91
|
+
*/
|
|
92
|
+
offset?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Filter emails by starting unix timestamp in seconds.
|
|
95
|
+
*/
|
|
96
|
+
from_timestamp?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Filter emails by ending unix timestamp in seconds.
|
|
99
|
+
*/
|
|
100
|
+
to_timestamp?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Filter emails by 'to' address. Address must start with this.
|
|
103
|
+
*
|
|
104
|
+
* 'foo' would return for 'foobar@namespace.mailisk.net' but not 'barfoo@namespace.mailisk.net'
|
|
105
|
+
*/
|
|
106
|
+
to_addr_prefix?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Filter emails by 'from' address. Address must include this.
|
|
109
|
+
*
|
|
110
|
+
* '@foo' would return for 'a@foo.com', 'b@foo.net'
|
|
111
|
+
*/
|
|
112
|
+
from_addr_includes?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Filter emails by subject. This is case insensitive. Subject must include this.
|
|
115
|
+
*
|
|
116
|
+
* 'password' would return for 'Password reset', 'Reset password notification' but not 'Reset'
|
|
117
|
+
*/
|
|
118
|
+
subject_includes?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Will keep the request going till at least one email would be returned.
|
|
121
|
+
*
|
|
122
|
+
* Default is `true`
|
|
123
|
+
*/
|
|
124
|
+
wait?: boolean;
|
|
125
|
+
}
|
|
126
|
+
interface SearchInboxResponse {
|
|
127
|
+
/**
|
|
128
|
+
* Total number of emails matching query.
|
|
129
|
+
*/
|
|
130
|
+
total_count: number;
|
|
131
|
+
/**
|
|
132
|
+
* Parameters that were used for the query
|
|
133
|
+
*/
|
|
134
|
+
options: SearchInboxParams;
|
|
135
|
+
/**
|
|
136
|
+
* Emails
|
|
137
|
+
*/
|
|
138
|
+
data: Email[];
|
|
139
|
+
}
|
|
140
|
+
interface SmtpSettings {
|
|
141
|
+
data: {
|
|
142
|
+
host: string;
|
|
143
|
+
port: number;
|
|
144
|
+
username: string;
|
|
145
|
+
password: string;
|
|
146
|
+
};
|
|
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
|
+
}
|
|
158
|
+
interface ListNamespacesResponse {
|
|
159
|
+
total_count: number;
|
|
160
|
+
data: {
|
|
161
|
+
id: string;
|
|
162
|
+
namespace: string;
|
|
163
|
+
}[];
|
|
164
|
+
}
|
|
165
|
+
interface SendVirtualEmailParams {
|
|
166
|
+
/** Sender of email */
|
|
167
|
+
from: string;
|
|
168
|
+
/**
|
|
169
|
+
* Recepients of email
|
|
170
|
+
*
|
|
171
|
+
* Must match namespace. E.g. if using namespace 'mynamespace' `to` must be 'something@mynamespace.mailisk.net'.
|
|
172
|
+
*/
|
|
173
|
+
to: string;
|
|
174
|
+
/** The subject of the e-mail */
|
|
175
|
+
subject: string;
|
|
176
|
+
/** The plaintext version of the message */
|
|
177
|
+
text?: string | undefined;
|
|
178
|
+
/** The HTML version of the message */
|
|
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;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
declare class MailiskClient {
|
|
236
|
+
constructor({ apiKey, baseUrl, auth }: {
|
|
237
|
+
apiKey: string;
|
|
238
|
+
baseUrl?: string;
|
|
239
|
+
auth?: AxiosBasicCredentials;
|
|
240
|
+
});
|
|
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>;
|
|
263
|
+
/**
|
|
264
|
+
* List all namespaces that belong to the current account (API key).
|
|
265
|
+
*/
|
|
266
|
+
listNamespaces(): Promise<ListNamespacesResponse>;
|
|
267
|
+
/**
|
|
268
|
+
* Send an email using the Virtual SMTP.
|
|
269
|
+
*
|
|
270
|
+
* These emails can only be sent to valid Mailisk namespaces, i.e. emails that end in @mynamespace.mailisk.net
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* For example, sending a test email:
|
|
274
|
+
* ```typescript
|
|
275
|
+
* client.sendVirtualEmail(namespace, {
|
|
276
|
+
* from: "test@example.com",
|
|
277
|
+
* to: `john@${namespace}.mailisk.net`,
|
|
278
|
+
* subject: "This is a test",
|
|
279
|
+
* text: "Testing",
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
sendVirtualEmail(namespace: string, params: SendVirtualEmailParams): Promise<void>;
|
|
284
|
+
/**
|
|
285
|
+
* Search inbox of a namespace.
|
|
286
|
+
*
|
|
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.
|
|
288
|
+
* It also uses a default `from_timestamp` of **current timestamp - 15 minutes**. This means that older emails will be ignored.
|
|
289
|
+
*
|
|
290
|
+
* Both of these settings can be overriden by passing them in the `params` object.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* Get the latest emails
|
|
294
|
+
* ```typescript
|
|
295
|
+
* const { data: emails } = await client.searchInbox(namespace);
|
|
296
|
+
* ```
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* Get the latest emails for a specific email address
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const { data: emails } = await client.searchInbox(namespace, {
|
|
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
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
searchInbox(namespace: string, params?: SearchInboxParams, config?: AxiosRequestConfig): Promise<SearchInboxResponse>;
|
|
317
|
+
/**
|
|
318
|
+
* Get the SMTP settings for a namespace.
|
|
319
|
+
*/
|
|
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>;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export { MailiskClient };
|
package/dist/index.js
CHANGED
|
@@ -19,22 +19,29 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
return to;
|
|
20
20
|
};
|
|
21
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
26
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
27
|
mod
|
|
24
28
|
));
|
|
25
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
30
|
|
|
27
31
|
// src/index.ts
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
30
34
|
MailiskClient: () => MailiskClient
|
|
31
35
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
37
|
|
|
34
38
|
// src/mailisk.ts
|
|
35
39
|
var import_axios = __toESM(require("axios"));
|
|
36
40
|
var import_nodemailer = __toESM(require("nodemailer"));
|
|
37
41
|
var MailiskClient = class {
|
|
42
|
+
static {
|
|
43
|
+
__name(this, "MailiskClient");
|
|
44
|
+
}
|
|
38
45
|
constructor({ apiKey, baseUrl, auth }) {
|
|
39
46
|
this.axiosInstance = import_axios.default.create({
|
|
40
47
|
headers: {
|
|
@@ -45,6 +52,15 @@ var MailiskClient = class {
|
|
|
45
52
|
});
|
|
46
53
|
}
|
|
47
54
|
axiosInstance;
|
|
55
|
+
/**
|
|
56
|
+
* Search SMS messages sent to a phone number.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* Search for SMS messages sent to a phone number
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const { data: smsMessages } = await client.searchSmsMessages("1234567890");
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
48
64
|
async searchSmsMessages(phoneNumber, params, config) {
|
|
49
65
|
let _params = { ...params };
|
|
50
66
|
if (params?.from_date === void 0 || params?.from_date === null) {
|
|
@@ -70,15 +86,43 @@ var MailiskClient = class {
|
|
|
70
86
|
params: requestParams
|
|
71
87
|
})).data;
|
|
72
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* List all SMS phone numbers associated with the current account.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* List all SMS phone numbers
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const { data: smsNumbers } = await client.listSmsNumbers();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
73
98
|
async listSmsNumbers() {
|
|
74
99
|
return (await this.axiosInstance.get("api/sms/numbers")).data;
|
|
75
100
|
}
|
|
76
101
|
async sendVirtualSms(params) {
|
|
77
102
|
return (await this.axiosInstance.post("api/sms/virtual", params)).data;
|
|
78
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* List all namespaces that belong to the current account (API key).
|
|
106
|
+
*/
|
|
79
107
|
async listNamespaces() {
|
|
80
108
|
return (await this.axiosInstance.get("api/namespaces")).data;
|
|
81
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Send an email using the Virtual SMTP.
|
|
112
|
+
*
|
|
113
|
+
* These emails can only be sent to valid Mailisk namespaces, i.e. emails that end in @mynamespace.mailisk.net
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* For example, sending a test email:
|
|
117
|
+
* ```typescript
|
|
118
|
+
* client.sendVirtualEmail(namespace, {
|
|
119
|
+
* from: "test@example.com",
|
|
120
|
+
* to: `john@${namespace}.mailisk.net`,
|
|
121
|
+
* subject: "This is a test",
|
|
122
|
+
* text: "Testing",
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
82
126
|
async sendVirtualEmail(namespace, params) {
|
|
83
127
|
const smtpSettings = await this.getSmtpSettings(namespace);
|
|
84
128
|
const transport = import_nodemailer.default.createTransport({
|
|
@@ -102,10 +146,42 @@ var MailiskClient = class {
|
|
|
102
146
|
});
|
|
103
147
|
transport.close();
|
|
104
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Search inbox of a namespace.
|
|
151
|
+
*
|
|
152
|
+
* 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.
|
|
153
|
+
* It also uses a default `from_timestamp` of **current timestamp - 15 minutes**. This means that older emails will be ignored.
|
|
154
|
+
*
|
|
155
|
+
* Both of these settings can be overriden by passing them in the `params` object.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* Get the latest emails
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const { data: emails } = await client.searchInbox(namespace);
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* Get the latest emails for a specific email address
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const { data: emails } = await client.searchInbox(namespace, {
|
|
167
|
+
* to_addr_prefix: 'john@mynamespace.mailisk.net'
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* Get the last 20 emails in the namespace
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const { data: emails } = await mailisk.searchInbox(namespace, {
|
|
175
|
+
* wait: false,
|
|
176
|
+
* from_timestamp: 0,
|
|
177
|
+
* limit: 20
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
105
181
|
async searchInbox(namespace, params, config) {
|
|
106
182
|
let _params = { ...params };
|
|
107
183
|
if (params?.from_timestamp === void 0 || params?.from_timestamp === null) {
|
|
108
|
-
_params.from_timestamp = Math.floor(new Date().getTime() / 1e3) - 15 * 60;
|
|
184
|
+
_params.from_timestamp = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - 15 * 60;
|
|
109
185
|
}
|
|
110
186
|
if (params?.wait !== false) {
|
|
111
187
|
_params.wait = true;
|
|
@@ -122,6 +198,9 @@ var MailiskClient = class {
|
|
|
122
198
|
params: _params
|
|
123
199
|
})).data;
|
|
124
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Get the SMTP settings for a namespace.
|
|
203
|
+
*/
|
|
125
204
|
async getSmtpSettings(namespace) {
|
|
126
205
|
const result = await this.axiosInstance.get(`api/smtp/${namespace}`);
|
|
127
206
|
return result.data;
|
|
@@ -130,13 +209,25 @@ var MailiskClient = class {
|
|
|
130
209
|
const result = await this.axiosInstance.get(`api/attachments/${attachmentId}`);
|
|
131
210
|
return result.data;
|
|
132
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Download an attachment from an attachment ID.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* Download an attachment from an email
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const attachment = email.attachments[0];
|
|
219
|
+
* const attachmentBuffer = await client.downloadAttachment(attachment.id);
|
|
220
|
+
*
|
|
221
|
+
* // save to file
|
|
222
|
+
* fs.writeFileSync(attachment.filename, attachmentBuffer);
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
133
225
|
async downloadAttachment(attachmentId) {
|
|
134
226
|
const result = await this.getAttachment(attachmentId);
|
|
135
227
|
const response = await import_axios.default.get(result.data.download_url, { responseType: "arraybuffer" });
|
|
136
228
|
return Buffer.from(response.data);
|
|
137
229
|
}
|
|
138
230
|
};
|
|
139
|
-
__name(MailiskClient, "MailiskClient");
|
|
140
231
|
// Annotate the CommonJS export names for ESM import in node:
|
|
141
232
|
0 && (module.exports = {
|
|
142
233
|
MailiskClient
|
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, { 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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B,WAA0C;AAC9D,UAAM,SAAS,MAAM,KAAK,cAAc,IAAI,YAAY,WAAW;AACnE,WAAO,OAAO;AAAA,EAChB;AAAA,EAEA,MAAM,cAAc,cAAsD;AACxE,UAAM,SAAS,MAAM,KAAK,cAAc,IAAI,mBAAmB,cAAc;AAC7E,WAAO,OAAO;AAAA,EAChB;AAAA,EAeA,MAAM,mBAAmB,cAAuC;AAC9D,UAAM,SAAS,MAAM,KAAK,cAAc,YAAY;AAEpD,UAAM,WAAW,MAAM,aAAAD,QAAM,IAAI,OAAO,KAAK,cAAc,EAAE,cAAc,cAAc,CAAC;AAC1F,WAAO,OAAO,KAAK,SAAS,IAAI;AAAA,EAClC;AACF;AAxOa;","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAgF;AAahF,wBAAuB;AAEhB,IAAM,gBAAN,MAAoB;AAAA,EAf3B,OAe2B;AAAA;AAAA;AAAA,EACzB,YAAY,EAAE,QAAQ,SAAS,KAAK,GAAuE;AACzG,SAAK,gBAAgB,aAAAA,QAAM,OAAO;AAAA,MAChC,SAAS;AAAA,QACP,aAAa;AAAA,MACf;AAAA,MACA,SAAS,WAAW;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWjB,MAAM,kBACJ,aACA,QACA,QACoC;AACpC,QAAI,UAAmC,EAAE,GAAG,OAAO;AAGnD,QAAI,QAAQ,cAAc,UAAa,QAAQ,cAAc,MAAM;AACjE,cAAQ,YAAY,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,GAAI,EAAE,YAAY;AAAA,IACxE;AAGA,QAAI,QAAQ,SAAS,OAAO;AAC1B,cAAQ,OAAO;AAAA,IACjB;AAEA,QAAI,UAAU,EAAE,GAAG,OAAO;AAE1B,QAAI,QAAQ,iBAAiB,QAAW;AACtC,cAAQ,eAAe;AAAA,IACzB;AAGA,QAAI,QAAQ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