Web SDK
Initialization
Initialize the SDK in Next.js, React, Vue, Svelte, Angular, and vanilla JavaScript environments.
Overview
The Asiyst.init() method establishes an encrypted connection with the Asiyst Cloud Gateway, validates domain credentials, downloads avatar manifests, and mounts the floating widget into the DOM.
Method Signature & Types
interface AsiystConfig {
projectId: string; // proj_...
publicKey: string; // pk_live_... or pk_test_...
options?: AsiystOptions;
}
Asiyst.init(config: AsiystConfig): Promise<AsiystInstance>;
Framework Integration Recipes
Next.js App Router (Client Component)
// components/asiyst-provider.tsx
"use client";
import { useEffect } from "react";
import { Asiyst } from "@asiyst/sdk";
export function AsiystProvider() {
useEffect(() => {
Asiyst.init({
projectId: process.env.NEXT_PUBLIC_ASIYST_PROJECT_ID!,
publicKey: process.env.NEXT_PUBLIC_ASIYST_PUBLIC_KEY!,
options: { position: "bottom-right", theme: "auto" },
}).catch(console.error);
return () => {
Asiyst.destroy();
};
}, []);
return null;
}
Vanilla JavaScript / CDN
<script type="module">
import { Asiyst } from "https://cdn.asiyst.com/sdk/v1/asiyst.esm.js";
await Asiyst.init({
projectId: "proj_9f8a2b3c4d",
publicKey: "pk_live_8e7d6c5b4a3f2e1d",
});
</script>
Error Handling & Readiness
try {
const instance = await Asiyst.init({ projectId, publicKey });
console.log("Asiyst ready, version:", instance.version);
} catch (err: any) {
if (err.code === "DOMAIN_NOT_ALLOWED") {
console.error("Current website domain is not whitelisted.");
}
}