@@ -46,27 +46,27 @@ interface PasswordRequirements {
4646 requireSymbol: boolean ;
4747}
4848
49- const configs = await createReplaneClient <Configs >({
49+ const replane = await createReplaneClient <Configs >({
5050 // Each SDK key belongs to one project only
5151 sdkKey: process .env .REPLANE_SDK_KEY ! ,
5252 baseUrl: " https://replane.my-hosting.com" ,
5353});
5454
5555// Get a config value (knows about latest updates via SSE)
56- const featureFlag = configs .get (" new-onboarding" ); // Typed as boolean
56+ const featureFlag = replane .get (" new-onboarding" ); // Typed as boolean
5757
5858if (featureFlag ) {
5959 console .log (" New onboarding enabled!" );
6060}
6161
6262// Typed config - no need to specify type again
63- const passwordReqs = configs .get (" password-requirements" );
63+ const passwordReqs = replane .get (" password-requirements" );
6464
6565// Use the value directly
6666const { minLength } = passwordReqs ; // TypeScript knows this is PasswordRequirements
6767
6868// With context for override evaluation
69- const enabled = configs .get (" billing-enabled" , {
69+ const enabled = replane .get (" billing-enabled" , {
7070 context: {
7171 userId: " user-123" ,
7272 plan: " premium" ,
@@ -79,7 +79,7 @@ if (enabled) {
7979}
8080
8181// When done, clean up resources
82- configs .close ();
82+ replane .close ();
8383```
8484
8585## API
@@ -105,7 +105,7 @@ Type parameter `T` defines the shape of your configs (a mapping of config names
105105- ` retryDelayMs ` (number) – base delay between retries in ms (a small jitter is applied). Default: 200.
106106- ` logger ` (object) – custom logger with ` debug ` , ` info ` , ` warn ` , ` error ` methods. Default: ` console ` .
107107
108- ### ` configs .get<K>(name, options?)`
108+ ### ` replane .get<K>(name, options?)`
109109
110110Gets the current config value. The configs client maintains an up-to-date cache that receives realtime updates via Server-Sent Events (SSE) in the background.
111111
@@ -119,7 +119,7 @@ Returns the config value of type `T[K]` (synchronous). The return type is automa
119119
120120Notes:
121121
122- - The configs client receives realtime updates via SSE in the background.
122+ - The Replane client receives realtime updates via SSE in the background.
123123- If the config is not found, throws a ` ReplaneError ` with code ` not_found ` .
124124- Context-based overrides are evaluated automatically based on context.
125125
@@ -131,24 +131,24 @@ interface Configs {
131131 " max-connections" : number ;
132132}
133133
134- const configs = await createReplaneClient <Configs >({
134+ const replane = await createReplaneClient <Configs >({
135135 sdkKey: " your-sdk-key" ,
136136 baseUrl: " https://replane.my-host.com" ,
137137});
138138
139139// Get value without context - TypeScript knows this is boolean
140- const enabled = configs .get (" billing-enabled" );
140+ const enabled = replane .get (" billing-enabled" );
141141
142142// Get value with context for override evaluation
143- const userEnabled = configs .get (" billing-enabled" , {
143+ const userEnabled = replane .get (" billing-enabled" , {
144144 context: { userId: " user-123" , plan: " premium" },
145145});
146146
147147// Clean up when done
148- configs .close ();
148+ replane .close ();
149149```
150150
151- ### ` configs .subscribe(callback)` or ` configs .subscribe(configName, callback)`
151+ ### ` replane .subscribe(callback)` or ` replane .subscribe(configName, callback)`
152152
153153Subscribe to config changes and receive real-time updates when configs are modified.
154154
@@ -157,14 +157,14 @@ Subscribe to config changes and receive real-time updates when configs are modif
1571571 . ** Subscribe to all config changes:**
158158
159159 ``` ts
160- const unsubscribe = configs .subscribe ((config ) => {
160+ const unsubscribe = replane .subscribe ((config ) => {
161161 console .log (` Config ${config .name } changed to: ` , config .value );
162162 });
163163 ```
164164
1651652 . ** Subscribe to a specific config:**
166166 ``` ts
167- const unsubscribe = configs .subscribe (" billing-enabled" , (config ) => {
167+ const unsubscribe = replane .subscribe (" billing-enabled" , (config ) => {
168168 console .log (` billing-enabled changed to: ` , config .value );
169169 });
170170 ```
@@ -184,18 +184,18 @@ interface Configs {
184184 " max-connections" : number ;
185185}
186186
187- const configs = await createReplaneClient <Configs >({
187+ const replane = await createReplaneClient <Configs >({
188188 sdkKey: " your-sdk-key" ,
189189 baseUrl: " https://replane.my-host.com" ,
190190});
191191
192192// Subscribe to all config changes
193- const unsubscribeAll = configs .subscribe ((config ) => {
193+ const unsubscribeAll = replane .subscribe ((config ) => {
194194 console .log (` Config ${config .name } updated: ` , config .value );
195195});
196196
197197// Subscribe to a specific config
198- const unsubscribeFeature = configs .subscribe (" feature-flag" , (config ) => {
198+ const unsubscribeFeature = replane .subscribe (" feature-flag" , (config ) => {
199199 console .log (" Feature flag changed:" , config .value );
200200 // config.value is typed as boolean
201201});
@@ -205,7 +205,7 @@ unsubscribeAll();
205205unsubscribeFeature ();
206206
207207// Clean up when done
208- configs .close ();
208+ replane .close ();
209209```
210210
211211### ` createInMemoryReplaneClient(initialData) `
@@ -234,34 +234,34 @@ interface Configs {
234234 " max-items" : { value: number ; ttl: number };
235235}
236236
237- const configs = createInMemoryReplaneClient <Configs >({
237+ const replane = createInMemoryReplaneClient <Configs >({
238238 " feature-a" : true ,
239239 " max-items" : { value: 10 , ttl: 3600 },
240240});
241241
242- const featureA = configs .get (" feature-a" ); // TypeScript knows this is boolean
242+ const featureA = replane .get (" feature-a" ); // TypeScript knows this is boolean
243243console .log (featureA ); // true
244244
245- const maxItems = configs .get (" max-items" ); // TypeScript knows the type
245+ const maxItems = replane .get (" max-items" ); // TypeScript knows the type
246246console .log (maxItems ); // { value: 10, ttl: 3600 }
247247
248- configs .close ();
248+ replane .close ();
249249```
250250
251- ### ` configs .close()`
251+ ### ` replane .close()`
252252
253- Gracefully shuts down the configs client and cleans up resources. Subsequent method calls will throw. Use this in environments where you manage resource lifecycles explicitly (e.g. shutting down a server or worker).
253+ Gracefully shuts down the Replane client and cleans up resources. Subsequent method calls will throw. Use this in environments where you manage resource lifecycles explicitly (e.g. shutting down a server or worker).
254254
255255``` ts
256256// During shutdown
257- configs .close ();
257+ replane .close ();
258258```
259259
260260### Errors
261261
262262` createReplaneClient ` throws if the initial request to fetch configs fails with non‑2xx HTTP responses and network errors. A ` ReplaneError ` is thrown for HTTP failures; other errors may be thrown for network/parse issues.
263263
264- The configs client receives realtime updates via SSE in the background. SSE connection errors are logged and automatically retried, but don't affect ` get ` calls (which return the last known value).
264+ The Replane client receives realtime updates via SSE in the background. SSE connection errors are logged and automatically retried, but don't affect ` get ` calls (which return the last known value).
265265
266266## Environment notes
267267
@@ -282,12 +282,12 @@ interface Configs {
282282 layout: LayoutConfig ;
283283}
284284
285- const configs = await createReplaneClient <Configs >({
285+ const replane = await createReplaneClient <Configs >({
286286 sdkKey: process .env .REPLANE_SDK_KEY ! ,
287287 baseUrl: " https://replane.my-host.com" ,
288288});
289289
290- const layout = configs .get (" layout" ); // TypeScript knows this is LayoutConfig
290+ const layout = replane .get (" layout" ); // TypeScript knows this is LayoutConfig
291291console .log (layout ); // { variant: "a", ttl: 3600 }
292292```
293293
@@ -298,20 +298,20 @@ interface Configs {
298298 " advanced-features" : boolean ;
299299}
300300
301- const configs = await createReplaneClient <Configs >({
301+ const replane = await createReplaneClient <Configs >({
302302 sdkKey: process .env .REPLANE_SDK_KEY ! ,
303303 baseUrl: " https://replane.my-host.com" ,
304304});
305305
306306// Config has base value `false` but override: if `plan === "premium"` then `true`
307307
308308// Free user
309- const freeUserEnabled = configs .get (" advanced-features" , {
309+ const freeUserEnabled = replane .get (" advanced-features" , {
310310 context: { plan: " free" },
311311}); // false
312312
313313// Premium user
314- const premiumUserEnabled = configs .get (" advanced-features" , {
314+ const premiumUserEnabled = replane .get (" advanced-features" , {
315315 context: { plan: " premium" },
316316}); // true
317317```
@@ -323,7 +323,7 @@ interface Configs {
323323 " feature-flag" : boolean ;
324324}
325325
326- const configs = await createReplaneClient <Configs >({
326+ const replane = await createReplaneClient <Configs >({
327327 sdkKey: process .env .REPLANE_SDK_KEY ! ,
328328 baseUrl: " https://replane.my-host.com" ,
329329 context: {
@@ -333,16 +333,16 @@ const configs = await createReplaneClient<Configs>({
333333});
334334
335335// This context is used for all configs unless overridden
336- const value1 = configs .get (" feature-flag" ); // Uses client-level context
337- const value2 = configs .get (" feature-flag" , {
336+ const value1 = replane .get (" feature-flag" ); // Uses client-level context
337+ const value2 = replane .get (" feature-flag" , {
338338 context: { userId: " user-321" },
339339}); // Merges with client context
340340```
341341
342342### Custom fetch (tests)
343343
344344``` ts
345- const configs = await createReplaneClient ({
345+ const replane = await createReplaneClient ({
346346 sdkKey: " TKN" ,
347347 baseUrl: " https://api" ,
348348 fetchFn: mockFetch ,
@@ -358,7 +358,7 @@ interface Configs {
358358 " optional-feature" : boolean ;
359359}
360360
361- const configs = await createReplaneClient <Configs >({
361+ const replane = await createReplaneClient <Configs >({
362362 sdkKey: process .env .REPLANE_SDK_KEY ! ,
363363 baseUrl: " https://replane.my-host.com" ,
364364 required: {
@@ -383,7 +383,7 @@ interface Configs {
383383 " timeout-ms" : number ;
384384}
385385
386- const configs = await createReplaneClient <Configs >({
386+ const replane = await createReplaneClient <Configs >({
387387 sdkKey: process .env .REPLANE_SDK_KEY ! ,
388388 baseUrl: " https://replane.my-host.com" ,
389389 fallbacks: {
@@ -395,7 +395,7 @@ const configs = await createReplaneClient<Configs>({
395395
396396// If the initial fetch fails, fallback values are used
397397// Once the configs client connects, it will receive realtime updates
398- const maxConnections = configs .get (" max-connections" ); // 10 (or real value)
398+ const maxConnections = replane .get (" max-connections" ); // 10 (or real value)
399399```
400400
401401### Multiple projects
@@ -411,7 +411,7 @@ interface ProjectBConfigs {
411411 " api-rate-limit" : number ;
412412}
413413
414- // Each project needs its own SDK key and configs client instance
414+ // Each project needs its own SDK key and Replane client instance
415415const projectAConfigs = await createReplaneClient <ProjectAConfigs >({
416416 sdkKey: process .env .PROJECT_A_SDK_KEY ! ,
417417 baseUrl: " https://replane.my-host.com" ,
@@ -422,7 +422,7 @@ const projectBConfigs = await createReplaneClient<ProjectBConfigs>({
422422 baseUrl: " https://replane.my-host.com" ,
423423});
424424
425- // Each configs client only accesses configs from its respective project
425+ // Each Replane client only accesses configs from its respective project
426426const featureA = projectAConfigs .get (" feature-flag" ); // boolean
427427const featureB = projectBConfigs .get (" feature-flag" ); // boolean
428428```
@@ -435,13 +435,13 @@ interface Configs {
435435 " max-users" : number ;
436436}
437437
438- const configs = await createReplaneClient <Configs >({
438+ const replane = await createReplaneClient <Configs >({
439439 sdkKey: process .env .REPLANE_SDK_KEY ! ,
440440 baseUrl: " https://replane.my-host.com" ,
441441});
442442
443443// Subscribe to all config changes
444- const unsubscribeAll = configs .subscribe ((config ) => {
444+ const unsubscribeAll = replane .subscribe ((config ) => {
445445 console .log (` Config ${config .name } changed: ` , config .value );
446446
447447 // React to specific config changes
@@ -451,13 +451,13 @@ const unsubscribeAll = configs.subscribe((config) => {
451451});
452452
453453// Subscribe to a specific config only
454- const unsubscribeFeature = configs .subscribe (" feature-flag" , (config ) => {
454+ const unsubscribeFeature = replane .subscribe (" feature-flag" , (config ) => {
455455 console .log (" Feature flag changed:" , config .value );
456456 // config.value is automatically typed as boolean
457457});
458458
459459// Subscribe to multiple specific configs
460- const unsubscribeMaxUsers = configs .subscribe (" max-users" , (config ) => {
460+ const unsubscribeMaxUsers = replane .subscribe (" max-users" , (config ) => {
461461 console .log (" Max users changed:" , config .value );
462462 // config.value is automatically typed as number
463463});
@@ -466,7 +466,7 @@ const unsubscribeMaxUsers = configs.subscribe("max-users", (config) => {
466466unsubscribeAll ();
467467unsubscribeFeature ();
468468unsubscribeMaxUsers ();
469- configs .close ();
469+ replane .close ();
470470```
471471
472472## Roadmap
0 commit comments