@remit/imap-worker 0.0.58 → 0.0.59

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/imap-worker",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -31,6 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@aws-sdk/client-s3": "^3.1055.0",
34
+ "@remit/config-transfer": "*",
34
35
  "@remit/data-ports": "*",
35
36
  "@remit/smtp-service": "*",
36
37
  "@remit/logger-lambda": "*",
@@ -1,10 +1,16 @@
1
1
  import { getClient } from "@remit/backend/client";
2
+ import { writeFolderRoleAppointment } from "@remit/backend/folder-role-appointments";
3
+ import {
4
+ bindImportedFolders,
5
+ type ConfigBinderDeps,
6
+ } from "@remit/config-transfer";
2
7
  import type {
3
8
  AccountItem,
4
9
  IAccountRepository,
5
10
  IMailboxRepository,
6
11
  IMailboxSpecialUseRepository,
7
12
  } from "@remit/data-ports";
13
+ import type { CanonicalMailboxRoleValue } from "@remit/data-ports/folder-role";
8
14
  import { SyncPhase } from "@remit/domain-enums";
9
15
  import type { Logger } from "@remit/logger-lambda";
10
16
  import { RefreshTokenError } from "@remit/mail-oauth-service";
@@ -82,12 +88,25 @@ export const syncMailboxes = async (
82
88
  event: SyncMailboxesEvent,
83
89
  log: Logger,
84
90
  ): Promise<void> => {
91
+ const client = await getClient();
85
92
  const {
86
93
  account: accountService,
87
94
  mailbox: mailboxService,
88
95
  mailboxSpecialUse: mailboxSpecialUseService,
89
96
  secrets,
90
- } = await getClient();
97
+ } = client;
98
+ const binder: ConfigBinderDeps = {
99
+ repositories: client,
100
+ appointFolderRole: (configId, accountId, role, mailboxId, lastKnownPath) =>
101
+ writeFolderRoleAppointment(
102
+ client.accountSetting,
103
+ configId,
104
+ accountId,
105
+ role as CanonicalMailboxRoleValue,
106
+ mailboxId,
107
+ lastKnownPath,
108
+ ),
109
+ };
91
110
 
92
111
  const { accountId } = event;
93
112
  log.info({ event: event.type, accountId }, "Handling event");
@@ -125,6 +144,7 @@ export const syncMailboxes = async (
125
144
  mailboxService,
126
145
  mailboxSpecialUseService,
127
146
  accountService,
147
+ binder,
128
148
  log,
129
149
  );
130
150
  } catch (err) {
@@ -157,6 +177,7 @@ const syncMailboxesForAccount = async (
157
177
  mailboxService: IMailboxRepository,
158
178
  mailboxSpecialUseService: IMailboxSpecialUseRepository,
159
179
  accountService: IAccountRepository,
180
+ binder: ConfigBinderDeps,
160
181
  log: Logger,
161
182
  ): Promise<void> => {
162
183
  const { accountId } = account;
@@ -194,6 +215,20 @@ const syncMailboxesForAccount = async (
194
215
 
195
216
  log.info({ result }, "Mailbox sync complete");
196
217
 
218
+ // The folder list this account holds is now known, which is the one thing a
219
+ // configuration import could not know when it ran: every folder in a file is
220
+ // named by IMAP path, and the ids are minted here. Binding what is bindable
221
+ // belongs at exactly this point, and is idempotent, so a later discovery
222
+ // simply finds nothing left to do.
223
+ const bound = await bindImportedFolders(
224
+ binder,
225
+ account.accountConfigId,
226
+ accountId,
227
+ );
228
+ if (bound.bound > 0 || bound.stillPending > 0) {
229
+ log.info({ accountId, ...bound }, "Bound imported folder references");
230
+ }
231
+
197
232
  const allMailboxes = await collectAllMailboxes(accountId, mailboxService);
198
233
 
199
234
  // This fan-out is where an account's IMAP work is decided: one SEARCH per