Skip to content

Adopt @canup/contracts: dependency rename + shared error kernel - #27

Merged
cescox merged 2 commits into
mainfrom
refactor/canup-contracts
Jun 26, 2026
Merged

cescox merged 2 commits into
mainfrom
refactor/canup-contracts

Conversation

@cescox

@cescox cescox commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Brings both SDK packages onto the published @canup/contracts wire-contract package and its shared error kernel.

1. Depend on @canup/contracts (renamed from @canup/types)

Mechanical rename of the dependency, all import specifiers, and the lockfile. Un-breaks install (the old package name was removed from npm).

2. Adopt the shared error kernel

Both packages shipped their own error type — the UI a local CanupError (emitting NETWORK_ERROR, carrying a details bag) and the CLI an ApiError (field statusCode) — duplicating, and diverging from, the canonical kernel @canup/contracts already exports. Both local classes are deleted in favor of the shared CanupError, unwrapResponse, toCanupError, and isCanupError.

Behavior changes (contract is the source of truth):

  • Error codes are now the contract vocabulary. The client-transport failure code is TRANSPORT_ERROR (was NETWORK_ERROR in the UI, HttpError in the CLI) — neither old code exists in the contract. Server codes still pass through verbatim via the open union.
  • The HTTP status field is httpStatus (was the CLI's statusCode).
  • Response decoding goes through unwrapResponse, which guards a non-JSON body — previously unguarded in the CLI client.

The kernel is bundled into each package's dist, so consumers gain no runtime dependency.

Verification

test (358 cli + 115 ui), lint, typecheck, build all green. Bundle: cli 22 kB gzip, ui 14 kB gzip.

Follow-up (not in this PR)

Deduplicating the hardcoded https://canup.link default origin into a shared CANUP_API_URL constant is a separate change — it needs @canup/contracts republished (patch, 0.2.1) first.

cescox added 2 commits June 26, 2026 10:10
The shared wire-contract package was renamed. Update the dependency,
all import specifiers, and the lockfile to match. Mechanical; no
behavior change.
Both packages shipped their own error type — the UI a local CanupError
(emitting NETWORK_ERROR, carrying a details bag) and the CLI an ApiError
(field statusCode) — duplicating, and diverging from, the canonical
kernel that @canup/contracts already exports. Delete both local classes
and adopt the shared CanupError, unwrapResponse, toCanupError, and
isCanupError.

Behavior changes, with the contract as the source of truth:
- Error codes are now the contract's vocabulary. The client-transport
  failure code is TRANSPORT_ERROR (was NETWORK_ERROR in the UI and
  HttpError in the CLI); neither old code exists in the contract. Server
  codes still pass through verbatim via the open union.
- The HTTP status field is httpStatus (was the CLI's statusCode).
- Response decoding goes through the contract's unwrapResponse, which
  also guards a non-JSON body — previously unguarded in the CLI client.

Tests updated to assert the contract vocabulary (TRANSPORT_ERROR,
httpStatus); they encode the adopted contract, not a behavior tweak. The
kernel is bundled into each package's dist, so consumers gain no runtime
dependency.
@github-actions

Copy link
Copy Markdown

Coverage Report for @canup/ui (packages/ui)

Status Category Percentage Covered / Total
🔵 Lines 98.39% (🎯 95%) 184 / 187
🔵 Statements 98.08% (🎯 95%) 205 / 209
🔵 Functions 98.07% (🎯 95%) 51 / 52
🔵 Branches 96.06% (🎯 85%) 122 / 127
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/ui/src/components/ActionButton.tsx 100% 100% 100% 100%
packages/ui/src/hooks/use-action.ts 100% 100% 100% 100%
packages/ui/src/hooks/use-credits.ts 100% 100% 100% 100%
packages/ui/src/hooks/use-customer.ts 100% 100% 100% 100%
packages/ui/src/internal/api-client.ts 93.75% 100% 100% 92.3% 26
packages/ui/src/internal/realtime.ts 96.87% 92.3% 92.3% 98.21% 45, 150
Generated in workflow #39 for commit b32694b by the Vitest Coverage Report Action

@github-actions

Copy link
Copy Markdown

Coverage Report for @canup/cli (packages/cli)

Status Category Percentage Covered / Total
🔵 Lines 98.91% (🎯 95%) 1098 / 1110
🔵 Statements 98.7% (🎯 95%) 1141 / 1156
🔵 Functions 98.46% (🎯 95%) 193 / 196
🔵 Branches 93.58% (🎯 85%) 467 / 499
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/api-client.ts 98.03% 95.23% 100% 97.87% 196
packages/cli/src/commands/init.ts 99.06% 88.63% 87.5% 99.03% 86
packages/cli/src/commands/pull.ts 100% 95.45% 100% 100%
packages/cli/src/commands/status.ts 100% 95% 100% 100%
packages/cli/src/commands/whoami.ts 100% 100% 100% 100%
packages/cli/src/commands/actions/_shared.ts 100% 100% 100% 100%
packages/cli/src/commands/actions/delete.ts 100% 100% 100% 100%
packages/cli/src/commands/actions/deploy.ts 100% 96.29% 100% 100%
packages/cli/src/commands/actions/invocations.ts 100% 94.11% 100% 100%
packages/cli/src/commands/actions/remove.ts 100% 100% 100% 100%
packages/cli/src/commands/actions/run.ts 100% 92.85% 100% 100%
packages/cli/src/commands/actions/test.ts 100% 93.1% 100% 100%
packages/cli/src/commands/deps/_shared.ts 100% 100% 100% 100%
packages/cli/src/commands/deps/add.ts 100% 100% 100% 100%
packages/cli/src/commands/deps/clear.ts 100% 100% 100% 100%
packages/cli/src/commands/deps/remove.ts 100% 100% 100% 100%
packages/cli/src/commands/secrets/delete.ts 100% 100% 100% 100%
packages/cli/src/commands/stripe/connect.ts 100% 91.66% 100% 100%
Generated in workflow #39 for commit b32694b by the Vitest Coverage Report Action

@cescox
cescox merged commit d157134 into main Jun 26, 2026
8 checks passed
@cescox
cescox deleted the refactor/canup-contracts branch June 26, 2026 08:27
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.

1 participant