@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
package/src/handlers/label.ts
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CreateLabelInput as CreateLabelRequestBody,
|
|
3
|
-
LabelResponse,
|
|
4
|
-
UpdateLabelInput as UpdateLabelRequestBody,
|
|
5
|
-
} from "@remit/api-openapi-types";
|
|
6
|
-
import type {
|
|
7
|
-
CreateLabelInput,
|
|
8
|
-
FilterItem,
|
|
9
|
-
LabelItem,
|
|
10
|
-
UpdateLabelInput,
|
|
11
|
-
} from "@remit/data-ports";
|
|
12
|
-
import type { APIGatewayProxyEvent } from "aws-lambda";
|
|
13
|
-
import { getAccountConfigIdFromEvent } from "../auth.js";
|
|
14
|
-
import { getClient } from "../service/data-client.js";
|
|
15
|
-
import type {
|
|
16
|
-
LabelDetailOperationIds,
|
|
17
|
-
LabelOperationIds,
|
|
18
|
-
OperationHandler,
|
|
19
|
-
} from "../types.js";
|
|
20
|
-
import { assertAccountOwnership } from "./account-ownership.js";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Minimal label-service surface the CRUD handlers need — declared as a `Pick`
|
|
24
|
-
* so tests can stub it without a live table.
|
|
25
|
-
*/
|
|
26
|
-
export interface LabelCrudDeps {
|
|
27
|
-
label: {
|
|
28
|
-
create(input: CreateLabelInput): Promise<LabelItem>;
|
|
29
|
-
get(accountConfigId: string, labelId: string): Promise<LabelItem>;
|
|
30
|
-
update(
|
|
31
|
-
accountConfigId: string,
|
|
32
|
-
labelId: string,
|
|
33
|
-
input: UpdateLabelInput,
|
|
34
|
-
): Promise<LabelItem>;
|
|
35
|
-
delete(accountConfigId: string, labelId: string): Promise<void>;
|
|
36
|
-
listPageByAccountConfig(
|
|
37
|
-
accountConfigId: string,
|
|
38
|
-
options?: { limit?: number; continuationToken?: string },
|
|
39
|
-
): Promise<{ items: LabelItem[]; continuationToken: string | undefined }>;
|
|
40
|
-
};
|
|
41
|
-
filter: {
|
|
42
|
-
listByAccountConfig(accountConfigId: string): Promise<FilterItem[]>;
|
|
43
|
-
delete(accountConfigId: string, filterId: string): Promise<void>;
|
|
44
|
-
};
|
|
45
|
-
messageLabel: {
|
|
46
|
-
removeAllByLabelId(accountConfigId: string, labelId: string): Promise<void>;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Every filter in the account whose action applies this label (issue #26). The
|
|
52
|
-
* count backs `LabelResponse.filterCount`; the list backs the cascade delete.
|
|
53
|
-
*/
|
|
54
|
-
export const findFiltersForLabel = async (
|
|
55
|
-
deps: Pick<LabelCrudDeps, "filter">,
|
|
56
|
-
accountConfigId: string,
|
|
57
|
-
labelId: string,
|
|
58
|
-
): Promise<FilterItem[]> => {
|
|
59
|
-
const filters = await deps.filter.listByAccountConfig(accountConfigId);
|
|
60
|
-
return filters.filter((filter) => filter.actionLabelId === labelId);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* `filterCount` is computed here, not stored (issue #26) — every other field
|
|
65
|
-
* comes straight off the `LabelItem` row.
|
|
66
|
-
*/
|
|
67
|
-
const toLabelResponse = (
|
|
68
|
-
item: LabelItem,
|
|
69
|
-
filterCount: number,
|
|
70
|
-
): LabelResponse => ({
|
|
71
|
-
labelId: item.labelId,
|
|
72
|
-
accountConfigId: item.accountConfigId,
|
|
73
|
-
name: item.name,
|
|
74
|
-
color: item.color,
|
|
75
|
-
filterCount,
|
|
76
|
-
createdAt: item.createdAt,
|
|
77
|
-
updatedAt: item.updatedAt,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Delete a label and cascade in both directions (issue #26): every filter
|
|
82
|
-
* whose `actionLabelId` is this label is deleted outright — never left
|
|
83
|
-
* dangling, never blocking the delete — and every `MessageLabel` row for it is
|
|
84
|
-
* removed. The label row itself is deleted last so a failure mid-cascade never
|
|
85
|
-
* leaves the label gone while its filters or applied-to-messages still exist.
|
|
86
|
-
*/
|
|
87
|
-
export const deleteLabelWithCascade = async (
|
|
88
|
-
deps: LabelCrudDeps,
|
|
89
|
-
accountConfigId: string,
|
|
90
|
-
labelId: string,
|
|
91
|
-
): Promise<void> => {
|
|
92
|
-
const filters = await findFiltersForLabel(deps, accountConfigId, labelId);
|
|
93
|
-
for (const filter of filters) {
|
|
94
|
-
await deps.filter.delete(accountConfigId, filter.filterId);
|
|
95
|
-
}
|
|
96
|
-
await deps.messageLabel.removeAllByLabelId(accountConfigId, labelId);
|
|
97
|
-
await deps.label.delete(accountConfigId, labelId);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const LabelOperations: Record<
|
|
101
|
-
LabelOperationIds,
|
|
102
|
-
OperationHandler<LabelOperationIds>
|
|
103
|
-
> = {
|
|
104
|
-
LabelOperations_listLabels: async (context, ...args: unknown[]) => {
|
|
105
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
106
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
107
|
-
const { accountId } = context.request.params as { accountId: string };
|
|
108
|
-
const { continuationToken } = context.request.query as {
|
|
109
|
-
continuationToken?: string;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const client = await getClient();
|
|
113
|
-
const account = await client.account.get(accountId);
|
|
114
|
-
assertAccountOwnership(account, accountConfigId, "read");
|
|
115
|
-
|
|
116
|
-
const page = await client.label.listPageByAccountConfig(accountConfigId, {
|
|
117
|
-
continuationToken,
|
|
118
|
-
});
|
|
119
|
-
const filters = await client.filter.listByAccountConfig(accountConfigId);
|
|
120
|
-
const filterCountByLabelId = new Map<string, number>();
|
|
121
|
-
for (const filter of filters) {
|
|
122
|
-
const labelId = filter.actionLabelId;
|
|
123
|
-
filterCountByLabelId.set(
|
|
124
|
-
labelId,
|
|
125
|
-
(filterCountByLabelId.get(labelId) ?? 0) + 1,
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
items: page.items.map((item) =>
|
|
131
|
-
toLabelResponse(item, filterCountByLabelId.get(item.labelId) ?? 0),
|
|
132
|
-
),
|
|
133
|
-
continuationToken: page.continuationToken,
|
|
134
|
-
};
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
LabelOperations_createLabel: async (context, ...args: unknown[]) => {
|
|
138
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
139
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
140
|
-
const { accountId } = context.request.params as { accountId: string };
|
|
141
|
-
const input = context.request.requestBody as CreateLabelRequestBody;
|
|
142
|
-
|
|
143
|
-
const client = await getClient();
|
|
144
|
-
const account = await client.account.get(accountId);
|
|
145
|
-
assertAccountOwnership(account, accountConfigId, "act");
|
|
146
|
-
|
|
147
|
-
const label = await client.label.create({
|
|
148
|
-
accountConfigId,
|
|
149
|
-
name: input.name,
|
|
150
|
-
color: input.color,
|
|
151
|
-
});
|
|
152
|
-
return toLabelResponse(label, 0);
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
export const LabelDetailOperations: Record<
|
|
157
|
-
LabelDetailOperationIds,
|
|
158
|
-
OperationHandler<LabelDetailOperationIds>
|
|
159
|
-
> = {
|
|
160
|
-
LabelDetailOperations_getLabel: async (context, ...args: unknown[]) => {
|
|
161
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
162
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
163
|
-
const { accountId, labelId } = context.request.params as {
|
|
164
|
-
accountId: string;
|
|
165
|
-
labelId: string;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const client = await getClient();
|
|
169
|
-
const account = await client.account.get(accountId);
|
|
170
|
-
assertAccountOwnership(account, accountConfigId, "read");
|
|
171
|
-
|
|
172
|
-
const label = await client.label.get(accountConfigId, labelId);
|
|
173
|
-
const filters = await findFiltersForLabel(client, accountConfigId, labelId);
|
|
174
|
-
return toLabelResponse(label, filters.length);
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
LabelDetailOperations_updateLabel: async (context, ...args: unknown[]) => {
|
|
178
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
179
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
180
|
-
const { accountId, labelId } = context.request.params as {
|
|
181
|
-
accountId: string;
|
|
182
|
-
labelId: string;
|
|
183
|
-
};
|
|
184
|
-
const body = context.request.requestBody as Partial<UpdateLabelRequestBody>;
|
|
185
|
-
|
|
186
|
-
const client = await getClient();
|
|
187
|
-
const account = await client.account.get(accountId);
|
|
188
|
-
assertAccountOwnership(account, accountConfigId, "act");
|
|
189
|
-
|
|
190
|
-
const updated = await client.label.update(accountConfigId, labelId, body);
|
|
191
|
-
const filters = await findFiltersForLabel(client, accountConfigId, labelId);
|
|
192
|
-
return toLabelResponse(updated, filters.length);
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
LabelDetailOperations_deleteLabel: async (context, ...args: unknown[]) => {
|
|
196
|
-
const event = args[0] as APIGatewayProxyEvent;
|
|
197
|
-
const accountConfigId = getAccountConfigIdFromEvent(event);
|
|
198
|
-
const { accountId, labelId } = context.request.params as {
|
|
199
|
-
accountId: string;
|
|
200
|
-
labelId: string;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const client = await getClient();
|
|
204
|
-
const account = await client.account.get(accountId);
|
|
205
|
-
assertAccountOwnership(account, accountConfigId, "act");
|
|
206
|
-
|
|
207
|
-
await deleteLabelWithCascade(client, accountConfigId, labelId);
|
|
208
|
-
return { statusCode: 204 };
|
|
209
|
-
},
|
|
210
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
FilterItem,
|
|
3
|
-
IAccountSettingRepository,
|
|
4
|
-
IFilterRepository,
|
|
5
|
-
MailboxItem,
|
|
6
|
-
} from "@remit/data-ports";
|
|
7
|
-
import { FILTER_NO_ACTION } from "@remit/data-ports";
|
|
8
|
-
import { BadRequestError } from "@remit/data-ports/errors";
|
|
9
|
-
import type { CanonicalMailboxRoleValue } from "@remit/data-ports/folder-role";
|
|
10
|
-
import { loadFolderAppointmentsForAccount } from "./folder-role-appointments.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* What a folder is bound to: the filters that move mail into it, and the
|
|
14
|
-
* canonical roles it has been appointed to.
|
|
15
|
-
*/
|
|
16
|
-
export interface MailboxBindings {
|
|
17
|
-
filterNames: string[];
|
|
18
|
-
roles: CanonicalMailboxRoleValue[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* `filter.actionMailboxId` has no reverse index, so the filters are listed for
|
|
23
|
-
* the account config and matched — they are few and per-config, so this is not
|
|
24
|
-
* a mailbox scan. Role appointments are `account_setting` rows whose *value* is
|
|
25
|
-
* a mailboxId, which a `mailbox_id` column scan cannot find, so the existing
|
|
26
|
-
* per-account appointment map answers for them.
|
|
27
|
-
*/
|
|
28
|
-
export const loadMailboxBindings = async (
|
|
29
|
-
client: {
|
|
30
|
-
filter: Pick<IFilterRepository, "listByAccountConfig">;
|
|
31
|
-
accountSetting: Pick<IAccountSettingRepository, "get">;
|
|
32
|
-
},
|
|
33
|
-
accountConfigId: string,
|
|
34
|
-
accountId: string,
|
|
35
|
-
mailboxId: string,
|
|
36
|
-
): Promise<MailboxBindings> => {
|
|
37
|
-
const [filters, appointments] = await Promise.all([
|
|
38
|
-
client.filter.listByAccountConfig(accountConfigId),
|
|
39
|
-
loadFolderAppointmentsForAccount(
|
|
40
|
-
client.accountSetting,
|
|
41
|
-
accountConfigId,
|
|
42
|
-
accountId,
|
|
43
|
-
),
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
const filterNames = filters
|
|
47
|
-
.filter(
|
|
48
|
-
(filter: FilterItem) =>
|
|
49
|
-
filter.actionMailboxId !== FILTER_NO_ACTION &&
|
|
50
|
-
filter.actionMailboxId === mailboxId,
|
|
51
|
-
)
|
|
52
|
-
.map((filter: FilterItem) => filter.name);
|
|
53
|
-
|
|
54
|
-
const roles: CanonicalMailboxRoleValue[] = [];
|
|
55
|
-
for (const [role, appointment] of appointments) {
|
|
56
|
-
if (appointment.mailboxId === mailboxId) {
|
|
57
|
-
roles.push(role as CanonicalMailboxRoleValue);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return { filterNames, roles };
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const asList = (items: readonly string[]): string =>
|
|
65
|
-
items.length === 1
|
|
66
|
-
? items[0]
|
|
67
|
-
: `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Refuse a delete while any durable reference is bound to the folder (D16).
|
|
71
|
-
*
|
|
72
|
-
* This is what makes the settled-target rule total: a binding is only created
|
|
73
|
-
* against a settled folder and only removed by the user, so a `mailboxId` that
|
|
74
|
-
* names nothing never exists and no reader of a filter's `actionMailboxId` or a
|
|
75
|
-
* role appointment needs a missing-target branch. It removes code rather than
|
|
76
|
-
* adding a check.
|
|
77
|
-
*
|
|
78
|
-
* The alternatives both cost more than they look. `Filter` has no enabled flag
|
|
79
|
-
* and its `actionMailboxId` sentinel means "no move action", so clearing the
|
|
80
|
-
* target silently turns a move-filter into one that does something else;
|
|
81
|
-
* deleting the user's filters outright is not a decision a folder delete gets
|
|
82
|
-
* to make.
|
|
83
|
-
*
|
|
84
|
-
* The message **names** each binding rather than counting them, because a count
|
|
85
|
-
* is not actionable — and this fires on ordinary configurations, since pointing
|
|
86
|
-
* a filter at a folder is what filters are for.
|
|
87
|
-
*/
|
|
88
|
-
export const assertNoBindings = (
|
|
89
|
-
mailbox: Pick<MailboxItem, "fullPath">,
|
|
90
|
-
bindings: MailboxBindings,
|
|
91
|
-
): void => {
|
|
92
|
-
const clauses: string[] = [];
|
|
93
|
-
if (bindings.filterNames.length > 0) {
|
|
94
|
-
clauses.push(
|
|
95
|
-
`the ${bindings.filterNames.length === 1 ? "filter" : "filters"} ${asList(
|
|
96
|
-
bindings.filterNames.map((name) => `“${name}”`),
|
|
97
|
-
)}`,
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
if (bindings.roles.length > 0) {
|
|
101
|
-
clauses.push(
|
|
102
|
-
`the ${asList(bindings.roles)} ${
|
|
103
|
-
bindings.roles.length === 1 ? "role" : "roles"
|
|
104
|
-
}`,
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
if (clauses.length === 0) return;
|
|
108
|
-
throw new BadRequestError(
|
|
109
|
-
`“${mailbox.fullPath}” is used by ${asList(clauses)}.`,
|
|
110
|
-
);
|
|
111
|
-
};
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import type { MailboxItem } from "@remit/data-ports";
|
|
4
|
-
import { MailboxSyncStatus } from "@remit/domain-enums";
|
|
5
|
-
import { applyMailboxPatch, type MailboxPatchClient } from "./mailbox.js";
|
|
6
|
-
|
|
7
|
-
const ACCOUNT_ID = "acc-1";
|
|
8
|
-
const CONFIG_ID = "cfg-1";
|
|
9
|
-
|
|
10
|
-
const mailbox = (over: Partial<MailboxItem> = {}): MailboxItem =>
|
|
11
|
-
({
|
|
12
|
-
mailboxId: "mbx-1",
|
|
13
|
-
accountId: ACCOUNT_ID,
|
|
14
|
-
fullPath: "Work",
|
|
15
|
-
hierarchyDelimiter: "/",
|
|
16
|
-
syncStatus: MailboxSyncStatus.synced,
|
|
17
|
-
...over,
|
|
18
|
-
}) as MailboxItem;
|
|
19
|
-
|
|
20
|
-
const clientOver = (
|
|
21
|
-
row: MailboxItem,
|
|
22
|
-
others: MailboxItem[] = [],
|
|
23
|
-
): {
|
|
24
|
-
client: MailboxPatchClient;
|
|
25
|
-
renames: { mailboxId: string; newPath: string }[];
|
|
26
|
-
dismissals: string[];
|
|
27
|
-
settings: string[];
|
|
28
|
-
} => {
|
|
29
|
-
const renames: { mailboxId: string; newPath: string }[] = [];
|
|
30
|
-
const dismissals: string[] = [];
|
|
31
|
-
const settings: string[] = [];
|
|
32
|
-
const client: MailboxPatchClient = {
|
|
33
|
-
mailbox: {
|
|
34
|
-
get: async () => row,
|
|
35
|
-
listAllByAccount: async () => [row, ...others],
|
|
36
|
-
},
|
|
37
|
-
mailboxQueue: {
|
|
38
|
-
renameMailbox: async (mailboxId, newPath) => {
|
|
39
|
-
renames.push({ mailboxId, newPath });
|
|
40
|
-
return mailbox({ pendingPath: newPath });
|
|
41
|
-
},
|
|
42
|
-
dismissMailboxIntent: async (mailboxId) => {
|
|
43
|
-
dismissals.push(mailboxId);
|
|
44
|
-
return mailbox();
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
accountSetting: {
|
|
48
|
-
get: async () => null,
|
|
49
|
-
upsert: async (item) => {
|
|
50
|
-
settings.push(item.name);
|
|
51
|
-
return item as never;
|
|
52
|
-
},
|
|
53
|
-
delete: async (_configId, name) => {
|
|
54
|
-
settings.push(name);
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
return { client, renames, dismissals, settings };
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const patch = (
|
|
62
|
-
client: MailboxPatchClient,
|
|
63
|
-
body: Record<string, unknown>,
|
|
64
|
-
): Promise<MailboxItem> =>
|
|
65
|
-
applyMailboxPatch(client, CONFIG_ID, "mbx-1", ACCOUNT_ID, body);
|
|
66
|
-
|
|
67
|
-
const refusedWith = (message: string) => (error: unknown) =>
|
|
68
|
-
(error as { statusCode?: number }).statusCode === 400 &&
|
|
69
|
-
(error as Error).message === message;
|
|
70
|
-
|
|
71
|
-
describe("applyMailboxPatch — renames that can never succeed (D4, D5)", () => {
|
|
72
|
-
it("refuses to rename the inbox", async () => {
|
|
73
|
-
const { client, renames } = clientOver(mailbox({ fullPath: "INBOX" }));
|
|
74
|
-
|
|
75
|
-
await assert.rejects(
|
|
76
|
-
patch(client, { fullPath: "Postvak" }),
|
|
77
|
-
refusedWith("The inbox can't be renamed."),
|
|
78
|
-
);
|
|
79
|
-
assert.equal(renames.length, 0);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("refuses a target that canonicalizes to the inbox", async () => {
|
|
83
|
-
const { client, renames } = clientOver(mailbox());
|
|
84
|
-
|
|
85
|
-
await assert.rejects(
|
|
86
|
-
patch(client, { fullPath: "inbox" }),
|
|
87
|
-
refusedWith("“INBOX” is reserved for the inbox."),
|
|
88
|
-
);
|
|
89
|
-
assert.equal(renames.length, 0);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("refuses an empty target", async () => {
|
|
93
|
-
const { client, renames } = clientOver(mailbox());
|
|
94
|
-
|
|
95
|
-
await assert.rejects(
|
|
96
|
-
patch(client, { fullPath: " " }),
|
|
97
|
-
refusedWith("A folder needs a name."),
|
|
98
|
-
);
|
|
99
|
-
assert.equal(renames.length, 0);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("refuses a target another folder already holds", async () => {
|
|
103
|
-
const { client, renames } = clientOver(mailbox(), [
|
|
104
|
-
mailbox({ mailboxId: "mbx-2", fullPath: "Projects" }),
|
|
105
|
-
]);
|
|
106
|
-
|
|
107
|
-
await assert.rejects(
|
|
108
|
-
patch(client, { fullPath: "Projects" }),
|
|
109
|
-
refusedWith("A folder named “Projects” is already there."),
|
|
110
|
-
);
|
|
111
|
-
assert.equal(renames.length, 0);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* The sweep reads a folder whose leaf name is a role's conventional name but
|
|
116
|
-
* which lacks the server's flag as a duplicate, and deletes its row — under
|
|
117
|
-
* D8, with the folder's mail — as soon as another folder holds the flag. A
|
|
118
|
-
* rename to one of those settles `synced` and is then reaped.
|
|
119
|
-
*/
|
|
120
|
-
for (const [name, leaf] of [
|
|
121
|
-
["Archive", "Archive"],
|
|
122
|
-
["Trash", "Trash"],
|
|
123
|
-
["Drafts", "Drafts"],
|
|
124
|
-
["Sent", "Sent"],
|
|
125
|
-
["Junk", "Spam"],
|
|
126
|
-
] as const) {
|
|
127
|
-
it(`refuses a rename to the reserved ${name} name`, async () => {
|
|
128
|
-
const { client, renames } = clientOver(mailbox());
|
|
129
|
-
|
|
130
|
-
await assert.rejects(
|
|
131
|
-
patch(client, { fullPath: `Work/${leaf}` }),
|
|
132
|
-
refusedWith(
|
|
133
|
-
`“${leaf}” is reserved for a system folder. Pick another name.`,
|
|
134
|
-
),
|
|
135
|
-
);
|
|
136
|
-
assert.equal(renames.length, 0);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
it("refuses a target another rename is already on its way to", async () => {
|
|
141
|
-
// A path a rename is aiming at is as taken as one a folder sits at (D2).
|
|
142
|
-
// Two renames onto one target both settle, both write it, and the sweep
|
|
143
|
-
// then reaps one row — with its mail — and inserts a duplicate.
|
|
144
|
-
const { client, renames } = clientOver(mailbox(), [
|
|
145
|
-
mailbox({
|
|
146
|
-
mailboxId: "mbx-2",
|
|
147
|
-
fullPath: "Admin",
|
|
148
|
-
syncStatus: MailboxSyncStatus.pending,
|
|
149
|
-
pendingPath: "Projects",
|
|
150
|
-
}),
|
|
151
|
-
]);
|
|
152
|
-
|
|
153
|
-
await assert.rejects(
|
|
154
|
-
patch(client, { fullPath: "Projects" }),
|
|
155
|
-
refusedWith("“Admin” is already being renamed to “Projects”."),
|
|
156
|
-
);
|
|
157
|
-
assert.equal(renames.length, 0);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("lets a failed rename's stale target go to somebody else", async () => {
|
|
161
|
-
// `failed` keeps its target so the client can name what the rename was
|
|
162
|
-
// aiming at and offer a retry (T6), and nothing clears it until the user
|
|
163
|
-
// retries or dismisses. Honouring that claim would tell everyone else the
|
|
164
|
-
// path is taken by a rename that is not happening, with nothing to wait
|
|
165
|
-
// for and no way to find out.
|
|
166
|
-
const { client, renames } = clientOver(mailbox(), [
|
|
167
|
-
mailbox({
|
|
168
|
-
mailboxId: "mbx-2",
|
|
169
|
-
fullPath: "Admin",
|
|
170
|
-
syncStatus: MailboxSyncStatus.failed,
|
|
171
|
-
pendingPath: "Projects",
|
|
172
|
-
}),
|
|
173
|
-
]);
|
|
174
|
-
|
|
175
|
-
await patch(client, { fullPath: "Projects" });
|
|
176
|
-
|
|
177
|
-
assert.deepEqual(renames, [{ mailboxId: "mbx-1", newPath: "Projects" }]);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("lets a retry aim at the target its own failed rename recorded", async () => {
|
|
181
|
-
const { client, renames } = clientOver(
|
|
182
|
-
mailbox({
|
|
183
|
-
syncStatus: MailboxSyncStatus.failed,
|
|
184
|
-
pendingPath: "Projects",
|
|
185
|
-
}),
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
await patch(client, { fullPath: "Projects" });
|
|
189
|
-
|
|
190
|
-
assert.deepEqual(renames, [{ mailboxId: "mbx-1", newPath: "Projects" }]);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("records the intent for an ordinary target", async () => {
|
|
194
|
-
const { client, renames } = clientOver(mailbox());
|
|
195
|
-
|
|
196
|
-
const renamed = await patch(client, { fullPath: "Projects" });
|
|
197
|
-
|
|
198
|
-
assert.deepEqual(renames, [{ mailboxId: "mbx-1", newPath: "Projects" }]);
|
|
199
|
-
assert.equal(renamed.pendingPath, "Projects");
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe("applyMailboxPatch — dismissing a failed intent (T10, T11)", () => {
|
|
204
|
-
it("reads a target equal to the confirmed path as a dismissal, not a rename", async () => {
|
|
205
|
-
const { client, renames, dismissals } = clientOver(
|
|
206
|
-
mailbox({
|
|
207
|
-
syncStatus: MailboxSyncStatus.failed,
|
|
208
|
-
pendingPath: "Projects",
|
|
209
|
-
}),
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
const dismissed = await patch(client, { fullPath: "Work" });
|
|
213
|
-
|
|
214
|
-
assert.deepEqual(dismissals, ["mbx-1"]);
|
|
215
|
-
assert.equal(renames.length, 0, "nothing is enqueued for a dismissal");
|
|
216
|
-
assert.equal(dismissed.syncStatus, MailboxSyncStatus.synced);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("dismisses even where the folder's own name is reserved", async () => {
|
|
220
|
-
// The refusals gate a rename's target. Keeping the name a folder already
|
|
221
|
-
// has is not one, and a folder called `Archive` must still be able to
|
|
222
|
-
// dismiss a rename that failed.
|
|
223
|
-
const { client, dismissals } = clientOver(
|
|
224
|
-
mailbox({ fullPath: "Archive", syncStatus: MailboxSyncStatus.failed }),
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
await patch(client, { fullPath: "Archive" });
|
|
228
|
-
|
|
229
|
-
assert.deepEqual(dismissals, ["mbx-1"]);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe("applyMailboxPatch — an override-only PATCH", () => {
|
|
234
|
-
it("touches no mutation state", async () => {
|
|
235
|
-
const { client, renames, dismissals, settings } = clientOver(mailbox());
|
|
236
|
-
|
|
237
|
-
await patch(client, { muted: true });
|
|
238
|
-
|
|
239
|
-
assert.equal(renames.length, 0);
|
|
240
|
-
assert.equal(dismissals.length, 0);
|
|
241
|
-
assert.equal(
|
|
242
|
-
settings.length > 0,
|
|
243
|
-
true,
|
|
244
|
-
"the override row is still written",
|
|
245
|
-
);
|
|
246
|
-
});
|
|
247
|
-
});
|