@remit/imap-worker 0.0.92 → 0.0.94
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/dist/config-env.js +6 -1
- package/dist/context.d.ts +3 -1
- package/dist/context.js +0 -1
- package/dist/handlers/sync-message-body.js +5 -1
- package/dist/lifecycle-connection-scope.d.ts +24 -0
- package/dist/lifecycle-connection-scope.js +35 -0
- package/dist/process.d.ts +1 -0
- package/dist/process.js +1 -0
- package/package.json +1 -1
package/dist/config-env.js
CHANGED
|
@@ -2,6 +2,9 @@ import { attemptBudget } from "@remit/sqs-client/attempt-budget";
|
|
|
2
2
|
import { DEFAULT_MAILBOX_FRESHNESS_MS, defaultImapWorkerConfig, } from "./context.js";
|
|
3
3
|
import { workerVersion } from "./worker-version.js";
|
|
4
4
|
const DEFAULT_CONNECTIONS_PER_ACCOUNT = 2;
|
|
5
|
+
const BODY_BATCH_SIZE = 200;
|
|
6
|
+
const BODY_PROCESS_CONCURRENCY = 8;
|
|
7
|
+
const BODY_PROCESS_BYTES_IN_FLIGHT = 256 * 1024 * 1024;
|
|
5
8
|
// Deployments that drive sync from a test harness set MAILBOX_FRESHNESS_MS low
|
|
6
9
|
// so their explicit nudges are never no-oped by the freshness gate.
|
|
7
10
|
export const resolveMailboxFreshnessMs = (env) => {
|
|
@@ -23,7 +26,9 @@ export const imapWorkerConfigFromEnv = (env) => {
|
|
|
23
26
|
messageDelete: attemptBudget("MESSAGE_DELETE_MAX_ATTEMPTS", attempts.messageDelete, env),
|
|
24
27
|
messageCopy: attemptBudget("MESSAGE_COPY_MAX_ATTEMPTS", attempts.messageCopy, env),
|
|
25
28
|
},
|
|
26
|
-
bodyBatchSize:
|
|
29
|
+
bodyBatchSize: BODY_BATCH_SIZE,
|
|
30
|
+
bodyProcessConcurrency: BODY_PROCESS_CONCURRENCY,
|
|
31
|
+
bodyProcessBytesInFlight: BODY_PROCESS_BYTES_IN_FLIGHT,
|
|
27
32
|
mailboxFreshnessMs: resolveMailboxFreshnessMs(env),
|
|
28
33
|
workerVersion: workerVersion(),
|
|
29
34
|
};
|
package/dist/context.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface AttemptBudgets {
|
|
|
29
29
|
export interface ImapWorkerConfig {
|
|
30
30
|
readonly attempts: AttemptBudgets;
|
|
31
31
|
readonly bodyBatchSize: number;
|
|
32
|
+
readonly bodyProcessConcurrency: number;
|
|
33
|
+
readonly bodyProcessBytesInFlight: number;
|
|
32
34
|
readonly mailboxFreshnessMs: number;
|
|
33
35
|
readonly workerVersion: string;
|
|
34
36
|
}
|
|
@@ -43,4 +45,4 @@ export interface ProcessContext {
|
|
|
43
45
|
readonly accountObjects: AccountObjectStore;
|
|
44
46
|
}
|
|
45
47
|
export declare const DEFAULT_MAILBOX_FRESHNESS_MS = 60000;
|
|
46
|
-
export declare const defaultImapWorkerConfig: Omit<ImapWorkerConfig, "workerVersion">;
|
|
48
|
+
export declare const defaultImapWorkerConfig: Omit<ImapWorkerConfig, "workerVersion" | "bodyBatchSize" | "bodyProcessConcurrency" | "bodyProcessBytesInFlight">;
|
package/dist/context.js
CHANGED
|
@@ -132,7 +132,11 @@ export const syncMessageBody = async (event, ctx, receiveCount) => {
|
|
|
132
132
|
placement: await resolveFolderPlacement(mailboxSpecialUseService, accountId, mailbox.mailboxId),
|
|
133
133
|
};
|
|
134
134
|
await (async () => {
|
|
135
|
-
const result = await bodySyncService.syncBodies(messageIds, accountId, account.accountConfigId, folder, getConnectionChecked,
|
|
135
|
+
const result = await bodySyncService.syncBodies(messageIds, accountId, account.accountConfigId, folder, getConnectionChecked, {
|
|
136
|
+
force,
|
|
137
|
+
concurrency: config.bodyProcessConcurrency,
|
|
138
|
+
bytesInFlight: config.bodyProcessBytesInFlight,
|
|
139
|
+
});
|
|
136
140
|
if (result.failedMessageIds.length === 0) {
|
|
137
141
|
return;
|
|
138
142
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ConnectionScopeFactory } from "@remit/backend/create-remit-client";
|
|
2
|
+
import type { AccountItem } from "@remit/data-ports";
|
|
3
|
+
import { ConflictError } from "@remit/data-ports/errors";
|
|
4
|
+
import type { Logger } from "@remit/logger";
|
|
5
|
+
import type { ConnectionScope } from "@remit/mailbox-service";
|
|
6
|
+
import type { MailCredentials } from "@remit/mailbox-service/types";
|
|
7
|
+
import type { TokenService } from "./context.js";
|
|
8
|
+
/**
|
|
9
|
+
* The account holds no credential a connection can be opened with: it stores
|
|
10
|
+
* none, or its OAuth consent was withdrawn. The account has already been
|
|
11
|
+
* flipped to the state that says so; the caller has to reconnect it.
|
|
12
|
+
*/
|
|
13
|
+
export declare class AccountNeedsReconnectError extends ConflictError {
|
|
14
|
+
name: string;
|
|
15
|
+
constructor(accountId: string);
|
|
16
|
+
}
|
|
17
|
+
export type OpenConnection = (account: AccountItem, credentials: MailCredentials) => ConnectionScope | Promise<ConnectionScope>;
|
|
18
|
+
/**
|
|
19
|
+
* The read path's connection scope, resolving credentials under the same OAuth
|
|
20
|
+
* lifecycle the queue handlers run: a rotated refresh token is persisted, and a
|
|
21
|
+
* revoked token or a missing credential flips the account's connection state
|
|
22
|
+
* and answers 409 instead of surfacing as a 500.
|
|
23
|
+
*/
|
|
24
|
+
export declare const lifecycleConnectionScope: (tokenService: TokenService, open: OpenConnection, log: Logger) => ConnectionScopeFactory;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ConflictError } from "@remit/data-ports/errors";
|
|
2
|
+
import { withOAuthLifecycle } from "./with-oauth-lifecycle.js";
|
|
3
|
+
import { buildLifecycleDeps } from "./with-oauth-lifecycle-deps.js";
|
|
4
|
+
/**
|
|
5
|
+
* The account holds no credential a connection can be opened with: it stores
|
|
6
|
+
* none, or its OAuth consent was withdrawn. The account has already been
|
|
7
|
+
* flipped to the state that says so; the caller has to reconnect it.
|
|
8
|
+
*/
|
|
9
|
+
export class AccountNeedsReconnectError extends ConflictError {
|
|
10
|
+
name = "AccountNeedsReconnectError";
|
|
11
|
+
constructor(accountId) {
|
|
12
|
+
super(`Account ${accountId} has to be reconnected before it can be read`);
|
|
13
|
+
this.publicApiError = {
|
|
14
|
+
code: "account_needs_reconnect",
|
|
15
|
+
details: { accountId },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The read path's connection scope, resolving credentials under the same OAuth
|
|
21
|
+
* lifecycle the queue handlers run: a rotated refresh token is persisted, and a
|
|
22
|
+
* revoked token or a missing credential flips the account's connection state
|
|
23
|
+
* and answers 409 instead of surfacing as a 500.
|
|
24
|
+
*/
|
|
25
|
+
export const lifecycleConnectionScope = (tokenService, open, log) => (accountService, secrets) => async (accountId) => {
|
|
26
|
+
const account = await accountService.get(accountId);
|
|
27
|
+
const opened = [];
|
|
28
|
+
await withOAuthLifecycle(buildLifecycleDeps(secrets, accountService, tokenService), account, log, async (credentials) => {
|
|
29
|
+
opened.push(await open(account, credentials));
|
|
30
|
+
});
|
|
31
|
+
const [scope] = opened;
|
|
32
|
+
if (scope === undefined)
|
|
33
|
+
throw new AccountNeedsReconnectError(accountId);
|
|
34
|
+
return scope;
|
|
35
|
+
};
|
package/dist/process.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export type { ConnectionScope } from "@remit/mailbox-service";
|
|
|
2
2
|
export { type BorrowedConnection, type ConnectImap, type ConnectionPool, type ConnectionPoolOptions, createConnectionPool, type PoolAccount, type PoolOverflow, } from "./connection-pool.js";
|
|
3
3
|
export { type AccountObjectPage, type AccountObjectStore, type AttemptBudgets, DEFAULT_MAILBOX_FRESHNESS_MS, defaultImapWorkerConfig, type ImapFailureKind, type ImapWorkerConfig, type ImapWorkerQueueName, type ProcessContext, type TokenService, type WorkerMetrics, } from "./context.js";
|
|
4
4
|
export type { ImapEvent, WorkerEvent } from "./events.js";
|
|
5
|
+
export { AccountNeedsReconnectError, lifecycleConnectionScope, type OpenConnection, } from "./lifecycle-connection-scope.js";
|
|
5
6
|
export { processEvent } from "./processor.js";
|
|
6
7
|
export type { WorkerQueues } from "./queues.js";
|
package/dist/process.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { createConnectionPool, } from "./connection-pool.js";
|
|
2
2
|
export { DEFAULT_MAILBOX_FRESHNESS_MS, defaultImapWorkerConfig, } from "./context.js";
|
|
3
|
+
export { AccountNeedsReconnectError, lifecycleConnectionScope, } from "./lifecycle-connection-scope.js";
|
|
3
4
|
export { processEvent } from "./processor.js";
|