@tenxyte/core
The official core JavaScript/TypeScript SDK for the Tenxyte API.
This SDK is the foundation for interacting securely with Tenxyte's robust authentication, multi-tenant organization management, and Advanced AI Security (AIRS) capabilities.
Installation
You can install the package using npm, yarn, or pnpm:
npm install @tenxyte/core
yarn add @tenxyte/core
pnpm add @tenxyte/core
Initialization
The single entry point for all operations is the TenxyteClient. You must initialize it with your API's base URL and (if you're using App-Centric auth) the appKey in headers.
Important: Never expose an appSecret in frontend environments like React or Vue client bundles. Use it exclusively in server-side processes.
import { TenxyteClient } from '@tenxyte/core';
const tx = new TenxyteClient({
baseUrl: 'https://api.my-backend.com',
headers: {
'X-Access-Key': 'your-public-app-key'
}
});
The SDK is composed of separate functional modules: auth, security, rbac, user, b2b, and ai.
Authentication Flows
Standard Email / Password
try {
const { user, tokens } = await tx.auth.loginWithEmail('user@example.com', 'secure_password!');
console.log(`Welcome back, ${user.first_name}!`);
} catch (error) {
if (error.code === '2FA_REQUIRED') {
await tx.auth.loginWithEmail('user@example.com', 'secure_password!', { totpCode: '123456' });
}
}
Social Login (OAuth2)
const response = await tx.auth.loginWithSocial('google', {
id_token: 'google_id_token_jwt'
});
const callback = await tx.auth.handleSocialCallback('github', 'auth_code', 'https://myapp.com/callback');
Passwordless (Magic Link)
await tx.auth.requestMagicLink('user@example.com', 'https://myapp.com/verify-magic');
const { user, tokens } = await tx.auth.verifyMagicLink(urlParams.get('token'));
Authorization & RBAC
The SDK automatically intercepts your requests to attach Authorization: Bearer <token> when available.
By utilizing the embedded EventEmitter, you can listen to rotation and expiration changes.
tx.http.addResponseInterceptor(async (response) => {
return response;
});
Verifying Roles and Permissions
const myRoles = await tx.user.getMyRoles();
const roles = await tx.rbac.listRoles();
Advanced Security
WebAuthn / Passkeys
The security module natively wraps browser credentials APIs to seamlessly interact with Tenxyte's FIDO2 bindings.
await tx.security.registerWebAuthn('My MacBook Chrome');
const session = await tx.security.authenticateWebAuthn('user@example.com');
2FA (TOTP) Enrollment
const { secret, qr_code_url, backup_codes } = await tx.security.setup2FA();
await tx.security.confirm2FA(userProvidedCode);
B2B Organizations (Multi-Tenancy)
Tenxyte natively supports complex multi-tenant B2B topologies. Using switchOrganization instructs the SDK to pass the context X-Org-Slug downstream transparently.
tx.b2b.switchOrganization('acme-corp');
const members = await tx.b2b.listMembers('acme-corp');
await tx.b2b.inviteMember('acme-corp', { email: 'dev@example.com', role_code: 'admin' });
tx.b2b.clearOrganization();
AIRS (AI Responsibility & Security)
If your architecture includes orchestrating authenticated LLM agents that take action via Tenxyte endpoints, you must use AgentTokens.
const agentTokenData = await tx.ai.createAgentToken({
agent_id: 'Invoice-Parser-Bot',
permissions: ['invoices.read', 'invoices.create'],
budget_limit_usd: 5.00,
circuit_breaker: { max_requests: 100, window_seconds: 60 }
});
tx.ai.setAgentToken(agentTokenData.token);
await tx.ai.sendHeartbeat(agentTokenData.id);
await tx.ai.reportUsage(agentTokenData.id, {
cost_usd: 0.015,
prompt_tokens: 1540,
completion_tokens: 420
});
tx.ai.clearAgentToken();
Human In The Loop (HITL) & Auditing
tx.ai.setTraceId('trace-1234abcd-prompt');
const pendingActions = await tx.ai.listPendingActions();
await tx.ai.confirmPendingAction(pendingActions[0].confirmation_token);
License
MIT