Skip to content

@cshield/client

@cshield/client

Client SDK for communicating with ContractShield sidecar or centralized service.

Installation

Terminal window
npm install @cshield/client

Usage

import { ContractShieldClient } from '@cshield/client';
const client = new ContractShieldClient({
url: 'http://localhost:3100',
cacheEnabled: true,
cacheTtlMs: 60000,
failOpen: true,
retries: 2,
timeoutMs: 5000
});
const decision = await client.evaluate(context);

Options

OptionTypeDefaultDescription
urlstringrequiredSidecar/service URL
socketPathstring-Unix socket path (faster)
cacheEnabledbooleanfalseEnable response caching
cacheTtlMsnumber60000Cache TTL in ms
failOpenbooleanfalseAllow on error
retriesnumber0Retry attempts
timeoutMsnumber5000Request timeout

Unix Socket (Low Latency)

const client = new ContractShieldClient({
socketPath: '/var/run/contractshield/pdp.sock'
});

Latency: ~0.1ms vs ~1-5ms for HTTP.