@remit/web-client 0.0.351 → 0.0.352

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.
@@ -8,7 +8,7 @@
8
8
  Installability. The preset serves this page for every host. The two theme colours are the light and dark --canvas tokens from
9
9
  packages/ui/src/tokens.css.
10
10
  -->
11
- <link rel="manifest" href="/manifest.webmanifest" />
11
+ <link rel="manifest" href="/manifest.webmanifest" crossorigin="use-credentials" />
12
12
  <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
13
13
  <link rel="icon" href="/favicon.ico" sizes="16x16 32x32" />
14
14
  <link rel="icon" href="/icons/icon-192.png" type="image/png" sizes="192x192" />
@@ -6,7 +6,7 @@ import { useCallback, useMemo } from "react";
6
6
  import { useTranslation } from "react-i18next";
7
7
  import { useLabelUnreadCounts } from "../../hooks/useCollectionThreads";
8
8
  import { useLabelList } from "../../hooks/useLabels";
9
- import { folderFailure } from "../../lib/folder-failure";
9
+ import { folderFailure, folderUnavailable } from "../../lib/folder-failure";
10
10
  import { buildMailboxRoleMap, labelForMailbox, shouldShowUnreadBadgeForRole, } from "../../lib/folder-roles";
11
11
  import { withoutLabelFolders } from "../../lib/label-folders";
12
12
  import { useMailContext } from "../../lib/mail-context";
@@ -44,6 +44,15 @@ function sortMailboxes(mailboxes, roleMap, t) {
44
44
  labels.sort((a, b) => compareLabelNames(labelForMailbox(a, undefined, t), labelForMailbox(b, undefined, t)));
45
45
  return { system, labels };
46
46
  }
47
+ const folderNote = (mb) => {
48
+ const unavailable = folderUnavailable(mb);
49
+ if (unavailable)
50
+ return { kind: "unavailable", text: unavailable };
51
+ const failure = folderFailure(mb);
52
+ if (failure)
53
+ return { kind: "failure", text: failure };
54
+ return undefined;
55
+ };
47
56
  /**
48
57
  * Convert an API mailbox to a NavMailbox for the kit: `role` comes from the
49
58
  * account's folder-role map (RFC 032 exclusive-folder-appointment, #976), the
@@ -58,7 +67,7 @@ function toNavMailbox(mb, role, t) {
58
67
  unseen: showBadge ? mb.unseenCount : undefined,
59
68
  role,
60
69
  fullPath: mb.fullPath,
61
- failure: folderFailure(mb),
70
+ note: folderNote(mb),
62
71
  };
63
72
  }
64
73
  function toNavLabels(labels, unreadByLabel) {
@@ -17,6 +17,7 @@ import { formatErrorMessage } from "@remit/ui";
17
17
  import { useMutation, useQuery, useQueryClient, } from "@tanstack/react-query";
18
18
  import { useCallback, useMemo } from "react";
19
19
  import { softErrorStatuses } from "../../lib/error-classifier";
20
+ import { listPages } from "../../lib/list-pages";
20
21
  const SUGGESTION_META = softErrorStatuses(400, 404);
21
22
  /** Every read an answer can change: the cards, the calendar, the sender rules. */
22
23
  const ANSWERED_QUERY_IDS = new Set([
@@ -63,18 +64,19 @@ export function usePendingCalendarSuggestions() {
63
64
  };
64
65
  }
65
66
  const findPending = async (suggestionId, signal) => {
66
- let continuationToken;
67
- do {
67
+ const pages = listPages(async (continuationToken) => {
68
68
  const { data } = await calendarSuggestionOperationsListCalendarSuggestions({
69
69
  query: { state: "Pending", continuationToken },
70
70
  signal,
71
71
  throwOnError: true,
72
72
  });
73
- const found = data.items.find((item) => item.suggestionId === suggestionId);
73
+ return data;
74
+ });
75
+ for await (const items of pages) {
76
+ const found = items.find((item) => item.suggestionId === suggestionId);
74
77
  if (found)
75
78
  return found;
76
- continuationToken = data.continuationToken;
77
- } while (continuationToken);
79
+ }
78
80
  return null;
79
81
  };
80
82
  export function usePendingCalendarSuggestion(suggestionId) {
@@ -4,7 +4,16 @@ import { useQueryClient } from "@tanstack/react-query";
4
4
  import { useCallback, useRef, useState } from "react";
5
5
  import { advanceMove, beginMove, failMove, MOVE_BATCH_SIZE, } from "../lib/delete-folder";
6
6
  import { awaitFreshMailboxCount, mailboxSyncStamp, } from "../lib/fresh-mailbox-count";
7
+ import { listPages } from "../lib/list-pages";
7
8
  const PAGE_CAP = 50;
9
+ const threadPages = (mailboxId, signal) => listPages(async (continuationToken) => {
10
+ const { data } = await threadOperationsListThreads({
11
+ path: { mailboxId },
12
+ query: { order: "desc", continuationToken },
13
+ throwOnError: true,
14
+ });
15
+ return data;
16
+ }, { maxPages: PAGE_CAP, signal });
8
17
  const errorText = (error) => error instanceof Error ? error.message : "Something went wrong.";
9
18
  /**
10
19
  * Run a network call to a branchable result instead of a thrown exception, so
@@ -20,16 +29,8 @@ const attempt = (work) => work.then((value) => ({ ok: true, value }), (error) =>
20
29
  */
21
30
  const collectMovableIds = async (mailboxId, alreadyMoved, limit, signal) => {
22
31
  const ids = [];
23
- let continuationToken;
24
- for (let page = 0; page < PAGE_CAP; page += 1) {
25
- if (signal.aborted)
26
- return ids;
27
- const { data } = await threadOperationsListThreads({
28
- path: { mailboxId },
29
- query: { order: "desc", continuationToken },
30
- throwOnError: true,
31
- });
32
- for (const item of data.items) {
32
+ for await (const items of threadPages(mailboxId, signal)) {
33
+ for (const item of items) {
33
34
  if (alreadyMoved.has(item.messageId))
34
35
  continue;
35
36
  if (ids.includes(item.messageId))
@@ -38,9 +39,6 @@ const collectMovableIds = async (mailboxId, alreadyMoved, limit, signal) => {
38
39
  if (ids.length >= limit)
39
40
  return ids;
40
41
  }
41
- if (!data.continuationToken)
42
- break;
43
- continuationToken = data.continuationToken;
44
42
  }
45
43
  return ids;
46
44
  };
@@ -52,19 +50,8 @@ const collectMovableIds = async (mailboxId, alreadyMoved, limit, signal) => {
52
50
  */
53
51
  const liveMessageCount = async (mailboxId, signal) => {
54
52
  let count = 0;
55
- let continuationToken;
56
- for (let page = 0; page < PAGE_CAP; page += 1) {
57
- if (signal.aborted)
58
- return count;
59
- const { data } = await threadOperationsListThreads({
60
- path: { mailboxId },
61
- query: { order: "desc", continuationToken },
62
- throwOnError: true,
63
- });
64
- count += data.items.length;
65
- if (!data.continuationToken)
66
- break;
67
- continuationToken = data.continuationToken;
53
+ for await (const items of threadPages(mailboxId, signal)) {
54
+ count += items.length;
68
55
  }
69
56
  return count;
70
57
  };
@@ -2,6 +2,7 @@ import { labelDetailOperationsDeleteLabelMutation, labelDetailOperationsUpdateLa
2
2
  import { labelOperationsListLabels } from "@remit/api-http-client/sdk.gen.ts";
3
3
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
4
4
  import { useCallback } from "react";
5
+ import { listPages } from "../lib/list-pages";
5
6
  /**
6
7
  * The query key the label list reads and every mutation invalidates on
7
8
  * success — the same contract `buildFilterListKey` pins for filters, so the
@@ -11,16 +12,16 @@ import { useCallback } from "react";
11
12
  export const buildLabelListKey = (accountId) => labelOperationsListLabelsQueryKey({ path: { accountId } });
12
13
  const listAllLabels = async (accountId) => {
13
14
  const labels = [];
14
- let continuationToken;
15
- do {
15
+ const pages = listPages(async (continuationToken) => {
16
16
  const { data } = await labelOperationsListLabels({
17
17
  path: { accountId },
18
18
  query: { continuationToken },
19
19
  throwOnError: true,
20
20
  });
21
- labels.push(...data.items);
22
- continuationToken = data.continuationToken;
23
- } while (continuationToken);
21
+ return data;
22
+ });
23
+ for await (const items of pages)
24
+ labels.push(...items);
24
25
  return labels;
25
26
  };
26
27
  const NO_LABELS = [];
@@ -1,6 +1,7 @@
1
1
  import { threadOperationsSearchThreadsQueryKey } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
2
  import { threadOperationsSearchThreads } from "@remit/api-http-client/sdk.gen.ts";
3
3
  import { useQuery } from "@tanstack/react-query";
4
+ import { listPages } from "../lib/list-pages";
4
5
  import { rescueCandidateReason } from "../lib/rescue-candidates";
5
6
  const TRUST_REASON = "We can verify this sender";
6
7
  /**
@@ -29,16 +30,19 @@ export function useRescueCandidates(junkMailboxId) {
29
30
  queryKey: threadOperationsSearchThreadsQueryKey({ path, query }),
30
31
  queryFn: async () => {
31
32
  const items = [];
32
- let continuationToken;
33
- do {
33
+ const pages = listPages(async (continuationToken) => {
34
34
  const { data: page } = await threadOperationsSearchThreads({
35
35
  path,
36
36
  query: { ...query, continuationToken },
37
37
  throwOnError: true,
38
38
  });
39
- items.push(...(page.items ?? []));
40
- continuationToken = page.continuationToken;
41
- } while (continuationToken);
39
+ return {
40
+ items: page.items ?? [],
41
+ continuationToken: page.continuationToken,
42
+ };
43
+ });
44
+ for await (const page of pages)
45
+ items.push(...page);
42
46
  return { items };
43
47
  },
44
48
  enabled: !!junkMailboxId,
@@ -1,7 +1,8 @@
1
- import { PlacementAction } from "@remit/domain-enums";
1
+ import { FromPlacement, PlacementAction } from "@remit/domain-enums";
2
2
  const FROM_PLACEMENT_LABEL = {
3
- inbox: "Inbox",
4
- junk: "Junk",
3
+ [FromPlacement.Inbox]: "Inbox",
4
+ [FromPlacement.Junk]: "Junk",
5
+ [FromPlacement.Other]: "another folder",
5
6
  };
6
7
  /** A standing-filter move names an arbitrary destination via `destinationMailboxId`; a classifier move names a direction via `action`. */
7
8
  const isFilterMove = (autoMoved) => autoMoved.destinationMailboxId !== undefined;
@@ -19,8 +20,8 @@ export const autoMovedLabel = (autoMoved, sourceFolderName) => {
19
20
  if (isFilterMove(autoMoved)) {
20
21
  return `Moved from ${sourceFolderName ?? "another folder"} by Remit`;
21
22
  }
22
- const from = autoMoved.fromPlacement ?? "";
23
- return `Moved from ${FROM_PLACEMENT_LABEL[from] ?? "another folder"} by Remit`;
23
+ const from = autoMoved.fromPlacement ?? FromPlacement.Other;
24
+ return `Moved from ${FROM_PLACEMENT_LABEL[from]} by Remit`;
24
25
  };
25
26
  /**
26
27
  * The mailbox the verdict's `action` implies as the destination — where a
@@ -74,9 +75,9 @@ export const resolveUndoTargetMailboxId = (autoMoved, mailboxes) => {
74
75
  return undefined;
75
76
  if (isFilterMove(autoMoved))
76
77
  return autoMoved.fromMailboxId;
77
- if (autoMoved.fromPlacement === "inbox")
78
+ if (autoMoved.fromPlacement === FromPlacement.Inbox)
78
79
  return mailboxes.inboxMailboxId;
79
- if (autoMoved.fromPlacement === "junk")
80
+ if (autoMoved.fromPlacement === FromPlacement.Junk)
80
81
  return mailboxes.junkMailboxId;
81
82
  return undefined;
82
83
  };
@@ -1,2 +1,3 @@
1
1
  import type { RemitImapMailboxResponse } from "@remit/api-http-client/types.gen.ts";
2
2
  export declare const folderFailure: (mailbox: Pick<RemitImapMailboxResponse, "syncStatus" | "syncFailureReason">) => string | undefined;
3
+ export declare const folderUnavailable: (mailbox: Pick<RemitImapMailboxResponse, "statusRefused">) => string | undefined;
@@ -6,3 +6,6 @@ export const folderFailure = (mailbox) => {
6
6
  return "The last change to this folder failed.";
7
7
  return `The mail server refused the last change: ${reason}`;
8
8
  };
9
+ export const folderUnavailable = (mailbox) => mailbox.statusRefused
10
+ ? "The mail server refuses to open this folder. Check its permissions on the server, or unsubscribe from it."
11
+ : undefined;
@@ -0,0 +1,13 @@
1
+ export interface ListPage<T> {
2
+ items: T[];
3
+ continuationToken?: string;
4
+ }
5
+ /**
6
+ * Follow a list endpoint's `continuationToken` and yield each page's items,
7
+ * stopping at the last page, after `maxPages` when given, or once `signal`
8
+ * aborts.
9
+ */
10
+ export declare function listPages<T>(fetchPage: (continuationToken: string | undefined) => Promise<ListPage<T>>, { maxPages, signal, }?: {
11
+ maxPages?: number;
12
+ signal?: AbortSignal;
13
+ }): AsyncGenerator<T[]>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Follow a list endpoint's `continuationToken` and yield each page's items,
3
+ * stopping at the last page, after `maxPages` when given, or once `signal`
4
+ * aborts.
5
+ */
6
+ export async function* listPages(fetchPage, { maxPages = Number.POSITIVE_INFINITY, signal, } = {}) {
7
+ let continuationToken;
8
+ for (let page = 0; page < maxPages; page += 1) {
9
+ if (signal?.aborted)
10
+ return;
11
+ const data = await fetchPage(continuationToken);
12
+ yield data.items;
13
+ if (!data.continuationToken)
14
+ return;
15
+ continuationToken = data.continuationToken;
16
+ }
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/web-client",
3
- "version": "0.0.351",
3
+ "version": "0.0.352",
4
4
  "type": "module",
5
5
  "description": "Remit web client, published as composable primitives — the app shell, auth shells, and runtime config. A distributor imports what it composes and bundles it.",
6
6
  "exports": {
@@ -91,7 +91,7 @@
91
91
  },
92
92
  "dependencies": {
93
93
  "@hookform/resolvers": "5.4.0",
94
- "@remit/ui": "0.0.242",
94
+ "@remit/ui": "0.0.243",
95
95
  "@tanstack/react-query": "5.101.2",
96
96
  "@tanstack/react-query-devtools": "5.101.2",
97
97
  "@tanstack/react-router": "1.170.18",