@gw2me/client 0.7.0 → 0.8.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/dpop.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { D as DPoPParams } from './types-yBP8cksw.js';
2
+
3
+ declare function generateDPoPKeyPair(): Promise<CryptoKeyPair>;
4
+ declare function createDPoPJwt({ htm, htu, nonce, accessToken }: DPoPParams, keyPair: CryptoKeyPair): Promise<string>;
5
+ declare function jwkThumbprint(key: CryptoKey): Promise<string>;
6
+
7
+ 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 m=(t,r)=>{for(var e in r)u(t,e,{get:r[e],enumerable:!0})},P=(t,r,e,a)=>{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:!(a=d(r,n))||a.enumerable});return t};var A=t=>P(u({},"__esModule",{value:!0}),t);var K={};m(K,{createDPoPJwt:()=>h,generateDPoPKeyPair:()=>b,jwkThumbprint:()=>C});module.exports=A(K);function o(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 h({htm:t,htu:r,nonce:e,accessToken:a},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:o(crypto.getRandomValues(new Uint8Array(32))),htm:t,htu:r,nonce:e,ath:a?o(await crypto.subtle.digest("SHA-256",i(a))):void 0}),s=`${o(i(c))}.${o(i(y))}`,f={name:"ECDSA",hash:"SHA-256"},g=o(await crypto.subtle.sign(f,n.privateKey,i(s)));return`${s}.${g}`}var S=new TextEncoder;function i(t){return S.encode(t)}async function p(t){let{kty:r,e,k:a,n,x:c,y,crv:s}=await crypto.subtle.exportKey("jwk",t);return{e,k:a,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 o(e)}0&&(module.exports={createDPoPJwt,generateDPoPKeyPair,jwkThumbprint});
package/dist/index.d.ts CHANGED
@@ -1,28 +1,5 @@
1
- declare enum Scope {
2
- Identify = "identify",
3
- Email = "email",
4
- Accounts = "accounts",
5
- Accounts_Verified = "accounts.verified",
6
- Accounts_DisplayName = "accounts.displayName",
7
- GW2_Account = "gw2:account",
8
- GW2_Inventories = "gw2:inventories",
9
- GW2_Characters = "gw2:characters",
10
- GW2_Tradingpost = "gw2:tradingpost",
11
- GW2_Wallet = "gw2:wallet",
12
- GW2_Unlocks = "gw2:unlocks",
13
- GW2_Pvp = "gw2:pvp",
14
- GW2_Wvw = "gw2:wvw",
15
- GW2_Builds = "gw2:builds",
16
- GW2_Progression = "gw2:progression",
17
- GW2_Guilds = "gw2:guilds"
18
- }
19
- interface ClientInfo {
20
- client_id: string;
21
- client_secret?: string;
22
- }
23
- interface Options {
24
- url: string;
25
- }
1
+ import { O as Options, a as DPoPCallback, S as Scope, C as ClientInfo } from './types-yBP8cksw.js';
2
+ export { D as DPoPParams } from './types-yBP8cksw.js';
26
3
 
27
4
  interface UserResponse {
28
5
  user: {
@@ -48,11 +25,14 @@ interface SubtokenResponse {
48
25
  subtoken: string;
49
26
  expiresAt: string;
50
27
  }
28
+ interface ApiOptions extends Options {
29
+ dpop?: DPoPCallback;
30
+ }
51
31
  declare class Gw2MeApi {
52
32
  #private;
53
33
  private access_token;
54
34
  private options?;
55
- constructor(access_token: string, options?: Partial<Options> | undefined);
35
+ constructor(access_token: string, options?: Partial<ApiOptions> | undefined);
56
36
  user(): Promise<UserResponse>;
57
37
  saveSettings(settings: unknown): Promise<void>;
58
38
  accounts(): Promise<AccountsResponse>;
@@ -83,25 +63,34 @@ interface AuthorizationUrlParams {
83
63
  state?: string;
84
64
  code_challenge?: string;
85
65
  code_challenge_method?: 'S256';
66
+ dpop_jkt?: string;
86
67
  prompt?: 'none' | 'consent';
87
68
  include_granted_scopes?: boolean;
88
69
  verified_accounts_only?: boolean;
89
70
  }
71
+ interface PushedAuthorizationRequestParams extends AuthorizationUrlParams {
72
+ dpop?: DPoPCallback;
73
+ }
90
74
  interface AuthorizationUrlRequestUriParams {
91
75
  request_uri: string;
92
76
  }
77
+ type TokenType = 'Bearer' | 'DPoP';
93
78
  interface AuthTokenParams {
94
79
  code: string;
80
+ token_type?: TokenType;
95
81
  redirect_uri: string;
96
82
  code_verifier?: string;
83
+ dpop?: DPoPCallback;
97
84
  }
98
85
  interface RefreshTokenParams {
99
86
  refresh_token: string;
87
+ refresh_token_type?: TokenType;
88
+ dpop?: DPoPCallback;
100
89
  }
101
90
  interface TokenResponse {
102
91
  access_token: string;
103
92
  issued_token_type: 'urn:ietf:params:oauth:token-type:access_token';
104
- token_type: 'Bearer';
93
+ token_type: TokenType;
105
94
  expires_in: number;
106
95
  refresh_token?: string;
107
96
  scope: string;
@@ -112,15 +101,30 @@ interface RevokeTokenParams {
112
101
  interface IntrospectTokenParams {
113
102
  token: string;
114
103
  }
115
- type IntrospectTokenResponse = {
116
- active: true;
117
- scope: string;
118
- client_id: string;
119
- token_type: 'Bearer';
120
- exp?: number;
121
- } | {
122
- active: false;
123
- };
104
+ declare namespace IntrospectTokenResponse {
105
+ interface Inactive {
106
+ active: false;
107
+ }
108
+ namespace Active {
109
+ interface Common {
110
+ active: true;
111
+ scope: string;
112
+ client_id: string;
113
+ exp?: number;
114
+ }
115
+ interface Bearer extends Common {
116
+ token_type: 'Bearer';
117
+ }
118
+ interface DPoP extends Common {
119
+ token_type: 'DPoP';
120
+ cnf: {
121
+ jkt: string;
122
+ };
123
+ }
124
+ }
125
+ type Active = Active.Bearer | Active.DPoP;
126
+ }
127
+ type IntrospectTokenResponse = IntrospectTokenResponse.Inactive | IntrospectTokenResponse.Active;
124
128
  interface PushedAuthorizationRequestResponse {
125
129
  request_uri: string;
126
130
  expires_in: number;
@@ -128,11 +132,11 @@ interface PushedAuthorizationRequestResponse {
128
132
  declare class Gw2MeClient {
129
133
  #private;
130
134
  private options?;
131
- constructor({ client_id, client_secret }: ClientInfo, options?: Partial<Options> | undefined);
135
+ constructor(client: ClientInfo, options?: Partial<Options> | undefined);
132
136
  getAuthorizationUrl(params: AuthorizationUrlParams | AuthorizationUrlRequestUriParams): string;
133
- pushAuthorizationRequest(params: AuthorizationUrlParams): Promise<PushedAuthorizationRequestResponse>;
134
- getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
135
- refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
137
+ pushAuthorizationRequest(params: PushedAuthorizationRequestParams): Promise<PushedAuthorizationRequestResponse>;
138
+ getAccessToken({ code, token_type, redirect_uri, code_verifier, dpop }: AuthTokenParams): Promise<TokenResponse>;
139
+ refreshToken({ refresh_token, refresh_token_type, dpop }: RefreshTokenParams): Promise<TokenResponse>;
136
140
  revokeToken({ token }: RevokeTokenParams): Promise<void>;
137
141
  introspectToken({ token }: IntrospectTokenParams): Promise<IntrospectTokenResponse>;
138
142
  /**
@@ -145,7 +149,7 @@ declare class Gw2MeClient {
145
149
  code: string;
146
150
  state: string | undefined;
147
151
  };
148
- api(access_token: string): Gw2MeApi;
152
+ api(access_token: string, options?: Partial<Omit<ApiOptions, keyof Options>>): Gw2MeApi;
149
153
  get fedCM(): Gw2MeFedCM;
150
154
  }
151
155
 
@@ -158,4 +162,4 @@ declare class Gw2MeOAuthError extends Gw2MeError {
158
162
  constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined);
159
163
  }
160
164
 
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 };
165
+ export { type AccountsResponse, type ApiOptions, type AuthTokenParams, type AuthorizationUrlParams, type AuthorizationUrlRequestUriParams, ClientInfo, DPoPCallback, type FedCMRequestOptions, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeFedCM, Gw2MeOAuthError, type IntrospectTokenParams, IntrospectTokenResponse, Options, type PushedAuthorizationRequestParams, type PushedAuthorizationRequestResponse, type RefreshTokenParams, type RevokeTokenParams, Scope, type SubtokenOptions, type SubtokenResponse, type TokenResponse, type TokenType, type UserResponse };
package/dist/index.js CHANGED
@@ -1 +1 @@
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});
1
+ "use strict";var C=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var G=n=>{throw TypeError(n)};var E=(n,e)=>{for(var t in e)C(n,t,{get:e[t],enumerable:!0})},B=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of W(e))!L.call(n,o)&&o!==t&&C(n,o,{get:()=>e[o],enumerable:!(r=j(e,o))||r.enumerable});return n};var M=n=>B(C({},"__esModule",{value:!0}),n);var U=(n,e,t)=>e.has(n)||G("Cannot "+t);var a=(n,e,t)=>(U(n,e,"read from private field"),t?t.call(n):e.get(n)),m=(n,e,t)=>e.has(n)?G("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),_=(n,e,t,r)=>(U(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),i=(n,e,t)=>(U(n,e,"access private method"),t);var J={};E(J,{Gw2MeApi:()=>T,Gw2MeClient:()=>q,Gw2MeError:()=>d,Gw2MeOAuthError:()=>x,Scope:()=>I});module.exports=M(J);var I=(u=>(u.Identify="identify",u.Email="email",u.Accounts="accounts",u.Accounts_Verified="accounts.verified",u.Accounts_DisplayName="accounts.displayName",u.GW2_Account="gw2:account",u.GW2_Inventories="gw2:inventories",u.GW2_Characters="gw2:characters",u.GW2_Tradingpost="gw2:tradingpost",u.GW2_Wallet="gw2:wallet",u.GW2_Unlocks="gw2:unlocks",u.GW2_Pvp="gw2:pvp",u.GW2_Wvw="gw2:wvw",u.GW2_Builds="gw2:builds",u.GW2_Progression="gw2:progression",u.GW2_Guilds="gw2:guilds",u))(I||{});var d=class extends Error{},x=class extends d{constructor(t,r,o){super(`Received ${t}`+(r?`: ${r}`:"")+(o?` (${o})`:""));this.error=t;this.error_description=r;this.error_uri=o}};async function l(n){if(await z(n),!(n.headers.get("Content-Type")==="application/json"))throw new d("gw2.me did not return a valid JSON response");return n.json()}async function z(n){if(!n.ok){let e;throw n.headers.get("Content-Type")==="application/json"&&(e=(await n.json()).error_description),new d(`gw2.me returned an error: ${e??"Unknown error"}`)}}var f,S,R,T=class{constructor(e,t){this.access_token=e;this.options=t;m(this,f)}user(){return i(this,f,R).call(this,"api/user").then(e=>fetch(e)).then(l)}saveSettings(e){return i(this,f,R).call(this,"api/user/settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(t=>fetch(t)).then(z)}accounts(){return i(this,f,R).call(this,"api/accounts").then(e=>fetch(e)).then(l)}subtoken(e,t){let r=i(this,f,S).call(this,`api/accounts/${e}/subtoken`);return t?.permissions&&r.searchParams.set("permissions",t.permissions.join(",")),i(this,f,R).call(this,r).then(o=>fetch(o)).then(l)}};f=new WeakSet,S=function(e){return new URL(e,this.options?.url||"https://gw2.me/")},R=async function(e,t){let r=e instanceof URL?e:i(this,f,S).call(this,e),o=this.options?.dpop,s=new Headers(t?.headers);return s.set("Authorization",`${o?"DPoP":"Bearer"} ${this.access_token}`),o&&s.set("DPoP",await o({htm:t?.method??"GET",htu:r.toString(),accessToken:this.access_token})),new Request(r,{cache:"no-cache",...t,headers:s})};var A,v,O=class{constructor(e,t){m(this,A);m(this,v);_(this,A,e),_(this,v,t)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({scopes:e,mediation:t,signal:r,mode:o,code_challenge:s,code_challenge_method:h}){if(!this.isSupported())throw new d("FedCM is not supported");return navigator.credentials.get({mediation:t,signal:r,identity:{providers:[{configURL:a(this,A),clientId:a(this,v),fields:[e.includes("identify")&&"name",e.includes("email")&&"email"].filter(Boolean),nonce:`${h}:${s}`,params:{scope:e.join(" "),code_challenge:s,code_challenge_method:h}}],mode:o}})}};A=new WeakMap,v=new WeakMap;var c,b,p,P,y,q=class{constructor(e,t){this.options=t;m(this,p);m(this,c);m(this,b);_(this,c,e),_(this,b,new O(i(this,p,P).call(this,"/fed-cm/config.json"),e.client_id))}getAuthorizationUrl(e){let t="request_uri"in e?new URLSearchParams({client_id:a(this,c).client_id,response_type:"code",request_uri:e.request_uri}):$(a(this,c).client_id,e);return i(this,p,P).call(this,`/oauth2/authorize?${t.toString()}`).toString()}async pushAuthorizationRequest(e){let t=i(this,p,P).call(this,"/oauth2/par"),r={"Content-Type":"application/x-www-form-urlencoded"};e.dpop&&(r.DPoP=await e.dpop({htm:"POST",htu:t.toString()}));let o=$(a(this,c).client_id,e);return a(this,c).client_secret&&(r.Authorization=i(this,p,y).call(this)),await fetch(t,{method:"POST",headers:r,body:o,cache:"no-store"}).then(l)}async getAccessToken({code:e,token_type:t,redirect_uri:r,code_verifier:o,dpop:s}){let h=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:a(this,c).client_id,redirect_uri:r}),g={"Content-Type":"application/x-www-form-urlencoded"};a(this,c).client_secret&&(g.Authorization=i(this,p,y).call(this)),o&&h.set("code_verifier",o);let w=i(this,p,P).call(this,"/api/token");return s&&(g.DPoP=await s({htm:"POST",htu:w.toString(),accessToken:t==="DPoP"?e:void 0})),await fetch(w,{method:"POST",headers:g,body:h,cache:"no-store"}).then(l)}async refreshToken({refresh_token:e,refresh_token_type:t,dpop:r}){let o=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:a(this,c).client_id}),s={"Content-Type":"application/x-www-form-urlencoded"};a(this,c).client_secret&&(s.Authorization=i(this,p,y).call(this));let h=i(this,p,P).call(this,"/api/token");return r&&(s.DPoP=await r({htm:"POST",htu:h.toString(),accessToken:t==="DPoP"?e:void 0})),await fetch(h,{method:"POST",headers:s,body:o,cache:"no-store"}).then(l)}async revokeToken({token:e}){let t=new URLSearchParams({token:e}),r={"Content-Type":"application/x-www-form-urlencoded"};a(this,c).client_secret&&(r.Authorization=i(this,p,y).call(this)),await fetch(i(this,p,P).call(this,"/api/token/revoke"),{method:"POST",cache:"no-store",headers:r,body:t}).then(l)}async introspectToken({token:e}){let t=new URLSearchParams({token:e}),r={"Content-Type":"application/x-www-form-urlencoded"};return a(this,c).client_secret&&(r.Authorization=i(this,p,y).call(this)),await fetch(i(this,p,P).call(this,"/api/token/introspect"),{method:"POST",cache:"no-store",headers:r,body:t}).then(l)}parseAuthorizationResponseSearchParams(e){let t=i(this,p,P).call(this,"/").origin,r=e.get("iss");if(!r)throw new d("Issuer Identifier verification failed: parameter `iss` is missing");if(r!==t)throw new d(`Issuer Identifier verification failed: expected "${t}", got "${r}"`);let o=e.get("error");if(o){let g=e.get("error_description")??void 0,w=e.get("error_uri")??void 0;throw new x(o,g,w)}let s=e.get("code");if(!s)throw new d("Parameter `code` is missing");let h=e.get("state")||void 0;return{code:s,state:h}}api(e,t){return new T(e,{...this.options,...t})}get fedCM(){return a(this,b)}};c=new WeakMap,b=new WeakMap,p=new WeakSet,P=function(e){return new URL(e,this.options?.url||"https://gw2.me/")},y=function(){if(!a(this,c).client_secret)throw new d("client_secret is required");return`Basic ${btoa(`${a(this,c).client_id}:${a(this,c).client_secret}`)}`};function $(n,{redirect_uri:e,scopes:t,state:r,code_challenge:o,code_challenge_method:s,dpop_jkt:h,prompt:g,include_granted_scopes:w,verified_accounts_only:D}){let k=new URLSearchParams({client_id:n,response_type:"code",redirect_uri:e,scope:t.join(" ")});return r&&k.append("state",r),o&&s&&(k.append("code_challenge",o),k.append("code_challenge_method",s)),h&&k.append("dpop_jkt",h),g&&k.append("prompt",g),w&&k.append("include_granted_scopes","true"),D&&k.append("verified_accounts_only","true"),k}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});
@@ -0,0 +1,34 @@
1
+ declare enum Scope {
2
+ Identify = "identify",
3
+ Email = "email",
4
+ Accounts = "accounts",
5
+ Accounts_Verified = "accounts.verified",
6
+ Accounts_DisplayName = "accounts.displayName",
7
+ GW2_Account = "gw2:account",
8
+ GW2_Inventories = "gw2:inventories",
9
+ GW2_Characters = "gw2:characters",
10
+ GW2_Tradingpost = "gw2:tradingpost",
11
+ GW2_Wallet = "gw2:wallet",
12
+ GW2_Unlocks = "gw2:unlocks",
13
+ GW2_Pvp = "gw2:pvp",
14
+ GW2_Wvw = "gw2:wvw",
15
+ GW2_Builds = "gw2:builds",
16
+ GW2_Progression = "gw2:progression",
17
+ GW2_Guilds = "gw2:guilds"
18
+ }
19
+ interface ClientInfo {
20
+ client_id: string;
21
+ client_secret?: string;
22
+ }
23
+ interface Options {
24
+ url: string;
25
+ }
26
+ interface DPoPParams {
27
+ htm: 'POST' | 'GET' | (string & {});
28
+ htu: string;
29
+ nonce?: string;
30
+ accessToken?: string;
31
+ }
32
+ type DPoPCallback = (params: DPoPParams) => string | Promise<string>;
33
+
34
+ export { type ClientInfo as C, type DPoPParams as D, type Options as O, Scope as S, type DPoPCallback as a };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw2me/client",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
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"