@medialane/sdk 0.27.0 → 0.28.0
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.cjs +62 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -1
- package/dist/index.d.ts +58 -1
- package/dist/index.js +60 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4686,6 +4686,63 @@ var MedialaneError = class extends Error {
|
|
|
4686
4686
|
this.name = "MedialaneError";
|
|
4687
4687
|
}
|
|
4688
4688
|
};
|
|
4689
|
+
|
|
4690
|
+
// src/utils/rpc.ts
|
|
4691
|
+
var PUBLIC_RPC_FALLBACKS = [
|
|
4692
|
+
"https://rpc.starknet.lava.build",
|
|
4693
|
+
"https://starknet-mainnet.public.blastapi.io/rpc/v0_7",
|
|
4694
|
+
"https://free-rpc.nethermind.io/mainnet-juno/v0_7"
|
|
4695
|
+
];
|
|
4696
|
+
var TRANSIENT_BODY_RE = /"code"\s*:\s*-32001|"code"\s*:\s*-32603|unable to complete|rate.?limit|too many|throttl|exceed.*quota|temporarily unavailable|service unavailable|overload|gateway.*time|upstream.*time|backend.*error/i;
|
|
4697
|
+
function isTransientRpcError(input) {
|
|
4698
|
+
const { status, body } = input;
|
|
4699
|
+
if (typeof status === "number" && (status === 429 || status >= 500)) return true;
|
|
4700
|
+
if (body == null) return false;
|
|
4701
|
+
if (typeof body === "object") {
|
|
4702
|
+
const err = body.error;
|
|
4703
|
+
if (!err || typeof err !== "object") return false;
|
|
4704
|
+
const code = err.code;
|
|
4705
|
+
if (typeof code === "number") {
|
|
4706
|
+
if (code === 429) return true;
|
|
4707
|
+
if (code >= -32099 && code <= -32e3) return true;
|
|
4708
|
+
if (code === -32603) return true;
|
|
4709
|
+
}
|
|
4710
|
+
const message = err.message;
|
|
4711
|
+
return typeof message === "string" ? TRANSIENT_BODY_RE.test(message) : false;
|
|
4712
|
+
}
|
|
4713
|
+
return TRANSIENT_BODY_RE.test(String(body));
|
|
4714
|
+
}
|
|
4715
|
+
function createFailoverFetch(urls, options = {}) {
|
|
4716
|
+
const endpoints = urls.filter((u) => Boolean(u));
|
|
4717
|
+
if (endpoints.length === 0) {
|
|
4718
|
+
throw new Error("createFailoverFetch: at least one RPC URL is required");
|
|
4719
|
+
}
|
|
4720
|
+
const doFetch = options.baseFetch ?? fetch;
|
|
4721
|
+
const failover = async (_input, init) => {
|
|
4722
|
+
let lastError;
|
|
4723
|
+
for (let i = 0; i < endpoints.length; i++) {
|
|
4724
|
+
const url = endpoints[i];
|
|
4725
|
+
const isLast = i === endpoints.length - 1;
|
|
4726
|
+
try {
|
|
4727
|
+
const res = await doFetch(url, init);
|
|
4728
|
+
const text = await res.text();
|
|
4729
|
+
const rebuilt = () => new Response(text, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
4730
|
+
if (isLast || !isTransientRpcError({ status: res.status, body: text })) {
|
|
4731
|
+
return rebuilt();
|
|
4732
|
+
}
|
|
4733
|
+
options.onFailover?.({ url, status: res.status });
|
|
4734
|
+
} catch (err) {
|
|
4735
|
+
lastError = err;
|
|
4736
|
+
if (isLast) throw err;
|
|
4737
|
+
options.onFailover?.({ url, error: err });
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4740
|
+
throw lastError ?? new Error("createFailoverFetch: all endpoints failed");
|
|
4741
|
+
};
|
|
4742
|
+
return failover;
|
|
4743
|
+
}
|
|
4744
|
+
|
|
4745
|
+
// src/marketplace/utils.ts
|
|
4689
4746
|
var START_TIME_BUFFER_SECS = 30;
|
|
4690
4747
|
function generateSalt() {
|
|
4691
4748
|
const bytes = new Uint8Array(31);
|
|
@@ -4726,7 +4783,8 @@ var _providerCache = /* @__PURE__ */ new WeakMap();
|
|
|
4726
4783
|
function getProvider(config) {
|
|
4727
4784
|
let p = _providerCache.get(config);
|
|
4728
4785
|
if (!p) {
|
|
4729
|
-
|
|
4786
|
+
const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
|
|
4787
|
+
p = new starknet.RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
|
|
4730
4788
|
_providerCache.set(config, p);
|
|
4731
4789
|
}
|
|
4732
4790
|
return p;
|
|
@@ -6563,6 +6621,7 @@ exports.POPCollectionABI = POPCollectionABI;
|
|
|
6563
6621
|
exports.POPFactoryABI = POPFactoryABI;
|
|
6564
6622
|
exports.POP_COLLECTION_CLASS_HASH_MAINNET = POP_COLLECTION_CLASS_HASH_MAINNET;
|
|
6565
6623
|
exports.POP_FACTORY_CONTRACT_MAINNET = POP_FACTORY_CONTRACT_MAINNET;
|
|
6624
|
+
exports.PUBLIC_RPC_FALLBACKS = PUBLIC_RPC_FALLBACKS;
|
|
6566
6625
|
exports.PopService = PopService;
|
|
6567
6626
|
exports.SUPPORTED_NETWORKS = SUPPORTED_NETWORKS;
|
|
6568
6627
|
exports.SUPPORTED_TOKENS = SUPPORTED_TOKENS;
|
|
@@ -6571,6 +6630,7 @@ exports.build1155OrderTypedData = build1155OrderTypedData;
|
|
|
6571
6630
|
exports.buildCancellationTypedData = buildCancellationTypedData;
|
|
6572
6631
|
exports.buildFeeCall = buildFeeCall;
|
|
6573
6632
|
exports.buildOrderTypedData = buildOrderTypedData;
|
|
6633
|
+
exports.createFailoverFetch = createFailoverFetch;
|
|
6574
6634
|
exports.encodeByteArray = encodeByteArray;
|
|
6575
6635
|
exports.formatAmount = formatAmount;
|
|
6576
6636
|
exports.getListableTokens = getListableTokens;
|
|
@@ -6579,6 +6639,7 @@ exports.getServicesByCapability = getServicesByCapability;
|
|
|
6579
6639
|
exports.getTokenByAddress = getTokenByAddress;
|
|
6580
6640
|
exports.getTokenBySymbol = getTokenBySymbol;
|
|
6581
6641
|
exports.isServiceId = isServiceId;
|
|
6642
|
+
exports.isTransientRpcError = isTransientRpcError;
|
|
6582
6643
|
exports.listServices = listServices;
|
|
6583
6644
|
exports.normalizeAddress = normalizeAddress;
|
|
6584
6645
|
exports.normalizeHash = normalizeHash;
|