Skip to content

RasepiHQ/rasepi-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rasepi JavaScript/TypeScript SDK

Official JavaScript and TypeScript client library for the Rasepi API.

Works with Node.js 18+, Deno, Bun, and modern browsers (uses native fetch).

Installation

npm install @rasepihq/rasepi-js
# or
yarn add @rasepihq/rasepi-js
# or
pnpm add @rasepihq/rasepi-js

Quick Start

import { RasepiClient } from "@rasepihq/rasepi-js";

const client = new RasepiClient({
  baseUrl: "https://api.rasepi.com",
  accessToken: "your-access-token",
});

// List hubs
const hubs = await client.hubs.list();
console.log(hubs);

// Create an entry
const entry = await client.entries.create("hub-id", {
  title: "Getting Started",
  content: { type: "doc", content: [] },
  expiresAt: "2026-12-31T00:00:00Z",
});

Authentication

OAuth 2.0 Flow

// 1. Get the login URL
const loginUrl = client.auth.getLoginUrl("google", "https://yourapp.com/callback");

// 2. After provider callback, exchange the one-time code
const tokens = await client.auth.exchangeCode(code);

// 3. Create a new client with the tokens
const authedClient = new RasepiClient({
  baseUrl: "https://api.rasepi.com",
  accessToken: tokens.access_token,
  refreshToken: tokens.refresh_token,
  onTokenRefreshed: (access, refresh) => {
    // Persist the new tokens
    saveTokens(access, refresh);
  },
});

Dev Token (Development Only)

const client = new RasepiClient({
  baseUrl: "http://localhost:5000",
  devToken: "dev-token-{tenantId}:{userId}",
});

Features

  • Zero dependencies — uses native fetch (Node 18+)
  • Full TypeScript support — complete type definitions
  • Automatic token refresh — handles 401 → refresh → retry
  • Retry with backoff — retries 429 and 5xx errors
  • Configurable timeout — default 30 seconds

API Resources

Resource Description
client.auth OAuth login, code exchange, token refresh
client.hubs Hub CRUD, members
client.entries Entry CRUD, permissions
client.translations Block-level translations, stale detection
client.analytics Hub/entry analytics, events, time spent
client.ai AI search, conversations
client.portal Public portal feed, topics, content
client.sharing Share links management
client.expiryTemplates Expiry template CRUD
client.tags Hub tags
client.categories Hub categories
client.glossaries Hub glossary terms
client.languages Available languages, hub language config
client.plugins Plugin management and configuration
client.users User management, preferences
client.groups Group CRUD, members
client.notifications Notification management
client.freshness Content freshness scores, expiry tracking
client.billing Subscription, usage, invoices

Examples

Translations (Block-Level)

// List translations for an entry
const translations = await client.translations.list("entry-id");

// Get stale blocks that need retranslation
const stale = await client.translations.getStaleBlocks("entry-id", "de");

// Mark translation as up to date
await client.translations.markUpToDate("entry-id", "de");

Content Freshness

// Get entries expiring within 30 days
const expiring = await client.freshness.getExpiring("hub-id", 30);

// Renew an entry
await client.freshness.renew("entry-id", {
  newExpiresAt: "2027-06-30T00:00:00Z",
  reason: "Content reviewed and updated",
});

AI Search

const results = await client.ai.search("hub-id", "deployment guide");
console.log(results);

Error Handling

import { RasepiApiError } from "@rasepihq/rasepi-js";

try {
  await client.hubs.get("non-existent-id");
} catch (error) {
  if (error instanceof RasepiApiError) {
    console.error(`API error ${error.statusCode}: ${error.message}`);
    console.error("Response:", error.responseBody);
  }
}

Configuration

const client = new RasepiClient({
  baseUrl: "https://api.rasepi.com",  // Required
  accessToken: "...",                   // JWT access token
  refreshToken: "...",                  // For automatic renewal
  devToken: "...",                      // Dev-only token
  timeout: 30000,                       // Request timeout (ms)
  maxRetries: 3,                        // Retry attempts for 429/5xx
  onTokenRefreshed: (access, refresh) => {
    // Called when tokens are auto-refreshed
  },
});

License

MIT — see LICENSE.

About

Official JavaScript/TypeScript client library for the Rasepi API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors