@contractspec/example.calendar-google 1.57.0 → 1.59.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.
Files changed (41) hide show
  1. package/.turbo/turbo-build.log +34 -33
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +25 -0
  4. package/dist/browser/docs/calendar-google.docblock.js +45 -0
  5. package/dist/browser/docs/index.js +45 -0
  6. package/dist/browser/example.js +33 -0
  7. package/dist/browser/index.js +164 -0
  8. package/dist/browser/run.js +89 -0
  9. package/dist/browser/sync.js +87 -0
  10. package/dist/docs/calendar-google.docblock.d.ts +2 -1
  11. package/dist/docs/calendar-google.docblock.d.ts.map +1 -0
  12. package/dist/docs/calendar-google.docblock.js +25 -28
  13. package/dist/docs/index.d.ts +2 -1
  14. package/dist/docs/index.d.ts.map +1 -0
  15. package/dist/docs/index.js +46 -1
  16. package/dist/example.d.ts +2 -6
  17. package/dist/example.d.ts.map +1 -1
  18. package/dist/example.js +32 -42
  19. package/dist/index.d.ts +4 -3
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +164 -4
  22. package/dist/node/docs/calendar-google.docblock.js +45 -0
  23. package/dist/node/docs/index.js +45 -0
  24. package/dist/node/example.js +33 -0
  25. package/dist/node/index.js +164 -0
  26. package/dist/node/run.js +89 -0
  27. package/dist/node/sync.js +87 -0
  28. package/dist/run.d.ts +2 -1
  29. package/dist/run.d.ts.map +1 -0
  30. package/dist/run.js +86 -8
  31. package/dist/sync.d.ts +8 -12
  32. package/dist/sync.d.ts.map +1 -1
  33. package/dist/sync.js +70 -74
  34. package/package.json +69 -26
  35. package/tsdown.config.js +1 -2
  36. package/.turbo/turbo-build$colon$bundle.log +0 -33
  37. package/dist/docs/calendar-google.docblock.js.map +0 -1
  38. package/dist/example.js.map +0 -1
  39. package/dist/run.js.map +0 -1
  40. package/dist/sync.js.map +0 -1
  41. package/tsconfig.tsbuildinfo +0 -1
@@ -1,34 +1,35 @@
1
- $ bun build:types && bun build:bundle
2
- $ tsc --noEmit
3
- $ tsdown
4
- ℹ tsdown v0.20.3 powered by rolldown v1.0.0-rc.3
5
- ℹ config file: /home/runner/work/contractspec/contractspec/packages/examples/calendar-google/tsdown.config.js
6
- ℹ entry: src/example.ts, src/index.ts, src/run.ts, src/sync.ts, src/docs/calendar-google.docblock.ts, src/docs/index.ts
7
- ℹ target: esnext
8
- ℹ tsconfig: tsconfig.json
9
- ℹ Build start
10
- ℹ dist/sync.js 2.97 kB │ gzip: 1.25 kB
11
- ℹ dist/docs/calendar-google.docblock.js 1.62 kB │ gzip: 0.80 kB
12
- ℹ dist/example.js 0.96 kB │ gzip: 0.49 kB
13
- ℹ dist/run.js 0.28 kB │ gzip: 0.22 kB
14
- ℹ dist/index.js 0.28 kB │ gzip: 0.16 kB
15
- ℹ dist/docs/index.js 0.04 kB │ gzip: 0.06 kB
16
- ℹ dist/sync.js.map 5.05 kB │ gzip: 1.98 kB
17
- ℹ dist/docs/calendar-google.docblock.js.map 2.13 kB │ gzip: 0.98 kB
18
- ℹ dist/example.js.map 1.43 kB │ gzip: 0.69 kB
19
- ℹ dist/run.js.map 0.49 kB │ gzip: 0.33 kB
20
- ℹ dist/sync.d.ts.map 0.34 kB │ gzip: 0.21 kB
21
- ℹ dist/example.d.ts.map 0.13 kB │ gzip: 0.13 kB
22
- ℹ dist/sync.d.ts 0.78 kB │ gzip: 0.33 kB
23
- ℹ dist/index.d.ts 0.29 kB │ gzip: 0.15 kB
24
- ℹ dist/example.d.ts 0.25 kB │ gzip: 0.17 kB
25
- ℹ dist/docs/calendar-google.docblock.d.ts 0.01 kB │ gzip: 0.03 kB
26
- ℹ dist/docs/index.d.ts 0.01 kB │ gzip: 0.03 kB
27
- ℹ dist/run.d.ts 0.01 kB │ gzip: 0.03 kB
28
- ℹ 18 files, total: 17.06 kB
29
- [PLUGIN_TIMINGS] Warning: 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 19ms
33
7
 
34
- ✔ Build complete in 90538ms
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 49ms
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 30ms
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,30 @@
1
1
  # @contractspec/example.calendar-google
2
2
 
3
+ ## 1.59.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1a0cf44: fix: publishConfig not supported by bun
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [1a0cf44]
12
+ - @contractspec/integration.providers-impls@1.59.0
13
+ - @contractspec/lib.contracts@1.59.0
14
+
15
+ ## 1.58.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 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`.
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [d1f0fd0]
24
+ - Updated dependencies [4355a9e]
25
+ - @contractspec/integration.providers-impls@1.58.0
26
+ - @contractspec/lib.contracts@1.58.0
27
+
3
28
  ## 1.57.0
4
29
 
5
30
  ### 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
- //#region src/docs/calendar-google.docblock.ts
4
- registerDocBlocks([{
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: [
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
- id: "docs.examples.calendar-google.usage",
27
- title: "Google Calendar - Usage",
28
- summary: "How to run the calendar sync with env-driven settings.",
29
- kind: "usage",
30
- visibility: "public",
31
- route: "/docs/examples/calendar-google/usage",
32
- tags: ["calendar", "usage"],
33
- body: `## Usage
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
- //#endregion
49
- //# sourceMappingURL=calendar-google.docblock.js.map
44
+ }
45
+ ];
46
+ registerDocBlocks(blocks);
@@ -1 +1,2 @@
1
- export { };
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"}