AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
fix(pieces): publishing a Google Calendar New Event trigger no longer times out (#15569)
Bartosz Majewski9af0f247c571
diff --git a/bun.lock b/bun.lockindex 0ec3f6107ae..d74907c0a6b 100644--- a/bun.lock+++ b/bun.lock@@ -3776,7 +3776,7 @@},"packages/pieces/community/google-calendar": {"name": "@activepieces/piece-google-calendar",- "version": "0.11.0",+ "version": "0.11.1","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",@@ -3788,6 +3788,7 @@},"devDependencies": {"tslib": "2.6.2",+ "vitest": "3.2.6",},},"packages/pieces/community/google-cloud-storage": {@@ -5124,7 +5125,7 @@},"packages/pieces/community/linear": {"name": "@activepieces/piece-linear",- "version": "0.6.0",+ "version": "0.6.1","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",diff --git a/packages/pieces/community/google-calendar/package.json b/packages/pieces/community/google-calendar/package.jsonindex 8c4b81c6d35..9f414bcea87 100644--- a/packages/pieces/community/google-calendar/package.json+++ b/packages/pieces/community/google-calendar/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/piece-google-calendar",- "version": "0.11.0",+ "version": "0.11.1","main": "./dist/src/index.js","types": "./dist/src/index.d.ts","dependencies": {@@ -13,11 +13,13 @@"@activepieces/core-utils": "workspace:*"},"devDependencies": {- "tslib": "2.6.2"+ "tslib": "2.6.2",+ "vitest": "3.2.6"},"scripts": {"build": "tsc -p tsconfig.lib.json && cp package.json dist/","bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",- "lint": "eslint 'src/**/*.ts'"+ "lint": "eslint 'src/**/*.ts'",+ "test": "vitest run"}}diff --git a/packages/pieces/community/google-calendar/src/lib/common/helper.test.ts b/packages/pieces/community/google-calendar/src/lib/common/helper.test.tsnew file mode 100644index 00000000000..6fe098e6e56--- /dev/null+++ b/packages/pieces/community/google-calendar/src/lib/common/helper.test.ts@@ -0,0 +1,89 @@+import { HttpRequest, httpClient } from '@activepieces/pieces-common';+import { AppConnectionType } from '@activepieces/pieces-framework';+import { afterEach, describe, expect, it, vi } from 'vitest';+import { getInitialSyncToken, listEventsWithSyncToken } from './helper';++const AUTH = {+ type: AppConnectionType.OAUTH2 as const,+ access_token: 'token-123',+ data: {},+};++const RESPONSE_SHAPING_PARAMS = ['syncToken', 'pageToken', 'fields'];++function stubHttpClient(bodies: unknown[]): Record<string, string>[] {+ const captured: Record<string, string>[] = [];+ vi.spyOn(httpClient, 'sendRequest').mockImplementation(+ async (request: HttpRequest) => {+ captured.push({ ...request.queryParams });+ return {+ status: 200,+ headers: {},+ body: bodies[captured.length - 1],+ };+ }+ );+ return captured;+}++function seriesFilters(params: Record<string, string>): string[] {+ return Object.keys(params)+ .filter((key) => !RESPONSE_SHAPING_PARAMS.includes(key))+ .sort();+}++afterEach(() => {+ vi.restoreAllMocks();+});++describe('getInitialSyncToken', () => {+ it('does not ask Google to expand recurring events into instances', async () => {+ const captured = stubHttpClient([{ items: [], nextSyncToken: 'sync-1' }]);++ await getInitialSyncToken({ calendarId: 'primary', authProp: AUTH });++ expect(captured[0]['singleEvents']).toBeUndefined();+ expect(captured[0]['showDeleted']).toBeUndefined();+ expect(captured[0]['maxResults']).toBe('2500');+ });++ it('sends the same series filters as the incremental call it seeds', async () => {+ const fullSync = stubHttpClient([{ items: [], nextSyncToken: 'sync-1' }]);+ await getInitialSyncToken({ calendarId: 'primary', authProp: AUTH });++ const incremental = stubHttpClient([{ items: [], nextSyncToken: 'sync-2' }]);+ await listEventsWithSyncToken({+ calendarId: 'primary',+ syncToken: 'sync-1',+ authProp: AUTH,+ });++ expect(seriesFilters(fullSync[0])).toEqual(seriesFilters(incremental[0]));+ });++ it('asks Google for the tokens only, never the event bodies it discards', async () => {+ const captured = stubHttpClient([{ nextSyncToken: 'sync-1' }]);++ await getInitialSyncToken({ calendarId: 'primary', authProp: AUTH });++ expect(captured[0]['fields']).toBe('nextPageToken,nextSyncToken');+ });++ it('pages until Google stops returning a page token and keeps the final sync token', async () => {+ const captured = stubHttpClient([+ { items: [{ id: 'a' }], nextPageToken: 'page-2' },+ { items: [{ id: 'b' }], nextPageToken: 'page-3' },+ { items: [{ id: 'c' }], nextSyncToken: 'sync-final' },+ ]);++ const token = await getInitialSyncToken({+ calendarId: 'primary',+ authProp: AUTH,+ });++ expect(token).toBe('sync-final');+ expect(captured).toHaveLength(3);+ expect(captured[1]['pageToken']).toBe('page-2');+ expect(captured[2]['pageToken']).toBe('page-3');+ });+});diff --git a/packages/pieces/community/google-calendar/src/lib/common/helper.ts b/packages/pieces/community/google-calendar/src/lib/common/helper.tsindex d8c25d16ef0..5906509bd91 100644--- a/packages/pieces/community/google-calendar/src/lib/common/helper.ts+++ b/packages/pieces/community/google-calendar/src/lib/common/helper.ts@@ -16,6 +16,10 @@ import {GetColorsResponse,} from './types';+const SYNC_SERIES_PARAMS: Record<string, string> = {+ maxResults: '2500',+};+export async function stopWatchEvent(body: GoogleWatchResponse,authProp: GoogleCalendarAuthValue@@ -70,9 +74,8 @@ export async function getInitialSyncToken({}): Promise<string | undefined> {const accessToken = await getAccessToken(authProp);const qParams: Record<string, string> = {- singleEvents: 'true',- showDeleted: 'true',- maxResults: '2500',+ ...SYNC_SERIES_PARAMS,+ fields: 'nextPageToken,nextSyncToken',};let pageToken = '';let nextSyncToken: string | undefined;@@ -113,8 +116,8 @@ export async function listEventsWithSyncToken({}> {const accessToken = await getAccessToken(authProp);const qParams: Record<string, string> = {+ ...SYNC_SERIES_PARAMS,syncToken,- maxResults: '2500',};let pageToken = '';let nextSyncToken: string | undefined;diff --git a/packages/pieces/community/google-calendar/vitest.config.ts b/packages/pieces/community/google-calendar/vitest.config.tsnew file mode 100644index 00000000000..ba8ade4a178--- /dev/null+++ b/packages/pieces/community/google-calendar/vitest.config.ts@@ -0,0 +1,17 @@+import path from 'path'+import { defineConfig } from 'vitest/config'++const repoRoot = path.resolve(__dirname, '../../../..')++export default defineConfig({+ test: {+ globals: true,+ environment: 'node',+ },+ resolve: {+ alias: {+ '@activepieces/pieces-framework': path.resolve(repoRoot, 'packages/pieces/framework/src/index.ts'),+ '@activepieces/pieces-common': path.resolve(repoRoot, 'packages/pieces/common/src/index.ts'),+ },+ },+})