@bccampus/kaltura-client
v1.1.0
Published
Kaltura Typescript client (readonly)
Maintainers
Readme
Kaltura Typescript Client
A read-only facade to Kaltura server with typescript support for read/query action requests, classes and enums.
Instructions
Getting Started
This build is read-only. Actions that upload, create, edit or delete server resources are intentionally not exposed. Authentication/session bootstrap actions remain available so you can obtain a KS for reading data.
Building the sources
This library is auto-generated using
kaltura/clients-generatorphp engine, and then modified to use modern tools and to make it read-only and dependency-free.
The package is built with Vite (npm run build), which emits one module file plus one .d.ts file per source module so deep imports keep working. TypeScript interfaces re-exported from barrel files must be marked with the inline type modifier (for example export { Foo, type FooArgs } from './Foo'), otherwise Rolldown treats them as missing runtime exports.
Code is formatted with Oxfmt: npm run format rewrites files and npm run format:check verifies them (used by CI).
Running tests
The test suite is powered by Vitest and requires Node.js 22.12 or newer.
- Run
npm testto run the unit tests. They use a mocked HTTP transport and don't require network access. - Use
npm run test:watchwhile developing.
Running integration tests
Live integration tests are skipped by default. They call a real Kaltura server and depend on the data available in the configured account.
Enable them with KALTURA_INTEGRATION_TEST=1:
KALTURA_INTEGRATION_TEST=1 npm testOn PowerShell:
$env:KALTURA_INTEGRATION_TEST="1"; npm testThe following environment variables can be used to point the integration tests at another account:
| Variable | Purpose |
| -------------------------- | --------------------------------- |
| KALTURA_ENDPOINT | API endpoint |
| KALTURA_PARTNER_ID | Partner id |
| KALTURA_USER | User id used to start the session |
| KALTURA_ADMIN_SECRET | Admin secret |
| KALTURA_SESSION_TYPE | user (default) or admin |
| KALTURA_CLIENT_TAG | Value sent as clientTag |
| KALTURA_INTEGRATION_TEST | Running integration tests |
If you want to test the library against the production server, set
KALTURA_ENDPOINTto your production API endpoint.
Example
import { KalturaClient } from "@bccampus/kaltura-client";
import { SessionStartAction } from "@bccampus/kaltura-client/api/types/SessionStartAction";
import { KalturaSessionType } from "@bccampus/kaltura-client/api/types/KalturaSessionType";
import { MediaGetAction } from "@bccampus/kaltura-client/api/types/MediaGetAction";
const client = new KalturaClient({
clientTag: "BCcampus_Resource_Importer",
endpointUrl: "https://api.ca.kaltura.com",
});
async function startSession() {
const sessionStartAction = new SessionStartAction({
partnerId: 0,
secret: "xxxxxxxxxxxxxxxxxxxxxxxxx",
userId: "test-user",
type: KalturaSessionType.admin,
expiry: 3600,
privileges: "disableentitlement",
});
try {
const session = await client.request(sessionStartAction);
if (session) {
client.setDefaultRequestOptions({ ks: session });
return true;
}
console.log("Failed to start kaltura session");
return false;
} catch (error) {
console.log(`Kaltura session error: \n ${error}`);
return false;
}
}
async function getVideoById(id: string) {
if (!(await startSession())) return null;
const media = await client.request(
new MediaGetAction({
entryId: id,
}),
);
return media;
}
await getVideoById("0_qwerty");