@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.
- package/.turbo/turbo-build.log +34 -33
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +25 -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/dist/node/run.js
ADDED
|
@@ -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
|
+
};
|
package/dist/run.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":""}
|
package/dist/run.js
CHANGED
|
@@ -1,12 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/sync.ts
|
|
3
|
+
import { google } from "googleapis";
|
|
4
|
+
import { GoogleCalendarProvider } from "@contractspec/integration.providers-impls/impls/google-calendar";
|
|
5
|
+
async function runCalendarSyncFromEnv() {
|
|
6
|
+
const calendarId = resolveCalendarId();
|
|
7
|
+
const dryRun = process.env.CONTRACTSPEC_CALENDAR_DRY_RUN === "true";
|
|
8
|
+
const eventInput = buildSampleEvent(calendarId);
|
|
9
|
+
const listQuery = buildUpcomingQuery(calendarId);
|
|
10
|
+
if (dryRun) {
|
|
11
|
+
return { created: eventInput, upcoming: [eventInput] };
|
|
12
|
+
}
|
|
13
|
+
const provider = createProviderFromEnv(calendarId);
|
|
14
|
+
const created = await provider.createEvent(eventInput);
|
|
15
|
+
const upcoming = await provider.listEvents(listQuery);
|
|
16
|
+
return { created, upcoming: upcoming.events };
|
|
17
|
+
}
|
|
18
|
+
function buildSampleEvent(calendarId) {
|
|
19
|
+
const start = new Date;
|
|
20
|
+
const end = new Date(start.getTime() + 30 * 60 * 1000);
|
|
21
|
+
return {
|
|
22
|
+
calendarId,
|
|
23
|
+
title: "Product sync review",
|
|
24
|
+
description: "Review onboarding friction and sync action items.",
|
|
25
|
+
location: "Zoom",
|
|
26
|
+
start,
|
|
27
|
+
end,
|
|
28
|
+
conference: { create: true, type: "google_meet" },
|
|
29
|
+
attendees: [{ email: "teammate@example.com", name: "Teammate" }],
|
|
30
|
+
reminders: [{ method: "popup", minutesBeforeStart: 10 }],
|
|
31
|
+
metadata: { source: "contractspec-example" }
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function buildUpcomingQuery(calendarId) {
|
|
35
|
+
const now = new Date;
|
|
36
|
+
const inSevenDays = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
|
|
37
|
+
return {
|
|
38
|
+
calendarId,
|
|
39
|
+
timeMin: now,
|
|
40
|
+
timeMax: inSevenDays,
|
|
41
|
+
maxResults: 5
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createProviderFromEnv(calendarId) {
|
|
45
|
+
const auth = createGoogleAuthFromEnv();
|
|
46
|
+
return new GoogleCalendarProvider({ auth, calendarId });
|
|
47
|
+
}
|
|
48
|
+
function createGoogleAuthFromEnv() {
|
|
49
|
+
const clientId = requireEnv("GOOGLE_CLIENT_ID");
|
|
50
|
+
const clientSecret = requireEnv("GOOGLE_CLIENT_SECRET");
|
|
51
|
+
const refreshToken = requireEnv("GOOGLE_REFRESH_TOKEN");
|
|
52
|
+
const redirectUri = process.env.GOOGLE_REDIRECT_URI ?? "https://developers.google.com/oauthplayground";
|
|
53
|
+
const oauth = new google.auth.OAuth2(clientId, clientSecret, redirectUri);
|
|
54
|
+
oauth.setCredentials({ refresh_token: refreshToken });
|
|
55
|
+
return oauth;
|
|
56
|
+
}
|
|
57
|
+
function resolveCalendarId() {
|
|
58
|
+
return process.env.GOOGLE_CALENDAR_ID ?? "primary";
|
|
59
|
+
}
|
|
60
|
+
function requireEnv(key) {
|
|
61
|
+
const value = process.env[key];
|
|
62
|
+
if (!value) {
|
|
63
|
+
throw new Error(buildMissingEnvMessage(key));
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
function buildMissingEnvMessage(key) {
|
|
68
|
+
if (key !== "GOOGLE_REFRESH_TOKEN") {
|
|
69
|
+
return `Missing required env var: ${key}`;
|
|
70
|
+
}
|
|
71
|
+
return [
|
|
72
|
+
`Missing required env var: ${key}`,
|
|
73
|
+
"Get a refresh token with OAuth Playground:",
|
|
74
|
+
"1) Open https://developers.google.com/oauthplayground",
|
|
75
|
+
'2) Click the gear icon and enable "Use your own OAuth credentials"',
|
|
76
|
+
"3) Enter GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET",
|
|
77
|
+
"4) Authorize scope https://www.googleapis.com/auth/calendar",
|
|
78
|
+
"5) Exchange for tokens and copy the refresh token",
|
|
79
|
+
"Then export GOOGLE_REFRESH_TOKEN and rerun the script."
|
|
80
|
+
].join(`
|
|
81
|
+
`);
|
|
82
|
+
}
|
|
2
83
|
|
|
3
|
-
|
|
84
|
+
// src/run.ts
|
|
4
85
|
runCalendarSyncFromEnv().then((result) => {
|
|
5
|
-
|
|
86
|
+
console.log(JSON.stringify(result, null, 2));
|
|
6
87
|
}).catch((error) => {
|
|
7
|
-
|
|
8
|
-
|
|
88
|
+
console.error(error);
|
|
89
|
+
process.exitCode = 1;
|
|
9
90
|
});
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
//# sourceMappingURL=run.js.map
|
package/dist/sync.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { CalendarEvent, CalendarEventInput, CalendarListEventsQuery, CalendarProvider } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
created?: CalendarEvent | CalendarEventInput;
|
|
6
|
-
upcoming: CalendarEvent[] | CalendarEventInput[];
|
|
1
|
+
import type { CalendarEvent, CalendarEventInput, CalendarListEventsQuery, CalendarProvider } from '@contractspec/integration.providers-impls/calendar';
|
|
2
|
+
export interface CalendarSyncOutput {
|
|
3
|
+
created?: CalendarEvent | CalendarEventInput;
|
|
4
|
+
upcoming: CalendarEvent[] | CalendarEventInput[];
|
|
7
5
|
}
|
|
8
|
-
declare function runCalendarSyncFromEnv(): Promise<CalendarSyncOutput>;
|
|
9
|
-
declare function buildSampleEvent(calendarId: string): CalendarEventInput;
|
|
10
|
-
declare function buildUpcomingQuery(calendarId: string): CalendarListEventsQuery;
|
|
11
|
-
declare function createProviderFromEnv(calendarId: string): CalendarProvider;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { CalendarSyncOutput, buildSampleEvent, buildUpcomingQuery, createProviderFromEnv, runCalendarSyncFromEnv };
|
|
6
|
+
export declare function runCalendarSyncFromEnv(): Promise<CalendarSyncOutput>;
|
|
7
|
+
export declare function buildSampleEvent(calendarId: string): CalendarEventInput;
|
|
8
|
+
export declare function buildUpcomingQuery(calendarId: string): CalendarListEventsQuery;
|
|
9
|
+
export declare function createProviderFromEnv(calendarId: string): CalendarProvider;
|
|
14
10
|
//# sourceMappingURL=sync.d.ts.map
|
package/dist/sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,oDAAoD,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,aAAa,GAAG,kBAAkB,CAAC;IAC7C,QAAQ,EAAE,aAAa,EAAE,GAAG,kBAAkB,EAAE,CAAC;CAClD;AAED,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAc1E;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB,CAevE;AAED,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,GACjB,uBAAuB,CASzB;AAED,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB,CAG1E"}
|
package/dist/sync.js
CHANGED
|
@@ -1,92 +1,88 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/sync.ts
|
|
1
3
|
import { google } from "googleapis";
|
|
2
4
|
import { GoogleCalendarProvider } from "@contractspec/integration.providers-impls/impls/google-calendar";
|
|
3
|
-
|
|
4
|
-
//#region src/sync.ts
|
|
5
5
|
async function runCalendarSyncFromEnv() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
upcoming: (await provider.listEvents(listQuery)).events
|
|
18
|
-
};
|
|
6
|
+
const calendarId = resolveCalendarId();
|
|
7
|
+
const dryRun = process.env.CONTRACTSPEC_CALENDAR_DRY_RUN === "true";
|
|
8
|
+
const eventInput = buildSampleEvent(calendarId);
|
|
9
|
+
const listQuery = buildUpcomingQuery(calendarId);
|
|
10
|
+
if (dryRun) {
|
|
11
|
+
return { created: eventInput, upcoming: [eventInput] };
|
|
12
|
+
}
|
|
13
|
+
const provider = createProviderFromEnv(calendarId);
|
|
14
|
+
const created = await provider.createEvent(eventInput);
|
|
15
|
+
const upcoming = await provider.listEvents(listQuery);
|
|
16
|
+
return { created, upcoming: upcoming.events };
|
|
19
17
|
}
|
|
20
18
|
function buildSampleEvent(calendarId) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
name: "Teammate"
|
|
36
|
-
}],
|
|
37
|
-
reminders: [{
|
|
38
|
-
method: "popup",
|
|
39
|
-
minutesBeforeStart: 10
|
|
40
|
-
}],
|
|
41
|
-
metadata: { source: "contractspec-example" }
|
|
42
|
-
};
|
|
19
|
+
const start = new Date;
|
|
20
|
+
const end = new Date(start.getTime() + 30 * 60 * 1000);
|
|
21
|
+
return {
|
|
22
|
+
calendarId,
|
|
23
|
+
title: "Product sync review",
|
|
24
|
+
description: "Review onboarding friction and sync action items.",
|
|
25
|
+
location: "Zoom",
|
|
26
|
+
start,
|
|
27
|
+
end,
|
|
28
|
+
conference: { create: true, type: "google_meet" },
|
|
29
|
+
attendees: [{ email: "teammate@example.com", name: "Teammate" }],
|
|
30
|
+
reminders: [{ method: "popup", minutesBeforeStart: 10 }],
|
|
31
|
+
metadata: { source: "contractspec-example" }
|
|
32
|
+
};
|
|
43
33
|
}
|
|
44
34
|
function buildUpcomingQuery(calendarId) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
const now = new Date;
|
|
36
|
+
const inSevenDays = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
|
|
37
|
+
return {
|
|
38
|
+
calendarId,
|
|
39
|
+
timeMin: now,
|
|
40
|
+
timeMax: inSevenDays,
|
|
41
|
+
maxResults: 5
|
|
42
|
+
};
|
|
52
43
|
}
|
|
53
44
|
function createProviderFromEnv(calendarId) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
calendarId
|
|
57
|
-
});
|
|
45
|
+
const auth = createGoogleAuthFromEnv();
|
|
46
|
+
return new GoogleCalendarProvider({ auth, calendarId });
|
|
58
47
|
}
|
|
59
48
|
function createGoogleAuthFromEnv() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
const clientId = requireEnv("GOOGLE_CLIENT_ID");
|
|
50
|
+
const clientSecret = requireEnv("GOOGLE_CLIENT_SECRET");
|
|
51
|
+
const refreshToken = requireEnv("GOOGLE_REFRESH_TOKEN");
|
|
52
|
+
const redirectUri = process.env.GOOGLE_REDIRECT_URI ?? "https://developers.google.com/oauthplayground";
|
|
53
|
+
const oauth = new google.auth.OAuth2(clientId, clientSecret, redirectUri);
|
|
54
|
+
oauth.setCredentials({ refresh_token: refreshToken });
|
|
55
|
+
return oauth;
|
|
67
56
|
}
|
|
68
57
|
function resolveCalendarId() {
|
|
69
|
-
|
|
58
|
+
return process.env.GOOGLE_CALENDAR_ID ?? "primary";
|
|
70
59
|
}
|
|
71
60
|
function requireEnv(key) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
const value = process.env[key];
|
|
62
|
+
if (!value) {
|
|
63
|
+
throw new Error(buildMissingEnvMessage(key));
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
75
66
|
}
|
|
76
67
|
function buildMissingEnvMessage(key) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
68
|
+
if (key !== "GOOGLE_REFRESH_TOKEN") {
|
|
69
|
+
return `Missing required env var: ${key}`;
|
|
70
|
+
}
|
|
71
|
+
return [
|
|
72
|
+
`Missing required env var: ${key}`,
|
|
73
|
+
"Get a refresh token with OAuth Playground:",
|
|
74
|
+
"1) Open https://developers.google.com/oauthplayground",
|
|
75
|
+
'2) Click the gear icon and enable "Use your own OAuth credentials"',
|
|
76
|
+
"3) Enter GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET",
|
|
77
|
+
"4) Authorize scope https://www.googleapis.com/auth/calendar",
|
|
78
|
+
"5) Exchange for tokens and copy the refresh token",
|
|
79
|
+
"Then export GOOGLE_REFRESH_TOKEN and rerun the script."
|
|
80
|
+
].join(`
|
|
81
|
+
`);
|
|
88
82
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
export {
|
|
84
|
+
runCalendarSyncFromEnv,
|
|
85
|
+
createProviderFromEnv,
|
|
86
|
+
buildUpcomingQuery,
|
|
87
|
+
buildSampleEvent
|
|
88
|
+
};
|
package/package.json
CHANGED
|
@@ -1,52 +1,95 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/example.calendar-google",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.59.0",
|
|
4
4
|
"description": "Google Calendar integration example: list and create events.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
-
".": "./
|
|
9
|
-
"./docs": "./
|
|
10
|
-
"./docs/calendar-google.docblock": "./
|
|
11
|
-
"./
|
|
12
|
-
"./
|
|
13
|
-
"./
|
|
14
|
-
"
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./docs": "./src/docs/index.ts",
|
|
10
|
+
"./docs/calendar-google.docblock": "./src/docs/calendar-google.docblock.ts",
|
|
11
|
+
"./docs/index": "./src/docs/index.ts",
|
|
12
|
+
"./example": "./src/example.ts",
|
|
13
|
+
"./run": "./src/run.ts",
|
|
14
|
+
"./sync": "./src/sync.ts"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
18
18
|
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
19
|
-
"build": "bun build:
|
|
20
|
-
"build:bundle": "
|
|
21
|
-
"build:types": "
|
|
22
|
-
"dev": "bun
|
|
19
|
+
"build": "bun run prebuild && bun run build:bundle && bun run build:types",
|
|
20
|
+
"build:bundle": "contractspec-bun-build transpile",
|
|
21
|
+
"build:types": "contractspec-bun-build types",
|
|
22
|
+
"dev": "contractspec-bun-build dev",
|
|
23
23
|
"clean": "rimraf dist .turbo",
|
|
24
24
|
"lint": "bun lint:fix",
|
|
25
25
|
"lint:fix": "eslint src --fix",
|
|
26
26
|
"lint:check": "eslint src",
|
|
27
|
-
"test": "bun test"
|
|
27
|
+
"test": "bun test",
|
|
28
|
+
"prebuild": "contractspec-bun-build prebuild",
|
|
29
|
+
"typecheck": "tsc --noEmit"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"@contractspec/integration.providers-impls": "1.
|
|
31
|
-
"@contractspec/lib.contracts": "1.
|
|
32
|
+
"@contractspec/integration.providers-impls": "1.59.0",
|
|
33
|
+
"@contractspec/lib.contracts": "1.59.0",
|
|
32
34
|
"googleapis": "^171.4.0"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
|
-
"@contractspec/tool.
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"typescript": "^5.9.3"
|
|
37
|
+
"@contractspec/tool.typescript": "1.59.0",
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"@contractspec/tool.bun": "1.58.0"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public",
|
|
42
43
|
"exports": {
|
|
43
|
-
".":
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"bun": "./dist/index.js",
|
|
47
|
+
"node": "./dist/node/index.mjs",
|
|
48
|
+
"browser": "./dist/browser/index.js",
|
|
49
|
+
"default": "./dist/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./docs": {
|
|
52
|
+
"types": "./dist/docs/index.d.ts",
|
|
53
|
+
"bun": "./dist/docs/index.js",
|
|
54
|
+
"node": "./dist/node/docs/index.mjs",
|
|
55
|
+
"browser": "./dist/browser/docs/index.js",
|
|
56
|
+
"default": "./dist/docs/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./docs/calendar-google.docblock": {
|
|
59
|
+
"types": "./dist/docs/calendar-google.docblock.d.ts",
|
|
60
|
+
"bun": "./dist/docs/calendar-google.docblock.js",
|
|
61
|
+
"node": "./dist/node/docs/calendar-google.docblock.mjs",
|
|
62
|
+
"browser": "./dist/browser/docs/calendar-google.docblock.js",
|
|
63
|
+
"default": "./dist/docs/calendar-google.docblock.js"
|
|
64
|
+
},
|
|
65
|
+
"./docs/index": {
|
|
66
|
+
"types": "./dist/docs/index.d.ts",
|
|
67
|
+
"bun": "./dist/docs/index.js",
|
|
68
|
+
"node": "./dist/node/docs/index.mjs",
|
|
69
|
+
"browser": "./dist/browser/docs/index.js",
|
|
70
|
+
"default": "./dist/docs/index.js"
|
|
71
|
+
},
|
|
72
|
+
"./example": {
|
|
73
|
+
"types": "./dist/example.d.ts",
|
|
74
|
+
"bun": "./dist/example.js",
|
|
75
|
+
"node": "./dist/node/example.mjs",
|
|
76
|
+
"browser": "./dist/browser/example.js",
|
|
77
|
+
"default": "./dist/example.js"
|
|
78
|
+
},
|
|
79
|
+
"./run": {
|
|
80
|
+
"types": "./dist/run.d.ts",
|
|
81
|
+
"bun": "./dist/run.js",
|
|
82
|
+
"node": "./dist/node/run.mjs",
|
|
83
|
+
"browser": "./dist/browser/run.js",
|
|
84
|
+
"default": "./dist/run.js"
|
|
85
|
+
},
|
|
86
|
+
"./sync": {
|
|
87
|
+
"types": "./dist/sync.d.ts",
|
|
88
|
+
"bun": "./dist/sync.js",
|
|
89
|
+
"node": "./dist/node/sync.mjs",
|
|
90
|
+
"browser": "./dist/browser/sync.js",
|
|
91
|
+
"default": "./dist/sync.js"
|
|
92
|
+
}
|
|
50
93
|
},
|
|
51
94
|
"registry": "https://registry.npmjs.org/"
|
|
52
95
|
},
|
package/tsdown.config.js
CHANGED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
$ tsdown
|
|
2
|
-
[34mℹ[39m tsdown [2mv0.20.3[22m powered by rolldown [2mv1.0.0-rc.3[22m
|
|
3
|
-
[34mℹ[39m config file: [4m/home/runner/work/contractspec/contractspec/packages/examples/calendar-google/tsdown.config.js[24m
|
|
4
|
-
[34mℹ[39m entry: [34msrc/example.ts, src/index.ts, src/run.ts, src/sync.ts, src/docs/calendar-google.docblock.ts, src/docs/index.ts[39m
|
|
5
|
-
[34mℹ[39m target: [34mesnext[39m
|
|
6
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
7
|
-
[34mℹ[39m Build start
|
|
8
|
-
[34mℹ[39m Cleaning 19 files
|
|
9
|
-
[34mℹ[39m [2mdist/[22m[1msync.js[22m [2m2.97 kB[22m [2m│ gzip: 1.25 kB[22m
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[1mdocs/calendar-google.docblock.js[22m [2m1.62 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
11
|
-
[34mℹ[39m [2mdist/[22m[1mexample.js[22m [2m0.96 kB[22m [2m│ gzip: 0.49 kB[22m
|
|
12
|
-
[34mℹ[39m [2mdist/[22m[1mrun.js[22m [2m0.28 kB[22m [2m│ gzip: 0.22 kB[22m
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[1mindex.js[22m [2m0.28 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
14
|
-
[34mℹ[39m [2mdist/[22m[1mdocs/index.js[22m [2m0.04 kB[22m [2m│ gzip: 0.06 kB[22m
|
|
15
|
-
[34mℹ[39m [2mdist/[22msync.js.map [2m5.05 kB[22m [2m│ gzip: 1.98 kB[22m
|
|
16
|
-
[34mℹ[39m [2mdist/[22mdocs/calendar-google.docblock.js.map [2m2.13 kB[22m [2m│ gzip: 0.98 kB[22m
|
|
17
|
-
[34mℹ[39m [2mdist/[22mexample.js.map [2m1.43 kB[22m [2m│ gzip: 0.69 kB[22m
|
|
18
|
-
[34mℹ[39m [2mdist/[22mrun.js.map [2m0.49 kB[22m [2m│ gzip: 0.33 kB[22m
|
|
19
|
-
[34mℹ[39m [2mdist/[22msync.d.ts.map [2m0.34 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
20
|
-
[34mℹ[39m [2mdist/[22mexample.d.ts.map [2m0.13 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
21
|
-
[34mℹ[39m [2mdist/[22m[32m[1msync.d.ts[22m[39m [2m0.78 kB[22m [2m│ gzip: 0.33 kB[22m
|
|
22
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m0.29 kB[22m [2m│ gzip: 0.15 kB[22m
|
|
23
|
-
[34mℹ[39m [2mdist/[22m[32m[1mexample.d.ts[22m[39m [2m0.25 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
24
|
-
[34mℹ[39m [2mdist/[22m[32m[1mdocs/calendar-google.docblock.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
25
|
-
[34mℹ[39m [2mdist/[22m[32m[1mdocs/index.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
26
|
-
[34mℹ[39m [2mdist/[22m[32m[1mrun.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
27
|
-
[34mℹ[39m 18 files, total: 17.06 kB
|
|
28
|
-
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in plugins. Here is a breakdown:
|
|
29
|
-
- rolldown-plugin-dts:generate (60%)
|
|
30
|
-
- tsdown:external (40%)
|
|
31
|
-
See https://rolldown.rs/options/checks#plugintimings for more details.
|
|
32
|
-
|
|
33
|
-
[32m✔[39m Build complete in [32m46144ms[39m
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calendar-google.docblock.js","names":[],"sources":["../../src/docs/calendar-google.docblock.ts"],"sourcesContent":["import type { DocBlock } from '@contractspec/lib.contracts/docs';\nimport { registerDocBlocks } from '@contractspec/lib.contracts/docs';\n\nconst blocks: DocBlock[] = [\n {\n id: 'docs.examples.calendar-google',\n title: 'Google Calendar (example)',\n summary: 'List upcoming events and create a new event via Google Calendar.',\n kind: 'reference',\n visibility: 'public',\n route: '/docs/examples/calendar-google',\n tags: ['calendar', 'google-calendar', 'example'],\n body: `## What this example shows\n- Create a Google OAuth client from env vars.\n- List upcoming events with time bounds.\n- Create a new event with attendees and reminders.\n\n## Guardrails\n- Keep refresh tokens in secrets.\n- Use dry-run when validating payloads.\n- Limit maxResults for quick previews.`,\n },\n {\n id: 'docs.examples.calendar-google.usage',\n title: 'Google Calendar - Usage',\n summary: 'How to run the calendar sync with env-driven settings.',\n kind: 'usage',\n visibility: 'public',\n route: '/docs/examples/calendar-google/usage',\n tags: ['calendar', 'usage'],\n body: `## Usage\n- Set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_REFRESH_TOKEN.\n- Optionally set GOOGLE_CALENDAR_ID (defaults to primary).\n- Run the sync script to create a sample event.\n\n## Refresh token\n- Open https://developers.google.com/oauthplayground.\n- Enable \"Use your own OAuth credentials\" and enter client ID/secret.\n- Authorize https://www.googleapis.com/auth/calendar and exchange tokens.\n- Copy the refresh token into GOOGLE_REFRESH_TOKEN.\n\n## Example\n- Call runCalendarSyncFromEnv() from run.ts to execute the flow.`,\n },\n];\n\nregisterDocBlocks(blocks);\n"],"mappings":";;;AA8CA,kBA3C2B,CACzB;CACE,IAAI;CACJ,OAAO;CACP,SAAS;CACT,MAAM;CACN,YAAY;CACZ,OAAO;CACP,MAAM;EAAC;EAAY;EAAmB;EAAU;CAChD,MAAM;;;;;;;;;CASP,EACD;CACE,IAAI;CACJ,OAAO;CACP,SAAS;CACT,MAAM;CACN,YAAY;CACZ,OAAO;CACP,MAAM,CAAC,YAAY,QAAQ;CAC3B,MAAM;;;;;;;;;;;;;CAaP,CACF,CAEwB"}
|