@kontext.dev/kontext-sdk
Version:
Unified SDK for AI-powered context and personalization
3 lines • 1.49 kB
JavaScript
import {a}from'./chunk-AXQVSE5D.js';import {b,a as a$1}from'./chunk-FRDJ4LIP.js';var s=class{constructor(e){if(!e.apiKey)throw new Error("Kontext API key is required");this.config={apiKey:e.apiKey,providers:e.providers||["gmail","preferences"],apiUrl:e.apiUrl||"https://api.kontext.dev",cache:{ttl:e.cache?.ttl||300,storage:e.cache?.storage||"memory"},limits:{maxTokensPerRequest:e.limits?.maxTokensPerRequest||2e3,monthlyBudget:e.limits?.monthlyBudget||0}},this.vault=new a(this.config.apiUrl,this.config.apiKey),this.profile=new b(this.config.apiUrl,this.config.apiKey),this.users={purge:async({userId:t})=>this.purgeUser(t)};}async disconnect(e){return this.purgeUser(e)}async purgeUser(e){if(!e||typeof e!="string")throw this.createError("Valid userId is required for disconnect. Please provide a non-empty string userId.","INVALID_USER_ID",400);try{let t=await fetch(`${this.config.apiUrl}/users/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"x-api-key":this.config.apiKey}});if(!t.ok){let a=await t.text().catch(()=>"")||`HTTP ${t.status}`;throw t.status===404?this.createError("User not found. The user may have already been purged.","USER_NOT_FOUND",404):this.createError(a,"DISCONNECT_FAILED",t.status||500)}}catch(t){let r=t instanceof Error?t.message:"Failed to purge user";throw this.createError(r,"DISCONNECT_FAILED",500)}}createError(e,t,r){return new a$1(e,t,r)}};
export{s as a};//# sourceMappingURL=chunk-LKUOP2A6.js.map
//# sourceMappingURL=chunk-LKUOP2A6.js.map