Skip to main content

@signapps/api-client

A generated, type-safe RTK Query client for the API — Redux hooks for every endpoint, with automatic cache invalidation and runtime Zod response validation.

  • Workspace: packages/api-client
  • Depends on: @signapps/types (for response schemas)
  • Build: tsc -p tsconfig.jsondist/

How it's generated

A two-step codegen runs from the API's OpenAPI spec (apps/api/docs/openapi.json):

  1. scripts/generate-response-schemas.mjs scans the spec and maps each endpoint's operationId to the matching Zod schema from @signapps/types/dto/*, writing endpointResponseSchemas.ts.
  2. rtk-query-codegen-openapi generates generatedApi.ts (queries, mutations, lazy queries, and React hooks).

enhancedApi.ts then wraps the generated API to (a) run transformResponse Zod validation on every endpoint that has a matching schema and (b) add custom providesTags/invalidatesTags for cache management. authBridge.ts wires token lifecycle.

Run codegen with:

pnpm generate:api-client

Exports

From index.ts:

  • api — the enhanced RTK Query instance
  • setApiTokenGetter, setOnUnauthorized — auth hooks
  • everything from generatedApi — the typed React hooks (e.g. useListCustomersQuery, useCreateCustomerMutation, …)
Generated file

src/generatedApi.ts and src/endpointResponseSchemas.ts are generated and gitignored — never edit them by hand. Change the API's OpenAPI source and re-run codegen instead.

Consumed by

Web admin (and other React apps).