@particle-academy/gmail-inbox-js 0.1.0 → 0.3.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 CHANGED
@@ -12,6 +12,63 @@ derived — somebody has to write what changed — but writing it in the
12
12
  provider repo would be a hand-edit that `.weaver.json` flags and the next
13
13
  sync destroys.
14
14
 
15
+ ## [0.3.0] — 2026-11-08
16
+
17
+ ### Added
18
+
19
+ - **Laravel integration, in this package** (`src/Laravel/`), auto-discovered
20
+ through composer's `extra.laravel`. Laravel is SUGGESTED, never required:
21
+ outside a Laravel app none of it loads.
22
+ - a service provider that merges `config/gmail-inbox.php` under
23
+ `connectors.gmail-inbox` (credentials from the environment, or per call for a
24
+ multi-account app);
25
+ - the `GmailInbox` facade: `GmailInbox::call('<operation>', [...])` runs any action;
26
+ - `GmailInbox::fake()`, answered from the connector's faker, with
27
+ `assertSent` / `assertNotSent` / `assertNothingSent` / `assertSentCount`;
28
+ - a webhook ROUTE per trigger (`Route::gmailInboxMessageReceived('/path')`) that VERIFIES the raw delivery with the trigger's own scheme before the app sees it, answers 401 with the reason when it does not, then dispatches an event (`Events\\…Received`);
29
+ - its own Pest test of all of it against a booted Laravel app.
30
+
31
+ ### Changed
32
+
33
+ - **Tests: Pest `^5`**, and `laravel/framework` `^13` as a DEV-ONLY test
34
+ dependency (the framework this package integrates with; nothing ships in
35
+ `require`).
36
+
37
+ ## [0.2.0] — 2026-11-08
38
+
39
+ ### Added
40
+
41
+ - **`message_received`: a trigger for new Gmail mail, still read-only**
42
+ (`gmail.readonly` is the only scope). `mailbox_watch` makes Gmail publish
43
+ mailbox changes to a Cloud Pub/Sub topic in YOUR app's own Google Cloud
44
+ project, and a push subscription delivers each change to your host.
45
+ - **Every push is verified before anything reads it.** It carries a
46
+ Google-signed token in `Authorization`, checked for Google's issuer, the
47
+ subscription's audience (`pushAudience`), and the push service account
48
+ with `email_verified` true (`pushServiceAccount`). The service-account
49
+ check is what refuses a stranger's subscription aimed at your URL.
50
+ - **Routing.** The Pub/Sub envelope is unwrapped, then the push is routed by
51
+ `emailAddress`, only after verification. One topic serves every mailbox.
52
+ - **What arrives.** A push carries only the mailbox's NEW position, so the
53
+ trigger reads `history.list` from the cursor YOUR HOST stored. It reads
54
+ every page and publishes the changes under `history` with `cursor: {used,
55
+ next}`. Your host persists `cursor.next` when a run succeeds.
56
+ - **Received mail only, by default:** `labelId: INBOX` and `historyTypes:
57
+ messageAdded`, so no sent mail or drafts. Widen either in the trigger's
58
+ config.
59
+ - **A lapsed cursor** (Gmail's 404) or more than 20 pages fails by name, as
60
+ `cursor-expired` or `cursor-overflow`. Each carries a bounded resync query
61
+ (`newer_than:7d`; `resyncWindowDays` sets it, default 7). Watch again
62
+ first, then list with that query. The mailbox is never fully re-pulled.
63
+ - **The watch is a lease:** Gmail's `expiration` is in epoch milliseconds,
64
+ renewed by watching again, a day early. Google requires at least once
65
+ every 7 days and recommends daily.
66
+ - **Read state is never changed.**
67
+
68
+ New actions: `mailbox_watch`, `mailbox_stop` and `history_list`. New
69
+ credentials: `pushAudience` and `pushServiceAccount`, needed only for the
70
+ trigger. Requires fancy-connector-core 0.14.0.
71
+
15
72
  ## [0.1.0] — 2026-10-01
16
73
 
17
74
  ### Added
package/README.md CHANGED
@@ -35,7 +35,7 @@ Everything below is generated from `provider/manifest.json`, so it cannot disagr
35
35
 
36
36
  ### Credentials
37
37
 
38
- A Gmail Inbox connection holds 4 values.
38
+ A Gmail Inbox connection holds 6 values.
39
39
 
40
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
41
 
@@ -45,6 +45,8 @@ A Gmail Inbox connection holds 4 values.
45
45
  | **OAuth client secret** | per installation | **secret** | The client secret for the same OAuth app. One value for the whole installation. |
46
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
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. |
48
50
 
49
51
  ### Authorising
50
52
 
@@ -67,6 +69,21 @@ The refresh tokens do **not** rotate: the same one is reusable, so a refresh may
67
69
 
68
70
  ### Actions
69
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
+
70
87
  #### `label_list` — List Gmail labels
71
88
 
72
89
  List every label on the mailbox, system and user-created.
@@ -77,6 +94,29 @@ List every label on the mailbox, system and user-created.
77
94
  |---|---|---|
78
95
  | `userId` | yes | Mailbox |
79
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
+
80
120
  #### `message_get` — Gmail message
81
121
 
82
122
  Read one message's headers and preview. The body's plain/HTML text is NOT decoded -- see the raw payload for that.
@@ -114,6 +154,18 @@ Read every message in a conversation thread, oldest first.
114
154
  | `userId` | yes | Mailbox |
115
155
  | `id` | yes | A message's threadId, from message_list or message_get. |
116
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
+
117
169
  ## Run it before you have credentials
118
170
 
119
171
  Every operation ships a **faker**, whether or not Gmail Inbox has a sandbox. Set a