TypeScript client for the Locu REST API.
npm install @loculabs/api-clientimport{createLocuClient}from'@loculabs/api-client'constlocu=createLocuClient({token: 'your-api-token',})// Tasksconst{data: tasks}=awaitlocu.tasks.list()consttask=awaitlocu.tasks.create({name: 'My task',section: 'today'})awaitlocu.tasks.update(task.id,{done: 'completed'})// Projectsconst{data: projects}=awaitlocu.projects.list()// Notesconst{data: notes}=awaitlocu.notes.list()// Sessionsconst{data: sessions}=awaitlocu.sessions.list()// Timerconsttimer=awaitlocu.timer.get()awaitlocu.timer.start({taskId: 'task-id'})awaitlocu.timer.stop()// Webhooksconstwebhook=awaitlocu.webhooks.create({url: 'https://example.com/webhook'})console.log('Secret:',webhook.secret)// Save this!import{verifyWebhookSignature,parseWebhookPayload}from'@loculabs/api-client'app.post('/webhook',(req,res)=>{constresult=verifyWebhookSignature(process.env.WEBHOOK_SECRET,req.headers['x-webhook-signature'],req.body,{maxAge: 300})if(!result.valid){returnres.status(401).json({error: result.error})}constpayload=parseWebhookPayload(req.body)console.log('Event:',payload.event,'Data:',payload.data)res.sendStatus(200)})The client code is generated from a declarative configuration that validates against the OpenAPI spec. This ensures you never forget to add new endpoints.
# Generate types from OpenAPI spec + generate client code
npm run generate
# Or for local development (uses localhost API)
npm run generate:devIf the API has new endpoints that aren't covered by the client, the generator will fail with an error listing the missing paths:
❌ ERROR: The following API paths are NOT covered by the client:
- /users
- /users/{id}
Add them to RESOURCES in scripts/generate-client.ts
- Add the new resource to
RESOURCESin scripts/generate-client.ts - Run
npm run generate - The client will be regenerated with the new endpoints
MIT