@remit/backend 0.0.148 → 0.0.149
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.
|
@@ -2,8 +2,9 @@ import { ensureAccountConfig } from "@remit/data-ports/account-config";
|
|
|
2
2
|
import { AccountAuthType, AccountService, ConnectionState, } from "@remit/domain-enums";
|
|
3
3
|
import { logger } from "@remit/logger";
|
|
4
4
|
import { createMailOAuthService, microsoftProviderConfig, RefreshTokenError, } from "@remit/mail-oauth-service";
|
|
5
|
-
import { ownedAccount, resolveConnectionCredentials, testImapConnection,
|
|
5
|
+
import { ownedAccount, resolveConnectionCredentials, testImapConnection, } from "@remit/mailbox-service";
|
|
6
6
|
import { deserializeEncryptedPayload, serializeEncryptedPayload, } from "@remit/secrets-service";
|
|
7
|
+
import { verifySmtpConnection } from "@remit/smtp-service";
|
|
7
8
|
import { loadMsOAuth } from "../config/msoauth.js";
|
|
8
9
|
import { deleteAccount } from "../service/account-deletion.js";
|
|
9
10
|
import { fireAndForget } from "../service/fire-and-forget.js";
|
|
@@ -44,7 +45,7 @@ export const triggerAccountSyncSafe = async (client, accountId) => {
|
|
|
44
45
|
* reauth-required case is mapped to the distinct `reauth_required` error code
|
|
45
46
|
* so the UI can route the user into the OAuth re-auth flow.
|
|
46
47
|
*/
|
|
47
|
-
const testOAuthConnection = async (msOAuth, existingAccount, account, secrets) => {
|
|
48
|
+
const testOAuthConnection = async (msOAuth, existingAccount, account, secrets, mailTransports) => {
|
|
48
49
|
const { config, credentials: app } = await loadMsOAuth(msOAuth);
|
|
49
50
|
const tokenService = createMailOAuthService(microsoftProviderConfig({
|
|
50
51
|
clientId: app.clientId,
|
|
@@ -93,19 +94,20 @@ const testOAuthConnection = async (msOAuth, existingAccount, account, secrets) =
|
|
|
93
94
|
secure: existingAccount.imapTls,
|
|
94
95
|
user: existingAccount.username,
|
|
95
96
|
credentials,
|
|
96
|
-
});
|
|
97
|
+
}, mailTransports.imap(existingAccount.imapHost, existingAccount.imapTls));
|
|
97
98
|
result.imapSuccess = imapResult.success;
|
|
98
99
|
if (!imapResult.success) {
|
|
99
100
|
result.imapError = imapResult.error;
|
|
100
101
|
}
|
|
101
102
|
// OAuth accounts share the same access token for IMAP and SMTP.
|
|
102
103
|
if (existingAccount.smtpEnabled) {
|
|
103
|
-
const smtpResult = await
|
|
104
|
+
const smtpResult = await verifySmtpConnection({
|
|
104
105
|
host: existingAccount.smtpHost ?? "",
|
|
105
106
|
port: existingAccount.smtpPort ?? 587,
|
|
106
107
|
secure: existingAccount.smtpTls ?? false,
|
|
107
108
|
user: existingAccount.smtpUsername || existingAccount.username,
|
|
108
109
|
credentials,
|
|
110
|
+
getSocket: mailTransports.smtp,
|
|
109
111
|
});
|
|
110
112
|
result.smtpSuccess = smtpResult.success;
|
|
111
113
|
if (!smtpResult.success) {
|
|
@@ -181,7 +183,7 @@ export const AccountOperations = {
|
|
|
181
183
|
AccountOperations_testConnection: async (context, ctx) => {
|
|
182
184
|
const accountConfigId = ctx.identity.accountConfigId;
|
|
183
185
|
const input = context.request.requestBody;
|
|
184
|
-
const { account, secrets } = ctx.client;
|
|
186
|
+
const { account, secrets, mailTransports } = ctx.client;
|
|
185
187
|
// Resolve password - use provided password or decrypt stored password
|
|
186
188
|
let imapPassword = input.password;
|
|
187
189
|
let smtpPassword = input.smtpPassword;
|
|
@@ -190,7 +192,7 @@ export const AccountOperations = {
|
|
|
190
192
|
unwrap(ownedAccount(existingAccount, accountConfigId, "read"));
|
|
191
193
|
const authType = existingAccount.authType ?? "password";
|
|
192
194
|
if (authType === "oauthMicrosoft") {
|
|
193
|
-
return testOAuthConnection(ctx.config.msOAuth, existingAccount, account, secrets);
|
|
195
|
+
return testOAuthConnection(ctx.config.msOAuth, existingAccount, account, secrets, mailTransports);
|
|
194
196
|
}
|
|
195
197
|
if (existingAccount.passwordHash) {
|
|
196
198
|
const payload = deserializeEncryptedPayload(JSON.parse(existingAccount.passwordHash));
|
|
@@ -218,17 +220,16 @@ export const AccountOperations = {
|
|
|
218
220
|
host: input.imapHost,
|
|
219
221
|
port: input.imapPort,
|
|
220
222
|
secure: input.imapTls,
|
|
221
|
-
startTls: input.imapStartTls,
|
|
222
223
|
user: input.username,
|
|
223
224
|
credentials: { kind: "password", password: imapPassword },
|
|
224
|
-
});
|
|
225
|
+
}, mailTransports.imap(input.imapHost, input.imapTls));
|
|
225
226
|
result.imapSuccess = imapResult.success;
|
|
226
227
|
if (!imapResult.success) {
|
|
227
228
|
result.imapError = imapResult.error;
|
|
228
229
|
}
|
|
229
230
|
// Test SMTP connection if configured
|
|
230
231
|
if (input.smtpHost) {
|
|
231
|
-
const smtpResult = await
|
|
232
|
+
const smtpResult = await verifySmtpConnection({
|
|
232
233
|
host: input.smtpHost,
|
|
233
234
|
port: input.smtpPort ?? 587,
|
|
234
235
|
secure: input.smtpTls ?? false,
|
|
@@ -237,6 +238,7 @@ export const AccountOperations = {
|
|
|
237
238
|
kind: "password",
|
|
238
239
|
password: smtpPassword ?? imapPassword,
|
|
239
240
|
},
|
|
241
|
+
getSocket: mailTransports.smtp,
|
|
240
242
|
});
|
|
241
243
|
result.smtpSuccess = smtpResult.success;
|
|
242
244
|
if (!smtpResult.success) {
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { IAccountConfigRepository, IAccountExportRequestRepository, IAccountRepository, IAccountSettingRepository, IAddressRepository, ICalendarCollectionRepository, ICalendarEventIndexRepository, ICalendarFeedTokenRepository, ICalendarObjectRepository, ICalendarStore, ICalendarSuggestionRepository, IConfigImportRepository, IEnvelopeRepository, IFilterRepository, ILabelRepository, IMailboxLockRepository, IMailboxRepository, IMailboxSpecialUseRepository, IMessageFlagPushRepository, IMessageFlagRepository, IMessageLabelRepository, IMessagePlacementMoveRepository, IMessageRepository, IOrganizeJobRequestRepository, IOutboxAttachmentRepository, IOutboxMessageRepository, IQuarantineRepository, ISenderSignerStandingRepository, ISyncWarningRepository, IThreadMessageRepository } from "@remit/data-ports";
|
|
2
2
|
import { BodySyncQueueService, BodySyncService, type ConnectionScope, type FilterConfig, FlagQueueService, type ImapTransport, MailboxQueueService, MessageMoveService, OutboxAttachmentService, OutboxQueueService, SpamReportService } from "@remit/mailbox-service";
|
|
3
3
|
import { type SecretsService } from "@remit/secrets-service";
|
|
4
|
+
import type { SmtpGetSocket } from "@remit/smtp-service";
|
|
4
5
|
import type { StorageService } from "@remit/storage-service";
|
|
5
6
|
import type { QueueName, RemitClientQueues } from "./queues.js";
|
|
6
7
|
export type { ConnectionScope };
|
|
7
8
|
export type ConnectionScopeFactory = (accountService: IAccountRepository, secretsService: SecretsService) => (accountId: string) => Promise<ConnectionScope>;
|
|
9
|
+
export interface MailTransports {
|
|
10
|
+
imap: (host: string, secure: boolean) => ImapTransport;
|
|
11
|
+
smtp: SmtpGetSocket;
|
|
12
|
+
}
|
|
8
13
|
export interface RemitClientCore {
|
|
9
14
|
accountConfig: IAccountConfigRepository;
|
|
10
15
|
account: IAccountRepository;
|
|
@@ -39,6 +44,7 @@ export interface RemitClientCore {
|
|
|
39
44
|
flagPush: IMessageFlagPushRepository;
|
|
40
45
|
outboxAttachment: OutboxAttachmentService;
|
|
41
46
|
createConnectionScope: (accountId: string) => Promise<ConnectionScope>;
|
|
47
|
+
mailTransports: MailTransports;
|
|
42
48
|
}
|
|
43
49
|
export interface SyncQueueServices {
|
|
44
50
|
flagQueue: FlagQueueService;
|
|
@@ -94,6 +100,7 @@ export interface RemitClientSharedDeps {
|
|
|
94
100
|
storage: StorageService;
|
|
95
101
|
secrets: SecretsService;
|
|
96
102
|
connectionScope: ConnectionScopeFactory;
|
|
103
|
+
mailTransports: MailTransports;
|
|
97
104
|
queues: RemitClientQueues;
|
|
98
105
|
}
|
|
99
106
|
export interface RemitClientDeps extends RemitClientSharedDeps {
|
|
@@ -45,7 +45,7 @@ export const buildReadPathFilterConfig = (repositories, queues) => {
|
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
export const createRemitCore = (deps) => {
|
|
48
|
-
const { repositories, storage, secrets, connectionScope } = deps;
|
|
48
|
+
const { repositories, storage, secrets, connectionScope, mailTransports } = deps;
|
|
49
49
|
return {
|
|
50
50
|
accountConfig: repositories.accountConfig,
|
|
51
51
|
account: repositories.account,
|
|
@@ -87,6 +87,7 @@ export const createRemitCore = (deps) => {
|
|
|
87
87
|
storage,
|
|
88
88
|
}),
|
|
89
89
|
createConnectionScope: connectionScope(repositories.account, secrets),
|
|
90
|
+
mailTransports,
|
|
90
91
|
};
|
|
91
92
|
};
|
|
92
93
|
export const composeSyncServices = (core, queues) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { nodeTransport } from "@remit/mailbox-service/node-transport";
|
|
2
2
|
import { createCachedDataKeyProvider, createSecretsService, } from "@remit/secrets-service";
|
|
3
3
|
import { createKmsDataKeyProvider, FAKE_KMS_KEY_ID, } from "@remit/secrets-service/kms";
|
|
4
|
+
import { directSmtpSocket } from "@remit/smtp-service";
|
|
4
5
|
import { createFifoQueueProducer, createStandardQueueProducer, } from "@remit/sqs-client/producer";
|
|
5
6
|
import { createStorageService } from "@remit/storage-service/s3";
|
|
6
7
|
import { env } from "expect-env";
|
|
@@ -21,9 +22,13 @@ export const sqsQueues = (urls) => ({
|
|
|
21
22
|
}),
|
|
22
23
|
body: createStandardQueueProducer({ queueUrl: urls.body }),
|
|
23
24
|
});
|
|
24
|
-
export const buildSharedDeps = (queues) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
export const buildSharedDeps = (queues) => {
|
|
26
|
+
const imapTransport = nodeTransport();
|
|
27
|
+
return {
|
|
28
|
+
storage: createStorageService(),
|
|
29
|
+
secrets: createSecretsService(createCachedDataKeyProvider(createKmsDataKeyProvider(process.env.KMS_KEY_ID ?? FAKE_KMS_KEY_ID))),
|
|
30
|
+
connectionScope: passwordConnectionScope(imapTransport),
|
|
31
|
+
mailTransports: { imap: () => imapTransport, smtp: directSmtpSocket },
|
|
32
|
+
queues,
|
|
33
|
+
};
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remit/backend",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.149",
|
|
4
4
|
"description": "Remit Mail Inspector API backend",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "",
|
|
@@ -101,6 +101,7 @@
|
|
|
101
101
|
"@remit/mail-oauth-service": "*",
|
|
102
102
|
"@remit/secrets-service": "*",
|
|
103
103
|
"@remit/mailbox-service": "*",
|
|
104
|
+
"@remit/smtp-service": "*",
|
|
104
105
|
"@remit/storage-service": "*",
|
|
105
106
|
"@remit/auth-service": "*",
|
|
106
107
|
"@remit/drizzle-service": "*",
|