@particle-academy/google-calendar-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/dist/flow.cjs ADDED
@@ -0,0 +1,682 @@
1
+ 'use strict';
2
+
3
+ var fancyConnectorCore = require('@particle-academy/fancy-connector-core');
4
+ var googleCalendarUi = require('@particle-academy/google-calendar-ui');
5
+
6
+ // src/flow.ts
7
+
8
+ // src/faker.ts
9
+ function fakeChannelStop({ config, fake }) {
10
+ return {};
11
+ }
12
+ function fakeChannelWatch({ config, fake }) {
13
+ 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)}`;
14
+ const boundToken = config.token !== void 0 && config.token !== null && config.token !== "" ? String(config.token) : fake.id("tok");
15
+ return {
16
+ "kind": "api#channel",
17
+ "id": boundChannelid,
18
+ "resourceId": fake.id("o3hgv1538sdjfh"),
19
+ "resourceUri": "https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json",
20
+ "token": boundToken,
21
+ "expiration": "1789430400000"
22
+ };
23
+ }
24
+ function fakeEventCreate({ config, fake }) {
25
+ return {
26
+ "kind": "calendar#event",
27
+ "etag": '"3456789012345679"',
28
+ "id": fake.id("evt"),
29
+ "status": config.status !== void 0 && config.status !== null && config.status !== "" ? String(config.status) : "confirmed",
30
+ "htmlLink": "https://www.google.com/calendar/event?eid=ZmFrZQ",
31
+ "created": "2026-09-30T09:00:00.000Z",
32
+ "updated": "2026-09-30T09:00:00.000Z",
33
+ "summary": config.summary !== void 0 && config.summary !== null && config.summary !== "" ? String(config.summary) : "Design review",
34
+ "description": config.description !== void 0 && config.description !== null && config.description !== "" ? String(config.description) : "",
35
+ "location": config.location !== void 0 && config.location !== null && config.location !== "" ? String(config.location) : "",
36
+ "creator": {
37
+ "email": "ada@example.test"
38
+ },
39
+ "organizer": {
40
+ "email": "ada@example.test"
41
+ },
42
+ "start": {
43
+ "dateTime": config.startDateTime !== void 0 && config.startDateTime !== null && config.startDateTime !== "" ? String(config.startDateTime) : "2026-10-01T14:00:00Z",
44
+ "timeZone": config.startTimeZone !== void 0 && config.startTimeZone !== null && config.startTimeZone !== "" ? String(config.startTimeZone) : "UTC"
45
+ },
46
+ "end": {
47
+ "dateTime": config.endDateTime !== void 0 && config.endDateTime !== null && config.endDateTime !== "" ? String(config.endDateTime) : "2026-10-01T15:00:00Z",
48
+ "timeZone": config.endTimeZone !== void 0 && config.endTimeZone !== null && config.endTimeZone !== "" ? String(config.endTimeZone) : "UTC"
49
+ },
50
+ "iCalUID": `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`,
51
+ "sequence": 0,
52
+ "reminders": {
53
+ "useDefault": true
54
+ },
55
+ "eventType": "default"
56
+ };
57
+ }
58
+ function fakeEventDelete({ config, fake }) {
59
+ return {};
60
+ }
61
+ function fakeEventGet({ config, fake }) {
62
+ const boundEventid = config.eventId !== void 0 && config.eventId !== null && config.eventId !== "" ? String(config.eventId) : fake.id("evt");
63
+ return {
64
+ "kind": "calendar#event",
65
+ "etag": '"3456789012345678"',
66
+ "id": boundEventid,
67
+ "status": "confirmed",
68
+ "htmlLink": "https://www.google.com/calendar/event?eid=ZmFrZQ",
69
+ "created": "2026-09-01T09:00:00.000Z",
70
+ "updated": "2026-09-10T15:30:00.000Z",
71
+ "summary": "Design review",
72
+ "description": "Quarterly design review with the platform team.",
73
+ "creator": {
74
+ "email": "ada@example.test"
75
+ },
76
+ "organizer": {
77
+ "email": "ada@example.test"
78
+ },
79
+ "start": {
80
+ "dateTime": "2026-09-22T14:00:00+00:00",
81
+ "timeZone": "UTC"
82
+ },
83
+ "end": {
84
+ "dateTime": "2026-09-22T15:00:00+00:00",
85
+ "timeZone": "UTC"
86
+ },
87
+ "iCalUID": `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`,
88
+ "sequence": 0,
89
+ "attendees": [
90
+ {
91
+ "email": "ada@example.test",
92
+ "organizer": true,
93
+ "responseStatus": "accepted"
94
+ },
95
+ {
96
+ "email": "grace@example.test",
97
+ "responseStatus": "needsAction"
98
+ }
99
+ ],
100
+ "reminders": {
101
+ "useDefault": true
102
+ },
103
+ "eventType": "default"
104
+ };
105
+ }
106
+ function fakeEventList({ config, fake }) {
107
+ return {
108
+ "kind": "calendar#events",
109
+ "etag": '"p33cd9r3ab8ne20g"',
110
+ "summary": "ada@example.test",
111
+ "updated": "2026-09-10T15:30:00.000Z",
112
+ "timeZone": "UTC",
113
+ "accessRole": "owner",
114
+ "defaultReminders": [
115
+ {
116
+ "method": "popup",
117
+ "minutes": 10
118
+ }
119
+ ],
120
+ "nextSyncToken": fake.id("CPDSyncToken"),
121
+ "items": [
122
+ {
123
+ "kind": "calendar#event",
124
+ "etag": '"3456789012345678"',
125
+ "id": fake.id("evt"),
126
+ "status": "confirmed",
127
+ "htmlLink": "https://www.google.com/calendar/event?eid=ZmFrZQ",
128
+ "created": "2026-09-01T09:00:00.000Z",
129
+ "updated": "2026-09-10T15:30:00.000Z",
130
+ "summary": "Design review",
131
+ "creator": {
132
+ "email": "ada@example.test"
133
+ },
134
+ "organizer": {
135
+ "email": "ada@example.test"
136
+ },
137
+ "start": {
138
+ "dateTime": "2026-09-22T14:00:00+00:00",
139
+ "timeZone": "UTC"
140
+ },
141
+ "end": {
142
+ "dateTime": "2026-09-22T15:00:00+00:00",
143
+ "timeZone": "UTC"
144
+ },
145
+ "iCalUID": `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`,
146
+ "sequence": 0,
147
+ "reminders": {
148
+ "useDefault": true
149
+ },
150
+ "eventType": "default"
151
+ }
152
+ ]
153
+ };
154
+ }
155
+ function fakeEventUpdate({ config, fake }) {
156
+ return {
157
+ "kind": "calendar#event",
158
+ "etag": '"3456789012345680"',
159
+ "id": config.eventId !== void 0 && config.eventId !== null && config.eventId !== "" ? String(config.eventId) : fake.id("evt"),
160
+ "status": config.status !== void 0 && config.status !== null && config.status !== "" ? String(config.status) : "confirmed",
161
+ "htmlLink": "https://www.google.com/calendar/event?eid=ZmFrZQ",
162
+ "created": "2026-09-01T09:00:00.000Z",
163
+ "updated": "2026-09-30T09:15:00.000Z",
164
+ "summary": config.summary !== void 0 && config.summary !== null && config.summary !== "" ? String(config.summary) : "Design review",
165
+ "description": config.description !== void 0 && config.description !== null && config.description !== "" ? String(config.description) : "",
166
+ "location": config.location !== void 0 && config.location !== null && config.location !== "" ? String(config.location) : "",
167
+ "creator": {
168
+ "email": "ada@example.test"
169
+ },
170
+ "organizer": {
171
+ "email": "ada@example.test"
172
+ },
173
+ "start": {
174
+ "dateTime": config.startDateTime !== void 0 && config.startDateTime !== null && config.startDateTime !== "" ? String(config.startDateTime) : "2026-10-01T14:00:00Z",
175
+ "timeZone": config.startTimeZone !== void 0 && config.startTimeZone !== null && config.startTimeZone !== "" ? String(config.startTimeZone) : "UTC"
176
+ },
177
+ "end": {
178
+ "dateTime": config.endDateTime !== void 0 && config.endDateTime !== null && config.endDateTime !== "" ? String(config.endDateTime) : "2026-10-01T15:00:00Z",
179
+ "timeZone": config.endTimeZone !== void 0 && config.endTimeZone !== null && config.endTimeZone !== "" ? String(config.endTimeZone) : "UTC"
180
+ },
181
+ "iCalUID": `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`,
182
+ "sequence": 1,
183
+ "reminders": {
184
+ "useDefault": true
185
+ },
186
+ "eventType": "default"
187
+ };
188
+ }
189
+ function fakeEventsChanged({ config, fake }) {
190
+ const boundChannelid = `${fake.hex(8)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(4)}-${fake.hex(12)}`;
191
+ return {
192
+ "channelId": boundChannelid,
193
+ "messageNumber": "2",
194
+ "resourceId": fake.id("o3hgv1538sdjfh"),
195
+ "resourceState": config.sample !== void 0 && config.sample !== null && config.sample !== "" ? String(config.sample) : "exists",
196
+ "resourceUri": "https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json",
197
+ "channelExpiration": "Tue, 15 Sep 2026 00:00:00 GMT"
198
+ };
199
+ }
200
+ var googleCalendarFaker = (operation, request) => {
201
+ switch (operation) {
202
+ case "channel_stop":
203
+ return fakeChannelStop(request);
204
+ case "channel_watch":
205
+ return fakeChannelWatch(request);
206
+ case "event_create":
207
+ return fakeEventCreate(request);
208
+ case "event_delete":
209
+ return fakeEventDelete(request);
210
+ case "event_get":
211
+ return fakeEventGet(request);
212
+ case "event_list":
213
+ return fakeEventList(request);
214
+ case "event_update":
215
+ return fakeEventUpdate(request);
216
+ case "events_changed":
217
+ return fakeEventsChanged(request);
218
+ default:
219
+ throw new Error(
220
+ `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.`
221
+ );
222
+ }
223
+ };
224
+
225
+ // src/service.ts
226
+ var GOOGLE_CALENDAR_BASE_URLS = {
227
+ "live": "https://www.googleapis.com"
228
+ };
229
+ var GOOGLE_CALENDAR_REQUIRES = [
230
+ "accessToken",
231
+ "refreshToken",
232
+ "clientId",
233
+ "clientSecret"
234
+ ];
235
+ function googleCalendarAuthorize(credentials, request, _mode) {
236
+ request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
237
+ }
238
+ var GOOGLE_CALENDAR = {
239
+ service: "google_calendar",
240
+ title: "Google Calendar",
241
+ sandbox: "none",
242
+ baseUrls: { ...GOOGLE_CALENDAR_BASE_URLS },
243
+ requires: [...GOOGLE_CALENDAR_REQUIRES],
244
+ authorize: googleCalendarAuthorize,
245
+ faker: googleCalendarFaker
246
+ };
247
+ var CHANNEL_STOP_OPERATION = "channel_stop";
248
+ async function googleCalendarChannelStop(options) {
249
+ const config = options.config ?? {};
250
+ if (config.channelId === void 0 || config.channelId === null || config.channelId === "") {
251
+ throw new Error(`channel_stop: "channelId" is required (Channel ID).`);
252
+ }
253
+ if (config.resourceId === void 0 || config.resourceId === null || config.resourceId === "") {
254
+ throw new Error(`channel_stop: "resourceId" is required (Resource ID).`);
255
+ }
256
+ return fancyConnectorCore.callConnector(GOOGLE_CALENDAR, {
257
+ operation: CHANNEL_STOP_OPERATION,
258
+ config,
259
+ input: options.input,
260
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
261
+ ...options.mode === void 0 ? {} : { mode: options.mode },
262
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
263
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
264
+ ...options.transport === void 0 ? {} : { transport: options.transport },
265
+ request: {
266
+ method: "POST",
267
+ path: "/calendar/v3/channels/stop",
268
+ json: {
269
+ "id": String(config.channelId),
270
+ "resourceId": String(config.resourceId)
271
+ }
272
+ }
273
+ });
274
+ }
275
+ var CHANNEL_WATCH_OPERATION = "channel_watch";
276
+ async function googleCalendarChannelWatch(options) {
277
+ const config = options.config ?? {};
278
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
279
+ throw new Error(`channel_watch: "calendarId" is required (Calendar ID).`);
280
+ }
281
+ if (config.channelId === void 0 || config.channelId === null || config.channelId === "") {
282
+ throw new Error(`channel_watch: "channelId" is required (Channel ID).`);
283
+ }
284
+ if (config.address === void 0 || config.address === null || config.address === "") {
285
+ throw new Error(`channel_watch: "address" is required (Notification URL).`);
286
+ }
287
+ if (config.token === void 0 || config.token === null || config.token === "") {
288
+ throw new Error(`channel_watch: "token" is required (Channel token).`);
289
+ }
290
+ if (config.ttlSeconds === void 0 || config.ttlSeconds === null || config.ttlSeconds === "") {
291
+ throw new Error(`channel_watch: "ttlSeconds" is required (Lifetime (seconds)).`);
292
+ }
293
+ return fancyConnectorCore.callConnector(GOOGLE_CALENDAR, {
294
+ operation: CHANNEL_WATCH_OPERATION,
295
+ config,
296
+ input: options.input,
297
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
298
+ ...options.mode === void 0 ? {} : { mode: options.mode },
299
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
300
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
301
+ ...options.transport === void 0 ? {} : { transport: options.transport },
302
+ request: {
303
+ method: "POST",
304
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events/watch`,
305
+ json: nestFields({
306
+ "id": String(config.channelId),
307
+ "address": String(config.address),
308
+ "token": String(config.token),
309
+ "params.ttl": String(config.ttlSeconds),
310
+ "type": "web_hook"
311
+ })
312
+ }
313
+ });
314
+ }
315
+ function nestFields(flat) {
316
+ const out = {};
317
+ for (const [path, value] of Object.entries(flat)) {
318
+ const parts = path.split(".");
319
+ let node = out;
320
+ while (parts.length > 1) {
321
+ const key = parts.shift();
322
+ const wantsArray = /^\d+$/.test(parts[0] ?? "");
323
+ if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
324
+ node = node[key];
325
+ }
326
+ node[parts[0]] = value;
327
+ }
328
+ return out;
329
+ }
330
+ var EVENT_CREATE_OPERATION = "event_create";
331
+ async function googleCalendarEventCreate(options) {
332
+ const config = options.config ?? {};
333
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
334
+ throw new Error(`event_create: "calendarId" is required (Calendar ID).`);
335
+ }
336
+ if (config.summary === void 0 || config.summary === null || config.summary === "") {
337
+ throw new Error(`event_create: "summary" is required (Title).`);
338
+ }
339
+ if (config.startDateTime === void 0 || config.startDateTime === null || config.startDateTime === "") {
340
+ throw new Error(`event_create: "startDateTime" is required (Start).`);
341
+ }
342
+ if (config.endDateTime === void 0 || config.endDateTime === null || config.endDateTime === "") {
343
+ throw new Error(`event_create: "endDateTime" is required (End).`);
344
+ }
345
+ return fancyConnectorCore.callConnector(GOOGLE_CALENDAR, {
346
+ operation: EVENT_CREATE_OPERATION,
347
+ config,
348
+ input: options.input,
349
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
350
+ ...options.mode === void 0 ? {} : { mode: options.mode },
351
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
352
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
353
+ ...options.transport === void 0 ? {} : { transport: options.transport },
354
+ request: {
355
+ method: "POST",
356
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events`,
357
+ json: nestFields2({
358
+ "summary": String(config.summary),
359
+ ...config.description !== void 0 && config.description !== null && config.description !== "" ? { "description": String(config.description) } : {},
360
+ ...config.location !== void 0 && config.location !== null && config.location !== "" ? { "location": String(config.location) } : {},
361
+ "start.dateTime": String(config.startDateTime),
362
+ ...config.startTimeZone !== void 0 && config.startTimeZone !== null && config.startTimeZone !== "" ? { "start.timeZone": String(config.startTimeZone) } : {},
363
+ "end.dateTime": String(config.endDateTime),
364
+ ...config.endTimeZone !== void 0 && config.endTimeZone !== null && config.endTimeZone !== "" ? { "end.timeZone": String(config.endTimeZone) } : {},
365
+ ...config.status !== void 0 && config.status !== null && config.status !== "" ? { "status": String(config.status) } : {},
366
+ ...config.visibility !== void 0 && config.visibility !== null && config.visibility !== "" ? { "visibility": String(config.visibility) } : {},
367
+ ...config.transparency !== void 0 && config.transparency !== null && config.transparency !== "" ? { "transparency": String(config.transparency) } : {},
368
+ ...config.colorId !== void 0 && config.colorId !== null && config.colorId !== "" ? { "colorId": String(config.colorId) } : {}
369
+ })
370
+ }
371
+ });
372
+ }
373
+ function nestFields2(flat) {
374
+ const out = {};
375
+ for (const [path, value] of Object.entries(flat)) {
376
+ const parts = path.split(".");
377
+ let node = out;
378
+ while (parts.length > 1) {
379
+ const key = parts.shift();
380
+ const wantsArray = /^\d+$/.test(parts[0] ?? "");
381
+ if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
382
+ node = node[key];
383
+ }
384
+ node[parts[0]] = value;
385
+ }
386
+ return out;
387
+ }
388
+ var EVENT_DELETE_OPERATION = "event_delete";
389
+ async function googleCalendarEventDelete(options) {
390
+ const config = options.config ?? {};
391
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
392
+ throw new Error(`event_delete: "calendarId" is required (Calendar ID).`);
393
+ }
394
+ if (config.eventId === void 0 || config.eventId === null || config.eventId === "") {
395
+ throw new Error(`event_delete: "eventId" is required (Event ID).`);
396
+ }
397
+ return fancyConnectorCore.callConnector(GOOGLE_CALENDAR, {
398
+ operation: EVENT_DELETE_OPERATION,
399
+ config,
400
+ input: options.input,
401
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
402
+ ...options.mode === void 0 ? {} : { mode: options.mode },
403
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
404
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
405
+ ...options.transport === void 0 ? {} : { transport: options.transport },
406
+ request: {
407
+ method: "DELETE",
408
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events/${encodeURIComponent(String(config.eventId))}`,
409
+ query: {}
410
+ }
411
+ });
412
+ }
413
+ var EVENT_GET_OPERATION = "event_get";
414
+ async function googleCalendarEventGet(options) {
415
+ const config = options.config ?? {};
416
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
417
+ throw new Error(`event_get: "calendarId" is required (Calendar ID).`);
418
+ }
419
+ if (config.eventId === void 0 || config.eventId === null || config.eventId === "") {
420
+ throw new Error(`event_get: "eventId" is required (Event ID).`);
421
+ }
422
+ return fancyConnectorCore.callConnector(GOOGLE_CALENDAR, {
423
+ operation: EVENT_GET_OPERATION,
424
+ config,
425
+ input: options.input,
426
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
427
+ ...options.mode === void 0 ? {} : { mode: options.mode },
428
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
429
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
430
+ ...options.transport === void 0 ? {} : { transport: options.transport },
431
+ request: {
432
+ method: "GET",
433
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events/${encodeURIComponent(String(config.eventId))}`,
434
+ query: {}
435
+ }
436
+ });
437
+ }
438
+ var EVENT_LIST_OPERATION = "event_list";
439
+ async function googleCalendarEventList(options) {
440
+ const config = options.config ?? {};
441
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
442
+ throw new Error(`event_list: "calendarId" is required (Calendar ID).`);
443
+ }
444
+ {
445
+ const n = Number(config.maxResults);
446
+ const given = config.maxResults !== void 0 && config.maxResults !== null && config.maxResults !== "";
447
+ if (given && !(Number.isInteger(n) && n >= 1 && n <= 2500)) {
448
+ throw new Error(
449
+ `event_list: "maxResults" must be a integer, got ${JSON.stringify(config.maxResults)}.`
450
+ );
451
+ }
452
+ }
453
+ return fancyConnectorCore.callConnector(GOOGLE_CALENDAR, {
454
+ operation: EVENT_LIST_OPERATION,
455
+ config,
456
+ input: options.input,
457
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
458
+ ...options.mode === void 0 ? {} : { mode: options.mode },
459
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
460
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
461
+ ...options.transport === void 0 ? {} : { transport: options.transport },
462
+ request: {
463
+ method: "GET",
464
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events`,
465
+ query: {
466
+ ...config.syncToken !== void 0 && config.syncToken !== null && config.syncToken !== "" ? { "syncToken": String(config.syncToken) } : {},
467
+ ...config.timeMin !== void 0 && config.timeMin !== null && config.timeMin !== "" ? { "timeMin": String(config.timeMin) } : {},
468
+ ...config.timeMax !== void 0 && config.timeMax !== null && config.timeMax !== "" ? { "timeMax": String(config.timeMax) } : {},
469
+ "maxResults": config.maxResults !== void 0 && config.maxResults !== null && config.maxResults !== "" ? Math.trunc(Number(config.maxResults)) : 250,
470
+ ...config.pageToken !== void 0 && config.pageToken !== null && config.pageToken !== "" ? { "pageToken": String(config.pageToken) } : {},
471
+ ...config.singleEvents !== void 0 && config.singleEvents !== null && config.singleEvents !== "" ? { "singleEvents": Boolean(config.singleEvents) } : {}
472
+ }
473
+ }
474
+ });
475
+ }
476
+ var EVENT_UPDATE_OPERATION = "event_update";
477
+ async function googleCalendarEventUpdate(options) {
478
+ const config = options.config ?? {};
479
+ if (config.calendarId === void 0 || config.calendarId === null || config.calendarId === "") {
480
+ throw new Error(`event_update: "calendarId" is required (Calendar ID).`);
481
+ }
482
+ if (config.eventId === void 0 || config.eventId === null || config.eventId === "") {
483
+ throw new Error(`event_update: "eventId" is required (Event ID).`);
484
+ }
485
+ return fancyConnectorCore.callConnector(GOOGLE_CALENDAR, {
486
+ operation: EVENT_UPDATE_OPERATION,
487
+ config,
488
+ input: options.input,
489
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
490
+ ...options.mode === void 0 ? {} : { mode: options.mode },
491
+ ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
492
+ ...options.attempts === void 0 ? {} : { attempts: options.attempts },
493
+ ...options.transport === void 0 ? {} : { transport: options.transport },
494
+ request: {
495
+ method: "PATCH",
496
+ path: `/calendar/v3/calendars/${encodeURIComponent(String(config.calendarId))}/events/${encodeURIComponent(String(config.eventId))}`,
497
+ json: nestFields3({
498
+ ...config.summary !== void 0 && config.summary !== null && config.summary !== "" ? { "summary": String(config.summary) } : {},
499
+ ...config.description !== void 0 && config.description !== null && config.description !== "" ? { "description": String(config.description) } : {},
500
+ ...config.location !== void 0 && config.location !== null && config.location !== "" ? { "location": String(config.location) } : {},
501
+ ...config.startDateTime !== void 0 && config.startDateTime !== null && config.startDateTime !== "" ? { "start.dateTime": String(config.startDateTime) } : {},
502
+ ...config.startTimeZone !== void 0 && config.startTimeZone !== null && config.startTimeZone !== "" ? { "start.timeZone": String(config.startTimeZone) } : {},
503
+ ...config.endDateTime !== void 0 && config.endDateTime !== null && config.endDateTime !== "" ? { "end.dateTime": String(config.endDateTime) } : {},
504
+ ...config.endTimeZone !== void 0 && config.endTimeZone !== null && config.endTimeZone !== "" ? { "end.timeZone": String(config.endTimeZone) } : {},
505
+ ...config.status !== void 0 && config.status !== null && config.status !== "" ? { "status": String(config.status) } : {},
506
+ ...config.visibility !== void 0 && config.visibility !== null && config.visibility !== "" ? { "visibility": String(config.visibility) } : {},
507
+ ...config.transparency !== void 0 && config.transparency !== null && config.transparency !== "" ? { "transparency": String(config.transparency) } : {},
508
+ ...config.colorId !== void 0 && config.colorId !== null && config.colorId !== "" ? { "colorId": String(config.colorId) } : {}
509
+ })
510
+ }
511
+ });
512
+ }
513
+ function nestFields3(flat) {
514
+ const out = {};
515
+ for (const [path, value] of Object.entries(flat)) {
516
+ const parts = path.split(".");
517
+ let node = out;
518
+ while (parts.length > 1) {
519
+ const key = parts.shift();
520
+ const wantsArray = /^\d+$/.test(parts[0] ?? "");
521
+ if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
522
+ node = node[key];
523
+ }
524
+ node[parts[0]] = value;
525
+ }
526
+ return out;
527
+ }
528
+ var GOOGLE_CALENDAR_EVENTS_CHANGED_TOKEN_SCHEME = { kind: "shared-token", in: "header", name: "X-Goog-Channel-Token" };
529
+ var GOOGLE_CALENDAR_EVENTS_CHANGED_LEASE = {
530
+ expiresAtFrom: "expiration",
531
+ expiresAtUnit: "epoch-ms",
532
+ renewBeforeSeconds: 86400,
533
+ renewOperation: "channel_watch"
534
+ };
535
+ var GOOGLE_CALENDAR_EVENTS_CHANGED = {
536
+ service: "google_calendar",
537
+ operation: "events_changed",
538
+ delivery: "subscription",
539
+ 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.",
540
+ subscriptionTtl: 604800,
541
+ lease: GOOGLE_CALENDAR_EVENTS_CHANGED_LEASE,
542
+ verification: {
543
+ scheme: GOOGLE_CALENDAR_EVENTS_CHANGED_TOKEN_SCHEME
544
+ },
545
+ faker: googleCalendarFaker
546
+ };
547
+
548
+ // src/flow.ts
549
+ var googleCalendarChannelStopExecutor = async (ctx) => {
550
+ const config = ctx.node.data?.config ?? {};
551
+ const result = await googleCalendarChannelStop({
552
+ config,
553
+ input: ctx.inputs?.in
554
+ });
555
+ ctx.emit({
556
+ type: "log",
557
+ level: "info",
558
+ nodeId: ctx.node.id,
559
+ message: `google_calendar channel_stop ${result.data?.id} (${result.mode})`
560
+ });
561
+ return { __port: "out", value: result };
562
+ };
563
+ var googleCalendarChannelWatchExecutor = async (ctx) => {
564
+ const config = ctx.node.data?.config ?? {};
565
+ const result = await googleCalendarChannelWatch({
566
+ config,
567
+ input: ctx.inputs?.in
568
+ });
569
+ ctx.emit({
570
+ type: "log",
571
+ level: "info",
572
+ nodeId: ctx.node.id,
573
+ message: `google_calendar channel_watch ${result.data?.id} (${result.mode})`
574
+ });
575
+ return { __port: "out", value: result };
576
+ };
577
+ var googleCalendarEventCreateExecutor = async (ctx) => {
578
+ const config = ctx.node.data?.config ?? {};
579
+ const result = await googleCalendarEventCreate({
580
+ config,
581
+ input: ctx.inputs?.in
582
+ });
583
+ ctx.emit({
584
+ type: "log",
585
+ level: "info",
586
+ nodeId: ctx.node.id,
587
+ message: `google_calendar event_create ${result.data?.id} (${result.mode})`
588
+ });
589
+ return { __port: "out", value: result };
590
+ };
591
+ var googleCalendarEventDeleteExecutor = async (ctx) => {
592
+ const config = ctx.node.data?.config ?? {};
593
+ const result = await googleCalendarEventDelete({
594
+ config,
595
+ input: ctx.inputs?.in
596
+ });
597
+ ctx.emit({
598
+ type: "log",
599
+ level: "info",
600
+ nodeId: ctx.node.id,
601
+ message: `google_calendar event_delete ${result.data?.id} (${result.mode})`
602
+ });
603
+ return { __port: "out", value: result };
604
+ };
605
+ var googleCalendarEventGetExecutor = async (ctx) => {
606
+ const config = ctx.node.data?.config ?? {};
607
+ const result = await googleCalendarEventGet({
608
+ config,
609
+ input: ctx.inputs?.in
610
+ });
611
+ ctx.emit({
612
+ type: "log",
613
+ level: "info",
614
+ nodeId: ctx.node.id,
615
+ message: `google_calendar event_get ${result.data?.id} (${result.mode})`
616
+ });
617
+ return { __port: "out", value: result };
618
+ };
619
+ var googleCalendarEventListExecutor = async (ctx) => {
620
+ const config = ctx.node.data?.config ?? {};
621
+ const result = await googleCalendarEventList({
622
+ config,
623
+ input: ctx.inputs?.in
624
+ });
625
+ ctx.emit({
626
+ type: "log",
627
+ level: "info",
628
+ nodeId: ctx.node.id,
629
+ message: `google_calendar event_list ${result.data?.id} (${result.mode})`
630
+ });
631
+ return { __port: "out", value: result };
632
+ };
633
+ var googleCalendarEventUpdateExecutor = async (ctx) => {
634
+ const config = ctx.node.data?.config ?? {};
635
+ const result = await googleCalendarEventUpdate({
636
+ config,
637
+ input: ctx.inputs?.in
638
+ });
639
+ ctx.emit({
640
+ type: "log",
641
+ level: "info",
642
+ nodeId: ctx.node.id,
643
+ message: `google_calendar event_update ${result.data?.id} (${result.mode})`
644
+ });
645
+ return { __port: "out", value: result };
646
+ };
647
+ var googleCalendarEventsChangedTriggerExecutor = async (ctx) => {
648
+ const config = ctx.node.data?.config ?? {};
649
+ const connection = fancyConnectorCore.resolveConnection({
650
+ service: GOOGLE_CALENDAR.service,
651
+ operation: "events_changed",
652
+ sandbox: GOOGLE_CALENDAR.sandbox,
653
+ baseUrls: GOOGLE_CALENDAR.baseUrls,
654
+ requires: GOOGLE_CALENDAR.requires,
655
+ connectionId: typeof config.connection === "string" ? config.connection : null,
656
+ requested: typeof config.mode === "string" ? config.mode : null
657
+ });
658
+ const event = fancyConnectorCore.triggerEvent(GOOGLE_CALENDAR_EVENTS_CHANGED, connection, ctx.inputs?.in, config);
659
+ return { __port: "out", value: event };
660
+ };
661
+ var GOOGLE_CALENDAR_RUNNABLE_KINDS = [
662
+ { ...googleCalendarUi.googleCalendarChannelStopKind, executor: googleCalendarChannelStopExecutor },
663
+ { ...googleCalendarUi.googleCalendarChannelWatchKind, executor: googleCalendarChannelWatchExecutor },
664
+ { ...googleCalendarUi.googleCalendarEventCreateKind, executor: googleCalendarEventCreateExecutor },
665
+ { ...googleCalendarUi.googleCalendarEventDeleteKind, executor: googleCalendarEventDeleteExecutor },
666
+ { ...googleCalendarUi.googleCalendarEventGetKind, executor: googleCalendarEventGetExecutor },
667
+ { ...googleCalendarUi.googleCalendarEventListKind, executor: googleCalendarEventListExecutor },
668
+ { ...googleCalendarUi.googleCalendarEventUpdateKind, executor: googleCalendarEventUpdateExecutor },
669
+ { ...googleCalendarUi.googleCalendarEventsChangedTriggerKind, executor: googleCalendarEventsChangedTriggerExecutor }
670
+ ];
671
+
672
+ exports.GOOGLE_CALENDAR_RUNNABLE_KINDS = GOOGLE_CALENDAR_RUNNABLE_KINDS;
673
+ exports.googleCalendarChannelStopExecutor = googleCalendarChannelStopExecutor;
674
+ exports.googleCalendarChannelWatchExecutor = googleCalendarChannelWatchExecutor;
675
+ exports.googleCalendarEventCreateExecutor = googleCalendarEventCreateExecutor;
676
+ exports.googleCalendarEventDeleteExecutor = googleCalendarEventDeleteExecutor;
677
+ exports.googleCalendarEventGetExecutor = googleCalendarEventGetExecutor;
678
+ exports.googleCalendarEventListExecutor = googleCalendarEventListExecutor;
679
+ exports.googleCalendarEventUpdateExecutor = googleCalendarEventUpdateExecutor;
680
+ exports.googleCalendarEventsChangedTriggerExecutor = googleCalendarEventsChangedTriggerExecutor;
681
+ //# sourceMappingURL=flow.cjs.map
682
+ //# sourceMappingURL=flow.cjs.map