Skip to Content
SDKsNode.js

Node.js SDK

The @relynt/sdk package provides a typed client for the Relynt authorization gateway in Node.js and TypeScript.

Install

npm install @relynt/sdk

Quick start

import { RelyntClient } from "@relynt/sdk"; const client = new RelyntClient({ baseUrl: process.env.RELYNT_API_BASE_URL!, agentSecret: process.env.RELYNT_AGENT_SECRET!, }); const result = await client.requestAction({ action: "update_deal", resource: "crm:deal:123", payload: { amount: 52000, previous_amount: 50000, }, }); console.log(result.decision); // "allow" | "deny" | "pending_approval" console.log(result.receiptId); // UUID of the signed receipt

Handling approvals

When the policy requires human approval, the decision will be "pending_approval" and an approvalId is returned. Use pollApproval to wait for the decision:

if (result.decision === "pending_approval") { const approval = await client.pollApproval({ approvalId: result.approvalId!, timeoutMs: 300_000, // 5 minutes }); console.log(approval.status); // "approved" | "denied" | "expired" console.log(approval.decidedBy); // e.g. "slack:U12345" }

Idempotency

Pass an idempotencyKey to prevent duplicate processing when retrying:

const result = await client.requestAction({ action: "update_deal", resource: "crm:deal:123", payload: { amount: 52000 }, idempotencyKey: "my-unique-key-abc123", });

Error handling

The SDK throws typed errors that you can catch and handle:

import { RelyntClient, AuthenticationError, RequestError, ApprovalTimeoutError, NetworkError, } from "@relynt/sdk"; try { const result = await client.requestAction({ ... }); } catch (err) { if (err instanceof AuthenticationError) { // Invalid or expired agent secret (401/403) } else if (err instanceof RequestError) { // Bad request (4xx) } else if (err instanceof NetworkError) { // Gateway unreachable or request timed out } }

API reference

new RelyntClient(config)

ParameterTypeRequiredDescription
baseUrlstringYesRelynt gateway URL
agentSecretstringYesAgent credential from rotation
timeoutMsnumberNoRequest timeout (default: 30000)

client.requestAction(params)

ParameterTypeRequiredDescription
actionstringYesOperation name (e.g. "update_deal")
resourcestringYesResource identifier (e.g. "crm:deal:123")
payloadobjectYesAction payload
idempotencyKeystringNoDeduplication key
instanceIdstringNoAgent instance identifier

Returns ActionResult:

{ decision: "allow" | "deny" | "pending_approval"; receiptId: string; approvalId?: string; toolResponse?: Record<string, unknown>; reason?: string; riskLevel?: "low" | "medium" | "high"; policyVersion?: string; }

client.pollApproval(params)

ParameterTypeRequiredDescription
approvalIdstringYesApproval ID from requestAction
intervalMsnumberNoPoll interval (default: 3000)
timeoutMsnumberNoMax wait time (default: 300000)

Returns ApprovalResult:

{ status: "approved" | "denied" | "expired"; decidedBy?: string; decidedAt?: string; }

Environment variables

VariableDescription
RELYNT_API_BASE_URLGateway URL
RELYNT_AGENT_SECRETAgent credential (from dashboard rotation)
RELYNT_AGENT_IDAgent UUID (informational)
RELYNT_ORG_IDOrganization UUID (informational)
Last updated on