@gw2me/client 0.5.2 → 0.5.3

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
@@ -55,15 +55,16 @@ declare class Gw2MeApi {
55
55
  }
56
56
 
57
57
  interface FedCMRequestOptions {
58
+ scopes: Scope[];
58
59
  mediation?: CredentialMediationRequirement;
59
- mode?: 'button';
60
+ mode?: 'passive' | 'active';
60
61
  signal?: AbortSignal;
61
62
  }
62
63
  declare class Gw2MeFedCM {
63
64
  #private;
64
65
  constructor(configUrl: URL, clientId: string);
65
66
  isSupported(): boolean;
66
- request({ mediation, signal, mode }: FedCMRequestOptions): Promise<null | {
67
+ request({ scopes, mediation, signal, mode }: FedCMRequestOptions): Promise<null | {
67
68
  token: string;
68
69
  type: "identity";
69
70
  }>;
package/dist/index.js CHANGED
@@ -1 +1 @@
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});
1
+ "use strict";var U=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var z=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 E=r=>j(U({},"__esModule",{value:!0}),r);var I=(r,e,t)=>e.has(r)||z("Cannot "+t);var o=(r,e,t)=>(I(r,e,"read from private field"),t?t.call(r):e.get(r)),u=(r,e,t)=>e.has(r)?z("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 M={};L(M,{Gw2MeApi:()=>x,Gw2MeClient:()=>O,Gw2MeError:()=>a,Gw2MeOAuthError:()=>y,Scope:()=>C});module.exports=E(M);var C=(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))(C||{});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 _,T,x=class{constructor(e,t){this.access_token=e;this.options=t;u(this,_)}user(){return fetch(c(this,_,T).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(g)}accounts(){return fetch(c(this,_,T).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(g)}subtoken(e){return fetch(c(this,_,T).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(g)}};_=new WeakSet,T=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var R,v,b=class{constructor(e,t){u(this,R);u(this,v);w(this,R,e),w(this,v,t)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({scopes:e,mediation:t,signal:n,mode:i}){if(!this.isSupported())throw new a("FedCM is not supported");return navigator.credentials.get({mediation:t,signal:n,identity:{providers:[{configURL:o(this,R),clientId:o(this,v),fields:[e.includes("identify")&&"name",e.includes("email")&&"email"].filter(Boolean),params:{scope:e.join(" ")}}],mode:i}})}};R=new WeakMap,v=new WeakMap;var p,d,P,h,l,O=class{constructor({client_id:e,client_secret:t},n){this.options=n;u(this,h);u(this,p);u(this,d);u(this,P);w(this,p,e),w(this,d,t),w(this,P,new b(c(this,h,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,h,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,h,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,h,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,h,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,h,l).call(this,"/api/token/introspect"),{method:"POST",cache:"no-store",headers:n,body:t}).then(g)}parseAuthorizationResponseSearchParams(e){let t=c(this,h,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,P)}};p=new WeakMap,d=new WeakMap,P=new WeakMap,h=new WeakSet,l=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,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw2me/client",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
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": "7.1.1"
45
+ "undici-types": "7.2.0"
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",