@partylayer/sdk 0.12.1 → 0.13.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.mjs CHANGED
@@ -41,6 +41,7 @@ var GenericAnnounceAdapter = class {
41
41
  icon;
42
42
  provider;
43
43
  metadataEnabled;
44
+ staticMetadata;
44
45
  mapError;
45
46
  // Optional WalletAdapter surface — assigned in the ctor ONLY when configured,
46
47
  // so `getCapabilities()` and `'x' in adapter` feature-detection stay honest.
@@ -54,6 +55,7 @@ var GenericAnnounceAdapter = class {
54
55
  this.provider = args.provider;
55
56
  const config = args.config;
56
57
  this.metadataEnabled = config?.metadata === true;
58
+ this.staticMetadata = config?.staticMetadata;
57
59
  this.mapError = config?.mapError;
58
60
  if (config?.events) this.on = this.makeOn();
59
61
  if (config?.restore) this.restore = this.makeRestore();
@@ -96,7 +98,7 @@ var GenericAnnounceAdapter = class {
96
98
  network: reportedNetwork ?? account.networkId ?? ctx.network
97
99
  };
98
100
  if (this.metadataEnabled) {
99
- session.metadata = buildMetadata(status, account);
101
+ session.metadata = { ...this.staticMetadata ?? {}, ...buildMetadata(status, account) };
100
102
  }
101
103
  return { partyId, session, capabilities: this.getCapabilities() };
102
104
  });
@@ -161,7 +163,12 @@ var GenericAnnounceAdapter = class {
161
163
  return {
162
164
  ...persisted,
163
165
  walletId: this.walletId,
164
- metadata: { ...persisted.metadata ?? {}, ...buildMetadata(status, account) }
166
+ // persisted (lowest) → static config → runtime RPC (wins).
167
+ metadata: {
168
+ ...persisted.metadata ?? {},
169
+ ...this.staticMetadata ?? {},
170
+ ...buildMetadata(status, account)
171
+ }
165
172
  };
166
173
  });
167
174
  }
@@ -715,12 +722,21 @@ var SESSION_STORAGE_KEY = "active_session";
715
722
  var WALLETS_CHANGED_DEBOUNCE_MS = 50;
716
723
  function deriveAnnounceConfig(entry) {
717
724
  const cfg = entry.adapter?.config ?? {};
718
- return {
725
+ const config = {
719
726
  events: entry.capabilities?.events === true,
720
727
  restore: cfg.restore === true,
721
728
  ledgerApi: cfg.ledgerApi === true,
722
729
  metadata: cfg.metadata === true
723
730
  };
731
+ const sm = cfg.staticMetadata;
732
+ if (sm && typeof sm === "object") {
733
+ const out = {};
734
+ for (const [k, v] of Object.entries(sm)) {
735
+ if (typeof v === "string") out[k] = v;
736
+ }
737
+ if (Object.keys(out).length > 0) config.staticMetadata = out;
738
+ }
739
+ return config;
724
740
  }
725
741
  var PartyLayerClient = class {
726
742
  config;
@@ -734,6 +750,13 @@ var PartyLayerClient = class {
734
750
  warmPlans = /* @__PURE__ */ new Map();
735
751
  eventHandlers = /* @__PURE__ */ new Map();
736
752
  activeSession = null;
753
+ /**
754
+ * True when `activeSession` was revived AS-IS (no live `status()` probe) because
755
+ * its adapter wasn't registered yet at restore time (the lazy configured-announce
756
+ * case). Cleared once a live probe validates it (or on fresh connect). When set,
757
+ * `aggregateAnnouncedWallets` re-probes the session the moment that adapter is born.
758
+ */
759
+ activeSessionNeedsProbe = false;
737
760
  registryClient;
738
761
  // Expose for React hooks
739
762
  logger;
@@ -1013,6 +1036,28 @@ var PartyLayerClient = class {
1013
1036
  config: deriveAnnounceConfig(entry)
1014
1037
  });
1015
1038
  this.adapters.set(configured.walletId, configured);
1039
+ const active = this.activeSession;
1040
+ if (active && this.activeSessionNeedsProbe && active.walletId === configured.walletId && configured.restore) {
1041
+ try {
1042
+ const reprobed = await configured.restore(this.createAdapterContext(), {
1043
+ ...active,
1044
+ encrypted: ""
1045
+ });
1046
+ if (reprobed) {
1047
+ this.activeSession = reprobed;
1048
+ this.activeSessionNeedsProbe = false;
1049
+ await this.persistSession(reprobed);
1050
+ this.emit("session:connected", { type: "session:connected", session: reprobed });
1051
+ } else {
1052
+ await this.removeSession(active.sessionId);
1053
+ this.activeSession = null;
1054
+ this.activeSessionNeedsProbe = false;
1055
+ this.emit("session:expired", { type: "session:expired", sessionId: active.sessionId });
1056
+ }
1057
+ } catch (err) {
1058
+ this.logger.warn("Restore re-probe failed; leaving session as-is", err);
1059
+ }
1060
+ }
1016
1061
  }
1017
1062
  } catch {
1018
1063
  }
@@ -1239,6 +1284,7 @@ var PartyLayerClient = class {
1239
1284
  }
1240
1285
  await this.persistSession(session);
1241
1286
  this.activeSession = session;
1287
+ this.activeSessionNeedsProbe = false;
1242
1288
  this.updateRegistryStatus();
1243
1289
  this.telemetry?.increment?.(METRICS.WALLET_CONNECT_SUCCESS);
1244
1290
  this.telemetry?.increment?.(METRICS.SESSIONS_CREATED);
@@ -1629,6 +1675,7 @@ var PartyLayerClient = class {
1629
1675
  });
1630
1676
  if (restored) {
1631
1677
  this.activeSession = restored;
1678
+ this.activeSessionNeedsProbe = false;
1632
1679
  await this.persistSession(restored);
1633
1680
  this.telemetry?.increment?.(METRICS.SESSIONS_RESTORED);
1634
1681
  this.telemetry?.increment?.(METRICS.WALLET_CONNECT_SUCCESS);
@@ -1647,6 +1694,7 @@ var PartyLayerClient = class {
1647
1694
  }
1648
1695
  }
1649
1696
  this.activeSession = session;
1697
+ this.activeSessionNeedsProbe = true;
1650
1698
  return session;
1651
1699
  } catch (err) {
1652
1700
  this.logger.warn("Failed to restore session", err);