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
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
mockAttachmentResponse,
|
|
12
12
|
mockSmsMessagesResponse,
|
|
13
13
|
mockSmsNumbersResponse,
|
|
14
|
+
mockTotpDevice,
|
|
15
|
+
mockTotpDevicesResponse,
|
|
16
|
+
mockTotpOtpResponse,
|
|
14
17
|
} from "../mocks/axios-mocks";
|
|
15
18
|
|
|
16
19
|
const setupMockAxios = () => {
|
|
@@ -281,6 +284,156 @@ describe("MailiskClient", () => {
|
|
|
281
284
|
});
|
|
282
285
|
});
|
|
283
286
|
|
|
287
|
+
describe("listTotpDevices", () => {
|
|
288
|
+
it("should fetch and return saved TOTP devices", async () => {
|
|
289
|
+
const { mockGet } = setupMockAxios();
|
|
290
|
+
mockGet.mockResolvedValueOnce({ data: mockTotpDevicesResponse });
|
|
291
|
+
|
|
292
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
293
|
+
const result = await client.listTotpDevices({
|
|
294
|
+
limit: 20,
|
|
295
|
+
offset: 0,
|
|
296
|
+
username: " qa@example.com ",
|
|
297
|
+
issuer: " GitHub ",
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
expect(mockGet).toHaveBeenCalledWith("api/devices", {
|
|
301
|
+
params: {
|
|
302
|
+
limit: 20,
|
|
303
|
+
offset: 0,
|
|
304
|
+
username: "qa@example.com",
|
|
305
|
+
issuer: "GitHub",
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
expect(result).toEqual(mockTotpDevicesResponse);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("should handle omitted saved TOTP device filters", async () => {
|
|
312
|
+
const { mockGet } = setupMockAxios();
|
|
313
|
+
mockGet.mockResolvedValueOnce({ data: mockTotpDevicesResponse });
|
|
314
|
+
|
|
315
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
316
|
+
const result = await client.listTotpDevices();
|
|
317
|
+
|
|
318
|
+
expect(mockGet).toHaveBeenCalledWith("api/devices", {
|
|
319
|
+
params: {
|
|
320
|
+
username: undefined,
|
|
321
|
+
issuer: undefined,
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
expect(result).toEqual(mockTotpDevicesResponse);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe("createTotpDevice", () => {
|
|
329
|
+
it("should create a saved TOTP device from a shared secret", async () => {
|
|
330
|
+
const { mockPost } = setupMockAxios();
|
|
331
|
+
mockPost.mockResolvedValueOnce({ data: mockTotpDevice });
|
|
332
|
+
|
|
333
|
+
const params = {
|
|
334
|
+
sharedSecret: "JBSWY3DPEHPK3PXP",
|
|
335
|
+
name: "GitHub staging",
|
|
336
|
+
expiresAt: "2026-06-01T12:00:00.000Z",
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
340
|
+
const result = await client.createTotpDevice(params);
|
|
341
|
+
|
|
342
|
+
expect(mockPost).toHaveBeenCalledWith("api/devices", params);
|
|
343
|
+
expect(result).toEqual(mockTotpDevice);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("should create a saved TOTP device with custom settings", async () => {
|
|
347
|
+
const { mockPost } = setupMockAxios();
|
|
348
|
+
mockPost.mockResolvedValueOnce({ data: mockTotpDevice });
|
|
349
|
+
|
|
350
|
+
const params = {
|
|
351
|
+
secret: "JBSWY3DPEHPK3PXP",
|
|
352
|
+
name: "GitHub staging",
|
|
353
|
+
username: "qa@example.com",
|
|
354
|
+
issuer: "GitHub",
|
|
355
|
+
digits: 6 as const,
|
|
356
|
+
period: 30,
|
|
357
|
+
algorithm: "SHA1" as const,
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
361
|
+
const result = await client.createCustomTotpDevice(params);
|
|
362
|
+
|
|
363
|
+
expect(mockPost).toHaveBeenCalledWith("api/devices/custom", params);
|
|
364
|
+
expect(result).toEqual(mockTotpDevice);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it("should create a saved TOTP device from a Base32 secret key", async () => {
|
|
368
|
+
const { mockPost } = setupMockAxios();
|
|
369
|
+
mockPost.mockResolvedValueOnce({ data: mockTotpDevice });
|
|
370
|
+
|
|
371
|
+
const params = {
|
|
372
|
+
base32SecretKey: "JBSWY3DPEHPK3PXP",
|
|
373
|
+
username: "qa@example.com",
|
|
374
|
+
issuer: "GitHub",
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
378
|
+
const result = await client.createTotpDeviceFromBase32SecretKey(params);
|
|
379
|
+
|
|
380
|
+
expect(mockPost).toHaveBeenCalledWith("api/devices/base32-secret-key", params);
|
|
381
|
+
expect(result).toEqual(mockTotpDevice);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("should create a saved TOTP device from an otpauth URL", async () => {
|
|
385
|
+
const { mockPost } = setupMockAxios();
|
|
386
|
+
mockPost.mockResolvedValueOnce({ data: mockTotpDevice });
|
|
387
|
+
|
|
388
|
+
const params = {
|
|
389
|
+
otpAuthUrl: "otpauth://totp/GitHub:qa@example.com?secret=JBSWY3DPEHPK3PXP&issuer=GitHub",
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
393
|
+
const result = await client.createTotpDeviceFromOtpAuthUrl(params);
|
|
394
|
+
|
|
395
|
+
expect(mockPost).toHaveBeenCalledWith("api/devices/otpauth-url", params);
|
|
396
|
+
expect(result).toEqual(mockTotpDevice);
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
describe("TOTP OTP", () => {
|
|
401
|
+
it("should generate a TOTP code from a shared secret without saving", async () => {
|
|
402
|
+
const { mockPost } = setupMockAxios();
|
|
403
|
+
mockPost.mockResolvedValueOnce({ data: mockTotpOtpResponse });
|
|
404
|
+
|
|
405
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
406
|
+
const result = await client.getTotpOtpBySharedSecret("JBSWY3DPEHPK3PXP");
|
|
407
|
+
|
|
408
|
+
expect(mockPost).toHaveBeenCalledWith("api/devices/otp", { sharedSecret: "JBSWY3DPEHPK3PXP" });
|
|
409
|
+
expect(result).toEqual(mockTotpOtpResponse);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it("should generate a TOTP code for a saved device", async () => {
|
|
413
|
+
const { mockGet } = setupMockAxios();
|
|
414
|
+
mockGet.mockResolvedValueOnce({ data: mockTotpOtpResponse });
|
|
415
|
+
|
|
416
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
417
|
+
const result = await client.getTotpOtpByDeviceId("9b1f6ec0-b90d-4bd8-8dd0-f6b2d5138273");
|
|
418
|
+
|
|
419
|
+
expect(mockGet).toHaveBeenCalledWith("api/devices/9b1f6ec0-b90d-4bd8-8dd0-f6b2d5138273/otp");
|
|
420
|
+
expect(result).toEqual(mockTotpOtpResponse);
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
describe("deleteTotpDevice", () => {
|
|
425
|
+
it("should delete a saved TOTP device", async () => {
|
|
426
|
+
const { mockDelete } = setupMockAxios();
|
|
427
|
+
mockDelete.mockResolvedValueOnce({ data: undefined });
|
|
428
|
+
|
|
429
|
+
const client = new MailiskClient({ apiKey: "test-key" });
|
|
430
|
+
const result = await client.deleteTotpDevice("9b1f6ec0-b90d-4bd8-8dd0-f6b2d5138273");
|
|
431
|
+
|
|
432
|
+
expect(mockDelete).toHaveBeenCalledWith("api/devices/9b1f6ec0-b90d-4bd8-8dd0-f6b2d5138273");
|
|
433
|
+
expect(result).toBeUndefined();
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
284
437
|
describe("searchInbox", () => {
|
|
285
438
|
it("should fetch and return emails with default parameters", async () => {
|
|
286
439
|
const { mockGet } = setupMockAxios();
|