@remit/data-ports 0.0.46 → 0.0.48

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/data-ports",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -25,10 +25,6 @@
25
25
  "types": "./src/account-settings.ts",
26
26
  "default": "./src/account-settings.ts"
27
27
  },
28
- "./mailbox-role": {
29
- "types": "./src/mailbox-role.ts",
30
- "default": "./src/mailbox-role.ts"
31
- },
32
28
  "./display-name": {
33
29
  "types": "./src/display-name.ts",
34
30
  "default": "./src/display-name.ts"
@@ -168,6 +168,21 @@ export const STALE_TRASH_FOLDER_REASON = `The folder appointed as this account's
168
168
  */
169
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.`;
170
170
 
171
+ /**
172
+ * The mailboxes holding Junk and Trash across a set of accounts, as ids. The
173
+ * shape a SQL predicate needs when it must ask "is this message in Junk"
174
+ * without spelling the rule a second time: resolution happens once, here, and
175
+ * SQL compares mailbox ids.
176
+ *
177
+ * A role resolves to at most one mailbox per account, so each list holds one id
178
+ * per account that has that folder — and no entry at all for an account that
179
+ * has none.
180
+ */
181
+ export interface JunkRoleMailboxes {
182
+ readonly junkMailboxIds: readonly string[];
183
+ readonly trashMailboxIds: readonly string[];
184
+ }
185
+
171
186
  /** The minimal mailbox shape role resolution reads. */
172
187
  export interface RoleMailboxCandidate extends MailboxNameCandidate {
173
188
  specialUse?: readonly string[];
@@ -1,3 +1,4 @@
1
+ import type { JunkRoleMailboxes } from "../folder-role.js";
1
2
  import type {
2
3
  AddressItem,
3
4
  CreateAddressInput,
@@ -13,7 +14,15 @@ export interface IAddressRepository {
13
14
  upsertAddress(input: CreateAddressInput): Promise<AddressItem>;
14
15
  upsertCorrespondentAddress(input: CreateAddressInput): Promise<AddressItem>;
15
16
  upsertJunkAddress(input: CreateAddressInput): Promise<AddressItem>;
16
- reconcileJunkOnlyForMessage(messageId: string): Promise<void>;
17
+ /**
18
+ * `roles` covers every account under the message's config, resolved by the
19
+ * caller once per batch: this runs inside the per-message sync loop, and
20
+ * role resolution is deliberately uncached.
21
+ */
22
+ reconcileJunkOnlyForMessage(
23
+ messageId: string,
24
+ roles: JunkRoleMailboxes,
25
+ ): Promise<void>;
17
26
  getAddress(accountConfigId: string, addressId: string): Promise<AddressItem>;
18
27
  getAddress(
19
28
  accountConfigId: string,
@@ -1,4 +1,4 @@
1
- import type { RoleResolution } from "../folder-role.js";
1
+ import type { JunkRoleMailboxes, RoleResolution } from "../folder-role.js";
2
2
  import type {
3
3
  MailboxSpecialUseItem,
4
4
  MailboxSpecialUseValue,
@@ -47,4 +47,14 @@ export interface IMailboxSpecialUseRepository {
47
47
  findJunkMailbox(
48
48
  accountId: string,
49
49
  ): Promise<{ mailboxId: string; fullPath: string } | null>;
50
+ /**
51
+ * Junk and Trash for every account under one config, as mailbox ids. The
52
+ * address book is keyed by config and an address carries sightings from all
53
+ * of them, so a predicate over an address must weigh every account's Junk —
54
+ * resolving only the account in hand withholds a sender on one and restores
55
+ * it on the next.
56
+ */
57
+ resolveJunkRolesForConfig(
58
+ accountConfigId: string,
59
+ ): Promise<JunkRoleMailboxes>;
50
60
  }
@@ -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,
@@ -1,14 +0,0 @@
1
- import { CanonicalMailboxRole } from "@remit/domain-enums";
2
- import { ROLE_NAME_HINTS } from "./folder-role.js";
3
-
4
- /**
5
- * The conventional names for a role, taken from the one table every
6
- * special-folder lookup shares (`folder-role.ts`). Exported so the SQLite junk
7
- * repair can spell the same rule; a second list here is how `INBOX/Sent` and
8
- * `INBOX/Spam` came to be resolvable in one place and not another.
9
- */
10
- export const JUNK_FOLDER_NAMES: readonly string[] =
11
- ROLE_NAME_HINTS[CanonicalMailboxRole.Junk] ?? [];
12
-
13
- export const TRASH_FOLDER_NAMES: readonly string[] =
14
- ROLE_NAME_HINTS[CanonicalMailboxRole.Trash] ?? [];