@gw2me/client 0.1.2 → 0.1.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 +16 -13
- package/dist/index.js +1 -151
- package/package.json +6 -7
- package/dist/index.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
declare enum Scope {
|
|
2
2
|
Identify = "identify",
|
|
3
3
|
Email = "email",
|
|
4
4
|
GW2_Account = "gw2:account",
|
|
@@ -12,54 +12,56 @@ export declare enum Scope {
|
|
|
12
12
|
GW2_Progression = "gw2:progression",
|
|
13
13
|
GW2_Guilds = "gw2:guilds"
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
interface AuthorizationUrlParams {
|
|
16
16
|
redirect_uri: string;
|
|
17
17
|
client_id: string;
|
|
18
18
|
scopes: Scope[];
|
|
19
19
|
state?: string;
|
|
20
20
|
code_challenge?: string;
|
|
21
21
|
code_challenge_method?: 'S256';
|
|
22
|
+
prompt?: 'none' | 'consent';
|
|
23
|
+
include_granted_scopes?: boolean;
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
declare function getAuthorizationUrl({ redirect_uri, client_id, scopes, state, code_challenge, code_challenge_method, prompt, include_granted_scopes }: AuthorizationUrlParams): string;
|
|
26
|
+
interface AuthTokenParams {
|
|
25
27
|
code: string;
|
|
26
28
|
redirect_uri: string;
|
|
27
29
|
client_id: string;
|
|
28
30
|
client_secret?: string;
|
|
29
31
|
code_verifier?: string;
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
interface RefreshTokenParams {
|
|
32
34
|
refresh_token: string;
|
|
33
35
|
client_id: string;
|
|
34
36
|
client_secret: string;
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
interface TokenResponse {
|
|
37
39
|
access_token: string;
|
|
38
40
|
token_type: 'Bearer';
|
|
39
41
|
expires_in: number;
|
|
40
42
|
refresh_token?: string;
|
|
41
43
|
scope: string;
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
declare function getAccessToken({ code, client_id, client_secret, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
|
|
46
|
+
declare function refreshToken({ refresh_token, client_id, client_secret }: RefreshTokenParams): Promise<TokenResponse>;
|
|
47
|
+
interface UserResponse {
|
|
46
48
|
user: {
|
|
47
49
|
id: string;
|
|
48
50
|
name: string;
|
|
49
51
|
email?: string;
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
interface AccountsResponse {
|
|
53
55
|
accounts: {
|
|
54
56
|
id: string;
|
|
55
57
|
name: string;
|
|
56
58
|
}[];
|
|
57
59
|
}
|
|
58
|
-
|
|
60
|
+
interface SubtokenResponse {
|
|
59
61
|
subtoken: string;
|
|
60
62
|
expiresAt: string;
|
|
61
63
|
}
|
|
62
|
-
|
|
64
|
+
declare const rest: {
|
|
63
65
|
user({ access_token }: {
|
|
64
66
|
access_token: string;
|
|
65
67
|
}): Promise<UserResponse>;
|
|
@@ -71,4 +73,5 @@ export declare const rest: {
|
|
|
71
73
|
accountId: string;
|
|
72
74
|
}): Promise<SubtokenResponse>;
|
|
73
75
|
};
|
|
74
|
-
|
|
76
|
+
|
|
77
|
+
export { AccountsResponse, AuthTokenParams, AuthorizationUrlParams, RefreshTokenParams, Scope, SubtokenResponse, TokenResponse, UserResponse, getAccessToken, getAuthorizationUrl, refreshToken, rest };
|
package/dist/index.js
CHANGED
|
@@ -1,151 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __async = (__this, __arguments, generator) => {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
var fulfilled = (value) => {
|
|
22
|
-
try {
|
|
23
|
-
step(generator.next(value));
|
|
24
|
-
} catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var rejected = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.throw(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// src/index.ts
|
|
41
|
-
var src_exports = {};
|
|
42
|
-
__export(src_exports, {
|
|
43
|
-
Scope: () => Scope,
|
|
44
|
-
getAccessToken: () => getAccessToken,
|
|
45
|
-
getAuthorizationUrl: () => getAuthorizationUrl,
|
|
46
|
-
refreshToken: () => refreshToken,
|
|
47
|
-
rest: () => rest
|
|
48
|
-
});
|
|
49
|
-
module.exports = __toCommonJS(src_exports);
|
|
50
|
-
var Scope = /* @__PURE__ */ ((Scope2) => {
|
|
51
|
-
Scope2["Identify"] = "identify";
|
|
52
|
-
Scope2["Email"] = "email";
|
|
53
|
-
Scope2["GW2_Account"] = "gw2:account";
|
|
54
|
-
Scope2["GW2_Inventories"] = "gw2:inventories";
|
|
55
|
-
Scope2["GW2_Characters"] = "gw2:characters";
|
|
56
|
-
Scope2["GW2_Tradingpost"] = "gw2:tradingpost";
|
|
57
|
-
Scope2["GW2_Wallet"] = "gw2:wallet";
|
|
58
|
-
Scope2["GW2_Unlocks"] = "gw2:unlocks";
|
|
59
|
-
Scope2["GW2_Pvp"] = "gw2:pvp";
|
|
60
|
-
Scope2["GW2_Builds"] = "gw2:builds";
|
|
61
|
-
Scope2["GW2_Progression"] = "gw2:progression";
|
|
62
|
-
Scope2["GW2_Guilds"] = "gw2:guilds";
|
|
63
|
-
return Scope2;
|
|
64
|
-
})(Scope || {});
|
|
65
|
-
function getUrl() {
|
|
66
|
-
return process.env.GW2ME_URL || "https://gw2.me/";
|
|
67
|
-
}
|
|
68
|
-
function getAuthorizationUrl({ redirect_uri, client_id, scopes, state, code_challenge, code_challenge_method }) {
|
|
69
|
-
const params = new URLSearchParams({
|
|
70
|
-
"response_type": "code",
|
|
71
|
-
"redirect_uri": redirect_uri,
|
|
72
|
-
"client_id": client_id,
|
|
73
|
-
"scope": scopes.join(" ")
|
|
74
|
-
});
|
|
75
|
-
if (state) {
|
|
76
|
-
params.append("state", state);
|
|
77
|
-
}
|
|
78
|
-
if (code_challenge && code_challenge_method) {
|
|
79
|
-
params.append("code_challenge", code_challenge);
|
|
80
|
-
params.append("code_challenge_method", code_challenge_method);
|
|
81
|
-
}
|
|
82
|
-
return `${getUrl()}oauth2/authorize?${params.toString()}`;
|
|
83
|
-
}
|
|
84
|
-
function getAccessToken(_0) {
|
|
85
|
-
return __async(this, arguments, function* ({ code, client_id, client_secret, redirect_uri, code_verifier }) {
|
|
86
|
-
const data = new URLSearchParams({
|
|
87
|
-
grant_type: "authorization_code",
|
|
88
|
-
code,
|
|
89
|
-
client_id,
|
|
90
|
-
redirect_uri
|
|
91
|
-
});
|
|
92
|
-
if (client_secret) {
|
|
93
|
-
data.set("client_secret", client_secret);
|
|
94
|
-
}
|
|
95
|
-
if (code_verifier) {
|
|
96
|
-
data.set("code_verifier", code_verifier);
|
|
97
|
-
}
|
|
98
|
-
const token = yield fetch(`${getUrl()}api/token`, {
|
|
99
|
-
method: "POST",
|
|
100
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
101
|
-
body: data,
|
|
102
|
-
cache: "no-store"
|
|
103
|
-
}).then((r) => r.json());
|
|
104
|
-
return token;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
function refreshToken(_0) {
|
|
108
|
-
return __async(this, arguments, function* ({ refresh_token, client_id, client_secret }) {
|
|
109
|
-
const data = new URLSearchParams({
|
|
110
|
-
grant_type: "refresh_token",
|
|
111
|
-
refresh_token,
|
|
112
|
-
client_id,
|
|
113
|
-
client_secret
|
|
114
|
-
});
|
|
115
|
-
const token = yield fetch(`${getUrl()}api/token`, {
|
|
116
|
-
method: "POST",
|
|
117
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
118
|
-
body: data,
|
|
119
|
-
cache: "no-store"
|
|
120
|
-
}).then((r) => r.json());
|
|
121
|
-
return token;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
var rest = {
|
|
125
|
-
user({ access_token }) {
|
|
126
|
-
return fetch(`${getUrl()}api/user`, {
|
|
127
|
-
headers: { "Authorization": `Bearer ${access_token}` },
|
|
128
|
-
cache: "no-store"
|
|
129
|
-
}).then((r) => r.json());
|
|
130
|
-
},
|
|
131
|
-
accounts({ access_token }) {
|
|
132
|
-
return fetch(`${getUrl()}api/accounts`, {
|
|
133
|
-
headers: { "Authorization": `Bearer ${access_token}` },
|
|
134
|
-
cache: "no-store"
|
|
135
|
-
}).then((r) => r.json());
|
|
136
|
-
},
|
|
137
|
-
subtoken({ access_token, accountId }) {
|
|
138
|
-
return fetch(`${getUrl()}api/accounts/${accountId}/subtoken`, {
|
|
139
|
-
headers: { "Authorization": `Bearer ${access_token}` },
|
|
140
|
-
cache: "no-store"
|
|
141
|
-
}).then((r) => r.json());
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
-
0 && (module.exports = {
|
|
146
|
-
Scope,
|
|
147
|
-
getAccessToken,
|
|
148
|
-
getAuthorizationUrl,
|
|
149
|
-
refreshToken,
|
|
150
|
-
rest
|
|
151
|
-
});
|
|
1
|
+
"use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var n in e)d(t,n,{get:e[n],enumerable:!0})},w=(t,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of f(e))!k.call(t,r)&&r!==n&&d(t,r,{get:()=>e[r],enumerable:!(a=l(e,r))||a.enumerable});return t};var P=t=>w(d({},"__esModule",{value:!0}),t);var h=(t,e,n)=>new Promise((a,r)=>{var u=s=>{try{c(n.next(s))}catch(g){r(g)}},i=s=>{try{c(n.throw(s))}catch(g){r(g)}},c=s=>s.done?a(s.value):Promise.resolve(s.value).then(u,i);c((n=n.apply(t,e)).next())});var y={};m(y,{Scope:()=>_,getAccessToken:()=>R,getAuthorizationUrl:()=>x,refreshToken:()=>T,rest:()=>A});module.exports=P(y);var _=(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))(_||{});function p(){return process.env.GW2ME_URL||"https://gw2.me/"}function x({redirect_uri:t,client_id:e,scopes:n,state:a,code_challenge:r,code_challenge_method:u,prompt:i,include_granted_scopes:c}){let s=new URLSearchParams({response_type:"code",redirect_uri:t,client_id:e,scope:n.join(" ")});return a&&s.append("state",a),r&&u&&(s.append("code_challenge",r),s.append("code_challenge_method",u)),i&&s.append("prompt",i),c&&s.append("include_granted_scopes","true"),`${p()}oauth2/authorize?${s.toString()}`}function R(u){return h(this,arguments,function*({code:t,client_id:e,client_secret:n,redirect_uri:a,code_verifier:r}){let i=new URLSearchParams({grant_type:"authorization_code",code:t,client_id:e,redirect_uri:a});return n&&i.set("client_secret",n),r&&i.set("code_verifier",r),yield fetch(`${p()}api/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i,cache:"no-store"}).then(s=>s.json())})}function T(a){return h(this,arguments,function*({refresh_token:t,client_id:e,client_secret:n}){let r=new URLSearchParams({grant_type:"refresh_token",refresh_token:t,client_id:e,client_secret:n});return yield fetch(`${p()}api/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r,cache:"no-store"}).then(i=>i.json())})}var A={user({access_token:t}){return fetch(`${p()}api/user`,{headers:{Authorization:`Bearer ${t}`},cache:"no-store"}).then(e=>e.json())},accounts({access_token:t}){return fetch(`${p()}api/accounts`,{headers:{Authorization:`Bearer ${t}`},cache:"no-store"}).then(e=>e.json())},subtoken({access_token:t,accountId:e}){return fetch(`${p()}api/accounts/${e}/subtoken`,{headers:{Authorization:`Bearer ${t}`},cache:"no-store"}).then(n=>n.json())}};0&&(module.exports={Scope,getAccessToken,getAuthorizationUrl,refreshToken,rest});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gw2me/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "gw2.me client library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
"build:ci": "tsup src/index.ts --minify --dts",
|
|
11
11
|
"clean": "rm -rf dist/",
|
|
12
12
|
"lint": "eslint src",
|
|
13
|
-
"publish-package": "if test `npm view . version | sed -n 2p` != $npm_package_version; then npm publish --access public; else echo not changed; fi"
|
|
14
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
"publish-package": "if test `npm view . version | sed -n 2p` != $npm_package_version; then npm publish --access public; else echo not changed; fi"
|
|
15
14
|
},
|
|
16
15
|
"repository": {
|
|
17
16
|
"type": "git",
|
|
@@ -35,11 +34,11 @@
|
|
|
35
34
|
"homepage": "https://github.com/gw2treasures/gw2.me#readme",
|
|
36
35
|
"devDependencies": {
|
|
37
36
|
"@tsconfig/recommended": "1.0.3",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "6.7.
|
|
39
|
-
"@typescript-eslint/parser": "6.7.
|
|
40
|
-
"eslint": "8.
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "6.7.5",
|
|
38
|
+
"@typescript-eslint/parser": "6.7.5",
|
|
39
|
+
"eslint": "8.51.0",
|
|
41
40
|
"tsup": "7.2.0",
|
|
42
41
|
"typescript": "5.2.2",
|
|
43
|
-
"undici-types": "5.
|
|
42
|
+
"undici-types": "5.26.3"
|
|
44
43
|
}
|
|
45
44
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK;IACf,QAAQ,aAAa;IACrB,KAAK,UAAU;IAEf,WAAW,gBAAgB;IAC3B,eAAe,oBAAoB;IACnC,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;IACnC,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,eAAe,oBAAoB;IACnC,UAAU,eAAe;CAC1B;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,KAAK,EAAE,CAAC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