@remit/backend 0.0.142 → 0.0.144
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/dev-server/content-handler.d.ts +38 -0
- package/dist/dev-server/content-handler.js +46 -0
- package/dist/src/api.d.ts +7 -0
- package/dist/src/api.js +144 -0
- package/dist/src/auth.d.ts +30 -0
- package/dist/src/auth.js +73 -0
- package/dist/src/config/msoauth.d.ts +30 -0
- package/dist/src/config/msoauth.js +30 -0
- package/{src/data-backend.ts → dist/src/data-backend.d.ts} +2 -4
- package/dist/src/data-backend.js +12 -0
- package/{src/derive/autoMoved.ts → dist/src/derive/autoMoved.d.ts} +1 -29
- package/dist/src/derive/autoMoved.js +49 -0
- package/dist/src/derive/contentSignature.d.ts +41 -0
- package/{src/derive/contentSignature.ts → dist/src/derive/contentSignature.js} +27 -72
- package/dist/src/derive/contentUrl.d.ts +46 -0
- package/dist/src/derive/contentUrl.js +46 -0
- package/{src/derive/deriveMuted.ts → dist/src/derive/deriveMuted.d.ts} +1 -3
- package/dist/src/derive/deriveMuted.js +7 -0
- package/dist/src/derive/enrichThreadRows.d.ts +118 -0
- package/dist/src/derive/enrichThreadRows.js +151 -0
- package/dist/src/derive/filterThreadCriteria.d.ts +23 -0
- package/dist/src/derive/filterThreadCriteria.js +24 -0
- package/{src/derive/pendingMoveCounts.ts → dist/src/derive/pendingMoveCounts.d.ts} +5 -53
- package/dist/src/derive/pendingMoveCounts.js +53 -0
- package/{src/derive/senderTrust.ts → dist/src/derive/senderTrust.d.ts} +1 -9
- package/dist/src/derive/senderTrust.js +19 -0
- package/dist/src/error.d.ts +21 -0
- package/dist/src/error.js +85 -0
- package/dist/src/handlers/account-guards.d.ts +36 -0
- package/dist/src/handlers/account-guards.js +107 -0
- package/dist/src/handlers/account-oauth.d.ts +14 -0
- package/dist/src/handlers/account-oauth.js +387 -0
- package/dist/src/handlers/account-overrides.d.ts +53 -0
- package/dist/src/handlers/account-overrides.js +233 -0
- package/dist/src/handlers/account-signature.d.ts +28 -0
- package/dist/src/handlers/account-signature.js +85 -0
- package/dist/src/handlers/account.d.ts +6 -0
- package/dist/src/handlers/account.js +350 -0
- package/dist/src/handlers/address.d.ts +35 -0
- package/dist/src/handlers/address.js +141 -0
- package/dist/src/handlers/calendar-event.d.ts +70 -0
- package/dist/src/handlers/calendar-event.js +425 -0
- package/dist/src/handlers/calendar-feed.d.ts +47 -0
- package/dist/src/handlers/calendar-feed.js +192 -0
- package/dist/src/handlers/calendar-suggestion.d.ts +47 -0
- package/dist/src/handlers/calendar-suggestion.js +212 -0
- package/dist/src/handlers/calendar.d.ts +116 -0
- package/dist/src/handlers/calendar.js +330 -0
- package/dist/src/handlers/config.d.ts +43 -0
- package/dist/src/handlers/config.js +176 -0
- package/dist/src/handlers/ensure-account-config.d.ts +9 -0
- package/dist/src/handlers/ensure-account-config.js +27 -0
- package/dist/src/handlers/filter.d.ts +3 -0
- package/dist/src/handlers/filter.js +103 -0
- package/dist/src/handlers/folder-role-appointments.d.ts +68 -0
- package/dist/src/handlers/folder-role-appointments.js +168 -0
- package/dist/src/handlers/folder-role-labels.d.ts +26 -0
- package/dist/src/handlers/folder-role-labels.js +40 -0
- package/dist/src/handlers/folder-role.d.ts +9 -0
- package/dist/src/handlers/folder-role.js +40 -0
- package/dist/src/handlers/index.d.ts +2 -0
- package/dist/src/handlers/index.js +60 -0
- package/dist/src/handlers/label.d.ts +43 -0
- package/dist/src/handlers/label.js +114 -0
- package/dist/src/handlers/mailbox-bindings.d.ts +41 -0
- package/dist/src/handlers/mailbox-bindings.js +61 -0
- package/dist/src/handlers/mailbox.d.ts +23 -0
- package/dist/src/handlers/mailbox.js +219 -0
- package/dist/src/handlers/me.d.ts +2 -0
- package/dist/src/handlers/me.js +138 -0
- package/dist/src/handlers/message.d.ts +84 -0
- package/dist/src/handlers/message.js +607 -0
- package/dist/src/handlers/organize.d.ts +10 -0
- package/dist/src/handlers/organize.js +112 -0
- package/dist/src/handlers/outbox-attachment.d.ts +23 -0
- package/dist/src/handlers/outbox-attachment.js +81 -0
- package/dist/src/handlers/outbox.d.ts +4 -0
- package/dist/src/handlers/outbox.js +144 -0
- package/dist/src/handlers/sync-progress.d.ts +46 -0
- package/dist/src/handlers/sync-progress.js +63 -0
- package/dist/src/handlers/sync.d.ts +28 -0
- package/dist/src/handlers/sync.js +82 -0
- package/dist/src/handlers/system-update.d.ts +2 -0
- package/dist/src/handlers/system-update.js +172 -0
- package/dist/src/handlers/thread.d.ts +148 -0
- package/dist/src/handlers/thread.js +233 -0
- package/dist/src/handlers/unified-threads.d.ts +247 -0
- package/dist/src/handlers/unified-threads.js +409 -0
- package/{src/handlers/vip-suggestions.ts → dist/src/handlers/vip-suggestions.d.ts} +1 -13
- package/dist/src/handlers/vip-suggestions.js +16 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +37 -0
- package/{src/json.ts → dist/src/json.d.ts} +1 -4
- package/dist/src/json.js +10 -0
- package/dist/src/jwt-auth.d.ts +18 -0
- package/dist/src/jwt-auth.js +97 -0
- package/dist/src/request-context.d.ts +9 -0
- package/dist/src/request-context.js +22 -0
- package/dist/src/request.d.ts +3 -0
- package/dist/src/request.js +7 -0
- package/dist/src/response.d.ts +27 -0
- package/dist/src/response.js +87 -0
- package/dist/src/service/account-deletion.d.ts +22 -0
- package/dist/src/service/account-deletion.js +39 -0
- package/dist/src/service/compose-sqlite.d.ts +2 -0
- package/dist/src/service/compose-sqlite.js +11 -0
- package/dist/src/service/create-remit-client.d.ts +95 -0
- package/dist/src/service/create-remit-client.js +207 -0
- package/dist/src/service/data-client.d.ts +12 -0
- package/dist/src/service/data-client.js +44 -0
- package/dist/src/service/export-identity.d.ts +3 -0
- package/dist/src/service/export-identity.js +35 -0
- package/dist/src/service/fire-and-forget.d.ts +54 -0
- package/dist/src/service/fire-and-forget.js +38 -0
- package/dist/src/service/organize.d.ts +184 -0
- package/dist/src/service/organize.js +384 -0
- package/dist/src/service/refusal.d.ts +4 -0
- package/dist/src/service/refusal.js +20 -0
- package/dist/src/service/sender-category.d.ts +51 -0
- package/{src/service/sender-category.ts → dist/src/service/sender-category.js} +40 -81
- package/dist/src/service/sqs.d.ts +1 -0
- package/{src/service/sqs.ts → dist/src/service/sqs.js} +0 -1
- package/dist/src/service/trigger-sync.d.ts +51 -0
- package/dist/src/service/trigger-sync.js +39 -0
- package/dist/src/types.d.ts +49 -0
- package/dist/src/types.js +1 -0
- package/package.json +113 -98
- package/.env.test +0 -4
- package/dev-server/content-auth.test.ts +0 -113
- package/dev-server/content-auth.ts +0 -54
- package/dev-server/content-handler.test.ts +0 -105
- package/dev-server/content-handler.ts +0 -79
- package/dev-server/content-path.test.ts +0 -37
- package/dev-server/content-path.ts +0 -27
- package/dev-server/cors.test.ts +0 -48
- package/dev-server/cors.ts +0 -25
- package/dev-server/keep-alive.test.ts +0 -24
- package/dev-server/lambda-helpers.ts +0 -69
- package/dev-server/log-output.test.ts +0 -173
- package/dev-server/oauth-callback-route.test.ts +0 -66
- package/dev-server/relational-health.test.ts +0 -83
- package/dev-server/relational-health.ts +0 -39
- package/dev-server/server.ts +0 -384
- package/dev-server/sync-age.test.ts +0 -91
- package/dev-server/sync-age.ts +0 -55
- package/dev-server/upload-handler.ts +0 -132
- package/dev-server/upload-route.test.ts +0 -196
- package/scripts/backfill-classification.ts +0 -91
- package/scripts/backfill-list-id.ts +0 -83
- package/scripts/config-save.ts +0 -128
- package/src/auth.test.ts +0 -12
- package/src/auth.ts +0 -92
- package/src/config/msoauth.test.ts +0 -48
- package/src/config/msoauth.ts +0 -48
- package/src/data-backend.test.ts +0 -23
- package/src/derive/autoMoved.test.ts +0 -104
- package/src/derive/contentSignature.test.ts +0 -161
- package/src/derive/contentUrl.test.ts +0 -172
- package/src/derive/contentUrl.ts +0 -86
- package/src/derive/deriveMuted.test.ts +0 -34
- package/src/derive/enrichThreadRows.test.ts +0 -360
- package/src/derive/enrichThreadRows.ts +0 -234
- package/src/derive/filterThreadCriteria.test.ts +0 -126
- package/src/derive/filterThreadCriteria.ts +0 -51
- package/src/derive/senderTrust.test.ts +0 -67
- package/src/error.test.ts +0 -201
- package/src/error.ts +0 -123
- package/src/handlers/account-guards.test.ts +0 -67
- package/src/handlers/account-guards.ts +0 -169
- package/src/handlers/account-oauth-callback.test.ts +0 -155
- package/src/handlers/account-oauth-consent.test.ts +0 -336
- package/src/handlers/account-oauth-start.test.ts +0 -191
- package/src/handlers/account-oauth.test.ts +0 -439
- package/src/handlers/account-oauth.ts +0 -635
- package/src/handlers/account-overrides.test.ts +0 -88
- package/src/handlers/account-overrides.ts +0 -323
- package/src/handlers/account-ownership.ts +0 -25
- package/src/handlers/account-signature.ts +0 -117
- package/src/handlers/account-synced-services.test.ts +0 -245
- package/src/handlers/account.ts +0 -552
- package/src/handlers/address.test.ts +0 -381
- package/src/handlers/address.ts +0 -200
- package/src/handlers/calendar-event.test.ts +0 -685
- package/src/handlers/calendar-event.ts +0 -738
- package/src/handlers/calendar-feed-validators.test.ts +0 -228
- package/src/handlers/calendar-feed.test.ts +0 -439
- package/src/handlers/calendar-feed.ts +0 -291
- package/src/handlers/calendar-sqlite-fixture.ts +0 -36
- package/src/handlers/calendar-suggestion.test.ts +0 -1269
- package/src/handlers/calendar-suggestion.ts +0 -425
- package/src/handlers/calendar.test.ts +0 -1080
- package/src/handlers/calendar.ts +0 -517
- package/src/handlers/config.test.ts +0 -245
- package/src/handlers/config.ts +0 -332
- package/src/handlers/ensure-account-config.ts +0 -30
- package/src/handlers/filter.test.ts +0 -644
- package/src/handlers/filter.ts +0 -518
- package/src/handlers/folder-role-appointments.test.ts +0 -438
- package/src/handlers/folder-role-appointments.ts +0 -249
- package/src/handlers/folder-role-labels.ts +0 -63
- package/src/handlers/folder-role.test.ts +0 -209
- package/src/handlers/folder-role.ts +0 -80
- package/src/handlers/index.ts +0 -83
- package/src/handlers/label.test.ts +0 -112
- package/src/handlers/label.ts +0 -210
- package/src/handlers/mailbox-bindings.ts +0 -111
- package/src/handlers/mailbox-rename-refusal.test.ts +0 -247
- package/src/handlers/mailbox-settled-target.test.ts +0 -251
- package/src/handlers/mailbox.test.ts +0 -280
- package/src/handlers/mailbox.ts +0 -581
- package/src/handlers/me.test.ts +0 -81
- package/src/handlers/me.ts +0 -203
- package/src/handlers/message-read-backfill.test.ts +0 -103
- package/src/handlers/message.test.ts +0 -131
- package/src/handlers/message.ts +0 -1131
- package/src/handlers/organize.test.ts +0 -277
- package/src/handlers/organize.ts +0 -197
- package/src/handlers/outbox-attachment.test.ts +0 -765
- package/src/handlers/outbox-attachment.ts +0 -126
- package/src/handlers/outbox-list.test.ts +0 -179
- package/src/handlers/outbox.test.ts +0 -772
- package/src/handlers/outbox.ts +0 -258
- package/src/handlers/search.test.ts +0 -161
- package/src/handlers/search.ts +0 -105
- package/src/handlers/sync-progress.test.ts +0 -205
- package/src/handlers/sync-progress.ts +0 -99
- package/src/handlers/sync.test.ts +0 -168
- package/src/handlers/sync.ts +0 -118
- package/src/handlers/system-update.test.ts +0 -497
- package/src/handlers/system-update.ts +0 -230
- package/src/handlers/thread.test.ts +0 -396
- package/src/handlers/thread.ts +0 -427
- package/src/handlers/unified-threads-mail-sources.sqlite.test.ts +0 -197
- package/src/handlers/unified-threads.test.ts +0 -785
- package/src/handlers/unified-threads.ts +0 -669
- package/src/index.test.ts +0 -83
- package/src/index.ts +0 -228
- package/src/jwt-auth.test.ts +0 -152
- package/src/jwt-auth.ts +0 -132
- package/src/log-redaction.test.ts +0 -144
- package/src/openapi-spec.test.ts +0 -118
- package/src/request-context.test.ts +0 -61
- package/src/request-context.ts +0 -33
- package/src/request-pipeline.test.ts +0 -88
- package/src/request.ts +0 -10
- package/src/response.test.ts +0 -130
- package/src/response.ts +0 -144
- package/src/service/compose-sqlite.ts +0 -98
- package/src/service/config-import.ts +0 -39
- package/src/service/create-remit-client.ts +0 -521
- package/src/service/data-client.test.ts +0 -97
- package/src/service/data-client.ts +0 -58
- package/src/service/export-identity.ts +0 -39
- package/src/service/filter.ts +0 -40
- package/src/service/fire-and-forget.test.ts +0 -126
- package/src/service/fire-and-forget.ts +0 -79
- package/src/service/localhost-env-config.test.ts +0 -36
- package/src/service/organize-queue.ts +0 -98
- package/src/service/organize.test.ts +0 -1451
- package/src/service/organize.ts +0 -1025
- package/src/service/read-path-filter-config.test.ts +0 -243
- package/src/service/semantic-capability.test.ts +0 -78
- package/src/service/semantic-capability.ts +0 -95
- package/src/service/sender-category.test.ts +0 -235
- package/src/service/trigger-sync.test.ts +0 -205
- package/src/service/trigger-sync.ts +0 -100
- package/src/stdout-capture-fixture.ts +0 -40
- package/src/types.ts +0 -271
- package/tsconfig.json +0 -7
package/src/handlers/me.ts
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { SendMessageCommand } from "@aws-sdk/client-sqs";
|
|
2
|
-
import type {
|
|
3
|
-
AccountExportRequestResponse,
|
|
4
|
-
CreateExportResponse,
|
|
5
|
-
DeleteAccountConfigResponse,
|
|
6
|
-
DeleteMeInput,
|
|
7
|
-
QuarantineListResponse,
|
|
8
|
-
VipSuggestionsResponse,
|
|
9
|
-
} from "@remit/api-openapi-types";
|
|
10
|
-
import { BadRequestError, NotFoundError } from "@remit/data-ports/errors";
|
|
11
|
-
import { logger } from "@remit/logger-lambda";
|
|
12
|
-
import type { APIGatewayProxyEvent } from "aws-lambda";
|
|
13
|
-
import { env } from "expect-env";
|
|
14
|
-
import type { Context } from "openapi-backend";
|
|
15
|
-
import { getAccountConfigIdFromEvent, getSubFromEvent } from "../auth.js";
|
|
16
|
-
import { getClient } from "../service/data-client.js";
|
|
17
|
-
import { sqsClient } from "../service/sqs.js";
|
|
18
|
-
import type { MeOperationIds, OperationHandler } from "../types.js";
|
|
19
|
-
import { toVipSuggestionEntry } from "./vip-suggestions.js";
|
|
20
|
-
|
|
21
|
-
const DOWNLOAD_URL_TTL_SECONDS = 60 * 60;
|
|
22
|
-
|
|
23
|
-
export const MeOperations: Record<
|
|
24
|
-
MeOperationIds,
|
|
25
|
-
OperationHandler<MeOperationIds>
|
|
26
|
-
> = {
|
|
27
|
-
MeOperations_listVipSuggestions: async (
|
|
28
|
-
_context: Context,
|
|
29
|
-
...args: unknown[]
|
|
30
|
-
): Promise<VipSuggestionsResponse> => {
|
|
31
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
32
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
33
|
-
|
|
34
|
-
const { address } = await getClient();
|
|
35
|
-
const items = await address.listSuggestedVips({ accountConfigId });
|
|
36
|
-
|
|
37
|
-
return { suggestions: items.map(toVipSuggestionEntry) };
|
|
38
|
-
},
|
|
39
|
-
MeOperations_listQuarantine: async (
|
|
40
|
-
_context: Context,
|
|
41
|
-
...args: unknown[]
|
|
42
|
-
): Promise<QuarantineListResponse> => {
|
|
43
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
44
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
45
|
-
|
|
46
|
-
const { quarantine } = await getClient();
|
|
47
|
-
const entries = await quarantine.listByAccountConfigId(accountConfigId);
|
|
48
|
-
|
|
49
|
-
return { entries };
|
|
50
|
-
},
|
|
51
|
-
MeOperations_deleteMe: async (
|
|
52
|
-
_context: Context,
|
|
53
|
-
...args: unknown[]
|
|
54
|
-
): Promise<DeleteAccountConfigResponse> => {
|
|
55
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
56
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
57
|
-
|
|
58
|
-
const { confirmEmail } = JSON.parse(
|
|
59
|
-
event.body ?? "{}",
|
|
60
|
-
) as Partial<DeleteMeInput>;
|
|
61
|
-
const callerEmail = event.requestContext?.authorizer?.claims?.email as
|
|
62
|
-
| string
|
|
63
|
-
| undefined;
|
|
64
|
-
|
|
65
|
-
if (typeof confirmEmail !== "string" || confirmEmail.trim() === "") {
|
|
66
|
-
throw new BadRequestError("confirmEmail is required");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!callerEmail) {
|
|
70
|
-
throw new BadRequestError("Account email claim missing from token");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (confirmEmail.toLowerCase() !== callerEmail.toLowerCase()) {
|
|
74
|
-
throw new BadRequestError(
|
|
75
|
-
"confirmEmail does not match your account email",
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const { accountConfig } = await getClient();
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
await accountConfig.update(accountConfigId, {
|
|
83
|
-
state: "deleting",
|
|
84
|
-
deletedAt: Date.now(),
|
|
85
|
-
});
|
|
86
|
-
} catch (err: unknown) {
|
|
87
|
-
// If already in "deleting" state, treat as idempotent
|
|
88
|
-
if (
|
|
89
|
-
err instanceof Error &&
|
|
90
|
-
(err.name === "ConditionalCheckFailedException" ||
|
|
91
|
-
err.message.includes("ConditionalCheckFailed"))
|
|
92
|
-
) {
|
|
93
|
-
return {
|
|
94
|
-
statusCode: 202,
|
|
95
|
-
message: "Account deletion already in progress",
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
throw err;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const queueUrl = env.SQS_QUEUE_URL_ACCOUNT_FANOUT;
|
|
102
|
-
|
|
103
|
-
await sqsClient.send(
|
|
104
|
-
new SendMessageCommand({
|
|
105
|
-
QueueUrl: queueUrl,
|
|
106
|
-
MessageBody: JSON.stringify({
|
|
107
|
-
type: "AccountDelete",
|
|
108
|
-
accountConfigId,
|
|
109
|
-
}),
|
|
110
|
-
}),
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// biome-ignore lint/plugin/no-logger-info: account deletion is an audit-grade signal
|
|
114
|
-
logger.info({ accountConfigId }, "Account deletion initiated");
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
statusCode: 202,
|
|
118
|
-
message: "Account deletion initiated",
|
|
119
|
-
};
|
|
120
|
-
},
|
|
121
|
-
MeOperations_createExport: async (
|
|
122
|
-
_context: Context,
|
|
123
|
-
...args: unknown[]
|
|
124
|
-
): Promise<CreateExportResponse> => {
|
|
125
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
126
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
127
|
-
const userId = getSubFromEvent(event);
|
|
128
|
-
|
|
129
|
-
if (!userId) {
|
|
130
|
-
throw new Error(
|
|
131
|
-
"Missing Cognito `sub`: cannot attribute an export request to a user",
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const { accountExportRequest } = await getClient();
|
|
136
|
-
const exportRequest = await accountExportRequest.create({
|
|
137
|
-
accountConfigId,
|
|
138
|
-
userId,
|
|
139
|
-
state: "Pending",
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
await sqsClient.send(
|
|
143
|
-
new SendMessageCommand({
|
|
144
|
-
QueueUrl: env.SQS_QUEUE_URL_ACCOUNT_FANOUT,
|
|
145
|
-
MessageBody: JSON.stringify({
|
|
146
|
-
type: "AccountExport",
|
|
147
|
-
accountConfigId,
|
|
148
|
-
accountExportRequestId: exportRequest.accountExportRequestId,
|
|
149
|
-
}),
|
|
150
|
-
}),
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
// biome-ignore lint/plugin/no-logger-info: account export is an audit-grade signal
|
|
154
|
-
logger.info(
|
|
155
|
-
{
|
|
156
|
-
accountConfigId,
|
|
157
|
-
accountExportRequestId: exportRequest.accountExportRequestId,
|
|
158
|
-
},
|
|
159
|
-
"Account export initiated",
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
statusCode: 202,
|
|
164
|
-
exportId: exportRequest.accountExportRequestId,
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
MeOperations_getExport: async (
|
|
168
|
-
context: Context,
|
|
169
|
-
...args: unknown[]
|
|
170
|
-
): Promise<AccountExportRequestResponse> => {
|
|
171
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
172
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
173
|
-
const exportId = context.request.params.exportId as string;
|
|
174
|
-
|
|
175
|
-
const { accountExportRequest, storage } = await getClient();
|
|
176
|
-
const exportRequest = await accountExportRequest.get(exportId);
|
|
177
|
-
|
|
178
|
-
if (exportRequest.accountConfigId !== accountConfigId) {
|
|
179
|
-
throw new NotFoundError(`Export not found: ${exportId}`);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const downloadUrl =
|
|
183
|
-
exportRequest.state === "Ready" && exportRequest.objectKey
|
|
184
|
-
? await storage.getPresignedDownloadUrl(
|
|
185
|
-
exportRequest.objectKey,
|
|
186
|
-
DOWNLOAD_URL_TTL_SECONDS,
|
|
187
|
-
)
|
|
188
|
-
: undefined;
|
|
189
|
-
|
|
190
|
-
return {
|
|
191
|
-
accountExportRequestId: exportRequest.accountExportRequestId,
|
|
192
|
-
accountConfigId: exportRequest.accountConfigId,
|
|
193
|
-
userId: exportRequest.userId,
|
|
194
|
-
state: exportRequest.state,
|
|
195
|
-
createdAt: exportRequest.createdAt,
|
|
196
|
-
updatedAt: exportRequest.updatedAt,
|
|
197
|
-
objectKey: exportRequest.objectKey,
|
|
198
|
-
downloadUrl,
|
|
199
|
-
expiresAt: exportRequest.expiresAt,
|
|
200
|
-
errorMessage: exportRequest.errorMessage,
|
|
201
|
-
};
|
|
202
|
-
},
|
|
203
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { afterEach, describe, it } from "node:test";
|
|
3
|
-
import type { APIGatewayProxyEvent } from "aws-lambda";
|
|
4
|
-
import type { Context } from "openapi-backend";
|
|
5
|
-
import {
|
|
6
|
-
_resetForTest,
|
|
7
|
-
type RemitClient,
|
|
8
|
-
setClient,
|
|
9
|
-
} from "../service/data-client.js";
|
|
10
|
-
import { MessageOperations } from "./message.js";
|
|
11
|
-
|
|
12
|
-
type Handler = (
|
|
13
|
-
context: Context,
|
|
14
|
-
event: APIGatewayProxyEvent,
|
|
15
|
-
) => Promise<unknown>;
|
|
16
|
-
|
|
17
|
-
const describeMessage =
|
|
18
|
-
MessageOperations.MessageOperations_describeMessage as unknown as Handler;
|
|
19
|
-
const getRawMessage =
|
|
20
|
-
MessageOperations.MessageOperations_getRawMessage as unknown as Handler;
|
|
21
|
-
|
|
22
|
-
const MESSAGE_ID = "msg-1";
|
|
23
|
-
const MAILBOX_ID = "mb-1";
|
|
24
|
-
const ACCOUNT_ID = "acc-1";
|
|
25
|
-
|
|
26
|
-
const event = {
|
|
27
|
-
requestContext: { authorizer: { claims: { sub: "sub-610" } } },
|
|
28
|
-
} as unknown as APIGatewayProxyEvent;
|
|
29
|
-
|
|
30
|
-
const context = {
|
|
31
|
-
request: { params: { messageId: MESSAGE_ID } },
|
|
32
|
-
} as unknown as Context;
|
|
33
|
-
|
|
34
|
-
const unstoredMessage = {
|
|
35
|
-
messageId: MESSAGE_ID,
|
|
36
|
-
mailboxId: MAILBOX_ID,
|
|
37
|
-
uid: 7,
|
|
38
|
-
internalDate: 1,
|
|
39
|
-
status: "active",
|
|
40
|
-
syncStatus: "synced",
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const mailboxRow = {
|
|
44
|
-
mailboxId: MAILBOX_ID,
|
|
45
|
-
accountId: ACCOUNT_ID,
|
|
46
|
-
fullPath: "Junk",
|
|
47
|
-
cursorState: "normal",
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const clientWithFailingFolderLookup = (opened: string[]): RemitClient =>
|
|
51
|
-
({
|
|
52
|
-
message: {
|
|
53
|
-
get: async () => unstoredMessage,
|
|
54
|
-
describe: async () => ({
|
|
55
|
-
message: [unstoredMessage],
|
|
56
|
-
envelope: [],
|
|
57
|
-
envelopeAddress: [],
|
|
58
|
-
messageFlag: [],
|
|
59
|
-
bodyPart: [],
|
|
60
|
-
messageReference: [],
|
|
61
|
-
}),
|
|
62
|
-
},
|
|
63
|
-
messageLabel: { listByMessageId: async () => [] },
|
|
64
|
-
account: {
|
|
65
|
-
listAllByAccountConfig: async () => [{ accountId: ACCOUNT_ID }],
|
|
66
|
-
},
|
|
67
|
-
mailbox: {
|
|
68
|
-
get: async (_accountId: string, ids: string | string[]) =>
|
|
69
|
-
Array.isArray(ids) ? [mailboxRow] : mailboxRow,
|
|
70
|
-
},
|
|
71
|
-
storage: { bodyPartExists: async () => false },
|
|
72
|
-
mailboxSpecialUse: {
|
|
73
|
-
findJunkMailbox: async () => {
|
|
74
|
-
throw new Error("special-use lookup timed out");
|
|
75
|
-
},
|
|
76
|
-
findInboxMailbox: async () => null,
|
|
77
|
-
},
|
|
78
|
-
createConnectionScope: async (accountId: string) => {
|
|
79
|
-
opened.push(accountId);
|
|
80
|
-
return {
|
|
81
|
-
getConnection: async () => ({}),
|
|
82
|
-
disconnect: async () => {},
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
}) as unknown as RemitClient;
|
|
86
|
-
|
|
87
|
-
describe("reading an unstored message when the folder lookup fails", () => {
|
|
88
|
-
afterEach(() => _resetForTest());
|
|
89
|
-
|
|
90
|
-
for (const [name, handler] of [
|
|
91
|
-
["describeMessage", describeMessage],
|
|
92
|
-
["getRawMessage", getRawMessage],
|
|
93
|
-
] as const) {
|
|
94
|
-
it(`${name} opens no IMAP connection`, async () => {
|
|
95
|
-
const opened: string[] = [];
|
|
96
|
-
setClient(clientWithFailingFolderLookup(opened));
|
|
97
|
-
|
|
98
|
-
await assert.rejects(handler(context, event), /special-use lookup/);
|
|
99
|
-
|
|
100
|
-
assert.deepEqual(opened, []);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
});
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import { MessagePlacementUnsettledError } from "@remit/data-ports/errors";
|
|
4
|
-
import {
|
|
5
|
-
MoveNotSettledError,
|
|
6
|
-
NoJunkMailboxError,
|
|
7
|
-
} from "@remit/mailbox-service";
|
|
8
|
-
import { GENERIC_FAILURE_REASON, settleSpamReportBulk } from "./message.js";
|
|
9
|
-
|
|
10
|
-
describe("settleSpamReportBulk", () => {
|
|
11
|
-
it("aggregates successes and failures, surfacing the one allowlisted reason verbatim", async () => {
|
|
12
|
-
const outcome = await settleSpamReportBulk(
|
|
13
|
-
["msg-1", "msg-2", "msg-3"],
|
|
14
|
-
async (messageId) => {
|
|
15
|
-
if (messageId === "msg-2") {
|
|
16
|
-
throw new MoveNotSettledError(messageId);
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
assert.equal(outcome.successCount, 2);
|
|
22
|
-
assert.equal(outcome.failureCount, 1);
|
|
23
|
-
assert.deepEqual(outcome.failures, [
|
|
24
|
-
{
|
|
25
|
-
messageId: "msg-2",
|
|
26
|
-
reason:
|
|
27
|
-
"Message msg-2's move to Junk has not settled yet; try again in a moment.",
|
|
28
|
-
},
|
|
29
|
-
]);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("tells the user to create the missing Junk folder rather than to try again", async () => {
|
|
33
|
-
// Retrying cannot resolve this one, so the generic retry copy would be a
|
|
34
|
-
// dead end. The service's own text names the folder and the fix.
|
|
35
|
-
const outcome = await settleSpamReportBulk(["msg-1"], async () => {
|
|
36
|
-
throw new NoJunkMailboxError();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const reason = outcome.failures?.[0].reason ?? "";
|
|
40
|
-
assert.match(reason, /no Junk folder/);
|
|
41
|
-
assert.match(reason, /Create one/);
|
|
42
|
-
assert.notEqual(reason, GENERIC_FAILURE_REASON);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// A refusal the move gate raises used to collapse to the generic retry copy,
|
|
46
|
-
// which is a dead end (#665). One reason reaches it now — a mutation still in
|
|
47
|
-
// flight — and it words the wait rather than the server's sentence.
|
|
48
|
-
it("words a placement refusal from its reason, never from the server's sentence", async () => {
|
|
49
|
-
const outcome = await settleSpamReportBulk(
|
|
50
|
-
["msg-1", "msg-2"],
|
|
51
|
-
async (messageId) => {
|
|
52
|
-
throw new MessagePlacementUnsettledError(
|
|
53
|
-
`Message ${messageId} was not acted on: its folder and uid do not name the same message`,
|
|
54
|
-
"acc-1",
|
|
55
|
-
messageId,
|
|
56
|
-
"in_flight",
|
|
57
|
-
);
|
|
58
|
-
},
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const reasons = outcome.failures?.map((f) => f.reason) ?? [];
|
|
62
|
-
assert.equal(reasons.length, 2);
|
|
63
|
-
for (const reason of reasons) {
|
|
64
|
-
assert.match(reason ?? "", /try again in a moment/i);
|
|
65
|
-
assert.notEqual(reason, GENERIC_FAILURE_REASON);
|
|
66
|
-
assert.doesNotMatch(reason ?? "", /folder and uid/);
|
|
67
|
-
assert.doesNotMatch(reason ?? "", /acc-1/);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("omits failures entirely when every message succeeds", async () => {
|
|
72
|
-
const outcome = await settleSpamReportBulk(
|
|
73
|
-
["msg-1", "msg-2"],
|
|
74
|
-
async () => {},
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
assert.equal(outcome.successCount, 2);
|
|
78
|
-
assert.equal(outcome.failureCount, 0);
|
|
79
|
-
assert.equal(outcome.failures, undefined);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// The response is user-facing (the field is documented as shown as-is) and
|
|
83
|
-
// this is a 200, not an error path guarded by error.ts's own flattening —
|
|
84
|
-
// so this is the one place a raw internal message could otherwise leak: an
|
|
85
|
-
// account id in "No Junk mailbox found for account <id>", a message id in
|
|
86
|
-
// "has no From address to act on", or an AWS SDK message naming a queue
|
|
87
|
-
// URL or ECONNREFUSED host:port on an SQS failure.
|
|
88
|
-
it("never puts an arbitrary error's raw text in the response — only the allowlisted reason ships", async () => {
|
|
89
|
-
const outcome = await settleSpamReportBulk(
|
|
90
|
-
["msg-leaky-error", "msg-leaky-string", "msg-settled-ok"],
|
|
91
|
-
async (messageId) => {
|
|
92
|
-
if (messageId === "msg-leaky-error") {
|
|
93
|
-
throw new Error(
|
|
94
|
-
"No Junk mailbox found for account acc-super-secret-internal-id",
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
if (messageId === "msg-leaky-string") {
|
|
98
|
-
return Promise.reject("ECONNREFUSED sqs.us-east-1.amazonaws.com:443");
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
assert.equal(outcome.failureCount, 2);
|
|
104
|
-
const reasons = outcome.failures?.map((f) => f.reason) ?? [];
|
|
105
|
-
assert.deepEqual(reasons, [GENERIC_FAILURE_REASON, GENERIC_FAILURE_REASON]);
|
|
106
|
-
|
|
107
|
-
const leaked = reasons.some(
|
|
108
|
-
(reason) =>
|
|
109
|
-
reason.includes("acc-super-secret-internal-id") ||
|
|
110
|
-
reason.includes("ECONNREFUSED") ||
|
|
111
|
-
reason.includes("amazonaws.com"),
|
|
112
|
-
);
|
|
113
|
-
assert.equal(leaked, false, "no internal detail may reach the response");
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("runs every message concurrently — total time is one wait, not N waits", async () => {
|
|
117
|
-
const WAIT_MS = 60;
|
|
118
|
-
const start = Date.now();
|
|
119
|
-
|
|
120
|
-
await settleSpamReportBulk(
|
|
121
|
-
Array.from({ length: 10 }, (_, i) => `msg-${i}`),
|
|
122
|
-
() => new Promise((resolve) => setTimeout(resolve, WAIT_MS)),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const elapsed = Date.now() - start;
|
|
126
|
-
assert.ok(
|
|
127
|
-
elapsed < WAIT_MS * 5,
|
|
128
|
-
`expected roughly one wait (~${WAIT_MS}ms), took ${elapsed}ms — looks sequential`,
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
});
|