Skip to content

feat: add user-template write endpoints to TemplateClient#604

Draft
scottlovegrove wants to merge 4 commits into
scottl/templates-readfrom
scottl/templates-user-write
Draft

feat: add user-template write endpoints to TemplateClient#604
scottlovegrove wants to merge 4 commits into
scottl/templates-readfrom
scottl/templates-user-write

Conversation

@scottlovegrove
Copy link
Copy Markdown
Contributor

@scottlovegrove scottlovegrove commented May 15, 2026

Summary

Stacks on top of #603. Adds the full /templates/user/* surface to the SDK:

  • createUserTemplatePOST /templates/user
  • updateUserTemplate(id, args)PUT /templates/user/{id}
  • deleteUserTemplate(id)DELETE /templates/user/{id}
  • previewUserTemplateFromFilePOST /templates/user/preview_from_file (multipart)
  • createUserTemplateFromFilePOST /templates/user/import (multipart, accepts uploadedFileName from a prior preview)

updateUserTemplate / deleteUserTemplate validate templateId is non-empty before any network call and URL-encode the path segment.

Test plan

  • npm run check (oxlint + oxfmt) passes
  • npm test — 602 tests pass (9 new)
  • Tests cover JSON payloads (camelCase → snake_case conversion), URL-encoding of the path segment, empty-templateId rejection, multipart additional fields, and uploadedFileName pass-through

🤖 Generated with Claude Code

@scottlovegrove scottlovegrove self-assigned this May 15, 2026
Copy link
Copy Markdown
Member

@doistbot doistbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR successfully expands the SDK's TemplateClient by introducing the full suite of write and file-import endpoints for user templates. The thorough test coverage and careful Zod schema modeling provide a solid foundation for these new capabilities. There are just a few remaining details to refine, such as addressing a bug that prevents the file upload optimization from working, strengthening types with ColorKey and enums, centralizing the URL-encoding logic, and removing some duplication in the test mocks and argument interfaces.

Share FeedbackReview Logs

Comment thread src/clients/template-client.ts
Comment thread src/types/templates/types.ts Outdated
Comment thread src/consts/endpoints.ts Outdated
Comment thread src/todoist-api.templates.test.ts
Comment thread src/types/templates/requests.ts Outdated
Comment thread src/types/templates/requests.ts Outdated
Comment thread src/todoist-api.templates.test.ts
@scottlovegrove scottlovegrove force-pushed the scottl/templates-user-write branch from e17320e to 372d20a Compare May 17, 2026 13:50
scottlovegrove and others added 4 commits May 17, 2026 15:48
Adds createUserTemplate, updateUserTemplate, deleteUserTemplate,
previewUserTemplateFromFile, and createUserTemplateFromFile to the SDK,
exposing the full /templates/user/* surface for managing user-owned
templates. These endpoints are live but not in the public OpenAPI spec.

- Define UpdateUserTemplateResponseSchema (TemplateSchema extended with
  status: 'ok'), DeleteUserTemplateResponseSchema, and
  PreviewUserTemplateFromFileResponseSchema, all mirroring the server
  TypedDicts in todoist/apps/import_export/controllers/user_templates.py.
- createUserTemplate / createUserTemplateFromFile reuse the existing
  TemplateSchema validator since both return a plain Template.
- updateUserTemplate / deleteUserTemplate reject empty templateId before
  hitting the network and URL-encode the path segment.
- createUserTemplateFromFile forwards optional uploadedFileName so callers
  can chain preview → create without re-uploading the CSV.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The server returns items / notes / project_notes for /templates/user/preview_from_file,
matching the wire shape of /templates/import_into_project. The rest of the SDK exposes
those as tasks (items) and comments (notes), so PreviewUserTemplateFromFileResponseSchema
now does the same:

- items → tasks
- notes + project_notes → comments (concatenated; CommentSchema already accepts both
  task-scoped notes via itemId and project-scoped notes via projectId)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Move encodeURIComponent into getUserTemplateEndpoint so any future caller picks
  up the encoding automatically, and drop the now-redundant inline encoding in
  updateUserTemplate / deleteUserTemplate.
- Allow createUserTemplateFromFile to skip re-uploading when uploadedFileName is
  provided: make `file` optional, validate that at least one of file or
  uploadedFileName is set, and send a regular JSON POST (no multipart) when no
  file is supplied.
- Tighten PreviewUserTemplateFromFileResponseSchema.templateType to
  z.enum(TEMPLATE_TYPE_VALUES) to match TemplateSchema.
- Replace stringly-typed color: string | number with ColorKey | number across
  CreateUserTemplateArgs / UpdateUserTemplateArgs / CreateUserTemplateFromFileArgs.
- Extract a shared TemplateFileUpload alias (Pick<UploadFileArgs, 'file' | 'fileName'>)
  and reuse it across CreateProjectFromTemplateArgs, ImportTemplateIntoProjectArgs,
  PreviewUserTemplateFromFileArgs, and CreateUserTemplateFromFileArgs.
- Derive MOCK_TEMPLATE_CAMEL dynamically via camelCaseKeys(MOCK_TEMPLATE_API).
- Add tests for deleteUserTemplate URL-encoding, JSON-only import path
  (uploadedFileName without file), and the missing-input rejection.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove force-pushed the scottl/templates-user-write branch from 372d20a to 96099fe Compare May 17, 2026 14:48
@scottlovegrove scottlovegrove marked this pull request as draft May 22, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants