Preview
Changelog

Every @zitadel/api call runs on the client you give it

Released in v0.10.0

A ZitadelClient holds one connection: the base URL, the token, and any timeout, abort signal, user agent or fetch. It never changes once created; client.with({ … }) returns a changed copy. Every operation takes its settings from the client it runs on, so an app's own client and the sign-in widget's can no longer leak a timeout, abort signal or token into each other's requests.

import { createZitadelApi, ZitadelClient } from "@zitadel/api/client";

const api = createZitadelApi(
  new ZitadelClient({
    baseUrl: process.env.ZITADEL_URL!,
    token: process.env.ZITADEL_PROJECT_SECRET!, // server-side only
  }),
);

const project = await api.getProject(process.env.ZITADEL_PROJECT_ID!);

A client's onRequest runs before every request with the operation's name, URL and request. Throw from it to stop the request before anything is sent.

Breaking: code that calls @zitadel/api directly changes as follows. The SDKs and the widgets need no change of yours.

  • createZitadelClient(options) is createZitadelApi(new ZitadelClient({ baseUrl, token })).
  • A generated operation you import on its own takes its client first, as in getProject(client, projectId). A call without one does not compile.
  • setProxyPath, getProxyPath, getApiBaseUrl, setRequestPolicy, createApi, CSRF_HEADER and the @zitadel/api/runtime/auth entry (setApiAuthToken, setApiCsrfToken, setApiCsrfRejectionHandler and their getters) are gone. An app that needs a CSRF header passes its own fetch to the client.
  • The generated get…Url builders are no longer exported; call the operation, which builds its own URL.
  • getApi(project) still binds every operation to the project's client and gains a client property; getClient(project) returns that client.
  • pagedFunctions[name].withToken takes and returns the operation's full arguments, its client first.
  • In @zitadel/testing, ConnectedZitadel.api and the seeding helpers take the bound ZitadelApi type.

API client

Pull request#3392