@togglhq/cli 1.6.10 → 1.6.11

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/build/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as CommanderError, t as createProgram } from "./program-Cl1_dH7S.js";
2
+ import { n as CommanderError, t as createProgram } from "./program-D4ljmpVV.js";
3
3
  //#region src/cli.ts
4
4
  try {
5
5
  await createProgram({ enableUpdateNotification: true }).parseAsync(process.argv);
package/build/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createProgram } from "./program-Cl1_dH7S.js";
1
+ import { t as createProgram } from "./program-D4ljmpVV.js";
2
2
  export { createProgram };
@@ -11730,6 +11730,10 @@ function openAuthBrowser(url) {
11730
11730
  });
11731
11731
  }
11732
11732
  const TOGGL_OAUTH_CLIENT_ID = "000000";
11733
+ /** Production accounts-be client for hosted `/focus/cli/auth-code` redirects. */
11734
+ const TOGGL_OAUTH_MANUAL_CLIENT_ID = "2ca88f39-18c5-4686-9101-3d3b7bd24470";
11735
+ /** Staging accounts-be client for hosted `/focus/cli/auth-code` redirects. */
11736
+ const TOGGL_OAUTH_MANUAL_STAGING_CLIENT_ID = "88972024-c0b3-46d1-8191-e48fb876434c";
11733
11737
  const TOGGL_OAUTH_CALLBACK_PORT = 8716;
11734
11738
  const TOGGL_OAUTH_LOGIN_TIMEOUT_MS = 12e4;
11735
11739
  const TOGGL_OAUTH_MANUAL_CALLBACK_PATH = "/focus/cli/auth-code";
@@ -11743,6 +11747,16 @@ function togglOAuthRedirectUri(port = TOGGL_OAUTH_CALLBACK_PORT) {
11743
11747
  function togglOAuthManualRedirectUri(accountsApiUrl) {
11744
11748
  return `${accountsApiUrl.replace(/\/$/, "")}${TOGGL_OAUTH_MANUAL_CALLBACK_PATH}`;
11745
11749
  }
11750
+ /**
11751
+ * Localhost CLI login keeps the test client (`000000`, domain `http://localhost`).
11752
+ * Manual/headless login uses dedicated first-party clients whose domain prefixes
11753
+ * match the hosted auth-code page. Do not send `000000` with a hosted redirect.
11754
+ */
11755
+ function resolveTogglOAuthClientId(flowMode, accountsApiUrl) {
11756
+ if (flowMode !== "manual") return TOGGL_OAUTH_CLIENT_ID;
11757
+ if (accountsApiUrl.replace(/\/$/, "") === "https://accounts.toggl.space") return TOGGL_OAUTH_MANUAL_STAGING_CLIENT_ID;
11758
+ return TOGGL_OAUTH_MANUAL_CLIENT_ID;
11759
+ }
11746
11760
  const BACKGROUND_DARK_SVG = `<svg width="1440" height="900" viewBox="0 0 1440 900" fill="none" xmlns="http://www.w3.org/2000/svg">
11747
11761
  <g clip-path="url(#clip0_11555_363)">
11748
11762
  <g clip-path="url(#clip1_11555_363)">
@@ -12091,12 +12105,12 @@ function waitForOAuthCallback(port = TOGGL_OAUTH_CALLBACK_PORT, timeoutMs = TOGG
12091
12105
  });
12092
12106
  });
12093
12107
  }
12094
- async function exchangeAuthorizationCode(accountsApiUrl, code, verifier, redirectUri = togglOAuthRedirectUri()) {
12108
+ async function exchangeAuthorizationCode(accountsApiUrl, code, verifier, redirectUri = togglOAuthRedirectUri(), clientId = TOGGL_OAUTH_CLIENT_ID) {
12095
12109
  const params = new URLSearchParams({
12096
12110
  grant_type: "authorization_code",
12097
12111
  code,
12098
12112
  code_verifier: verifier,
12099
- client_id: TOGGL_OAUTH_CLIENT_ID,
12113
+ client_id: clientId,
12100
12114
  redirect_uri: redirectUri
12101
12115
  });
12102
12116
  const response = await fetch(`${accountsApiUrl}/api/oauth/token?${params}`, { method: "POST" });
@@ -12133,7 +12147,7 @@ function resolveTogglOAuthFlowMode(options) {
12133
12147
  }
12134
12148
  function buildTogglOAuthAuthorizationUrl(options) {
12135
12149
  return `${options.accountsApiUrl.replace(/\/$/, "")}/focus/login/?${new URLSearchParams({
12136
- client_id: TOGGL_OAUTH_CLIENT_ID,
12150
+ client_id: resolveTogglOAuthClientId(options.flowMode, options.accountsApiUrl),
12137
12151
  code_challenge: options.codeChallenge,
12138
12152
  code_challenge_method: "S256",
12139
12153
  redirect_uri: options.redirectUri,
@@ -12149,6 +12163,7 @@ async function obtainTogglOAuthAuthorizationCode(options) {
12149
12163
  authorizationCode: options.authorizationCode
12150
12164
  });
12151
12165
  const redirectUri = resolveTogglOAuthRedirectUri(options.accountsApiUrl, flowMode);
12166
+ const clientId = resolveTogglOAuthClientId(flowMode, options.accountsApiUrl);
12152
12167
  const { verifier, challenge } = generateOAuthPKCE();
12153
12168
  const authUrl = buildTogglOAuthAuthorizationUrl({
12154
12169
  accountsApiUrl: options.accountsApiUrl,
@@ -12186,6 +12201,7 @@ async function obtainTogglOAuthAuthorizationCode(options) {
12186
12201
  code,
12187
12202
  verifier,
12188
12203
  redirectUri,
12204
+ clientId,
12189
12205
  flowMode
12190
12206
  };
12191
12207
  }
@@ -12251,7 +12267,7 @@ async function runCliAuthFlow(options = {}) {
12251
12267
  const focusApiUrl = options.focusApiUrl ?? "https://focus.toggl.com";
12252
12268
  const explicitProfileName = options.profileName;
12253
12269
  log("Toggl CLI — Authentication\n");
12254
- const { code, verifier, redirectUri } = await obtainTogglOAuthAuthorizationCode({
12270
+ const { code, verifier, redirectUri, clientId } = await obtainTogglOAuthAuthorizationCode({
12255
12271
  accountsApiUrl,
12256
12272
  flowMode: options.oauthFlowMode ?? (options.manualPrompt ? "manual" : "local"),
12257
12273
  authorizationCode: options.authorizationCode,
@@ -12259,7 +12275,7 @@ async function runCliAuthFlow(options = {}) {
12259
12275
  log
12260
12276
  });
12261
12277
  log("Exchanging authorization code...");
12262
- const tokens = await exchangeAuthorizationCode(accountsApiUrl, code, verifier, redirectUri);
12278
+ const tokens = await exchangeAuthorizationCode(accountsApiUrl, code, verifier, redirectUri, clientId);
12263
12279
  log("Fetching account info...");
12264
12280
  const user = await fetchAccountsApiMe(accountsApiUrl, tokens.access_token);
12265
12281
  if (!user.user_account_id) throw new Error("Could not determine user ID from API response.");
@@ -12281,6 +12297,7 @@ async function runCliAuthFlow(options = {}) {
12281
12297
  focus_api_url: focusApiUrl,
12282
12298
  accounts_api_url: accountsApiUrl,
12283
12299
  authenticated_at: (/* @__PURE__ */ new Date()).toISOString(),
12300
+ oauth_client_id: clientId,
12284
12301
  workspaces
12285
12302
  };
12286
12303
  const profileName = explicitProfileName ?? (options.deriveProfileName ?? deriveCliProfileName)({
@@ -12308,11 +12325,11 @@ const PUBLIC_CLI_PACKAGE_SPEC = `${PUBLIC_CLI_PACKAGE_NAME}@latest`;
12308
12325
  function npxMcpAuthCommand() {
12309
12326
  return `npx ${PUBLIC_MCP_PACKAGE_NAME} auth`;
12310
12327
  }
12311
- async function refreshTokens(accountsApiUrl, refreshToken) {
12328
+ async function refreshTokens(accountsApiUrl, refreshToken, clientId = TOGGL_OAUTH_CLIENT_ID) {
12312
12329
  const params = new URLSearchParams({
12313
12330
  grant_type: "refresh_token",
12314
12331
  refresh_token: refreshToken,
12315
- client_id: TOGGL_OAUTH_CLIENT_ID
12332
+ client_id: clientId
12316
12333
  });
12317
12334
  const response = await fetch(`${accountsApiUrl}/api/oauth/token?${params}`, { method: "POST" });
12318
12335
  if (!response.ok) {
@@ -12326,7 +12343,7 @@ async function getValidToken(scope = "cli", profile) {
12326
12343
  if (!authConfig) throw new Error(scope === "cli" ? "Not authenticated. Run `toggl auth` to sign in." : `Not authenticated. Run \`${npxMcpAuthCommand()}\` to sign in.`);
12327
12344
  const now = Date.now() / 1e3;
12328
12345
  if (authConfig.expires_at > now + 60) return authConfig.access_token;
12329
- const tokens = await refreshTokens(authConfig.accounts_api_url, authConfig.refresh_token);
12346
+ const tokens = await refreshTokens(authConfig.accounts_api_url, authConfig.refresh_token, authConfig.oauth_client_id ?? "000000");
12330
12347
  authConfig.access_token = tokens.access_token;
12331
12348
  authConfig.refresh_token = tokens.refresh_token;
12332
12349
  authConfig.expires_at = now + tokens.expires_in;
@@ -25080,4 +25097,4 @@ Common commands:
25080
25097
  //#endregion
25081
25098
  export { CommanderError as n, createProgram as t };
25082
25099
 
25083
- //# sourceMappingURL=program-Cl1_dH7S.js.map
25100
+ //# sourceMappingURL=program-D4ljmpVV.js.map
package/build/program.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createProgram } from "./program-Cl1_dH7S.js";
1
+ import { t as createProgram } from "./program-D4ljmpVV.js";
2
2
  export { createProgram };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@togglhq/cli",
3
- "version": "1.6.10",
3
+ "version": "1.6.11",
4
4
  "description": "Toggl CLI for Toggl 2.0 API operations.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",