@posthog/wizard 1.35.2 → 1.36.1

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 (64) hide show
  1. package/README.md +1 -3
  2. package/dist/bin.js +1 -12
  3. package/dist/bin.js.map +1 -1
  4. package/dist/src/__tests__/cli.test.js +5 -58
  5. package/dist/src/__tests__/cli.test.js.map +1 -1
  6. package/dist/src/lib/agent-interface.js +8 -0
  7. package/dist/src/lib/agent-interface.js.map +1 -1
  8. package/dist/src/lib/agent-runner.js +2 -13
  9. package/dist/src/lib/agent-runner.js.map +1 -1
  10. package/dist/src/lib/commandments.d.ts +1 -0
  11. package/dist/src/lib/commandments.js +23 -0
  12. package/dist/src/lib/commandments.js.map +1 -0
  13. package/dist/src/lib/constants.d.ts +3 -1
  14. package/dist/src/lib/constants.js +5 -1
  15. package/dist/src/lib/constants.js.map +1 -1
  16. package/dist/src/lib/version.d.ts +1 -1
  17. package/dist/src/lib/version.js +1 -1
  18. package/dist/src/lib/version.js.map +1 -1
  19. package/dist/src/mcp.d.ts +0 -2
  20. package/dist/src/mcp.js +0 -1
  21. package/dist/src/mcp.js.map +1 -1
  22. package/dist/src/run.d.ts +0 -2
  23. package/dist/src/run.js +0 -1
  24. package/dist/src/run.js.map +1 -1
  25. package/dist/src/steps/add-mcp-server-to-clients/MCPClient.d.ts +4 -5
  26. package/dist/src/steps/add-mcp-server-to-clients/MCPClient.js +6 -6
  27. package/dist/src/steps/add-mcp-server-to-clients/MCPClient.js.map +1 -1
  28. package/dist/src/steps/add-mcp-server-to-clients/__tests__/defaults.test.js +1 -21
  29. package/dist/src/steps/add-mcp-server-to-clients/__tests__/defaults.test.js.map +1 -1
  30. package/dist/src/steps/add-mcp-server-to-clients/clients/__tests__/claude.test.js +2 -7
  31. package/dist/src/steps/add-mcp-server-to-clients/clients/__tests__/claude.test.js.map +1 -1
  32. package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.d.ts +1 -2
  33. package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.js +2 -2
  34. package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.js.map +1 -1
  35. package/dist/src/steps/add-mcp-server-to-clients/clients/codex.d.ts +1 -2
  36. package/dist/src/steps/add-mcp-server-to-clients/clients/codex.js +2 -2
  37. package/dist/src/steps/add-mcp-server-to-clients/clients/codex.js.map +1 -1
  38. package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.d.ts +2 -3
  39. package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.js +4 -4
  40. package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.js.map +1 -1
  41. package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.d.ts +2 -3
  42. package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.js +4 -4
  43. package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.js.map +1 -1
  44. package/dist/src/steps/add-mcp-server-to-clients/clients/zed.d.ts +2 -3
  45. package/dist/src/steps/add-mcp-server-to-clients/clients/zed.js +4 -4
  46. package/dist/src/steps/add-mcp-server-to-clients/clients/zed.js.map +1 -1
  47. package/dist/src/steps/add-mcp-server-to-clients/defaults.d.ts +3 -4
  48. package/dist/src/steps/add-mcp-server-to-clients/defaults.js +6 -13
  49. package/dist/src/steps/add-mcp-server-to-clients/defaults.js.map +1 -1
  50. package/dist/src/steps/add-mcp-server-to-clients/index.d.ts +2 -4
  51. package/dist/src/steps/add-mcp-server-to-clients/index.js +4 -5
  52. package/dist/src/steps/add-mcp-server-to-clients/index.js.map +1 -1
  53. package/dist/src/utils/clack-utils.d.ts +2 -4
  54. package/dist/src/utils/clack-utils.js +18 -41
  55. package/dist/src/utils/clack-utils.js.map +1 -1
  56. package/dist/src/utils/oauth.d.ts +0 -2
  57. package/dist/src/utils/oauth.js +9 -11
  58. package/dist/src/utils/oauth.js.map +1 -1
  59. package/dist/src/utils/types.d.ts +0 -4
  60. package/dist/src/utils/types.js.map +1 -1
  61. package/dist/src/utils/urls.d.ts +1 -1
  62. package/dist/src/utils/urls.js +22 -9
  63. package/dist/src/utils/urls.js.map +1 -1
  64. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../../src/utils/oauth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqMA,4CAyGC;AA9SD,oDAAsC;AACtC,gDAAkC;AAClC,kDAA0B;AAC1B,kDAA0B;AAC1B,8CAAsB;AACtB,6BAAwB;AACxB,oDAA4B;AAC5B,gDAA6E;AAC7E,+CAAsC;AACtC,2CAAwC;AAExC,iCAA2E;AAE3E,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;CAqB7B,CAAC;AAEF,MAAM,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE;IACxB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;IACtB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;IACtB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;IACjB,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE;IACzB,YAAY,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC5C,oBAAoB,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CACrD,CAAC,CAAC;AAUH,SAAS,oBAAoB;IAC3B,OAAO,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB;IAC7C,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC1E,CAAC;AAED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,GAAG,CAAC,uBAAuB,CAAC,OACnC,KAAK,CAAC,OACR,OAAO,eAAK,CAAC,GAAG,CACd,8EAA8E,sBAAU,EAAE,CAC3F,EAAE,CACJ,CAAC;QACJ,CAAC;QAED,qBAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE;YAChC,IAAI,EAAE,YAAY;YAClB,YAAY,EAAE,MAAM,CAAC,WAAW;SACjC,CAAC,CAAC;QAEH,MAAM,IAAA,mBAAK,GAAE,CAAC;QACd,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import * as crypto from 'node:crypto';\nimport * as http from 'node:http';\nimport axios from 'axios';\nimport chalk from 'chalk';\nimport opn from 'opn';\nimport { z } from 'zod';\nimport clack from './clack';\nimport { ISSUES_URL, OAUTH_PORT, WIZARD_USER_AGENT } from '../lib/constants';\nimport { abort } from './clack-utils';\nimport { analytics } from './analytics';\nimport type { CloudRegion } from './types';\nimport { getCloudUrlFromRegion, getOauthClientIdFromRegion } from './urls';\n\nconst OAUTH_CALLBACK_STYLES = `\n <style>\n * {\n font-family: monospace;\n background-color: #1b0a00;\n color: #F7A502;\n font-weight: medium;\n font-size: 24px;\n margin: .25rem;\n }\n\n .blink {\n animation: blink-animation 1s steps(2, start) infinite;\n }\n\n @keyframes blink-animation {\n to {\n opacity: 0;\n }\n }\n </style>\n`;\n\nconst OAuthTokenResponseSchema = z.object({\n access_token: z.string(),\n expires_in: z.number(),\n token_type: z.string(),\n scope: z.string(),\n refresh_token: z.string(),\n scoped_teams: z.array(z.number()).optional(),\n scoped_organizations: z.array(z.string()).optional(),\n});\n\nexport type OAuthTokenResponse = z.infer<typeof OAuthTokenResponseSchema>;\n\ninterface OAuthConfig {\n scopes: string[];\n cloudRegion: CloudRegion;\n signup?: boolean;\n}\n\nfunction generateCodeVerifier(): string {\n return crypto.randomBytes(32).toString('base64url');\n}\n\nfunction generateCodeChallenge(verifier: string): string {\n return crypto.createHash('sha256').update(verifier).digest('base64url');\n}\n\nasync function startCallbackServer(\n authUrl: string,\n signupUrl: string,\n): Promise<{\n server: http.Server;\n waitForCallback: () => Promise<string>;\n}> {\n return new Promise((resolve, reject) => {\n let callbackResolve: (code: string) => void;\n let callbackReject: (error: Error) => void;\n\n const waitForCallback = () =>\n new Promise<string>((res, rej) => {\n callbackResolve = res;\n callbackReject = rej;\n });\n\n const server = http.createServer((req, res) => {\n if (!req.url) {\n res.writeHead(400);\n res.end();\n return;\n }\n const url = new URL(req.url, `http://localhost:${OAUTH_PORT}`);\n\n if (url.pathname === '/authorize') {\n const isSignup = url.searchParams.get('signup') === 'true';\n const redirectUrl = isSignup ? signupUrl : authUrl;\n res.writeHead(302, { Location: redirectUrl });\n res.end();\n return;\n }\n\n const code = url.searchParams.get('code');\n const error = url.searchParams.get('error');\n\n if (error) {\n const isAccessDenied = error === 'access_denied';\n res.writeHead(isAccessDenied ? 200 : 400, {\n 'Content-Type': 'text/html; charset=utf-8',\n });\n res.end(`\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <title>PostHog wizard - Authorization ${\n isAccessDenied ? 'cancelled' : 'failed'\n }</title>\n ${OAUTH_CALLBACK_STYLES}\n </head>\n <body>\n <p>${\n isAccessDenied\n ? 'Authorization cancelled.'\n : `Authorization failed.`\n }</p>\n <p>Return to your terminal. This window will close automatically.</p>\n <script>window.close();</script>\n </body>\n </html>\n `);\n callbackReject(new Error(`OAuth error: ${error}`));\n return;\n }\n\n if (code) {\n res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });\n res.end(`\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <title>PostHog wizard is ready</title>\n ${OAUTH_CALLBACK_STYLES}\n </head>\n <body>\n <p>PostHog login complete!</p>\n <p>Return to your terminal: the wizard is hard at work on your project<span class=\"blink\">█</span></p>\n <script>window.close();</script>\n </body>\n </html>\n `);\n callbackResolve(code);\n } else {\n res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' });\n res.end(`\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <title>PostHog wizard - Invalid request</title>\n ${OAUTH_CALLBACK_STYLES}\n </head>\n <body>\n <p>Invalid request - no authorization code received.</p>\n <p>You can close this window.</p>\n </body>\n </html>\n `);\n }\n });\n\n server.listen(OAUTH_PORT, () => {\n resolve({ server, waitForCallback });\n });\n\n server.on('error', reject);\n });\n}\n\nasync function exchangeCodeForToken(\n code: string,\n codeVerifier: string,\n config: OAuthConfig,\n): Promise<OAuthTokenResponse> {\n const cloudUrl = getCloudUrlFromRegion(config.cloudRegion);\n\n const response = await axios.post(\n `${cloudUrl}/oauth/token`,\n {\n grant_type: 'authorization_code',\n code,\n redirect_uri: `http://localhost:${OAUTH_PORT}/callback`,\n client_id: getOauthClientIdFromRegion(config.cloudRegion),\n code_verifier: codeVerifier,\n },\n {\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': WIZARD_USER_AGENT,\n },\n },\n );\n\n return OAuthTokenResponseSchema.parse(response.data);\n}\n\nexport async function performOAuthFlow(\n config: OAuthConfig,\n): Promise<OAuthTokenResponse> {\n const cloudUrl = getCloudUrlFromRegion(config.cloudRegion);\n const codeVerifier = generateCodeVerifier();\n const codeChallenge = generateCodeChallenge(codeVerifier);\n\n const authUrl = new URL(`${cloudUrl}/oauth/authorize`);\n authUrl.searchParams.set(\n 'client_id',\n getOauthClientIdFromRegion(config.cloudRegion),\n );\n authUrl.searchParams.set(\n 'redirect_uri',\n `http://localhost:${OAUTH_PORT}/callback`,\n );\n authUrl.searchParams.set('response_type', 'code');\n authUrl.searchParams.set('code_challenge', codeChallenge);\n authUrl.searchParams.set('code_challenge_method', 'S256');\n authUrl.searchParams.set('scope', config.scopes.join(' '));\n authUrl.searchParams.set('required_access_level', 'project');\n\n const signupUrl = new URL(\n `${cloudUrl}/signup?next=${encodeURIComponent(authUrl.toString())}`,\n );\n\n const localSignupUrl = `http://localhost:${OAUTH_PORT}/authorize?signup=true`;\n const localLoginUrl = `http://localhost:${OAUTH_PORT}/authorize`;\n\n const urlToOpen = config.signup ? localSignupUrl : localLoginUrl;\n\n const { server, waitForCallback } = await startCallbackServer(\n authUrl.toString(),\n signupUrl.toString(),\n );\n\n clack.log.info(\n `${chalk.bold(\n \"If the browser window didn't open automatically, please open the following link to be redirected to PostHog:\",\n )}\\n\\n${chalk.cyan(urlToOpen)}${\n config.signup\n ? `\\n\\nIf you already have an account, you can use this link:\\n\\n${chalk.cyan(\n localLoginUrl,\n )}`\n : ``\n }`,\n );\n\n if (process.env.NODE_ENV !== 'test') {\n opn(urlToOpen, { wait: false }).catch(() => {\n // opn throws in environments without a browser\n });\n }\n\n const loginSpinner = clack.spinner();\n loginSpinner.start('Waiting for authorization...');\n\n try {\n const code = await Promise.race([\n waitForCallback(),\n new Promise<never>((_, reject) =>\n setTimeout(() => reject(new Error('Authorization timed out')), 60_000),\n ),\n ]);\n\n const token = await exchangeCodeForToken(code, codeVerifier, config);\n\n server.close();\n loginSpinner.stop('Authorization complete!');\n\n return token;\n } catch (e) {\n loginSpinner.stop('Authorization failed.');\n server.close();\n\n const error = e instanceof Error ? e : new Error('Unknown error');\n\n if (error.message.includes('timeout')) {\n clack.log.error('Authorization timed out. Please try again.');\n } else if (error.message.includes('access_denied')) {\n clack.log.info(\n `${chalk.yellow(\n 'Authorization was cancelled.',\n )}\\n\\nYou denied access to PostHog. To use the wizard, you need to authorize access to your PostHog account.\\n\\n${chalk.dim(\n 'You can try again by re-running the wizard.',\n )}`,\n );\n } else {\n clack.log.error(\n `${chalk.red('Authorization failed:')}\\n\\n${\n error.message\n }\\n\\n${chalk.dim(\n `If you think this is a bug in the PostHog wizard, please create an issue:\\n${ISSUES_URL}`,\n )}`,\n );\n }\n\n analytics.captureException(error, {\n step: 'oauth_flow',\n cloud_region: config.cloudRegion,\n });\n\n await abort();\n throw error;\n }\n}\n"]}
1
+ {"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../../src/utils/oauth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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esContent":["import * as crypto from 'node:crypto';\nimport * as http from 'node:http';\nimport axios from 'axios';\nimport chalk from 'chalk';\nimport opn from 'opn';\nimport { z } from 'zod';\nimport clack from './clack';\nimport {\n IS_DEV,\n ISSUES_URL,\n OAUTH_PORT,\n POSTHOG_DEV_CLIENT_ID,\n POSTHOG_OAUTH_URL,\n POSTHOG_PROXY_CLIENT_ID,\n WIZARD_USER_AGENT,\n} from '../lib/constants';\nimport { abort } from './clack-utils';\nimport { analytics } from './analytics';\n\nconst OAUTH_CALLBACK_STYLES = `\n <style>\n * {\n font-family: monospace;\n background-color: #1b0a00;\n color: #F7A502;\n font-weight: medium;\n font-size: 24px;\n margin: .25rem;\n }\n\n .blink {\n animation: blink-animation 1s steps(2, start) infinite;\n }\n\n @keyframes blink-animation {\n to {\n opacity: 0;\n }\n }\n </style>\n`;\n\nconst OAuthTokenResponseSchema = z.object({\n access_token: z.string(),\n expires_in: z.number(),\n token_type: z.string(),\n scope: z.string(),\n refresh_token: z.string(),\n scoped_teams: z.array(z.number()).optional(),\n scoped_organizations: z.array(z.string()).optional(),\n});\n\nexport type OAuthTokenResponse = z.infer<typeof OAuthTokenResponseSchema>;\n\ninterface OAuthConfig {\n scopes: string[];\n signup?: boolean;\n}\n\nfunction generateCodeVerifier(): string {\n return crypto.randomBytes(32).toString('base64url');\n}\n\nfunction generateCodeChallenge(verifier: string): string {\n return crypto.createHash('sha256').update(verifier).digest('base64url');\n}\n\nasync function startCallbackServer(\n authUrl: string,\n signupUrl: string,\n): Promise<{\n server: http.Server;\n waitForCallback: () => Promise<string>;\n}> {\n return new Promise((resolve, reject) => {\n let callbackResolve: (code: string) => void;\n let callbackReject: (error: Error) => void;\n\n const waitForCallback = () =>\n new Promise<string>((res, rej) => {\n callbackResolve = res;\n callbackReject = rej;\n });\n\n const server = http.createServer((req, res) => {\n if (!req.url) {\n res.writeHead(400);\n res.end();\n return;\n }\n const url = new URL(req.url, `http://localhost:${OAUTH_PORT}`);\n\n if (url.pathname === '/authorize') {\n const isSignup = url.searchParams.get('signup') === 'true';\n const redirectUrl = isSignup ? signupUrl : authUrl;\n res.writeHead(302, { Location: redirectUrl });\n res.end();\n return;\n }\n\n const code = url.searchParams.get('code');\n const error = url.searchParams.get('error');\n\n if (error) {\n const isAccessDenied = error === 'access_denied';\n res.writeHead(isAccessDenied ? 200 : 400, {\n 'Content-Type': 'text/html; charset=utf-8',\n });\n res.end(`\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <title>PostHog wizard - Authorization ${\n isAccessDenied ? 'cancelled' : 'failed'\n }</title>\n ${OAUTH_CALLBACK_STYLES}\n </head>\n <body>\n <p>${\n isAccessDenied\n ? 'Authorization cancelled.'\n : `Authorization failed.`\n }</p>\n <p>Return to your terminal. This window will close automatically.</p>\n <script>window.close();</script>\n </body>\n </html>\n `);\n callbackReject(new Error(`OAuth error: ${error}`));\n return;\n }\n\n if (code) {\n res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });\n res.end(`\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <title>PostHog wizard is ready</title>\n ${OAUTH_CALLBACK_STYLES}\n </head>\n <body>\n <p>PostHog login complete!</p>\n <p>Return to your terminal: the wizard is hard at work on your project<span class=\"blink\">█</span></p>\n <script>window.close();</script>\n </body>\n </html>\n `);\n callbackResolve(code);\n } else {\n res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' });\n res.end(`\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <title>PostHog wizard - Invalid request</title>\n ${OAUTH_CALLBACK_STYLES}\n </head>\n <body>\n <p>Invalid request - no authorization code received.</p>\n <p>You can close this window.</p>\n </body>\n </html>\n `);\n }\n });\n\n server.listen(OAUTH_PORT, () => {\n resolve({ server, waitForCallback });\n });\n\n server.on('error', reject);\n });\n}\n\nasync function exchangeCodeForToken(\n code: string,\n codeVerifier: string,\n): Promise<OAuthTokenResponse> {\n const clientId = IS_DEV ? POSTHOG_DEV_CLIENT_ID : POSTHOG_PROXY_CLIENT_ID;\n\n const response = await axios.post(\n `${POSTHOG_OAUTH_URL}/oauth/token`,\n {\n grant_type: 'authorization_code',\n code,\n redirect_uri: `http://localhost:${OAUTH_PORT}/callback`,\n client_id: clientId,\n code_verifier: codeVerifier,\n },\n {\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': WIZARD_USER_AGENT,\n },\n },\n );\n\n return OAuthTokenResponseSchema.parse(response.data);\n}\n\nexport async function performOAuthFlow(\n config: OAuthConfig,\n): Promise<OAuthTokenResponse> {\n const clientId = IS_DEV ? POSTHOG_DEV_CLIENT_ID : POSTHOG_PROXY_CLIENT_ID;\n const codeVerifier = generateCodeVerifier();\n const codeChallenge = generateCodeChallenge(codeVerifier);\n\n const authUrl = new URL(`${POSTHOG_OAUTH_URL}/oauth/authorize`);\n authUrl.searchParams.set('client_id', clientId);\n authUrl.searchParams.set(\n 'redirect_uri',\n `http://localhost:${OAUTH_PORT}/callback`,\n );\n authUrl.searchParams.set('response_type', 'code');\n authUrl.searchParams.set('code_challenge', codeChallenge);\n authUrl.searchParams.set('code_challenge_method', 'S256');\n authUrl.searchParams.set('scope', config.scopes.join(' '));\n authUrl.searchParams.set('required_access_level', 'project');\n\n const signupUrl = new URL(\n `${POSTHOG_OAUTH_URL}/signup?next=${encodeURIComponent(\n authUrl.toString(),\n )}`,\n );\n\n const localSignupUrl = `http://localhost:${OAUTH_PORT}/authorize?signup=true`;\n const localLoginUrl = `http://localhost:${OAUTH_PORT}/authorize`;\n\n const urlToOpen = config.signup ? localSignupUrl : localLoginUrl;\n\n const { server, waitForCallback } = await startCallbackServer(\n authUrl.toString(),\n signupUrl.toString(),\n );\n\n clack.log.info(\n `${chalk.bold(\n \"If the browser window didn't open automatically, please open the following link to be redirected to PostHog:\",\n )}\\n\\n${chalk.cyan(urlToOpen)}${\n config.signup\n ? `\\n\\nIf you already have an account, you can use this link:\\n\\n${chalk.cyan(\n localLoginUrl,\n )}`\n : ``\n }`,\n );\n\n if (process.env.NODE_ENV !== 'test') {\n opn(urlToOpen, { wait: false }).catch(() => {\n // opn throws in environments without a browser\n });\n }\n\n const loginSpinner = clack.spinner();\n loginSpinner.start('Waiting for authorization...');\n\n try {\n const code = await Promise.race([\n waitForCallback(),\n new Promise<never>((_, reject) =>\n setTimeout(() => reject(new Error('Authorization timed out')), 60_000),\n ),\n ]);\n\n const token = await exchangeCodeForToken(code, codeVerifier);\n\n server.close();\n loginSpinner.stop('Authorization complete!');\n\n return token;\n } catch (e) {\n loginSpinner.stop('Authorization failed.');\n server.close();\n\n const error = e instanceof Error ? e : new Error('Unknown error');\n\n if (error.message.includes('timeout')) {\n clack.log.error('Authorization timed out. Please try again.');\n } else if (error.message.includes('access_denied')) {\n clack.log.info(\n `${chalk.yellow(\n 'Authorization was cancelled.',\n )}\\n\\nYou denied access to PostHog. To use the wizard, you need to authorize access to your PostHog account.\\n\\n${chalk.dim(\n 'You can try again by re-running the wizard.',\n )}`,\n );\n } else {\n clack.log.error(\n `${chalk.red('Authorization failed:')}\\n\\n${\n error.message\n }\\n\\n${chalk.dim(\n `If you think this is a bug in the PostHog wizard, please create an issue:\\n${ISSUES_URL}`,\n )}`,\n );\n }\n\n analytics.captureException(error, {\n step: 'oauth_flow',\n });\n\n await abort();\n throw error;\n }\n}\n"]}
@@ -21,10 +21,6 @@ export type WizardOptions = {
21
21
  * The directory to run the wizard in.
22
22
  */
23
23
  installDir: string;
24
- /**
25
- * The cloud region to use.
26
- */
27
- cloudRegion?: CloudRegion;
28
24
  /**
29
25
  * Whether to select the default option for all questions automatically.
30
26
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"","sourcesContent":["export type PostHogProjectData = Record<string, unknown>;\n\nexport type PreselectedProject = {\n project: PostHogProjectData;\n authToken: string;\n};\n\nexport type WizardOptions = {\n /**\n * Whether to enable debug mode.\n */\n debug: boolean;\n\n /**\n * Whether to force install the SDK package to continue with the installation in case\n * any package manager checks are failing (e.g. peer dependency versions).\n *\n * Use with caution and only if you know what you're doing.\n *\n * Does not apply to all wizard flows (currently NPM only)\n */\n forceInstall: boolean;\n\n /**\n * The directory to run the wizard in.\n */\n installDir: string;\n\n /**\n * The cloud region to use.\n */\n cloudRegion?: CloudRegion;\n\n /**\n * Whether to select the default option for all questions automatically.\n */\n default: boolean;\n\n /**\n * Whether to create a new PostHog account during setup.\n */\n signup: boolean;\n\n /**\n * Whether to use the local MCP server at http://localhost:8787/mcp\n */\n localMcp: boolean;\n\n /**\n * CI mode - non-interactive execution\n */\n ci: boolean;\n\n /**\n * Personal API key (phx_xxx) - used for LLM gateway auth, skips OAuth\n */\n apiKey?: string;\n\n /**\n * PostHog project ID. When set (e.g. in CI with --project-id), the wizard uses this project\n * instead of the default from the API key or OAuth.\n */\n projectId?: number;\n\n /**\n * Whether to show the menu for manual integration selection instead of auto-detecting.\n */\n menu: boolean;\n\n /**\n * Whether to run in benchmark mode with per-phase token tracking.\n * When enabled, the wizard runs each workflow phase as a separate agent call\n * and writes detailed usage data to /tmp/posthog-wizard-benchmark.json.\n */\n benchmark: boolean;\n};\n\nexport interface Feature {\n id: string;\n prompt: string;\n enabledHint?: string;\n disabledHint?: string;\n}\n\nexport type FileChange = {\n filePath: string;\n oldContent?: string;\n newContent: string;\n};\n\nexport type CloudRegion = 'us' | 'eu';\n\nexport type AIModel =\n | 'gpt-5-mini'\n | 'o4-mini'\n | 'gemini-2.5-flash'\n | 'gemini-2.5-pro';\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"","sourcesContent":["export type PostHogProjectData = Record<string, unknown>;\n\nexport type PreselectedProject = {\n project: PostHogProjectData;\n authToken: string;\n};\n\nexport type WizardOptions = {\n /**\n * Whether to enable debug mode.\n */\n debug: boolean;\n\n /**\n * Whether to force install the SDK package to continue with the installation in case\n * any package manager checks are failing (e.g. peer dependency versions).\n *\n * Use with caution and only if you know what you're doing.\n *\n * Does not apply to all wizard flows (currently NPM only)\n */\n forceInstall: boolean;\n\n /**\n * The directory to run the wizard in.\n */\n installDir: string;\n\n /**\n * Whether to select the default option for all questions automatically.\n */\n default: boolean;\n\n /**\n * Whether to create a new PostHog account during setup.\n */\n signup: boolean;\n\n /**\n * Whether to use the local MCP server at http://localhost:8787/mcp\n */\n localMcp: boolean;\n\n /**\n * CI mode - non-interactive execution\n */\n ci: boolean;\n\n /**\n * Personal API key (phx_xxx) - used for LLM gateway auth, skips OAuth\n */\n apiKey?: string;\n\n /**\n * PostHog project ID. When set (e.g. in CI with --project-id), the wizard uses this project\n * instead of the default from the API key or OAuth.\n */\n projectId?: number;\n\n /**\n * Whether to show the menu for manual integration selection instead of auto-detecting.\n */\n menu: boolean;\n\n /**\n * Whether to run in benchmark mode with per-phase token tracking.\n * When enabled, the wizard runs each workflow phase as a separate agent call\n * and writes detailed usage data to /tmp/posthog-wizard-benchmark.json.\n */\n benchmark: boolean;\n};\n\nexport interface Feature {\n id: string;\n prompt: string;\n enabledHint?: string;\n disabledHint?: string;\n}\n\nexport type FileChange = {\n filePath: string;\n oldContent?: string;\n newContent: string;\n};\n\nexport type CloudRegion = 'us' | 'eu';\n\nexport type AIModel =\n | 'gpt-5-mini'\n | 'o4-mini'\n | 'gemini-2.5-flash'\n | 'gemini-2.5-pro';\n"]}
@@ -3,5 +3,5 @@ export declare const getAssetHostFromHost: (host: string) => string;
3
3
  export declare const getUiHostFromHost: (host: string) => string;
4
4
  export declare const getHostFromRegion: (region: CloudRegion) => "http://localhost:8010" | "https://us.i.posthog.com" | "https://eu.i.posthog.com";
5
5
  export declare const getCloudUrlFromRegion: (region: CloudRegion) => "http://localhost:8010" | "https://us.posthog.com" | "https://eu.posthog.com";
6
- export declare const getOauthClientIdFromRegion: (region: CloudRegion) => "c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM" | "bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy" | "DC5uRLVbGI02YQ82grxgnK6Qn12SXWpCqdPb60oZ";
6
+ export declare function detectRegionFromToken(accessToken: string): Promise<CloudRegion>;
7
7
  export declare const getLlmGatewayUrlFromHost: (host: string) => "http://localhost:3308/wizard" | "https://gateway.eu.posthog.com/wizard" | "https://gateway.us.posthog.com/wizard";
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLlmGatewayUrlFromHost = exports.getOauthClientIdFromRegion = exports.getCloudUrlFromRegion = exports.getHostFromRegion = exports.getUiHostFromHost = exports.getAssetHostFromHost = void 0;
6
+ exports.getLlmGatewayUrlFromHost = exports.getCloudUrlFromRegion = exports.getHostFromRegion = exports.getUiHostFromHost = exports.getAssetHostFromHost = void 0;
7
+ exports.detectRegionFromToken = detectRegionFromToken;
8
+ const axios_1 = __importDefault(require("axios"));
4
9
  const constants_1 = require("../lib/constants");
5
10
  const getAssetHostFromHost = (host) => {
6
11
  if (host.includes('us.i.posthog.com')) {
@@ -42,16 +47,24 @@ const getCloudUrlFromRegion = (region) => {
42
47
  return 'https://us.posthog.com';
43
48
  };
44
49
  exports.getCloudUrlFromRegion = getCloudUrlFromRegion;
45
- const getOauthClientIdFromRegion = (region) => {
50
+ async function detectRegionFromToken(accessToken) {
46
51
  if (constants_1.IS_DEV) {
47
- return constants_1.POSTHOG_DEV_CLIENT_ID;
48
- }
49
- if (region === 'us') {
50
- return constants_1.POSTHOG_US_CLIENT_ID;
52
+ return 'us';
51
53
  }
52
- return constants_1.POSTHOG_EU_CLIENT_ID;
53
- };
54
- exports.getOauthClientIdFromRegion = getOauthClientIdFromRegion;
54
+ const headers = {
55
+ Authorization: `Bearer ${accessToken}`,
56
+ 'User-Agent': constants_1.WIZARD_USER_AGENT,
57
+ };
58
+ const [usResult, euResult] = await Promise.allSettled([
59
+ axios_1.default.get('https://us.posthog.com/api/users/@me/', { headers }),
60
+ axios_1.default.get('https://eu.posthog.com/api/users/@me/', { headers }),
61
+ ]);
62
+ if (usResult.status === 'fulfilled')
63
+ return 'us';
64
+ if (euResult.status === 'fulfilled')
65
+ return 'eu';
66
+ throw new Error('Could not determine cloud region from access token. Please check your PostHog account.');
67
+ }
55
68
  const getLlmGatewayUrlFromHost = (host) => {
56
69
  if (host.includes('localhost')) {
57
70
  return 'http://localhost:3308/wizard';
@@ -1 +1 @@
1
- {"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../src/utils/urls.ts"],"names":[],"mappings":";;;AAAA,gDAK0B;AAGnB,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAE,EAAE;IACnD,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACtC,OAAO,iCAAiC,CAAC;IAC3C,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACtC,OAAO,iCAAiC,CAAC;IAC3C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAVW,QAAA,oBAAoB,wBAU/B;AAEK,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE;IAChD,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACtC,OAAO,wBAAwB,CAAC;IAClC,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACtC,OAAO,wBAAwB,CAAC;IAClC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAVW,QAAA,iBAAiB,qBAU5B;AAEK,MAAM,iBAAiB,GAAG,CAAC,MAAmB,EAAE,EAAE;IACvD,IAAI,kBAAM,EAAE,CAAC;QACX,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,0BAA0B,CAAC;IACpC,CAAC;IAED,OAAO,0BAA0B,CAAC;AACpC,CAAC,CAAC;AAVW,QAAA,iBAAiB,qBAU5B;AAEK,MAAM,qBAAqB,GAAG,CAAC,MAAmB,EAAE,EAAE;IAC3D,IAAI,kBAAM,EAAE,CAAC;QACX,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,wBAAwB,CAAC;IAClC,CAAC;IAED,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC;AAVW,QAAA,qBAAqB,yBAUhC;AAEK,MAAM,0BAA0B,GAAG,CAAC,MAAmB,EAAE,EAAE;IAChE,IAAI,kBAAM,EAAE,CAAC;QACX,OAAO,iCAAqB,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,gCAAoB,CAAC;IAC9B,CAAC;IACD,OAAO,gCAAoB,CAAC;AAC9B,CAAC,CAAC;AATW,QAAA,0BAA0B,8BASrC;AAEK,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,OAAO,8BAA8B,CAAC;IACxC,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACzE,OAAO,uCAAuC,CAAC;IACjD,CAAC;IAED,OAAO,uCAAuC,CAAC;AACjD,CAAC,CAAC;AAVW,QAAA,wBAAwB,4BAUnC","sourcesContent":["import {\n IS_DEV,\n POSTHOG_DEV_CLIENT_ID,\n POSTHOG_EU_CLIENT_ID,\n POSTHOG_US_CLIENT_ID,\n} from '../lib/constants';\nimport type { CloudRegion } from './types';\n\nexport const getAssetHostFromHost = (host: string) => {\n if (host.includes('us.i.posthog.com')) {\n return 'https://us-assets.i.posthog.com';\n }\n\n if (host.includes('eu.i.posthog.com')) {\n return 'https://eu-assets.i.posthog.com';\n }\n\n return host;\n};\n\nexport const getUiHostFromHost = (host: string) => {\n if (host.includes('us.i.posthog.com')) {\n return 'https://us.posthog.com';\n }\n\n if (host.includes('eu.i.posthog.com')) {\n return 'https://eu.posthog.com';\n }\n\n return host;\n};\n\nexport const getHostFromRegion = (region: CloudRegion) => {\n if (IS_DEV) {\n return 'http://localhost:8010';\n }\n\n if (region === 'eu') {\n return 'https://eu.i.posthog.com';\n }\n\n return 'https://us.i.posthog.com';\n};\n\nexport const getCloudUrlFromRegion = (region: CloudRegion) => {\n if (IS_DEV) {\n return 'http://localhost:8010';\n }\n\n if (region === 'eu') {\n return 'https://eu.posthog.com';\n }\n\n return 'https://us.posthog.com';\n};\n\nexport const getOauthClientIdFromRegion = (region: CloudRegion) => {\n if (IS_DEV) {\n return POSTHOG_DEV_CLIENT_ID;\n }\n\n if (region === 'us') {\n return POSTHOG_US_CLIENT_ID;\n }\n return POSTHOG_EU_CLIENT_ID;\n};\n\nexport const getLlmGatewayUrlFromHost = (host: string) => {\n if (host.includes('localhost')) {\n return 'http://localhost:3308/wizard';\n }\n\n if (host.includes('eu.posthog.com') || host.includes('eu.i.posthog.com')) {\n return 'https://gateway.eu.posthog.com/wizard';\n }\n\n return 'https://gateway.us.posthog.com/wizard';\n};\n"]}
1
+ {"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../src/utils/urls.ts"],"names":[],"mappings":";;;;;;AAoDA,sDAuBC;AA3ED,kDAA0B;AAC1B,gDAA6D;AAGtD,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAE,EAAE;IACnD,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACtC,OAAO,iCAAiC,CAAC;IAC3C,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACtC,OAAO,iCAAiC,CAAC;IAC3C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAVW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AAE,CAAC;QAC/D,eAAK,CAAC,GAAG,CAAC,uCAAuC,EAAE,EAAE,OAAO,EAAE,CAAC;KAChE,CAAC,CAAC;IAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IACjD,IAAI,QAAQ,CAAC,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAEjD,MAAM,IAAI,KAAK,CACb,wFAAwF,CACzF,CAAC;AACJ,CAAC;AAEM,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,OAAO,8BAA8B,CAAC;IACxC,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACzE,OAAO,uCAAuC,CAAC;IACjD,CAAC;IAED,OAAO,uCAAuC,CAAC;AACjD,CAAC,CAAC;AAVW,QAAA,wBAAwB,4BAUnC","sourcesContent":["import axios from 'axios';\nimport { IS_DEV, WIZARD_USER_AGENT } from '../lib/constants';\nimport type { CloudRegion } from './types';\n\nexport const getAssetHostFromHost = (host: string) => {\n if (host.includes('us.i.posthog.com')) {\n return 'https://us-assets.i.posthog.com';\n }\n\n if (host.includes('eu.i.posthog.com')) {\n return 'https://eu-assets.i.posthog.com';\n }\n\n return host;\n};\n\nexport const getUiHostFromHost = (host: string) => {\n if (host.includes('us.i.posthog.com')) {\n return 'https://us.posthog.com';\n }\n\n if (host.includes('eu.i.posthog.com')) {\n return 'https://eu.posthog.com';\n }\n\n return host;\n};\n\nexport const getHostFromRegion = (region: CloudRegion) => {\n if (IS_DEV) {\n return 'http://localhost:8010';\n }\n\n if (region === 'eu') {\n return 'https://eu.i.posthog.com';\n }\n\n return 'https://us.i.posthog.com';\n};\n\nexport const getCloudUrlFromRegion = (region: CloudRegion) => {\n if (IS_DEV) {\n return 'http://localhost:8010';\n }\n\n if (region === 'eu') {\n return 'https://eu.posthog.com';\n }\n\n return 'https://us.posthog.com';\n};\n\nexport async function detectRegionFromToken(\n accessToken: string,\n): Promise<CloudRegion> {\n if (IS_DEV) {\n return 'us';\n }\n\n const headers = {\n Authorization: `Bearer ${accessToken}`,\n 'User-Agent': WIZARD_USER_AGENT,\n };\n\n const [usResult, euResult] = await Promise.allSettled([\n axios.get('https://us.posthog.com/api/users/@me/', { headers }),\n axios.get('https://eu.posthog.com/api/users/@me/', { headers }),\n ]);\n\n if (usResult.status === 'fulfilled') return 'us';\n if (euResult.status === 'fulfilled') return 'eu';\n\n throw new Error(\n 'Could not determine cloud region from access token. Please check your PostHog account.',\n );\n}\n\nexport const getLlmGatewayUrlFromHost = (host: string) => {\n if (host.includes('localhost')) {\n return 'http://localhost:3308/wizard';\n }\n\n if (host.includes('eu.posthog.com') || host.includes('eu.i.posthog.com')) {\n return 'https://gateway.eu.posthog.com/wizard';\n }\n\n return 'https://gateway.us.posthog.com/wizard';\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/wizard",
3
- "version": "1.35.2",
3
+ "version": "1.36.1",
4
4
  "homepage": "https://github.com/PostHog/wizard",
5
5
  "repository": "https://github.com/PostHog/wizard",
6
6
  "description": "The PostHog wizard helps you to configure your project",
@@ -32,7 +32,7 @@
32
32
  "definition": "dist/index.d.ts"
33
33
  },
34
34
  "dependencies": {
35
- "@anthropic-ai/claude-agent-sdk": "~0.1.65",
35
+ "@anthropic-ai/claude-agent-sdk": "~0.2.63",
36
36
  "@clack/core": "^0.3.4",
37
37
  "@clack/prompts": "0.7.0",
38
38
  "@langchain/core": "^0.3.40",
@@ -45,7 +45,7 @@
45
45
  "lodash": "^4.17.21",
46
46
  "magicast": "^0.2.10",
47
47
  "opn": "^5.4.0",
48
- "posthog-node": "^4.18.0",
48
+ "posthog-node": "^5.24.17",
49
49
  "read-env": "^1.3.0",
50
50
  "recast": "^0.23.3",
51
51
  "semver": "^7.5.3",