TypeScript client wrapper + vite dev proxy (in Mark/Kimi_Agent_Brother_10_Digitizing_App) #3

Closed
opened 2026-06-23 21:20:11 +00:00 by Mark · 1 comment
Owner

Goal

Wire the ThreadCraft frontend to the deployed easystitch-service so #6, #8, #9, #10, and #2 can call it. Deliverable is a typed TS client and a dev proxy — no UI work in this issue.

Note: this issue lives in the frontend repo (Mark/Kimi_Agent_Brother_10_Digitizing_App), but is being decomposed here for tracking the integration spec. The actual sub-issue will be filed against ThreadCraft.

Implementation

  1. src/lib/easystitch-client.ts — typed wrapper exposing:
    • digitize(image: Blob, settings: AutoDigitizeSettings): Promise<DigitizeResponse>
    • exportPES(stitchObjects: StitchObject[], opts?: ExportOpts): Promise<Blob>
    • resolveThreads(colors: string[]): Promise<ThreadMatch[]>
    • All requests hit import.meta.env.VITE_EASYSTITCH_API_URL + /v1/....
    • Response types mirror the FastAPI pydantic models (manually kept in sync for v1).
    • Errors surface as a typed EasystitchError with status, code, message. Network failures → retryable; 5xx → retryable with backoff; 4xx → not retryable.
  2. vite.config.ts — add a proxy entry for dev:
    server: {
      proxy: {
        '/api/easystitch': {
          target: process.env.EASYSTITCH_API_URL || 'http://localhost:8080',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api\/easystitch/, ''),
        },
      },
    }
    
    In dev, the client uses /api/easystitch as the base URL (relative). In prod, it uses VITE_EASYSTITCH_API_URL.
  3. .env.example — document VITE_EASYSTITCH_API_URL=http://easystitch-service.tail018ac4.ts.net.
  4. No UI changes in this issue — only the client + proxy plumbing. The downstream issues (#6, #8, #9, #10, #2) will call the client from their respective components.

Files touched

  • New: src/lib/easystitch-client.ts
  • New: src/lib/easystitch-client.test.ts (unit tests with msw or vi.mock for fetch)
  • Modified: vite.config.ts
  • Modified: .env.example
  • Modified: package.json — no new deps required (uses native fetch)

Acceptance

  • tsc --noEmit is clean.
  • Unit tests cover happy path + 4xx + 5xx + network failure for each method.
  • Manual smoke: dev server proxies /api/easystitch/healthz to the service and returns 200.

Dependencies

  • FastAPI wrapper issue must be complete (response shape must be stable).
  • node_hub deployment issue must be complete (or local service running on :8080) for the dev proxy to hit something real.
## Goal Wire the ThreadCraft frontend to the deployed easystitch-service so #6, #8, #9, #10, and #2 can call it. Deliverable is a typed TS client and a dev proxy — no UI work in this issue. **Note:** this issue lives in the frontend repo (`Mark/Kimi_Agent_Brother_10_Digitizing_App`), but is being decomposed here for tracking the integration spec. The actual sub-issue will be filed against ThreadCraft. ## Implementation 1. **`src/lib/easystitch-client.ts`** — typed wrapper exposing: - `digitize(image: Blob, settings: AutoDigitizeSettings): Promise<DigitizeResponse>` - `exportPES(stitchObjects: StitchObject[], opts?: ExportOpts): Promise<Blob>` - `resolveThreads(colors: string[]): Promise<ThreadMatch[]>` - All requests hit `import.meta.env.VITE_EASYSTITCH_API_URL` + `/v1/...`. - Response types mirror the FastAPI pydantic models (manually kept in sync for v1). - Errors surface as a typed `EasystitchError` with `status`, `code`, `message`. Network failures → retryable; 5xx → retryable with backoff; 4xx → not retryable. 2. **`vite.config.ts`** — add a proxy entry for dev: ```ts server: { proxy: { '/api/easystitch': { target: process.env.EASYSTITCH_API_URL || 'http://localhost:8080', changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/easystitch/, ''), }, }, } ``` In dev, the client uses `/api/easystitch` as the base URL (relative). In prod, it uses `VITE_EASYSTITCH_API_URL`. 3. **`.env.example`** — document `VITE_EASYSTITCH_API_URL=http://easystitch-service.tail018ac4.ts.net`. 4. **No UI changes in this issue** — only the client + proxy plumbing. The downstream issues (#6, #8, #9, #10, #2) will call the client from their respective components. ## Files touched - **New:** `src/lib/easystitch-client.ts` - **New:** `src/lib/easystitch-client.test.ts` (unit tests with msw or vi.mock for fetch) - **Modified:** `vite.config.ts` - **Modified:** `.env.example` - **Modified:** `package.json` — no new deps required (uses native `fetch`) ## Acceptance - `tsc --noEmit` is clean. - Unit tests cover happy path + 4xx + 5xx + network failure for each method. - Manual smoke: dev server proxies `/api/easystitch/healthz` to the service and returns 200. ## Dependencies - FastAPI wrapper issue must be complete (response shape must be stable). - node_hub deployment issue must be complete (or local service running on :8080) for the dev proxy to hit something real.
Mark closed this issue 2026-06-25 03:08:15 +00:00
Author
Owner

Closed via commit 9e1ae96 in Mark/Kimi_Agent_Brother_10_Digitizing_App.

Delivered:

  • src/lib/easystitch-client.ts (typed client + EasystitchError)
  • src/lib/easystitch-client.test.ts (14/14 passing)
  • vitest.config.ts
  • vite.config.ts proxy entry (/api/easystitch -> localhost:8080)
  • .env.example documenting VITE_EASYSTITCH_API_URL + EASYSTITCH_API_URL
  • package.json: vitest devDep + 'test' / 'test:watch' scripts

Deviation from issue body: added vitest as a devDep even though the issue said 'no new deps required'. The acceptance criteria required unit tests, and the frontend repo had no test runner. Issue #1 (Vitest + RTL test suite) overlaps slightly — when #1 lands it merges cleanly with this work.

Closed via commit 9e1ae96 in Mark/Kimi_Agent_Brother_10_Digitizing_App. Delivered: - src/lib/easystitch-client.ts (typed client + EasystitchError) - src/lib/easystitch-client.test.ts (14/14 passing) - vitest.config.ts - vite.config.ts proxy entry (/api/easystitch -> localhost:8080) - .env.example documenting VITE_EASYSTITCH_API_URL + EASYSTITCH_API_URL - package.json: vitest devDep + 'test' / 'test:watch' scripts Deviation from issue body: added `vitest` as a devDep even though the issue said 'no new deps required'. The acceptance criteria required unit tests, and the frontend repo had no test runner. Issue #1 (Vitest + RTL test suite) overlaps slightly — when #1 lands it merges cleanly with this work.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/easystitch-service#3
No description provided.