mailisk 2.2.4 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/dist/index.d.mts +536 -0
- package/dist/index.d.ts +199 -1
- package/dist/index.js +219 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +212 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/mailisk.interfaces.ts +109 -0
- package/src/mailisk.ts +144 -2
- package/tests/mocks/axios-mocks.ts +31 -0
- package/tests/unit/mailisk.test.ts +153 -0
package/dist/index.d.ts
CHANGED
|
@@ -231,6 +231,104 @@ interface SendVirtualSmsParams {
|
|
|
231
231
|
/** The body of the SMS message */
|
|
232
232
|
body: string;
|
|
233
233
|
}
|
|
234
|
+
type TotpAlgorithm = "SHA1" | "SHA256" | "SHA512";
|
|
235
|
+
type KnownTotpDeviceSource = "shared_secret" | "custom" | "base32_secret_key" | "otpauth_url";
|
|
236
|
+
type TotpDeviceSource = KnownTotpDeviceSource | (string & {});
|
|
237
|
+
interface TotpDevice {
|
|
238
|
+
id: string;
|
|
239
|
+
organisation_id: string;
|
|
240
|
+
name: string;
|
|
241
|
+
username?: string | null;
|
|
242
|
+
issuer?: string | null;
|
|
243
|
+
digits: number;
|
|
244
|
+
period: number;
|
|
245
|
+
algorithm: TotpAlgorithm;
|
|
246
|
+
source: TotpDeviceSource;
|
|
247
|
+
expiresAt?: string | null;
|
|
248
|
+
created_at: string;
|
|
249
|
+
updated_at: string;
|
|
250
|
+
}
|
|
251
|
+
interface ListTotpDevicesParams {
|
|
252
|
+
/** The maximum number of saved TOTP devices returned (1-100), used alongside `offset` for pagination. */
|
|
253
|
+
limit?: number;
|
|
254
|
+
/** The number of saved TOTP devices to skip/ignore, used alongside `limit` for pagination. Must be >= 0. */
|
|
255
|
+
offset?: number;
|
|
256
|
+
/** Case-insensitive partial username match. Trimmed before sending. */
|
|
257
|
+
username?: string;
|
|
258
|
+
/** Case-insensitive partial issuer match. Trimmed before sending. */
|
|
259
|
+
issuer?: string;
|
|
260
|
+
}
|
|
261
|
+
interface ListTotpDevicesResponse {
|
|
262
|
+
total_count: number;
|
|
263
|
+
options: ListTotpDevicesParams;
|
|
264
|
+
items: TotpDevice[];
|
|
265
|
+
}
|
|
266
|
+
interface CreateTotpDeviceParams {
|
|
267
|
+
/** Base32 shared secret. Uses default TOTP settings. */
|
|
268
|
+
sharedSecret: string;
|
|
269
|
+
/** Optional saved-device display name. Max 120 characters. */
|
|
270
|
+
name?: string;
|
|
271
|
+
/** Future ISO timestamp after which the saved device expires. */
|
|
272
|
+
expiresAt?: string;
|
|
273
|
+
}
|
|
274
|
+
interface CreateCustomTotpDeviceParams {
|
|
275
|
+
/** Base32 shared secret. */
|
|
276
|
+
secret: string;
|
|
277
|
+
/** Optional saved-device display name. Max 120 characters. */
|
|
278
|
+
name?: string;
|
|
279
|
+
/** Account label. Max 240 characters. */
|
|
280
|
+
username?: string;
|
|
281
|
+
/** Issuer/app label. Max 240 characters. */
|
|
282
|
+
issuer?: string;
|
|
283
|
+
/** Number of OTP digits. */
|
|
284
|
+
digits?: 6 | 8;
|
|
285
|
+
/** OTP period in seconds. Must be an integer from 10 to 300. */
|
|
286
|
+
period?: number;
|
|
287
|
+
/** Hashing algorithm. */
|
|
288
|
+
algorithm?: TotpAlgorithm;
|
|
289
|
+
/** Future ISO timestamp after which the saved device expires. */
|
|
290
|
+
expiresAt?: string;
|
|
291
|
+
}
|
|
292
|
+
interface CreateBase32SecretKeyTotpDeviceParams {
|
|
293
|
+
/** Base32 shared secret key. */
|
|
294
|
+
base32SecretKey: string;
|
|
295
|
+
/** Optional saved-device display name. Max 120 characters. */
|
|
296
|
+
name?: string;
|
|
297
|
+
/** Account label. Max 240 characters. */
|
|
298
|
+
username?: string;
|
|
299
|
+
/** Issuer/app label. Max 240 characters. */
|
|
300
|
+
issuer?: string;
|
|
301
|
+
/** Number of OTP digits. */
|
|
302
|
+
digits?: 6 | 8;
|
|
303
|
+
/** OTP period in seconds. Must be an integer from 10 to 300. */
|
|
304
|
+
period?: number;
|
|
305
|
+
/** Hashing algorithm. */
|
|
306
|
+
algorithm?: TotpAlgorithm;
|
|
307
|
+
/** Future ISO timestamp after which the saved device expires. */
|
|
308
|
+
expiresAt?: string;
|
|
309
|
+
}
|
|
310
|
+
interface CreateOtpAuthUrlTotpDeviceParams {
|
|
311
|
+
/** otpauth://totp URL with a secret query parameter. */
|
|
312
|
+
otpAuthUrl: string;
|
|
313
|
+
/** Optional saved-device display name. Max 120 characters. */
|
|
314
|
+
name?: string;
|
|
315
|
+
/** Account label, used when missing from the URL label. Max 240 characters. */
|
|
316
|
+
username?: string;
|
|
317
|
+
/** Issuer/app label, used when missing from the URL. Max 240 characters. */
|
|
318
|
+
issuer?: string;
|
|
319
|
+
/** Number of OTP digits, used when missing from the URL. */
|
|
320
|
+
digits?: 6 | 8;
|
|
321
|
+
/** OTP period in seconds, used when missing from the URL. Must be an integer from 10 to 300. */
|
|
322
|
+
period?: number;
|
|
323
|
+
/** Hashing algorithm, used when missing from the URL. */
|
|
324
|
+
algorithm?: TotpAlgorithm;
|
|
325
|
+
/** Future ISO timestamp after which the saved device expires. */
|
|
326
|
+
expiresAt?: string;
|
|
327
|
+
}
|
|
328
|
+
interface TotpOtpResponse {
|
|
329
|
+
code: string;
|
|
330
|
+
expires: string;
|
|
331
|
+
}
|
|
234
332
|
|
|
235
333
|
declare class MailiskClient {
|
|
236
334
|
constructor({ apiKey, baseUrl, auth }: {
|
|
@@ -260,6 +358,106 @@ declare class MailiskClient {
|
|
|
260
358
|
*/
|
|
261
359
|
listSmsNumbers(): Promise<ListSmsNumbersResponse>;
|
|
262
360
|
sendVirtualSms(params: SendVirtualSmsParams): Promise<void>;
|
|
361
|
+
/**
|
|
362
|
+
* List saved TOTP devices.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* List saved TOTP devices for an issuer and username
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const { items: devices } = await client.listTotpDevices({
|
|
368
|
+
* issuer: "GitHub",
|
|
369
|
+
* username: "qa@example.com",
|
|
370
|
+
* });
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
listTotpDevices(params?: ListTotpDevicesParams): Promise<ListTotpDevicesResponse>;
|
|
374
|
+
/**
|
|
375
|
+
* Create a saved TOTP device from a Base32 shared secret using default TOTP settings.
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* Create a saved TOTP device from a shared secret
|
|
379
|
+
* ```typescript
|
|
380
|
+
* const device = await client.createTotpDevice({
|
|
381
|
+
* name: "GitHub staging",
|
|
382
|
+
* sharedSecret: "JBSWY3DPEHPK3PXP",
|
|
383
|
+
* });
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
createTotpDevice(params: CreateTotpDeviceParams): Promise<TotpDevice>;
|
|
387
|
+
/**
|
|
388
|
+
* Create a saved TOTP device with custom settings.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* Create a saved TOTP device with custom settings
|
|
392
|
+
* ```typescript
|
|
393
|
+
* const device = await client.createCustomTotpDevice({
|
|
394
|
+
* name: "GitHub staging",
|
|
395
|
+
* secret: "JBSWY3DPEHPK3PXP",
|
|
396
|
+
* username: "qa@example.com",
|
|
397
|
+
* issuer: "GitHub",
|
|
398
|
+
* digits: 6,
|
|
399
|
+
* period: 30,
|
|
400
|
+
* algorithm: "SHA1",
|
|
401
|
+
* });
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
createCustomTotpDevice(params: CreateCustomTotpDeviceParams): Promise<TotpDevice>;
|
|
405
|
+
/**
|
|
406
|
+
* Create a saved TOTP device from a Base32 secret key.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* Create a saved TOTP device from a Base32 secret key
|
|
410
|
+
* ```typescript
|
|
411
|
+
* const device = await client.createTotpDeviceFromBase32SecretKey({
|
|
412
|
+
* base32SecretKey: "JBSWY3DPEHPK3PXP",
|
|
413
|
+
* username: "qa@example.com",
|
|
414
|
+
* issuer: "GitHub",
|
|
415
|
+
* });
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
createTotpDeviceFromBase32SecretKey(params: CreateBase32SecretKeyTotpDeviceParams): Promise<TotpDevice>;
|
|
419
|
+
/**
|
|
420
|
+
* Create a saved TOTP device from an otpauth://totp URL.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* Create a saved TOTP device from an otpauth URL
|
|
424
|
+
* ```typescript
|
|
425
|
+
* const device = await client.createTotpDeviceFromOtpAuthUrl({
|
|
426
|
+
* otpAuthUrl: "otpauth://totp/GitHub:qa@example.com?secret=JBSWY3DPEHPK3PXP&issuer=GitHub",
|
|
427
|
+
* });
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
createTotpDeviceFromOtpAuthUrl(params: CreateOtpAuthUrlTotpDeviceParams): Promise<TotpDevice>;
|
|
431
|
+
/**
|
|
432
|
+
* Generate a TOTP code from a shared secret without saving a device.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* Generate a TOTP code from a shared secret
|
|
436
|
+
* ```typescript
|
|
437
|
+
* const { code } = await client.getTotpOtpBySharedSecret("JBSWY3DPEHPK3PXP");
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
getTotpOtpBySharedSecret(sharedSecret: string): Promise<TotpOtpResponse>;
|
|
441
|
+
/**
|
|
442
|
+
* Generate a TOTP code for a saved device.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* Generate a TOTP code for a saved device
|
|
446
|
+
* ```typescript
|
|
447
|
+
* const { code } = await client.getTotpOtpByDeviceId(device.id);
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
450
|
+
getTotpOtpByDeviceId(deviceId: string): Promise<TotpOtpResponse>;
|
|
451
|
+
/**
|
|
452
|
+
* Delete a saved TOTP device.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* Delete a saved TOTP device
|
|
456
|
+
* ```typescript
|
|
457
|
+
* await client.deleteTotpDevice(device.id);
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
deleteTotpDevice(deviceId: string): Promise<void>;
|
|
263
461
|
/**
|
|
264
462
|
* List all namespaces that belong to the current account (API key).
|
|
265
463
|
*/
|
|
@@ -335,4 +533,4 @@ declare class MailiskClient {
|
|
|
335
533
|
downloadAttachment(attachmentId: string): Promise<Buffer>;
|
|
336
534
|
}
|
|
337
535
|
|
|
338
|
-
export { MailiskClient };
|
|
536
|
+
export { type CreateBase32SecretKeyTotpDeviceParams, type CreateCustomTotpDeviceParams, type CreateOtpAuthUrlTotpDeviceParams, type CreateTotpDeviceParams, type Email, type EmailAddress, type EmailAttachment, type GetAttachmentResponse, type KnownTotpDeviceSource, type ListNamespacesResponse, type ListSmsNumbersResponse, type ListTotpDevicesParams, type ListTotpDevicesResponse, MailiskClient, type SearchInboxParams, type SearchInboxResponse, type SearchSmsMessagesParams, type SearchSmsMessagesResponse, type SendVirtualEmailParams, type SendVirtualSmsParams, type SmsMessage, type SmsNumber, type SmtpSettings, type TotpAlgorithm, type TotpDevice, type TotpDeviceSource, type TotpOtpResponse };
|
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,166 @@ 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 saved TOTP devices.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* List saved TOTP devices for an issuer and username
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const { items: devices } = await client.listTotpDevices({
|
|
111
|
+
* issuer: "GitHub",
|
|
112
|
+
* username: "qa@example.com",
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
async listTotpDevices(params) {
|
|
117
|
+
const requestParams = {
|
|
118
|
+
...params,
|
|
119
|
+
username: params?.username?.trim(),
|
|
120
|
+
issuer: params?.issuer?.trim()
|
|
121
|
+
};
|
|
122
|
+
return (await this.axiosInstance.get("api/devices", {
|
|
123
|
+
params: requestParams
|
|
124
|
+
})).data;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a saved TOTP device from a Base32 shared secret using default TOTP settings.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* Create a saved TOTP device from a shared secret
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const device = await client.createTotpDevice({
|
|
133
|
+
* name: "GitHub staging",
|
|
134
|
+
* sharedSecret: "JBSWY3DPEHPK3PXP",
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async createTotpDevice(params) {
|
|
139
|
+
return (await this.axiosInstance.post("api/devices", params)).data;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Create a saved TOTP device with custom settings.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* Create a saved TOTP device with custom settings
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const device = await client.createCustomTotpDevice({
|
|
148
|
+
* name: "GitHub staging",
|
|
149
|
+
* secret: "JBSWY3DPEHPK3PXP",
|
|
150
|
+
* username: "qa@example.com",
|
|
151
|
+
* issuer: "GitHub",
|
|
152
|
+
* digits: 6,
|
|
153
|
+
* period: 30,
|
|
154
|
+
* algorithm: "SHA1",
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
async createCustomTotpDevice(params) {
|
|
159
|
+
return (await this.axiosInstance.post("api/devices/custom", params)).data;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Create a saved TOTP device from a Base32 secret key.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* Create a saved TOTP device from a Base32 secret key
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const device = await client.createTotpDeviceFromBase32SecretKey({
|
|
168
|
+
* base32SecretKey: "JBSWY3DPEHPK3PXP",
|
|
169
|
+
* username: "qa@example.com",
|
|
170
|
+
* issuer: "GitHub",
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
async createTotpDeviceFromBase32SecretKey(params) {
|
|
175
|
+
return (await this.axiosInstance.post("api/devices/base32-secret-key", params)).data;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Create a saved TOTP device from an otpauth://totp URL.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* Create a saved TOTP device from an otpauth URL
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const device = await client.createTotpDeviceFromOtpAuthUrl({
|
|
184
|
+
* otpAuthUrl: "otpauth://totp/GitHub:qa@example.com?secret=JBSWY3DPEHPK3PXP&issuer=GitHub",
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
async createTotpDeviceFromOtpAuthUrl(params) {
|
|
189
|
+
return (await this.axiosInstance.post("api/devices/otpauth-url", params)).data;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Generate a TOTP code from a shared secret without saving a device.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* Generate a TOTP code from a shared secret
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const { code } = await client.getTotpOtpBySharedSecret("JBSWY3DPEHPK3PXP");
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
async getTotpOtpBySharedSecret(sharedSecret) {
|
|
201
|
+
return (await this.axiosInstance.post("api/devices/otp", { sharedSecret })).data;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Generate a TOTP code for a saved device.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* Generate a TOTP code for a saved device
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const { code } = await client.getTotpOtpByDeviceId(device.id);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
async getTotpOtpByDeviceId(deviceId) {
|
|
213
|
+
return (await this.axiosInstance.get(`api/devices/${deviceId}/otp`)).data;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Delete a saved TOTP device.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* Delete a saved TOTP device
|
|
220
|
+
* ```typescript
|
|
221
|
+
* await client.deleteTotpDevice(device.id);
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
async deleteTotpDevice(deviceId) {
|
|
225
|
+
await this.axiosInstance.delete(`api/devices/${deviceId}`);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* List all namespaces that belong to the current account (API key).
|
|
229
|
+
*/
|
|
79
230
|
async listNamespaces() {
|
|
80
231
|
return (await this.axiosInstance.get("api/namespaces")).data;
|
|
81
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Send an email using the Virtual SMTP.
|
|
235
|
+
*
|
|
236
|
+
* These emails can only be sent to valid Mailisk namespaces, i.e. emails that end in @mynamespace.mailisk.net
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* For example, sending a test email:
|
|
240
|
+
* ```typescript
|
|
241
|
+
* client.sendVirtualEmail(namespace, {
|
|
242
|
+
* from: "test@example.com",
|
|
243
|
+
* to: `john@${namespace}.mailisk.net`,
|
|
244
|
+
* subject: "This is a test",
|
|
245
|
+
* text: "Testing",
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
82
249
|
async sendVirtualEmail(namespace, params) {
|
|
83
250
|
const smtpSettings = await this.getSmtpSettings(namespace);
|
|
84
251
|
const transport = import_nodemailer.default.createTransport({
|
|
@@ -102,10 +269,42 @@ var MailiskClient = class {
|
|
|
102
269
|
});
|
|
103
270
|
transport.close();
|
|
104
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Search inbox of a namespace.
|
|
274
|
+
*
|
|
275
|
+
* 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.
|
|
276
|
+
* It also uses a default `from_timestamp` of **current timestamp - 15 minutes**. This means that older emails will be ignored.
|
|
277
|
+
*
|
|
278
|
+
* Both of these settings can be overriden by passing them in the `params` object.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* Get the latest emails
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const { data: emails } = await client.searchInbox(namespace);
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* Get the latest emails for a specific email address
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const { data: emails } = await client.searchInbox(namespace, {
|
|
290
|
+
* to_addr_prefix: 'john@mynamespace.mailisk.net'
|
|
291
|
+
* });
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* Get the last 20 emails in the namespace
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const { data: emails } = await mailisk.searchInbox(namespace, {
|
|
298
|
+
* wait: false,
|
|
299
|
+
* from_timestamp: 0,
|
|
300
|
+
* limit: 20
|
|
301
|
+
* });
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
105
304
|
async searchInbox(namespace, params, config) {
|
|
106
305
|
let _params = { ...params };
|
|
107
306
|
if (params?.from_timestamp === void 0 || params?.from_timestamp === null) {
|
|
108
|
-
_params.from_timestamp = Math.floor(new Date().getTime() / 1e3) - 15 * 60;
|
|
307
|
+
_params.from_timestamp = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - 15 * 60;
|
|
109
308
|
}
|
|
110
309
|
if (params?.wait !== false) {
|
|
111
310
|
_params.wait = true;
|
|
@@ -122,6 +321,9 @@ var MailiskClient = class {
|
|
|
122
321
|
params: _params
|
|
123
322
|
})).data;
|
|
124
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* Get the SMTP settings for a namespace.
|
|
326
|
+
*/
|
|
125
327
|
async getSmtpSettings(namespace) {
|
|
126
328
|
const result = await this.axiosInstance.get(`api/smtp/${namespace}`);
|
|
127
329
|
return result.data;
|
|
@@ -130,13 +332,25 @@ var MailiskClient = class {
|
|
|
130
332
|
const result = await this.axiosInstance.get(`api/attachments/${attachmentId}`);
|
|
131
333
|
return result.data;
|
|
132
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Download an attachment from an attachment ID.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* Download an attachment from an email
|
|
340
|
+
* ```typescript
|
|
341
|
+
* const attachment = email.attachments[0];
|
|
342
|
+
* const attachmentBuffer = await client.downloadAttachment(attachment.id);
|
|
343
|
+
*
|
|
344
|
+
* // save to file
|
|
345
|
+
* fs.writeFileSync(attachment.filename, attachmentBuffer);
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
133
348
|
async downloadAttachment(attachmentId) {
|
|
134
349
|
const result = await this.getAttachment(attachmentId);
|
|
135
350
|
const response = await import_axios.default.get(result.data.download_url, { responseType: "arraybuffer" });
|
|
136
351
|
return Buffer.from(response.data);
|
|
137
352
|
}
|
|
138
353
|
};
|
|
139
|
-
__name(MailiskClient, "MailiskClient");
|
|
140
354
|
// Annotate the CommonJS export names for ESM import in node:
|
|
141
355
|
0 && (module.exports = {
|
|
142
356
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAgF;AAahF,wBAAuB;AAEhB,IAAM,gBAAN,MAAoB;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,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,QAAQ,QAAQ,YAAY,QAAW;AACjD,cAAQ,UAAU,MAAO,KAAK;AAAA,IAChC;AAEA,UAAM,gBAAgB;AAAA,MACpB,GAAG;AAAA,MACH,WAAW,QAAQ,aAAa;AAAA,MAChC,SAAS,QAAQ,WAAW;AAAA,IAC9B;AAEA,YACE,MAAM,KAAK,cAAc,IAAI,WAAW,wBAAwB;AAAA,MAC9D,GAAG;AAAA,MACH,QAAQ;AAAA,IACV,CAAC,GACD;AAAA,EACJ;AAAA,EAWA,MAAM,iBAAkD;AACtD,YAAQ,MAAM,KAAK,cAAc,IAAI,iBAAiB,GAAG;AAAA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AM,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;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\";\nexport * from \"./mailisk.interfaces\";\n","import axios, { AxiosBasicCredentials, AxiosInstance, AxiosRequestConfig } from \"axios\";\nimport {\n CreateBase32SecretKeyTotpDeviceParams,\n CreateCustomTotpDeviceParams,\n CreateOtpAuthUrlTotpDeviceParams,\n CreateTotpDeviceParams,\n GetAttachmentResponse,\n ListNamespacesResponse,\n ListSmsNumbersResponse,\n ListTotpDevicesParams,\n ListTotpDevicesResponse,\n SearchInboxParams,\n SearchInboxResponse,\n SearchSmsMessagesParams,\n SearchSmsMessagesResponse,\n SendVirtualEmailParams,\n SendVirtualSmsParams,\n SmtpSettings,\n TotpDevice,\n TotpOtpResponse,\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 saved TOTP devices.\n *\n * @example\n * List saved TOTP devices for an issuer and username\n * ```typescript\n * const { items: devices } = await client.listTotpDevices({\n * issuer: \"GitHub\",\n * username: \"qa@example.com\",\n * });\n * ```\n */\n async listTotpDevices(params?: ListTotpDevicesParams): Promise<ListTotpDevicesResponse> {\n const requestParams: ListTotpDevicesParams = {\n ...params,\n username: params?.username?.trim(),\n issuer: params?.issuer?.trim(),\n };\n\n return (\n await this.axiosInstance.get(\"api/devices\", {\n params: requestParams,\n })\n ).data;\n }\n\n /**\n * Create a saved TOTP device from a Base32 shared secret using default TOTP settings.\n *\n * @example\n * Create a saved TOTP device from a shared secret\n * ```typescript\n * const device = await client.createTotpDevice({\n * name: \"GitHub staging\",\n * sharedSecret: \"JBSWY3DPEHPK3PXP\",\n * });\n * ```\n */\n async createTotpDevice(params: CreateTotpDeviceParams): Promise<TotpDevice> {\n return (await this.axiosInstance.post(\"api/devices\", params)).data;\n }\n\n /**\n * Create a saved TOTP device with custom settings.\n *\n * @example\n * Create a saved TOTP device with custom settings\n * ```typescript\n * const device = await client.createCustomTotpDevice({\n * name: \"GitHub staging\",\n * secret: \"JBSWY3DPEHPK3PXP\",\n * username: \"qa@example.com\",\n * issuer: \"GitHub\",\n * digits: 6,\n * period: 30,\n * algorithm: \"SHA1\",\n * });\n * ```\n */\n async createCustomTotpDevice(params: CreateCustomTotpDeviceParams): Promise<TotpDevice> {\n return (await this.axiosInstance.post(\"api/devices/custom\", params)).data;\n }\n\n /**\n * Create a saved TOTP device from a Base32 secret key.\n *\n * @example\n * Create a saved TOTP device from a Base32 secret key\n * ```typescript\n * const device = await client.createTotpDeviceFromBase32SecretKey({\n * base32SecretKey: \"JBSWY3DPEHPK3PXP\",\n * username: \"qa@example.com\",\n * issuer: \"GitHub\",\n * });\n * ```\n */\n async createTotpDeviceFromBase32SecretKey(params: CreateBase32SecretKeyTotpDeviceParams): Promise<TotpDevice> {\n return (await this.axiosInstance.post(\"api/devices/base32-secret-key\", params)).data;\n }\n\n /**\n * Create a saved TOTP device from an otpauth://totp URL.\n *\n * @example\n * Create a saved TOTP device from an otpauth URL\n * ```typescript\n * const device = await client.createTotpDeviceFromOtpAuthUrl({\n * otpAuthUrl: \"otpauth://totp/GitHub:qa@example.com?secret=JBSWY3DPEHPK3PXP&issuer=GitHub\",\n * });\n * ```\n */\n async createTotpDeviceFromOtpAuthUrl(params: CreateOtpAuthUrlTotpDeviceParams): Promise<TotpDevice> {\n return (await this.axiosInstance.post(\"api/devices/otpauth-url\", params)).data;\n }\n\n /**\n * Generate a TOTP code from a shared secret without saving a device.\n *\n * @example\n * Generate a TOTP code from a shared secret\n * ```typescript\n * const { code } = await client.getTotpOtpBySharedSecret(\"JBSWY3DPEHPK3PXP\");\n * ```\n */\n async getTotpOtpBySharedSecret(sharedSecret: string): Promise<TotpOtpResponse> {\n return (await this.axiosInstance.post(\"api/devices/otp\", { sharedSecret })).data;\n }\n\n /**\n * Generate a TOTP code for a saved device.\n *\n * @example\n * Generate a TOTP code for a saved device\n * ```typescript\n * const { code } = await client.getTotpOtpByDeviceId(device.id);\n * ```\n */\n async getTotpOtpByDeviceId(deviceId: string): Promise<TotpOtpResponse> {\n return (await this.axiosInstance.get(`api/devices/${deviceId}/otp`)).data;\n }\n\n /**\n * Delete a saved TOTP device.\n *\n * @example\n * Delete a saved TOTP device\n * ```typescript\n * await client.deleteTotpDevice(device.id);\n * ```\n */\n async deleteTotpDevice(deviceId: string): Promise<void> {\n await this.axiosInstance.delete(`api/devices/${deviceId}`);\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;AAqBhF,wBAAuB;AAEhB,IAAM,gBAAN,MAAoB;AAAA,EAvB3B,OAuB2B;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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