@reqdesk/sdk-core
v1.4.2
Published
Core types, API client, storage, auth, i18n, theme, and metadata for the Reqdesk SDK
Readme
@reqdesk/sdk-core
Framework-agnostic core for the Reqdesk SDK. Ships the typed API client, storage backend, OIDC auth contract, theme primitives, i18n catalogue, and client-metadata collectors that every higher-level package (@reqdesk/widget, @reqdesk/sdk-react, the browser extension) consumes.
If you only need to talk to the Reqdesk API from your own UI — without the FAB, shadow DOM, or React surface — this is the package to install.
Install
npm install @reqdesk/sdk-core
# or
bun add @reqdesk/sdk-core
# or
pnpm add @reqdesk/sdk-coreZero peer dependencies. Pure ESM/CJS dual-build, fully tree-shakeable (sideEffects: false).
What ships
Typed API client
import { createApiClient } from '@reqdesk/sdk-core'
const api = createApiClient({
apiUrl: 'https://api.reqdesk.support',
apiKey: 'rqd_pk_…', // project-scoped or workspace-scoped
getAuthToken: async () => oidcUser?.accessToken, // optional
})
const { data } = await api.submitTicket({
title: 'Login flow regression',
description: 'Repro on Safari 17.4',
email: '[email protected]',
priority: 'high',
})
const { data: tickets } = await api.listMyTickets({ email: '[email protected]' })The client is built on ofetch, transparently maps snake_case wire payloads to camelCase, attaches the API key + signed-identity headers when present, and surfaces WidgetError on every failure path (no unknown-typed throws).
Storage backend
import { createLocalStorageBackend, type StorageBackend } from '@reqdesk/sdk-core'
const storage: StorageBackend = createLocalStorageBackend('reqdesk:v1:')
storage.set('preferred-language', 'ar')
const lang = storage.get('preferred-language')StorageBackend is the seam every consumer uses for prefs, draft tickets, and identity. Provide your own implementation (in-memory, encrypted, IndexedDB) when you need it.
Theme primitives
import { themeToVars, themeToStyle, hexToHsl, DEFAULT_THEME } from '@reqdesk/sdk-core'
const vars = themeToVars({ primaryColor: '#42b983', mode: 'dark' })
// → CSS custom-property map: '--rqd-primary', '--rqd-bg', '--rqd-text', …Centralised brand-token mapping. The widget shadow DOM, the React provider, and the extension all funnel through these helpers so a single theme config produces a consistent, contrast-aware surface across every host.
i18n
import { getTranslations, t, en, ar } from '@reqdesk/sdk-core'
const tr = getTranslations('ar') // bilingual catalogue, RTL-aware
const label = t(tr, 'submit.title') // with merged overridesEnglish and Arabic are bundled. Hosts can pass Record<string, string> overrides at init.
Client metadata
import {
collectMinimalMetadata,
collectDiagnosticMetadata,
collectAllMetadata,
} from '@reqdesk/sdk-core'
const meta = await collectAllMetadata()
// → { url, userAgent, viewport, locale, timezone, …diagnostic fields }Three privacy-tiered collectors that tickets attach automatically. The diagnostic tier is opt-in and gated by getMetadataPreferences() so end users own the disclosure.
Authentication contract
import type { AuthProvider, AuthState, OidcAuthConfig } from '@reqdesk/sdk-core'Implement AuthProvider to plug any OIDC stack into the SDK. @reqdesk/widget ships an oidc-spa-backed implementation; the extension ships a chrome.identity-backed one. Both satisfy the same contract so views (SubmitTicketView, MyTicketsView, …) work unchanged.
Used by
@reqdesk/widget— embeddable IIFE + React widget@reqdesk/sdk-react— provider, views, query options@reqdesk/extension— Chrome / Edge browser extension
Versioning
Patch releases for bug fixes, minor for additive APIs, major for breaking signatures. The @reqdesk/widget minor track follows @reqdesk/sdk-core minors so the widget never lags behind a new core capability.
License
See LICENSE in the monorepo root.
