Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <hello@internxt.com>",
"version": "1.16.2",
"version": "1.16.3",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
11 changes: 11 additions & 0 deletions src/mail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
SetupMailAccountPayload,
SearchFiltersQuery,
MailAccountKeysResponse,
MailAccountResponse,
EncryptedKeystore,
KeystoreType,
RecipientWithPublicKey,
Expand Down Expand Up @@ -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<MailAccountResponse> {
return this.client.get('/users/me/mail-account', this.headers());
}

/**
* Sets up a mail account for the user
*
Expand Down
8 changes: 8 additions & 0 deletions src/mail/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions test/mail/index.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand Down
Loading