@doist/todoist-api-typescript 1.5.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.
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.revokeAuthToken = exports.getAuthToken = exports.getAuthorizationUrl = exports.getAuthStateParameter = void 0;
40
+ var restClient_1 = require("./restClient");
41
+ var uuid_1 = require("uuid");
42
+ var types_1 = require("./types");
43
+ var endpoints_1 = require("./consts/endpoints");
44
+ function getAuthStateParameter() {
45
+ return (0, uuid_1.v4)();
46
+ }
47
+ exports.getAuthStateParameter = getAuthStateParameter;
48
+ function getAuthorizationUrl(clientId, permissions, state) {
49
+ if (!(permissions === null || permissions === void 0 ? void 0 : permissions.length)) {
50
+ throw new Error('At least one scope value should be passed for permissions.');
51
+ }
52
+ var scope = permissions.join(',');
53
+ return "" + endpoints_1.API_AUTHORIZATION_BASE_URI + endpoints_1.ENDPOINT_AUTHORIZATION + "?client_id=" + clientId + "&scope=" + scope + "&state=" + state;
54
+ }
55
+ exports.getAuthorizationUrl = getAuthorizationUrl;
56
+ function getAuthToken(args) {
57
+ var _a;
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var response;
60
+ return __generator(this, function (_b) {
61
+ switch (_b.label) {
62
+ case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_AUTHORIZATION_BASE_URI, endpoints_1.ENDPOINT_GET_TOKEN, undefined, args)];
63
+ case 1:
64
+ response = _b.sent();
65
+ if (response.status !== 200 || !((_a = response.data) === null || _a === void 0 ? void 0 : _a.accessToken)) {
66
+ throw new types_1.TodoistRequestError('Authentication token exchange failed.', response.status, response.data);
67
+ }
68
+ return [2 /*return*/, response.data];
69
+ }
70
+ });
71
+ });
72
+ }
73
+ exports.getAuthToken = getAuthToken;
74
+ function revokeAuthToken(args) {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var response;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_SYNC_BASE_URI, endpoints_1.ENDPOINT_REVOKE_TOKEN, undefined, args)];
80
+ case 1:
81
+ response = _a.sent();
82
+ return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
83
+ }
84
+ });
85
+ });
86
+ }
87
+ exports.revokeAuthToken = revokeAuthToken;
@@ -0,0 +1,15 @@
1
+ export declare const API_REST_BASE_URI = "https://api.todoist.com/rest/v1/";
2
+ export declare const API_SYNC_BASE_URI = "https://api.todoist.com/sync/v8/";
3
+ export declare const API_AUTHORIZATION_BASE_URI = "https://todoist.com/oauth/";
4
+ export declare const ENDPOINT_REST_TASKS = "tasks";
5
+ export declare const ENDPOINT_REST_PROJECTS = "projects";
6
+ export declare const ENDPOINT_REST_SECTIONS = "sections";
7
+ export declare const ENDPOINT_REST_LABELS = "labels";
8
+ export declare const ENDPOINT_REST_COMMENTS = "comments";
9
+ export declare const ENDPOINT_REST_TASK_CLOSE = "close";
10
+ export declare const ENDPOINT_REST_TASK_REOPEN = "reopen";
11
+ export declare const ENDPOINT_REST_PROJECT_COLLABORATORS = "collaborators";
12
+ export declare const ENDPOINT_SYNC_QUICK_ADD = "quick/add";
13
+ export declare const ENDPOINT_AUTHORIZATION = "authorize";
14
+ export declare const ENDPOINT_GET_TOKEN = "access_token";
15
+ export declare const ENDPOINT_REVOKE_TOKEN = "access_tokens/revoke";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENDPOINT_REVOKE_TOKEN = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_TASK_REOPEN = exports.ENDPOINT_REST_TASK_CLOSE = exports.ENDPOINT_REST_COMMENTS = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASKS = exports.API_AUTHORIZATION_BASE_URI = exports.API_SYNC_BASE_URI = exports.API_REST_BASE_URI = void 0;
4
+ exports.API_REST_BASE_URI = 'https://api.todoist.com/rest/v1/';
5
+ exports.API_SYNC_BASE_URI = 'https://api.todoist.com/sync/v8/';
6
+ exports.API_AUTHORIZATION_BASE_URI = 'https://todoist.com/oauth/';
7
+ exports.ENDPOINT_REST_TASKS = 'tasks';
8
+ exports.ENDPOINT_REST_PROJECTS = 'projects';
9
+ exports.ENDPOINT_REST_SECTIONS = 'sections';
10
+ exports.ENDPOINT_REST_LABELS = 'labels';
11
+ exports.ENDPOINT_REST_COMMENTS = 'comments';
12
+ exports.ENDPOINT_REST_TASK_CLOSE = 'close';
13
+ exports.ENDPOINT_REST_TASK_REOPEN = 'reopen';
14
+ exports.ENDPOINT_REST_PROJECT_COLLABORATORS = 'collaborators';
15
+ exports.ENDPOINT_SYNC_QUICK_ADD = 'quick/add';
16
+ exports.ENDPOINT_AUTHORIZATION = 'authorize';
17
+ exports.ENDPOINT_GET_TOKEN = 'access_token';
18
+ exports.ENDPOINT_REVOKE_TOKEN = 'access_tokens/revoke';
@@ -0,0 +1,5 @@
1
+ export * from './TodoistApi';
2
+ export * from './restClient';
3
+ export * from './authentication';
4
+ export * from './types';
5
+ export * from './utils';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./TodoistApi"), exports);
14
+ __exportStar(require("./restClient"), exports);
15
+ __exportStar(require("./authentication"), exports);
16
+ __exportStar(require("./types"), exports);
17
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,4 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { HttpMethod } from './types/http';
3
+ export declare function isSuccess(response: AxiosResponse): boolean;
4
+ export declare function request<T extends unknown>(httpMethod: HttpMethod, baseUri: string, relativePath: string, apiToken?: string, payload?: unknown, requestId?: string): Promise<AxiosResponse<T>>;
@@ -0,0 +1,144 @@
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;
24
+ return g = { next: verb(0), "throw": verb(1), "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 (_) 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.request = exports.isSuccess = void 0;
54
+ var axios_1 = __importDefault(require("axios"));
55
+ var axios_case_converter_1 = __importDefault(require("axios-case-converter"));
56
+ var url_join_1 = __importDefault(require("url-join"));
57
+ var errors_1 = require("./types/errors");
58
+ var uuid_1 = require("uuid");
59
+ var axios_retry_1 = __importDefault(require("axios-retry"));
60
+ var defaultHeaders = {
61
+ 'Content-Type': 'application/json',
62
+ };
63
+ function getAuthHeader(apiKey) {
64
+ return "Bearer " + apiKey;
65
+ }
66
+ function isNetworkError(error) {
67
+ return Boolean(!error.response && error.code !== 'ECONNABORTED');
68
+ }
69
+ function getRetryDelay(retryCount) {
70
+ return retryCount === 1 ? 0 : 500;
71
+ }
72
+ function isAxiosError(error) {
73
+ var _a;
74
+ return Boolean((_a = error) === null || _a === void 0 ? void 0 : _a.isAxiosError);
75
+ }
76
+ function getTodoistRequestError(error, originalStack) {
77
+ var requestError = new errors_1.TodoistRequestError(error.message);
78
+ requestError.stack = isAxiosError(error) && originalStack ? originalStack.stack : error.stack;
79
+ if (isAxiosError(error) && error.response) {
80
+ requestError.httpStatusCode = error.response.status;
81
+ requestError.responseData = error.response.data;
82
+ }
83
+ return requestError;
84
+ }
85
+ function getRequestConfiguration(apiToken, requestId) {
86
+ var authHeader = apiToken ? { Authorization: getAuthHeader(apiToken) } : undefined;
87
+ var requestIdHeader = requestId ? { 'X-Request-Id': requestId } : undefined;
88
+ var headers = __assign(__assign(__assign({}, defaultHeaders), authHeader), requestIdHeader);
89
+ return { headers: headers };
90
+ }
91
+ function getAxiosClient(apiToken, requestId) {
92
+ var configuration = getRequestConfiguration(apiToken, requestId);
93
+ var client = (0, axios_case_converter_1.default)(axios_1.default.create(configuration));
94
+ (0, axios_retry_1.default)(client, {
95
+ retries: 3,
96
+ retryCondition: isNetworkError,
97
+ retryDelay: getRetryDelay,
98
+ });
99
+ return client;
100
+ }
101
+ function isSuccess(response) {
102
+ return response.status >= 200 && response.status < 300;
103
+ }
104
+ exports.isSuccess = isSuccess;
105
+ function request(httpMethod, baseUri, relativePath, apiToken, payload, requestId) {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ var originalStack, axiosClient, _a, error_1;
108
+ return __generator(this, function (_b) {
109
+ switch (_b.label) {
110
+ case 0:
111
+ originalStack = new Error();
112
+ _b.label = 1;
113
+ case 1:
114
+ _b.trys.push([1, 9, , 10]);
115
+ if (httpMethod === 'POST' && !requestId) {
116
+ requestId = (0, uuid_1.v4)();
117
+ }
118
+ axiosClient = getAxiosClient(apiToken, requestId);
119
+ _a = httpMethod;
120
+ switch (_a) {
121
+ case 'GET': return [3 /*break*/, 2];
122
+ case 'POST': return [3 /*break*/, 4];
123
+ case 'DELETE': return [3 /*break*/, 6];
124
+ }
125
+ return [3 /*break*/, 8];
126
+ case 2: return [4 /*yield*/, axiosClient.get((0, url_join_1.default)(baseUri, relativePath), { params: payload })];
127
+ case 3: return [2 /*return*/, _b.sent()];
128
+ case 4: return [4 /*yield*/, axiosClient.post((0, url_join_1.default)(baseUri, relativePath), payload)];
129
+ case 5: return [2 /*return*/, _b.sent()];
130
+ case 6: return [4 /*yield*/, axiosClient.delete((0, url_join_1.default)(baseUri, relativePath))];
131
+ case 7: return [2 /*return*/, _b.sent()];
132
+ case 8: return [3 /*break*/, 10];
133
+ case 9:
134
+ error_1 = _b.sent();
135
+ if (!isAxiosError(error_1) && !(error_1 instanceof Error)) {
136
+ throw new Error('An unknown error occurred during the request');
137
+ }
138
+ throw getTodoistRequestError(error_1, originalStack);
139
+ case 10: return [2 /*return*/];
140
+ }
141
+ });
142
+ });
143
+ }
144
+ exports.request = request;
@@ -0,0 +1,2 @@
1
+ export declare function assertInstance<T extends new (...args: any) => any>(value: unknown, type: T): asserts value is InstanceType<T>;
2
+ export declare function assertInputValidationError(apiCall: () => Promise<unknown>): Promise<void>;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.assertInputValidationError = exports.assertInstance = void 0;
40
+ var mocks_1 = require("./mocks");
41
+ var runtypes_1 = require("runtypes");
42
+ // Has to use 'any' to express constructor type
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ function assertInstance(value, type) {
45
+ if (value instanceof type) {
46
+ return;
47
+ }
48
+ throw new TypeError("Unexpected type " + typeof value);
49
+ }
50
+ exports.assertInstance = assertInstance;
51
+ function assertInputValidationError(apiCall) {
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ var requestMock, e_1;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0:
57
+ requestMock = (0, mocks_1.setupRestClientMock)(undefined);
58
+ expect.assertions(1);
59
+ _a.label = 1;
60
+ case 1:
61
+ _a.trys.push([1, 3, , 4]);
62
+ return [4 /*yield*/, apiCall()];
63
+ case 2:
64
+ _a.sent();
65
+ return [3 /*break*/, 4];
66
+ case 3:
67
+ e_1 = _a.sent();
68
+ assertInstance(e_1, runtypes_1.ValidationError);
69
+ expect(requestMock).not.toBeCalled();
70
+ return [3 /*break*/, 4];
71
+ case 4: return [2 /*return*/];
72
+ }
73
+ });
74
+ });
75
+ }
76
+ exports.assertInputValidationError = assertInputValidationError;
@@ -0,0 +1,2 @@
1
+ /// <reference types="jest" />
2
+ export declare function setupRestClientMock(responseData: unknown, status?: number): jest.SpyInstance;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.setupRestClientMock = void 0;
23
+ var jest_mock_extended_1 = require("jest-mock-extended");
24
+ var restClient = __importStar(require("../restClient"));
25
+ function setupRestClientMock(responseData, status) {
26
+ if (status === void 0) { status = 200; }
27
+ var response = (0, jest_mock_extended_1.mock)({ status: status, data: responseData });
28
+ return jest.spyOn(restClient, 'request').mockResolvedValue(response);
29
+ }
30
+ exports.setupRestClientMock = setupRestClientMock;
@@ -0,0 +1,110 @@
1
+ import { Label, Project, QuickAddTaskResponse, Section, Task, User, Comment, Attachment } from '../types';
2
+ export declare const DEFAULT_AUTH_TOKEN = "AToken";
3
+ export declare const DEFAULT_REQUEST_ID = "ARequestID";
4
+ export declare const INVALID_ENTITY_ID: number;
5
+ export declare const DEFAULT_DUE_DATE: {
6
+ recurring: boolean;
7
+ string: string;
8
+ date: string;
9
+ };
10
+ export declare const INVALID_DUE_DATE: {
11
+ recurring: string;
12
+ string: string;
13
+ date: string;
14
+ };
15
+ export declare const DEFAULT_QUICK_ADD_RESPONSE: QuickAddTaskResponse;
16
+ export declare const DEFAULT_TASK: Task;
17
+ export declare const INVALID_TASK: {
18
+ due: {
19
+ recurring: string;
20
+ string: string;
21
+ date: string;
22
+ };
23
+ id: number;
24
+ order: number;
25
+ content: string;
26
+ description: string;
27
+ projectId: number;
28
+ sectionId: number;
29
+ completed: boolean;
30
+ labelIds: number[];
31
+ priority: number;
32
+ commentCount: number;
33
+ created: string;
34
+ url: string;
35
+ parentId?: number | undefined;
36
+ assignee?: number | undefined;
37
+ };
38
+ export declare const DEFAULT_PROJECT: Project;
39
+ export declare const INVALID_PROJECT: {
40
+ name: number;
41
+ id: number;
42
+ commentCount: number;
43
+ url: string;
44
+ color: number;
45
+ shared: boolean;
46
+ favorite: boolean;
47
+ parentId?: number | undefined;
48
+ order?: number | undefined;
49
+ inboxProject?: boolean | undefined;
50
+ teamInbox?: boolean | undefined;
51
+ syncId?: number | undefined;
52
+ };
53
+ export declare const DEFAULT_SECTION: Section;
54
+ export declare const INVALID_SECTION: {
55
+ projectId: undefined;
56
+ id: number;
57
+ order: number;
58
+ name: string;
59
+ };
60
+ export declare const DEFAULT_LABEL: Label;
61
+ export declare const INVALID_LABEL: {
62
+ favorite: string;
63
+ id: number;
64
+ order: number;
65
+ name: string;
66
+ color: number;
67
+ };
68
+ export declare const DEFAULT_USER: User;
69
+ export declare const INVALID_USER: {
70
+ email: undefined;
71
+ id: number;
72
+ name: string;
73
+ };
74
+ export declare const DEFAULT_ATTACHMENT: Attachment;
75
+ export declare const INVALID_ATTACHMENT: {
76
+ uploadState: string;
77
+ resourceType: string;
78
+ fileName?: string | undefined;
79
+ fileSize?: number | undefined;
80
+ fileType?: string | undefined;
81
+ fileUrl?: string | undefined;
82
+ fileDuration?: number | undefined;
83
+ image?: string | undefined;
84
+ imageWidth?: number | undefined;
85
+ imageHeight?: number | undefined;
86
+ url?: string | undefined;
87
+ title?: string | undefined;
88
+ };
89
+ export declare const DEFAULT_COMMENT: Comment;
90
+ export declare const INVALID_COMMENT: {
91
+ attachment: {
92
+ uploadState: string;
93
+ resourceType: string;
94
+ fileName?: string | undefined;
95
+ fileSize?: number | undefined;
96
+ fileType?: string | undefined;
97
+ fileUrl?: string | undefined;
98
+ fileDuration?: number | undefined;
99
+ image?: string | undefined;
100
+ imageWidth?: number | undefined;
101
+ imageHeight?: number | undefined;
102
+ url?: string | undefined;
103
+ title?: string | undefined;
104
+ };
105
+ id: number;
106
+ content: string;
107
+ posted: string;
108
+ taskId?: number | undefined;
109
+ projectId?: number | undefined;
110
+ };
@@ -0,0 +1,132 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.INVALID_COMMENT = exports.DEFAULT_COMMENT = exports.INVALID_ATTACHMENT = exports.DEFAULT_ATTACHMENT = exports.INVALID_USER = exports.DEFAULT_USER = exports.INVALID_LABEL = exports.DEFAULT_LABEL = exports.INVALID_SECTION = exports.DEFAULT_SECTION = exports.INVALID_PROJECT = exports.DEFAULT_PROJECT = exports.INVALID_TASK = exports.DEFAULT_TASK = exports.DEFAULT_QUICK_ADD_RESPONSE = exports.INVALID_DUE_DATE = exports.DEFAULT_DUE_DATE = exports.INVALID_ENTITY_ID = exports.DEFAULT_REQUEST_ID = exports.DEFAULT_AUTH_TOKEN = void 0;
15
+ var DEFAULT_TASK_ID = 1234;
16
+ var DEFAULT_TASK_CONTENT = 'This is a task';
17
+ var DEFAULT_TASK_DESCRIPTION = 'A description';
18
+ var DEFAULT_TASK_PRIORITY = 1;
19
+ var DEFAULT_ORDER = 3;
20
+ var DEFAULT_PROJECT_ID = 123;
21
+ var DEFAULT_PROJECT_NAME = 'This is a project';
22
+ var DEFAULT_LABEL_ID = 456;
23
+ var DEFAULT_LABEL_NAME = 'This is a label';
24
+ var DEFAULT_SECTION_ID = 456;
25
+ var DEFAULT_SECTION_NAME = 'This is a section';
26
+ var DEFAULT_PARENT_ID = 5678;
27
+ var DEFAULT_ASSIGNEE = 1234;
28
+ var DEFAULT_DATE = '2020-09-08T12:00:00Z';
29
+ var DEFAULT_ENTITY_COLOR = 30;
30
+ var DEFAULT_LABELS = [1, 2, 3];
31
+ var DEFAULT_USER_ID = 5;
32
+ var DEFAULT_USER_NAME = 'A User';
33
+ var DEFAULT_USER_EMAIL = 'atestuser@doist.com';
34
+ var DEFAULT_COMMENT_ID = 4;
35
+ var DEFAULT_COMMENT_CONTENT = 'A comment';
36
+ exports.DEFAULT_AUTH_TOKEN = 'AToken';
37
+ exports.DEFAULT_REQUEST_ID = 'ARequestID';
38
+ exports.INVALID_ENTITY_ID = 'invalid/entity/id';
39
+ exports.DEFAULT_DUE_DATE = {
40
+ recurring: false,
41
+ string: 'a date string',
42
+ date: DEFAULT_DATE,
43
+ };
44
+ exports.INVALID_DUE_DATE = __assign(__assign({}, exports.DEFAULT_DUE_DATE), { recurring: 'false' });
45
+ exports.DEFAULT_QUICK_ADD_RESPONSE = {
46
+ id: DEFAULT_TASK_ID,
47
+ projectId: DEFAULT_PROJECT_ID,
48
+ content: DEFAULT_TASK_CONTENT,
49
+ description: DEFAULT_TASK_DESCRIPTION,
50
+ priority: DEFAULT_TASK_PRIORITY,
51
+ sectionId: DEFAULT_SECTION_ID,
52
+ parentId: DEFAULT_PARENT_ID,
53
+ childOrder: DEFAULT_ORDER,
54
+ labels: DEFAULT_LABELS,
55
+ responsibleUid: DEFAULT_ASSIGNEE,
56
+ checked: 0,
57
+ dateAdded: DEFAULT_DATE,
58
+ syncId: null,
59
+ due: {
60
+ date: DEFAULT_DATE,
61
+ timezone: null,
62
+ string: 'a date string',
63
+ lang: 'en',
64
+ isRecurring: false,
65
+ },
66
+ };
67
+ exports.DEFAULT_TASK = {
68
+ id: DEFAULT_TASK_ID,
69
+ order: DEFAULT_ORDER,
70
+ parentId: DEFAULT_PARENT_ID,
71
+ content: DEFAULT_TASK_CONTENT,
72
+ description: DEFAULT_TASK_DESCRIPTION,
73
+ projectId: DEFAULT_PROJECT_ID,
74
+ sectionId: DEFAULT_SECTION_ID,
75
+ completed: false,
76
+ labelIds: DEFAULT_LABELS,
77
+ priority: DEFAULT_TASK_PRIORITY,
78
+ commentCount: 0,
79
+ created: DEFAULT_DATE,
80
+ url: 'https://todoist.com/showTask?id=1234',
81
+ due: exports.DEFAULT_DUE_DATE,
82
+ assignee: DEFAULT_ASSIGNEE,
83
+ };
84
+ exports.INVALID_TASK = __assign(__assign({}, exports.DEFAULT_TASK), { due: exports.INVALID_DUE_DATE });
85
+ exports.DEFAULT_PROJECT = {
86
+ id: DEFAULT_PROJECT_ID,
87
+ name: DEFAULT_PROJECT_NAME,
88
+ color: DEFAULT_ENTITY_COLOR,
89
+ order: DEFAULT_ORDER,
90
+ parentId: DEFAULT_PROJECT_ID,
91
+ commentCount: 0,
92
+ favorite: false,
93
+ shared: false,
94
+ url: "https://todoist.com/showProject?id=123",
95
+ };
96
+ exports.INVALID_PROJECT = __assign(__assign({}, exports.DEFAULT_PROJECT), { name: 123 });
97
+ exports.DEFAULT_SECTION = {
98
+ id: DEFAULT_SECTION_ID,
99
+ name: DEFAULT_SECTION_NAME,
100
+ order: DEFAULT_ORDER,
101
+ projectId: DEFAULT_PROJECT_ID,
102
+ };
103
+ exports.INVALID_SECTION = __assign(__assign({}, exports.DEFAULT_SECTION), { projectId: undefined });
104
+ exports.DEFAULT_LABEL = {
105
+ id: DEFAULT_LABEL_ID,
106
+ name: DEFAULT_LABEL_NAME,
107
+ color: DEFAULT_ENTITY_COLOR,
108
+ order: DEFAULT_ORDER,
109
+ favorite: false,
110
+ };
111
+ exports.INVALID_LABEL = __assign(__assign({}, exports.DEFAULT_LABEL), { favorite: 'true' });
112
+ exports.DEFAULT_USER = {
113
+ id: DEFAULT_USER_ID,
114
+ name: DEFAULT_USER_NAME,
115
+ email: DEFAULT_USER_EMAIL,
116
+ };
117
+ exports.INVALID_USER = __assign(__assign({}, exports.DEFAULT_USER), { email: undefined });
118
+ exports.DEFAULT_ATTACHMENT = {
119
+ resourceType: 'file',
120
+ fileType: 'image/png',
121
+ fileUrl: 'https://someurl.com/image.jpg',
122
+ uploadState: 'completed',
123
+ };
124
+ exports.INVALID_ATTACHMENT = __assign(__assign({}, exports.DEFAULT_ATTACHMENT), { uploadState: 'something random' });
125
+ exports.DEFAULT_COMMENT = {
126
+ id: DEFAULT_COMMENT_ID,
127
+ content: DEFAULT_COMMENT_CONTENT,
128
+ projectId: DEFAULT_PROJECT_ID,
129
+ attachment: exports.DEFAULT_ATTACHMENT,
130
+ posted: DEFAULT_DATE,
131
+ };
132
+ exports.INVALID_COMMENT = __assign(__assign({}, exports.DEFAULT_COMMENT), { attachment: exports.INVALID_ATTACHMENT });