@gw2me/client 0.5.1 → 0.5.2
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 +17 -4
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -87,9 +87,6 @@ interface AuthTokenParams {
|
|
|
87
87
|
interface RefreshTokenParams {
|
|
88
88
|
refresh_token: string;
|
|
89
89
|
}
|
|
90
|
-
interface RevokeTokenParams {
|
|
91
|
-
token: string;
|
|
92
|
-
}
|
|
93
90
|
interface TokenResponse {
|
|
94
91
|
access_token: string;
|
|
95
92
|
issued_token_type: 'urn:ietf:params:oauth:token-type:access_token';
|
|
@@ -98,6 +95,21 @@ interface TokenResponse {
|
|
|
98
95
|
refresh_token?: string;
|
|
99
96
|
scope: string;
|
|
100
97
|
}
|
|
98
|
+
interface RevokeTokenParams {
|
|
99
|
+
token: string;
|
|
100
|
+
}
|
|
101
|
+
interface IntrospectTokenParams {
|
|
102
|
+
token: string;
|
|
103
|
+
}
|
|
104
|
+
type IntrospectTokenResponse = {
|
|
105
|
+
active: true;
|
|
106
|
+
scope: string;
|
|
107
|
+
client_id: string;
|
|
108
|
+
token_type: 'Bearer';
|
|
109
|
+
exp?: number;
|
|
110
|
+
} | {
|
|
111
|
+
active: false;
|
|
112
|
+
};
|
|
101
113
|
declare class Gw2MeClient {
|
|
102
114
|
#private;
|
|
103
115
|
private options?;
|
|
@@ -106,6 +118,7 @@ declare class Gw2MeClient {
|
|
|
106
118
|
getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
|
|
107
119
|
refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
|
|
108
120
|
revokeToken({ token }: RevokeTokenParams): Promise<void>;
|
|
121
|
+
introspectToken({ token }: IntrospectTokenParams): Promise<IntrospectTokenResponse>;
|
|
109
122
|
/**
|
|
110
123
|
* Parses the search params received from gw2.me on the redirect url (code and state).
|
|
111
124
|
* If gw2.me returned an error response, this will throw an error.
|
|
@@ -129,4 +142,4 @@ declare class Gw2MeOAuthError extends Gw2MeError {
|
|
|
129
142
|
constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined);
|
|
130
143
|
}
|
|
131
144
|
|
|
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 };
|
|
145
|
+
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 SubtokenResponse, type TokenResponse, type UserResponse };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var U=Object.defineProperty;var
|
|
1
|
+
"use strict";var U=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var O=r=>{throw TypeError(r)};var L=(r,e)=>{for(var t in e)U(r,t,{get:e[t],enumerable:!0})},j=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of W(e))!B.call(r,i)&&i!==t&&U(r,i,{get:()=>e[i],enumerable:!(n=G(e,i))||n.enumerable});return r};var M=r=>j(U({},"__esModule",{value:!0}),r);var I=(r,e,t)=>e.has(r)||O("Cannot "+t);var o=(r,e,t)=>(I(r,e,"read from private field"),t?t.call(r):e.get(r)),h=(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),w=(r,e,t,n)=>(I(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),c=(r,e,t)=>(I(r,e,"access private method"),t);var E={};L(E,{Gw2MeApi:()=>x,Gw2MeClient:()=>C,Gw2MeError:()=>a,Gw2MeOAuthError:()=>y,Scope:()=>z});module.exports=M(E);var z=(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))(z||{});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 g(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 _,b,x=class{constructor(e,t){this.access_token=e;this.options=t;h(this,_)}user(){return fetch(c(this,_,b).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(g)}accounts(){return fetch(c(this,_,b).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(g)}subtoken(e){return fetch(c(this,_,b).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(g)}};_=new WeakSet,b=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var R,P,T=class{constructor(e,t){h(this,R);h(this,P);w(this,R,e),w(this,P,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,P)}],mode:n}})}};R=new WeakMap,P=new WeakMap;var p,d,v,u,l,C=class{constructor({client_id:e,client_secret:t},n){this.options=n;h(this,u);h(this,p);h(this,d);h(this,v);w(this,p,e),w(this,d,t),w(this,v,new T(c(this,u,l).call(this,"/fed-cm/config.json"),o(this,p)))}getAuthorizationUrl({redirect_uri:e,scopes:t,state:n,code_challenge:i,code_challenge_method:f,prompt:k,include_granted_scopes:$,verified_accounts_only:A}){let m=new URLSearchParams({client_id:o(this,p),response_type:"code",redirect_uri:e,scope:t.join(" ")});return n&&m.append("state",n),i&&f&&(m.append("code_challenge",i),m.append("code_challenge_method",f)),k&&m.append("prompt",k),$&&m.append("include_granted_scopes","true"),A&&m.append("verified_accounts_only","true"),c(this,u,l).call(this,`/oauth2/authorize?${m.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}),f={"Content-Type":"application/x-www-form-urlencoded"};return o(this,d)&&(f.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,d)}`)}`),n&&i.set("code_verifier",n),await fetch(c(this,u,l).call(this,"/api/token"),{method:"POST",headers:f,body:i,cache:"no-store"}).then(g)}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)}),n={"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${btoa(`${o(this,p)}:${o(this,d)}`)}`};return await fetch(c(this,u,l).call(this,"/api/token"),{method:"POST",headers:n,body:t,cache:"no-store"}).then(g)}async revokeToken({token:e}){let t=new URLSearchParams({token:e}),n={"Content-Type":"application/x-www-form-urlencoded"};o(this,d)&&(n.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,d)}`)}`),await fetch(c(this,u,l).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 o(this,d)&&(n.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,d)}`)}`),await fetch(c(this,u,l).call(this,"/api/token/introspect"),{method:"POST",cache:"no-store",headers:n,body:t}).then(g)}parseAuthorizationResponseSearchParams(e){let t=c(this,u,l).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 $=e.get("error_description")??void 0,A=e.get("error_uri")??void 0;throw new y(i,$,A)}let f=e.get("code");if(!f)throw new a("Parameter `code` is missing");let k=e.get("state")||void 0;return{code:f,state:k}}api(e){return new x(e,this.options)}get fedCM(){return o(this,v)}};p=new WeakMap,d=new WeakMap,v=new WeakMap,u=new WeakSet,l=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};0&&(module.exports={Gw2MeApi,Gw2MeClient,Gw2MeError,Gw2MeOAuthError,Scope});
|