@stacks/network
Advanced tools
Comparing version 6.16.2-pr.0746d956.2 to 6.16.2-pr.0c509c33.3
@@ -31,6 +31,5 @@ import 'cross-fetch/polyfill'; | ||
return; | ||
const headers = context.init.headers instanceof Headers | ||
? context.init.headers | ||
: (context.init.headers = new Headers(context.init.headers)); | ||
const headers = new Headers(context.init.headers); | ||
headers.set(httpHeader, apiKey); | ||
context.init.headers = headers; | ||
}, | ||
@@ -37,0 +36,0 @@ }; |
@@ -38,6 +38,5 @@ "use strict"; | ||
return; | ||
const headers = context.init.headers instanceof Headers | ||
? context.init.headers | ||
: (context.init.headers = new Headers(context.init.headers)); | ||
const headers = new Headers(context.init.headers); | ||
headers.set(httpHeader, apiKey); | ||
context.init.headers = headers; | ||
}, | ||
@@ -44,0 +43,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StacksNetwork=e():t.StacksNetwork=e()}(this,(()=>(()=>{var t={616:function(){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function h(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function l(t){return"string"!=typeof t&&(t=String(t)),t}function u(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=p(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=h(t),e=l(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},d.prototype.delete=function(t){delete this.map[h(t)]},d.prototype.get=function(t){return t=h(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(h(t))},d.prototype.set=function(t,e){this.map[h(t)]=l(e)},d.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),u(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),u(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),u(t)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var r,n,o=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new d(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),v.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function E(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function A(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},m.call(w.prototype),m.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},A.error=function(){var t=new A(null,{status:0,statusText:""});return t.type="error",t};var g=[301,302,303,307,308];A.redirect=function(t,e){if(-1===g.indexOf(e))throw new RangeError("Invalid status code");return new A(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function U(t,r){return new Promise((function(n,i){var s=new w(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new d,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new A(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",c)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}U.polyfill=!0,t.fetch||(t.fetch=U,t.Headers=d,t.Request=w,t.Response=A),e.Headers=d,e.Request=w,e.Response=A,e.fetch=U,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:this)}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{HIRO_MAINNET_DEFAULT:()=>v,HIRO_MOCKNET_DEFAULT:()=>E,HIRO_TESTNET_DEFAULT:()=>w,StacksDevnet:()=>_,StacksMainnet:()=>T,StacksMocknet:()=>O,StacksNetwork:()=>U,StacksNetworks:()=>A,StacksTestnet:()=>x,createApiKeyMiddleware:()=>f,createFetchFn:()=>p,fetchWrapper:()=>u,getFetchOptions:()=>h,hostMatches:()=>d,setFetchOptions:()=>l}),r(616);var t=Object.defineProperty,e=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(e,r,n)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,a=(t,r)=>{for(var n in r||(r={}))o.call(r,n)&&s(t,n,r[n]);if(e)for(var n of e(r))i.call(r,n)&&s(t,n,r[n]);return t};const c={referrerPolicy:"origin",headers:{"x-hiro-product":"stacksjs"}},h=()=>c,l=t=>Object.assign(c,t);async function u(t,e){const r={};return Object.assign(r,c,e),await fetch(t,r)}function d(t,e){return"string"==typeof e?e===t:e.exec(t)}function f({apiKey:t,host:e=/(.*)api(.*)(\.stacks\.co|\.hiro\.so)$/i,httpHeader:r="x-api-key"}){return{pre:n=>{d(new URL(n.url).host,e)&&(n.init.headers instanceof Headers?n.init.headers:n.init.headers=new Headers(n.init.headers)).set(r,t)}}}function p(...t){const{fetchLib:e,middlewares:r}=function(t){let e=u,r=[];return t.length>0&&"function"==typeof t[0]&&(e=t.shift()),t.length>0&&(r=t),{fetchLib:e,middlewares:r}}(t);return async(t,n)=>{var o;let i={url:t,init:null!=n?n:{}};for(const t of r)if("function"==typeof t.pre){const r=await Promise.resolve(t.pre(a({fetch:e},i)));i=null!=r?r:i}let s=await e(i.url,i.init);for(const t of r)if("function"==typeof t.post){const r=await Promise.resolve(t.post({fetch:e,url:i.url,init:i.init,response:null!=(o=null==s?void 0:s.clone())?o:s}));s=null!=r?r:s}return s}}var y,b,m;!function(t){t[t.Testnet=2147483648]="Testnet",t[t.Mainnet=1]="Mainnet"}(y||(y={})),function(t){t[t.Mainnet=0]="Mainnet",t[t.Testnet=128]="Testnet"}(b||(b={})),function(t){t[t.Mainnet=385875968]="Mainnet",t[t.Testnet=4278190080]="Testnet"}(m||(m={}));const v="https://api.mainnet.hiro.so",w="https://api.testnet.hiro.so",E="http://localhost:3999",A=["mainnet","testnet","devnet","mocknet"],g=class{constructor(t){var e;this.version=b.Mainnet,this.chainId=y.Mainnet,this.bnsLookupUrl="https://api.mainnet.hiro.so",this.broadcastEndpoint="/v2/transactions",this.transferFeeEstimateEndpoint="/v2/fees/transfer",this.transactionFeeEstimateEndpoint="/v2/fees/transaction",this.accountEndpoint="/v2/accounts",this.contractAbiEndpoint="/v2/contracts/interface",this.readOnlyFunctionCallEndpoint="/v2/contracts/call-read",this.isMainnet=()=>this.version===b.Mainnet,this.getBroadcastApiUrl=()=>`${this.coreApiUrl}${this.broadcastEndpoint}`,this.getTransferFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`,this.getTransactionFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`,this.getAccountApiUrl=t=>`${this.coreApiUrl}${this.accountEndpoint}/${t}?proof=0`,this.getAccountExtendedBalancesApiUrl=t=>`${this.coreApiUrl}/extended/v1/address/${t}/balances`,this.getAbiApiUrl=(t,e)=>`${this.coreApiUrl}${this.contractAbiEndpoint}/${t}/${e}`,this.getReadOnlyFunctionCallApiUrl=(t,e,r)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${t}/${e}/${encodeURIComponent(r)}`,this.getInfoUrl=()=>`${this.coreApiUrl}/v2/info`,this.getBlockTimeInfoUrl=()=>`${this.coreApiUrl}/extended/v1/info/network_block_times`,this.getPoxInfoUrl=()=>`${this.coreApiUrl}/v2/pox`,this.getRewardsUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getRewardsTotalUrl=t=>`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}/total`,this.getRewardHoldersUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getStackerInfoUrl=(t,e)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}\n ${t}/${e}/get-stacker-info`,this.getDataVarUrl=(t,e,r)=>`${this.coreApiUrl}/v2/data_var/${t}/${e}/${r}?proof=0`,this.getMapEntryUrl=(t,e,r)=>`${this.coreApiUrl}/v2/map_entry/${t}/${e}/${r}?proof=0`,this.coreApiUrl=t.url,this.fetchFn=null!=(e=t.fetchFn)?e:p()}getNameInfo(t){const e=`${this.bnsLookupUrl}/v1/names/${t}`;return this.fetchFn(e).then((t=>{if(404===t.status)throw new Error("Name not found");if(200!==t.status)throw new Error(`Bad response status: ${t.status}`);return t.json()})).then((t=>t.address?Object.assign({},t,{address:t.address}):t))}};g.fromName=t=>{switch(t){case"mainnet":return new T;case"testnet":return new x;case"devnet":return new _;case"mocknet":return new O;default:throw new Error(`Invalid network name provided. Must be one of the following: ${A.join(", ")}`)}},g.fromNameOrNetwork=t=>"string"!=typeof t&&"version"in t?t:g.fromName(t);let U=g;class T extends U{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:v,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Mainnet,this.chainId=y.Mainnet}}class x extends U{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:w,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Testnet,this.chainId=y.Testnet}}class O extends U{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:E,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Testnet,this.chainId=y.Testnet}}const _=O})(),n})())); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StacksNetwork=e():t.StacksNetwork=e()}(this,(()=>(()=>{var t={616:function(){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function h(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function l(t){return"string"!=typeof t&&(t=String(t)),t}function u(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=p(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=h(t),e=l(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},d.prototype.delete=function(t){delete this.map[h(t)]},d.prototype.get=function(t){return t=h(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(h(t))},d.prototype.set=function(t,e){this.map[h(t)]=l(e)},d.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),u(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),u(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),u(t)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var r,n,o=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new d(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),v.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function E(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function A(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},m.call(w.prototype),m.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},A.error=function(){var t=new A(null,{status:0,statusText:""});return t.type="error",t};var g=[301,302,303,307,308];A.redirect=function(t,e){if(-1===g.indexOf(e))throw new RangeError("Invalid status code");return new A(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function U(t,r){return new Promise((function(n,i){var s=new w(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new d,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new A(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",c)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}U.polyfill=!0,t.fetch||(t.fetch=U,t.Headers=d,t.Request=w,t.Response=A),e.Headers=d,e.Request=w,e.Response=A,e.fetch=U,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:this)}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{HIRO_MAINNET_DEFAULT:()=>v,HIRO_MOCKNET_DEFAULT:()=>E,HIRO_TESTNET_DEFAULT:()=>w,StacksDevnet:()=>_,StacksMainnet:()=>T,StacksMocknet:()=>O,StacksNetwork:()=>U,StacksNetworks:()=>A,StacksTestnet:()=>x,createApiKeyMiddleware:()=>f,createFetchFn:()=>p,fetchWrapper:()=>u,getFetchOptions:()=>h,hostMatches:()=>d,setFetchOptions:()=>l}),r(616);var t=Object.defineProperty,e=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(e,r,n)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,a=(t,r)=>{for(var n in r||(r={}))o.call(r,n)&&s(t,n,r[n]);if(e)for(var n of e(r))i.call(r,n)&&s(t,n,r[n]);return t};const c={referrerPolicy:"origin",headers:{"x-hiro-product":"stacksjs"}},h=()=>c,l=t=>Object.assign(c,t);async function u(t,e){const r={};return Object.assign(r,c,e),await fetch(t,r)}function d(t,e){return"string"==typeof e?e===t:e.exec(t)}function f({apiKey:t,host:e=/(.*)api(.*)(\.stacks\.co|\.hiro\.so)$/i,httpHeader:r="x-api-key"}){return{pre:n=>{if(!d(new URL(n.url).host,e))return;const o=new Headers(n.init.headers);o.set(r,t),n.init.headers=o}}}function p(...t){const{fetchLib:e,middlewares:r}=function(t){let e=u,r=[];return t.length>0&&"function"==typeof t[0]&&(e=t.shift()),t.length>0&&(r=t),{fetchLib:e,middlewares:r}}(t);return async(t,n)=>{var o;let i={url:t,init:null!=n?n:{}};for(const t of r)if("function"==typeof t.pre){const r=await Promise.resolve(t.pre(a({fetch:e},i)));i=null!=r?r:i}let s=await e(i.url,i.init);for(const t of r)if("function"==typeof t.post){const r=await Promise.resolve(t.post({fetch:e,url:i.url,init:i.init,response:null!=(o=null==s?void 0:s.clone())?o:s}));s=null!=r?r:s}return s}}var y,b,m;!function(t){t[t.Testnet=2147483648]="Testnet",t[t.Mainnet=1]="Mainnet"}(y||(y={})),function(t){t[t.Mainnet=0]="Mainnet",t[t.Testnet=128]="Testnet"}(b||(b={})),function(t){t[t.Mainnet=385875968]="Mainnet",t[t.Testnet=4278190080]="Testnet"}(m||(m={}));const v="https://api.mainnet.hiro.so",w="https://api.testnet.hiro.so",E="http://localhost:3999",A=["mainnet","testnet","devnet","mocknet"],g=class{constructor(t){var e;this.version=b.Mainnet,this.chainId=y.Mainnet,this.bnsLookupUrl="https://api.mainnet.hiro.so",this.broadcastEndpoint="/v2/transactions",this.transferFeeEstimateEndpoint="/v2/fees/transfer",this.transactionFeeEstimateEndpoint="/v2/fees/transaction",this.accountEndpoint="/v2/accounts",this.contractAbiEndpoint="/v2/contracts/interface",this.readOnlyFunctionCallEndpoint="/v2/contracts/call-read",this.isMainnet=()=>this.version===b.Mainnet,this.getBroadcastApiUrl=()=>`${this.coreApiUrl}${this.broadcastEndpoint}`,this.getTransferFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`,this.getTransactionFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`,this.getAccountApiUrl=t=>`${this.coreApiUrl}${this.accountEndpoint}/${t}?proof=0`,this.getAccountExtendedBalancesApiUrl=t=>`${this.coreApiUrl}/extended/v1/address/${t}/balances`,this.getAbiApiUrl=(t,e)=>`${this.coreApiUrl}${this.contractAbiEndpoint}/${t}/${e}`,this.getReadOnlyFunctionCallApiUrl=(t,e,r)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${t}/${e}/${encodeURIComponent(r)}`,this.getInfoUrl=()=>`${this.coreApiUrl}/v2/info`,this.getBlockTimeInfoUrl=()=>`${this.coreApiUrl}/extended/v1/info/network_block_times`,this.getPoxInfoUrl=()=>`${this.coreApiUrl}/v2/pox`,this.getRewardsUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getRewardsTotalUrl=t=>`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}/total`,this.getRewardHoldersUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getStackerInfoUrl=(t,e)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}\n ${t}/${e}/get-stacker-info`,this.getDataVarUrl=(t,e,r)=>`${this.coreApiUrl}/v2/data_var/${t}/${e}/${r}?proof=0`,this.getMapEntryUrl=(t,e,r)=>`${this.coreApiUrl}/v2/map_entry/${t}/${e}/${r}?proof=0`,this.coreApiUrl=t.url,this.fetchFn=null!=(e=t.fetchFn)?e:p()}getNameInfo(t){const e=`${this.bnsLookupUrl}/v1/names/${t}`;return this.fetchFn(e).then((t=>{if(404===t.status)throw new Error("Name not found");if(200!==t.status)throw new Error(`Bad response status: ${t.status}`);return t.json()})).then((t=>t.address?Object.assign({},t,{address:t.address}):t))}};g.fromName=t=>{switch(t){case"mainnet":return new T;case"testnet":return new x;case"devnet":return new _;case"mocknet":return new O;default:throw new Error(`Invalid network name provided. Must be one of the following: ${A.join(", ")}`)}},g.fromNameOrNetwork=t=>"string"!=typeof t&&"version"in t?t:g.fromName(t);let U=g;class T extends U{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:v,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Mainnet,this.chainId=y.Mainnet}}class x extends U{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:w,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Testnet,this.chainId=y.Testnet}}class O extends U{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:E,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Testnet,this.chainId=y.Testnet}}const _=O})(),n})())); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@stacks/network", | ||
"version": "6.16.2-pr.0746d956.2+0746d956", | ||
"version": "6.16.2-pr.0c509c33.3+0c509c33", | ||
"description": "Library for Stacks network operations", | ||
@@ -23,3 +23,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@stacks/common": "^6.16.2-pr.0746d956.2+0746d956", | ||
"@stacks/common": "^6.16.2-pr.0c509c33.3+0c509c33", | ||
"cross-fetch": "^3.1.5" | ||
@@ -56,3 +56,3 @@ }, | ||
}, | ||
"gitHead": "0746d9569b04bbf33fd4f4deb6f319c38164f390" | ||
"gitHead": "0c509c33441c221b2928d753bf2e9efa6d1bca51" | ||
} |
@@ -111,7 +111,5 @@ import 'cross-fetch/polyfill'; | ||
const headers = | ||
context.init.headers instanceof Headers | ||
? context.init.headers | ||
: (context.init.headers = new Headers(context.init.headers)); | ||
const headers = new Headers(context.init.headers); | ||
headers.set(httpHeader, apiKey); | ||
context.init.headers = headers; | ||
}, | ||
@@ -118,0 +116,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
126584
1037