Every @zitadel/api call runs on the client you give it
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)iscreateZitadelApi(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_HEADERand the@zitadel/api/runtime/authentry (setApiAuthToken,setApiCsrfToken,setApiCsrfRejectionHandlerand their getters) are gone. An app that needs a CSRF header passes its ownfetchto the client.- The generated
get…Urlbuilders 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 aclientproperty;getClient(project)returns that client.pagedFunctions[name].withTokentakes and returns the operation's full arguments, its client first.- In
@zitadel/testing,ConnectedZitadel.apiand the seeding helpers take the boundZitadelApitype.
Pull request#3392