@pollar/core 0.7.0 → 0.7.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.d.mts +352 -46
- package/dist/index.d.ts +352 -46
- package/dist/index.js +61 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -14
- 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 +61 -13
- package/dist/index.rn.js.map +1 -1
- package/dist/index.rn.mjs +60 -14
- package/dist/index.rn.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.rn.mjs
CHANGED
|
@@ -567,7 +567,7 @@ function createClient(clientOptions) {
|
|
|
567
567
|
const {
|
|
568
568
|
baseUrl: localBaseUrl,
|
|
569
569
|
fetch: fetch2 = baseFetch,
|
|
570
|
-
Request = CustomRequest,
|
|
570
|
+
Request: Request2 = CustomRequest,
|
|
571
571
|
headers,
|
|
572
572
|
params = {},
|
|
573
573
|
parseAs = "json",
|
|
@@ -619,7 +619,7 @@ function createClient(clientOptions) {
|
|
|
619
619
|
};
|
|
620
620
|
let id;
|
|
621
621
|
let options;
|
|
622
|
-
let request = new
|
|
622
|
+
let request = new Request2(
|
|
623
623
|
createFinalURL(schemaPath, { baseUrl: finalBaseUrl, params, querySerializer, pathSerializer }),
|
|
624
624
|
requestInit
|
|
625
625
|
);
|
|
@@ -649,7 +649,7 @@ function createClient(clientOptions) {
|
|
|
649
649
|
id
|
|
650
650
|
});
|
|
651
651
|
if (result) {
|
|
652
|
-
if (result instanceof
|
|
652
|
+
if (result instanceof Request2) {
|
|
653
653
|
request = result;
|
|
654
654
|
} else if (result instanceof Response) {
|
|
655
655
|
response = result;
|
|
@@ -1021,6 +1021,22 @@ function createApiClient(baseUrl) {
|
|
|
1021
1021
|
return createClient({ baseUrl });
|
|
1022
1022
|
}
|
|
1023
1023
|
|
|
1024
|
+
// src/api/endpoints/distribution.ts
|
|
1025
|
+
async function listDistributionRules(api) {
|
|
1026
|
+
const { data, error } = await api.GET("/distribution/rules");
|
|
1027
|
+
if (!data?.content || error) {
|
|
1028
|
+
throw new Error(error?.error ?? "Failed to list distribution rules");
|
|
1029
|
+
}
|
|
1030
|
+
return data.content.rules;
|
|
1031
|
+
}
|
|
1032
|
+
async function claimDistributionRule(api, body) {
|
|
1033
|
+
const { data, error } = await api.POST("/distribution/claim", { body });
|
|
1034
|
+
if (!data?.content || error) {
|
|
1035
|
+
throw new Error(error?.error ?? "Failed to claim distribution rule");
|
|
1036
|
+
}
|
|
1037
|
+
return data.content;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1024
1040
|
// src/api/endpoints/kyc.ts
|
|
1025
1041
|
async function getKycStatus(api, providerId) {
|
|
1026
1042
|
const { data, error } = await api.GET("/kyc/status", {
|
|
@@ -1867,7 +1883,6 @@ async function loginWallet(type, deps) {
|
|
|
1867
1883
|
|
|
1868
1884
|
// src/client/client.ts
|
|
1869
1885
|
var isBrowser = typeof window !== "undefined" && typeof localStorage !== "undefined";
|
|
1870
|
-
var RETRIED_HEADER = "X-Pollar-Retried";
|
|
1871
1886
|
function warnServerSide(method) {
|
|
1872
1887
|
console.warn(
|
|
1873
1888
|
`[PollarClient] ${method}() called server-side \u2014 browser APIs unavailable. Use PollarClient only in Client Components.`
|
|
@@ -1885,6 +1900,13 @@ var PollarClient = class {
|
|
|
1885
1900
|
this._profile = null;
|
|
1886
1901
|
/** Last `DPoP-Nonce` we saw from a server response. Carried into the next proof. */
|
|
1887
1902
|
this._dpopNonce = null;
|
|
1903
|
+
/**
|
|
1904
|
+
* Snapshot of each in-flight request's body, taken in `onRequest` before
|
|
1905
|
+
* `fetch()` consumes the stream. Needed because `Request.clone()` throws
|
|
1906
|
+
* once the body is disturbed, so the auto-retry path (DPoP nonce challenge
|
|
1907
|
+
* / 401 refresh) must rebuild the request from scratch instead of cloning.
|
|
1908
|
+
*/
|
|
1909
|
+
this._requestBodyCache = /* @__PURE__ */ new WeakMap();
|
|
1888
1910
|
/** Singleton in-flight refresh — concurrent 401s coalesce into one /auth/refresh call. */
|
|
1889
1911
|
this._refreshPromise = null;
|
|
1890
1912
|
this._storageEventHandler = null;
|
|
@@ -1969,6 +1991,13 @@ var PollarClient = class {
|
|
|
1969
1991
|
onRequest: async ({ request }) => {
|
|
1970
1992
|
request.headers.set("x-pollar-api-key", self.apiKey);
|
|
1971
1993
|
await self._initialized;
|
|
1994
|
+
if (request.body !== null) {
|
|
1995
|
+
try {
|
|
1996
|
+
self._requestBodyCache.set(request, await request.clone().arrayBuffer());
|
|
1997
|
+
} catch (err) {
|
|
1998
|
+
console.warn("[PollarClient] Could not snapshot request body for retry", err);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
1972
2001
|
const isRefresh = request.url.includes("/auth/refresh");
|
|
1973
2002
|
if (!isRefresh && self._refreshPromise) await self._refreshPromise;
|
|
1974
2003
|
if (isRefresh) {
|
|
@@ -1991,7 +2020,6 @@ var PollarClient = class {
|
|
|
1991
2020
|
const newNonce = response.headers.get("DPoP-Nonce");
|
|
1992
2021
|
if (newNonce) self._dpopNonce = newNonce;
|
|
1993
2022
|
if (response.status !== 401) return response;
|
|
1994
|
-
if (request.headers.get(RETRIED_HEADER)) return response;
|
|
1995
2023
|
if (request.url.includes("/auth/refresh")) return response;
|
|
1996
2024
|
const wwwAuth = response.headers.get("WWW-Authenticate") ?? "";
|
|
1997
2025
|
const isNonceChallenge = wwwAuth.includes("use_dpop_nonce");
|
|
@@ -2024,19 +2052,29 @@ var PollarClient = class {
|
|
|
2024
2052
|
}
|
|
2025
2053
|
}
|
|
2026
2054
|
async _retryRequest(originalRequest) {
|
|
2027
|
-
const
|
|
2028
|
-
clone.headers.set(RETRIED_HEADER, "1");
|
|
2055
|
+
const headers = new Headers(originalRequest.headers);
|
|
2029
2056
|
const accessToken = this._session?.token?.accessToken;
|
|
2030
2057
|
if (accessToken) {
|
|
2031
|
-
const proof = await this._buildProofForRequest(
|
|
2058
|
+
const proof = await this._buildProofForRequest(originalRequest, accessToken);
|
|
2032
2059
|
if (proof) {
|
|
2033
|
-
|
|
2034
|
-
|
|
2060
|
+
headers.set("Authorization", `DPoP ${accessToken}`);
|
|
2061
|
+
headers.set("DPoP", proof);
|
|
2035
2062
|
} else {
|
|
2036
|
-
|
|
2063
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
2037
2064
|
}
|
|
2038
2065
|
}
|
|
2039
|
-
|
|
2066
|
+
const cachedBody = this._requestBodyCache.get(originalRequest);
|
|
2067
|
+
const retried = new Request(originalRequest.url, {
|
|
2068
|
+
method: originalRequest.method,
|
|
2069
|
+
headers,
|
|
2070
|
+
body: cachedBody ?? null,
|
|
2071
|
+
credentials: originalRequest.credentials,
|
|
2072
|
+
mode: originalRequest.mode,
|
|
2073
|
+
redirect: originalRequest.redirect,
|
|
2074
|
+
referrer: originalRequest.referrer,
|
|
2075
|
+
integrity: originalRequest.integrity
|
|
2076
|
+
});
|
|
2077
|
+
return fetch(retried);
|
|
2040
2078
|
}
|
|
2041
2079
|
// ─── Refresh (race-safe singleton) ───────────────────────────────────────
|
|
2042
2080
|
/**
|
|
@@ -2361,7 +2399,8 @@ var PollarClient = class {
|
|
|
2361
2399
|
const details = error?.details;
|
|
2362
2400
|
this._setTransactionState({ step: "error", ...details && { details } });
|
|
2363
2401
|
}
|
|
2364
|
-
} catch {
|
|
2402
|
+
} catch (err) {
|
|
2403
|
+
console.error("[PollarClient] buildTx failed", err);
|
|
2365
2404
|
this._setTransactionState({ step: "error" });
|
|
2366
2405
|
}
|
|
2367
2406
|
}
|
|
@@ -2449,6 +2488,13 @@ var PollarClient = class {
|
|
|
2449
2488
|
pollRampTransaction(txId, opts) {
|
|
2450
2489
|
return pollRampTransaction(this._api, txId, opts);
|
|
2451
2490
|
}
|
|
2491
|
+
// ─── Distribution ─────────────────────────────────────────────────────────
|
|
2492
|
+
listDistributionRules() {
|
|
2493
|
+
return listDistributionRules(this._api);
|
|
2494
|
+
}
|
|
2495
|
+
claimDistributionRule(body) {
|
|
2496
|
+
return claimDistributionRule(this._api, body);
|
|
2497
|
+
}
|
|
2452
2498
|
_setTxHistoryState(next) {
|
|
2453
2499
|
this._txHistoryState = next;
|
|
2454
2500
|
for (const cb of this._txHistoryStateListeners) cb(next);
|
|
@@ -2594,6 +2640,6 @@ _setDefaultKeyManagerFactory((storage, apiKey) => {
|
|
|
2594
2640
|
return new NobleKeyManager(storage, apiKey);
|
|
2595
2641
|
});
|
|
2596
2642
|
|
|
2597
|
-
export { AUTH_ERROR_CODES, AlbedoAdapter, FreighterAdapter, NobleKeyManager, PollarClient, StellarClient, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, computeJwkThumbprint, createLocalStorageAdapter, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, normalizeHtu, pollKycStatus, pollRampTransaction, resolveKyc, startKyc };
|
|
2643
|
+
export { AUTH_ERROR_CODES, AlbedoAdapter, FreighterAdapter, NobleKeyManager, 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 };
|
|
2598
2644
|
//# sourceMappingURL=index.rn.mjs.map
|
|
2599
2645
|
//# sourceMappingURL=index.rn.mjs.map
|