@particle-academy/google-calendar-js 0.0.0 → 0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@particle-academy/google-calendar-ui`,
4
+ `@particle-academy/google-calendar-js`, `particle-academy/google-calendar-php`
5
+ and `fancy-google-calendar`.
6
+
7
+ The four packages share one version, because they are generated from one
8
+ `provider/` definition and a version that meant something different in each
9
+ would be a version nobody could reason about.
10
+
11
+ ## [0.1.0] — 2026-09-15
12
+
13
+ ### Added
14
+
15
+ - **First release.** Actions `event_get`, `event_list` (full or incremental
16
+ with a `syncToken`; a `410` means list in full again), `channel_watch` and
17
+ `channel_stop`; the `events_changed` trigger, the first in the estate with
18
+ `delivery: "subscription"`. Google cannot renew a channel, so the trigger's
19
+ lease names `channel_watch` again as its renew, 86400 seconds before the
20
+ week-long channel expires. Deliveries carry an EMPTY body and are verified
21
+ by the channel token Google echoes in `X-Goog-Channel-Token`.
22
+ - Requires `fancy-connector-core` ≥ 0.8.0 in js and php — the release that
23
+ carries `LeaseDeclaration` and the shared-token verification scheme.
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,156 @@
1
- # @particle-academy/google-calendar-js
1
+ # Google Calendar
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/google-calendar 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
+ Google Calendar 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/google-calendar-ui` | `npm install @particle-academy/google-calendar-ui` |
14
+ | Node | `@particle-academy/google-calendar-js` | `npm install @particle-academy/google-calendar-js` |
15
+ | PHP 8.4+ | `particle-academy/google-calendar-php` | `composer require particle-academy/google-calendar-php` |
16
+ | Python 3.11+ | `fancy-google-calendar` | `pip install fancy-google-calendar` |
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 Google Calendar 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 Google Calendar connection holds 5 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 | From Google Cloud Console -> APIs & Services -> Credentials. ONE value for the whole installation, not per connected account. |
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
+ | **Channel token** | per connected account | **secret** | A secret the host chooses per connected account and sends as `token` on every events.watch. Google echoes it back in the X-Goog-Channel-Token header of every notification, and that echo is the ONLY thing that authenticates a delivery -- Google does not sign them. Up to 256 characters. |
49
+
50
+ ### Authorising
51
+
52
+ Google Calendar 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.
53
+
54
+ - **Authorize URL** — https://accounts.google.com/o/oauth2/v2/auth
55
+ - **Token URL** — https://oauth2.googleapis.com/token
56
+ - **Scopes** — `https://www.googleapis.com/auth/calendar.events`
57
+ - **Access token lifetime** — 3600 seconds (1 hours). A host that never refreshes works all afternoon and is broken by morning.
58
+
59
+ 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.
60
+
61
+ ### The estate
62
+
63
+ **Google Calendar has no test estate, and somebody checked.** Everything this connector does is real. Use the faker to build against it.
64
+
65
+ > Google has no sandbox for Calendar. A test calendar is a real one in a real account, so every watch and every read is real -- point this at a scratch calendar, not a production one. The faker is the only way to develop against it without touching an account.
66
+
67
+ ## What it can do
68
+
69
+ ### Actions
70
+
71
+ #### `channel_stop` — Google Calendar stop watching
72
+
73
+ Close a push-notification channel. The host's subscription machinery calls this before re-creating a channel and when a trigger is removed.
74
+
75
+ `POST /calendar/v3/channels/stop` · idempotent — safe to replay
76
+
77
+ | Input | Required | What it is |
78
+ |---|---|---|
79
+ | `channelId` | yes | The channel's id, as sent to channel_watch. |
80
+ | `resourceId` | yes | The resourceId channel_watch answered with. Both are needed; Google refuses a stop with only one. |
81
+
82
+ #### `channel_watch` — Google Calendar watch
83
+
84
+ Open a push-notification channel on a calendar's events. The host's subscription machinery calls this; it is not a node most workflows need.
85
+
86
+ `POST /calendar/v3/calendars/{calendarId}/events/watch` · **unsafe to replay** — a retried durable run does it TWICE
87
+
88
+ | Input | Required | What it is |
89
+ |---|---|---|
90
+ | `calendarId` | yes | `primary` for the connected account's own calendar, or a calendar's id. |
91
+ | `channelId` | yes | A UUID the host mints for THIS channel. Google requires it to be unique; it comes back in every notification as X-Goog-Channel-ID and is what channel_stop needs. |
92
+ | `address` | yes | The HTTPS URL the host mounts for this trigger. Google POSTs notifications here with an EMPTY body and the facts in X-Goog-* headers. |
93
+ | `token` | yes | The connection's channelToken. The host fills this from the connection -- never type a value here. Google echoes it in X-Goog-Channel-Token, and that echo is how a delivery is verified. |
94
+ | `ttlSeconds` | yes | How long Google keeps the channel alive. Google's default is 604800 (one week), and the discovery document types it as a STRING inside `params`. |
95
+
96
+ #### `event_get` — Google Calendar event
97
+
98
+ Read one event from a Google Calendar.
99
+
100
+ `GET /calendar/v3/calendars/{calendarId}/events/{eventId}` · reads only — safe to replay
101
+
102
+ | Input | Required | What it is |
103
+ |---|---|---|
104
+ | `calendarId` | yes | `primary` for the connected account's own calendar, or a calendar's id (usually an email address). |
105
+ | `eventId` | yes | The event's id, as published by another node or by a notification's follow-up list. |
106
+
107
+ #### `event_list` — Google Calendar events
108
+
109
+ List events from a Google Calendar, in full or incrementally with a sync token.
110
+
111
+ `GET /calendar/v3/calendars/{calendarId}/events` · reads only — safe to replay
112
+
113
+ | Input | Required | What it is |
114
+ |---|---|---|
115
+ | `calendarId` | yes | `primary` for the connected account's own calendar, or a calendar's id. |
116
+ | `syncToken` | no | From a previous list's nextSyncToken. With one set, Google returns ONLY what changed since -- including deletions, as cancelled events. Leave blank for a full list. |
117
+ | `timeMin` | no | RFC 3339 lower bound on an event's END time, e.g. 2026-09-15T00:00:00Z. Not allowed together with a sync token. |
118
+ | `timeMax` | no | RFC 3339 upper bound on an event's START time. Not allowed together with a sync token. |
119
+ | `maxResults` | no | Events per page. Google's default is 250 and its maximum 2500; a nextPageToken means there are more. |
120
+ | `pageToken` | no | From a previous page's nextPageToken. |
121
+ | `singleEvents` | no | Return each occurrence of a recurring event as its own item, rather than the series once. |
122
+
123
+ ### Triggers
124
+
125
+ #### `events_changed` — Google Calendar change
126
+
127
+ Start a run when something changes on a watched Google Calendar.
128
+
129
+ A SUBSCRIPTION: Google Calendar 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 `channel_watch` response (`expiration`); 86400 seconds before it, Google Calendar cannot renew one, so the host stops it (`channel_stop`) and creates it again (`channel_watch`). A lease that lapses is re-listed AND re-subscribed, because notifications during the gap are gone. Every delivery: the token Google Calendar echoes back is compared with the connection's `channelToken` before anything runs.
130
+
131
+ **You have to set this up with the provider first:**
132
+
133
+ The host mints a UUID, calls channel_watch with it, its own URL for this trigger and the connection's channelToken, and stores the returned id, resourceId and expiration. Google cannot renew a channel: 86400 seconds before it expires the host calls channel_stop and then channel_watch again. A channel that lapsed is re-listed FIRST (event_list with the stored syncToken; a 410 means list in full) and then re-created, because notifications during the gap are gone. Google delivers with an EMPTY body: the host verifies X-Goog-Channel-Token against the connection's channelToken and injects the X-Goog-* headers as the event, camel-cased as below. The first message on a new channel is `sync` and carries no change.
134
+
135
+ ## Run it before you have credentials
136
+
137
+ Every operation ships a **faker**, whether or not Google Calendar has a sandbox. Set a
138
+ node's mode to `fake` and it returns the shape Google Calendar actually publishes — the
139
+ same field names, deterministically — so you can wire the downstream nodes before
140
+ touching an account, a key, or a network.
141
+
142
+ ## This repository is generated
143
+
144
+ `provider/` is the source. Everything under `packages/` is emitted from it and
145
+ **must not be hand-edited** — CI regenerates and diffs on every push, and the
146
+ next protocol sync destroys anything it finds. See [`AGENTS.md`](AGENTS.md).
147
+
148
+ ## Two namespaces, which do not match on purpose
149
+
150
+ The repo is `github.com/Fancy-Friends/google-calendar`; the packages publish under
151
+ `particle-academy`. Nothing derives one from the other — the names come from
152
+ weaver's `friends.json` and nowhere else.
153
+
154
+ ## Licence
155
+
156
+ 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>
@@ -0,0 +1,338 @@
1
+ import { callConnector, verifyDelivery } from '@particle-academy/fancy-connector-core';
2
+
3
+ // src/faker.ts
4
+ function fakeChannelStop({ config, fake }) {
5
+ return {};
6
+ }
7
+ function fakeChannelWatch({ config, fake }) {
8
+ const boundChannelid = config.channelId !== void 0 && config.channelId !== null && config.channelId !== "" ? String(config.channelId) : `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`;
9
+ const boundToken = config.token !== void 0 && config.token !== null && config.token !== "" ? String(config.token) : fake.id("tok");
10
+ return {
11
+ "kind": "api#channel",
12
+ "id": boundChannelid,
13
+ "resourceId": fake.id("o3hgv1538sdjfh"),
14
+ "resourceUri": "https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json",
15
+ "token": boundToken,
16
+ "expiration": "1789430400000"
17
+ };
18
+ }
19
+ function fakeEventGet({ config, fake }) {
20
+ const boundEventid = config.eventId !== void 0 && config.eventId !== null && config.eventId !== "" ? String(config.eventId) : fake.id("evt");
21
+ return {
22
+ "kind": "calendar#event",
23
+ "etag": '"3456789012345678"',
24
+ "id": boundEventid,
25
+ "status": "confirmed",
26
+ "htmlLink": "https://www.google.com/calendar/event?eid=ZmFrZQ",
27
+ "created": "2026-09-01T09:00:00.000Z",
28
+ "updated": "2026-09-10T15:30:00.000Z",
29
+ "summary": "Design review",
30
+ "description": "Quarterly design review with the platform team.",
31
+ "creator": {
32
+ "email": "ada@example.test"
33
+ },
34
+ "organizer": {
35
+ "email": "ada@example.test"
36
+ },
37
+ "start": {
38
+ "dateTime": "2026-09-22T14:00:00+00:00",
39
+ "timeZone": "UTC"
40
+ },
41
+ "end": {
42
+ "dateTime": "2026-09-22T15:00:00+00:00",
43
+ "timeZone": "UTC"
44
+ },
45
+ "iCalUID": `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`,
46
+ "sequence": 0,
47
+ "attendees": [
48
+ {
49
+ "email": "ada@example.test",
50
+ "organizer": true,
51
+ "responseStatus": "accepted"
52
+ },
53
+ {
54
+ "email": "grace@example.test",
55
+ "responseStatus": "needsAction"
56
+ }
57
+ ],
58
+ "reminders": {
59
+ "useDefault": true
60
+ },
61
+ "eventType": "default"
62
+ };
63
+ }
64
+ function fakeEventList({ config, fake }) {
65
+ return {
66
+ "kind": "calendar#events",
67
+ "etag": '"p33cd9r3ab8ne20g"',
68
+ "summary": "ada@example.test",
69
+ "updated": "2026-09-10T15:30:00.000Z",
70
+ "timeZone": "UTC",
71
+ "accessRole": "owner",
72
+ "defaultReminders": [
73
+ {
74
+ "method": "popup",
75
+ "minutes": 10
76
+ }
77
+ ],
78
+ "nextSyncToken": fake.id("CPDSyncToken"),
79
+ "items": [
80
+ {
81
+ "kind": "calendar#event",
82
+ "etag": '"3456789012345678"',
83
+ "id": fake.id("evt"),
84
+ "status": "confirmed",
85
+ "htmlLink": "https://www.google.com/calendar/event?eid=ZmFrZQ",
86
+ "created": "2026-09-01T09:00:00.000Z",
87
+ "updated": "2026-09-10T15:30:00.000Z",
88
+ "summary": "Design review",
89
+ "creator": {
90
+ "email": "ada@example.test"
91
+ },
92
+ "organizer": {
93
+ "email": "ada@example.test"
94
+ },
95
+ "start": {
96
+ "dateTime": "2026-09-22T14:00:00+00:00",
97
+ "timeZone": "UTC"
98
+ },
99
+ "end": {
100
+ "dateTime": "2026-09-22T15:00:00+00:00",
101
+ "timeZone": "UTC"
102
+ },
103
+ "iCalUID": `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`,
104
+ "sequence": 0,
105
+ "reminders": {
106
+ "useDefault": true
107
+ },
108
+ "eventType": "default"
109
+ }
110
+ ]
111
+ };
112
+ }
113
+ function fakeEventsChanged({ config, fake }) {
114
+ const boundChannelid = `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`;
115
+ return {
116
+ "channelId": boundChannelid,
117
+ "messageNumber": "2",
118
+ "resourceId": fake.id("o3hgv1538sdjfh"),
119
+ "resourceState": config.sample !== void 0 && config.sample !== null && config.sample !== "" ? String(config.sample) : "exists",
120
+ "resourceUri": "https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json",
121
+ "channelExpiration": "Tue, 15 Sep 2026 00:00:00 GMT"
122
+ };
123
+ }
124
+ var googleCalendarFaker = (operation, request) => {
125
+ switch (operation) {
126
+ case "channel_stop":
127
+ return fakeChannelStop(request);
128
+ case "channel_watch":
129
+ return fakeChannelWatch(request);
130
+ case "event_get":
131
+ return fakeEventGet(request);
132
+ case "event_list":
133
+ return fakeEventList(request);
134
+ case "events_changed":
135
+ return fakeEventsChanged(request);
136
+ default:
137
+ throw new Error(
138
+ `google_calendar: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
139
+ );
140
+ }
141
+ };
142
+
143
+ // src/service.ts
144
+ var CONNECTOR_API_VERSION = 1;
145
+ var GOOGLE_CALENDAR_BASE_URLS = {
146
+ "live": "https://www.googleapis.com"
147
+ };
148
+ var GOOGLE_CALENDAR_REQUIRES = [
149
+ "accessToken",
150
+ "refreshToken",
151
+ "clientId",
152
+ "clientSecret"
153
+ ];
154
+ function googleCalendarAuthorize(credentials, request, _mode) {
155
+ request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
156
+ }
157
+ var GOOGLE_CALENDAR = {
158
+ service: "google_calendar",
159
+ title: "Google Calendar",
160
+ sandbox: "none",
161
+ baseUrls: { ...GOOGLE_CALENDAR_BASE_URLS },
162
+ requires: [...GOOGLE_CALENDAR_REQUIRES],
163
+ authorize: googleCalendarAuthorize,
164
+ faker: googleCalendarFaker
165
+ };
166
+ var CHANNEL_STOP_OPERATION = "channel_stop";
167
+ async function googleCalendarChannelStop(options) {
168
+ const config = options.config ?? {};
169
+ if (config.channelId === void 0 || config.channelId === null || config.channelId === "") {
170
+ throw new Error(`channel_stop: "channelId" is required (Channel ID).`);
171
+ }
172
+ if (config.resourceId === void 0 || config.resourceId === null || config.resourceId === "") {
173
+ throw new Error(`channel_stop: "resourceId" is required (Resource ID).`);
174
+ }
175
+ return callConnector(GOOGLE_CALENDAR, {
176
+ operation: CHANNEL_STOP_OPERATION,
177
+ config,
178
+ input: options.input,
179
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
180
+ ...options.mode === void 0 ? {} : { mode: options.mode },
181
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
182
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
183
+ ...options.transport === void 0 ? {} : { transport: options.transport },
184
+ request: {
185
+ method: "POST",
186
+ path: "/calendar/v3/channels/stop",
187
+ json: {
188
+ "id": String(config.channelId),
189
+ "resourceId": String(config.resourceId)
190
+ }
191
+ }
192
+ });
193
+ }
194
+ var CHANNEL_WATCH_OPERATION = "channel_watch";
195
+ async function googleCalendarChannelWatch(options) {
196
+ const config = options.config ?? {};
197
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
198
+ throw new Error(`channel_watch: "calendarId" is required (Calendar ID).`);
199
+ }
200
+ if (config.channelId === void 0 || config.channelId === null || config.channelId === "") {
201
+ throw new Error(`channel_watch: "channelId" is required (Channel ID).`);
202
+ }
203
+ if (config.address === void 0 || config.address === null || config.address === "") {
204
+ throw new Error(`channel_watch: "address" is required (Notification URL).`);
205
+ }
206
+ if (config.token === void 0 || config.token === null || config.token === "") {
207
+ throw new Error(`channel_watch: "token" is required (Channel token).`);
208
+ }
209
+ if (config.ttlSeconds === void 0 || config.ttlSeconds === null || config.ttlSeconds === "") {
210
+ throw new Error(`channel_watch: "ttlSeconds" is required (Lifetime (seconds)).`);
211
+ }
212
+ return callConnector(GOOGLE_CALENDAR, {
213
+ operation: CHANNEL_WATCH_OPERATION,
214
+ config,
215
+ input: options.input,
216
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
217
+ ...options.mode === void 0 ? {} : { mode: options.mode },
218
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
219
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
220
+ ...options.transport === void 0 ? {} : { transport: options.transport },
221
+ request: {
222
+ method: "POST",
223
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events/watch`,
224
+ json: nestFields({
225
+ "id": String(config.channelId),
226
+ "address": String(config.address),
227
+ "token": String(config.token),
228
+ "params.ttl": String(config.ttlSeconds),
229
+ "type": "web_hook"
230
+ })
231
+ }
232
+ });
233
+ }
234
+ function nestFields(flat) {
235
+ const out = {};
236
+ for (const [path, value] of Object.entries(flat)) {
237
+ const parts = path.split(".");
238
+ let node = out;
239
+ while (parts.length > 1) {
240
+ const key = parts.shift();
241
+ const wantsArray = /^\d+$/.test(parts[0] ?? "");
242
+ if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
243
+ node = node[key];
244
+ }
245
+ node[parts[0]] = value;
246
+ }
247
+ return out;
248
+ }
249
+ var EVENT_GET_OPERATION = "event_get";
250
+ async function googleCalendarEventGet(options) {
251
+ const config = options.config ?? {};
252
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
253
+ throw new Error(`event_get: "calendarId" is required (Calendar ID).`);
254
+ }
255
+ if (config.eventId === void 0 || config.eventId === null || config.eventId === "") {
256
+ throw new Error(`event_get: "eventId" is required (Event ID).`);
257
+ }
258
+ return callConnector(GOOGLE_CALENDAR, {
259
+ operation: EVENT_GET_OPERATION,
260
+ config,
261
+ input: options.input,
262
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
263
+ ...options.mode === void 0 ? {} : { mode: options.mode },
264
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
265
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
266
+ ...options.transport === void 0 ? {} : { transport: options.transport },
267
+ request: {
268
+ method: "GET",
269
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events/${encodeURIComponent(String(config.eventId))}`,
270
+ query: {}
271
+ }
272
+ });
273
+ }
274
+ var EVENT_LIST_OPERATION = "event_list";
275
+ async function googleCalendarEventList(options) {
276
+ const config = options.config ?? {};
277
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
278
+ throw new Error(`event_list: "calendarId" is required (Calendar ID).`);
279
+ }
280
+ {
281
+ const n = Number(config.maxResults);
282
+ const given = config.maxResults !== void 0 && config.maxResults !== null && config.maxResults !== "";
283
+ if (given && !(Number.isInteger(n) && n >= 1 && n <= 2500)) {
284
+ throw new Error(
285
+ `event_list: "maxResults" must be a integer, got ${JSON.stringify(config.maxResults)}.`
286
+ );
287
+ }
288
+ }
289
+ return callConnector(GOOGLE_CALENDAR, {
290
+ operation: EVENT_LIST_OPERATION,
291
+ config,
292
+ input: options.input,
293
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
294
+ ...options.mode === void 0 ? {} : { mode: options.mode },
295
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
296
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
297
+ ...options.transport === void 0 ? {} : { transport: options.transport },
298
+ request: {
299
+ method: "GET",
300
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events`,
301
+ query: {
302
+ ...config.syncToken !== void 0 && config.syncToken !== null && config.syncToken !== "" ? { "syncToken": String(config.syncToken) } : {},
303
+ ...config.timeMin !== void 0 && config.timeMin !== null && config.timeMin !== "" ? { "timeMin": String(config.timeMin) } : {},
304
+ ...config.timeMax !== void 0 && config.timeMax !== null && config.timeMax !== "" ? { "timeMax": String(config.timeMax) } : {},
305
+ "maxResults": config.maxResults !== void 0 && config.maxResults !== null && config.maxResults !== "" ? Math.trunc(Number(config.maxResults)) : 250,
306
+ ...config.pageToken !== void 0 && config.pageToken !== null && config.pageToken !== "" ? { "pageToken": String(config.pageToken) } : {},
307
+ ...config.singleEvents !== void 0 && config.singleEvents !== null && config.singleEvents !== "" ? { "singleEvents": Boolean(config.singleEvents) } : {}
308
+ }
309
+ }
310
+ });
311
+ }
312
+ var GOOGLE_CALENDAR_EVENTS_CHANGED_TOKEN_SCHEME = { kind: "shared-token", in: "header", name: "X-Goog-Channel-Token" };
313
+ var GOOGLE_CALENDAR_EVENTS_CHANGED_LEASE = {
314
+ expiresAtFrom: "expiration",
315
+ expiresAtUnit: "epoch-ms",
316
+ renewBeforeSeconds: 86400,
317
+ renewOperation: "channel_watch"
318
+ };
319
+ var GOOGLE_CALENDAR_EVENTS_CHANGED_SUBSCRIPTION = { create: "channel_watch", renew: null, stop: "channel_stop" };
320
+ var GOOGLE_CALENDAR_EVENTS_CHANGED = {
321
+ service: "google_calendar",
322
+ operation: "events_changed",
323
+ delivery: "subscription",
324
+ setup: "The host mints a UUID, calls channel_watch with it, its own URL for this trigger and the connection's channelToken, and stores the returned id, resourceId and expiration. Google cannot renew a channel: 86400 seconds before it expires the host calls channel_stop and then channel_watch again. A channel that lapsed is re-listed FIRST (event_list with the stored syncToken; a 410 means list in full) and then re-created, because notifications during the gap are gone. Google delivers with an EMPTY body: the host verifies X-Goog-Channel-Token against the connection's channelToken and injects the X-Goog-* headers as the event, camel-cased as below. The first message on a new channel is `sync` and carries no change.",
325
+ subscriptionTtl: 604800,
326
+ lease: GOOGLE_CALENDAR_EVENTS_CHANGED_LEASE,
327
+ verification: {
328
+ scheme: GOOGLE_CALENDAR_EVENTS_CHANGED_TOKEN_SCHEME
329
+ },
330
+ faker: googleCalendarFaker
331
+ };
332
+ function verifyGoogleCalendarDelivery(delivery, channelToken, now) {
333
+ return verifyDelivery(GOOGLE_CALENDAR_EVENTS_CHANGED, delivery, channelToken, now);
334
+ }
335
+
336
+ export { CHANNEL_STOP_OPERATION, CHANNEL_WATCH_OPERATION, CONNECTOR_API_VERSION, EVENT_GET_OPERATION, EVENT_LIST_OPERATION, GOOGLE_CALENDAR, GOOGLE_CALENDAR_BASE_URLS, GOOGLE_CALENDAR_EVENTS_CHANGED, GOOGLE_CALENDAR_EVENTS_CHANGED_LEASE, GOOGLE_CALENDAR_EVENTS_CHANGED_SUBSCRIPTION, GOOGLE_CALENDAR_EVENTS_CHANGED_TOKEN_SCHEME, GOOGLE_CALENDAR_REQUIRES, googleCalendarAuthorize, googleCalendarChannelStop, googleCalendarChannelWatch, googleCalendarEventGet, googleCalendarEventList, googleCalendarFaker, verifyGoogleCalendarDelivery };
337
+ //# sourceMappingURL=chunk-VH6QZLPP.js.map
338
+ //# sourceMappingURL=chunk-VH6QZLPP.js.map