@usevane/core
v0.1.4
Published
Signal schema, hashing, sampling, and config fetch for the Vane SDK.
Readme
@usevane/core
Signal schema, hashing, sampling, and config fetch for the Vane SDK.
bun add @usevane/coreExports
| Export | Description |
|:-------|:------------|
| SignalSchema | Zod schema defining the traffic signal contract |
| Signal | TypeScript type derived from SignalSchema |
| hashIp(ip, salt) | SHA-256 hash an IP address using Web Crypto |
| shouldSample(rate) | Probabilistic sampler — returns true at the given rate |
| validateSampleRate(rate) | Validate a sample rate is in [0, 1] |
| fetchProjectConfig(apiKey, baseUrl) | Fetch project config from the Vane API |
| ProjectConfigSchema | Zod schema for project configuration |
| ProjectConfig | TypeScript type derived from ProjectConfigSchema |
| PlatformAdapter | Interface for platform-specific signal delivery |
Usage
import { SignalSchema, hashIp, shouldSample, fetchProjectConfig } from '@usevane/core'
// Validate a signal
const result = SignalSchema.safeParse(payload)
// Hash an IP (Web Crypto — edge-safe)
const hashed = await hashIp('203.0.113.1', 'your-salt')
// Sample at 10%
if (shouldSample(0.1)) {
// send signal
}
// Fetch project config
const config = await fetchProjectConfig('proj_xxx', 'https://usevane.dev')Constraints
- Zero Node.js APIs. Runs on edge runtimes (Vercel Edge, Cloudflare Workers).
- Uses
crypto.subtlefor hashing. Neverimport crypto from 'crypto'. - Zod is the only runtime dependency.
Docs
License
MIT
