Shared TypeScript client and models for Citolab QTI backends. It is used by apps that run on the Firebase backend (qti-backend-firebase) and by apps that run on a .NET backend.
- Shared models (
Assessment,Session,Delivery,ItemStatisticsWithResponses, ...) that frontends and backends agree on. - Pre-configured API clients that handle authentication, token refresh, retry on
401/403and unwrapping of{ success, data }responses:QtiApi: student side (login by code, test context, logging)QtiTeacherApi: teacher/reviewer dashboards (deliveries, results, statistics)QtiToolsApi: package upload and plausible answers
- Pluggable authentication via
IAuthStudentProviderandITeacherAuthProvider. Firebase providers are included; other backends supply their own (e.g. a .NET or MSAL provider in the app).
App-specific endpoints do not belong here. Call them in the app through the client's axios instance, which already carries the auth headers and token refresh:
const { data } = await teacherApi.axios.post(`/my-app/some-endpoint`, body);Only add a method to this package when the endpoint exists with the same contract on every backend that uses the package.
npm install @citolab/qti-api axios @citolab/qti-componentsaxios (>= 1.7) and @citolab/qti-components (8.x, 9.x or 10.x) are peer dependencies.
import {
FirebaseAuthStudentProvider,
FirebaseTeacherAuthProvider,
QtiApi,
QtiTeacherApi,
} from "@citolab/qti-api";
const qtiApi = new QtiApi(apiUrl, new FirebaseAuthStudentProvider(firebaseApiKey));
const teacherApi = new QtiTeacherApi({
apiIUrl: apiUrl,
authProvider: new FirebaseTeacherAuthProvider(firebaseApiKey),
});Implement the provider interface and pass it to the same clients:
import type { ITeacherAuthProvider, TeacherAuthResult } from "@citolab/qti-api";
class MyTeacherAuthProvider implements ITeacherAuthProvider {
getProviderId() {
return "my-backend";
}
async authenticate(email: string, password: string): Promise<TeacherAuthResult> {
/* call your login endpoint */
}
// signUp, passwordReset, getLoggedInUser, refreshToken
}
const teacherApi = new QtiTeacherApi({ apiIUrl: apiUrl, authProvider: new MyTeacherAuthProvider() });All clients accept axiosConfig to reuse an existing axios instance:
new QtiTeacherApi({
apiIUrl: apiUrl,
authProvider,
axiosConfig: {
instance: myAxios,
clearInterceptors: false, // remove existing interceptors first
addAuthenticationInterceptors: true, // token refresh / retry on 401 and 403
},
});npm run release:patch # or release:minor / release:majorThis project is licensed under the GPLv3 License.