@gw2me/client 0.2.7 → 0.4.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 CHANGED
@@ -89,6 +89,7 @@ interface RefreshTokenParams {
89
89
  }
90
90
  interface TokenResponse {
91
91
  access_token: string;
92
+ issued_token_type: 'urn:ietf:params:oauth:token-type:access_token';
92
93
  token_type: 'Bearer';
93
94
  expires_in: number;
94
95
  refresh_token?: string;
@@ -101,8 +102,27 @@ declare class Gw2MeClient {
101
102
  getAuthorizationUrl({ redirect_uri, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes, verified_accounts_only, }: AuthorizationUrlParams): string;
102
103
  getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
103
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
+ };
104
115
  api(access_token: string): Gw2MeApi;
105
116
  get fedCM(): Gw2MeFedCM;
106
117
  }
107
118
 
108
- export { type AccountsResponse, type AuthTokenParams, type AuthorizationUrlParams, type ClientInfo, Gw2MeApi, Gw2MeClient, type Options, type RefreshTokenParams, Scope, type SubtokenResponse, type TokenResponse, type UserResponse };
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 b=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var C=t=>{throw TypeError(t)};var E=(t,e)=>{for(var r in e)b(t,r,{get:e[r],enumerable:!0})},I=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of j(e))!z.call(t,o)&&o!==r&&b(t,o,{get:()=>e[o],enumerable:!(n=G(e,o))||n.enumerable});return t};var L=t=>I(b({},"__esModule",{value:!0}),t);var v=(t,e,r)=>e.has(t)||C("Cannot "+r);var s=(t,e,r)=>(v(t,e,"read from private field"),r?r.call(t):e.get(t)),a=(t,e,r)=>e.has(t)?C("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),h=(t,e,r,n)=>(v(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),c=(t,e,r)=>(v(t,e,"access private method"),r);var M={};E(M,{Gw2MeApi:()=>m,Gw2MeClient:()=>A,Scope:()=>T});module.exports=L(M);var T=(i=>(i.Identify="identify",i.Email="email",i.Accounts="accounts",i.Accounts_Verified="accounts.verified",i.Accounts_DisplayName="accounts.displayName",i.GW2_Account="gw2:account",i.GW2_Inventories="gw2:inventories",i.GW2_Characters="gw2:characters",i.GW2_Tradingpost="gw2:tradingpost",i.GW2_Wallet="gw2:wallet",i.GW2_Unlocks="gw2:unlocks",i.GW2_Pvp="gw2:pvp",i.GW2_Wvw="gw2:wvw",i.GW2_Builds="gw2:builds",i.GW2_Progression="gw2:progression",i.GW2_Guilds="gw2:guilds",i))(T||{});async function l(t){let e=t.headers.get("Content-Type")==="application/json";if(!t.ok){let r;throw e&&(r=(await t.json()).error_description),new Error(`gw2.me returned an error: ${r??"Unknown error"}`)}if(!e)throw new Error("gw2.me did not return a valid JSON response");return t.json()}var f,x,m=class{constructor(e,r){this.access_token=e;this.options=r;a(this,f)}user(){return fetch(c(this,f,x).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(l)}accounts(){return fetch(c(this,f,x).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(l)}subtoken(e){return fetch(c(this,f,x).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(l)}};f=new WeakSet,x=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var _,w,R=class{constructor(e,r){a(this,_);a(this,w);h(this,_,e),h(this,w,r)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({mediation:e,signal:r,mode:n}){if(!this.isSupported())throw new Error("FedCM is not supported");return navigator.credentials.get({mediation:e,signal:r,identity:{providers:[{configURL:s(this,_),clientId:s(this,w)}],mode:n}})}};_=new WeakMap,w=new WeakMap;var p,d,y,g,k,A=class{constructor({client_id:e,client_secret:r},n){this.options=n;a(this,g);a(this,p);a(this,d);a(this,y);h(this,p,e),h(this,d,r),h(this,y,new R(c(this,g,k).call(this,"/fed-cm/config.json"),s(this,p)))}getAuthorizationUrl({redirect_uri:e,scopes:r,state:n,code_challenge:o,code_challenge_method:P,prompt:U,include_granted_scopes:O,verified_accounts_only:W}){let u=new URLSearchParams({client_id:s(this,p),response_type:"code",redirect_uri:e,scope:r.join(" ")});return n&&u.append("state",n),o&&P&&(u.append("code_challenge",o),u.append("code_challenge_method",P)),U&&u.append("prompt",U),O&&u.append("include_granted_scopes","true"),W&&u.append("verified_accounts_only","true"),c(this,g,k).call(this,`/oauth2/authorize?${u.toString()}`).toString()}async getAccessToken({code:e,redirect_uri:r,code_verifier:n}){let o=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:s(this,p),redirect_uri:r});return s(this,d)&&o.set("client_secret",s(this,d)),n&&o.set("code_verifier",n),await fetch(c(this,g,k).call(this,"/api/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o,cache:"no-store"}).then(l)}async refreshToken({refresh_token:e}){if(!s(this,d))throw new Error("client_secret required");let r=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:s(this,p),client_secret:s(this,d)});return await fetch(c(this,g,k).call(this,"/api/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r,cache:"no-store"}).then(l)}api(e){return new m(e,this.options)}get fedCM(){return s(this,y)}};p=new WeakMap,d=new WeakMap,y=new WeakMap,g=new WeakSet,k=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};0&&(module.exports={Gw2MeApi,Gw2MeClient,Scope});
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/package.json CHANGED
@@ -1,17 +1,9 @@
1
1
  {
2
2
  "name": "@gw2me/client",
3
- "version": "0.2.7",
3
+ "version": "0.4.0",
4
4
  "description": "gw2.me client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "scripts": {
8
- "build": "npm run clean && if test $CI; then npm run build:ci; else npm run build:local; fi",
9
- "build:local": "tsup src/index.ts && tsc --emitDeclarationOnly --declaration --declarationMap",
10
- "build:ci": "tsup src/index.ts --minify --dts",
11
- "clean": "rm -rf dist/",
12
- "lint": "eslint src",
13
- "publish-package": "gw2treasures-publish-package"
14
- },
15
7
  "repository": {
16
8
  "type": "git",
17
9
  "url": "git+https://github.com/GW2Treasures/gw2.me.git"
@@ -33,12 +25,20 @@
33
25
  },
34
26
  "homepage": "https://github.com/gw2treasures/gw2.me#readme",
35
27
  "devDependencies": {
36
- "@gw2treasures/eslint-config": "0.0.4",
37
- "@gw2treasures/publish-package": "0.0.1",
28
+ "@gw2treasures/eslint-config": "0.0.6",
29
+ "@gw2treasures/publish-package": "0.1.0-rc.0",
38
30
  "@gw2treasures/tsconfig": "0.0.1",
39
- "eslint": "8.57.0",
40
- "tsup": "8.2.4",
41
- "typescript": "5.5.4",
42
- "undici-types": "6.19.8"
31
+ "eslint": "8.57.1",
32
+ "tsup": "8.3.5",
33
+ "typescript": "5.7.2",
34
+ "undici-types": "6.21.0"
35
+ },
36
+ "scripts": {
37
+ "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",
40
+ "clean": "rm -rf dist/",
41
+ "lint": "eslint src",
42
+ "publish-package": "gw2treasures-publish-package"
43
43
  }
44
- }
44
+ }