@bobfrankston/rmfmail 1.0.467
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/README.md +429 -0
- package/bin/build-icon-ico.js +283 -0
- package/bin/lean-accounts.js +172 -0
- package/bin/mailx.js +1580 -0
- package/bin/mailx.js.map +1 -0
- package/bin/mailx.ts +1549 -0
- package/bin/postinstall.js +39 -0
- package/bin/postinstall.js.map +1 -0
- package/bin/postinstall.ts +41 -0
- package/bin/tsconfig.json +10 -0
- package/client/.gitattributes +10 -0
- package/client/.msger-window.json +1 -0
- package/client/android.html +226 -0
- package/client/app.js +3400 -0
- package/client/app.js.map +1 -0
- package/client/app.ts +3190 -0
- package/client/components/address-book.js +199 -0
- package/client/components/address-book.js.map +1 -0
- package/client/components/address-book.ts +204 -0
- package/client/components/alarms.js +299 -0
- package/client/components/alarms.js.map +1 -0
- package/client/components/alarms.ts +276 -0
- package/client/components/calendar-sidebar.js +508 -0
- package/client/components/calendar-sidebar.js.map +1 -0
- package/client/components/calendar-sidebar.ts +474 -0
- package/client/components/calendar.js +217 -0
- package/client/components/calendar.js.map +1 -0
- package/client/components/calendar.ts +211 -0
- package/client/components/context-menu.js +80 -0
- package/client/components/context-menu.js.map +1 -0
- package/client/components/context-menu.ts +95 -0
- package/client/components/folder-picker.js +119 -0
- package/client/components/folder-picker.js.map +1 -0
- package/client/components/folder-picker.ts +127 -0
- package/client/components/folder-tree.js +1093 -0
- package/client/components/folder-tree.js.map +1 -0
- package/client/components/folder-tree.ts +1069 -0
- package/client/components/message-list.js +1140 -0
- package/client/components/message-list.js.map +1 -0
- package/client/components/message-list.ts +1129 -0
- package/client/components/message-viewer.js +1291 -0
- package/client/components/message-viewer.js.map +1 -0
- package/client/components/message-viewer.ts +1257 -0
- package/client/components/outbox-view.js +104 -0
- package/client/components/outbox-view.js.map +1 -0
- package/client/components/outbox-view.ts +102 -0
- package/client/components/tasks.js +261 -0
- package/client/components/tasks.js.map +1 -0
- package/client/components/tasks.ts +234 -0
- package/client/compose/compose.css +560 -0
- package/client/compose/compose.html +52 -0
- package/client/compose/compose.js +1289 -0
- package/client/compose/compose.js.map +1 -0
- package/client/compose/compose.ts +1231 -0
- package/client/compose/editor.js +616 -0
- package/client/compose/editor.js.map +1 -0
- package/client/compose/editor.ts +599 -0
- package/client/compose/ghost-text.js +122 -0
- package/client/compose/ghost-text.js.map +1 -0
- package/client/compose/ghost-text.ts +140 -0
- package/client/favicon.svg +11 -0
- package/client/icon.ico +0 -0
- package/client/icon.png +0 -0
- package/client/index.html +230 -0
- package/client/lib/android-bootstrap.js +9 -0
- package/client/lib/android-bootstrap.js.map +1 -0
- package/client/lib/android-bootstrap.ts +9 -0
- package/client/lib/api-client.js +378 -0
- package/client/lib/api-client.js.map +1 -0
- package/client/lib/api-client.ts +439 -0
- package/client/lib/local-service.js +603 -0
- package/client/lib/local-service.js.map +1 -0
- package/client/lib/local-service.ts +646 -0
- package/client/lib/local-store.js +214 -0
- package/client/lib/local-store.js.map +1 -0
- package/client/lib/local-store.ts +283 -0
- package/client/lib/mailxapi.js +304 -0
- package/client/lib/message-state.js +132 -0
- package/client/lib/message-state.js.map +1 -0
- package/client/lib/message-state.ts +160 -0
- package/client/package.json +16 -0
- package/client/styles/components.css +2049 -0
- package/client/styles/layout.css +332 -0
- package/client/styles/variables.css +85 -0
- package/client/tsconfig.json +19 -0
- package/package.json +124 -0
- package/packages/mailx-api/.gitattributes +10 -0
- package/packages/mailx-api/index.d.ts +10 -0
- package/packages/mailx-api/index.d.ts.map +1 -0
- package/packages/mailx-api/index.js +322 -0
- package/packages/mailx-api/index.js.map +1 -0
- package/packages/mailx-api/index.ts +283 -0
- package/packages/mailx-api/package.json +27 -0
- package/packages/mailx-api/tsconfig.json +9 -0
- package/packages/mailx-api/tsconfig.tsbuildinfo +1 -0
- package/packages/mailx-compose/.gitattributes +10 -0
- package/packages/mailx-compose/index.d.ts +21 -0
- package/packages/mailx-compose/index.d.ts.map +1 -0
- package/packages/mailx-compose/index.js +61 -0
- package/packages/mailx-compose/index.js.map +1 -0
- package/packages/mailx-compose/index.ts +85 -0
- package/packages/mailx-compose/package.json +18 -0
- package/packages/mailx-compose/tsconfig.json +9 -0
- package/packages/mailx-core/index.d.ts +139 -0
- package/packages/mailx-core/index.d.ts.map +1 -0
- package/packages/mailx-core/index.js +403 -0
- package/packages/mailx-core/index.js.map +1 -0
- package/packages/mailx-core/index.ts +424 -0
- package/packages/mailx-core/ipc.d.ts +13 -0
- package/packages/mailx-core/ipc.d.ts.map +1 -0
- package/packages/mailx-core/ipc.js +56 -0
- package/packages/mailx-core/ipc.js.map +1 -0
- package/packages/mailx-core/ipc.ts +62 -0
- package/packages/mailx-core/package.json +18 -0
- package/packages/mailx-core/tsconfig.json +9 -0
- package/packages/mailx-host/.gitattributes +10 -0
- package/packages/mailx-host/index.d.ts +21 -0
- package/packages/mailx-host/index.d.ts.map +1 -0
- package/packages/mailx-host/index.js +29 -0
- package/packages/mailx-host/index.js.map +1 -0
- package/packages/mailx-host/index.ts +38 -0
- package/packages/mailx-host/package.json +23 -0
- package/packages/mailx-host/tsconfig.json +9 -0
- package/packages/mailx-host/types-shim.d.ts +14 -0
- package/packages/mailx-imap/.gitattributes +10 -0
- package/packages/mailx-imap/index.d.ts +442 -0
- package/packages/mailx-imap/index.d.ts.map +1 -0
- package/packages/mailx-imap/index.js +3684 -0
- package/packages/mailx-imap/index.js.map +1 -0
- package/packages/mailx-imap/index.ts +3652 -0
- package/packages/mailx-imap/package-lock.json +131 -0
- package/packages/mailx-imap/package.json +28 -0
- package/packages/mailx-imap/providers/gmail-api.d.ts +8 -0
- package/packages/mailx-imap/providers/gmail-api.d.ts.map +1 -0
- package/packages/mailx-imap/providers/gmail-api.js +8 -0
- package/packages/mailx-imap/providers/gmail-api.js.map +1 -0
- package/packages/mailx-imap/providers/gmail-api.ts +8 -0
- package/packages/mailx-imap/providers/outlook-api.ts +7 -0
- package/packages/mailx-imap/providers/types.d.ts +9 -0
- package/packages/mailx-imap/providers/types.d.ts.map +1 -0
- package/packages/mailx-imap/providers/types.js +9 -0
- package/packages/mailx-imap/providers/types.js.map +1 -0
- package/packages/mailx-imap/providers/types.ts +9 -0
- package/packages/mailx-imap/tsconfig.json +9 -0
- package/packages/mailx-imap/tsconfig.tsbuildinfo +1 -0
- package/packages/mailx-send/.gitattributes +10 -0
- package/packages/mailx-send/README.md +217 -0
- package/packages/mailx-send/cli-queue.d.ts +11 -0
- package/packages/mailx-send/cli-queue.d.ts.map +1 -0
- package/packages/mailx-send/cli-queue.js +59 -0
- package/packages/mailx-send/cli-queue.js.map +1 -0
- package/packages/mailx-send/cli-queue.ts +62 -0
- package/packages/mailx-send/cli-send.d.ts +17 -0
- package/packages/mailx-send/cli-send.d.ts.map +1 -0
- package/packages/mailx-send/cli-send.js +75 -0
- package/packages/mailx-send/cli-send.js.map +1 -0
- package/packages/mailx-send/cli-send.ts +83 -0
- package/packages/mailx-send/cli.d.ts +22 -0
- package/packages/mailx-send/cli.d.ts.map +1 -0
- package/packages/mailx-send/cli.js +115 -0
- package/packages/mailx-send/cli.js.map +1 -0
- package/packages/mailx-send/cli.ts +126 -0
- package/packages/mailx-send/index.d.ts +77 -0
- package/packages/mailx-send/index.d.ts.map +1 -0
- package/packages/mailx-send/index.js +264 -0
- package/packages/mailx-send/index.js.map +1 -0
- package/packages/mailx-send/index.ts +333 -0
- package/packages/mailx-send/mailsend/README.md +133 -0
- package/packages/mailx-send/mailsend/cli.d.ts +12 -0
- package/packages/mailx-send/mailsend/cli.d.ts.map +1 -0
- package/packages/mailx-send/mailsend/cli.js +70 -0
- package/packages/mailx-send/mailsend/cli.js.map +1 -0
- package/packages/mailx-send/mailsend/cli.ts +81 -0
- package/packages/mailx-send/mailsend/index.d.ts +77 -0
- package/packages/mailx-send/mailsend/index.d.ts.map +1 -0
- package/packages/mailx-send/mailsend/index.js +264 -0
- package/packages/mailx-send/mailsend/index.js.map +1 -0
- package/packages/mailx-send/mailsend/index.ts +333 -0
- package/packages/mailx-send/mailsend/package-lock.json +65 -0
- package/packages/mailx-send/mailsend/package.json +26 -0
- package/packages/mailx-send/mailsend/tsconfig.json +21 -0
- package/packages/mailx-send/package-lock.json +65 -0
- package/packages/mailx-send/package.json +37 -0
- package/packages/mailx-send/tsconfig.json +21 -0
- package/packages/mailx-server/.gitattributes +10 -0
- package/packages/mailx-server/index.d.ts +8 -0
- package/packages/mailx-server/index.d.ts.map +1 -0
- package/packages/mailx-server/index.js +397 -0
- package/packages/mailx-server/index.js.map +1 -0
- package/packages/mailx-server/index.ts +429 -0
- package/packages/mailx-server/package.json +28 -0
- package/packages/mailx-server/tsconfig.json +9 -0
- package/packages/mailx-server/tsconfig.tsbuildinfo +1 -0
- package/packages/mailx-service/google-sync.d.ts +96 -0
- package/packages/mailx-service/google-sync.d.ts.map +1 -0
- package/packages/mailx-service/google-sync.js +153 -0
- package/packages/mailx-service/google-sync.js.map +1 -0
- package/packages/mailx-service/google-sync.ts +238 -0
- package/packages/mailx-service/index.d.ts +366 -0
- package/packages/mailx-service/index.d.ts.map +1 -0
- package/packages/mailx-service/index.js +2589 -0
- package/packages/mailx-service/index.js.map +1 -0
- package/packages/mailx-service/index.ts +2512 -0
- package/packages/mailx-service/jsonrpc.d.ts +25 -0
- package/packages/mailx-service/jsonrpc.d.ts.map +1 -0
- package/packages/mailx-service/jsonrpc.js +238 -0
- package/packages/mailx-service/jsonrpc.js.map +1 -0
- package/packages/mailx-service/jsonrpc.ts +268 -0
- package/packages/mailx-service/package.json +22 -0
- package/packages/mailx-service/tsconfig.json +9 -0
- package/packages/mailx-settings/.gitattributes +10 -0
- package/packages/mailx-settings/cloud.d.ts +47 -0
- package/packages/mailx-settings/cloud.d.ts.map +1 -0
- package/packages/mailx-settings/cloud.js +408 -0
- package/packages/mailx-settings/cloud.js.map +1 -0
- package/packages/mailx-settings/cloud.ts +393 -0
- package/packages/mailx-settings/index.d.ts +140 -0
- package/packages/mailx-settings/index.d.ts.map +1 -0
- package/packages/mailx-settings/index.js +872 -0
- package/packages/mailx-settings/index.js.map +1 -0
- package/packages/mailx-settings/index.ts +908 -0
- package/packages/mailx-settings/package.json +20 -0
- package/packages/mailx-settings/tsconfig.json +9 -0
- package/packages/mailx-settings/tsconfig.tsbuildinfo +1 -0
- package/packages/mailx-store/.gitattributes +10 -0
- package/packages/mailx-store/db.d.ts +346 -0
- package/packages/mailx-store/db.d.ts.map +1 -0
- package/packages/mailx-store/db.js +1796 -0
- package/packages/mailx-store/db.js.map +1 -0
- package/packages/mailx-store/db.ts +2007 -0
- package/packages/mailx-store/file-store.d.ts +36 -0
- package/packages/mailx-store/file-store.d.ts.map +1 -0
- package/packages/mailx-store/file-store.js +80 -0
- package/packages/mailx-store/file-store.js.map +1 -0
- package/packages/mailx-store/file-store.ts +82 -0
- package/packages/mailx-store/index.d.ts +7 -0
- package/packages/mailx-store/index.d.ts.map +1 -0
- package/packages/mailx-store/index.js +7 -0
- package/packages/mailx-store/index.js.map +1 -0
- package/packages/mailx-store/index.ts +7 -0
- package/packages/mailx-store/package.json +19 -0
- package/packages/mailx-store/tsconfig.json +9 -0
- package/packages/mailx-store/tsconfig.tsbuildinfo +1 -0
- package/packages/mailx-store-web/android-bootstrap.d.ts +16 -0
- package/packages/mailx-store-web/android-bootstrap.d.ts.map +1 -0
- package/packages/mailx-store-web/android-bootstrap.js +1247 -0
- package/packages/mailx-store-web/android-bootstrap.js.map +1 -0
- package/packages/mailx-store-web/android-bootstrap.ts +1262 -0
- package/packages/mailx-store-web/db.d.ts +132 -0
- package/packages/mailx-store-web/db.d.ts.map +1 -0
- package/packages/mailx-store-web/db.js +642 -0
- package/packages/mailx-store-web/db.js.map +1 -0
- package/packages/mailx-store-web/db.ts +756 -0
- package/packages/mailx-store-web/gmail-api-web.d.ts +11 -0
- package/packages/mailx-store-web/gmail-api-web.d.ts.map +1 -0
- package/packages/mailx-store-web/gmail-api-web.js +11 -0
- package/packages/mailx-store-web/gmail-api-web.js.map +1 -0
- package/packages/mailx-store-web/gmail-api-web.ts +11 -0
- package/packages/mailx-store-web/imap-web-provider.d.ts +33 -0
- package/packages/mailx-store-web/imap-web-provider.d.ts.map +1 -0
- package/packages/mailx-store-web/imap-web-provider.js +140 -0
- package/packages/mailx-store-web/imap-web-provider.js.map +1 -0
- package/packages/mailx-store-web/imap-web-provider.ts +156 -0
- package/packages/mailx-store-web/index.d.ts +10 -0
- package/packages/mailx-store-web/index.d.ts.map +1 -0
- package/packages/mailx-store-web/index.js +10 -0
- package/packages/mailx-store-web/index.js.map +1 -0
- package/packages/mailx-store-web/index.ts +10 -0
- package/packages/mailx-store-web/main-thread-host.d.ts +15 -0
- package/packages/mailx-store-web/main-thread-host.d.ts.map +1 -0
- package/packages/mailx-store-web/main-thread-host.js +292 -0
- package/packages/mailx-store-web/main-thread-host.js.map +1 -0
- package/packages/mailx-store-web/main-thread-host.ts +322 -0
- package/packages/mailx-store-web/package.json +23 -0
- package/packages/mailx-store-web/provider-types.d.ts +7 -0
- package/packages/mailx-store-web/provider-types.d.ts.map +1 -0
- package/packages/mailx-store-web/provider-types.js +7 -0
- package/packages/mailx-store-web/provider-types.js.map +1 -0
- package/packages/mailx-store-web/provider-types.ts +7 -0
- package/packages/mailx-store-web/sql-wasm-esm.js +10 -0
- package/packages/mailx-store-web/sql.js.d.ts +29 -0
- package/packages/mailx-store-web/sync-manager.d.ts +68 -0
- package/packages/mailx-store-web/sync-manager.d.ts.map +1 -0
- package/packages/mailx-store-web/sync-manager.js +506 -0
- package/packages/mailx-store-web/sync-manager.js.map +1 -0
- package/packages/mailx-store-web/sync-manager.ts +508 -0
- package/packages/mailx-store-web/tsconfig.json +10 -0
- package/packages/mailx-store-web/web-jsonrpc.d.ts +20 -0
- package/packages/mailx-store-web/web-jsonrpc.d.ts.map +1 -0
- package/packages/mailx-store-web/web-jsonrpc.js +102 -0
- package/packages/mailx-store-web/web-jsonrpc.js.map +1 -0
- package/packages/mailx-store-web/web-jsonrpc.ts +116 -0
- package/packages/mailx-store-web/web-message-store.d.ts +16 -0
- package/packages/mailx-store-web/web-message-store.d.ts.map +1 -0
- package/packages/mailx-store-web/web-message-store.js +89 -0
- package/packages/mailx-store-web/web-message-store.js.map +1 -0
- package/packages/mailx-store-web/web-message-store.ts +97 -0
- package/packages/mailx-store-web/web-service.d.ts +111 -0
- package/packages/mailx-store-web/web-service.d.ts.map +1 -0
- package/packages/mailx-store-web/web-service.js +542 -0
- package/packages/mailx-store-web/web-service.js.map +1 -0
- package/packages/mailx-store-web/web-service.ts +616 -0
- package/packages/mailx-store-web/web-settings.d.ts +83 -0
- package/packages/mailx-store-web/web-settings.d.ts.map +1 -0
- package/packages/mailx-store-web/web-settings.js +491 -0
- package/packages/mailx-store-web/web-settings.js.map +1 -0
- package/packages/mailx-store-web/web-settings.ts +522 -0
- package/packages/mailx-store-web/worker-bundle.js +6838 -0
- package/packages/mailx-store-web/worker-entry.d.ts +8 -0
- package/packages/mailx-store-web/worker-entry.d.ts.map +1 -0
- package/packages/mailx-store-web/worker-entry.js +187 -0
- package/packages/mailx-store-web/worker-entry.js.map +1 -0
- package/packages/mailx-store-web/worker-entry.ts +215 -0
- package/packages/mailx-store-web/worker-tcp-transport.d.ts +28 -0
- package/packages/mailx-store-web/worker-tcp-transport.d.ts.map +1 -0
- package/packages/mailx-store-web/worker-tcp-transport.js +98 -0
- package/packages/mailx-store-web/worker-tcp-transport.js.map +1 -0
- package/packages/mailx-store-web/worker-tcp-transport.ts +101 -0
- package/packages/mailx-types/.gitattributes +10 -0
- package/packages/mailx-types/index.d.ts +319 -0
- package/packages/mailx-types/index.d.ts.map +1 -0
- package/packages/mailx-types/index.js +243 -0
- package/packages/mailx-types/index.js.map +1 -0
- package/packages/mailx-types/index.ts +498 -0
- package/packages/mailx-types/package.json +16 -0
- package/packages/mailx-types/tsconfig.json +9 -0
- package/packages/mailx-types/tsconfig.tsbuildinfo +1 -0
- package/todo.json +13 -0
- package/tsconfig.base.json +31 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Calendar / Tasks / People (Contacts) two-way sync helpers.
|
|
3
|
+
*
|
|
4
|
+
* Used by MailxService to push local edits to Google and pull server
|
|
5
|
+
* changes into the local cache. All functions take a `getToken` function
|
|
6
|
+
* and a fetch implementation so they stay platform-agnostic (Node uses
|
|
7
|
+
* global `fetch` on Node 18+; browsers use window.fetch).
|
|
8
|
+
*
|
|
9
|
+
* Error handling: throws on network / HTTP errors. Caller catches and
|
|
10
|
+
* either retries via the store_sync drainer or surfaces to the UI.
|
|
11
|
+
*/
|
|
12
|
+
export class GoogleHttpError extends Error {
|
|
13
|
+
status;
|
|
14
|
+
statusText;
|
|
15
|
+
body;
|
|
16
|
+
constructor(status, statusText, body) {
|
|
17
|
+
super(`Google API ${status} ${statusText}: ${body.slice(0, 300)}`);
|
|
18
|
+
this.status = status;
|
|
19
|
+
this.statusText = statusText;
|
|
20
|
+
this.body = body;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function googleFetch(tokenProvider, url, init = {}) {
|
|
24
|
+
const token = await tokenProvider();
|
|
25
|
+
const headers = new Headers(init.headers || {});
|
|
26
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
27
|
+
if (init.body && !headers.has("Content-Type"))
|
|
28
|
+
headers.set("Content-Type", "application/json");
|
|
29
|
+
const res = await fetch(url, { ...init, headers });
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
const body = await res.text().catch(() => "");
|
|
32
|
+
throw new GoogleHttpError(res.status, res.statusText, body);
|
|
33
|
+
}
|
|
34
|
+
return res;
|
|
35
|
+
}
|
|
36
|
+
export async function listCalendarEvents(tokenProvider, fromMs, toMs, calendarId = "primary") {
|
|
37
|
+
const from = new Date(fromMs).toISOString();
|
|
38
|
+
const to = new Date(toMs).toISOString();
|
|
39
|
+
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events`
|
|
40
|
+
+ `?timeMin=${encodeURIComponent(from)}&timeMax=${encodeURIComponent(to)}`
|
|
41
|
+
+ `&singleEvents=true&orderBy=startTime&maxResults=250`;
|
|
42
|
+
const all = [];
|
|
43
|
+
let pageToken;
|
|
44
|
+
do {
|
|
45
|
+
const pagedUrl = pageToken ? `${url}&pageToken=${encodeURIComponent(pageToken)}` : url;
|
|
46
|
+
const res = await googleFetch(tokenProvider, pagedUrl);
|
|
47
|
+
const data = await res.json();
|
|
48
|
+
for (const ev of (data.items || []))
|
|
49
|
+
all.push(ev);
|
|
50
|
+
pageToken = data.nextPageToken;
|
|
51
|
+
} while (pageToken);
|
|
52
|
+
return all;
|
|
53
|
+
}
|
|
54
|
+
export async function createCalendarEvent(tokenProvider, event, calendarId = "primary") {
|
|
55
|
+
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events`;
|
|
56
|
+
const res = await googleFetch(tokenProvider, url, { method: "POST", body: JSON.stringify(event) });
|
|
57
|
+
return res.json();
|
|
58
|
+
}
|
|
59
|
+
export async function updateCalendarEvent(tokenProvider, eventId, event, calendarId = "primary") {
|
|
60
|
+
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events/${encodeURIComponent(eventId)}`;
|
|
61
|
+
const res = await googleFetch(tokenProvider, url, { method: "PATCH", body: JSON.stringify(event) });
|
|
62
|
+
return res.json();
|
|
63
|
+
}
|
|
64
|
+
export async function deleteCalendarEvent(tokenProvider, eventId, calendarId = "primary") {
|
|
65
|
+
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events/${encodeURIComponent(eventId)}`;
|
|
66
|
+
await googleFetch(tokenProvider, url, { method: "DELETE" });
|
|
67
|
+
}
|
|
68
|
+
export async function listTasks(tokenProvider, listId = "@default", showCompleted = false) {
|
|
69
|
+
const url = `https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(listId)}/tasks`
|
|
70
|
+
+ `?showCompleted=${showCompleted}&maxResults=100`;
|
|
71
|
+
const res = await googleFetch(tokenProvider, url);
|
|
72
|
+
const data = await res.json();
|
|
73
|
+
return data.items || [];
|
|
74
|
+
}
|
|
75
|
+
export async function createTask(tokenProvider, task, listId = "@default") {
|
|
76
|
+
const url = `https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(listId)}/tasks`;
|
|
77
|
+
const res = await googleFetch(tokenProvider, url, { method: "POST", body: JSON.stringify(task) });
|
|
78
|
+
return res.json();
|
|
79
|
+
}
|
|
80
|
+
export async function updateTask(tokenProvider, taskId, task, listId = "@default") {
|
|
81
|
+
const url = `https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(listId)}/tasks/${encodeURIComponent(taskId)}`;
|
|
82
|
+
const res = await googleFetch(tokenProvider, url, { method: "PATCH", body: JSON.stringify(task) });
|
|
83
|
+
return res.json();
|
|
84
|
+
}
|
|
85
|
+
export async function deleteTask(tokenProvider, taskId, listId = "@default") {
|
|
86
|
+
const url = `https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(listId)}/tasks/${encodeURIComponent(taskId)}`;
|
|
87
|
+
await googleFetch(tokenProvider, url, { method: "DELETE" });
|
|
88
|
+
}
|
|
89
|
+
// ── Contacts (People API) ──
|
|
90
|
+
export async function createContact(tokenProvider, person) {
|
|
91
|
+
const url = `https://people.googleapis.com/v1/people:createContact`;
|
|
92
|
+
const res = await googleFetch(tokenProvider, url, { method: "POST", body: JSON.stringify(person) });
|
|
93
|
+
return res.json();
|
|
94
|
+
}
|
|
95
|
+
export async function updateContact(tokenProvider, resourceName, updatePersonFields, person) {
|
|
96
|
+
const url = `https://people.googleapis.com/v1/${resourceName}:updateContact`
|
|
97
|
+
+ `?updatePersonFields=${encodeURIComponent(updatePersonFields)}`;
|
|
98
|
+
const res = await googleFetch(tokenProvider, url, { method: "PATCH", body: JSON.stringify(person) });
|
|
99
|
+
return res.json();
|
|
100
|
+
}
|
|
101
|
+
export async function deleteContact(tokenProvider, resourceName) {
|
|
102
|
+
const url = `https://people.googleapis.com/v1/${resourceName}:deleteContact`;
|
|
103
|
+
await googleFetch(tokenProvider, url, { method: "DELETE" });
|
|
104
|
+
}
|
|
105
|
+
// ── Conversion helpers ──
|
|
106
|
+
export function calendarEventToLocal(ev, accountId) {
|
|
107
|
+
const allDay = !!ev.start.date && !ev.start.dateTime;
|
|
108
|
+
const startMs = allDay
|
|
109
|
+
? Date.parse(ev.start.date)
|
|
110
|
+
: Date.parse(ev.start.dateTime);
|
|
111
|
+
const endMs = allDay
|
|
112
|
+
? Date.parse(ev.end.date)
|
|
113
|
+
: Date.parse(ev.end.dateTime);
|
|
114
|
+
return {
|
|
115
|
+
providerId: ev.id, accountId,
|
|
116
|
+
title: ev.summary || "(no title)",
|
|
117
|
+
startMs, endMs, allDay,
|
|
118
|
+
location: ev.location || "", notes: ev.description || "",
|
|
119
|
+
etag: ev.etag || "",
|
|
120
|
+
recurringEventId: ev.recurringEventId,
|
|
121
|
+
htmlLink: ev.htmlLink,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export function localToCalendarEvent(local) {
|
|
125
|
+
const toIso = (ms) => new Date(ms).toISOString();
|
|
126
|
+
const toDate = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
127
|
+
return {
|
|
128
|
+
summary: local.title,
|
|
129
|
+
start: local.allDay ? { date: toDate(local.startMs) } : { dateTime: toIso(local.startMs) },
|
|
130
|
+
end: local.allDay ? { date: toDate(local.endMs) } : { dateTime: toIso(local.endMs) },
|
|
131
|
+
location: local.location || undefined,
|
|
132
|
+
description: local.notes || undefined,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function taskToLocal(t, accountId) {
|
|
136
|
+
return {
|
|
137
|
+
providerId: t.id, accountId, title: t.title || "",
|
|
138
|
+
notes: t.notes || "",
|
|
139
|
+
dueMs: t.due ? Date.parse(t.due) : undefined,
|
|
140
|
+
completedMs: t.completed ? Date.parse(t.completed) : undefined,
|
|
141
|
+
etag: t.etag || "",
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export function localToTask(local) {
|
|
145
|
+
return {
|
|
146
|
+
title: local.title,
|
|
147
|
+
notes: local.notes || undefined,
|
|
148
|
+
due: local.dueMs ? new Date(local.dueMs).toISOString() : undefined,
|
|
149
|
+
completed: local.completedMs ? new Date(local.completedMs).toISOString() : undefined,
|
|
150
|
+
status: local.completedMs ? "completed" : "needsAction",
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=google-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-sync.js","sourceRoot":"","sources":["google-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACtC,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,IAAI,CAAS;IACb,YAAY,MAAc,EAAE,UAAkB,EAAE,IAAY;QACxD,KAAK,CAAC,cAAc,MAAM,IAAI,UAAU,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAED,KAAK,UAAU,WAAW,CACtB,aAA4B,EAAE,GAAW,EAAE,OAAoB,EAAE;IAEjE,MAAM,KAAK,GAAG,MAAM,aAAa,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;IAChD,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB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,KAAK,CAAC,KAAK,IAAI,SAAS;QAC/B,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;QAClE,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;QACpF,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa;KAC1D,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Calendar / Tasks / People (Contacts) two-way sync helpers.
|
|
3
|
+
*
|
|
4
|
+
* Used by MailxService to push local edits to Google and pull server
|
|
5
|
+
* changes into the local cache. All functions take a `getToken` function
|
|
6
|
+
* and a fetch implementation so they stay platform-agnostic (Node uses
|
|
7
|
+
* global `fetch` on Node 18+; browsers use window.fetch).
|
|
8
|
+
*
|
|
9
|
+
* Error handling: throws on network / HTTP errors. Caller catches and
|
|
10
|
+
* either retries via the store_sync drainer or surfaces to the UI.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
type TokenProvider = () => Promise<string>;
|
|
14
|
+
|
|
15
|
+
export class GoogleHttpError extends Error {
|
|
16
|
+
status: number;
|
|
17
|
+
statusText: string;
|
|
18
|
+
body: string;
|
|
19
|
+
constructor(status: number, statusText: string, body: string) {
|
|
20
|
+
super(`Google API ${status} ${statusText}: ${body.slice(0, 300)}`);
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.statusText = statusText;
|
|
23
|
+
this.body = body;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function googleFetch(
|
|
28
|
+
tokenProvider: TokenProvider, url: string, init: RequestInit = {},
|
|
29
|
+
): Promise<Response> {
|
|
30
|
+
const token = await tokenProvider();
|
|
31
|
+
const headers = new Headers(init.headers || {});
|
|
32
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
33
|
+
if (init.body && !headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
34
|
+
const res = await fetch(url, { ...init, headers });
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
const body = await res.text().catch(() => "");
|
|
37
|
+
throw new GoogleHttpError(res.status, res.statusText, body);
|
|
38
|
+
}
|
|
39
|
+
return res;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ── Calendar ──
|
|
43
|
+
|
|
44
|
+
export interface GCalEvent {
|
|
45
|
+
id: string;
|
|
46
|
+
summary: string;
|
|
47
|
+
start: { dateTime?: string; date?: string };
|
|
48
|
+
end: { dateTime?: string; date?: string };
|
|
49
|
+
location?: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
etag?: string;
|
|
52
|
+
/** Set on instances expanded from a recurring series (singleEvents=true).
|
|
53
|
+
* Absent for singletons. Lets the UI filter out recurring expansions. */
|
|
54
|
+
recurringEventId?: string;
|
|
55
|
+
/** Link to open the event in Google Calendar web. */
|
|
56
|
+
htmlLink?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function listCalendarEvents(
|
|
60
|
+
tokenProvider: TokenProvider, fromMs: number, toMs: number, calendarId = "primary",
|
|
61
|
+
): Promise<GCalEvent[]> {
|
|
62
|
+
const from = new Date(fromMs).toISOString();
|
|
63
|
+
const to = new Date(toMs).toISOString();
|
|
64
|
+
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events`
|
|
65
|
+
+ `?timeMin=${encodeURIComponent(from)}&timeMax=${encodeURIComponent(to)}`
|
|
66
|
+
+ `&singleEvents=true&orderBy=startTime&maxResults=250`;
|
|
67
|
+
const all: GCalEvent[] = [];
|
|
68
|
+
let pageToken: string | undefined;
|
|
69
|
+
do {
|
|
70
|
+
const pagedUrl = pageToken ? `${url}&pageToken=${encodeURIComponent(pageToken)}` : url;
|
|
71
|
+
const res = await googleFetch(tokenProvider, pagedUrl);
|
|
72
|
+
const data = await res.json() as any;
|
|
73
|
+
for (const ev of (data.items || [])) all.push(ev);
|
|
74
|
+
pageToken = data.nextPageToken;
|
|
75
|
+
} while (pageToken);
|
|
76
|
+
return all;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function createCalendarEvent(
|
|
80
|
+
tokenProvider: TokenProvider, event: any, calendarId = "primary",
|
|
81
|
+
): Promise<GCalEvent> {
|
|
82
|
+
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events`;
|
|
83
|
+
const res = await googleFetch(tokenProvider, url, { method: "POST", body: JSON.stringify(event) });
|
|
84
|
+
return res.json();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function updateCalendarEvent(
|
|
88
|
+
tokenProvider: TokenProvider, eventId: string, event: any, calendarId = "primary",
|
|
89
|
+
): Promise<GCalEvent> {
|
|
90
|
+
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events/${encodeURIComponent(eventId)}`;
|
|
91
|
+
const res = await googleFetch(tokenProvider, url, { method: "PATCH", body: JSON.stringify(event) });
|
|
92
|
+
return res.json();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function deleteCalendarEvent(
|
|
96
|
+
tokenProvider: TokenProvider, eventId: string, calendarId = "primary",
|
|
97
|
+
): Promise<void> {
|
|
98
|
+
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events/${encodeURIComponent(eventId)}`;
|
|
99
|
+
await googleFetch(tokenProvider, url, { method: "DELETE" });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ── Tasks ──
|
|
103
|
+
|
|
104
|
+
export interface GTask {
|
|
105
|
+
id: string;
|
|
106
|
+
title: string;
|
|
107
|
+
notes?: string;
|
|
108
|
+
due?: string;
|
|
109
|
+
completed?: string;
|
|
110
|
+
status?: "needsAction" | "completed";
|
|
111
|
+
etag?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function listTasks(
|
|
115
|
+
tokenProvider: TokenProvider, listId = "@default", showCompleted = false,
|
|
116
|
+
): Promise<GTask[]> {
|
|
117
|
+
const url = `https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(listId)}/tasks`
|
|
118
|
+
+ `?showCompleted=${showCompleted}&maxResults=100`;
|
|
119
|
+
const res = await googleFetch(tokenProvider, url);
|
|
120
|
+
const data = await res.json() as any;
|
|
121
|
+
return data.items || [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function createTask(
|
|
125
|
+
tokenProvider: TokenProvider, task: any, listId = "@default",
|
|
126
|
+
): Promise<GTask> {
|
|
127
|
+
const url = `https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(listId)}/tasks`;
|
|
128
|
+
const res = await googleFetch(tokenProvider, url, { method: "POST", body: JSON.stringify(task) });
|
|
129
|
+
return res.json();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function updateTask(
|
|
133
|
+
tokenProvider: TokenProvider, taskId: string, task: any, listId = "@default",
|
|
134
|
+
): Promise<GTask> {
|
|
135
|
+
const url = `https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(listId)}/tasks/${encodeURIComponent(taskId)}`;
|
|
136
|
+
const res = await googleFetch(tokenProvider, url, { method: "PATCH", body: JSON.stringify(task) });
|
|
137
|
+
return res.json();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function deleteTask(
|
|
141
|
+
tokenProvider: TokenProvider, taskId: string, listId = "@default",
|
|
142
|
+
): Promise<void> {
|
|
143
|
+
const url = `https://tasks.googleapis.com/tasks/v1/lists/${encodeURIComponent(listId)}/tasks/${encodeURIComponent(taskId)}`;
|
|
144
|
+
await googleFetch(tokenProvider, url, { method: "DELETE" });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ── Contacts (People API) ──
|
|
148
|
+
|
|
149
|
+
export async function createContact(
|
|
150
|
+
tokenProvider: TokenProvider, person: any,
|
|
151
|
+
): Promise<any> {
|
|
152
|
+
const url = `https://people.googleapis.com/v1/people:createContact`;
|
|
153
|
+
const res = await googleFetch(tokenProvider, url, { method: "POST", body: JSON.stringify(person) });
|
|
154
|
+
return res.json();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function updateContact(
|
|
158
|
+
tokenProvider: TokenProvider, resourceName: string, updatePersonFields: string, person: any,
|
|
159
|
+
): Promise<any> {
|
|
160
|
+
const url = `https://people.googleapis.com/v1/${resourceName}:updateContact`
|
|
161
|
+
+ `?updatePersonFields=${encodeURIComponent(updatePersonFields)}`;
|
|
162
|
+
const res = await googleFetch(tokenProvider, url, { method: "PATCH", body: JSON.stringify(person) });
|
|
163
|
+
return res.json();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function deleteContact(
|
|
167
|
+
tokenProvider: TokenProvider, resourceName: string,
|
|
168
|
+
): Promise<void> {
|
|
169
|
+
const url = `https://people.googleapis.com/v1/${resourceName}:deleteContact`;
|
|
170
|
+
await googleFetch(tokenProvider, url, { method: "DELETE" });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ── Conversion helpers ──
|
|
174
|
+
|
|
175
|
+
export function calendarEventToLocal(ev: GCalEvent, accountId: string): {
|
|
176
|
+
providerId: string; accountId: string; title: string;
|
|
177
|
+
startMs: number; endMs: number; allDay: boolean;
|
|
178
|
+
location: string; notes: string; etag: string;
|
|
179
|
+
recurringEventId: string | undefined;
|
|
180
|
+
htmlLink: string | undefined;
|
|
181
|
+
} {
|
|
182
|
+
const allDay = !!ev.start.date && !ev.start.dateTime;
|
|
183
|
+
const startMs = allDay
|
|
184
|
+
? Date.parse(ev.start.date!)
|
|
185
|
+
: Date.parse(ev.start.dateTime!);
|
|
186
|
+
const endMs = allDay
|
|
187
|
+
? Date.parse(ev.end.date!)
|
|
188
|
+
: Date.parse(ev.end.dateTime!);
|
|
189
|
+
return {
|
|
190
|
+
providerId: ev.id, accountId,
|
|
191
|
+
title: ev.summary || "(no title)",
|
|
192
|
+
startMs, endMs, allDay,
|
|
193
|
+
location: ev.location || "", notes: ev.description || "",
|
|
194
|
+
etag: ev.etag || "",
|
|
195
|
+
recurringEventId: ev.recurringEventId,
|
|
196
|
+
htmlLink: ev.htmlLink,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function localToCalendarEvent(local: {
|
|
201
|
+
title: string; startMs: number; endMs: number; allDay?: boolean;
|
|
202
|
+
location?: string; notes?: string;
|
|
203
|
+
}): any {
|
|
204
|
+
const toIso = (ms: number) => new Date(ms).toISOString();
|
|
205
|
+
const toDate = (ms: number) => new Date(ms).toISOString().slice(0, 10);
|
|
206
|
+
return {
|
|
207
|
+
summary: local.title,
|
|
208
|
+
start: local.allDay ? { date: toDate(local.startMs) } : { dateTime: toIso(local.startMs) },
|
|
209
|
+
end: local.allDay ? { date: toDate(local.endMs) } : { dateTime: toIso(local.endMs) },
|
|
210
|
+
location: local.location || undefined,
|
|
211
|
+
description: local.notes || undefined,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function taskToLocal(t: GTask, accountId: string): {
|
|
216
|
+
providerId: string; accountId: string; title: string; notes: string;
|
|
217
|
+
dueMs: number | undefined; completedMs: number | undefined; etag: string;
|
|
218
|
+
} {
|
|
219
|
+
return {
|
|
220
|
+
providerId: t.id, accountId, title: t.title || "",
|
|
221
|
+
notes: t.notes || "",
|
|
222
|
+
dueMs: t.due ? Date.parse(t.due) : undefined,
|
|
223
|
+
completedMs: t.completed ? Date.parse(t.completed) : undefined,
|
|
224
|
+
etag: t.etag || "",
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function localToTask(local: {
|
|
229
|
+
title: string; notes?: string; dueMs?: number; completedMs?: number;
|
|
230
|
+
}): any {
|
|
231
|
+
return {
|
|
232
|
+
title: local.title,
|
|
233
|
+
notes: local.notes || undefined,
|
|
234
|
+
due: local.dueMs ? new Date(local.dueMs).toISOString() : undefined,
|
|
235
|
+
completed: local.completedMs ? new Date(local.completedMs).toISOString() : undefined,
|
|
236
|
+
status: local.completedMs ? "completed" : "needsAction",
|
|
237
|
+
};
|
|
238
|
+
}
|