@calimero-network/mero-react 9.1.1 → 9.1.3

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,5 +1,5 @@
1
1
  import { createContext, useMemo, useState, useRef, useCallback, useEffect, useContext } from 'react';
2
- import { LocalStorageTokenStore, parseAuthCallback, MeroJs, buildAuthLoginUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, compareSemver } from '@calimero-network/mero-js';
2
+ import { LocalStorageTokenStore, parseAuthCallback, MeroJs, buildAuthLoginUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, compareSemver, AuthRevokedError, HTTPError } from '@calimero-network/mero-js';
3
3
  export * from '@calimero-network/mero-js';
4
4
  export { CAPABILITIES, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, hasCap, localNodeUrl, nodeEndpoint, probeNodeHealth, withCap, withoutCap } from '@calimero-network/mero-js';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -285,12 +285,20 @@ var isBrowser = typeof window !== "undefined";
285
285
  function getPermissionsForMode(mode) {
286
286
  switch (mode) {
287
287
  case "single-context" /* SingleContext */:
288
- return ["context:execute", "context:list", "application:list", "blob", "context:alias"];
288
+ return [
289
+ "context:execute",
290
+ "context:list",
291
+ "context:subscribe",
292
+ "application:list",
293
+ "blob",
294
+ "context:alias"
295
+ ];
289
296
  case "multi-context" /* MultiContext */:
290
297
  return [
291
298
  "context:create",
292
299
  "context:list",
293
300
  "context:execute",
301
+ "context:subscribe",
294
302
  "application:list",
295
303
  "namespace",
296
304
  "group",
@@ -490,7 +498,22 @@ function MeroProvider({
490
498
  const onError = (err) => {
491
499
  if (!active) return;
492
500
  setIsOnline(false);
493
- if (!err.message.includes("401")) return;
501
+ if (err instanceof AuthRevokedError) {
502
+ logout();
503
+ return;
504
+ }
505
+ if (err instanceof HTTPError && err.status === 403) {
506
+ if (err.headers?.get("x-auth-error") === "permission_denied") {
507
+ console.warn(
508
+ "[MeroProvider] This session cannot open an event stream (403 permission_denied): its token predates the context:subscribe grant. Logging out \u2014 a fresh login mints a key that can subscribe."
509
+ );
510
+ logout();
511
+ return;
512
+ }
513
+ return;
514
+ }
515
+ const status = err instanceof HTTPError ? err.status : null;
516
+ if (status !== 401 && !err.message.includes("401")) return;
494
517
  if (recoveringRef.current) return;
495
518
  recoveringRef.current = true;
496
519
  void (async () => {