@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.cjs CHANGED
@@ -571,25 +571,23 @@ var AuthClient = class {
571
571
  }
572
572
  };
573
573
  async function refreshAccessToken(baseUrl, refreshToken) {
574
+ const refreshUrl = `${baseUrl.replace(/\/$/, "")}/api/auth/refresh`;
574
575
  let response;
575
576
  try {
576
- response = await fetch(`${baseUrl.replace(/\/$/, "")}/api/auth/refresh`, {
577
+ response = await fetch(refreshUrl, {
577
578
  method: "POST",
578
579
  headers: { "Content-Type": "application/json" },
579
580
  body: JSON.stringify({ refreshToken })
580
581
  });
581
582
  } catch (error) {
582
- throw new core.EdgeBaseError(
583
- 0,
584
- `Network error: ${error instanceof Error ? error.message : "Failed to refresh access token."}`
583
+ throw core.networkError(
584
+ `Auth session refresh could not reach ${refreshUrl}. Make sure the EdgeBase server is running and reachable.`,
585
+ { cause: error }
585
586
  );
586
587
  }
587
588
  const body = await response.json().catch(() => null);
588
589
  if (!response.ok) {
589
- throw new core.EdgeBaseError(
590
- response.status,
591
- typeof body?.message === "string" ? body.message : "Failed to refresh access token."
592
- );
590
+ throw core.parseErrorResponse(response.status, body);
593
591
  }
594
592
  if (!body?.accessToken || !body?.refreshToken) {
595
593
  throw new core.EdgeBaseError(500, "Invalid auth refresh response.");
@@ -758,7 +756,7 @@ var DatabaseLiveClient = class {
758
756
  (refreshToken) => refreshAccessToken(this.baseUrl, refreshToken)
759
757
  );
760
758
  if (!token) throw new core.EdgeBaseError(401, "No access token available. Sign in first.");
761
- this.sendRaw({ type: "auth", token, sdkVersion: "0.2.5" });
759
+ this.sendRaw({ type: "auth", token, sdkVersion: "0.2.6" });
762
760
  return new Promise((resolve, reject) => {
763
761
  const timeout = setTimeout(() => reject(new core.EdgeBaseError(401, "Auth timeout")), 1e4);
764
762
  const original = this.ws?.onmessage;
@@ -878,7 +876,7 @@ var DatabaseLiveClient = class {
878
876
  refreshAuth() {
879
877
  const token = this.tokenManager.currentAccessToken;
880
878
  if (!token || !this.ws || !this.connected) return;
881
- this.sendRaw({ type: "auth", token, sdkVersion: "0.2.5" });
879
+ this.sendRaw({ type: "auth", token, sdkVersion: "0.2.6" });
882
880
  }
883
881
  handleAuthStateChange(user) {
884
882
  if (user) {
@@ -2366,7 +2364,7 @@ var RoomClient = class _RoomClient {
2366
2364
  (refreshToken) => refreshAccessToken(this.baseUrl, refreshToken)
2367
2365
  );
2368
2366
  if (!token) {
2369
- throw new core.EdgeBaseError(401, "Authentication required");
2367
+ throw new core.EdgeBaseError(401, "Authentication required before calling room media APIs. Sign in and join the room first.");
2370
2368
  }
2371
2369
  const url = new URL(`${this.baseUrl.replace(/\/$/, "")}/api/room/media/${providerPath}/${path}`);
2372
2370
  url.searchParams.set("namespace", this.namespace);
@@ -2394,11 +2392,27 @@ var RoomClient = class _RoomClient {
2394
2392
  */
2395
2393
  static async getMetadata(baseUrl, namespace, roomId) {
2396
2394
  const url = `${baseUrl.replace(/\/$/, "")}/api/room/metadata?namespace=${encodeURIComponent(namespace)}&id=${encodeURIComponent(roomId)}`;
2397
- const res = await fetch(url);
2395
+ let res;
2396
+ try {
2397
+ res = await fetch(url);
2398
+ } catch (error) {
2399
+ throw core.networkError(
2400
+ `Room metadata request could not reach ${url}. Make sure the EdgeBase server is running and reachable.`,
2401
+ { cause: error }
2402
+ );
2403
+ }
2404
+ const data = await res.json().catch(() => null);
2398
2405
  if (!res.ok) {
2399
- throw new core.EdgeBaseError(res.status, `Failed to get room metadata: ${res.statusText}`);
2406
+ const parsed = core.parseErrorResponse(res.status, data);
2407
+ if (data && typeof data === "object" && typeof data.message === "string") {
2408
+ throw parsed;
2409
+ }
2410
+ throw new core.EdgeBaseError(
2411
+ res.status,
2412
+ `Failed to load room metadata for '${roomId}' in namespace '${namespace}'. ${parsed.message}`
2413
+ );
2400
2414
  }
2401
- return res.json();
2415
+ return data ?? {};
2402
2416
  }
2403
2417
  // ─── Connection Lifecycle ───
2404
2418
  /** Connect to the room, authenticate, and join */
@@ -2481,7 +2495,7 @@ var RoomClient = class _RoomClient {
2481
2495
  */
2482
2496
  async send(actionType, payload) {
2483
2497
  if (!this.ws || !this.connected || !this.authenticated) {
2484
- throw new core.EdgeBaseError(400, "Not connected to room");
2498
+ throw new core.EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2485
2499
  }
2486
2500
  const requestId = generateRequestId();
2487
2501
  return new Promise((resolve, reject) => {
@@ -2665,7 +2679,7 @@ var RoomClient = class _RoomClient {
2665
2679
  }
2666
2680
  async sendSignal(event, payload, options) {
2667
2681
  if (!this.ws || !this.connected || !this.authenticated) {
2668
- throw new core.EdgeBaseError(400, "Not connected to room");
2682
+ throw new core.EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2669
2683
  }
2670
2684
  const requestId = generateRequestId();
2671
2685
  return new Promise((resolve, reject) => {
@@ -2697,7 +2711,7 @@ var RoomClient = class _RoomClient {
2697
2711
  }
2698
2712
  async sendMemberStateRequest(payload) {
2699
2713
  if (!this.ws || !this.connected || !this.authenticated) {
2700
- throw new core.EdgeBaseError(400, "Not connected to room");
2714
+ throw new core.EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2701
2715
  }
2702
2716
  const requestId = generateRequestId();
2703
2717
  return new Promise((resolve, reject) => {
@@ -2711,7 +2725,7 @@ var RoomClient = class _RoomClient {
2711
2725
  }
2712
2726
  async sendAdmin(operation, memberId, payload) {
2713
2727
  if (!this.ws || !this.connected || !this.authenticated) {
2714
- throw new core.EdgeBaseError(400, "Not connected to room");
2728
+ throw new core.EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2715
2729
  }
2716
2730
  const requestId = generateRequestId();
2717
2731
  return new Promise((resolve, reject) => {
@@ -2731,7 +2745,7 @@ var RoomClient = class _RoomClient {
2731
2745
  }
2732
2746
  async sendMedia(operation, kind, payload) {
2733
2747
  if (!this.ws || !this.connected || !this.authenticated) {
2734
- throw new core.EdgeBaseError(400, "Not connected to room");
2748
+ throw new core.EdgeBaseError(400, "Not connected to room. Call room.join() and wait for the room to connect before sending actions, signals, or media.");
2735
2749
  }
2736
2750
  const requestId = generateRequestId();
2737
2751
  return new Promise((resolve, reject) => {