@replanejs/svelte 0.9.0 → 0.9.4
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 +54 -18
- package/dist/ReplaneContext.svelte +86 -48
- package/dist/ReplaneContext.svelte.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types.d.ts +24 -64
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -6
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
[](https://github.com/replane-dev/replane-javascript/blob/main/LICENSE)
|
|
5
5
|
[](https://github.com/orgs/replane-dev/discussions)
|
|
6
6
|
|
|
7
|
+
> **Tip:** Get started instantly with [Replane Cloud](https://cloud.replane.dev) — no infrastructure required.
|
|
8
|
+
|
|
7
9
|
Svelte SDK for [Replane](https://github.com/replane-dev/replane) - feature flags and remote configuration with reactive stores.
|
|
8
10
|
|
|
9
11
|
## Installation
|
|
@@ -21,7 +23,7 @@ npm install @replanejs/svelte
|
|
|
21
23
|
|
|
22
24
|
const replane = new Replane();
|
|
23
25
|
await replane.connect({
|
|
24
|
-
baseUrl: 'https://
|
|
26
|
+
baseUrl: 'https://cloud.replane.dev', // or your self-hosted URL
|
|
25
27
|
sdkKey: 'your-sdk-key',
|
|
26
28
|
});
|
|
27
29
|
</script>
|
|
@@ -46,22 +48,31 @@ npm install @replanejs/svelte
|
|
|
46
48
|
{/if}
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
##
|
|
51
|
+
## Provider Props
|
|
52
|
+
|
|
53
|
+
| Prop | Type | Required | Description |
|
|
54
|
+
| ------------ | --------------------------- | -------- | ------------------------------------------------------- |
|
|
55
|
+
| `connection` | `ConnectOptions \| null` | Yes | Connection options (see below), or `null` to skip connection |
|
|
56
|
+
| `defaults` | `Record<string, unknown>` | No | Default values if server is unavailable |
|
|
57
|
+
| `context` | `Record<string, unknown>` | No | Default context for override evaluations |
|
|
58
|
+
| `snapshot` | `ReplaneSnapshot` | No | Snapshot for SSR hydration |
|
|
59
|
+
| `logger` | `ReplaneLogger` | No | Custom logger (default: console) |
|
|
60
|
+
| `loader` | `Snippet` | No | Snippet to show while loading |
|
|
61
|
+
| `async` | `boolean` | No | Connect asynchronously (renders immediately with defaults) |
|
|
50
62
|
|
|
51
|
-
|
|
63
|
+
## Connection Options
|
|
64
|
+
|
|
65
|
+
The `connection` prop accepts the following options:
|
|
52
66
|
|
|
53
67
|
| Option | Type | Required | Description |
|
|
54
68
|
| --------------------- | --------------------- | -------- | ---------------------------------------- |
|
|
55
69
|
| `baseUrl` | `string` | Yes | Replane server URL |
|
|
56
70
|
| `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
71
|
| `connectTimeoutMs` | `number` | No | SDK connection timeout (default: 5000) |
|
|
60
72
|
| `requestTimeoutMs` | `number` | No | Timeout for SSE requests (default: 2000) |
|
|
61
73
|
| `retryDelayMs` | `number` | No | Base delay between retries (default: 200)|
|
|
62
74
|
| `inactivityTimeoutMs` | `number` | No | SSE inactivity timeout (default: 30000) |
|
|
63
75
|
| `fetchFn` | `typeof fetch` | No | Custom fetch implementation |
|
|
64
|
-
| `logger` | `ReplaneLogger` | No | Custom logger (default: console) |
|
|
65
76
|
|
|
66
77
|
See [`@replanejs/sdk` documentation](https://github.com/replane-dev/replane-javascript/tree/main/packages/sdk#api) for more details.
|
|
67
78
|
|
|
@@ -130,7 +141,7 @@ Create a reactive store from a client directly (without context). Type-safe with
|
|
|
130
141
|
|
|
131
142
|
Context component that makes the Replane client available to your component tree.
|
|
132
143
|
|
|
133
|
-
Can be used in
|
|
144
|
+
Can be used in several ways:
|
|
134
145
|
|
|
135
146
|
**1. With a pre-created client:**
|
|
136
147
|
|
|
@@ -140,7 +151,7 @@ Can be used in three ways:
|
|
|
140
151
|
|
|
141
152
|
const replane = new Replane();
|
|
142
153
|
await replane.connect({
|
|
143
|
-
baseUrl: 'https://
|
|
154
|
+
baseUrl: 'https://cloud.replane.dev', // or your self-hosted URL
|
|
144
155
|
sdkKey: 'your-sdk-key',
|
|
145
156
|
});
|
|
146
157
|
</script>
|
|
@@ -150,20 +161,20 @@ Can be used in three ways:
|
|
|
150
161
|
</ReplaneContext>
|
|
151
162
|
```
|
|
152
163
|
|
|
153
|
-
**2. With
|
|
164
|
+
**2. With connection (client managed internally):**
|
|
154
165
|
|
|
155
166
|
```svelte
|
|
156
167
|
<script>
|
|
157
168
|
import { ReplaneContext } from '@replanejs/svelte';
|
|
158
169
|
|
|
159
|
-
const
|
|
170
|
+
const connection = {
|
|
160
171
|
baseUrl: 'https://your-replane-server.com',
|
|
161
172
|
sdkKey: 'your-sdk-key',
|
|
162
173
|
};
|
|
163
174
|
</script>
|
|
164
175
|
|
|
165
176
|
<svelte:boundary onerror={(e) => console.error(e)}>
|
|
166
|
-
<ReplaneContext {
|
|
177
|
+
<ReplaneContext {connection}>
|
|
167
178
|
<App />
|
|
168
179
|
|
|
169
180
|
{#snippet loader()}
|
|
@@ -177,7 +188,30 @@ Can be used in three ways:
|
|
|
177
188
|
</svelte:boundary>
|
|
178
189
|
```
|
|
179
190
|
|
|
180
|
-
**3. With
|
|
191
|
+
**3. With async mode:**
|
|
192
|
+
|
|
193
|
+
Connect in the background while rendering immediately with defaults:
|
|
194
|
+
|
|
195
|
+
```svelte
|
|
196
|
+
<script>
|
|
197
|
+
import { ReplaneContext } from '@replanejs/svelte';
|
|
198
|
+
|
|
199
|
+
const connection = {
|
|
200
|
+
baseUrl: 'https://your-replane-server.com',
|
|
201
|
+
sdkKey: 'your-sdk-key',
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const defaults = {
|
|
205
|
+
featureEnabled: false,
|
|
206
|
+
};
|
|
207
|
+
</script>
|
|
208
|
+
|
|
209
|
+
<ReplaneContext {connection} {defaults} async>
|
|
210
|
+
<App />
|
|
211
|
+
</ReplaneContext>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**4. With a snapshot (for SSR/hydration):**
|
|
181
215
|
|
|
182
216
|
```svelte
|
|
183
217
|
<script>
|
|
@@ -185,13 +219,13 @@ Can be used in three ways:
|
|
|
185
219
|
|
|
186
220
|
let { data, children } = $props();
|
|
187
221
|
|
|
188
|
-
const
|
|
222
|
+
const connection = {
|
|
189
223
|
baseUrl: import.meta.env.VITE_REPLANE_BASE_URL,
|
|
190
224
|
sdkKey: import.meta.env.VITE_REPLANE_SDK_KEY,
|
|
191
225
|
};
|
|
192
226
|
</script>
|
|
193
227
|
|
|
194
|
-
<ReplaneContext {
|
|
228
|
+
<ReplaneContext {connection} snapshot={data.replaneSnapshot}>
|
|
195
229
|
{@render children()}
|
|
196
230
|
</ReplaneContext>
|
|
197
231
|
```
|
|
@@ -241,8 +275,10 @@ import { getReplaneSnapshot } from "@replanejs/svelte";
|
|
|
241
275
|
|
|
242
276
|
export async function load() {
|
|
243
277
|
const snapshot = await getReplaneSnapshot({
|
|
244
|
-
|
|
245
|
-
|
|
278
|
+
connection: {
|
|
279
|
+
baseUrl: import.meta.env.REPLANE_BASE_URL,
|
|
280
|
+
sdkKey: import.meta.env.REPLANE_SDK_KEY,
|
|
281
|
+
},
|
|
246
282
|
});
|
|
247
283
|
|
|
248
284
|
return { replaneSnapshot: snapshot };
|
|
@@ -256,13 +292,13 @@ export async function load() {
|
|
|
256
292
|
|
|
257
293
|
let { data, children } = $props();
|
|
258
294
|
|
|
259
|
-
const
|
|
295
|
+
const connection = {
|
|
260
296
|
baseUrl: import.meta.env.VITE_REPLANE_BASE_URL,
|
|
261
297
|
sdkKey: import.meta.env.VITE_REPLANE_SDK_KEY,
|
|
262
298
|
};
|
|
263
299
|
</script>
|
|
264
300
|
|
|
265
|
-
<ReplaneContext {
|
|
301
|
+
<ReplaneContext {connection} snapshot={data.replaneSnapshot}>
|
|
266
302
|
{@render children()}
|
|
267
303
|
</ReplaneContext>
|
|
268
304
|
```
|
|
@@ -26,72 +26,109 @@
|
|
|
26
26
|
| { status: "ready"; client: Replane<T>; error: null }
|
|
27
27
|
| { status: "error"; client: null; error: Error };
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
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 -
|
|
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
|
-
|
|
44
|
-
const { options, snapshot } = props;
|
|
101
|
+
const { connection, logger } = props;
|
|
45
102
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
//
|
|
76
|
-
|
|
121
|
+
// Loading mode - create client and connect
|
|
122
|
+
const { context, defaults } = props;
|
|
77
123
|
|
|
78
124
|
const client = new ReplaneClass<T>({
|
|
79
|
-
logger
|
|
80
|
-
context
|
|
81
|
-
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
|
|
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
|
}
|
|
124
162
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReplaneContext.svelte.d.ts","sourceRoot":"","sources":["../src/ReplaneContext.svelte.ts"],"names":[],"mappings":"AAIE,OAAO,KAAK,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,EAC/B,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,GAC/B,CAAC;AAMJ,iBAAS,QAAQ,CAAC,CAAC,SAAS,MAAM;
|
|
1
|
+
{"version":3,"file":"ReplaneContext.svelte.d.ts","sourceRoot":"","sources":["../src/ReplaneContext.svelte.ts"],"names":[],"mappings":"AAIE,OAAO,KAAK,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,EAC/B,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,GAC/B,CAAC;AAMJ,iBAAS,QAAQ,CAAC,CAAC,SAAS,MAAM;WAwKL,mBAAmB,CAAC,CAAC,CAAC;;;;;EAA4E;AAC/H,cAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM;IACpC,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,MAAM,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClD,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,QAAQ;IACR,OAAO;CACV;AAED,UAAU,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,
|
|
7
|
-
export { hasClient
|
|
6
|
+
export type { ReplaneContextValue, ReplaneContextProps, ReplaneContextWithClientProps, ReplaneContextWithOptionsProps, } from "./types";
|
|
7
|
+
export { hasClient } from "./types";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
-
*
|
|
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
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
*
|
|
21
|
-
*
|
|
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
|
-
|
|
28
|
+
connection: ConnectOptions | null;
|
|
24
29
|
/**
|
|
25
30
|
* Default context for all config evaluations.
|
|
26
31
|
*/
|
|
27
|
-
context?:
|
|
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
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,eAAe,EACf,cAAc,IAAI,kBAAkB,EACpC,aAAa,EACb,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7E,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvF,0CAA0C;IAC1C,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,uBAAuB;IACvB,QAAQ,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.
|
|
2
|
-
export declare const DEFAULT_AGENT = "replane-js-svelte/0.9.
|
|
1
|
+
export declare const VERSION = "0.9.4";
|
|
2
|
+
export declare const DEFAULT_AGENT = "replane-js-svelte/0.9.4";
|
|
3
3
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replanejs/svelte",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
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.
|
|
42
|
+
"@replanejs/sdk": "^0.9.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@sveltejs/package": "^2.3.10",
|