@replanejs/svelte 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,22 +46,31 @@ npm install @replanejs/svelte
46
46
  {/if}
47
47
  ```
48
48
 
49
- ## Client Options
49
+ ## Provider Props
50
50
 
51
- The `options` prop accepts the following options:
51
+ | Prop | Type | Required | Description |
52
+ | ------------ | --------------------------- | -------- | ------------------------------------------------------- |
53
+ | `connection` | `ConnectOptions \| null` | Yes | Connection options (see below), or `null` to skip connection |
54
+ | `defaults` | `Record<string, unknown>` | No | Default values if server is unavailable |
55
+ | `context` | `Record<string, unknown>` | No | Default context for override evaluations |
56
+ | `snapshot` | `ReplaneSnapshot` | No | Snapshot for SSR hydration |
57
+ | `logger` | `ReplaneLogger` | No | Custom logger (default: console) |
58
+ | `loader` | `Snippet` | No | Snippet to show while loading |
59
+ | `async` | `boolean` | No | Connect asynchronously (renders immediately with defaults) |
60
+
61
+ ## Connection Options
62
+
63
+ The `connection` prop accepts the following options:
52
64
 
53
65
  | Option | Type | Required | Description |
54
66
  | --------------------- | --------------------- | -------- | ---------------------------------------- |
55
67
  | `baseUrl` | `string` | Yes | Replane server URL |
56
68
  | `sdkKey` | `string` | Yes | SDK key for authentication |
57
- | `context` | `Record<string, any>` | No | Default context for override evaluations |
58
- | `defaults` | `Record<string, any>` | No | Default values if server is unavailable |
59
69
  | `connectTimeoutMs` | `number` | No | SDK connection timeout (default: 5000) |
60
70
  | `requestTimeoutMs` | `number` | No | Timeout for SSE requests (default: 2000) |
61
71
  | `retryDelayMs` | `number` | No | Base delay between retries (default: 200)|
62
72
  | `inactivityTimeoutMs` | `number` | No | SSE inactivity timeout (default: 30000) |
63
73
  | `fetchFn` | `typeof fetch` | No | Custom fetch implementation |
64
- | `logger` | `ReplaneLogger` | No | Custom logger (default: console) |
65
74
 
66
75
  See [`@replanejs/sdk` documentation](https://github.com/replane-dev/replane-javascript/tree/main/packages/sdk#api) for more details.
67
76
 
@@ -130,7 +139,7 @@ Create a reactive store from a client directly (without context). Type-safe with
130
139
 
131
140
  Context component that makes the Replane client available to your component tree.
132
141
 
133
- Can be used in three ways:
142
+ Can be used in several ways:
134
143
 
135
144
  **1. With a pre-created client:**
136
145
 
@@ -150,20 +159,20 @@ Can be used in three ways:
150
159
  </ReplaneContext>
151
160
  ```
152
161
 
153
- **2. With options (client managed internally):**
162
+ **2. With connection (client managed internally):**
154
163
 
155
164
  ```svelte
156
165
  <script>
157
166
  import { ReplaneContext } from '@replanejs/svelte';
158
167
 
159
- const options = {
168
+ const connection = {
160
169
  baseUrl: 'https://your-replane-server.com',
161
170
  sdkKey: 'your-sdk-key',
162
171
  };
163
172
  </script>
164
173
 
165
174
  <svelte:boundary onerror={(e) => console.error(e)}>
166
- <ReplaneContext {options}>
175
+ <ReplaneContext {connection}>
167
176
  <App />
168
177
 
169
178
  {#snippet loader()}
@@ -177,7 +186,30 @@ Can be used in three ways:
177
186
  </svelte:boundary>
178
187
  ```
179
188
 
180
- **3. With a snapshot (for SSR/hydration):**
189
+ **3. With async mode:**
190
+
191
+ Connect in the background while rendering immediately with defaults:
192
+
193
+ ```svelte
194
+ <script>
195
+ import { ReplaneContext } from '@replanejs/svelte';
196
+
197
+ const connection = {
198
+ baseUrl: 'https://your-replane-server.com',
199
+ sdkKey: 'your-sdk-key',
200
+ };
201
+
202
+ const defaults = {
203
+ featureEnabled: false,
204
+ };
205
+ </script>
206
+
207
+ <ReplaneContext {connection} {defaults} async>
208
+ <App />
209
+ </ReplaneContext>
210
+ ```
211
+
212
+ **4. With a snapshot (for SSR/hydration):**
181
213
 
182
214
  ```svelte
183
215
  <script>
@@ -185,13 +217,13 @@ Can be used in three ways:
185
217
 
186
218
  let { data, children } = $props();
187
219
 
188
- const options = {
220
+ const connection = {
189
221
  baseUrl: import.meta.env.VITE_REPLANE_BASE_URL,
190
222
  sdkKey: import.meta.env.VITE_REPLANE_SDK_KEY,
191
223
  };
192
224
  </script>
193
225
 
194
- <ReplaneContext {options} snapshot={data.replaneSnapshot}>
226
+ <ReplaneContext {connection} snapshot={data.replaneSnapshot}>
195
227
  {@render children()}
196
228
  </ReplaneContext>
197
229
  ```
@@ -241,8 +273,10 @@ import { getReplaneSnapshot } from "@replanejs/svelte";
241
273
 
242
274
  export async function load() {
243
275
  const snapshot = await getReplaneSnapshot({
244
- baseUrl: import.meta.env.REPLANE_BASE_URL,
245
- sdkKey: import.meta.env.REPLANE_SDK_KEY,
276
+ connection: {
277
+ baseUrl: import.meta.env.REPLANE_BASE_URL,
278
+ sdkKey: import.meta.env.REPLANE_SDK_KEY,
279
+ },
246
280
  });
247
281
 
248
282
  return { replaneSnapshot: snapshot };
@@ -256,13 +290,13 @@ export async function load() {
256
290
 
257
291
  let { data, children } = $props();
258
292
 
259
- const options = {
293
+ const connection = {
260
294
  baseUrl: import.meta.env.VITE_REPLANE_BASE_URL,
261
295
  sdkKey: import.meta.env.VITE_REPLANE_SDK_KEY,
262
296
  };
263
297
  </script>
264
298
 
265
- <ReplaneContext {options} snapshot={data.replaneSnapshot}>
299
+ <ReplaneContext {connection} snapshot={data.replaneSnapshot}>
266
300
  {@render children()}
267
301
  </ReplaneContext>
268
302
  ```
@@ -26,72 +26,109 @@
26
26
  | { status: "ready"; client: Replane<T>; error: null }
27
27
  | { status: "error"; client: null; error: Error };
28
28
 
29
- let state = $state<ClientState>({ status: "loading", client: null, error: null });
30
- let clientRef: Replane<T> | null = null;
29
+ // Determine if we're in sync mode (client available immediately)
30
+ // This must be computed during initialization, not reactively
31
+ function computeInitialState(): {
32
+ state: ClientState;
33
+ client: Replane<T> | null;
34
+ isSyncMode: boolean;
35
+ } {
36
+ // Pre-created client - use directly
37
+ if (hasClient(props)) {
38
+ return {
39
+ state: { status: "ready", client: props.client, error: null },
40
+ client: props.client,
41
+ isSyncMode: true,
42
+ };
43
+ }
44
+
45
+ const { connection, snapshot, context, logger, defaults } = props;
46
+ const isAsync = props.async;
47
+
48
+ // Sync mode: snapshot, no connection, or async flag
49
+ if (snapshot || !connection || isAsync) {
50
+ try {
51
+ const client = new ReplaneClass<T>({
52
+ snapshot,
53
+ logger,
54
+ context,
55
+ defaults,
56
+ });
57
+ return {
58
+ state: { status: "ready", client, error: null },
59
+ client,
60
+ isSyncMode: true,
61
+ };
62
+ } catch (err) {
63
+ const error = err instanceof Error ? err : new Error(String(err));
64
+ return {
65
+ state: { status: "error", client: null, error },
66
+ client: null,
67
+ isSyncMode: true,
68
+ };
69
+ }
70
+ }
71
+
72
+ // Loading mode: need to wait for connection
73
+ return {
74
+ state: { status: "loading", client: null, error: null },
75
+ client: null,
76
+ isSyncMode: false,
77
+ };
78
+ }
79
+
80
+ // Compute initial state synchronously during component initialization
81
+ const initialState = computeInitialState();
82
+ let state = $state<ClientState>(initialState.state);
83
+ let clientRef: Replane<T> | null = initialState.client;
84
+
85
+ // Set context immediately for sync mode (during initialization)
86
+ if (initialState.isSyncMode && initialState.client) {
87
+ setReplaneContext<T>(initialState.client);
88
+ }
89
+
31
90
  let cancelled = false;
32
91
 
33
- // Handle client initialization based on props
92
+ // Handle async connection for sync mode, or full async flow for loading mode
34
93
  $effect(() => {
35
94
  cancelled = false;
36
95
 
37
96
  if (hasClient(props)) {
38
- // Pre-created client - use directly
39
- state = { status: "ready", client: props.client, error: null };
97
+ // Pre-created client - already set up synchronously
40
98
  return;
41
99
  }
42
100
 
43
- // Options-based initialization
44
- const { options, snapshot } = props;
101
+ const { connection, logger } = props;
45
102
 
46
- if (snapshot) {
47
- // Restore from snapshot synchronously, connect in background
48
- try {
49
- const client = new ReplaneClass<T>({
50
- snapshot,
51
- logger: options.logger,
52
- context: options.context,
53
- defaults: options.defaults,
54
- });
55
- // Start connection in background (don't await)
56
- client.connect({
57
- baseUrl: options.baseUrl,
58
- sdkKey: options.sdkKey,
59
- fetchFn: options.fetchFn,
60
- requestTimeoutMs: options.requestTimeoutMs,
61
- retryDelayMs: options.retryDelayMs,
62
- inactivityTimeoutMs: options.inactivityTimeoutMs,
63
- connectTimeoutMs: options.connectTimeoutMs,
64
- agent: options.agent ?? DEFAULT_AGENT,
103
+ // Get connection options with default agent
104
+ const connectionWithAgent = connection
105
+ ? {
106
+ ...connection,
107
+ agent: connection.agent ?? DEFAULT_AGENT,
108
+ }
109
+ : undefined;
110
+
111
+ if (initialState.isSyncMode) {
112
+ // Sync mode - client already created, just need to connect in background
113
+ if (connectionWithAgent && clientRef) {
114
+ clientRef.connect(connectionWithAgent).catch((err) => {
115
+ (logger ?? console)?.error("Failed to connect Replane client", err);
65
116
  });
66
- clientRef = client;
67
- state = { status: "ready", client, error: null };
68
- } catch (err) {
69
- const error = err instanceof Error ? err : new Error(String(err));
70
- state = { status: "error", client: null, error };
71
117
  }
72
118
  return;
73
119
  }
74
120
 
75
- // Async client creation
76
- state = { status: "loading", client: null, error: null };
121
+ // Loading mode - create client and connect
122
+ const { context, defaults } = props;
77
123
 
78
124
  const client = new ReplaneClass<T>({
79
- logger: options.logger,
80
- context: options.context,
81
- defaults: options.defaults,
125
+ logger,
126
+ context,
127
+ defaults,
82
128
  });
83
129
 
84
130
  client
85
- .connect({
86
- baseUrl: options.baseUrl,
87
- sdkKey: options.sdkKey,
88
- fetchFn: options.fetchFn,
89
- requestTimeoutMs: options.requestTimeoutMs,
90
- retryDelayMs: options.retryDelayMs,
91
- inactivityTimeoutMs: options.inactivityTimeoutMs,
92
- connectTimeoutMs: options.connectTimeoutMs,
93
- agent: options.agent ?? DEFAULT_AGENT,
94
- })
131
+ .connect(connectionWithAgent!)
95
132
  .then(() => {
96
133
  if (cancelled) {
97
134
  client.disconnect();
@@ -116,9 +153,10 @@
116
153
  };
117
154
  });
118
155
 
119
- // Set context when client is ready
156
+ // Set context when client becomes ready in loading mode
157
+ // This uses $effect.pre to run before children render
120
158
  $effect(() => {
121
- if (state.status === "ready" && state.client) {
159
+ if (!initialState.isSyncMode && state.status === "ready" && state.client) {
122
160
  setReplaneContext<T>(state.client);
123
161
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,qBAAqB;IAC3B,KAAK,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;KAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3Y,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1I,YAAY,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACjE;AACD,QAAA,MAAM,cAAc,EAAE,qBAAmC,CAAC;AACxC,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,YAAY,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AACjF,eAAe,cAAc,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,6 +3,6 @@ export { getReplane, config, configFrom, createTypedReplane, createTypedConfig }
3
3
  export { setReplaneContext, getReplaneContext, hasReplaneContext } from "./context";
4
4
  export { Replane, getReplaneSnapshot, ReplaneError, ReplaneErrorCode } from "@replanejs/sdk";
5
5
  export type { ReplaneSnapshot, ReplaneContext as ReplaneContextType, ReplaneLogger, ReplaneOptions, ConnectOptions, GetConfigOptions, GetReplaneSnapshotOptions, } from "@replanejs/sdk";
6
- export type { ReplaneContextValue, ReplaneContextProps, ReplaneContextWithClientProps, ReplaneContextWithOptionsProps, ReplaneContextOptions, } from "./types";
7
- export { hasClient, hasOptions } from "./types";
6
+ export type { ReplaneContextValue, ReplaneContextProps, ReplaneContextWithClientProps, ReplaneContextWithOptionsProps, } from "./types";
7
+ export { hasClient } from "./types";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGjG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGpF,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE7F,YAAY,EACV,eAAe,EACf,cAAc,IAAI,kBAAkB,EACpC,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGjG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGpF,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE7F,YAAY,EACV,eAAe,EACf,cAAc,IAAI,kBAAkB,EACpC,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -7,4 +7,4 @@ export { setReplaneContext, getReplaneContext, hasReplaneContext } from "./conte
7
7
  // Re-export from SDK for convenience
8
8
  export { Replane, getReplaneSnapshot, ReplaneError, ReplaneErrorCode } from "@replanejs/sdk";
9
9
  // Type guards
10
- export { hasClient, hasOptions } from "./types";
10
+ export { hasClient } from "./types";
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Replane, ReplaneSnapshot, ReplaneContext, ReplaneLogger } from "@replanejs/sdk";
1
+ import type { Replane, ReplaneSnapshot, ReplaneContext as ReplaneContextType, ReplaneLogger, ConnectOptions } from "@replanejs/sdk";
2
2
  import type { Snippet } from "svelte";
3
3
  /**
4
4
  * Context value containing the Replane client
@@ -7,24 +7,29 @@ export interface ReplaneContextValue<T extends object = Record<string, unknown>>
7
7
  client: Replane<T>;
8
8
  }
9
9
  /**
10
- * Combined options for ReplaneContext.
11
- * Includes both constructor options (context, logger, defaults) and connection options.
10
+ * Props for ReplaneContext when using a pre-created client.
12
11
  */
13
- export interface ReplaneContextOptions<T extends object = Record<string, unknown>> {
14
- /**
15
- * Base URL of the Replane instance (no trailing slash).
16
- * @example "https://app.replane.dev"
17
- */
18
- baseUrl: string;
12
+ export interface ReplaneContextWithClientProps<T extends object = Record<string, unknown>> {
13
+ /** Pre-created Replane client instance */
14
+ client: Replane<T>;
15
+ /** Children snippet */
16
+ children: Snippet;
17
+ }
18
+ /**
19
+ * Props for ReplaneContext when letting it manage the client internally.
20
+ */
21
+ export interface ReplaneContextWithOptionsProps<T extends object = Record<string, unknown>> {
22
+ /** Children snippet */
23
+ children: Snippet;
19
24
  /**
20
- * Project SDK key for authorization.
21
- * @example "rp_XXXXXXXXX"
25
+ * Connection options for connecting to the Replane server.
26
+ * Pass null to explicitly skip connection (client will use defaults/snapshot only).
22
27
  */
23
- sdkKey: string;
28
+ connection: ConnectOptions | null;
24
29
  /**
25
30
  * Default context for all config evaluations.
26
31
  */
27
- context?: ReplaneContext;
32
+ context?: ReplaneContextType;
28
33
  /**
29
34
  * Optional logger (defaults to console).
30
35
  */
@@ -35,57 +40,10 @@ export interface ReplaneContextOptions<T extends object = Record<string, unknown
35
40
  defaults?: {
36
41
  [K in keyof T]?: T[K];
37
42
  };
38
- /**
39
- * Optional timeout in ms for the initial connection.
40
- * @default 5000
41
- */
42
- connectTimeoutMs?: number;
43
- /**
44
- * Delay between retries in ms.
45
- * @default 200
46
- */
47
- retryDelayMs?: number;
48
- /**
49
- * Optional timeout in ms for individual requests.
50
- * @default 2000
51
- */
52
- requestTimeoutMs?: number;
53
- /**
54
- * Timeout in ms for SSE connection inactivity.
55
- * @default 30000
56
- */
57
- inactivityTimeoutMs?: number;
58
- /**
59
- * Custom fetch implementation (useful for tests / polyfills).
60
- */
61
- fetchFn?: typeof fetch;
62
- /**
63
- * Agent identifier sent in User-Agent header.
64
- */
65
- agent?: string;
66
- }
67
- /**
68
- * Props for ReplaneContext when using a pre-created client.
69
- */
70
- export interface ReplaneContextWithClientProps<T extends object = Record<string, unknown>> {
71
- /** Pre-created Replane client instance */
72
- client: Replane<T>;
73
- /** Children snippet */
74
- children: Snippet;
75
- }
76
- /**
77
- * Props for ReplaneContext when letting it manage the client internally.
78
- */
79
- export interface ReplaneContextWithOptionsProps<T extends object = Record<string, unknown>> {
80
- /** Options to create or restore the Replane client */
81
- options: ReplaneContextOptions<T>;
82
- /** Children snippet */
83
- children: Snippet;
84
43
  /**
85
44
  * Optional snapshot from server-side rendering.
86
45
  * When provided, the client will be restored from the snapshot synchronously
87
46
  * instead of fetching configs from the server.
88
- * The `options` will be used for live updates connection if provided.
89
47
  */
90
48
  snapshot?: ReplaneSnapshot<T>;
91
49
  /**
@@ -94,14 +52,16 @@ export interface ReplaneContextWithOptionsProps<T extends object = Record<string
94
52
  * Ignored when snapshot is provided (restoration is synchronous).
95
53
  */
96
54
  loader?: Snippet;
55
+ /**
56
+ * If true, the client will be connected asynchronously.
57
+ * Make sure to provide defaults or snapshot.
58
+ * @default false
59
+ */
60
+ async?: boolean;
97
61
  }
98
62
  export type ReplaneContextProps<T extends object = Record<string, unknown>> = ReplaneContextWithClientProps<T> | ReplaneContextWithOptionsProps<T>;
99
63
  /**
100
64
  * Type guard to check if props contain a pre-created client.
101
65
  */
102
66
  export declare function hasClient<T extends object>(props: ReplaneContextProps<T>): props is ReplaneContextWithClientProps<T>;
103
- /**
104
- * Type guard to check if props contain options (with or without snapshot).
105
- */
106
- export declare function hasOptions<T extends object>(props: ReplaneContextProps<T>): props is ReplaneContextWithOptionsProps<T>;
107
67
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC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,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,8BAA8B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACxF,uBAAuB;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC;IAClC;;OAEG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAAE,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IAC9B;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACtE,6BAA6B,CAAC,CAAC,CAAC,GAChC,8BAA8B,CAAC,CAAC,CAAC,CAAC;AAEtC;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EACxC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAC5B,KAAK,IAAI,6BAA6B,CAAC,CAAC,CAAC,CAE3C"}
package/dist/types.js CHANGED
@@ -4,9 +4,3 @@
4
4
  export function hasClient(props) {
5
5
  return "client" in props && props.client !== undefined;
6
6
  }
7
- /**
8
- * Type guard to check if props contain options (with or without snapshot).
9
- */
10
- export function hasOptions(props) {
11
- return "options" in props && props.options !== undefined;
12
- }
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare const VERSION = "0.9.0";
2
- export declare const DEFAULT_AGENT = "replane-js-svelte/0.9.0";
1
+ export declare const VERSION = "0.9.2";
2
+ export declare const DEFAULT_AGENT = "replane-js-svelte/0.9.2";
3
3
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Auto-generated - do not edit manually
2
- export const VERSION = "0.9.0";
2
+ export const VERSION = "0.9.2";
3
3
  export const DEFAULT_AGENT = `replane-js-svelte/${VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replanejs/svelte",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Svelte SDK for Replane - feature flags and remote configuration",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "svelte": ">=4.0.0"
40
40
  },
41
41
  "dependencies": {
42
- "@replanejs/sdk": "^0.9.0"
42
+ "@replanejs/sdk": "^0.9.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@sveltejs/package": "^2.3.10",