ticktick-cli 1.0.2 → 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 +4 -0
- package/dist/auth.js +1 -1
- package/dist/cli.js +27 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -100,6 +100,8 @@ Interactive login:
|
|
|
100
100
|
ticktick auth login
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
+
Successful auth stores the token in your local config file and masks secrets in the terminal output by default.
|
|
104
|
+
|
|
103
105
|
If you already have an authorization code:
|
|
104
106
|
|
|
105
107
|
```bash
|
|
@@ -118,6 +120,8 @@ Check current auth state:
|
|
|
118
120
|
ticktick auth status
|
|
119
121
|
```
|
|
120
122
|
|
|
123
|
+
If you need the raw token values in the terminal, add `--show-secrets` to `auth login`, `auth exchange`, or `auth status`.
|
|
124
|
+
|
|
121
125
|
Clear the stored access token:
|
|
122
126
|
|
|
123
127
|
```bash
|
package/dist/auth.js
CHANGED
|
@@ -118,7 +118,7 @@ export async function openBrowserWith(url, options = {}) {
|
|
|
118
118
|
const stderr = options.stderr ?? ((text) => process.stderr.write(text));
|
|
119
119
|
try {
|
|
120
120
|
if (platform === "win32") {
|
|
121
|
-
await run("
|
|
121
|
+
await run("rundll32", ["url.dll,FileProtocolHandler", url]);
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
if (platform === "darwin") {
|
package/dist/cli.js
CHANGED
|
@@ -83,6 +83,7 @@ function buildAuthCommands(root, dependencies) {
|
|
|
83
83
|
.command("login")
|
|
84
84
|
.description("Open the OAuth flow, exchange the code, and store the access token")
|
|
85
85
|
.option("--timeout-ms <number>", "Timeout while waiting for the callback", parseInteger, 120000)
|
|
86
|
+
.option("--show-secrets", "Include access token and refresh token in the output")
|
|
86
87
|
.action(async (...args) => {
|
|
87
88
|
const command = args.at(-1);
|
|
88
89
|
const options = command.optsWithGlobals();
|
|
@@ -97,24 +98,27 @@ function buildAuthCommands(root, dependencies) {
|
|
|
97
98
|
});
|
|
98
99
|
return;
|
|
99
100
|
}
|
|
101
|
+
dependencies.stderr(`Waiting for OAuth callback on ${config.redirectUri}...\n`);
|
|
100
102
|
const codePromise = dependencies.waitForOAuthCode(config.redirectUri, state, options.timeoutMs);
|
|
101
103
|
await dependencies.openBrowser(url);
|
|
102
104
|
const code = await codePromise;
|
|
103
105
|
const token = await dependencies.exchangeAuthorizationCode(config, code);
|
|
104
106
|
await persistConfig(config, token, dependencies);
|
|
105
|
-
dependencies.printJson(token);
|
|
107
|
+
dependencies.printJson(formatAuthSuccess(config, token, options.showSecrets, dependencies));
|
|
106
108
|
});
|
|
107
109
|
auth
|
|
108
110
|
.command("exchange <code>")
|
|
109
111
|
.description("Exchange an authorization code for an access token")
|
|
112
|
+
.option("--show-secrets", "Include access token and refresh token in the output")
|
|
110
113
|
.action(async (...args) => {
|
|
111
114
|
const command = args.at(-1);
|
|
112
115
|
const [code] = args;
|
|
113
|
-
const
|
|
116
|
+
const options = command.optsWithGlobals();
|
|
117
|
+
const config = await dependencies.resolveRuntimeConfig(runtimeOverrides(options, dependencies));
|
|
114
118
|
requireClientCredentials(config);
|
|
115
119
|
const token = await dependencies.exchangeAuthorizationCode(config, code);
|
|
116
120
|
await persistConfig(config, token, dependencies);
|
|
117
|
-
dependencies.printJson(token);
|
|
121
|
+
dependencies.printJson(formatAuthSuccess(config, token, options.showSecrets, dependencies));
|
|
118
122
|
});
|
|
119
123
|
auth
|
|
120
124
|
.command("status")
|
|
@@ -509,6 +513,26 @@ async function persistConfig(runtime, token, dependencies) {
|
|
|
509
513
|
};
|
|
510
514
|
await dependencies.saveStoredConfig(runtime.configFile, next);
|
|
511
515
|
}
|
|
516
|
+
function formatAuthSuccess(runtime, token, showSecrets, dependencies) {
|
|
517
|
+
return {
|
|
518
|
+
ok: true,
|
|
519
|
+
message: "Authorization complete.",
|
|
520
|
+
service: runtime.service,
|
|
521
|
+
configFile: runtime.configFile,
|
|
522
|
+
redirectUri: runtime.redirectUri,
|
|
523
|
+
scope: token.scope ?? runtime.scopes,
|
|
524
|
+
tokenType: token.token_type,
|
|
525
|
+
expiresIn: token.expires_in,
|
|
526
|
+
accessToken: showSecrets
|
|
527
|
+
? token.access_token
|
|
528
|
+
: dependencies.maskSecret(token.access_token),
|
|
529
|
+
refreshToken: token.refresh_token
|
|
530
|
+
? showSecrets
|
|
531
|
+
? token.refresh_token
|
|
532
|
+
: dependencies.maskSecret(token.refresh_token)
|
|
533
|
+
: undefined,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
512
536
|
function requireClientCredentials(config) {
|
|
513
537
|
if (!config.clientId || !config.clientSecret) {
|
|
514
538
|
throw new Error("Client credentials are required. Set TICKTICK_CLIENT_ID and TICKTICK_CLIENT_SECRET or use `ticktick config set`.");
|