Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Unreleased

- Fix: the project dropdown reads the next page of projects when you click "Load more". Before, it showed the first 100 projects again, so a project after the first 100 never showed.
- Fix: the AI agent, project template and project member dropdowns show more than the first page of rows.
- Fix: Find Project searches all of your projects, not only the first 100.
- Each list reads at most 20 pages, so a bad API response cannot make it ask for pages forever.

## 1.3.0

- New triggers (instant, Taskade Pro plan or higher): New Comment, Task Assigned, New Project, Project Assigned, Member Joined Project.
Expand Down
4 changes: 4 additions & 0 deletions packages/n8n-nodes-taskade/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Fix: a list call reads at most 100 pages (10,000 rows). Before, a response that ignored `page` or `after` made Return All and the member and template dropdowns ask for pages forever.

## 1.0.1

- No change to the node. This release is the first one from GitHub Actions through npm trusted publishing (OIDC), with no npm token.
Expand Down
30 changes: 21 additions & 9 deletions packages/n8n-nodes-taskade/nodes/Taskade/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ export async function taskadeApiRequest(
}

/**
* Collects every item of a cursor-paginated v2 list (`listTasks`), or stops at `limit`.
* The cursor is the ID of the last item on the previous page.
* The most pages that one list call reads (10,000 rows at 100 rows a page).
* A response that ignores `page` or `after` returns the same full page every
* time, and this bound stops the loop.
*/
export const MAX_PAGES = 100;

/**
* Collects every item of a cursor-paginated v2 list (`listTasks`), or stops at `limit`
* or after MAX_PAGES pages. The cursor is the ID of the last item on the previous page.
*/
export async function taskadeApiRequestCursorItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
Expand All @@ -85,25 +92,29 @@ export async function taskadeApiRequestCursorItems(
const items: IDataObject[] = [];
let after: string | undefined;

for (;;) {
for (let page = 1; page <= MAX_PAGES; page++) {
const response = await taskadeApiRequest.call(this, endpoint, {
...body,
limit: pageSize,
...(after === undefined ? {} : { after }),
});
const page = (response.items as IDataObject[] | undefined) ?? [];
items.push(...page);
const pageItems = (response.items as IDataObject[] | undefined) ?? [];
items.push(...pageItems);
if (limit !== undefined && items.length >= limit) {
return items.slice(0, limit);
}
if (page.length < pageSize) {
if (pageItems.length < pageSize) {
return items;
}
after = String(page[page.length - 1].id);
after = String(pageItems[pageItems.length - 1].id);
}
return items;
}

/** Collects every item of a page-numbered v2 list (`listMyProjects`, `listTemplates`), or stops at `limit`. */
/**
* Collects every item of a page-numbered v2 list (`listMyProjects`, `listTemplates`),
* or stops at `limit` or after MAX_PAGES pages.
*/
export async function taskadeApiRequestPagedItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
endpoint: string,
Expand All @@ -113,7 +124,7 @@ export async function taskadeApiRequestPagedItems(
const pageSize = 100;
const items: IDataObject[] = [];

for (let page = 1; ; page++) {
for (let page = 1; page <= MAX_PAGES; page++) {
const response = await taskadeApiRequest.call(this, endpoint, {
...body,
limit: pageSize,
Expand All @@ -128,6 +139,7 @@ export async function taskadeApiRequestPagedItems(
return items;
}
}
return items;
}

/** Sends a numeric string as a number, because number fields reject a string value. */
Expand Down
33 changes: 33 additions & 0 deletions packages/n8n-nodes-taskade/test/Taskade.node.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IDataObject, IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-workflow';
import { describe, expect, it } from 'vitest';

import { MAX_PAGES } from '../nodes/Taskade/GenericFunctions';
import { Taskade, toTaskadeDate } from '../nodes/Taskade/Taskade.node';
import { createContext } from './helpers';

Expand Down Expand Up @@ -299,6 +300,38 @@ describe('list search', () => {
});
});

describe('page bound', () => {
// An API that ignores `page` and `after` returns the same full page every
// time. The fake API throws after 1,000 calls, so a loop without a bound
// fails this test instead of running forever.
const fullPageForever = () => {
let count = 0;
return () => {
count += 1;
if (count > 1000) {
throw new Error('runaway loop: more than 1,000 requests');
}
return { ok: true, items: Array.from({ length: 100 }, (_, n) => ({ id: `r${n}`, handle: `u${n}` })) };
};
};

it('stops Get Many tasks with Return All at MAX_PAGES when the API ignores the cursor', async () => {
const { output, calls } = await run(
{ resource: 'task', operation: 'getMany', projectId: 'p1', returnAll: true },
fullPageForever(),
);
expect(calls).toHaveLength(MAX_PAGES);
expect(output).toHaveLength(MAX_PAGES * 100);
});

it('stops the project member list at MAX_PAGES when the API ignores the page', async () => {
const context = createContext({ authentication: 'accessToken', projectId: 'p1' }, fullPageForever());
await node.methods.loadOptions.getProjectMembers.call(context as unknown as ILoadOptionsFunctions);
expect(context.calls).toHaveLength(MAX_PAGES);
expect(context.calls.at(-1)?.body?.page).toBe(MAX_PAGES);
});
});

describe('toTaskadeDate', () => {
it('keeps only the date for all-day values', () => {
expect(toTaskadeDate('2026-10-09T15:30:00', true, 'UTC')).toEqual({ date: '2026-10-09' });
Expand Down
45 changes: 45 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { Bundle, ZObject } from 'zapier-platform-core';
export const BASE_V1 = 'https://www.taskade.com/api/v1';
export const BASE_V2 = 'https://www.taskade.com/api/v2';

/** Rows to ask for on each page of a page-numbered list. It is the default of `GET /me/projects`. */
export const PAGE_SIZE = 100;

/**
* The most pages that the app reads from one page-numbered list (2,000 rows at
* PAGE_SIZE). A response that ignores the `page` parameter returns the same
* full page every time, and this bound stops the app from asking forever.
*/
export const MAX_PAGES = 20;

export interface ApiResponse {
ok?: boolean;
message?: string;
Expand Down Expand Up @@ -40,6 +50,41 @@ export const request = async (z: ZObject, bundle: Bundle, opts: RequestOptions)
});
};

/**
* Turns the dropdown page that Zapier sends (`bundle.meta.page`, 0 for the
* first page) into the `page` (1 for the first page) and `limit` parameters of
* a page-numbered Taskade list. Returns null at MAX_PAGES and after it, so the
* caller returns no rows and Zapier stops asking for more.
*/
export const dropdownPageParams = (bundle: Bundle): { limit: string; page: string } | null => {
const page = Number(bundle.meta?.page ?? 0);
if (!Number.isInteger(page) || page < 0 || page >= MAX_PAGES) {
return null;
}
return { limit: String(PAGE_SIZE), page: String(page + 1) };
};

/**
* Reads every page of a page-numbered Taskade list. It stops at the first page
* with fewer than PAGE_SIZE rows, or after MAX_PAGES pages.
*/
export const listAllPages = async (z: ZObject, bundle: Bundle, path: string) => {
const items: Array<Record<string, unknown>> = [];
for (let page = 1; page <= MAX_PAGES; page++) {
const response = await request(z, bundle, {
method: 'GET',
path,
params: { limit: String(PAGE_SIZE), page: String(page) },
});
const pageItems = parseOk(z, response.json).items ?? [];
items.push(...pageItems);
Comment on lines +72 to +80
if (pageItems.length < PAGE_SIZE) {
break;
}
}
return items;
};

/** Throws the Taskade error message when the API returns `{ ok: false }`, else returns the body. */
export const parseOk = (z: ZObject, data: ApiResponse): ApiResponse => {
if (data && data.ok === false) {
Expand Down
17 changes: 12 additions & 5 deletions src/searches/findProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bundle, ZObject } from 'zapier-platform-core';

import { ApiResponse, parseOk, request } from '../client';
import { ApiResponse, listAllPages, parseOk, request } from '../client';
import { spaceField } from '../fields';

const perform = async (z: ZObject, bundle: Bundle) => {
Expand All @@ -9,13 +9,20 @@ const perform = async (z: ZObject, bundle: Bundle) => {
? `/folders/${bundle.inputData.space_id}/projects`
: '/me/projects';

// Best-effort: widen the page size; matching is client-side over the result set.
const response = await request(z, bundle, { method: 'GET', path, params: { limit: '100' } });
// The match runs here, over the projects that the API returns. GET /me/projects
// is page-numbered, so read each page. GET /folders/{folderId}/projects takes no page parameter.
let projects: Array<Record<string, unknown>>;
if (bundle.inputData.space_id != null) {
const response = await request(z, bundle, { method: 'GET', path, params: { limit: '100' } });
const data: ApiResponse = parseOk(z, response.json);
projects = data.items ?? [];
} else {
projects = await listAllPages(z, bundle, path);
}

const data: ApiResponse = parseOk(z, response.json);
const query = String(bundle.inputData.query ?? '').toLowerCase();

return (data.items ?? [])
return projects
.filter((project) =>
String(project.name ?? project.title ?? '')
.toLowerCase()
Expand Down
153 changes: 153 additions & 0 deletions src/test/pagination.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { Bundle, ZObject } from 'zapier-platform-core';

import { MAX_PAGES } from '../client';
import FindProject from '../searches/findProject';
import GetAllAgents from '../triggers/getAllAgents';
import GetAllAssignableMembers from '../triggers/getAllAssignableMembers';
import GetAllProjects from '../triggers/getAllProjects';
import GetAllProjectTemplates from '../triggers/getAllProjectTemplates';

// A stand-in for the Taskade API. It pages a list of `total` rows with the
// `page` and `limit` query parameters, the same way that the public API does.
// `defaultLimit` is the page size that the API uses when no `limit` is sent.
// With `ignorePage`, it returns the first page for every request, which is the
// bad response that the page bound protects against.

interface FakeRequest {
url: string;
method: string;
params?: Record<string, string | undefined>;
}

const pagedZ = (total: number, options: { defaultLimit?: number; ignorePage?: boolean } = {}) => {
const rows = Array.from({ length: total }, (_, index) => ({
id: `id-${index + 1}`,
name: `Row ${index + 1}`,
handle: `user${index + 1}`,
displayName: `User ${index + 1}`,
}));
const calls: FakeRequest[] = [];
const z = {
request: async (request: FakeRequest) => {
calls.push(request);
const limit = Number(request.params?.limit ?? options.defaultLimit ?? 100);
const page = options.ignorePage ? 1 : Number(request.params?.page ?? 1);
const items = rows.slice((page - 1) * limit, page * limit);
return { status: 200, json: { ok: true, items } };
},
errors: { Error: class extends Error {} },
} as unknown as ZObject;
return { z, calls };
};

const bundleFor = (inputData: Record<string, unknown>, page?: number) =>
({
authData: { access_token: 'token' },
inputData,
meta: page === undefined ? {} : { page },
}) as unknown as Bundle;

const ids = (rows: Array<{ id: string }>) => rows.map((row) => row.id);

describe('dropdown: get_all_projects without a folder', () => {
it('shows the projects after the first 100 when Zapier asks for the next page', async () => {
const { z } = pagedZ(150);
const first = await GetAllProjects.operation.perform(z, bundleFor({}, 0));
const second = await GetAllProjects.operation.perform(z, bundleFor({}, 1));
expect(first).toHaveLength(100);
expect(ids(second)).toEqual(Array.from({ length: 50 }, (_, index) => `id-${index + 101}`));
});

it('sends the page and limit parameters of GET /me/projects', async () => {
const { z, calls } = pagedZ(150);
await GetAllProjects.operation.perform(z, bundleFor({}, 1));
expect(calls[0].url).toBe('https://www.taskade.com/api/v1/me/projects');
expect(calls[0].params).toEqual({ limit: '100', page: '2' });
});

it('returns no rows after the last page', async () => {
const { z } = pagedZ(150);
expect(await GetAllProjects.operation.perform(z, bundleFor({}, 2))).toEqual([]);
});

it('stops at the page bound when the API ignores the page parameter', async () => {
const { z, calls } = pagedZ(150, { ignorePage: true });
expect(await GetAllProjects.operation.perform(z, bundleFor({}, MAX_PAGES))).toEqual([]);
expect(calls).toHaveLength(0);
});
});

describe('dropdown: get_all_projects in a folder', () => {
it('lists the folder projects on the first page', async () => {
const { z, calls } = pagedZ(3);
const result = await GetAllProjects.operation.perform(z, bundleFor({ space_id: 'folder-1' }, 0));
expect(ids(result)).toEqual(['id-1', 'id-2', 'id-3']);
expect(calls[0].url).toBe('https://www.taskade.com/api/v1/folders/folder-1/projects');
});

it('does not repeat the folder projects when Zapier asks for the next page', async () => {
// GET /folders/{folderId}/projects takes no page parameter, so one request returns every row.
const { z, calls } = pagedZ(3);
expect(await GetAllProjects.operation.perform(z, bundleFor({ space_id: 'folder-1' }, 1))).toEqual([]);
expect(calls).toHaveLength(0);
});
});

describe('search: find_project without a folder', () => {
it('finds a project that is after the first 100', async () => {
const { z } = pagedZ(150);
const result = await FindProject.operation.perform(z, bundleFor({ query: 'Row 130' }));
expect(result).toEqual([{ id: 'id-130', name: 'Row 130' }]);
});

it('reads at most the page bound when the API ignores the page parameter', async () => {
const { z, calls } = pagedZ(150, { ignorePage: true });
expect(await FindProject.operation.perform(z, bundleFor({ query: 'no match' }))).toEqual([]);
expect(calls).toHaveLength(MAX_PAGES);
});
});

describe('dropdowns on other page-numbered lists', () => {
it('get_all_agents shows the second page', async () => {
const { z, calls } = pagedZ(130, { defaultLimit: 20 });
const result = await GetAllAgents.operation.perform(z, bundleFor({ space_id: 'folder-1' }, 1));
expect(ids(result)).toEqual(Array.from({ length: 30 }, (_, index) => `id-${index + 101}`));
expect(calls[0].params).toEqual({ limit: '100', page: '2' });
});

it('get_all_project_templates shows more than the 20 rows of the default page', async () => {
const { z } = pagedZ(30, { defaultLimit: 20 });
const result = await GetAllProjectTemplates.operation.perform(z, bundleFor({ space_id: 'folder-1' }, 0));
expect(result).toHaveLength(30);
});

it('get_all_assignable_members shows more than the 20 rows of the default page', async () => {
const { z, calls } = pagedZ(30, { defaultLimit: 20 });
const result = await GetAllAssignableMembers.operation.perform(z, bundleFor({ project_id: 'project-1' }, 0));
expect(result).toHaveLength(30);
expect(calls[0].url).toBe('https://www.taskade.com/api/v1/projects/project-1/members');
});

it('every page-numbered dropdown tells Zapier that it can load more rows', () => {
for (const trigger of [GetAllProjects, GetAllAgents, GetAllProjectTemplates, GetAllAssignableMembers]) {
const { canPaginate } = trigger.operation as { canPaginate?: boolean };
expect({ key: trigger.key, canPaginate }).toEqual({
key: trigger.key,
canPaginate: true,
});
}
});

it('every page-numbered dropdown stops at the page bound', async () => {
const triggers = [
{ trigger: GetAllAgents, inputData: { space_id: 'folder-1' } },
{ trigger: GetAllProjectTemplates, inputData: { space_id: 'folder-1' } },
{ trigger: GetAllAssignableMembers, inputData: { project_id: 'project-1' } },
];
for (const { trigger, inputData } of triggers) {
const { z, calls } = pagedZ(150, { ignorePage: true });
expect(await trigger.operation.perform(z, bundleFor(inputData, MAX_PAGES))).toEqual([]);
expect(calls).toHaveLength(0);
}
});
});
Loading
Loading