SDK Initialization
Loading the SDK
Script Tag (Recommended)
1<script src="https://sdk.workapps.tech/v1.js"></script>2<script>3 const sdk = new WorkAppsSDK();4</script>
Always use the full CDN URL. Never use a relative path like /sdk/v1.js. The CDN version ensures you always run a compatible release.
ES Module Import
1import WorkAppsSDK from 'https://sdk.workapps.tech/v1.js';2const sdk = new WorkAppsSDK();
Constructor Options
1const sdk = new WorkAppsSDK({2 // All options are optional — defaults work for most apps.34 appId: undefined, // Auto-detected from window.__WORKAPPS__ — never set this manually5 baseUrl: '/api/workapps/v1', // Data API base path — do not change (exposed for testing environments only)67 onUnauthorized: () => {8 // Called on 401. Default: redirect to /login.9 // Override to save draft state before redirecting.10 },1112 onMaintenanceStart: (status) => {13 // Called with { status, message?, estimatedSeconds? } when maintenance begins.14 },1516 onMaintenanceEnd: () => {17 // Called when maintenance ends (any request succeeds after a 503).18 },1920 retry: {21 maxRetries: 3, // Retries for 429/502 (default: 3)22 baseDelayMs: 500, // Base delay before first retry (default: 500ms)23 },24});
How appId is Resolved
The SDK reads appId from window.__WORKAPPS__.appId, which is injected by WorkApps when your app is served. You never set this yourself. If appId cannot be resolved, the constructor throws immediately with ErrorCode.MissingAppId.
Retry Behavior
The SDK retries automatically for:
429 Rate Limited— respectsRetry-Afterheader if present (integer seconds or HTTP-date)502 Bad Gateway— network infrastructure hiccups- Network failures (device offline, DNS failure) — for
GETand single-recordDELETEonly (idempotent)
POST, PATCH, and bulk DELETE are not retried on network failure to avoid double-writes. Single-record DELETE is retried because it is idempotent.
503 Maintenance is never retried — the SDK enters maintenance mode immediately.
Cleanup
Call destroy() when your app unmounts to abort all in-flight requests and clear event handlers:
1sdk.destroy();
Pending promises reject with an AbortError. After destroy(), maintenance event handlers are also cleared.