fuzzy-cactus
v0.1.0
Published
Universal Context Layer (UCL) API client for Node.js and browsers
Maintainers
Readme
UCL API Client (TypeScript)
Universal Context Layer API client for browser and Node.js with a modular, extensible design.
Repository: https://github.com/unifiedcontextlayer/ucl-api-node
Install
npm install ucl-api
# or
yarn add ucl-apiQuick Start
import { UclClient } from 'ucl-api';
const ucl = new UclClient({
workspaceId: 'ws_123',
authToken: async () => '<your-token>',
// baseUrl?: 'https://qa.fastn.ai',
// stage?: 'LIVE',
// fetch?: customFetch
});
const res = await ucl.connectors.auth({
connectorId: 'c789',
// tenantId?: 't123',
// orgId?: 'o001',
// workspaceId?: 'override-org', // overrides orgId if provided
// refresh?: false
});
console.log(res.auth);Design
- Modular:
constants,types,fetchresolver,httpclient,confignormalizer, andclientsurface. - Cross-environment: Uses global
fetchwhen available; falls back tocross-fetchin Node.js. - Token providers: Pass a string token or an async function for on-demand refresh without recreating the client.
- Stable HTTP: Centralized header construction and error handling.
API
class UclClient
Constructor:
new UclClient({
workspaceId: string,
authToken?: string | () => string | Promise<string>,
baseUrl?: string, // default: https://live.fastn.ai/api
stage?: string, // default: LIVE
fetch?: typeof fetch // optional custom fetch
})Methods:
setAuthToken(tokenOrProvider)— update token or async provider at runtime.setFetch(fetchLike)— override thefetchimplementation.
Namespaces:
connectors.auth(params)
Input:
{
connectorId: string; // required
tenantId?: string; // optional → header x-fastn-space-tenantid
orgId?: string; // optional
workspaceId?: string; // optional; if provided, overrides orgId
refresh?: boolean; // optional
}Behavior:
- Headers include
x-fastn-space-id(from constructor),stage(defaultLIVE),x-fastn-custom-auth: true, andauthorization(your token). orgIdresolution: useworkspaceId(param) if provided; elseorgId; else'community'.- Response shape:
{ auth: { ... } }whereauthcarries OAuth fields likeaccess_token,expires_in(when applicable) or connector-specific credentials.
Returns:
type AuthResponse = { auth: Record<string, unknown> };Error Handling
- Non-2xx responses throw
Error('HTTP <status> <statusText>: <body>'). - Missing auth token throws:
authToken is required. Provide it in config or via setAuthToken().
Testing
This package ships with Jest tests. Run:
npm testTo run live E2E against your workspace, export envs (or create a local .env):
export UCL_E2E=1
export UCL_BASE_URL=https://live.fastn.ai/api
export UCL_WORKSPACE_ID=<your-workspace-id>
export UCL_AUTH_TOKEN='<your-token>'
export UCL_CONNECTOR_ID=<your-connector-id>
export UCL_ORG_ID=<your-org-id>
export UCL_REFRESH=false
export UCL_TENANT_ID=<your-tenant-id>
npm testContributing
- Follow TypeScript strictness and naming best practices.
- Keep modules focused and reusable. Avoid duplication.
- Add/extend tests for new features.
License
MIT © Fastn
