@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.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyManager, PublicEcJwk } from './index.mjs';
|
|
2
|
-
export { AUTH_ERROR_CODES, AdapterFn, AlbedoAdapter, AuthErrorCode, AuthOpenContext, AuthState, AuthUrlOpener, BuildOutcome, BuildProofArgs, ConnectWalletResponse, DistributionClaimBody, DistributionClaimContent, DistributionRule, DistributionRulesState, EnabledAssetRecord, EnabledAssetsState, FreighterAdapter, KycFlow, KycLevel, KycProvider, KycStartBody, KycStartResponse, KycStatus, LocalStorageAdapterOptions, NetworkState, POLLAR_CORE_VERSION, PasskeyCeremony, PasskeySigner, PaymentInstructions, PollarAdapter, PollarAdapters, PollarApiClient, PollarApplicationConfigContent, PollarApplicationConfigResponse, PollarClient, PollarClientConfig, PollarFlowError, PollarLoginOptions, PollarPersistedSession, PollarUserProfile, RampDirection, RampQuote, RampTxStatus, RampsOfframpBody, RampsOfframpResponse, RampsOnrampBody, RampsOnrampResponse, RampsQuoteQuery, RampsQuoteResponse, RampsTransactionResponse, RulePeriod, SessionInfo, SessionsState, SignAuthEntryOptions, SignAuthEntryResponse, SignOutcome, SignTransactionOptions, SignTransactionResponse, StellarBalance, StellarClient, StellarClientConfig, StellarNetwork, SubmitOutcome, TransactionState, TxBuildBody, TxBuildContent, TxBuildResponse, TxBuildSignSubmitBody, TxBuildSignSubmitContent, TxBuildSignSubmitResponse, TxErrorPhase, TxHistoryContent, TxHistoryParams, TxHistoryRecord, TxHistoryState, TxSignAndSendBody, TxSignBody, TxSignContent, TxSignResponse, TxSignSendResponse, TxSubmitSignedBody, WalletAdapter, WalletAdapterResolver, WalletAssetsContent, WalletBalanceContent, WalletBalanceRecord, WalletBalanceState, WalletId, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, pollarPaths, resolveKyc, startKyc } from './index.mjs';
|
|
2
|
+
export { AUTH_ERROR_CODES, AdapterFn, AlbedoAdapter, AuthErrorCode, AuthOpenContext, AuthState, AuthUrlOpener, BuildOutcome, BuildProofArgs, ConnectWalletResponse, DistributionClaimBody, DistributionClaimContent, DistributionRule, DistributionRulesState, EnabledAssetRecord, EnabledAssetsState, FreighterAdapter, KycFlow, KycLevel, KycProvider, KycStartBody, KycStartResponse, KycStatus, LocalStorageAdapterOptions, LogLevel, NetworkState, POLLAR_CORE_VERSION, PasskeyCeremony, PasskeySigner, PaymentInstructions, PollarAdapter, PollarAdapters, PollarApiClient, PollarApplicationConfigContent, PollarApplicationConfigResponse, PollarClient, PollarClientConfig, PollarFlowError, PollarLogger, PollarLoginOptions, PollarPersistedSession, PollarUserProfile, RampDirection, RampQuote, RampTxStatus, RampsOfframpBody, RampsOfframpResponse, RampsOnrampBody, RampsOnrampResponse, RampsQuoteQuery, RampsQuoteResponse, RampsTransactionResponse, RulePeriod, SessionInfo, SessionsState, SignAuthEntryOptions, SignAuthEntryResponse, SignOutcome, SignTransactionOptions, SignTransactionResponse, StellarBalance, StellarClient, StellarClientConfig, StellarNetwork, SubmitOutcome, TransactionState, TxBuildBody, TxBuildContent, TxBuildResponse, TxBuildSignSubmitBody, TxBuildSignSubmitContent, TxBuildSignSubmitResponse, TxErrorPhase, TxHistoryContent, TxHistoryParams, TxHistoryRecord, TxHistoryState, TxSignAndSendBody, TxSignBody, TxSignContent, TxSignResponse, TxSignSendResponse, TxSubmitSignedBody, WalletAdapter, WalletAdapterResolver, WalletAssetsContent, WalletBalanceContent, WalletBalanceRecord, WalletBalanceState, WalletId, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createLogger, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, pollarPaths, resolveKyc, startKyc } from './index.mjs';
|
|
3
3
|
import { S as Storage } from './types-DqgJIJBl.mjs';
|
|
4
4
|
export { O as OnStorageDegrade, a as StorageDegradeReason } from './types-DqgJIJBl.mjs';
|
|
5
5
|
import './types-Dyky8g0p.mjs';
|
package/dist/index.rn.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyManager, PublicEcJwk } from './index.js';
|
|
2
|
-
export { AUTH_ERROR_CODES, AdapterFn, AlbedoAdapter, AuthErrorCode, AuthOpenContext, AuthState, AuthUrlOpener, BuildOutcome, BuildProofArgs, ConnectWalletResponse, DistributionClaimBody, DistributionClaimContent, DistributionRule, DistributionRulesState, EnabledAssetRecord, EnabledAssetsState, FreighterAdapter, KycFlow, KycLevel, KycProvider, KycStartBody, KycStartResponse, KycStatus, LocalStorageAdapterOptions, NetworkState, POLLAR_CORE_VERSION, PasskeyCeremony, PasskeySigner, PaymentInstructions, PollarAdapter, PollarAdapters, PollarApiClient, PollarApplicationConfigContent, PollarApplicationConfigResponse, PollarClient, PollarClientConfig, PollarFlowError, PollarLoginOptions, PollarPersistedSession, PollarUserProfile, RampDirection, RampQuote, RampTxStatus, RampsOfframpBody, RampsOfframpResponse, RampsOnrampBody, RampsOnrampResponse, RampsQuoteQuery, RampsQuoteResponse, RampsTransactionResponse, RulePeriod, SessionInfo, SessionsState, SignAuthEntryOptions, SignAuthEntryResponse, SignOutcome, SignTransactionOptions, SignTransactionResponse, StellarBalance, StellarClient, StellarClientConfig, StellarNetwork, SubmitOutcome, TransactionState, TxBuildBody, TxBuildContent, TxBuildResponse, TxBuildSignSubmitBody, TxBuildSignSubmitContent, TxBuildSignSubmitResponse, TxErrorPhase, TxHistoryContent, TxHistoryParams, TxHistoryRecord, TxHistoryState, TxSignAndSendBody, TxSignBody, TxSignContent, TxSignResponse, TxSignSendResponse, TxSubmitSignedBody, WalletAdapter, WalletAdapterResolver, WalletAssetsContent, WalletBalanceContent, WalletBalanceRecord, WalletBalanceState, WalletId, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, pollarPaths, resolveKyc, startKyc } from './index.js';
|
|
2
|
+
export { AUTH_ERROR_CODES, AdapterFn, AlbedoAdapter, AuthErrorCode, AuthOpenContext, AuthState, AuthUrlOpener, BuildOutcome, BuildProofArgs, ConnectWalletResponse, DistributionClaimBody, DistributionClaimContent, DistributionRule, DistributionRulesState, EnabledAssetRecord, EnabledAssetsState, FreighterAdapter, KycFlow, KycLevel, KycProvider, KycStartBody, KycStartResponse, KycStatus, LocalStorageAdapterOptions, LogLevel, NetworkState, POLLAR_CORE_VERSION, PasskeyCeremony, PasskeySigner, PaymentInstructions, PollarAdapter, PollarAdapters, PollarApiClient, PollarApplicationConfigContent, PollarApplicationConfigResponse, PollarClient, PollarClientConfig, PollarFlowError, PollarLogger, PollarLoginOptions, PollarPersistedSession, PollarUserProfile, RampDirection, RampQuote, RampTxStatus, RampsOfframpBody, RampsOfframpResponse, RampsOnrampBody, RampsOnrampResponse, RampsQuoteQuery, RampsQuoteResponse, RampsTransactionResponse, RulePeriod, SessionInfo, SessionsState, SignAuthEntryOptions, SignAuthEntryResponse, SignOutcome, SignTransactionOptions, SignTransactionResponse, StellarBalance, StellarClient, StellarClientConfig, StellarNetwork, SubmitOutcome, TransactionState, TxBuildBody, TxBuildContent, TxBuildResponse, TxBuildSignSubmitBody, TxBuildSignSubmitContent, TxBuildSignSubmitResponse, TxErrorPhase, TxHistoryContent, TxHistoryParams, TxHistoryRecord, TxHistoryState, TxSignAndSendBody, TxSignBody, TxSignContent, TxSignResponse, TxSignSendResponse, TxSubmitSignedBody, WalletAdapter, WalletAdapterResolver, WalletAssetsContent, WalletBalanceContent, WalletBalanceRecord, WalletBalanceState, WalletId, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createLogger, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, pollarPaths, resolveKyc, startKyc } from './index.js';
|
|
3
3
|
import { S as Storage } from './types-DqgJIJBl.js';
|
|
4
4
|
export { O as OnStorageDegrade, a as StorageDegradeReason } from './types-DqgJIJBl.js';
|
|
5
5
|
import './types-Dyky8g0p.js';
|
package/dist/index.rn.js
CHANGED
|
@@ -304,7 +304,6 @@ var NobleKeyManager = class {
|
|
|
304
304
|
if (this.privateKey) return;
|
|
305
305
|
if (!this._initPromise) {
|
|
306
306
|
this._initPromise = this._doInit().catch((err) => {
|
|
307
|
-
console.error("[PollarClient:keys] NobleKeyManager init failed", err);
|
|
308
307
|
this._initPromise = null;
|
|
309
308
|
throw err;
|
|
310
309
|
});
|
|
@@ -1012,6 +1011,16 @@ function normalizeHtu(rawUrl) {
|
|
|
1012
1011
|
return `${scheme}//${host}${portPart}${url.pathname}`;
|
|
1013
1012
|
}
|
|
1014
1013
|
|
|
1014
|
+
// src/lib/logger.ts
|
|
1015
|
+
var RANK = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
1016
|
+
function createLogger(level = "info", sink = console) {
|
|
1017
|
+
const threshold = RANK[level];
|
|
1018
|
+
const gate = (lvl) => (...args) => {
|
|
1019
|
+
if (threshold >= RANK[lvl]) sink[lvl](...args);
|
|
1020
|
+
};
|
|
1021
|
+
return { error: gate("error"), warn: gate("warn"), info: gate("info"), debug: gate("debug") };
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1015
1024
|
// src/storage/web.ts
|
|
1016
1025
|
var LOG_PREFIX = "[PollarClient:storage]";
|
|
1017
1026
|
function createMemoryAdapter() {
|
|
@@ -1035,7 +1044,7 @@ function createLocalStorageAdapter(options = {}) {
|
|
|
1035
1044
|
function degrade(reason, error) {
|
|
1036
1045
|
if (degraded) return;
|
|
1037
1046
|
degraded = true;
|
|
1038
|
-
console.warn(`${LOG_PREFIX} localStorage unavailable (${reason}); degrading to in-memory storage`);
|
|
1047
|
+
(options.logger ?? console).warn(`${LOG_PREFIX} localStorage unavailable (${reason}); degrading to in-memory storage`);
|
|
1039
1048
|
options.onDegrade?.(reason, error);
|
|
1040
1049
|
}
|
|
1041
1050
|
return {
|
|
@@ -1100,7 +1109,7 @@ function defaultStorage(options = {}) {
|
|
|
1100
1109
|
}
|
|
1101
1110
|
|
|
1102
1111
|
// src/version.ts
|
|
1103
|
-
var POLLAR_CORE_VERSION = "0.9.0-rc.
|
|
1112
|
+
var POLLAR_CORE_VERSION = "0.9.0-rc.1" ;
|
|
1104
1113
|
|
|
1105
1114
|
// src/visibility/noop.ts
|
|
1106
1115
|
function createNoopVisibilityProvider() {
|
|
@@ -1384,85 +1393,85 @@ function isBoundedString(v, max, allowEmpty = false) {
|
|
|
1384
1393
|
if (!allowEmpty && v.length === 0) return false;
|
|
1385
1394
|
return v.length <= max;
|
|
1386
1395
|
}
|
|
1387
|
-
function isValidSession(value) {
|
|
1396
|
+
function isValidSession(value, logger = console) {
|
|
1388
1397
|
if (typeof value !== "object" || value === null) {
|
|
1389
|
-
|
|
1398
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 value is not an object");
|
|
1390
1399
|
return false;
|
|
1391
1400
|
}
|
|
1392
1401
|
const s = value;
|
|
1393
1402
|
if (!isBoundedString(s["clientSessionId"], MAX_CLIENT_SESSION_ID)) {
|
|
1394
|
-
|
|
1403
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 clientSessionId missing/empty/too long");
|
|
1395
1404
|
return false;
|
|
1396
1405
|
}
|
|
1397
1406
|
if (s["userId"] !== null && !isBoundedString(s["userId"], MAX_USER_ID)) {
|
|
1398
|
-
|
|
1407
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 userId must be string|null");
|
|
1399
1408
|
return false;
|
|
1400
1409
|
}
|
|
1401
1410
|
if (!isBoundedString(s["status"], MAX_STATUS)) {
|
|
1402
|
-
|
|
1411
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 status must be string");
|
|
1403
1412
|
return false;
|
|
1404
1413
|
}
|
|
1405
1414
|
const token = s["token"];
|
|
1406
1415
|
if (typeof token !== "object" || token === null) {
|
|
1407
|
-
|
|
1416
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 token missing or not an object");
|
|
1408
1417
|
return false;
|
|
1409
1418
|
}
|
|
1410
1419
|
const t = token;
|
|
1411
1420
|
if (!isBoundedString(t["accessToken"], MAX_ACCESS_TOKEN)) {
|
|
1412
|
-
|
|
1421
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 token.accessToken missing/empty/too long");
|
|
1413
1422
|
return false;
|
|
1414
1423
|
}
|
|
1415
1424
|
if (!isBoundedString(t["refreshToken"], MAX_REFRESH_TOKEN)) {
|
|
1416
|
-
|
|
1425
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 token.refreshToken missing/empty/too long");
|
|
1417
1426
|
return false;
|
|
1418
1427
|
}
|
|
1419
1428
|
if (typeof t["expiresAt"] !== "number" || !Number.isFinite(t["expiresAt"])) {
|
|
1420
|
-
|
|
1429
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 token.expiresAt must be a finite number");
|
|
1421
1430
|
return false;
|
|
1422
1431
|
}
|
|
1423
1432
|
const user = s["user"];
|
|
1424
1433
|
if (typeof user !== "object" || user === null) {
|
|
1425
|
-
|
|
1434
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 user missing or not an object");
|
|
1426
1435
|
return false;
|
|
1427
1436
|
}
|
|
1428
1437
|
const u = user;
|
|
1429
1438
|
if (u["id"] !== void 0 && !isBoundedString(u["id"], MAX_USER_ID)) {
|
|
1430
|
-
|
|
1439
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 user.id must be string if present");
|
|
1431
1440
|
return false;
|
|
1432
1441
|
}
|
|
1433
1442
|
if (typeof u["ready"] !== "boolean") {
|
|
1434
|
-
|
|
1443
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 user.ready must be boolean");
|
|
1435
1444
|
return false;
|
|
1436
1445
|
}
|
|
1437
1446
|
const wallet = s["wallet"];
|
|
1438
1447
|
if (typeof wallet !== "object" || wallet === null) {
|
|
1439
|
-
|
|
1448
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet missing or not an object");
|
|
1440
1449
|
return false;
|
|
1441
1450
|
}
|
|
1442
1451
|
const w = wallet;
|
|
1443
1452
|
if (w["type"] !== "custodial" && w["type"] !== "smart" && w["type"] !== "external") {
|
|
1444
|
-
|
|
1453
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.type must be custodial|smart|external");
|
|
1445
1454
|
return false;
|
|
1446
1455
|
}
|
|
1447
1456
|
if (w["address"] !== null && !isBoundedString(w["address"], MAX_WALLET_PUBLIC_KEY)) {
|
|
1448
|
-
|
|
1457
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.address must be string|null");
|
|
1449
1458
|
return false;
|
|
1450
1459
|
}
|
|
1451
1460
|
if (w["existsOnStellar"] !== void 0 && typeof w["existsOnStellar"] !== "boolean") {
|
|
1452
|
-
|
|
1461
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.existsOnStellar must be boolean if present");
|
|
1453
1462
|
return false;
|
|
1454
1463
|
}
|
|
1455
1464
|
if (w["createdAt"] !== void 0 && (typeof w["createdAt"] !== "number" || !Number.isFinite(w["createdAt"]))) {
|
|
1456
|
-
|
|
1465
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.createdAt must be a finite number if present");
|
|
1457
1466
|
return false;
|
|
1458
1467
|
}
|
|
1459
1468
|
if (w["linkedAt"] !== void 0 && (typeof w["linkedAt"] !== "number" || !Number.isFinite(w["linkedAt"]))) {
|
|
1460
|
-
|
|
1469
|
+
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.linkedAt must be a finite number if present");
|
|
1461
1470
|
return false;
|
|
1462
1471
|
}
|
|
1463
1472
|
return true;
|
|
1464
1473
|
}
|
|
1465
|
-
async function readStorage(storage, apiKeyHash) {
|
|
1474
|
+
async function readStorage(storage, apiKeyHash, logger = console) {
|
|
1466
1475
|
const raw = await storage.get(sessionStorageKey(apiKeyHash));
|
|
1467
1476
|
if (!raw) return null;
|
|
1468
1477
|
try {
|
|
@@ -1473,9 +1482,9 @@ async function readStorage(storage, apiKeyHash) {
|
|
|
1473
1482
|
w["address"] = w["publicKey"];
|
|
1474
1483
|
}
|
|
1475
1484
|
}
|
|
1476
|
-
if (!isValidSession(session)) {
|
|
1485
|
+
if (!isValidSession(session, logger)) {
|
|
1477
1486
|
await storage.remove(sessionStorageKey(apiKeyHash));
|
|
1478
|
-
|
|
1487
|
+
logger.warn("[PollarClient:session] Stored session is invalid \u2014 clearing storage");
|
|
1479
1488
|
return null;
|
|
1480
1489
|
}
|
|
1481
1490
|
if (session.token.expiresAt * 1e3 < Date.now()) {
|
|
@@ -1483,7 +1492,7 @@ async function readStorage(storage, apiKeyHash) {
|
|
|
1483
1492
|
}
|
|
1484
1493
|
return session;
|
|
1485
1494
|
} catch (error) {
|
|
1486
|
-
|
|
1495
|
+
logger.error("[PollarClient:session] Failed to parse session from storage", error);
|
|
1487
1496
|
await storage.remove(sessionStorageKey(apiKeyHash));
|
|
1488
1497
|
return null;
|
|
1489
1498
|
}
|
|
@@ -1545,7 +1554,7 @@ function abortableDelay(ms, signal) {
|
|
|
1545
1554
|
});
|
|
1546
1555
|
}
|
|
1547
1556
|
var MAX_BACKOFF_MS = 5e3;
|
|
1548
|
-
async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200, signal) {
|
|
1557
|
+
async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200, signal, logger = console) {
|
|
1549
1558
|
let backoff = retryDelayMs;
|
|
1550
1559
|
const sleep = async (ms) => {
|
|
1551
1560
|
if (ms <= 0) return;
|
|
@@ -1563,7 +1572,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
|
|
|
1563
1572
|
}));
|
|
1564
1573
|
} catch (e) {
|
|
1565
1574
|
if (e instanceof Error && e.name === "AbortError") throw e;
|
|
1566
|
-
|
|
1575
|
+
logger.debug("[PollarClient:stream] session-status request failed; will retry", e);
|
|
1567
1576
|
}
|
|
1568
1577
|
if (error || !data) {
|
|
1569
1578
|
await sleep(backoff);
|
|
@@ -1603,7 +1612,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
|
|
|
1603
1612
|
} catch (e) {
|
|
1604
1613
|
if (e instanceof Error && e.name === "AbortError") throw e;
|
|
1605
1614
|
if (e instanceof SessionStatusError) throw e;
|
|
1606
|
-
|
|
1615
|
+
logger.debug("[PollarClient:stream] session-status stream read failed; will retry", e);
|
|
1607
1616
|
} finally {
|
|
1608
1617
|
reader.releaseLock();
|
|
1609
1618
|
}
|
|
@@ -1613,7 +1622,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
|
|
|
1613
1622
|
if (delay) await sleep(delay);
|
|
1614
1623
|
}
|
|
1615
1624
|
}
|
|
1616
|
-
async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500, signal) {
|
|
1625
|
+
async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500, signal, logger = console) {
|
|
1617
1626
|
const url = `${baseUrl}/auth/session/status/${encodeURIComponent(clientSessionId)}/poll`;
|
|
1618
1627
|
let backoff = intervalMs;
|
|
1619
1628
|
const sleep = async (ms) => {
|
|
@@ -1631,7 +1640,7 @@ async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500,
|
|
|
1631
1640
|
envelope = await response.json().catch(() => null);
|
|
1632
1641
|
} catch (e) {
|
|
1633
1642
|
if (e instanceof Error && e.name === "AbortError") throw e;
|
|
1634
|
-
|
|
1643
|
+
logger.debug("[PollarClient:stream] session-status poll failed; will retry", e);
|
|
1635
1644
|
}
|
|
1636
1645
|
if (httpStatus === 404 || envelope?.code === "INVALID_CLIENT_SESSION_ID") {
|
|
1637
1646
|
throw new SessionStatusError("INVALID_CLIENT_SESSION_ID");
|
|
@@ -1648,13 +1657,13 @@ async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500,
|
|
|
1648
1657
|
}
|
|
1649
1658
|
}
|
|
1650
1659
|
function waitForSessionReady(args) {
|
|
1651
|
-
const { api, baseUrl, clientSessionId, check, useStreaming, retryDelayMs, signal } = args;
|
|
1652
|
-
return useStreaming ? streamUntilFound(api, clientSessionId, check, retryDelayMs ?? 200, signal) : pollUntilFound(baseUrl, clientSessionId, check, retryDelayMs ?? 500, signal);
|
|
1660
|
+
const { api, baseUrl, clientSessionId, check, useStreaming, retryDelayMs, signal, logger = console } = args;
|
|
1661
|
+
return useStreaming ? streamUntilFound(api, clientSessionId, check, retryDelayMs ?? 200, signal, logger) : pollUntilFound(baseUrl, clientSessionId, check, retryDelayMs ?? 500, signal, logger);
|
|
1653
1662
|
}
|
|
1654
1663
|
|
|
1655
1664
|
// src/client/auth/authenticate.ts
|
|
1656
1665
|
async function authenticate(clientSessionId, deps, expectedWallet) {
|
|
1657
|
-
const { api, basePath, useStreaming, signal, setAuthState, storeSession, clearSession } = deps;
|
|
1666
|
+
const { api, logger, basePath, useStreaming, signal, setAuthState, storeSession, clearSession } = deps;
|
|
1658
1667
|
setAuthState({ step: "authenticating" });
|
|
1659
1668
|
try {
|
|
1660
1669
|
await waitForSessionReady({
|
|
@@ -1663,7 +1672,8 @@ async function authenticate(clientSessionId, deps, expectedWallet) {
|
|
|
1663
1672
|
clientSessionId,
|
|
1664
1673
|
check: (data2) => data2?.status === "READY",
|
|
1665
1674
|
useStreaming,
|
|
1666
|
-
signal
|
|
1675
|
+
signal,
|
|
1676
|
+
logger
|
|
1667
1677
|
});
|
|
1668
1678
|
} catch (err) {
|
|
1669
1679
|
if (err instanceof SessionStatusError) {
|
|
@@ -1688,7 +1698,7 @@ async function authenticate(clientSessionId, deps, expectedWallet) {
|
|
|
1688
1698
|
},
|
|
1689
1699
|
signal
|
|
1690
1700
|
});
|
|
1691
|
-
if (data?.code === "SDK_LOGIN_SUCCESS" && isValidSession(data?.content)) {
|
|
1701
|
+
if (data?.code === "SDK_LOGIN_SUCCESS" && isValidSession(data?.content, logger)) {
|
|
1692
1702
|
if (expectedWallet && data.content.data.providers.wallet?.address !== expectedWallet) {
|
|
1693
1703
|
setAuthState({
|
|
1694
1704
|
step: "error",
|
|
@@ -2006,7 +2016,9 @@ var PollarClient = class {
|
|
|
2006
2016
|
this.apiKey = config.apiKey;
|
|
2007
2017
|
this.id = randomUUID();
|
|
2008
2018
|
this.basePath = `${config.baseUrl || "https://sdk.api.pollar.xyz"}/v1`;
|
|
2019
|
+
this._log = createLogger(config.logLevel ?? "info", config.logger);
|
|
2009
2020
|
this._storage = config.storage ?? defaultStorage({
|
|
2021
|
+
logger: this._log,
|
|
2010
2022
|
onDegrade: (reason, error) => {
|
|
2011
2023
|
config.onStorageDegrade?.(reason, error);
|
|
2012
2024
|
this._dispatchStorageDegrade(reason, error);
|
|
@@ -2030,7 +2042,7 @@ var PollarClient = class {
|
|
|
2030
2042
|
this._initialized = Promise.resolve();
|
|
2031
2043
|
return;
|
|
2032
2044
|
}
|
|
2033
|
-
|
|
2045
|
+
this._log.info(
|
|
2034
2046
|
`[PollarClient] Initialized v${POLLAR_CORE_VERSION} \u2014 endpoint: ${this.basePath}, network: ${this._networkState.network}`
|
|
2035
2047
|
);
|
|
2036
2048
|
this._initialized = this._initialize();
|
|
@@ -2057,7 +2069,7 @@ var PollarClient = class {
|
|
|
2057
2069
|
const sessionKey = sessionStorageKey(this._apiKeyHash);
|
|
2058
2070
|
const handler = (e) => {
|
|
2059
2071
|
if (e.key === sessionKey) {
|
|
2060
|
-
this._restoreSession().catch((err) =>
|
|
2072
|
+
this._restoreSession().catch((err) => this._log.error("[PollarClient] Cross-tab restore failed", err));
|
|
2061
2073
|
}
|
|
2062
2074
|
};
|
|
2063
2075
|
window.addEventListener("storage", handler);
|
|
@@ -2066,7 +2078,7 @@ var PollarClient = class {
|
|
|
2066
2078
|
try {
|
|
2067
2079
|
await this._keyManager.init();
|
|
2068
2080
|
} catch (err) {
|
|
2069
|
-
|
|
2081
|
+
this._log.warn("[PollarClient] KeyManager init failed; DPoP unavailable for this session", err);
|
|
2070
2082
|
}
|
|
2071
2083
|
await this._restoreSession();
|
|
2072
2084
|
this._visibilityUnsubscribe = this._visibilityProvider.onChange((visible) => {
|
|
@@ -2107,7 +2119,7 @@ var PollarClient = class {
|
|
|
2107
2119
|
try {
|
|
2108
2120
|
self._requestBodyCache.set(request, await request.clone().arrayBuffer());
|
|
2109
2121
|
} catch (err) {
|
|
2110
|
-
|
|
2122
|
+
this._log.warn("[PollarClient] Could not snapshot request body for retry", err);
|
|
2111
2123
|
}
|
|
2112
2124
|
}
|
|
2113
2125
|
const isRefresh = request.url.includes("/auth/refresh");
|
|
@@ -2166,7 +2178,7 @@ var PollarClient = class {
|
|
|
2166
2178
|
this._keyManager
|
|
2167
2179
|
);
|
|
2168
2180
|
} catch (err) {
|
|
2169
|
-
|
|
2181
|
+
this._log.warn("[PollarClient] DPoP proof build failed", err);
|
|
2170
2182
|
return null;
|
|
2171
2183
|
}
|
|
2172
2184
|
}
|
|
@@ -2220,7 +2232,7 @@ var PollarClient = class {
|
|
|
2220
2232
|
async _doRefresh() {
|
|
2221
2233
|
const refreshToken = this._session?.token?.refreshToken;
|
|
2222
2234
|
if (!refreshToken) {
|
|
2223
|
-
|
|
2235
|
+
this._log.warn("[PollarClient] Refresh skipped: no refresh token in session");
|
|
2224
2236
|
await this._clearSession();
|
|
2225
2237
|
throw new Error("No refresh token available");
|
|
2226
2238
|
}
|
|
@@ -2231,18 +2243,18 @@ var PollarClient = class {
|
|
|
2231
2243
|
data = response.data;
|
|
2232
2244
|
error = response.error;
|
|
2233
2245
|
} catch (err) {
|
|
2234
|
-
|
|
2246
|
+
this._log.error("[PollarClient] /auth/refresh request threw", err);
|
|
2235
2247
|
await this._clearSession();
|
|
2236
2248
|
throw err;
|
|
2237
2249
|
}
|
|
2238
2250
|
if (error || !data) {
|
|
2239
|
-
|
|
2251
|
+
this._log.error("[PollarClient] /auth/refresh returned error", { error });
|
|
2240
2252
|
await this._clearSession();
|
|
2241
2253
|
throw new Error("Refresh failed");
|
|
2242
2254
|
}
|
|
2243
2255
|
const successData = data;
|
|
2244
2256
|
if (!successData.success || !successData.content?.token) {
|
|
2245
|
-
|
|
2257
|
+
this._log.error("[PollarClient] /auth/refresh response malformed", {
|
|
2246
2258
|
success: successData.success,
|
|
2247
2259
|
hasToken: !!successData.content?.token
|
|
2248
2260
|
});
|
|
@@ -2251,7 +2263,7 @@ var PollarClient = class {
|
|
|
2251
2263
|
}
|
|
2252
2264
|
const newToken = successData.content.token;
|
|
2253
2265
|
if (typeof newToken.accessToken !== "string" || typeof newToken.refreshToken !== "string" || typeof newToken.expiresAt !== "number") {
|
|
2254
|
-
|
|
2266
|
+
this._log.error("[PollarClient] /auth/refresh token shape invalid", {
|
|
2255
2267
|
accessToken: typeof newToken.accessToken,
|
|
2256
2268
|
refreshToken: typeof newToken.refreshToken,
|
|
2257
2269
|
expiresAt: typeof newToken.expiresAt
|
|
@@ -2263,9 +2275,9 @@ var PollarClient = class {
|
|
|
2263
2275
|
try {
|
|
2264
2276
|
this._session = { ...this._session, token: newToken };
|
|
2265
2277
|
await writeStorage(this._storage, this.apiKeyHash, this._session);
|
|
2266
|
-
|
|
2278
|
+
this._log.info("[PollarClient] Tokens refreshed");
|
|
2267
2279
|
} catch (err) {
|
|
2268
|
-
|
|
2280
|
+
this._log.error("[PollarClient] Failed to persist refreshed session", err);
|
|
2269
2281
|
}
|
|
2270
2282
|
this._scheduleNextRefresh();
|
|
2271
2283
|
}
|
|
@@ -2319,7 +2331,7 @@ var PollarClient = class {
|
|
|
2319
2331
|
try {
|
|
2320
2332
|
await this.refresh();
|
|
2321
2333
|
} catch (err) {
|
|
2322
|
-
|
|
2334
|
+
this._log.warn("[PollarClient] Proactive refresh failed; session cleared", err);
|
|
2323
2335
|
}
|
|
2324
2336
|
}
|
|
2325
2337
|
_clearRefreshTimer() {
|
|
@@ -2365,7 +2377,7 @@ var PollarClient = class {
|
|
|
2365
2377
|
try {
|
|
2366
2378
|
cb(reason, error);
|
|
2367
2379
|
} catch (err) {
|
|
2368
|
-
|
|
2380
|
+
this._log.error("[PollarClient] onStorageDegrade listener threw", err);
|
|
2369
2381
|
}
|
|
2370
2382
|
}
|
|
2371
2383
|
}
|
|
@@ -2485,20 +2497,20 @@ var PollarClient = class {
|
|
|
2485
2497
|
warnServerSide("logout");
|
|
2486
2498
|
return;
|
|
2487
2499
|
}
|
|
2488
|
-
|
|
2500
|
+
this._log.info("[PollarClient] Logout requested", { everywhere: !!options.everywhere });
|
|
2489
2501
|
if (this._session?.token?.accessToken) {
|
|
2490
2502
|
try {
|
|
2491
2503
|
await this._api.POST("/auth/logout", {
|
|
2492
2504
|
body: options.everywhere ? { everywhere: true } : {}
|
|
2493
2505
|
});
|
|
2494
2506
|
} catch (err) {
|
|
2495
|
-
|
|
2507
|
+
this._log.warn("[PollarClient] Server logout failed (continuing with local clear)", err);
|
|
2496
2508
|
}
|
|
2497
2509
|
}
|
|
2498
2510
|
try {
|
|
2499
2511
|
await this._clearSession();
|
|
2500
2512
|
} catch (err) {
|
|
2501
|
-
|
|
2513
|
+
this._log.warn("[PollarClient] Local logout cleanup failed", err);
|
|
2502
2514
|
}
|
|
2503
2515
|
}
|
|
2504
2516
|
/** Convenience: revoke every active session for this user (all devices). */
|
|
@@ -2574,6 +2586,14 @@ var PollarClient = class {
|
|
|
2574
2586
|
getNetworkState() {
|
|
2575
2587
|
return this._networkState;
|
|
2576
2588
|
}
|
|
2589
|
+
/**
|
|
2590
|
+
* The client's level-gated logger (built from `logLevel` / `logger`). Exposed
|
|
2591
|
+
* so the runtime layer (`@pollar/react`) can route its own logs through the
|
|
2592
|
+
* same level and sink instead of calling `console` directly.
|
|
2593
|
+
*/
|
|
2594
|
+
getLogger() {
|
|
2595
|
+
return this._log;
|
|
2596
|
+
}
|
|
2577
2597
|
setNetwork(network) {
|
|
2578
2598
|
this._setNetworkState({ step: "connected", network });
|
|
2579
2599
|
}
|
|
@@ -2722,7 +2742,7 @@ var PollarClient = class {
|
|
|
2722
2742
|
this._setTransactionState({ step: "error", phase: "building", ...details && { details } });
|
|
2723
2743
|
return { status: "error", ...details && { details } };
|
|
2724
2744
|
} catch (err) {
|
|
2725
|
-
|
|
2745
|
+
this._log.error("[PollarClient] buildTx failed", err);
|
|
2726
2746
|
this._setTransactionState({ step: "error", phase: "building" });
|
|
2727
2747
|
return { status: "error" };
|
|
2728
2748
|
}
|
|
@@ -3235,6 +3255,7 @@ var PollarClient = class {
|
|
|
3235
3255
|
_flowDeps(signal) {
|
|
3236
3256
|
return {
|
|
3237
3257
|
api: this._api,
|
|
3258
|
+
logger: this._log,
|
|
3238
3259
|
basePath: this.basePath,
|
|
3239
3260
|
// SSE status streaming works on web; React Native's `fetch` has no
|
|
3240
3261
|
// readable `response.body`, so those clients poll the non-streaming
|
|
@@ -3287,12 +3308,12 @@ var PollarClient = class {
|
|
|
3287
3308
|
}
|
|
3288
3309
|
_handleFlowError(error) {
|
|
3289
3310
|
if (error instanceof Error && error.name === "AbortError") {
|
|
3290
|
-
|
|
3311
|
+
this._log.debug("[PollarClient] Login cancelled");
|
|
3291
3312
|
this._setAuthState({ step: "idle" });
|
|
3292
3313
|
return;
|
|
3293
3314
|
}
|
|
3294
3315
|
if (error instanceof Error && error.code === AUTH_ERROR_CODES.WALLET_RESOLVER_TIMEOUT) {
|
|
3295
|
-
|
|
3316
|
+
this._log.error("[PollarClient]", error.message);
|
|
3296
3317
|
this._setAuthState({
|
|
3297
3318
|
step: "error",
|
|
3298
3319
|
previousStep: this._authState.step,
|
|
@@ -3301,7 +3322,7 @@ var PollarClient = class {
|
|
|
3301
3322
|
});
|
|
3302
3323
|
return;
|
|
3303
3324
|
}
|
|
3304
|
-
|
|
3325
|
+
this._log.error("[PollarClient] Unexpected error in auth flow", error);
|
|
3305
3326
|
this._setAuthState({
|
|
3306
3327
|
step: "error",
|
|
3307
3328
|
previousStep: this._authState.step,
|
|
@@ -3310,22 +3331,22 @@ var PollarClient = class {
|
|
|
3310
3331
|
});
|
|
3311
3332
|
}
|
|
3312
3333
|
async _restoreSession() {
|
|
3313
|
-
this._session = await readStorage(this._storage, this.apiKeyHash);
|
|
3334
|
+
this._session = await readStorage(this._storage, this.apiKeyHash, this._log);
|
|
3314
3335
|
if (this._session) {
|
|
3315
3336
|
const storedType = await readWalletType(this._storage, this.apiKeyHash);
|
|
3316
3337
|
if (storedType) {
|
|
3317
3338
|
try {
|
|
3318
3339
|
this._walletAdapter = await this._resolveWalletAdapter(storedType);
|
|
3319
3340
|
} catch (err) {
|
|
3320
|
-
|
|
3341
|
+
this._log.warn("[PollarClient] Could not restore wallet adapter for stored id", { id: storedType, err });
|
|
3321
3342
|
}
|
|
3322
3343
|
}
|
|
3323
|
-
|
|
3344
|
+
this._log.info("[PollarClient] Session restored from storage");
|
|
3324
3345
|
this._setAuthState({ step: "authenticated", session: this._session, verified: false });
|
|
3325
3346
|
this._scheduleNextRefresh();
|
|
3326
3347
|
void this._resume();
|
|
3327
3348
|
} else {
|
|
3328
|
-
|
|
3349
|
+
this._log.info("[PollarClient] No session in storage");
|
|
3329
3350
|
}
|
|
3330
3351
|
}
|
|
3331
3352
|
/**
|
|
@@ -3356,13 +3377,13 @@ var PollarClient = class {
|
|
|
3356
3377
|
this._setAuthState({ step: "authenticated", session: this._session, verified: true });
|
|
3357
3378
|
} catch (err) {
|
|
3358
3379
|
if (err?.name === "AbortError") return;
|
|
3359
|
-
|
|
3380
|
+
this._log.warn("[PollarClient] resume failed (network); will retry", err);
|
|
3360
3381
|
} finally {
|
|
3361
3382
|
if (this._resumeController === controller) this._resumeController = null;
|
|
3362
3383
|
}
|
|
3363
3384
|
}
|
|
3364
3385
|
async _storeSession(session) {
|
|
3365
|
-
|
|
3386
|
+
this._log.info("[PollarClient] Session stored");
|
|
3366
3387
|
const w = session.wallet;
|
|
3367
3388
|
const persisted = {
|
|
3368
3389
|
clientSessionId: session.clientSessionId,
|
|
@@ -3397,7 +3418,7 @@ var PollarClient = class {
|
|
|
3397
3418
|
this._scheduleNextRefresh();
|
|
3398
3419
|
}
|
|
3399
3420
|
async _clearSession() {
|
|
3400
|
-
|
|
3421
|
+
this._log.info("[PollarClient] Session cleared");
|
|
3401
3422
|
this._clearRefreshTimer();
|
|
3402
3423
|
this._session = null;
|
|
3403
3424
|
this._profile = null;
|
|
@@ -3406,7 +3427,7 @@ var PollarClient = class {
|
|
|
3406
3427
|
try {
|
|
3407
3428
|
await this._keyManager.reset();
|
|
3408
3429
|
} catch (err) {
|
|
3409
|
-
|
|
3430
|
+
this._log.warn("[PollarClient] KeyManager reset failed during clearSession", err);
|
|
3410
3431
|
}
|
|
3411
3432
|
await removeStorage(this._storage, this.apiKeyHash);
|
|
3412
3433
|
this._transactionState = null;
|
|
@@ -3418,17 +3439,17 @@ var PollarClient = class {
|
|
|
3418
3439
|
_setNetworkState(next) {
|
|
3419
3440
|
this._networkState = next;
|
|
3420
3441
|
const label = next.step === "connected" ? next.network : next.step;
|
|
3421
|
-
|
|
3442
|
+
this._log.debug(`[PollarClient] network:${label}`);
|
|
3422
3443
|
for (const cb of this._networkStateListeners) cb(next);
|
|
3423
3444
|
}
|
|
3424
3445
|
_setAuthState(next) {
|
|
3425
3446
|
this._authState = next;
|
|
3426
|
-
|
|
3447
|
+
this._log.debug(`[PollarClient] auth:${next.step}`);
|
|
3427
3448
|
for (const cb of this._authStateListeners) cb(next);
|
|
3428
3449
|
}
|
|
3429
3450
|
_setTransactionState(next) {
|
|
3430
3451
|
this._transactionState = next;
|
|
3431
|
-
|
|
3452
|
+
this._log.debug(`[PollarClient] transaction:${next.step}`);
|
|
3432
3453
|
for (const cb of this._transactionStateListeners) cb(next);
|
|
3433
3454
|
}
|
|
3434
3455
|
/**
|
|
@@ -3532,7 +3553,6 @@ var WebCryptoKeyManager = class {
|
|
|
3532
3553
|
if (this.keyPair) return;
|
|
3533
3554
|
if (!this._initPromise) {
|
|
3534
3555
|
this._initPromise = this._doInit().catch((err) => {
|
|
3535
|
-
console.error("[PollarClient:keys] WebCryptoKeyManager init failed", err);
|
|
3536
3556
|
this._initPromise = null;
|
|
3537
3557
|
throw err;
|
|
3538
3558
|
});
|
|
@@ -3682,6 +3702,7 @@ exports.canonicalEcJwk = canonicalEcJwk;
|
|
|
3682
3702
|
exports.claimDistributionRule = claimDistributionRule;
|
|
3683
3703
|
exports.computeJwkThumbprint = computeJwkThumbprint;
|
|
3684
3704
|
exports.createLocalStorageAdapter = createLocalStorageAdapter;
|
|
3705
|
+
exports.createLogger = createLogger;
|
|
3685
3706
|
exports.createMemoryAdapter = createMemoryAdapter;
|
|
3686
3707
|
exports.createOffRamp = createOffRamp;
|
|
3687
3708
|
exports.createOnRamp = createOnRamp;
|