@remit/web-client 0.0.345 → 0.0.347

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.
Files changed (58) hide show
  1. package/dist/src/components/mail/{FlaggedList.d.ts → CollectionList.d.ts} +7 -3
  2. package/dist/src/components/mail/{FlaggedList.js → CollectionList.js} +25 -22
  3. package/dist/src/components/mail/CollectionPane.d.ts +32 -0
  4. package/dist/src/components/mail/{FlaggedPane.js → CollectionPane.js} +32 -30
  5. package/dist/src/components/mail/MailSidebarAdapter.js +29 -7
  6. package/dist/src/hooks/{useStarredThreads.d.ts → useCollectionThreads.d.ts} +10 -8
  7. package/dist/src/hooks/{useStarredThreads.js → useCollectionThreads.js} +16 -14
  8. package/dist/src/hooks/useCurrentMailboxName.d.ts +1 -0
  9. package/dist/src/hooks/useCurrentMailboxName.js +6 -1
  10. package/dist/src/hooks/useLabels.d.ts +10 -9
  11. package/dist/src/hooks/useLabels.js +25 -6
  12. package/dist/src/lib/{flagged-criteria.d.ts → collection-criteria.d.ts} +18 -6
  13. package/dist/src/lib/{flagged-criteria.js → collection-criteria.js} +4 -3
  14. package/dist/src/lib/label-folders.d.ts +6 -0
  15. package/dist/src/lib/label-folders.js +10 -0
  16. package/dist/src/lib/mail-route.d.ts +10 -5
  17. package/dist/src/lib/mail-route.js +9 -1
  18. package/dist/src/lib/mail-search.d.ts +11 -0
  19. package/dist/src/lib/mail-search.js +4 -0
  20. package/dist/src/lib/search-scope.d.ts +2 -2
  21. package/dist/src/lib/search-scope.js +4 -4
  22. package/dist/src/lib/search-tokens.d.ts +1 -1
  23. package/dist/src/lib/search-tokens.js +2 -2
  24. package/dist/src/routeTree.gen.d.ts +288 -3
  25. package/dist/src/routeTree.gen.js +65 -0
  26. package/dist/src/routes/mail/flagged/$threadId/$messageId.js +2 -2
  27. package/dist/src/routes/mail/flagged/$threadId/index.js +2 -2
  28. package/dist/src/routes/mail/flagged/index.js +2 -2
  29. package/dist/src/routes/mail/flagged.js +3 -2
  30. package/dist/src/routes/mail/label/$labelId/$threadId/$messageId/$mode.{-$outboxMessageId}.d.ts +18 -0
  31. package/dist/src/routes/mail/label/$labelId/$threadId/$messageId/$mode.{-$outboxMessageId}.js +8 -0
  32. package/dist/src/routes/mail/label/$labelId/$threadId/$messageId.d.ts +15 -0
  33. package/dist/src/routes/mail/label/$labelId/$threadId/$messageId.js +14 -0
  34. package/dist/src/routes/mail/label/$labelId/$threadId/index.d.ts +15 -0
  35. package/dist/src/routes/mail/label/$labelId/$threadId/index.js +9 -0
  36. package/dist/src/routes/mail/label/$labelId/$threadId.d.ts +15 -0
  37. package/dist/src/routes/mail/label/$labelId/$threadId.js +8 -0
  38. package/dist/src/routes/mail/label/$labelId/compose.{-$outboxMessageId}.d.ts +15 -0
  39. package/dist/src/routes/mail/label/$labelId/compose.{-$outboxMessageId}.js +10 -0
  40. package/dist/src/routes/mail/label/$labelId/index.d.ts +15 -0
  41. package/dist/src/routes/mail/label/$labelId/index.js +9 -0
  42. package/dist/src/routes/mail/label/$labelId.d.ts +15 -0
  43. package/dist/src/routes/mail/label/$labelId.js +30 -0
  44. package/dist/src/routes/mail/label/index.d.ts +29 -0
  45. package/dist/src/routes/mail/label/index.js +18 -0
  46. package/dist/src/routing/browsed-list.d.ts +1 -1
  47. package/dist/src/routing/browsed-list.js +15 -4
  48. package/dist/src/routing/compose.js +10 -6
  49. package/dist/src/routing/index.d.ts +1 -1
  50. package/dist/src/routing/index.js +1 -1
  51. package/dist/src/routing/nav-selection.d.ts +5 -0
  52. package/dist/src/routing/nav-selection.js +15 -0
  53. package/dist/src/routing/open-thread.js +23 -3
  54. package/dist/src/routing/reply.js +28 -11
  55. package/dist/src/routing/search-mirror.d.ts +5 -0
  56. package/dist/src/routing/search-mirror.js +20 -2
  57. package/package.json +2 -2
  58. package/dist/src/components/mail/FlaggedPane.d.ts +0 -29
@@ -1,4 +1,5 @@
1
- import { labelDetailOperationsDeleteLabelMutation, labelDetailOperationsUpdateLabelMutation, labelOperationsCreateLabelMutation, labelOperationsListLabelsOptions, labelOperationsListLabelsQueryKey, } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
1
+ import { labelDetailOperationsDeleteLabelMutation, labelDetailOperationsUpdateLabelMutation, labelOperationsCreateLabelMutation, labelOperationsListLabelsQueryKey, } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
+ import { labelOperationsListLabels } from "@remit/api-http-client/sdk.gen.ts";
2
3
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
4
  import { useCallback } from "react";
4
5
  /**
@@ -8,16 +9,34 @@ import { useCallback } from "react";
8
9
  * label is created, renamed, recolored, or deleted (issue #26).
9
10
  */
10
11
  export const buildLabelListKey = (accountId) => labelOperationsListLabelsQueryKey({ path: { accountId } });
11
- /** List the account's labels. */
12
+ const listAllLabels = async (accountId) => {
13
+ const labels = [];
14
+ let continuationToken;
15
+ do {
16
+ const { data } = await labelOperationsListLabels({
17
+ path: { accountId },
18
+ query: { continuationToken },
19
+ throwOnError: true,
20
+ });
21
+ labels.push(...data.items);
22
+ continuationToken = data.continuationToken;
23
+ } while (continuationToken);
24
+ return labels;
25
+ };
26
+ const NO_LABELS = [];
27
+ /**
28
+ * The user's labels, every page of them. Labels belong to the user rather than
29
+ * to one account, so any of their accounts answers for all of them.
30
+ */
12
31
  export const useLabelList = (accountId) => {
13
32
  const query = useQuery({
14
- ...labelOperationsListLabelsOptions({
15
- path: { accountId: accountId ?? "" },
16
- }),
33
+ queryKey: buildLabelListKey(accountId ?? ""),
34
+ queryFn: () => listAllLabels(accountId ?? ""),
17
35
  enabled: !!accountId,
18
36
  });
19
37
  return {
20
- labels: query.data?.items ?? [],
38
+ labels: query.data ?? NO_LABELS,
39
+ isSuccess: query.isSuccess,
21
40
  isPending: query.isPending,
22
41
  isError: query.isError,
23
42
  error: query.error,
@@ -1,5 +1,6 @@
1
1
  /**
2
- * What the Flagged view asks `listAllThreads` for, and what is left over.
2
+ * What a collection view — Starred or a label — asks `listAllThreads` for, and
3
+ * what is left over.
3
4
  *
4
5
  * Every criterion the view offers — the category chip, the Unread and Has
5
6
  * attachment chips, and the `from:` / `subject:` / `category:` / `is:unread` /
@@ -9,8 +10,9 @@
9
10
  * starred collection is paged, so anything below the newest page was invisible
10
11
  * to it (#308, #1128).
11
12
  *
12
- * `starred` is the view rather than a criterion: the request always carries it,
13
- * which is what makes `is:starred` a carried token instead of residue.
13
+ * On Starred, `starred` is the view rather than a criterion: the request always
14
+ * carries it, which is what makes `is:starred` a carried token instead of
15
+ * residue. On a label it is a criterion like any other.
14
16
  *
15
17
  * A chip beats a token where both set the same parameter — a control on screen
16
18
  * beats text in a field — and the overruled token drops to the residue, where
@@ -19,6 +21,16 @@
19
21
  import type { InboxFilterCriteria } from "./inbox-filters.js";
20
22
  import type { SearchToken } from "./search-tokens.js";
21
23
  import { type ThreadSearchTokenParamName, type ThreadSearchTokenParams } from "./thread-search-tokens.js";
24
+ /**
25
+ * A list that spans accounts and folders, as the listing parameter that names
26
+ * it: the starred mail, or one label's folders.
27
+ */
28
+ export type ThreadCollection = {
29
+ starred: true;
30
+ } | {
31
+ labelId: string;
32
+ };
33
+ export declare const STARRED: ThreadCollection;
22
34
  /**
23
35
  * The token parameters `listAllThreads` carries, which is every parameter it
24
36
  * takes. `from` and `subject` joined them once the operation grew a parameter
@@ -26,11 +38,11 @@ import { type ThreadSearchTokenParamName, type ThreadSearchTokenParams } from ".
26
38
  * token could be asked for on its own and both were applied over the pages
27
39
  * already fetched — a match below them never appeared (#1128).
28
40
  */
29
- export declare const FLAGGED_TOKEN_PARAMS: readonly ThreadSearchTokenParamName[];
30
- export interface FlaggedCriteria {
41
+ export declare const COLLECTION_TOKEN_PARAMS: readonly ThreadSearchTokenParamName[];
42
+ export interface CollectionRequest {
31
43
  /** What the request narrows by, chips and carried tokens together. */
32
44
  criteria: ThreadSearchTokenParams;
33
45
  /** The tokens no parameter carries; apply these over the returned rows. */
34
46
  residual: SearchToken[];
35
47
  }
36
- export declare const flaggedCriteria: (chips: InboxFilterCriteria, tokens: readonly SearchToken[]) => FlaggedCriteria;
48
+ export declare const collectionCriteria: (collection: ThreadCollection, chips: InboxFilterCriteria, tokens: readonly SearchToken[]) => CollectionRequest;
@@ -1,5 +1,6 @@
1
1
  import { inboxFilterParams } from "./inbox-filters.js";
2
2
  import { threadSearchTokens, } from "./thread-search-tokens.js";
3
+ export const STARRED = { starred: true };
3
4
  /**
4
5
  * The token parameters `listAllThreads` carries, which is every parameter it
5
6
  * takes. `from` and `subject` joined them once the operation grew a parameter
@@ -7,7 +8,7 @@ import { threadSearchTokens, } from "./thread-search-tokens.js";
7
8
  * token could be asked for on its own and both were applied over the pages
8
9
  * already fetched — a match below them never appeared (#1128).
9
10
  */
10
- export const FLAGGED_TOKEN_PARAMS = [
11
+ export const COLLECTION_TOKEN_PARAMS = [
11
12
  "from",
12
13
  "subject",
13
14
  "category",
@@ -15,8 +16,8 @@ export const FLAGGED_TOKEN_PARAMS = [
15
16
  "starred",
16
17
  "attachments",
17
18
  ];
18
- export const flaggedCriteria = (chips, tokens) => {
19
+ export const collectionCriteria = (collection, chips, tokens) => {
19
20
  const chipParams = inboxFilterParams(chips);
20
- const { params, residual } = threadSearchTokens(tokens, { ...chipParams, starred: true }, FLAGGED_TOKEN_PARAMS);
21
+ const { params, residual } = threadSearchTokens(tokens, { ...chipParams, ...collection }, COLLECTION_TOKEN_PARAMS);
21
22
  return { criteria: { ...params, ...chipParams }, residual };
22
23
  };
@@ -0,0 +1,6 @@
1
+ import type { RemitImapLabelResponse, RemitImapMailboxResponse } from "@remit/api-http-client/types.gen.ts";
2
+ /**
3
+ * An account's folders without the label folders and the `_remit` root above
4
+ * them, which the sidebar lists once per label instead.
5
+ */
6
+ export declare function withoutLabelFolders(mailboxes: readonly RemitImapMailboxResponse[], labels: readonly RemitImapLabelResponse[]): RemitImapMailboxResponse[];
@@ -0,0 +1,10 @@
1
+ const parentPath = ({ fullPath, hierarchyDelimiter, }) => fullPath.split(hierarchyDelimiter).slice(0, -1).join(hierarchyDelimiter);
2
+ /**
3
+ * An account's folders without the label folders and the `_remit` root above
4
+ * them, which the sidebar lists once per label instead.
5
+ */
6
+ export function withoutLabelFolders(mailboxes, labels) {
7
+ const labelIds = new Set(labels.flatMap((label) => label.folders.flatMap((f) => f.state === "Missing" ? [] : [f.mailboxId])));
8
+ const roots = new Set(mailboxes.filter((mb) => labelIds.has(mb.mailboxId)).map(parentPath));
9
+ return mailboxes.filter((mb) => !labelIds.has(mb.mailboxId) && !roots.has(mb.fullPath));
10
+ }
@@ -17,9 +17,10 @@ export declare const MAIL_BRIEF_ROUTE_ID: "/mail/brief";
17
17
  export declare const MAIL_MAILBOX_ROUTE_ID: "/mail/$mailboxId";
18
18
  export declare const MAIL_OUTBOX_ROUTE_ID: "/mail/outbox";
19
19
  export declare const MAIL_FLAGGED_ROUTE_ID: "/mail/flagged";
20
+ export declare const MAIL_LABEL_ROUTE_ID: "/mail/label/$labelId";
20
21
  /**
21
- * The list a location is browsing. A mailbox route carries its id, which is
22
- * absent only in the frame before the router has resolved the param.
22
+ * The list a location is browsing. A mailbox or label route carries its id,
23
+ * which is absent only in the frame before the router has resolved the param.
23
24
  */
24
25
  export type MailListRoute = {
25
26
  list: "brief";
@@ -30,15 +31,19 @@ export type MailListRoute = {
30
31
  } | {
31
32
  list: "mailbox";
32
33
  mailboxId: string | undefined;
34
+ } | {
35
+ list: "label";
36
+ labelId: string | undefined;
33
37
  };
34
38
  /**
35
- * The list a caller is on, flattened to the two values a navigation to it — or
36
- * a decision about it — needs. Both are primitives, so a caller holding them in
37
- * a dependency array settles, and `list` is `undefined` outside the mail shell.
39
+ * The list a caller is on, flattened to the values a navigation to it — or a
40
+ * decision about it — needs. All are primitives, so a caller holding them in a
41
+ * dependency array settles, and `list` is `undefined` outside the mail shell.
38
42
  */
39
43
  export interface BrowsedList {
40
44
  list: MailListRoute["list"] | undefined;
41
45
  mailboxId: string | undefined;
46
+ labelId: string | undefined;
42
47
  }
43
48
  /**
44
49
  * The list layout among the matched routes, or `undefined` outside the mail
@@ -12,6 +12,7 @@ export const MAIL_BRIEF_ROUTE_ID = "/mail/brief";
12
12
  export const MAIL_MAILBOX_ROUTE_ID = "/mail/$mailboxId";
13
13
  export const MAIL_OUTBOX_ROUTE_ID = "/mail/outbox";
14
14
  export const MAIL_FLAGGED_ROUTE_ID = "/mail/flagged";
15
+ export const MAIL_LABEL_ROUTE_ID = "/mail/label/$labelId";
15
16
  /**
16
17
  * The list layout among the matched routes, or `undefined` outside the mail
17
18
  * shell.
@@ -27,6 +28,8 @@ export function mailListRoute(matches) {
27
28
  return { list: "flagged" };
28
29
  if (match.routeId === MAIL_OUTBOX_ROUTE_ID)
29
30
  return { list: "outbox" };
31
+ if (match.routeId === MAIL_LABEL_ROUTE_ID)
32
+ return { list: "label", labelId: match.params?.labelId };
30
33
  if (match.routeId === MAIL_MAILBOX_ROUTE_ID)
31
34
  return { list: "mailbox", mailboxId: match.params?.mailboxId };
32
35
  }
@@ -62,6 +65,8 @@ export function mailViewKey(pathname) {
62
65
  return MAIL_FLAGGED_ROUTE_ID;
63
66
  if (list === "outbox")
64
67
  return MAIL_OUTBOX_ROUTE_ID;
68
+ if (list === "label")
69
+ return `${MAIL_LABEL_ROUTE_ID}:${segments[2] ?? ""}`;
65
70
  return mailboxViewKey(list);
66
71
  }
67
72
  /**
@@ -111,5 +116,8 @@ export function locationIsOnList(pathname, listPath) {
111
116
  */
112
117
  export function locationOpensDetail(pathname) {
113
118
  const segments = pathname.split(/[?#]/)[0].split("/").filter(Boolean);
114
- return segments[0] === "mail" && segments.length > 2;
119
+ if (segments[0] !== "mail")
120
+ return false;
121
+ const listSegments = segments[1] === "label" ? 3 : 2;
122
+ return segments.length > listSegments;
115
123
  }
@@ -21,6 +21,10 @@ export declare const briefSearchSchema: z.ZodObject<{
21
21
  export declare const flaggedSearchSchema: z.ZodObject<{
22
22
  q: z.ZodOptional<z.ZodString>;
23
23
  }, z.core.$strip>;
24
+ /** The same, for `/mail/label/<label>/<thread>/<message>`. */
25
+ export declare const labelSearchSchema: z.ZodObject<{
26
+ q: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strip>;
24
28
  /**
25
29
  * The outbox's open message is a path segment
26
30
  * (`/mail/outbox/draft/<outboxMessageId>`), so the query carries nothing but
@@ -77,6 +81,9 @@ export declare const mailListSearchSchemas: {
77
81
  readonly "/mail/$mailboxId": z.ZodObject<{
78
82
  q: z.ZodOptional<z.ZodString>;
79
83
  }, z.core.$strip>;
84
+ readonly "/mail/label/$labelId": z.ZodObject<{
85
+ q: z.ZodOptional<z.ZodString>;
86
+ }, z.core.$strip>;
80
87
  };
81
88
  export declare const composeSeedSearch: z.ZodObject<{
82
89
  body: z.ZodOptional<z.ZodString>;
@@ -96,4 +103,8 @@ export declare const replySearchSchemas: {
96
103
  q: z.ZodOptional<z.ZodString>;
97
104
  body: z.ZodOptional<z.ZodString>;
98
105
  }, z.core.$strip>;
106
+ readonly label: z.ZodObject<{
107
+ q: z.ZodOptional<z.ZodString>;
108
+ body: z.ZodOptional<z.ZodString>;
109
+ }, z.core.$strip>;
99
110
  };
@@ -20,6 +20,8 @@ const listSearch = z.object({ q: z.string().optional() });
20
20
  export const briefSearchSchema = listSearch.extend({});
21
21
  /** The same, for `/mail/flagged/<thread>/<message>`. */
22
22
  export const flaggedSearchSchema = listSearch.extend({});
23
+ /** The same, for `/mail/label/<label>/<thread>/<message>`. */
24
+ export const labelSearchSchema = listSearch.extend({});
23
25
  /**
24
26
  * The outbox's open message is a path segment
25
27
  * (`/mail/outbox/draft/<outboxMessageId>`), so the query carries nothing but
@@ -53,6 +55,7 @@ export const mailListSearchSchemas = {
53
55
  "/mail/flagged": flaggedSearchSchema,
54
56
  "/mail/outbox": outboxSearchSchema,
55
57
  "/mail/$mailboxId": mailboxSearchSchema,
58
+ "/mail/label/$labelId": labelSearchSchema,
56
59
  };
57
60
  export const composeSeedSearch = z.object({ body: z.string().optional() });
58
61
  export const withoutComposeSeed = (prev) => {
@@ -63,4 +66,5 @@ export const replySearchSchemas = {
63
66
  brief: briefSearchSchema.extend(composeSeedSearch.shape),
64
67
  flagged: flaggedSearchSchema.extend(composeSeedSearch.shape),
65
68
  mailbox: mailboxSearchSchema.extend(composeSeedSearch.shape),
69
+ label: labelSearchSchema.extend(composeSeedSearch.shape),
66
70
  };
@@ -68,8 +68,8 @@ export declare function routeMailboxId(browsed: BrowsedList): string | undefined
68
68
  /**
69
69
  * The scope of the active route.
70
70
  *
71
- * `mailboxName` is the sidebar's own label for the mailbox route (resolved by
72
- * `useCurrentMailboxName`). Until it resolves the scope is `pending`: no chip,
71
+ * `mailboxName` is the sidebar's own name for the mailbox or label route
72
+ * (resolved by `useCurrentMailboxName`). Until it resolves the scope is `pending`: no chip,
73
73
  * because a chip reading a raw uuid is worse than none, but not `global`
74
74
  * either, because the list underneath is already narrowed.
75
75
  */
@@ -29,8 +29,8 @@ export function routeMailboxId(browsed) {
29
29
  /**
30
30
  * The scope of the active route.
31
31
  *
32
- * `mailboxName` is the sidebar's own label for the mailbox route (resolved by
33
- * `useCurrentMailboxName`). Until it resolves the scope is `pending`: no chip,
32
+ * `mailboxName` is the sidebar's own name for the mailbox or label route
33
+ * (resolved by `useCurrentMailboxName`). Until it resolves the scope is `pending`: no chip,
34
34
  * because a chip reading a raw uuid is worse than none, but not `global`
35
35
  * either, because the list underneath is already narrowed.
36
36
  */
@@ -47,7 +47,7 @@ export function searchScopeForRoute(browsed, mailboxName) {
47
47
  chip: { id: SEARCH_SCOPE_CHIP_ID, label: "in:outbox" },
48
48
  };
49
49
  }
50
- if (browsed.list === "mailbox") {
50
+ if (browsed.list === "mailbox" || browsed.list === "label") {
51
51
  if (!mailboxName)
52
52
  return { kind: "pending" };
53
53
  return {
@@ -80,7 +80,7 @@ export function searchScopeForRoute(browsed, mailboxName) {
80
80
  export function resultsScopeForRoute(browsed, state, role) {
81
81
  if (state.kind === "global")
82
82
  return { kind: "global" };
83
- if (browsed.list === "flagged")
83
+ if (browsed.list === "flagged" || browsed.list === "label")
84
84
  return { kind: "collection" };
85
85
  return { kind: "folder", ...(role ? { role } : {}) };
86
86
  }
@@ -35,7 +35,7 @@
35
35
  *
36
36
  * Pure functions only: no React, no fetch — the name index is injected, not
37
37
  * fetched here. `MailListHeader` renders the chips and the callers that issue
38
- * search requests (`MailboxPane`, `DailyBrief`, `FlaggedList`) apply the
38
+ * search requests (`MailboxPane`, `DailyBrief`, `CollectionList`) apply the
39
39
  * parsed tokens to the params each engine's API actually supports.
40
40
  */
41
41
  import type { RemitImapMessageCategory } from "@remit/api-http-client/types.gen.ts";
@@ -35,7 +35,7 @@
35
35
  *
36
36
  * Pure functions only: no React, no fetch — the name index is injected, not
37
37
  * fetched here. `MailListHeader` renders the chips and the callers that issue
38
- * search requests (`MailboxPane`, `DailyBrief`, `FlaggedList`) apply the
38
+ * search requests (`MailboxPane`, `DailyBrief`, `CollectionList`) apply the
39
39
  * parsed tokens to the params each engine's API actually supports.
40
40
  */
41
41
  import { MessageCategory } from "@remit/domain-enums";
@@ -98,7 +98,7 @@ export function resolveCategory(value) {
98
98
  const alias = CATEGORY_ALIASES[lower];
99
99
  if (alias)
100
100
  return alias;
101
- const known = Object.values(MessageCategory).find((c) => c === lower);
101
+ const known = Object.values(MessageCategory).find((c) => c.toLowerCase() === lower);
102
102
  return known;
103
103
  }
104
104
  function parseStateToken(raw, value) {