mailisk 2.2.3 → 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 +199 -1
- package/dist/index.d.ts +199 -1
- package/dist/index.js +123 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +123 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- 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/README.md
CHANGED
|
@@ -5,6 +5,7 @@ Mailisk is an end-to-end email and SMS testing platform. It allows you to receiv
|
|
|
5
5
|
- Get a unique subdomain and unlimited email addresses for free.
|
|
6
6
|
- Easily automate E2E password reset and account verification by catching emails.
|
|
7
7
|
- Receive SMS messages and automate SMS tests.
|
|
8
|
+
- Generate TOTP authenticator codes and manage saved TOTP devices.
|
|
8
9
|
- Virtual SMTP and SMS support to test without 3rd party clients.
|
|
9
10
|
|
|
10
11
|
## Get started
|
|
@@ -214,3 +215,99 @@ await mailisk.sendVirtualSms({
|
|
|
214
215
|
body: "Test message",
|
|
215
216
|
});
|
|
216
217
|
```
|
|
218
|
+
|
|
219
|
+
## Client functions (TOTP)
|
|
220
|
+
|
|
221
|
+
TOTP methods call the Mailisk API to generate codes and manage saved authenticator devices. The client does not generate TOTP codes locally.
|
|
222
|
+
|
|
223
|
+
These endpoints require an organisation API key, prefixed with `sk_org_`.
|
|
224
|
+
|
|
225
|
+
### `listTotpDevices(params?)`
|
|
226
|
+
|
|
227
|
+
List active saved TOTP devices.
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
const devices = await mailisk.listTotpDevices({
|
|
231
|
+
limit: 20,
|
|
232
|
+
offset: 0,
|
|
233
|
+
issuer: "GitHub",
|
|
234
|
+
username: "qa@example.com",
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### `createTotpDevice(params)`
|
|
239
|
+
|
|
240
|
+
Create a saved TOTP device from a Base32 shared secret using default settings: 6 digits, 30 second period, and SHA1.
|
|
241
|
+
|
|
242
|
+
```js
|
|
243
|
+
const device = await mailisk.createTotpDevice({
|
|
244
|
+
name: "GitHub staging",
|
|
245
|
+
sharedSecret: "JBSWY3DPEHPK3PXP",
|
|
246
|
+
expiresAt: "2026-06-01T12:00:00.000Z",
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### `createCustomTotpDevice(params)`
|
|
251
|
+
|
|
252
|
+
Create a saved TOTP device with custom settings.
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
const device = await mailisk.createCustomTotpDevice({
|
|
256
|
+
name: "GitHub staging",
|
|
257
|
+
secret: "JBSWY3DPEHPK3PXP",
|
|
258
|
+
username: "qa@example.com",
|
|
259
|
+
issuer: "GitHub",
|
|
260
|
+
digits: 6,
|
|
261
|
+
period: 30,
|
|
262
|
+
algorithm: "SHA1",
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### `createTotpDeviceFromBase32SecretKey(params)`
|
|
267
|
+
|
|
268
|
+
Create a saved TOTP device from a Base32 secret key.
|
|
269
|
+
|
|
270
|
+
```js
|
|
271
|
+
const device = await mailisk.createTotpDeviceFromBase32SecretKey({
|
|
272
|
+
base32SecretKey: "JBSWY3DPEHPK3PXP",
|
|
273
|
+
username: "qa@example.com",
|
|
274
|
+
issuer: "GitHub",
|
|
275
|
+
});
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### `createTotpDeviceFromOtpAuthUrl(params)`
|
|
279
|
+
|
|
280
|
+
Create a saved TOTP device from an `otpauth://totp/...` URL.
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
const device = await mailisk.createTotpDeviceFromOtpAuthUrl({
|
|
284
|
+
otpAuthUrl: "otpauth://totp/GitHub:qa@example.com?secret=JBSWY3DPEHPK3PXP&issuer=GitHub",
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### `getTotpOtpBySharedSecret(sharedSecret)`
|
|
289
|
+
|
|
290
|
+
Generate a TOTP code from a shared secret without saving a device.
|
|
291
|
+
|
|
292
|
+
```js
|
|
293
|
+
const otp = await mailisk.getTotpOtpBySharedSecret("JBSWY3DPEHPK3PXP");
|
|
294
|
+
|
|
295
|
+
console.log(otp.code);
|
|
296
|
+
console.log(otp.expires);
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### `getTotpOtpByDeviceId(deviceId)`
|
|
300
|
+
|
|
301
|
+
Generate a TOTP code for a saved device.
|
|
302
|
+
|
|
303
|
+
```js
|
|
304
|
+
const otp = await mailisk.getTotpOtpByDeviceId(device.id);
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### `deleteTotpDevice(deviceId)`
|
|
308
|
+
|
|
309
|
+
Delete a saved TOTP device.
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
await mailisk.deleteTotpDevice(device.id);
|
|
313
|
+
```
|
package/dist/index.d.mts
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.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
|
@@ -101,6 +101,129 @@ var MailiskClient = class {
|
|
|
101
101
|
async sendVirtualSms(params) {
|
|
102
102
|
return (await this.axiosInstance.post("api/sms/virtual", params)).data;
|
|
103
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
|
+
}
|
|
104
227
|
/**
|
|
105
228
|
* List all namespaces that belong to the current account (API key).
|
|
106
229
|
*/
|