@gw2me/client 0.6.2 → 0.7.0

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 AuthorizationUrlParams {
87
87
  include_granted_scopes?: boolean;
88
88
  verified_accounts_only?: boolean;
89
89
  }
90
+ interface AuthorizationUrlRequestUriParams {
91
+ request_uri: string;
92
+ }
90
93
  interface AuthTokenParams {
91
94
  code: string;
92
95
  redirect_uri: string;
@@ -118,11 +121,16 @@ type IntrospectTokenResponse = {
118
121
  } | {
119
122
  active: false;
120
123
  };
124
+ interface PushedAuthorizationRequestResponse {
125
+ request_uri: string;
126
+ expires_in: number;
127
+ }
121
128
  declare class Gw2MeClient {
122
129
  #private;
123
130
  private options?;
124
131
  constructor({ client_id, client_secret }: ClientInfo, options?: Partial<Options> | undefined);
125
- getAuthorizationUrl({ redirect_uri, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes, verified_accounts_only, }: AuthorizationUrlParams): string;
132
+ getAuthorizationUrl(params: AuthorizationUrlParams | AuthorizationUrlRequestUriParams): string;
133
+ pushAuthorizationRequest(params: AuthorizationUrlParams): Promise<PushedAuthorizationRequestResponse>;
126
134
  getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
127
135
  refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
128
136
  revokeToken({ token }: RevokeTokenParams): Promise<void>;
@@ -150,4 +158,4 @@ declare class Gw2MeOAuthError extends Gw2MeError {
150
158
  constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined);
151
159
  }
152
160
 
153
- export { type AccountsResponse, type AuthTokenParams, type AuthorizationUrlParams, type ClientInfo, type FedCMRequestOptions, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeFedCM, Gw2MeOAuthError, type IntrospectTokenParams, type IntrospectTokenResponse, type Options, type RefreshTokenParams, type RevokeTokenParams, Scope, type SubtokenOptions, type SubtokenResponse, type TokenResponse, type UserResponse };
161
+ export { type AccountsResponse, type AuthTokenParams, type AuthorizationUrlParams, type AuthorizationUrlRequestUriParams, type ClientInfo, type FedCMRequestOptions, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeFedCM, Gw2MeOAuthError, type IntrospectTokenParams, type IntrospectTokenResponse, type Options, type PushedAuthorizationRequestResponse, type RefreshTokenParams, type RevokeTokenParams, Scope, type SubtokenOptions, type SubtokenResponse, type TokenResponse, type UserResponse };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var O=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var S=n=>{throw TypeError(n)};var B=(n,e)=>{for(var t in e)O(n,t,{get:e[t],enumerable:!0})},E=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of W(e))!j.call(n,i)&&i!==t&&O(n,i,{get:()=>e[i],enumerable:!(r=G(e,i))||r.enumerable});return n};var L=n=>E(O({},"__esModule",{value:!0}),n);var U=(n,e,t)=>e.has(n)||S("Cannot "+t);var o=(n,e,t)=>(U(n,e,"read from private field"),t?t.call(n):e.get(n)),h=(n,e,t)=>e.has(n)?S("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),k=(n,e,t,r)=>(U(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),c=(n,e,t)=>(U(n,e,"access private method"),t);var M={};B(M,{Gw2MeApi:()=>R,Gw2MeClient:()=>z,Gw2MeError:()=>a,Gw2MeOAuthError:()=>y,Scope:()=>C});module.exports=L(M);var C=(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))(C||{});var a=class extends Error{},y=class extends a{constructor(t,r,i){super(`Received ${t}`+(r?`: ${r}`:"")+(i?` (${i})`:""));this.error=t;this.error_description=r;this.error_uri=i}};async function f(n){if(await I(n),!(n.headers.get("Content-Type")==="application/json"))throw new a("gw2.me did not return a valid JSON response");return n.json()}async function I(n){if(!n.ok){let e;throw n.headers.get("Content-Type")==="application/json"&&(e=(await n.json()).error_description),new a(`gw2.me returned an error: ${e??"Unknown error"}`)}}var _,x,R=class{constructor(e,t){this.access_token=e;this.options=t;h(this,_)}user(){return fetch(c(this,_,x).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}saveSettings(e){return fetch(c(this,_,x).call(this,"api/user/settings"),{method:"POST",headers:{Authorization:`Bearer ${this.access_token}`,"Content-Type":"application/json"},body:JSON.stringify(e)}).then(I)}accounts(){return fetch(c(this,_,x).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}subtoken(e,t){let r=c(this,_,x).call(this,`api/accounts/${e}/subtoken`);return t?.permissions&&r.searchParams.set("permissions",t.permissions.join(",")),fetch(r,{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}};_=new WeakSet,x=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var v,P,b=class{constructor(e,t){h(this,v);h(this,P);k(this,v,e),k(this,P,t)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({scopes:e,mediation:t,signal:r,mode:i,code_challenge:u,code_challenge_method:l}){if(!this.isSupported())throw new a("FedCM is not supported");return navigator.credentials.get({mediation:t,signal:r,identity:{providers:[{configURL:o(this,v),clientId:o(this,P),fields:[e.includes("identify")&&"name",e.includes("email")&&"email"].filter(Boolean),nonce:`${l}:${u}`,params:{scope:e.join(" "),code_challenge:u,code_challenge_method:l}}],mode:i}})}};v=new WeakMap,P=new WeakMap;var p,d,T,g,m,z=class{constructor({client_id:e,client_secret:t},r){this.options=r;h(this,g);h(this,p);h(this,d);h(this,T);k(this,p,e),k(this,d,t),k(this,T,new b(c(this,g,m).call(this,"/fed-cm/config.json"),o(this,p)))}getAuthorizationUrl({redirect_uri:e,scopes:t,state:r,code_challenge:i,code_challenge_method:u,prompt:l,include_granted_scopes:$,verified_accounts_only:A}){let w=new URLSearchParams({client_id:o(this,p),response_type:"code",redirect_uri:e,scope:t.join(" ")});return r&&w.append("state",r),i&&u&&(w.append("code_challenge",i),w.append("code_challenge_method",u)),l&&w.append("prompt",l),$&&w.append("include_granted_scopes","true"),A&&w.append("verified_accounts_only","true"),c(this,g,m).call(this,`/oauth2/authorize?${w.toString()}`).toString()}async getAccessToken({code:e,redirect_uri:t,code_verifier:r}){let i=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:o(this,p),redirect_uri:t}),u={"Content-Type":"application/x-www-form-urlencoded"};return o(this,d)&&(u.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,d)}`)}`),r&&i.set("code_verifier",r),await fetch(c(this,g,m).call(this,"/api/token"),{method:"POST",headers:u,body:i,cache:"no-store"}).then(f)}async refreshToken({refresh_token:e}){if(!o(this,d))throw new a("client_secret required");let t=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:o(this,p)}),r={"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${btoa(`${o(this,p)}:${o(this,d)}`)}`};return await fetch(c(this,g,m).call(this,"/api/token"),{method:"POST",headers:r,body:t,cache:"no-store"}).then(f)}async revokeToken({token:e}){let t=new URLSearchParams({token:e}),r={"Content-Type":"application/x-www-form-urlencoded"};o(this,d)&&(r.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,d)}`)}`),await fetch(c(this,g,m).call(this,"/api/token/revoke"),{method:"POST",cache:"no-store",headers:r,body:t}).then(f)}async introspectToken({token:e}){let t=new URLSearchParams({token:e}),r={"Content-Type":"application/x-www-form-urlencoded"};return o(this,d)&&(r.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,d)}`)}`),await fetch(c(this,g,m).call(this,"/api/token/introspect"),{method:"POST",cache:"no-store",headers:r,body:t}).then(f)}parseAuthorizationResponseSearchParams(e){let t=c(this,g,m).call(this,"/").origin,r=e.get("iss");if(!r)throw new a("Issuer Identifier verification failed: parameter `iss` is missing");if(r!==t)throw new a(`Issuer Identifier verification failed: expected "${t}", got "${r}"`);let i=e.get("error");if(i){let $=e.get("error_description")??void 0,A=e.get("error_uri")??void 0;throw new y(i,$,A)}let u=e.get("code");if(!u)throw new a("Parameter `code` is missing");let l=e.get("state")||void 0;return{code:u,state:l}}api(e){return new R(e,this.options)}get fedCM(){return o(this,T)}};p=new WeakMap,d=new WeakMap,T=new WeakMap,g=new WeakSet,m=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 B=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var q=r=>{throw TypeError(r)};var j=(r,e)=>{for(var t in e)U(r,t,{get:e[t],enumerable:!0})},L=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of G(e))!W.call(r,s)&&s!==t&&U(r,s,{get:()=>e[s],enumerable:!(n=B(e,s))||n.enumerable});return r};var E=r=>L(U({},"__esModule",{value:!0}),r);var z=(r,e,t)=>e.has(r)||q("Cannot "+t);var i=(r,e,t)=>(z(r,e,"read from private field"),t?t.call(r):e.get(r)),g=(r,e,t)=>e.has(r)?q("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),_=(r,e,t,n)=>(z(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),c=(r,e,t)=>(z(r,e,"access private method"),t);var M={};j(M,{Gw2MeApi:()=>P,Gw2MeClient:()=>I,Gw2MeError:()=>p,Gw2MeOAuthError:()=>y,Scope:()=>O});module.exports=E(M);var O=(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))(O||{});var p=class extends Error{},y=class extends p{constructor(t,n,s){super(`Received ${t}`+(n?`: ${n}`:"")+(s?` (${s})`:""));this.error=t;this.error_description=n;this.error_uri=s}};async function f(r){if(await C(r),!(r.headers.get("Content-Type")==="application/json"))throw new p("gw2.me did not return a valid JSON response");return r.json()}async function C(r){if(!r.ok){let e;throw r.headers.get("Content-Type")==="application/json"&&(e=(await r.json()).error_description),new p(`gw2.me returned an error: ${e??"Unknown error"}`)}}var k,R,P=class{constructor(e,t){this.access_token=e;this.options=t;g(this,k)}user(){return fetch(c(this,k,R).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}saveSettings(e){return fetch(c(this,k,R).call(this,"api/user/settings"),{method:"POST",headers:{Authorization:`Bearer ${this.access_token}`,"Content-Type":"application/json"},body:JSON.stringify(e)}).then(C)}accounts(){return fetch(c(this,k,R).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}subtoken(e,t){let n=c(this,k,R).call(this,`api/accounts/${e}/subtoken`);return t?.permissions&&n.searchParams.set("permissions",t.permissions.join(",")),fetch(n,{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}};k=new WeakSet,R=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var x,b,v=class{constructor(e,t){g(this,x);g(this,b);_(this,x,e),_(this,b,t)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({scopes:e,mediation:t,signal:n,mode:s,code_challenge:d,code_challenge_method:m}){if(!this.isSupported())throw new p("FedCM is not supported");return navigator.credentials.get({mediation:t,signal:n,identity:{providers:[{configURL:i(this,x),clientId:i(this,b),fields:[e.includes("identify")&&"name",e.includes("email")&&"email"].filter(Boolean),nonce:`${m}:${d}`,params:{scope:e.join(" "),code_challenge:d,code_challenge_method:m}}],mode:s}})}};x=new WeakMap,b=new WeakMap;var a,u,A,h,l,I=class{constructor({client_id:e,client_secret:t},n){this.options=n;g(this,h);g(this,a);g(this,u);g(this,A);_(this,a,e),_(this,u,t),_(this,A,new v(c(this,h,l).call(this,"/fed-cm/config.json"),i(this,a)))}getAuthorizationUrl(e){let t="request_uri"in e?new URLSearchParams({client_id:i(this,a),response_type:"code",request_uri:e.request_uri}):S(i(this,a),e);return c(this,h,l).call(this,`/oauth2/authorize?${t.toString()}`).toString()}async pushAuthorizationRequest(e){let t=S(i(this,a),e),n={"Content-Type":"application/x-www-form-urlencoded"};return i(this,u)&&(n.Authorization=`Basic ${btoa(`${i(this,a)}:${i(this,u)}`)}`),await fetch(c(this,h,l).call(this,"/oauth2/par"),{method:"POST",headers:n,body:t,cache:"no-store"}).then(f)}async getAccessToken({code:e,redirect_uri:t,code_verifier:n}){let s=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:i(this,a),redirect_uri:t}),d={"Content-Type":"application/x-www-form-urlencoded"};return i(this,u)&&(d.Authorization=`Basic ${btoa(`${i(this,a)}:${i(this,u)}`)}`),n&&s.set("code_verifier",n),await fetch(c(this,h,l).call(this,"/api/token"),{method:"POST",headers:d,body:s,cache:"no-store"}).then(f)}async refreshToken({refresh_token:e}){if(!i(this,u))throw new p("client_secret required");let t=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:i(this,a)}),n={"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${btoa(`${i(this,a)}:${i(this,u)}`)}`};return await fetch(c(this,h,l).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"};i(this,u)&&(n.Authorization=`Basic ${btoa(`${i(this,a)}:${i(this,u)}`)}`),await fetch(c(this,h,l).call(this,"/api/token/revoke"),{method:"POST",cache:"no-store",headers:n,body:t}).then(f)}async introspectToken({token:e}){let t=new URLSearchParams({token:e}),n={"Content-Type":"application/x-www-form-urlencoded"};return i(this,u)&&(n.Authorization=`Basic ${btoa(`${i(this,a)}:${i(this,u)}`)}`),await fetch(c(this,h,l).call(this,"/api/token/introspect"),{method:"POST",cache:"no-store",headers:n,body:t}).then(f)}parseAuthorizationResponseSearchParams(e){let t=c(this,h,l).call(this,"/").origin,n=e.get("iss");if(!n)throw new p("Issuer Identifier verification failed: parameter `iss` is missing");if(n!==t)throw new p(`Issuer Identifier verification failed: expected "${t}", got "${n}"`);let s=e.get("error");if(s){let T=e.get("error_description")??void 0,$=e.get("error_uri")??void 0;throw new y(s,T,$)}let d=e.get("code");if(!d)throw new p("Parameter `code` is missing");let m=e.get("state")||void 0;return{code:d,state:m}}api(e){return new P(e,this.options)}get fedCM(){return i(this,A)}};a=new WeakMap,u=new WeakMap,A=new WeakMap,h=new WeakSet,l=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};function S(r,{redirect_uri:e,scopes:t,state:n,code_challenge:s,code_challenge_method:d,prompt:m,include_granted_scopes:T,verified_accounts_only:$}){let w=new URLSearchParams({client_id:r,response_type:"code",redirect_uri:e,scope:t.join(" ")});return n&&w.append("state",n),s&&d&&(w.append("code_challenge",s),w.append("code_challenge_method",d)),m&&w.append("prompt",m),T&&w.append("include_granted_scopes","true"),$&&w.append("verified_accounts_only","true"),w}0&&(module.exports={Gw2MeApi,Gw2MeClient,Gw2MeError,Gw2MeOAuthError,Scope});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw2me/client",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "gw2.me client library",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",