@savvagent/svelte
v1.0.1
Published
Svelte SDK for Savvagent feature flags with stores and runes
Maintainers
Readme
@savvagent/svelte
Svelte SDK for Savvagent with stores and real-time updates. Compatible with Svelte 4 and 5.
Installation
npm install @savvagent/svelteQuick Start
<!-- +layout.svelte -->
<script>
import { initSavvagent } from '@savvagent/svelte';
initSavvagent({
apiKey: 'sdk_...',
applicationId: 'your-app-id',
});
</script>
<slot />Stores
createFlagStore(flagKey, options)
Full flag state with loading and error handling.
<script>
import { createFlagStore } from '@savvagent/svelte';
const featureFlag = createFlagStore('new-feature', {
context: { user_id: $user?.id },
defaultValue: false,
realtime: true,
});
</script>
{#if $featureFlag.loading}
<p>Loading...</p>
{:else if $featureFlag.value}
<NewFeature />
{:else}
<OldFeature />
{/if}createFlag(flagKey, options)
Simple boolean store.
<script>
import { createFlag } from '@savvagent/svelte';
const isEnabled = createFlag('new-feature');
</script>
{#if $isEnabled}
<NewFeature />
{/if}createUserIdStore()
Manage user identification.
<script>
import { createUserIdStore } from '@savvagent/svelte';
const userId = createUserIdStore();
// Set on login
$userId = user.id;
// Clear on logout
$userId = null;
</script>Functions
trackError(flagKey, error, context?)
Track errors with flag context.
<script>
import { trackError } from '@savvagent/svelte';
async function handleAction() {
try {
await doSomething();
} catch (error) {
trackError('new-feature', error);
}
}
</script>License
MIT
