@gw2me/client 0.3.0 → 0.4.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 +20 -1
- package/dist/index.js +1 -1
- package/dist/pkce.d.ts +11 -0
- package/dist/pkce.js +1 -0
- package/package.json +17 -6
package/dist/index.d.ts
CHANGED
|
@@ -102,8 +102,27 @@ declare class Gw2MeClient {
|
|
|
102
102
|
getAuthorizationUrl({ redirect_uri, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes, verified_accounts_only, }: AuthorizationUrlParams): string;
|
|
103
103
|
getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
|
|
104
104
|
refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
|
|
105
|
+
/**
|
|
106
|
+
* Parses the search params received from gw2.me on the redirect url (code and state).
|
|
107
|
+
* If gw2.me returned an error response, this will throw an error.
|
|
108
|
+
*
|
|
109
|
+
* @returns The code and optional state.
|
|
110
|
+
*/
|
|
111
|
+
parseAuthorizationResponseSearchParams(searchParams: URLSearchParams): {
|
|
112
|
+
code: string;
|
|
113
|
+
state: string | undefined;
|
|
114
|
+
};
|
|
105
115
|
api(access_token: string): Gw2MeApi;
|
|
106
116
|
get fedCM(): Gw2MeFedCM;
|
|
107
117
|
}
|
|
108
118
|
|
|
109
|
-
|
|
119
|
+
declare class Gw2MeError extends Error {
|
|
120
|
+
}
|
|
121
|
+
declare class Gw2MeOAuthError extends Gw2MeError {
|
|
122
|
+
error: string;
|
|
123
|
+
error_description?: string | undefined;
|
|
124
|
+
error_uri?: string | undefined;
|
|
125
|
+
constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined);
|
|
126
|
+
}
|
|
127
|
+
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var O=r=>{throw TypeError(r)};var L=(r,e)=>{for(var t in e)C(r,t,{get:e[t],enumerable:!0})},M=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z(e))!j.call(r,i)&&i!==t&&C(r,i,{get:()=>e[i],enumerable:!(n=W(e,i))||n.enumerable});return r};var B=r=>M(C({},"__esModule",{value:!0}),r);var T=(r,e,t)=>e.has(r)||O("Cannot "+t);var s=(r,e,t)=>(T(r,e,"read from private field"),t?t.call(r):e.get(r)),c=(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),l=(r,e,t,n)=>(T(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),p=(r,e,t)=>(T(r,e,"access private method"),t);var E={};L(E,{Gw2MeApi:()=>x,Gw2MeClient:()=>I,Gw2MeError:()=>a,Gw2MeOAuthError:()=>y,Scope:()=>G});module.exports=B(E);var G=(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))(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 m(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 w,A,x=class{constructor(e,t){this.access_token=e;this.options=t;c(this,w)}user(){return fetch(p(this,w,A).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(m)}accounts(){return fetch(p(this,w,A).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(m)}subtoken(e){return fetch(p(this,w,A).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(m)}};w=new WeakSet,A=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var R,b,P=class{constructor(e,t){c(this,R);c(this,b);l(this,R,e),l(this,b,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:s(this,R),clientId:s(this,b)}],mode:n}})}};R=new WeakMap,b=new WeakMap;var d,g,v,h,_,I=class{constructor({client_id:e,client_secret:t},n){this.options=n;c(this,h);c(this,d);c(this,g);c(this,v);l(this,d,e),l(this,g,t),l(this,v,new P(p(this,h,_).call(this,"/fed-cm/config.json"),s(this,d)))}getAuthorizationUrl({redirect_uri:e,scopes:t,state:n,code_challenge:i,code_challenge_method:u,prompt:k,include_granted_scopes:U,verified_accounts_only:$}){let f=new URLSearchParams({client_id:s(this,d),response_type:"code",redirect_uri:e,scope:t.join(" ")});return n&&f.append("state",n),i&&u&&(f.append("code_challenge",i),f.append("code_challenge_method",u)),k&&f.append("prompt",k),U&&f.append("include_granted_scopes","true"),$&&f.append("verified_accounts_only","true"),p(this,h,_).call(this,`/oauth2/authorize?${f.toString()}`).toString()}async getAccessToken({code:e,redirect_uri:t,code_verifier:n}){let i=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:s(this,d),redirect_uri:t}),u={"Content-Type":"application/x-www-form-urlencoded"};return s(this,g)&&(u.Authorization=`Basic ${btoa(`${s(this,d)}:${s(this,g)}`)}`),n&&i.set("code_verifier",n),await fetch(p(this,h,_).call(this,"/api/token"),{method:"POST",headers:u,body:i,cache:"no-store"}).then(m)}async refreshToken({refresh_token:e}){if(!s(this,g))throw new a("client_secret required");let t=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:s(this,d)}),n={"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${btoa(`${s(this,d)}:${s(this,g)}`)}`};return await fetch(p(this,h,_).call(this,"/api/token"),{method:"POST",headers:n,body:t,cache:"no-store"}).then(m)}parseAuthorizationResponseSearchParams(e){let t=p(this,h,_).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 U=e.get("error_description")??void 0,$=e.get("error_uri")??void 0;throw new y(i,U,$)}let u=e.get("code");if(!u)throw new a("Parameter `code` is missing");let k=e.get("state")||void 0;return{code:u,state:k}}api(e){return new x(e,this.options)}get fedCM(){return s(this,v)}};d=new WeakMap,g=new WeakMap,v=new WeakMap,h=new WeakSet,_=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
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface PKCEChallenge {
|
|
2
|
+
code_challenge: string;
|
|
3
|
+
code_challenge_method: 'S256';
|
|
4
|
+
}
|
|
5
|
+
interface PKCEPair {
|
|
6
|
+
challenge: PKCEChallenge;
|
|
7
|
+
verifier: string;
|
|
8
|
+
}
|
|
9
|
+
declare function generatePKCEPair(): Promise<PKCEPair>;
|
|
10
|
+
|
|
11
|
+
export { type PKCEChallenge, type PKCEPair, generatePKCEPair };
|
package/dist/pkce.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var n in e)t(r,n,{get:e[n],enumerable:!0})},s=(r,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of i(e))!g.call(r,c)&&c!==n&&t(r,c,{get:()=>e[c],enumerable:!(a=l(e,c))||a.enumerable});return r};var f=r=>s(t({},"__esModule",{value:!0}),r);var u={};d(u,{generatePKCEPair:()=>h});module.exports=f(u);async function h(){let r=new Uint8Array(32);crypto.getRandomValues(r);let e=o(r.buffer),n=new TextEncoder,a=await crypto.subtle.digest("SHA-256",n.encode(e));return{verifier:e,challenge:{code_challenge_method:"S256",code_challenge:o(a)}}}function o(r){return btoa(String.fromCharCode(...new Uint8Array(r))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}0&&(module.exports={generatePKCEPair});
|
package/package.json
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gw2me/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "gw2.me client library",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./package.json": "./package.json",
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./pkce": {
|
|
14
|
+
"types": "./dist/pkce.d.ts",
|
|
15
|
+
"default": "./dist/pkce.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
7
18
|
"repository": {
|
|
8
19
|
"type": "git",
|
|
9
20
|
"url": "git+https://github.com/GW2Treasures/gw2.me.git"
|
|
@@ -30,13 +41,13 @@
|
|
|
30
41
|
"@gw2treasures/tsconfig": "0.0.1",
|
|
31
42
|
"eslint": "8.57.1",
|
|
32
43
|
"tsup": "8.3.5",
|
|
33
|
-
"typescript": "5.
|
|
44
|
+
"typescript": "5.7.2",
|
|
34
45
|
"undici-types": "6.21.0"
|
|
35
46
|
},
|
|
36
47
|
"scripts": {
|
|
37
48
|
"build": "pnpm run clean && if test $CI; then pnpm run build:ci; else pnpm run build:local; fi",
|
|
38
|
-
"build:local": "tsup src/index.ts && tsc --emitDeclarationOnly --declaration --declarationMap",
|
|
39
|
-
"build:ci": "tsup src/index.ts --minify --dts",
|
|
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",
|
|
40
51
|
"clean": "rm -rf dist/",
|
|
41
52
|
"lint": "eslint src",
|
|
42
53
|
"publish-package": "gw2treasures-publish-package"
|