Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

bump @googleapis/calendar to 19 and gmail to 21, pinning the OAuth2 contract they carry (#7372)

[._.]/ Adam Eivyf0d487923ce6
diff --git a/server/package-lock.json b/server/package-lock.json
index 46ec29cb5e..50c8bee609 100644
--- a/server/package-lock.json
+++ b/server/package-lock.json
@@ -9,8 +9,8 @@
"version": "1.7.1",
"dependencies": {
"@cantoo/pdf-lib": "2.9.2",
- "@googleapis/calendar": "16.0.0",
- "@googleapis/gmail": "18.0.0",
+ "@googleapis/calendar": "19.0.0",
+ "@googleapis/gmail": "21.0.0",
"@novnc/novnc": "1.7.0",
"chokidar": "5.0.0",
"express": "5.2.1",
@@ -158,27 +158,27 @@
}
},
"node_modules/@googleapis/calendar": {
- "version": "16.0.0",
- "resolved": "https://registry.npmjs.org/@googleapis/calendar/-/calendar-16.0.0.tgz",
- "integrity": "sha512-Z/8Jdf4hMvmMlBMhP0whZNPSixEpYv4mC5RJfrlvrnqpf/rV68MJ+8M9MmyqUt7/SQp2zRfVmEqkk+csB2Cgmg==",
+ "version": "19.0.0",
+ "resolved": "https://registry.npmjs.org/@googleapis/calendar/-/calendar-19.0.0.tgz",
+ "integrity": "sha512-IK8eQiTDUCmI43sHlAs7O/PpPphSPY40HDoW/L7byQdQ4Qq8E9FaVDB/HRBsvlLToS+yI4x3C90tR8HrFoHYWQ==",
"license": "Apache-2.0",
"dependencies": {
- "googleapis-common": "^8.0.0"
+ "googleapis-common": "^9.0.0"
},
"engines": {
- "node": ">=12.0.0"
+ "node": ">=22.0.0"
}
},
"node_modules/@googleapis/gmail": {
- "version": "18.0.0",
- "resolved": "https://registry.npmjs.org/@googleapis/gmail/-/gmail-18.0.0.tgz",
- "integrity": "sha512-qC8CaF3mgi8ZMm7IYK1Pk6AF3z2v1IE++8rtn+Mmpx+zIhbS9MMazY7+WicwgLKKskn5zQLXCoNv0Jn7OdFfPg==",
+ "version": "21.0.0",
+ "resolved": "https://registry.npmjs.org/@googleapis/gmail/-/gmail-21.0.0.tgz",
+ "integrity": "sha512-b9znRPY7U+McFYv2DhoA/Nq22B/q68vTlRA+EuOwPnmglhei74KUUKX3EPX3vYIxkgVcYN3iGN7tKan8g2Iz/g==",
"license": "Apache-2.0",
"dependencies": {
- "googleapis-common": "^8.0.0"
+ "googleapis-common": "^9.0.0"
},
"engines": {
- "node": ">=12.0.0"
+ "node": ">=22.0.0"
}
},
"node_modules/@img/colour": {
@@ -2281,9 +2281,9 @@
}
},
"node_modules/gaxios": {
- "version": "7.1.4",
- "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-7.1.4.tgz",
- "integrity": "sha512-bTIgTsM2bWn3XklZISBTQX7ZSddGW+IO3bMdGaemHZ3tbqExMENHLx6kKZ/KlejgrMtj8q7wBItt51yegqalrA==",
+ "version": "7.3.1",
+ "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-7.3.1.tgz",
+ "integrity": "sha512-kB3rzJV7d9juLZh8/56QTXCwQfxyhdOMdyYk1HdQKFtF8TJTDTZQJtixWIwXdE9Jji91mC41DUNpjleo4L4eAQ==",
"license": "Apache-2.0",
"dependencies": {
"extend": "^3.0.2",
@@ -2295,17 +2295,17 @@
}
},
"node_modules/gcp-metadata": {
- "version": "8.1.2",
- "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-8.1.2.tgz",
- "integrity": "sha512-zV/5HKTfCeKWnxG0Dmrw51hEWFGfcF2xiXqcA3+J90WDuP0SvoiSO5ORvcBsifmx/FoIjgQN3oNOGaQ5PhLFkg==",
+ "version": "9.0.3",
+ "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-9.0.3.tgz",
+ "integrity": "sha512-2YYnIlHaKBGT2IPg3G2M57hia9Galz15zsEOvw9T3oRf0lSn6KN6VcHQLqby7x8ksYKnjXvp3rp2KJyLCN6zfQ==",
"license": "Apache-2.0",
"dependencies": {
- "gaxios": "^7.0.0",
- "google-logging-utils": "^1.0.0",
+ "gaxios": "^7.1.3",
+ "google-logging-utils": "^2.0.0",
"json-bigint": "^1.0.0"
},
"engines": {
- "node": ">=18"
+ "node": ">=22"
}
},
"node_modules/get-intrinsic": {
@@ -2380,46 +2380,47 @@
"node": ">= 6"
}
},
+ "node_modules/google-auth-library": {
+ "version": "11.0.2",
+ "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-11.0.2.tgz",
+ "integrity": "sha512-vzpgPutxrghPsnjrjpzLX2bdv8IOL719Rh0oEjGnQu8YCIbnbMuTTQ5zU9LcKvLdOPgCxBwppbvnhgW90Qna5Q==",
+ "license": "Apache-2.0",
+ "dependencies": {
+ "base64-js": "^1.3.0",
+ "ecdsa-sig-formatter": "^1.0.11",
+ "gaxios": "^7.1.4",
+ "gcp-metadata": "^9.0.0",
+ "google-logging-utils": "^2.0.0",
+ "jws": "^4.0.0"
+ },
+ "engines": {
+ "node": ">=22"
+ }
+ },
"node_modules/google-logging-utils": {
- "version": "1.1.3",
- "resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-1.1.3.tgz",
- "integrity": "sha512-eAmLkjDjAFCVXg7A1unxHsLf961m6y17QFqXqAXGj/gVkKFrEICfStRfwUlGNfeCEjNRa32JEWOUTlYXPyyKvA==",
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-2.0.1.tgz",
+ "integrity": "sha512-HMhaQghlOTvbcb3c4T5jmmOMtG3JUF1iOQMezaJXL86CDS+Tm2vHd0IeLFRAx3+ewd+bo9E1HFHoy17X5aJa9A==",
"license": "Apache-2.0",
"engines": {
- "node": ">=14"
+ "node": ">=22"
}
},
"node_modules/googleapis-common": {
- "version": "8.0.1",
- "resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-8.0.1.tgz",
- "integrity": "sha512-eCzNACUXPb1PW5l0ULTzMHaL/ltPRADoPgjBlT8jWsTbxkCp6siv+qKJ/1ldaybCthGwsYFYallF7u9AkU4L+A==",
+ "version": "9.0.4",
+ "resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-9.0.4.tgz",
+ "integrity": "sha512-fcI5bm1gN+9MNb+gvANRPFsxaJ07h/ZYvKCh6H3RoDJBUTwp5ySaCpCqnmX8gnGJUD/9bKmkacivRJT1g+xXyg==",
"license": "Apache-2.0",
"dependencies": {
"extend": "^3.0.2",
- "gaxios": "^7.0.0-rc.4",
- "google-auth-library": "^10.1.0",
+ "gaxios": "^7.3.0",
+ "google-auth-library": "^11.0.0",
+ "google-logging-utils": "^2.0.0",
"qs": "^6.7.0",
"url-template": "^2.0.8"
},
"engines": {
- "node": ">=18.0.0"
- }
- },
- "node_modules/googleapis-common/node_modules/google-auth-library": {
- "version": "10.9.1",
- "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-10.9.1.tgz",
- "integrity": "sha512-i1ydyHrqcIxXkWh/uBmVkzCvIuq5yiK2ATndIe5XxKholrG/MTYP9xGYka4sQhrbIAgGjL2B6NOE7rFaiF3fXw==",
- "license": "Apache-2.0",
- "dependencies": {
- "base64-js": "^1.3.0",
- "ecdsa-sig-formatter": "^1.0.11",
- "gaxios": "^7.1.4",
- "gcp-metadata": "8.1.2",
- "google-logging-utils": "1.1.3",
- "jws": "^4.0.0"
- },
- "engines": {
- "node": ">=18"
+ "node": ">=22"
}
},
"node_modules/gopd": {
diff --git a/server/package.json b/server/package.json
index 18758a917e..5fa58cc7e0 100644
--- a/server/package.json
+++ b/server/package.json
@@ -22,8 +22,8 @@
},
"dependencies": {
"@cantoo/pdf-lib": "2.9.2",
- "@googleapis/calendar": "16.0.0",
- "@googleapis/gmail": "18.0.0",
+ "@googleapis/calendar": "19.0.0",
+ "@googleapis/gmail": "21.0.0",
"@novnc/novnc": "1.7.0",
"chokidar": "5.0.0",
"express": "5.2.1",
diff --git a/server/services/googleAuth.test.js b/server/services/googleAuth.test.js
new file mode 100644
index 0000000000..c3f5bf8d6e
--- /dev/null
+++ b/server/services/googleAuth.test.js
@@ -0,0 +1,190 @@
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import { createServer } from 'node:http';
+
+// `@googleapis/calendar` re-exports google-auth-library's OAuth2 client, and
+// googleAuth.js builds its whole token lifecycle on it: construct with
+// (clientId, clientSecret, redirectUri), seed with setCredentials(), subscribe
+// to the 'tokens' event, and let the client refresh an expired access token on
+// its own. Every one of those is library behavior a @googleapis major can move
+// under us — and the refresh is the one path that only runs against a real
+// expired token, so the suites that mock the Google client cannot see it break.
+//
+// These tests drive the REAL client against a loopback token endpoint, so a
+// dependency bump that changes refresh, credential merging, or the event
+// contract fails here instead of in production on the next token expiry.
+// Added with the @googleapis/calendar 16→19 + gmail 18→21 bump, which carried
+// google-auth-library 10→11 (#7372).
+
+vi.mock('../lib/fileUtils.js', () => ({
+ PATHS: { calendar: '/test/calendar' },
+ ensureDir: vi.fn(async () => {}),
+ tryReadFile: vi.fn(),
+ atomicWrite: vi.fn(async () => {}),
+}));
+
+import { auth } from '@googleapis/calendar';
+import { atomicWrite, tryReadFile } from '../lib/fileUtils.js';
+import { clearAuth, getAuthenticatedClient, handleCallback } from './googleAuth.js';
+
+const CREDENTIALS = { clientId: 'test-client-id', clientSecret: 'test-secret', redirectUri: 'http://localhost:5555/cb' };
+const REFRESHED = { access_token: 'refreshed-access', expires_in: 3600, scope: 'https://www.googleapis.com/auth/calendar', token_type: 'Bearer' };
+
+let server;
+let tokenUrl;
+let requestBodies;
+
+/** Files googleAuth.js reads by path; anything else is absent. */
+function stubFiles({ credentials = CREDENTIALS, tokens }) {
+ tryReadFile.mockImplementation(async (file) => {
+ if (file.endsWith('credentials.json')) return credentials ? JSON.stringify(credentials) : null;
+ if (file.endsWith('tokens.json')) return tokens ? JSON.stringify(tokens) : null;
+ return null;
+ });
+}
+
+const expiredTokens = () => ({ access_token: 'stale-access', refresh_token: 'durable-refresh', expiry_date: Date.now() - 60_000, scope: 'https://www.googleapis.com/auth/calendar' });
+
+/**
+ * Redirect one client's token endpoint at the loopback server. Asserts the knob
+ * still exists first: without it the refresh below would leave the machine for
+ * Google's real endpoint, turning a contract break into a confusing network
+ * failure. A major that renames it should fail HERE, saying so.
+ */
+function redirectTokenEndpoint(client) {
+ expect(typeof client.endpoints?.oauth2TokenUrl).toBe('string');
+ client.endpoints.oauth2TokenUrl = tokenUrl;
+}
+
+/** The write googleAuth.js makes for the tokens file, or undefined. */
+const lastTokenWrite = () => atomicWrite.mock.calls.filter(([file]) => file.endsWith('tokens.json')).at(-1)?.[1];
+
+beforeEach(async () => {
+ requestBodies = [];
+ server = createServer((req, res) => {
+ let body = '';
+ req.on('data', (chunk) => { body += chunk; });
+ req.on('end', () => {
+ requestBodies.push(body);
+ res.writeHead(200, { 'content-type': 'application/json' });
+ res.end(JSON.stringify(REFRESHED));
+ });
+ });
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
+ tokenUrl = `http://127.0.0.1:${server.address().port}/token`;
+
+ stubFiles({ tokens: null });
+ await clearAuth(); // drop the module-level client cached by a prior test
+ vi.clearAllMocks();
+});
+
+afterEach(async () => {
+ // gaxios holds the refresh connection open; close() alone would wait on it.
+ server.closeAllConnections();
+ await new Promise((resolve) => server.close(resolve));
+ vi.restoreAllMocks();
+});
+
+describe('googleAuth OAuth2 client contract', () => {
+ it('destructures auth.OAuth2 as a constructor', () => {
+ expect(typeof auth.OAuth2).toBe('function');
+ const client = new auth.OAuth2(CREDENTIALS.clientId, CREDENTIALS.clientSecret, CREDENTIALS.redirectUri);
+ expect(client.credentials).toEqual({});
+ });
+
+ it('generates a consent URL carrying the offline/consent/state options getAuthUrl passes', () => {
+ const client = new auth.OAuth2(CREDENTIALS.clientId, CREDENTIALS.clientSecret, CREDENTIALS.redirectUri);
+ const url = client.generateAuthUrl({
+ access_type: 'offline',
+ prompt: 'consent',
+ scope: ['https://www.googleapis.com/auth/calendar'],
+ state: 'messages',
+ });
+ expect(url).toContain('access_type=offline');
+ expect(url).toContain('prompt=consent');
+ // The callback is shared by Calendar and Messages; the state is what routes
+ // the user back to the tab they started from.
+ expect(url).toContain('state=messages');
+ });
+
+ it('returns null until both credentials and an access token exist', async () => {
+ stubFiles({ credentials: null, tokens: expiredTokens() });
+ expect(await getAuthenticatedClient()).toBeNull();
+
+ stubFiles({ tokens: null });
+ await clearAuth();
+ expect(await getAuthenticatedClient()).toBeNull();
+ });
+});
+
+describe('googleAuth token refresh', () => {
+ it('refreshes an expired access token and persists it without losing the refresh token', async () => {
+ stubFiles({ tokens: expiredTokens() });
+ const client = await getAuthenticatedClient();
+ redirectTokenEndpoint(client);
+
+ const { token } = await client.getAccessToken();
+
+ expect(token).toBe(REFRESHED.access_token);
+ expect(client.credentials.access_token).toBe(REFRESHED.access_token);
+ // The refresh response carries no refresh token of its own; the client
+ // re-attaches the one it was seeded with. Losing it would strand the
+ // install on a silent re-authorization prompt.
+ expect(client.credentials.refresh_token).toBe('durable-refresh');
+ expect(client.credentials.expiry_date).toBeGreaterThan(Date.now());
+ expect(requestBodies).toHaveLength(1);
+ expect(requestBodies[0]).toContain('grant_type=refresh_token');
+ expect(requestBodies[0]).toContain('refresh_token=durable-refresh');
+
+ await vi.waitFor(() => expect(lastTokenWrite()).toBeDefined());
+ expect(lastTokenWrite()).toMatchObject({
+ access_token: REFRESHED.access_token,
+ refresh_token: 'durable-refresh',
+ });
+ });
+
+ it('keeps the stored refresh token when the refresh payload omits it', async () => {
+ stubFiles({ tokens: expiredTokens() });
+ const client = await getAuthenticatedClient();
+
+ // A token endpoint is not obliged to echo the refresh token back, and the
+ // client only re-attaches it as a convenience. Persistence must merge over
+ // what is already on disk rather than trust the payload to be complete —
+ // writing the bare payload would strand the install on a re-auth prompt at
+ // the next expiry.
+ client.emit('tokens', { access_token: 'rotated-access', expiry_date: Date.now() + 3_600_000 });
+
+ await vi.waitFor(() => expect(lastTokenWrite()).toBeDefined());
+ expect(lastTokenWrite()).toMatchObject({
+ access_token: 'rotated-access',
+ refresh_token: 'durable-refresh',
+ });
+ });
+
+ it('serves an unexpired token from the client without re-hitting the token endpoint', async () => {
+ stubFiles({ tokens: { access_token: 'live-access', refresh_token: 'durable-refresh', expiry_date: Date.now() + 3_600_000 } });
+ const client = await getAuthenticatedClient();
+ redirectTokenEndpoint(client);
+
+ const { token } = await client.getAccessToken();
+
+ expect(token).toBe('live-access');
+ expect(requestBodies).toHaveLength(0);
+ });
+});
+
+describe('googleAuth callback', () => {
+ it('stores the exchanged tokens and leaves the client authorized', async () => {
+ stubFiles({ tokens: null });
+ const exchange = vi.spyOn(auth.OAuth2.prototype, 'getToken')
+ .mockResolvedValue({ tokens: { access_token: 'fresh-access', refresh_token: 'fresh-refresh', expiry_date: Date.now() + 3_600_000 } });
+
+ const result = await handleCallback('auth-code');
+
+ expect(result).toEqual({ success: true });
+ expect(exchange).toHaveBeenCalledWith('auth-code');
+ expect(lastTokenWrite()).toMatchObject({ access_token: 'fresh-access', refresh_token: 'fresh-refresh' });
+
+ stubFiles({ tokens: { access_token: 'fresh-access', refresh_token: 'fresh-refresh', expiry_date: Date.now() + 3_600_000 } });
+ expect((await getAuthenticatedClient()).credentials.access_token).toBe('fresh-access');
+ });
+});