@traffical/sdk-spec
v0.1.0
Published
Language-agnostic specifications for Traffical SDKs - schemas and test vectors
Maintainers
Readme
Traffical SDK Specification
Language-agnostic specifications for implementing Traffical SDKs.
Overview
This repository contains:
- JSON Schemas - Type definitions for configuration bundles and events
- Test Vectors - Deterministic test fixtures for validating SDK implementations
All Traffical SDKs must implement these specifications to ensure consistent behavior across languages.
Schemas
config-bundle.schema.json
The complete configuration bundle that SDKs fetch and cache. Contains:
- Organization and project identifiers
- Hashing configuration (unit key, bucket count)
- Parameters with defaults and layer membership
- Layers with policies and allocations
- Conditions for targeting
events.schema.json
Event payloads sent to the Traffical API:
- Exposure events (when a user is assigned to a variant)
- Track events (custom user actions)
traffical-config.schema.json
Local project configuration file (.traffical/config.yaml) schema.
Test Vectors
The test-vectors/ directory contains deterministic test fixtures for validating SDK implementations.
Purpose
All Traffical SDKs must produce identical results for the same inputs:
- Hashing consistency - FNV-1a hash produces the same bucket across all implementations
- Resolution correctness - Parameter resolution follows the layered priority system
- Condition evaluation - Context predicates are evaluated identically
Fixture Structure
test-vectors/
├── fixtures/
│ ├── bundle_*.json # Config bundles to test against
│ └── expected_*.json # Expected outputs for each bundle
└── README.mdRunning Tests
Each SDK implementation should:
- Load the bundle JSON
- For each test case:
- Compute buckets and verify against
expectedHashing - Resolve parameters and verify against
expectedAssignments
- Compute buckets and verify against
Hash Function Reference
Traffical uses FNV-1a (32-bit) for bucket computation:
Input: unitKeyValue + ":" + layerId
Hash: FNV-1a(input) >>> 0
Bucket: hash % bucketCountExample
- Input:
"user-abc:layer_ui" - FNV-1a hash:
2947556742 - Bucket (mod 1000):
742
FNV-1a Algorithm
FNV_OFFSET_BASIS = 2166136261
FNV_PRIME = 16777619
hash = FNV_OFFSET_BASIS
for each byte in input:
hash = hash XOR byte
hash = hash * FNV_PRIME
return hash >>> 0 // Ensure unsigned 32-bitSDK Implementations
| Language | Repository | |----------|------------| | JavaScript/TypeScript | traffical/js-sdk | | Go | Coming soon | | Java | Coming soon |
License
MIT License - see LICENSE for details.
