@clozeinc/forge-api
TypeScript client for the Cloze Forge API. Used by apps scaffolded from the Cloze Forge app template.
Install
npm install @clozeinc/forge-api
Usage
import { Cloze } from "@clozeinc/forge-api";
const cloze = new Cloze();
const { data, error } = await cloze.projects.get({
query: { id: "direct:12345" },
});
if (error) {
// transport / HTTP failure
} else if (data.errorcode !== 0) {
// application-level Cloze error (data.message has details)
} else {
const project = data.project;
}
Success = !error && data.errorcode === 0. Both layers matter — a present
data alone is not enough.
What lives here
- The generated
Clozeclass and every resource (People,Projects,Companies,Timeline,Analytics,Team,User,Webhooks,Messages,Account) plus every request/response type. - The transport wiring that auto-detects three runtime environments:
- Embedded in a Cloze host iframe → routes requests to the parent
window over
postMessage. - Running on a
cloze.app/cloze.buildsubdomain → uses the site's session cookie plus theX-CSRFheader. - Standalone anywhere else → resolves a bearer token from an
explicit
authconfig, a?api_key=URL param, or a prompt.
- Embedded in a Cloze host iframe → routes requests to the parent
window over
Consumers who need to override transport can either pass their own
client to new Cloze({ client }) or import createClientConfig and
postMessageFetch from the package root and compose their own setup.
Do not hand-edit .gen.ts files
Files ending in .gen.ts are produced by @hey-api/openapi-ts from the
Cloze OpenAPI spec (forge-openapi.json). They are regenerated
wholesale — hand edits will be lost.
Runtime behavior lives in src/api-config.ts and
src/iframe-transport.ts; those are safe to edit.