@gw2me/client 0.8.0 → 0.8.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/dpop.d.ts +3 -7
- package/dist/dpop.js +1 -1
- package/dist/index.d.ts +13 -35
- package/dist/index.js +1 -1
- package/dist/types-yBP8cksw.d.ts +34 -0
- package/package.json +1 -1
package/dist/dpop.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
+
import { D as DPoPParams } from './types-yBP8cksw.js';
|
|
2
|
+
|
|
1
3
|
declare function generateDPoPKeyPair(): Promise<CryptoKeyPair>;
|
|
2
|
-
|
|
3
|
-
htm: 'GET' | 'POST' | (string & {});
|
|
4
|
-
htu: string;
|
|
5
|
-
nonce?: string;
|
|
6
|
-
accessToken?: string;
|
|
7
|
-
}
|
|
8
|
-
declare function createDPoPJwt({ htm, htu, nonce, accessToken }: DPoPOptions, keyPair: CryptoKeyPair): Promise<string>;
|
|
4
|
+
declare function createDPoPJwt({ htm, htu, nonce, accessToken }: DPoPParams, keyPair: CryptoKeyPair): Promise<string>;
|
|
9
5
|
declare function jwkThumbprint(key: CryptoKey): Promise<string>;
|
|
10
6
|
|
|
11
7
|
export { createDPoPJwt, generateDPoPKeyPair, jwkThumbprint };
|
package/dist/dpop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var m=(t,r)=>{for(var e in r)u(t,e,{get:r[e],enumerable:!0})},P=(t,r,e,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of w(r))!l.call(t,n)&&n!==e&&u(t,n,{get:()=>r[n],enumerable:!(a=d(r,n))||a.enumerable});return t};var A=t=>P(u({},"__esModule",{value:!0}),t);var K={};m(K,{createDPoPJwt:()=>h,generateDPoPKeyPair:()=>b,jwkThumbprint:()=>C});module.exports=A(K);function o(t){let r=t instanceof ArrayBuffer?new Uint8Array(t):t;return btoa(String.fromCharCode(...r)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function b(){return crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!1,["sign"])}async function h({htm:t,htu:r,nonce:e,accessToken:a},n){let c=JSON.stringify({alg:"ES256",typ:"dpop+jwt",jwk:await p(n.publicKey)}),y=JSON.stringify({iat:Math.floor(Date.now()/1e3),jti:o(crypto.getRandomValues(new Uint8Array(32))),htm:t,htu:r,nonce:e,ath:a?o(await crypto.subtle.digest("SHA-256",i(a))):void 0}),s=`${o(i(c))}.${o(i(y))}`,f={name:"ECDSA",hash:"SHA-256"},g=o(await crypto.subtle.sign(f,n.privateKey,i(s)));return`${s}.${g}`}var S=new TextEncoder;function i(t){return S.encode(t)}async function p(t){let{kty:r,e,k:a,n,x:c,y,crv:s}=await crypto.subtle.exportKey("jwk",t);return{e,k:a,crv:s,kty:r,n,x:c,y}}async function C(t){let r=JSON.stringify(await p(t)),e=await crypto.subtle.digest("SHA-256",i(r));return o(e)}0&&(module.exports={createDPoPJwt,generateDPoPKeyPair,jwkThumbprint});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Email = "email",
|
|
4
|
-
Accounts = "accounts",
|
|
5
|
-
Accounts_Verified = "accounts.verified",
|
|
6
|
-
Accounts_DisplayName = "accounts.displayName",
|
|
7
|
-
GW2_Account = "gw2:account",
|
|
8
|
-
GW2_Inventories = "gw2:inventories",
|
|
9
|
-
GW2_Characters = "gw2:characters",
|
|
10
|
-
GW2_Tradingpost = "gw2:tradingpost",
|
|
11
|
-
GW2_Wallet = "gw2:wallet",
|
|
12
|
-
GW2_Unlocks = "gw2:unlocks",
|
|
13
|
-
GW2_Pvp = "gw2:pvp",
|
|
14
|
-
GW2_Wvw = "gw2:wvw",
|
|
15
|
-
GW2_Builds = "gw2:builds",
|
|
16
|
-
GW2_Progression = "gw2:progression",
|
|
17
|
-
GW2_Guilds = "gw2:guilds"
|
|
18
|
-
}
|
|
19
|
-
interface ClientInfo {
|
|
20
|
-
client_id: string;
|
|
21
|
-
client_secret?: string;
|
|
22
|
-
}
|
|
23
|
-
interface Options {
|
|
24
|
-
url: string;
|
|
25
|
-
}
|
|
1
|
+
import { O as Options, a as DPoPCallback, S as Scope, C as ClientInfo } from './types-yBP8cksw.js';
|
|
2
|
+
export { D as DPoPParams } from './types-yBP8cksw.js';
|
|
26
3
|
|
|
27
4
|
interface UserResponse {
|
|
28
5
|
user: {
|
|
@@ -49,7 +26,7 @@ interface SubtokenResponse {
|
|
|
49
26
|
expiresAt: string;
|
|
50
27
|
}
|
|
51
28
|
interface ApiOptions extends Options {
|
|
52
|
-
|
|
29
|
+
dpop?: DPoPCallback;
|
|
53
30
|
}
|
|
54
31
|
declare class Gw2MeApi {
|
|
55
32
|
#private;
|
|
@@ -92,27 +69,28 @@ interface AuthorizationUrlParams {
|
|
|
92
69
|
verified_accounts_only?: boolean;
|
|
93
70
|
}
|
|
94
71
|
interface PushedAuthorizationRequestParams extends AuthorizationUrlParams {
|
|
95
|
-
|
|
72
|
+
dpop?: DPoPCallback;
|
|
96
73
|
}
|
|
97
74
|
interface AuthorizationUrlRequestUriParams {
|
|
98
75
|
request_uri: string;
|
|
99
76
|
}
|
|
77
|
+
type TokenType = 'Bearer' | 'DPoP';
|
|
100
78
|
interface AuthTokenParams {
|
|
101
79
|
code: string;
|
|
102
|
-
token_type?:
|
|
80
|
+
token_type?: TokenType;
|
|
103
81
|
redirect_uri: string;
|
|
104
82
|
code_verifier?: string;
|
|
105
|
-
|
|
83
|
+
dpop?: DPoPCallback;
|
|
106
84
|
}
|
|
107
85
|
interface RefreshTokenParams {
|
|
108
86
|
refresh_token: string;
|
|
109
|
-
refresh_token_type?:
|
|
110
|
-
|
|
87
|
+
refresh_token_type?: TokenType;
|
|
88
|
+
dpop?: DPoPCallback;
|
|
111
89
|
}
|
|
112
90
|
interface TokenResponse {
|
|
113
91
|
access_token: string;
|
|
114
92
|
issued_token_type: 'urn:ietf:params:oauth:token-type:access_token';
|
|
115
|
-
token_type:
|
|
93
|
+
token_type: TokenType;
|
|
116
94
|
expires_in: number;
|
|
117
95
|
refresh_token?: string;
|
|
118
96
|
scope: string;
|
|
@@ -157,8 +135,8 @@ declare class Gw2MeClient {
|
|
|
157
135
|
constructor(client: ClientInfo, options?: Partial<Options> | undefined);
|
|
158
136
|
getAuthorizationUrl(params: AuthorizationUrlParams | AuthorizationUrlRequestUriParams): string;
|
|
159
137
|
pushAuthorizationRequest(params: PushedAuthorizationRequestParams): Promise<PushedAuthorizationRequestResponse>;
|
|
160
|
-
getAccessToken({ code, token_type, redirect_uri, code_verifier,
|
|
161
|
-
refreshToken({ refresh_token, refresh_token_type,
|
|
138
|
+
getAccessToken({ code, token_type, redirect_uri, code_verifier, dpop }: AuthTokenParams): Promise<TokenResponse>;
|
|
139
|
+
refreshToken({ refresh_token, refresh_token_type, dpop }: RefreshTokenParams): Promise<TokenResponse>;
|
|
162
140
|
revokeToken({ token }: RevokeTokenParams): Promise<void>;
|
|
163
141
|
introspectToken({ token }: IntrospectTokenParams): Promise<IntrospectTokenResponse>;
|
|
164
142
|
/**
|
|
@@ -184,4 +162,4 @@ declare class Gw2MeOAuthError extends Gw2MeError {
|
|
|
184
162
|
constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined);
|
|
185
163
|
}
|
|
186
164
|
|
|
187
|
-
export { type AccountsResponse, type ApiOptions, type AuthTokenParams, type AuthorizationUrlParams, type AuthorizationUrlRequestUriParams,
|
|
165
|
+
export { type AccountsResponse, type ApiOptions, type AuthTokenParams, type AuthorizationUrlParams, type AuthorizationUrlRequestUriParams, ClientInfo, DPoPCallback, type FedCMRequestOptions, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeFedCM, Gw2MeOAuthError, type IntrospectTokenParams, IntrospectTokenResponse, Options, type PushedAuthorizationRequestParams, type PushedAuthorizationRequestResponse, type RefreshTokenParams, type RevokeTokenParams, Scope, type SubtokenOptions, type SubtokenResponse, type TokenResponse, type TokenType, type UserResponse };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var G=n=>{throw TypeError(n)};var E=(n,e)=>{for(var t in e)C(n,t,{get:e[t],enumerable:!0})},B=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of W(e))!L.call(n,o)&&o!==t&&C(n,o,{get:()=>e[o],enumerable:!(r=j(e,o))||r.enumerable});return n};var M=n=>B(C({},"__esModule",{value:!0}),n);var U=(n,e,t)=>e.has(n)||G("Cannot "+t);var a=(n,e,t)=>(U(n,e,"read from private field"),t?t.call(n):e.get(n)),m=(n,e,t)=>e.has(n)?G("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),_=(n,e,t,r)=>(U(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),i=(n,e,t)=>(U(n,e,"access private method"),t);var J={};E(J,{Gw2MeApi:()=>T,Gw2MeClient:()=>q,Gw2MeError:()=>d,Gw2MeOAuthError:()=>x,Scope:()=>I});module.exports=M(J);var I=(u=>(u.Identify="identify",u.Email="email",u.Accounts="accounts",u.Accounts_Verified="accounts.verified",u.Accounts_DisplayName="accounts.displayName",u.GW2_Account="gw2:account",u.GW2_Inventories="gw2:inventories",u.GW2_Characters="gw2:characters",u.GW2_Tradingpost="gw2:tradingpost",u.GW2_Wallet="gw2:wallet",u.GW2_Unlocks="gw2:unlocks",u.GW2_Pvp="gw2:pvp",u.GW2_Wvw="gw2:wvw",u.GW2_Builds="gw2:builds",u.GW2_Progression="gw2:progression",u.GW2_Guilds="gw2:guilds",u))(I||{});var d=class extends Error{},x=class extends d{constructor(t,r,o){super(`Received ${t}`+(r?`: ${r}`:"")+(o?` (${o})`:""));this.error=t;this.error_description=r;this.error_uri=o}};async function l(n){if(await z(n),!(n.headers.get("Content-Type")==="application/json"))throw new d("gw2.me did not return a valid JSON response");return n.json()}async function z(n){if(!n.ok){let e;throw n.headers.get("Content-Type")==="application/json"&&(e=(await n.json()).error_description),new d(`gw2.me returned an error: ${e??"Unknown error"}`)}}var f,S,R,T=class{constructor(e,t){this.access_token=e;this.options=t;m(this,f)}user(){return i(this,f,R).call(this,"api/user").then(e=>fetch(e)).then(l)}saveSettings(e){return i(this,f,R).call(this,"api/user/settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(t=>fetch(t)).then(z)}accounts(){return i(this,f,R).call(this,"api/accounts").then(e=>fetch(e)).then(l)}subtoken(e,t){let r=i(this,f,S).call(this,`api/accounts/${e}/subtoken`);return t?.permissions&&r.searchParams.set("permissions",t.permissions.join(",")),i(this,f,R).call(this,r).then(o=>fetch(o)).then(l)}};f=new WeakSet,S=function(e){return new URL(e,this.options?.url||"https://gw2.me/")},R=async function(e,t){let r=e instanceof URL?e:i(this,f,S).call(this,e),o=this.options?.dpop,s=new Headers(t?.headers);return s.set("Authorization",`${o?"DPoP":"Bearer"} ${this.access_token}`),o&&s.set("DPoP",await o({htm:t?.method??"GET",htu:r.toString(),accessToken:this.access_token})),new Request(r,{cache:"no-cache",...t,headers:s})};var A,v,O=class{constructor(e,t){m(this,A);m(this,v);_(this,A,e),_(this,v,t)}isSupported(){return typeof window<"u"&&"IdentityCredential"in window}request({scopes:e,mediation:t,signal:r,mode:o,code_challenge:s,code_challenge_method:h}){if(!this.isSupported())throw new d("FedCM is not supported");return navigator.credentials.get({mediation:t,signal:r,identity:{providers:[{configURL:a(this,A),clientId:a(this,v),fields:[e.includes("identify")&&"name",e.includes("email")&&"email"].filter(Boolean),nonce:`${h}:${s}`,params:{scope:e.join(" "),code_challenge:s,code_challenge_method:h}}],mode:o}})}};A=new WeakMap,v=new WeakMap;var c,b,p,P,y,q=class{constructor(e,t){this.options=t;m(this,p);m(this,c);m(this,b);_(this,c,e),_(this,b,new O(i(this,p,P).call(this,"/fed-cm/config.json"),e.client_id))}getAuthorizationUrl(e){let t="request_uri"in e?new URLSearchParams({client_id:a(this,c).client_id,response_type:"code",request_uri:e.request_uri}):$(a(this,c).client_id,e);return i(this,p,P).call(this,`/oauth2/authorize?${t.toString()}`).toString()}async pushAuthorizationRequest(e){let t=i(this,p,P).call(this,"/oauth2/par"),r={"Content-Type":"application/x-www-form-urlencoded"};e.dpop&&(r.DPoP=await e.dpop({htm:"POST",htu:t.toString()}));let o=$(a(this,c).client_id,e);return a(this,c).client_secret&&(r.Authorization=i(this,p,y).call(this)),await fetch(t,{method:"POST",headers:r,body:o,cache:"no-store"}).then(l)}async getAccessToken({code:e,token_type:t,redirect_uri:r,code_verifier:o,dpop:s}){let h=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:a(this,c).client_id,redirect_uri:r}),g={"Content-Type":"application/x-www-form-urlencoded"};a(this,c).client_secret&&(g.Authorization=i(this,p,y).call(this)),o&&h.set("code_verifier",o);let w=i(this,p,P).call(this,"/api/token");return s&&(g.DPoP=await s({htm:"POST",htu:w.toString(),accessToken:t==="DPoP"?e:void 0})),await fetch(w,{method:"POST",headers:g,body:h,cache:"no-store"}).then(l)}async refreshToken({refresh_token:e,refresh_token_type:t,dpop:r}){let o=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:a(this,c).client_id}),s={"Content-Type":"application/x-www-form-urlencoded"};a(this,c).client_secret&&(s.Authorization=i(this,p,y).call(this));let h=i(this,p,P).call(this,"/api/token");return r&&(s.DPoP=await r({htm:"POST",htu:h.toString(),accessToken:t==="DPoP"?e:void 0})),await fetch(h,{method:"POST",headers:s,body:o,cache:"no-store"}).then(l)}async revokeToken({token:e}){let t=new URLSearchParams({token:e}),r={"Content-Type":"application/x-www-form-urlencoded"};a(this,c).client_secret&&(r.Authorization=i(this,p,y).call(this)),await fetch(i(this,p,P).call(this,"/api/token/revoke"),{method:"POST",cache:"no-store",headers:r,body:t}).then(l)}async introspectToken({token:e}){let t=new URLSearchParams({token:e}),r={"Content-Type":"application/x-www-form-urlencoded"};return a(this,c).client_secret&&(r.Authorization=i(this,p,y).call(this)),await fetch(i(this,p,P).call(this,"/api/token/introspect"),{method:"POST",cache:"no-store",headers:r,body:t}).then(l)}parseAuthorizationResponseSearchParams(e){let t=i(this,p,P).call(this,"/").origin,r=e.get("iss");if(!r)throw new d("Issuer Identifier verification failed: parameter `iss` is missing");if(r!==t)throw new d(`Issuer Identifier verification failed: expected "${t}", got "${r}"`);let o=e.get("error");if(o){let g=e.get("error_description")??void 0,w=e.get("error_uri")??void 0;throw new x(o,g,w)}let s=e.get("code");if(!s)throw new d("Parameter `code` is missing");let h=e.get("state")||void 0;return{code:s,state:h}}api(e,t){return new T(e,{...this.options,...t})}get fedCM(){return a(this,b)}};c=new WeakMap,b=new WeakMap,p=new WeakSet,P=function(e){return new URL(e,this.options?.url||"https://gw2.me/")},y=function(){if(!a(this,c).client_secret)throw new d("client_secret is required");return`Basic ${btoa(`${a(this,c).client_id}:${a(this,c).client_secret}`)}`};function $(n,{redirect_uri:e,scopes:t,state:r,code_challenge:o,code_challenge_method:s,dpop_jkt:h,prompt:g,include_granted_scopes:w,verified_accounts_only:D}){let k=new URLSearchParams({client_id:n,response_type:"code",redirect_uri:e,scope:t.join(" ")});return r&&k.append("state",r),o&&s&&(k.append("code_challenge",o),k.append("code_challenge_method",s)),h&&k.append("dpop_jkt",h),g&&k.append("prompt",g),w&&k.append("include_granted_scopes","true"),D&&k.append("verified_accounts_only","true"),k}0&&(module.exports={Gw2MeApi,Gw2MeClient,Gw2MeError,Gw2MeOAuthError,Scope});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
declare enum Scope {
|
|
2
|
+
Identify = "identify",
|
|
3
|
+
Email = "email",
|
|
4
|
+
Accounts = "accounts",
|
|
5
|
+
Accounts_Verified = "accounts.verified",
|
|
6
|
+
Accounts_DisplayName = "accounts.displayName",
|
|
7
|
+
GW2_Account = "gw2:account",
|
|
8
|
+
GW2_Inventories = "gw2:inventories",
|
|
9
|
+
GW2_Characters = "gw2:characters",
|
|
10
|
+
GW2_Tradingpost = "gw2:tradingpost",
|
|
11
|
+
GW2_Wallet = "gw2:wallet",
|
|
12
|
+
GW2_Unlocks = "gw2:unlocks",
|
|
13
|
+
GW2_Pvp = "gw2:pvp",
|
|
14
|
+
GW2_Wvw = "gw2:wvw",
|
|
15
|
+
GW2_Builds = "gw2:builds",
|
|
16
|
+
GW2_Progression = "gw2:progression",
|
|
17
|
+
GW2_Guilds = "gw2:guilds"
|
|
18
|
+
}
|
|
19
|
+
interface ClientInfo {
|
|
20
|
+
client_id: string;
|
|
21
|
+
client_secret?: string;
|
|
22
|
+
}
|
|
23
|
+
interface Options {
|
|
24
|
+
url: string;
|
|
25
|
+
}
|
|
26
|
+
interface DPoPParams {
|
|
27
|
+
htm: 'POST' | 'GET' | (string & {});
|
|
28
|
+
htu: string;
|
|
29
|
+
nonce?: string;
|
|
30
|
+
accessToken?: string;
|
|
31
|
+
}
|
|
32
|
+
type DPoPCallback = (params: DPoPParams) => string | Promise<string>;
|
|
33
|
+
|
|
34
|
+
export { type ClientInfo as C, type DPoPParams as D, type Options as O, Scope as S, type DPoPCallback as a };
|