@gw2me/client 0.6.1 → 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 +10 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
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(
|
|
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, Gw2MeApi, Gw2MeClient, Gw2MeError, 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
|
|
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});
|