@swing.xyz/cross-chain-api
Advanced tools
Comparing version 0.0.7 to 0.0.8
# @swing.xyz/cross-chain-api | ||
## 0.0.8 | ||
### Patch Changes | ||
- fb92704: Add option to override `baseUrl` and `environment`. This is useful if you need to point at a local dev server. | ||
```ts | ||
getSwingAPI({ | ||
baseUrl: "http://localhost:3000", | ||
}); | ||
getSwingPlatformAPI({ | ||
baseUrl: "http://localhost:4000", | ||
}); | ||
``` | ||
## 0.0.7 | ||
@@ -4,0 +20,0 @@ |
@@ -1348,2 +1348,10 @@ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */ | ||
/** | ||
* The base URL of the Swing Cross-Chain API. | ||
* | ||
* This option overrides the value set by the `environment` option. | ||
* | ||
* @default https://swap.prod.swing.xyz | ||
*/ | ||
baseUrl?: string; | ||
/** | ||
* Default headers to send on each request. | ||
@@ -1358,2 +1366,3 @@ * | ||
* @param environment The API environment to use. Default: production | ||
* @param baseUrl The base URL of the Swing Cross-Chain API. Default: https://swap.prod.swing.xyz | ||
* @param headers Default headers to send with each request. | ||
@@ -1367,4 +1376,4 @@ * @returns SwingAPI | ||
*/ | ||
declare function getSwingAPI({ environment, headers, }?: SwingAPIOptions): SwingAPI; | ||
declare function getSwingAPI({ environment, baseUrl, headers, }?: SwingAPIOptions): SwingAPI; | ||
export { Environment, SwingAPI, SwingAPIOptions, components, getSwingAPI, operations, paths, schemas }; |
@@ -1,2 +0,2 @@ | ||
var C={"Content-Type":"application/json"};function g(t={}){let{fetch:e=globalThis.fetch,querySerializer:n,bodySerializer:o,...r}=t,a=r.baseUrl??"";a.endsWith("/")&&(a=a.slice(0,-1));async function f(i,s){let{fetch:E=e,headers:I,body:b,params:w={},parseAs:d="json",querySerializer:O=n??R,bodySerializer:T=o??U,...v}=s||{},j=z(i,{baseUrl:a,params:w,querySerializer:O}),A=$(C,t?.headers,I,w.header),p={redirect:"follow",...r,...v,headers:A};b&&(p.body=T(b)),p.body instanceof FormData&&A.delete("Content-Type");let c=await E(j,p);if(c.status===204||c.headers.get("Content-Length")==="0")return c.ok?{data:{},response:c}:{error:{},response:c};if(c.ok){let l;if(d!=="stream"){let m=c.clone();l=typeof m[d]=="function"?await m[d]():await m.text()}else l=c.clone().body;return{data:l,response:c}}let u={};try{u=await c.clone().json()}catch{u=await c.clone().text()}return{error:u,response:c}}return{async GET(i,...s){return f(i,{...s[0],method:"GET"})},async PUT(i,...s){return f(i,{...s[0],method:"PUT"})},async POST(i,...s){return f(i,{...s[0],method:"POST"})},async DELETE(i,...s){return f(i,{...s[0],method:"DELETE"})},async OPTIONS(i,...s){return f(i,{...s[0],method:"OPTIONS"})},async HEAD(i,...s){return f(i,{...s[0],method:"HEAD"})},async PATCH(i,...s){return f(i,{...s[0],method:"PATCH"})},async TRACE(i,...s){return f(i,{...s[0],method:"TRACE"})}}}function R(t){let e=[];if(t&&typeof t=="object")for(let[n,o]of Object.entries(t)){let r=y([n],o);r&&e.push(r)}return e.join("&")}function y(t,e){if(e!=null){if(typeof e=="string")return`${h(t)}=${encodeURIComponent(e)}`;if(typeof e=="number"||typeof e=="boolean")return`${h(t)}=${String(e)}`;if(Array.isArray(e)){if(!e.length)return;let n=[];for(let o of e){let r=y(t,o);r!==void 0&&n.push(r)}return n.join("&")}if(typeof e=="object"){if(!Object.keys(e).length)return;let n=[];for(let[o,r]of Object.entries(e))if(r!=null){let a=y([...t,o],r);a!==void 0&&n.push(a)}return n.join("&")}return encodeURIComponent(`${h(t)}=${String(e)}`)}}function h(t){let e=t[0];for(let n of t.slice(1))e+=`[${n}]`;return e}function U(t){return JSON.stringify(t)}function z(t,e){let n=`${e.baseUrl}${t}`;if(e.params.path)for(let[r,a]of Object.entries(e.params.path))n=n.replace(`{${r}}`,encodeURIComponent(String(a)));let o=e.querySerializer(e.params.query??{});return o&&(n+=`?${o}`),n}function $(...t){let e=new Headers;for(let n of t){if(!n||typeof n!="object")continue;let o=n instanceof Headers?n.entries():Object.entries(n);for(let[r,a]of o)a===null?e.delete(r):a!==void 0&&e.set(r,a)}return e}var P={environment:"production",headers:{}},S={production:"https://swap.prod.swing.xyz",development:"https://swap.dev.swing.xyz",testnet:"https://swap-testnet.dev.swing.xyz"},x=new WeakMap;function D({environment:t=P.environment,headers:e}=P){let n={environment:t,headers:e};if(!(n.environment in S))if(n.environment==="dev")n.environment="development";else throw new Error(`Invalid environment: ${n.environment}. Valid options are ${Object.keys(S).join(", ")}.`);let o=x.get(n);return o||(o={...g({baseUrl:S[n.environment],headers:{...n.headers,"x-swing-environment":n.environment}}),environment:n.environment},x.set(n,o)),o}export{D as getSwingAPI}; | ||
var C={"Content-Type":"application/json"};function g(t={}){let{fetch:e=globalThis.fetch,querySerializer:n,bodySerializer:r,...o}=t,a=o.baseUrl??"";a.endsWith("/")&&(a=a.slice(0,-1));async function f(i,s){let{fetch:E=e,headers:I,body:b,params:w={},parseAs:d="json",querySerializer:O=n??U,bodySerializer:T=r??R,...v}=s||{},j=z(i,{baseUrl:a,params:w,querySerializer:O}),A=$(C,t?.headers,I,w.header),p={redirect:"follow",...o,...v,headers:A};b&&(p.body=T(b)),p.body instanceof FormData&&A.delete("Content-Type");let c=await E(j,p);if(c.status===204||c.headers.get("Content-Length")==="0")return c.ok?{data:{},response:c}:{error:{},response:c};if(c.ok){let l;if(d!=="stream"){let m=c.clone();l=typeof m[d]=="function"?await m[d]():await m.text()}else l=c.clone().body;return{data:l,response:c}}let u={};try{u=await c.clone().json()}catch{u=await c.clone().text()}return{error:u,response:c}}return{async GET(i,...s){return f(i,{...s[0],method:"GET"})},async PUT(i,...s){return f(i,{...s[0],method:"PUT"})},async POST(i,...s){return f(i,{...s[0],method:"POST"})},async DELETE(i,...s){return f(i,{...s[0],method:"DELETE"})},async OPTIONS(i,...s){return f(i,{...s[0],method:"OPTIONS"})},async HEAD(i,...s){return f(i,{...s[0],method:"HEAD"})},async PATCH(i,...s){return f(i,{...s[0],method:"PATCH"})},async TRACE(i,...s){return f(i,{...s[0],method:"TRACE"})}}}function U(t){let e=[];if(t&&typeof t=="object")for(let[n,r]of Object.entries(t)){let o=y([n],r);o&&e.push(o)}return e.join("&")}function y(t,e){if(e!=null){if(typeof e=="string")return`${h(t)}=${encodeURIComponent(e)}`;if(typeof e=="number"||typeof e=="boolean")return`${h(t)}=${String(e)}`;if(Array.isArray(e)){if(!e.length)return;let n=[];for(let r of e){let o=y(t,r);o!==void 0&&n.push(o)}return n.join("&")}if(typeof e=="object"){if(!Object.keys(e).length)return;let n=[];for(let[r,o]of Object.entries(e))if(o!=null){let a=y([...t,r],o);a!==void 0&&n.push(a)}return n.join("&")}return encodeURIComponent(`${h(t)}=${String(e)}`)}}function h(t){let e=t[0];for(let n of t.slice(1))e+=`[${n}]`;return e}function R(t){return JSON.stringify(t)}function z(t,e){let n=`${e.baseUrl}${t}`;if(e.params.path)for(let[o,a]of Object.entries(e.params.path))n=n.replace(`{${o}}`,encodeURIComponent(String(a)));let r=e.querySerializer(e.params.query??{});return r&&(n+=`?${r}`),n}function $(...t){let e=new Headers;for(let n of t){if(!n||typeof n!="object")continue;let r=n instanceof Headers?n.entries():Object.entries(n);for(let[o,a]of r)a===null?e.delete(o):a!==void 0&&e.set(o,a)}return e}var S={production:"https://swap.prod.swing.xyz",development:"https://swap.dev.swing.xyz",testnet:"https://swap-testnet.dev.swing.xyz"},P={environment:"production",baseUrl:"",headers:{}},x=new WeakMap;function D({environment:t=P.environment,baseUrl:e,headers:n}=P){let r={environment:t||"production",headers:n,baseUrl:e};if(!(r.environment in S))if(r.environment==="dev")r.environment="development";else throw new Error(`Invalid environment: ${r.environment}. Valid options are ${Object.keys(S).join(", ")}.`);let o=x.get(r);return o||(o={...g({baseUrl:e||S[r.environment],headers:{...r.headers,"x-swing-environment":r.environment}}),environment:r.environment},x.set(r,o)),o}export{D as getSwingAPI}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@swing.xyz/cross-chain-api", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
67345
1386