Skip to content

Commit 5b667fb

Browse files
committed
chore: update naming
1 parent 67c822d commit 5b667fb

4 files changed

Lines changed: 36 additions & 32 deletions

File tree

packages/sdk/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,20 @@ Type parameter `T` defines the shape of your configs (a mapping of config names
9898

9999
#### Options
100100

101-
- `baseUrl` (string) – Replane origin (no trailing slash needed).
101+
- `baseUrl` (string) – Replane origin (no trailing slash needed). Required.
102102
- `sdkKey` (string) – SDK key for authorization. Required. **Note:** Each SDK key is tied to a specific project and can only access configs from that project. To access configs from multiple projects, create multiple SDK keys and initialize separate client instances.
103103
- `required` (object or array) – mark specific configs as required. If any required config is missing, the client will throw an error during initialization. Can be an object with boolean values or an array of config names. Optional.
104-
- `fallbacks` (object) – fallback values to use if the initial request to fetch configs fails. Allows the client to start even when the API is unavailable. Optional.
104+
- `defaults` (object) – default values to use if the initial request to fetch configs fails or times out. These values are used immediately while waiting for server connection. Allows the client to start even when the API is unavailable. Optional.
105105
- `context` (object) – default context for all config evaluations. Can be overridden per-request in `get()`. Optional.
106106
- `fetchFn` (function) – custom fetch (e.g. `undici.fetch` or mocked fetch in tests). Optional.
107-
- `timeoutMs` (number) – abort the request after N ms. Default: 2000.
108-
- `retries` (number) – number of retry attempts on failures (5xx or network errors). Default: 2.
109-
- `retryDelayMs` (number) – base delay between retries in ms (a small jitter is applied). Default: 200.
107+
- `requestTimeoutMs` (number) – timeout for SSE requests in ms. Default: 2000.
108+
- `initializationTimeoutMs` (number) – timeout for SDK initialization in ms. Default: 5000.
109+
- `retryDelayMs` (number) – base delay between retries in ms. Default: 200.
110+
- `inactivityTimeoutMs` (number) – timeout for SSE inactivity before reconnecting in ms. Default: 30000.
110111
- `logger` (object) – custom logger with `debug`, `info`, `warn`, `error` methods. Default: `console`.
112+
- `agent` (string) – agent identifier sent in User-Agent header.
113+
- `onConnectionError` (function) – callback invoked when a connection error occurs during SSE streaming.
114+
- `onConnected` (function) – callback invoked when the SSE connection is successfully established.
111115

112116
### `replane.get<K>(name, options?)`
113117

@@ -383,7 +387,7 @@ const replane = await createReplaneClient<Configs>({
383387
// If any required config is missing, initialization will throw
384388
```
385389

386-
### Fallback configs
390+
### Default configs
387391

388392
```ts
389393
interface Configs {
@@ -395,15 +399,15 @@ interface Configs {
395399
const replane = await createReplaneClient<Configs>({
396400
sdkKey: process.env.REPLANE_SDK_KEY!,
397401
baseUrl: "https://replane.my-host.com",
398-
fallbacks: {
402+
defaults: {
399403
"feature-flag": false, // Use false if fetch fails
400404
"max-connections": 10, // Use 10 if fetch fails
401405
"timeout-ms": 5000, // Use 5s if fetch fails
402406
},
403407
});
404408

405-
// If the initial fetch fails, fallback values are used
406-
// Once the configs client connects, it will receive realtime updates
409+
// If the initial fetch fails or times out, default values are used
410+
// Once the client connects, it will receive realtime updates
407411
const maxConnections = replane.get("max-connections"); // 10 (or real value)
408412
```
409413

packages/sdk/src/client-types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,17 @@ export interface ReplaneClientOptions<T extends object> {
163163
| Array<keyof T>;
164164

165165
/**
166-
* Fallback values to use if the initial request to fetch configs fails.
167-
* When provided, all configs must be specified.
166+
* Default values to use if the initial request to fetch configs fails or times out.
167+
* These values are used immediately while waiting for server connection.
168168
* @example
169169
* {
170-
* fallbacks: {
170+
* defaults: {
171171
* config1: "value1",
172172
* config2: 42,
173173
* },
174174
* }
175175
*/
176-
fallbacks?: {
176+
defaults?: {
177177
[K in keyof T]: T[K];
178178
};
179179

@@ -283,7 +283,7 @@ export interface ReplaneFinalOptions {
283283
retryDelayMs: number;
284284
context: ReplaneContext;
285285
requiredConfigs: string[];
286-
fallbacks: ConfigDto[];
286+
defaults: ConfigDto[];
287287
agent: string;
288288
onConnectionError?: (error: unknown) => void;
289289
onConnected?: () => void;

packages/sdk/src/client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ async function createReplaneClientInternal<T extends object = Record<string, unk
323323
storage: ReplaneStorage
324324
): Promise<ReplaneClient<T>> {
325325
const { client, configs, startStreaming, clientReady } = createClientCore<T>({
326-
initialConfigs: sdkOptions.fallbacks,
326+
initialConfigs: sdkOptions.defaults,
327327
context: sdkOptions.context,
328328
logger: sdkOptions.logger,
329329
storage,
@@ -337,8 +337,8 @@ async function createReplaneClientInternal<T extends object = Record<string, unk
337337
});
338338

339339
const initializationTimeoutId = setTimeout(() => {
340-
if (sdkOptions.fallbacks.length === 0) {
341-
// no fallbacks, we have nothing to work with
340+
if (sdkOptions.defaults.length === 0) {
341+
// no defaults, we have nothing to work with
342342
client.close();
343343

344344
clientReady.reject(
@@ -404,7 +404,7 @@ function toFinalOptions<T extends object>(options: ReplaneClientOptions<T>): Rep
404404
: Object.entries(options.required ?? {})
405405
.filter(([_, value]) => value !== undefined)
406406
.map(([name]) => name),
407-
fallbacks: Object.entries(options.fallbacks ?? {})
407+
defaults: Object.entries(options.defaults ?? {})
408408
.filter(([_, value]) => value !== undefined)
409409
.map(([name, value]) => ({
410410
name,

packages/sdk/tests/index.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ describe("createReplaneClient", () => {
13791379
});
13801380
});
13811381

1382-
describe("initialization and fallbacks", () => {
1382+
describe("initialization and defaults", () => {
13831383
it("should not throw error when SDK key is missing", async () => {
13841384
await expect(
13851385
createReplaneClient({
@@ -1392,9 +1392,9 @@ describe("createReplaneClient", () => {
13921392
).rejects.toThrow("Replane client initialization timed out");
13931393
});
13941394

1395-
it("should use fallbacks and timeout when server does not respond", async () => {
1395+
it("should use defaults and timeout when server does not respond", async () => {
13961396
clientPromise = createClient<Record<string, unknown>>({
1397-
fallbacks: { config1: "fallback-value" },
1397+
defaults: { config1: "fallback-value" },
13981398
initializationTimeoutMs: 50,
13991399
});
14001400

@@ -1403,27 +1403,27 @@ describe("createReplaneClient", () => {
14031403
expect(client.get("config1")).toBe("fallback-value");
14041404
});
14051405

1406-
it("should throw timeout error when no fallbacks and server does not respond", async () => {
1406+
it("should throw timeout error when no defaults and server does not respond", async () => {
14071407
clientPromise = createClient({
14081408
initializationTimeoutMs: 50,
14091409
});
14101410

14111411
await expect(clientPromise).rejects.toThrow("Replane client initialization timed out");
14121412
});
14131413

1414-
it("should throw error when required config is missing from fallbacks", async () => {
1414+
it("should throw error when required config is missing from defaults", async () => {
14151415
clientPromise = createClient<Record<string, unknown>>({
1416-
fallbacks: { config1: "fallback-value" },
1416+
defaults: { config1: "fallback-value" },
14171417
required: ["config1", "config2"],
14181418
initializationTimeoutMs: 50,
14191419
});
14201420

14211421
await expect(clientPromise).rejects.toThrow("Required configs are missing: config2");
14221422
});
14231423

1424-
it("should succeed when all required configs are in fallbacks", async () => {
1424+
it("should succeed when all required configs are in defaults", async () => {
14251425
clientPromise = createClient<Record<string, unknown>>({
1426-
fallbacks: { config1: "fallback1", config2: "fallback2" },
1426+
defaults: { config1: "fallback1", config2: "fallback2" },
14271427
required: ["config1", "config2"],
14281428
initializationTimeoutMs: 50,
14291429
});
@@ -1433,9 +1433,9 @@ describe("createReplaneClient", () => {
14331433
expect(client.get("config2")).toBe("fallback2");
14341434
});
14351435

1436-
it("should override fallbacks with server values", async () => {
1436+
it("should override defaults with server values", async () => {
14371437
clientPromise = createClient<Record<string, unknown>>({
1438-
fallbacks: { config1: "fallback-value" },
1438+
defaults: { config1: "fallback-value" },
14391439
});
14401440
const connection = await mockServer.acceptConnection();
14411441
await connection.push({
@@ -1450,7 +1450,7 @@ describe("createReplaneClient", () => {
14501450

14511451
it("should accept required as object format", async () => {
14521452
clientPromise = createClient<Record<string, unknown>>({
1453-
fallbacks: { config1: "fallback1", config2: "fallback2" },
1453+
defaults: { config1: "fallback1", config2: "fallback2" },
14541454
required: { config1: true, config2: true },
14551455
initializationTimeoutMs: 50,
14561456
});
@@ -1461,7 +1461,7 @@ describe("createReplaneClient", () => {
14611461

14621462
it("should handle empty required array", async () => {
14631463
clientPromise = createClient<Record<string, unknown>>({
1464-
fallbacks: { config1: "fallback1" },
1464+
defaults: { config1: "fallback1" },
14651465
required: [],
14661466
initializationTimeoutMs: 50,
14671467
});
@@ -1470,7 +1470,7 @@ describe("createReplaneClient", () => {
14701470
expect(client.get("config1")).toBe("fallback1");
14711471
});
14721472

1473-
it("should call onConnectionError callback when initial connection fails with fallbacks", async () => {
1473+
it("should call onConnectionError callback when initial connection fails with defaults", async () => {
14741474
const onConnectionError = vi.fn();
14751475
const failingFetch = vi.fn().mockRejectedValue(new Error("Connection refused"));
14761476

@@ -1479,7 +1479,7 @@ describe("createReplaneClient", () => {
14791479
baseUrl: "https://replane.my-host.com",
14801480
fetchFn: failingFetch,
14811481
logger: silentLogger,
1482-
fallbacks: { config1: "fallback-value" },
1482+
defaults: { config1: "fallback-value" },
14831483
initializationTimeoutMs: 50,
14841484
retryDelayMs: 10,
14851485
onConnectionError,

0 commit comments

Comments
 (0)