@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/README.md +35 -0
- package/dist/index.d.mts +55 -2
- package/dist/index.d.ts +55 -2
- package/dist/index.js +89 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -68
- package/dist/index.mjs.map +1 -1
- package/dist/index.rn.d.mts +1 -1
- package/dist/index.rn.d.ts +1 -1
- package/dist/index.rn.js +89 -68
- package/dist/index.rn.js.map +1 -1
- package/dist/index.rn.mjs +89 -69
- package/dist/index.rn.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.rn.mjs
CHANGED
|
@@ -302,7 +302,6 @@ var NobleKeyManager = class {
|
|
|
302
302
|
if (this.privateKey) return;
|
|
303
303
|
if (!this._initPromise) {
|
|
304
304
|
this._initPromise = this._doInit().catch((err) => {
|
|
305
|
-
console.error("[PollarClient:keys] NobleKeyManager init failed", err);
|
|
306
305
|
this._initPromise = null;
|
|
307
306
|
throw err;
|
|
308
307
|
});
|
|
@@ -1010,6 +1009,16 @@ function normalizeHtu(rawUrl) {
|
|
|
1010
1009
|
return `${scheme}//${host}${portPart}${url.pathname}`;
|
|
1011
1010
|
}
|
|
1012
1011
|
|
|
1012
|
+
// src/lib/logger.ts
|
|
1013
|
+
var RANK = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
1014
|
+
function createLogger(level = "info", sink = console) {
|
|
1015
|
+
const threshold = RANK[level];
|
|
1016
|
+
const gate = (lvl) => (...args) => {
|
|
1017
|
+
if (threshold >= RANK[lvl]) sink[lvl](...args);
|
|
1018
|
+
};
|
|
1019
|
+
return { error: gate("error"), warn: gate("warn"), info: gate("info"), debug: gate("debug") };
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1013
1022
|
// src/storage/web.ts
|
|
1014
1023
|
var LOG_PREFIX = "[PollarClient:storage]";
|
|
1015
1024
|
function createMemoryAdapter() {
|
|
@@ -1033,7 +1042,7 @@ function createLocalStorageAdapter(options = {}) {
|
|
|
1033
1042
|
function degrade(reason, error) {
|
|
1034
1043
|
if (degraded) return;
|
|
1035
1044
|
degraded = true;
|
|
1036
|
-
console.warn(`${LOG_PREFIX} localStorage unavailable (${reason}); degrading to in-memory storage`);
|
|
1045
|
+
(options.logger ?? console).warn(`${LOG_PREFIX} localStorage unavailable (${reason}); degrading to in-memory storage`);
|
|
1037
1046
|
options.onDegrade?.(reason, error);
|
|
1038
1047
|
}
|
|
1039
1048
|
return {
|
|
@@ -1098,7 +1107,7 @@ function defaultStorage(options = {}) {
|
|
|
1098
1107
|
}
|
|
1099
1108
|
|
|
1100
1109
|
// src/version.ts
|
|
1101
|
-
var POLLAR_CORE_VERSION = "0.9.0-rc.
|
|
1110
|
+
var POLLAR_CORE_VERSION = "0.9.0-rc.1" ;
|
|
1102
1111
|
|
|
1103
1112
|
// src/visibility/noop.ts
|
|
1104
1113
|
function createNoopVisibilityProvider() {
|
|
@@ -1382,85 +1391,85 @@ function isBoundedString(v, max, allowEmpty = false) {
|
|
|
1382
1391
|
if (!allowEmpty && v.length === 0) return false;
|
|
1383
1392
|
return v.length <= max;
|
|
1384
1393
|
}
|
|
1385
|
-
function isValidSession(value) {
|
|
1394
|
+
function isValidSession(value, logger = console) {
|
|
1386
1395
|
if (typeof value !== "object" || value === null) {
|
|
1387
|
-
|
|
1396
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 value is not an object");
|
|
1388
1397
|
return false;
|
|
1389
1398
|
}
|
|
1390
1399
|
const s = value;
|
|
1391
1400
|
if (!isBoundedString(s["clientSessionId"], MAX_CLIENT_SESSION_ID)) {
|
|
1392
|
-
|
|
1401
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 clientSessionId missing/empty/too long");
|
|
1393
1402
|
return false;
|
|
1394
1403
|
}
|
|
1395
1404
|
if (s["userId"] !== null && !isBoundedString(s["userId"], MAX_USER_ID)) {
|
|
1396
|
-
|
|
1405
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 userId must be string|null");
|
|
1397
1406
|
return false;
|
|
1398
1407
|
}
|
|
1399
1408
|
if (!isBoundedString(s["status"], MAX_STATUS)) {
|
|
1400
|
-
|
|
1409
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 status must be string");
|
|
1401
1410
|
return false;
|
|
1402
1411
|
}
|
|
1403
1412
|
const token = s["token"];
|
|
1404
1413
|
if (typeof token !== "object" || token === null) {
|
|
1405
|
-
|
|
1414
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 token missing or not an object");
|
|
1406
1415
|
return false;
|
|
1407
1416
|
}
|
|
1408
1417
|
const t = token;
|
|
1409
1418
|
if (!isBoundedString(t["accessToken"], MAX_ACCESS_TOKEN)) {
|
|
1410
|
-
|
|
1419
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 token.accessToken missing/empty/too long");
|
|
1411
1420
|
return false;
|
|
1412
1421
|
}
|
|
1413
1422
|
if (!isBoundedString(t["refreshToken"], MAX_REFRESH_TOKEN)) {
|
|
1414
|
-
|
|
1423
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 token.refreshToken missing/empty/too long");
|
|
1415
1424
|
return false;
|
|
1416
1425
|
}
|
|
1417
1426
|
if (typeof t["expiresAt"] !== "number" || !Number.isFinite(t["expiresAt"])) {
|
|
1418
|
-
|
|
1427
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 token.expiresAt must be a finite number");
|
|
1419
1428
|
return false;
|
|
1420
1429
|
}
|
|
1421
1430
|
const user = s["user"];
|
|
1422
1431
|
if (typeof user !== "object" || user === null) {
|
|
1423
|
-
|
|
1432
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 user missing or not an object");
|
|
1424
1433
|
return false;
|
|
1425
1434
|
}
|
|
1426
1435
|
const u = user;
|
|
1427
1436
|
if (u["id"] !== void 0 && !isBoundedString(u["id"], MAX_USER_ID)) {
|
|
1428
|
-
|
|
1437
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 user.id must be string if present");
|
|
1429
1438
|
return false;
|
|
1430
1439
|
}
|
|
1431
1440
|
if (typeof u["ready"] !== "boolean") {
|
|
1432
|
-
|
|
1441
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 user.ready must be boolean");
|
|
1433
1442
|
return false;
|
|
1434
1443
|
}
|
|
1435
1444
|
const wallet = s["wallet"];
|
|
1436
1445
|
if (typeof wallet !== "object" || wallet === null) {
|
|
1437
|
-
|
|
1446
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet missing or not an object");
|
|
1438
1447
|
return false;
|
|
1439
1448
|
}
|
|
1440
1449
|
const w = wallet;
|
|
1441
1450
|
if (w["type"] !== "custodial" && w["type"] !== "smart" && w["type"] !== "external") {
|
|
1442
|
-
|
|
1451
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.type must be custodial|smart|external");
|
|
1443
1452
|
return false;
|
|
1444
1453
|
}
|
|
1445
1454
|
if (w["address"] !== null && !isBoundedString(w["address"], MAX_WALLET_PUBLIC_KEY)) {
|
|
1446
|
-
|
|
1455
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.address must be string|null");
|
|
1447
1456
|
return false;
|
|
1448
1457
|
}
|
|
1449
1458
|
if (w["existsOnStellar"] !== void 0 && typeof w["existsOnStellar"] !== "boolean") {
|
|
1450
|
-
|
|
1459
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.existsOnStellar must be boolean if present");
|
|
1451
1460
|
return false;
|
|
1452
1461
|
}
|
|
1453
1462
|
if (w["createdAt"] !== void 0 && (typeof w["createdAt"] !== "number" || !Number.isFinite(w["createdAt"]))) {
|
|
1454
|
-
|
|
1463
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.createdAt must be a finite number if present");
|
|
1455
1464
|
return false;
|
|
1456
1465
|
}
|
|
1457
1466
|
if (w["linkedAt"] !== void 0 && (typeof w["linkedAt"] !== "number" || !Number.isFinite(w["linkedAt"]))) {
|
|
1458
|
-
|
|
1467
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.linkedAt must be a finite number if present");
|
|
1459
1468
|
return false;
|
|
1460
1469
|
}
|
|
1461
1470
|
return true;
|
|
1462
1471
|
}
|
|
1463
|
-
async function readStorage(storage, apiKeyHash) {
|
|
1472
|
+
async function readStorage(storage, apiKeyHash, logger = console) {
|
|
1464
1473
|
const raw = await storage.get(sessionStorageKey(apiKeyHash));
|
|
1465
1474
|
if (!raw) return null;
|
|
1466
1475
|
try {
|
|
@@ -1471,9 +1480,9 @@ async function readStorage(storage, apiKeyHash) {
|
|
|
1471
1480
|
w["address"] = w["publicKey"];
|
|
1472
1481
|
}
|
|
1473
1482
|
}
|
|
1474
|
-
if (!isValidSession(session)) {
|
|
1483
|
+
if (!isValidSession(session, logger)) {
|
|
1475
1484
|
await storage.remove(sessionStorageKey(apiKeyHash));
|
|
1476
|
-
|
|
1485
|
+
logger.warn("[PollarClient:session] Stored session is invalid \u2014 clearing storage");
|
|
1477
1486
|
return null;
|
|
1478
1487
|
}
|
|
1479
1488
|
if (session.token.expiresAt * 1e3 < Date.now()) {
|
|
@@ -1481,7 +1490,7 @@ async function readStorage(storage, apiKeyHash) {
|
|
|
1481
1490
|
}
|
|
1482
1491
|
return session;
|
|
1483
1492
|
} catch (error) {
|
|
1484
|
-
|
|
1493
|
+
logger.error("[PollarClient:session] Failed to parse session from storage", error);
|
|
1485
1494
|
await storage.remove(sessionStorageKey(apiKeyHash));
|
|
1486
1495
|
return null;
|
|
1487
1496
|
}
|
|
@@ -1543,7 +1552,7 @@ function abortableDelay(ms, signal) {
|
|
|
1543
1552
|
});
|
|
1544
1553
|
}
|
|
1545
1554
|
var MAX_BACKOFF_MS = 5e3;
|
|
1546
|
-
async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200, signal) {
|
|
1555
|
+
async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200, signal, logger = console) {
|
|
1547
1556
|
let backoff = retryDelayMs;
|
|
1548
1557
|
const sleep = async (ms) => {
|
|
1549
1558
|
if (ms <= 0) return;
|
|
@@ -1561,7 +1570,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
|
|
|
1561
1570
|
}));
|
|
1562
1571
|
} catch (e) {
|
|
1563
1572
|
if (e instanceof Error && e.name === "AbortError") throw e;
|
|
1564
|
-
|
|
1573
|
+
logger.debug("[PollarClient:stream] session-status request failed; will retry", e);
|
|
1565
1574
|
}
|
|
1566
1575
|
if (error || !data) {
|
|
1567
1576
|
await sleep(backoff);
|
|
@@ -1601,7 +1610,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
|
|
|
1601
1610
|
} catch (e) {
|
|
1602
1611
|
if (e instanceof Error && e.name === "AbortError") throw e;
|
|
1603
1612
|
if (e instanceof SessionStatusError) throw e;
|
|
1604
|
-
|
|
1613
|
+
logger.debug("[PollarClient:stream] session-status stream read failed; will retry", e);
|
|
1605
1614
|
} finally {
|
|
1606
1615
|
reader.releaseLock();
|
|
1607
1616
|
}
|
|
@@ -1611,7 +1620,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
|
|
|
1611
1620
|
if (delay) await sleep(delay);
|
|
1612
1621
|
}
|
|
1613
1622
|
}
|
|
1614
|
-
async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500, signal) {
|
|
1623
|
+
async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500, signal, logger = console) {
|
|
1615
1624
|
const url = `${baseUrl}/auth/session/status/${encodeURIComponent(clientSessionId)}/poll`;
|
|
1616
1625
|
let backoff = intervalMs;
|
|
1617
1626
|
const sleep = async (ms) => {
|
|
@@ -1629,7 +1638,7 @@ async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500,
|
|
|
1629
1638
|
envelope = await response.json().catch(() => null);
|
|
1630
1639
|
} catch (e) {
|
|
1631
1640
|
if (e instanceof Error && e.name === "AbortError") throw e;
|
|
1632
|
-
|
|
1641
|
+
logger.debug("[PollarClient:stream] session-status poll failed; will retry", e);
|
|
1633
1642
|
}
|
|
1634
1643
|
if (httpStatus === 404 || envelope?.code === "INVALID_CLIENT_SESSION_ID") {
|
|
1635
1644
|
throw new SessionStatusError("INVALID_CLIENT_SESSION_ID");
|
|
@@ -1646,13 +1655,13 @@ async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500,
|
|
|
1646
1655
|
}
|
|
1647
1656
|
}
|
|
1648
1657
|
function waitForSessionReady(args) {
|
|
1649
|
-
const { api, baseUrl, clientSessionId, check, useStreaming, retryDelayMs, signal } = args;
|
|
1650
|
-
return useStreaming ? streamUntilFound(api, clientSessionId, check, retryDelayMs ?? 200, signal) : pollUntilFound(baseUrl, clientSessionId, check, retryDelayMs ?? 500, signal);
|
|
1658
|
+
const { api, baseUrl, clientSessionId, check, useStreaming, retryDelayMs, signal, logger = console } = args;
|
|
1659
|
+
return useStreaming ? streamUntilFound(api, clientSessionId, check, retryDelayMs ?? 200, signal, logger) : pollUntilFound(baseUrl, clientSessionId, check, retryDelayMs ?? 500, signal, logger);
|
|
1651
1660
|
}
|
|
1652
1661
|
|
|
1653
1662
|
// src/client/auth/authenticate.ts
|
|
1654
1663
|
async function authenticate(clientSessionId, deps, expectedWallet) {
|
|
1655
|
-
const { api, basePath, useStreaming, signal, setAuthState, storeSession, clearSession } = deps;
|
|
1664
|
+
const { api, logger, basePath, useStreaming, signal, setAuthState, storeSession, clearSession } = deps;
|
|
1656
1665
|
setAuthState({ step: "authenticating" });
|
|
1657
1666
|
try {
|
|
1658
1667
|
await waitForSessionReady({
|
|
@@ -1661,7 +1670,8 @@ async function authenticate(clientSessionId, deps, expectedWallet) {
|
|
|
1661
1670
|
clientSessionId,
|
|
1662
1671
|
check: (data2) => data2?.status === "READY",
|
|
1663
1672
|
useStreaming,
|
|
1664
|
-
signal
|
|
1673
|
+
signal,
|
|
1674
|
+
logger
|
|
1665
1675
|
});
|
|
1666
1676
|
} catch (err) {
|
|
1667
1677
|
if (err instanceof SessionStatusError) {
|
|
@@ -1686,7 +1696,7 @@ async function authenticate(clientSessionId, deps, expectedWallet) {
|
|
|
1686
1696
|
},
|
|
1687
1697
|
signal
|
|
1688
1698
|
});
|
|
1689
|
-
if (data?.code === "SDK_LOGIN_SUCCESS" && isValidSession(data?.content)) {
|
|
1699
|
+
if (data?.code === "SDK_LOGIN_SUCCESS" && isValidSession(data?.content, logger)) {
|
|
1690
1700
|
if (expectedWallet && data.content.data.providers.wallet?.address !== expectedWallet) {
|
|
1691
1701
|
setAuthState({
|
|
1692
1702
|
step: "error",
|
|
@@ -2004,7 +2014,9 @@ var PollarClient = class {
|
|
|
2004
2014
|
this.apiKey = config.apiKey;
|
|
2005
2015
|
this.id = randomUUID();
|
|
2006
2016
|
this.basePath = `${config.baseUrl || "https://sdk.api.pollar.xyz"}/v1`;
|
|
2017
|
+
this._log = createLogger(config.logLevel ?? "info", config.logger);
|
|
2007
2018
|
this._storage = config.storage ?? defaultStorage({
|
|
2019
|
+
logger: this._log,
|
|
2008
2020
|
onDegrade: (reason, error) => {
|
|
2009
2021
|
config.onStorageDegrade?.(reason, error);
|
|
2010
2022
|
this._dispatchStorageDegrade(reason, error);
|
|
@@ -2028,7 +2040,7 @@ var PollarClient = class {
|
|
|
2028
2040
|
this._initialized = Promise.resolve();
|
|
2029
2041
|
return;
|
|
2030
2042
|
}
|
|
2031
|
-
|
|
2043
|
+
this._log.info(
|
|
2032
2044
|
`[PollarClient] Initialized v${POLLAR_CORE_VERSION} \u2014 endpoint: ${this.basePath}, network: ${this._networkState.network}`
|
|
2033
2045
|
);
|
|
2034
2046
|
this._initialized = this._initialize();
|
|
@@ -2055,7 +2067,7 @@ var PollarClient = class {
|
|
|
2055
2067
|
const sessionKey = sessionStorageKey(this._apiKeyHash);
|
|
2056
2068
|
const handler = (e) => {
|
|
2057
2069
|
if (e.key === sessionKey) {
|
|
2058
|
-
this._restoreSession().catch((err) =>
|
|
2070
|
+
this._restoreSession().catch((err) => this._log.error("[PollarClient] Cross-tab restore failed", err));
|
|
2059
2071
|
}
|
|
2060
2072
|
};
|
|
2061
2073
|
window.addEventListener("storage", handler);
|
|
@@ -2064,7 +2076,7 @@ var PollarClient = class {
|
|
|
2064
2076
|
try {
|
|
2065
2077
|
await this._keyManager.init();
|
|
2066
2078
|
} catch (err) {
|
|
2067
|
-
|
|
2079
|
+
this._log.warn("[PollarClient] KeyManager init failed; DPoP unavailable for this session", err);
|
|
2068
2080
|
}
|
|
2069
2081
|
await this._restoreSession();
|
|
2070
2082
|
this._visibilityUnsubscribe = this._visibilityProvider.onChange((visible) => {
|
|
@@ -2105,7 +2117,7 @@ var PollarClient = class {
|
|
|
2105
2117
|
try {
|
|
2106
2118
|
self._requestBodyCache.set(request, await request.clone().arrayBuffer());
|
|
2107
2119
|
} catch (err) {
|
|
2108
|
-
|
|
2120
|
+
this._log.warn("[PollarClient] Could not snapshot request body for retry", err);
|
|
2109
2121
|
}
|
|
2110
2122
|
}
|
|
2111
2123
|
const isRefresh = request.url.includes("/auth/refresh");
|
|
@@ -2164,7 +2176,7 @@ var PollarClient = class {
|
|
|
2164
2176
|
this._keyManager
|
|
2165
2177
|
);
|
|
2166
2178
|
} catch (err) {
|
|
2167
|
-
|
|
2179
|
+
this._log.warn("[PollarClient] DPoP proof build failed", err);
|
|
2168
2180
|
return null;
|
|
2169
2181
|
}
|
|
2170
2182
|
}
|
|
@@ -2218,7 +2230,7 @@ var PollarClient = class {
|
|
|
2218
2230
|
async _doRefresh() {
|
|
2219
2231
|
const refreshToken = this._session?.token?.refreshToken;
|
|
2220
2232
|
if (!refreshToken) {
|
|
2221
|
-
|
|
2233
|
+
this._log.warn("[PollarClient] Refresh skipped: no refresh token in session");
|
|
2222
2234
|
await this._clearSession();
|
|
2223
2235
|
throw new Error("No refresh token available");
|
|
2224
2236
|
}
|
|
@@ -2229,18 +2241,18 @@ var PollarClient = class {
|
|
|
2229
2241
|
data = response.data;
|
|
2230
2242
|
error = response.error;
|
|
2231
2243
|
} catch (err) {
|
|
2232
|
-
|
|
2244
|
+
this._log.error("[PollarClient] /auth/refresh request threw", err);
|
|
2233
2245
|
await this._clearSession();
|
|
2234
2246
|
throw err;
|
|
2235
2247
|
}
|
|
2236
2248
|
if (error || !data) {
|
|
2237
|
-
|
|
2249
|
+
this._log.error("[PollarClient] /auth/refresh returned error", { error });
|
|
2238
2250
|
await this._clearSession();
|
|
2239
2251
|
throw new Error("Refresh failed");
|
|
2240
2252
|
}
|
|
2241
2253
|
const successData = data;
|
|
2242
2254
|
if (!successData.success || !successData.content?.token) {
|
|
2243
|
-
|
|
2255
|
+
this._log.error("[PollarClient] /auth/refresh response malformed", {
|
|
2244
2256
|
success: successData.success,
|
|
2245
2257
|
hasToken: !!successData.content?.token
|
|
2246
2258
|
});
|
|
@@ -2249,7 +2261,7 @@ var PollarClient = class {
|
|
|
2249
2261
|
}
|
|
2250
2262
|
const newToken = successData.content.token;
|
|
2251
2263
|
if (typeof newToken.accessToken !== "string" || typeof newToken.refreshToken !== "string" || typeof newToken.expiresAt !== "number") {
|
|
2252
|
-
|
|
2264
|
+
this._log.error("[PollarClient] /auth/refresh token shape invalid", {
|
|
2253
2265
|
accessToken: typeof newToken.accessToken,
|
|
2254
2266
|
refreshToken: typeof newToken.refreshToken,
|
|
2255
2267
|
expiresAt: typeof newToken.expiresAt
|
|
@@ -2261,9 +2273,9 @@ var PollarClient = class {
|
|
|
2261
2273
|
try {
|
|
2262
2274
|
this._session = { ...this._session, token: newToken };
|
|
2263
2275
|
await writeStorage(this._storage, this.apiKeyHash, this._session);
|
|
2264
|
-
|
|
2276
|
+
this._log.info("[PollarClient] Tokens refreshed");
|
|
2265
2277
|
} catch (err) {
|
|
2266
|
-
|
|
2278
|
+
this._log.error("[PollarClient] Failed to persist refreshed session", err);
|
|
2267
2279
|
}
|
|
2268
2280
|
this._scheduleNextRefresh();
|
|
2269
2281
|
}
|
|
@@ -2317,7 +2329,7 @@ var PollarClient = class {
|
|
|
2317
2329
|
try {
|
|
2318
2330
|
await this.refresh();
|
|
2319
2331
|
} catch (err) {
|
|
2320
|
-
|
|
2332
|
+
this._log.warn("[PollarClient] Proactive refresh failed; session cleared", err);
|
|
2321
2333
|
}
|
|
2322
2334
|
}
|
|
2323
2335
|
_clearRefreshTimer() {
|
|
@@ -2363,7 +2375,7 @@ var PollarClient = class {
|
|
|
2363
2375
|
try {
|
|
2364
2376
|
cb(reason, error);
|
|
2365
2377
|
} catch (err) {
|
|
2366
|
-
|
|
2378
|
+
this._log.error("[PollarClient] onStorageDegrade listener threw", err);
|
|
2367
2379
|
}
|
|
2368
2380
|
}
|
|
2369
2381
|
}
|
|
@@ -2483,20 +2495,20 @@ var PollarClient = class {
|
|
|
2483
2495
|
warnServerSide("logout");
|
|
2484
2496
|
return;
|
|
2485
2497
|
}
|
|
2486
|
-
|
|
2498
|
+
this._log.info("[PollarClient] Logout requested", { everywhere: !!options.everywhere });
|
|
2487
2499
|
if (this._session?.token?.accessToken) {
|
|
2488
2500
|
try {
|
|
2489
2501
|
await this._api.POST("/auth/logout", {
|
|
2490
2502
|
body: options.everywhere ? { everywhere: true } : {}
|
|
2491
2503
|
});
|
|
2492
2504
|
} catch (err) {
|
|
2493
|
-
|
|
2505
|
+
this._log.warn("[PollarClient] Server logout failed (continuing with local clear)", err);
|
|
2494
2506
|
}
|
|
2495
2507
|
}
|
|
2496
2508
|
try {
|
|
2497
2509
|
await this._clearSession();
|
|
2498
2510
|
} catch (err) {
|
|
2499
|
-
|
|
2511
|
+
this._log.warn("[PollarClient] Local logout cleanup failed", err);
|
|
2500
2512
|
}
|
|
2501
2513
|
}
|
|
2502
2514
|
/** Convenience: revoke every active session for this user (all devices). */
|
|
@@ -2572,6 +2584,14 @@ var PollarClient = class {
|
|
|
2572
2584
|
getNetworkState() {
|
|
2573
2585
|
return this._networkState;
|
|
2574
2586
|
}
|
|
2587
|
+
/**
|
|
2588
|
+
* The client's level-gated logger (built from `logLevel` / `logger`). Exposed
|
|
2589
|
+
* so the runtime layer (`@pollar/react`) can route its own logs through the
|
|
2590
|
+
* same level and sink instead of calling `console` directly.
|
|
2591
|
+
*/
|
|
2592
|
+
getLogger() {
|
|
2593
|
+
return this._log;
|
|
2594
|
+
}
|
|
2575
2595
|
setNetwork(network) {
|
|
2576
2596
|
this._setNetworkState({ step: "connected", network });
|
|
2577
2597
|
}
|
|
@@ -2720,7 +2740,7 @@ var PollarClient = class {
|
|
|
2720
2740
|
this._setTransactionState({ step: "error", phase: "building", ...details && { details } });
|
|
2721
2741
|
return { status: "error", ...details && { details } };
|
|
2722
2742
|
} catch (err) {
|
|
2723
|
-
|
|
2743
|
+
this._log.error("[PollarClient] buildTx failed", err);
|
|
2724
2744
|
this._setTransactionState({ step: "error", phase: "building" });
|
|
2725
2745
|
return { status: "error" };
|
|
2726
2746
|
}
|
|
@@ -3233,6 +3253,7 @@ var PollarClient = class {
|
|
|
3233
3253
|
_flowDeps(signal) {
|
|
3234
3254
|
return {
|
|
3235
3255
|
api: this._api,
|
|
3256
|
+
logger: this._log,
|
|
3236
3257
|
basePath: this.basePath,
|
|
3237
3258
|
// SSE status streaming works on web; React Native's `fetch` has no
|
|
3238
3259
|
// readable `response.body`, so those clients poll the non-streaming
|
|
@@ -3285,12 +3306,12 @@ var PollarClient = class {
|
|
|
3285
3306
|
}
|
|
3286
3307
|
_handleFlowError(error) {
|
|
3287
3308
|
if (error instanceof Error && error.name === "AbortError") {
|
|
3288
|
-
|
|
3309
|
+
this._log.debug("[PollarClient] Login cancelled");
|
|
3289
3310
|
this._setAuthState({ step: "idle" });
|
|
3290
3311
|
return;
|
|
3291
3312
|
}
|
|
3292
3313
|
if (error instanceof Error && error.code === AUTH_ERROR_CODES.WALLET_RESOLVER_TIMEOUT) {
|
|
3293
|
-
|
|
3314
|
+
this._log.error("[PollarClient]", error.message);
|
|
3294
3315
|
this._setAuthState({
|
|
3295
3316
|
step: "error",
|
|
3296
3317
|
previousStep: this._authState.step,
|
|
@@ -3299,7 +3320,7 @@ var PollarClient = class {
|
|
|
3299
3320
|
});
|
|
3300
3321
|
return;
|
|
3301
3322
|
}
|
|
3302
|
-
|
|
3323
|
+
this._log.error("[PollarClient] Unexpected error in auth flow", error);
|
|
3303
3324
|
this._setAuthState({
|
|
3304
3325
|
step: "error",
|
|
3305
3326
|
previousStep: this._authState.step,
|
|
@@ -3308,22 +3329,22 @@ var PollarClient = class {
|
|
|
3308
3329
|
});
|
|
3309
3330
|
}
|
|
3310
3331
|
async _restoreSession() {
|
|
3311
|
-
this._session = await readStorage(this._storage, this.apiKeyHash);
|
|
3332
|
+
this._session = await readStorage(this._storage, this.apiKeyHash, this._log);
|
|
3312
3333
|
if (this._session) {
|
|
3313
3334
|
const storedType = await readWalletType(this._storage, this.apiKeyHash);
|
|
3314
3335
|
if (storedType) {
|
|
3315
3336
|
try {
|
|
3316
3337
|
this._walletAdapter = await this._resolveWalletAdapter(storedType);
|
|
3317
3338
|
} catch (err) {
|
|
3318
|
-
|
|
3339
|
+
this._log.warn("[PollarClient] Could not restore wallet adapter for stored id", { id: storedType, err });
|
|
3319
3340
|
}
|
|
3320
3341
|
}
|
|
3321
|
-
|
|
3342
|
+
this._log.info("[PollarClient] Session restored from storage");
|
|
3322
3343
|
this._setAuthState({ step: "authenticated", session: this._session, verified: false });
|
|
3323
3344
|
this._scheduleNextRefresh();
|
|
3324
3345
|
void this._resume();
|
|
3325
3346
|
} else {
|
|
3326
|
-
|
|
3347
|
+
this._log.info("[PollarClient] No session in storage");
|
|
3327
3348
|
}
|
|
3328
3349
|
}
|
|
3329
3350
|
/**
|
|
@@ -3354,13 +3375,13 @@ var PollarClient = class {
|
|
|
3354
3375
|
this._setAuthState({ step: "authenticated", session: this._session, verified: true });
|
|
3355
3376
|
} catch (err) {
|
|
3356
3377
|
if (err?.name === "AbortError") return;
|
|
3357
|
-
|
|
3378
|
+
this._log.warn("[PollarClient] resume failed (network); will retry", err);
|
|
3358
3379
|
} finally {
|
|
3359
3380
|
if (this._resumeController === controller) this._resumeController = null;
|
|
3360
3381
|
}
|
|
3361
3382
|
}
|
|
3362
3383
|
async _storeSession(session) {
|
|
3363
|
-
|
|
3384
|
+
this._log.info("[PollarClient] Session stored");
|
|
3364
3385
|
const w = session.wallet;
|
|
3365
3386
|
const persisted = {
|
|
3366
3387
|
clientSessionId: session.clientSessionId,
|
|
@@ -3395,7 +3416,7 @@ var PollarClient = class {
|
|
|
3395
3416
|
this._scheduleNextRefresh();
|
|
3396
3417
|
}
|
|
3397
3418
|
async _clearSession() {
|
|
3398
|
-
|
|
3419
|
+
this._log.info("[PollarClient] Session cleared");
|
|
3399
3420
|
this._clearRefreshTimer();
|
|
3400
3421
|
this._session = null;
|
|
3401
3422
|
this._profile = null;
|
|
@@ -3404,7 +3425,7 @@ var PollarClient = class {
|
|
|
3404
3425
|
try {
|
|
3405
3426
|
await this._keyManager.reset();
|
|
3406
3427
|
} catch (err) {
|
|
3407
|
-
|
|
3428
|
+
this._log.warn("[PollarClient] KeyManager reset failed during clearSession", err);
|
|
3408
3429
|
}
|
|
3409
3430
|
await removeStorage(this._storage, this.apiKeyHash);
|
|
3410
3431
|
this._transactionState = null;
|
|
@@ -3416,17 +3437,17 @@ var PollarClient = class {
|
|
|
3416
3437
|
_setNetworkState(next) {
|
|
3417
3438
|
this._networkState = next;
|
|
3418
3439
|
const label = next.step === "connected" ? next.network : next.step;
|
|
3419
|
-
|
|
3440
|
+
this._log.debug(`[PollarClient] network:${label}`);
|
|
3420
3441
|
for (const cb of this._networkStateListeners) cb(next);
|
|
3421
3442
|
}
|
|
3422
3443
|
_setAuthState(next) {
|
|
3423
3444
|
this._authState = next;
|
|
3424
|
-
|
|
3445
|
+
this._log.debug(`[PollarClient] auth:${next.step}`);
|
|
3425
3446
|
for (const cb of this._authStateListeners) cb(next);
|
|
3426
3447
|
}
|
|
3427
3448
|
_setTransactionState(next) {
|
|
3428
3449
|
this._transactionState = next;
|
|
3429
|
-
|
|
3450
|
+
this._log.debug(`[PollarClient] transaction:${next.step}`);
|
|
3430
3451
|
for (const cb of this._transactionStateListeners) cb(next);
|
|
3431
3452
|
}
|
|
3432
3453
|
/**
|
|
@@ -3530,7 +3551,6 @@ var WebCryptoKeyManager = class {
|
|
|
3530
3551
|
if (this.keyPair) return;
|
|
3531
3552
|
if (!this._initPromise) {
|
|
3532
3553
|
this._initPromise = this._doInit().catch((err) => {
|
|
3533
|
-
console.error("[PollarClient:keys] WebCryptoKeyManager init failed", err);
|
|
3534
3554
|
this._initPromise = null;
|
|
3535
3555
|
throw err;
|
|
3536
3556
|
});
|
|
@@ -3666,6 +3686,6 @@ _setDefaultKeyManagerFactory((storage, apiKey) => {
|
|
|
3666
3686
|
return new NobleKeyManager(storage, apiKey);
|
|
3667
3687
|
});
|
|
3668
3688
|
|
|
3669
|
-
export { AUTH_ERROR_CODES, AlbedoAdapter, FreighterAdapter, NobleKeyManager, 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 };
|
|
3689
|
+
export { AUTH_ERROR_CODES, AlbedoAdapter, FreighterAdapter, NobleKeyManager, 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 };
|
|
3670
3690
|
//# sourceMappingURL=index.rn.mjs.map
|
|
3671
3691
|
//# sourceMappingURL=index.rn.mjs.map
|