@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 +1,46 @@
1
- import "./calendar-google.docblock.js";
1
+ // @bun
2
+ // src/docs/calendar-google.docblock.ts
3
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
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
14
+ - Create a Google OAuth client from env vars.
15
+ - List upcoming events with time bounds.
16
+ - Create a new event with attendees and reminders.
17
+
18
+ ## Guardrails
19
+ - Keep refresh tokens in secrets.
20
+ - Use dry-run when validating payloads.
21
+ - Limit maxResults for quick previews.`
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
32
+ - Set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_REFRESH_TOKEN.
33
+ - Optionally set GOOGLE_CALENDAR_ID (defaults to primary).
34
+ - Run the sync script to create a sample event.
35
+
36
+ ## Refresh token
37
+ - Open https://developers.google.com/oauthplayground.
38
+ - Enable "Use your own OAuth credentials" and enter client ID/secret.
39
+ - Authorize https://www.googleapis.com/auth/calendar and exchange tokens.
40
+ - Copy the refresh token into GOOGLE_REFRESH_TOKEN.
41
+
42
+ ## Example
43
+ - Call runCalendarSyncFromEnv() from run.ts to execute the flow.`
44
+ }
45
+ ];
46
+ registerDocBlocks(blocks);
package/dist/example.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- import * as _contractspec_lib_contracts0 from "@contractspec/lib.contracts";
2
-
3
- //#region src/example.d.ts
4
- declare const example: _contractspec_lib_contracts0.ExampleSpec;
5
- //#endregion
6
- export { example as default };
1
+ declare const example: import("@contractspec/lib.contracts").ExampleSpec;
2
+ export default example;
7
3
  //# sourceMappingURL=example.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"example.d.ts","names":[],"sources":["../src/example.ts"],"mappings":";;;cAEM,OAAA,EA2BJ,4BAAA,CA3BW,WAAA"}
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,OAAO,mDA2BX,CAAC;AAEH,eAAe,OAAO,CAAC"}
package/dist/example.js CHANGED
@@ -1,44 +1,34 @@
1
+ // @bun
2
+ // src/example.ts
1
3
  import { defineExample } from "@contractspec/lib.contracts";
2
-
3
- //#region src/example.ts
4
- const example = defineExample({
5
- meta: {
6
- key: "calendar-google",
7
- version: "1.0.0",
8
- title: "Google Calendar",
9
- description: "List upcoming events and create a new event using the Google Calendar provider.",
10
- kind: "integration",
11
- visibility: "public",
12
- stability: "experimental",
13
- owners: ["@platform.integrations"],
14
- tags: [
15
- "calendar",
16
- "google-calendar",
17
- "integrations"
18
- ]
19
- },
20
- docs: {
21
- rootDocId: "docs.examples.calendar-google",
22
- usageDocId: "docs.examples.calendar-google.usage"
23
- },
24
- entrypoints: {
25
- packageName: "@contractspec/example.calendar-google",
26
- docs: "./docs"
27
- },
28
- surfaces: {
29
- templates: true,
30
- sandbox: {
31
- enabled: true,
32
- modes: ["markdown", "specs"]
33
- },
34
- studio: {
35
- enabled: true,
36
- installable: true
37
- },
38
- mcp: { enabled: true }
39
- }
4
+ var example = defineExample({
5
+ meta: {
6
+ key: "calendar-google",
7
+ version: "1.0.0",
8
+ title: "Google Calendar",
9
+ description: "List upcoming events and create a new event using the Google Calendar provider.",
10
+ kind: "integration",
11
+ visibility: "public",
12
+ stability: "experimental",
13
+ owners: ["@platform.integrations"],
14
+ tags: ["calendar", "google-calendar", "integrations"]
15
+ },
16
+ docs: {
17
+ rootDocId: "docs.examples.calendar-google",
18
+ usageDocId: "docs.examples.calendar-google.usage"
19
+ },
20
+ entrypoints: {
21
+ packageName: "@contractspec/example.calendar-google",
22
+ docs: "./docs"
23
+ },
24
+ surfaces: {
25
+ templates: true,
26
+ sandbox: { enabled: true, modes: ["markdown", "specs"] },
27
+ studio: { enabled: true, installable: true },
28
+ mcp: { enabled: true }
29
+ }
40
30
  });
41
-
42
- //#endregion
43
- export { example as default };
44
- //# sourceMappingURL=example.js.map
31
+ var example_default = example;
32
+ export {
33
+ example_default as default
34
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import example from "./example.js";
2
- import { CalendarSyncOutput, buildSampleEvent, buildUpcomingQuery, createProviderFromEnv, runCalendarSyncFromEnv } from "./sync.js";
3
- export { CalendarSyncOutput, buildSampleEvent, buildUpcomingQuery, createProviderFromEnv, example, runCalendarSyncFromEnv };
1
+ export * from './sync';
2
+ export { default as example } from './example';
3
+ import './docs';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,165 @@
1
- import example from "./example.js";
2
- import { buildSampleEvent, buildUpcomingQuery, createProviderFromEnv, runCalendarSyncFromEnv } from "./sync.js";
3
- import "./docs/index.js";
1
+ // @bun
2
+ // src/docs/calendar-google.docblock.ts
3
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
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
14
+ - Create a Google OAuth client from env vars.
15
+ - List upcoming events with time bounds.
16
+ - Create a new event with attendees and reminders.
4
17
 
5
- export { buildSampleEvent, buildUpcomingQuery, createProviderFromEnv, example, runCalendarSyncFromEnv };
18
+ ## Guardrails
19
+ - Keep refresh tokens in secrets.
20
+ - Use dry-run when validating payloads.
21
+ - Limit maxResults for quick previews.`
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
32
+ - Set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_REFRESH_TOKEN.
33
+ - Optionally set GOOGLE_CALENDAR_ID (defaults to primary).
34
+ - Run the sync script to create a sample event.
35
+
36
+ ## Refresh token
37
+ - Open https://developers.google.com/oauthplayground.
38
+ - Enable "Use your own OAuth credentials" and enter client ID/secret.
39
+ - Authorize https://www.googleapis.com/auth/calendar and exchange tokens.
40
+ - Copy the refresh token into GOOGLE_REFRESH_TOKEN.
41
+
42
+ ## Example
43
+ - Call runCalendarSyncFromEnv() from run.ts to execute the flow.`
44
+ }
45
+ ];
46
+ registerDocBlocks(blocks);
47
+ // src/example.ts
48
+ import { defineExample } from "@contractspec/lib.contracts";
49
+ var example = defineExample({
50
+ meta: {
51
+ key: "calendar-google",
52
+ version: "1.0.0",
53
+ title: "Google Calendar",
54
+ description: "List upcoming events and create a new event using the Google Calendar provider.",
55
+ kind: "integration",
56
+ visibility: "public",
57
+ stability: "experimental",
58
+ owners: ["@platform.integrations"],
59
+ tags: ["calendar", "google-calendar", "integrations"]
60
+ },
61
+ docs: {
62
+ rootDocId: "docs.examples.calendar-google",
63
+ usageDocId: "docs.examples.calendar-google.usage"
64
+ },
65
+ entrypoints: {
66
+ packageName: "@contractspec/example.calendar-google",
67
+ docs: "./docs"
68
+ },
69
+ surfaces: {
70
+ templates: true,
71
+ sandbox: { enabled: true, modes: ["markdown", "specs"] },
72
+ studio: { enabled: true, installable: true },
73
+ mcp: { enabled: true }
74
+ }
75
+ });
76
+ var example_default = example;
77
+
78
+ // src/sync.ts
79
+ import { google } from "googleapis";
80
+ import { GoogleCalendarProvider } from "@contractspec/integration.providers-impls/impls/google-calendar";
81
+ async function runCalendarSyncFromEnv() {
82
+ const calendarId = resolveCalendarId();
83
+ const dryRun = process.env.CONTRACTSPEC_CALENDAR_DRY_RUN === "true";
84
+ const eventInput = buildSampleEvent(calendarId);
85
+ const listQuery = buildUpcomingQuery(calendarId);
86
+ if (dryRun) {
87
+ return { created: eventInput, upcoming: [eventInput] };
88
+ }
89
+ const provider = createProviderFromEnv(calendarId);
90
+ const created = await provider.createEvent(eventInput);
91
+ const upcoming = await provider.listEvents(listQuery);
92
+ return { created, upcoming: upcoming.events };
93
+ }
94
+ function buildSampleEvent(calendarId) {
95
+ const start = new Date;
96
+ const end = new Date(start.getTime() + 30 * 60 * 1000);
97
+ return {
98
+ calendarId,
99
+ title: "Product sync review",
100
+ description: "Review onboarding friction and sync action items.",
101
+ location: "Zoom",
102
+ start,
103
+ end,
104
+ conference: { create: true, type: "google_meet" },
105
+ attendees: [{ email: "teammate@example.com", name: "Teammate" }],
106
+ reminders: [{ method: "popup", minutesBeforeStart: 10 }],
107
+ metadata: { source: "contractspec-example" }
108
+ };
109
+ }
110
+ function buildUpcomingQuery(calendarId) {
111
+ const now = new Date;
112
+ const inSevenDays = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
113
+ return {
114
+ calendarId,
115
+ timeMin: now,
116
+ timeMax: inSevenDays,
117
+ maxResults: 5
118
+ };
119
+ }
120
+ function createProviderFromEnv(calendarId) {
121
+ const auth = createGoogleAuthFromEnv();
122
+ return new GoogleCalendarProvider({ auth, calendarId });
123
+ }
124
+ function createGoogleAuthFromEnv() {
125
+ const clientId = requireEnv("GOOGLE_CLIENT_ID");
126
+ const clientSecret = requireEnv("GOOGLE_CLIENT_SECRET");
127
+ const refreshToken = requireEnv("GOOGLE_REFRESH_TOKEN");
128
+ const redirectUri = process.env.GOOGLE_REDIRECT_URI ?? "https://developers.google.com/oauthplayground";
129
+ const oauth = new google.auth.OAuth2(clientId, clientSecret, redirectUri);
130
+ oauth.setCredentials({ refresh_token: refreshToken });
131
+ return oauth;
132
+ }
133
+ function resolveCalendarId() {
134
+ return process.env.GOOGLE_CALENDAR_ID ?? "primary";
135
+ }
136
+ function requireEnv(key) {
137
+ const value = process.env[key];
138
+ if (!value) {
139
+ throw new Error(buildMissingEnvMessage(key));
140
+ }
141
+ return value;
142
+ }
143
+ function buildMissingEnvMessage(key) {
144
+ if (key !== "GOOGLE_REFRESH_TOKEN") {
145
+ return `Missing required env var: ${key}`;
146
+ }
147
+ return [
148
+ `Missing required env var: ${key}`,
149
+ "Get a refresh token with OAuth Playground:",
150
+ "1) Open https://developers.google.com/oauthplayground",
151
+ '2) Click the gear icon and enable "Use your own OAuth credentials"',
152
+ "3) Enter GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET",
153
+ "4) Authorize scope https://www.googleapis.com/auth/calendar",
154
+ "5) Exchange for tokens and copy the refresh token",
155
+ "Then export GOOGLE_REFRESH_TOKEN and rerun the script."
156
+ ].join(`
157
+ `);
158
+ }
159
+ export {
160
+ runCalendarSyncFromEnv,
161
+ example_default as example,
162
+ createProviderFromEnv,
163
+ buildUpcomingQuery,
164
+ buildSampleEvent
165
+ };
@@ -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
+ };