@gw2me/client 0.6.2 → 0.8.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/dpop.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ declare function generateDPoPKeyPair(): Promise<CryptoKeyPair>;
2
+ interface DPoPOptions {
3
+ htm: 'GET' | 'POST' | (string & {});
4
+ htu: string;
5
+ nonce?: string;
6
+ accessToken?: string;
7
+ }
8
+ declare function createDPoPJwt({ htm, htu, nonce, accessToken }: DPoPOptions, keyPair: CryptoKeyPair): Promise<string>;
9
+ declare function jwkThumbprint(key: CryptoKey): Promise<string>;
10
+
11
+ export { createDPoPJwt, generateDPoPKeyPair, jwkThumbprint };
package/dist/dpop.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var h=(t,r)=>{for(var e in r)u(t,e,{get:r[e],enumerable:!0})},A=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of w(r))!l.call(t,n)&&n!==e&&u(t,n,{get:()=>r[n],enumerable:!(o=d(r,n))||o.enumerable});return t};var P=t=>A(u({},"__esModule",{value:!0}),t);var E={};h(E,{createDPoPJwt:()=>m,generateDPoPKeyPair:()=>b,jwkThumbprint:()=>C});module.exports=P(E);function a(t){let r=t instanceof ArrayBuffer?new Uint8Array(t):t;return btoa(String.fromCharCode(...r)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function b(){return crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!1,["sign"])}async function m({htm:t,htu:r,nonce:e,accessToken:o},n){let c=JSON.stringify({alg:"ES256",typ:"dpop+jwt",jwk:await p(n.publicKey)}),y=JSON.stringify({iat:Math.floor(Date.now()/1e3),jti:a(crypto.getRandomValues(new Uint8Array(32))),htm:t,htu:r,nonce:e,ath:o?a(await crypto.subtle.digest("SHA-256",i(o))):void 0}),s=`${a(i(c))}.${a(i(y))}`,g={name:"ECDSA",hash:"SHA-256"},f=a(await crypto.subtle.sign(g,n.privateKey,i(s)));return`${s}.${f}`}var S=new TextEncoder;function i(t){return S.encode(t)}async function p(t){let{kty:r,e,k:o,n,x:c,y,crv:s}=await crypto.subtle.exportKey("jwk",t);return{e,k:o,crv:s,kty:r,n,x:c,y}}async function C(t){let r=JSON.stringify(await p(t)),e=await crypto.subtle.digest("SHA-256",i(r));return a(e)}0&&(module.exports={createDPoPJwt,generateDPoPKeyPair,jwkThumbprint});
package/dist/index.d.ts CHANGED
@@ -48,11 +48,14 @@ interface SubtokenResponse {
48
48
  subtoken: string;
49
49
  expiresAt: string;
50
50
  }
51
+ interface ApiOptions extends Options {
52
+ dpopKeyPair?: CryptoKeyPair;
53
+ }
51
54
  declare class Gw2MeApi {
52
55
  #private;
53
56
  private access_token;
54
57
  private options?;
55
- constructor(access_token: string, options?: Partial<Options> | undefined);
58
+ constructor(access_token: string, options?: Partial<ApiOptions> | undefined);
56
59
  user(): Promise<UserResponse>;
57
60
  saveSettings(settings: unknown): Promise<void>;
58
61
  accounts(): Promise<AccountsResponse>;
@@ -83,22 +86,33 @@ interface AuthorizationUrlParams {
83
86
  state?: string;
84
87
  code_challenge?: string;
85
88
  code_challenge_method?: 'S256';
89
+ dpop_jkt?: string;
86
90
  prompt?: 'none' | 'consent';
87
91
  include_granted_scopes?: boolean;
88
92
  verified_accounts_only?: boolean;
89
93
  }
94
+ interface PushedAuthorizationRequestParams extends AuthorizationUrlParams {
95
+ dpopKeyPair?: CryptoKeyPair;
96
+ }
97
+ interface AuthorizationUrlRequestUriParams {
98
+ request_uri: string;
99
+ }
90
100
  interface AuthTokenParams {
91
101
  code: string;
102
+ token_type?: 'Bearer' | 'DPoP';
92
103
  redirect_uri: string;
93
104
  code_verifier?: string;
105
+ dpopKeyPair?: CryptoKeyPair;
94
106
  }
95
107
  interface RefreshTokenParams {
96
108
  refresh_token: string;
109
+ refresh_token_type?: 'Bearer' | 'DPoP';
110
+ dpopKeyPair?: CryptoKeyPair;
97
111
  }
98
112
  interface TokenResponse {
99
113
  access_token: string;
100
114
  issued_token_type: 'urn:ietf:params:oauth:token-type:access_token';
101
- token_type: 'Bearer';
115
+ token_type: 'Bearer' | 'DPoP';
102
116
  expires_in: number;
103
117
  refresh_token?: string;
104
118
  scope: string;
@@ -109,22 +123,42 @@ interface RevokeTokenParams {
109
123
  interface IntrospectTokenParams {
110
124
  token: string;
111
125
  }
112
- type IntrospectTokenResponse = {
113
- active: true;
114
- scope: string;
115
- client_id: string;
116
- token_type: 'Bearer';
117
- exp?: number;
118
- } | {
119
- active: false;
120
- };
126
+ declare namespace IntrospectTokenResponse {
127
+ interface Inactive {
128
+ active: false;
129
+ }
130
+ namespace Active {
131
+ interface Common {
132
+ active: true;
133
+ scope: string;
134
+ client_id: string;
135
+ exp?: number;
136
+ }
137
+ interface Bearer extends Common {
138
+ token_type: 'Bearer';
139
+ }
140
+ interface DPoP extends Common {
141
+ token_type: 'DPoP';
142
+ cnf: {
143
+ jkt: string;
144
+ };
145
+ }
146
+ }
147
+ type Active = Active.Bearer | Active.DPoP;
148
+ }
149
+ type IntrospectTokenResponse = IntrospectTokenResponse.Inactive | IntrospectTokenResponse.Active;
150
+ interface PushedAuthorizationRequestResponse {
151
+ request_uri: string;
152
+ expires_in: number;
153
+ }
121
154
  declare class Gw2MeClient {
122
155
  #private;
123
156
  private options?;
124
- 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;
126
- getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
127
- refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
157
+ constructor(client: ClientInfo, options?: Partial<Options> | undefined);
158
+ getAuthorizationUrl(params: AuthorizationUrlParams | AuthorizationUrlRequestUriParams): string;
159
+ pushAuthorizationRequest(params: PushedAuthorizationRequestParams): Promise<PushedAuthorizationRequestResponse>;
160
+ getAccessToken({ code, token_type, redirect_uri, code_verifier, dpopKeyPair }: AuthTokenParams): Promise<TokenResponse>;
161
+ refreshToken({ refresh_token, refresh_token_type, dpopKeyPair }: RefreshTokenParams): Promise<TokenResponse>;
128
162
  revokeToken({ token }: RevokeTokenParams): Promise<void>;
129
163
  introspectToken({ token }: IntrospectTokenParams): Promise<IntrospectTokenResponse>;
130
164
  /**
@@ -137,7 +171,7 @@ declare class Gw2MeClient {
137
171
  code: string;
138
172
  state: string | undefined;
139
173
  };
140
- api(access_token: string): Gw2MeApi;
174
+ api(access_token: string, options?: Partial<Omit<ApiOptions, keyof Options>>): Gw2MeApi;
141
175
  get fedCM(): Gw2MeFedCM;
142
176
  }
143
177
 
@@ -150,4 +184,4 @@ declare class Gw2MeOAuthError extends Gw2MeError {
150
184
  constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined);
151
185
  }
152
186
 
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 };
187
+ export { type AccountsResponse, type ApiOptions, type AuthTokenParams, type AuthorizationUrlParams, type AuthorizationUrlRequestUriParams, type ClientInfo, type FedCMRequestOptions, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeFedCM, Gw2MeOAuthError, type IntrospectTokenParams, IntrospectTokenResponse, type Options, type PushedAuthorizationRequestParams, 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 z=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var E=r=>{throw TypeError(r)};var N=(r,e)=>{for(var t in e)z(r,t,{get:e[t],enumerable:!0})},H=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of L(e))!M.call(r,o)&&o!==t&&z(r,o,{get:()=>e[o],enumerable:!(n=J(e,o))||n.enumerable});return r};var F=r=>H(z({},"__esModule",{value:!0}),r);var D=(r,e,t)=>e.has(r)||E("Cannot "+t);var c=(r,e,t)=>(D(r,e,"read from private field"),t?t.call(r):e.get(r)),m=(r,e,t)=>e.has(r)?E("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),k=(r,e,t,n)=>(D(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),s=(r,e,t)=>(D(r,e,"access private method"),t);var Q={};N(Q,{Gw2MeApi:()=>v,Gw2MeClient:()=>$,Gw2MeError:()=>f,Gw2MeOAuthError:()=>T,Scope:()=>j});module.exports=F(Q);var j=(d=>(d.Identify="identify",d.Email="email",d.Accounts="accounts",d.Accounts_Verified="accounts.verified",d.Accounts_DisplayName="accounts.displayName",d.GW2_Account="gw2:account",d.GW2_Inventories="gw2:inventories",d.GW2_Characters="gw2:characters",d.GW2_Tradingpost="gw2:tradingpost",d.GW2_Wallet="gw2:wallet",d.GW2_Unlocks="gw2:unlocks",d.GW2_Pvp="gw2:pvp",d.GW2_Wvw="gw2:wvw",d.GW2_Builds="gw2:builds",d.GW2_Progression="gw2:progression",d.GW2_Guilds="gw2:guilds",d))(j||{});function _(r){let e=r instanceof ArrayBuffer?new Uint8Array(r):r;return btoa(String.fromCharCode(...e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function x({htm:r,htu:e,nonce:t,accessToken:n},o){let i=JSON.stringify({alg:"ES256",typ:"dpop+jwt",jwk:await G(o.publicKey)}),a=JSON.stringify({iat:Math.floor(Date.now()/1e3),jti:_(crypto.getRandomValues(new Uint8Array(32))),htm:r,htu:e,nonce:t,ath:n?_(await crypto.subtle.digest("SHA-256",A(n))):void 0}),h=`${_(A(i))}.${_(A(a))}`,y={name:"ECDSA",hash:"SHA-256"},U=_(await crypto.subtle.sign(y,o.privateKey,A(h)));return`${h}.${U}`}var V=new TextEncoder;function A(r){return V.encode(r)}async function G(r){let{kty:e,e:t,k:n,n:o,x:i,y:a,crv:h}=await crypto.subtle.exportKey("jwk",r);return{e:t,k:n,crv:h,kty:e,n:o,x:i,y:a}}async function W(r){let e=JSON.stringify(await G(r)),t=await crypto.subtle.digest("SHA-256",A(e));return _(t)}var f=class extends Error{},T=class extends f{constructor(t,n,o){super(`Received ${t}`+(n?`: ${n}`:"")+(o?` (${o})`:""));this.error=t;this.error_description=n;this.error_uri=o}};async function g(r){if(await q(r),!(r.headers.get("Content-Type")==="application/json"))throw new f("gw2.me did not return a valid JSON response");return r.json()}async function q(r){if(!r.ok){let e;throw r.headers.get("Content-Type")==="application/json"&&(e=(await r.json()).error_description),new f(`gw2.me returned an error: ${e??"Unknown error"}`)}}var l,K,b,v=class{constructor(e,t){this.access_token=e;this.options=t;m(this,l)}user(){return s(this,l,b).call(this,"api/user").then(e=>fetch(e)).then(g)}saveSettings(e){return s(this,l,b).call(this,"api/user/settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(t=>fetch(t)).then(q)}accounts(){return s(this,l,b).call(this,"api/accounts").then(e=>fetch(e)).then(g)}subtoken(e,t){let n=s(this,l,K).call(this,`api/accounts/${e}/subtoken`);return t?.permissions&&n.searchParams.set("permissions",t.permissions.join(",")),s(this,l,b).call(this,n).then(o=>fetch(o)).then(g)}};l=new WeakSet,K=function(e){return new URL(e,this.options?.url||"https://gw2.me/")},b=async function(e,t){let n=e instanceof URL?e:s(this,l,K).call(this,e),o=this.options?.dpopKeyPair,i=new Headers(t?.headers);if(i.set("Authorization",`${o?"DPoP":"Bearer"} ${this.access_token}`),o){let a=await x({htm:t?.method??"GET",htu:n.toString(),accessToken:this.access_token},o);i.set("DPoP",a)}return new Request(n,{cache:"no-cache",...t,headers:i})};var O,C,I=class{constructor(e,t){m(this,O);m(this,C);k(this,O,e),k(this,C,t)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({scopes:e,mediation:t,signal:n,mode:o,code_challenge:i,code_challenge_method:a}){if(!this.isSupported())throw new f("FedCM is not supported");return navigator.credentials.get({mediation:t,signal:n,identity:{providers:[{configURL:c(this,O),clientId:c(this,C),fields:[e.includes("identify")&&"name",e.includes("email")&&"email"].filter(Boolean),nonce:`${a}:${i}`,params:{scope:e.join(" "),code_challenge:i,code_challenge_method:a}}],mode:o}})}};O=new WeakMap,C=new WeakMap;var p,S,u,P,R,$=class{constructor(e,t){this.options=t;m(this,u);m(this,p);m(this,S);k(this,p,e),k(this,S,new I(s(this,u,P).call(this,"/fed-cm/config.json"),e.client_id))}getAuthorizationUrl(e){let t="request_uri"in e?new URLSearchParams({client_id:c(this,p).client_id,response_type:"code",request_uri:e.request_uri}):B(c(this,p).client_id,e);return s(this,u,P).call(this,`/oauth2/authorize?${t.toString()}`).toString()}async pushAuthorizationRequest(e){let t=s(this,u,P).call(this,"/oauth2/par"),n={"Content-Type":"application/x-www-form-urlencoded"};e.dpopKeyPair&&(n.DPoP=await x({htm:"POST",htu:t.toString()},e.dpopKeyPair),e.dpop_jkt=await W(e.dpopKeyPair.publicKey));let o=B(c(this,p).client_id,e);return c(this,p).client_secret&&(n.Authorization=s(this,u,R).call(this)),await fetch(t,{method:"POST",headers:n,body:o,cache:"no-store"}).then(g)}async getAccessToken({code:e,token_type:t,redirect_uri:n,code_verifier:o,dpopKeyPair:i}){let a=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:c(this,p).client_id,redirect_uri:n}),h={"Content-Type":"application/x-www-form-urlencoded"};c(this,p).client_secret&&(h.Authorization=s(this,u,R).call(this)),o&&a.set("code_verifier",o);let y=s(this,u,P).call(this,"/api/token");return i&&(h.DPoP=await x({htm:"POST",htu:y.toString(),accessToken:t==="DPoP"?e:void 0},i)),await fetch(y,{method:"POST",headers:h,body:a,cache:"no-store"}).then(g)}async refreshToken({refresh_token:e,refresh_token_type:t,dpopKeyPair:n}){let o=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:c(this,p).client_id}),i={"Content-Type":"application/x-www-form-urlencoded"};c(this,p).client_secret&&(i.Authorization=s(this,u,R).call(this));let a=s(this,u,P).call(this,"/api/token");return n&&(i.DPoP=await x({htm:"POST",htu:a.toString(),accessToken:t==="DPoP"?e:void 0},n)),await fetch(a,{method:"POST",headers:i,body:o,cache:"no-store"}).then(g)}async revokeToken({token:e}){let t=new URLSearchParams({token:e}),n={"Content-Type":"application/x-www-form-urlencoded"};c(this,p).client_secret&&(n.Authorization=s(this,u,R).call(this)),await fetch(s(this,u,P).call(this,"/api/token/revoke"),{method:"POST",cache:"no-store",headers:n,body:t}).then(g)}async introspectToken({token:e}){let t=new URLSearchParams({token:e}),n={"Content-Type":"application/x-www-form-urlencoded"};return c(this,p).client_secret&&(n.Authorization=s(this,u,R).call(this)),await fetch(s(this,u,P).call(this,"/api/token/introspect"),{method:"POST",cache:"no-store",headers:n,body:t}).then(g)}parseAuthorizationResponseSearchParams(e){let t=s(this,u,P).call(this,"/").origin,n=e.get("iss");if(!n)throw new f("Issuer Identifier verification failed: parameter `iss` is missing");if(n!==t)throw new f(`Issuer Identifier verification failed: expected "${t}", got "${n}"`);let o=e.get("error");if(o){let h=e.get("error_description")??void 0,y=e.get("error_uri")??void 0;throw new T(o,h,y)}let i=e.get("code");if(!i)throw new f("Parameter `code` is missing");let a=e.get("state")||void 0;return{code:i,state:a}}api(e,t){return new v(e,{...this.options,...t})}get fedCM(){return c(this,S)}};p=new WeakMap,S=new WeakMap,u=new WeakSet,P=function(e){return new URL(e,this.options?.url||"https://gw2.me/")},R=function(){if(!c(this,p).client_secret)throw new f("client_secret is required");return`Basic ${btoa(`${c(this,p).client_id}:${c(this,p).client_secret}`)}`};function B(r,{redirect_uri:e,scopes:t,state:n,code_challenge:o,code_challenge_method:i,dpop_jkt:a,prompt:h,include_granted_scopes:y,verified_accounts_only:U}){let w=new URLSearchParams({client_id:r,response_type:"code",redirect_uri:e,scope:t.join(" ")});return n&&w.append("state",n),o&&i&&(w.append("code_challenge",o),w.append("code_challenge_method",i)),a&&w.append("dpop_jkt",a),h&&w.append("prompt",h),y&&w.append("include_granted_scopes","true"),U&&w.append("verified_accounts_only","true"),w}0&&(module.exports={Gw2MeApi,Gw2MeClient,Gw2MeError,Gw2MeOAuthError,Scope});
package/dist/pkce.js CHANGED
@@ -1 +1 @@
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});
1
+ "use strict";var o=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var g=(e,r)=>{for(var n in r)o(e,n,{get:r[n],enumerable:!0})},f=(e,r,n,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of i(r))!d.call(e,a)&&a!==n&&o(e,a,{get:()=>r[a],enumerable:!(c=l(r,a))||c.enumerable});return e};var s=e=>f(o({},"__esModule",{value:!0}),e);var u={};g(u,{generatePKCEPair:()=>h});module.exports=s(u);function t(e){let r=e instanceof ArrayBuffer?new Uint8Array(e):e;return btoa(String.fromCharCode(...r)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function h(){let e=new Uint8Array(32);crypto.getRandomValues(e);let r=t(e),n=new TextEncoder,c=await crypto.subtle.digest("SHA-256",n.encode(r));return{code_verifier:r,challenge:{code_challenge_method:"S256",code_challenge:t(new Uint8Array(c))}}}0&&(module.exports={generatePKCEPair});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw2me/client",
3
- "version": "0.6.2",
3
+ "version": "0.8.0",
4
4
  "description": "gw2.me client library",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -10,6 +10,10 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "default": "./dist/index.js"
12
12
  },
13
+ "./dpop": {
14
+ "types": "./dist/dpop.d.ts",
15
+ "default": "./dist/dpop.js"
16
+ },
13
17
  "./pkce": {
14
18
  "types": "./dist/pkce.d.ts",
15
19
  "default": "./dist/pkce.js"
@@ -36,18 +40,19 @@
36
40
  },
37
41
  "homepage": "https://github.com/gw2treasures/gw2.me#readme",
38
42
  "devDependencies": {
39
- "@gw2treasures/eslint-config": "0.0.6",
43
+ "@gw2treasures/eslint-config": "0.1.0",
40
44
  "@gw2treasures/publish-package": "0.1.0-rc.0",
41
45
  "@gw2treasures/tsconfig": "0.0.1",
42
- "eslint": "8.57.1",
46
+ "eslint": "9.25.1",
43
47
  "tsup": "8.4.0",
44
- "typescript": "5.8.2",
45
- "undici-types": "7.5.0"
48
+ "typescript": "5.8.3",
49
+ "typescript-eslint": "8.31.0",
50
+ "undici-types": "7.8.0"
46
51
  },
47
52
  "scripts": {
48
53
  "build": "pnpm run clean && if test $CI; then pnpm run build:ci; else pnpm run build:local; fi",
49
- "build:local": "tsup src/index.ts src/pkce.ts && tsc --emitDeclarationOnly --declaration --declarationMap",
50
- "build:ci": "tsup src/index.ts src/pkce.ts --minify --dts",
54
+ "build:local": "tsup src/index.ts src/dpop.ts src/pkce.ts && tsc --emitDeclarationOnly --declaration --declarationMap",
55
+ "build:ci": "tsup src/index.ts src/dpop.ts src/pkce.ts --minify --dts",
51
56
  "clean": "rm -rf dist/",
52
57
  "lint": "eslint src",
53
58
  "publish-package": "gw2treasures-publish-package"