@gw2me/client 0.1.2

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.
@@ -0,0 +1,74 @@
1
+ export declare enum Scope {
2
+ Identify = "identify",
3
+ Email = "email",
4
+ GW2_Account = "gw2:account",
5
+ GW2_Inventories = "gw2:inventories",
6
+ GW2_Characters = "gw2:characters",
7
+ GW2_Tradingpost = "gw2:tradingpost",
8
+ GW2_Wallet = "gw2:wallet",
9
+ GW2_Unlocks = "gw2:unlocks",
10
+ GW2_Pvp = "gw2:pvp",
11
+ GW2_Builds = "gw2:builds",
12
+ GW2_Progression = "gw2:progression",
13
+ GW2_Guilds = "gw2:guilds"
14
+ }
15
+ export interface AuthorizationUrlParams {
16
+ redirect_uri: string;
17
+ client_id: string;
18
+ scopes: Scope[];
19
+ state?: string;
20
+ code_challenge?: string;
21
+ code_challenge_method?: 'S256';
22
+ }
23
+ export declare function getAuthorizationUrl({ redirect_uri, client_id, scopes, state, code_challenge, code_challenge_method }: AuthorizationUrlParams): string;
24
+ export interface AuthTokenParams {
25
+ code: string;
26
+ redirect_uri: string;
27
+ client_id: string;
28
+ client_secret?: string;
29
+ code_verifier?: string;
30
+ }
31
+ export interface RefreshTokenParams {
32
+ refresh_token: string;
33
+ client_id: string;
34
+ client_secret: string;
35
+ }
36
+ export interface TokenResponse {
37
+ access_token: string;
38
+ token_type: 'Bearer';
39
+ expires_in: number;
40
+ refresh_token?: string;
41
+ scope: string;
42
+ }
43
+ export declare function getAccessToken({ code, client_id, client_secret, redirect_uri, code_verifier }: AuthTokenParams): Promise<TokenResponse>;
44
+ export declare function refreshToken({ refresh_token, client_id, client_secret }: RefreshTokenParams): Promise<TokenResponse>;
45
+ export interface UserResponse {
46
+ user: {
47
+ id: string;
48
+ name: string;
49
+ email?: string;
50
+ };
51
+ }
52
+ export interface AccountsResponse {
53
+ accounts: {
54
+ id: string;
55
+ name: string;
56
+ }[];
57
+ }
58
+ export interface SubtokenResponse {
59
+ subtoken: string;
60
+ expiresAt: string;
61
+ }
62
+ export declare const rest: {
63
+ user({ access_token }: {
64
+ access_token: string;
65
+ }): Promise<UserResponse>;
66
+ accounts({ access_token }: {
67
+ access_token: string;
68
+ }): Promise<AccountsResponse>;
69
+ subtoken({ access_token, accountId }: {
70
+ access_token: string;
71
+ accountId: string;
72
+ }): Promise<SubtokenResponse>;
73
+ };
74
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAMD,wBAAgB,mBAAmB,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,EAAE,sBAAsB,UAoB5I;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,QAAQ,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,cAAc,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CAuB7I;AAED,wBAAsB,YAAY,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAe1H;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAA;CACF;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAA;CACJ;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,IAAI;;sBACwB,MAAM;QAAK,QAAQ,YAAY,CAAC;;sBAO5B,MAAM;QAAK,QAAQ,gBAAgB,CAAC;;sBAOzB,MAAM;mBAAa,MAAM;QAAK,QAAQ,gBAAgB,CAAC;CAM9G,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,151 @@
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
+ });
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@gw2me/client",
3
+ "version": "0.1.2",
4
+ "description": "gw2.me client library",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "npm run clean && if test $CI; then npm run build:ci; else npm run build:local; fi",
9
+ "build:local": "tsup src/index.ts && tsc --emitDeclarationOnly --declaration --declarationMap",
10
+ "build:ci": "tsup src/index.ts --minify --dts",
11
+ "clean": "rm -rf dist/",
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"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/GW2Treasures/gw2.me.git"
19
+ },
20
+ "keywords": [
21
+ "gw2me",
22
+ "gw2",
23
+ "guildwars2",
24
+ "auth",
25
+ "oauth2"
26
+ ],
27
+ "files": [
28
+ "dist/"
29
+ ],
30
+ "author": "darthmaim",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/gw2treasures/gw2.me/issues"
34
+ },
35
+ "homepage": "https://github.com/gw2treasures/gw2.me#readme",
36
+ "devDependencies": {
37
+ "@tsconfig/recommended": "1.0.3",
38
+ "@typescript-eslint/eslint-plugin": "6.7.4",
39
+ "@typescript-eslint/parser": "6.7.4",
40
+ "eslint": "8.50.0",
41
+ "tsup": "7.2.0",
42
+ "typescript": "5.2.2",
43
+ "undici-types": "5.25.3"
44
+ }
45
+ }