@doist/todoist-api-typescript 7.5.0 → 7.6.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.
@@ -5,6 +5,7 @@ exports.getAuthStateParameter = getAuthStateParameter;
5
5
  exports.getAuthorizationUrl = getAuthorizationUrl;
6
6
  exports.getAuthToken = getAuthToken;
7
7
  exports.revokeToken = revokeToken;
8
+ exports.migratePersonalToken = migratePersonalToken;
8
9
  const http_client_1 = require("./transport/http-client");
9
10
  const uuid_1 = require("uuid");
10
11
  const types_1 = require("./types");
@@ -58,7 +59,7 @@ function getAuthStateParameter() {
58
59
  * ```
59
60
  *
60
61
  * @returns The full authorization URL to redirect users to
61
- * @see https://todoist.com/api/v1/docs#tag/Authorization/OAuth
62
+ * @see https://developer.todoist.com/api/v1/#tag/Authorization/OAuth
62
63
  */
63
64
  function getAuthorizationUrl({ clientId, permissions, state, baseUrl, }) {
64
65
  if (!(permissions === null || permissions === void 0 ? void 0 : permissions.length)) {
@@ -126,7 +127,7 @@ async function getAuthToken(args, options) {
126
127
  *
127
128
  * @returns True if revocation was successful
128
129
  * @see https://datatracker.ietf.org/doc/html/rfc7009
129
- * @see https://todoist.com/api/v1/docs#tag/Authorization
130
+ * @see https://developer.todoist.com/api/v1/#tag/Authorization
130
131
  */
131
132
  async function revokeToken(args, options) {
132
133
  if (typeof options === 'string') {
@@ -158,3 +159,46 @@ async function revokeToken(args, options) {
158
159
  });
159
160
  return (0, http_client_1.isSuccess)(response);
160
161
  }
162
+ /**
163
+ * Migrates a personal API token to an OAuth access token.
164
+ *
165
+ * This allows applications to transition users from personal API tokens
166
+ * to proper OAuth tokens without requiring the user to go through the
167
+ * full OAuth authorization flow.
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const { accessToken } = await migratePersonalToken({
172
+ * clientId: 'your-client-id',
173
+ * clientSecret: 'your-client-secret',
174
+ * personalToken: 'user-personal-token',
175
+ * scope: 'data:read_write,data:delete'
176
+ * })
177
+ * ```
178
+ *
179
+ * @returns The new OAuth token response
180
+ * @throws {@link TodoistRequestError} If the migration fails
181
+ */
182
+ async function migratePersonalToken(args, options) {
183
+ var _a;
184
+ const baseUrl = options === null || options === void 0 ? void 0 : options.baseUrl;
185
+ const customFetch = options === null || options === void 0 ? void 0 : options.customFetch;
186
+ try {
187
+ const response = await (0, http_client_1.request)({
188
+ httpMethod: 'POST',
189
+ baseUri: (0, endpoints_1.getSyncBaseUri)(baseUrl),
190
+ relativePath: endpoints_1.ENDPOINT_REST_ACCESS_TOKENS_MIGRATE,
191
+ apiToken: undefined,
192
+ payload: Object.assign(Object.assign({}, args), { scope: args.scope.join(',') }),
193
+ customFetch,
194
+ });
195
+ if (response.status !== 200 || !((_a = response.data) === null || _a === void 0 ? void 0 : _a.accessToken)) {
196
+ throw new types_1.TodoistRequestError('Personal token migration failed.', response.status, response.data);
197
+ }
198
+ return response.data;
199
+ }
200
+ catch (error) {
201
+ const err = error;
202
+ throw new types_1.TodoistRequestError('Personal token migration failed.', err.httpStatusCode, err.responseData);
203
+ }
204
+ }
@@ -1,11 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENDPOINT_WORKSPACE_LOGO = exports.ENDPOINT_WORKSPACE_JOIN = exports.ENDPOINT_WORKSPACE_INVITATIONS_DELETE = exports.ENDPOINT_WORKSPACE_INVITATIONS_ALL = exports.ENDPOINT_WORKSPACE_INVITATIONS = exports.ENDPOINT_REST_WORKSPACES = exports.ENDPOINT_REVOKE = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL = exports.ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE = exports.SECTION_UNARCHIVE = exports.SECTION_ARCHIVE = exports.ENDPOINT_REST_PROJECT_JOIN = exports.ENDPOINT_REST_PROJECT_FULL = exports.ENDPOINT_REST_PROJECTS_PERMISSIONS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED_COUNT = 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_LOCATION_REMINDERS = exports.ENDPOINT_REST_REMINDERS = 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
- exports.ENDPOINT_WORKSPACE_USERS = exports.ENDPOINT_WORKSPACE_PLAN_DETAILS = void 0;
3
+ exports.ENDPOINT_REST_ID_MAPPINGS = exports.ENDPOINT_REST_EMAILS = exports.ENDPOINT_REST_BACKUPS_DOWNLOAD = exports.ENDPOINT_REST_BACKUPS = exports.ENDPOINT_REST_ACCESS_TOKENS_MIGRATE = exports.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_ID = exports.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_FILE = exports.ENDPOINT_REST_TEMPLATES_CREATE_FROM_FILE = exports.ENDPOINT_REST_TEMPLATES_URL = exports.ENDPOINT_REST_TEMPLATES_FILE = exports.ENDPOINT_REST_TASKS_COMPLETED = exports.ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL = exports.ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE = exports.SECTION_UNARCHIVE = exports.SECTION_ARCHIVE = exports.ENDPOINT_REST_PROJECT_JOIN = exports.ENDPOINT_REST_PROJECT_FULL = exports.ENDPOINT_REST_PROJECTS_PERMISSIONS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED_COUNT = 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_LOCATION_REMINDERS = exports.ENDPOINT_REST_REMINDERS = 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
+ exports.ENDPOINT_WORKSPACE_MEMBERS = 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_REST_WORKSPACES = exports.ENDPOINT_REVOKE = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_MOVED_IDS = void 0;
5
5
  exports.getSyncBaseUri = getSyncBaseUri;
6
6
  exports.getAuthBaseUri = getAuthBaseUri;
7
7
  exports.getWorkspaceInvitationAcceptEndpoint = getWorkspaceInvitationAcceptEndpoint;
8
8
  exports.getWorkspaceInvitationRejectEndpoint = getWorkspaceInvitationRejectEndpoint;
9
+ exports.getProjectInsightsActivityStatsEndpoint = getProjectInsightsActivityStatsEndpoint;
10
+ exports.getProjectInsightsHealthEndpoint = getProjectInsightsHealthEndpoint;
11
+ exports.getProjectInsightsHealthContextEndpoint = getProjectInsightsHealthContextEndpoint;
12
+ exports.getProjectInsightsProgressEndpoint = getProjectInsightsProgressEndpoint;
13
+ exports.getProjectInsightsHealthAnalyzeEndpoint = getProjectInsightsHealthAnalyzeEndpoint;
14
+ exports.getWorkspaceInsightsEndpoint = getWorkspaceInsightsEndpoint;
15
+ exports.getWorkspaceUserTasksEndpoint = getWorkspaceUserTasksEndpoint;
16
+ exports.getWorkspaceInviteUsersEndpoint = getWorkspaceInviteUsersEndpoint;
17
+ exports.getWorkspaceUserEndpoint = getWorkspaceUserEndpoint;
9
18
  exports.getWorkspaceActiveProjectsEndpoint = getWorkspaceActiveProjectsEndpoint;
10
19
  exports.getWorkspaceArchivedProjectsEndpoint = getWorkspaceArchivedProjectsEndpoint;
11
20
  const BASE_URI = 'https://api.todoist.com';
@@ -58,6 +67,18 @@ exports.SECTION_ARCHIVE = 'archive';
58
67
  exports.SECTION_UNARCHIVE = 'unarchive';
59
68
  exports.ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE = exports.ENDPOINT_REST_PROJECTS + '/move_to_workspace';
60
69
  exports.ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL = exports.ENDPOINT_REST_PROJECTS + '/move_to_personal';
70
+ exports.ENDPOINT_REST_TASKS_COMPLETED = exports.ENDPOINT_REST_TASKS + '/completed';
71
+ exports.ENDPOINT_REST_TEMPLATES_FILE = 'templates/file';
72
+ exports.ENDPOINT_REST_TEMPLATES_URL = 'templates/url';
73
+ exports.ENDPOINT_REST_TEMPLATES_CREATE_FROM_FILE = 'templates/create_project_from_file';
74
+ exports.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_FILE = 'templates/import_into_project_from_file';
75
+ exports.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_ID = 'templates/import_into_project_from_template_id';
76
+ exports.ENDPOINT_REST_ACCESS_TOKENS_MIGRATE = 'access_tokens/migrate_personal_token';
77
+ exports.ENDPOINT_REST_BACKUPS = 'backups';
78
+ exports.ENDPOINT_REST_BACKUPS_DOWNLOAD = 'backups/download';
79
+ exports.ENDPOINT_REST_EMAILS = 'emails';
80
+ exports.ENDPOINT_REST_ID_MAPPINGS = 'id_mappings';
81
+ exports.ENDPOINT_REST_MOVED_IDS = 'moved_ids';
61
82
  exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_TASKS + '/quick';
62
83
  exports.ENDPOINT_SYNC = 'sync';
63
84
  exports.ENDPOINT_AUTHORIZATION = 'authorize';
@@ -79,6 +100,37 @@ function getWorkspaceInvitationAcceptEndpoint(inviteCode) {
79
100
  function getWorkspaceInvitationRejectEndpoint(inviteCode) {
80
101
  return `workspaces/invitations/${inviteCode}/reject`;
81
102
  }
103
+ // Insights endpoints
104
+ function getProjectInsightsActivityStatsEndpoint(projectId) {
105
+ return `projects/${projectId}/insights/activity_stats`;
106
+ }
107
+ function getProjectInsightsHealthEndpoint(projectId) {
108
+ return `projects/${projectId}/insights/health`;
109
+ }
110
+ function getProjectInsightsHealthContextEndpoint(projectId) {
111
+ return `projects/${projectId}/insights/health/context`;
112
+ }
113
+ function getProjectInsightsProgressEndpoint(projectId) {
114
+ return `projects/${projectId}/insights/progress`;
115
+ }
116
+ function getProjectInsightsHealthAnalyzeEndpoint(projectId) {
117
+ return `projects/${projectId}/insights/health/analyze`;
118
+ }
119
+ function getWorkspaceInsightsEndpoint(workspaceId) {
120
+ return `workspaces/${workspaceId}/insights`;
121
+ }
122
+ // Workspace members
123
+ exports.ENDPOINT_WORKSPACE_MEMBERS = 'workspaces/members';
124
+ // Workspace user management (require workspace_id and/or user_id parameters)
125
+ function getWorkspaceUserTasksEndpoint(workspaceId, userId) {
126
+ return `workspaces/${workspaceId}/users/${userId}/tasks`;
127
+ }
128
+ function getWorkspaceInviteUsersEndpoint(workspaceId) {
129
+ return `workspaces/${workspaceId}/users/invite`;
130
+ }
131
+ function getWorkspaceUserEndpoint(workspaceId, userId) {
132
+ return `workspaces/${workspaceId}/users/${userId}`;
133
+ }
82
134
  // Workspace projects (require workspace_id parameter)
83
135
  function getWorkspaceActiveProjectsEndpoint(workspaceId) {
84
136
  return `workspaces/${workspaceId}/projects/active`;