A TypeScript client library for the Outline knowledge base API, providing type-safe methods to interact with documents, collections, and authentication.
- π Full TypeScript Support - Complete type definitions for all API endpoints
- π Automatic Retry Logic - Built-in retry mechanism for failed requests
- π Document Management - Create, read, update, delete, and search documents
- π Collection Management - Organize documents with collections
- π Authentication - Secure API key authentication
- β‘ Async Iterators - Efficiently iterate through large datasets
- π‘οΈ Error Handling - Comprehensive error types and handling
npm install outline-api-clientimport { createOutlineClient } from 'outline-api-client';
// Initialize the client
const client = createOutlineClient('your-api-key');
// Get document list
const documents = await client.documents.list({ limit: 10 });
// Search documents
const results = await client.documents.search('API design');
// Create a new document
const newDoc = await client.documents.create({
title: 'New Document',
text: '# Content\n\nDocument content here',
collectionId: 'collection-id',
publish: true
});This library is primarily designed for Node.js environments. Outline's SaaS platform (app.getoutline.com) does not allow direct browser access due to CORS restrictions. For browser-based applications, you'll need to:
- Create a backend proxy server
- Use server-side rendering (Next.js, etc.)
- Build a backend API that uses this library
import { OutlineClient } from 'outline-api-client';
const client = new OutlineClient({
apiKey: 'your-api-key',
apiUrl: 'https://app.getoutline.com/api', // optional
timeout: 30000, // optional, in milliseconds
retryAttempts: 3, // optional
retryDelay: 1000 // optional, in milliseconds
});const response = await client.documents.list({
collectionId: 'collection-id',
limit: 25,
offset: 0,
sort: 'updatedAt',
direction: 'DESC'
});const doc = await client.documents.info('document-id');const results = await client.documents.search('search query', {
collectionId: 'collection-id',
includeArchived: false,
includeDrafts: false,
limit: 25
});const newDoc = await client.documents.create({
title: 'Document Title',
text: '# Markdown content',
collectionId: 'collection-id',
parentDocumentId: 'parent-id', // optional
publish: true
});const updated = await client.documents.update('document-id', {
title: 'Updated Title',
text: 'Updated content',
publish: true
});await client.documents.delete('document-id', permanent);const exported = await client.documents.export('document-id', 'markdown');
// formats: 'markdown', 'html', 'pdf'const collections = await client.collections.list();const collection = await client.collections.info('collection-id');const newCollection = await client.collections.create({
name: 'New Collection',
description: 'Collection description',
color: '#4285F4',
permission: 'read_write'
});const docs = await client.collections.documents('collection-id', {
limit: 50,
offset: 0
});const authInfo = await client.auth.info();
console.log(authInfo.data?.user);
console.log(authInfo.data?.team);Iterate through all documents efficiently:
// Iterate through all documents
for await (const document of client.documents.iterate()) {
console.log(document.title);
}
// Iterate through collection documents
for await (const document of client.documents.iterate({ collectionId: 'id' })) {
console.log(document.title);
}import { OutlineAPIError } from 'outline-api-client';
try {
const doc = await client.documents.info('invalid-id');
} catch (error) {
if (error instanceof OutlineAPIError) {
if (error.isNotFoundError()) {
console.log('Document not found');
} else if (error.isAuthError()) {
console.log('Authentication failed');
} else if (error.isRateLimitError()) {
console.log('Rate limit exceeded');
}
}
}const client = new OutlineClient({
apiKey: 'your-api-key',
apiUrl: 'https://custom.outline.instance/api',
timeout: 60000, // 60 seconds
retryAttempts: 5,
retryDelay: 2000 // 2 seconds
});A React demo is included to showcase the library's capabilities. Note that due to CORS restrictions, the demo cannot directly connect to Outline SaaS.
# Run the demo
npm run demo:devMIT
Contributions are welcome! Please feel free to submit a Pull Request.