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
3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ RDS_PASSWORD=example
# Stalwart
STALWART_JMAP_URL=http://localhost:8085
STALWART_ADMIN_URL=http://localhost:8085
STALWART_ADMIN_TOKEN=
STALWART_ADMIN_USER=
STALWART_ADMIN_SECRET=

# Auth
JWT_SECRET=
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ export default [
],
},
},
{
files: ['**/*.spec.ts', '**/*.test.ts'],
rules: {
'@typescript-eslint/unbound-method': 'off',
},
},
];
16 changes: 16 additions & 0 deletions migrations/20260325105400-add-deleted-at-to-mail-accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('mail_accounts', 'deleted_at', {
type: Sequelize.DATE,
allowNull: true,
defaultValue: null,
});
},

async down(queryInterface) {
await queryInterface.removeColumn('mail_accounts', 'deleted_at');
},
};
16 changes: 16 additions & 0 deletions migrations/20260325105401-add-deleted-at-to-mail-addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('mail_addresses', 'deleted_at', {
type: Sequelize.DATE,
allowNull: true,
defaultValue: null,
});
},

async down(queryInterface) {
await queryInterface.removeColumn('mail_addresses', 'deleted_at');
},
};
20 changes: 20 additions & 0 deletions migrations/20260326100000-rename-drive-user-uuid-to-user-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
await queryInterface.renameColumn(
'mail_accounts',
'drive_user_uuid',
'user_id',
);
},

async down(queryInterface) {
await queryInterface.renameColumn(
'mail_accounts',
'user_id',
'drive_user_uuid',
);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('mail_provider_accounts', 'deleted_at', {
type: Sequelize.DATE,
allowNull: true,
defaultValue: null,
});
},

async down(queryInterface) {
await queryInterface.removeColumn('mail_provider_accounts', 'deleted_at');
},
};
6 changes: 3 additions & 3 deletions seeders/20260318200321-test-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const domain = {
const account = {
id: 'a1b2c3d4-0000-0000-0000-000000000002',
// Matches the uuid of the test user in drive-server-wip seeders
drive_user_uuid: '87204d6b-c4a7-4f38-bd99-f7f47964a643',
user_id: '87204d6b-c4a7-4f38-bd99-f7f47964a643',
created_at: new Date(),
updated_at: new Date(),
};
Expand Down Expand Up @@ -49,8 +49,8 @@ module.exports = {
}

const [existingAccount] = await queryInterface.sequelize.query(
'SELECT id FROM mail_accounts WHERE drive_user_uuid = :uuid',
{ replacements: { uuid: account.drive_user_uuid }, type: queryInterface.sequelize.QueryTypes.SELECT },
'SELECT id FROM mail_accounts WHERE user_id = :uuid',
{ replacements: { uuid: account.user_id }, type: queryInterface.sequelize.QueryTypes.SELECT },
);
if (!existingAccount) {
await queryInterface.bulkInsert('mail_accounts', [account]);
Expand Down
3 changes: 2 additions & 1 deletion src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default () => ({
stalwart: {
url: process.env.STALWART_JMAP_URL ?? 'http://localhost:8085',
adminUrl: process.env.STALWART_ADMIN_URL ?? 'http://localhost:8085',
adminToken: process.env.STALWART_ADMIN_TOKEN ?? '',
adminUser: process.env.STALWART_ADMIN_USER ?? 'mail-api',
adminSecret: process.env.STALWART_ADMIN_SECRET ?? '',
masterUser: process.env.STALWART_MASTER_USER ?? 'master',
masterPassword: process.env.STALWART_MASTER_PASSWORD ?? '',
},
Expand Down
7 changes: 7 additions & 0 deletions src/modules/account/account-provider.port.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { AccountInfo, CreateAccountParams } from './account.types.js';

export abstract class AccountProvider {
abstract createAccount(params: CreateAccountParams): Promise<void>;
abstract deleteAccount(name: string): Promise<void>;
abstract getAccount(name: string): Promise<AccountInfo | null>;
}
14 changes: 13 additions & 1 deletion src/modules/account/account.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Module } from '@nestjs/common';
import { SequelizeModule } from '@nestjs/sequelize';
import { StalwartModule } from '../infrastructure/stalwart/stalwart.module.js';
import { AccountService } from './account.service.js';
import {
MailAccountModel,
MailAddressModel,
MailDomainModel,
MailProviderAccountModel,
} from './models/index.js';
import { AccountRepository } from './repositories/account.repository.js';
import { AddressRepository } from './repositories/address.repository.js';
import { DomainRepository } from './repositories/domain.repository.js';

@Module({
imports: [
Expand All @@ -15,7 +20,14 @@ import {
MailDomainModel,
MailProviderAccountModel,
]),
StalwartModule,
],
exports: [SequelizeModule],
providers: [
AccountRepository,
AddressRepository,
DomainRepository,
AccountService,
],
exports: [AccountService],
})
export class AccountModule {}
Loading
Loading