@remit/data-ports 0.0.45 → 0.0.47
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/package.json +1 -1
- package/src/folder-role.test.ts +27 -0
- package/src/folder-role.ts +40 -2
- package/src/interfaces/outbox-message.ts +19 -0
package/package.json
CHANGED
package/src/folder-role.test.ts
CHANGED
|
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
3
|
import {
|
|
4
4
|
CanonicalMailboxRole,
|
|
5
|
+
FolderAppointmentSource,
|
|
5
6
|
MailboxSpecialUse,
|
|
6
7
|
MailboxSyncStatus,
|
|
7
8
|
} from "@remit/domain-enums";
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
resolveConfirmedMailboxForRole,
|
|
16
17
|
resolveMailboxForRole,
|
|
17
18
|
resolveRoleForAccount,
|
|
19
|
+
trashSourceMeetsAssurance,
|
|
18
20
|
} from "./folder-role.js";
|
|
19
21
|
|
|
20
22
|
const mailbox = (
|
|
@@ -328,6 +330,31 @@ describe("the adapters over resolveRoleForAccount", () => {
|
|
|
328
330
|
});
|
|
329
331
|
});
|
|
330
332
|
|
|
333
|
+
describe("trashSourceMeetsAssurance", () => {
|
|
334
|
+
it("confirms the user's appointment and the server's flag, and nothing else", () => {
|
|
335
|
+
// The set a client may word an expunge from. `Reserved` reads as
|
|
336
|
+
// designated and is not: it is the INBOX name rule, which nobody chose.
|
|
337
|
+
const confirmed = Object.values(FolderAppointmentSource).filter((source) =>
|
|
338
|
+
trashSourceMeetsAssurance(source, "confirmed"),
|
|
339
|
+
);
|
|
340
|
+
assert.deepEqual(confirmed, [
|
|
341
|
+
FolderAppointmentSource.Appointed,
|
|
342
|
+
FolderAppointmentSource.Flagged,
|
|
343
|
+
]);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("adds the name guess at `resolved`, where a wrong guess only misfiles", () => {
|
|
347
|
+
const resolved = Object.values(FolderAppointmentSource).filter((source) =>
|
|
348
|
+
trashSourceMeetsAssurance(source, "resolved"),
|
|
349
|
+
);
|
|
350
|
+
assert.deepEqual(resolved, [
|
|
351
|
+
FolderAppointmentSource.Appointed,
|
|
352
|
+
FolderAppointmentSource.Flagged,
|
|
353
|
+
FolderAppointmentSource.Proposed,
|
|
354
|
+
]);
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
331
358
|
describe("the appointment name and its label sibling", () => {
|
|
332
359
|
it("never lets the label row parse as an appointment", () => {
|
|
333
360
|
// The label is display only. If the appointment parser matched it, a path
|
package/src/folder-role.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AccountSettingName,
|
|
3
3
|
CanonicalMailboxRole,
|
|
4
|
+
FolderAppointmentSource,
|
|
4
5
|
MailboxSpecialUse,
|
|
5
6
|
} from "@remit/domain-enums";
|
|
6
7
|
import {
|
|
@@ -160,9 +161,12 @@ export const STALE_TRASH_FOLDER_REASON = `The folder appointed as this account's
|
|
|
160
161
|
|
|
161
162
|
/**
|
|
162
163
|
* A folder matches the Trash name hint and nothing else — enough to file a
|
|
163
|
-
* delete somewhere retrievable, never enough to
|
|
164
|
+
* delete somewhere retrievable, never enough to erase what is already in it.
|
|
165
|
+
* Emptying that folder and deleting a message already inside it both land here
|
|
166
|
+
* (#876), so the sentence names neither verb: "nothing was deleted" is true of
|
|
167
|
+
* both, the way its two siblings above are.
|
|
164
168
|
*/
|
|
165
|
-
export const UNCONFIRMED_TRASH_FOLDER_REASON = `Nobody has confirmed which folder is this account's Trash, so
|
|
169
|
+
export const UNCONFIRMED_TRASH_FOLDER_REASON = `Nobody has confirmed which folder is this account's Trash, so nothing was deleted. Appoint one under ${FOLDER_ROLES_SETTINGS_PATH}, then try again.`;
|
|
166
170
|
|
|
167
171
|
/** The minimal mailbox shape role resolution reads. */
|
|
168
172
|
export interface RoleMailboxCandidate extends MailboxNameCandidate {
|
|
@@ -307,6 +311,40 @@ export const meetsTrashAssurance = <T>(
|
|
|
307
311
|
level: TrashAssuranceLevel,
|
|
308
312
|
): boolean => trashMailboxAt(resolution, level).allowed;
|
|
309
313
|
|
|
314
|
+
export type FolderAppointmentSourceValue =
|
|
315
|
+
(typeof FolderAppointmentSource)[keyof typeof FolderAppointmentSource];
|
|
316
|
+
|
|
317
|
+
/** The resolution each reported source came from (`toFolderAppointment`). */
|
|
318
|
+
const RESOLUTION_FOR_SOURCE: Record<
|
|
319
|
+
FolderAppointmentSourceValue,
|
|
320
|
+
RoleResolution<null>
|
|
321
|
+
> = {
|
|
322
|
+
[FolderAppointmentSource.Appointed]: { kind: "appointed", mailbox: null },
|
|
323
|
+
[FolderAppointmentSource.Flagged]: { kind: "flagged", mailbox: null },
|
|
324
|
+
[FolderAppointmentSource.Reserved]: { kind: "reserved", mailbox: null },
|
|
325
|
+
[FolderAppointmentSource.Proposed]: { kind: "proposed", mailbox: null },
|
|
326
|
+
[FolderAppointmentSource.Stale]: {
|
|
327
|
+
kind: "appointment_stale",
|
|
328
|
+
appointedMailboxId: "",
|
|
329
|
+
fallback: { kind: "none" },
|
|
330
|
+
},
|
|
331
|
+
[FolderAppointmentSource.None]: { kind: "none" },
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The same gate as {@link trashMailboxAt}, asked of the source `/config`
|
|
336
|
+
* reports rather than of the resolution the server computed — so a client can
|
|
337
|
+
* word a delete from the answer the service will give it.
|
|
338
|
+
*
|
|
339
|
+
* It runs that switch rather than restating it. A hand-written mirror gets
|
|
340
|
+
* `Reserved` wrong: it reads as designated, and the gate accepts only the user's
|
|
341
|
+
* appointment and the server's flag.
|
|
342
|
+
*/
|
|
343
|
+
export const trashSourceMeetsAssurance = (
|
|
344
|
+
source: FolderAppointmentSourceValue,
|
|
345
|
+
level: TrashAssuranceLevel,
|
|
346
|
+
): boolean => meetsTrashAssurance(RESOLUTION_FOR_SOURCE[source], level);
|
|
347
|
+
|
|
310
348
|
/**
|
|
311
349
|
* The mailbox a role is CONFIRMED to hold: the one the user appointed, or the
|
|
312
350
|
* one the server flagged (RFC 6154). No name guessing — `null` here means
|
|
@@ -59,6 +59,25 @@ export interface IOutboxMessageRepository {
|
|
|
59
59
|
outboxMessageId: string,
|
|
60
60
|
status: OutboxMessageItem["status"],
|
|
61
61
|
): Promise<OutboxMessageItem>;
|
|
62
|
+
/**
|
|
63
|
+
* Write `input` only while the row still holds `expected`, and answer `null`
|
|
64
|
+
* when it does not.
|
|
65
|
+
*
|
|
66
|
+
* Every status transition is a read the caller decided on followed by a
|
|
67
|
+
* write, and the SMTP worker or a second request can move the row between
|
|
68
|
+
* the two. Naming the status that decision was made against turns the write
|
|
69
|
+
* into a compare-and-set: an edit no longer pulls a row back out of `queued`
|
|
70
|
+
* while its send event is on the wire, and a settle no longer overwrites a
|
|
71
|
+
* status the worker has already reached. `null` is the caller's to read —
|
|
72
|
+
* a conflict for an action the user asked for, and nothing to do for a
|
|
73
|
+
* settle that has been overtaken.
|
|
74
|
+
*/
|
|
75
|
+
updateIfStatus(
|
|
76
|
+
accountConfigId: string,
|
|
77
|
+
outboxMessageId: string,
|
|
78
|
+
expected: OutboxMessageItem["status"],
|
|
79
|
+
input: UpdateOutboxMessageInput,
|
|
80
|
+
): Promise<OutboxMessageItem | null>;
|
|
62
81
|
markSent(
|
|
63
82
|
accountConfigId: string,
|
|
64
83
|
outboxMessageId: string,
|