@doist/todoist-sdk 9.4.0 → 9.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.
- package/dist/cjs/test-utils/webhook-fixtures.js +32 -0
- package/dist/cjs/types/sections/types.js +8 -6
- package/dist/cjs/types/webhooks/comments.js +96 -0
- package/dist/cjs/types/webhooks/index.js +4 -0
- package/dist/cjs/types/webhooks/labels.js +54 -0
- package/dist/cjs/types/webhooks/projects.js +36 -0
- package/dist/cjs/types/webhooks/sections.js +48 -0
- package/dist/cjs/types/webhooks/types.js +40 -5
- package/dist/esm/test-utils/webhook-fixtures.js +26 -0
- package/dist/esm/types/sections/types.js +7 -5
- package/dist/esm/types/webhooks/comments.js +93 -0
- package/dist/esm/types/webhooks/index.js +4 -0
- package/dist/esm/types/webhooks/labels.js +51 -0
- package/dist/esm/types/webhooks/projects.js +33 -0
- package/dist/esm/types/webhooks/sections.js +45 -0
- package/dist/esm/types/webhooks/types.js +40 -5
- package/dist/types/test-utils/webhook-fixtures.d.ts +13 -0
- package/dist/types/types/sections/types.d.ts +18 -0
- package/dist/types/types/webhooks/comments.d.ts +1600 -0
- package/dist/types/types/webhooks/index.d.ts +4 -0
- package/dist/types/types/webhooks/labels.d.ts +160 -0
- package/dist/types/types/webhooks/projects.d.ts +345 -0
- package/dist/types/types/webhooks/sections.d.ts +335 -0
- package/dist/types/types/webhooks/types.d.ts +1635 -36
- package/package.json +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getSectionUrl } from '../../utils/url-helpers.js';
|
|
3
|
+
import { SectionBaseSchema } from '../sections/types.js';
|
|
4
|
+
import { BaseWebhookEnvelopeShape } from './envelope.js';
|
|
5
|
+
/**
|
|
6
|
+
* Enum-like object of section (`section:*`) webhook event names. Single
|
|
7
|
+
* source of truth for the discriminator values — `SECTION_WEBHOOK_EVENTS`
|
|
8
|
+
* and every `z.literal()` below derive from it.
|
|
9
|
+
*/
|
|
10
|
+
export const SectionWebhookEventEnum = {
|
|
11
|
+
Added: 'section:added',
|
|
12
|
+
Updated: 'section:updated',
|
|
13
|
+
Deleted: 'section:deleted',
|
|
14
|
+
Archived: 'section:archived',
|
|
15
|
+
Unarchived: 'section:unarchived',
|
|
16
|
+
};
|
|
17
|
+
/** Webhook events that carry a section as their `eventData`. */
|
|
18
|
+
export const SECTION_WEBHOOK_EVENTS = [
|
|
19
|
+
SectionWebhookEventEnum.Added,
|
|
20
|
+
SectionWebhookEventEnum.Updated,
|
|
21
|
+
SectionWebhookEventEnum.Deleted,
|
|
22
|
+
SectionWebhookEventEnum.Archived,
|
|
23
|
+
SectionWebhookEventEnum.Unarchived,
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* A section as delivered in a webhook payload.
|
|
27
|
+
*
|
|
28
|
+
* Reuses {@link SectionBaseSchema} and overrides `updatedAt` to tolerate
|
|
29
|
+
* payloads that deliver it as `null` or omit the key entirely — tombstones
|
|
30
|
+
* and never-updated sections come through without an `updated_at` value.
|
|
31
|
+
* The result is normalised to `Date | null` so consumers don't have to
|
|
32
|
+
* handle three shapes. Surfaces the computed `url` so the exposed shape
|
|
33
|
+
* matches {@link Section}.
|
|
34
|
+
*/
|
|
35
|
+
export const WebhookSectionSchema = SectionBaseSchema.extend({
|
|
36
|
+
updatedAt: z.coerce
|
|
37
|
+
.date()
|
|
38
|
+
.nullish()
|
|
39
|
+
.transform((value) => value !== null && value !== void 0 ? value : null),
|
|
40
|
+
}).transform((data) => (Object.assign(Object.assign({}, data), { url: getSectionUrl(data.id, data.name) })));
|
|
41
|
+
export const SectionAddedPayloadSchema = z.object(Object.assign(Object.assign({}, BaseWebhookEnvelopeShape), { eventName: z.literal(SectionWebhookEventEnum.Added), eventData: WebhookSectionSchema }));
|
|
42
|
+
export const SectionUpdatedPayloadSchema = z.object(Object.assign(Object.assign({}, BaseWebhookEnvelopeShape), { eventName: z.literal(SectionWebhookEventEnum.Updated), eventData: WebhookSectionSchema }));
|
|
43
|
+
export const SectionDeletedPayloadSchema = z.object(Object.assign(Object.assign({}, BaseWebhookEnvelopeShape), { eventName: z.literal(SectionWebhookEventEnum.Deleted), eventData: WebhookSectionSchema }));
|
|
44
|
+
export const SectionArchivedPayloadSchema = z.object(Object.assign(Object.assign({}, BaseWebhookEnvelopeShape), { eventName: z.literal(SectionWebhookEventEnum.Archived), eventData: WebhookSectionSchema }));
|
|
45
|
+
export const SectionUnarchivedPayloadSchema = z.object(Object.assign(Object.assign({}, BaseWebhookEnvelopeShape), { eventName: z.literal(SectionWebhookEventEnum.Unarchived), eventData: WebhookSectionSchema }));
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { WEBHOOK_EVENTS, WebhookEventSchema } from '../apps/types.js';
|
|
3
|
+
import { COMMENT_WEBHOOK_EVENTS, CommentAddedPayloadSchema, CommentDeletedPayloadSchema, CommentUpdatedPayloadSchema, } from './comments.js';
|
|
3
4
|
import { BaseWebhookEnvelopeShape } from './envelope.js';
|
|
5
|
+
import { LABEL_WEBHOOK_EVENTS, LabelAddedPayloadSchema, LabelDeletedPayloadSchema, LabelUpdatedPayloadSchema, } from './labels.js';
|
|
6
|
+
import { PROJECT_WEBHOOK_EVENTS, ProjectAddedPayloadSchema, ProjectArchivedPayloadSchema, ProjectDeletedPayloadSchema, ProjectUnarchivedPayloadSchema, ProjectUpdatedPayloadSchema, } from './projects.js';
|
|
7
|
+
import { SECTION_WEBHOOK_EVENTS, SectionAddedPayloadSchema, SectionArchivedPayloadSchema, SectionDeletedPayloadSchema, SectionUnarchivedPayloadSchema, SectionUpdatedPayloadSchema, } from './sections.js';
|
|
4
8
|
import { TASK_WEBHOOK_EVENTS, TaskAddedPayloadSchema, TaskCompletedPayloadSchema, TaskDeletedPayloadSchema, TaskUncompletedPayloadSchema, TaskUpdatedPayloadSchema, } from './tasks.js';
|
|
5
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Events whose payloads have been narrowed per resource. Each phase adds to
|
|
11
|
+
* this list; {@link UntypedWebhookPayloadSchema} below is derived by taking
|
|
12
|
+
* every {@link WebhookEvent} not present here.
|
|
13
|
+
*/
|
|
14
|
+
const TYPED_WEBHOOK_EVENTS = [
|
|
15
|
+
...TASK_WEBHOOK_EVENTS,
|
|
16
|
+
...COMMENT_WEBHOOK_EVENTS,
|
|
17
|
+
...LABEL_WEBHOOK_EVENTS,
|
|
18
|
+
...PROJECT_WEBHOOK_EVENTS,
|
|
19
|
+
...SECTION_WEBHOOK_EVENTS,
|
|
20
|
+
];
|
|
21
|
+
const untypedEventNames = WEBHOOK_EVENTS.filter((event) => !TYPED_WEBHOOK_EVENTS.includes(event));
|
|
6
22
|
/**
|
|
7
23
|
* A single branch covering every event whose payload has not yet been typed
|
|
8
24
|
* per resource. Follow-up PRs will replace slices of this with dedicated
|
|
9
|
-
* variants (
|
|
25
|
+
* variants (filters, reminders).
|
|
10
26
|
*/
|
|
11
27
|
export const UntypedWebhookPayloadSchema = z.object(Object.assign(Object.assign({}, BaseWebhookEnvelopeShape), { eventName: z.enum(untypedEventNames), eventData: z.unknown(), eventDataExtra: z.unknown().optional() }));
|
|
12
28
|
/**
|
|
@@ -16,9 +32,12 @@ export const UntypedWebhookPayloadSchema = z.object(Object.assign(Object.assign(
|
|
|
16
32
|
* (`item:added`) in the `event_name` field, so consumers using
|
|
17
33
|
* `parseWebhookPayload` receive camelCase fields directly.
|
|
18
34
|
*
|
|
19
|
-
* Typed today: `item:*` events carry a parsed {@link Task}
|
|
20
|
-
*
|
|
21
|
-
*
|
|
35
|
+
* Typed today: `item:*` events carry a parsed {@link Task}; `note:*` events
|
|
36
|
+
* carry a parsed comment (item-comment or project-comment); `label:*` events
|
|
37
|
+
* carry a parsed label; `project:*` events carry a parsed {@link Project}
|
|
38
|
+
* (personal or workspace); `section:*` events carry a parsed
|
|
39
|
+
* {@link WebhookSection}. Other events still expose `eventData` as
|
|
40
|
+
* `unknown`; they will be narrowed in follow-up PRs (filters, reminders).
|
|
22
41
|
*/
|
|
23
42
|
export const WebhookPayloadSchema = z.discriminatedUnion('eventName', [
|
|
24
43
|
TaskAddedPayloadSchema,
|
|
@@ -26,6 +45,22 @@ export const WebhookPayloadSchema = z.discriminatedUnion('eventName', [
|
|
|
26
45
|
TaskCompletedPayloadSchema,
|
|
27
46
|
TaskUncompletedPayloadSchema,
|
|
28
47
|
TaskDeletedPayloadSchema,
|
|
48
|
+
CommentAddedPayloadSchema,
|
|
49
|
+
CommentUpdatedPayloadSchema,
|
|
50
|
+
CommentDeletedPayloadSchema,
|
|
51
|
+
LabelAddedPayloadSchema,
|
|
52
|
+
LabelUpdatedPayloadSchema,
|
|
53
|
+
LabelDeletedPayloadSchema,
|
|
54
|
+
ProjectAddedPayloadSchema,
|
|
55
|
+
ProjectUpdatedPayloadSchema,
|
|
56
|
+
ProjectDeletedPayloadSchema,
|
|
57
|
+
ProjectArchivedPayloadSchema,
|
|
58
|
+
ProjectUnarchivedPayloadSchema,
|
|
59
|
+
SectionAddedPayloadSchema,
|
|
60
|
+
SectionUpdatedPayloadSchema,
|
|
61
|
+
SectionDeletedPayloadSchema,
|
|
62
|
+
SectionArchivedPayloadSchema,
|
|
63
|
+
SectionUnarchivedPayloadSchema,
|
|
29
64
|
UntypedWebhookPayloadSchema,
|
|
30
65
|
]);
|
|
31
66
|
export { WebhookEventSchema };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const CLIENT_SECRET = "test-client-secret";
|
|
2
|
+
/** HMAC-SHA256 signs a raw body with the test client secret (or an override). */
|
|
3
|
+
export declare function sign(body: string, secret?: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Snake_case task payload matching the v1 webhook wire shape.
|
|
6
|
+
*/
|
|
7
|
+
export declare function rawTask(overrides?: Record<string, unknown>): Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Wraps an event's `event_data` in the snake_case envelope the backend sends
|
|
10
|
+
* (initiator, version, timestamps, etc). `extra` passes extra top-level keys
|
|
11
|
+
* like `event_data_extra`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function envelope(event: string, eventData: unknown, extra?: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Raw section fields (the persisted shape). Exposed so schemas that extend
|
|
4
|
+
* or override a field — notably the webhook variant — can reuse the base
|
|
5
|
+
* without duplicating every field.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SectionBaseSchema: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
userId: z.ZodString;
|
|
10
|
+
projectId: z.ZodString;
|
|
11
|
+
addedAt: z.ZodCoercedDate<unknown>;
|
|
12
|
+
updatedAt: z.ZodCoercedDate<unknown>;
|
|
13
|
+
archivedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
|
|
14
|
+
name: z.ZodString;
|
|
15
|
+
sectionOrder: z.ZodNumber;
|
|
16
|
+
isArchived: z.ZodBoolean;
|
|
17
|
+
isDeleted: z.ZodBoolean;
|
|
18
|
+
isCollapsed: z.ZodBoolean;
|
|
19
|
+
}, z.core.$strip>;
|
|
2
20
|
export declare const SectionSchema: z.ZodPipe<z.ZodObject<{
|
|
3
21
|
id: z.ZodString;
|
|
4
22
|
userId: z.ZodString;
|