@replanejs/sdk 0.5.12 → 0.6.1

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
@@ -242,8 +242,8 @@ class ReplaneRemoteStorage {
242
242
  });
243
243
  for await (const sseEvent of rawEvents) {
244
244
  resetInactivityTimer();
245
- if (sseEvent.type === "ping") continue;
246
- const event = JSON.parse(sseEvent.payload);
245
+ if (sseEvent.type === "comment") continue;
246
+ const event = JSON.parse(sseEvent.data);
247
247
  if (typeof event === "object" && event !== null && "type" in event && typeof event.type === "string" && SUPPORTED_REPLICATION_STREAM_RECORD_TYPES.includes(event.type)) {
248
248
  yield event;
249
249
  }
@@ -324,20 +324,17 @@ async function _createReplaneClient(sdkOptions, storage) {
324
324
  currentConfigs: [...configs.values()].map((config) => ({
325
325
  name: config.name,
326
326
  overrides: config.overrides,
327
- version: config.version,
328
327
  value: config.value
329
328
  })),
330
329
  requiredConfigs: sdkOptions.requiredConfigs
331
330
  })
332
331
  });
333
332
  for await (const event of replicationStream) {
334
- const updatedConfigs = event.type === "config_change" ? [event] : event.configs;
333
+ const updatedConfigs = event.type === "config_change" ? [event.config] : event.configs;
335
334
  for (const config of updatedConfigs) {
336
- if (config.version <= (configs.get(config.name)?.version ?? -1)) continue;
337
335
  configs.set(config.name, {
338
336
  name: config.name,
339
337
  overrides: config.overrides,
340
- version: config.version,
341
338
  value: config.value
342
339
  });
343
340
  for (const callback of clientSubscriptions) {
@@ -456,7 +453,7 @@ function toFinalOptions(defaults) {
456
453
  globalThis.fetch.bind(globalThis),
457
454
  requestTimeoutMs: defaults.requestTimeoutMs ?? 2e3,
458
455
  initializationTimeoutMs: defaults.initializationTimeoutMs ?? 5e3,
459
- inactivityTimeoutMs: defaults.inactivityTimeoutMs ?? 6e4,
456
+ inactivityTimeoutMs: defaults.inactivityTimeoutMs ?? 3e4,
460
457
  logger: defaults.logger ?? console,
461
458
  retryDelayMs: defaults.retryDelayMs ?? 200,
462
459
  context: {
@@ -534,11 +531,11 @@ async function* fetchSse(params) {
534
531
  buffer = frames.pop() ?? "";
535
532
  for (const frame of frames) {
536
533
  const dataLines = [];
537
- let isPing = false;
534
+ let comment = null;
538
535
  for (const rawLine of frame.split(/\r?\n/)) {
539
536
  if (!rawLine) continue;
540
537
  if (rawLine.startsWith(":")) {
541
- isPing = true;
538
+ comment = rawLine.slice(1);
542
539
  continue;
543
540
  }
544
541
  if (rawLine.startsWith(SSE_DATA_PREFIX)) {
@@ -547,10 +544,10 @@ async function* fetchSse(params) {
547
544
  }
548
545
  }
549
546
  if (dataLines.length) {
550
- const payload = dataLines.join("\n");
551
- yield { type: "data", payload };
552
- } else if (isPing) {
553
- yield { type: "ping" };
547
+ const data = dataLines.join("\n");
548
+ yield { type: "data", data };
549
+ } else if (comment !== null) {
550
+ yield { type: "comment", comment };
554
551
  }
555
552
  }
556
553
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region src/index.d.ts
2
2
  type Configs = object;
3
- type ReplaneContext = Record<string, unknown>;
3
+ type ReplaneContext = Record<string, string | number | boolean | null | undefined>;
4
4
  interface ReplaneClientOptions<T extends Configs> {
5
5
  /**
6
6
  * Base URL of the Replane instance (no trailing slash).
@@ -39,7 +39,7 @@ interface ReplaneClientOptions<T extends Configs> {
39
39
  /**
40
40
  * Timeout in ms for SSE connection inactivity.
41
41
  * If no events (including pings) are received within this time, the connection will be re-established.
42
- * @default 60000
42
+ * @default 30000
43
43
  */
44
44
  inactivityTimeoutMs?: number;
45
45
  /**
package/dist/index.js CHANGED
@@ -195,8 +195,8 @@ var ReplaneRemoteStorage = class {
195
195
  });
196
196
  for await (const sseEvent of rawEvents) {
197
197
  resetInactivityTimer();
198
- if (sseEvent.type === "ping") continue;
199
- const event = JSON.parse(sseEvent.payload);
198
+ if (sseEvent.type === "comment") continue;
199
+ const event = JSON.parse(sseEvent.data);
200
200
  if (typeof event === "object" && event !== null && "type" in event && typeof event.type === "string" && SUPPORTED_REPLICATION_STREAM_RECORD_TYPES.includes(event.type)) yield event;
201
201
  }
202
202
  } finally {
@@ -281,20 +281,17 @@ async function _createReplaneClient(sdkOptions, storage) {
281
281
  currentConfigs: [...configs.values()].map((config) => ({
282
282
  name: config.name,
283
283
  overrides: config.overrides,
284
- version: config.version,
285
284
  value: config.value
286
285
  })),
287
286
  requiredConfigs: sdkOptions.requiredConfigs
288
287
  })
289
288
  });
290
289
  for await (const event of replicationStream) {
291
- const updatedConfigs = event.type === "config_change" ? [event] : event.configs;
290
+ const updatedConfigs = event.type === "config_change" ? [event.config] : event.configs;
292
291
  for (const config of updatedConfigs) {
293
- if (config.version <= (configs.get(config.name)?.version ?? -1)) continue;
294
292
  configs.set(config.name, {
295
293
  name: config.name,
296
294
  overrides: config.overrides,
297
- version: config.version,
298
295
  value: config.value
299
296
  });
300
297
  for (const callback of clientSubscriptions) callback({
@@ -392,7 +389,7 @@ function toFinalOptions(defaults) {
392
389
  fetchFn: defaults.fetchFn ?? globalThis.fetch.bind(globalThis),
393
390
  requestTimeoutMs: defaults.requestTimeoutMs ?? 2e3,
394
391
  initializationTimeoutMs: defaults.initializationTimeoutMs ?? 5e3,
395
- inactivityTimeoutMs: defaults.inactivityTimeoutMs ?? 6e4,
392
+ inactivityTimeoutMs: defaults.inactivityTimeoutMs ?? 3e4,
396
393
  logger: defaults.logger ?? console,
397
394
  retryDelayMs: defaults.retryDelayMs ?? 200,
398
395
  context: { ...defaults.context ?? {} },
@@ -460,11 +457,11 @@ async function* fetchSse(params) {
460
457
  buffer = frames.pop() ?? "";
461
458
  for (const frame of frames) {
462
459
  const dataLines = [];
463
- let isPing = false;
460
+ let comment = null;
464
461
  for (const rawLine of frame.split(/\r?\n/)) {
465
462
  if (!rawLine) continue;
466
463
  if (rawLine.startsWith(":")) {
467
- isPing = true;
464
+ comment = rawLine.slice(1);
468
465
  continue;
469
466
  }
470
467
  if (rawLine.startsWith(SSE_DATA_PREFIX)) {
@@ -473,12 +470,15 @@ async function* fetchSse(params) {
473
470
  }
474
471
  }
475
472
  if (dataLines.length) {
476
- const payload = dataLines.join("\n");
473
+ const data = dataLines.join("\n");
477
474
  yield {
478
475
  type: "data",
479
- payload
476
+ data
480
477
  };
481
- } else if (isPing) yield { type: "ping" };
478
+ } else if (comment !== null) yield {
479
+ type: "comment",
480
+ comment
481
+ };
482
482
  }
483
483
  }
484
484
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replanejs/sdk",
3
- "version": "0.5.12",
3
+ "version": "0.6.1",
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",