@domicile-desktop/manganese-bar-module-gmail 2.0.1 → 2.1.0

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.
@@ -1,8 +1,6 @@
1
1
  // New mail as desktop notifications, sent to the notification server the
2
2
  // compositor runs. See docs/architecture/NOTIFICATIONS.md.
3
3
 
4
- import type { Browser } from "@domicile-desktop/sdk/desktop/browser";
5
- import { AppReuse } from "@domicile-desktop/sdk/desktop/browser";
6
4
  import type { Dbus } from "@domicile-desktop/sdk/desktop/dbus";
7
5
  import type {
8
6
  DbusSignal,
@@ -13,8 +11,10 @@ import { Bus, ListenedKind } from "@domicile-desktop/sdk/system";
13
11
  import type { Favicons } from "@domicile-desktop/system-apps/favicons";
14
12
  import { z } from "zod";
15
13
 
16
- import { gmailAppId, inboxAddress } from "./addresses";
14
+ import { inboxAddress } from "./addresses";
17
15
  import type { Mail, MailNews } from "./gmail-api";
16
+ import type { MailBrowser } from "./open-mail";
17
+ import { openMail } from "./open-mail";
18
18
 
19
19
  /** The notification server's address on the session bus. */
20
20
  const SERVER = {
@@ -33,11 +33,19 @@ const MOST_NAMED = 3;
33
33
  /** What notifies: the bus, and the browser a press opens Gmail in. */
34
34
  export type NoticeDesk = {
35
35
  readonly dbus: Pick<Dbus, "call" | "match">;
36
- readonly browser: Pick<Browser, "openApp">;
36
+ readonly browser: MailBrowser;
37
37
  };
38
38
 
39
39
  /** The account mail arrived for. */
40
- export type MailAccount = { email: string; nickname: string };
40
+ /**
41
+ * An account whose mail is notified, and the browser profile its Gmail
42
+ * window opens in: its site's, as the engine routes it, when `undefined`.
43
+ */
44
+ export type MailAccount = {
45
+ email: string;
46
+ nickname: string;
47
+ profile?: string | undefined;
48
+ };
41
49
 
42
50
  /**
43
51
  * Notifies the desk of mail that arrived, under the account's nickname: a
@@ -48,7 +56,11 @@ export type MailAccount = { email: string; nickname: string };
48
56
  * is. A notification closes once all its messages are read. Rejects when the
49
57
  * server refuses.
50
58
  */
51
- export const mailNotices = (desk: NoticeDesk, icons: Favicons) => {
59
+ export const mailNotices = (
60
+ desk: NoticeDesk,
61
+ icons: Favicons,
62
+ open: typeof openMail = openMail,
63
+ ) => {
52
64
  // Each notification still up, by id.
53
65
  const shown = new Map<number, Shown>();
54
66
  const presses: { listening: Promise<void> | undefined } = {
@@ -58,7 +70,7 @@ export const mailNotices = (desk: NoticeDesk, icons: Favicons) => {
58
70
  account: MailAccount,
59
71
  { arrived, read }: MailNews,
60
72
  ): Promise<void> => {
61
- presses.listening ??= listen(desk, shown);
73
+ presses.listening ??= listen(desk, shown, open);
62
74
  await presses.listening;
63
75
  const site = inboxAddress(account.email);
64
76
  if (arrived.length > 0) {
@@ -66,11 +78,12 @@ export const mailNotices = (desk: NoticeDesk, icons: Favicons) => {
66
78
  }
67
79
  // The theme's Gmail icon until the site's is found.
68
80
  const picture = icons.icon(site).unwrapOr("gmail");
69
- for (const notice of notices(account.email, arrived)) {
81
+ for (const notice of notices(arrived)) {
70
82
  const id = await notify(desk, account.nickname, picture, notice);
71
83
  shown.set(id, {
72
84
  email: account.email,
73
- opens: notice.opens,
85
+ profile: account.profile,
86
+ thread: notice.thread,
74
87
  unread: notice.messages,
75
88
  });
76
89
  }
@@ -87,35 +100,42 @@ export const mailNotices = (desk: NoticeDesk, icons: Favicons) => {
87
100
  };
88
101
 
89
102
  /**
90
- * One notification still up: its account, what a press opens, and its unread
91
- * messages.
103
+ * One notification still up: its account, the thread a press opens, and its
104
+ * unread messages.
92
105
  */
93
- type Shown = { email: string; opens: string; unread: readonly string[] };
106
+ type Shown = {
107
+ email: string;
108
+ profile: string | undefined;
109
+ /** The thread a press opens; the inbox for `undefined`. */
110
+ thread: string | undefined;
111
+ unread: readonly string[];
112
+ };
94
113
 
95
114
  type Notice = {
96
115
  summary: string;
97
116
  body: string;
98
- opens: string;
117
+ /** The thread a press opens, by its hex id; the inbox for `undefined`. */
118
+ thread: string | undefined;
99
119
  /** The ids of the messages it tells of. */
100
120
  messages: readonly string[];
101
121
  };
102
122
 
103
123
  /** `mail`'s notifications, oldest first, so the newest shows on top. */
104
- const notices = (email: string, mail: readonly Mail[]): Notice[] =>
124
+ const notices = (mail: readonly Mail[]): Notice[] =>
105
125
  mail.length > MOST_APART
106
126
  ? [
107
127
  {
108
128
  body: senders(mail),
109
129
  messages: mail.map(({ id }) => id),
110
- opens: inboxAddress(email),
111
130
  summary: `${mail.length.toString()} new emails`,
131
+ thread: undefined,
112
132
  },
113
133
  ]
114
134
  : mail.toReversed().map(({ from, id, subject, threadId }) => ({
115
135
  body: subject,
116
136
  messages: [id],
117
- opens: `${inboxAddress(email)}#inbox/${threadId}`,
118
137
  summary: from,
138
+ thread: threadId,
119
139
  }));
120
140
 
121
141
  /** Who sent `mail`, each once, newest first. */
@@ -181,12 +201,13 @@ const close = async (desk: NoticeDesk, id: number): Promise<void> =>
181
201
  });
182
202
 
183
203
  /**
184
- * Opens each press of one of `shown` from now on. Resolves once listening, or
185
- * rejects when the bus refuses.
204
+ * Opens each press of one of `shown` from now on with `open`. Resolves once
205
+ * listening, or rejects when the bus refuses.
186
206
  */
187
207
  const listen = async (
188
208
  desk: NoticeDesk,
189
209
  shown: Map<number, Shown>,
210
+ open: typeof openMail,
190
211
  ): Promise<void> =>
191
212
  (
192
213
  await desk.dbus.match({
@@ -200,7 +221,7 @@ const listen = async (
200
221
  throw new Error(`could not hear presses of mail: ${error.message}`);
201
222
  },
202
223
  Ok: (listening) => {
203
- follow(desk, shown, listening).catch((error: unknown) => {
224
+ follow(desk, shown, listening, open).catch((error: unknown) => {
204
225
  // biome-ignore lint/suspicious/noConsole: a broken listener leaves presses unanswered, with nothing else to tell
205
226
  console.error("Stopped hearing presses of mail", error);
206
227
  });
@@ -211,7 +232,10 @@ const follow = async (
211
232
  desk: NoticeDesk,
212
233
  shown: Map<number, Shown>,
213
234
  listening: Listening<Listened<DbusSignal>>,
235
+ open: typeof openMail,
214
236
  ): Promise<void> => {
237
+ // Each account's press still waiting for Gmail to start, as its stop.
238
+ const waiting = new Map<string, () => void>();
215
239
  const reader = listening.items.getReader();
216
240
  for (let next = await reader.read(); !next.done; next = await reader.read()) {
217
241
  switch (next.value.kind) {
@@ -221,10 +245,11 @@ const follow = async (
221
245
  const pressed = shown.get(id);
222
246
  if (pressed !== undefined) {
223
247
  shown.delete(id);
224
- desk.browser.openApp(pressed.opens, {
225
- id: gmailAppId(pressed.email),
226
- reuse: AppReuse.Navigate,
227
- });
248
+ waiting.get(pressed.email)?.();
249
+ waiting.set(
250
+ pressed.email,
251
+ open(desk.browser, pressed.email, pressed.thread, pressed.profile),
252
+ );
228
253
  }
229
254
  break;
230
255
  }
@@ -0,0 +1,203 @@
1
+ import type { Browser } from "@domicile-desktop/sdk/desktop/browser";
2
+ import { AppReuse } from "@domicile-desktop/sdk/desktop/browser";
3
+
4
+ import { GMAIL_ORIGIN, gmailAppId, inboxAddress } from "./addresses";
5
+ import { threadToken } from "./thread-token";
6
+
7
+ /** The path of an account's mail page. */
8
+ const MAIL_PATH = /^\/mail\/u\/\d+\/$/;
9
+
10
+ /** The hash of Gmail's inbox. */
11
+ const INBOX = "#inbox";
12
+
13
+ /** How often a press looks for its mail's row in the inbox. */
14
+ const LOOK_MS = 500;
15
+
16
+ /**
17
+ * How long a press looks for its mail's row before opening the mail on its
18
+ * own. Gmail shows its offline copy of the list first, and the new mail joins
19
+ * it once Gmail has synced.
20
+ */
21
+ const WAIT_MS = 20_000;
22
+
23
+ /** The browser {@link openMail} opens Gmail in. */
24
+ export type MailBrowser = Pick<
25
+ Browser,
26
+ "clickMatch" | "on" | "openApp" | "windows"
27
+ >;
28
+
29
+ /**
30
+ * Shows the inbox in the account's Gmail window, then, given a `thread` (the
31
+ * Gmail API's hex id), clicks that mail's row in it, as the user would. With
32
+ * Gmail's reading pane on, that shows the mail beside the list: Gmail keeps
33
+ * the address at `#inbox` then, so no address opens that view. It changes
34
+ * only the hash of a running Gmail mail page; loading an address afresh would
35
+ * load all of Gmail again. With no such page open, it loads the inbox first.
36
+ *
37
+ * It looks for the row until it shows, as Gmail brings its list up to date,
38
+ * and stops if the window leaves the inbox or closes. A row that never shows,
39
+ * as for a mail in another tab, opens the mail on its own after
40
+ * {@link WAIT_MS}, saying why with `warn`. Returns a function that stops it.
41
+ * A new window is in browser profile `profile`, or its site's when
42
+ * `undefined`.
43
+ */
44
+ export const openMail = (
45
+ browser: MailBrowser,
46
+ email: string,
47
+ thread: string | undefined,
48
+ profile?: string,
49
+ // biome-ignore lint/suspicious/noConsole: a fallback the user sees but cannot tell why
50
+ warn: (message: string) => void = console.warn,
51
+ ): (() => void) => {
52
+ const id = gmailAppId(email);
53
+ const inProfile = profile === undefined ? {} : { profile };
54
+ const goTo = (started: URL, hash: string) => {
55
+ started.hash = hash;
56
+ browser.openApp(started.href, {
57
+ id,
58
+ reuse: AppReuse.Navigate,
59
+ ...inProfile,
60
+ });
61
+ };
62
+ const show = (started: URL): (() => void) => {
63
+ if (started.hash !== INBOX) {
64
+ goTo(new URL(started), INBOX);
65
+ }
66
+ return thread === undefined
67
+ ? () => undefined
68
+ : clickRow(browser, id, thread, warn, () => {
69
+ goTo(started, `${INBOX}/${threadToken(thread)}`);
70
+ });
71
+ };
72
+ const open = listed(browser, id);
73
+ const started = open === undefined ? undefined : startedAt(open.url);
74
+ if (started === undefined) {
75
+ browser.openApp(inboxAddress(email, profile), {
76
+ id,
77
+ reuse: AppReuse.Navigate,
78
+ ...inProfile,
79
+ });
80
+ return whenStarted(browser, id, show);
81
+ } else {
82
+ return show(started);
83
+ }
84
+ };
85
+
86
+ /**
87
+ * Clicks thread `thread`'s row in window `id`'s inbox once Gmail lists it.
88
+ * Calls `alone` if it never does in {@link WAIT_MS}. Gives up when the window
89
+ * closes, or leaves the inbox after reaching it. Says what went wrong with
90
+ * `warn`. Returns a function that stops it.
91
+ */
92
+ const clickRow = (
93
+ browser: MailBrowser,
94
+ id: string,
95
+ thread: string,
96
+ warn: (message: string) => void,
97
+ alone: () => void,
98
+ ): (() => void) => {
99
+ const row = `tr [data-legacy-thread-id="${thread}"]`;
100
+ const state = { arrived: false, asking: false, warned: false };
101
+ const stop = () => {
102
+ clearInterval(looking);
103
+ clearTimeout(deadline);
104
+ };
105
+ const look = () => {
106
+ const window = listed(browser, id);
107
+ const at = window === undefined ? undefined : URL.parse(window.url)?.hash;
108
+ if (window === undefined || (state.arrived && at !== INBOX)) {
109
+ // Closed, or the user went elsewhere: a click now would take them back.
110
+ stop();
111
+ } else if (at === INBOX && !state.asking) {
112
+ state.arrived = true;
113
+ state.asking = true;
114
+ browser.clickMatch(window.id, row).then(
115
+ (clicked) => {
116
+ state.asking = false;
117
+ if (clicked) {
118
+ stop();
119
+ }
120
+ },
121
+ (error: unknown) => {
122
+ state.asking = false;
123
+ // The page left as it was asked, or the window closed. The next
124
+ // look asks again, or sees where it went and stops. Said once, as
125
+ // each look would say it again.
126
+ if (!state.warned) {
127
+ state.warned = true;
128
+ warn(`Gmail's window gave no answer to a click: ${String(error)}`);
129
+ }
130
+ },
131
+ );
132
+ }
133
+ };
134
+ const looking = setInterval(look, LOOK_MS);
135
+ const deadline = setTimeout(() => {
136
+ stop();
137
+ // A closed window has nothing to open the mail in; opening it would open
138
+ // a new one the user closed.
139
+ if (listed(browser, id) !== undefined) {
140
+ warn(
141
+ `Gmail never listed thread ${thread} in its inbox; opening it alone`,
142
+ );
143
+ alone();
144
+ }
145
+ }, WAIT_MS);
146
+ look();
147
+ return stop;
148
+ };
149
+
150
+ /**
151
+ * Calls `then` with the address of window `id`'s page once Gmail has started
152
+ * in it. Gives up when the window closes after it was listed. Returns a
153
+ * function that stops the wait, and whatever `then` started.
154
+ */
155
+ const whenStarted = (
156
+ browser: MailBrowser,
157
+ id: string,
158
+ then: (started: URL) => () => void,
159
+ ): (() => void) => {
160
+ const watch: { seen: boolean; stopThen: () => void } = {
161
+ seen: listed(browser, id) !== undefined,
162
+ stopThen: () => undefined,
163
+ };
164
+ const stop = browser.on("change", () => {
165
+ const window = listed(browser, id);
166
+ if (window === undefined) {
167
+ // Closed before Gmail started: nothing is left to show it in.
168
+ if (watch.seen) {
169
+ stop();
170
+ }
171
+ } else {
172
+ watch.seen = true;
173
+ const started = startedAt(window.url);
174
+ if (started !== undefined) {
175
+ stop();
176
+ watch.stopThen = then(started);
177
+ }
178
+ }
179
+ });
180
+ return () => {
181
+ stop();
182
+ watch.stopThen();
183
+ };
184
+ };
185
+
186
+ /**
187
+ * The Gmail mail page's address once Gmail has started: it sets a hash, such
188
+ * as `#inbox`, when its app is running. `undefined` before then, such as on
189
+ * the sign-in page or the redirect to `/mail/u/<n>/`, and on Gmail's other
190
+ * apps, such as Chat at `/chat/u/<n>/`.
191
+ */
192
+ const startedAt = (url: string): URL | undefined => {
193
+ const parsed = URL.parse(url);
194
+ return parsed?.origin === GMAIL_ORIGIN &&
195
+ MAIL_PATH.test(parsed.pathname) &&
196
+ parsed.hash !== ""
197
+ ? parsed
198
+ : undefined;
199
+ };
200
+
201
+ /** Window `id`, once the browser lists it. */
202
+ const listed = (browser: MailBrowser, id: string) =>
203
+ browser.windows?.find(({ appId }) => appId === id);
package/src/read-inbox.ts CHANGED
@@ -2,7 +2,12 @@ import { Result } from "@cprussin/option-result";
2
2
 
3
3
  import type { GoogleClient } from "./consent";
4
4
  import type { Counts, Mail, MailNews, Unread } from "./gmail-api";
5
- import { inboxCounts, mailHeaders, unreadMail } from "./gmail-api";
5
+ import {
6
+ inboxCounts,
7
+ mailHeaders,
8
+ sendAsAddresses,
9
+ unreadMail,
10
+ } from "./gmail-api";
6
11
  import type { Fetch, TokenRefusal } from "./google-token";
7
12
  import { refreshAccess, TokenRefusalKind } from "./google-token";
8
13
  import { Inbox } from "./inbox";
@@ -11,7 +16,11 @@ import { forgetToken, storedToken } from "./stored-token";
11
16
  /** How many of the newest unread conversations a reading names. */
12
17
  const LATEST = 8;
13
18
 
14
- type Held = { token: string; expiresAt: number };
19
+ /**
20
+ * An access token, and the addresses the account sends from, read once per
21
+ * token: they change only in Gmail's settings.
22
+ */
23
+ type Held = { token: string; expiresAt: number; addresses: readonly string[] };
15
24
 
16
25
  /**
17
26
  * Reads the account's inbox through the Gmail API, each call one read.
@@ -20,6 +29,8 @@ type Held = { token: string; expiresAt: number };
20
29
  * (which is then forgotten), it is signed out.
21
30
  * - The refresh token gets an access token, kept until it expires or Gmail
22
31
  * refuses it.
32
+ * - Each read names the addresses the account sends from, asked for once
33
+ * per access token.
23
34
  * - Each read names the newest message of each of the {@link LATEST} newest
24
35
  * unread conversations. A message's headers are asked for once.
25
36
  * - Each read passes `onMail` the unread messages that arrived since the
@@ -27,8 +38,8 @@ type Held = { token: string; expiresAt: number };
27
38
  * first read after signing in passes none, so mail already there is not
28
39
  * news.
29
40
  *
30
- * A read rejects when Google gives no access token, or Gmail no counts or
31
- * messages.
41
+ * A read rejects when Google gives no access token, or Gmail no counts,
42
+ * messages or addresses.
32
43
  */
33
44
  export const inboxReader = (
34
45
  domicile: Fetch,
@@ -61,7 +72,12 @@ export const inboxReader = (
61
72
  if (mail.length > 0 || read.length > 0) {
62
73
  await onMail({ arrived: mail, read });
63
74
  }
64
- return Inbox.Counted(counts.total, counts.unread, latest);
75
+ return Inbox.Counted(
76
+ counts.total,
77
+ counts.unread,
78
+ latest,
79
+ access.addresses,
80
+ );
65
81
  },
66
82
  });
67
83
 
@@ -88,13 +104,20 @@ export const inboxReader = (
88
104
  const askedAt = now();
89
105
  return (await refreshAccess(domicile, client, refreshToken)).match({
90
106
  Err: (refusal) => Promise.resolve(refused(refusal)),
91
- Ok: (access) => {
92
- held.current = {
93
- expiresAt: askedAt + access.expiresInMs,
94
- token: access.token,
95
- };
96
- return count(held.current);
97
- },
107
+ Ok: async (access) =>
108
+ (await sendAsAddresses(domicile, access.token)).match({
109
+ Err: (why): Promise<Inbox> => {
110
+ throw new Error(why);
111
+ },
112
+ Ok: (addresses) => {
113
+ held.current = {
114
+ addresses,
115
+ expiresAt: askedAt + access.expiresInMs,
116
+ token: access.token,
117
+ };
118
+ return count(held.current);
119
+ },
120
+ }),
98
121
  });
99
122
  };
100
123
 
package/src/sign-in.ts CHANGED
@@ -25,6 +25,7 @@ export const signIn = async (
25
25
  domicile: Desk,
26
26
  client: GoogleClient,
27
27
  email: string,
28
+ profile?: string,
28
29
  storage?: Parameters<typeof storeToken>[2],
29
30
  state: string = randomState(),
30
31
  ): Promise<void> => {
@@ -43,7 +44,10 @@ export const signIn = async (
43
44
  }
44
45
  };
45
46
  const stop = browser.on("change", windowsChanged);
46
- browser.open(consentAddress(client, email, state));
47
+ browser.open(
48
+ consentAddress(client, email, state),
49
+ profile === undefined ? {} : { profile },
50
+ );
47
51
  });
48
52
  const refreshToken = await code.match({
49
53
  Err: (why) => {
@@ -0,0 +1,31 @@
1
+ /** The digits of the base64 text a token encodes, in base64's order. */
2
+ const BASE64 =
3
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4
+
5
+ /** The digits of a token, in base 40. */
6
+ const CONSONANTS = "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz";
7
+
8
+ /**
9
+ * The token Gmail's own links name the thread by, as in `#inbox/FMfcg…`, for
10
+ * the Gmail API's hex `threadId`. Gmail opens a thread named this way as a
11
+ * click on it in the list does: beside the inbox when the reading pane is on.
12
+ * Named by the API's id, it opens the thread on its own.
13
+ *
14
+ * The token is `f:<thread id in decimal>`, base64-encoded with its padding
15
+ * dropped, then read as one number in base 64 and written in base 40.
16
+ */
17
+ export const threadToken = (threadId: string): string =>
18
+ digits(
19
+ [...btoa(`f:${BigInt(`0x${threadId}`).toString()}`).replace(/=+$/, "")]
20
+ .map((digit) => BigInt(BASE64.indexOf(digit)))
21
+ .reduce((sum, digit) => sum * 64n + digit, 0n),
22
+ CONSONANTS,
23
+ );
24
+
25
+ /** `value`'s digits in `alphabet`'s base, most significant first. */
26
+ const digits = (value: bigint, alphabet: string): string => {
27
+ const base = BigInt(alphabet.length);
28
+ return value === 0n
29
+ ? ""
30
+ : digits(value / base, alphabet) + alphabet[Number(value % base)];
31
+ };
@@ -0,0 +1,94 @@
1
+ import type { Browser } from "@domicile-desktop/sdk/desktop/browser";
2
+ import { AppReuse } from "@domicile-desktop/sdk/desktop/browser";
3
+
4
+ import { composeAddress, draftAddress, gmailAppId } from "./addresses";
5
+ import type { GoogleClient } from "./consent";
6
+ import { createDraft } from "./gmail-api";
7
+ import { refreshAccess, TokenRefusalKind } from "./google-token";
8
+ import { draftMessage, mailLink } from "./mail-draft";
9
+ import { storedToken } from "./stored-token";
10
+
11
+ /** The desktop {@link writeMail} asks Gmail through and opens Gmail in. */
12
+ export type WriteDesktop = {
13
+ readonly browser: Pick<Browser, "fetch" | "openApp">;
14
+ };
15
+
16
+ /**
17
+ * Opens the account's Gmail window with a new message, filled in from the
18
+ * `mailto:` link `link`, from address `from`.
19
+ *
20
+ * - From the account's own address: Gmail's new message form over the inbox,
21
+ * as Gmail's own handler for the link opens it.
22
+ * - From an alias: Gmail's form has no way to name the sender, so the
23
+ * message starts as a draft from the alias, through the Gmail API, and the
24
+ * window opens that draft. Should that fail, it says why with `warn` and
25
+ * opens the form from the account's own address instead, so the link is
26
+ * never lost.
27
+ *
28
+ * A new window is in browser profile `profile`, or its site's when
29
+ * `undefined`. Resolves once the window is asked to open.
30
+ */
31
+ export const writeMail = async (
32
+ domicile: WriteDesktop,
33
+ client: GoogleClient,
34
+ email: string,
35
+ link: string,
36
+ from: string,
37
+ profile?: string,
38
+ storage?: Parameters<typeof storedToken>[1],
39
+ // biome-ignore lint/suspicious/noConsole: a fallback the user sees but cannot tell why
40
+ warn: (message: string) => void = console.warn,
41
+ ): Promise<void> => {
42
+ const open = (address: string) => {
43
+ domicile.browser.openApp(address, {
44
+ id: gmailAppId(email),
45
+ reuse: AppReuse.Navigate,
46
+ ...(profile === undefined ? {} : { profile }),
47
+ });
48
+ };
49
+ if (from === email) {
50
+ open(composeAddress(email, link, profile));
51
+ } else {
52
+ const drafted = await draftFrom(
53
+ domicile,
54
+ client,
55
+ email,
56
+ link,
57
+ from,
58
+ storage,
59
+ );
60
+ drafted.match({
61
+ Err: (why) => {
62
+ warn(`Gmail could not start an email from ${from}: ${why}`);
63
+ open(composeAddress(email, link, profile));
64
+ },
65
+ Ok: (message) => {
66
+ open(draftAddress(email, message, profile));
67
+ },
68
+ });
69
+ }
70
+ };
71
+
72
+ /** Saves `link`'s message from `from` as a draft; resolves its message id. */
73
+ const draftFrom = (
74
+ domicile: WriteDesktop,
75
+ client: GoogleClient,
76
+ email: string,
77
+ link: string,
78
+ from: string,
79
+ storage?: Parameters<typeof storedToken>[1],
80
+ ) =>
81
+ storedToken(email, storage)
82
+ .okOr(`${email} is signed out`)
83
+ .andThenAsync(async (refreshToken) =>
84
+ (await refreshAccess(domicile, client, refreshToken)).mapErr((refusal) =>
85
+ refusal.kind === TokenRefusalKind.Revoked
86
+ ? `${email} needs to sign in again`
87
+ : refusal.reason,
88
+ ),
89
+ )
90
+ .then((access) =>
91
+ access.andThenAsync(({ token }) =>
92
+ createDraft(domicile, token, draftMessage(from, mailLink(link))),
93
+ ),
94
+ );
@@ -3,11 +3,11 @@ import { css } from '../css/index.mjs';
3
3
 
4
4
  const aspectRatioConfig = {
5
5
  transform(props, { map }) {
6
- const { ratio = 4 / 3, ...rest } = props;
6
+ const { ratio = 1.3333333333333333, ...rest } = props;
7
7
  return {
8
8
  position: "relative",
9
9
  _before: {
10
- content: `""`,
10
+ content: '""',
11
11
  display: "block",
12
12
  height: "0",
13
13
  paddingBottom: map(ratio, (r) => `${1 / r * 100}%`)
@@ -3,8 +3,7 @@ import { css } from '../css/index.mjs';
3
3
 
4
4
  const bleedConfig = {
5
5
  transform(props, { map, isCssUnit, isCssVar }) {
6
- const { inline, block, ...rest } = props;
7
- const valueFn = (v) => isCssUnit(v) || isCssVar(v) ? v : `token(spacing.${v}, ${v})`;
6
+ const { inline, block, ...rest } = props, valueFn = (v) => isCssUnit(v) || isCssVar(v) ? v : `token(spacing.${v}, ${v})`;
8
7
  return {
9
8
  "--bleed-x": map(inline, valueFn),
10
9
  "--bleed-y": map(block, valueFn),
@@ -11,28 +11,22 @@ transform(props, { map }) {
11
11
  position: "absolute",
12
12
  insetBlockStart: map(placement, (v) => {
13
13
  const [side] = v.split("-");
14
- const map2 = { top: offsetY, middle: "50%", bottom: "auto" };
15
- return map2[side];
14
+ return { top: offsetY, middle: "50%", bottom: "auto" }[side];
16
15
  }),
17
16
  insetBlockEnd: map(placement, (v) => {
18
17
  const [side] = v.split("-");
19
- const map2 = { top: "auto", middle: "50%", bottom: offsetY };
20
- return map2[side];
18
+ return { top: "auto", middle: "50%", bottom: offsetY }[side];
21
19
  }),
22
20
  insetInlineStart: map(placement, (v) => {
23
21
  const [, align] = v.split("-");
24
- const map2 = { start: offsetX, center: "50%", end: "auto" };
25
- return map2[align];
22
+ return { start: offsetX, center: "50%", end: "auto" }[align];
26
23
  }),
27
24
  insetInlineEnd: map(placement, (v) => {
28
25
  const [, align] = v.split("-");
29
- const map2 = { start: "auto", center: "50%", end: offsetX };
30
- return map2[align];
26
+ return { start: "auto", center: "50%", end: offsetX }[align];
31
27
  }),
32
28
  translate: map(placement, (v) => {
33
- const [side, align] = v.split("-");
34
- const mapX = { start: "-50%", center: "-50%", end: "50%" };
35
- const mapY = { top: "-50%", middle: "-50%", bottom: "50%" };
29
+ const [side, align] = v.split("-"), mapX = { start: "-50%", center: "-50%", end: "50%" }, mapY = { top: "-50%", middle: "-50%", bottom: "50%" };
36
30
  return `${mapX[align]} ${mapY[side]}`;
37
31
  }),
38
32
  ...rest
@@ -3,8 +3,7 @@ import { css } from '../css/index.mjs';
3
3
 
4
4
  const gridItemConfig = {
5
5
  transform(props, { map }) {
6
- const { colSpan, rowSpan, colStart, rowStart, colEnd, rowEnd, ...rest } = props;
7
- const spanFn = (v) => v === "auto" ? v : `span ${v}`;
6
+ const { colSpan, rowSpan, colStart, rowStart, colEnd, rowEnd, ...rest } = props, spanFn = (v) => v === "auto" ? v : `span ${v}`;
8
7
  return {
9
8
  gridColumn: colSpan != null ? map(colSpan, spanFn) : void 0,
10
9
  gridRow: rowSpan != null ? map(rowSpan, spanFn) : void 0,