@posthog/wizard 1.14.0 → 1.16.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.
- package/dist/bin.js +17 -4
- package/dist/bin.js.map +1 -1
- package/dist/src/__tests__/run.test.js +1 -0
- package/dist/src/__tests__/run.test.js.map +1 -1
- package/dist/src/astro/astro-wizard.js +5 -3
- package/dist/src/astro/astro-wizard.js.map +1 -1
- package/dist/src/lib/agent-interface.d.ts +27 -0
- package/dist/src/lib/agent-interface.js +161 -0
- package/dist/src/lib/agent-interface.js.map +1 -0
- package/dist/src/lib/api.d.ts +75 -0
- package/dist/src/lib/api.js +102 -0
- package/dist/src/lib/api.js.map +1 -0
- package/dist/src/lib/constants.d.ts +12 -0
- package/dist/src/lib/constants.js +15 -1
- package/dist/src/lib/constants.js.map +1 -1
- package/dist/src/mcp.d.ts +4 -1
- package/dist/src/mcp.js +6 -3
- package/dist/src/mcp.js.map +1 -1
- package/dist/src/nextjs/event-setup.js +5 -3
- package/dist/src/nextjs/event-setup.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard-agent.d.ts +5 -0
- package/dist/src/nextjs/nextjs-wizard-agent.js +146 -0
- package/dist/src/nextjs/nextjs-wizard-agent.js.map +1 -0
- package/dist/src/nextjs/nextjs-wizard.js +5 -3
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/react/react-wizard.js +5 -3
- package/dist/src/react/react-wizard.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.js +5 -3
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/run.js +69 -2
- package/dist/src/run.js.map +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/MCPClient.d.ts +8 -8
- package/dist/src/steps/add-mcp-server-to-clients/MCPClient.js +16 -13
- package/dist/src/steps/add-mcp-server-to-clients/MCPClient.js.map +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/clients/__tests__/claude.test.js +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/clients/__tests__/claude.test.js.map +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.d.ts +3 -3
- package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.js +12 -8
- package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.js.map +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.d.ts +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.js +2 -2
- package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.js.map +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/defaults.d.ts +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/defaults.js +3 -2
- package/dist/src/steps/add-mcp-server-to-clients/defaults.js.map +1 -1
- package/dist/src/steps/add-mcp-server-to-clients/index.d.ts +7 -5
- package/dist/src/steps/add-mcp-server-to-clients/index.js +16 -14
- package/dist/src/steps/add-mcp-server-to-clients/index.js.map +1 -1
- package/dist/src/svelte/svelte-wizard.js +5 -3
- package/dist/src/svelte/svelte-wizard.js.map +1 -1
- package/dist/src/utils/__tests__/analytics.test.js +9 -0
- package/dist/src/utils/__tests__/analytics.test.js.map +1 -1
- package/dist/src/utils/analytics.d.ts +2 -0
- package/dist/src/utils/analytics.js +18 -1
- package/dist/src/utils/analytics.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +2 -1
- package/dist/src/utils/clack-utils.js +31 -60
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/errors.d.ts +3 -0
- package/dist/src/utils/errors.js +11 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/file-utils.d.ts +9 -6
- package/dist/src/utils/file-utils.js +9 -6
- package/dist/src/utils/file-utils.js.map +1 -1
- package/dist/src/utils/oauth.d.ts +35 -0
- package/dist/src/utils/oauth.js +212 -0
- package/dist/src/utils/oauth.js.map +1 -0
- package/dist/src/utils/query.d.ts +3 -2
- package/dist/src/utils/query.js +48 -3
- package/dist/src/utils/query.js.map +1 -1
- package/dist/src/utils/types.d.ts +1 -1
- package/dist/src/utils/types.js.map +1 -1
- package/dist/src/utils/urls.d.ts +2 -0
- package/dist/src/utils/urls.js +24 -4
- package/dist/src/utils/urls.js.map +1 -1
- package/package.json +6 -2
package/dist/bin.js
CHANGED
|
@@ -125,15 +125,28 @@ if (process.env.NODE_ENV === 'test') {
|
|
|
125
125
|
.command('mcp <command>', 'MCP server management commands', (yargs) => {
|
|
126
126
|
return yargs
|
|
127
127
|
.command('add', 'Install PostHog MCP server to supported clients', (yargs) => {
|
|
128
|
-
return yargs.options({
|
|
128
|
+
return yargs.options({
|
|
129
|
+
local: {
|
|
130
|
+
default: false,
|
|
131
|
+
describe: 'Add local development MCP server (http://localhost:8787)',
|
|
132
|
+
type: 'boolean',
|
|
133
|
+
},
|
|
134
|
+
});
|
|
129
135
|
}, (argv) => {
|
|
130
136
|
const options = { ...argv };
|
|
131
137
|
void (0, mcp_1.runMCPInstall)(options);
|
|
132
138
|
})
|
|
133
139
|
.command('remove', 'Remove PostHog MCP server from supported clients', (yargs) => {
|
|
134
|
-
return yargs.options({
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
return yargs.options({
|
|
141
|
+
local: {
|
|
142
|
+
default: false,
|
|
143
|
+
describe: 'Remove local development MCP server (http://localhost:8787)',
|
|
144
|
+
type: 'boolean',
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}, (argv) => {
|
|
148
|
+
const options = { ...argv };
|
|
149
|
+
void (0, mcp_1.runMCPRemove)(options);
|
|
137
150
|
})
|
|
138
151
|
.demandCommand(1, 'You must specify a subcommand (add or remove)')
|
|
139
152
|
.help();
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../bin.ts"],"names":[],"mappings":";;;;;;AACA,mCAAmC;AACnC,iDAA0C;AAE1C,kDAA0B;AAC1B,2CAAwC;AACxC,kDAA0B;AAE1B,MAAM,kBA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AQ,EACR,kDAAkD,EAClD,CAAC,KAAK,EAAE,EAAE;QACR,OAAO,KAAK,CAAC,OAAO,CAAC;YACnB,KAAK,EAAE;gBACL,OAAO,EAAE,KAAK;gBACd,QAAQ,EACN,6DAA6D;gBAC/D,IAAI,EAAE,SAAS;aAChB;SACF,CAAC,CAAC;IACL,CAAC,EACD,CAAC,IAAI,EAAE,EAAE;QACP,MAAM,OAAO,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;QAC5B,KAAK,IAAA,kBAAY,EAAC,OAA8B,CAAC,CAAC;IACpD,CAAC,CACF;SACA,aAAa,CAAC,CAAC,EAAE,+CAA+C,CAAC;SACjE,IAAI,EAAE,CAAC;AACZ,CAAC,CAAC;KACD,IAAI,EAAE;KACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC;KAClB,OAAO,EAAE;KACT,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC;KACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,eAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { satisfies } from 'semver';\nimport { red } from './src/utils/logging';\n\nimport yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\nimport chalk from 'chalk';\n\nconst NODE_VERSION_RANGE = '>=18.17.0';\n\n// Have to run this above the other imports because they are importing clack that\n// has the problematic imports.\nif (!satisfies(process.version, NODE_VERSION_RANGE)) {\n red(\n `PostHog wizard requires Node.js ${NODE_VERSION_RANGE}. You are using Node.js ${process.version}. Please upgrade your Node.js version.`,\n );\n process.exit(1);\n}\n\nimport { runMCPInstall, runMCPRemove } from './src/mcp';\nimport type { CloudRegion, WizardOptions } from './src/utils/types';\nimport { runWizard } from './src/run';\nimport { runEventSetupWizard } from './src/nextjs/event-setup';\nimport {\n readEnvironment,\n isNonInteractiveEnvironment,\n} from './src/utils/environment';\nimport path from 'path';\nimport clack from './src/utils/clack';\n\nif (isNonInteractiveEnvironment()) {\n clack.intro(chalk.inverse(`PostHog Wizard`));\n\n clack.log.error(\n 'This installer requires an interactive terminal (TTY) to run.\\n' +\n 'It appears you are running in a non-interactive environment.\\n' +\n 'Please run the wizard in an interactive terminal.',\n );\n process.exit(1);\n}\n\nif (process.env.NODE_ENV === 'test') {\n void (async () => {\n try {\n const { server } = await import('./e2e-tests/mocks/server.js');\n server.listen({\n onUnhandledRequest: 'bypass',\n });\n } catch (error) {\n // Mock server import failed - this can happen during non-E2E tests\n }\n })();\n}\n\nyargs(hideBin(process.argv))\n .env('POSTHOG_WIZARD')\n // global options\n .options({\n debug: {\n default: false,\n describe: 'Enable verbose logging\\nenv: POSTHOG_WIZARD_DEBUG',\n type: 'boolean',\n },\n region: {\n describe: 'PostHog cloud region\\nenv: POSTHOG_WIZARD_REGION',\n choices: ['us', 'eu'],\n type: 'string',\n },\n default: {\n default: true,\n describe:\n 'Use default options for all prompts\\nenv: POSTHOG_WIZARD_DEFAULT',\n type: 'boolean',\n },\n signup: {\n default: false,\n describe:\n 'Create a new PostHog account during setup\\nenv: POSTHOG_WIZARD_SIGNUP',\n type: 'boolean',\n },\n })\n .command(\n ['$0'],\n 'Run the PostHog setup wizard',\n (yargs) => {\n return yargs.options({\n 'force-install': {\n default: false,\n describe:\n 'Force install packages even if peer dependency checks fail\\nenv: POSTHOG_WIZARD_FORCE_INSTALL',\n type: 'boolean',\n },\n 'install-dir': {\n describe:\n 'Directory to install PostHog in\\nenv: POSTHOG_WIZARD_INSTALL_DIR',\n type: 'string',\n },\n integration: {\n describe: 'Integration to set up',\n choices: ['nextjs', 'astro', 'react', 'svelte', 'react-native'],\n type: 'string',\n },\n });\n },\n (argv) => {\n const options = { ...argv };\n void runWizard(options as unknown as WizardOptions);\n },\n )\n .command(\n 'event-setup',\n 'Run the event setup wizard',\n (yargs) => {\n return yargs.options({\n 'install-dir': {\n describe:\n 'Directory to run the wizard in\\nenv: POSTHOG_WIZARD_INSTALL_DIR',\n type: 'string',\n },\n });\n },\n (argv) => {\n const finalArgs = {\n ...argv,\n ...readEnvironment(),\n } as any;\n\n let resolvedInstallDir: string;\n if (finalArgs.installDir) {\n if (path.isAbsolute(finalArgs.installDir)) {\n resolvedInstallDir = finalArgs.installDir;\n } else {\n resolvedInstallDir = path.join(process.cwd(), finalArgs.installDir);\n }\n } else {\n resolvedInstallDir = process.cwd();\n }\n\n const wizardOptions: WizardOptions = {\n debug: finalArgs.debug ?? false,\n installDir: resolvedInstallDir,\n cloudRegion: finalArgs.region as CloudRegion | undefined,\n default: finalArgs.default ?? false,\n signup: finalArgs.signup ?? false,\n forceInstall: false,\n };\n\n void runEventSetupWizard(wizardOptions);\n },\n )\n .command('mcp <command>', 'MCP server management commands', (yargs) => {\n return yargs\n .command(\n 'add',\n 'Install PostHog MCP server to supported clients',\n (yargs) => {\n return yargs.options({\n local: {\n default: false,\n describe:\n 'Add local development MCP server (http://localhost:8787)',\n type: 'boolean',\n },\n });\n },\n (argv) => {\n const options = { ...argv };\n void runMCPInstall(\n options as unknown as {\n signup: boolean;\n region?: CloudRegion;\n local?: boolean;\n },\n );\n },\n )\n .command(\n 'remove',\n 'Remove PostHog MCP server from supported clients',\n (yargs) => {\n return yargs.options({\n local: {\n default: false,\n describe:\n 'Remove local development MCP server (http://localhost:8787)',\n type: 'boolean',\n },\n });\n },\n (argv) => {\n const options = { ...argv };\n void runMCPRemove(options as { local?: boolean });\n },\n )\n .demandCommand(1, 'You must specify a subcommand (add or remove)')\n .help();\n })\n .help()\n .alias('help', 'h')\n .version()\n .alias('version', 'v')\n .wrap(process.stdout.isTTY ? yargs.terminalWidth() : 80).argv;\n"]}
|
|
@@ -5,6 +5,7 @@ const nextjs_wizard_1 = require("../nextjs/nextjs-wizard");
|
|
|
5
5
|
const analytics_1 = require("../utils/analytics");
|
|
6
6
|
const constants_1 = require("../lib/constants");
|
|
7
7
|
jest.mock('../nextjs/nextjs-wizard');
|
|
8
|
+
jest.mock('../nextjs/nextjs-wizard-agent');
|
|
8
9
|
jest.mock('../utils/analytics');
|
|
9
10
|
jest.mock('../utils/clack');
|
|
10
11
|
const mockRunNextjsWizard = nextjs_wizard_1.runNextjsWizard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.test.js","sourceRoot":"","sources":["../../../src/__tests__/run.test.ts"],"names":[],"mappings":";;AAAA,gCAAmC;AACnC,2DAA0D;AAC1D,kDAA+C;AAC/C,gDAA+C;AAE/C,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;AACrC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAChC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAE5B,MAAM,mBAAmB,GAAG,+BAE3B,CAAC;AACF,MAAM,aAAa,GAAG,qBAA0C,CAAC;AAEjE,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;QAErB,aAAa,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QACjC,aAAa,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QAC3C,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAEhE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE;YAClD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iEAAiE,EAAE,KAAK,IAAI,EAAE;QAC/E,MAAM,SAAS,GAAG,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QAC7C,MAAM,QAAQ,GAAG;YACf,WAAW,EAAE,uBAAW,CAAC,MAAM;YAC/B,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,KAAK;SACpB,CAAC;QAEF,mBAAmB,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAEjD,MAAM,MAAM,CAAC,IAAA,eAAS,EAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAEzE,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,SAAS,EAAE;YACrE,WAAW,EAAE,uBAAW,CAAC,MAAM;YAC/B,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;SACpC,CAAC,CAAC;QAEH,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;QACrE,MAAM,QAAQ,GAAG,EAAE,WAAW,EAAE,uBAAW,CAAC,MAAM,EAAE,CAAC;QAErD,mBAAmB,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAEjD,MAAM,IAAA,eAAS,EAAC,QAAQ,CAAC,CAAC;QAE1B,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC9D,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { runWizard } from '../run';\nimport { runNextjsWizard } from '../nextjs/nextjs-wizard';\nimport { analytics } from '../utils/analytics';\nimport { Integration } from '../lib/constants';\n\njest.mock('../nextjs/nextjs-wizard');\njest.mock('../utils/analytics');\njest.mock('../utils/clack');\n\nconst mockRunNextjsWizard = runNextjsWizard as jest.MockedFunction<\n typeof runNextjsWizard\n>;\nconst mockAnalytics = analytics as jest.Mocked<typeof analytics>;\n\ndescribe('runWizard error handling', () => {\n beforeEach(() => {\n jest.clearAllMocks();\n\n mockAnalytics.setTag = jest.fn();\n mockAnalytics.captureException = jest.fn();\n mockAnalytics.shutdown = jest.fn().mockResolvedValue(undefined);\n\n jest.spyOn(process, 'exit').mockImplementation(() => {\n throw new Error('process.exit called');\n });\n });\n\n afterEach(() => {\n jest.restoreAllMocks();\n });\n\n it('should capture exception and shutdown analytics on wizard error', async () => {\n const testError = new Error('Wizard failed');\n const testArgs = {\n integration: Integration.nextjs,\n debug: true,\n forceInstall: false,\n };\n\n mockRunNextjsWizard.mockRejectedValue(testError);\n\n await expect(runWizard(testArgs)).rejects.toThrow('process.exit called');\n\n expect(mockAnalytics.captureException).toHaveBeenCalledWith(testError, {\n integration: Integration.nextjs,\n arguments: JSON.stringify(testArgs),\n });\n\n expect(mockAnalytics.shutdown).toHaveBeenCalledWith('error');\n });\n\n it('should not call captureException when wizard succeeds', async () => {\n const testArgs = { integration: Integration.nextjs };\n\n mockRunNextjsWizard.mockResolvedValue(undefined);\n\n await runWizard(testArgs);\n\n expect(mockAnalytics.captureException).not.toHaveBeenCalled();\n expect(mockAnalytics.shutdown).not.toHaveBeenCalled();\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"run.test.js","sourceRoot":"","sources":["../../../src/__tests__/run.test.ts"],"names":[],"mappings":";;AAAA,gCAAmC;AACnC,2DAA0D;AAC1D,kDAA+C;AAC/C,gDAA+C;AAE/C,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;AACrC,IAAI,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;AAC3C,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAChC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAE5B,MAAM,mBAAmB,GAAG,+BAE3B,CAAC;AACF,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,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;QACrE,MAAM,QAAQ,GAAG,EAAE,WAAW,EAAE,uBAAW,CAAC,MAAM,EAAE,CAAC;QAErD,mBAAmB,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAEjD,MAAM,IAAA,eAAS,EAAC,QAAQ,CAAC,CAAC;QAE1B,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC9D,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { runWizard } from '../run';\nimport { runNextjsWizard } from '../nextjs/nextjs-wizard';\nimport { analytics } from '../utils/analytics';\nimport { Integration } from '../lib/constants';\n\njest.mock('../nextjs/nextjs-wizard');\njest.mock('../nextjs/nextjs-wizard-agent');\njest.mock('../utils/analytics');\njest.mock('../utils/clack');\n\nconst mockRunNextjsWizard = runNextjsWizard as jest.MockedFunction<\n typeof runNextjsWizard\n>;\nconst mockAnalytics = analytics as jest.Mocked<typeof analytics>;\n\ndescribe('runWizard error handling', () => {\n beforeEach(() => {\n jest.clearAllMocks();\n\n mockAnalytics.setTag = jest.fn();\n mockAnalytics.captureException = jest.fn();\n mockAnalytics.shutdown = jest.fn().mockResolvedValue(undefined);\n\n jest.spyOn(process, 'exit').mockImplementation(() => {\n throw new Error('process.exit called');\n });\n });\n\n afterEach(() => {\n jest.restoreAllMocks();\n });\n\n it('should capture exception and shutdown analytics on wizard error', async () => {\n const testError = new Error('Wizard failed');\n const testArgs = {\n integration: Integration.nextjs,\n debug: true,\n forceInstall: false,\n };\n\n mockRunNextjsWizard.mockRejectedValue(testError);\n\n await expect(runWizard(testArgs)).rejects.toThrow('process.exit called');\n\n expect(mockAnalytics.captureException).toHaveBeenCalledWith(testError, {\n integration: Integration.nextjs,\n arguments: JSON.stringify(testArgs),\n });\n\n expect(mockAnalytics.shutdown).toHaveBeenCalledWith('error');\n });\n\n it('should not call captureException when wizard succeeds', async () => {\n const testArgs = { integration: Integration.nextjs };\n\n mockRunNextjsWizard.mockResolvedValue(undefined);\n\n await runWizard(testArgs);\n\n expect(mockAnalytics.captureException).not.toHaveBeenCalled();\n expect(mockAnalytics.shutdown).not.toHaveBeenCalled();\n });\n});\n"]}
|
|
@@ -31,7 +31,7 @@ async function runAstroWizard(options) {
|
|
|
31
31
|
if (astroVersion) {
|
|
32
32
|
analytics_1.analytics.setTag('astro-version', astroVersion);
|
|
33
33
|
}
|
|
34
|
-
const { projectApiKey,
|
|
34
|
+
const { projectApiKey, accessToken, host, projectId } = await (0, clack_utils_1.getOrAskForProjectData)({
|
|
35
35
|
...options,
|
|
36
36
|
cloudRegion,
|
|
37
37
|
});
|
|
@@ -49,16 +49,18 @@ async function runAstroWizard(options) {
|
|
|
49
49
|
integration: constants_1.Integration.astro,
|
|
50
50
|
relevantFiles,
|
|
51
51
|
documentation: installationDocumentation,
|
|
52
|
-
|
|
52
|
+
accessToken,
|
|
53
53
|
cloudRegion,
|
|
54
|
+
projectId,
|
|
54
55
|
});
|
|
55
56
|
await (0, file_utils_1.generateFileChangesForIntegration)({
|
|
56
57
|
integration: constants_1.Integration.astro,
|
|
57
58
|
filesToChange,
|
|
58
|
-
|
|
59
|
+
accessToken,
|
|
59
60
|
installDir: options.installDir,
|
|
60
61
|
documentation: installationDocumentation,
|
|
61
62
|
cloudRegion,
|
|
63
|
+
projectId,
|
|
62
64
|
});
|
|
63
65
|
await (0, steps_1.runPrettierStep)({
|
|
64
66
|
installDir: options.installDir,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro-wizard.js","sourceRoot":"","sources":["../../../src/astro/astro-wizard.ts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BAAgB;QAChB,eAAe,EAAE,EAAE;KACpB,CAAC,CAAC;IAEH,eAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAE1B,MAAM,qBAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/* eslint-disable max-lines */\n\nimport {\n abort,\n askForAIConsent,\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n printWelcome,\n} from '../utils/clack-utils';\nimport { getPackageVersion } from '../utils/package-json';\nimport clack from '../utils/clack';\nimport { Integration } from '../lib/constants';\nimport { getAstroDocumentation } from './docs';\nimport { analytics } from '../utils/analytics';\nimport {\n generateFileChangesForIntegration,\n getFilesToChange,\n getRelevantFilesForIntegration,\n} from '../utils/file-utils';\nimport type { WizardOptions } from '../utils/types';\nimport { askForCloudRegion } from '../utils/clack-utils';\nimport { getOutroMessage } from '../lib/messages';\nimport {\n addEditorRulesStep,\n addMCPServerToClientsStep,\n runPrettierStep,\n} from '../steps';\n\nexport async function runAstroWizard(options: WizardOptions): Promise<void> {\n printWelcome({\n wizardName: 'PostHog Astro wizard',\n });\n\n const aiConsent = await askForAIConsent(options);\n\n if (!aiConsent) {\n await abort(\n 'The Astro wizard requires AI to get setup right now. Please view the docs to setup Astro manually instead: https://posthog.com/docs/libraries/js',\n 0,\n );\n }\n\n const cloudRegion = options.cloudRegion ?? (await askForCloudRegion());\n\n await confirmContinueIfNoOrDirtyGitRepo(options);\n\n const packageJson = await getPackageDotJson(options);\n\n await ensurePackageIsInstalled(packageJson, 'astro', 'Astro');\n\n const astroVersion = getPackageVersion('astro', packageJson);\n\n if (astroVersion) {\n analytics.setTag('astro-version', astroVersion);\n }\n\n const { projectApiKey, accessToken, host, projectId } =\n await getOrAskForProjectData({\n ...options,\n cloudRegion,\n });\n\n clack.log.info('Heading to include the PostHogSnippet in your Astro project');\n\n const relevantFiles = await getRelevantFilesForIntegration({\n installDir: options.installDir,\n integration: Integration.astro,\n });\n\n const installationDocumentation = getAstroDocumentation({\n projectApiKey,\n host,\n });\n\n clack.log.info('Reviewing PostHog documentation for Astro');\n\n const filesToChange = await getFilesToChange({\n integration: Integration.astro,\n relevantFiles,\n documentation: installationDocumentation,\n accessToken,\n cloudRegion,\n projectId,\n });\n\n await generateFileChangesForIntegration({\n integration: Integration.astro,\n filesToChange,\n accessToken,\n installDir: options.installDir,\n documentation: installationDocumentation,\n cloudRegion,\n projectId,\n });\n\n await runPrettierStep({\n installDir: options.installDir,\n integration: Integration.astro,\n });\n\n const addedEditorRules = await addEditorRulesStep({\n installDir: options.installDir,\n rulesName: 'astro-rules.md',\n integration: Integration.astro,\n });\n\n await addMCPServerToClientsStep({\n cloudRegion,\n integration: Integration.astro,\n });\n\n const outroMessage = getOutroMessage({\n options,\n integration: Integration.astro,\n cloudRegion,\n addedEditorRules,\n uploadedEnvVars: [],\n });\n\n clack.outro(outroMessage);\n\n await analytics.shutdown('success');\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared agent interface for PostHog wizards
|
|
3
|
+
* Provides common agent initialization and event handling
|
|
4
|
+
*/
|
|
5
|
+
import { Agent } from '@posthog/agent';
|
|
6
|
+
import clack from '../utils/clack';
|
|
7
|
+
import type { WizardOptions } from '../utils/types';
|
|
8
|
+
export type AgentConfig = {
|
|
9
|
+
workingDirectory: string;
|
|
10
|
+
posthogMcpUrl: string;
|
|
11
|
+
posthogApiKey: string;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Initialize a PostHog Agent instance with the provided configuration
|
|
16
|
+
*/
|
|
17
|
+
export declare function initializeAgent(config: AgentConfig, options: WizardOptions, spinner: ReturnType<typeof clack.spinner>): Agent;
|
|
18
|
+
/**
|
|
19
|
+
* Execute an agent with the provided prompt and options
|
|
20
|
+
* Handles the full lifecycle: spinner, execution, error handling
|
|
21
|
+
*/
|
|
22
|
+
export declare function runAgent(agent: Agent, prompt: string, options: WizardOptions, spinner: ReturnType<typeof clack.spinner>, config?: {
|
|
23
|
+
estimatedDurationMinutes?: number;
|
|
24
|
+
spinnerMessage?: string;
|
|
25
|
+
successMessage?: string;
|
|
26
|
+
errorMessage?: string;
|
|
27
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared agent interface for PostHog wizards
|
|
4
|
+
* Provides common agent initialization and event handling
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.initializeAgent = initializeAgent;
|
|
11
|
+
exports.runAgent = runAgent;
|
|
12
|
+
// @ts-ignore - posthog-agent is ESM, wizard is CommonJS. Works at runtime via local link.
|
|
13
|
+
const agent_1 = require("@posthog/agent");
|
|
14
|
+
const clack_1 = __importDefault(require("../utils/clack"));
|
|
15
|
+
const debug_1 = require("../utils/debug");
|
|
16
|
+
const analytics_1 = require("../utils/analytics");
|
|
17
|
+
const constants_1 = require("./constants");
|
|
18
|
+
// TODO: Remove these if/when posthog/agent exports an enum for events
|
|
19
|
+
const EventType = {
|
|
20
|
+
RAW_SDK_EVENT: 'raw_sdk_event',
|
|
21
|
+
TOKEN: 'token',
|
|
22
|
+
TOOL_CALL: 'tool_call',
|
|
23
|
+
TOOL_RESULT: 'tool_result',
|
|
24
|
+
ERROR: 'error',
|
|
25
|
+
DONE: 'done',
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Initialize a PostHog Agent instance with the provided configuration
|
|
29
|
+
*/
|
|
30
|
+
function initializeAgent(config, options, spinner) {
|
|
31
|
+
clack_1.default.log.step('Initializing PostHog agent...');
|
|
32
|
+
try {
|
|
33
|
+
const agentConfig = {
|
|
34
|
+
workingDirectory: config.workingDirectory,
|
|
35
|
+
posthogMcpUrl: config.posthogMcpUrl,
|
|
36
|
+
posthogApiKey: config.posthogApiKey,
|
|
37
|
+
onEvent: (event) => {
|
|
38
|
+
handleAgentEvent(event, options, spinner);
|
|
39
|
+
},
|
|
40
|
+
debug: config.debug ?? false,
|
|
41
|
+
};
|
|
42
|
+
if (options.debug) {
|
|
43
|
+
(0, debug_1.debug)('Agent config:', {
|
|
44
|
+
workingDirectory: agentConfig.workingDirectory,
|
|
45
|
+
posthogMcpUrl: agentConfig.posthogMcpUrl,
|
|
46
|
+
posthogApiKeyPresent: !!agentConfig.posthogApiKey,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const agent = new agent_1.Agent(agentConfig);
|
|
50
|
+
clack_1.default.log.success("Agent initialized. Let's get cooking!");
|
|
51
|
+
return agent;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
clack_1.default.log.error(`Failed to initialize agent: ${error.message}`);
|
|
55
|
+
(0, debug_1.debug)('Agent initialization error:', error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Handle agent events and provide user feedback
|
|
61
|
+
* This function processes events from the agent SDK and provides appropriate
|
|
62
|
+
* user feedback through the CLI spinner and logging
|
|
63
|
+
*/
|
|
64
|
+
function handleAgentEvent(event, options, spinner) {
|
|
65
|
+
if (options.debug) {
|
|
66
|
+
(0, debug_1.debug)(`Event type: ${event.type}`, JSON.stringify(event, null, 2));
|
|
67
|
+
}
|
|
68
|
+
// Only show [STATUS] events to the user - everything else goes to debug log
|
|
69
|
+
switch (event.type) {
|
|
70
|
+
case EventType.RAW_SDK_EVENT:
|
|
71
|
+
if (event.sdkMessage?.type === 'assistant') {
|
|
72
|
+
const message = event.sdkMessage.message;
|
|
73
|
+
if (message?.content && Array.isArray(message.content)) {
|
|
74
|
+
const textContent = message.content
|
|
75
|
+
.filter((block) => block.type === 'text')
|
|
76
|
+
.map((block) => block.text)
|
|
77
|
+
.join('\n');
|
|
78
|
+
// Check if the text contains a [STATUS] marker
|
|
79
|
+
const statusMatch = textContent.match(/^.*\[STATUS\]\s*(.+?)$/m);
|
|
80
|
+
if (statusMatch) {
|
|
81
|
+
// Stop spinner, log the status step, restart spinner
|
|
82
|
+
// This creates the progress list as the agent proceeds
|
|
83
|
+
spinner.stop(statusMatch[1].trim());
|
|
84
|
+
spinner.start('Integrating PostHog...');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case EventType.TOKEN:
|
|
90
|
+
if (options.debug) {
|
|
91
|
+
(0, debug_1.debug)(event.content);
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case EventType.TOOL_CALL:
|
|
95
|
+
if (options.debug) {
|
|
96
|
+
(0, debug_1.debug)(`Tool: ${event.toolName}`);
|
|
97
|
+
(0, debug_1.debug)(' Args:', JSON.stringify(event.args, null, 2));
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case EventType.TOOL_RESULT:
|
|
101
|
+
if (options.debug) {
|
|
102
|
+
(0, debug_1.debug)(`✅ ${event.toolName} completed`);
|
|
103
|
+
const resultStr = typeof event.result === 'string'
|
|
104
|
+
? event.result
|
|
105
|
+
: JSON.stringify(event.result, null, 2);
|
|
106
|
+
const truncated = resultStr.length > 500
|
|
107
|
+
? `${resultStr.substring(0, 500)}...`
|
|
108
|
+
: resultStr;
|
|
109
|
+
(0, debug_1.debug)(' Result:', truncated);
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
case EventType.ERROR:
|
|
113
|
+
// Always show errors to user
|
|
114
|
+
clack_1.default.log.error(`Error: ${event.message}`);
|
|
115
|
+
if (options.debug && event.error) {
|
|
116
|
+
(0, debug_1.debug)('Error details:', event.error);
|
|
117
|
+
}
|
|
118
|
+
if (event.error instanceof Error) {
|
|
119
|
+
analytics_1.analytics.captureException(event.error, {
|
|
120
|
+
event_type: event.type,
|
|
121
|
+
message: event.message,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case EventType.DONE:
|
|
126
|
+
if (event.durationMs) {
|
|
127
|
+
if (options.debug) {
|
|
128
|
+
(0, debug_1.debug)(`Completed in ${Math.round(event.durationMs / 1000)}s`);
|
|
129
|
+
}
|
|
130
|
+
analytics_1.analytics.capture(constants_1.WIZARD_INTERACTION_EVENT_NAME, {
|
|
131
|
+
action: 'agent integration completed',
|
|
132
|
+
duration_ms: event.durationMs,
|
|
133
|
+
duration_seconds: Math.round(event.durationMs / 1000),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Execute an agent with the provided prompt and options
|
|
141
|
+
* Handles the full lifecycle: spinner, execution, error handling
|
|
142
|
+
*/
|
|
143
|
+
async function runAgent(agent, prompt, options, spinner, config) {
|
|
144
|
+
const { estimatedDurationMinutes = 8, spinnerMessage = 'Customizing your PostHog setup...', successMessage = 'PostHog integration complete', errorMessage = 'Integration failed', } = config ?? {};
|
|
145
|
+
clack_1.default.log.step(`This whole process should take about ${estimatedDurationMinutes} minutes including error checking and fixes.\n\nGrab some coffee!`);
|
|
146
|
+
spinner.start(spinnerMessage);
|
|
147
|
+
try {
|
|
148
|
+
await agent.run(prompt, {
|
|
149
|
+
repositoryPath: options.installDir,
|
|
150
|
+
permissionMode: agent_1.PermissionMode.ACCEPT_EDITS,
|
|
151
|
+
});
|
|
152
|
+
spinner.stop(successMessage);
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
spinner.stop(errorMessage);
|
|
156
|
+
clack_1.default.log.error(`Error: ${error.message}`);
|
|
157
|
+
(0, debug_1.debug)('Full error:', error);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=agent-interface.js.map
|
|
@@ -0,0 +1 @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AAE,CAAC;IAEjB,eAAK,CAAC,GAAG,CAAC,IAAI,CACZ,wCAAwC,wBAAwB,mEAAmE,CACpI,CAAC;IAEF,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAE9B,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE;YACtB,cAAc,EAAE,OAAO,CAAC,UAAU;YAClC,cAAc,EAAE,sBAAc,CAAC,YAAY;SAC5C,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3B,eAAK,CAAC,GAAG,CAAC,KAAK,CAAC,UAAW,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,IAAA,aAAK,EAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QAC5B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/**\n * Shared agent interface for PostHog wizards\n * Provides common agent initialization and event handling\n */\n\n// @ts-ignore - posthog-agent is ESM, wizard is CommonJS. Works at runtime via local link.\nimport { Agent, PermissionMode, type AgentEvent } from '@posthog/agent';\nimport clack from '../utils/clack';\nimport { debug } from '../utils/debug';\nimport type { WizardOptions } from '../utils/types';\nimport { analytics } from '../utils/analytics';\nimport { WIZARD_INTERACTION_EVENT_NAME } from './constants';\n\n// TODO: Remove these if/when posthog/agent exports an enum for events\nconst EventType = {\n RAW_SDK_EVENT: 'raw_sdk_event',\n TOKEN: 'token',\n TOOL_CALL: 'tool_call',\n TOOL_RESULT: 'tool_result',\n ERROR: 'error',\n DONE: 'done',\n} as const;\n\nexport type AgentConfig = {\n workingDirectory: string;\n posthogMcpUrl: string;\n posthogApiKey: string;\n debug?: boolean;\n};\n\n/**\n * Initialize a PostHog Agent instance with the provided configuration\n */\nexport function initializeAgent(\n config: AgentConfig,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n): Agent {\n clack.log.step('Initializing PostHog agent...');\n\n try {\n const agentConfig = {\n workingDirectory: config.workingDirectory,\n posthogMcpUrl: config.posthogMcpUrl,\n posthogApiKey: config.posthogApiKey,\n onEvent: (event: AgentEvent) => {\n handleAgentEvent(event, options, spinner);\n },\n debug: config.debug ?? false,\n };\n\n if (options.debug) {\n debug('Agent config:', {\n workingDirectory: agentConfig.workingDirectory,\n posthogMcpUrl: agentConfig.posthogMcpUrl,\n posthogApiKeyPresent: !!agentConfig.posthogApiKey,\n });\n }\n\n const agent = new Agent(agentConfig);\n clack.log.success(\"Agent initialized. Let's get cooking!\");\n return agent;\n } catch (error) {\n clack.log.error(`Failed to initialize agent: ${(error as Error).message}`);\n debug('Agent initialization error:', error);\n throw error;\n }\n}\n\n/**\n * Handle agent events and provide user feedback\n * This function processes events from the agent SDK and provides appropriate\n * user feedback through the CLI spinner and logging\n */\nfunction handleAgentEvent(\n event: AgentEvent,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n): void {\n if (options.debug) {\n debug(`Event type: ${event.type}`, JSON.stringify(event, null, 2));\n }\n\n // Only show [STATUS] events to the user - everything else goes to debug log\n switch (event.type) {\n case EventType.RAW_SDK_EVENT:\n if (event.sdkMessage?.type === 'assistant') {\n const message = event.sdkMessage.message;\n if (message?.content && Array.isArray(message.content)) {\n const textContent = message.content\n .filter((block: any) => block.type === 'text')\n .map((block: any) => block.text)\n .join('\\n');\n\n // Check if the text contains a [STATUS] marker\n const statusMatch = textContent.match(/^.*\\[STATUS\\]\\s*(.+?)$/m);\n if (statusMatch) {\n // Stop spinner, log the status step, restart spinner\n // This creates the progress list as the agent proceeds\n spinner.stop(statusMatch[1].trim());\n spinner.start('Integrating PostHog...');\n }\n }\n }\n break;\n\n case EventType.TOKEN:\n if (options.debug) {\n debug(event.content);\n }\n break;\n\n case EventType.TOOL_CALL:\n if (options.debug) {\n debug(`Tool: ${event.toolName}`);\n debug(' Args:', JSON.stringify(event.args, null, 2));\n }\n break;\n\n case EventType.TOOL_RESULT:\n if (options.debug) {\n debug(`✅ ${event.toolName} completed`);\n const resultStr: string =\n typeof event.result === 'string'\n ? event.result\n : JSON.stringify(event.result, null, 2);\n const truncated =\n resultStr.length > 500\n ? `${resultStr.substring(0, 500)}...`\n : resultStr;\n debug(' Result:', truncated);\n }\n break;\n\n case EventType.ERROR:\n // Always show errors to user\n clack.log.error(`Error: ${event.message}`);\n if (options.debug && event.error) {\n debug('Error details:', event.error);\n }\n if (event.error instanceof Error) {\n analytics.captureException(event.error, {\n event_type: event.type,\n message: event.message,\n });\n }\n break;\n\n case EventType.DONE:\n if (event.durationMs) {\n if (options.debug) {\n debug(`Completed in ${Math.round(event.durationMs / 1000)}s`);\n }\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'agent integration completed',\n duration_ms: event.durationMs,\n duration_seconds: Math.round(event.durationMs / 1000),\n });\n }\n break;\n }\n}\n\n/**\n * Execute an agent with the provided prompt and options\n * Handles the full lifecycle: spinner, execution, error handling\n */\nexport async function runAgent(\n agent: Agent,\n prompt: string,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n config?: {\n estimatedDurationMinutes?: number;\n spinnerMessage?: string;\n successMessage?: string;\n errorMessage?: string;\n },\n): Promise<void> {\n const {\n estimatedDurationMinutes = 8,\n spinnerMessage = 'Customizing your PostHog setup...',\n successMessage = 'PostHog integration complete',\n errorMessage = 'Integration failed',\n } = config ?? {};\n\n clack.log.step(\n `This whole process should take about ${estimatedDurationMinutes} minutes including error checking and fixes.\\n\\nGrab some coffee!`,\n );\n\n spinner.start(spinnerMessage);\n\n try {\n await agent.run(prompt, {\n repositoryPath: options.installDir,\n permissionMode: PermissionMode.ACCEPT_EDITS,\n });\n spinner.stop(successMessage);\n } catch (error) {\n spinner.stop(errorMessage);\n clack.log.error(`Error: ${(error as Error).message}`);\n debug('Full error:', error);\n throw error;\n }\n}\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ApiUserSchema: z.ZodObject<{
|
|
3
|
+
distinct_id: z.ZodString;
|
|
4
|
+
organizations: z.ZodArray<z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
id: string;
|
|
8
|
+
}, {
|
|
9
|
+
id: string;
|
|
10
|
+
}>, "many">;
|
|
11
|
+
team: z.ZodObject<{
|
|
12
|
+
id: z.ZodNumber;
|
|
13
|
+
organization: z.ZodString;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
id: number;
|
|
16
|
+
organization: string;
|
|
17
|
+
}, {
|
|
18
|
+
id: number;
|
|
19
|
+
organization: string;
|
|
20
|
+
}>;
|
|
21
|
+
organization: z.ZodObject<{
|
|
22
|
+
id: z.ZodString;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
id: string;
|
|
25
|
+
}, {
|
|
26
|
+
id: string;
|
|
27
|
+
}>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
team: {
|
|
30
|
+
id: number;
|
|
31
|
+
organization: string;
|
|
32
|
+
};
|
|
33
|
+
distinct_id: string;
|
|
34
|
+
organizations: {
|
|
35
|
+
id: string;
|
|
36
|
+
}[];
|
|
37
|
+
organization: {
|
|
38
|
+
id: string;
|
|
39
|
+
};
|
|
40
|
+
}, {
|
|
41
|
+
team: {
|
|
42
|
+
id: number;
|
|
43
|
+
organization: string;
|
|
44
|
+
};
|
|
45
|
+
distinct_id: string;
|
|
46
|
+
organizations: {
|
|
47
|
+
id: string;
|
|
48
|
+
}[];
|
|
49
|
+
organization: {
|
|
50
|
+
id: string;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
export declare const ApiProjectSchema: z.ZodObject<{
|
|
54
|
+
id: z.ZodNumber;
|
|
55
|
+
uuid: z.ZodString;
|
|
56
|
+
organization: z.ZodString;
|
|
57
|
+
api_token: z.ZodString;
|
|
58
|
+
name: z.ZodString;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
id: number;
|
|
61
|
+
organization: string;
|
|
62
|
+
uuid: string;
|
|
63
|
+
api_token: string;
|
|
64
|
+
name: string;
|
|
65
|
+
}, {
|
|
66
|
+
id: number;
|
|
67
|
+
organization: string;
|
|
68
|
+
uuid: string;
|
|
69
|
+
api_token: string;
|
|
70
|
+
name: string;
|
|
71
|
+
}>;
|
|
72
|
+
export type ApiUser = z.infer<typeof ApiUserSchema>;
|
|
73
|
+
export type ApiProject = z.infer<typeof ApiProjectSchema>;
|
|
74
|
+
export declare function fetchUserData(accessToken: string, baseUrl: string): Promise<ApiUser>;
|
|
75
|
+
export declare function fetchProjectData(accessToken: string, projectId: number, baseUrl: string): Promise<ApiProject>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ApiProjectSchema = exports.ApiUserSchema = void 0;
|
|
7
|
+
exports.fetchUserData = fetchUserData;
|
|
8
|
+
exports.fetchProjectData = fetchProjectData;
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const analytics_1 = require("../utils/analytics");
|
|
12
|
+
exports.ApiUserSchema = zod_1.z.object({
|
|
13
|
+
distinct_id: zod_1.z.string(),
|
|
14
|
+
organizations: zod_1.z.array(zod_1.z.object({
|
|
15
|
+
id: zod_1.z.string().uuid(),
|
|
16
|
+
})),
|
|
17
|
+
team: zod_1.z.object({
|
|
18
|
+
id: zod_1.z.number(),
|
|
19
|
+
organization: zod_1.z.string().uuid(),
|
|
20
|
+
}),
|
|
21
|
+
organization: zod_1.z.object({
|
|
22
|
+
id: zod_1.z.string().uuid(),
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
exports.ApiProjectSchema = zod_1.z.object({
|
|
26
|
+
id: zod_1.z.number(),
|
|
27
|
+
uuid: zod_1.z.string().uuid(),
|
|
28
|
+
organization: zod_1.z.string().uuid(),
|
|
29
|
+
api_token: zod_1.z.string(),
|
|
30
|
+
name: zod_1.z.string(),
|
|
31
|
+
});
|
|
32
|
+
class ApiError extends Error {
|
|
33
|
+
statusCode;
|
|
34
|
+
endpoint;
|
|
35
|
+
constructor(message, statusCode, endpoint) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.statusCode = statusCode;
|
|
38
|
+
this.endpoint = endpoint;
|
|
39
|
+
this.name = 'ApiError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function fetchUserData(accessToken, baseUrl) {
|
|
43
|
+
try {
|
|
44
|
+
const response = await axios_1.default.get(`${baseUrl}/api/users/@me/`, {
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: `Bearer ${accessToken}`,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return exports.ApiUserSchema.parse(response.data);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const apiError = handleApiError(error, 'fetch user data');
|
|
53
|
+
analytics_1.analytics.captureException(apiError, {
|
|
54
|
+
endpoint: '/api/users/@me/',
|
|
55
|
+
baseUrl,
|
|
56
|
+
});
|
|
57
|
+
throw apiError;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function fetchProjectData(accessToken, projectId, baseUrl) {
|
|
61
|
+
try {
|
|
62
|
+
const response = await axios_1.default.get(`${baseUrl}/api/projects/${projectId}/`, {
|
|
63
|
+
headers: {
|
|
64
|
+
Authorization: `Bearer ${accessToken}`,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
return exports.ApiProjectSchema.parse(response.data);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const apiError = handleApiError(error, 'fetch project data');
|
|
71
|
+
analytics_1.analytics.captureException(apiError, {
|
|
72
|
+
endpoint: `/api/projects/${projectId}/`,
|
|
73
|
+
baseUrl,
|
|
74
|
+
projectId,
|
|
75
|
+
});
|
|
76
|
+
throw apiError;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function handleApiError(error, operation) {
|
|
80
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
81
|
+
const axiosError = error;
|
|
82
|
+
const status = axiosError.response?.status;
|
|
83
|
+
const detail = axiosError.response?.data?.detail;
|
|
84
|
+
const endpoint = axiosError.config?.url;
|
|
85
|
+
if (status === 401) {
|
|
86
|
+
return new ApiError(`Authentication failed while trying to ${operation}`, status, endpoint);
|
|
87
|
+
}
|
|
88
|
+
if (status === 403) {
|
|
89
|
+
return new ApiError(`Access denied while trying to ${operation}`, status, endpoint);
|
|
90
|
+
}
|
|
91
|
+
if (status === 404) {
|
|
92
|
+
return new ApiError(`Resource not found while trying to ${operation}`, status, endpoint);
|
|
93
|
+
}
|
|
94
|
+
const message = detail || `Failed to ${operation}`;
|
|
95
|
+
return new ApiError(message, status, endpoint);
|
|
96
|
+
}
|
|
97
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
98
|
+
return new ApiError(`Invalid response format while trying to ${operation}`);
|
|
99
|
+
}
|
|
100
|
+
return new ApiError(`Unexpected error while trying to ${operation}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/lib/api.ts"],"names":[],"mappings":";;;;;;AA0CA,sCAoBC;AAED,4CAsBC;AAtFD,kDAA0C;AAC1C,6BAAwB;AACxB,kDAA+C;AAElC,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,aAAa,EAAE,OAAC,C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AC;QAExC,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,OAAO,IAAI,QAAQ,CACjB,yCAAyC,SAAS,EAAE,EACpD,MAAM,EACN,QAAQ,CACT,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,OAAO,IAAI,QAAQ,CACjB,iCAAiC,SAAS,EAAE,EAC5C,MAAM,EACN,QAAQ,CACT,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,OAAO,IAAI,QAAQ,CACjB,sCAAsC,SAAS,EAAE,EACjD,MAAM,EACN,QAAQ,CACT,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,aAAa,SAAS,EAAE,CAAC;QACnD,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,KAAK,YAAY,OAAC,CAAC,QAAQ,EAAE,CAAC;QAChC,OAAO,IAAI,QAAQ,CAAC,2CAA2C,SAAS,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,IAAI,QAAQ,CACjB,oCAAoC,SAAS,KAC3C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAC3C,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import axios, { AxiosError } from 'axios';\nimport { z } from 'zod';\nimport { analytics } from '../utils/analytics';\n\nexport const ApiUserSchema = z.object({\n distinct_id: z.string(),\n organizations: z.array(\n z.object({\n id: z.string().uuid(),\n }),\n ),\n team: z.object({\n id: z.number(),\n organization: z.string().uuid(),\n }),\n organization: z.object({\n id: z.string().uuid(),\n }),\n});\n\nexport const ApiProjectSchema = z.object({\n id: z.number(),\n uuid: z.string().uuid(),\n organization: z.string().uuid(),\n api_token: z.string(),\n name: z.string(),\n});\n\nexport type ApiUser = z.infer<typeof ApiUserSchema>;\nexport type ApiProject = z.infer<typeof ApiProjectSchema>;\n\nclass ApiError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n public readonly endpoint?: string,\n ) {\n super(message);\n this.name = 'ApiError';\n }\n}\n\nexport async function fetchUserData(\n accessToken: string,\n baseUrl: string,\n): Promise<ApiUser> {\n try {\n const response = await axios.get(`${baseUrl}/api/users/@me/`, {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n return ApiUserSchema.parse(response.data);\n } catch (error) {\n const apiError = handleApiError(error, 'fetch user data');\n analytics.captureException(apiError, {\n endpoint: '/api/users/@me/',\n baseUrl,\n });\n throw apiError;\n }\n}\n\nexport async function fetchProjectData(\n accessToken: string,\n projectId: number,\n baseUrl: string,\n): Promise<ApiProject> {\n try {\n const response = await axios.get(`${baseUrl}/api/projects/${projectId}/`, {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n return ApiProjectSchema.parse(response.data);\n } catch (error) {\n const apiError = handleApiError(error, 'fetch project data');\n analytics.captureException(apiError, {\n endpoint: `/api/projects/${projectId}/`,\n baseUrl,\n projectId,\n });\n throw apiError;\n }\n}\n\nfunction handleApiError(error: unknown, operation: string): ApiError {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError<{ detail?: string }>;\n const status = axiosError.response?.status;\n const detail = axiosError.response?.data?.detail;\n const endpoint = axiosError.config?.url;\n\n if (status === 401) {\n return new ApiError(\n `Authentication failed while trying to ${operation}`,\n status,\n endpoint,\n );\n }\n\n if (status === 403) {\n return new ApiError(\n `Access denied while trying to ${operation}`,\n status,\n endpoint,\n );\n }\n\n if (status === 404) {\n return new ApiError(\n `Resource not found while trying to ${operation}`,\n status,\n endpoint,\n );\n }\n\n const message = detail || `Failed to ${operation}`;\n return new ApiError(message, status, endpoint);\n }\n\n if (error instanceof z.ZodError) {\n return new ApiError(`Invalid response format while trying to ${operation}`);\n }\n\n return new ApiError(\n `Unexpected error while trying to ${operation}: ${\n error instanceof Error ? error.message : 'Unknown error'\n }`,\n );\n}\n"]}
|
|
@@ -5,6 +5,13 @@ export declare enum Integration {
|
|
|
5
5
|
reactNative = "react-native",
|
|
6
6
|
astro = "astro"
|
|
7
7
|
}
|
|
8
|
+
export declare enum FeatureFlagDefinition {
|
|
9
|
+
NextV2 = "wizard-next-v2"
|
|
10
|
+
}
|
|
11
|
+
export declare enum WizardVariant {
|
|
12
|
+
Legacy = "legacy",
|
|
13
|
+
Agent = "agent"
|
|
14
|
+
}
|
|
8
15
|
export declare function getIntegrationDescription(type: string): string;
|
|
9
16
|
type IntegrationChoice = {
|
|
10
17
|
name: string;
|
|
@@ -23,4 +30,9 @@ export declare const DEFAULT_HOST_URL: string;
|
|
|
23
30
|
export declare const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = "sTMFPsFhdP1Ssg";
|
|
24
31
|
export declare const ANALYTICS_HOST_URL = "https://internal-j.posthog.com";
|
|
25
32
|
export declare const DUMMY_PROJECT_API_KEY = "_YOUR_POSTHOG_PROJECT_API_KEY_";
|
|
33
|
+
export declare const POSTHOG_US_CLIENT_ID = "c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM";
|
|
34
|
+
export declare const POSTHOG_EU_CLIENT_ID = "bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy";
|
|
35
|
+
export declare const POSTHOG_DEV_CLIENT_ID = "DC5uRLVbGI02YQ82grxgnK6Qn12SXWpCqdPb60oZ";
|
|
36
|
+
export declare const OAUTH_PORT = 8239;
|
|
37
|
+
export declare const WIZARD_INTERACTION_EVENT_NAME = "wizard interaction";
|
|
26
38
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DUMMY_PROJECT_API_KEY = exports.ANALYTICS_HOST_URL = exports.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = exports.DEFAULT_HOST_URL = exports.ISSUES_URL = exports.DEFAULT_URL = exports.DEBUG = exports.IS_DEV = exports.Integration = void 0;
|
|
3
|
+
exports.WIZARD_INTERACTION_EVENT_NAME = exports.OAUTH_PORT = exports.POSTHOG_DEV_CLIENT_ID = exports.POSTHOG_EU_CLIENT_ID = exports.POSTHOG_US_CLIENT_ID = exports.DUMMY_PROJECT_API_KEY = exports.ANALYTICS_HOST_URL = exports.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = exports.DEFAULT_HOST_URL = exports.ISSUES_URL = exports.DEFAULT_URL = exports.DEBUG = exports.IS_DEV = exports.WizardVariant = exports.FeatureFlagDefinition = exports.Integration = void 0;
|
|
4
4
|
exports.getIntegrationDescription = getIntegrationDescription;
|
|
5
5
|
exports.getIntegrationChoices = getIntegrationChoices;
|
|
6
6
|
var Integration;
|
|
@@ -11,6 +11,15 @@ var Integration;
|
|
|
11
11
|
Integration["reactNative"] = "react-native";
|
|
12
12
|
Integration["astro"] = "astro";
|
|
13
13
|
})(Integration || (exports.Integration = Integration = {}));
|
|
14
|
+
var FeatureFlagDefinition;
|
|
15
|
+
(function (FeatureFlagDefinition) {
|
|
16
|
+
FeatureFlagDefinition["NextV2"] = "wizard-next-v2";
|
|
17
|
+
})(FeatureFlagDefinition || (exports.FeatureFlagDefinition = FeatureFlagDefinition = {}));
|
|
18
|
+
var WizardVariant;
|
|
19
|
+
(function (WizardVariant) {
|
|
20
|
+
WizardVariant["Legacy"] = "legacy";
|
|
21
|
+
WizardVariant["Agent"] = "agent";
|
|
22
|
+
})(WizardVariant || (exports.WizardVariant = WizardVariant = {}));
|
|
14
23
|
function getIntegrationDescription(type) {
|
|
15
24
|
switch (type) {
|
|
16
25
|
case Integration.nextjs:
|
|
@@ -45,4 +54,9 @@ exports.DEFAULT_HOST_URL = exports.IS_DEV
|
|
|
45
54
|
exports.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';
|
|
46
55
|
exports.ANALYTICS_HOST_URL = 'https://internal-j.posthog.com';
|
|
47
56
|
exports.DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';
|
|
57
|
+
exports.POSTHOG_US_CLIENT_ID = 'c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM';
|
|
58
|
+
exports.POSTHOG_EU_CLIENT_ID = 'bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy';
|
|
59
|
+
exports.POSTHOG_DEV_CLIENT_ID = 'DC5uRLVbGI02YQ82grxgnK6Qn12SXWpCqdPb60oZ';
|
|
60
|
+
exports.OAUTH_PORT = 8239;
|
|
61
|
+
exports.WIZARD_INTERACTION_EVENT_NAME = 'wizard interaction';
|
|
48
62
|
//# sourceMappingURL=constants.js.map
|