@doist/todoist-api-typescript 5.9.0 → 6.0.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.
- package/dist/cjs/authentication.js +158 -0
- package/dist/{consts → cjs/consts}/endpoints.js +10 -12
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/rest-client.js +124 -0
- package/dist/{test-utils → cjs/test-utils}/asserts.js +1 -1
- package/dist/{test-utils → cjs/test-utils}/mocks.js +8 -4
- package/dist/cjs/test-utils/msw-setup.js +27 -0
- package/dist/{test-utils → cjs/test-utils}/test-defaults.js +41 -52
- package/dist/cjs/todoist-api.js +1235 -0
- package/dist/{types → cjs/types}/entities.js +19 -30
- package/dist/cjs/types/errors.js +22 -0
- package/dist/cjs/types/http.js +22 -0
- package/dist/cjs/utils/case-conversion.js +69 -0
- package/dist/{utils → cjs/utils}/colors.js +3 -3
- package/dist/cjs/utils/fetch-with-retry.js +150 -0
- package/dist/cjs/utils/multipart-upload.js +126 -0
- package/dist/{utils → cjs/utils}/processing-helpers.js +3 -3
- package/dist/{utils → cjs/utils}/sanitization.js +17 -28
- package/dist/{utils → cjs/utils}/url-helpers.js +15 -15
- package/dist/{utils → cjs/utils}/validators.js +2 -2
- package/dist/esm/authentication.js +151 -0
- package/dist/esm/consts/endpoints.js +65 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/rest-client.js +119 -0
- package/dist/esm/test-utils/asserts.js +8 -0
- package/dist/esm/test-utils/mocks.js +10 -0
- package/dist/esm/test-utils/msw-setup.js +22 -0
- package/dist/esm/test-utils/test-defaults.js +198 -0
- package/dist/esm/todoist-api.js +1231 -0
- package/dist/esm/types/entities.js +366 -0
- package/dist/esm/types/errors.js +18 -0
- package/dist/esm/types/http.js +18 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/requests.js +1 -0
- package/dist/esm/types/sync.js +1 -0
- package/dist/esm/utils/activity-helpers.js +36 -0
- package/dist/esm/utils/case-conversion.js +61 -0
- package/dist/esm/utils/colors.js +215 -0
- package/dist/esm/utils/fetch-with-retry.js +147 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/multipart-upload.js +120 -0
- package/dist/esm/utils/processing-helpers.js +12 -0
- package/dist/esm/utils/sanitization.js +112 -0
- package/dist/esm/utils/url-helpers.js +68 -0
- package/dist/esm/utils/validators.js +97 -0
- package/dist/{authentication.d.ts → types/authentication.d.ts} +6 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/{rest-client.d.ts → types/rest-client.d.ts} +3 -4
- package/dist/types/test-utils/msw-setup.d.ts +3 -0
- package/dist/types/types/http.d.ts +68 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/utils/case-conversion.d.ts +12 -0
- package/dist/types/utils/fetch-with-retry.d.ts +11 -0
- package/package.json +24 -8
- package/dist/authentication.js +0 -220
- package/dist/index.d.ts +0 -4
- package/dist/rest-client.js +0 -178
- package/dist/todoist-api.js +0 -1845
- package/dist/types/errors.js +0 -39
- package/dist/types/http.d.ts +0 -1
- package/dist/types/http.js +0 -2
- package/dist/utils/multipart-upload.js +0 -171
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{types → cjs/types}/index.js +0 -0
- /package/dist/{types → cjs/types}/requests.js +0 -0
- /package/dist/{types → cjs/types}/sync.js +0 -0
- /package/dist/{utils → cjs/utils}/activity-helpers.js +0 -0
- /package/dist/{utils → cjs/utils}/index.js +0 -0
- /package/dist/{consts → types/consts}/endpoints.d.ts +0 -0
- /package/dist/{test-utils → types/test-utils}/asserts.d.ts +0 -0
- /package/dist/{test-utils → types/test-utils}/mocks.d.ts +0 -0
- /package/dist/{test-utils → types/test-utils}/test-defaults.d.ts +0 -0
- /package/dist/{todoist-api.d.ts → types/todoist-api.d.ts} +0 -0
- /package/dist/types/{entities.d.ts → types/entities.d.ts} +0 -0
- /package/dist/types/{errors.d.ts → types/errors.d.ts} +0 -0
- /package/dist/types/{requests.d.ts → types/requests.d.ts} +0 -0
- /package/dist/types/{sync.d.ts → types/sync.d.ts} +0 -0
- /package/dist/{utils → types/utils}/activity-helpers.d.ts +0 -0
- /package/dist/{utils → types/utils}/colors.d.ts +0 -0
- /package/dist/{utils → types/utils}/index.d.ts +0 -0
- /package/dist/{utils → types/utils}/multipart-upload.d.ts +0 -0
- /package/dist/{utils → types/utils}/processing-helpers.d.ts +0 -0
- /package/dist/{utils → types/utils}/sanitization.d.ts +0 -0
- /package/dist/{utils → types/utils}/url-helpers.d.ts +0 -0
- /package/dist/{utils → types/utils}/validators.d.ts +0 -0
package/dist/types/errors.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TodoistRequestError = void 0;
|
|
19
|
-
var ts_custom_error_1 = require("ts-custom-error");
|
|
20
|
-
var authenticationErrorCodes = [401, 403];
|
|
21
|
-
var TodoistRequestError = /** @class */ (function (_super) {
|
|
22
|
-
__extends(TodoistRequestError, _super);
|
|
23
|
-
function TodoistRequestError(message, httpStatusCode, responseData) {
|
|
24
|
-
var _this = _super.call(this, message) || this;
|
|
25
|
-
_this.message = message;
|
|
26
|
-
_this.httpStatusCode = httpStatusCode;
|
|
27
|
-
_this.responseData = responseData;
|
|
28
|
-
_this.isAuthenticationError = function () {
|
|
29
|
-
if (!_this.httpStatusCode) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
return authenticationErrorCodes.includes(_this.httpStatusCode);
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(_this, 'name', { value: 'TodoistRequestError' });
|
|
35
|
-
return _this;
|
|
36
|
-
}
|
|
37
|
-
return TodoistRequestError;
|
|
38
|
-
}(ts_custom_error_1.CustomError));
|
|
39
|
-
exports.TodoistRequestError = TodoistRequestError;
|
package/dist/types/http.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type HttpMethod = 'POST' | 'GET' | 'DELETE' | 'PUT';
|
package/dist/types/http.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.uploadMultipartFile = uploadMultipartFile;
|
|
54
|
-
var form_data_1 = __importDefault(require("form-data"));
|
|
55
|
-
var fs_1 = require("fs");
|
|
56
|
-
var path_1 = require("path");
|
|
57
|
-
var axios_1 = __importDefault(require("axios"));
|
|
58
|
-
/**
|
|
59
|
-
* Helper function to determine content-type from filename extension.
|
|
60
|
-
* @param fileName - The filename to analyze
|
|
61
|
-
* @returns The appropriate MIME type
|
|
62
|
-
*/
|
|
63
|
-
function getContentTypeFromFileName(fileName) {
|
|
64
|
-
var extension = fileName.toLowerCase().split('.').pop();
|
|
65
|
-
switch (extension) {
|
|
66
|
-
case 'png':
|
|
67
|
-
return 'image/png';
|
|
68
|
-
case 'jpg':
|
|
69
|
-
case 'jpeg':
|
|
70
|
-
return 'image/jpeg';
|
|
71
|
-
case 'gif':
|
|
72
|
-
return 'image/gif';
|
|
73
|
-
case 'webp':
|
|
74
|
-
return 'image/webp';
|
|
75
|
-
case 'svg':
|
|
76
|
-
return 'image/svg+xml';
|
|
77
|
-
default:
|
|
78
|
-
return 'application/octet-stream';
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Uploads a file using multipart/form-data.
|
|
83
|
-
*
|
|
84
|
-
* This is a shared utility for uploading files to Todoist endpoints that require
|
|
85
|
-
* multipart/form-data content type (e.g., file uploads, workspace logo uploads).
|
|
86
|
-
*
|
|
87
|
-
* @param baseUrl - The base API URL (e.g., https://api.todoist.com/api/v1/)
|
|
88
|
-
* @param authToken - The authentication token
|
|
89
|
-
* @param endpoint - The relative endpoint path (e.g., 'uploads', 'workspaces/logo')
|
|
90
|
-
* @param file - The file content (Buffer, ReadableStream, or file system path)
|
|
91
|
-
* @param fileName - Optional file name (required for Buffer/Stream, optional for paths)
|
|
92
|
-
* @param additionalFields - Additional form fields to include (e.g., project_id, workspace_id)
|
|
93
|
-
* @param requestId - Optional request ID for idempotency
|
|
94
|
-
* @returns The response data from the server
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
* // Upload from a file path
|
|
99
|
-
* const result = await uploadMultipartFile(
|
|
100
|
-
* 'https://api.todoist.com/api/v1/',
|
|
101
|
-
* 'my-token',
|
|
102
|
-
* 'uploads',
|
|
103
|
-
* '/path/to/file.pdf',
|
|
104
|
-
* undefined,
|
|
105
|
-
* { project_id: '12345' }
|
|
106
|
-
* )
|
|
107
|
-
*
|
|
108
|
-
* // Upload from a Buffer
|
|
109
|
-
* const buffer = Buffer.from('file content')
|
|
110
|
-
* const result = await uploadMultipartFile(
|
|
111
|
-
* 'https://api.todoist.com/api/v1/',
|
|
112
|
-
* 'my-token',
|
|
113
|
-
* 'uploads',
|
|
114
|
-
* buffer,
|
|
115
|
-
* 'document.pdf',
|
|
116
|
-
* { project_id: '12345' }
|
|
117
|
-
* )
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
function uploadMultipartFile(args) {
|
|
121
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
-
var baseUrl, authToken, endpoint, file, fileName, additionalFields, requestId, form, filePath, resolvedFileName, contentType, _i, _a, _b, key, value, url, headers, response;
|
|
123
|
-
return __generator(this, function (_c) {
|
|
124
|
-
switch (_c.label) {
|
|
125
|
-
case 0:
|
|
126
|
-
baseUrl = args.baseUrl, authToken = args.authToken, endpoint = args.endpoint, file = args.file, fileName = args.fileName, additionalFields = args.additionalFields, requestId = args.requestId;
|
|
127
|
-
form = new form_data_1.default();
|
|
128
|
-
// Determine file type and add to form data
|
|
129
|
-
if (typeof file === 'string') {
|
|
130
|
-
filePath = file;
|
|
131
|
-
resolvedFileName = fileName || (0, path_1.basename)(filePath);
|
|
132
|
-
form.append('file', (0, fs_1.createReadStream)(filePath), resolvedFileName);
|
|
133
|
-
}
|
|
134
|
-
else if (Buffer.isBuffer(file)) {
|
|
135
|
-
// Buffer - require fileName
|
|
136
|
-
if (!fileName) {
|
|
137
|
-
throw new Error('fileName is required when uploading from a Buffer');
|
|
138
|
-
}
|
|
139
|
-
contentType = getContentTypeFromFileName(fileName);
|
|
140
|
-
form.append('file', file, {
|
|
141
|
-
filename: fileName,
|
|
142
|
-
contentType: contentType,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
// Stream - require fileName
|
|
147
|
-
if (!fileName) {
|
|
148
|
-
throw new Error('fileName is required when uploading from a stream');
|
|
149
|
-
}
|
|
150
|
-
form.append('file', file, fileName);
|
|
151
|
-
}
|
|
152
|
-
// Add additional fields to the form
|
|
153
|
-
for (_i = 0, _a = Object.entries(additionalFields); _i < _a.length; _i++) {
|
|
154
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
155
|
-
if (value !== undefined && value !== null) {
|
|
156
|
-
form.append(key, value.toString());
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
url = "".concat(baseUrl).concat(endpoint);
|
|
160
|
-
headers = __assign({ Authorization: "Bearer ".concat(authToken) }, form.getHeaders());
|
|
161
|
-
if (requestId) {
|
|
162
|
-
headers['X-Request-Id'] = requestId;
|
|
163
|
-
}
|
|
164
|
-
return [4 /*yield*/, axios_1.default.post(url, form, { headers: headers })];
|
|
165
|
-
case 1:
|
|
166
|
-
response = _c.sent();
|
|
167
|
-
return [2 /*return*/, response.data];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|