Commit Graph
2 Commits
Author SHA1 Message Date
Mao NakamotoandClaude Opus 4.7 acb81480b5 feat(orangecat): persist orangecat_service_id + render "OC ✓" badge on /money
Closes the Loop A persistence story. After
syncSubscriptionToOrangeCat() succeeds, the subscription row now stores
the OrangeCat service id back, so the /money page can render a per-row
"OC ✓" badge and future backfill jobs can target only the still-null
rows.

Schema (drizzle migration 0021):
- subscriptions.orangecat_service_id (uuid, nullable). Null = not
  mirrored (integration off, sync failed, or row predates the
  integration). Apply via `npm run migrate`.
- Partial index on (user_id) WHERE orangecat_service_id IS NULL — the
  shape the "what still needs syncing" backfill query will use; the
  column is mostly null for now.

orangecat.ts:
- syncSubscriptionToOrangeCat() now writes the back-link after a
  successful POST. The DB update is also non-fatal — OrangeCat already
  has the truth, and the next /money render still reflects the synced
  state once the column is populated.

UI (/money page SubRow):
- New "OC ✓" badge appears next to the subscription name when
  orangecatServiceId is present. Hover shows the OrangeCat service id
  for cross-system debugging.

SDK bump:
- @orangecat/sdk moved from 0.1.0 → 0.2.0 (file:vendor/). 0.2.0 adds
  .list() on every resource, which a future backfill script uses to
  enumerate what's already on the OrangeCat side before re-syncing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-03 16:06:15 +02:00
Mao NakamotoandClaude Opus 4.7 1e969983c0 feat(orangecat): Loop A — mirror subscriptions to OrangeCat via @orangecat/sdk
First real cross-product call from FleetCrown into OrangeCat. Whenever a
FleetCrown user adds a subscription on /money, the same record is
mirrored into OrangeCat as a `service` owned by the FleetCrown group
actor. Mao now sees FleetCrown's monthly burn inside the OrangeCat
ledger — the bitbaum studio narrative gets its first real data point.

- Adds @orangecat/sdk@0.1.0 as a file:vendor/ dep
  (vendor/orangecat-sdk-0.1.0.tgz committed; mirrors npm-install
  semantics for dev + Vercel until the SDK is published).
- src/lib/integrations/orangecat.ts: singleton client, no-ops when
  ORANGECAT_API_KEY is unset. syncSubscriptionToOrangeCat() is
  fire-and-forget — never throws, never blocks the subscription POST.
  Stable Idempotency-Key (`fleetcrown_sub_<id>`) so retries dedupe
  cleanly when server-side dedup lands.
- src/db/queries/money.ts: hook fires after the DB insert returns.
  Whether the OC sync succeeds or fails is irrelevant to the user
  response — the local subscription is already persisted.
- .env.example: documents ORANGECAT_API_KEY + ORANGECAT_API_BASE.

Reliability defaults baked in by the SDK: 20s timeout, 3 exp-backoff
retries on network / 5xx / 429 honouring Retry-After, User-Agent
identifying FleetCrown, AbortSignal-clean.

Failure modes are non-fatal and logged with enough context for backfill:
- ORANGECAT_API_KEY unset → silent no-op (most dev envs today)
- OrangeCat returns OrangeCatError → console.warn with code+status,
  subscription still saved locally
- Network error → SDK retries internally, then console.warn

Follow-ups (each its own commit, all post-this-spike):
- schema: add subscriptions.orangecat_service_id column so the link
  persists and the UI can render a "Synced ✓" badge
- once /api/v1 exposes GET via integration-key auth, run a backfill
  job for existing subscriptions
- when OrangeCat publishes the SDK to npm, replace the vendor/ tarball
  with a normal version range

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-03 15:27:51 +02:00