@pollar/core 0.9.0-rc.0 → 0.9.0-rc.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
@@ -339,7 +339,6 @@ var WebCryptoKeyManager = class {
339
339
  if (this.keyPair) return;
340
340
  if (!this._initPromise) {
341
341
  this._initPromise = this._doInit().catch((err) => {
342
- console.error("[PollarClient:keys] WebCryptoKeyManager init failed", err);
343
342
  this._initPromise = null;
344
343
  throw err;
345
344
  });
@@ -1074,6 +1073,16 @@ function normalizeHtu(rawUrl) {
1074
1073
  return `${scheme}//${host}${portPart}${url.pathname}`;
1075
1074
  }
1076
1075
 
1076
+ // src/lib/logger.ts
1077
+ var RANK = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
1078
+ function createLogger(level = "info", sink = console) {
1079
+ const threshold = RANK[level];
1080
+ const gate = (lvl) => (...args) => {
1081
+ if (threshold >= RANK[lvl]) sink[lvl](...args);
1082
+ };
1083
+ return { error: gate("error"), warn: gate("warn"), info: gate("info"), debug: gate("debug") };
1084
+ }
1085
+
1077
1086
  // src/storage/web.ts
1078
1087
  var LOG_PREFIX = "[PollarClient:storage]";
1079
1088
  function createMemoryAdapter() {
@@ -1097,7 +1106,7 @@ function createLocalStorageAdapter(options = {}) {
1097
1106
  function degrade(reason, error) {
1098
1107
  if (degraded) return;
1099
1108
  degraded = true;
1100
- console.warn(`${LOG_PREFIX} localStorage unavailable (${reason}); degrading to in-memory storage`);
1109
+ (options.logger ?? console).warn(`${LOG_PREFIX} localStorage unavailable (${reason}); degrading to in-memory storage`);
1101
1110
  options.onDegrade?.(reason, error);
1102
1111
  }
1103
1112
  return {
@@ -1162,7 +1171,7 @@ function defaultStorage(options = {}) {
1162
1171
  }
1163
1172
 
1164
1173
  // src/version.ts
1165
- var POLLAR_CORE_VERSION = "0.9.0-rc.0" ;
1174
+ var POLLAR_CORE_VERSION = "0.9.0-rc.1" ;
1166
1175
 
1167
1176
  // src/visibility/noop.ts
1168
1177
  function createNoopVisibilityProvider() {
@@ -1446,85 +1455,85 @@ function isBoundedString(v, max, allowEmpty = false) {
1446
1455
  if (!allowEmpty && v.length === 0) return false;
1447
1456
  return v.length <= max;
1448
1457
  }
1449
- function isValidSession(value) {
1458
+ function isValidSession(value, logger = console) {
1450
1459
  if (typeof value !== "object" || value === null) {
1451
- console.warn("[PollarClient:session] Invalid session \u2014 value is not an object");
1460
+ logger.debug("[PollarClient:session] Invalid session \u2014 value is not an object");
1452
1461
  return false;
1453
1462
  }
1454
1463
  const s = value;
1455
1464
  if (!isBoundedString(s["clientSessionId"], MAX_CLIENT_SESSION_ID)) {
1456
- console.warn("[PollarClient:session] Invalid session \u2014 clientSessionId missing/empty/too long");
1465
+ logger.debug("[PollarClient:session] Invalid session \u2014 clientSessionId missing/empty/too long");
1457
1466
  return false;
1458
1467
  }
1459
1468
  if (s["userId"] !== null && !isBoundedString(s["userId"], MAX_USER_ID)) {
1460
- console.warn("[PollarClient:session] Invalid session \u2014 userId must be string|null");
1469
+ logger.debug("[PollarClient:session] Invalid session \u2014 userId must be string|null");
1461
1470
  return false;
1462
1471
  }
1463
1472
  if (!isBoundedString(s["status"], MAX_STATUS)) {
1464
- console.warn("[PollarClient:session] Invalid session \u2014 status must be string");
1473
+ logger.debug("[PollarClient:session] Invalid session \u2014 status must be string");
1465
1474
  return false;
1466
1475
  }
1467
1476
  const token = s["token"];
1468
1477
  if (typeof token !== "object" || token === null) {
1469
- console.warn("[PollarClient:session] Invalid session \u2014 token missing or not an object");
1478
+ logger.debug("[PollarClient:session] Invalid session \u2014 token missing or not an object");
1470
1479
  return false;
1471
1480
  }
1472
1481
  const t = token;
1473
1482
  if (!isBoundedString(t["accessToken"], MAX_ACCESS_TOKEN)) {
1474
- console.warn("[PollarClient:session] Invalid session \u2014 token.accessToken missing/empty/too long");
1483
+ logger.debug("[PollarClient:session] Invalid session \u2014 token.accessToken missing/empty/too long");
1475
1484
  return false;
1476
1485
  }
1477
1486
  if (!isBoundedString(t["refreshToken"], MAX_REFRESH_TOKEN)) {
1478
- console.warn("[PollarClient:session] Invalid session \u2014 token.refreshToken missing/empty/too long");
1487
+ logger.debug("[PollarClient:session] Invalid session \u2014 token.refreshToken missing/empty/too long");
1479
1488
  return false;
1480
1489
  }
1481
1490
  if (typeof t["expiresAt"] !== "number" || !Number.isFinite(t["expiresAt"])) {
1482
- console.warn("[PollarClient:session] Invalid session \u2014 token.expiresAt must be a finite number");
1491
+ logger.debug("[PollarClient:session] Invalid session \u2014 token.expiresAt must be a finite number");
1483
1492
  return false;
1484
1493
  }
1485
1494
  const user = s["user"];
1486
1495
  if (typeof user !== "object" || user === null) {
1487
- console.warn("[PollarClient:session] Invalid session \u2014 user missing or not an object");
1496
+ logger.debug("[PollarClient:session] Invalid session \u2014 user missing or not an object");
1488
1497
  return false;
1489
1498
  }
1490
1499
  const u = user;
1491
1500
  if (u["id"] !== void 0 && !isBoundedString(u["id"], MAX_USER_ID)) {
1492
- console.warn("[PollarClient:session] Invalid session \u2014 user.id must be string if present");
1501
+ logger.debug("[PollarClient:session] Invalid session \u2014 user.id must be string if present");
1493
1502
  return false;
1494
1503
  }
1495
1504
  if (typeof u["ready"] !== "boolean") {
1496
- console.warn("[PollarClient:session] Invalid session \u2014 user.ready must be boolean");
1505
+ logger.debug("[PollarClient:session] Invalid session \u2014 user.ready must be boolean");
1497
1506
  return false;
1498
1507
  }
1499
1508
  const wallet = s["wallet"];
1500
1509
  if (typeof wallet !== "object" || wallet === null) {
1501
- console.warn("[PollarClient:session] Invalid session \u2014 wallet missing or not an object");
1510
+ logger.debug("[PollarClient:session] Invalid session \u2014 wallet missing or not an object");
1502
1511
  return false;
1503
1512
  }
1504
1513
  const w = wallet;
1505
1514
  if (w["type"] !== "custodial" && w["type"] !== "smart" && w["type"] !== "external") {
1506
- console.warn("[PollarClient:session] Invalid session \u2014 wallet.type must be custodial|smart|external");
1515
+ logger.debug("[PollarClient:session] Invalid session \u2014 wallet.type must be custodial|smart|external");
1507
1516
  return false;
1508
1517
  }
1509
1518
  if (w["address"] !== null && !isBoundedString(w["address"], MAX_WALLET_PUBLIC_KEY)) {
1510
- console.warn("[PollarClient:session] Invalid session \u2014 wallet.address must be string|null");
1519
+ logger.debug("[PollarClient:session] Invalid session \u2014 wallet.address must be string|null");
1511
1520
  return false;
1512
1521
  }
1513
1522
  if (w["existsOnStellar"] !== void 0 && typeof w["existsOnStellar"] !== "boolean") {
1514
- console.warn("[PollarClient:session] Invalid session \u2014 wallet.existsOnStellar must be boolean if present");
1523
+ logger.debug("[PollarClient:session] Invalid session \u2014 wallet.existsOnStellar must be boolean if present");
1515
1524
  return false;
1516
1525
  }
1517
1526
  if (w["createdAt"] !== void 0 && (typeof w["createdAt"] !== "number" || !Number.isFinite(w["createdAt"]))) {
1518
- console.warn("[PollarClient:session] Invalid session \u2014 wallet.createdAt must be a finite number if present");
1527
+ logger.debug("[PollarClient:session] Invalid session \u2014 wallet.createdAt must be a finite number if present");
1519
1528
  return false;
1520
1529
  }
1521
1530
  if (w["linkedAt"] !== void 0 && (typeof w["linkedAt"] !== "number" || !Number.isFinite(w["linkedAt"]))) {
1522
- console.warn("[PollarClient:session] Invalid session \u2014 wallet.linkedAt must be a finite number if present");
1531
+ logger.debug("[PollarClient:session] Invalid session \u2014 wallet.linkedAt must be a finite number if present");
1523
1532
  return false;
1524
1533
  }
1525
1534
  return true;
1526
1535
  }
1527
- async function readStorage(storage, apiKeyHash) {
1536
+ async function readStorage(storage, apiKeyHash, logger = console) {
1528
1537
  const raw = await storage.get(sessionStorageKey(apiKeyHash));
1529
1538
  if (!raw) return null;
1530
1539
  try {
@@ -1535,9 +1544,9 @@ async function readStorage(storage, apiKeyHash) {
1535
1544
  w["address"] = w["publicKey"];
1536
1545
  }
1537
1546
  }
1538
- if (!isValidSession(session)) {
1547
+ if (!isValidSession(session, logger)) {
1539
1548
  await storage.remove(sessionStorageKey(apiKeyHash));
1540
- console.warn("[PollarClient:session] Stored session is invalid \u2014 clearing storage");
1549
+ logger.warn("[PollarClient:session] Stored session is invalid \u2014 clearing storage");
1541
1550
  return null;
1542
1551
  }
1543
1552
  if (session.token.expiresAt * 1e3 < Date.now()) {
@@ -1545,7 +1554,7 @@ async function readStorage(storage, apiKeyHash) {
1545
1554
  }
1546
1555
  return session;
1547
1556
  } catch (error) {
1548
- console.error("[PollarClient:session] Failed to parse session from storage", error);
1557
+ logger.error("[PollarClient:session] Failed to parse session from storage", error);
1549
1558
  await storage.remove(sessionStorageKey(apiKeyHash));
1550
1559
  return null;
1551
1560
  }
@@ -1607,7 +1616,7 @@ function abortableDelay(ms, signal) {
1607
1616
  });
1608
1617
  }
1609
1618
  var MAX_BACKOFF_MS = 5e3;
1610
- async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200, signal) {
1619
+ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200, signal, logger = console) {
1611
1620
  let backoff = retryDelayMs;
1612
1621
  const sleep = async (ms) => {
1613
1622
  if (ms <= 0) return;
@@ -1625,7 +1634,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
1625
1634
  }));
1626
1635
  } catch (e) {
1627
1636
  if (e instanceof Error && e.name === "AbortError") throw e;
1628
- console.warn("[PollarClient:stream] session-status request failed; will retry", e);
1637
+ logger.debug("[PollarClient:stream] session-status request failed; will retry", e);
1629
1638
  }
1630
1639
  if (error || !data) {
1631
1640
  await sleep(backoff);
@@ -1665,7 +1674,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
1665
1674
  } catch (e) {
1666
1675
  if (e instanceof Error && e.name === "AbortError") throw e;
1667
1676
  if (e instanceof SessionStatusError) throw e;
1668
- console.warn("[PollarClient:stream] session-status stream read failed; will retry", e);
1677
+ logger.debug("[PollarClient:stream] session-status stream read failed; will retry", e);
1669
1678
  } finally {
1670
1679
  reader.releaseLock();
1671
1680
  }
@@ -1675,7 +1684,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
1675
1684
  if (delay) await sleep(delay);
1676
1685
  }
1677
1686
  }
1678
- async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500, signal) {
1687
+ async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500, signal, logger = console) {
1679
1688
  const url = `${baseUrl}/auth/session/status/${encodeURIComponent(clientSessionId)}/poll`;
1680
1689
  let backoff = intervalMs;
1681
1690
  const sleep = async (ms) => {
@@ -1693,7 +1702,7 @@ async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500,
1693
1702
  envelope = await response.json().catch(() => null);
1694
1703
  } catch (e) {
1695
1704
  if (e instanceof Error && e.name === "AbortError") throw e;
1696
- console.warn("[PollarClient:stream] session-status poll failed; will retry", e);
1705
+ logger.debug("[PollarClient:stream] session-status poll failed; will retry", e);
1697
1706
  }
1698
1707
  if (httpStatus === 404 || envelope?.code === "INVALID_CLIENT_SESSION_ID") {
1699
1708
  throw new SessionStatusError("INVALID_CLIENT_SESSION_ID");
@@ -1710,13 +1719,13 @@ async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500,
1710
1719
  }
1711
1720
  }
1712
1721
  function waitForSessionReady(args) {
1713
- const { api, baseUrl, clientSessionId, check, useStreaming, retryDelayMs, signal } = args;
1714
- return useStreaming ? streamUntilFound(api, clientSessionId, check, retryDelayMs ?? 200, signal) : pollUntilFound(baseUrl, clientSessionId, check, retryDelayMs ?? 500, signal);
1722
+ const { api, baseUrl, clientSessionId, check, useStreaming, retryDelayMs, signal, logger = console } = args;
1723
+ return useStreaming ? streamUntilFound(api, clientSessionId, check, retryDelayMs ?? 200, signal, logger) : pollUntilFound(baseUrl, clientSessionId, check, retryDelayMs ?? 500, signal, logger);
1715
1724
  }
1716
1725
 
1717
1726
  // src/client/auth/authenticate.ts
1718
1727
  async function authenticate(clientSessionId, deps, expectedWallet) {
1719
- const { api, basePath, useStreaming, signal, setAuthState, storeSession, clearSession } = deps;
1728
+ const { api, logger, basePath, useStreaming, signal, setAuthState, storeSession, clearSession } = deps;
1720
1729
  setAuthState({ step: "authenticating" });
1721
1730
  try {
1722
1731
  await waitForSessionReady({
@@ -1725,7 +1734,8 @@ async function authenticate(clientSessionId, deps, expectedWallet) {
1725
1734
  clientSessionId,
1726
1735
  check: (data2) => data2?.status === "READY",
1727
1736
  useStreaming,
1728
- signal
1737
+ signal,
1738
+ logger
1729
1739
  });
1730
1740
  } catch (err) {
1731
1741
  if (err instanceof SessionStatusError) {
@@ -1750,7 +1760,7 @@ async function authenticate(clientSessionId, deps, expectedWallet) {
1750
1760
  },
1751
1761
  signal
1752
1762
  });
1753
- if (data?.code === "SDK_LOGIN_SUCCESS" && isValidSession(data?.content)) {
1763
+ if (data?.code === "SDK_LOGIN_SUCCESS" && isValidSession(data?.content, logger)) {
1754
1764
  if (expectedWallet && data.content.data.providers.wallet?.address !== expectedWallet) {
1755
1765
  setAuthState({
1756
1766
  step: "error",
@@ -2068,7 +2078,9 @@ var PollarClient = class {
2068
2078
  this.apiKey = config.apiKey;
2069
2079
  this.id = randomUUID();
2070
2080
  this.basePath = `${config.baseUrl || "https://sdk.api.pollar.xyz"}/v1`;
2081
+ this._log = createLogger(config.logLevel ?? "info", config.logger);
2071
2082
  this._storage = config.storage ?? defaultStorage({
2083
+ logger: this._log,
2072
2084
  onDegrade: (reason, error) => {
2073
2085
  config.onStorageDegrade?.(reason, error);
2074
2086
  this._dispatchStorageDegrade(reason, error);
@@ -2092,7 +2104,7 @@ var PollarClient = class {
2092
2104
  this._initialized = Promise.resolve();
2093
2105
  return;
2094
2106
  }
2095
- console.info(
2107
+ this._log.info(
2096
2108
  `[PollarClient] Initialized v${POLLAR_CORE_VERSION} \u2014 endpoint: ${this.basePath}, network: ${this._networkState.network}`
2097
2109
  );
2098
2110
  this._initialized = this._initialize();
@@ -2119,7 +2131,7 @@ var PollarClient = class {
2119
2131
  const sessionKey = sessionStorageKey(this._apiKeyHash);
2120
2132
  const handler = (e) => {
2121
2133
  if (e.key === sessionKey) {
2122
- this._restoreSession().catch((err) => console.error("[PollarClient] Cross-tab restore failed", err));
2134
+ this._restoreSession().catch((err) => this._log.error("[PollarClient] Cross-tab restore failed", err));
2123
2135
  }
2124
2136
  };
2125
2137
  window.addEventListener("storage", handler);
@@ -2128,7 +2140,7 @@ var PollarClient = class {
2128
2140
  try {
2129
2141
  await this._keyManager.init();
2130
2142
  } catch (err) {
2131
- console.warn("[PollarClient] KeyManager init failed; DPoP unavailable for this session", err);
2143
+ this._log.warn("[PollarClient] KeyManager init failed; DPoP unavailable for this session", err);
2132
2144
  }
2133
2145
  await this._restoreSession();
2134
2146
  this._visibilityUnsubscribe = this._visibilityProvider.onChange((visible) => {
@@ -2169,7 +2181,7 @@ var PollarClient = class {
2169
2181
  try {
2170
2182
  self._requestBodyCache.set(request, await request.clone().arrayBuffer());
2171
2183
  } catch (err) {
2172
- console.warn("[PollarClient] Could not snapshot request body for retry", err);
2184
+ this._log.warn("[PollarClient] Could not snapshot request body for retry", err);
2173
2185
  }
2174
2186
  }
2175
2187
  const isRefresh = request.url.includes("/auth/refresh");
@@ -2228,7 +2240,7 @@ var PollarClient = class {
2228
2240
  this._keyManager
2229
2241
  );
2230
2242
  } catch (err) {
2231
- console.warn("[PollarClient] DPoP proof build failed", err);
2243
+ this._log.warn("[PollarClient] DPoP proof build failed", err);
2232
2244
  return null;
2233
2245
  }
2234
2246
  }
@@ -2282,7 +2294,7 @@ var PollarClient = class {
2282
2294
  async _doRefresh() {
2283
2295
  const refreshToken = this._session?.token?.refreshToken;
2284
2296
  if (!refreshToken) {
2285
- console.warn("[PollarClient] Refresh skipped: no refresh token in session");
2297
+ this._log.warn("[PollarClient] Refresh skipped: no refresh token in session");
2286
2298
  await this._clearSession();
2287
2299
  throw new Error("No refresh token available");
2288
2300
  }
@@ -2293,18 +2305,18 @@ var PollarClient = class {
2293
2305
  data = response.data;
2294
2306
  error = response.error;
2295
2307
  } catch (err) {
2296
- console.error("[PollarClient] /auth/refresh request threw", err);
2308
+ this._log.error("[PollarClient] /auth/refresh request threw", err);
2297
2309
  await this._clearSession();
2298
2310
  throw err;
2299
2311
  }
2300
2312
  if (error || !data) {
2301
- console.error("[PollarClient] /auth/refresh returned error", { error });
2313
+ this._log.error("[PollarClient] /auth/refresh returned error", { error });
2302
2314
  await this._clearSession();
2303
2315
  throw new Error("Refresh failed");
2304
2316
  }
2305
2317
  const successData = data;
2306
2318
  if (!successData.success || !successData.content?.token) {
2307
- console.error("[PollarClient] /auth/refresh response malformed", {
2319
+ this._log.error("[PollarClient] /auth/refresh response malformed", {
2308
2320
  success: successData.success,
2309
2321
  hasToken: !!successData.content?.token
2310
2322
  });
@@ -2313,7 +2325,7 @@ var PollarClient = class {
2313
2325
  }
2314
2326
  const newToken = successData.content.token;
2315
2327
  if (typeof newToken.accessToken !== "string" || typeof newToken.refreshToken !== "string" || typeof newToken.expiresAt !== "number") {
2316
- console.error("[PollarClient] /auth/refresh token shape invalid", {
2328
+ this._log.error("[PollarClient] /auth/refresh token shape invalid", {
2317
2329
  accessToken: typeof newToken.accessToken,
2318
2330
  refreshToken: typeof newToken.refreshToken,
2319
2331
  expiresAt: typeof newToken.expiresAt
@@ -2325,9 +2337,9 @@ var PollarClient = class {
2325
2337
  try {
2326
2338
  this._session = { ...this._session, token: newToken };
2327
2339
  await writeStorage(this._storage, this.apiKeyHash, this._session);
2328
- console.info("[PollarClient] Tokens refreshed");
2340
+ this._log.info("[PollarClient] Tokens refreshed");
2329
2341
  } catch (err) {
2330
- console.error("[PollarClient] Failed to persist refreshed session", err);
2342
+ this._log.error("[PollarClient] Failed to persist refreshed session", err);
2331
2343
  }
2332
2344
  this._scheduleNextRefresh();
2333
2345
  }
@@ -2381,7 +2393,7 @@ var PollarClient = class {
2381
2393
  try {
2382
2394
  await this.refresh();
2383
2395
  } catch (err) {
2384
- console.warn("[PollarClient] Proactive refresh failed; session cleared", err);
2396
+ this._log.warn("[PollarClient] Proactive refresh failed; session cleared", err);
2385
2397
  }
2386
2398
  }
2387
2399
  _clearRefreshTimer() {
@@ -2427,7 +2439,7 @@ var PollarClient = class {
2427
2439
  try {
2428
2440
  cb(reason, error);
2429
2441
  } catch (err) {
2430
- console.error("[PollarClient] onStorageDegrade listener threw", err);
2442
+ this._log.error("[PollarClient] onStorageDegrade listener threw", err);
2431
2443
  }
2432
2444
  }
2433
2445
  }
@@ -2547,20 +2559,20 @@ var PollarClient = class {
2547
2559
  warnServerSide("logout");
2548
2560
  return;
2549
2561
  }
2550
- console.info("[PollarClient] Logout requested", { everywhere: !!options.everywhere });
2562
+ this._log.info("[PollarClient] Logout requested", { everywhere: !!options.everywhere });
2551
2563
  if (this._session?.token?.accessToken) {
2552
2564
  try {
2553
2565
  await this._api.POST("/auth/logout", {
2554
2566
  body: options.everywhere ? { everywhere: true } : {}
2555
2567
  });
2556
2568
  } catch (err) {
2557
- console.warn("[PollarClient] Server logout failed (continuing with local clear)", err);
2569
+ this._log.warn("[PollarClient] Server logout failed (continuing with local clear)", err);
2558
2570
  }
2559
2571
  }
2560
2572
  try {
2561
2573
  await this._clearSession();
2562
2574
  } catch (err) {
2563
- console.warn("[PollarClient] Local logout cleanup failed", err);
2575
+ this._log.warn("[PollarClient] Local logout cleanup failed", err);
2564
2576
  }
2565
2577
  }
2566
2578
  /** Convenience: revoke every active session for this user (all devices). */
@@ -2636,6 +2648,14 @@ var PollarClient = class {
2636
2648
  getNetworkState() {
2637
2649
  return this._networkState;
2638
2650
  }
2651
+ /**
2652
+ * The client's level-gated logger (built from `logLevel` / `logger`). Exposed
2653
+ * so the runtime layer (`@pollar/react`) can route its own logs through the
2654
+ * same level and sink instead of calling `console` directly.
2655
+ */
2656
+ getLogger() {
2657
+ return this._log;
2658
+ }
2639
2659
  setNetwork(network) {
2640
2660
  this._setNetworkState({ step: "connected", network });
2641
2661
  }
@@ -2784,7 +2804,7 @@ var PollarClient = class {
2784
2804
  this._setTransactionState({ step: "error", phase: "building", ...details && { details } });
2785
2805
  return { status: "error", ...details && { details } };
2786
2806
  } catch (err) {
2787
- console.error("[PollarClient] buildTx failed", err);
2807
+ this._log.error("[PollarClient] buildTx failed", err);
2788
2808
  this._setTransactionState({ step: "error", phase: "building" });
2789
2809
  return { status: "error" };
2790
2810
  }
@@ -3297,6 +3317,7 @@ var PollarClient = class {
3297
3317
  _flowDeps(signal) {
3298
3318
  return {
3299
3319
  api: this._api,
3320
+ logger: this._log,
3300
3321
  basePath: this.basePath,
3301
3322
  // SSE status streaming works on web; React Native's `fetch` has no
3302
3323
  // readable `response.body`, so those clients poll the non-streaming
@@ -3349,12 +3370,12 @@ var PollarClient = class {
3349
3370
  }
3350
3371
  _handleFlowError(error) {
3351
3372
  if (error instanceof Error && error.name === "AbortError") {
3352
- console.info("[PollarClient] Login cancelled");
3373
+ this._log.debug("[PollarClient] Login cancelled");
3353
3374
  this._setAuthState({ step: "idle" });
3354
3375
  return;
3355
3376
  }
3356
3377
  if (error instanceof Error && error.code === AUTH_ERROR_CODES.WALLET_RESOLVER_TIMEOUT) {
3357
- console.error("[PollarClient]", error.message);
3378
+ this._log.error("[PollarClient]", error.message);
3358
3379
  this._setAuthState({
3359
3380
  step: "error",
3360
3381
  previousStep: this._authState.step,
@@ -3363,7 +3384,7 @@ var PollarClient = class {
3363
3384
  });
3364
3385
  return;
3365
3386
  }
3366
- console.error("[PollarClient] Unexpected error in auth flow", error);
3387
+ this._log.error("[PollarClient] Unexpected error in auth flow", error);
3367
3388
  this._setAuthState({
3368
3389
  step: "error",
3369
3390
  previousStep: this._authState.step,
@@ -3372,22 +3393,22 @@ var PollarClient = class {
3372
3393
  });
3373
3394
  }
3374
3395
  async _restoreSession() {
3375
- this._session = await readStorage(this._storage, this.apiKeyHash);
3396
+ this._session = await readStorage(this._storage, this.apiKeyHash, this._log);
3376
3397
  if (this._session) {
3377
3398
  const storedType = await readWalletType(this._storage, this.apiKeyHash);
3378
3399
  if (storedType) {
3379
3400
  try {
3380
3401
  this._walletAdapter = await this._resolveWalletAdapter(storedType);
3381
3402
  } catch (err) {
3382
- console.warn("[PollarClient] Could not restore wallet adapter for stored id", { id: storedType, err });
3403
+ this._log.warn("[PollarClient] Could not restore wallet adapter for stored id", { id: storedType, err });
3383
3404
  }
3384
3405
  }
3385
- console.info("[PollarClient] Session restored from storage");
3406
+ this._log.info("[PollarClient] Session restored from storage");
3386
3407
  this._setAuthState({ step: "authenticated", session: this._session, verified: false });
3387
3408
  this._scheduleNextRefresh();
3388
3409
  void this._resume();
3389
3410
  } else {
3390
- console.info("[PollarClient] No session in storage");
3411
+ this._log.info("[PollarClient] No session in storage");
3391
3412
  }
3392
3413
  }
3393
3414
  /**
@@ -3418,13 +3439,13 @@ var PollarClient = class {
3418
3439
  this._setAuthState({ step: "authenticated", session: this._session, verified: true });
3419
3440
  } catch (err) {
3420
3441
  if (err?.name === "AbortError") return;
3421
- console.warn("[PollarClient] resume failed (network); will retry", err);
3442
+ this._log.warn("[PollarClient] resume failed (network); will retry", err);
3422
3443
  } finally {
3423
3444
  if (this._resumeController === controller) this._resumeController = null;
3424
3445
  }
3425
3446
  }
3426
3447
  async _storeSession(session) {
3427
- console.info("[PollarClient] Session stored");
3448
+ this._log.info("[PollarClient] Session stored");
3428
3449
  const w = session.wallet;
3429
3450
  const persisted = {
3430
3451
  clientSessionId: session.clientSessionId,
@@ -3459,7 +3480,7 @@ var PollarClient = class {
3459
3480
  this._scheduleNextRefresh();
3460
3481
  }
3461
3482
  async _clearSession() {
3462
- console.info("[PollarClient] Session cleared");
3483
+ this._log.info("[PollarClient] Session cleared");
3463
3484
  this._clearRefreshTimer();
3464
3485
  this._session = null;
3465
3486
  this._profile = null;
@@ -3468,7 +3489,7 @@ var PollarClient = class {
3468
3489
  try {
3469
3490
  await this._keyManager.reset();
3470
3491
  } catch (err) {
3471
- console.warn("[PollarClient] KeyManager reset failed during clearSession", err);
3492
+ this._log.warn("[PollarClient] KeyManager reset failed during clearSession", err);
3472
3493
  }
3473
3494
  await removeStorage(this._storage, this.apiKeyHash);
3474
3495
  this._transactionState = null;
@@ -3480,17 +3501,17 @@ var PollarClient = class {
3480
3501
  _setNetworkState(next) {
3481
3502
  this._networkState = next;
3482
3503
  const label = next.step === "connected" ? next.network : next.step;
3483
- console.info(`[PollarClient] network:${label}`);
3504
+ this._log.debug(`[PollarClient] network:${label}`);
3484
3505
  for (const cb of this._networkStateListeners) cb(next);
3485
3506
  }
3486
3507
  _setAuthState(next) {
3487
3508
  this._authState = next;
3488
- console.info(`[PollarClient] auth:${next.step}`);
3509
+ this._log.debug(`[PollarClient] auth:${next.step}`);
3489
3510
  for (const cb of this._authStateListeners) cb(next);
3490
3511
  }
3491
3512
  _setTransactionState(next) {
3492
3513
  this._transactionState = next;
3493
- console.info(`[PollarClient] transaction:${next.step}`);
3514
+ this._log.debug(`[PollarClient] transaction:${next.step}`);
3494
3515
  for (const cb of this._transactionStateListeners) cb(next);
3495
3516
  }
3496
3517
  /**
@@ -3538,6 +3559,6 @@ var StellarClient = class {
3538
3559
  // src/index.ts
3539
3560
  _setDefaultKeyManagerFactory((_storage, apiKey) => new WebCryptoKeyManager(apiKey));
3540
3561
 
3541
- export { AUTH_ERROR_CODES, AlbedoAdapter, FreighterAdapter, POLLAR_CORE_VERSION, PollarClient, StellarClient, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, resolveKyc, startKyc };
3562
+ export { AUTH_ERROR_CODES, AlbedoAdapter, FreighterAdapter, POLLAR_CORE_VERSION, PollarClient, StellarClient, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createLogger, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, resolveKyc, startKyc };
3542
3563
  //# sourceMappingURL=index.mjs.map
3543
3564
  //# sourceMappingURL=index.mjs.map