Svelte
Installation
Section titled “Installation”npm install @rep-protocol/svelte @rep-protocol/sdkBasic usage
Section titled “Basic usage”<script lang="ts"> import { repStore, repSecureStore } from '@rep-protocol/svelte';
// PUBLIC tier — synchronous, updates on hot reload const apiUrl = repStore('API_URL', 'http://localhost:3000'); const flags = repStore('FEATURE_FLAGS', '');
// SENSITIVE tier — starts as null, resolves after decryption const analyticsKey = repSecureStore('ANALYTICS_KEY');</script>
<p>API: {$apiUrl}</p><p>Analytics: {$analyticsKey ?? 'loading...'}</p>repStore(key, defaultValue?)
Section titled “repStore(key, defaultValue?)”Reads a PUBLIC tier variable as a Svelte Readable<string | undefined>.
const value: Readable<string | undefined> = repStore('API_URL');const value: Readable<string | undefined> = repStore('API_URL', 'fallback');- Synchronous initial value from the REP payload
- Automatically updates when the variable changes via hot reload
- Lazy SSE: the connection is established only when there is at least one subscriber, and closed when all subscribers unsubscribe
repSecureStore(key)
Section titled “repSecureStore(key)”Reads a SENSITIVE tier variable as a Readable<string | null>.
const value: Readable<string | null> = repSecureStore('ANALYTICS_KEY');- Starts as
null - Resolves to the decrypted value once the session key fetch completes
- Errors are swallowed (the SDK logs them); the store stays
null
Hot reload
Section titled “Hot reload”repStore subscribes to the SSE stream lazily — only when there’s at least one subscriber. The store value updates automatically. When the last subscriber unsubscribes, the SSE connection is closed.
Development mode
Section titled “Development mode”const apiUrl = repStore('API_URL', 'http://localhost:3000');Add to your index.html:
<script id="__rep__" type="application/json">{"public":{"API_URL":"http://localhost:3000"},"_meta":{"version":"0.1.0","injected_at":"2026-01-01T00:00:00Z","integrity":"hmac-sha256:dev","ttl":0}}</script>Requirements
Section titled “Requirements”- Svelte >= 4 or Svelte 5
@rep-protocol/sdkas a peer dependency
For the full API reference, see Svelte Adapter Reference.