@facilio/vibe-sdk
v0.1.5
Published
Browser SDK for Vibe — login/logout against Facilio identity-service, scoped to the vibe service.
Readme
@facilio/vibe-sdk
Browser SDK for Vibe. Wraps the Facilio identity-service redirect flow (?service=vibe) so product apps can drop in login() / logout() without re-implementing the dance.
The SDK is designed for the multi-tenant Vibe deployment, where every product subdomain routes to the same vibe-server, and /identity/* on that origin is served by a co-deployed identity-service. As a result there's no identity URL to configure — the SDK just talks to the current origin.
Install
npm i @facilio/vibe-sdkOr via CDN in plain HTML:
<script src="https://unpkg.com/@facilio/vibe-sdk"></script>Usage
Modern bundler (Vite / webpack / Next.js)
import { createVibe } from '@facilio/vibe-sdk';
const vibe = createVibe(); // serverURL defaults to window.location.origin
document.querySelector('#login')!.addEventListener('click', () => vibe.login());
document.querySelector('#logout')!.addEventListener('click', () => vibe.logout());
const me = await vibe.getCurrentUser(); // null if not signed in
if (!me) vibe.login();Plain HTML
<script src="https://unpkg.com/@facilio/vibe-sdk"></script>
<script>
const vibe = VibeSDK.createVibe();
document.getElementById('login').onclick = () => vibe.login();
document.getElementById('logout').onclick = () => vibe.logout();
</script>API
createVibe(config?) / new Vibe(config?)
| Field | Type | Required | Default | Notes |
|-------------|----------|----------|---------------------------|------------------------------------------------------------------------------------------------|
| serverURL | string | no | window.location.origin | Override vibe-server base URL. Rarely needed — only for testing against a different env. |
| service | string | no | 'vibe' | service= query param sent to identity-service. |
vibe.login(redirectTo?)
Redirects the browser to ${serverURL}/identity/login?service=vibe&redirect=.... After login, identity-service redirects back to redirectTo (defaults to window.location.href).
vibe.logout(redirectTo?)
Same shape as login, hits /identity/logout.
vibe.getCurrentUser<T>() : Promise<T | null>
GETs ${serverURL}/api/runtime/getCurrentUser with cookies. Returns null on 401.
vibe.isAuthenticated() : Promise<boolean>
Convenience wrapper around getCurrentUser.
vibe.fetch(path, init?) : Promise<Response>
Convenience fetch that auto-attaches credentials: 'include' and triggers login() on 401. Pass a relative path (/api/...) or full URL.
How it works
login()/logout()window.location.assign()to${serverURL}/identity/${action}?....- Tomcat routes
/identity/*to the co-deployed identity-service WAR. - Identity-service authenticates the user, sets a session cookie on the current host, and redirects back to
redirectTo. - The session cookie is same-origin with vibe-server, so it auto-flows on
vibe.fetch()/vibe.getCurrentUser()calls.
Server requirements
The vibe-server backing this SDK must:
- Be deployed in a Tomcat that also hosts
identity.warat the/identitycontext. (See vibe-server's Dockerfile /compile_copy.shfor the build recipe.) - Expose
GET /api/runtime/getCurrentUser→ user payload (200) or401.
No CORS is required for the supported deployment model (SDK page and vibe-server share an origin).
Build
npm install
npm run build # produces dist/ — ESM + CJS + IIFE + .d.ts
npm run dev # watch mode
npm run typecheck # tsc --noEmit