@remit/backend 0.0.143 → 0.0.145
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 +5 -0
- package/dist/src/api.js +73 -0
- package/dist/src/auth.d.ts +24 -0
- package/dist/src/auth.js +81 -0
- package/dist/src/config/api-config.d.ts +20 -0
- package/dist/src/config/api-config.js +1 -0
- package/dist/src/config/from-env.d.ts +2 -0
- package/dist/src/config/from-env.js +65 -0
- package/dist/src/config/msoauth-secrets-manager.d.ts +2 -0
- package/dist/src/config/msoauth-secrets-manager.js +28 -0
- package/dist/src/config/msoauth.d.ts +19 -0
- package/dist/src/config/msoauth.js +6 -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 +40 -0
- package/{src/derive/contentSignature.ts → dist/src/derive/contentSignature.js} +23 -77
- package/dist/src/derive/contentUrl.d.ts +33 -0
- package/dist/src/derive/contentUrl.js +27 -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 +15 -0
- package/dist/src/handlers/account-oauth.js +334 -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 +7 -0
- package/dist/src/handlers/account.js +337 -0
- package/dist/src/handlers/address.d.ts +35 -0
- package/dist/src/handlers/address.js +133 -0
- package/dist/src/handlers/calendar-event.d.ts +70 -0
- package/dist/src/handlers/calendar-event.js +417 -0
- package/dist/src/handlers/calendar-feed.d.ts +47 -0
- package/dist/src/handlers/calendar-feed.js +184 -0
- package/dist/src/handlers/calendar-suggestion.d.ts +47 -0
- package/dist/src/handlers/calendar-suggestion.js +204 -0
- package/dist/src/handlers/calendar.d.ts +116 -0
- package/dist/src/handlers/calendar.js +323 -0
- package/dist/src/handlers/config.d.ts +43 -0
- package/dist/src/handlers/config.js +164 -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 +88 -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 +37 -0
- package/dist/src/handlers/index.d.ts +88 -0
- package/dist/src/handlers/index.js +62 -0
- package/dist/src/handlers/label.d.ts +43 -0
- package/dist/src/handlers/label.js +107 -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 +211 -0
- package/dist/src/handlers/me.d.ts +2 -0
- package/dist/src/handlers/me.js +117 -0
- package/dist/src/handlers/message.d.ts +82 -0
- package/dist/src/handlers/message.js +595 -0
- package/dist/src/handlers/organize.d.ts +10 -0
- package/dist/src/handlers/organize.js +103 -0
- package/dist/src/handlers/outbox-attachment.d.ts +25 -0
- package/dist/src/handlers/outbox-attachment.js +77 -0
- package/dist/src/handlers/outbox.d.ts +4 -0
- package/dist/src/handlers/outbox.js +136 -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 +73 -0
- package/dist/src/handlers/system-update.d.ts +2 -0
- package/dist/src/handlers/system-update.js +159 -0
- package/dist/src/handlers/thread.d.ts +148 -0
- package/dist/src/handlers/thread.js +228 -0
- package/dist/src/handlers/unified-threads.d.ts +247 -0
- package/dist/src/handlers/unified-threads.js +406 -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 +5 -0
- package/dist/src/index.js +53 -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 +15 -0
- package/dist/src/jwt-auth.js +45 -0
- package/dist/src/lambda.d.ts +13 -0
- package/dist/src/lambda.js +33 -0
- package/dist/src/request.d.ts +9 -0
- package/dist/src/request.js +17 -0
- package/dist/src/response.d.ts +44 -0
- package/dist/src/response.js +80 -0
- package/dist/src/serve.d.ts +31 -0
- package/dist/src/serve.js +117 -0
- package/dist/src/service/account-deletion.d.ts +20 -0
- package/dist/src/service/account-deletion.js +33 -0
- package/dist/src/service/compose-sqlite.d.ts +3 -0
- package/dist/src/service/compose-sqlite.js +13 -0
- package/dist/src/service/create-remit-client.d.ts +109 -0
- package/dist/src/service/create-remit-client.js +188 -0
- package/dist/src/service/data-client.d.ts +12 -0
- package/dist/src/service/data-client.js +42 -0
- package/dist/src/service/export-identity.d.ts +4 -0
- package/dist/src/service/export-identity.js +33 -0
- package/dist/src/service/fire-and-forget.d.ts +54 -0
- package/dist/src/service/fire-and-forget.js +37 -0
- package/dist/src/service/organize.d.ts +181 -0
- package/dist/src/service/organize.js +367 -0
- package/dist/src/service/queues.d.ts +12 -0
- package/dist/src/service/queues.js +1 -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/shared-deps.d.ts +6 -0
- package/dist/src/service/shared-deps.js +24 -0
- package/dist/src/service/trigger-sync.d.ts +57 -0
- package/dist/src/service/trigger-sync.js +31 -0
- package/dist/src/types.d.ts +72 -0
- package/dist/src/types.js +1 -0
- package/package.json +125 -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/data-backend.ts +0 -14
- 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 -522
- 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/sqs.ts +0 -4
- 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
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { IAccountSettingRepository } from "@remit/data-ports";
|
|
2
|
-
import {
|
|
3
|
-
type CanonicalMailboxRoleValue,
|
|
4
|
-
composeFolderRoleAppointmentLabelName,
|
|
5
|
-
} from "@remit/data-ports/folder-role";
|
|
6
|
-
import { rebaseMailboxPath } from "@remit/data-ports/mailbox-name";
|
|
7
|
-
import { loadFolderAppointmentsForAccount } from "./folder-role-appointments.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The label row beside each role appointment records the path its folder had at
|
|
11
|
-
* the time (#887), so a folder another client later deletes can still be named
|
|
12
|
-
* back to the user. It is display only, and it lives here rather than beside
|
|
13
|
-
* the appointment writer because that writer is guarded as the only writer of
|
|
14
|
-
* the appointment row itself.
|
|
15
|
-
*
|
|
16
|
-
* A rename keeps every mailboxId, so an appointment survives it — but the path
|
|
17
|
-
* recorded beside it still names where the folder was. Move the labels with the
|
|
18
|
-
* branch, or a later third-party delete names a path the user has not seen
|
|
19
|
-
* since the rename.
|
|
20
|
-
*
|
|
21
|
-
* Driven by the settle, not by the intent: under D2 the row keeps the path the
|
|
22
|
-
* mail server holds until the rename lands, so a label moved when the intent
|
|
23
|
-
* was recorded would name a path that does not exist — permanently, if the
|
|
24
|
-
* rename then fails.
|
|
25
|
-
*
|
|
26
|
-
* The renamed folder is matched by id; its descendants are matched by the path
|
|
27
|
-
* each label already holds.
|
|
28
|
-
*/
|
|
29
|
-
export const refreshFolderAppointmentLabels = async (
|
|
30
|
-
accountSetting: Pick<IAccountSettingRepository, "get" | "upsert">,
|
|
31
|
-
accountConfigId: string,
|
|
32
|
-
accountId: string,
|
|
33
|
-
renamed: { mailboxId: string; oldPath: string; newPath: string },
|
|
34
|
-
delimiter: string,
|
|
35
|
-
): Promise<void> => {
|
|
36
|
-
const persisted = await loadFolderAppointmentsForAccount(
|
|
37
|
-
accountSetting,
|
|
38
|
-
accountConfigId,
|
|
39
|
-
accountId,
|
|
40
|
-
);
|
|
41
|
-
for (const [role, appointment] of persisted) {
|
|
42
|
-
const moved =
|
|
43
|
-
appointment.mailboxId === renamed.mailboxId
|
|
44
|
-
? renamed.newPath
|
|
45
|
-
: appointment.lastKnownPath === undefined
|
|
46
|
-
? undefined
|
|
47
|
-
: rebaseMailboxPath(
|
|
48
|
-
appointment.lastKnownPath,
|
|
49
|
-
renamed.oldPath,
|
|
50
|
-
renamed.newPath,
|
|
51
|
-
delimiter,
|
|
52
|
-
);
|
|
53
|
-
if (moved === undefined || moved === appointment.lastKnownPath) continue;
|
|
54
|
-
await accountSetting.upsert({
|
|
55
|
-
accountConfigId,
|
|
56
|
-
name: composeFolderRoleAppointmentLabelName(
|
|
57
|
-
accountId,
|
|
58
|
-
role as CanonicalMailboxRoleValue,
|
|
59
|
-
),
|
|
60
|
-
value: { kind: "String", value: moved },
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import type { AccountSettingItem, MailboxItem } from "@remit/data-ports";
|
|
4
|
-
import { isPublicApiError } from "@remit/data-ports/errors";
|
|
5
|
-
import { composeFolderRoleAppointmentLabelName } from "@remit/data-ports/folder-role";
|
|
6
|
-
import { CanonicalMailboxRole, MailboxSyncStatus } from "@remit/domain-enums";
|
|
7
|
-
import { refreshFolderAppointmentLabels } from "./folder-role-labels.js";
|
|
8
|
-
import { assertMailboxSettled } from "./mailbox.js";
|
|
9
|
-
|
|
10
|
-
const mailbox = (over: Partial<MailboxItem>): MailboxItem =>
|
|
11
|
-
({
|
|
12
|
-
mailboxId: "mb-1",
|
|
13
|
-
fullPath: "INBOX/Prullenbak",
|
|
14
|
-
hierarchyDelimiter: "/",
|
|
15
|
-
...over,
|
|
16
|
-
}) as unknown as MailboxItem;
|
|
17
|
-
|
|
18
|
-
const caught = (run: () => void): unknown => {
|
|
19
|
-
let thrown: unknown;
|
|
20
|
-
assert.throws(run, (error: unknown) => {
|
|
21
|
-
thrown = error;
|
|
22
|
-
return true;
|
|
23
|
-
});
|
|
24
|
-
return thrown;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const publicErrorOf = (error: unknown) => {
|
|
28
|
-
if (typeof error !== "object" || error === null) return undefined;
|
|
29
|
-
const { publicApiError } = error as { publicApiError?: unknown };
|
|
30
|
-
return isPublicApiError(publicApiError) ? publicApiError : undefined;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
describe("assertMailboxSettled", () => {
|
|
34
|
-
it("refuses a folder the mail server has not created yet", () => {
|
|
35
|
-
const error = caught(() =>
|
|
36
|
-
assertMailboxSettled(mailbox({ syncStatus: MailboxSyncStatus.pending })),
|
|
37
|
-
);
|
|
38
|
-
assert.equal(publicErrorOf(error)?.code, "mailbox_not_settled");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("refuses a folder on its way out", () => {
|
|
42
|
-
const error = caught(() =>
|
|
43
|
-
assertMailboxSettled(mailbox({ syncStatus: MailboxSyncStatus.deleting })),
|
|
44
|
-
);
|
|
45
|
-
assert.equal(publicErrorOf(error)?.code, "mailbox_not_settled");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("carries the mailbox and its state, so the client words a wait", () => {
|
|
49
|
-
const error = caught(() =>
|
|
50
|
-
assertMailboxSettled(
|
|
51
|
-
mailbox({ mailboxId: "mb-9", syncStatus: MailboxSyncStatus.pending }),
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
assert.deepEqual(publicErrorOf(error)?.details, {
|
|
55
|
-
mailboxId: "mb-9",
|
|
56
|
-
syncStatus: "pending",
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("refuses a folder whose last change failed", () => {
|
|
61
|
-
// `failed` means the folder exists at `fullPath` and the last rename or
|
|
62
|
-
// delete did not land, so it is exactly as unready to be bound to as a
|
|
63
|
-
// folder mid-mutation — and the user has a retry or a dismissal to make
|
|
64
|
-
// before anything should point at it.
|
|
65
|
-
const error = caught(() =>
|
|
66
|
-
assertMailboxSettled(mailbox({ syncStatus: MailboxSyncStatus.failed })),
|
|
67
|
-
);
|
|
68
|
-
assert.equal(publicErrorOf(error)?.code, "mailbox_not_settled");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("answers 422, not 409", () => {
|
|
72
|
-
// 409 already means "this folder is being changed right now, refresh".
|
|
73
|
-
// This means "the folder you are pointing at has not settled yet", which
|
|
74
|
-
// is different copy and a different remedy (D4).
|
|
75
|
-
const error = caught(() =>
|
|
76
|
-
assertMailboxSettled(mailbox({ syncStatus: MailboxSyncStatus.pending })),
|
|
77
|
-
);
|
|
78
|
-
assert.equal((error as { statusCode?: number }).statusCode, 422);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("words each state differently, because each has its own remedy", () => {
|
|
82
|
-
const messageFor = (syncStatus: MailboxItem["syncStatus"]) =>
|
|
83
|
-
(caught(() => assertMailboxSettled(mailbox({ syncStatus }))) as Error)
|
|
84
|
-
.message;
|
|
85
|
-
|
|
86
|
-
assert.match(messageFor(MailboxSyncStatus.pending), /hasn.t confirmed it/);
|
|
87
|
-
assert.match(messageFor(MailboxSyncStatus.deleting), /being deleted/);
|
|
88
|
-
assert.match(messageFor(MailboxSyncStatus.failed), /Retry or dismiss/);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("allows a settled folder", () => {
|
|
92
|
-
assert.doesNotThrow(() =>
|
|
93
|
-
assertMailboxSettled(mailbox({ syncStatus: MailboxSyncStatus.synced })),
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe("refreshFolderAppointmentLabels — the label follows a settled rename", () => {
|
|
99
|
-
const labelName = composeFolderRoleAppointmentLabelName(
|
|
100
|
-
"acc-1",
|
|
101
|
-
CanonicalMailboxRole.Trash,
|
|
102
|
-
);
|
|
103
|
-
const sentLabelName = composeFolderRoleAppointmentLabelName(
|
|
104
|
-
"acc-1",
|
|
105
|
-
CanonicalMailboxRole.Sent,
|
|
106
|
-
);
|
|
107
|
-
const appointmentName = (role: string) =>
|
|
108
|
-
`FolderRoleAppointment#acc-1#${role}`;
|
|
109
|
-
|
|
110
|
-
const settingsFor = (
|
|
111
|
-
rows: Record<string, string>,
|
|
112
|
-
): {
|
|
113
|
-
store: Record<string, string>;
|
|
114
|
-
accountSetting: Parameters<typeof refreshFolderAppointmentLabels>[0];
|
|
115
|
-
} => {
|
|
116
|
-
const store: Record<string, string> = { ...rows };
|
|
117
|
-
const accountSetting = {
|
|
118
|
-
get: async (_configId: string, name: string) =>
|
|
119
|
-
store[name] === undefined
|
|
120
|
-
? undefined
|
|
121
|
-
: ({
|
|
122
|
-
name,
|
|
123
|
-
value: { kind: "String", value: store[name] },
|
|
124
|
-
} as AccountSettingItem),
|
|
125
|
-
upsert: async (item: AccountSettingItem) => {
|
|
126
|
-
if (item.value.kind === "String") store[item.name] = item.value.value;
|
|
127
|
-
return item;
|
|
128
|
-
},
|
|
129
|
-
} as unknown as Parameters<typeof refreshFolderAppointmentLabels>[0];
|
|
130
|
-
return { store, accountSetting };
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const settle = (
|
|
134
|
-
accountSetting: Parameters<typeof refreshFolderAppointmentLabels>[0],
|
|
135
|
-
renamed: { mailboxId: string; oldPath: string; newPath: string },
|
|
136
|
-
) =>
|
|
137
|
-
refreshFolderAppointmentLabels(
|
|
138
|
-
accountSetting,
|
|
139
|
-
"cfg-1",
|
|
140
|
-
"acc-1",
|
|
141
|
-
renamed,
|
|
142
|
-
"/",
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
it("rewrites the recorded path for the folder that was renamed", async () => {
|
|
146
|
-
const { store, accountSetting } = settingsFor({
|
|
147
|
-
[appointmentName(CanonicalMailboxRole.Trash)]: "mb-1",
|
|
148
|
-
[labelName]: "INBOX/Prullenbak",
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
await settle(accountSetting, {
|
|
152
|
-
mailboxId: "mb-1",
|
|
153
|
-
oldPath: "INBOX/Prullenbak",
|
|
154
|
-
newPath: "INBOX/Verwijderd",
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
assert.equal(store[labelName], "INBOX/Verwijderd");
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// IMAP RENAME moves the subtree in one command, so every label under the
|
|
161
|
-
// branch moves with it.
|
|
162
|
-
it("carries every appointed folder under the renamed branch with it", async () => {
|
|
163
|
-
const { store, accountSetting } = settingsFor({
|
|
164
|
-
[appointmentName(CanonicalMailboxRole.Trash)]: "mb-trash",
|
|
165
|
-
[labelName]: "INBOX/Prullenbak",
|
|
166
|
-
[appointmentName(CanonicalMailboxRole.Sent)]: "mb-sent",
|
|
167
|
-
[sentLabelName]: "INBOX/Verzonden",
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
await settle(accountSetting, {
|
|
171
|
-
mailboxId: "mb-1",
|
|
172
|
-
oldPath: "INBOX",
|
|
173
|
-
newPath: "Mail",
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
assert.equal(store[labelName], "Mail/Prullenbak");
|
|
177
|
-
assert.equal(store[sentLabelName], "Mail/Verzonden");
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("leaves a folder outside the renamed branch alone", async () => {
|
|
181
|
-
const { store, accountSetting } = settingsFor({
|
|
182
|
-
[appointmentName(CanonicalMailboxRole.Trash)]: "mb-trash",
|
|
183
|
-
[labelName]: "Archief/Prullenbak",
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
await settle(accountSetting, {
|
|
187
|
-
mailboxId: "mb-1",
|
|
188
|
-
oldPath: "INBOX",
|
|
189
|
-
newPath: "Mail",
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
assert.equal(store[labelName], "Archief/Prullenbak");
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("never rebases a sibling that merely shares the prefix", async () => {
|
|
196
|
-
const { store, accountSetting } = settingsFor({
|
|
197
|
-
[appointmentName(CanonicalMailboxRole.Trash)]: "mb-trash",
|
|
198
|
-
[labelName]: "INBOXES/Prullenbak",
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
await settle(accountSetting, {
|
|
202
|
-
mailboxId: "mb-1",
|
|
203
|
-
oldPath: "INBOX",
|
|
204
|
-
newPath: "Mail",
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
assert.equal(store[labelName], "INBOXES/Prullenbak");
|
|
208
|
-
});
|
|
209
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AppointFolderRoleInput,
|
|
3
|
-
CanonicalMailboxRole,
|
|
4
|
-
} from "@remit/api-openapi-types";
|
|
5
|
-
import type { APIGatewayProxyEvent } from "aws-lambda";
|
|
6
|
-
import { getAccountConfigIdFromEvent } from "../auth.js";
|
|
7
|
-
import { getClient } from "../service/data-client.js";
|
|
8
|
-
import type { FolderRoleOperationIds, OperationHandler } from "../types.js";
|
|
9
|
-
import { toAccountResponse } from "./account-guards.js";
|
|
10
|
-
import { loadAccountOverrides } from "./account-overrides.js";
|
|
11
|
-
import { assertAccountOwnership } from "./account-ownership.js";
|
|
12
|
-
import { loadSignatureForAccount } from "./account-signature.js";
|
|
13
|
-
import {
|
|
14
|
-
resolveAccountFolderAppointments,
|
|
15
|
-
writeFolderRoleAppointment,
|
|
16
|
-
} from "./folder-role-appointments.js";
|
|
17
|
-
import { assertMailboxInAccount, assertMailboxSettled } from "./mailbox.js";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* RFC 032 exclusive-folder-appointment (#976): the single write operation for
|
|
21
|
-
* the per-account role map. `appoint(role, mailboxId)` sets `map[role]` —
|
|
22
|
-
* there is no second place a duplicate appointment could live, so writing a
|
|
23
|
-
* role replaces whichever mailbox previously held it. `mailboxId: null` clears
|
|
24
|
-
* the role back to unfilled.
|
|
25
|
-
*/
|
|
26
|
-
export const FolderRoleOperations: Record<
|
|
27
|
-
FolderRoleOperationIds,
|
|
28
|
-
OperationHandler<FolderRoleOperationIds>
|
|
29
|
-
> = {
|
|
30
|
-
FolderRoleOperations_appointFolderRole: async (
|
|
31
|
-
context,
|
|
32
|
-
...args: unknown[]
|
|
33
|
-
) => {
|
|
34
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
35
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
36
|
-
const { accountId, role } = context.request.params as {
|
|
37
|
-
accountId: string;
|
|
38
|
-
role: CanonicalMailboxRole;
|
|
39
|
-
};
|
|
40
|
-
const body = context.request.requestBody as AppointFolderRoleInput;
|
|
41
|
-
|
|
42
|
-
const { account, accountSetting, mailbox } = await getClient();
|
|
43
|
-
const existing = await account.get(accountId);
|
|
44
|
-
assertAccountOwnership(existing, accountConfigId, "act");
|
|
45
|
-
|
|
46
|
-
let lastKnownPath: string | undefined;
|
|
47
|
-
if (body.mailboxId) {
|
|
48
|
-
const target = await mailbox.get(accountId, body.mailboxId);
|
|
49
|
-
assertMailboxInAccount(target, accountId, "act");
|
|
50
|
-
assertMailboxSettled(target);
|
|
51
|
-
lastKnownPath = target.fullPath;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
await writeFolderRoleAppointment(
|
|
55
|
-
accountSetting,
|
|
56
|
-
accountConfigId,
|
|
57
|
-
accountId,
|
|
58
|
-
role,
|
|
59
|
-
body.mailboxId ?? null,
|
|
60
|
-
lastKnownPath,
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const [signature, overrides, folderAppointments] = await Promise.all([
|
|
64
|
-
loadSignatureForAccount(accountSetting, accountConfigId, accountId),
|
|
65
|
-
loadAccountOverrides(accountSetting, accountConfigId, accountId),
|
|
66
|
-
resolveAccountFolderAppointments(
|
|
67
|
-
{ mailbox, accountSetting },
|
|
68
|
-
accountConfigId,
|
|
69
|
-
accountId,
|
|
70
|
-
),
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
return toAccountResponse(
|
|
74
|
-
existing,
|
|
75
|
-
signature,
|
|
76
|
-
overrides,
|
|
77
|
-
folderAppointments,
|
|
78
|
-
);
|
|
79
|
-
},
|
|
80
|
-
};
|
package/src/handlers/index.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { OperationHandler, OperationIds } from "../types.js";
|
|
2
|
-
import { AccountDetailOperations, AccountOperations } from "./account.js";
|
|
3
|
-
import { MicrosoftOAuthOperations } from "./account-oauth.js";
|
|
4
|
-
import { AddressDetailOperations, AddressOperations } from "./address.js";
|
|
5
|
-
import { CalendarDetailOperations, CalendarOperations } from "./calendar.js";
|
|
6
|
-
import {
|
|
7
|
-
CalendarEventDetailOperations,
|
|
8
|
-
CalendarEventOperations,
|
|
9
|
-
CalendarFreeBusyOperations,
|
|
10
|
-
} from "./calendar-event.js";
|
|
11
|
-
import {
|
|
12
|
-
CalendarFeedDetailOperations,
|
|
13
|
-
CalendarFeedOperations,
|
|
14
|
-
} from "./calendar-feed.js";
|
|
15
|
-
import {
|
|
16
|
-
CalendarSuggestionActionOperations,
|
|
17
|
-
CalendarSuggestionOperations,
|
|
18
|
-
MessageCalendarSuggestionOperations,
|
|
19
|
-
} from "./calendar-suggestion.js";
|
|
20
|
-
import { ConfigOperations } from "./config.js";
|
|
21
|
-
import { FilterDetailOperations, FilterOperations } from "./filter.js";
|
|
22
|
-
import { FolderRoleOperations } from "./folder-role.js";
|
|
23
|
-
import { LabelDetailOperations, LabelOperations } from "./label.js";
|
|
24
|
-
import {
|
|
25
|
-
MailboxDetailOperations,
|
|
26
|
-
MailboxOperations,
|
|
27
|
-
TrashOperations,
|
|
28
|
-
} from "./mailbox.js";
|
|
29
|
-
import { MeOperations } from "./me.js";
|
|
30
|
-
import { MessageBulkOperations, MessageOperations } from "./message.js";
|
|
31
|
-
import { OrganizeJobDetailOperations, OrganizeOperations } from "./organize.js";
|
|
32
|
-
import {
|
|
33
|
-
OutboxAttachmentOperations,
|
|
34
|
-
OutboxDetailOperations,
|
|
35
|
-
OutboxOperations,
|
|
36
|
-
} from "./outbox.js";
|
|
37
|
-
import { SemanticSearchOperations } from "./search.js";
|
|
38
|
-
import { SyncOperations } from "./sync.js";
|
|
39
|
-
import { SystemOperations } from "./system-update.js";
|
|
40
|
-
import { ThreadDetailOperations, ThreadOperations } from "./thread.js";
|
|
41
|
-
import { UnifiedThreadOperations } from "./unified-threads.js";
|
|
42
|
-
|
|
43
|
-
// biome-ignore lint/suspicious/noExplicitAny: Types are narrowed downstream
|
|
44
|
-
export const handlers: Record<OperationIds, OperationHandler<any>> = {
|
|
45
|
-
...MeOperations,
|
|
46
|
-
...ConfigOperations,
|
|
47
|
-
...SystemOperations,
|
|
48
|
-
...AccountOperations,
|
|
49
|
-
...AccountDetailOperations,
|
|
50
|
-
...MicrosoftOAuthOperations,
|
|
51
|
-
...MailboxOperations,
|
|
52
|
-
...MailboxDetailOperations,
|
|
53
|
-
...FolderRoleOperations,
|
|
54
|
-
...FilterOperations,
|
|
55
|
-
...FilterDetailOperations,
|
|
56
|
-
...LabelOperations,
|
|
57
|
-
...LabelDetailOperations,
|
|
58
|
-
...OrganizeOperations,
|
|
59
|
-
...OrganizeJobDetailOperations,
|
|
60
|
-
...CalendarOperations,
|
|
61
|
-
...CalendarDetailOperations,
|
|
62
|
-
...CalendarFeedDetailOperations,
|
|
63
|
-
...CalendarFeedOperations,
|
|
64
|
-
...CalendarEventOperations,
|
|
65
|
-
...CalendarEventDetailOperations,
|
|
66
|
-
...CalendarFreeBusyOperations,
|
|
67
|
-
...TrashOperations,
|
|
68
|
-
...SyncOperations,
|
|
69
|
-
...ThreadDetailOperations,
|
|
70
|
-
...UnifiedThreadOperations,
|
|
71
|
-
...ThreadOperations,
|
|
72
|
-
...MessageOperations,
|
|
73
|
-
...MessageBulkOperations,
|
|
74
|
-
...OutboxOperations,
|
|
75
|
-
...OutboxDetailOperations,
|
|
76
|
-
...OutboxAttachmentOperations,
|
|
77
|
-
...AddressOperations,
|
|
78
|
-
...AddressDetailOperations,
|
|
79
|
-
...SemanticSearchOperations,
|
|
80
|
-
...CalendarSuggestionOperations,
|
|
81
|
-
...MessageCalendarSuggestionOperations,
|
|
82
|
-
...CalendarSuggestionActionOperations,
|
|
83
|
-
};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, test } from "node:test";
|
|
3
|
-
import type { FilterItem, LabelItem } from "@remit/data-ports";
|
|
4
|
-
import {
|
|
5
|
-
deleteLabelWithCascade,
|
|
6
|
-
findFiltersForLabel,
|
|
7
|
-
type LabelCrudDeps,
|
|
8
|
-
} from "./label.js";
|
|
9
|
-
|
|
10
|
-
const filter = (filterId: string, actionLabelId: string): FilterItem =>
|
|
11
|
-
({ filterId, actionLabelId }) as unknown as FilterItem;
|
|
12
|
-
|
|
13
|
-
const label = (labelId: string): LabelItem =>
|
|
14
|
-
({
|
|
15
|
-
labelId,
|
|
16
|
-
accountConfigId: "acc-1",
|
|
17
|
-
name: "x",
|
|
18
|
-
color: "Default",
|
|
19
|
-
}) as LabelItem;
|
|
20
|
-
|
|
21
|
-
const buildDeps = (filters: FilterItem[]) => {
|
|
22
|
-
const deletedFilterIds: string[] = [];
|
|
23
|
-
const removedLabelIds: string[] = [];
|
|
24
|
-
const deletedLabelIds: string[] = [];
|
|
25
|
-
|
|
26
|
-
const deps: LabelCrudDeps = {
|
|
27
|
-
label: {
|
|
28
|
-
create: async () => label("unused"),
|
|
29
|
-
get: async (_accountConfigId: string, labelId: string) => label(labelId),
|
|
30
|
-
update: async (_accountConfigId: string, labelId: string) =>
|
|
31
|
-
label(labelId),
|
|
32
|
-
delete: async (_accountConfigId: string, labelId: string) => {
|
|
33
|
-
deletedLabelIds.push(labelId);
|
|
34
|
-
},
|
|
35
|
-
listPageByAccountConfig: async () => ({
|
|
36
|
-
items: [],
|
|
37
|
-
continuationToken: undefined,
|
|
38
|
-
}),
|
|
39
|
-
},
|
|
40
|
-
filter: {
|
|
41
|
-
listByAccountConfig: async () => filters,
|
|
42
|
-
delete: async (_accountConfigId: string, filterId: string) => {
|
|
43
|
-
deletedFilterIds.push(filterId);
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
messageLabel: {
|
|
47
|
-
removeAllByLabelId: async (_accountConfigId: string, labelId: string) => {
|
|
48
|
-
removedLabelIds.push(labelId);
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return { deps, deletedFilterIds, removedLabelIds, deletedLabelIds };
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
describe("findFiltersForLabel", () => {
|
|
57
|
-
test("returns only the filters whose actionLabelId matches", async () => {
|
|
58
|
-
const filters = [
|
|
59
|
-
filter("f1", "label-1"),
|
|
60
|
-
filter("f2", "label-2"),
|
|
61
|
-
filter("f3", "label-1"),
|
|
62
|
-
];
|
|
63
|
-
const { deps } = buildDeps(filters);
|
|
64
|
-
|
|
65
|
-
const found = await findFiltersForLabel(deps, "acc-1", "label-1");
|
|
66
|
-
assert.deepEqual(found.map((f) => f.filterId).sort(), ["f1", "f3"]);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test("returns an empty list when no filter uses the label", async () => {
|
|
70
|
-
const { deps } = buildDeps([filter("f1", "label-2")]);
|
|
71
|
-
const found = await findFiltersForLabel(deps, "acc-1", "label-1");
|
|
72
|
-
assert.deepEqual(found, []);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe("deleteLabelWithCascade", () => {
|
|
77
|
-
test("deletes every filter referencing the label, clears applied messages, then deletes the label", async () => {
|
|
78
|
-
const filters = [
|
|
79
|
-
filter("f1", "label-1"),
|
|
80
|
-
filter("f2", "label-2"),
|
|
81
|
-
filter("f3", "label-1"),
|
|
82
|
-
];
|
|
83
|
-
const { deps, deletedFilterIds, removedLabelIds, deletedLabelIds } =
|
|
84
|
-
buildDeps(filters);
|
|
85
|
-
|
|
86
|
-
await deleteLabelWithCascade(deps, "acc-1", "label-1");
|
|
87
|
-
|
|
88
|
-
assert.deepEqual(deletedFilterIds.sort(), ["f1", "f3"]);
|
|
89
|
-
assert.deepEqual(removedLabelIds, ["label-1"]);
|
|
90
|
-
assert.deepEqual(deletedLabelIds, ["label-1"]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("never touches a filter that references a different label", async () => {
|
|
94
|
-
const filters = [filter("f1", "label-2")];
|
|
95
|
-
const { deps, deletedFilterIds } = buildDeps(filters);
|
|
96
|
-
|
|
97
|
-
await deleteLabelWithCascade(deps, "acc-1", "label-1");
|
|
98
|
-
|
|
99
|
-
assert.deepEqual(deletedFilterIds, []);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("is a no-op on the filter/messageLabel side when nothing references the label", async () => {
|
|
103
|
-
const { deps, deletedFilterIds, removedLabelIds, deletedLabelIds } =
|
|
104
|
-
buildDeps([]);
|
|
105
|
-
|
|
106
|
-
await deleteLabelWithCascade(deps, "acc-1", "label-1");
|
|
107
|
-
|
|
108
|
-
assert.deepEqual(deletedFilterIds, []);
|
|
109
|
-
assert.deepEqual(removedLabelIds, ["label-1"]);
|
|
110
|
-
assert.deepEqual(deletedLabelIds, ["label-1"]);
|
|
111
|
-
});
|
|
112
|
-
});
|