@contractspec/example.calendar-google 1.57.0 → 1.58.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/.turbo/turbo-build.log +34 -33
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +13 -0
- package/dist/browser/docs/calendar-google.docblock.js +45 -0
- package/dist/browser/docs/index.js +45 -0
- package/dist/browser/example.js +33 -0
- package/dist/browser/index.js +164 -0
- package/dist/browser/run.js +89 -0
- package/dist/browser/sync.js +87 -0
- package/dist/docs/calendar-google.docblock.d.ts +2 -1
- package/dist/docs/calendar-google.docblock.d.ts.map +1 -0
- package/dist/docs/calendar-google.docblock.js +25 -28
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +46 -1
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +32 -42
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +164 -4
- package/dist/node/docs/calendar-google.docblock.js +45 -0
- package/dist/node/docs/index.js +45 -0
- package/dist/node/example.js +33 -0
- package/dist/node/index.js +164 -0
- package/dist/node/run.js +89 -0
- package/dist/node/sync.js +87 -0
- package/dist/run.d.ts +2 -1
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +86 -8
- package/dist/sync.d.ts +8 -12
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +70 -74
- package/package.json +69 -26
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -33
- package/dist/docs/calendar-google.docblock.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/run.js.map +0 -1
- package/dist/sync.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
$ bun
|
|
2
|
-
$
|
|
3
|
-
$
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[34mℹ[39m target: [34mesnext[39m
|
|
8
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
|
-
[34mℹ[39m Build start
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[1msync.js[22m [2m2.97 kB[22m [2m│ gzip: 1.25 kB[22m
|
|
11
|
-
[34mℹ[39m [2mdist/[22m[1mdocs/calendar-google.docblock.js[22m [2m1.62 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
12
|
-
[34mℹ[39m [2mdist/[22m[1mexample.js[22m [2m0.96 kB[22m [2m│ gzip: 0.49 kB[22m
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[1mrun.js[22m [2m0.28 kB[22m [2m│ gzip: 0.22 kB[22m
|
|
14
|
-
[34mℹ[39m [2mdist/[22m[1mindex.js[22m [2m0.28 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
15
|
-
[34mℹ[39m [2mdist/[22m[1mdocs/index.js[22m [2m0.04 kB[22m [2m│ gzip: 0.06 kB[22m
|
|
16
|
-
[34mℹ[39m [2mdist/[22msync.js.map [2m5.05 kB[22m [2m│ gzip: 1.98 kB[22m
|
|
17
|
-
[34mℹ[39m [2mdist/[22mdocs/calendar-google.docblock.js.map [2m2.13 kB[22m [2m│ gzip: 0.98 kB[22m
|
|
18
|
-
[34mℹ[39m [2mdist/[22mexample.js.map [2m1.43 kB[22m [2m│ gzip: 0.69 kB[22m
|
|
19
|
-
[34mℹ[39m [2mdist/[22mrun.js.map [2m0.49 kB[22m [2m│ gzip: 0.33 kB[22m
|
|
20
|
-
[34mℹ[39m [2mdist/[22msync.d.ts.map [2m0.34 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
21
|
-
[34mℹ[39m [2mdist/[22mexample.d.ts.map [2m0.13 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
22
|
-
[34mℹ[39m [2mdist/[22m[32m[1msync.d.ts[22m[39m [2m0.78 kB[22m [2m│ gzip: 0.33 kB[22m
|
|
23
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m0.29 kB[22m [2m│ gzip: 0.15 kB[22m
|
|
24
|
-
[34mℹ[39m [2mdist/[22m[32m[1mexample.d.ts[22m[39m [2m0.25 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
25
|
-
[34mℹ[39m [2mdist/[22m[32m[1mdocs/calendar-google.docblock.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
26
|
-
[34mℹ[39m [2mdist/[22m[32m[1mdocs/index.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
27
|
-
[34mℹ[39m [2mdist/[22m[32m[1mrun.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
28
|
-
[34mℹ[39m 18 files, total: 17.06 kB
|
|
29
|
-
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in plugins. Here is a breakdown:
|
|
30
|
-
- tsdown:external (50%)
|
|
31
|
-
- rolldown-plugin-dts:generate (50%)
|
|
32
|
-
See https://rolldown.rs/options/checks#plugintimings for more details.
|
|
1
|
+
$ contractspec-bun-build prebuild
|
|
2
|
+
$ bun run prebuild && bun run build:bundle && bun run build:types
|
|
3
|
+
$ contractspec-bun-build prebuild
|
|
4
|
+
$ contractspec-bun-build transpile
|
|
5
|
+
[contractspec-bun-build] transpile target=bun root=src entries=6
|
|
6
|
+
Bundled 6 modules in 24ms
|
|
33
7
|
|
|
34
|
-
|
|
8
|
+
docs/calendar-google.docblock.js 1.63 KB (entry point)
|
|
9
|
+
./index.js 5.64 KB (entry point)
|
|
10
|
+
docs/index.js 1.63 KB (entry point)
|
|
11
|
+
./example.js 0.96 KB (entry point)
|
|
12
|
+
./run.js 3.15 KB (entry point)
|
|
13
|
+
./sync.js 3.1 KB (entry point)
|
|
14
|
+
|
|
15
|
+
[contractspec-bun-build] transpile target=node root=src entries=6
|
|
16
|
+
Bundled 6 modules in 10ms
|
|
17
|
+
|
|
18
|
+
docs/calendar-google.docblock.js 1.62 KB (entry point)
|
|
19
|
+
./index.js 5.63 KB (entry point)
|
|
20
|
+
docs/index.js 1.62 KB (entry point)
|
|
21
|
+
./example.js 0.95 KB (entry point)
|
|
22
|
+
./run.js 3.15 KB (entry point)
|
|
23
|
+
./sync.js 3.1 KB (entry point)
|
|
24
|
+
|
|
25
|
+
[contractspec-bun-build] transpile target=browser root=src entries=6
|
|
26
|
+
Bundled 6 modules in 15ms
|
|
27
|
+
|
|
28
|
+
docs/calendar-google.docblock.js 1.62 KB (entry point)
|
|
29
|
+
./index.js 5.63 KB (entry point)
|
|
30
|
+
docs/index.js 1.62 KB (entry point)
|
|
31
|
+
./example.js 0.95 KB (entry point)
|
|
32
|
+
./run.js 3.15 KB (entry point)
|
|
33
|
+
./sync.js 3.1 KB (entry point)
|
|
34
|
+
|
|
35
|
+
$ contractspec-bun-build types
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ contractspec-bun-build prebuild
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @contractspec/example.calendar-google
|
|
2
2
|
|
|
3
|
+
## 1.58.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d1f0fd0: chore: Migrate non-app package builds from tsdown to shared Bun tooling, add `@contractspec/tool.bun`, and standardize `prebuild`/`build`/`typecheck` with platform-aware exports and `tsc` declaration emission into `dist`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [d1f0fd0]
|
|
12
|
+
- Updated dependencies [4355a9e]
|
|
13
|
+
- @contractspec/integration.providers-impls@1.58.0
|
|
14
|
+
- @contractspec/lib.contracts@1.58.0
|
|
15
|
+
|
|
3
16
|
## 1.57.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/docs/calendar-google.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var blocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.examples.calendar-google",
|
|
6
|
+
title: "Google Calendar (example)",
|
|
7
|
+
summary: "List upcoming events and create a new event via Google Calendar.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/examples/calendar-google",
|
|
11
|
+
tags: ["calendar", "google-calendar", "example"],
|
|
12
|
+
body: `## What this example shows
|
|
13
|
+
- Create a Google OAuth client from env vars.
|
|
14
|
+
- List upcoming events with time bounds.
|
|
15
|
+
- Create a new event with attendees and reminders.
|
|
16
|
+
|
|
17
|
+
## Guardrails
|
|
18
|
+
- Keep refresh tokens in secrets.
|
|
19
|
+
- Use dry-run when validating payloads.
|
|
20
|
+
- Limit maxResults for quick previews.`
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "docs.examples.calendar-google.usage",
|
|
24
|
+
title: "Google Calendar - Usage",
|
|
25
|
+
summary: "How to run the calendar sync with env-driven settings.",
|
|
26
|
+
kind: "usage",
|
|
27
|
+
visibility: "public",
|
|
28
|
+
route: "/docs/examples/calendar-google/usage",
|
|
29
|
+
tags: ["calendar", "usage"],
|
|
30
|
+
body: `## Usage
|
|
31
|
+
- Set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_REFRESH_TOKEN.
|
|
32
|
+
- Optionally set GOOGLE_CALENDAR_ID (defaults to primary).
|
|
33
|
+
- Run the sync script to create a sample event.
|
|
34
|
+
|
|
35
|
+
## Refresh token
|
|
36
|
+
- Open https://developers.google.com/oauthplayground.
|
|
37
|
+
- Enable "Use your own OAuth credentials" and enter client ID/secret.
|
|
38
|
+
- Authorize https://www.googleapis.com/auth/calendar and exchange tokens.
|
|
39
|
+
- Copy the refresh token into GOOGLE_REFRESH_TOKEN.
|
|
40
|
+
|
|
41
|
+
## Example
|
|
42
|
+
- Call runCalendarSyncFromEnv() from run.ts to execute the flow.`
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
registerDocBlocks(blocks);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/docs/calendar-google.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var blocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.examples.calendar-google",
|
|
6
|
+
title: "Google Calendar (example)",
|
|
7
|
+
summary: "List upcoming events and create a new event via Google Calendar.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/examples/calendar-google",
|
|
11
|
+
tags: ["calendar", "google-calendar", "example"],
|
|
12
|
+
body: `## What this example shows
|
|
13
|
+
- Create a Google OAuth client from env vars.
|
|
14
|
+
- List upcoming events with time bounds.
|
|
15
|
+
- Create a new event with attendees and reminders.
|
|
16
|
+
|
|
17
|
+
## Guardrails
|
|
18
|
+
- Keep refresh tokens in secrets.
|
|
19
|
+
- Use dry-run when validating payloads.
|
|
20
|
+
- Limit maxResults for quick previews.`
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "docs.examples.calendar-google.usage",
|
|
24
|
+
title: "Google Calendar - Usage",
|
|
25
|
+
summary: "How to run the calendar sync with env-driven settings.",
|
|
26
|
+
kind: "usage",
|
|
27
|
+
visibility: "public",
|
|
28
|
+
route: "/docs/examples/calendar-google/usage",
|
|
29
|
+
tags: ["calendar", "usage"],
|
|
30
|
+
body: `## Usage
|
|
31
|
+
- Set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_REFRESH_TOKEN.
|
|
32
|
+
- Optionally set GOOGLE_CALENDAR_ID (defaults to primary).
|
|
33
|
+
- Run the sync script to create a sample event.
|
|
34
|
+
|
|
35
|
+
## Refresh token
|
|
36
|
+
- Open https://developers.google.com/oauthplayground.
|
|
37
|
+
- Enable "Use your own OAuth credentials" and enter client ID/secret.
|
|
38
|
+
- Authorize https://www.googleapis.com/auth/calendar and exchange tokens.
|
|
39
|
+
- Copy the refresh token into GOOGLE_REFRESH_TOKEN.
|
|
40
|
+
|
|
41
|
+
## Example
|
|
42
|
+
- Call runCalendarSyncFromEnv() from run.ts to execute the flow.`
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
registerDocBlocks(blocks);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/example.ts
|
|
2
|
+
import { defineExample } from "@contractspec/lib.contracts";
|
|
3
|
+
var example = defineExample({
|
|
4
|
+
meta: {
|
|
5
|
+
key: "calendar-google",
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
title: "Google Calendar",
|
|
8
|
+
description: "List upcoming events and create a new event using the Google Calendar provider.",
|
|
9
|
+
kind: "integration",
|
|
10
|
+
visibility: "public",
|
|
11
|
+
stability: "experimental",
|
|
12
|
+
owners: ["@platform.integrations"],
|
|
13
|
+
tags: ["calendar", "google-calendar", "integrations"]
|
|
14
|
+
},
|
|
15
|
+
docs: {
|
|
16
|
+
rootDocId: "docs.examples.calendar-google",
|
|
17
|
+
usageDocId: "docs.examples.calendar-google.usage"
|
|
18
|
+
},
|
|
19
|
+
entrypoints: {
|
|
20
|
+
packageName: "@contractspec/example.calendar-google",
|
|
21
|
+
docs: "./docs"
|
|
22
|
+
},
|
|
23
|
+
surfaces: {
|
|
24
|
+
templates: true,
|
|
25
|
+
sandbox: { enabled: true, modes: ["markdown", "specs"] },
|
|
26
|
+
studio: { enabled: true, installable: true },
|
|
27
|
+
mcp: { enabled: true }
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var example_default = example;
|
|
31
|
+
export {
|
|
32
|
+
example_default as default
|
|
33
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// src/docs/calendar-google.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
3
|
+
var blocks = [
|
|
4
|
+
{
|
|
5
|
+
id: "docs.examples.calendar-google",
|
|
6
|
+
title: "Google Calendar (example)",
|
|
7
|
+
summary: "List upcoming events and create a new event via Google Calendar.",
|
|
8
|
+
kind: "reference",
|
|
9
|
+
visibility: "public",
|
|
10
|
+
route: "/docs/examples/calendar-google",
|
|
11
|
+
tags: ["calendar", "google-calendar", "example"],
|
|
12
|
+
body: `## What this example shows
|
|
13
|
+
- Create a Google OAuth client from env vars.
|
|
14
|
+
- List upcoming events with time bounds.
|
|
15
|
+
- Create a new event with attendees and reminders.
|
|
16
|
+
|
|
17
|
+
## Guardrails
|
|
18
|
+
- Keep refresh tokens in secrets.
|
|
19
|
+
- Use dry-run when validating payloads.
|
|
20
|
+
- Limit maxResults for quick previews.`
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "docs.examples.calendar-google.usage",
|
|
24
|
+
title: "Google Calendar - Usage",
|
|
25
|
+
summary: "How to run the calendar sync with env-driven settings.",
|
|
26
|
+
kind: "usage",
|
|
27
|
+
visibility: "public",
|
|
28
|
+
route: "/docs/examples/calendar-google/usage",
|
|
29
|
+
tags: ["calendar", "usage"],
|
|
30
|
+
body: `## Usage
|
|
31
|
+
- Set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_REFRESH_TOKEN.
|
|
32
|
+
- Optionally set GOOGLE_CALENDAR_ID (defaults to primary).
|
|
33
|
+
- Run the sync script to create a sample event.
|
|
34
|
+
|
|
35
|
+
## Refresh token
|
|
36
|
+
- Open https://developers.google.com/oauthplayground.
|
|
37
|
+
- Enable "Use your own OAuth credentials" and enter client ID/secret.
|
|
38
|
+
- Authorize https://www.googleapis.com/auth/calendar and exchange tokens.
|
|
39
|
+
- Copy the refresh token into GOOGLE_REFRESH_TOKEN.
|
|
40
|
+
|
|
41
|
+
## Example
|
|
42
|
+
- Call runCalendarSyncFromEnv() from run.ts to execute the flow.`
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
registerDocBlocks(blocks);
|
|
46
|
+
// src/example.ts
|
|
47
|
+
import { defineExample } from "@contractspec/lib.contracts";
|
|
48
|
+
var example = defineExample({
|
|
49
|
+
meta: {
|
|
50
|
+
key: "calendar-google",
|
|
51
|
+
version: "1.0.0",
|
|
52
|
+
title: "Google Calendar",
|
|
53
|
+
description: "List upcoming events and create a new event using the Google Calendar provider.",
|
|
54
|
+
kind: "integration",
|
|
55
|
+
visibility: "public",
|
|
56
|
+
stability: "experimental",
|
|
57
|
+
owners: ["@platform.integrations"],
|
|
58
|
+
tags: ["calendar", "google-calendar", "integrations"]
|
|
59
|
+
},
|
|
60
|
+
docs: {
|
|
61
|
+
rootDocId: "docs.examples.calendar-google",
|
|
62
|
+
usageDocId: "docs.examples.calendar-google.usage"
|
|
63
|
+
},
|
|
64
|
+
entrypoints: {
|
|
65
|
+
packageName: "@contractspec/example.calendar-google",
|
|
66
|
+
docs: "./docs"
|
|
67
|
+
},
|
|
68
|
+
surfaces: {
|
|
69
|
+
templates: true,
|
|
70
|
+
sandbox: { enabled: true, modes: ["markdown", "specs"] },
|
|
71
|
+
studio: { enabled: true, installable: true },
|
|
72
|
+
mcp: { enabled: true }
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
var example_default = example;
|
|
76
|
+
|
|
77
|
+
// src/sync.ts
|
|
78
|
+
import { google } from "googleapis";
|
|
79
|
+
import { GoogleCalendarProvider } from "@contractspec/integration.providers-impls/impls/google-calendar";
|
|
80
|
+
async function runCalendarSyncFromEnv() {
|
|
81
|
+
const calendarId = resolveCalendarId();
|
|
82
|
+
const dryRun = process.env.CONTRACTSPEC_CALENDAR_DRY_RUN === "true";
|
|
83
|
+
const eventInput = buildSampleEvent(calendarId);
|
|
84
|
+
const listQuery = buildUpcomingQuery(calendarId);
|
|
85
|
+
if (dryRun) {
|
|
86
|
+
return { created: eventInput, upcoming: [eventInput] };
|
|
87
|
+
}
|
|
88
|
+
const provider = createProviderFromEnv(calendarId);
|
|
89
|
+
const created = await provider.createEvent(eventInput);
|
|
90
|
+
const upcoming = await provider.listEvents(listQuery);
|
|
91
|
+
return { created, upcoming: upcoming.events };
|
|
92
|
+
}
|
|
93
|
+
function buildSampleEvent(calendarId) {
|
|
94
|
+
const start = new Date;
|
|
95
|
+
const end = new Date(start.getTime() + 30 * 60 * 1000);
|
|
96
|
+
return {
|
|
97
|
+
calendarId,
|
|
98
|
+
title: "Product sync review",
|
|
99
|
+
description: "Review onboarding friction and sync action items.",
|
|
100
|
+
location: "Zoom",
|
|
101
|
+
start,
|
|
102
|
+
end,
|
|
103
|
+
conference: { create: true, type: "google_meet" },
|
|
104
|
+
attendees: [{ email: "teammate@example.com", name: "Teammate" }],
|
|
105
|
+
reminders: [{ method: "popup", minutesBeforeStart: 10 }],
|
|
106
|
+
metadata: { source: "contractspec-example" }
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function buildUpcomingQuery(calendarId) {
|
|
110
|
+
const now = new Date;
|
|
111
|
+
const inSevenDays = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
|
|
112
|
+
return {
|
|
113
|
+
calendarId,
|
|
114
|
+
timeMin: now,
|
|
115
|
+
timeMax: inSevenDays,
|
|
116
|
+
maxResults: 5
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function createProviderFromEnv(calendarId) {
|
|
120
|
+
const auth = createGoogleAuthFromEnv();
|
|
121
|
+
return new GoogleCalendarProvider({ auth, calendarId });
|
|
122
|
+
}
|
|
123
|
+
function createGoogleAuthFromEnv() {
|
|
124
|
+
const clientId = requireEnv("GOOGLE_CLIENT_ID");
|
|
125
|
+
const clientSecret = requireEnv("GOOGLE_CLIENT_SECRET");
|
|
126
|
+
const refreshToken = requireEnv("GOOGLE_REFRESH_TOKEN");
|
|
127
|
+
const redirectUri = process.env.GOOGLE_REDIRECT_URI ?? "https://developers.google.com/oauthplayground";
|
|
128
|
+
const oauth = new google.auth.OAuth2(clientId, clientSecret, redirectUri);
|
|
129
|
+
oauth.setCredentials({ refresh_token: refreshToken });
|
|
130
|
+
return oauth;
|
|
131
|
+
}
|
|
132
|
+
function resolveCalendarId() {
|
|
133
|
+
return process.env.GOOGLE_CALENDAR_ID ?? "primary";
|
|
134
|
+
}
|
|
135
|
+
function requireEnv(key) {
|
|
136
|
+
const value = process.env[key];
|
|
137
|
+
if (!value) {
|
|
138
|
+
throw new Error(buildMissingEnvMessage(key));
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
function buildMissingEnvMessage(key) {
|
|
143
|
+
if (key !== "GOOGLE_REFRESH_TOKEN") {
|
|
144
|
+
return `Missing required env var: ${key}`;
|
|
145
|
+
}
|
|
146
|
+
return [
|
|
147
|
+
`Missing required env var: ${key}`,
|
|
148
|
+
"Get a refresh token with OAuth Playground:",
|
|
149
|
+
"1) Open https://developers.google.com/oauthplayground",
|
|
150
|
+
'2) Click the gear icon and enable "Use your own OAuth credentials"',
|
|
151
|
+
"3) Enter GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET",
|
|
152
|
+
"4) Authorize scope https://www.googleapis.com/auth/calendar",
|
|
153
|
+
"5) Exchange for tokens and copy the refresh token",
|
|
154
|
+
"Then export GOOGLE_REFRESH_TOKEN and rerun the script."
|
|
155
|
+
].join(`
|
|
156
|
+
`);
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
runCalendarSyncFromEnv,
|
|
160
|
+
example_default as example,
|
|
161
|
+
createProviderFromEnv,
|
|
162
|
+
buildUpcomingQuery,
|
|
163
|
+
buildSampleEvent
|
|
164
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/sync.ts
|
|
2
|
+
import { google } from "googleapis";
|
|
3
|
+
import { GoogleCalendarProvider } from "@contractspec/integration.providers-impls/impls/google-calendar";
|
|
4
|
+
async function runCalendarSyncFromEnv() {
|
|
5
|
+
const calendarId = resolveCalendarId();
|
|
6
|
+
const dryRun = process.env.CONTRACTSPEC_CALENDAR_DRY_RUN === "true";
|
|
7
|
+
const eventInput = buildSampleEvent(calendarId);
|
|
8
|
+
const listQuery = buildUpcomingQuery(calendarId);
|
|
9
|
+
if (dryRun) {
|
|
10
|
+
return { created: eventInput, upcoming: [eventInput] };
|
|
11
|
+
}
|
|
12
|
+
const provider = createProviderFromEnv(calendarId);
|
|
13
|
+
const created = await provider.createEvent(eventInput);
|
|
14
|
+
const upcoming = await provider.listEvents(listQuery);
|
|
15
|
+
return { created, upcoming: upcoming.events };
|
|
16
|
+
}
|
|
17
|
+
function buildSampleEvent(calendarId) {
|
|
18
|
+
const start = new Date;
|
|
19
|
+
const end = new Date(start.getTime() + 30 * 60 * 1000);
|
|
20
|
+
return {
|
|
21
|
+
calendarId,
|
|
22
|
+
title: "Product sync review",
|
|
23
|
+
description: "Review onboarding friction and sync action items.",
|
|
24
|
+
location: "Zoom",
|
|
25
|
+
start,
|
|
26
|
+
end,
|
|
27
|
+
conference: { create: true, type: "google_meet" },
|
|
28
|
+
attendees: [{ email: "teammate@example.com", name: "Teammate" }],
|
|
29
|
+
reminders: [{ method: "popup", minutesBeforeStart: 10 }],
|
|
30
|
+
metadata: { source: "contractspec-example" }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function buildUpcomingQuery(calendarId) {
|
|
34
|
+
const now = new Date;
|
|
35
|
+
const inSevenDays = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
|
|
36
|
+
return {
|
|
37
|
+
calendarId,
|
|
38
|
+
timeMin: now,
|
|
39
|
+
timeMax: inSevenDays,
|
|
40
|
+
maxResults: 5
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function createProviderFromEnv(calendarId) {
|
|
44
|
+
const auth = createGoogleAuthFromEnv();
|
|
45
|
+
return new GoogleCalendarProvider({ auth, calendarId });
|
|
46
|
+
}
|
|
47
|
+
function createGoogleAuthFromEnv() {
|
|
48
|
+
const clientId = requireEnv("GOOGLE_CLIENT_ID");
|
|
49
|
+
const clientSecret = requireEnv("GOOGLE_CLIENT_SECRET");
|
|
50
|
+
const refreshToken = requireEnv("GOOGLE_REFRESH_TOKEN");
|
|
51
|
+
const redirectUri = process.env.GOOGLE_REDIRECT_URI ?? "https://developers.google.com/oauthplayground";
|
|
52
|
+
const oauth = new google.auth.OAuth2(clientId, clientSecret, redirectUri);
|
|
53
|
+
oauth.setCredentials({ refresh_token: refreshToken });
|
|
54
|
+
return oauth;
|
|
55
|
+
}
|
|
56
|
+
function resolveCalendarId() {
|
|
57
|
+
return process.env.GOOGLE_CALENDAR_ID ?? "primary";
|
|
58
|
+
}
|
|
59
|
+
function requireEnv(key) {
|
|
60
|
+
const value = process.env[key];
|
|
61
|
+
if (!value) {
|
|
62
|
+
throw new Error(buildMissingEnvMessage(key));
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function buildMissingEnvMessage(key) {
|
|
67
|
+
if (key !== "GOOGLE_REFRESH_TOKEN") {
|
|
68
|
+
return `Missing required env var: ${key}`;
|
|
69
|
+
}
|
|
70
|
+
return [
|
|
71
|
+
`Missing required env var: ${key}`,
|
|
72
|
+
"Get a refresh token with OAuth Playground:",
|
|
73
|
+
"1) Open https://developers.google.com/oauthplayground",
|
|
74
|
+
'2) Click the gear icon and enable "Use your own OAuth credentials"',
|
|
75
|
+
"3) Enter GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET",
|
|
76
|
+
"4) Authorize scope https://www.googleapis.com/auth/calendar",
|
|
77
|
+
"5) Exchange for tokens and copy the refresh token",
|
|
78
|
+
"Then export GOOGLE_REFRESH_TOKEN and rerun the script."
|
|
79
|
+
].join(`
|
|
80
|
+
`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/run.ts
|
|
84
|
+
runCalendarSyncFromEnv().then((result) => {
|
|
85
|
+
console.log(JSON.stringify(result, null, 2));
|
|
86
|
+
}).catch((error) => {
|
|
87
|
+
console.error(error);
|
|
88
|
+
process.exitCode = 1;
|
|
89
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/sync.ts
|
|
2
|
+
import { google } from "googleapis";
|
|
3
|
+
import { GoogleCalendarProvider } from "@contractspec/integration.providers-impls/impls/google-calendar";
|
|
4
|
+
async function runCalendarSyncFromEnv() {
|
|
5
|
+
const calendarId = resolveCalendarId();
|
|
6
|
+
const dryRun = process.env.CONTRACTSPEC_CALENDAR_DRY_RUN === "true";
|
|
7
|
+
const eventInput = buildSampleEvent(calendarId);
|
|
8
|
+
const listQuery = buildUpcomingQuery(calendarId);
|
|
9
|
+
if (dryRun) {
|
|
10
|
+
return { created: eventInput, upcoming: [eventInput] };
|
|
11
|
+
}
|
|
12
|
+
const provider = createProviderFromEnv(calendarId);
|
|
13
|
+
const created = await provider.createEvent(eventInput);
|
|
14
|
+
const upcoming = await provider.listEvents(listQuery);
|
|
15
|
+
return { created, upcoming: upcoming.events };
|
|
16
|
+
}
|
|
17
|
+
function buildSampleEvent(calendarId) {
|
|
18
|
+
const start = new Date;
|
|
19
|
+
const end = new Date(start.getTime() + 30 * 60 * 1000);
|
|
20
|
+
return {
|
|
21
|
+
calendarId,
|
|
22
|
+
title: "Product sync review",
|
|
23
|
+
description: "Review onboarding friction and sync action items.",
|
|
24
|
+
location: "Zoom",
|
|
25
|
+
start,
|
|
26
|
+
end,
|
|
27
|
+
conference: { create: true, type: "google_meet" },
|
|
28
|
+
attendees: [{ email: "teammate@example.com", name: "Teammate" }],
|
|
29
|
+
reminders: [{ method: "popup", minutesBeforeStart: 10 }],
|
|
30
|
+
metadata: { source: "contractspec-example" }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function buildUpcomingQuery(calendarId) {
|
|
34
|
+
const now = new Date;
|
|
35
|
+
const inSevenDays = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
|
|
36
|
+
return {
|
|
37
|
+
calendarId,
|
|
38
|
+
timeMin: now,
|
|
39
|
+
timeMax: inSevenDays,
|
|
40
|
+
maxResults: 5
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function createProviderFromEnv(calendarId) {
|
|
44
|
+
const auth = createGoogleAuthFromEnv();
|
|
45
|
+
return new GoogleCalendarProvider({ auth, calendarId });
|
|
46
|
+
}
|
|
47
|
+
function createGoogleAuthFromEnv() {
|
|
48
|
+
const clientId = requireEnv("GOOGLE_CLIENT_ID");
|
|
49
|
+
const clientSecret = requireEnv("GOOGLE_CLIENT_SECRET");
|
|
50
|
+
const refreshToken = requireEnv("GOOGLE_REFRESH_TOKEN");
|
|
51
|
+
const redirectUri = process.env.GOOGLE_REDIRECT_URI ?? "https://developers.google.com/oauthplayground";
|
|
52
|
+
const oauth = new google.auth.OAuth2(clientId, clientSecret, redirectUri);
|
|
53
|
+
oauth.setCredentials({ refresh_token: refreshToken });
|
|
54
|
+
return oauth;
|
|
55
|
+
}
|
|
56
|
+
function resolveCalendarId() {
|
|
57
|
+
return process.env.GOOGLE_CALENDAR_ID ?? "primary";
|
|
58
|
+
}
|
|
59
|
+
function requireEnv(key) {
|
|
60
|
+
const value = process.env[key];
|
|
61
|
+
if (!value) {
|
|
62
|
+
throw new Error(buildMissingEnvMessage(key));
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function buildMissingEnvMessage(key) {
|
|
67
|
+
if (key !== "GOOGLE_REFRESH_TOKEN") {
|
|
68
|
+
return `Missing required env var: ${key}`;
|
|
69
|
+
}
|
|
70
|
+
return [
|
|
71
|
+
`Missing required env var: ${key}`,
|
|
72
|
+
"Get a refresh token with OAuth Playground:",
|
|
73
|
+
"1) Open https://developers.google.com/oauthplayground",
|
|
74
|
+
'2) Click the gear icon and enable "Use your own OAuth credentials"',
|
|
75
|
+
"3) Enter GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET",
|
|
76
|
+
"4) Authorize scope https://www.googleapis.com/auth/calendar",
|
|
77
|
+
"5) Exchange for tokens and copy the refresh token",
|
|
78
|
+
"Then export GOOGLE_REFRESH_TOKEN and rerun the script."
|
|
79
|
+
].join(`
|
|
80
|
+
`);
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
runCalendarSyncFromEnv,
|
|
84
|
+
createProviderFromEnv,
|
|
85
|
+
buildUpcomingQuery,
|
|
86
|
+
buildSampleEvent
|
|
87
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=calendar-google.docblock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-google.docblock.d.ts","sourceRoot":"","sources":["../../src/docs/calendar-google.docblock.ts"],"names":[],"mappings":""}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/docs/calendar-google.docblock.ts
|
|
1
3
|
import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"calendar",
|
|
13
|
-
"google-calendar",
|
|
14
|
-
"example"
|
|
15
|
-
],
|
|
16
|
-
body: `## What this example shows
|
|
4
|
+
var blocks = [
|
|
5
|
+
{
|
|
6
|
+
id: "docs.examples.calendar-google",
|
|
7
|
+
title: "Google Calendar (example)",
|
|
8
|
+
summary: "List upcoming events and create a new event via Google Calendar.",
|
|
9
|
+
kind: "reference",
|
|
10
|
+
visibility: "public",
|
|
11
|
+
route: "/docs/examples/calendar-google",
|
|
12
|
+
tags: ["calendar", "google-calendar", "example"],
|
|
13
|
+
body: `## What this example shows
|
|
17
14
|
- Create a Google OAuth client from env vars.
|
|
18
15
|
- List upcoming events with time bounds.
|
|
19
16
|
- Create a new event with attendees and reminders.
|
|
@@ -22,15 +19,16 @@ registerDocBlocks([{
|
|
|
22
19
|
- Keep refresh tokens in secrets.
|
|
23
20
|
- Use dry-run when validating payloads.
|
|
24
21
|
- Limit maxResults for quick previews.`
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "docs.examples.calendar-google.usage",
|
|
25
|
+
title: "Google Calendar - Usage",
|
|
26
|
+
summary: "How to run the calendar sync with env-driven settings.",
|
|
27
|
+
kind: "usage",
|
|
28
|
+
visibility: "public",
|
|
29
|
+
route: "/docs/examples/calendar-google/usage",
|
|
30
|
+
tags: ["calendar", "usage"],
|
|
31
|
+
body: `## Usage
|
|
34
32
|
- Set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_REFRESH_TOKEN.
|
|
35
33
|
- Optionally set GOOGLE_CALENDAR_ID (defaults to primary).
|
|
36
34
|
- Run the sync script to create a sample event.
|
|
@@ -43,7 +41,6 @@ registerDocBlocks([{
|
|
|
43
41
|
|
|
44
42
|
## Example
|
|
45
43
|
- Call runCalendarSyncFromEnv() from run.ts to execute the flow.`
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=calendar-google.docblock.js.map
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
registerDocBlocks(blocks);
|
package/dist/docs/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import './calendar-google.docblock';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docs/index.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC"}
|