@swing.xyz/cross-chain-api
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,2 +0,2 @@ | ||
var A={"Content-Type":"application/json"};function m(e={}){let{fetch:n=globalThis.fetch,querySerializer:o,bodySerializer:a,...d}=e,i=d.baseUrl??"";i.endsWith("/")&&(i=i.slice(0,-1));async function c(t,r){let{fetch:T=n,headers:w,body:S,params:E={},parseAs:l="json",querySerializer:g=o??P,bodySerializer:C=a??R,...U}=r||{},x=v(t,{baseUrl:i,params:E,querySerializer:g}),b=z(A,e?.headers,w,E.header),u={redirect:"follow",...d,...U,headers:b};S&&(u.body=C(S)),u.body instanceof FormData&&b.delete("Content-Type");let s=await T(x,u);if(s.status===204||s.headers.get("Content-Length")==="0")return s.ok?{data:{},response:s}:{error:{},response:s};if(s.ok){let y;if(l!=="stream"){let h=s.clone();y=typeof h[l]=="function"?await h[l]():await h.text()}else y=s.clone().body;return{data:y,response:s}}let p={};try{p=await s.clone().json()}catch{p=await s.clone().text()}return{error:p,response:s}}return{async GET(t,...r){return c(t,{...r[0],method:"GET"})},async PUT(t,...r){return c(t,{...r[0],method:"PUT"})},async POST(t,...r){return c(t,{...r[0],method:"POST"})},async DELETE(t,...r){return c(t,{...r[0],method:"DELETE"})},async OPTIONS(t,...r){return c(t,{...r[0],method:"OPTIONS"})},async HEAD(t,...r){return c(t,{...r[0],method:"HEAD"})},async PATCH(t,...r){return c(t,{...r[0],method:"PATCH"})},async TRACE(t,...r){return c(t,{...r[0],method:"TRACE"})}}}function P(e){let n=new URLSearchParams;if(e&&typeof e=="object")for(let[o,a]of Object.entries(e))a!=null&&n.set(o,a);return n.toString()}function R(e){return JSON.stringify(e)}function v(e,n){let o=`${n.baseUrl}${e}`;if(n.params.path)for(let[d,i]of Object.entries(n.params.path))o=o.replace(`{${d}}`,encodeURIComponent(String(i)));let a=n.querySerializer(n.params.query??{});return a&&(o+=`?${a}`),o}function z(...e){let n=new Headers;for(let o of e){if(!o||typeof o!="object")continue;let a=o instanceof Headers?o.entries():Object.entries(o);for(let[d,i]of a)i===null?n.delete(d):i!==void 0&&n.set(d,i)}return n}var O={production:"https://swap.prod.swing.xyz",development:"https://swap.dev.swing.xyz",testnet:"https://swap-testnet.dev.swing.xyz"},f={production:void 0,development:void 0,testnet:void 0};function I({environment:e="production"}={}){if(!(e in f))if(e==="dev")e="development";else throw new Error(`Invalid environment: ${e}. Valid options are ${Object.keys(f).join(", ")}.`);if(!f[e]){let n=m({baseUrl:O[e]});f[e]={...n,environment:e}}return f[e]||f.production}export{I as getSwingAPI}; | ||
var C={"Content-Type":"application/json"};function g(t={}){let{fetch:e=globalThis.fetch,querySerializer:n,bodySerializer:s,...r}=t,a=r.baseUrl??"";a.endsWith("/")&&(a=a.slice(0,-1));async function f(o,i){let{fetch:x=e,headers:P,body:b,params:w={},parseAs:d="json",querySerializer:T=n??U,bodySerializer:I=s??R,...j}=i||{},O=z(o,{baseUrl:a,params:w,querySerializer:T}),A=$(C,t?.headers,P,w.header),u={redirect:"follow",...r,...j,headers:A};b&&(u.body=I(b)),u.body instanceof FormData&&A.delete("Content-Type");let c=await x(O,u);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 y=c.clone();l=typeof y[d]=="function"?await y[d]():await y.text()}else l=c.clone().body;return{data:l,response:c}}let p={};try{p=await c.clone().json()}catch{p=await c.clone().text()}return{error:p,response:c}}return{async GET(o,...i){return f(o,{...i[0],method:"GET"})},async PUT(o,...i){return f(o,{...i[0],method:"PUT"})},async POST(o,...i){return f(o,{...i[0],method:"POST"})},async DELETE(o,...i){return f(o,{...i[0],method:"DELETE"})},async OPTIONS(o,...i){return f(o,{...i[0],method:"OPTIONS"})},async HEAD(o,...i){return f(o,{...i[0],method:"HEAD"})},async PATCH(o,...i){return f(o,{...i[0],method:"PATCH"})},async TRACE(o,...i){return f(o,{...i[0],method:"TRACE"})}}}function U(t){let e=[];if(t&&typeof t=="object")for(let[n,s]of Object.entries(t)){let r=m([n],s);r&&e.push(r)}return e.join("&")}function m(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 s of e){let r=m(t,s);r!==void 0&&n.push(r)}return n.join("&")}if(typeof e=="object"){if(!Object.keys(e).length)return;let n=[];for(let[s,r]of Object.entries(e))if(r!=null){let a=m([...t,s],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 R(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 s=e.querySerializer(e.params.query??{});return s&&(n+=`?${s}`),n}function $(...t){let e=new Headers;for(let n of t){if(!n||typeof n!="object")continue;let s=n instanceof Headers?n.entries():Object.entries(n);for(let[r,a]of s)a===null?e.delete(r):a!==void 0&&e.set(r,a)}return e}var S={production:"https://swap.prod.swing.xyz",development:"https://swap.dev.swing.xyz",testnet:"https://swap-testnet.dev.swing.xyz"},E=new WeakMap;function D({environment:t="production",headers:e}={environment:"production"}){if(!(t in S))if(t==="dev")t="development";else throw new Error(`Invalid environment: ${t}. Valid options are ${Object.keys(S).join(", ")}.`);let n=E.get({environment:t,headers:e});return n||(n={...g({baseUrl:S[t]}),environment:t},E.set({environment:t,headers:e},n)),n}export{D as getSwingAPI}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@swing.xyz/cross-chain-api", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"publishConfig": { | ||
@@ -42,7 +42,7 @@ "access": "public" | ||
"@swing.xyz/tsconfig": "workspace:*", | ||
"openapi-fetch": "^0.7.10", | ||
"openapi-fetch": "^0.8.1", | ||
"openapi-typescript": "^6.7.0", | ||
"tsup": "^7.2.0", | ||
"tsx": "^3.13.0" | ||
"tsx": "^3.14.0" | ||
} | ||
} |
@@ -11,8 +11,13 @@ # Swing Cross-Chain API | ||
## Usage | ||
```ts | ||
import { getSwingAPI } from "@swing.xyz/cross-chain-api"; | ||
const swingAPI = getSwingAPI(); | ||
const swingAPI = getSwingAPI({ | ||
// Optional use a different API environment | ||
// environment: "production", | ||
}); | ||
const config = await swingAPI.GET("/config"); | ||
const config = await swingAPI.GET("/v0/transfer/config"); | ||
``` |
Sorry, the diff of this file is too big to display
71794
1523
23