@globiguard/js
v0.3.0
Published
Official dependency-minimal vanilla JavaScript SDK for GlobiGuard.
Readme
globiguard-js
Official dependency-minimal vanilla JavaScript SDK for GlobiGuard.
This package is plain ESM JavaScript with no runtime dependencies. It mirrors the TypeScript SDK wire contract while staying usable from modern browsers, Node, and workers.
Install
npm install @globiguard/jsServer client
import { createServerClient, secretCredential } from "@globiguard/js";
const client = createServerClient({
environment: "sandbox",
services: { controlPlane: "https://api.globiguard.com" },
credential: secretCredential("proj_123", "ggsk_test_...", "sandbox")
});
const decision = await client.governedActions.authorizeActionOrThrow({
context: {
actionType: "refund.create",
destination: {
type: "custom",
name: "payments-production"
},
dataClasses: ["CONFIDENTIAL"],
actor: {
id: "support-agent-123",
type: "agent"
},
purpose: "Resolve an approved customer escalation",
correlationId: "case_456",
idempotencyKey: "case_456:refund:v1"
}
});authorizeActionOrThrow returns only a current, short-lived, obligation-free
ALLOW that explicitly authorizes the exact action once. MODIFY, QUEUE,
BLOCK, dry-run, expired, and incomplete responses raise a
GlobiguardAuthorityError; the downstream business action must remain stopped.
Use client.audit.getIncidentReplay(...) and
client.audit.getEvidencePackageSummary(...) to retrieve the metadata-only
history and evidence linked to the authorization.
AI intercept
createAiIntercept wraps any AI provider call with a GlobiGuard governance checkpoint. Input is authorized before the model is called; output is classified and authorized if sensitive.
import { createServerClient, secretCredential, createAiIntercept } from '@globiguard/js';
import OpenAI from 'openai';
const client = createServerClient({
environment: 'live',
services: {
controlPlane: 'https://api.globiguard.com',
brain: 'https://brain.globiguard.com',
},
credential: secretCredential('proj_123', 'sk_...', 'live'),
});
const intercept = createAiIntercept(client.governedActions);
// OpenAI — returns a Proxy, call exactly like the original client
const governed = intercept.openai(new OpenAI());
const response = await governed.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Summarise this contract...' }],
});
// Anthropic
import Anthropic from '@anthropic-ai/sdk';
const governed = intercept.anthropic(new Anthropic());
const msg = await governed.messages.create({ model: 'claude-opus-4-8', max_tokens: 1024, messages: [...] });
// Google GenAI
import { GoogleGenerativeAI } from '@google/generative-ai';
const model = new GoogleGenerativeAI('api-key').getGenerativeModel({ model: 'gemini-1.5-pro' });
const governed = intercept.google(model);
const result = await governed.generateContent('Draft a privacy policy...');
// AWS Bedrock
import { BedrockRuntimeClient } from '@aws-sdk/client-bedrock-runtime';
const governed = intercept.bedrock(new BedrockRuntimeClient({ region: 'us-east-1' }));
const out = await governed.send(command);
// Cohere
import { CohereClient } from 'cohere-ai';
const governed = intercept.cohere(new CohereClient({ token: '...' }));
const res = await governed.chat({ message: 'Summarise...' });
// Mistral
import { Mistral } from '@mistralai/mistralai';
const governed = intercept.mistral(new Mistral({ apiKey: '...' }));
const res = await governed.chat.complete({ model: 'mistral-large-latest', messages: [...] });
// Ollama
import { Ollama } from 'ollama';
const governed = intercept.ollama(new Ollama());
const res = await governed.chat({ model: 'llama3', messages: [{ role: 'user', content: 'Hello' }] });
// Vercel AI SDK
import { openai } from '@ai-sdk/openai';
const governed = intercept.vercel(openai('gpt-4o'));
const { text } = await generateText({ model: governed, prompt: '...' });
// LangChain JS
import { ChatOpenAI } from '@langchain/openai';
const governed = intercept.langchain(new ChatOpenAI({ model: 'gpt-4o' }));
const result = await governed.invoke('Draft a contract...');
// Any provider via generic()
const governed = intercept.generic(myProviderFn, { extractInput: (params) => params.prompt });
const result = await governed({ prompt: 'Hello' });createAiIntercept accepts an optional second argument { mode, actionType, destination, onBlock }. Default mode is "scan_both". When a governance decision is BLOCK, GlobiguardAuthorityError is thrown; pass onBlock to handle it yourself.
Webhooks
const result = await verifyTrustWebhook({
headers: request.headers,
rawBody,
signingSecret: "whsec_..."
});Always pass the exact raw request body bytes/string.
Bootstrap and entitlements
The SDK includes hosted/self-hosted/sovereign bootstrap request builders and offline entitlement manifest verification. Node verifies Ed25519 through node:crypto; browsers use Web Crypto where Ed25519 is available.
Security posture
- Runtime dependencies: zero.
- HTTPS is required outside local.
- Local credentials require localhost or loopback service URLs.
- Reserved GlobiGuard auth headers cannot be overridden per request.
- Request paths reject absolute URLs, query strings, fragments, backslashes, invalid percent encoding, and dot segments.
- Trust webhooks require raw-body HMAC verification.
Development
npm test