@doist/todoist-api-typescript 6.2.0 → 6.3.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENDPOINT_WORKSPACE_USERS = exports.ENDPOINT_WORKSPACE_PLAN_DETAILS = exports.ENDPOINT_WORKSPACE_LOGO = exports.ENDPOINT_WORKSPACE_JOIN = exports.ENDPOINT_WORKSPACE_INVITATIONS_DELETE = exports.ENDPOINT_WORKSPACE_INVITATIONS_ALL = exports.ENDPOINT_WORKSPACE_INVITATIONS = exports.ENDPOINT_REVOKE = exports.ENDPOINT_REVOKE_TOKEN = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.PROJECT_UNARCHIVE = exports.PROJECT_ARCHIVE = exports.ENDPOINT_REST_UPLOADS = exports.ENDPOINT_REST_ACTIVITIES = exports.ENDPOINT_REST_PRODUCTIVITY = exports.ENDPOINT_REST_USER = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASK_MOVE = exports.ENDPOINT_REST_TASK_REOPEN = exports.ENDPOINT_REST_TASK_CLOSE = exports.ENDPOINT_REST_COMMENTS = exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_TASKS_COMPLETED_SEARCH = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST_TASKS_FILTER = exports.ENDPOINT_REST_TASKS = exports.API_BASE_URI = exports.API_VERSION = exports.TODOIST_WEB_URI = void 0;
3
+ exports.ENDPOINT_WORKSPACE_USERS = exports.ENDPOINT_WORKSPACE_PLAN_DETAILS = exports.ENDPOINT_WORKSPACE_LOGO = exports.ENDPOINT_WORKSPACE_JOIN = exports.ENDPOINT_WORKSPACE_INVITATIONS_DELETE = exports.ENDPOINT_WORKSPACE_INVITATIONS_ALL = exports.ENDPOINT_WORKSPACE_INVITATIONS = exports.ENDPOINT_REVOKE = exports.ENDPOINT_REVOKE_TOKEN = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.PROJECT_UNARCHIVE = exports.PROJECT_ARCHIVE = exports.ENDPOINT_REST_UPLOADS = exports.ENDPOINT_REST_ACTIVITIES = exports.ENDPOINT_REST_PRODUCTIVITY = exports.ENDPOINT_REST_USER = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS_SEARCH = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASK_MOVE = exports.ENDPOINT_REST_TASK_REOPEN = exports.ENDPOINT_REST_TASK_CLOSE = exports.ENDPOINT_REST_COMMENTS = exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS_SEARCH = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS_SEARCH = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_TASKS_COMPLETED_SEARCH = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST_TASKS_FILTER = exports.ENDPOINT_REST_TASKS = exports.API_BASE_URI = exports.API_VERSION = exports.TODOIST_WEB_URI = void 0;
4
4
  exports.getSyncBaseUri = getSyncBaseUri;
5
5
  exports.getAuthBaseUri = getAuthBaseUri;
6
6
  exports.getWorkspaceInvitationAcceptEndpoint = getWorkspaceInvitationAcceptEndpoint;
@@ -27,7 +27,9 @@ exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST
27
27
  exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS + '/completed/by_due_date';
28
28
  exports.ENDPOINT_REST_TASKS_COMPLETED_SEARCH = 'completed/search';
29
29
  exports.ENDPOINT_REST_SECTIONS = 'sections';
30
+ exports.ENDPOINT_REST_SECTIONS_SEARCH = exports.ENDPOINT_REST_SECTIONS + '/search';
30
31
  exports.ENDPOINT_REST_LABELS = 'labels';
32
+ exports.ENDPOINT_REST_LABELS_SEARCH = exports.ENDPOINT_REST_LABELS + '/search';
31
33
  exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS + '/shared';
32
34
  exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED + '/rename';
33
35
  exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED + '/remove';
@@ -36,6 +38,7 @@ exports.ENDPOINT_REST_TASK_CLOSE = 'close';
36
38
  exports.ENDPOINT_REST_TASK_REOPEN = 'reopen';
37
39
  exports.ENDPOINT_REST_TASK_MOVE = 'move';
38
40
  exports.ENDPOINT_REST_PROJECTS = 'projects';
41
+ exports.ENDPOINT_REST_PROJECTS_SEARCH = exports.ENDPOINT_REST_PROJECTS + '/search';
39
42
  exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS + '/archived';
40
43
  exports.ENDPOINT_REST_PROJECT_COLLABORATORS = 'collaborators';
41
44
  exports.ENDPOINT_REST_USER = 'user';
@@ -406,6 +406,26 @@ class TodoistApi {
406
406
  nextCursor,
407
407
  };
408
408
  }
409
+ /**
410
+ * Searches projects by name.
411
+ *
412
+ * @param args - Search parameters including the query string.
413
+ * @returns A promise that resolves to a paginated response of projects.
414
+ */
415
+ async searchProjects(args) {
416
+ const { data: { results, nextCursor }, } = await (0, rest_client_1.request)({
417
+ httpMethod: 'GET',
418
+ baseUri: this.syncApiBase,
419
+ relativePath: endpoints_1.ENDPOINT_REST_PROJECTS_SEARCH,
420
+ apiToken: this.authToken,
421
+ customFetch: this.customFetch,
422
+ payload: args,
423
+ });
424
+ return {
425
+ results: (0, validators_1.validateProjectArray)(results),
426
+ nextCursor,
427
+ };
428
+ }
409
429
  /**
410
430
  * Retrieves all archived projects with optional filters.
411
431
  *
@@ -566,6 +586,26 @@ class TodoistApi {
566
586
  nextCursor,
567
587
  };
568
588
  }
589
+ /**
590
+ * Searches sections by name.
591
+ *
592
+ * @param args - Search parameters including the query string.
593
+ * @returns A promise that resolves to a paginated response of sections.
594
+ */
595
+ async searchSections(args) {
596
+ const { data: { results, nextCursor }, } = await (0, rest_client_1.request)({
597
+ httpMethod: 'GET',
598
+ baseUri: this.syncApiBase,
599
+ relativePath: endpoints_1.ENDPOINT_REST_SECTIONS_SEARCH,
600
+ apiToken: this.authToken,
601
+ customFetch: this.customFetch,
602
+ payload: args,
603
+ });
604
+ return {
605
+ results: (0, validators_1.validateSectionArray)(results),
606
+ nextCursor,
607
+ };
608
+ }
569
609
  /**
570
610
  * Retrieves a single section by its ID.
571
611
  *
@@ -679,6 +719,26 @@ class TodoistApi {
679
719
  nextCursor,
680
720
  };
681
721
  }
722
+ /**
723
+ * Searches labels by name.
724
+ *
725
+ * @param args - Search parameters including the query string.
726
+ * @returns A promise that resolves to a paginated response of labels.
727
+ */
728
+ async searchLabels(args) {
729
+ const { data: { results, nextCursor }, } = await (0, rest_client_1.request)({
730
+ httpMethod: 'GET',
731
+ baseUri: this.syncApiBase,
732
+ relativePath: endpoints_1.ENDPOINT_REST_LABELS_SEARCH,
733
+ apiToken: this.authToken,
734
+ customFetch: this.customFetch,
735
+ payload: args,
736
+ });
737
+ return {
738
+ results: (0, validators_1.validateLabelArray)(results),
739
+ nextCursor,
740
+ };
741
+ }
682
742
  /**
683
743
  * Adds a new label.
684
744
  *
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __rest = (this && this.__rest) || function (s, e) {
3
36
  var t = {};
4
37
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -12,7 +45,6 @@ var __rest = (this && this.__rest) || function (s, e) {
12
45
  };
13
46
  Object.defineProperty(exports, "__esModule", { value: true });
14
47
  exports.fetchWithRetry = fetchWithRetry;
15
- const undici_1 = require("undici");
16
48
  const http_1 = require("../types/http");
17
49
  /**
18
50
  * Default retry configuration matching the original axios-retry behavior
@@ -27,13 +59,32 @@ const DEFAULT_RETRY_CONFIG = {
27
59
  },
28
60
  };
29
61
  /**
30
- * HTTP agent with keepAlive disabled to prevent hanging connections
31
- * This ensures the process exits immediately after requests complete
62
+ * Cached HTTP agent to prevent creating multiple agents
63
+ * null = not initialized, undefined = browser env, UndiciAgent = Node.js env
32
64
  */
33
- const httpAgent = new undici_1.Agent({
34
- keepAliveTimeout: 1, // Close connections after 1ms of idle time
35
- keepAliveMaxTimeout: 1, // Maximum time to keep connections alive
36
- });
65
+ let httpAgent = null;
66
+ /**
67
+ * Gets the HTTP agent for Node.js environments or undefined for browser environments.
68
+ * Uses dynamic import to avoid loading undici in browser environments.
69
+ */
70
+ async function getHttpAgent() {
71
+ var _a;
72
+ if (httpAgent === null) {
73
+ if (typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
74
+ // We're in Node.js - dynamically import undici
75
+ const { Agent } = await Promise.resolve().then(() => __importStar(require('undici')));
76
+ httpAgent = new Agent({
77
+ keepAliveTimeout: 1, // Close connections after 1ms of idle time
78
+ keepAliveMaxTimeout: 1, // Maximum time to keep connections alive
79
+ });
80
+ }
81
+ else {
82
+ // We're in browser - no agent needed
83
+ httpAgent = undefined;
84
+ }
85
+ }
86
+ return httpAgent;
87
+ }
37
88
  /**
38
89
  * Converts Headers object to a plain object
39
90
  */
@@ -118,7 +169,7 @@ async function fetchWithRetry(args) {
118
169
  else {
119
170
  const nativeResponse = await fetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: requestSignal,
120
171
  // @ts-expect-error - dispatcher is a valid option for Node.js fetch but not in the TS types
121
- dispatcher: httpAgent }));
172
+ dispatcher: await getHttpAgent() }));
122
173
  fetchResponse = convertResponseToCustomFetch(nativeResponse);
123
174
  }
124
175
  // Check if the response is successful
@@ -18,7 +18,9 @@ export const ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = ENDPOINT_REST_TA
18
18
  export const ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = ENDPOINT_REST_TASKS + '/completed/by_due_date';
19
19
  export const ENDPOINT_REST_TASKS_COMPLETED_SEARCH = 'completed/search';
20
20
  export const ENDPOINT_REST_SECTIONS = 'sections';
21
+ export const ENDPOINT_REST_SECTIONS_SEARCH = ENDPOINT_REST_SECTIONS + '/search';
21
22
  export const ENDPOINT_REST_LABELS = 'labels';
23
+ export const ENDPOINT_REST_LABELS_SEARCH = ENDPOINT_REST_LABELS + '/search';
22
24
  export const ENDPOINT_REST_LABELS_SHARED = ENDPOINT_REST_LABELS + '/shared';
23
25
  export const ENDPOINT_REST_LABELS_SHARED_RENAME = ENDPOINT_REST_LABELS_SHARED + '/rename';
24
26
  export const ENDPOINT_REST_LABELS_SHARED_REMOVE = ENDPOINT_REST_LABELS_SHARED + '/remove';
@@ -27,6 +29,7 @@ export const ENDPOINT_REST_TASK_CLOSE = 'close';
27
29
  export const ENDPOINT_REST_TASK_REOPEN = 'reopen';
28
30
  export const ENDPOINT_REST_TASK_MOVE = 'move';
29
31
  export const ENDPOINT_REST_PROJECTS = 'projects';
32
+ export const ENDPOINT_REST_PROJECTS_SEARCH = ENDPOINT_REST_PROJECTS + '/search';
30
33
  export const ENDPOINT_REST_PROJECTS_ARCHIVED = ENDPOINT_REST_PROJECTS + '/archived';
31
34
  export const ENDPOINT_REST_PROJECT_COLLABORATORS = 'collaborators';
32
35
  export const ENDPOINT_REST_USER = 'user';
@@ -1,5 +1,5 @@
1
1
  import { request, isSuccess } from './rest-client.js';
2
- import { getSyncBaseUri, ENDPOINT_REST_TASKS, ENDPOINT_REST_TASKS_FILTER, ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE, ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE, ENDPOINT_REST_TASKS_COMPLETED_SEARCH, ENDPOINT_REST_PROJECTS, ENDPOINT_SYNC_QUICK_ADD, ENDPOINT_REST_TASK_CLOSE, ENDPOINT_REST_TASK_REOPEN, ENDPOINT_REST_TASK_MOVE, ENDPOINT_REST_LABELS, ENDPOINT_REST_PROJECT_COLLABORATORS, ENDPOINT_REST_SECTIONS, ENDPOINT_REST_COMMENTS, ENDPOINT_REST_LABELS_SHARED, ENDPOINT_REST_LABELS_SHARED_RENAME, ENDPOINT_REST_LABELS_SHARED_REMOVE, ENDPOINT_SYNC, PROJECT_ARCHIVE, PROJECT_UNARCHIVE, ENDPOINT_REST_PROJECTS_ARCHIVED, ENDPOINT_REST_USER, ENDPOINT_REST_PRODUCTIVITY, ENDPOINT_REST_ACTIVITIES, ENDPOINT_REST_UPLOADS, ENDPOINT_WORKSPACE_INVITATIONS, ENDPOINT_WORKSPACE_INVITATIONS_ALL, ENDPOINT_WORKSPACE_INVITATIONS_DELETE, getWorkspaceInvitationAcceptEndpoint, getWorkspaceInvitationRejectEndpoint, ENDPOINT_WORKSPACE_JOIN, ENDPOINT_WORKSPACE_LOGO, ENDPOINT_WORKSPACE_PLAN_DETAILS, ENDPOINT_WORKSPACE_USERS, getWorkspaceActiveProjectsEndpoint, getWorkspaceArchivedProjectsEndpoint, } from './consts/endpoints.js';
2
+ import { getSyncBaseUri, ENDPOINT_REST_TASKS, ENDPOINT_REST_TASKS_FILTER, ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE, ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE, ENDPOINT_REST_TASKS_COMPLETED_SEARCH, ENDPOINT_REST_PROJECTS, ENDPOINT_REST_PROJECTS_SEARCH, ENDPOINT_SYNC_QUICK_ADD, ENDPOINT_REST_TASK_CLOSE, ENDPOINT_REST_TASK_REOPEN, ENDPOINT_REST_TASK_MOVE, ENDPOINT_REST_LABELS, ENDPOINT_REST_LABELS_SEARCH, ENDPOINT_REST_PROJECT_COLLABORATORS, ENDPOINT_REST_SECTIONS, ENDPOINT_REST_SECTIONS_SEARCH, ENDPOINT_REST_COMMENTS, ENDPOINT_REST_LABELS_SHARED, ENDPOINT_REST_LABELS_SHARED_RENAME, ENDPOINT_REST_LABELS_SHARED_REMOVE, ENDPOINT_SYNC, PROJECT_ARCHIVE, PROJECT_UNARCHIVE, ENDPOINT_REST_PROJECTS_ARCHIVED, ENDPOINT_REST_USER, ENDPOINT_REST_PRODUCTIVITY, ENDPOINT_REST_ACTIVITIES, ENDPOINT_REST_UPLOADS, ENDPOINT_WORKSPACE_INVITATIONS, ENDPOINT_WORKSPACE_INVITATIONS_ALL, ENDPOINT_WORKSPACE_INVITATIONS_DELETE, getWorkspaceInvitationAcceptEndpoint, getWorkspaceInvitationRejectEndpoint, ENDPOINT_WORKSPACE_JOIN, ENDPOINT_WORKSPACE_LOGO, ENDPOINT_WORKSPACE_PLAN_DETAILS, ENDPOINT_WORKSPACE_USERS, getWorkspaceActiveProjectsEndpoint, getWorkspaceArchivedProjectsEndpoint, } from './consts/endpoints.js';
3
3
  import { validateAttachment, validateComment, validateCommentArray, validateCurrentUser, validateLabel, validateLabelArray, validateProject, validateProjectArray, validateSection, validateSectionArray, validateTask, validateTaskArray, validateUserArray, validateProductivityStats, validateActivityEventArray, validateWorkspaceUserArray, validateWorkspaceInvitation, validateWorkspaceInvitationArray, validateWorkspacePlanDetails, validateJoinWorkspaceResult, } from './utils/validators.js';
4
4
  import { formatDateToYYYYMMDD } from './utils/url-helpers.js';
5
5
  import { uploadMultipartFile } from './utils/multipart-upload.js';
@@ -403,6 +403,26 @@ export class TodoistApi {
403
403
  nextCursor,
404
404
  };
405
405
  }
406
+ /**
407
+ * Searches projects by name.
408
+ *
409
+ * @param args - Search parameters including the query string.
410
+ * @returns A promise that resolves to a paginated response of projects.
411
+ */
412
+ async searchProjects(args) {
413
+ const { data: { results, nextCursor }, } = await request({
414
+ httpMethod: 'GET',
415
+ baseUri: this.syncApiBase,
416
+ relativePath: ENDPOINT_REST_PROJECTS_SEARCH,
417
+ apiToken: this.authToken,
418
+ customFetch: this.customFetch,
419
+ payload: args,
420
+ });
421
+ return {
422
+ results: validateProjectArray(results),
423
+ nextCursor,
424
+ };
425
+ }
406
426
  /**
407
427
  * Retrieves all archived projects with optional filters.
408
428
  *
@@ -563,6 +583,26 @@ export class TodoistApi {
563
583
  nextCursor,
564
584
  };
565
585
  }
586
+ /**
587
+ * Searches sections by name.
588
+ *
589
+ * @param args - Search parameters including the query string.
590
+ * @returns A promise that resolves to a paginated response of sections.
591
+ */
592
+ async searchSections(args) {
593
+ const { data: { results, nextCursor }, } = await request({
594
+ httpMethod: 'GET',
595
+ baseUri: this.syncApiBase,
596
+ relativePath: ENDPOINT_REST_SECTIONS_SEARCH,
597
+ apiToken: this.authToken,
598
+ customFetch: this.customFetch,
599
+ payload: args,
600
+ });
601
+ return {
602
+ results: validateSectionArray(results),
603
+ nextCursor,
604
+ };
605
+ }
566
606
  /**
567
607
  * Retrieves a single section by its ID.
568
608
  *
@@ -676,6 +716,26 @@ export class TodoistApi {
676
716
  nextCursor,
677
717
  };
678
718
  }
719
+ /**
720
+ * Searches labels by name.
721
+ *
722
+ * @param args - Search parameters including the query string.
723
+ * @returns A promise that resolves to a paginated response of labels.
724
+ */
725
+ async searchLabels(args) {
726
+ const { data: { results, nextCursor }, } = await request({
727
+ httpMethod: 'GET',
728
+ baseUri: this.syncApiBase,
729
+ relativePath: ENDPOINT_REST_LABELS_SEARCH,
730
+ apiToken: this.authToken,
731
+ customFetch: this.customFetch,
732
+ payload: args,
733
+ });
734
+ return {
735
+ results: validateLabelArray(results),
736
+ nextCursor,
737
+ };
738
+ }
679
739
  /**
680
740
  * Adds a new label.
681
741
  *
@@ -9,7 +9,6 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { Agent } from 'undici';
13
12
  import { isNetworkError } from '../types/http.js';
14
13
  /**
15
14
  * Default retry configuration matching the original axios-retry behavior
@@ -24,13 +23,32 @@ const DEFAULT_RETRY_CONFIG = {
24
23
  },
25
24
  };
26
25
  /**
27
- * HTTP agent with keepAlive disabled to prevent hanging connections
28
- * This ensures the process exits immediately after requests complete
26
+ * Cached HTTP agent to prevent creating multiple agents
27
+ * null = not initialized, undefined = browser env, UndiciAgent = Node.js env
29
28
  */
30
- const httpAgent = new Agent({
31
- keepAliveTimeout: 1, // Close connections after 1ms of idle time
32
- keepAliveMaxTimeout: 1, // Maximum time to keep connections alive
33
- });
29
+ let httpAgent = null;
30
+ /**
31
+ * Gets the HTTP agent for Node.js environments or undefined for browser environments.
32
+ * Uses dynamic import to avoid loading undici in browser environments.
33
+ */
34
+ async function getHttpAgent() {
35
+ var _a;
36
+ if (httpAgent === null) {
37
+ if (typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
38
+ // We're in Node.js - dynamically import undici
39
+ const { Agent } = await import('undici');
40
+ httpAgent = new Agent({
41
+ keepAliveTimeout: 1, // Close connections after 1ms of idle time
42
+ keepAliveMaxTimeout: 1, // Maximum time to keep connections alive
43
+ });
44
+ }
45
+ else {
46
+ // We're in browser - no agent needed
47
+ httpAgent = undefined;
48
+ }
49
+ }
50
+ return httpAgent;
51
+ }
34
52
  /**
35
53
  * Converts Headers object to a plain object
36
54
  */
@@ -115,7 +133,7 @@ export async function fetchWithRetry(args) {
115
133
  else {
116
134
  const nativeResponse = await fetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: requestSignal,
117
135
  // @ts-expect-error - dispatcher is a valid option for Node.js fetch but not in the TS types
118
- dispatcher: httpAgent }));
136
+ dispatcher: await getHttpAgent() }));
119
137
  fetchResponse = convertResponseToCustomFetch(nativeResponse);
120
138
  }
121
139
  // Check if the response is successful
@@ -9,7 +9,9 @@ export declare const ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE: string;
9
9
  export declare const ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE: string;
10
10
  export declare const ENDPOINT_REST_TASKS_COMPLETED_SEARCH = "completed/search";
11
11
  export declare const ENDPOINT_REST_SECTIONS = "sections";
12
+ export declare const ENDPOINT_REST_SECTIONS_SEARCH: string;
12
13
  export declare const ENDPOINT_REST_LABELS = "labels";
14
+ export declare const ENDPOINT_REST_LABELS_SEARCH: string;
13
15
  export declare const ENDPOINT_REST_LABELS_SHARED: string;
14
16
  export declare const ENDPOINT_REST_LABELS_SHARED_RENAME: string;
15
17
  export declare const ENDPOINT_REST_LABELS_SHARED_REMOVE: string;
@@ -18,6 +20,7 @@ export declare const ENDPOINT_REST_TASK_CLOSE = "close";
18
20
  export declare const ENDPOINT_REST_TASK_REOPEN = "reopen";
19
21
  export declare const ENDPOINT_REST_TASK_MOVE = "move";
20
22
  export declare const ENDPOINT_REST_PROJECTS = "projects";
23
+ export declare const ENDPOINT_REST_PROJECTS_SEARCH: string;
21
24
  export declare const ENDPOINT_REST_PROJECTS_ARCHIVED: string;
22
25
  export declare const ENDPOINT_REST_PROJECT_COLLABORATORS = "collaborators";
23
26
  export declare const ENDPOINT_REST_USER = "user";
@@ -1,5 +1,5 @@
1
1
  import { Attachment, PersonalProject, WorkspaceProject, Label, Section, Comment, Task, CurrentUser, ProductivityStats, WorkspaceInvitation, WorkspacePlanDetails, JoinWorkspaceResult } from './types/entities.js';
2
- import { AddCommentArgs, AddLabelArgs, AddProjectArgs, AddSectionArgs, AddTaskArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, GetTasksByFilterArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, GetSharedLabelsArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs, GetProjectsArgs, GetProjectCollaboratorsArgs, GetLabelsArgs, GetLabelsResponse, GetTasksResponse, GetProjectsResponse, GetProjectCollaboratorsResponse, GetSectionsArgs, GetSectionsResponse, GetSharedLabelsResponse, GetCommentsResponse, type MoveTaskArgs, GetCompletedTasksByCompletionDateArgs, GetCompletedTasksByDueDateArgs, GetCompletedTasksResponse, GetArchivedProjectsArgs, GetArchivedProjectsResponse, SearchCompletedTasksArgs, GetActivityLogsArgs, GetActivityLogsResponse, UploadFileArgs, DeleteUploadArgs, GetWorkspaceInvitationsArgs, DeleteWorkspaceInvitationArgs, WorkspaceInvitationActionArgs, JoinWorkspaceArgs, WorkspaceLogoArgs, GetWorkspacePlanDetailsArgs, GetWorkspaceUsersArgs, GetWorkspaceUsersResponse, GetWorkspaceProjectsArgs, WorkspaceInvitationsResponse, AllWorkspaceInvitationsResponse, WorkspaceLogoResponse } from './types/requests.js';
2
+ import { AddCommentArgs, AddLabelArgs, AddProjectArgs, AddSectionArgs, AddTaskArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, GetTasksByFilterArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, GetSharedLabelsArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs, GetProjectsArgs, SearchProjectsArgs, GetProjectCollaboratorsArgs, GetLabelsArgs, SearchLabelsArgs, GetLabelsResponse, GetTasksResponse, GetProjectsResponse, GetProjectCollaboratorsResponse, GetSectionsArgs, SearchSectionsArgs, GetSectionsResponse, GetSharedLabelsResponse, GetCommentsResponse, type MoveTaskArgs, GetCompletedTasksByCompletionDateArgs, GetCompletedTasksByDueDateArgs, GetCompletedTasksResponse, GetArchivedProjectsArgs, GetArchivedProjectsResponse, SearchCompletedTasksArgs, GetActivityLogsArgs, GetActivityLogsResponse, UploadFileArgs, DeleteUploadArgs, GetWorkspaceInvitationsArgs, DeleteWorkspaceInvitationArgs, WorkspaceInvitationActionArgs, JoinWorkspaceArgs, WorkspaceLogoArgs, GetWorkspacePlanDetailsArgs, GetWorkspaceUsersArgs, GetWorkspaceUsersResponse, GetWorkspaceProjectsArgs, WorkspaceInvitationsResponse, AllWorkspaceInvitationsResponse, WorkspaceLogoResponse } from './types/requests.js';
3
3
  import { CustomFetch } from './types/http.js';
4
4
  /**
5
5
  * A client for interacting with the Todoist API v1.
@@ -174,6 +174,13 @@ export declare class TodoistApi {
174
174
  * @returns A promise that resolves to an array of projects.
175
175
  */
176
176
  getProjects(args?: GetProjectsArgs): Promise<GetProjectsResponse>;
177
+ /**
178
+ * Searches projects by name.
179
+ *
180
+ * @param args - Search parameters including the query string.
181
+ * @returns A promise that resolves to a paginated response of projects.
182
+ */
183
+ searchProjects(args: SearchProjectsArgs): Promise<GetProjectsResponse>;
177
184
  /**
178
185
  * Retrieves all archived projects with optional filters.
179
186
  *
@@ -238,6 +245,13 @@ export declare class TodoistApi {
238
245
  * @returns A promise that resolves to an array of sections.
239
246
  */
240
247
  getSections(args?: GetSectionsArgs): Promise<GetSectionsResponse>;
248
+ /**
249
+ * Searches sections by name.
250
+ *
251
+ * @param args - Search parameters including the query string.
252
+ * @returns A promise that resolves to a paginated response of sections.
253
+ */
254
+ searchSections(args: SearchSectionsArgs): Promise<GetSectionsResponse>;
241
255
  /**
242
256
  * Retrieves a single section by its ID.
243
257
  *
@@ -284,6 +298,13 @@ export declare class TodoistApi {
284
298
  * @returns A promise that resolves to an array of labels.
285
299
  */
286
300
  getLabels(args?: GetLabelsArgs): Promise<GetLabelsResponse>;
301
+ /**
302
+ * Searches labels by name.
303
+ *
304
+ * @param args - Search parameters including the query string.
305
+ * @returns A promise that resolves to a paginated response of labels.
306
+ */
307
+ searchLabels(args: SearchLabelsArgs): Promise<GetLabelsResponse>;
287
308
  /**
288
309
  * Adds a new label.
289
310
  *
@@ -160,6 +160,15 @@ export type GetProjectsArgs = {
160
160
  cursor?: string | null;
161
161
  limit?: number;
162
162
  };
163
+ /**
164
+ * Arguments for searching projects.
165
+ */
166
+ type SearchArgs = {
167
+ query: string;
168
+ cursor?: string | null;
169
+ limit?: number;
170
+ };
171
+ export type SearchProjectsArgs = SearchArgs;
163
172
  /**
164
173
  * Response from retrieving projects.
165
174
  * @see https://todoist.com/api/v1/docs#tag/Projects/operation/get_projects_api_v1_projects_get
@@ -230,6 +239,12 @@ export type GetSectionsArgs = {
230
239
  cursor?: string | null;
231
240
  limit?: number;
232
241
  };
242
+ /**
243
+ * Arguments for searching sections.
244
+ */
245
+ export type SearchSectionsArgs = SearchArgs & {
246
+ projectId?: string | null;
247
+ };
233
248
  /**
234
249
  * Response from retrieving sections.
235
250
  * @see https://todoist.com/api/v1/docs#tag/Sections/operation/get_sections_api_v1_sections_get
@@ -262,6 +277,10 @@ export type GetLabelsArgs = {
262
277
  cursor?: string | null;
263
278
  limit?: number;
264
279
  };
280
+ /**
281
+ * Arguments for searching labels.
282
+ */
283
+ export type SearchLabelsArgs = SearchArgs;
265
284
  /**
266
285
  * Response from retrieving labels.
267
286
  * @see https://todoist.com/api/v1/docs#tag/Labels/operation/get_labels_api_v1_labels_get
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/todoist-api-typescript",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "description": "A typescript wrapper for the Todoist REST API.",
5
5
  "author": "Doist developers",
6
6
  "repository": "https://github.com/Doist/todoist-api-typescript",