@irfanshadikrishad/anilist 1.0.1 → 1.0.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/README.md CHANGED
@@ -39,25 +39,30 @@ here `<client-id>` and `<client-secret>` should be replaced by the ones that you
39
39
 
40
40
  #### CLI Commands Overview
41
41
 
42
- | **Command** | **Options** | **Description** |
43
- | ----------------------------------- | -------------------------------- | ------------------------------------------------ |
44
- | **`login`** | `-i, --id` `-s, --secret` | Log in with your AniList credentials |
45
- | **`logout`** | _None_ | Log out from your AniList account |
46
- | **`me`** | _None_ | Display information about the logged-in user |
47
- | **`-V, --version`** | _None_ | Display the current version of the CLI |
48
- | **`-h, --help`** | _None_ | Display available commands and options |
49
- | **`trending`** <br> _(alias: `tr`)_ | `-c (default: 10)` | Fetch trending anime (default count is 10) |
50
- | **`popular`** <br> _(alias: `plr`)_ | `-c (default: 10)` | Fetch popular anime (default count is 10) |
51
- | **`user`** | `-un (username)` | Get information about a specific AniList user |
52
- | **`lists`** <br> _(alias: `ls`)_ | `-a, --anime` <br> `-m, --manga` | Fetch anime or manga lists of the logged-in user |
53
- | **`delete`** <br> _(alias: `del`)_ | `-a, --anime` <br> `-m, --manga` | Delete collections of anime or manga |
54
- | **`upcoming`** <br> _(alias:`up`)_ | `-c (default: 10)` | Fetch upcoming anime (default count is 10) |
55
- | **`anime`** | `anime Id` | Get anime details by Anime Id |
42
+ | **Command** | **Options** | **Description** |
43
+ | ----------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------ |
44
+ | **`login`** | `-i, --id` `-s, --secret` | Log in with your AniList credentials |
45
+ | **`logout`** | _None_ | Log out from your AniList account |
46
+ | **`me`** | _None_ | Display information about the logged-in user |
47
+ | **`-V, --version`** | _None_ | Display the current version of the CLI |
48
+ | **`-h, --help`** | _None_ | Display available commands and options |
49
+ | **`trending`** <br> _(alias: `tr`)_ | `-c (default: 10)` | Fetch trending anime (default count is 10) |
50
+ | **`popular`** <br> _(alias: `plr`)_ | `-c (default: 10)` | Fetch popular anime (default count is 10) |
51
+ | **`user`** | `<username>` | Get information about a specific AniList user |
52
+ | **`lists`** <br> _(alias: `ls`)_ | `-a, --anime` <br> `-m, --manga` | Fetch anime or manga lists of the logged-in user |
53
+ | **`delete`** <br> _(alias: `del`)_ | `-a, --anime` <br> `-m, --manga` <br> `-ac, --activity` | Delete collections of anime, manga or activities |
54
+ | **`upcoming`** <br> _(alias:`up`)_ | `-c (default: 10)` | Fetch upcoming anime (default count is 10) |
55
+ | **`anime`** | `<anime-id>` | Get anime details by Anime Id |
56
+ | **`search`** <br> _(alias:`srch`/`find`)_ | `<query>` <br> `-a, --anime` <br> `-m, --manga` <br> `-c (default: 10)` | Get anime/manga search results |
56
57
 
57
58
  #### Command Breakdown:
58
59
 
59
60
  #### `login`:
60
61
 
62
+ ```bash
63
+ anilist login -i <client-id> -s <client-secret>
64
+ ```
65
+
61
66
  - **Options**:
62
67
  - `-i, --id`: Specify AniList Client ID
63
68
  - `-s, --secret`: Provide the AniList Client Secret
@@ -65,46 +70,82 @@ here `<client-id>` and `<client-secret>` should be replaced by the ones that you
65
70
 
66
71
  #### `logout`:
67
72
 
73
+ ```bash
74
+ anilist logout
75
+ ```
76
+
68
77
  - **Description**: End the current session and log out from your AniList account.
69
78
 
70
79
  #### `me`:
71
80
 
81
+ ```bash
82
+ anilist me
83
+ ```
84
+
72
85
  - **Description**: Retrieve and display information about the currently logged-in user, including stats and profile details.
73
86
 
74
87
  #### `-V, --version`:
75
88
 
89
+ ```bash
90
+ anilist -V
91
+ ```
92
+
76
93
  - **Description**: Quickly check which version of the CLI you are running.
77
94
 
78
95
  #### `-h, --help`:
79
96
 
97
+ ```bash
98
+ anilist -h
99
+ ```
100
+
80
101
  - **Description**: List all available commands and their usage details for quick reference.
81
102
 
82
103
  #### `trending` _(alias: `tr`)_:
83
104
 
105
+ ```bash
106
+ anilist tr -c 15
107
+ ```
108
+
84
109
  - **Options**:
85
110
  - `-c (count)`: Specify how many trending anime to fetch (default: 10).
86
111
  - **Description**: Fetch the current trending anime series, with the option to customize how many results to display.
87
112
 
88
113
  #### `popular` _(alias: `plr`)_:
89
114
 
115
+ ```bash
116
+ anilist popular
117
+ ```
118
+
90
119
  - **Options**:
91
120
  - `-c (count)`: Specify how many popular anime to fetch (default: 10).
92
121
  - **Description**: Fetch the most popular anime series, with the option to customize how many results to display.
93
122
 
94
123
  #### `upcoming` _(alias: `up`)_:
95
124
 
125
+ ```bash
126
+ anilist up -c 25
127
+ ```
128
+
96
129
  - **Options**:
97
130
  - `-c (count)`: Specify how many upcoming anime to fetch (default: 10).
98
131
  - **Description**: Fetch the upcoming anime series next season, with the option to customize how many results to display.
99
132
 
100
133
  #### `user`:
101
134
 
135
+ ```bash
136
+ anilist user <username>
137
+ ```
138
+
102
139
  - **Options**:
103
- - `-un (username)`: Specify the AniList username to fetch.
140
+ - `<username>`: Specify the AniList username to fetch.
104
141
  - **Description**: Retrieve profile information about a specific AniList user.
105
142
 
106
143
  #### `lists` _(alias: `ls`)_:
107
144
 
145
+ ```bash
146
+ anilist ls -a
147
+ ```
148
+
108
149
  - **Options**:
109
150
  - `-a, --anime`: Fetch the authenticated user's anime list.
110
151
  - `-m, --manga`: Fetch the authenticated user's manga list.
@@ -112,17 +153,39 @@ here `<client-id>` and `<client-secret>` should be replaced by the ones that you
112
153
 
113
154
  #### `delete` _(alias: `del`)_:
114
155
 
156
+ ```bash
157
+ anilist del -ac
158
+ ```
159
+
115
160
  - **Options**:
116
161
  - `-a, --anime`: Delete your specific anime collection that you want.
117
162
  - `-m, --manga`: Delete your specific manga collection that you want.
163
+ - `-ac, --activity`: Delete all or any type of activities you want.
118
164
  - **Description**: Delete the entire anime or manga collection from the logged-in user's profile.
119
165
 
120
166
  #### `anime`
121
167
 
168
+ ```bash
169
+ anilist anime <anime-id>
170
+ ```
171
+
122
172
  - **Options**
123
- - `anime Id` _(eg: 21)_ : Id of the anime you want to get details of.
173
+ - `<anime-id>` _(eg: 21)_ : Id of the anime you want to get details of.
124
174
  - **Description**: Get anime details by anime Id.
125
175
 
176
+ #### `search` _(alias: `srch`/`find`)_:
177
+
178
+ ```bash
179
+ anilist search <query> -a -c 20
180
+ ```
181
+
182
+ - **Options**:
183
+ - `<query>` : What you want to search (eg: naruto).
184
+ - `-a, --anime`: To get results of anime search.
185
+ - `-m, --manga`: To get results of manga search.
186
+ - `-c (count)`: Specify how many items to fetch (default: 10).
187
+ - **Description**: Get anime/manga search results
188
+
126
189
  #### Security
127
190
 
128
191
  Since you are creating your own API client for login no else else can get your credentials and the generated access token will be stored in your own system. So, As long as you don't share your device (in case you do, just logout) you are safe.
@@ -1,9 +1,10 @@
1
1
  declare function getAccessTokenFromUser(): Promise<any>;
2
2
  declare function storeAccessToken(token: string): Promise<void>;
3
3
  declare function retriveAccessToken(): Promise<string>;
4
- declare function anilistUserLogin(cID: number, cSECRET: string): Promise<void>;
5
- declare function currentUserInfo(): Promise<void>;
4
+ declare function anilistUserLogin(clientId: number, clientSecret: string): Promise<void>;
5
+ declare function currentUserInfo(): Promise<any>;
6
6
  declare function isLoggedIn(): Promise<Boolean>;
7
7
  declare function logoutUser(): Promise<void>;
8
8
  declare function currentUsersId(): Promise<any>;
9
- export { getAccessTokenFromUser, storeAccessToken, retriveAccessToken, anilistUserLogin, currentUserInfo, isLoggedIn, logoutUser, currentUsersId, };
9
+ declare function currentUsersName(): Promise<any>;
10
+ export { getAccessTokenFromUser, storeAccessToken, retriveAccessToken, anilistUserLogin, currentUserInfo, isLoggedIn, logoutUser, currentUsersId, currentUsersName, };
@@ -20,19 +20,24 @@ const home_dir = os.homedir();
20
20
  const save_path = path.join(home_dir, ".anilist_token");
21
21
  function getAccessTokenFromUser() {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
- const answers = yield inquirer.prompt([
23
+ const { token } = yield inquirer.prompt([
24
24
  {
25
25
  type: "password",
26
26
  name: "token",
27
27
  message: "Please enter your AniList access token:",
28
28
  },
29
29
  ]);
30
- return answers.token;
30
+ return token;
31
31
  });
32
32
  }
33
33
  function storeAccessToken(token) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
- fs.writeFileSync(save_path, token, { encoding: "utf8" });
35
+ try {
36
+ fs.writeFileSync(save_path, token, { encoding: "utf8" });
37
+ }
38
+ catch (error) {
39
+ console.error(`Error storing acess-token.`);
40
+ }
36
41
  });
37
42
  }
38
43
  function retriveAccessToken() {
@@ -45,10 +50,10 @@ function retriveAccessToken() {
45
50
  }
46
51
  });
47
52
  }
48
- function anilistUserLogin(cID, cSECRET) {
53
+ function anilistUserLogin(clientId, clientSecret) {
49
54
  return __awaiter(this, void 0, void 0, function* () {
50
55
  console.log("Starting AniList login...");
51
- const authUrl = `https://anilist.co/api/v2/oauth/authorize?client_id=${cID}&redirect_uri=${redirectUri}&response_type=code`;
56
+ const authUrl = `https://anilist.co/api/v2/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code`;
52
57
  console.log("Opening browser for AniList login...");
53
58
  open(authUrl);
54
59
  const authCode = yield getAccessTokenFromUser();
@@ -59,16 +64,22 @@ function anilistUserLogin(cID, cSECRET) {
59
64
  },
60
65
  body: JSON.stringify({
61
66
  grant_type: "authorization_code",
62
- client_id: String(cID),
63
- client_secret: cSECRET,
67
+ client_id: String(clientId),
68
+ client_secret: clientSecret,
64
69
  redirect_uri: redirectUri,
65
70
  code: authCode,
66
71
  }),
67
72
  });
68
73
  const token_Data = yield tokenResponse.json();
69
74
  if (token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token) {
70
- console.log("Login successful!");
71
75
  yield storeAccessToken(token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token);
76
+ const name = yield currentUsersName();
77
+ if (name) {
78
+ console.log(`\nWelcome Back, ${name}!`);
79
+ }
80
+ else {
81
+ console.log(`Logged in successfull!`);
82
+ }
72
83
  }
73
84
  else {
74
85
  console.error("Failed to get access token:", token_Data);
@@ -97,7 +108,7 @@ function currentUserInfo() {
97
108
  id: user === null || user === void 0 ? void 0 : user.id,
98
109
  page: 1,
99
110
  perPage: 10,
100
- }, headers);
111
+ });
101
112
  const activities = (_b = (_a = activiResponse === null || activiResponse === void 0 ? void 0 : activiResponse.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities;
102
113
  console.log(`\nID:\t\t\t${user === null || user === void 0 ? void 0 : user.id}`);
103
114
  console.log(`Name:\t\t\t${user === null || user === void 0 ? void 0 : user.name}`);
@@ -119,13 +130,16 @@ function currentUserInfo() {
119
130
  ? console.log(`${status} ${progress} of ${getTitle(media === null || media === void 0 ? void 0 : media.title)}`)
120
131
  : console.log(`${status} ${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
121
132
  });
133
+ return user;
122
134
  }
123
135
  else {
124
136
  console.log(`Something went wrong. Please log in again. ${errors[0].message}`);
137
+ return null;
125
138
  }
126
139
  }
127
140
  else {
128
141
  console.log(`User not logged in. Please login first.`);
142
+ return null;
129
143
  }
130
144
  });
131
145
  }
@@ -145,7 +159,7 @@ function logoutUser() {
145
159
  if (fs.existsSync(save_path)) {
146
160
  try {
147
161
  fs.unlinkSync(save_path);
148
- console.log("Logout successful.");
162
+ console.log("\nLogout successful.");
149
163
  }
150
164
  catch (error) {
151
165
  console.error("Error logging out:", error);
@@ -176,4 +190,24 @@ function currentUsersId() {
176
190
  }
177
191
  });
178
192
  }
179
- export { getAccessTokenFromUser, storeAccessToken, retriveAccessToken, anilistUserLogin, currentUserInfo, isLoggedIn, logoutUser, currentUsersId, };
193
+ function currentUsersName() {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ var _a;
196
+ const request = yield fetch(aniListEndpoint, {
197
+ method: "POST",
198
+ headers: {
199
+ "Content-Type": "application/json",
200
+ Authorization: `Bearer ${yield retriveAccessToken()}`,
201
+ },
202
+ body: JSON.stringify({ query: currentUserQuery }),
203
+ });
204
+ const { data } = yield request.json();
205
+ if (request.status === 200) {
206
+ return (_a = data === null || data === void 0 ? void 0 : data.Viewer) === null || _a === void 0 ? void 0 : _a.name;
207
+ }
208
+ else {
209
+ return null;
210
+ }
211
+ });
212
+ }
213
+ export { getAccessTokenFromUser, storeAccessToken, retriveAccessToken, anilistUserLogin, currentUserInfo, isLoggedIn, logoutUser, currentUsersId, currentUsersName, };
@@ -1,2 +1,12 @@
1
- declare function fetcher(query: string, variables: object, headers: HeadersInit): Promise<any>;
1
+ /**
2
+ * Sends a GraphQL request to the AniList API.
3
+ *
4
+ * This function constructs a request with the provided query and variables,
5
+ * handles authorization, and processes the API response.
6
+ *
7
+ * @param {string} query - The AniList GraphQL query to be executed.
8
+ * @param {object} variables - An object containing the variables for the query.
9
+ * @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
10
+ */
11
+ declare function fetcher(query: string, variables: object): Promise<object | null>;
2
12
  export { fetcher };
@@ -9,10 +9,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import fetch from "node-fetch";
11
11
  import { aniListEndpoint } from "./workers.js";
12
- function fetcher(query, variables, headers) {
12
+ import { isLoggedIn, retriveAccessToken } from "./auth.js";
13
+ /**
14
+ * Sends a GraphQL request to the AniList API.
15
+ *
16
+ * This function constructs a request with the provided query and variables,
17
+ * handles authorization, and processes the API response.
18
+ *
19
+ * @param {string} query - The AniList GraphQL query to be executed.
20
+ * @param {object} variables - An object containing the variables for the query.
21
+ * @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
22
+ */
23
+ function fetcher(query, variables) {
13
24
  return __awaiter(this, void 0, void 0, function* () {
14
25
  var _a;
15
26
  try {
27
+ const LOGGEDIN = yield isLoggedIn();
28
+ const headers = {
29
+ "content-type": "application/json",
30
+ };
31
+ if (LOGGEDIN) {
32
+ headers["Authorization"] = `Bearer ${yield retriveAccessToken()}`;
33
+ }
16
34
  const request = yield fetch(aniListEndpoint, {
17
35
  method: "POST",
18
36
  headers: headers,