@gw2me/client 0.1.3 → 0.2.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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/index.d.ts +46 -37
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 GW2Treasures
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# `@gw2me/client`
|
|
2
|
+
|
|
3
|
+
This is a client library to interact with the gw2.me API.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Gw2MeClient } from '@gw2me/client';
|
|
9
|
+
|
|
10
|
+
const client = new Gw2MeClient({ client_id: '<client_id>' });
|
|
11
|
+
const url = client.getAuthorizationUrl({ /* ... */ });
|
|
12
|
+
|
|
13
|
+
// redirect user to url
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
npm i @gw2me/client
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
**@gw2me/client** is licensed under the [MIT License](./LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,43 @@ declare enum Scope {
|
|
|
12
12
|
GW2_Progression = "gw2:progression",
|
|
13
13
|
GW2_Guilds = "gw2:guilds"
|
|
14
14
|
}
|
|
15
|
+
interface ClientInfo {
|
|
16
|
+
client_id: string;
|
|
17
|
+
client_secret?: string;
|
|
18
|
+
}
|
|
19
|
+
interface Options {
|
|
20
|
+
url: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface UserResponse {
|
|
24
|
+
user: {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
email?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface AccountsResponse {
|
|
31
|
+
accounts: {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
}[];
|
|
35
|
+
}
|
|
36
|
+
interface SubtokenResponse {
|
|
37
|
+
subtoken: string;
|
|
38
|
+
expiresAt: string;
|
|
39
|
+
}
|
|
40
|
+
declare class Gw2MeApi {
|
|
41
|
+
#private;
|
|
42
|
+
private access_token;
|
|
43
|
+
private options?;
|
|
44
|
+
constructor(access_token: string, options?: Partial<Options> | undefined);
|
|
45
|
+
user(): Promise<UserResponse>;
|
|
46
|
+
accounts(): Promise<AccountsResponse>;
|
|
47
|
+
subtoken(accountId: string): Promise<SubtokenResponse>;
|
|
48
|
+
}
|
|
49
|
+
|
|
15
50
|
interface AuthorizationUrlParams {
|
|
16
51
|
redirect_uri: string;
|
|
17
|
-
client_id: string;
|
|
18
52
|
scopes: Scope[];
|
|
19
53
|
state?: string;
|
|
20
54
|
code_challenge?: string;
|
|
@@ -22,18 +56,13 @@ interface AuthorizationUrlParams {
|
|
|
22
56
|
prompt?: 'none' | 'consent';
|
|
23
57
|
include_granted_scopes?: boolean;
|
|
24
58
|
}
|
|
25
|
-
declare function getAuthorizationUrl({ redirect_uri, client_id, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes }: AuthorizationUrlParams): string;
|
|
26
59
|
interface AuthTokenParams {
|
|
27
60
|
code: string;
|
|
28
61
|
redirect_uri: string;
|
|
29
|
-
client_id: string;
|
|
30
|
-
client_secret?: string;
|
|
31
62
|
code_verifier?: string;
|
|
32
63
|
}
|
|
33
64
|
interface RefreshTokenParams {
|
|
34
65
|
refresh_token: string;
|
|
35
|
-
client_id: string;
|
|
36
|
-
client_secret: string;
|
|
37
66
|
}
|
|
38
67
|
interface TokenResponse {
|
|
39
68
|
access_token: string;
|
|
@@ -42,36 +71,16 @@ interface TokenResponse {
|
|
|
42
71
|
refresh_token?: string;
|
|
43
72
|
scope: string;
|
|
44
73
|
}
|
|
45
|
-
declare
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
accounts: {
|
|
56
|
-
id: string;
|
|
57
|
-
name: string;
|
|
58
|
-
}[];
|
|
59
|
-
}
|
|
60
|
-
interface SubtokenResponse {
|
|
61
|
-
subtoken: string;
|
|
62
|
-
expiresAt: string;
|
|
74
|
+
declare class Gw2MeClient {
|
|
75
|
+
#private;
|
|
76
|
+
private options?;
|
|
77
|
+
private client_id;
|
|
78
|
+
private client_secret?;
|
|
79
|
+
constructor({ client_id, client_secret }: ClientInfo, options?: Partial<Options> | undefined);
|
|
80
|
+
getAuthorizationUrl({ redirect_uri, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes }: AuthorizationUrlParams): string;
|
|
81
|
+
getAccessToken({ code, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
|
|
82
|
+
refreshToken({ refresh_token }: RefreshTokenParams): Promise<TokenResponse>;
|
|
83
|
+
api(access_token: string): Gw2MeApi;
|
|
63
84
|
}
|
|
64
|
-
declare const rest: {
|
|
65
|
-
user({ access_token }: {
|
|
66
|
-
access_token: string;
|
|
67
|
-
}): Promise<UserResponse>;
|
|
68
|
-
accounts({ access_token }: {
|
|
69
|
-
access_token: string;
|
|
70
|
-
}): Promise<AccountsResponse>;
|
|
71
|
-
subtoken({ access_token, accountId }: {
|
|
72
|
-
access_token: string;
|
|
73
|
-
accountId: string;
|
|
74
|
-
}): Promise<SubtokenResponse>;
|
|
75
|
-
};
|
|
76
85
|
|
|
77
|
-
export { AccountsResponse, AuthTokenParams, AuthorizationUrlParams,
|
|
86
|
+
export { AccountsResponse, AuthTokenParams, AuthorizationUrlParams, ClientInfo, Gw2MeApi, Gw2MeClient, Options, RefreshTokenParams, Scope, SubtokenResponse, TokenResponse, UserResponse };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var k=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var y=(n,e)=>{for(var t in e)k(n,t,{get:e[t],enumerable:!0})},b=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of T(e))!A.call(n,i)&&i!==t&&k(n,i,{get:()=>e[i],enumerable:!(s=R(e,i))||s.enumerable});return n};var U=n=>b(k({},"__esModule",{value:!0}),n);var W=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var g=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)};var c=(n,e,t)=>(W(n,e,"access private method"),t);var w=(n,e,t)=>new Promise((s,i)=>{var a=r=>{try{p(t.next(r))}catch(m){i(m)}},u=r=>{try{p(t.throw(r))}catch(m){i(m)}},p=r=>r.done?s(r.value):Promise.resolve(r.value).then(a,u);p((t=t.apply(n,e)).next())});var $={};y($,{Gw2MeApi:()=>d,Gw2MeClient:()=>P,Scope:()=>x});module.exports=U($);var x=(o=>(o.Identify="identify",o.Email="email",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_Builds="gw2:builds",o.GW2_Progression="gw2:progression",o.GW2_Guilds="gw2:guilds",o))(x||{});var h,_,d=class{constructor(e,t){this.access_token=e;this.options=t;g(this,h)}user(){return fetch(`${c(this,h,_).call(this)}api/user`,{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(e=>e.json())}accounts(){return fetch(`${c(this,h,_).call(this)}api/accounts`,{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(e=>e.json())}subtoken(e){return fetch(`${c(this,h,_).call(this)}api/accounts/${e}/subtoken`,{headers:{Authorization:`Bearer ${this.access_token}`},cache:"no-store"}).then(t=>t.json())}};h=new WeakSet,_=function(){var e;return((e=this.options)==null?void 0:e.url)||"https://gw2.me/"};var l,f,P=class{constructor({client_id:e,client_secret:t},s){this.options=s;g(this,l);this.client_id=e,this.client_secret=t}getAuthorizationUrl({redirect_uri:e,scopes:t,state:s,code_challenge:i,code_challenge_method:a,prompt:u,include_granted_scopes:p}){let r=new URLSearchParams({client_id:this.client_id,response_type:"code",redirect_uri:e,scope:t.join(" ")});return s&&r.append("state",s),i&&a&&(r.append("code_challenge",i),r.append("code_challenge_method",a)),u&&r.append("prompt",u),p&&r.append("include_granted_scopes","true"),`${c(this,l,f).call(this)}oauth2/authorize?${r.toString()}`}getAccessToken(i){return w(this,arguments,function*({code:e,redirect_uri:t,code_verifier:s}){let a=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:this.client_id,redirect_uri:t});return this.client_secret&&a.set("client_secret",this.client_secret),s&&a.set("code_verifier",s),yield fetch(`${c(this,l,f).call(this)}api/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:a,cache:"no-store"}).then(p=>p.json())})}refreshToken(t){return w(this,arguments,function*({refresh_token:e}){if(!this.client_secret)throw new Error("client_secret required");let s=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:this.client_id,client_secret:this.client_secret});return yield fetch(`${c(this,l,f).call(this)}api/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s,cache:"no-store"}).then(a=>a.json())})}api(e){return new d(e,this.options)}};l=new WeakSet,f=function(){var e;return((e=this.options)==null?void 0:e.url)||"https://gw2.me/"};0&&(module.exports={Gw2MeApi,Gw2MeClient,Scope});
|