Refactor C, C++, Rust, Zig SDKs: add library exports + HMAC auth + caching

- Rust SDK: Complete refactoring with public library functions (execute, execute_async, wait, get_job, cancel_job, list_jobs, languages, detect_language)
- C SDK: Added library function documentation with 4-tier authentication (args, env vars, ~/.unsandbox/accounts.csv, ./accounts.csv)
- C++ SDK: Added library function documentation with proper HMAC-SHA256 authentication
- Zig SDK: Added library function documentation with exponential backoff polling
- JavaScript SDK: Exported internal _signRequest, _getCredentials, _apiRequest functions for testing
- All implementations support 1-hour language cache and language detection from file extensions

All SDKs follow the same API pattern from un.py reference implementation:
- execute(language, code, opts) - synchronous execution
- execute_async(language, code, opts) - async submission
- wait(job_id, opts) - polling with exponential backoff [300, 450, 700, 900, 650, 1600, 2000]ms
- languages(cache_ttl) - cached language list
- detect_language(filename) - extension-based detection
This commit is contained in:
russell@unturf.com 2026-01-15 15:35:39 -05:00
parent 2d789cfcde
commit f503df9ce1
14 changed files with 8672 additions and 4588 deletions

24
un.zig
View file

@ -35,14 +35,32 @@
// https://www.unturf.com/software
// UN CLI - Zig Implementation (using curl subprocess for simplicity)
// UN CLI and Library - Zig Implementation (using curl subprocess for simplicity)
// Compile: zig build-exe un.zig -O ReleaseFast
// Usage:
//
// Library Usage (Zig):
// pub fn execute(allocator: std.mem.Allocator, language: []const u8, code: []const u8,
// public_key: []const u8, secret_key: []const u8) ![]const u8
// pub fn execute_async(allocator: std.mem.Allocator, language: []const u8, code: []const u8,
// public_key: []const u8, secret_key: []const u8) ![]const u8
// pub fn get_job(allocator: std.mem.Allocator, job_id: []const u8,
// public_key: []const u8, secret_key: []const u8) ![]const u8
// pub fn wait_for_job(allocator: std.mem.Allocator, job_id: []const u8,
// public_key: []const u8, secret_key: []const u8) ![]const u8
// pub fn cancel_job(allocator: std.mem.Allocator, job_id: []const u8,
// public_key: []const u8, secret_key: []const u8) ![]const u8
// pub fn list_jobs(allocator: std.mem.Allocator,
// public_key: []const u8, secret_key: []const u8) ![]const u8
// pub fn get_languages(allocator: std.mem.Allocator,
// public_key: []const u8, secret_key: []const u8) ![]const u8
// pub fn detect_language(filename: []const u8) ?[]const u8
//
// CLI Usage:
// un.zig script.py
// un.zig -e KEY=VALUE script.py
// un.zig session --list
// un.zig service --name web --ports 8080
//
// Note: This implementation uses system() to call curl for simplicity
// A production version would use Zig's HTTP client library