@edge-base/react-native 0.2.5 → 0.2.6

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { EdgeBaseError, createSubscription, ApiPaths, ContextManager, HttpClient, DefaultDbApi, HttpClientAdapter, PublicHttpClientAdapter, StorageClient, FunctionsClient, DbRef } from '@edge-base/core';
1
+ import { EdgeBaseError, createSubscription, networkError, parseErrorResponse, ApiPaths, ContextManager, HttpClient, DefaultDbApi, HttpClientAdapter, PublicHttpClientAdapter, StorageClient, FunctionsClient, DbRef } from '@edge-base/core';
2
2
  import React, { useCallback, useState, useEffect } from 'react';
3
3
 
4
4
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -565,25 +565,23 @@ var AuthClient = class {
565
565
  }
566
566
  };
567
567
  async function refreshAccessToken(baseUrl, refreshToken) {
568
+ const refreshUrl = `${baseUrl.replace(/\/$/, "")}/api/auth/refresh`;
568
569
  let response;
569
570
  try {
570
- response = await fetch(`${baseUrl.replace(/\/$/, "")}/api/auth/refresh`, {
571
+ response = await fetch(refreshUrl, {
571
572
  method: "POST",
572
573
  headers: { "Content-Type": "application/json" },
573
574
  body: JSON.stringify({ refreshToken })
574
575
  });
575
576
  } catch (error) {
576
- throw new EdgeBaseError(
577
- 0,
578
- `Network error: ${error instanceof Error ? error.message : "Failed to refresh access token."}`
577
+ throw networkError(
578
+ `Auth session refresh could not reach ${refreshUrl}. Make sure the EdgeBase server is running and reachable.`,
579
+ { cause: error }
579
580
  );
580
581
  }
581
582
  const body = await response.json().catch(() => null);
582
583
  if (!response.ok) {
583
- throw new EdgeBaseError(
584
- response.status,
585
- typeof body?.message === "string" ? body.message : "Failed to refresh access token."
586
- );
584
+ throw parseErrorResponse(response.status, body);
587
585
  }
588
586
  if (!body?.accessToken || !body?.refreshToken) {
589
587
  throw new EdgeBaseError(500, "Invalid auth refresh response.");
@@ -752,7 +750,7 @@ var DatabaseLiveClient = class {
752
750
  (refreshToken) => refreshAccessToken(this.baseUrl, refreshToken)
753
751
  );
754
752
  if (!token) throw new EdgeBaseError(401, "No access token available. Sign in first.");
755
- this.sendRaw({ type: "auth", token, sdkVersion: "0.2.5" });
753
+ this.sendRaw({ type: "auth", token, sdkVersion: "0.2.6" });
756
754
  return new Promise((resolve, reject) => {
757
755
  const timeout = setTimeout(() => reject(new EdgeBaseError(401, "Auth timeout")), 1e4);
758
756
  const original = this.ws?.onmessage;
@@ -872,7 +870,7 @@ var DatabaseLiveClient = class {
872
870
  refreshAuth() {
873
871
  const token = this.tokenManager.currentAccessToken;
874
872
  if (!token || !this.ws || !this.connected) return;
875
- this.sendRaw({ type: "auth", token, sdkVersion: "0.2.5" });
873
+ this.sendRaw({ type: "auth", token, sdkVersion: "0.2.6" });
876
874
  }
877
875
  handleAuthStateChange(user) {
878
876
  if (user) {
@@ -2360,7 +2358,7 @@ var RoomClient = class _RoomClient {
2360
2358
  (refreshToken) => refreshAccessToken(this.baseUrl, refreshToken)
2361
2359
  );
2362
2360
  if (!token) {
2363
- throw new EdgeBaseError(401, "Authentication required");
2361
+ throw new EdgeBaseError(401, "Authentication required before calling room media APIs. Sign in and join the room first.");
2364
2362
  }
2365
2363
  const url = new URL(`${this.baseUrl.replace(/\/$/, "")}/api/room/media/${providerPath}/${path}`);
2366
2364
  url.searchParams.set("namespace", this.namespace);
@@ -2388,11 +2386,27 @@ var RoomClient = class _RoomClient {
2388
2386
  */
2389
2387
  static async getMetadata(baseUrl, namespace, roomId) {
2390
2388
  const url = `${baseUrl.replace(/\/$/, "")}/api/room/metadata?namespace=${encodeURIComponent(namespace)}&id=${encodeURIComponent(roomId)}`;
2391
- const res = await fetch(url);
2389
+ let res;
2390
+ try {
2391
+ res = await fetch(url);
2392
+ } catch (error) {
2393
+ throw networkError(
2394
+ `Room metadata request could not reach ${url}. Make sure the EdgeBase server is running and reachable.`,
2395
+ { cause: error }
2396
+ );
2397
+ }
2398
+ const data = await res.json().catch(() => null);
2392
2399
  if (!res.ok) {
2393
- throw new EdgeBaseError(res.status, `Failed to get room metadata: ${res.statusText}`);
2400
+ const parsed = parseErrorResponse(res.status, data);
2401
+ if (data && typeof data === "object" && typeof data.message === "string") {
2402
+ throw parsed;
2403
+ }
2404
+ throw new EdgeBaseError(
2405
+ res.status,
2406
+ `Failed to load room metadata for '${roomId}' in namespace '${namespace}'. ${parsed.message}`
2407
+ );
2394
2408
  }
2395
- return res.json();
2409
+ return data ?? {};
2396
2410
  }
2397
2411
  // ─── Connection Lifecycle ───
2398
2412
  /** Connect to the room, authenticate, and join */
@@ -2475,7 +2489,7 @@ var RoomClient = class _RoomClient {
2475
2489
  */
2476
2490
  async send(actionType, payload) {
2477
2491
  if (!this.ws || !this.connected || !this.authenticated) {
2478
- throw new EdgeBaseError(400, "Not connected to room");
2492
+ throw new EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2479
2493
  }
2480
2494
  const requestId = generateRequestId();
2481
2495
  return new Promise((resolve, reject) => {
@@ -2659,7 +2673,7 @@ var RoomClient = class _RoomClient {
2659
2673
  }
2660
2674
  async sendSignal(event, payload, options) {
2661
2675
  if (!this.ws || !this.connected || !this.authenticated) {
2662
- throw new EdgeBaseError(400, "Not connected to room");
2676
+ throw new EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2663
2677
  }
2664
2678
  const requestId = generateRequestId();
2665
2679
  return new Promise((resolve, reject) => {
@@ -2691,7 +2705,7 @@ var RoomClient = class _RoomClient {
2691
2705
  }
2692
2706
  async sendMemberStateRequest(payload) {
2693
2707
  if (!this.ws || !this.connected || !this.authenticated) {
2694
- throw new EdgeBaseError(400, "Not connected to room");
2708
+ throw new EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2695
2709
  }
2696
2710
  const requestId = generateRequestId();
2697
2711
  return new Promise((resolve, reject) => {
@@ -2705,7 +2719,7 @@ var RoomClient = class _RoomClient {
2705
2719
  }
2706
2720
  async sendAdmin(operation, memberId, payload) {
2707
2721
  if (!this.ws || !this.connected || !this.authenticated) {
2708
- throw new EdgeBaseError(400, "Not connected to room");
2722
+ throw new EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2709
2723
  }
2710
2724
  const requestId = generateRequestId();
2711
2725
  return new Promise((resolve, reject) => {
@@ -2725,7 +2739,7 @@ var RoomClient = class _RoomClient {
2725
2739
  }
2726
2740
  async sendMedia(operation, kind, payload) {
2727
2741
  if (!this.ws || !this.connected || !this.authenticated) {
2728
- throw new EdgeBaseError(400, "Not connected to room");
2742
+ throw new EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2729
2743
  }
2730
2744
  const requestId = generateRequestId();
2731
2745
  return new Promise((resolve, reject) => {