@gw2me/client 0.4.1 → 0.5.1

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.d.ts CHANGED
@@ -87,6 +87,9 @@ interface AuthTokenParams {
87
87
  interface RefreshTokenParams {
88
88
  refresh_token: string;
89
89
  }
90
+ interface RevokeTokenParams {
91
+ token: string;
92
+ }
90
93
  interface TokenResponse {
91
94
  access_token: string;
92
95
  issued_token_type: 'urn:ietf:params:oauth:token-type:access_token';
@@ -102,6 +105,7 @@ declare class Gw2MeClient {
102
105
  getAuthorizationUrl({ redirect_uri, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes, verified_accounts_only, }: AuthorizationUrlParams): string;
103
106
  getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
104
107
  refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
108
+ revokeToken({ token }: RevokeTokenParams): Promise<void>;
105
109
  /**
106
110
  * Parses the search params received from gw2.me on the redirect url (code and state).
107
111
  * If gw2.me returned an error response, this will throw an error.
@@ -125,4 +129,4 @@ declare class Gw2MeOAuthError extends Gw2MeError {
125
129
  constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined);
126
130
  }
127
131
 
128
- export { type AccountsResponse, type AuthTokenParams, type AuthorizationUrlParams, type ClientInfo, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeOAuthError, type Options, type RefreshTokenParams, Scope, type SubtokenResponse, type TokenResponse, type UserResponse };
132
+ export { type AccountsResponse, type AuthTokenParams, type AuthorizationUrlParams, type ClientInfo, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeOAuthError, type Options, type RefreshTokenParams, type RevokeTokenParams, Scope, type SubtokenResponse, type TokenResponse, type UserResponse };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var C=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var O=r=>{throw TypeError(r)};var L=(r,e)=>{for(var t in e)C(r,t,{get:e[t],enumerable:!0})},M=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z(e))!j.call(r,i)&&i!==t&&C(r,i,{get:()=>e[i],enumerable:!(n=W(e,i))||n.enumerable});return r};var B=r=>M(C({},"__esModule",{value:!0}),r);var T=(r,e,t)=>e.has(r)||O("Cannot "+t);var s=(r,e,t)=>(T(r,e,"read from private field"),t?t.call(r):e.get(r)),c=(r,e,t)=>e.has(r)?O("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),l=(r,e,t,n)=>(T(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),p=(r,e,t)=>(T(r,e,"access private method"),t);var E={};L(E,{Gw2MeApi:()=>x,Gw2MeClient:()=>I,Gw2MeError:()=>a,Gw2MeOAuthError:()=>y,Scope:()=>G});module.exports=B(E);var G=(o=>(o.Identify="identify",o.Email="email",o.Accounts="accounts",o.Accounts_Verified="accounts.verified",o.Accounts_DisplayName="accounts.displayName",o.GW2_Account="gw2:account",o.GW2_Inventories="gw2:inventories",o.GW2_Characters="gw2:characters",o.GW2_Tradingpost="gw2:tradingpost",o.GW2_Wallet="gw2:wallet",o.GW2_Unlocks="gw2:unlocks",o.GW2_Pvp="gw2:pvp",o.GW2_Wvw="gw2:wvw",o.GW2_Builds="gw2:builds",o.GW2_Progression="gw2:progression",o.GW2_Guilds="gw2:guilds",o))(G||{});var a=class extends Error{},y=class extends a{constructor(t,n,i){super(`Received ${t}`+(n?`: ${n}`:"")+(i?` (${i})`:""));this.error=t;this.error_description=n;this.error_uri=i}};async function m(r){let e=r.headers.get("Content-Type")==="application/json";if(!r.ok){let t;throw e&&(t=(await r.json()).error_description),new a(`gw2.me returned an error: ${t??"Unknown error"}`)}if(!e)throw new a("gw2.me did not return a valid JSON response");return r.json()}var w,A,x=class{constructor(e,t){this.access_token=e;this.options=t;c(this,w)}user(){return fetch(p(this,w,A).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(m)}accounts(){return fetch(p(this,w,A).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(m)}subtoken(e){return fetch(p(this,w,A).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(m)}};w=new WeakSet,A=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var R,b,P=class{constructor(e,t){c(this,R);c(this,b);l(this,R,e),l(this,b,t)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({mediation:e,signal:t,mode:n}){if(!this.isSupported())throw new a("FedCM is not supported");return navigator.credentials.get({mediation:e,signal:t,identity:{providers:[{configURL:s(this,R),clientId:s(this,b)}],mode:n}})}};R=new WeakMap,b=new WeakMap;var d,g,v,h,_,I=class{constructor({client_id:e,client_secret:t},n){this.options=n;c(this,h);c(this,d);c(this,g);c(this,v);l(this,d,e),l(this,g,t),l(this,v,new P(p(this,h,_).call(this,"/fed-cm/config.json"),s(this,d)))}getAuthorizationUrl({redirect_uri:e,scopes:t,state:n,code_challenge:i,code_challenge_method:u,prompt:k,include_granted_scopes:U,verified_accounts_only:$}){let f=new URLSearchParams({client_id:s(this,d),response_type:"code",redirect_uri:e,scope:t.join(" ")});return n&&f.append("state",n),i&&u&&(f.append("code_challenge",i),f.append("code_challenge_method",u)),k&&f.append("prompt",k),U&&f.append("include_granted_scopes","true"),$&&f.append("verified_accounts_only","true"),p(this,h,_).call(this,`/oauth2/authorize?${f.toString()}`).toString()}async getAccessToken({code:e,redirect_uri:t,code_verifier:n}){let i=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:s(this,d),redirect_uri:t}),u={"Content-Type":"application/x-www-form-urlencoded"};return s(this,g)&&(u.Authorization=`Basic ${btoa(`${s(this,d)}:${s(this,g)}`)}`),n&&i.set("code_verifier",n),await fetch(p(this,h,_).call(this,"/api/token"),{method:"POST",headers:u,body:i,cache:"no-store"}).then(m)}async refreshToken({refresh_token:e}){if(!s(this,g))throw new a("client_secret required");let t=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:s(this,d)}),n={"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${btoa(`${s(this,d)}:${s(this,g)}`)}`};return await fetch(p(this,h,_).call(this,"/api/token"),{method:"POST",headers:n,body:t,cache:"no-store"}).then(m)}parseAuthorizationResponseSearchParams(e){let t=p(this,h,_).call(this,"/").origin,n=e.get("iss");if(!n)throw new a("Issuer Identifier verification failed: parameter `iss` is missing");if(n!==t)throw new a(`Issuer Identifier verification failed: expected "${t}", got "${n}"`);let i=e.get("error");if(i){let U=e.get("error_description")??void 0,$=e.get("error_uri")??void 0;throw new y(i,U,$)}let u=e.get("code");if(!u)throw new a("Parameter `code` is missing");let k=e.get("state")||void 0;return{code:u,state:k}}api(e){return new x(e,this.options)}get fedCM(){return s(this,v)}};d=new WeakMap,g=new WeakMap,v=new WeakMap,h=new WeakSet,_=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};0&&(module.exports={Gw2MeApi,Gw2MeClient,Gw2MeError,Gw2MeOAuthError,Scope});
1
+ "use strict";var U=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var I=r=>{throw TypeError(r)};var j=(r,e)=>{for(var t in e)U(r,t,{get:e[t],enumerable:!0})},B=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z(e))!L.call(r,i)&&i!==t&&U(r,i,{get:()=>e[i],enumerable:!(n=W(e,i))||n.enumerable});return r};var M=r=>B(U({},"__esModule",{value:!0}),r);var C=(r,e,t)=>e.has(r)||I("Cannot "+t);var o=(r,e,t)=>(C(r,e,"read from private field"),t?t.call(r):e.get(r)),d=(r,e,t)=>e.has(r)?I("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),m=(r,e,t,n)=>(C(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),c=(r,e,t)=>(C(r,e,"access private method"),t);var E={};j(E,{Gw2MeApi:()=>x,Gw2MeClient:()=>O,Gw2MeError:()=>a,Gw2MeOAuthError:()=>y,Scope:()=>G});module.exports=M(E);var G=(s=>(s.Identify="identify",s.Email="email",s.Accounts="accounts",s.Accounts_Verified="accounts.verified",s.Accounts_DisplayName="accounts.displayName",s.GW2_Account="gw2:account",s.GW2_Inventories="gw2:inventories",s.GW2_Characters="gw2:characters",s.GW2_Tradingpost="gw2:tradingpost",s.GW2_Wallet="gw2:wallet",s.GW2_Unlocks="gw2:unlocks",s.GW2_Pvp="gw2:pvp",s.GW2_Wvw="gw2:wvw",s.GW2_Builds="gw2:builds",s.GW2_Progression="gw2:progression",s.GW2_Guilds="gw2:guilds",s))(G||{});var a=class extends Error{},y=class extends a{constructor(t,n,i){super(`Received ${t}`+(n?`: ${n}`:"")+(i?` (${i})`:""));this.error=t;this.error_description=n;this.error_uri=i}};async function f(r){let e=r.headers.get("Content-Type")==="application/json";if(!r.ok){let t;throw e&&(t=(await r.json()).error_description),new a(`gw2.me returned an error: ${t??"Unknown error"}`)}if(!e)throw new a("gw2.me did not return a valid JSON response");return r.json()}var _,P,x=class{constructor(e,t){this.access_token=e;this.options=t;d(this,_)}user(){return fetch(c(this,_,P).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}accounts(){return fetch(c(this,_,P).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}subtoken(e){return fetch(c(this,_,P).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}};_=new WeakSet,P=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var R,v,A=class{constructor(e,t){d(this,R);d(this,v);m(this,R,e),m(this,v,t)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({mediation:e,signal:t,mode:n}){if(!this.isSupported())throw new a("FedCM is not supported");return navigator.credentials.get({mediation:e,signal:t,identity:{providers:[{configURL:o(this,R),clientId:o(this,v)}],mode:n}})}};R=new WeakMap,v=new WeakMap;var p,u,b,h,w,O=class{constructor({client_id:e,client_secret:t},n){this.options=n;d(this,h);d(this,p);d(this,u);d(this,b);m(this,p,e),m(this,u,t),m(this,b,new A(c(this,h,w).call(this,"/fed-cm/config.json"),o(this,p)))}getAuthorizationUrl({redirect_uri:e,scopes:t,state:n,code_challenge:i,code_challenge_method:g,prompt:k,include_granted_scopes:T,verified_accounts_only:$}){let l=new URLSearchParams({client_id:o(this,p),response_type:"code",redirect_uri:e,scope:t.join(" ")});return n&&l.append("state",n),i&&g&&(l.append("code_challenge",i),l.append("code_challenge_method",g)),k&&l.append("prompt",k),T&&l.append("include_granted_scopes","true"),$&&l.append("verified_accounts_only","true"),c(this,h,w).call(this,`/oauth2/authorize?${l.toString()}`).toString()}async getAccessToken({code:e,redirect_uri:t,code_verifier:n}){let i=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:o(this,p),redirect_uri:t}),g={"Content-Type":"application/x-www-form-urlencoded"};return o(this,u)&&(g.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,u)}`)}`),n&&i.set("code_verifier",n),await fetch(c(this,h,w).call(this,"/api/token"),{method:"POST",headers:g,body:i,cache:"no-store"}).then(f)}async refreshToken({refresh_token:e}){if(!o(this,u))throw new a("client_secret required");let t=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:o(this,p)}),n={"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${btoa(`${o(this,p)}:${o(this,u)}`)}`};return await fetch(c(this,h,w).call(this,"/api/token"),{method:"POST",headers:n,body:t,cache:"no-store"}).then(f)}async revokeToken({token:e}){let t=new URLSearchParams({token:e}),n={"Content-Type":"application/x-www-form-urlencoded"};o(this,u)&&(n.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,u)}`)}`),await fetch(c(this,h,w).call(this,"/api/revoke"),{method:"POST",cache:"no-store",headers:n,body:t}).then(f)}parseAuthorizationResponseSearchParams(e){let t=c(this,h,w).call(this,"/").origin,n=e.get("iss");if(!n)throw new a("Issuer Identifier verification failed: parameter `iss` is missing");if(n!==t)throw new a(`Issuer Identifier verification failed: expected "${t}", got "${n}"`);let i=e.get("error");if(i){let T=e.get("error_description")??void 0,$=e.get("error_uri")??void 0;throw new y(i,T,$)}let g=e.get("code");if(!g)throw new a("Parameter `code` is missing");let k=e.get("state")||void 0;return{code:g,state:k}}api(e){return new x(e,this.options)}get fedCM(){return o(this,b)}};p=new WeakMap,u=new WeakMap,b=new WeakMap,h=new WeakSet,w=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};0&&(module.exports={Gw2MeApi,Gw2MeClient,Gw2MeError,Gw2MeOAuthError,Scope});
package/dist/pkce.d.ts CHANGED
@@ -4,7 +4,7 @@ interface PKCEChallenge {
4
4
  }
5
5
  interface PKCEPair {
6
6
  challenge: PKCEChallenge;
7
- verifier: string;
7
+ code_verifier: string;
8
8
  }
9
9
  declare function generatePKCEPair(): Promise<PKCEPair>;
10
10
 
package/dist/pkce.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var n in e)t(r,n,{get:e[n],enumerable:!0})},s=(r,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of i(e))!g.call(r,c)&&c!==n&&t(r,c,{get:()=>e[c],enumerable:!(a=l(e,c))||a.enumerable});return r};var f=r=>s(t({},"__esModule",{value:!0}),r);var u={};d(u,{generatePKCEPair:()=>h});module.exports=f(u);async function h(){let r=new Uint8Array(32);crypto.getRandomValues(r);let e=o(r.buffer),n=new TextEncoder,a=await crypto.subtle.digest("SHA-256",n.encode(e));return{verifier:e,challenge:{code_challenge_method:"S256",code_challenge:o(a)}}}function o(r){return btoa(String.fromCharCode(...new Uint8Array(r))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}0&&(module.exports={generatePKCEPair});
1
+ "use strict";var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var d=(e,r)=>{for(var n in r)a(e,n,{get:r[n],enumerable:!0})},h=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let c of i(r))!g.call(e,c)&&c!==n&&a(e,c,{get:()=>r[c],enumerable:!(t=l(r,c))||t.enumerable});return e};var s=e=>h(a({},"__esModule",{value:!0}),e);var C={};d(C,{generatePKCEPair:()=>f});module.exports=s(C);async function f(){let e=new Uint8Array(32);crypto.getRandomValues(e);let r=o(e),n=new TextEncoder,t=await crypto.subtle.digest("SHA-256",n.encode(r));return{code_verifier:r,challenge:{code_challenge_method:"S256",code_challenge:o(new Uint8Array(t))}}}function o(e){return btoa(String.fromCharCode(...e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}0&&(module.exports={generatePKCEPair});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw2me/client",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "gw2.me client library",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "eslint": "8.57.1",
43
43
  "tsup": "8.3.5",
44
44
  "typescript": "5.7.2",
45
- "undici-types": "6.21.0"
45
+ "undici-types": "7.1.1"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "pnpm run clean && if test $CI; then pnpm run build:ci; else pnpm run build:local; fi",