@gw2me/client 0.2.4 → 0.2.5

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
@@ -53,6 +53,21 @@ declare class Gw2MeApi {
53
53
  subtoken(accountId: string): Promise<SubtokenResponse>;
54
54
  }
55
55
 
56
+ interface FedCMRequestOptions {
57
+ mediation?: CredentialMediationRequirement;
58
+ mode?: 'button';
59
+ signal?: AbortSignal;
60
+ }
61
+ declare class Gw2MeFedCM {
62
+ #private;
63
+ constructor(configUrl: URL, clientId: string);
64
+ isSupported(): boolean;
65
+ request({ mediation, signal, mode }: FedCMRequestOptions): Promise<null | {
66
+ token: string;
67
+ type: "identity";
68
+ }>;
69
+ }
70
+
56
71
  interface AuthorizationUrlParams {
57
72
  redirect_uri: string;
58
73
  scopes: Scope[];
@@ -81,13 +96,12 @@ interface TokenResponse {
81
96
  declare class Gw2MeClient {
82
97
  #private;
83
98
  private options?;
84
- private client_id;
85
- private client_secret?;
86
99
  constructor({ client_id, client_secret }: ClientInfo, options?: Partial<Options> | undefined);
87
100
  getAuthorizationUrl({ redirect_uri, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes, verified_accounts_only, }: AuthorizationUrlParams): string;
88
101
  getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
89
102
  refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
90
103
  api(access_token: string): Gw2MeApi;
104
+ get fedCM(): Gw2MeFedCM;
91
105
  }
92
106
 
93
107
  export { type AccountsResponse, type AuthTokenParams, type AuthorizationUrlParams, type ClientInfo, Gw2MeApi, Gw2MeClient, type Options, type RefreshTokenParams, Scope, type SubtokenResponse, type TokenResponse, type UserResponse };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var k=t=>{throw TypeError(t)};var T=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},U=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of R(e))!A.call(t,s)&&s!==r&&f(t,s,{get:()=>e[s],enumerable:!(i=v(e,s))||i.enumerable});return t};var b=t=>U(f({},"__esModule",{value:!0}),t);var W=(t,e,r)=>e.has(t)||k("Cannot "+r);var l=(t,e,r)=>e.has(t)?k("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r);var o=(t,e,r)=>(W(t,e,"access private method"),r);var G={};T(G,{Gw2MeApi:()=>u,Gw2MeClient:()=>m,Scope:()=>y});module.exports=b(G);var y=(n=>(n.Identify="identify",n.Email="email",n.Accounts="accounts",n.Accounts_Verified="accounts.verified",n.Accounts_DisplayName="accounts.displayName",n.GW2_Account="gw2:account",n.GW2_Inventories="gw2:inventories",n.GW2_Characters="gw2:characters",n.GW2_Tradingpost="gw2:tradingpost",n.GW2_Wallet="gw2:wallet",n.GW2_Unlocks="gw2:unlocks",n.GW2_Pvp="gw2:pvp",n.GW2_Wvw="gw2:wvw",n.GW2_Builds="gw2:builds",n.GW2_Progression="gw2:progression",n.GW2_Guilds="gw2:guilds",n))(y||{});async function c(t){let e=t.headers.get("Content-Type")==="application/json";if(!t.ok){let r;throw e&&(r=(await t.json()).error_message),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 p,d,u=class{constructor(e,r){this.access_token=e;this.options=r;l(this,p)}user(){return fetch(o(this,p,d).call(this,"api/user"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(c)}accounts(){return fetch(o(this,p,d).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(c)}subtoken(e){return fetch(o(this,p,d).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(c)}};p=new WeakSet,d=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};var h,g,m=class{constructor({client_id:e,client_secret:r},i){this.options=i;l(this,h);this.client_id=e,this.client_secret=r}getAuthorizationUrl({redirect_uri:e,scopes:r,state:i,code_challenge:s,code_challenge_method:_,prompt:w,include_granted_scopes:x,verified_accounts_only:P}){let a=new URLSearchParams({client_id:this.client_id,response_type:"code",redirect_uri:e,scope:r.join(" ")});return i&&a.append("state",i),s&&_&&(a.append("code_challenge",s),a.append("code_challenge_method",_)),w&&a.append("prompt",w),x&&a.append("include_granted_scopes","true"),P&&a.append("verified_accounts_only","true"),o(this,h,g).call(this,`/oauth2/authorize?${a.toString()}`).toString()}async getAccessToken({code:e,redirect_uri:r,code_verifier:i}){let s=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:this.client_id,redirect_uri:r});return this.client_secret&&s.set("client_secret",this.client_secret),i&&s.set("code_verifier",i),await fetch(o(this,h,g).call(this,"/api/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s,cache:"no-store"}).then(c)}async refreshToken({refresh_token:e}){if(!this.client_secret)throw new Error("client_secret required");let r=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:this.client_id,client_secret:this.client_secret});return await fetch(o(this,h,g).call(this,"/api/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r,cache:"no-store"}).then(c)}api(e){return new u(e,this.options)}};h=new WeakSet,g=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};0&&(module.exports={Gw2MeApi,Gw2MeClient,Scope});
1
+ "use strict";var v=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)v(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&&v(t,o,{get:()=>e[o],enumerable:!(n=G(e,o))||n.enumerable});return t};var L=t=>I(v({},"__esModule",{value:!0}),t);var A=(t,e,r)=>e.has(t)||C("Cannot "+r);var s=(t,e,r)=>(A(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)=>(A(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),c=(t,e,r)=>(A(t,e,"access private method"),r);var M={};E(M,{Gw2MeApi:()=>m,Gw2MeClient:()=>U,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 g(t){let e=t.headers.get("Content-Type")==="application/json";if(!t.ok){let r;throw e&&(r=(await t.json()).error_message),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(g)}accounts(){return fetch(c(this,f,x).call(this,"api/accounts"),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(g)}subtoken(e){return fetch(c(this,f,x).call(this,`api/accounts/${e}/subtoken`),{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(g)}};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,l,k,U=class{constructor({client_id:e,client_secret:r},n){this.options=n;a(this,l);a(this,p);a(this,d);a(this,y);h(this,p,e),h(this,d,r),h(this,y,new R(c(this,l,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:b,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)),b&&u.append("prompt",b),O&&u.append("include_granted_scopes","true"),W&&u.append("verified_accounts_only","true"),c(this,l,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,l,k).call(this,"/api/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o,cache:"no-store"}).then(g)}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,l,k).call(this,"/api/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r,cache:"no-store"}).then(g)}api(e){return new m(e,this.options)}get fedCM(){return s(this,y)}};p=new WeakMap,d=new WeakMap,y=new WeakMap,l=new WeakSet,k=function(e){return new URL(e,this.options?.url||"https://gw2.me/")};0&&(module.exports={Gw2MeApi,Gw2MeClient,Scope});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw2me/client",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "gw2.me client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",