Skip to content

feat: add Twist→Comms URL migration helper#42

Merged
scottlovegrove merged 1 commit into
mainfrom
feat/twist-comms-url-migration
Jun 26, 2026
Merged

feat: add Twist→Comms URL migration helper#42
scottlovegrove merged 1 commit into
mainfrom
feat/twist-comms-url-migration

Conversation

@scottlovegrove

Copy link
Copy Markdown
Collaborator

Context

As part of the Twist→Comms migration, Twist's backend exposes POST https://twist.com/api/comms_migration/fetch_new_url, which maps an old twist.com URL to its equivalent Comms URL. This is useful for migration tooling (e.g. rewriting bookmarks/history — see reference gist).

The endpoint authenticates with a Twist token, not a Comms one, so it doesn't belong on CommsApi (constructed with a Comms token). It mirrors authentication.ts: standalone top-level functions that take their own token plus optional baseUrl / customFetch.

Changes

New src/migration.ts:

  • fetchNewCommsUrl({ oldUrl, twistToken }, options?)Promise<string> — POSTs to the endpoint via the existing request() helper (auto snake_case payload, camelCase response, Bearer auth, retries). Always throws CommsRequestError on non-2xx; not-migratable URLs surface as 400 invalid_url / 404 not_imported in error.responseData.error.code.
  • fetchNewCommsUrls({ oldUrls, twistToken }, options?)Promise<MigrationResult[]> — batch variant. Processes sequentially (the endpoint is rate-sensitive); a failure on one URL doesn't abort the run. Each result is { oldUrl, newUrl } or { oldUrl, error }, in input order.
  • MigrationOptions (baseUrl, customFetch) mirrors AuthOptions.

Exported from src/index.ts.

Verification

  • npx vitest run src/migration.test.ts → 8 passed (success + header/body assertion, missing new_url, 400/404/500, custom baseUrl, batch mixed success/failure, empty input)
  • npx tsc --noEmit → clean
  • oxlint → 0 warnings/errors; oxfmt → formatted

🤖 Generated with Claude Code

Adds standalone helpers that translate twist.com URLs to their Comms
equivalents via Twist's comms_migration/fetch_new_url endpoint. These
authenticate with a Twist (not Comms) token, so they live alongside
authentication.ts rather than on CommsApi.

- fetchNewCommsUrl: single URL, throws CommsRequestError on non-2xx
- fetchNewCommsUrls: batch, sequential, collects per-URL success/failure

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove self-assigned this Jun 26, 2026
@scottlovegrove scottlovegrove requested a review from amix June 26, 2026 16:51

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR adds a new src/migration.ts module with standalone helper functions (fetchNewCommsUrl and fetchNewCommsUrls) that map old Twist URLs to their Comms equivalents, mirroring the auth pattern in authentication.ts.

Few things worth tightening:

  • MigrationOptions currently duplicates AuthOptions exactly — consider aliasing it or extracting a shared request-options type so future transport options don't drift between the two standalone helper modules.

I also included a few optional follow-up notes in the details below.

Optional follow-up note (1)
  • P3 src/migration.ts:21: MigrationOptions is an exact copy of AuthOptions, so these two top-level helper modules now have to stay in sync by hand. Consider aliasing AuthOptions here (or extracting a shared request-options type) so future transport options don't drift between auth and migration helpers.

Share FeedbackReview Logs

@scottlovegrove scottlovegrove merged commit 0fda8af into main Jun 26, 2026
4 checks passed
@scottlovegrove scottlovegrove deleted the feat/twist-comms-url-migration branch June 26, 2026 16:56
doist-release-bot Bot added a commit that referenced this pull request Jun 26, 2026
## [0.7.0](v0.6.1...v0.7.0) (2026-06-26)

### Features

* add Twist→Comms URL migration helper ([#42](#42)) ([0fda8af](0fda8af))
@doist-release-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@amix amix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Small nit regarding the test suite 👍

Comment thread src/migration.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants