@particle-academy/gmail-inbox-js 0.0.0 → 0.2.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,75 @@
1
+ # Changelog — Gmail Inbox
2
+
3
+ All four packages — `@particle-academy/gmail-inbox-ui`, `@particle-academy/gmail-inbox-js`,
4
+ `particle-academy/gmail-inbox-php` and `fancy-gmail-inbox` — are released together
5
+ under one version. They are generated from one `provider/` definition, so a
6
+ change to it changes all four, and separate version lines would only record
7
+ which of the four somebody remembered to bump.
8
+
9
+ **Write entries HERE**, in the weaver envelope at `providers/gmail-inbox/CHANGELOG.md`,
10
+ then regenerate. This file is the one thing in a release that cannot be
11
+ derived — somebody has to write what changed — but writing it in the
12
+ provider repo would be a hand-edit that `.weaver.json` flags and the next
13
+ sync destroys.
14
+
15
+ ## [0.2.0] — 2026-11-08
16
+
17
+ ### Added
18
+
19
+ - **`message_received`: a trigger for new Gmail mail, still read-only**
20
+ (`gmail.readonly` is the only scope). `mailbox_watch` makes Gmail publish
21
+ mailbox changes to a Cloud Pub/Sub topic in YOUR app's own Google Cloud
22
+ project, and a push subscription delivers each change to your host.
23
+ - **Every push is verified before anything reads it.** It carries a
24
+ Google-signed token in `Authorization`, checked for Google's issuer, the
25
+ subscription's audience (`pushAudience`), and the push service account
26
+ with `email_verified` true (`pushServiceAccount`). The service-account
27
+ check is what refuses a stranger's subscription aimed at your URL.
28
+ - **Routing.** The Pub/Sub envelope is unwrapped, then the push is routed by
29
+ `emailAddress`, only after verification. One topic serves every mailbox.
30
+ - **What arrives.** A push carries only the mailbox's NEW position, so the
31
+ trigger reads `history.list` from the cursor YOUR HOST stored. It reads
32
+ every page and publishes the changes under `history` with `cursor: {used,
33
+ next}`. Your host persists `cursor.next` when a run succeeds.
34
+ - **Received mail only, by default:** `labelId: INBOX` and `historyTypes:
35
+ messageAdded`, so no sent mail or drafts. Widen either in the trigger's
36
+ config.
37
+ - **A lapsed cursor** (Gmail's 404) or more than 20 pages fails by name, as
38
+ `cursor-expired` or `cursor-overflow`. Each carries a bounded resync query
39
+ (`newer_than:7d`; `resyncWindowDays` sets it, default 7). Watch again
40
+ first, then list with that query. The mailbox is never fully re-pulled.
41
+ - **The watch is a lease:** Gmail's `expiration` is in epoch milliseconds,
42
+ renewed by watching again, a day early. Google requires at least once
43
+ every 7 days and recommends daily.
44
+ - **Read state is never changed.**
45
+
46
+ New actions: `mailbox_watch`, `mailbox_stop` and `history_list`. New
47
+ credentials: `pushAudience` and `pushServiceAccount`, needed only for the
48
+ trigger. Requires fancy-connector-core 0.14.0.
49
+
50
+ ## [0.1.0] — 2026-10-01
51
+
52
+ ### Added
53
+
54
+ - **First release.** `message_list` (search, label filter, pagination),
55
+ `message_get`, `thread_get`, `label_list`. OAuth2 with `gmail.readonly`.
56
+ - **A SEPARATE connector from `gmail`, by design, not a scope widening of
57
+ it.** `gmail.readonly` is a RESTRICTED Google OAuth scope requiring an
58
+ annual CASA security assessment on the app that requests it, and
59
+ Google's verification is per OAUTH CLIENT — attaching it to `gmail`'s
60
+ own client would have put the recurring assessment on every existing
61
+ send-only consumer. A second connector, a second OAuth client, puts it
62
+ only where it is actually needed. Part of the owner's Google Workspace
63
+ commission (Tynn #19) — Fancy's own compliance audit found this before
64
+ any code was written, and the split was decided before this connector
65
+ existed.
66
+ - `message_get` and `thread_get` publish `payload.headers` (From, To,
67
+ Subject, Date, unparsed) and Gmail's own `snippet` preview, but do NOT
68
+ decode the MIME body tree — `payload.parts` can nest arbitrarily for a
69
+ multipart message, and flattening it to plain text/HTML is real parsing
70
+ work this connector does not do yet. The raw `payload` is still
71
+ published for a host that wants to decode it. Noted rather than
72
+ rushed, the same shape as Drive's deferred file upload.
73
+ - Gmail has no sandbox — every read reaches the connected account's real
74
+ mailbox. The faker is the only way to develop against it without doing
75
+ that.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Particle Academy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,190 @@
1
- # @particle-academy/gmail-inbox-js
1
+ # Gmail Inbox
2
2
 
3
- **0.0.0 claims the name and ships nothing.** It exists so a Trusted Publisher can be attached to the package; the first real release is published from https://github.com/Fancy-Friends/gmail-inbox by its `publish.yml` workflow with provenance, and this version is deprecated the moment it lands.
3
+ [![Fancified](art/fancified.svg)](https://particle.academy)
4
+
5
+ Gmail Inbox for [fancy-flow][flow] — as **four imported, versioned packages**, one
6
+ per runtime. Not vendored source: a copy cannot be upgraded, and third-party APIs
7
+ change.
8
+
9
+ [flow]: https://github.com/Particle-Academy/fancy-flow
10
+
11
+ | Runtime | Package | Install |
12
+ |---|---|---|
13
+ | Authoring surface (every host) | `@particle-academy/gmail-inbox-ui` | `npm install @particle-academy/gmail-inbox-ui` |
14
+ | Node | `@particle-academy/gmail-inbox-js` | `npm install @particle-academy/gmail-inbox-js` |
15
+ | PHP 8.4+ | `particle-academy/gmail-inbox-php` | `composer require particle-academy/gmail-inbox-php` |
16
+ | Python 3.11+ | `fancy-gmail-inbox` | `pip install fancy-gmail-inbox` |
17
+
18
+ The `ui` package is the editor surface and is React on every host — a PHP or
19
+ Python project installs it *and* its own runtime package, and never the `js` one.
20
+
21
+ ## What it costs you
22
+
23
+ One dependency: `@particle-academy/fancy-connector-core` (or
24
+ `particle-academy/fancy-connector-core` on Composer), which the `js` and `php`
25
+ packages pull in themselves. The Python package has **zero** runtime
26
+ dependencies.
27
+
28
+ **No Gmail Inbox SDK.** Plain HTTP, deliberately: a vendor SDK is third-party code
29
+ subject to the kit's full approval bar, and one per provider is hundreds of
30
+ dependencies nobody is tracking.
31
+
32
+ ## Setting it up
33
+
34
+ Everything below is generated from `provider/manifest.json`, so it cannot disagree with what the packages do.
35
+
36
+ ### Credentials
37
+
38
+ A Gmail Inbox connection holds 6 values.
39
+
40
+ **Two kinds of value, and mixing them up matters.** A `provider` credential is ONE value for the whole installation — an OAuth app's client secret serves every connected account. An `account` credential is one per connected account. A host that stores the second where it stores the first lets one account's credentials reach another's.
41
+
42
+ | Field | Scope | Secret | Where it comes from |
43
+ |---|---|---|---|
44
+ | **OAuth client ID** | per installation | not secret | A DIFFERENT OAuth app than `gmail`'s, from Google Cloud Console -> APIs & Services -> Credentials. This one requests a restricted scope and carries Google's annual CASA assessment; `gmail`'s does not. Do not reuse the same client for both. |
45
+ | **OAuth client secret** | per installation | **secret** | The client secret for the same OAuth app. One value for the whole installation. |
46
+ | **Access token** | per connected account | **secret** | Per connected Google account, and it expires after ONE HOUR. The host refreshes it with the refresh token. |
47
+ | **Refresh token** | per connected account | **secret** | Per connected Google account. Google issues one only when the consent request asks for offline access; without it the connection dies within the hour. |
48
+ | **Push audience** *(optional)* | per installation | not secret | The audience set on the Pub/Sub PUSH subscription (normally the endpoint URL your host mounts for message_received). Every push's Google-signed token must name it; an unchecked audience accepts any token Google signs for anyone. Needed only for the message_received trigger. |
49
+ | **Push service account** *(optional)* | per installation | not secret | The service account the push subscription authenticates as (its email). Every push's token must be for exactly this account: a stranger's subscription aimed at your URL carries a token Google signed correctly, and only this check refuses it. Needed only for message_received. |
50
+
51
+ ### Authorising
52
+
53
+ Gmail Inbox uses OAuth2 (authorization_code). The package DECLARES the exchange; the HOST performs it — a consent screen needs a browser, a redirect URI and somewhere to persist the result, and all three belong to the host.
54
+
55
+ - **Authorize URL** — https://accounts.google.com/o/oauth2/v2/auth
56
+ - **Token URL** — https://oauth2.googleapis.com/token
57
+ - **Scopes** — `https://www.googleapis.com/auth/gmail.readonly`
58
+ - **Access token lifetime** — 3600 seconds (1 hours). A host that never refreshes works all afternoon and is broken by morning.
59
+
60
+ The refresh tokens do **not** rotate: the same one is reusable, so a refresh may safely be retried and may run concurrently. Stated rather than assumed, because the opposite — a provider that spends the token and revokes the grant on a replay — looks identical until it happens.
61
+
62
+ ### The estate
63
+
64
+ **Gmail Inbox has no test estate, and somebody checked.** Everything this connector does is real. Use the faker to build against it.
65
+
66
+ > Gmail has no sandbox. Every read reaches the connected account's real mail. The faker is the only way to develop against it without touching a real mailbox.
67
+
68
+ ## What it can do
69
+
70
+ ### Actions
71
+
72
+ #### `history_list` — List Gmail mailbox history
73
+
74
+ List what changed in a mailbox since a history id: messages added or deleted, labels added or removed.
75
+
76
+ `GET /gmail/v1/users/{userId}/history` · reads only — safe to replay
77
+
78
+ | Input | Required | What it is |
79
+ |---|---|---|
80
+ | `userId` | yes | `me` is the connected account and is almost always what you want. |
81
+ | `startHistoryId` | yes | Changes AFTER this id. Take it from a watch, a message, or a previous list's historyId. Out of Gmail's range (typically older than a week) it answers 404. |
82
+ | `historyTypes` | no | Blank: every kind. messageAdded is new mail (and sent mail and drafts, unless a label narrows it). |
83
+ | `labelId` | no | Only messages with this label, e.g. INBOX for received mail. |
84
+ | `maxResults` | no | Gmail's own maximum is 500. |
85
+ | `pageToken` | no | From a previous page's nextPageToken. |
86
+
87
+ #### `label_list` — List Gmail labels
88
+
89
+ List every label on the mailbox, system and user-created.
90
+
91
+ `GET /gmail/v1/users/{userId}/labels` · reads only — safe to replay
92
+
93
+ | Input | Required | What it is |
94
+ |---|---|---|
95
+ | `userId` | yes | Mailbox |
96
+
97
+ #### `mailbox_stop` — Stop watching a Gmail mailbox
98
+
99
+ Turn off push notifications for a mailbox.
100
+
101
+ `POST /gmail/v1/users/{userId}/stop` · idempotent — safe to replay
102
+
103
+ | Input | Required | What it is |
104
+ |---|---|---|
105
+ | `userId` | yes | `me` is the connected account and is almost always what you want. |
106
+
107
+ #### `mailbox_watch` — Watch a Gmail mailbox
108
+
109
+ Start (or renew) push notifications for a mailbox to a Cloud Pub/Sub topic.
110
+
111
+ `POST /gmail/v1/users/{userId}/watch` · idempotent — safe to replay
112
+
113
+ | Input | Required | What it is |
114
+ |---|---|---|
115
+ | `userId` | yes | `me` is the connected account and is almost always what you want. |
116
+ | `topicName` | yes | The full topic name, in YOUR app's own Google Cloud project: Google requires its project id to match the project whose OAuth client makes this call. One topic serves every mailbox. |
117
+ | `labelIds` | no | Comma-separated label ids to restrict notifications to (e.g. INBOX). Blank: every change is pushed. |
118
+ | `labelFilterBehavior` | no | Whether the labels above are the ONLY ones notified (include) or the ones NOT notified (exclude). |
119
+
120
+ #### `message_get` — Gmail message
121
+
122
+ Read one message's headers and preview. The body's plain/HTML text is NOT decoded -- see the raw payload for that.
123
+
124
+ `GET /gmail/v1/users/{userId}/messages/{id}` · reads only — safe to replay
125
+
126
+ | Input | Required | What it is |
127
+ |---|---|---|
128
+ | `userId` | yes | Mailbox |
129
+ | `id` | yes | From message_list, or another node's output. |
130
+
131
+ #### `message_list` — List Gmail messages
132
+
133
+ List message ids matching a search, newest first.
134
+
135
+ `GET /gmail/v1/users/{userId}/messages` · reads only — safe to replay
136
+
137
+ | Input | Required | What it is |
138
+ |---|---|---|
139
+ | `userId` | yes | `me` is the connected account and is almost always what you want. |
140
+ | `q` | no | Gmail's own search syntax, exactly as typed into the Gmail search box -- e.g. "from:ada@example.test has:attachment newer_than:7d". Leave blank to list everything. |
141
+ | `labelId` | no | Only messages with this label -- e.g. INBOX, or a label_list id. Gmail's own query parameter accepts several, repeated; this connector offers one for now -- combine more in the search field above instead, using Gmail's own label: search operator. |
142
+ | `includeSpamTrash` | no | Include spam and trash |
143
+ | `maxResults` | no | Gmail's own maximum is 500. |
144
+ | `pageToken` | no | From a previous page's nextPageToken. |
145
+
146
+ #### `thread_get` — Gmail thread
147
+
148
+ Read every message in a conversation thread, oldest first.
149
+
150
+ `GET /gmail/v1/users/{userId}/threads/{id}` · reads only — safe to replay
151
+
152
+ | Input | Required | What it is |
153
+ |---|---|---|
154
+ | `userId` | yes | Mailbox |
155
+ | `id` | yes | A message's threadId, from message_list or message_get. |
156
+
157
+ ### Triggers
158
+
159
+ #### `message_received` — Gmail message received
160
+
161
+ Start when new mail arrives in a watched mailbox, with every new message since the last run.
162
+
163
+ A SUBSCRIPTION: Gmail Inbox delivers to your endpoint only while a subscription it issued is alive, at most 168 hours at a time. Its expiry is read from the `mailbox_watch` response (`expiration`); 86400 seconds before it, the host renews it (`mailbox_watch`). A lease that lapses is re-listed AND re-subscribed, because notifications during the gap are gone. Every delivery: the signature is verified before anything runs. The delivery only names what arrived, so the run's first step reads it: `history_list` with , published under `history`. A failed read fails the run.
164
+
165
+ **You have to set this up with the provider first:**
166
+
167
+ In YOUR app's Google Cloud project (the one owning the OAuth client): create a Pub/Sub topic, grant publish on it to gmail-api-push@system.gserviceaccount.com, and create a PUSH subscription to the route your host mounts for this trigger, with authentication on (a service account you choose; the endpoint URL as the audience). Put that audience and service account on the connection as pushAudience and pushServiceAccount, and fetch Google's signing keys for verification. Then call mailbox_watch with the topic for each mailbox and store its historyId as the trigger's cursor (startHistoryId); renew the watch daily. ONE topic serves every mailbox: route each push by its emailAddress, and only after the token verifies, to a mailbox you watched; drop an unmapped address with a 2xx. Persist cursor.next when a run succeeds. On cursor-expired or cursor-overflow, watch again for a fresh historyId FIRST, then list with message_list using the resyncQuery, and match it against the mail you already handled. This trigger never changes read state.
168
+
169
+ ## Run it before you have credentials
170
+
171
+ Every operation ships a **faker**, whether or not Gmail Inbox has a sandbox. Set a
172
+ node's mode to `fake` and it returns the shape Gmail Inbox actually publishes — the
173
+ same field names, deterministically — so you can wire the downstream nodes before
174
+ touching an account, a key, or a network.
175
+
176
+ ## This repository is generated
177
+
178
+ `provider/` is the source. Everything under `packages/` is emitted from it and
179
+ **must not be hand-edited** — CI regenerates and diffs on every push, and the
180
+ next protocol sync destroys anything it finds. See [`AGENTS.md`](AGENTS.md).
181
+
182
+ ## Two namespaces, which do not match on purpose
183
+
184
+ The repo is `github.com/Fancy-Friends/gmail-inbox`; the packages publish under
185
+ `particle-academy`. Nothing derives one from the other — the names come from
186
+ weaver's `friends.json` and nowhere else.
187
+
188
+ ## Licence
189
+
190
+ MIT.
@@ -0,0 +1,26 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="128" height="28" role="img" aria-label="Fancified — built with Fancy UI">
2
+ <title>Fancified · built with Fancy UI</title>
3
+ <defs>
4
+ <linearGradient id="fcdBg" x1="0" y1="0" x2="1" y2="1">
5
+ <stop offset="0" stop-color="#6d28d9"/>
6
+ <stop offset=".5" stop-color="#9333ea"/>
7
+ <stop offset="1" stop-color="#d946ef"/>
8
+ </linearGradient>
9
+ <linearGradient id="fcdGloss" x1="0" y1="0" x2="0" y2="1">
10
+ <stop offset="0" stop-color="#ffffff" stop-opacity=".30"/>
11
+ <stop offset=".55" stop-color="#ffffff" stop-opacity="0"/>
12
+ </linearGradient>
13
+ <clipPath id="fcdClip"><rect width="128" height="28" rx="7"/></clipPath>
14
+ </defs>
15
+ <g clip-path="url(#fcdClip)">
16
+ <rect width="128" height="28" fill="url(#fcdBg)"/>
17
+ <rect width="34" height="28" fill="#3b0764" fill-opacity=".5"/>
18
+ <rect width="128" height="13" fill="url(#fcdGloss)"/>
19
+ <g fill="#fff">
20
+ <path transform="translate(17 14)" d="M0 -7 C.6 -2.2 2.2 -.6 7 0 C2.2 .6 .6 2.2 0 7 C-.6 2.2 -2.2 .6 -7 0 C-2.2 -.6 -.6 -2.2 0 -7 Z"/>
21
+ <path transform="translate(25.5 7.5) scale(.34)" fill-opacity=".85" d="M0 -7 C.6 -2.2 2.2 -.6 7 0 C2.2 .6 .6 2.2 0 7 C-.6 2.2 -2.2 .6 -7 0 C-2.2 -.6 -.6 -2.2 0 -7 Z"/>
22
+ </g>
23
+ <text x="81" y="18.5" fill="#ffffff" text-anchor="middle" font-family="'Segoe UI',Verdana,'DejaVu Sans',sans-serif" font-size="12" font-weight="700" letter-spacing=".3">Fancified</text>
24
+ </g>
25
+ <rect x=".5" y=".5" width="127" height="27" rx="6.5" fill="none" stroke="#ffffff" stroke-opacity=".22"/>
26
+ </svg>