@b4m-oss/kiyax-js-sdk
v0.10.3
Published
KIYAX Public API SDK for JavaScript/TypeScript
Readme
@b4m-oss/kiyax-js-sdk
KIYAX Public API SDK for JavaScript/TypeScript
Installation
As an npm package
npm install @b4m-oss/kiyax-js-sdkVia script tag (CDN)
<script src="https://example.com/@b4m-oss/kiyax-js-sdk/dist/index.min.umd.js"></script>Usage
ES Module
import { KiyaxSDK } from '@b4m-oss/kiyax-js-sdk'
const sdk = new KiyaxSDK({
apiBase: 'https://example.com/', // Base URL of the KIYAX API
timeout: 10000, // Timeout in milliseconds
})
// Load a document and render it into a DOM element
await sdk.loadAndRenderDocument(1, '#document-container')
// Fetch document data only
const document = await sdk.getData(1)
console.log(document.title)
// Load a CMS article and render it
await sdk.loadAndRenderCMSArticle(1, '#article-container')
// Load a CMS article list
const list = await sdk.loadCMSList(1, { page: 1, limit: 10 })UMD (via script tag)
<div id="document-container"></div>
<script src="https://example.com/@b4m-oss/kiyax-js-sdk/dist/index.min.umd.js"></script>
<script>
const sdk = new KiyaxSDK.KiyaxSDK({
apiBase: 'https://example.com/'
})
sdk.loadAndRenderDocument(1, '#document-container')
.then(data => {
console.log('Loaded:', data)
})
.catch(error => {
console.error('Error:', error)
})
</script>API
KiyaxSDK
Constructor
new KiyaxSDK(config?: SDKConfig)config:
apiBase?: string- Base URL of the KIYAX API (default:https://example.com/)timeout?: number- Request timeout in milliseconds (default:10000)
Methods
loadDocument(docId: number, options?: LoadOptions): Promise<DocumentData>
Loads a document.
Parameters:
docId: number- Document IDoptions?: LoadOptionsapiBase?: string- Overrides the instance-levelapiBasetimeout?: number- Overrides the instance-leveltimeout
Returns: Promise<DocumentData>
loadCMSArticle(announcementId: number, options?: LoadOptions): Promise<CMSArticleData>
Loads a CMS article.
loadCMSList(symbolId: number, options?: LoadOptions & { page?: number; limit?: number }): Promise<CMSListData>
Loads a CMS article list.
getData(docId: number, options?: LoadOptions): Promise<DocumentData>
Fetches document data without rendering.
renderToElement(element: HTMLElement | string, data: DocumentData | CMSArticleData, options?: RenderOptions): Promise<void>
Renders data into a DOM element.
Parameters:
element: HTMLElement | string- Target element or CSS selectordata: DocumentData | CMSArticleData- Data to renderoptions?: RenderOptionsformat?: 'html' | 'markdown'- Output format (default:'html')className?: string- Base CSS class name (default:'kiyax-document'or'kiyax-cms-article')wrapperTag?: string- Wrapper tag (default:'div'or'article')
loadAndRenderDocument(docId: number, element: HTMLElement | string, loadOptions?: LoadOptions, renderOptions?: RenderOptions): Promise<DocumentData>
Loads a document and renders it into a DOM element.
loadAndRenderCMSArticle(announcementId: number, element: HTMLElement | string, loadOptions?: LoadOptions, renderOptions?: RenderOptions): Promise<CMSArticleData>
Loads a CMS article and renders it into a DOM element.
Types
DocumentData
interface DocumentData {
id: number
title: string
description: string | null
body: string
status: string
slug: string
created_at: string
updated_at: string
}CMSArticleData
interface CMSArticleData {
id: number
title: string
description: string | null
symbol_title: string | null
current_revision: {
id: number
title: string
description: string | null
body: string
}
created_at: string
updated_at: string
}Error handling
import { APIError, NetworkError } from '@b4m-oss/kiyax-js-sdk'
try {
const document = await sdk.loadDocument(1)
} catch (error) {
if (error instanceof APIError) {
console.error('API Error:', error.code, error.message)
} else if (error instanceof NetworkError) {
console.error('Network Error:', error.message)
}
}Authentication
The JS SDK supports the following modes:
- No authentication: Default
- Origin restriction: Handled via CORS configuration on the server
API key–based authentication is intended for server-side usage only (see the PHP SDK).
Development
npm install
npm run dev
npm run buildLicense
MIT
