@ncukondo/gcal-cli 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/dist/index.js +19 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -587718,7 +587718,7 @@ function errorCodeToExitCode(code) {
587718
587718
  // package.json
587719
587719
  var package_default = {
587720
587720
  name: "@ncukondo/gcal-cli",
587721
- version: "0.2.0",
587721
+ version: "0.2.2",
587722
587722
  type: "module",
587723
587723
  exports: {
587724
587724
  ".": "./dist/index.js"
@@ -587989,7 +587989,8 @@ async function getAuthenticatedClient(fs, fetchFn = globalThis.fetch) {
587989
587989
  }
587990
587990
  var OAUTH_SCOPES = [
587991
587991
  "https://www.googleapis.com/auth/calendar.readonly",
587992
- "https://www.googleapis.com/auth/calendar.events"
587992
+ "https://www.googleapis.com/auth/calendar.events",
587993
+ "email"
587993
587994
  ];
587994
587995
  async function startOAuthFlow(credentials, fs, fetchFn = globalThis.fetch) {
587995
587996
  return new Promise((resolve) => {
@@ -588135,17 +588136,30 @@ async function handleAuthStatus(opts) {
588135
588136
  }
588136
588137
  return { exitCode: ExitCode.AUTH };
588137
588138
  }
588138
- const email2 = await fetchUserEmail(tokens.access_token, fetchFn);
588139
- const expiresAt = new Date(tokens.expiry_date);
588139
+ let currentTokens = tokens;
588140
+ if (isTokenExpired(tokens.expiry_date)) {
588141
+ try {
588142
+ const credentials = getClientCredentials(fs);
588143
+ currentTokens = await refreshAccessToken(credentials, tokens, fetchFn);
588144
+ saveTokens(fs, currentTokens);
588145
+ } catch {}
588146
+ }
588147
+ const email2 = await fetchUserEmail(currentTokens.access_token, fetchFn);
588148
+ const expiresAt = new Date(currentTokens.expiry_date);
588149
+ const reAuthHint = "Run `gcal auth --logout` then `gcal auth` to re-authenticate with updated permissions.";
588140
588150
  if (format === "json") {
588141
588151
  write(formatJsonSuccess({
588142
588152
  authenticated: true,
588143
588153
  email: email2,
588144
- expires_at: expiresAt.toISOString()
588154
+ expires_at: expiresAt.toISOString(),
588155
+ ...email2 == null ? { hint: reAuthHint } : {}
588145
588156
  }));
588146
588157
  } else {
588147
588158
  write(`Authenticated as: ${email2 ?? "unknown"}`);
588148
588159
  write(`Token expires: ${expiresAt.toISOString()}`);
588160
+ if (email2 == null) {
588161
+ write(reAuthHint);
588162
+ }
588149
588163
  }
588150
588164
  return { exitCode: ExitCode.SUCCESS };
588151
588165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ncukondo/gcal-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"