TypeScript SDK
Install and use the MisarBlog TypeScript / JavaScript SDK
Installation
npm install @misar/blog
# or
pnpm add @misar/blog
Embed a MisarBlog article
import { embed } from '@misar/blog';
const result = embed('#container', {
username: 'gulshan',
slug: 'my-article',
theme: 'dark',
width: '100%',
height: 600,
});
// Remove the embed later
result.destroy();
Get the embed URL only
import { embedUrl } from '@misar/blog';
const url = embedUrl({ username: 'gulshan', slug: 'my-article', theme: 'light' });
// → "https://misar.blog/gulshan/my-article/embed?theme=light"
const profileUrl = embedUrl({ username: 'gulshan' });
// → "https://misar.blog/gulshan/embed"
Token management
import { refreshToken, getToken, clearToken } from '@misar/blog';
// Refresh an expiring token
const result = await refreshToken({ token: currentToken });
console.log(result.token, result.expiresAt);
// Read the stored token (from localStorage)
const stored = getToken();
// Remove the stored token
clearToken();
API reference
embed(container, options): EmbedResult
Mounts an <iframe> inside container (CSS selector or HTMLElement).
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| username | string | — | MisarBlog username (required) |
| slug | string | undefined | Article slug — omit for profile embed |
| theme | string | "auto" | "auto" | "light" | "dark" |
| width | string \| number | "100%" | iframe width |
| height | string \| number | 600 | iframe height |
| className | string | undefined | CSS class added to the iframe |
EmbedResult.destroy() removes the iframe from the DOM.
embedUrl(options): string
Returns the embed URL without mounting anything. Accepts the same options as embed except width, height, className.
refreshToken(options): Promise<TokenRefreshResult>
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| token | string | — | Current token to refresh (required) |
| baseUrl | string | "https://misar.blog" | Override for self-hosted instances |
Returns { token: string, expiresAt: number }.
getToken(): string | null
Reads the token stored in localStorage under misar_blog_token.
clearToken(): void
Removes the stored token from localStorage.