@replanejs/sdk 0.7.3 → 0.7.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/dist/index.d.ts +42 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
|
|
3
|
+
interface PropertyCondition {
|
|
4
|
+
operator: "equals" | "in" | "not_in" | "less_than" | "less_than_or_equal" | "greater_than" | "greater_than_or_equal";
|
|
5
|
+
property: string;
|
|
6
|
+
value: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface SegmentationCondition {
|
|
9
|
+
operator: "segmentation";
|
|
10
|
+
property: string;
|
|
11
|
+
fromPercentage: number;
|
|
12
|
+
toPercentage: number;
|
|
13
|
+
seed: string;
|
|
14
|
+
}
|
|
15
|
+
interface AndCondition {
|
|
16
|
+
operator: "and";
|
|
17
|
+
conditions: RenderedCondition[];
|
|
18
|
+
}
|
|
19
|
+
interface OrCondition {
|
|
20
|
+
operator: "or";
|
|
21
|
+
conditions: RenderedCondition[];
|
|
22
|
+
}
|
|
23
|
+
interface NotCondition {
|
|
24
|
+
operator: "not";
|
|
25
|
+
condition: RenderedCondition;
|
|
26
|
+
}
|
|
27
|
+
type RenderedCondition = PropertyCondition | SegmentationCondition | AndCondition | OrCondition | NotCondition;
|
|
28
|
+
interface RenderedOverride {
|
|
29
|
+
name: string;
|
|
30
|
+
conditions: RenderedCondition[];
|
|
31
|
+
value: unknown;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
1
34
|
//#region src/client-types.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Base constraint for config objects.
|
|
4
|
-
*/
|
|
5
|
-
type Configs = object;
|
|
6
35
|
/**
|
|
7
36
|
* Context object for override evaluation.
|
|
8
37
|
* Keys are property names, values can be strings, numbers, booleans, null, or undefined.
|
|
@@ -29,7 +58,7 @@ interface GetConfigOptions {
|
|
|
29
58
|
/**
|
|
30
59
|
* Helper type for mapping configs to their names and values
|
|
31
60
|
*/
|
|
32
|
-
type MapConfig<T extends
|
|
61
|
+
type MapConfig<T extends object> = { [K in keyof T]: {
|
|
33
62
|
name: K;
|
|
34
63
|
value: T[K];
|
|
35
64
|
} }[keyof T];
|
|
@@ -37,16 +66,12 @@ type MapConfig<T extends Configs> = { [K in keyof T]: {
|
|
|
37
66
|
* Serializable snapshot of the client state.
|
|
38
67
|
* Can be used to restore a client on the client-side from server-fetched configs.
|
|
39
68
|
*/
|
|
40
|
-
interface ReplaneSnapshot<_T extends
|
|
69
|
+
interface ReplaneSnapshot<_T extends object = object> {
|
|
41
70
|
/** Serialized config data */
|
|
42
71
|
configs: Array<{
|
|
43
72
|
name: string;
|
|
44
73
|
value: unknown;
|
|
45
|
-
overrides:
|
|
46
|
-
name: string;
|
|
47
|
-
conditions: unknown[];
|
|
48
|
-
value: unknown;
|
|
49
|
-
}>;
|
|
74
|
+
overrides: RenderedOverride[];
|
|
50
75
|
}>;
|
|
51
76
|
/** Default context used for override evaluation */
|
|
52
77
|
context?: ReplaneContext;
|
|
@@ -54,7 +79,7 @@ interface ReplaneSnapshot<_T extends Configs = Configs> {
|
|
|
54
79
|
/**
|
|
55
80
|
* The Replane client interface
|
|
56
81
|
*/
|
|
57
|
-
interface ReplaneClient<T extends
|
|
82
|
+
interface ReplaneClient<T extends object> {
|
|
58
83
|
/** Get a config by its name. */
|
|
59
84
|
get<K extends keyof T>(configName: K, options?: GetConfigOptions): T[K];
|
|
60
85
|
/** Subscribe to config changes.
|
|
@@ -79,7 +104,7 @@ interface ReplaneClient<T extends Configs> {
|
|
|
79
104
|
/**
|
|
80
105
|
* Options for creating a Replane client
|
|
81
106
|
*/
|
|
82
|
-
interface ReplaneClientOptions<T extends
|
|
107
|
+
interface ReplaneClientOptions<T extends object> {
|
|
83
108
|
/**
|
|
84
109
|
* Base URL of the Replane instance (no trailing slash).
|
|
85
110
|
* @example
|
|
@@ -163,7 +188,7 @@ interface ReplaneClientOptions<T extends Configs> {
|
|
|
163
188
|
/**
|
|
164
189
|
* Options for restoring a Replane client from a snapshot
|
|
165
190
|
*/
|
|
166
|
-
interface RestoreReplaneClientOptions<T extends
|
|
191
|
+
interface RestoreReplaneClientOptions<T extends object> {
|
|
167
192
|
/**
|
|
168
193
|
* Snapshot from a server-side client's getSnapshot() call.
|
|
169
194
|
*/
|
|
@@ -228,7 +253,7 @@ interface RestoreReplaneClientOptions<T extends Configs> {
|
|
|
228
253
|
* const value = client.get('my-config');
|
|
229
254
|
* ```
|
|
230
255
|
*/
|
|
231
|
-
declare function createReplaneClient<T extends
|
|
256
|
+
declare function createReplaneClient<T extends object = Record<string, unknown>>(sdkOptions: ReplaneClientOptions<T>): Promise<ReplaneClient<T>>;
|
|
232
257
|
/**
|
|
233
258
|
* Create a Replane client that uses in-memory storage.
|
|
234
259
|
* Useful for testing or when you have static config values.
|
|
@@ -239,7 +264,7 @@ declare function createReplaneClient<T extends Configs = Record<string, unknown>
|
|
|
239
264
|
* const value = client.get('my-config'); // 123
|
|
240
265
|
* ```
|
|
241
266
|
*/
|
|
242
|
-
declare function createInMemoryReplaneClient<T extends
|
|
267
|
+
declare function createInMemoryReplaneClient<T extends object = Record<string, unknown>>(initialData: T): ReplaneClient<T>;
|
|
243
268
|
/**
|
|
244
269
|
* Restore a Replane client from a snapshot.
|
|
245
270
|
* This is useful for SSR/hydration scenarios where the server has already fetched configs.
|
|
@@ -259,7 +284,7 @@ declare function createInMemoryReplaneClient<T extends Configs = Record<string,
|
|
|
259
284
|
* const value = client.get('my-config');
|
|
260
285
|
* ```
|
|
261
286
|
*/
|
|
262
|
-
declare function restoreReplaneClient<T extends
|
|
287
|
+
declare function restoreReplaneClient<T extends object = Record<string, unknown>>(options: RestoreReplaneClientOptions<T>): ReplaneClient<T>;
|
|
263
288
|
//# sourceMappingURL=client.d.ts.map
|
|
264
289
|
//#endregion
|
|
265
290
|
//#region src/error.d.ts
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/client-types.ts","../src/client.ts","../src/error.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/client-types.ts","../src/client.ts","../src/error.ts"],"sourcesContent":[],"mappings":";;UAqBU,iBAAA;;ECfE,QAAA,EAAA,MAAA;EAKK,KAAA,EAAA,OAAA;AAUjB;AAUA,UDGU,qBAAA,CCHW;EAAA,QAAA,EAAA,cAAA;EAAA,QACP,EAAA,MAAA;EAAC,cACL,EAAA,MAAA;EAAC,YACA,EAAA,MAAA;EAAC,IAAC,EAAA,MAAA;;AAEJ,UDMC,YAAA,CCND;EAMQ,QAAA,EAAA,KAAA;EAAe,UAAA,EDElB,iBCFkB,EAAA;;UDKtB,WAAA,CCHC;EAAK,QAMJ,EAAA,IAAA;EAAc,UAAA,EDDZ,iBCCY,EAAA;AAM1B;UDJU,YAAA,CCIoB;EAAA,QAER,EAAA,KAAA;EAAC,SAAc,EDJxB,iBCIwB;;AAAgC,KDDzD,iBAAA,GACR,iBCAiE,GDCjE,qBCDiE,GDEjE,YCFiE,GDGjE,WCHiE,GDIjE,YCJiE;AAAE,UDMtD,gBAAA,CCNsD;EAAC,IAK/B,EAAA,MAAA;EAAC,UAAX,EDGjB,iBCHiB,EAAA;EAAS,KAMZ,EAAA,OAAA;;;;ADlDtB;AAEqB;AAaI;AAUA;AAQrB,KC9CE,cAAA,GAAiB,MDgDhB,CAAA,MAAA,EAAA,MAAiB,GAAA,MAAA,GAAA,OAAA,GAAA,IAAA,GAAA,SAAA,CAAA;AAG9B;;;AAEI,UChDa,aAAA,CDgDb;EAAqB,KACrB,CAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;EAAY,IACZ,CAAA,GAAA,IAAA,EAAA,OAAA,EAAA,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MiB,CCsMW,CDtMX,CAAA,CAAA,ECuMzB,aDvMyB,CCuMX,CDvMW,CAAA;;;;;ADlDtB;AAEqB;AAqBjB,aGvCE,gBAAA;EH4CF,QAAA,GAAA,WAAW;EAKX,OAAA,GAAA,SAAY;EAKV,YAAA,GAAA,eAAiB;EAAA,SAAA,GAAA,YAAA;EAAA,SACzB,GAAA,WAAA;EAAiB,WACjB,GAAA,cAAA;EAAqB,WACrB,GAAA,cAAA;EAAY,MACZ,GAAA,QAAA;EAAW,cACX,GAAA,iBAAA;EAAY,OAAA,GAAA,SAAA;AAEhB;;;;AC1DY,cEaC,YAAA,SAAqB,KAAK,CFbJ;EAKlB,IAAA,EAAA,MAAA;EAUA,WAAA,CAAA,MAAA,EAAgB;IAUrB,OAAA,EAAS,MAAA;IAAA,IAAA,EAAA,MAAA;IACP,KAAA,CAAA,EAAA,OAAA;EAAC,CAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["params: { message: string; code: string; cause?: unknown }","ms: number","averageDelay: number","signals: Array<AbortSignal | undefined | null>","input: string | URL | Request","init: RequestInit","timeoutMs: number","fetchFn: typeof fetch","response: Response","message: string","body: unknown","params: FetchSseOptions","dataLines: string[]","comment: string | null","options: StartReplicationStreamOptions","error: unknown","inactivityTimer: ReturnType<typeof setTimeout> | null","options: ReplaneFinalOptions","path: string","input: string","baseValue: T","overrides: RenderedOverride[]","context: ReplaneContext","logger: ReplaneLogger","overrideResult: EvaluationResult","condition: RenderedCondition","contextValue","value: never","message: string","expectedValue: unknown","contextValue: unknown","options: ClientCoreOptions","configs: Map<string, ConfigDto>","updatedConfigs: ConfigDto[]","configName: K","getConfigOptions: GetConfigOptions","callbackOrConfigName: keyof T | ((config: MapConfig<T>) => void)","callbackOrUndefined?: (config: MapConfig<T>) => void","configName: keyof T | undefined","callback: (config: MapConfig<T>) => void","client: ReplaneClient<T>","sdkOptions: ReplaneClientOptions<T>","initialData: T","options: RestoreReplaneClientOptions<T>","initialConfigs: ConfigDto[]","storage: ReplaneRemoteStorage | null","streamOptions: ReplaneFinalOptions | null","sdkOptions: ReplaneFinalOptions","storage: ReplaneStorage","missingRequiredConfigs: string[]","defaults: ReplaneClientOptions<T>"],"sources":["../src/error.ts","../src/utils.ts","../src/sse.ts","../src/storage.ts","../src/hash.ts","../src/evaluation.ts","../src/client.ts"],"sourcesContent":["/**\n * Error codes for ReplaneError\n */\nexport enum ReplaneErrorCode {\n NotFound = \"not_found\",\n Timeout = \"timeout\",\n NetworkError = \"network_error\",\n AuthError = \"auth_error\",\n Forbidden = \"forbidden\",\n ServerError = \"server_error\",\n ClientError = \"client_error\",\n Closed = \"closed\",\n NotInitialized = \"not_initialized\",\n Unknown = \"unknown\",\n}\n\n/**\n * Custom error class for Replane SDK errors\n */\nexport class ReplaneError extends Error {\n code: string;\n\n constructor(params: { message: string; code: string; cause?: unknown }) {\n super(params.message, { cause: params.cause });\n this.name = \"ReplaneError\";\n this.code = params.code;\n }\n}\n","/**\n * Returns a promise that resolves after the specified delay\n *\n * @param ms - Delay in milliseconds\n */\nexport async function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Returns a promise that resolves after a delay with jitter.\n * The actual delay is the average delay ± 10% (jitter = averageDelay/5).\n *\n * @param averageDelay - The average delay in milliseconds\n */\nexport async function retryDelay(averageDelay: number): Promise<void> {\n const jitter = averageDelay / 5;\n const delayMs = averageDelay + Math.random() * jitter - jitter / 2;\n\n await delay(delayMs);\n}\n\n/**\n * Combines multiple abort signals into one.\n * When any of the input signals is aborted, the combined signal will also be aborted.\n *\n * @param signals - Array of AbortSignal instances (can contain undefined/null)\n * @returns An object containing the combined signal and a cleanup function\n */\nexport function combineAbortSignals(signals: Array<AbortSignal | undefined | null>): {\n signal: AbortSignal;\n cleanUpSignals: () => void;\n} {\n const controller = new AbortController();\n const onAbort = () => {\n controller.abort();\n cleanUpSignals();\n };\n\n const cleanUpSignals = () => {\n for (const s of signals) {\n s?.removeEventListener(\"abort\", onAbort);\n }\n };\n\n for (const s of signals) {\n s?.addEventListener(\"abort\", onAbort, { once: true });\n }\n\n if (signals.some((s) => s?.aborted)) {\n onAbort();\n }\n\n return { signal: controller.signal, cleanUpSignals };\n}\n\n/**\n * A deferred promise that can be resolved or rejected from outside.\n * Useful for coordinating async operations.\n */\nexport class Deferred<T> {\n public readonly promise: Promise<T>;\n public resolve!: (value: T) => void;\n public reject!: (error: unknown) => void;\n\n constructor() {\n this.promise = new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n}\n","import { ReplaneError, ReplaneErrorCode } from \"./error\";\nimport { combineAbortSignals } from \"./utils\";\n\nconst SSE_DATA_PREFIX = \"data:\";\n\n/**\n * Parsed SSE event\n */\nexport type SseEvent = { type: \"comment\"; comment: string } | { type: \"data\"; data: string };\n\n/**\n * Options for fetchSse\n */\nexport interface FetchSseOptions {\n fetchFn: typeof fetch;\n url: string;\n timeoutMs: number;\n body?: string;\n headers?: Record<string, string>;\n method?: string;\n signal?: AbortSignal;\n onConnect?: () => void;\n}\n\n/**\n * Fetch with timeout support\n */\nexport async function fetchWithTimeout(\n input: string | URL | Request,\n init: RequestInit,\n timeoutMs: number,\n fetchFn: typeof fetch\n): Promise<Response> {\n if (!fetchFn) {\n throw new Error(\"Global fetch is not available. Provide options.fetchFn.\");\n }\n if (!timeoutMs) return fetchFn(input, init);\n\n const timeoutController = new AbortController();\n const t = setTimeout(() => timeoutController.abort(), timeoutMs);\n // Note: We intentionally don't call cleanUpSignals() here because for streaming\n // responses (like SSE), the connection remains open after the response headers\n // are received. The abort signal needs to remain connected so that close() can\n // propagate the abort through the signal chain.\n const { signal } = combineAbortSignals([init.signal, timeoutController.signal]);\n try {\n return await fetchFn(input, {\n ...init,\n signal,\n });\n } finally {\n clearTimeout(t);\n }\n}\n\n/**\n * Ensures the response is successful, throwing ReplaneError if not\n */\nexport async function ensureSuccessfulResponse(response: Response, message: string): Promise<void> {\n if (response.status === 404) {\n throw new ReplaneError({\n message: `Not found: ${message}`,\n code: ReplaneErrorCode.NotFound,\n });\n }\n\n if (response.status === 401) {\n throw new ReplaneError({\n message: `Unauthorized access: ${message}`,\n code: ReplaneErrorCode.AuthError,\n });\n }\n\n if (response.status === 403) {\n throw new ReplaneError({\n message: `Forbidden access: ${message}`,\n code: ReplaneErrorCode.Forbidden,\n });\n }\n\n if (!response.ok) {\n let body: unknown;\n try {\n body = await response.text();\n } catch {\n body = \"<unable to read response body>\";\n }\n\n const code =\n response.status >= 500\n ? ReplaneErrorCode.ServerError\n : response.status >= 400\n ? ReplaneErrorCode.ClientError\n : ReplaneErrorCode.Unknown;\n\n throw new ReplaneError({\n message: `Fetch response isn't successful (${message}): ${response.status} ${response.statusText} - ${body}`,\n code,\n });\n }\n}\n\n/**\n * Fetches a Server-Sent Events (SSE) stream and yields parsed events.\n *\n * @param params - Options for the SSE fetch\n * @yields SseEvent objects containing either data or comment events\n */\nexport async function* fetchSse(params: FetchSseOptions): AsyncGenerator<SseEvent> {\n const abortController = new AbortController();\n const { signal, cleanUpSignals } = params.signal\n ? combineAbortSignals([params.signal, abortController.signal])\n : { signal: abortController.signal, cleanUpSignals: () => {} };\n\n try {\n const res = await fetchWithTimeout(\n params.url,\n {\n method: params.method ?? \"GET\",\n headers: { Accept: \"text/event-stream\", ...(params.headers ?? {}) },\n body: params.body,\n signal,\n },\n params.timeoutMs,\n params.fetchFn\n );\n\n await ensureSuccessfulResponse(res, `SSE ${params.url}`);\n const responseContentType = res.headers.get(\"content-type\") ?? \"\";\n\n if (!responseContentType.includes(\"text/event-stream\")) {\n throw new ReplaneError({\n message: `Expected text/event-stream, got \"${responseContentType}\"`,\n code: ReplaneErrorCode.ServerError,\n });\n }\n\n if (!res.body) {\n throw new ReplaneError({\n message: `Failed to fetch SSE ${params.url}: body is empty`,\n code: ReplaneErrorCode.Unknown,\n });\n }\n\n if (params.onConnect) {\n params.onConnect();\n }\n\n const decoded = res.body.pipeThrough(new TextDecoderStream());\n const reader = decoded.getReader();\n\n let buffer = \"\";\n\n try {\n while (true) {\n const { value, done } = await reader.read();\n if (done) break;\n buffer += value!;\n\n // Split on blank line; handle both \\n\\n and \\r\\n\\r\\n\n const frames = buffer.split(/\\r?\\n\\r?\\n/);\n buffer = frames.pop() ?? \"\";\n\n for (const frame of frames) {\n // Parse lines inside a single SSE event frame\n const dataLines: string[] = [];\n let comment: string | null = null;\n\n for (const rawLine of frame.split(/\\r?\\n/)) {\n if (!rawLine) continue;\n if (rawLine.startsWith(\":\")) {\n // comment/keepalive\n comment = rawLine.slice(1);\n continue;\n }\n\n if (rawLine.startsWith(SSE_DATA_PREFIX)) {\n // Keep leading space after \"data:\" if present per spec\n const line = rawLine.slice(SSE_DATA_PREFIX.length).replace(/^\\s/, \"\");\n dataLines.push(line);\n }\n }\n\n if (dataLines.length) {\n const data = dataLines.join(\"\\n\");\n yield { type: \"data\", data };\n } else if (comment !== null) {\n yield { type: \"comment\", comment };\n }\n }\n }\n } finally {\n try {\n await reader.cancel();\n } catch {\n // ignore error\n }\n abortController.abort();\n }\n } finally {\n cleanUpSignals();\n }\n}\n","import type { ReplicationStreamRecord, StartReplicationStreamBody } from \"./types\";\nimport type { ReplaneFinalOptions } from \"./client-types\";\nimport { fetchSse } from \"./sse\";\nimport { combineAbortSignals, retryDelay } from \"./utils\";\n\nconst SUPPORTED_REPLICATION_STREAM_RECORD_TYPES = Object.keys({\n config_change: true,\n init: true,\n} satisfies Record<ReplicationStreamRecord[\"type\"], true>);\n\n/**\n * Options for starting a replication stream\n */\nexport interface StartReplicationStreamOptions extends ReplaneFinalOptions {\n // getBody is a function to get the latest configs when we are trying\n // to reestablish the replication stream\n getBody: () => StartReplicationStreamBody;\n signal?: AbortSignal;\n onConnect?: () => void;\n}\n\n/**\n * Interface for storage implementations\n */\nexport interface ReplaneStorage {\n startReplicationStream(\n options: StartReplicationStreamOptions\n ): AsyncIterable<ReplicationStreamRecord>;\n close(): void;\n}\n\n/**\n * Remote storage implementation that connects to the Replane server\n * and streams config updates via SSE.\n */\nexport class ReplaneRemoteStorage implements ReplaneStorage {\n private closeController = new AbortController();\n\n /**\n * Start a replication stream that yields config updates.\n * This method never throws - it retries on failure with exponential backoff.\n */\n async *startReplicationStream(\n options: StartReplicationStreamOptions\n ): AsyncIterable<ReplicationStreamRecord> {\n const { signal, cleanUpSignals } = combineAbortSignals([\n this.closeController.signal,\n options.signal,\n ]);\n try {\n let failedAttempts = 0;\n while (!signal.aborted) {\n try {\n for await (const event of this.startReplicationStreamImpl({\n ...options,\n signal,\n onConnect: () => {\n failedAttempts = 0;\n },\n })) {\n yield event;\n }\n } catch (error: unknown) {\n failedAttempts++;\n const retryDelayMs = Math.min(options.retryDelayMs * 2 ** (failedAttempts - 1), 10_000);\n if (!signal.aborted) {\n options.logger.error(\n `Failed to fetch project events, retrying in ${retryDelayMs}ms...`,\n error\n );\n\n await retryDelay(retryDelayMs);\n }\n }\n }\n } finally {\n cleanUpSignals();\n }\n }\n\n private async *startReplicationStreamImpl(\n options: StartReplicationStreamOptions\n ): AsyncIterable<ReplicationStreamRecord> {\n // Create an abort controller for inactivity timeout\n const inactivityAbortController = new AbortController();\n const { signal: combinedSignal, cleanUpSignals } = options.signal\n ? combineAbortSignals([options.signal, inactivityAbortController.signal])\n : { signal: inactivityAbortController.signal, cleanUpSignals: () => {} };\n\n let inactivityTimer: ReturnType<typeof setTimeout> | null = null;\n\n const resetInactivityTimer = () => {\n if (inactivityTimer) clearTimeout(inactivityTimer);\n inactivityTimer = setTimeout(() => {\n inactivityAbortController.abort();\n }, options.inactivityTimeoutMs);\n };\n\n try {\n const rawEvents = fetchSse({\n fetchFn: options.fetchFn,\n headers: {\n Authorization: this.getAuthHeader(options),\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(options.getBody()),\n timeoutMs: options.requestTimeoutMs,\n method: \"POST\",\n signal: combinedSignal,\n url: this.getApiEndpoint(`/sdk/v1/replication/stream`, options),\n onConnect: () => {\n resetInactivityTimer();\n options.onConnect?.();\n },\n });\n\n for await (const sseEvent of rawEvents) {\n resetInactivityTimer();\n\n if (sseEvent.type === \"comment\") continue;\n\n const event = JSON.parse(sseEvent.data);\n if (\n typeof event === \"object\" &&\n event !== null &&\n \"type\" in event &&\n typeof event.type === \"string\" &&\n (SUPPORTED_REPLICATION_STREAM_RECORD_TYPES as unknown as string[]).includes(event.type)\n ) {\n yield event as ReplicationStreamRecord;\n }\n }\n } finally {\n if (inactivityTimer) clearTimeout(inactivityTimer);\n cleanUpSignals();\n }\n }\n\n /**\n * Close the storage and abort any active connections\n */\n close(): void {\n this.closeController.abort();\n }\n\n private getAuthHeader(options: ReplaneFinalOptions): string {\n return `Bearer ${options.sdkKey}`;\n }\n\n private getApiEndpoint(path: string, options: ReplaneFinalOptions): string {\n return `${options.baseUrl}/api${path}`;\n }\n}\n","/**\n * FNV-1a 32-bit hash function\n *\n * FNV (Fowler–Noll–Vo) is a non-cryptographic hash function known for its\n * speed and good distribution. This implementation uses the FNV-1a variant\n * which XORs before multiplying for better avalanche characteristics.\n *\n * @param input - The string to hash\n * @returns A 32-bit unsigned integer hash value\n */\nexport function fnv1a32(input: string): number {\n // Convert string to bytes (UTF-8)\n const encoder = new TextEncoder();\n const bytes = encoder.encode(input);\n\n // FNV-1a core\n let hash = 0x811c9dc5 >>> 0; // 2166136261, force uint32\n\n for (let i = 0; i < bytes.length; i++) {\n hash ^= bytes[i]; // XOR with byte\n hash = Math.imul(hash, 0x01000193) >>> 0; // * 16777619 mod 2^32\n }\n\n return hash >>> 0; // ensure unsigned 32-bit\n}\n\n/**\n * Convert FNV-1a hash to [0, 1) for bucketing.\n *\n * This is useful for percentage-based segmentation where you need\n * to deterministically assign a value to a bucket based on a string input.\n *\n * @param input - The string to hash\n * @returns A number in the range [0, 1)\n */\nexport function fnv1a32ToUnit(input: string): number {\n const h = fnv1a32(input);\n return h / 2 ** 32; // double in [0, 1)\n}\n","import type { RenderedCondition, RenderedOverride } from \"./types\";\nimport type { ReplaneContext, ReplaneLogger } from \"./client-types\";\nimport { fnv1a32ToUnit } from \"./hash\";\n\n/**\n * Result of evaluating a condition\n */\nexport type EvaluationResult = \"matched\" | \"not_matched\" | \"unknown\";\n\n/**\n * Evaluate config overrides based on context.\n * Returns the first matching override's value, or the base value if no override matches.\n *\n * @param baseValue - The default value to return if no override matches\n * @param overrides - Array of overrides to evaluate\n * @param context - The context to evaluate conditions against\n * @param logger - Logger for warnings\n * @returns The evaluated value\n */\nexport function evaluateOverrides<T>(\n baseValue: T,\n overrides: RenderedOverride[],\n context: ReplaneContext,\n logger: ReplaneLogger\n): T {\n // Find first matching override\n for (const override of overrides) {\n // All conditions must match (implicit AND)\n let overrideResult: EvaluationResult = \"matched\";\n const results = override.conditions.map((c) => evaluateCondition(c, context, logger));\n // AND: false > unknown > true\n if (results.some((r) => r === \"not_matched\")) {\n overrideResult = \"not_matched\";\n } else if (results.some((r) => r === \"unknown\")) {\n overrideResult = \"unknown\";\n }\n\n // Only use override if all conditions matched (not unknown)\n if (overrideResult === \"matched\") {\n return override.value as T;\n }\n }\n\n return baseValue;\n}\n\n/**\n * Evaluate a single condition against a context.\n *\n * @param condition - The condition to evaluate\n * @param context - The context to evaluate against\n * @param logger - Logger for warnings\n * @returns The evaluation result\n */\nexport function evaluateCondition(\n condition: RenderedCondition,\n context: ReplaneContext,\n logger: ReplaneLogger\n): EvaluationResult {\n const operator = condition.operator;\n\n // Composite conditions\n if (operator === \"and\") {\n const results = condition.conditions.map((c) => evaluateCondition(c, context, logger));\n // AND: false > unknown > true\n if (results.some((r) => r === \"not_matched\")) return \"not_matched\";\n if (results.some((r) => r === \"unknown\")) return \"unknown\";\n return \"matched\";\n }\n\n if (operator === \"or\") {\n const results = condition.conditions.map((c) => evaluateCondition(c, context, logger));\n // OR: true > unknown > false\n if (results.some((r) => r === \"matched\")) return \"matched\";\n if (results.some((r) => r === \"unknown\")) return \"unknown\";\n return \"not_matched\";\n }\n\n if (operator === \"not\") {\n const result = evaluateCondition(condition.condition, context, logger);\n if (result === \"matched\") return \"not_matched\";\n if (result === \"not_matched\") return \"matched\";\n return \"unknown\"; // NOT unknown = unknown\n }\n\n // Segmentation\n if (operator === \"segmentation\") {\n const contextValue = context[condition.property];\n if (contextValue === undefined || contextValue === null) {\n return \"unknown\";\n }\n\n // FNV-1a hash to bucket [0, 100)\n const hashInput = String(contextValue) + condition.seed;\n const unitValue = fnv1a32ToUnit(hashInput);\n return unitValue >= condition.fromPercentage / 100 && unitValue < condition.toPercentage / 100\n ? \"matched\"\n : \"not_matched\";\n }\n\n // Property-based conditions\n const property = condition.property;\n const contextValue = context[property];\n const expectedValue = condition.value;\n\n if (contextValue === undefined) {\n return \"unknown\";\n }\n\n // Type casting\n const castedValue = castToContextType(expectedValue, contextValue);\n\n switch (operator) {\n case \"equals\":\n return contextValue === castedValue ? \"matched\" : \"not_matched\";\n\n case \"in\":\n if (!Array.isArray(castedValue)) return \"unknown\";\n return castedValue.includes(contextValue) ? \"matched\" : \"not_matched\";\n\n case \"not_in\":\n if (!Array.isArray(castedValue)) return \"unknown\";\n return !castedValue.includes(contextValue) ? \"matched\" : \"not_matched\";\n\n case \"less_than\":\n if (typeof contextValue === \"number\" && typeof castedValue === \"number\") {\n return contextValue < castedValue ? \"matched\" : \"not_matched\";\n }\n if (typeof contextValue === \"string\" && typeof castedValue === \"string\") {\n return contextValue < castedValue ? \"matched\" : \"not_matched\";\n }\n return \"not_matched\";\n\n case \"less_than_or_equal\":\n if (typeof contextValue === \"number\" && typeof castedValue === \"number\") {\n return contextValue <= castedValue ? \"matched\" : \"not_matched\";\n }\n if (typeof contextValue === \"string\" && typeof castedValue === \"string\") {\n return contextValue <= castedValue ? \"matched\" : \"not_matched\";\n }\n return \"not_matched\";\n\n case \"greater_than\":\n if (typeof contextValue === \"number\" && typeof castedValue === \"number\") {\n return contextValue > castedValue ? \"matched\" : \"not_matched\";\n }\n if (typeof contextValue === \"string\" && typeof castedValue === \"string\") {\n return contextValue > castedValue ? \"matched\" : \"not_matched\";\n }\n return \"not_matched\";\n\n case \"greater_than_or_equal\":\n if (typeof contextValue === \"number\" && typeof castedValue === \"number\") {\n return contextValue >= castedValue ? \"matched\" : \"not_matched\";\n }\n if (typeof contextValue === \"string\" && typeof castedValue === \"string\") {\n return contextValue >= castedValue ? \"matched\" : \"not_matched\";\n }\n return \"not_matched\";\n\n default:\n warnNever(operator, logger, `Unexpected operator: ${operator}`);\n return \"unknown\";\n }\n}\n\n/**\n * Helper to warn about exhaustive check failures\n */\nfunction warnNever(value: never, logger: ReplaneLogger, message: string): void {\n logger.warn(message, { value });\n}\n\n/**\n * Cast expected value to match context value type.\n * This enables loose matching between different types (e.g., \"25\" matches 25).\n *\n * @param expectedValue - The value from the condition\n * @param contextValue - The value from the context\n * @returns The expected value cast to match the context value's type\n */\nexport function castToContextType(expectedValue: unknown, contextValue: unknown): unknown {\n if (typeof contextValue === \"number\") {\n if (typeof expectedValue === \"string\") {\n const num = Number(expectedValue);\n return isNaN(num) ? expectedValue : num;\n }\n return expectedValue;\n }\n\n if (typeof contextValue === \"boolean\") {\n if (typeof expectedValue === \"string\") {\n if (expectedValue === \"true\") return true;\n if (expectedValue === \"false\") return false;\n }\n if (typeof expectedValue === \"number\") {\n return expectedValue !== 0;\n }\n return expectedValue;\n }\n\n if (typeof contextValue === \"string\") {\n if (typeof expectedValue === \"number\" || typeof expectedValue === \"boolean\") {\n return String(expectedValue);\n }\n return expectedValue;\n }\n\n return expectedValue;\n}\n","import type { ConfigDto, RenderedOverride } from \"./types\";\nimport type {\n Configs,\n ReplaneContext,\n ReplaneLogger,\n GetConfigOptions,\n MapConfig,\n ReplaneSnapshot,\n ReplaneClient,\n ReplaneClientOptions,\n RestoreReplaneClientOptions,\n ReplaneFinalOptions,\n} from \"./client-types\";\nimport type { ReplaneStorage } from \"./storage\";\nimport { ReplaneRemoteStorage } from \"./storage\";\nimport { ReplaneError, ReplaneErrorCode } from \"./error\";\nimport { evaluateOverrides } from \"./evaluation\";\nimport { Deferred } from \"./utils\";\n\n/**\n * Internal options for creating the client core\n */\ninterface ClientCoreOptions {\n initialConfigs: ConfigDto[];\n context: ReplaneContext;\n logger: ReplaneLogger;\n storage: ReplaneStorage | null;\n streamOptions: ReplaneFinalOptions | null;\n requiredConfigs: string[];\n}\n\n/**\n * Result from creating the client core\n */\ninterface ClientCoreResult<T extends Configs> {\n client: ReplaneClient<T>;\n configs: Map<string, ConfigDto>;\n startStreaming: () => Promise<void>;\n clientReady: Deferred<void>;\n}\n\n/**\n * Creates the core client logic shared between createReplaneClient and restoreReplaneClient\n */\nfunction createClientCore<T extends Configs = Record<string, unknown>>(\n options: ClientCoreOptions\n): ClientCoreResult<T> {\n const { initialConfigs, context, logger, storage, streamOptions, requiredConfigs } = options;\n\n const configs: Map<string, ConfigDto> = new Map(\n initialConfigs.map((config) => [config.name, config])\n );\n\n const clientReady = new Deferred<void>();\n const configSubscriptions = new Map<keyof T, Set<(config: MapConfig<T>) => void>>();\n const clientSubscriptions = new Set<(config: MapConfig<T>) => void>();\n\n function processConfigUpdates(updatedConfigs: ConfigDto[]) {\n for (const config of updatedConfigs) {\n configs.set(config.name, {\n name: config.name,\n overrides: config.overrides,\n value: config.value,\n });\n for (const callback of clientSubscriptions) {\n callback({ name: config.name as keyof T, value: config.value as T[keyof T] });\n }\n for (const callback of configSubscriptions.get(config.name as keyof T) ?? []) {\n callback({ name: config.name as keyof T, value: config.value as T[keyof T] });\n }\n }\n }\n\n async function startStreaming(): Promise<void> {\n if (!storage || !streamOptions) return;\n\n try {\n const replicationStream = storage.startReplicationStream({\n ...streamOptions,\n getBody: () => ({\n currentConfigs: [...configs.values()].map((config) => ({\n name: config.name,\n overrides: config.overrides,\n value: config.value,\n })),\n requiredConfigs,\n }),\n });\n\n for await (const event of replicationStream) {\n const updatedConfigs: ConfigDto[] =\n event.type === \"config_change\" ? [event.config] : event.configs;\n processConfigUpdates(updatedConfigs);\n clientReady.resolve();\n }\n } catch (error) {\n logger.error(\"Replane: error in SSE connection:\", error);\n clientReady.reject(error);\n throw error;\n }\n }\n\n function get<K extends keyof T>(configName: K, getConfigOptions: GetConfigOptions = {}): T[K] {\n const config = configs.get(String(configName));\n\n if (config === undefined) {\n throw new ReplaneError({\n message: `Config not found: ${String(configName)}`,\n code: ReplaneErrorCode.NotFound,\n });\n }\n\n try {\n return evaluateOverrides<T[K]>(\n config.value as T[K],\n config.overrides,\n { ...context, ...(getConfigOptions?.context ?? {}) },\n logger\n );\n } catch (error) {\n logger.error(`Replane: error evaluating overrides for config ${String(configName)}:`, error);\n return config.value as T[K];\n }\n }\n\n const subscribe = (\n callbackOrConfigName: keyof T | ((config: MapConfig<T>) => void),\n callbackOrUndefined?: (config: MapConfig<T>) => void\n ) => {\n let configName: keyof T | undefined = undefined;\n let callback: (config: MapConfig<T>) => void;\n if (typeof callbackOrConfigName === \"function\") {\n callback = callbackOrConfigName;\n } else {\n configName = callbackOrConfigName as keyof T;\n if (callbackOrUndefined === undefined) {\n throw new Error(\"callback is required when config name is provided\");\n }\n callback = callbackOrUndefined!;\n }\n\n // Wrap the callback to ensure that we have a unique reference\n const originalCallback = callback;\n callback = (...args: Parameters<typeof callback>) => {\n originalCallback(...args);\n };\n\n if (configName === undefined) {\n clientSubscriptions.add(callback);\n return () => {\n clientSubscriptions.delete(callback);\n };\n }\n\n if (!configSubscriptions.has(configName)) {\n configSubscriptions.set(configName, new Set());\n }\n configSubscriptions.get(configName)!.add(callback);\n return () => {\n configSubscriptions.get(configName)?.delete(callback);\n if (configSubscriptions.get(configName)?.size === 0) {\n configSubscriptions.delete(configName);\n }\n };\n };\n\n const getSnapshot = (): ReplaneSnapshot<T> => ({\n configs: [...configs.values()].map((config) => ({\n name: config.name,\n value: config.value,\n overrides: config.overrides.map((override) => ({\n name: override.name,\n conditions: override.conditions,\n value: override.value,\n })),\n })),\n context,\n });\n\n const close = () => storage?.close();\n\n const client: ReplaneClient<T> = {\n get,\n subscribe: subscribe as ReplaneClient<T>[\"subscribe\"],\n getSnapshot,\n close,\n };\n\n return { client, configs, startStreaming, clientReady };\n}\n\n/**\n * Create a Replane client bound to an SDK key.\n *\n * @example\n * ```typescript\n * const client = await createReplaneClient({\n * sdkKey: 'your-sdk-key',\n * baseUrl: 'https://app.replane.dev'\n * });\n * const value = client.get('my-config');\n * ```\n */\nexport async function createReplaneClient<T extends Configs = Record<string, unknown>>(\n sdkOptions: ReplaneClientOptions<T>\n): Promise<ReplaneClient<T>> {\n const storage = new ReplaneRemoteStorage();\n return await createReplaneClientInternal(toFinalOptions(sdkOptions), storage);\n}\n\n/**\n * Create a Replane client that uses in-memory storage.\n * Useful for testing or when you have static config values.\n *\n * @example\n * ```typescript\n * const client = createInMemoryReplaneClient({ 'my-config': 123 });\n * const value = client.get('my-config'); // 123\n * ```\n */\nexport function createInMemoryReplaneClient<T extends Configs = Record<string, unknown>>(\n initialData: T\n): ReplaneClient<T> {\n return {\n get: (configName) => {\n const config = initialData[configName];\n if (config === undefined) {\n throw new ReplaneError({\n message: `Config not found: ${String(configName)}`,\n code: ReplaneErrorCode.NotFound,\n });\n }\n return config;\n },\n subscribe: () => {\n return () => {};\n },\n getSnapshot: () => ({\n configs: Object.entries(initialData).map(([name, value]) => ({\n name,\n value,\n overrides: [],\n })),\n }),\n close: () => {},\n };\n}\n\n/**\n * Restore a Replane client from a snapshot.\n * This is useful for SSR/hydration scenarios where the server has already fetched configs.\n *\n * @example\n * ```typescript\n * // On the server:\n * const serverClient = await createReplaneClient({ ... });\n * const snapshot = serverClient.getSnapshot();\n * // Pass snapshot to client via props/serialization\n *\n * // On the client:\n * const client = restoreReplaneClient({\n * snapshot,\n * connection: { sdkKey, baseUrl }\n * });\n * const value = client.get('my-config');\n * ```\n */\nexport function restoreReplaneClient<T extends Configs = Record<string, unknown>>(\n options: RestoreReplaneClientOptions<T>\n): ReplaneClient<T> {\n const { snapshot, connection } = options;\n const context = options.context ?? snapshot.context ?? {};\n const logger = connection?.logger ?? console;\n\n // Initialize configs from snapshot\n const initialConfigs: ConfigDto[] = snapshot.configs.map((config) => ({\n name: config.name,\n value: config.value,\n overrides: config.overrides as RenderedOverride[],\n }));\n\n let storage: ReplaneRemoteStorage | null = null;\n let streamOptions: ReplaneFinalOptions | null = null;\n\n if (connection) {\n storage = new ReplaneRemoteStorage();\n streamOptions = {\n sdkKey: connection.sdkKey,\n baseUrl: connection.baseUrl.replace(/\\/+$/, \"\"),\n fetchFn: connection.fetchFn ?? globalThis.fetch.bind(globalThis),\n requestTimeoutMs: connection.requestTimeoutMs ?? 2000,\n initializationTimeoutMs: 5000, // Not used for restore\n inactivityTimeoutMs: connection.inactivityTimeoutMs ?? 30_000,\n logger,\n retryDelayMs: connection.retryDelayMs ?? 200,\n context,\n requiredConfigs: [],\n fallbacks: [],\n };\n }\n\n const { client, startStreaming } = createClientCore<T>({\n initialConfigs,\n context,\n logger,\n storage,\n streamOptions,\n requiredConfigs: [],\n });\n\n // Start streaming in background (non-blocking) if connection is provided\n if (storage && streamOptions) {\n startStreaming().catch((error) => {\n logger.error(\"Replane: error in restored client SSE connection:\", error);\n });\n }\n\n return client;\n}\n\n/**\n * Internal function to create a Replane client with the given options and storage\n */\nasync function createReplaneClientInternal<T extends Configs = Record<string, unknown>>(\n sdkOptions: ReplaneFinalOptions,\n storage: ReplaneStorage\n): Promise<ReplaneClient<T>> {\n if (!sdkOptions.sdkKey) throw new Error(\"SDK key is required\");\n\n const { client, configs, startStreaming, clientReady } = createClientCore<T>({\n initialConfigs: sdkOptions.fallbacks,\n context: sdkOptions.context,\n logger: sdkOptions.logger,\n storage,\n streamOptions: sdkOptions,\n requiredConfigs: sdkOptions.requiredConfigs,\n });\n\n // Start streaming in background\n startStreaming().catch((error) => {\n sdkOptions.logger.error(\"Replane: error initializing client:\", error);\n });\n\n const initializationTimeoutId = setTimeout(() => {\n if (sdkOptions.fallbacks.length === 0) {\n // no fallbacks, we have nothing to work with\n client.close();\n\n clientReady.reject(\n new ReplaneError({\n message: \"Replane client initialization timed out\",\n code: ReplaneErrorCode.Timeout,\n })\n );\n\n return;\n }\n\n const missingRequiredConfigs: string[] = [];\n for (const requiredConfigName of sdkOptions.requiredConfigs) {\n if (!configs.has(requiredConfigName)) {\n missingRequiredConfigs.push(requiredConfigName);\n }\n }\n\n if (missingRequiredConfigs.length > 0) {\n client.close();\n clientReady.reject(\n new ReplaneError({\n message: `Required configs are missing: ${missingRequiredConfigs.join(\", \")}`,\n code: ReplaneErrorCode.NotFound,\n })\n );\n\n return;\n }\n\n clientReady.resolve();\n }, sdkOptions.initializationTimeoutMs);\n\n clientReady.promise.then(() => clearTimeout(initializationTimeoutId));\n\n await clientReady.promise;\n\n return client;\n}\n\n/**\n * Convert user options to final options with defaults\n */\nfunction toFinalOptions<T extends Configs>(defaults: ReplaneClientOptions<T>): ReplaneFinalOptions {\n return {\n sdkKey: defaults.sdkKey,\n baseUrl: defaults.baseUrl.replace(/\\/+$/, \"\"),\n fetchFn:\n defaults.fetchFn ??\n // some browsers require binding the fetch function to window\n globalThis.fetch.bind(globalThis),\n requestTimeoutMs: defaults.requestTimeoutMs ?? 2000,\n initializationTimeoutMs: defaults.initializationTimeoutMs ?? 5000,\n inactivityTimeoutMs: defaults.inactivityTimeoutMs ?? 30_000,\n logger: defaults.logger ?? console,\n retryDelayMs: defaults.retryDelayMs ?? 200,\n context: {\n ...(defaults.context ?? {}),\n },\n requiredConfigs: Array.isArray(defaults.required)\n ? defaults.required.map((name) => String(name))\n : Object.entries(defaults.required ?? {})\n .filter(([_, value]) => value !== undefined)\n .map(([name]) => name),\n fallbacks: Object.entries(defaults.fallbacks ?? {})\n .filter(([_, value]) => value !== undefined)\n .map(([name, value]) => ({\n name,\n overrides: [],\n version: -1,\n value,\n })),\n };\n}\n"],"mappings":";;;;AAGA,IAAY,gEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD;;;;AAKD,IAAa,eAAb,cAAkC,MAAM;CACtC;CAEA,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AAS;GACT;EACD,GAAE;CACN;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["params: { message: string; code: string; cause?: unknown }","ms: number","averageDelay: number","signals: Array<AbortSignal | undefined | null>","input: string | URL | Request","init: RequestInit","timeoutMs: number","fetchFn: typeof fetch","response: Response","message: string","body: unknown","params: FetchSseOptions","dataLines: string[]","comment: string | null","options: StartReplicationStreamOptions","error: unknown","inactivityTimer: ReturnType<typeof setTimeout> | null","options: ReplaneFinalOptions","path: string","input: string","baseValue: T","overrides: RenderedOverride[]","context: ReplaneContext","logger: ReplaneLogger","overrideResult: EvaluationResult","condition: RenderedCondition","contextValue","value: never","message: string","expectedValue: unknown","contextValue: unknown","options: ClientCoreOptions","configs: Map<string, ConfigDto>","updatedConfigs: ConfigDto[]","configName: K","getConfigOptions: GetConfigOptions","callbackOrConfigName: keyof T | ((config: MapConfig<T>) => void)","callbackOrUndefined?: (config: MapConfig<T>) => void","configName: keyof T | undefined","callback: (config: MapConfig<T>) => void","client: ReplaneClient<T>","sdkOptions: ReplaneClientOptions<T>","initialData: T","options: RestoreReplaneClientOptions<T>","initialConfigs: ConfigDto[]","storage: ReplaneRemoteStorage | null","streamOptions: ReplaneFinalOptions | null","sdkOptions: ReplaneFinalOptions","storage: ReplaneStorage","missingRequiredConfigs: string[]","defaults: ReplaneClientOptions<T>"],"sources":["../src/error.ts","../src/utils.ts","../src/sse.ts","../src/storage.ts","../src/hash.ts","../src/evaluation.ts","../src/client.ts"],"sourcesContent":["/**\n * Error codes for ReplaneError\n */\nexport enum ReplaneErrorCode {\n NotFound = \"not_found\",\n Timeout = \"timeout\",\n NetworkError = \"network_error\",\n AuthError = \"auth_error\",\n Forbidden = \"forbidden\",\n ServerError = \"server_error\",\n ClientError = \"client_error\",\n Closed = \"closed\",\n NotInitialized = \"not_initialized\",\n Unknown = \"unknown\",\n}\n\n/**\n * Custom error class for Replane SDK errors\n */\nexport class ReplaneError extends Error {\n code: string;\n\n constructor(params: { message: string; code: string; cause?: unknown }) {\n super(params.message, { cause: params.cause });\n this.name = \"ReplaneError\";\n this.code = params.code;\n }\n}\n","/**\n * Returns a promise that resolves after the specified delay\n *\n * @param ms - Delay in milliseconds\n */\nexport async function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Returns a promise that resolves after a delay with jitter.\n * The actual delay is the average delay ± 10% (jitter = averageDelay/5).\n *\n * @param averageDelay - The average delay in milliseconds\n */\nexport async function retryDelay(averageDelay: number): Promise<void> {\n const jitter = averageDelay / 5;\n const delayMs = averageDelay + Math.random() * jitter - jitter / 2;\n\n await delay(delayMs);\n}\n\n/**\n * Combines multiple abort signals into one.\n * When any of the input signals is aborted, the combined signal will also be aborted.\n *\n * @param signals - Array of AbortSignal instances (can contain undefined/null)\n * @returns An object containing the combined signal and a cleanup function\n */\nexport function combineAbortSignals(signals: Array<AbortSignal | undefined | null>): {\n signal: AbortSignal;\n cleanUpSignals: () => void;\n} {\n const controller = new AbortController();\n const onAbort = () => {\n controller.abort();\n cleanUpSignals();\n };\n\n const cleanUpSignals = () => {\n for (const s of signals) {\n s?.removeEventListener(\"abort\", onAbort);\n }\n };\n\n for (const s of signals) {\n s?.addEventListener(\"abort\", onAbort, { once: true });\n }\n\n if (signals.some((s) => s?.aborted)) {\n onAbort();\n }\n\n return { signal: controller.signal, cleanUpSignals };\n}\n\n/**\n * A deferred promise that can be resolved or rejected from outside.\n * Useful for coordinating async operations.\n */\nexport class Deferred<T> {\n public readonly promise: Promise<T>;\n public resolve!: (value: T) => void;\n public reject!: (error: unknown) => void;\n\n constructor() {\n this.promise = new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n}\n","import { ReplaneError, ReplaneErrorCode } from \"./error\";\nimport { combineAbortSignals } from \"./utils\";\n\nconst SSE_DATA_PREFIX = \"data:\";\n\n/**\n * Parsed SSE event\n */\nexport type SseEvent = { type: \"comment\"; comment: string } | { type: \"data\"; data: string };\n\n/**\n * Options for fetchSse\n */\nexport interface FetchSseOptions {\n fetchFn: typeof fetch;\n url: string;\n timeoutMs: number;\n body?: string;\n headers?: Record<string, string>;\n method?: string;\n signal?: AbortSignal;\n onConnect?: () => void;\n}\n\n/**\n * Fetch with timeout support\n */\nexport async function fetchWithTimeout(\n input: string | URL | Request,\n init: RequestInit,\n timeoutMs: number,\n fetchFn: typeof fetch\n): Promise<Response> {\n if (!fetchFn) {\n throw new Error(\"Global fetch is not available. Provide options.fetchFn.\");\n }\n if (!timeoutMs) return fetchFn(input, init);\n\n const timeoutController = new AbortController();\n const t = setTimeout(() => timeoutController.abort(), timeoutMs);\n // Note: We intentionally don't call cleanUpSignals() here because for streaming\n // responses (like SSE), the connection remains open after the response headers\n // are received. The abort signal needs to remain connected so that close() can\n // propagate the abort through the signal chain.\n const { signal } = combineAbortSignals([init.signal, timeoutController.signal]);\n try {\n return await fetchFn(input, {\n ...init,\n signal,\n });\n } finally {\n clearTimeout(t);\n }\n}\n\n/**\n * Ensures the response is successful, throwing ReplaneError if not\n */\nexport async function ensureSuccessfulResponse(response: Response, message: string): Promise<void> {\n if (response.status === 404) {\n throw new ReplaneError({\n message: `Not found: ${message}`,\n code: ReplaneErrorCode.NotFound,\n });\n }\n\n if (response.status === 401) {\n throw new ReplaneError({\n message: `Unauthorized access: ${message}`,\n code: ReplaneErrorCode.AuthError,\n });\n }\n\n if (response.status === 403) {\n throw new ReplaneError({\n message: `Forbidden access: ${message}`,\n code: ReplaneErrorCode.Forbidden,\n });\n }\n\n if (!response.ok) {\n let body: unknown;\n try {\n body = await response.text();\n } catch {\n body = \"<unable to read response body>\";\n }\n\n const code =\n response.status >= 500\n ? ReplaneErrorCode.ServerError\n : response.status >= 400\n ? ReplaneErrorCode.ClientError\n : ReplaneErrorCode.Unknown;\n\n throw new ReplaneError({\n message: `Fetch response isn't successful (${message}): ${response.status} ${response.statusText} - ${body}`,\n code,\n });\n }\n}\n\n/**\n * Fetches a Server-Sent Events (SSE) stream and yields parsed events.\n *\n * @param params - Options for the SSE fetch\n * @yields SseEvent objects containing either data or comment events\n */\nexport async function* fetchSse(params: FetchSseOptions): AsyncGenerator<SseEvent> {\n const abortController = new AbortController();\n const { signal, cleanUpSignals } = params.signal\n ? combineAbortSignals([params.signal, abortController.signal])\n : { signal: abortController.signal, cleanUpSignals: () => {} };\n\n try {\n const res = await fetchWithTimeout(\n params.url,\n {\n method: params.method ?? \"GET\",\n headers: { Accept: \"text/event-stream\", ...(params.headers ?? {}) },\n body: params.body,\n signal,\n },\n params.timeoutMs,\n params.fetchFn\n );\n\n await ensureSuccessfulResponse(res, `SSE ${params.url}`);\n const responseContentType = res.headers.get(\"content-type\") ?? \"\";\n\n if (!responseContentType.includes(\"text/event-stream\")) {\n throw new ReplaneError({\n message: `Expected text/event-stream, got \"${responseContentType}\"`,\n code: ReplaneErrorCode.ServerError,\n });\n }\n\n if (!res.body) {\n throw new ReplaneError({\n message: `Failed to fetch SSE ${params.url}: body is empty`,\n code: ReplaneErrorCode.Unknown,\n });\n }\n\n if (params.onConnect) {\n params.onConnect();\n }\n\n const decoded = res.body.pipeThrough(new TextDecoderStream());\n const reader = decoded.getReader();\n\n let buffer = \"\";\n\n try {\n while (true) {\n const { value, done } = await reader.read();\n if (done) break;\n buffer += value!;\n\n // Split on blank line; handle both \\n\\n and \\r\\n\\r\\n\n const frames = buffer.split(/\\r?\\n\\r?\\n/);\n buffer = frames.pop() ?? \"\";\n\n for (const frame of frames) {\n // Parse lines inside a single SSE event frame\n const dataLines: string[] = [];\n let comment: string | null = null;\n\n for (const rawLine of frame.split(/\\r?\\n/)) {\n if (!rawLine) continue;\n if (rawLine.startsWith(\":\")) {\n // comment/keepalive\n comment = rawLine.slice(1);\n continue;\n }\n\n if (rawLine.startsWith(SSE_DATA_PREFIX)) {\n // Keep leading space after \"data:\" if present per spec\n const line = rawLine.slice(SSE_DATA_PREFIX.length).replace(/^\\s/, \"\");\n dataLines.push(line);\n }\n }\n\n if (dataLines.length) {\n const data = dataLines.join(\"\\n\");\n yield { type: \"data\", data };\n } else if (comment !== null) {\n yield { type: \"comment\", comment };\n }\n }\n }\n } finally {\n try {\n await reader.cancel();\n } catch {\n // ignore error\n }\n abortController.abort();\n }\n } finally {\n cleanUpSignals();\n }\n}\n","import type { ReplicationStreamRecord, StartReplicationStreamBody } from \"./types\";\nimport type { ReplaneFinalOptions } from \"./client-types\";\nimport { fetchSse } from \"./sse\";\nimport { combineAbortSignals, retryDelay } from \"./utils\";\n\nconst SUPPORTED_REPLICATION_STREAM_RECORD_TYPES = Object.keys({\n config_change: true,\n init: true,\n} satisfies Record<ReplicationStreamRecord[\"type\"], true>);\n\n/**\n * Options for starting a replication stream\n */\nexport interface StartReplicationStreamOptions extends ReplaneFinalOptions {\n // getBody is a function to get the latest configs when we are trying\n // to reestablish the replication stream\n getBody: () => StartReplicationStreamBody;\n signal?: AbortSignal;\n onConnect?: () => void;\n}\n\n/**\n * Interface for storage implementations\n */\nexport interface ReplaneStorage {\n startReplicationStream(\n options: StartReplicationStreamOptions\n ): AsyncIterable<ReplicationStreamRecord>;\n close(): void;\n}\n\n/**\n * Remote storage implementation that connects to the Replane server\n * and streams config updates via SSE.\n */\nexport class ReplaneRemoteStorage implements ReplaneStorage {\n private closeController = new AbortController();\n\n /**\n * Start a replication stream that yields config updates.\n * This method never throws - it retries on failure with exponential backoff.\n */\n async *startReplicationStream(\n options: StartReplicationStreamOptions\n ): AsyncIterable<ReplicationStreamRecord> {\n const { signal, cleanUpSignals } = combineAbortSignals([\n this.closeController.signal,\n options.signal,\n ]);\n try {\n let failedAttempts = 0;\n while (!signal.aborted) {\n try {\n for await (const event of this.startReplicationStreamImpl({\n ...options,\n signal,\n onConnect: () => {\n failedAttempts = 0;\n },\n })) {\n yield event;\n }\n } catch (error: unknown) {\n failedAttempts++;\n const retryDelayMs = Math.min(options.retryDelayMs * 2 ** (failedAttempts - 1), 10_000);\n if (!signal.aborted) {\n options.logger.error(\n `Failed to fetch project events, retrying in ${retryDelayMs}ms...`,\n error\n );\n\n await retryDelay(retryDelayMs);\n }\n }\n }\n } finally {\n cleanUpSignals();\n }\n }\n\n private async *startReplicationStreamImpl(\n options: StartReplicationStreamOptions\n ): AsyncIterable<ReplicationStreamRecord> {\n // Create an abort controller for inactivity timeout\n const inactivityAbortController = new AbortController();\n const { signal: combinedSignal, cleanUpSignals } = options.signal\n ? combineAbortSignals([options.signal, inactivityAbortController.signal])\n : { signal: inactivityAbortController.signal, cleanUpSignals: () => {} };\n\n let inactivityTimer: ReturnType<typeof setTimeout> | null = null;\n\n const resetInactivityTimer = () => {\n if (inactivityTimer) clearTimeout(inactivityTimer);\n inactivityTimer = setTimeout(() => {\n inactivityAbortController.abort();\n }, options.inactivityTimeoutMs);\n };\n\n try {\n const rawEvents = fetchSse({\n fetchFn: options.fetchFn,\n headers: {\n Authorization: this.getAuthHeader(options),\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(options.getBody()),\n timeoutMs: options.requestTimeoutMs,\n method: \"POST\",\n signal: combinedSignal,\n url: this.getApiEndpoint(`/sdk/v1/replication/stream`, options),\n onConnect: () => {\n resetInactivityTimer();\n options.onConnect?.();\n },\n });\n\n for await (const sseEvent of rawEvents) {\n resetInactivityTimer();\n\n if (sseEvent.type === \"comment\") continue;\n\n const event = JSON.parse(sseEvent.data);\n if (\n typeof event === \"object\" &&\n event !== null &&\n \"type\" in event &&\n typeof event.type === \"string\" &&\n (SUPPORTED_REPLICATION_STREAM_RECORD_TYPES as unknown as string[]).includes(event.type)\n ) {\n yield event as ReplicationStreamRecord;\n }\n }\n } finally {\n if (inactivityTimer) clearTimeout(inactivityTimer);\n cleanUpSignals();\n }\n }\n\n /**\n * Close the storage and abort any active connections\n */\n close(): void {\n this.closeController.abort();\n }\n\n private getAuthHeader(options: ReplaneFinalOptions): string {\n return `Bearer ${options.sdkKey}`;\n }\n\n private getApiEndpoint(path: string, options: ReplaneFinalOptions): string {\n return `${options.baseUrl}/api${path}`;\n }\n}\n","/**\n * FNV-1a 32-bit hash function\n *\n * FNV (Fowler–Noll–Vo) is a non-cryptographic hash function known for its\n * speed and good distribution. This implementation uses the FNV-1a variant\n * which XORs before multiplying for better avalanche characteristics.\n *\n * @param input - The string to hash\n * @returns A 32-bit unsigned integer hash value\n */\nexport function fnv1a32(input: string): number {\n // Convert string to bytes (UTF-8)\n const encoder = new TextEncoder();\n const bytes = encoder.encode(input);\n\n // FNV-1a core\n let hash = 0x811c9dc5 >>> 0; // 2166136261, force uint32\n\n for (let i = 0; i < bytes.length; i++) {\n hash ^= bytes[i]; // XOR with byte\n hash = Math.imul(hash, 0x01000193) >>> 0; // * 16777619 mod 2^32\n }\n\n return hash >>> 0; // ensure unsigned 32-bit\n}\n\n/**\n * Convert FNV-1a hash to [0, 1) for bucketing.\n *\n * This is useful for percentage-based segmentation where you need\n * to deterministically assign a value to a bucket based on a string input.\n *\n * @param input - The string to hash\n * @returns A number in the range [0, 1)\n */\nexport function fnv1a32ToUnit(input: string): number {\n const h = fnv1a32(input);\n return h / 2 ** 32; // double in [0, 1)\n}\n","import type { RenderedCondition, RenderedOverride } from \"./types\";\nimport type { ReplaneContext, ReplaneLogger } from \"./client-types\";\nimport { fnv1a32ToUnit } from \"./hash\";\n\n/**\n * Result of evaluating a condition\n */\nexport type EvaluationResult = \"matched\" | \"not_matched\" | \"unknown\";\n\n/**\n * Evaluate config overrides based on context.\n * Returns the first matching override's value, or the base value if no override matches.\n *\n * @param baseValue - The default value to return if no override matches\n * @param overrides - Array of overrides to evaluate\n * @param context - The context to evaluate conditions against\n * @param logger - Logger for warnings\n * @returns The evaluated value\n */\nexport function evaluateOverrides<T>(\n baseValue: T,\n overrides: RenderedOverride[],\n context: ReplaneContext,\n logger: ReplaneLogger\n): T {\n // Find first matching override\n for (const override of overrides) {\n // All conditions must match (implicit AND)\n let overrideResult: EvaluationResult = \"matched\";\n const results = override.conditions.map((c) => evaluateCondition(c, context, logger));\n // AND: false > unknown > true\n if (results.some((r) => r === \"not_matched\")) {\n overrideResult = \"not_matched\";\n } else if (results.some((r) => r === \"unknown\")) {\n overrideResult = \"unknown\";\n }\n\n // Only use override if all conditions matched (not unknown)\n if (overrideResult === \"matched\") {\n return override.value as T;\n }\n }\n\n return baseValue;\n}\n\n/**\n * Evaluate a single condition against a context.\n *\n * @param condition - The condition to evaluate\n * @param context - The context to evaluate against\n * @param logger - Logger for warnings\n * @returns The evaluation result\n */\nexport function evaluateCondition(\n condition: RenderedCondition,\n context: ReplaneContext,\n logger: ReplaneLogger\n): EvaluationResult {\n const operator = condition.operator;\n\n // Composite conditions\n if (operator === \"and\") {\n const results = condition.conditions.map((c) => evaluateCondition(c, context, logger));\n // AND: false > unknown > true\n if (results.some((r) => r === \"not_matched\")) return \"not_matched\";\n if (results.some((r) => r === \"unknown\")) return \"unknown\";\n return \"matched\";\n }\n\n if (operator === \"or\") {\n const results = condition.conditions.map((c) => evaluateCondition(c, context, logger));\n // OR: true > unknown > false\n if (results.some((r) => r === \"matched\")) return \"matched\";\n if (results.some((r) => r === \"unknown\")) return \"unknown\";\n return \"not_matched\";\n }\n\n if (operator === \"not\") {\n const result = evaluateCondition(condition.condition, context, logger);\n if (result === \"matched\") return \"not_matched\";\n if (result === \"not_matched\") return \"matched\";\n return \"unknown\"; // NOT unknown = unknown\n }\n\n // Segmentation\n if (operator === \"segmentation\") {\n const contextValue = context[condition.property];\n if (contextValue === undefined || contextValue === null) {\n return \"unknown\";\n }\n\n // FNV-1a hash to bucket [0, 100)\n const hashInput = String(contextValue) + condition.seed;\n const unitValue = fnv1a32ToUnit(hashInput);\n return unitValue >= condition.fromPercentage / 100 && unitValue < condition.toPercentage / 100\n ? \"matched\"\n : \"not_matched\";\n }\n\n // Property-based conditions\n const property = condition.property;\n const contextValue = context[property];\n const expectedValue = condition.value;\n\n if (contextValue === undefined) {\n return \"unknown\";\n }\n\n // Type casting\n const castedValue = castToContextType(expectedValue, contextValue);\n\n switch (operator) {\n case \"equals\":\n return contextValue === castedValue ? \"matched\" : \"not_matched\";\n\n case \"in\":\n if (!Array.isArray(castedValue)) return \"unknown\";\n return castedValue.includes(contextValue) ? \"matched\" : \"not_matched\";\n\n case \"not_in\":\n if (!Array.isArray(castedValue)) return \"unknown\";\n return !castedValue.includes(contextValue) ? \"matched\" : \"not_matched\";\n\n case \"less_than\":\n if (typeof contextValue === \"number\" && typeof castedValue === \"number\") {\n return contextValue < castedValue ? \"matched\" : \"not_matched\";\n }\n if (typeof contextValue === \"string\" && typeof castedValue === \"string\") {\n return contextValue < castedValue ? \"matched\" : \"not_matched\";\n }\n return \"not_matched\";\n\n case \"less_than_or_equal\":\n if (typeof contextValue === \"number\" && typeof castedValue === \"number\") {\n return contextValue <= castedValue ? \"matched\" : \"not_matched\";\n }\n if (typeof contextValue === \"string\" && typeof castedValue === \"string\") {\n return contextValue <= castedValue ? \"matched\" : \"not_matched\";\n }\n return \"not_matched\";\n\n case \"greater_than\":\n if (typeof contextValue === \"number\" && typeof castedValue === \"number\") {\n return contextValue > castedValue ? \"matched\" : \"not_matched\";\n }\n if (typeof contextValue === \"string\" && typeof castedValue === \"string\") {\n return contextValue > castedValue ? \"matched\" : \"not_matched\";\n }\n return \"not_matched\";\n\n case \"greater_than_or_equal\":\n if (typeof contextValue === \"number\" && typeof castedValue === \"number\") {\n return contextValue >= castedValue ? \"matched\" : \"not_matched\";\n }\n if (typeof contextValue === \"string\" && typeof castedValue === \"string\") {\n return contextValue >= castedValue ? \"matched\" : \"not_matched\";\n }\n return \"not_matched\";\n\n default:\n warnNever(operator, logger, `Unexpected operator: ${operator}`);\n return \"unknown\";\n }\n}\n\n/**\n * Helper to warn about exhaustive check failures\n */\nfunction warnNever(value: never, logger: ReplaneLogger, message: string): void {\n logger.warn(message, { value });\n}\n\n/**\n * Cast expected value to match context value type.\n * This enables loose matching between different types (e.g., \"25\" matches 25).\n *\n * @param expectedValue - The value from the condition\n * @param contextValue - The value from the context\n * @returns The expected value cast to match the context value's type\n */\nexport function castToContextType(expectedValue: unknown, contextValue: unknown): unknown {\n if (typeof contextValue === \"number\") {\n if (typeof expectedValue === \"string\") {\n const num = Number(expectedValue);\n return isNaN(num) ? expectedValue : num;\n }\n return expectedValue;\n }\n\n if (typeof contextValue === \"boolean\") {\n if (typeof expectedValue === \"string\") {\n if (expectedValue === \"true\") return true;\n if (expectedValue === \"false\") return false;\n }\n if (typeof expectedValue === \"number\") {\n return expectedValue !== 0;\n }\n return expectedValue;\n }\n\n if (typeof contextValue === \"string\") {\n if (typeof expectedValue === \"number\" || typeof expectedValue === \"boolean\") {\n return String(expectedValue);\n }\n return expectedValue;\n }\n\n return expectedValue;\n}\n","import type { ConfigDto } from \"./types\";\nimport type {\n ReplaneContext,\n ReplaneLogger,\n GetConfigOptions,\n MapConfig,\n ReplaneSnapshot,\n ReplaneClient,\n ReplaneClientOptions,\n RestoreReplaneClientOptions,\n ReplaneFinalOptions,\n} from \"./client-types\";\nimport type { ReplaneStorage } from \"./storage\";\nimport { ReplaneRemoteStorage } from \"./storage\";\nimport { ReplaneError, ReplaneErrorCode } from \"./error\";\nimport { evaluateOverrides } from \"./evaluation\";\nimport { Deferred } from \"./utils\";\n\n/**\n * Internal options for creating the client core\n */\ninterface ClientCoreOptions {\n initialConfigs: ConfigDto[];\n context: ReplaneContext;\n logger: ReplaneLogger;\n storage: ReplaneStorage | null;\n streamOptions: ReplaneFinalOptions | null;\n requiredConfigs: string[];\n}\n\n/**\n * Result from creating the client core\n */\ninterface ClientCoreResult<T extends object> {\n client: ReplaneClient<T>;\n configs: Map<string, ConfigDto>;\n startStreaming: () => Promise<void>;\n clientReady: Deferred<void>;\n}\n\n/**\n * Creates the core client logic shared between createReplaneClient and restoreReplaneClient\n */\nfunction createClientCore<T extends object = Record<string, unknown>>(\n options: ClientCoreOptions\n): ClientCoreResult<T> {\n const { initialConfigs, context, logger, storage, streamOptions, requiredConfigs } = options;\n\n const configs: Map<string, ConfigDto> = new Map(\n initialConfigs.map((config) => [config.name, config])\n );\n\n const clientReady = new Deferred<void>();\n const configSubscriptions = new Map<keyof T, Set<(config: MapConfig<T>) => void>>();\n const clientSubscriptions = new Set<(config: MapConfig<T>) => void>();\n\n function processConfigUpdates(updatedConfigs: ConfigDto[]) {\n for (const config of updatedConfigs) {\n configs.set(config.name, {\n name: config.name,\n overrides: config.overrides,\n value: config.value,\n });\n for (const callback of clientSubscriptions) {\n callback({ name: config.name as keyof T, value: config.value as T[keyof T] });\n }\n for (const callback of configSubscriptions.get(config.name as keyof T) ?? []) {\n callback({ name: config.name as keyof T, value: config.value as T[keyof T] });\n }\n }\n }\n\n async function startStreaming(): Promise<void> {\n if (!storage || !streamOptions) return;\n\n try {\n const replicationStream = storage.startReplicationStream({\n ...streamOptions,\n getBody: () => ({\n currentConfigs: [...configs.values()].map((config) => ({\n name: config.name,\n overrides: config.overrides,\n value: config.value,\n })),\n requiredConfigs,\n }),\n });\n\n for await (const event of replicationStream) {\n const updatedConfigs: ConfigDto[] =\n event.type === \"config_change\" ? [event.config] : event.configs;\n processConfigUpdates(updatedConfigs);\n clientReady.resolve();\n }\n } catch (error) {\n logger.error(\"Replane: error in SSE connection:\", error);\n clientReady.reject(error);\n throw error;\n }\n }\n\n function get<K extends keyof T>(configName: K, getConfigOptions: GetConfigOptions = {}): T[K] {\n const config = configs.get(String(configName));\n\n if (config === undefined) {\n throw new ReplaneError({\n message: `Config not found: ${String(configName)}`,\n code: ReplaneErrorCode.NotFound,\n });\n }\n\n try {\n return evaluateOverrides<T[K]>(\n config.value as T[K],\n config.overrides,\n { ...context, ...(getConfigOptions?.context ?? {}) },\n logger\n );\n } catch (error) {\n logger.error(`Replane: error evaluating overrides for config ${String(configName)}:`, error);\n return config.value as T[K];\n }\n }\n\n const subscribe = (\n callbackOrConfigName: keyof T | ((config: MapConfig<T>) => void),\n callbackOrUndefined?: (config: MapConfig<T>) => void\n ) => {\n let configName: keyof T | undefined = undefined;\n let callback: (config: MapConfig<T>) => void;\n if (typeof callbackOrConfigName === \"function\") {\n callback = callbackOrConfigName;\n } else {\n configName = callbackOrConfigName as keyof T;\n if (callbackOrUndefined === undefined) {\n throw new Error(\"callback is required when config name is provided\");\n }\n callback = callbackOrUndefined!;\n }\n\n // Wrap the callback to ensure that we have a unique reference\n const originalCallback = callback;\n callback = (...args: Parameters<typeof callback>) => {\n originalCallback(...args);\n };\n\n if (configName === undefined) {\n clientSubscriptions.add(callback);\n return () => {\n clientSubscriptions.delete(callback);\n };\n }\n\n if (!configSubscriptions.has(configName)) {\n configSubscriptions.set(configName, new Set());\n }\n configSubscriptions.get(configName)!.add(callback);\n return () => {\n configSubscriptions.get(configName)?.delete(callback);\n if (configSubscriptions.get(configName)?.size === 0) {\n configSubscriptions.delete(configName);\n }\n };\n };\n\n const getSnapshot = (): ReplaneSnapshot<T> => ({\n configs: [...configs.values()].map((config) => ({\n name: config.name,\n value: config.value,\n overrides: config.overrides.map((override) => ({\n name: override.name,\n conditions: override.conditions,\n value: override.value,\n })),\n })),\n context,\n });\n\n const close = () => storage?.close();\n\n const client: ReplaneClient<T> = {\n get,\n subscribe: subscribe as ReplaneClient<T>[\"subscribe\"],\n getSnapshot,\n close,\n };\n\n return { client, configs, startStreaming, clientReady };\n}\n\n/**\n * Create a Replane client bound to an SDK key.\n *\n * @example\n * ```typescript\n * const client = await createReplaneClient({\n * sdkKey: 'your-sdk-key',\n * baseUrl: 'https://app.replane.dev'\n * });\n * const value = client.get('my-config');\n * ```\n */\nexport async function createReplaneClient<T extends object = Record<string, unknown>>(\n sdkOptions: ReplaneClientOptions<T>\n): Promise<ReplaneClient<T>> {\n const storage = new ReplaneRemoteStorage();\n return await createReplaneClientInternal(toFinalOptions(sdkOptions), storage);\n}\n\n/**\n * Create a Replane client that uses in-memory storage.\n * Useful for testing or when you have static config values.\n *\n * @example\n * ```typescript\n * const client = createInMemoryReplaneClient({ 'my-config': 123 });\n * const value = client.get('my-config'); // 123\n * ```\n */\nexport function createInMemoryReplaneClient<T extends object = Record<string, unknown>>(\n initialData: T\n): ReplaneClient<T> {\n return {\n get: (configName) => {\n const config = initialData[configName];\n if (config === undefined) {\n throw new ReplaneError({\n message: `Config not found: ${String(configName)}`,\n code: ReplaneErrorCode.NotFound,\n });\n }\n return config;\n },\n subscribe: () => {\n return () => {};\n },\n getSnapshot: () => ({\n configs: Object.entries(initialData).map(([name, value]) => ({\n name,\n value,\n overrides: [],\n })),\n }),\n close: () => {},\n };\n}\n\n/**\n * Restore a Replane client from a snapshot.\n * This is useful for SSR/hydration scenarios where the server has already fetched configs.\n *\n * @example\n * ```typescript\n * // On the server:\n * const serverClient = await createReplaneClient({ ... });\n * const snapshot = serverClient.getSnapshot();\n * // Pass snapshot to client via props/serialization\n *\n * // On the client:\n * const client = restoreReplaneClient({\n * snapshot,\n * connection: { sdkKey, baseUrl }\n * });\n * const value = client.get('my-config');\n * ```\n */\nexport function restoreReplaneClient<T extends object = Record<string, unknown>>(\n options: RestoreReplaneClientOptions<T>\n): ReplaneClient<T> {\n const { snapshot, connection } = options;\n const context = options.context ?? snapshot.context ?? {};\n const logger = connection?.logger ?? console;\n\n // Initialize configs from snapshot\n const initialConfigs: ConfigDto[] = snapshot.configs.map((config) => ({\n name: config.name,\n value: config.value,\n overrides: config.overrides,\n }));\n\n let storage: ReplaneRemoteStorage | null = null;\n let streamOptions: ReplaneFinalOptions | null = null;\n\n if (connection) {\n storage = new ReplaneRemoteStorage();\n streamOptions = {\n sdkKey: connection.sdkKey,\n baseUrl: connection.baseUrl.replace(/\\/+$/, \"\"),\n fetchFn: connection.fetchFn ?? globalThis.fetch.bind(globalThis),\n requestTimeoutMs: connection.requestTimeoutMs ?? 2000,\n initializationTimeoutMs: 5000, // Not used for restore\n inactivityTimeoutMs: connection.inactivityTimeoutMs ?? 30_000,\n logger,\n retryDelayMs: connection.retryDelayMs ?? 200,\n context,\n requiredConfigs: [],\n fallbacks: [],\n };\n }\n\n const { client, startStreaming } = createClientCore<T>({\n initialConfigs,\n context,\n logger,\n storage,\n streamOptions,\n requiredConfigs: [],\n });\n\n // Start streaming in background (non-blocking) if connection is provided\n if (storage && streamOptions) {\n startStreaming().catch((error) => {\n logger.error(\"Replane: error in restored client SSE connection:\", error);\n });\n }\n\n return client;\n}\n\n/**\n * Internal function to create a Replane client with the given options and storage\n */\nasync function createReplaneClientInternal<T extends object = Record<string, unknown>>(\n sdkOptions: ReplaneFinalOptions,\n storage: ReplaneStorage\n): Promise<ReplaneClient<T>> {\n if (!sdkOptions.sdkKey) throw new Error(\"SDK key is required\");\n\n const { client, configs, startStreaming, clientReady } = createClientCore<T>({\n initialConfigs: sdkOptions.fallbacks,\n context: sdkOptions.context,\n logger: sdkOptions.logger,\n storage,\n streamOptions: sdkOptions,\n requiredConfigs: sdkOptions.requiredConfigs,\n });\n\n // Start streaming in background\n startStreaming().catch((error) => {\n sdkOptions.logger.error(\"Replane: error initializing client:\", error);\n });\n\n const initializationTimeoutId = setTimeout(() => {\n if (sdkOptions.fallbacks.length === 0) {\n // no fallbacks, we have nothing to work with\n client.close();\n\n clientReady.reject(\n new ReplaneError({\n message: \"Replane client initialization timed out\",\n code: ReplaneErrorCode.Timeout,\n })\n );\n\n return;\n }\n\n const missingRequiredConfigs: string[] = [];\n for (const requiredConfigName of sdkOptions.requiredConfigs) {\n if (!configs.has(requiredConfigName)) {\n missingRequiredConfigs.push(requiredConfigName);\n }\n }\n\n if (missingRequiredConfigs.length > 0) {\n client.close();\n clientReady.reject(\n new ReplaneError({\n message: `Required configs are missing: ${missingRequiredConfigs.join(\", \")}`,\n code: ReplaneErrorCode.NotFound,\n })\n );\n\n return;\n }\n\n clientReady.resolve();\n }, sdkOptions.initializationTimeoutMs);\n\n clientReady.promise.then(() => clearTimeout(initializationTimeoutId));\n\n await clientReady.promise;\n\n return client;\n}\n\n/**\n * Convert user options to final options with defaults\n */\nfunction toFinalOptions<T extends object>(defaults: ReplaneClientOptions<T>): ReplaneFinalOptions {\n return {\n sdkKey: defaults.sdkKey,\n baseUrl: defaults.baseUrl.replace(/\\/+$/, \"\"),\n fetchFn:\n defaults.fetchFn ??\n // some browsers require binding the fetch function to window\n globalThis.fetch.bind(globalThis),\n requestTimeoutMs: defaults.requestTimeoutMs ?? 2000,\n initializationTimeoutMs: defaults.initializationTimeoutMs ?? 5000,\n inactivityTimeoutMs: defaults.inactivityTimeoutMs ?? 30_000,\n logger: defaults.logger ?? console,\n retryDelayMs: defaults.retryDelayMs ?? 200,\n context: {\n ...(defaults.context ?? {}),\n },\n requiredConfigs: Array.isArray(defaults.required)\n ? defaults.required.map((name) => String(name))\n : Object.entries(defaults.required ?? {})\n .filter(([_, value]) => value !== undefined)\n .map(([name]) => name),\n fallbacks: Object.entries(defaults.fallbacks ?? {})\n .filter(([_, value]) => value !== undefined)\n .map(([name, value]) => ({\n name,\n overrides: [],\n version: -1,\n value,\n })),\n };\n}\n"],"mappings":";;;;AAGA,IAAY,gEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD;;;;AAKD,IAAa,eAAb,cAAkC,MAAM;CACtC;CAEA,YAAYA,QAA4D;AACtE,QAAM,OAAO,SAAS,EAAE,OAAO,OAAO,MAAO,EAAC;AAC9C,OAAK,OAAO;AACZ,OAAK,OAAO,OAAO;CACpB;AACF;;;;;;;;;ACtBD,eAAsB,MAAMC,IAA2B;AACrD,QAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;AACxD;;;;;;;AAQD,eAAsB,WAAWC,cAAqC;CACpE,MAAM,SAAS,eAAe;CAC9B,MAAM,UAAU,eAAe,KAAK,QAAQ,GAAG,SAAS,SAAS;AAEjE,OAAM,MAAM,QAAQ;AACrB;;;;;;;;AASD,SAAgB,oBAAoBC,SAGlC;CACA,MAAM,aAAa,IAAI;CACvB,MAAM,UAAU,MAAM;AACpB,aAAW,OAAO;AAClB,kBAAgB;CACjB;CAED,MAAM,iBAAiB,MAAM;AAC3B,OAAK,MAAM,KAAK,QACd,IAAG,oBAAoB,SAAS,QAAQ;CAE3C;AAED,MAAK,MAAM,KAAK,QACd,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