@purrkit/rest 1.1.0 → 1.1.2

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/client.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { DiscordRestClient } from "./types";
2
2
  export interface ClientOptions {
3
3
  token: string;
4
+ tokenType?: "Bot" | "Bearer";
4
5
  baseUrl?: string;
5
- fetch?: typeof fetch;
6
+ fetch?: (input: RequestInfo | URL | string, init?: RequestInit) => Promise<Response>;
6
7
  }
7
8
  export declare function RESTClient(options: ClientOptions): DiscordRestClient;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- function h(u){let R=u.baseUrl||"https://discord.com/api/v10",k=u.fetch??globalThis.fetch,x=async(d,m,a,c,p)=>{let i=`${R}/${d.join("/")}`;if(c){let e=new URLSearchParams;for(let[r,t]of Object.entries(c))if(t!==void 0&&t!==null)if(Array.isArray(t))for(let o of t)e.append(r,String(o));else e.append(r,String(t));let n=e.toString();if(n)i+=`?${n}`}try{let e=typeof FormData<"u"&&a instanceof FormData,n={Authorization:`Bot ${u.token}`,...p};if(!e&&!n["Content-Type"]&&a!==void 0)n["Content-Type"]="application/json";let r=await k(i,{method:m,headers:n,body:e?a:a!==void 0?JSON.stringify(a):void 0}),t=r.ok,o=r.status,s=null;if(o!==204)s=await r.json().catch(()=>null);if(t)return{ok:!0,data:s,status:o};return{ok:!1,data:s&&typeof s==="object"&&"message"in s?s:{message:"Unknown API Error"},status:o}}catch(e){return{ok:!1,data:{message:e instanceof Error?e.message:"Network Error"},status:0}}},y=(d=[])=>{return new Proxy(()=>{},{apply(c,p,i){let e=[...d,...i.map(String)];return y(e)},get(c,p){let i=String(p);if(p==="then"){let t=x(d,"GET");return t.then.bind(t)}let e=i.toLowerCase(),n={create:"POST",post:"POST",delete:"DELETE",update:"PATCH",patch:"PATCH",put:"PUT",get:"GET"};if(e in n){let t=n[e];if(!t)throw Error(`unsupported HTTP method: ${e}`);return async(o,s)=>{let l,f,g;if(t==="GET"||t==="DELETE"){let T=o;f=T?.query,g=T?.headers}else l=o,f=s?.query,g=s?.headers;return x(d,t,l,f,g)}}let r=p==="me"?"@me":i;return y([...d,r])}})};return y([])}export{h as RESTClient};
2
+ function h(c){let R=c.baseUrl||"https://discord.com/api/v10",k=c.fetch??globalThis.fetch,x=async(d,m,a,u,p)=>{let i=`${R}/${d.join("/")}`;if(u){let e=new URLSearchParams;for(let[r,t]of Object.entries(u))if(t!==void 0&&t!==null)if(Array.isArray(t))for(let o of t)e.append(r,String(o));else e.append(r,String(t));let n=e.toString();if(n)i+=`?${n}`}try{let e=typeof FormData<"u"&&a instanceof FormData,n={Authorization:`${c.tokenType??"Bot"} ${c.token}`,...p};if(!e&&!n["Content-Type"]&&a!==void 0)n["Content-Type"]="application/json";let r=await k(i,{method:m,headers:n,body:e?a:a!==void 0?JSON.stringify(a):void 0}),t=r.ok,o=r.status,s=null;if(o!==204)s=await r.json().catch(()=>null);if(t)return{ok:!0,data:s,status:o};return{ok:!1,data:s&&typeof s==="object"&&"message"in s?s:{message:"Unknown API Error"},status:o}}catch(e){return{ok:!1,data:{message:e instanceof Error?e.message:"Network Error"},status:0}}},y=(d=[])=>{return new Proxy(()=>{},{apply(u,p,i){let e=[...d,...i.map(String)];return y(e)},get(u,p){let i=String(p);if(p==="then"){let t=x(d,"GET");return t.then.bind(t)}let e=i.toLowerCase(),n={create:"POST",post:"POST",delete:"DELETE",update:"PATCH",patch:"PATCH",put:"PUT",get:"GET"};if(e in n){let t=n[e];if(!t)throw Error(`unsupported HTTP method: ${e}`);return async(o,s)=>{let l,f,g;if(t==="GET"||t==="DELETE"){let T=o;f=T?.query,g=T?.headers}else l=o,f=s?.query,g=s?.headers;return x(d,t,l,f,g)}}let r=p==="me"?"@me":i;return y([...d,r])}})};return y([])}export{h as RESTClient};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purrkit/rest",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "license": "EUPL-1.2",
5
5
  "files": [
6
6
  "dist",