charis-cli 1.0.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.
Files changed (2) hide show
  1. package/login.js +37 -0
  2. package/package.json +19 -0
package/login.js ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ import open from "open";
3
+ import readline from "readline";
4
+
5
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
6
+ const question = (q) => new Promise(resolve => rl.question(q, resolve));
7
+
8
+ (async () => {
9
+ const userId = await question("Enter your Spotify userId: ");
10
+ const clientId = await question("Enter your Spotify clientId: ");
11
+ const clientSecret = await question("Enter your Spotify clientSecret: ");
12
+ rl.close();
13
+
14
+ // Redirect ke API Vercel
15
+ const redirectUri = "https://api.charisprod.xyz/v1/spotify/callback";
16
+
17
+ const state = Buffer.from(JSON.stringify({ userId, clientId, clientSecret })).toString("base64url");
18
+
19
+ const scope = [
20
+ "user-read-currently-playing",
21
+ "user-read-recently-played",
22
+ "user-top-read",
23
+ "user-read-private"
24
+ ].join(" ");
25
+
26
+ const authUrl = new URL("https://accounts.spotify.com/authorize");
27
+ authUrl.searchParams.set("response_type", "code");
28
+ authUrl.searchParams.set("client_id", clientId);
29
+ authUrl.searchParams.set("scope", scope);
30
+ authUrl.searchParams.set("redirect_uri", redirectUri);
31
+ authUrl.searchParams.set("state", state);
32
+ authUrl.searchParams.set("show_dialog", "true");
33
+
34
+ console.log("Opening Spotify login in your browser...");
35
+ await open(authUrl.toString());
36
+ console.log("After login, your tokens will be stored on the server. You can continue using the CLI after that.");
37
+ })();
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "charis-cli",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "bin": {
10
+ "charis": "./login.js"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "description": "",
16
+ "dependencies": {
17
+ "open": "^11.0.0"
18
+ }
19
+ }