diff --git a/package.json b/package.json index c36c011..127ac5e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@internxt/sdk", "author": "Internxt ", - "version": "1.16.2", + "version": "1.16.3", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/mail/index.ts b/src/mail/index.ts index 91f41d0..3e53989 100644 --- a/src/mail/index.ts +++ b/src/mail/index.ts @@ -14,6 +14,7 @@ import { SetupMailAccountPayload, SearchFiltersQuery, MailAccountKeysResponse, + MailAccountResponse, EncryptedKeystore, KeystoreType, RecipientWithPublicKey, @@ -173,6 +174,16 @@ export class MailApi { return this.client.get('/email/domains', this.headers()); } + /** + * Returns the current mail account for the authenticated user, including its + * state, default address, and (when suspended) the scheduled deletion time. + * + * @returns The mail account details — `MailAccountResponse` + */ + getMailAccount(): Promise { + return this.client.get('/users/me/mail-account', this.headers()); + } + /** * Sets up a mail account for the user * diff --git a/src/mail/types.ts b/src/mail/types.ts index 46cbebc..8a98651 100644 --- a/src/mail/types.ts +++ b/src/mail/types.ts @@ -31,6 +31,14 @@ export type MailAccountKeysResponse = { recoveryPrivateKey: string; }; +export type MailAccountResponse = { + id: string; + defaultAddress: string; + status: 'active' | 'suspended'; + suspendedAt?: string; + deletionAt?: string; +}; + export type EncryptedKeystore = { userEmail: string; type: KeystoreType; diff --git a/test/mail/index.test.ts b/test/mail/index.test.ts index 78b39ba..4e591a6 100644 --- a/test/mail/index.test.ts +++ b/test/mail/index.test.ts @@ -1,5 +1,6 @@ import { HttpClient } from '../../src/shared/http/client'; import { MailApi } from '../../src/mail/index'; +import type { MailAccountResponse } from '../../src/mail/types'; import { ApiSecurity, AppDetails } from '../../src/shared'; import { headersWithToken } from '../../src/shared/headers'; import { describe, it, expect, beforeEach, vi } from 'vitest'; @@ -9,6 +10,47 @@ describe('Mail service tests', () => { vi.restoreAllMocks(); }); + describe('getMailAccount', () => { + it('When the account is active, then it should GET /users/me/mail-account and return the account', async () => { + const { client, headers } = clientAndHeadersWithToken(); + const response: MailAccountResponse = { + id: 'account-1', + defaultAddress: 'jane@inxt.me', + status: 'active', + }; + const getStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue(response); + + const result = await client.getMailAccount(); + + expect(getStub).toHaveBeenCalledWith('/users/me/mail-account', headers); + expect(result).toEqual(response); + }); + + it('When the account is suspended, then it should return suspendedAt and deletionAt timestamps', async () => { + const { client, headers } = clientAndHeadersWithToken(); + const response: MailAccountResponse = { + id: 'account-1', + defaultAddress: 'jane@inxt.me', + status: 'suspended', + suspendedAt: '2026-05-01T00:00:00.000Z', + deletionAt: '2026-06-01T00:00:00.000Z', + }; + const getStub = vi.spyOn(HttpClient.prototype, 'get').mockResolvedValue(response); + + const result = await client.getMailAccount(); + + expect(getStub).toHaveBeenCalledWith('/users/me/mail-account', headers); + expect(result).toEqual(response); + }); + + it('When the HTTP client throws, then the error should propagate', async () => { + const { client } = clientAndHeadersWithToken(); + vi.spyOn(HttpClient.prototype, 'get').mockRejectedValue(new Error('Unauthorized')); + + await expect(client.getMailAccount()).rejects.toThrow('Unauthorized'); + }); + }); + describe('test mail account setup', () => { it('When a mail account setup is requested, then it should POST to /users/me/mail-account and return the created address', async () => { const { client, headers } = clientAndHeadersWithToken();