@replanejs/sdk 0.7.3 → 0.7.5

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.cjs CHANGED
@@ -20,18 +20,23 @@ var src_exports = {};
20
20
  __export(src_exports, {
21
21
  ReplaneError: () => import_error.ReplaneError,
22
22
  ReplaneErrorCode: () => import_error.ReplaneErrorCode,
23
+ clearSnapshotCache: () => import_snapshot.clearSnapshotCache,
23
24
  createInMemoryReplaneClient: () => import_client.createInMemoryReplaneClient,
24
25
  createReplaneClient: () => import_client.createReplaneClient,
26
+ getReplaneSnapshot: () => import_snapshot.getReplaneSnapshot,
25
27
  restoreReplaneClient: () => import_client.restoreReplaneClient
26
28
  });
27
29
  module.exports = __toCommonJS(src_exports);
28
30
  var import_client = require("./client");
29
31
  var import_error = require("./error");
32
+ var import_snapshot = require("./snapshot");
30
33
  // Annotate the CommonJS export names for ESM import in node:
31
34
  0 && (module.exports = {
32
35
  ReplaneError,
33
36
  ReplaneErrorCode,
37
+ clearSnapshotCache,
34
38
  createInMemoryReplaneClient,
35
39
  createReplaneClient,
40
+ getReplaneSnapshot,
36
41
  restoreReplaneClient
37
42
  });
@@ -0,0 +1,354 @@
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
34
+ //#region src/client-types.d.ts
35
+ /**
36
+ * Context object for override evaluation.
37
+ * Keys are property names, values can be strings, numbers, booleans, null, or undefined.
38
+ */
39
+ type ReplaneContext = Record<string, string | number | boolean | null | undefined>;
40
+ /**
41
+ * Logger interface for SDK logging
42
+ */
43
+ interface ReplaneLogger {
44
+ debug(...args: unknown[]): void;
45
+ info(...args: unknown[]): void;
46
+ warn(...args: unknown[]): void;
47
+ error(...args: unknown[]): void;
48
+ }
49
+ /**
50
+ * Options for getting a config value
51
+ */
52
+ interface GetConfigOptions {
53
+ /**
54
+ * Context for override evaluation (merged with client-level context).
55
+ */
56
+ context?: ReplaneContext;
57
+ }
58
+ /**
59
+ * Helper type for mapping configs to their names and values
60
+ */
61
+ type MapConfig<T extends object> = { [K in keyof T]: {
62
+ name: K;
63
+ value: T[K];
64
+ } }[keyof T];
65
+ /**
66
+ * Serializable snapshot of the client state.
67
+ * Can be used to restore a client on the client-side from server-fetched configs.
68
+ */
69
+ interface ReplaneSnapshot<_T extends object = object> {
70
+ /** Serialized config data */
71
+ configs: Array<{
72
+ name: string;
73
+ value: unknown;
74
+ overrides: RenderedOverride[];
75
+ }>;
76
+ /** Default context used for override evaluation */
77
+ context?: ReplaneContext;
78
+ }
79
+ /**
80
+ * The Replane client interface
81
+ */
82
+ interface ReplaneClient<T extends object> {
83
+ /** Get a config by its name. */
84
+ get<K extends keyof T>(configName: K, options?: GetConfigOptions): T[K];
85
+ /** Subscribe to config changes.
86
+ * @param callback - A function to call when an config is changed. The callback will be called with the new config value.
87
+ * @returns A function to unsubscribe from the config changes.
88
+ */
89
+ subscribe(callback: (config: MapConfig<T>) => void): () => void;
90
+ /** Subscribe to a specific config change.
91
+ * @param configName - The name of the config to subscribe to.
92
+ * @param callback - A function to call when the config is changed. The callback will be called with the new config value.
93
+ * @returns A function to unsubscribe from the config changes.
94
+ */
95
+ subscribe<K extends keyof T>(configName: K, callback: (config: MapConfig<Pick<T, K>>) => void): () => void;
96
+ /**
97
+ * Get a serializable snapshot of the current client state.
98
+ * Useful for SSR/hydration scenarios where you want to pass configs from server to client.
99
+ */
100
+ getSnapshot(): ReplaneSnapshot<T>;
101
+ /** Close the client and clean up resources. */
102
+ close(): void;
103
+ }
104
+ /**
105
+ * Options for creating a Replane client
106
+ */
107
+ interface ReplaneClientOptions<T extends object> {
108
+ /**
109
+ * Base URL of the Replane instance (no trailing slash).
110
+ * @example
111
+ * "https://app.replane.dev"
112
+ *
113
+ * @example
114
+ * "https://replane.yourdomain.com"
115
+ */
116
+ baseUrl: string;
117
+ /**
118
+ * Project SDK key for authorization.
119
+ * @example
120
+ * "rp_XXXXXXXXX"
121
+ */
122
+ sdkKey: string;
123
+ /**
124
+ * Custom fetch implementation (useful for tests / polyfills).
125
+ */
126
+ fetchFn?: typeof fetch;
127
+ /**
128
+ * Optional timeout in ms for the request.
129
+ * @default 2000
130
+ */
131
+ requestTimeoutMs?: number;
132
+ /**
133
+ * Optional timeout in ms for the SDK initialization.
134
+ * @default 5000
135
+ */
136
+ initializationTimeoutMs?: number;
137
+ /**
138
+ * Delay between retries in ms.
139
+ * @default 200
140
+ */
141
+ retryDelayMs?: number;
142
+ /**
143
+ * Timeout in ms for SSE connection inactivity.
144
+ * If no events (including pings) are received within this time, the connection will be re-established.
145
+ * @default 30000
146
+ */
147
+ inactivityTimeoutMs?: number;
148
+ /**
149
+ * Optional logger (defaults to console).
150
+ */
151
+ logger?: ReplaneLogger;
152
+ /**
153
+ * Default context for all config evaluations.
154
+ * Can be overridden per-request in `client.get()`.
155
+ */
156
+ context?: ReplaneContext;
157
+ /**
158
+ * Required configs for the client.
159
+ * If a config is not present, the client will throw an error during initialization.
160
+ * @example
161
+ * {
162
+ * required: {
163
+ * config1: true,
164
+ * config2: true,
165
+ * config3: false,
166
+ * },
167
+ * }
168
+ *
169
+ * @example
170
+ * {
171
+ * required: ["config1", "config2", "config3"],
172
+ * }
173
+ */
174
+ required?: { [K in keyof T]: boolean } | Array<keyof T>;
175
+ /**
176
+ * Fallback values to use if the initial request to fetch configs fails.
177
+ * When provided, all configs must be specified.
178
+ * @example
179
+ * {
180
+ * fallbacks: {
181
+ * config1: "value1",
182
+ * config2: 42,
183
+ * },
184
+ * }
185
+ */
186
+ fallbacks?: { [K in keyof T]: T[K] };
187
+ }
188
+ /**
189
+ * Options for restoring a Replane client from a snapshot
190
+ */
191
+ interface RestoreReplaneClientOptions<T extends object> {
192
+ /**
193
+ * Snapshot from a server-side client's getSnapshot() call.
194
+ */
195
+ snapshot: ReplaneSnapshot<T>;
196
+ /**
197
+ * Optional connection options for live updates.
198
+ * If provided, the client will connect to the Replane server for real-time config updates.
199
+ * If not provided, the client will only use the snapshot data (no live updates).
200
+ */
201
+ connection?: {
202
+ /**
203
+ * Base URL of the Replane instance (no trailing slash).
204
+ */
205
+ baseUrl: string;
206
+ /**
207
+ * Project SDK key for authorization.
208
+ */
209
+ sdkKey: string;
210
+ /**
211
+ * Custom fetch implementation (useful for tests / polyfills).
212
+ */
213
+ fetchFn?: typeof fetch;
214
+ /**
215
+ * Optional timeout in ms for the request.
216
+ * @default 2000
217
+ */
218
+ requestTimeoutMs?: number;
219
+ /**
220
+ * Delay between retries in ms.
221
+ * @default 200
222
+ */
223
+ retryDelayMs?: number;
224
+ /**
225
+ * Timeout in ms for SSE connection inactivity.
226
+ * @default 30000
227
+ */
228
+ inactivityTimeoutMs?: number;
229
+ /**
230
+ * Optional logger (defaults to console).
231
+ */
232
+ logger?: ReplaneLogger;
233
+ };
234
+ /**
235
+ * Override the context from the snapshot.
236
+ */
237
+ context?: ReplaneContext;
238
+ }
239
+ /**
240
+ * Internal options after processing user options
241
+ */
242
+ //#endregion
243
+ //#region src/client.d.ts
244
+ /**
245
+ * Create a Replane client bound to an SDK key.
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * const client = await createReplaneClient({
250
+ * sdkKey: 'your-sdk-key',
251
+ * baseUrl: 'https://app.replane.dev'
252
+ * });
253
+ * const value = client.get('my-config');
254
+ * ```
255
+ */
256
+ declare function createReplaneClient<T extends object = Record<string, unknown>>(sdkOptions: ReplaneClientOptions<T>): Promise<ReplaneClient<T>>;
257
+ /**
258
+ * Create a Replane client that uses in-memory storage.
259
+ * Useful for testing or when you have static config values.
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * const client = createInMemoryReplaneClient({ 'my-config': 123 });
264
+ * const value = client.get('my-config'); // 123
265
+ * ```
266
+ */
267
+ declare function createInMemoryReplaneClient<T extends object = Record<string, unknown>>(initialData: T): ReplaneClient<T>;
268
+ /**
269
+ * Restore a Replane client from a snapshot.
270
+ * This is useful for SSR/hydration scenarios where the server has already fetched configs.
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * // On the server:
275
+ * const serverClient = await createReplaneClient({ ... });
276
+ * const snapshot = serverClient.getSnapshot();
277
+ * // Pass snapshot to client via props/serialization
278
+ *
279
+ * // On the client:
280
+ * const client = restoreReplaneClient({
281
+ * snapshot,
282
+ * connection: { sdkKey, baseUrl }
283
+ * });
284
+ * const value = client.get('my-config');
285
+ * ```
286
+ */
287
+ declare function restoreReplaneClient<T extends object = Record<string, unknown>>(options: RestoreReplaneClientOptions<T>): ReplaneClient<T>;
288
+ //# sourceMappingURL=client.d.ts.map
289
+ //#endregion
290
+ //#region src/error.d.ts
291
+ /**
292
+ * Error codes for ReplaneError
293
+ */
294
+ declare enum ReplaneErrorCode {
295
+ NotFound = "not_found",
296
+ Timeout = "timeout",
297
+ NetworkError = "network_error",
298
+ AuthError = "auth_error",
299
+ Forbidden = "forbidden",
300
+ ServerError = "server_error",
301
+ ClientError = "client_error",
302
+ Closed = "closed",
303
+ NotInitialized = "not_initialized",
304
+ Unknown = "unknown",
305
+ }
306
+ /**
307
+ * Custom error class for Replane SDK errors
308
+ */
309
+ declare class ReplaneError extends Error {
310
+ code: string;
311
+ constructor(params: {
312
+ message: string;
313
+ code: string;
314
+ cause?: unknown;
315
+ });
316
+ }
317
+ //# sourceMappingURL=error.d.ts.map
318
+ //#endregion
319
+ //#region src/snapshot.d.ts
320
+ /**
321
+ * Extended options for getReplaneSnapshot with caching support.
322
+ */
323
+ interface GetReplaneSnapshotOptions<T extends object> extends ReplaneClientOptions<T> {
324
+ /**
325
+ * Cache TTL in milliseconds. When set, the client is cached and reused
326
+ * for instant subsequent calls within this duration.
327
+ * @default 60_000 (1 minute)
328
+ */
329
+ cacheTtlMs?: number;
330
+ }
331
+ /**
332
+ * Creates a Replane client and returns a snapshot.
333
+ * Useful for SSR/SSG scenarios where you need to fetch config once
334
+ * and pass it to the client.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * const snapshot = await getReplaneSnapshot({
339
+ * baseUrl: process.env.REPLANE_BASE_URL!,
340
+ * sdkKey: process.env.REPLANE_SDK_KEY!,
341
+ * });
342
+ * ```
343
+ */
344
+ declare function getReplaneSnapshot<T extends object>(options: GetReplaneSnapshotOptions<T>): Promise<ReplaneSnapshot<T>>;
345
+ /**
346
+ * Clears the client cache used by getReplaneSnapshot.
347
+ * Useful for testing or when you need to force re-initialization.
348
+ */
349
+ declare function clearSnapshotCache(): Promise<void>;
350
+ //# sourceMappingURL=snapshot.d.ts.map
351
+
352
+ //#endregion
353
+ export { type GetConfigOptions, type GetReplaneSnapshotOptions, type ReplaneClient, type ReplaneClientOptions, type ReplaneContext, ReplaneError, ReplaneErrorCode, type ReplaneLogger, type ReplaneSnapshot, type RestoreReplaneClientOptions, clearSnapshotCache, createInMemoryReplaneClient, createReplaneClient, getReplaneSnapshot, restoreReplaneClient };
354
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/client-types.ts","../src/client.ts","../src/error.ts","../src/snapshot.ts"],"sourcesContent":[],"mappings":";;UAqBU,iBAAA;;ECfE,QAAA,EAAA,MAAA;EAKK,KAAA,EAAA,OAAA;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AA,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;;;;;ADbT;AAEqB;AAaI;AAarB,UIzCO,yBJ2CH,CAAA,UAAiB,MAAA,CAAA,SI3CsC,oBJ2CtC,CI3C2D,CJ2C3D,CAAA,CAAA;EAGrB;AAKV;;;;EAEyB,UACrB,CAAA,EAAA,MAAA;;;AAEY;AAEhB;;;;AC1DA;AAKA;AAUA;AAUA;;;;AAGW,iBGcW,kBHdX,CAAA,UAAA,MAAA,CAAA,CAAA,OAAA,EGeA,yBHfA,CGe0B,CHf1B,CAAA,CAAA,EGgBR,OHhBQ,CGgBA,eHhBA,CGgBgB,CHhBhB,CAAA,CAAA;;;AAEF;AAMT;AAAgC,iBGwCV,kBAAA,CAAA,CHxCU,EGwCY,OHxCZ,CAAA,IAAA,CAAA"}
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 Configs> = { [K in keyof T]: {
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 Configs = Configs> {
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: Array<{
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 Configs> {
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 Configs> {
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 Configs> {
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 Configs = Record<string, unknown>>(sdkOptions: ReplaneClientOptions<T>): Promise<ReplaneClient<T>>;
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 Configs = Record<string, unknown>>(initialData: T): ReplaneClient<T>;
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 Configs = Record<string, unknown>>(options: RestoreReplaneClientOptions<T>): ReplaneClient<T>;
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
@@ -290,7 +315,40 @@ declare class ReplaneError extends Error {
290
315
  });
291
316
  }
292
317
  //# sourceMappingURL=error.d.ts.map
318
+ //#endregion
319
+ //#region src/snapshot.d.ts
320
+ /**
321
+ * Extended options for getReplaneSnapshot with caching support.
322
+ */
323
+ interface GetReplaneSnapshotOptions<T extends object> extends ReplaneClientOptions<T> {
324
+ /**
325
+ * Cache TTL in milliseconds. When set, the client is cached and reused
326
+ * for instant subsequent calls within this duration.
327
+ * @default 60_000 (1 minute)
328
+ */
329
+ cacheTtlMs?: number;
330
+ }
331
+ /**
332
+ * Creates a Replane client and returns a snapshot.
333
+ * Useful for SSR/SSG scenarios where you need to fetch config once
334
+ * and pass it to the client.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * const snapshot = await getReplaneSnapshot({
339
+ * baseUrl: process.env.REPLANE_BASE_URL!,
340
+ * sdkKey: process.env.REPLANE_SDK_KEY!,
341
+ * });
342
+ * ```
343
+ */
344
+ declare function getReplaneSnapshot<T extends object>(options: GetReplaneSnapshotOptions<T>): Promise<ReplaneSnapshot<T>>;
345
+ /**
346
+ * Clears the client cache used by getReplaneSnapshot.
347
+ * Useful for testing or when you need to force re-initialization.
348
+ */
349
+ declare function clearSnapshotCache(): Promise<void>;
350
+ //# sourceMappingURL=snapshot.d.ts.map
293
351
 
294
352
  //#endregion
295
- export { type GetConfigOptions, type ReplaneClient, type ReplaneClientOptions, type ReplaneContext, ReplaneError, ReplaneErrorCode, type ReplaneLogger, type ReplaneSnapshot, type RestoreReplaneClientOptions, createInMemoryReplaneClient, createReplaneClient, restoreReplaneClient };
353
+ export { type GetConfigOptions, type GetReplaneSnapshotOptions, type ReplaneClient, type ReplaneClientOptions, type ReplaneContext, ReplaneError, ReplaneErrorCode, type ReplaneLogger, type ReplaneSnapshot, type RestoreReplaneClientOptions, clearSnapshotCache, createInMemoryReplaneClient, createReplaneClient, getReplaneSnapshot, restoreReplaneClient };
296
354
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,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,iBC2JzB,2BD3JyB,CAAA,UC2Ja,OD3Jb,GC2JuB,MD3JvB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,WAAA,EC4J1B,CD5J0B,CAAA,EC6JtC,aD7JsC,CC6JxB,CD7JwB,CAAA;;;;;;;;;;;;;;;;AAqBT;AAQhC;;;AAmBmB,iBC0JH,oBD1JG,CAAA,UC0J4B,OD1J5B,GC0JsC,MD1JtC,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,OAAA,EC2JR,2BD3JQ,CC2JoB,CD3JpB,CAAA,CAAA,EC4JhB,aD5JgB,CC4JF,CD5JE,CAAA;;;;;AA5GnB;AAMA;AAKiB,aEbL,gBAAA;EFuBK,QAAA,GAAA,WAAgB;EAUrB,OAAA,GAAA,SAAS;EAAA,YAAA,GAAA,eAAA;EAAA,SAAW,GAAA,YAAA;EAAO,SACzB,GAAA,WAAA;EAAC,WACL,GAAA,cAAA;EAAC,WACA,GAAA,cAAA;EAAC,MAAC,GAAA,QAAA;EAAC,cAEN,GAAA,iBAAA;EAAC,OAAA,GAAA,SAAA;AAMT;;;;AAKe,cEjCF,YAAA,SAAqB,KAAK,CFiCxB;EAAK,IAHT,EAAA,MAAA;EAAK,WAUJ,CAAA,MAAA,EAAA;IAAc,OAAA,EAAA,MAAA;IAMT,IAAA,EAAA,MAAa;IAAA,KAAA,CAAA,EAAA,OAAA;EAAA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/client-types.ts","../src/client.ts","../src/error.ts","../src/snapshot.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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,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;;;;;ADbT;AAEqB;AAaI;AAarB,UIzCO,yBJ2CH,CAAA,UAAiB,MAAA,CAAA,SI3CsC,oBJ2CtC,CI3C2D,CJ2C3D,CAAA,CAAA;EAGrB;AAKV;;;;EAEyB,UACrB,CAAA,EAAA,MAAA;;;AAEY;AAEhB;;;;AC1DA;AAKA;AAUA;AAUA;;;;AAGW,iBGcW,kBHdX,CAAA,UAAA,MAAA,CAAA,CAAA,OAAA,EGeA,yBHfA,CGe0B,CHf1B,CAAA,CAAA,EGgBR,OHhBQ,CGgBA,eHhBA,CGgBgB,CHhBhB,CAAA,CAAA;;;AAEF;AAMT;AAAgC,iBGwCV,kBAAA,CAAA,CHxCU,EGwCY,OHxCZ,CAAA,IAAA,CAAA"}
package/dist/index.js CHANGED
@@ -770,5 +770,61 @@ function toFinalOptions(defaults) {
770
770
  }
771
771
 
772
772
  //#endregion
773
- export { ReplaneError, ReplaneErrorCode, createInMemoryReplaneClient, createReplaneClient, restoreReplaneClient };
773
+ //#region src/snapshot.ts
774
+ const clientCache = new Map();
775
+ function getCacheKey(options) {
776
+ return `${options.baseUrl}:${options.sdkKey}`;
777
+ }
778
+ function setupCleanupTimeout(cacheKey, cacheTtlMs) {
779
+ return setTimeout(() => {
780
+ clientCache.delete(cacheKey);
781
+ }, cacheTtlMs);
782
+ }
783
+ /**
784
+ * Creates a Replane client and returns a snapshot.
785
+ * Useful for SSR/SSG scenarios where you need to fetch config once
786
+ * and pass it to the client.
787
+ *
788
+ * @example
789
+ * ```ts
790
+ * const snapshot = await getReplaneSnapshot({
791
+ * baseUrl: process.env.REPLANE_BASE_URL!,
792
+ * sdkKey: process.env.REPLANE_SDK_KEY!,
793
+ * });
794
+ * ```
795
+ */
796
+ async function getReplaneSnapshot(options) {
797
+ const { cacheTtlMs = 6e4,...clientOptions } = options;
798
+ const cacheKey = getCacheKey(clientOptions);
799
+ const cached = clientCache.get(cacheKey);
800
+ if (cached) {
801
+ clearTimeout(cached.timeoutId);
802
+ cached.timeoutId = setupCleanupTimeout(cacheKey, cacheTtlMs);
803
+ const client$1 = await cached.clientPromise;
804
+ return client$1.getSnapshot();
805
+ }
806
+ const clientPromise = createReplaneClient(clientOptions);
807
+ const entry = {
808
+ clientPromise,
809
+ timeoutId: setupCleanupTimeout(cacheKey, cacheTtlMs)
810
+ };
811
+ clientCache.set(cacheKey, entry);
812
+ const client = await clientPromise;
813
+ return client.getSnapshot();
814
+ }
815
+ /**
816
+ * Clears the client cache used by getReplaneSnapshot.
817
+ * Useful for testing or when you need to force re-initialization.
818
+ */
819
+ async function clearSnapshotCache() {
820
+ const clientPromises = [...clientCache.values()].map((cached) => cached.clientPromise);
821
+ clientCache.clear();
822
+ for (const clientPromise of clientPromises) {
823
+ const client = await clientPromise;
824
+ client.close();
825
+ }
826
+ }
827
+
828
+ //#endregion
829
+ export { ReplaneError, ReplaneErrorCode, clearSnapshotCache, createInMemoryReplaneClient, createReplaneClient, getReplaneSnapshot, restoreReplaneClient };
774
830
  //# sourceMappingURL=index.js.map
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,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,IAAG,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAM,EAAC;AAGvD,KAAI,QAAQ,KAAK,CAAC,MAAM,GAAG,QAAQ,CACjC,UAAS;AAGX,QAAO;EAAE,QAAQ,WAAW;EAAQ;CAAgB;AACrD;;;;;AAMD,IAAa,WAAb,MAAyB;CACvB,AAAgB;CAChB,AAAO;CACP,AAAO;CAEP,cAAc;AACZ,OAAK,UAAU,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC9C,QAAK,UAAU;AACf,QAAK,SAAS;EACf;CACF;AACF;;;;ACpED,MAAM,kBAAkB;;;;AAwBxB,eAAsB,iBACpBC,OACAC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oB,CAC3C,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK;EAC5B,WAAW,OAAO,QAAQ,SAAS,aAAa,CAAE,EAAC,CAChD,OAAO,CAAC,CAAC,GAAG,MAAM,KAAK,iBAAoB,CAC3C,IAAI,CAAC,CAAC,MAAM,MAAM,MAAM;GACvB;GACA,WAAW,CAAE;GACb,SAAS;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>","options: ReplaneClientOptions<T>","cacheKey: string","cacheTtlMs: number","options: GetReplaneSnapshotOptions<T>","client","entry: CachedClient"],"sources":["../src/error.ts","../src/utils.ts","../src/sse.ts","../src/storage.ts","../src/hash.ts","../src/evaluation.ts","../src/client.ts","../src/snapshot.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","import { createReplaneClient } from \"./client\";\nimport type { ReplaneClient, ReplaneClientOptions, ReplaneSnapshot } from \"./client-types\";\n\n/**\n * Extended options for getReplaneSnapshot with caching support.\n */\nexport interface GetReplaneSnapshotOptions<T extends object> extends ReplaneClientOptions<T> {\n /**\n * Cache TTL in milliseconds. When set, the client is cached and reused\n * for instant subsequent calls within this duration.\n * @default 60_000 (1 minute)\n */\n cacheTtlMs?: number;\n}\n\ninterface CachedClient {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n clientPromise: Promise<ReplaneClient<any>>;\n timeoutId: TimeoutId;\n}\n\nconst clientCache = new Map<string, CachedClient>();\n\nfunction getCacheKey<T extends object>(options: ReplaneClientOptions<T>): string {\n return `${options.baseUrl}:${options.sdkKey}`;\n}\n\ntype TimeoutId = ReturnType<typeof setTimeout>;\n\nfunction setupCleanupTimeout(cacheKey: string, cacheTtlMs: number): TimeoutId {\n return setTimeout(() => {\n clientCache.delete(cacheKey);\n }, cacheTtlMs);\n}\n\n/**\n * Creates a Replane client and returns a snapshot.\n * Useful for SSR/SSG scenarios where you need to fetch config once\n * and pass it to the client.\n *\n * @example\n * ```ts\n * const snapshot = await getReplaneSnapshot({\n * baseUrl: process.env.REPLANE_BASE_URL!,\n * sdkKey: process.env.REPLANE_SDK_KEY!,\n * });\n * ```\n */\nexport async function getReplaneSnapshot<T extends object>(\n options: GetReplaneSnapshotOptions<T>\n): Promise<ReplaneSnapshot<T>> {\n const { cacheTtlMs = 60_000, ...clientOptions } = options;\n\n const cacheKey = getCacheKey(clientOptions);\n const cached = clientCache.get(cacheKey);\n\n // Return from cache if valid\n if (cached) {\n clearTimeout(cached.timeoutId);\n cached.timeoutId = setupCleanupTimeout(cacheKey, cacheTtlMs);\n\n const client = await cached.clientPromise;\n return client.getSnapshot() as ReplaneSnapshot<T>;\n }\n\n // Create new client and cache it\n const clientPromise = createReplaneClient<T>(clientOptions);\n const entry: CachedClient = {\n clientPromise: clientPromise,\n timeoutId: setupCleanupTimeout(cacheKey, cacheTtlMs),\n };\n clientCache.set(cacheKey, entry);\n\n const client = await clientPromise;\n\n return client.getSnapshot();\n}\n\n/**\n * Clears the client cache used by getReplaneSnapshot.\n * Useful for testing or when you need to force re-initialization.\n */\nexport async function clearSnapshotCache(): Promise<void> {\n const clientPromises = [...clientCache.values()].map((cached) => cached.clientPromise);\n clientCache.clear();\n for (const clientPromise of clientPromises) {\n const client = await clientPromise;\n client.close();\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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AACF;;;;AC9YD,MAAM,cAAc,IAAI;AAExB,SAAS,YAA8BC,SAA0C;AAC/E,SAAQ,EAAE,QAAQ,QAAQ,GAAG,QAAQ,OAAO;AAC7C;AAID,SAAS,oBAAoBC,UAAkBC,YAA+B;AAC5E,QAAO,WAAW,MAAM;AACtB,cAAY,OAAO,SAAS;CAC7B,GAAE,WAAW;AACf;;;;;;;;;;;;;;AAeD,eAAsB,mBACpBC,SAC6B;CAC7B,MAAM,EAAE,aAAa,IAAQ,GAAG,eAAe,GAAG;CAElD,MAAM,WAAW,YAAY,cAAc;CAC3C,MAAM,SAAS,YAAY,IAAI,SAAS;AAGxC,KAAI,QAAQ;AACV,eAAa,OAAO,UAAU;AAC9B,SAAO,YAAY,oBAAoB,UAAU,WAAW;EAE5D,MAAMC,WAAS,MAAM,OAAO;AAC5B,SAAO,SAAO,aAAa;CAC5B;CAGD,MAAM,gBAAgB,oBAAuB,cAAc;CAC3D,MAAMC,QAAsB;EACX;EACf,WAAW,oBAAoB,UAAU,WAAW;CACrD;AACD,aAAY,IAAI,UAAU,MAAM;CAEhC,MAAM,SAAS,MAAM;AAErB,QAAO,OAAO,aAAa;AAC5B;;;;;AAMD,eAAsB,qBAAoC;CACxD,MAAM,iBAAiB,CAAC,GAAG,YAAY,QAAQ,AAAC,EAAC,IAAI,CAAC,WAAW,OAAO,cAAc;AACtF,aAAY,OAAO;AACnB,MAAK,MAAM,iBAAiB,gBAAgB;EAC1C,MAAM,SAAS,MAAM;AACrB,SAAO,OAAO;CACf;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replanejs/sdk",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Dynamic configuration SDK for browser and server environments (Node.js, Deno, Bun). Powered by Replane.",
5
5
  "type": "module",
6
6
  "license": "MIT",