@doist/todoist-sdk 14.1.0 → 15.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/README.md +46 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/transport/http-dispatcher.js +25 -0
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/multipart-upload.js +171 -57
- package/dist/esm/utils/url-helpers.js +151 -23
- package/dist/types/index.d.ts +2 -1
- package/dist/types/transport/http-dispatcher.d.ts +26 -1
- package/dist/types/utils/index.d.ts +2 -1
- package/dist/types/utils/url-helpers.d.ts +88 -0
- package/package.json +6 -12
- package/dist/cjs/authentication.js +0 -317
- package/dist/cjs/clients/activity-client.js +0 -63
- package/dist/cjs/clients/app-client.js +0 -345
- package/dist/cjs/clients/backup-client.js +0 -47
- package/dist/cjs/clients/base-client.js +0 -31
- package/dist/cjs/clients/billing-client.js +0 -152
- package/dist/cjs/clients/comment-client.js +0 -91
- package/dist/cjs/clients/email-client.js +0 -43
- package/dist/cjs/clients/folder-client.js +0 -79
- package/dist/cjs/clients/id-mapping-client.js +0 -39
- package/dist/cjs/clients/insights-client.js +0 -87
- package/dist/cjs/clients/label-client.js +0 -126
- package/dist/cjs/clients/productivity-client.js +0 -27
- package/dist/cjs/clients/project-client.js +0 -235
- package/dist/cjs/clients/reminder-client.js +0 -198
- package/dist/cjs/clients/section-client.js +0 -117
- package/dist/cjs/clients/task-client.js +0 -254
- package/dist/cjs/clients/template-client.js +0 -88
- package/dist/cjs/clients/ui-extension-client.js +0 -107
- package/dist/cjs/clients/upload-client.js +0 -155
- package/dist/cjs/clients/view-options-client.js +0 -25
- package/dist/cjs/clients/workspace-client.js +0 -366
- package/dist/cjs/consts/endpoints.js +0 -224
- package/dist/cjs/index.js +0 -23
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/test-utils/asserts.js +0 -11
- package/dist/cjs/test-utils/msw-setup.js +0 -97
- package/dist/cjs/test-utils/obsidian-fetch-adapter.js +0 -54
- package/dist/cjs/test-utils/test-defaults.js +0 -371
- package/dist/cjs/test-utils/transport-seam.js +0 -17
- package/dist/cjs/test-utils/webhook-fixtures.js +0 -32
- package/dist/cjs/todoist-api.js +0 -1711
- package/dist/cjs/transport/fetch-with-retry.js +0 -219
- package/dist/cjs/transport/http-client.js +0 -134
- package/dist/cjs/transport/http-dispatcher.js +0 -173
- package/dist/cjs/transport/sync-request.js +0 -83
- package/dist/cjs/types/activity/index.js +0 -18
- package/dist/cjs/types/activity/requests.js +0 -2
- package/dist/cjs/types/activity/types.js +0 -28
- package/dist/cjs/types/apps/index.js +0 -18
- package/dist/cjs/types/apps/requests.js +0 -2
- package/dist/cjs/types/apps/types.js +0 -254
- package/dist/cjs/types/backups/index.js +0 -18
- package/dist/cjs/types/backups/requests.js +0 -2
- package/dist/cjs/types/backups/types.js +0 -8
- package/dist/cjs/types/billing/index.js +0 -18
- package/dist/cjs/types/billing/requests.js +0 -2
- package/dist/cjs/types/billing/types.js +0 -92
- package/dist/cjs/types/comments/index.js +0 -18
- package/dist/cjs/types/comments/requests.js +0 -2
- package/dist/cjs/types/comments/types.js +0 -60
- package/dist/cjs/types/common.js +0 -10
- package/dist/cjs/types/emails/index.js +0 -17
- package/dist/cjs/types/emails/requests.js +0 -5
- package/dist/cjs/types/errors.js +0 -29
- package/dist/cjs/types/folders/index.js +0 -17
- package/dist/cjs/types/folders/requests.js +0 -2
- package/dist/cjs/types/http.js +0 -24
- package/dist/cjs/types/id-mappings/index.js +0 -18
- package/dist/cjs/types/id-mappings/requests.js +0 -20
- package/dist/cjs/types/id-mappings/types.js +0 -12
- package/dist/cjs/types/index.js +0 -40
- package/dist/cjs/types/insights/index.js +0 -18
- package/dist/cjs/types/insights/requests.js +0 -2
- package/dist/cjs/types/insights/types.js +0 -80
- package/dist/cjs/types/labels/index.js +0 -18
- package/dist/cjs/types/labels/requests.js +0 -2
- package/dist/cjs/types/labels/types.js +0 -11
- package/dist/cjs/types/productivity/index.js +0 -17
- package/dist/cjs/types/productivity/types.js +0 -68
- package/dist/cjs/types/projects/index.js +0 -18
- package/dist/cjs/types/projects/requests.js +0 -2
- package/dist/cjs/types/projects/types.js +0 -66
- package/dist/cjs/types/reminders/index.js +0 -17
- package/dist/cjs/types/reminders/requests.js +0 -95
- package/dist/cjs/types/sections/index.js +0 -18
- package/dist/cjs/types/sections/requests.js +0 -2
- package/dist/cjs/types/sections/types.js +0 -25
- package/dist/cjs/types/sync/commands/calendars.js +0 -2
- package/dist/cjs/types/sync/commands/filters.js +0 -2
- package/dist/cjs/types/sync/commands/folders.js +0 -2
- package/dist/cjs/types/sync/commands/index.js +0 -34
- package/dist/cjs/types/sync/commands/labels.js +0 -5
- package/dist/cjs/types/sync/commands/notes.js +0 -2
- package/dist/cjs/types/sync/commands/notifications.js +0 -2
- package/dist/cjs/types/sync/commands/others.js +0 -2
- package/dist/cjs/types/sync/commands/project-view-options.js +0 -2
- package/dist/cjs/types/sync/commands/projects.js +0 -2
- package/dist/cjs/types/sync/commands/reminders.js +0 -2
- package/dist/cjs/types/sync/commands/sections.js +0 -2
- package/dist/cjs/types/sync/commands/shared.js +0 -20
- package/dist/cjs/types/sync/commands/sharing.js +0 -2
- package/dist/cjs/types/sync/commands/tasks.js +0 -2
- package/dist/cjs/types/sync/commands/view-options.js +0 -2
- package/dist/cjs/types/sync/commands/workspace-filters.js +0 -2
- package/dist/cjs/types/sync/commands/workspaces.js +0 -2
- package/dist/cjs/types/sync/index.js +0 -22
- package/dist/cjs/types/sync/request.js +0 -2
- package/dist/cjs/types/sync/resource-types.js +0 -39
- package/dist/cjs/types/sync/resources/calendars.js +0 -27
- package/dist/cjs/types/sync/resources/collaborators.js +0 -21
- package/dist/cjs/types/sync/resources/completed-info.js +0 -24
- package/dist/cjs/types/sync/resources/filters.js +0 -14
- package/dist/cjs/types/sync/resources/folders.js +0 -12
- package/dist/cjs/types/sync/resources/index.js +0 -32
- package/dist/cjs/types/sync/resources/live-notifications.js +0 -38
- package/dist/cjs/types/sync/resources/notes.js +0 -21
- package/dist/cjs/types/sync/resources/reminders.js +0 -50
- package/dist/cjs/types/sync/resources/suggestions.js +0 -36
- package/dist/cjs/types/sync/resources/tooltips.js +0 -8
- package/dist/cjs/types/sync/resources/user-plan-limits.js +0 -20
- package/dist/cjs/types/sync/resources/user-settings.js +0 -40
- package/dist/cjs/types/sync/resources/user.js +0 -110
- package/dist/cjs/types/sync/resources/view-options.js +0 -86
- package/dist/cjs/types/sync/resources/workspace-filters.js +0 -19
- package/dist/cjs/types/sync/resources/workspaces.js +0 -72
- package/dist/cjs/types/sync/response.js +0 -54
- package/dist/cjs/types/sync/user-preferences.js +0 -71
- package/dist/cjs/types/tasks/index.js +0 -18
- package/dist/cjs/types/tasks/requests.js +0 -2
- package/dist/cjs/types/tasks/types.js +0 -59
- package/dist/cjs/types/templates/index.js +0 -17
- package/dist/cjs/types/templates/requests.js +0 -2
- package/dist/cjs/types/ui-extensions/index.js +0 -18
- package/dist/cjs/types/ui-extensions/requests.js +0 -2
- package/dist/cjs/types/ui-extensions/types.js +0 -77
- package/dist/cjs/types/uploads/index.js +0 -17
- package/dist/cjs/types/uploads/requests.js +0 -2
- package/dist/cjs/types/users/index.js +0 -17
- package/dist/cjs/types/users/types.js +0 -51
- package/dist/cjs/types/webhooks/comments.js +0 -96
- package/dist/cjs/types/webhooks/envelope.js +0 -26
- package/dist/cjs/types/webhooks/filters.js +0 -30
- package/dist/cjs/types/webhooks/index.js +0 -25
- package/dist/cjs/types/webhooks/labels.js +0 -54
- package/dist/cjs/types/webhooks/projects.js +0 -36
- package/dist/cjs/types/webhooks/reminders.js +0 -35
- package/dist/cjs/types/webhooks/sections.js +0 -53
- package/dist/cjs/types/webhooks/tasks.js +0 -68
- package/dist/cjs/types/webhooks/types.js +0 -55
- package/dist/cjs/types/workspaces/index.js +0 -18
- package/dist/cjs/types/workspaces/requests.js +0 -2
- package/dist/cjs/types/workspaces/types.js +0 -154
- package/dist/cjs/utils/activity-helpers.js +0 -58
- package/dist/cjs/utils/case-conversion.js +0 -69
- package/dist/cjs/utils/colors.js +0 -143
- package/dist/cjs/utils/file-response.js +0 -32
- package/dist/cjs/utils/headers.js +0 -16
- package/dist/cjs/utils/index.js +0 -31
- package/dist/cjs/utils/multipart-upload.js +0 -179
- package/dist/cjs/utils/processing-helpers.js +0 -18
- package/dist/cjs/utils/project-helpers.js +0 -20
- package/dist/cjs/utils/request-helpers.js +0 -21
- package/dist/cjs/utils/sanitization.js +0 -116
- package/dist/cjs/utils/sync-helpers.js +0 -22
- package/dist/cjs/utils/task-sorting.js +0 -281
- package/dist/cjs/utils/uncompletable-helpers.js +0 -60
- package/dist/cjs/utils/url-helpers.js +0 -74
- package/dist/cjs/utils/validators.js +0 -108
- package/dist/cjs/utils/view-options.js +0 -19
- package/dist/cjs/utils/webhook-parser.js +0 -60
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_TASK_ORDERS = void 0;
|
|
4
|
-
exports.sortTasks = sortTasks;
|
|
5
|
-
/** Todoist's default task-ordering hierarchies. */
|
|
6
|
-
exports.DEFAULT_TASK_ORDERS = ['PRIORITY_FIRST', 'DATE_FIRST'];
|
|
7
|
-
const DEFAULT_TIMEZONE = 'UTC';
|
|
8
|
-
const DEFAULT_LOCALE = 'en';
|
|
9
|
-
const DATE_ONLY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
10
|
-
const DATE_TIME_PATTERN = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?$/;
|
|
11
|
-
const EXPLICIT_TIMEZONE_PATTERN = /(?:Z|[+-]\d{2}:?\d{2})$/i;
|
|
12
|
-
const DATE_TIME_FORMATTERS = new Map();
|
|
13
|
-
function compareNumber(a, b) {
|
|
14
|
-
if (a === b)
|
|
15
|
-
return 0;
|
|
16
|
-
return a < b ? -1 : 1;
|
|
17
|
-
}
|
|
18
|
-
function isValidDateParts(year, month, day) {
|
|
19
|
-
const date = new Date(0);
|
|
20
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
21
|
-
date.setUTCFullYear(year, month - 1, day);
|
|
22
|
-
return (date.getUTCFullYear() === year &&
|
|
23
|
-
date.getUTCMonth() === month - 1 &&
|
|
24
|
-
date.getUTCDate() === day);
|
|
25
|
-
}
|
|
26
|
-
function dateSortValue({ year, month, day, hour = 0, minute = 0, second = 0, millisecond = 0, isAllDay = false, }) {
|
|
27
|
-
if (!isValidDateParts(year, month, day) ||
|
|
28
|
-
hour < 0 ||
|
|
29
|
-
hour > 23 ||
|
|
30
|
-
minute < 0 ||
|
|
31
|
-
minute > 59 ||
|
|
32
|
-
second < 0 ||
|
|
33
|
-
second > 59 ||
|
|
34
|
-
millisecond < 0 ||
|
|
35
|
-
millisecond > 999) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
day: year * 10000 + month * 100 + day,
|
|
40
|
-
kind: isAllDay ? 0 : 1,
|
|
41
|
-
time: ((hour * 60 + minute) * 60 + second) * 1000 + millisecond,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function parseDateOnly(value) {
|
|
45
|
-
const match = DATE_ONLY_PATTERN.exec(value);
|
|
46
|
-
if (!match)
|
|
47
|
-
return null;
|
|
48
|
-
return dateSortValue({
|
|
49
|
-
year: Number(match[1]),
|
|
50
|
-
month: Number(match[2]),
|
|
51
|
-
day: Number(match[3]),
|
|
52
|
-
isAllDay: true,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function parseDateTimeComponents(value) {
|
|
56
|
-
var _a, _b;
|
|
57
|
-
const match = DATE_TIME_PATTERN.exec(value);
|
|
58
|
-
if (!match)
|
|
59
|
-
return null;
|
|
60
|
-
const milliseconds = Number(((_a = match[7]) !== null && _a !== void 0 ? _a : '').padEnd(3, '0').slice(0, 3));
|
|
61
|
-
const components = {
|
|
62
|
-
year: Number(match[1]),
|
|
63
|
-
month: Number(match[2]),
|
|
64
|
-
day: Number(match[3]),
|
|
65
|
-
hour: Number(match[4]),
|
|
66
|
-
minute: Number(match[5]),
|
|
67
|
-
second: Number((_b = match[6]) !== null && _b !== void 0 ? _b : 0),
|
|
68
|
-
millisecond: milliseconds,
|
|
69
|
-
};
|
|
70
|
-
return dateSortValue(components) === null ? null : components;
|
|
71
|
-
}
|
|
72
|
-
function createDateTimeFormatter(timezone, fallback) {
|
|
73
|
-
const cached = DATE_TIME_FORMATTERS.get(timezone);
|
|
74
|
-
if (cached)
|
|
75
|
-
return cached;
|
|
76
|
-
try {
|
|
77
|
-
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
78
|
-
timeZone: timezone,
|
|
79
|
-
calendar: 'iso8601',
|
|
80
|
-
numberingSystem: 'latn',
|
|
81
|
-
year: 'numeric',
|
|
82
|
-
month: '2-digit',
|
|
83
|
-
day: '2-digit',
|
|
84
|
-
hour: '2-digit',
|
|
85
|
-
minute: '2-digit',
|
|
86
|
-
second: '2-digit',
|
|
87
|
-
hourCycle: 'h23',
|
|
88
|
-
});
|
|
89
|
-
DATE_TIME_FORMATTERS.set(timezone, formatter);
|
|
90
|
-
return formatter;
|
|
91
|
-
}
|
|
92
|
-
catch (_a) {
|
|
93
|
-
return fallback !== null && fallback !== void 0 ? fallback : createDateTimeFormatter(DEFAULT_TIMEZONE);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function componentsAt(timestamp, formatter) {
|
|
97
|
-
const parts = formatter.formatToParts(new Date(timestamp));
|
|
98
|
-
function part(type) {
|
|
99
|
-
var _a;
|
|
100
|
-
return Number((_a = parts.find((entry) => entry.type === type)) === null || _a === void 0 ? void 0 : _a.value);
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
year: part('year'),
|
|
104
|
-
month: part('month'),
|
|
105
|
-
day: part('day'),
|
|
106
|
-
hour: part('hour'),
|
|
107
|
-
minute: part('minute'),
|
|
108
|
-
second: part('second'),
|
|
109
|
-
millisecond: new Date(timestamp).getUTCMilliseconds(),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function componentsAsUtcTimestamp({ year, month, day, hour = 0, minute = 0, second = 0, millisecond = 0, }) {
|
|
113
|
-
const date = new Date(0);
|
|
114
|
-
date.setUTCFullYear(year, month - 1, day);
|
|
115
|
-
date.setUTCHours(hour, minute, second, millisecond);
|
|
116
|
-
return date.getTime();
|
|
117
|
-
}
|
|
118
|
-
/** Resolves a zoned wall clock to an instant, including daylight-saving offsets. */
|
|
119
|
-
function timestampForWallClock(components, formatter) {
|
|
120
|
-
const target = componentsAsUtcTimestamp(components);
|
|
121
|
-
let timestamp = target;
|
|
122
|
-
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
123
|
-
const adjustment = target - componentsAsUtcTimestamp(componentsAt(timestamp, formatter));
|
|
124
|
-
if (adjustment === 0)
|
|
125
|
-
return timestamp;
|
|
126
|
-
timestamp += adjustment;
|
|
127
|
-
}
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
function dateSortValueAt(timestamp, formatter) {
|
|
131
|
-
const value = dateSortValue(componentsAt(timestamp, formatter));
|
|
132
|
-
return value ? Object.assign(Object.assign({}, value), { time: timestamp }) : null;
|
|
133
|
-
}
|
|
134
|
-
function parseFixedDateTime(value, formatter) {
|
|
135
|
-
if (parseDateTimeComponents(value.replace(EXPLICIT_TIMEZONE_PATTERN, '')) === null)
|
|
136
|
-
return null;
|
|
137
|
-
const timestamp = Date.parse(value);
|
|
138
|
-
return Number.isNaN(timestamp) ? null : dateSortValueAt(timestamp, formatter);
|
|
139
|
-
}
|
|
140
|
-
function parseZonedFloatingDateTime(value, sourceFormatter, accountFormatter) {
|
|
141
|
-
const components = parseDateTimeComponents(value);
|
|
142
|
-
if (!components)
|
|
143
|
-
return null;
|
|
144
|
-
const timestamp = timestampForWallClock(components, sourceFormatter);
|
|
145
|
-
return timestamp === null ? null : dateSortValueAt(timestamp, accountFormatter);
|
|
146
|
-
}
|
|
147
|
-
function parseTaskDate(value, formatter, timezone) {
|
|
148
|
-
var _a;
|
|
149
|
-
return ((_a = parseDateOnly(value)) !== null && _a !== void 0 ? _a : (EXPLICIT_TIMEZONE_PATTERN.test(value)
|
|
150
|
-
? parseFixedDateTime(value, formatter)
|
|
151
|
-
: parseZonedFloatingDateTime(value, timezone ? createDateTimeFormatter(timezone, formatter) : formatter, formatter)));
|
|
152
|
-
}
|
|
153
|
-
function compareNullable(a, b, compare) {
|
|
154
|
-
if (a === null || b === null) {
|
|
155
|
-
if (a === b)
|
|
156
|
-
return 0;
|
|
157
|
-
return a === null ? 1 : -1;
|
|
158
|
-
}
|
|
159
|
-
return compare(a, b);
|
|
160
|
-
}
|
|
161
|
-
function compareDateValues(left, right) {
|
|
162
|
-
return (compareNumber(left.day, right.day) ||
|
|
163
|
-
compareNumber(left.kind, right.kind) ||
|
|
164
|
-
compareNumber(left.time, right.time));
|
|
165
|
-
}
|
|
166
|
-
function compareDate(a, b) {
|
|
167
|
-
return compareNullable(a, b, compareDateValues);
|
|
168
|
-
}
|
|
169
|
-
function compareOptionalNumber(a, b) {
|
|
170
|
-
return compareNullable(a, b, compareNumber);
|
|
171
|
-
}
|
|
172
|
-
function compareOptionalText(a, b, collator) {
|
|
173
|
-
return compareNullable(a, b, (left, right) => collator.compare(left, right));
|
|
174
|
-
}
|
|
175
|
-
function prepareTasks(tasks, context, { formatter, resolveAssignee }) {
|
|
176
|
-
return tasks.map((task, index) => {
|
|
177
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
178
|
-
const due = task.due
|
|
179
|
-
? parseTaskDate((_a = task.due.datetime) !== null && _a !== void 0 ? _a : task.due.date, formatter, task.due.timezone)
|
|
180
|
-
: null;
|
|
181
|
-
const deadline = task.deadline ? parseTaskDate(task.deadline.date, formatter) : null;
|
|
182
|
-
return {
|
|
183
|
-
task,
|
|
184
|
-
index,
|
|
185
|
-
due,
|
|
186
|
-
deadline,
|
|
187
|
-
schedule: due !== null && due !== void 0 ? due : deadline,
|
|
188
|
-
added: task.addedAt && !Number.isNaN(task.addedAt.getTime())
|
|
189
|
-
? task.addedAt.getTime()
|
|
190
|
-
: null,
|
|
191
|
-
project: (_c = (_b = context.projectOrder) === null || _b === void 0 ? void 0 : _b.get(task.projectId)) !== null && _c !== void 0 ? _c : null,
|
|
192
|
-
workspace: (_e = (_d = context.workspaceOrder) === null || _d === void 0 ? void 0 : _d.get(task.projectId)) !== null && _e !== void 0 ? _e : null,
|
|
193
|
-
assignee: resolveAssignee ? ((_g = (_f = context.assigneeName) === null || _f === void 0 ? void 0 : _f.call(context, task)) !== null && _g !== void 0 ? _g : null) : null,
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
function comparePriorityFirst(a, b) {
|
|
198
|
-
const common = compareNumber(b.task.priority, a.task.priority) ||
|
|
199
|
-
compareDate(a.due, b.due) ||
|
|
200
|
-
compareDate(a.deadline, b.deadline);
|
|
201
|
-
if (common !== 0)
|
|
202
|
-
return common;
|
|
203
|
-
const project = compareOptionalNumber(a.project, b.project);
|
|
204
|
-
if (project !== 0)
|
|
205
|
-
return project;
|
|
206
|
-
if (a.task.projectId === b.task.projectId) {
|
|
207
|
-
return compareNumber(a.task.childOrder, b.task.childOrder);
|
|
208
|
-
}
|
|
209
|
-
return 0;
|
|
210
|
-
}
|
|
211
|
-
function compareDateFirst(a, b) {
|
|
212
|
-
return (compareDate(a.schedule, b.schedule) ||
|
|
213
|
-
compareNumber(b.task.priority, a.task.priority) ||
|
|
214
|
-
compareDate(a.deadline, b.deadline) ||
|
|
215
|
-
compareNumber(a.task.dayOrder, b.task.dayOrder) ||
|
|
216
|
-
compareOptionalNumber(a.added, b.added));
|
|
217
|
-
}
|
|
218
|
-
function compareDefault(a, b, defaultOrder) {
|
|
219
|
-
return defaultOrder === 'DATE_FIRST' ? compareDateFirst(a, b) : comparePriorityFirst(a, b);
|
|
220
|
-
}
|
|
221
|
-
function comparePrimary({ sortedBy, a, b, collator, }) {
|
|
222
|
-
switch (sortedBy) {
|
|
223
|
-
case 'ALPHABETICALLY':
|
|
224
|
-
return collator.compare(a.task.content, b.task.content);
|
|
225
|
-
case 'ASSIGNEE':
|
|
226
|
-
return compareOptionalText(a.assignee, b.assignee, collator);
|
|
227
|
-
case 'DUE_DATE':
|
|
228
|
-
return compareDate(a.due, b.due);
|
|
229
|
-
case 'DEADLINE':
|
|
230
|
-
return compareDate(a.deadline, b.deadline);
|
|
231
|
-
case 'ADDED_DATE':
|
|
232
|
-
return compareOptionalNumber(a.added, b.added);
|
|
233
|
-
case 'PRIORITY':
|
|
234
|
-
return compareNumber(a.task.priority, b.task.priority);
|
|
235
|
-
case 'PROJECT':
|
|
236
|
-
return compareOptionalNumber(a.project, b.project);
|
|
237
|
-
case 'WORKSPACE':
|
|
238
|
-
return compareOptionalNumber(a.workspace, b.workspace);
|
|
239
|
-
case 'MANUAL':
|
|
240
|
-
return 0;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function defaultSortOrder(sortedBy) {
|
|
244
|
-
return sortedBy === 'PRIORITY' ? 'DESC' : 'ASC';
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Sorts the supplied tasks using Todoist view-ordering rules.
|
|
248
|
-
*
|
|
249
|
-
* The function performs no I/O and always returns a new array. Exact project,
|
|
250
|
-
* workspace, assignee, localized text, and due-time ordering requires the
|
|
251
|
-
* corresponding context. Callers must sort each independent view section or
|
|
252
|
-
* group separately and preserve any subtask structure they render.
|
|
253
|
-
*
|
|
254
|
-
* This function sorts only the tasks supplied to it. Fetch every page first
|
|
255
|
-
* when globally correct ordering is required for a paginated query.
|
|
256
|
-
*/
|
|
257
|
-
function sortTasks(tasks, options, context = {}) {
|
|
258
|
-
var _a, _b, _c;
|
|
259
|
-
const locale = Array.isArray(context.locale)
|
|
260
|
-
? [...context.locale]
|
|
261
|
-
: ((_a = context.locale) !== null && _a !== void 0 ? _a : DEFAULT_LOCALE);
|
|
262
|
-
const collator = new Intl.Collator(locale, { sensitivity: 'base', numeric: true });
|
|
263
|
-
const formatter = createDateTimeFormatter((_b = context.timezone) !== null && _b !== void 0 ? _b : DEFAULT_TIMEZONE);
|
|
264
|
-
const sortedBy = options.sortedBy;
|
|
265
|
-
const prepared = prepareTasks(tasks, context, {
|
|
266
|
-
formatter,
|
|
267
|
-
resolveAssignee: sortedBy === 'ASSIGNEE',
|
|
268
|
-
});
|
|
269
|
-
const direction = sortedBy && sortedBy !== 'MANUAL' ? ((_c = options.sortOrder) !== null && _c !== void 0 ? _c : defaultSortOrder(sortedBy)) : null;
|
|
270
|
-
const directionMultiplier = direction === 'DESC' ? -1 : 1;
|
|
271
|
-
return prepared
|
|
272
|
-
.sort((a, b) => {
|
|
273
|
-
if (sortedBy && sortedBy !== 'MANUAL') {
|
|
274
|
-
const primary = comparePrimary({ sortedBy, a, b, collator }) * directionMultiplier;
|
|
275
|
-
if (primary !== 0)
|
|
276
|
-
return primary;
|
|
277
|
-
}
|
|
278
|
-
return compareDefault(a, b, options.defaultOrder) || compareNumber(a.index, b.index);
|
|
279
|
-
})
|
|
280
|
-
.map(({ task }) => task);
|
|
281
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addUncompletablePrefix = addUncompletablePrefix;
|
|
4
|
-
exports.removeUncompletablePrefix = removeUncompletablePrefix;
|
|
5
|
-
exports.hasUncompletablePrefix = hasUncompletablePrefix;
|
|
6
|
-
exports.processTaskContent = processTaskContent;
|
|
7
|
-
const UNCOMPLETABLE_PREFIX = '* ';
|
|
8
|
-
/**
|
|
9
|
-
* Adds the uncompletable prefix (* ) to task content if not already present
|
|
10
|
-
* @param content - The task content
|
|
11
|
-
* @returns Content with uncompletable prefix added
|
|
12
|
-
*/
|
|
13
|
-
function addUncompletablePrefix(content) {
|
|
14
|
-
if (content.startsWith(UNCOMPLETABLE_PREFIX)) {
|
|
15
|
-
return content;
|
|
16
|
-
}
|
|
17
|
-
return UNCOMPLETABLE_PREFIX + content;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Removes the uncompletable prefix (* ) from task content if present
|
|
21
|
-
* @param content - The task content
|
|
22
|
-
* @returns Content with uncompletable prefix removed
|
|
23
|
-
*/
|
|
24
|
-
function removeUncompletablePrefix(content) {
|
|
25
|
-
if (content.startsWith(UNCOMPLETABLE_PREFIX)) {
|
|
26
|
-
return content.slice(UNCOMPLETABLE_PREFIX.length);
|
|
27
|
-
}
|
|
28
|
-
return content;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Checks if task content has the uncompletable prefix (* )
|
|
32
|
-
* @param content - The task content
|
|
33
|
-
* @returns True if content starts with uncompletable prefix
|
|
34
|
-
*/
|
|
35
|
-
function hasUncompletablePrefix(content) {
|
|
36
|
-
return content.startsWith(UNCOMPLETABLE_PREFIX);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Processes task content based on isUncompletable flag, with content prefix taking precedence
|
|
40
|
-
* @param content - The original task content
|
|
41
|
-
* @param isUncompletable - Optional flag to make task uncompletable
|
|
42
|
-
* @returns Processed content
|
|
43
|
-
*
|
|
44
|
-
* Logic:
|
|
45
|
-
* - If content already has * prefix, task is uncompletable regardless of flag
|
|
46
|
-
* - If content doesn't have * prefix and isUncompletable is true, add the prefix
|
|
47
|
-
* - If isUncompletable is undefined or false (and no prefix), leave content unchanged
|
|
48
|
-
*/
|
|
49
|
-
function processTaskContent(content, isUncompletable) {
|
|
50
|
-
// Content prefix takes precedence - if already has prefix, keep it
|
|
51
|
-
if (hasUncompletablePrefix(content)) {
|
|
52
|
-
return content;
|
|
53
|
-
}
|
|
54
|
-
// If content doesn't have prefix and user wants uncompletable, add it
|
|
55
|
-
if (isUncompletable === true) {
|
|
56
|
-
return addUncompletablePrefix(content);
|
|
57
|
-
}
|
|
58
|
-
// Otherwise, leave content unchanged
|
|
59
|
-
return content;
|
|
60
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatDateToYYYYMMDD = formatDateToYYYYMMDD;
|
|
4
|
-
exports.getTaskUrl = getTaskUrl;
|
|
5
|
-
exports.getProjectUrl = getProjectUrl;
|
|
6
|
-
exports.getSectionUrl = getSectionUrl;
|
|
7
|
-
const endpoints_1 = require("../consts/endpoints");
|
|
8
|
-
/**
|
|
9
|
-
* Formats a Date object to YYYY-MM-DD string format.
|
|
10
|
-
*
|
|
11
|
-
* @internal
|
|
12
|
-
* @param date The Date object to format.
|
|
13
|
-
* @returns The formatted date string in YYYY-MM-DD format.
|
|
14
|
-
*/
|
|
15
|
-
function formatDateToYYYYMMDD(date) {
|
|
16
|
-
const year = date.getFullYear();
|
|
17
|
-
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
18
|
-
const day = String(date.getDate()).padStart(2, '0');
|
|
19
|
-
return `${year}-${month}-${day}`;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Generate the URL for a given task.
|
|
23
|
-
*
|
|
24
|
-
* @param taskId The ID of the task.
|
|
25
|
-
* @param content The content of the task.
|
|
26
|
-
* @returns The URL string for the task view.
|
|
27
|
-
*/
|
|
28
|
-
function getTaskUrl(taskId, content) {
|
|
29
|
-
const slug = content ? slugify(content) : undefined;
|
|
30
|
-
const path = slug ? `${slug}-${taskId}` : taskId;
|
|
31
|
-
return `${endpoints_1.TODOIST_WEB_URI}/task/${path}`;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Generate the URL for a given project.
|
|
35
|
-
*
|
|
36
|
-
* @param projectId The ID of the project.
|
|
37
|
-
* @param name The name of the project.
|
|
38
|
-
* @returns The URL string for the project view.
|
|
39
|
-
*/
|
|
40
|
-
function getProjectUrl(projectId, name) {
|
|
41
|
-
const slug = name ? slugify(name) : undefined;
|
|
42
|
-
const path = slug ? `${slug}-${projectId}` : projectId;
|
|
43
|
-
return `${endpoints_1.TODOIST_WEB_URI}/project/${path}`;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Generate the URL for a given section.
|
|
47
|
-
*
|
|
48
|
-
* @param sectionId The ID of the section.
|
|
49
|
-
* @param name The name of the section.
|
|
50
|
-
* @returns The URL string for the section view.
|
|
51
|
-
*/
|
|
52
|
-
function getSectionUrl(sectionId, name) {
|
|
53
|
-
const slug = name ? slugify(name) : undefined;
|
|
54
|
-
const path = slug ? `${slug}-${sectionId}` : sectionId;
|
|
55
|
-
return `${endpoints_1.TODOIST_WEB_URI}/section/${path}`;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Slugify function borrowed from Django.
|
|
59
|
-
*
|
|
60
|
-
* @param value The string to slugify.
|
|
61
|
-
* @returns The slugified string.
|
|
62
|
-
*/
|
|
63
|
-
function slugify(value) {
|
|
64
|
-
// Convert to ASCII
|
|
65
|
-
let result = value.normalize('NFKD').replace(/[\u0300-\u036f]/g, '');
|
|
66
|
-
// Remove non-ASCII characters
|
|
67
|
-
result = result.replace(/[^\x20-\x7E]/g, '');
|
|
68
|
-
// Convert to lowercase and replace non-alphanumeric characters with dashes
|
|
69
|
-
result = result.toLowerCase().replace(/[^\w\s-]/g, '');
|
|
70
|
-
// Replace spaces and repeated dashes with single dashes
|
|
71
|
-
result = result.replace(/[-\s]+/g, '-');
|
|
72
|
-
// Strip dashes from the beginning and end
|
|
73
|
-
return result.replace(/^-+|-+$/g, '');
|
|
74
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateFolder = exports.validateCollaboratorStateArray = exports.validateCollaboratorState = exports.validateCollaboratorArray = exports.validateCollaborator = exports.validateFilterArray = exports.validateFilter = exports.validateMovedIdArray = exports.validateMovedId = exports.validateIdMappingArray = exports.validateIdMapping = exports.validateBackupArray = exports.validateBackup = exports.validateWorkspaceInsights = exports.validateProjectProgress = exports.validateProjectHealthContext = exports.validateProjectHealth = exports.validateProjectActivityStats = exports.validateWorkspaceUserTaskArray = exports.validateWorkspaceUserTask = exports.validateMemberActivityInfoArray = exports.validateMemberActivityInfo = exports.validateWorkspaceArray = exports.validateWorkspace = exports.validateJoinWorkspaceResult = exports.validateWorkspacePlanDetails = exports.validateWorkspaceInvitationArray = exports.validateWorkspaceInvitation = exports.validateWorkspaceUserArray = exports.validateWorkspaceUser = exports.validateAttachment = exports.validateActivityEventArray = exports.validateActivityEvent = exports.validateCurrentUser = exports.validateProductivityStats = exports.validateUserArray = exports.validateUser = exports.validateCommentArray = exports.validateComment = exports.validateLabelArray = exports.validateLabel = exports.validateSectionArray = exports.validateSection = exports.validateWorkspaceProjectArray = exports.validateWorkspaceProject = exports.validateProjectArray = exports.validateProject = exports.validateTaskArray = exports.validateTask = exports.IdSchema = void 0;
|
|
5
|
-
exports.validateUiExtensionArray = exports.validateUiExtension = exports.validateUserAuthorizationArray = exports.validateUserAuthorization = exports.validateAppInstallationArray = exports.validateAppInstallation = exports.validateAppWebhook = exports.validateAppByDistributionToken = exports.validateAppDistributionToken = exports.validateAppTestToken = exports.validateAppVerificationToken = exports.validateAppSecrets = exports.validateAppWithUserCount = exports.validateAppArray = exports.validateApp = exports.validateSuggestionArray = exports.validateSuggestion = exports.validateUserSettings = exports.validateSyncUser = exports.validateSyncWorkspaceArray = exports.validateSyncWorkspace = exports.validateLiveNotificationArray = exports.validateLiveNotification = exports.validateUserPlanLimits = exports.validateProjectViewOptionsDefaultsArray = exports.validateProjectViewOptionsDefaults = exports.validateViewOptionsArray = exports.validateViewOptions = exports.validateCompletedInfoArray = exports.validateCompletedInfo = exports.validateLocationReminderArray = exports.validateLocationReminder = exports.validateReminderArray = exports.validateReminder = exports.validateCalendarAccountArray = exports.validateCalendarAccount = exports.validateCalendarArray = exports.validateCalendar = exports.validateWorkspaceFilterArray = exports.validateWorkspaceFilter = exports.validateTooltips = exports.validateNoteArray = exports.validateNote = exports.validatePricing = exports.validatePrices = exports.validateProPlanDetails = exports.validateSubscriptionInfo = exports.validateFolderArray = void 0;
|
|
6
|
-
exports.parseSyncResponse = parseSyncResponse;
|
|
7
|
-
const zod_1 = require("zod");
|
|
8
|
-
const types_1 = require("../types/activity/types");
|
|
9
|
-
const types_2 = require("../types/apps/types");
|
|
10
|
-
const types_3 = require("../types/backups/types");
|
|
11
|
-
const types_4 = require("../types/billing/types");
|
|
12
|
-
const types_5 = require("../types/comments/types");
|
|
13
|
-
const types_6 = require("../types/id-mappings/types");
|
|
14
|
-
const types_7 = require("../types/insights/types");
|
|
15
|
-
const types_8 = require("../types/labels/types");
|
|
16
|
-
const types_9 = require("../types/productivity/types");
|
|
17
|
-
const types_10 = require("../types/projects/types");
|
|
18
|
-
const types_11 = require("../types/sections/types");
|
|
19
|
-
const response_1 = require("../types/sync/response");
|
|
20
|
-
const types_12 = require("../types/tasks/types");
|
|
21
|
-
const types_13 = require("../types/ui-extensions/types");
|
|
22
|
-
const types_14 = require("../types/users/types");
|
|
23
|
-
const types_15 = require("../types/workspaces/types");
|
|
24
|
-
const resources_1 = require("../types/sync/resources");
|
|
25
|
-
function createValidator(schema) {
|
|
26
|
-
return {
|
|
27
|
-
validate: (input) => schema.parse(input),
|
|
28
|
-
validateArray: (input) => zod_1.z.array(schema).parse(input),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
const TMP_ID_MESSAGE = 'This looks like a client-side placeholder — wait for sync to complete before calling the API.';
|
|
32
|
-
exports.IdSchema = zod_1.z
|
|
33
|
-
.string()
|
|
34
|
-
.min(1)
|
|
35
|
-
.refine((id) => !id.startsWith('tmp-'), { message: TMP_ID_MESSAGE });
|
|
36
|
-
// Entity validators
|
|
37
|
-
_a = createValidator(types_12.TaskSchema), exports.validateTask = _a.validate, exports.validateTaskArray = _a.validateArray;
|
|
38
|
-
/**
|
|
39
|
-
* Validates and parses a project input.
|
|
40
|
-
* @param input The input to validate
|
|
41
|
-
* @returns A validated project (either PersonalProject or WorkspaceProject)
|
|
42
|
-
*/
|
|
43
|
-
_b = createValidator(types_10.ProjectSchema), exports.validateProject = _b.validate, exports.validateProjectArray = _b.validateArray;
|
|
44
|
-
_c = createValidator(types_10.WorkspaceProjectSchema), exports.validateWorkspaceProject = _c.validate, exports.validateWorkspaceProjectArray = _c.validateArray;
|
|
45
|
-
_d = createValidator(types_11.SectionSchema), exports.validateSection = _d.validate, exports.validateSectionArray = _d.validateArray;
|
|
46
|
-
_e = createValidator(types_8.LabelSchema), exports.validateLabel = _e.validate, exports.validateLabelArray = _e.validateArray;
|
|
47
|
-
_f = createValidator(types_5.CommentSchema), exports.validateComment = _f.validate, exports.validateCommentArray = _f.validateArray;
|
|
48
|
-
_g = createValidator(types_14.UserSchema), exports.validateUser = _g.validate, exports.validateUserArray = _g.validateArray;
|
|
49
|
-
exports.validateProductivityStats = createValidator(types_9.ProductivityStatsSchema).validate;
|
|
50
|
-
exports.validateCurrentUser = createValidator(types_14.CurrentUserSchema).validate;
|
|
51
|
-
_h = createValidator(types_1.ActivityEventSchema), exports.validateActivityEvent = _h.validate, exports.validateActivityEventArray = _h.validateArray;
|
|
52
|
-
exports.validateAttachment = createValidator(types_5.AttachmentSchema).validate;
|
|
53
|
-
_j = createValidator(types_15.WorkspaceUserSchema), exports.validateWorkspaceUser = _j.validate, exports.validateWorkspaceUserArray = _j.validateArray;
|
|
54
|
-
_k = createValidator(types_15.WorkspaceInvitationSchema), exports.validateWorkspaceInvitation = _k.validate, exports.validateWorkspaceInvitationArray = _k.validateArray;
|
|
55
|
-
exports.validateWorkspacePlanDetails = createValidator(types_15.WorkspacePlanDetailsSchema).validate;
|
|
56
|
-
exports.validateJoinWorkspaceResult = createValidator(types_15.JoinWorkspaceResultSchema).validate;
|
|
57
|
-
_l = createValidator(types_15.WorkspaceSchema), exports.validateWorkspace = _l.validate, exports.validateWorkspaceArray = _l.validateArray;
|
|
58
|
-
_m = createValidator(types_15.MemberActivityInfoSchema), exports.validateMemberActivityInfo = _m.validate, exports.validateMemberActivityInfoArray = _m.validateArray;
|
|
59
|
-
_o = createValidator(types_15.WorkspaceUserTaskSchema), exports.validateWorkspaceUserTask = _o.validate, exports.validateWorkspaceUserTaskArray = _o.validateArray;
|
|
60
|
-
exports.validateProjectActivityStats = createValidator(types_7.ProjectActivityStatsSchema).validate;
|
|
61
|
-
exports.validateProjectHealth = createValidator(types_7.ProjectHealthSchema).validate;
|
|
62
|
-
exports.validateProjectHealthContext = createValidator(types_7.ProjectHealthContextSchema).validate;
|
|
63
|
-
exports.validateProjectProgress = createValidator(types_7.ProjectProgressSchema).validate;
|
|
64
|
-
exports.validateWorkspaceInsights = createValidator(types_7.WorkspaceInsightsSchema).validate;
|
|
65
|
-
_p = createValidator(types_3.BackupSchema), exports.validateBackup = _p.validate, exports.validateBackupArray = _p.validateArray;
|
|
66
|
-
_q = createValidator(types_6.IdMappingSchema), exports.validateIdMapping = _q.validate, exports.validateIdMappingArray = _q.validateArray;
|
|
67
|
-
_r = createValidator(types_6.MovedIdSchema), exports.validateMovedId = _r.validate, exports.validateMovedIdArray = _r.validateArray;
|
|
68
|
-
// Sync resource validators
|
|
69
|
-
_s = createValidator(resources_1.FilterSchema), exports.validateFilter = _s.validate, exports.validateFilterArray = _s.validateArray;
|
|
70
|
-
_t = createValidator(resources_1.CollaboratorSchema), exports.validateCollaborator = _t.validate, exports.validateCollaboratorArray = _t.validateArray;
|
|
71
|
-
_u = createValidator(resources_1.CollaboratorStateSchema), exports.validateCollaboratorState = _u.validate, exports.validateCollaboratorStateArray = _u.validateArray;
|
|
72
|
-
_v = createValidator(resources_1.FolderSchema), exports.validateFolder = _v.validate, exports.validateFolderArray = _v.validateArray;
|
|
73
|
-
// Billing validators
|
|
74
|
-
exports.validateSubscriptionInfo = createValidator(types_4.SubscriptionInfoSchema).validate;
|
|
75
|
-
exports.validateProPlanDetails = createValidator(types_4.ProPlanDetailsSchema).validate;
|
|
76
|
-
exports.validatePrices = createValidator(types_4.PricesResponseSchema).validate;
|
|
77
|
-
exports.validatePricing = createValidator(types_4.PricingResponseSchema).validate;
|
|
78
|
-
_w = createValidator(resources_1.NoteSchema), exports.validateNote = _w.validate, exports.validateNoteArray = _w.validateArray;
|
|
79
|
-
exports.validateTooltips = createValidator(resources_1.TooltipsSchema).validate;
|
|
80
|
-
_x = createValidator(resources_1.WorkspaceFilterSchema), exports.validateWorkspaceFilter = _x.validate, exports.validateWorkspaceFilterArray = _x.validateArray;
|
|
81
|
-
_y = createValidator(resources_1.CalendarSchema), exports.validateCalendar = _y.validate, exports.validateCalendarArray = _y.validateArray;
|
|
82
|
-
_z = createValidator(resources_1.CalendarAccountSchema), exports.validateCalendarAccount = _z.validate, exports.validateCalendarAccountArray = _z.validateArray;
|
|
83
|
-
_0 = createValidator(resources_1.ReminderSchema), exports.validateReminder = _0.validate, exports.validateReminderArray = _0.validateArray;
|
|
84
|
-
_1 = createValidator(resources_1.LocationReminderSchema), exports.validateLocationReminder = _1.validate, exports.validateLocationReminderArray = _1.validateArray;
|
|
85
|
-
_2 = createValidator(resources_1.CompletedInfoSchema), exports.validateCompletedInfo = _2.validate, exports.validateCompletedInfoArray = _2.validateArray;
|
|
86
|
-
_3 = createValidator(resources_1.ViewOptionsSchema), exports.validateViewOptions = _3.validate, exports.validateViewOptionsArray = _3.validateArray;
|
|
87
|
-
_4 = createValidator(resources_1.ProjectViewOptionsDefaultsSchema), exports.validateProjectViewOptionsDefaults = _4.validate, exports.validateProjectViewOptionsDefaultsArray = _4.validateArray;
|
|
88
|
-
exports.validateUserPlanLimits = createValidator(resources_1.UserPlanLimitsSchema).validate;
|
|
89
|
-
_5 = createValidator(resources_1.LiveNotificationSchema), exports.validateLiveNotification = _5.validate, exports.validateLiveNotificationArray = _5.validateArray;
|
|
90
|
-
_6 = createValidator(resources_1.SyncWorkspaceSchema), exports.validateSyncWorkspace = _6.validate, exports.validateSyncWorkspaceArray = _6.validateArray;
|
|
91
|
-
exports.validateSyncUser = createValidator(resources_1.SyncUserSchema).validate;
|
|
92
|
-
exports.validateUserSettings = createValidator(resources_1.UserSettingsSchema).validate;
|
|
93
|
-
_7 = createValidator(resources_1.SuggestionSchema), exports.validateSuggestion = _7.validate, exports.validateSuggestionArray = _7.validateArray;
|
|
94
|
-
function parseSyncResponse(raw) {
|
|
95
|
-
return response_1.SyncResponseSchema.parse(raw);
|
|
96
|
-
}
|
|
97
|
-
// App management validators
|
|
98
|
-
_8 = createValidator(types_2.AppSchema), exports.validateApp = _8.validate, exports.validateAppArray = _8.validateArray;
|
|
99
|
-
exports.validateAppWithUserCount = createValidator(types_2.AppWithUserCountSchema).validate;
|
|
100
|
-
exports.validateAppSecrets = createValidator(types_2.AppSecretsSchema).validate;
|
|
101
|
-
exports.validateAppVerificationToken = createValidator(types_2.AppVerificationTokenSchema).validate;
|
|
102
|
-
exports.validateAppTestToken = createValidator(types_2.AppTestTokenSchema).validate;
|
|
103
|
-
exports.validateAppDistributionToken = createValidator(types_2.AppDistributionTokenSchema).validate;
|
|
104
|
-
exports.validateAppByDistributionToken = createValidator(types_2.AppByDistributionTokenSchema).validate;
|
|
105
|
-
exports.validateAppWebhook = createValidator(types_2.AppWebhookSchema).validate;
|
|
106
|
-
_9 = createValidator(types_2.AppInstallationSchema), exports.validateAppInstallation = _9.validate, exports.validateAppInstallationArray = _9.validateArray;
|
|
107
|
-
_10 = createValidator(types_2.UserAuthorizationSchema), exports.validateUserAuthorization = _10.validate, exports.validateUserAuthorizationArray = _10.validateArray;
|
|
108
|
-
_11 = createValidator(types_13.UiExtensionSchema), exports.validateUiExtension = _11.validate, exports.validateUiExtensionArray = _11.validateArray;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isActiveViewOption = isActiveViewOption;
|
|
4
|
-
exports.findViewOptions = findViewOptions;
|
|
5
|
-
/** Returns whether saved view options are active rather than a deletion tombstone. */
|
|
6
|
-
function isActiveViewOption(options) {
|
|
7
|
-
return options.isDeleted !== true;
|
|
8
|
-
}
|
|
9
|
-
/** Finds the active saved options for one logical view. */
|
|
10
|
-
function findViewOptions(options, args) {
|
|
11
|
-
var _a;
|
|
12
|
-
const targetObjectId = (_a = args.objectId) !== null && _a !== void 0 ? _a : null;
|
|
13
|
-
return options.find((entry) => {
|
|
14
|
-
var _a;
|
|
15
|
-
return isActiveViewOption(entry) &&
|
|
16
|
-
((_a = entry.objectId) !== null && _a !== void 0 ? _a : null) === targetObjectId &&
|
|
17
|
-
args.viewTypes.includes(entry.viewType);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseWebhookPayload = parseWebhookPayload;
|
|
4
|
-
exports.verifyWebhookSignature = verifyWebhookSignature;
|
|
5
|
-
const types_1 = require("../types/webhooks/types");
|
|
6
|
-
const case_conversion_1 = require("./case-conversion");
|
|
7
|
-
/**
|
|
8
|
-
* Parses an incoming webhook request body into a typed payload.
|
|
9
|
-
*
|
|
10
|
-
* The backend sends snake_case keys (e.g. `event_name`, `user_id`, `added_at`);
|
|
11
|
-
* this converts them to camelCase and validates against
|
|
12
|
-
* {@link WebhookPayloadSchema}. Event-specific `eventData` is returned as
|
|
13
|
-
* `unknown` for events that are not yet narrowed per-resource.
|
|
14
|
-
*
|
|
15
|
-
* Pass the parsed JSON body (or any unknown value) — validation throws on
|
|
16
|
-
* unexpected shape.
|
|
17
|
-
*/
|
|
18
|
-
function parseWebhookPayload(raw) {
|
|
19
|
-
return types_1.WebhookPayloadSchema.parse((0, case_conversion_1.camelCaseKeys)(raw));
|
|
20
|
-
}
|
|
21
|
-
const encoder = new TextEncoder();
|
|
22
|
-
function base64ToBytes(base64) {
|
|
23
|
-
const binary = atob(base64);
|
|
24
|
-
const bytes = new Uint8Array(binary.length);
|
|
25
|
-
for (let i = 0; i < binary.length; i++) {
|
|
26
|
-
bytes[i] = binary.charCodeAt(i);
|
|
27
|
-
}
|
|
28
|
-
return bytes;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Verifies a webhook request's HMAC signature.
|
|
32
|
-
*
|
|
33
|
-
* Todoist signs webhook deliveries with an HMAC-SHA256 of the raw request body
|
|
34
|
-
* using the app's `client_secret` as the key, base64-encoded in the
|
|
35
|
-
* `X-Todoist-Hmac-SHA256` header.
|
|
36
|
-
*
|
|
37
|
-
* Uses the Web Crypto API (`crypto.subtle`), which is available in Node ≥ 20,
|
|
38
|
-
* modern browsers, React Native (with polyfills), and edge runtimes. The
|
|
39
|
-
* comparison is constant-time.
|
|
40
|
-
*
|
|
41
|
-
* @returns `true` when the signature is valid, `false` otherwise. Never throws
|
|
42
|
-
* on malformed input.
|
|
43
|
-
*/
|
|
44
|
-
async function verifyWebhookSignature({ rawBody, signature, clientSecret, }) {
|
|
45
|
-
let provided;
|
|
46
|
-
try {
|
|
47
|
-
provided = base64ToBytes(signature);
|
|
48
|
-
}
|
|
49
|
-
catch (_a) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
const key = await crypto.subtle.importKey('raw', encoder.encode(clientSecret), { name: 'HMAC', hash: 'SHA-256' }, false, ['verify']);
|
|
53
|
-
const body = typeof rawBody === 'string' ? encoder.encode(rawBody) : rawBody;
|
|
54
|
-
try {
|
|
55
|
-
return await crypto.subtle.verify('HMAC', key, provided, body);
|
|
56
|
-
}
|
|
57
|
-
catch (_b) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
}
|