@gw2me/client 0.4.1 → 0.5.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/index.d.ts +5 -1
- package/dist/index.js +1 -1
- package/dist/pkce.d.ts +1 -1
- package/dist/pkce.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -87,6 +87,9 @@ interface AuthTokenParams {
|
|
|
87
87
|
interface RefreshTokenParams {
|
|
88
88
|
refresh_token: string;
|
|
89
89
|
}
|
|
90
|
+
interface RevokeTokenParams {
|
|
91
|
+
token: string;
|
|
92
|
+
}
|
|
90
93
|
interface TokenResponse {
|
|
91
94
|
access_token: string;
|
|
92
95
|
issued_token_type: 'urn:ietf:params:oauth:token-type:access_token';
|
|
@@ -102,6 +105,7 @@ declare class Gw2MeClient {
|
|
|
102
105
|
getAuthorizationUrl({ redirect_uri, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes, verified_accounts_only, }: AuthorizationUrlParams): string;
|
|
103
106
|
getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
|
|
104
107
|
refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
|
|
108
|
+
revokeToken({ token }: RevokeTokenParams): Promise<void>;
|
|
105
109
|
/**
|
|
106
110
|
* Parses the search params received from gw2.me on the redirect url (code and state).
|
|
107
111
|
* If gw2.me returned an error response, this will throw an error.
|
|
@@ -125,4 +129,4 @@ declare class Gw2MeOAuthError extends Gw2MeError {
|
|
|
125
129
|
constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined);
|
|
126
130
|
}
|
|
127
131
|
|
|
128
|
-
export { type AccountsResponse, type AuthTokenParams, type AuthorizationUrlParams, type ClientInfo, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeOAuthError, type Options, type RefreshTokenParams, Scope, type SubtokenResponse, type TokenResponse, type UserResponse };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var U=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var I=r=>{throw TypeError(r)};var j=(r,e)=>{for(var t in e)U(r,t,{get:e[t],enumerable:!0})},B=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z(e))!L.call(r,i)&&i!==t&&U(r,i,{get:()=>e[i],enumerable:!(n=W(e,i))||n.enumerable});return r};var M=r=>B(U({},"__esModule",{value:!0}),r);var C=(r,e,t)=>e.has(r)||I("Cannot "+t);var o=(r,e,t)=>(C(r,e,"read from private field"),t?t.call(r):e.get(r)),d=(r,e,t)=>e.has(r)?I("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),m=(r,e,t,n)=>(C(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),c=(r,e,t)=>(C(r,e,"access private method"),t);var E={};j(E,{Gw2MeApi:()=>x,Gw2MeClient:()=>O,Gw2MeError:()=>a,Gw2MeOAuthError:()=>y,Scope:()=>G});module.exports=M(E);var G=(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))(G||{});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 f(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 _,P,x=class{constructor(e,t){this.access_token=e;this.options=t;d(this,_)}user(){return fetch(c(this,_,P).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}accounts(){return fetch(c(this,_,P).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}subtoken(e){return fetch(c(this,_,P).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(f)}};_=new WeakSet,P=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var R,v,A=class{constructor(e,t){d(this,R);d(this,v);m(this,R,e),m(this,v,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,v)}],mode:n}})}};R=new WeakMap,v=new WeakMap;var p,u,b,h,w,O=class{constructor({client_id:e,client_secret:t},n){this.options=n;d(this,h);d(this,p);d(this,u);d(this,b);m(this,p,e),m(this,u,t),m(this,b,new A(c(this,h,w).call(this,"/fed-cm/config.json"),o(this,p)))}getAuthorizationUrl({redirect_uri:e,scopes:t,state:n,code_challenge:i,code_challenge_method:g,prompt:k,include_granted_scopes:T,verified_accounts_only:$}){let l=new URLSearchParams({client_id:o(this,p),response_type:"code",redirect_uri:e,scope:t.join(" ")});return n&&l.append("state",n),i&&g&&(l.append("code_challenge",i),l.append("code_challenge_method",g)),k&&l.append("prompt",k),T&&l.append("include_granted_scopes","true"),$&&l.append("verified_accounts_only","true"),c(this,h,w).call(this,`/oauth2/authorize?${l.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}),g={"Content-Type":"application/x-www-form-urlencoded"};return o(this,u)&&(g.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,u)}`)}`),n&&i.set("code_verifier",n),await fetch(c(this,h,w).call(this,"/api/token"),{method:"POST",headers:g,body:i,cache:"no-store"}).then(f)}async refreshToken({refresh_token:e}){if(!o(this,u))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,u)}`)}`};return await fetch(c(this,h,w).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"};o(this,u)&&(n.Authorization=`Basic ${btoa(`${o(this,p)}:${o(this,u)}`)}`),await fetch(c(this,h,w).call(this,"/api/revoke"),{method:"POST",cache:"no-store",headers:n,body:t}).then(f)}parseAuthorizationResponseSearchParams(e){let t=c(this,h,w).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 T=e.get("error_description")??void 0,$=e.get("error_uri")??void 0;throw new y(i,T,$)}let g=e.get("code");if(!g)throw new a("Parameter `code` is missing");let k=e.get("state")||void 0;return{code:g,state:k}}api(e){return new x(e,this.options)}get fedCM(){return o(this,b)}};p=new WeakMap,u=new WeakMap,b=new WeakMap,h=new WeakSet,w=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};0&&(module.exports={Gw2MeApi,Gw2MeClient,Gw2MeError,Gw2MeOAuthError,Scope});
|
package/dist/pkce.d.ts
CHANGED
package/dist/pkce.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gw2me/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "gw2.me client library",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"eslint": "8.57.1",
|
|
43
43
|
"tsup": "8.3.5",
|
|
44
44
|
"typescript": "5.7.2",
|
|
45
|
-
"undici-types": "
|
|
45
|
+
"undici-types": "7.1.1"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "pnpm run clean && if test $CI; then pnpm run build:ci; else pnpm run build:local; fi",
|