Skip to content

@presencelearning/api-client

Generated TypeScript API client using Hey-API.

  • Node.js >= 20.0.0
  • Zod 3.23+ or 4.x
  • Angular 19+ (optional, for provideApiClient)

This package supports both modern and legacy TypeScript module resolution:

  • moduleResolution: "bundler" (recommended) — Subpath imports work automatically
  • moduleResolution: "node" (legacy) — Subpath imports work via typesVersions

No path aliases needed in either case.

Terminal window
cd packages/api-client
npm install
Terminal window
# Generate all clients
npm run generate
# Generate specific API
npm run generate:workplace:v1
npm run generate:workplace:v2
npm run generate:workplace:v3
npm run generate:workplace:test
npm run generate:auth:v1
npm run generate:platform:v1
npm run generate:platform:v2
npm run generate:platform:v3
APIImport 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
  1. Copy an existing config:

    Terminal window
    cp openapi-ts.workplace-v1.config.ts openapi-ts.platform-v1.config.ts
  2. Edit input/output paths in the new config

  3. Add script to package.json:

    "generate:platform:v1": "openapi-ts -f openapi-ts.platform-v1.config.ts"
  4. Add to parallel generate script:

    "generate": "npm-run-all --parallel generate:workplace:* generate:platform:*"
  5. Add export to package.json exports field

See openapi-ts.workplace-v1.config.ts for documented options. Key settings:

  • input: OpenAPI schema URL or file path
  • output.path: Where to write generated files
  • plugins: TypeScript, client, SDK, and Zod configuration

Use provideApiClient() from the /angular subpath in your app config:

app.config.ts
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 call
const 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 } }),
});
}

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' } });

For more control, configure clients individually:

import { client } from '@presencelearning/api-client/workplace/v1';
client.setConfig({
baseUrl: 'https://api.presence.com/workplace',
auth: () => getToken(),
});

Source: packages/api-client