@presencelearning/api-client
Generated TypeScript API client using Hey-API.
Requirements
Section titled “Requirements”- Node.js >= 20.0.0
- Zod 3.23+ or 4.x
- Angular 19+ (optional, for
provideApiClient)
TypeScript Configuration
Section titled “TypeScript Configuration”This package supports both modern and legacy TypeScript module resolution:
moduleResolution: "bundler"(recommended) — Subpath imports work automaticallymoduleResolution: "node"(legacy) — Subpath imports work viatypesVersions
No path aliases needed in either case.
cd packages/api-clientnpm installGenerate Clients
Section titled “Generate Clients”# Generate all clientsnpm run generate
# Generate specific APInpm run generate:workplace:v1npm run generate:workplace:v2npm run generate:workplace:v3npm run generate:workplace:testnpm run generate:auth:v1npm run generate:platform:v1npm run generate:platform:v2npm run generate:platform:v3Available Clients
Section titled “Available Clients”| API | Import Path |
|---|---|
| Workplace v1 | @presencelearning/api-client/workplace/v1 |
| Workplace v2 | @presencelearning/api-client/workplace/v2 |
| Workplace v3 | @presencelearning/api-client/workplace/v3 |
| Workplace test | @presencelearning/api-client/workplace/test |
| Auth v1 | @presencelearning/api-client/auth/v1 |
| Platform v1 | @presencelearning/api-client/platform/v1 |
| Platform v2 | @presencelearning/api-client/platform/v2 |
| Platform v3 | @presencelearning/api-client/platform/v3 |
Adding More APIs
Section titled “Adding More APIs”-
Copy an existing config:
Terminal window cp openapi-ts.workplace-v1.config.ts openapi-ts.platform-v1.config.ts -
Edit input/output paths in the new config
-
Add script to package.json:
"generate:platform:v1": "openapi-ts -f openapi-ts.platform-v1.config.ts" -
Add to parallel generate script:
"generate": "npm-run-all --parallel generate:workplace:* generate:platform:*" -
Add export to package.json exports field
Configuration Options
Section titled “Configuration Options”See openapi-ts.workplace-v1.config.ts for documented options. Key settings:
input: OpenAPI schema URL or file pathoutput.path: Where to write generated filesplugins: TypeScript, client, SDK, and Zod configuration
Usage in Apps
Section titled “Usage in Apps”Angular Apps (Recommended)
Section titled “Angular Apps (Recommended)”Use provideApiClient() from the /angular subpath in your app config:
import { ApplicationConfig, inject } from '@angular/core';import { provideApiClient } from '@presencelearning/api-client/angular';
export const appConfig: ApplicationConfig = { providers: [ provideApiClient({ baseUrls: { auth: environment.apps.auth.url, workplace: environment.apps.apiWorkplace.url, platform: environment.apps.platform.url, }, // The auth callback runs inside an injection context, so AuthStore // can be resolved with inject() here. auth: () => inject(AuthStore).getCurrentToken(), }), ],};Then use SDK functions in your components:
import { v1UsersRetrieve } from '@presencelearning/api-client/workplace/v1';
// Simple async callconst user = await v1UsersRetrieve({ path: { id: '123' } });Using with Angular Signals and resource() (Experimental)
Section titled “Using with Angular Signals and resource() (Experimental)”The SDK returns Promises, which work seamlessly with Angular’s resource() API:
import { Component, input, resource } from '@angular/core';import { v1UsersRetrieve } from '@presencelearning/api-client/workplace/v1';
@Component({ template: ` @if (user.hasValue()) { <user-profile [user]="user.value()" /> } @else if (user.isLoading()) { <loading-spinner /> } @else if (user.error()) { <error-message [error]="user.error()" /> } `,})export class UserComponent { userId = input.required<string>();
user = resource({ request: () => ({ id: this.userId() }), loader: ({ request }) => v1UsersRetrieve({ path: { id: request.id } }), });}Non-Angular Apps
Section titled “Non-Angular Apps”Use configureClients() once at app startup to configure all API clients:
import { configureClients } from '@presencelearning/api-client';
configureClients({ baseUrls: { auth: 'http://localhost:9000', workplace: 'http://localhost:8000', platform: 'http://localhost:8020', }, auth: () => authStore.getCurrentToken(),});Then use SDK functions directly — they use the configured clients automatically:
import { someEndpoint } from '@presencelearning/api-client/workplace/v1';
const response = await someEndpoint({ path: { id: '123' } });Configure Individual Clients
Section titled “Configure Individual Clients”For more control, configure clients individually:
import { client } from '@presencelearning/api-client/workplace/v1';
client.setConfig({ baseUrl: 'https://api.presence.com/workplace', auth: () => getToken(),});Hey-API references
Section titled “Hey-API references”Source: packages/api-client