@posthog/wizard 1.8.3 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -81
- package/dist/bin.js +0 -6
- package/dist/bin.js.map +1 -1
- package/dist/src/lib/constants.d.ts +1 -1
- package/dist/src/lib/constants.js +1 -1
- package/dist/src/lib/constants.js.map +1 -1
- package/dist/src/nextjs/docs.js +6 -6
- package/dist/src/nextjs/docs.js.map +1 -1
- package/dist/src/nextjs/utils.js +0 -1
- package/dist/src/nextjs/utils.js.map +1 -1
- package/dist/src/utils/clack-utils.js +3 -5
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/query.d.ts +2 -3
- package/dist/src/utils/query.js +0 -13
- package/dist/src/utils/query.js.map +1 -1
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
> **⚠️ Experimental:** This wizard is still in an experimental phase. If you
|
|
6
|
-
> have any feedback, please drop an email to **joshua** [at] **posthog** [dot]
|
|
6
|
+
> have any feedback, please drop an email to **joshua** [at] **posthog** [dot]
|
|
7
7
|
> **com**.
|
|
8
8
|
|
|
9
9
|
<h1>PostHog wizard ✨</h1>
|
|
@@ -17,14 +17,13 @@ To use the wizard, you can run it directly using:
|
|
|
17
17
|
npx @posthog/wizard
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Currently the wizard can be used for **React, NextJS, Svelte, Astro and React
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
Currently the wizard can be used for **React, NextJS, Svelte, Astro and React Native**
|
|
21
|
+
projects. If you have other integrations you would like the wizard to support,
|
|
22
|
+
please open a [GitHub issue](https://github.com/posthog/wizard/issues)!
|
|
23
23
|
|
|
24
24
|
## MCP Commands
|
|
25
25
|
|
|
26
|
-
The wizard also includes commands for managing PostHog MCP (Model Context
|
|
27
|
-
Protocol) servers:
|
|
26
|
+
The wizard also includes commands for managing PostHog MCP (Model Context Protocol) servers:
|
|
28
27
|
|
|
29
28
|
```bash
|
|
30
29
|
# Install PostHog MCP server to supported clients
|
|
@@ -38,17 +37,17 @@ npx @posthog/wizard mcp remove
|
|
|
38
37
|
|
|
39
38
|
The following CLI arguments are available:
|
|
40
39
|
|
|
41
|
-
| Option | Description
|
|
42
|
-
| ----------------- |
|
|
43
|
-
| `--help` | Show help
|
|
44
|
-
| `--version` | Show version number
|
|
45
|
-
| `--debug` | Enable verbose logging
|
|
46
|
-
| `--region` | PostHog cloud region (when not specified, prompts for selection)
|
|
47
|
-
| `--default` | Use default options for all prompts
|
|
48
|
-
| `--signup` | Create a new PostHog account during setup
|
|
49
|
-
| `--integration` | Integration to set up
|
|
50
|
-
| `--force-install` | Force install packages even if peer dependency checks fail
|
|
51
|
-
| `--install-dir` | Directory to install PostHog in
|
|
40
|
+
| Option | Description | Type | Default | Choices | Environment Variable |
|
|
41
|
+
| ----------------- | -------------------------------------------------------------------------- | ------- | ------------------------------- | ---------------------------------------------------- | --------------------------------- |
|
|
42
|
+
| `--help` | Show help | boolean | | | |
|
|
43
|
+
| `--version` | Show version number | boolean | | | |
|
|
44
|
+
| `--debug` | Enable verbose logging | boolean | `false` | | `POSTHOG_WIZARD_DEBUG` |
|
|
45
|
+
| `--region` | PostHog cloud region (when not specified, prompts for selection) | string | | "us", "eu" | `POSTHOG_WIZARD_REGION` |
|
|
46
|
+
| `--default` | Use default options for all prompts | boolean | `true` | | `POSTHOG_WIZARD_DEFAULT` |
|
|
47
|
+
| `--signup` | Create a new PostHog account during setup | boolean | `false` | | `POSTHOG_WIZARD_SIGNUP` |
|
|
48
|
+
| `--integration` | Integration to set up | string | | "nextjs", "astro", "react", "svelte", "react-native" | |
|
|
49
|
+
| `--force-install` | Force install packages even if peer dependency checks fail | boolean | `false` | | `POSTHOG_WIZARD_FORCE_INSTALL` |
|
|
50
|
+
| `--install-dir` | Directory to install PostHog in | string | | | `POSTHOG_WIZARD_INSTALL_DIR` |
|
|
52
51
|
|
|
53
52
|
> Note: A large amount of the scaffolding for this came from the amazing Sentry
|
|
54
53
|
> wizard, which you can find [here](https://github.com/getsentry/sentry-wizard)
|
|
@@ -56,65 +55,43 @@ The following CLI arguments are available:
|
|
|
56
55
|
|
|
57
56
|
# Steal this code
|
|
58
57
|
|
|
59
|
-
While the wizard works great on its own, we also find the approach used by this
|
|
60
|
-
project is
|
|
61
|
-
[a powerful way to improve AI agent coding sessions](https://posthog.com/blog/envoy-wizard-llm-agent).
|
|
62
|
-
Agents can run CLI tools, which means that conventional code like this can
|
|
63
|
-
participate in the AI revolution as well – with all the benefits and control
|
|
64
|
-
that conventional code implies.
|
|
58
|
+
While the wizard works great on its own, we also find the approach used by this project is [a powerful way to improve AI agent coding sessions](https://posthog.com/blog/envoy-wizard-llm-agent). Agents can run CLI tools, which means that conventional code like this can participate in the AI revolution as well – with all the benefits and control that conventional code implies.
|
|
65
59
|
|
|
66
|
-
If you want to use this code as a starting place for your own project, here's a
|
|
67
|
-
quick explainer on its structure.
|
|
60
|
+
If you want to use this code as a starting place for your own project, here's a quick explainer on its structure.
|
|
68
61
|
|
|
69
62
|
## Entrypoint: `run.ts`
|
|
70
63
|
|
|
71
|
-
The entrypoint for this tool is `run.ts`. Use this file to interpret arguments
|
|
72
|
-
and set up the general flow of the application.
|
|
64
|
+
The entrypoint for this tool is `run.ts`. Use this file to interpret arguments and set up the general flow of the application.
|
|
73
65
|
|
|
74
66
|
## Analytics
|
|
75
67
|
|
|
76
|
-
Did you know you can capture PostHog events even for smaller, supporting
|
|
77
|
-
products like a command line tool? `src/utils/analytics.ts` is a great example
|
|
78
|
-
of how to do it.
|
|
68
|
+
Did you know you can capture PostHog events even for smaller, supporting products like a command line tool? `src/utils/analytics.ts` is a great example of how to do it.
|
|
79
69
|
|
|
80
|
-
This file wraps `posthog-node` with some convenience functions to set up an
|
|
81
|
-
analytics session and log events. We can see the usage and outcomes of this
|
|
82
|
-
wizard alongside all of our other PostHog product data, and this is very
|
|
83
|
-
powerful. For example: we could show in-product surveys to people who have used
|
|
84
|
-
the wizard to improve the experience.
|
|
70
|
+
This file wraps `posthog-node` with some convenience functions to set up an analytics session and log events. We can see the usage and outcomes of this wizard alongside all of our other PostHog product data, and this is very powerful. For example: we could show in-product surveys to people who have used the wizard to improve the experience.
|
|
85
71
|
|
|
86
72
|
## Leave rules behind
|
|
87
73
|
|
|
88
|
-
Supporting agent sessions after we leave is important. There are plenty of ways
|
|
89
|
-
to break or misconfigure PostHog, so guarding against this is key.
|
|
74
|
+
Supporting agent sessions after we leave is important. There are plenty of ways to break or misconfigure PostHog, so guarding against this is key.
|
|
90
75
|
|
|
91
|
-
`src/utils/rules/add-editor-rules.ts` demonstrates how to dynamically construct
|
|
92
|
-
rules files and store them in the project's `.cursor/rules` directory.
|
|
76
|
+
`src/utils/rules/add-editor-rules.ts` demonstrates how to dynamically construct rules files and store them in the project's `.cursor/rules` directory.
|
|
93
77
|
|
|
94
78
|
## Prompts and LLM interactions
|
|
95
79
|
|
|
96
|
-
LLM agent sessions are
|
|
80
|
+
LLM agent sessions are *anti-deterministic*: really, anything can happen.
|
|
97
81
|
|
|
98
|
-
But using LLMs for code generation is really advantageous: they can interpret
|
|
99
|
-
existing code at scale and then modify it reliably.
|
|
82
|
+
But using LLMs for code generation is really advantageous: they can interpret existing code at scale and then modify it reliably.
|
|
100
83
|
|
|
101
|
-
|
|
84
|
+
*If* they are well prompted.
|
|
102
85
|
|
|
103
|
-
`src/lib/prompts.ts` demonstrates how to wrap a deterministic fence around a
|
|
104
|
-
chaotic process. Every wizard session gets the same prompt, tailored to the
|
|
105
|
-
specific files in the project.
|
|
86
|
+
`src/lib/prompts.ts` demonstrates how to wrap a deterministic fence around a chaotic process. Every wizard session gets the same prompt, tailored to the specific files in the project.
|
|
106
87
|
|
|
107
|
-
These prompts are channeled using `src/utils/query.ts` to an LLM interface we
|
|
108
|
-
host. This gives us more control: we can be certain of the model version and
|
|
109
|
-
provider which interpret the prompts and modify the files. This way, we can find
|
|
110
|
-
the right tools for the job and again, apply them consistently.
|
|
88
|
+
These prompts are channeled using `src/utils/query.ts` to an LLM interface we host. This gives us more control: we can be certain of the model version and provider which interpret the prompts and modify the files. This way, we can find the right tools for the job and again, apply them consistently.
|
|
111
89
|
|
|
112
90
|
This also allows us to pick up the bill on behalf of our customers.
|
|
113
91
|
|
|
114
|
-
When we make improvements to this process, these are available instantly to all
|
|
115
|
-
users of the wizard, no training delays or other ambiguity.
|
|
92
|
+
When we make improvements to this process, these are available instantly to all users of the wizard, no training delays or other ambiguity.
|
|
116
93
|
|
|
117
|
-
##
|
|
94
|
+
## Testing locally
|
|
118
95
|
|
|
119
96
|
Run:
|
|
120
97
|
|
|
@@ -122,52 +99,35 @@ Run:
|
|
|
122
99
|
pnpm try --install-dir=[a path]
|
|
123
100
|
```
|
|
124
101
|
|
|
102
|
+
|
|
125
103
|
To build and use the tool locally:
|
|
126
104
|
|
|
127
|
-
```bash
|
|
128
|
-
bin/build
|
|
129
105
|
```
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
command any time you make changes to the wizard's source code.
|
|
106
|
+
pnpm build
|
|
107
|
+
```
|
|
108
|
+
This compiles the TypeScript code and prepares the `dist` directory. Run this command any time you make changes to the wizard's source code.
|
|
133
109
|
|
|
134
110
|
```bash
|
|
135
111
|
pnpm link --global
|
|
136
112
|
```
|
|
113
|
+
This command makes your local version of the wizard available system-wide. You generally only need to do this once.
|
|
137
114
|
|
|
138
|
-
|
|
139
|
-
generally only need to do this once.
|
|
140
|
-
|
|
141
|
-
Then:
|
|
115
|
+
Then:
|
|
142
116
|
|
|
143
117
|
```bash
|
|
144
118
|
wizard [options]
|
|
145
119
|
```
|
|
146
|
-
|
|
147
120
|
The wizard will execute your last build.
|
|
148
121
|
|
|
149
|
-
##
|
|
150
|
-
|
|
151
|
-
To run unit tests, run:
|
|
122
|
+
## Publishing your tool
|
|
152
123
|
|
|
153
|
-
|
|
154
|
-
bin/test
|
|
155
|
-
```
|
|
124
|
+
To make your version of a tool usable with a one-line `npx` command:
|
|
156
125
|
|
|
157
|
-
|
|
126
|
+
1. Edit `package.json`, especially details like `name`, `version`
|
|
127
|
+
2. Run [`npm publish`](https://docs.npmjs.com/cli/v7/commands/npm-publish) from your project directory
|
|
128
|
+
3. Now you can run it with `npx yourpackagename`
|
|
158
129
|
|
|
159
|
-
```bash
|
|
160
|
-
bin/test-e2e
|
|
161
|
-
```
|
|
162
130
|
|
|
163
|
-
E2E tests are a bit more complicated to create and adjust due to to their mocked
|
|
164
|
-
LLM calls. See the `e2e-tests/README.md` for more information.
|
|
165
131
|
|
|
166
|
-
## Publishing your tool
|
|
167
132
|
|
|
168
|
-
To make your version of a tool usable with a one-line `npx` command:
|
|
169
133
|
|
|
170
|
-
1. Edit `package.json`, especially details like `name`, `version`
|
|
171
|
-
2. Run [`npm publish`](https://docs.npmjs.com/cli/v7/commands/npm-publish) from
|
|
172
|
-
your project directory
|
|
173
|
-
3. Now you can run it with `npx yourpackagename`
|
package/dist/bin.js
CHANGED
|
@@ -17,12 +17,6 @@ if (!(0, semver_1.satisfies)(process.version, NODE_VERSION_RANGE)) {
|
|
|
17
17
|
}
|
|
18
18
|
const mcp_1 = require("./src/mcp");
|
|
19
19
|
const run_1 = require("./src/run");
|
|
20
|
-
const server_1 = require("./e2e-tests/mocks/server");
|
|
21
|
-
if (process.env.NODE_ENV === 'test') {
|
|
22
|
-
server_1.server.listen({
|
|
23
|
-
onUnhandledRequest: 'bypass',
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
20
|
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
27
21
|
.env('POSTHOG_WIZARD')
|
|
28
22
|
// global options
|
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,2CAAw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;IAC3B,CAAC,EACD,GAAG,EAAE;QACH,KAAK,IAAA,kBAAY,GAAE,CAAC;IACtB,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';\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';\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('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 },\n (argv) => {\n const options = { ...argv };\n void runMCPInstall(\n options as unknown as { signup: boolean; region?: CloudRegion },\n );\n },\n )\n .command(\n 'remove',\n 'Remove PostHog MCP server from supported clients',\n (yargs) => {\n return yargs.options({});\n },\n () => {\n void runMCPRemove();\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"]}
|
|
@@ -15,7 +15,7 @@ export interface Args {
|
|
|
15
15
|
debug: boolean;
|
|
16
16
|
integration: Integration;
|
|
17
17
|
}
|
|
18
|
-
export declare const IS_DEV
|
|
18
|
+
export declare const IS_DEV = false;
|
|
19
19
|
export declare const DEBUG = false;
|
|
20
20
|
export declare const DEFAULT_URL: string;
|
|
21
21
|
export declare const ISSUES_URL = "https://github.com/posthog/wizard/issues";
|
|
@@ -33,7 +33,7 @@ function getIntegrationChoices() {
|
|
|
33
33
|
value: type,
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
|
-
exports.IS_DEV =
|
|
36
|
+
exports.IS_DEV = false;
|
|
37
37
|
exports.DEBUG = false;
|
|
38
38
|
exports.DEFAULT_URL = exports.IS_DEV
|
|
39
39
|
? 'http://localhost:8010'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAQA,8DAeC;AAOD,sDAKC;AAnCD,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,2CAA4B,CAAA;IAC5B,8BAAe,CAAA;AACjB,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,OAAO,CAAC;QACjB,KAAK,WAAW,CAAC,WAAW;YAC1B,OAAO,cAAc,CAAC;QACxB,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,QAAQ,CAAC;QAClB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,OAAO,CAAC;QACjB;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAOD,SAAgB,qBAAqB;IACnC,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,EAAE,yBAAyB,CAAC,IAAI,CAAC;QACrC,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC,CAAC;AACN,CAAC;AAOY,QAAA,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAQA,8DAeC;AAOD,sDAKC;AAnCD,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,2CAA4B,CAAA;IAC5B,8BAAe,CAAA;AACjB,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,OAAO,CAAC;QACjB,KAAK,WAAW,CAAC,WAAW;YAC1B,OAAO,cAAc,CAAC;QACxB,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,QAAQ,CAAC;QAClB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,OAAO,CAAC;QACjB;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAOD,SAAgB,qBAAqB;IACnC,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,EAAE,yBAAyB,CAAC,IAAI,CAAC;QACrC,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC,CAAC;AACN,CAAC;AAOY,QAAA,MAAM,GAAG,KAAK,CAAC;AAEf,QAAA,KAAK,GAAG,KAAK,CAAC;AAEd,QAAA,WAAW,GAAG,cAAM;IAC/B,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,wBAAwB,CAAC;AAChB,QAAA,UAAU,GAAG,0CAA0C,CAAC;AACxD,QAAA,gBAAgB,GAAG,cAAM;IACpC,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,0BAA0B,CAAC;AAClB,QAAA,0CAA0C,GAAG,gBAAgB,CAAC;AAC9D,QAAA,kBAAkB,GAAG,gCAAgC,CAAC;AACtD,QAAA,qBAAqB,GAAG,gCAAgC,CAAC","sourcesContent":["export enum Integration {\n nextjs = 'nextjs',\n react = 'react',\n svelte = 'svelte',\n reactNative = 'react-native',\n astro = 'astro',\n}\n\nexport function getIntegrationDescription(type: string): string {\n switch (type) {\n case Integration.nextjs:\n return 'Next.js';\n case Integration.react:\n return 'React';\n case Integration.reactNative:\n return 'React Native';\n case Integration.svelte:\n return 'Svelte';\n case Integration.astro:\n return 'Astro';\n default:\n throw new Error(`Unknown integration ${type}`);\n }\n}\n\ntype IntegrationChoice = {\n name: string;\n value: string;\n};\n\nexport function getIntegrationChoices(): IntegrationChoice[] {\n return Object.keys(Integration).map((type: string) => ({\n name: getIntegrationDescription(type),\n value: type,\n }));\n}\n\nexport interface Args {\n debug: boolean;\n integration: Integration;\n}\n\nexport const IS_DEV = false;\n\nexport const DEBUG = false;\n\nexport const DEFAULT_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.posthog.com';\nexport const ISSUES_URL = 'https://github.com/posthog/wizard/issues';\nexport const DEFAULT_HOST_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.i.posthog.com';\nexport const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';\nexport const ANALYTICS_HOST_URL = 'https://internal-t.posthog.com';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n"]}
|
package/dist/src/nextjs/docs.js
CHANGED
|
@@ -113,8 +113,8 @@ const nextConfig = {
|
|
|
113
113
|
destination: "${host}/:path*",
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
|
-
source: "/ingest/
|
|
117
|
-
destination: "${host}/
|
|
116
|
+
source: "/ingest/decide",
|
|
117
|
+
destination: "${host}/decide",
|
|
118
118
|
},
|
|
119
119
|
];
|
|
120
120
|
},
|
|
@@ -207,8 +207,8 @@ const nextConfig = {
|
|
|
207
207
|
destination: "${host}/:path*",
|
|
208
208
|
},
|
|
209
209
|
{
|
|
210
|
-
source: "/ingest/
|
|
211
|
-
destination: "${host}/
|
|
210
|
+
source: "/ingest/decide",
|
|
211
|
+
destination: "${host}/decide",
|
|
212
212
|
},
|
|
213
213
|
];
|
|
214
214
|
},
|
|
@@ -269,8 +269,8 @@ const nextConfig = {
|
|
|
269
269
|
destination: "${host}/:path*",
|
|
270
270
|
},
|
|
271
271
|
{
|
|
272
|
-
source: "/ingest/
|
|
273
|
-
destination: "${host}/
|
|
272
|
+
source: "/ingest/decide",
|
|
273
|
+
destination: "${host}/decide",
|
|
274
274
|
},
|
|
275
275
|
];
|
|
276
276
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/nextjs/docs.ts"],"names":[],"mappings":";;;AAAA,wCAAwE;AAEjE,MAAM,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;wBAGL,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;;;;kBAoBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;eAgB1B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2BxC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsC/B,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AAjIW,QAAA,sBAAsB,0BAiIjC;AAEK,MAAM,wBAAwB,GAAG,CAAC,EACvC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;aAEI,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;mCAElD,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;kBAiBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;gBAgBzB,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsC/B,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AApGW,QAAA,wBAAwB,4BAoGnC;AAEK,MAAM,mBAAmB,GAAG,CAAC,EAClC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;+BAEsB,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;gDAKlE,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IACrC;2CAEE,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IACrC;;;;;;;;;;;cAWY,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;wBAwBb,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AAtEW,QAAA,mBAAmB,uBAsE9B","sourcesContent":["import { getAssetHostFromHost, getUiHostFromHost } from '../utils/urls';\n\nexport const getNextjsAppRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: PostHogProvider.${\n language === 'typescript' ? 'tsx' : 'jsx'\n } (put it somewhere where client files are, like the components folder)\nLOCATION: Wherever other providers are, or the components folder\n==============================\nChanges:\n- Create a PostHogProvider component that will be imported into the layout file.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\n\"use client\"\n\nimport posthog from \"posthog-js\"\nimport { PostHogProvider as PHProvider, usePostHog } from \"posthog-js/react\"\nimport { Suspense, useEffect } from \"react\"\nimport { usePathname, useSearchParams } from \"next/navigation\"\n\nexport function PostHogProvider({ children }: { children: React.ReactNode }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return (\n <PHProvider client={posthog}>\n {children}\n </PHProvider>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: layout.${language === 'typescript' ? 'tsx' : 'jsx'}\nLOCATION: Wherever the root layout is\n==============================\nChanges:\n- Import the PostHogProvider from the providers file and wrap the app in it.\n\nExample:\n--------------------------------------------------\n// other imports\nimport { PostHogProvider } from \"LOCATION_OF_POSTHOG_PROVIDER\"\n\nexport default function RootLayout({ children }) {\n return (\n <html lang=\"en\">\n <body>\n <PostHogProvider>\n {/* other providers */}\n {children}\n {/* other providers */}\n </PostHogProvider>\n </body>\n </html>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: posthog.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: Wherever works best given the project structure\n==============================\nChanges:\n- Initialize the PostHog Node.js client\n\nExample:\n--------------------------------------------------\nimport { PostHog } from \"posthog-node\"\n\n// NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n })\n return posthogClient\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n {\n source: \"/ingest/flags\",\n destination: \"${host}/flags\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n\nexport const getNextjsPagesRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: _app.${language === 'typescript' ? 'tsx' : 'jsx'}\nLOCATION: Wherever the root _app.${\n language === 'typescript' ? 'tsx' : 'jsx'\n } file is\n==============================\nChanges:\n- Initialize PostHog in _app.js.\n- Wrap the application in PostHogProvider.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\nimport { useEffect } from \"react\"\nimport posthog from \"posthog-js\"\nimport { PostHogProvider } from \"posthog-js/react\"\n\nexport default function App({ Component, pageProps }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return (\n <PostHogProvider client={posthog}>\n <Component {...pageProps} />\n </PostHogProvider>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: posthog.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: Wherever works best given the project structure\n==============================\nChanges:\n- Initialize the PostHog Node.js client\n\nExample:\n--------------------------------------------------\nimport { PostHog } from \"posthog-node\"\n\n// NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n })\n return posthogClient\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n {\n source: \"/ingest/flags\",\n destination: \"${host}/flags\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n\nexport const getModernNextjsDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: instrumentation-client.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: in the root of the application or inside an src folder.\n==============================\nChanges:\n- Create or update the instrumentation-client.${\n language === 'typescript' ? 'ts' : 'js'\n } file to use the PostHog client. If the file does not exist yet, create it.\n- Do *not* import instrumentation-client.${\n language === 'typescript' ? 'ts' : 'js'\n } in any other file; Next.js will automatically handle it.\n- Do not modify any other pages/components in the Next.js application; the PostHog client will be automatically initialized and handle all pageview tasks on its own.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\n\nimport posthog from \"posthog-js\"\n\nposthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n});\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n {\n source: \"/ingest/flags\",\n destination: \"${host}/flags\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/nextjs/docs.ts"],"names":[],"mappings":";;;AAAA,wCAAwE;AAEjE,MAAM,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;wBAGL,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;;;;kBAoBgB,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;eAgB1B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;wBAwBb,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AAtEW,QAAA,mBAAmB,uBAsE9B","sourcesContent":["import { getAssetHostFromHost, getUiHostFromHost } from '../utils/urls';\n\nexport const getNextjsAppRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: PostHogProvider.${\n language === 'typescript' ? 'tsx' : 'jsx'\n } (put it somewhere where client files are, like the components folder)\nLOCATION: Wherever other providers are, or the components folder\n==============================\nChanges:\n- Create a PostHogProvider component that will be imported into the layout file.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\n\"use client\"\n\nimport posthog from \"posthog-js\"\nimport { PostHogProvider as PHProvider, usePostHog } from \"posthog-js/react\"\nimport { Suspense, useEffect } from \"react\"\nimport { usePathname, useSearchParams } from \"next/navigation\"\n\nexport function PostHogProvider({ children }: { children: React.ReactNode }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return (\n <PHProvider client={posthog}>\n {children}\n </PHProvider>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: layout.${language === 'typescript' ? 'tsx' : 'jsx'}\nLOCATION: Wherever the root layout is\n==============================\nChanges:\n- Import the PostHogProvider from the providers file and wrap the app in it.\n\nExample:\n--------------------------------------------------\n// other imports\nimport { PostHogProvider } from \"LOCATION_OF_POSTHOG_PROVIDER\"\n\nexport default function RootLayout({ children }) {\n return (\n <html lang=\"en\">\n <body>\n <PostHogProvider>\n {/* other providers */}\n {children}\n {/* other providers */}\n </PostHogProvider>\n </body>\n </html>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: posthog.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: Wherever works best given the project structure\n==============================\nChanges:\n- Initialize the PostHog Node.js client\n\nExample:\n--------------------------------------------------\nimport { PostHog } from \"posthog-node\"\n\n// NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n })\n return posthogClient\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n {\n source: \"/ingest/decide\",\n destination: \"${host}/decide\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n\nexport const getNextjsPagesRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: _app.${language === 'typescript' ? 'tsx' : 'jsx'}\nLOCATION: Wherever the root _app.${\n language === 'typescript' ? 'tsx' : 'jsx'\n } file is\n==============================\nChanges:\n- Initialize PostHog in _app.js.\n- Wrap the application in PostHogProvider.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\nimport { useEffect } from \"react\"\nimport posthog from \"posthog-js\"\nimport { PostHogProvider } from \"posthog-js/react\"\n\nexport default function App({ Component, pageProps }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n })\n }, [])\n\n return (\n <PostHogProvider client={posthog}>\n <Component {...pageProps} />\n </PostHogProvider>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: posthog.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: Wherever works best given the project structure\n==============================\nChanges:\n- Initialize the PostHog Node.js client\n\nExample:\n--------------------------------------------------\nimport { PostHog } from \"posthog-node\"\n\n// NOTE: This is a Node.js client, so you can use it for sending events from the server side to PostHog.\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: process.env.NEXT_PUBLIC_POSTHOG_HOST,\n flushAt: 1,\n flushInterval: 0,\n })\n return posthogClient\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n {\n source: \"/ingest/decide\",\n destination: \"${host}/decide\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n\nexport const getModernNextjsDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: instrumentation-client.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: in the root of the application or inside an src folder.\n==============================\nChanges:\n- Create or update the instrumentation-client.${\n language === 'typescript' ? 'ts' : 'js'\n } file to use the PostHog client. If the file does not exist yet, create it.\n- Do *not* import instrumentation-client.${\n language === 'typescript' ? 'ts' : 'js'\n } in any other file; Next.js will automatically handle it.\n- Do not modify any other pages/components in the Next.js application; the PostHog client will be automatically initialized and handle all pageview tasks on its own.\n- Make sure to include the defaults: '2025-05-24' option in the init call.\n\nExample:\n--------------------------------------------------\n\nimport posthog from \"posthog-js\"\n\nposthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n defaults: '2025-05-24',\n capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this\n debug: process.env.NODE_ENV === \"development\",\n});\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n {\n source: \"/ingest/decide\",\n destination: \"${host}/decide\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n"]}
|
package/dist/src/nextjs/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/nextjs/utils.ts"],"names":[],"mappings":";;;;;;AAOA,wDAkBC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/nextjs/utils.ts"],"names":[],"mappings":";;;;;;AAOA,wDAkBC;AAaD,0CAmDC;AAzFD,mCAA2C;AAC3C,0DAA2B;AAC3B,sDAAwD;AACxD,2DAAmC;AAEnC,gDAA+C;AAE/C,SAAgB,sBAAsB,CAAC,OAA2B;IAChE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,OAAO,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,YAAY,GAAG,IAAA,cAAK,EAAC,MAAM,CAAC,CAAC;QACnC,IAAI,YAAY,IAAI,EAAE,EAAE,CAAC;YACvB,OAAO,GAAG,YAAY,IAAI,CAAC;QAC7B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,yCAAyB,CAAA;IACzB,6CAA6B,CAAA;AAC/B,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAEY,QAAA,eAAe,GAAG;IAC7B,oBAAoB;IACpB,YAAY;IACZ,aAAa;IACb,cAAc;CACf,CAAC;AACK,KAAK,UAAU,eAAe,CAAC,EACpC,UAAU,GACwB;IAClC,MAAM,YAAY,GAAG,MAAM,IAAA,mBAAE,EAAC,gCAAgC,EAAE;QAC9D,GAAG,EAAE,IAAI;Q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;IAC1D,OAAO,MAAM,KAAK,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC;AAC5E,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["import { major, minVersion } from 'semver';\nimport fg from 'fast-glob';\nimport { abortIfCancelled } from '../utils/clack-utils';\nimport clack from '../utils/clack';\nimport type { WizardOptions } from '../utils/types';\nimport { Integration } from '../lib/constants';\n\nexport function getNextJsVersionBucket(version: string | undefined) {\n if (!version) {\n return 'none';\n }\n\n try {\n const minVer = minVersion(version);\n if (!minVer) {\n return 'invalid';\n }\n const majorVersion = major(minVer);\n if (majorVersion >= 11) {\n return `${majorVersion}.x`;\n }\n return '<11.0.0';\n } catch {\n return 'unknown';\n }\n}\n\nexport enum NextJsRouter {\n APP_ROUTER = 'app-router',\n PAGES_ROUTER = 'pages-router',\n}\n\nexport const IGNORE_PATTERNS = [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/public/**',\n];\nexport async function getNextJsRouter({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<NextJsRouter> {\n const pagesMatches = await fg('**/pages/_app.@(ts|tsx|js|jsx)', {\n dot: true,\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n });\n\n const hasPagesDir = pagesMatches.length > 0;\n\n const appMatches = await fg('**/app/**/layout.@(ts|tsx|js|jsx)', {\n dot: true,\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n });\n\n const hasAppDir = appMatches.length > 0;\n\n if (hasPagesDir && !hasAppDir) {\n clack.log.info(\n `Detected ${getNextJsRouterName(NextJsRouter.PAGES_ROUTER)} 📃`,\n );\n return NextJsRouter.PAGES_ROUTER;\n }\n\n if (hasAppDir && !hasPagesDir) {\n clack.log.info(\n `Detected ${getNextJsRouterName(NextJsRouter.APP_ROUTER)} 📱`,\n );\n return NextJsRouter.APP_ROUTER;\n }\n\n const result: NextJsRouter = await abortIfCancelled(\n clack.select({\n message: 'What router are you using?',\n options: [\n {\n label: getNextJsRouterName(NextJsRouter.APP_ROUTER),\n value: NextJsRouter.APP_ROUTER,\n },\n {\n label: getNextJsRouterName(NextJsRouter.PAGES_ROUTER),\n value: NextJsRouter.PAGES_ROUTER,\n },\n ],\n }),\n Integration.nextjs,\n );\n\n return result;\n}\n\nexport const getNextJsRouterName = (router: NextJsRouter) => {\n return router === NextJsRouter.APP_ROUTER ? 'app router' : 'pages router';\n};\n"]}
|
|
@@ -415,11 +415,9 @@ async function askForWizardLogin(options) {
|
|
|
415
415
|
clack_1.default.log.info(`${chalk_1.default.bold(`If the browser window didn't open automatically, please open the following link to login into PostHog:`)}\n\n${chalk_1.default.cyan(urlToOpen)}${options.signup
|
|
416
416
|
? `\n\nIf you already have an account, you can use this link:\n\n${chalk_1.default.cyan(loginUrl.toString())}`
|
|
417
417
|
: ``}`);
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
});
|
|
422
|
-
}
|
|
418
|
+
(0, opn_1.default)(urlToOpen, { wait: false }).catch(() => {
|
|
419
|
+
// opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here
|
|
420
|
+
});
|
|
423
421
|
const loginSpinner = clack_1.default.spinner();
|
|
424
422
|
loginSpinner.start('Waiting for you to log in using the link above');
|
|
425
423
|
const data = await new Promise((resolve) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clack-utils.js","sourceRoot":"","sources":["../../../src/utils/clack-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,sBAKC;AAED,4CAoBC;AAED,oCAaC;AAED,8EA6CC;AAED,kCASC;AAED,wEAmBC;AAED,kDAmBC;AAED,kGAkDC;AAED,gDAmBC;AAQD,wCAgHC;AAYD,4DAuBC;AAED,8CA4BC;AAED,oDAmBC;AAED,8CAoCC;AAED,8CAQC;AASD,wDAoCC;AAsHD,oDAkCC;AAwBD,8DAwBC;AAgCD,0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ACX,KAAK,EAAE,KAAK;wBACZ,IAAI,EAAE,iBAAiB;qBACxB;iBACF;gBACD,YAAY,EAAE,IAAI;aACnB,CAAC,CACH,CAAC;QAEN,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,iBAAiB;IACrC,OAAO,MAAM,IAAA,qBAAS,EAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,WAAW,GAAgB,MAAM,gBAAgB,CACrD,eAAK,CAAC,MAAM,CAAC;YACX,OAAO,EAAE,kCAAkC;YAC3C,OAAO,EAAE;gBACP;oBACE,KAAK,EAAE,SAAS;oBAChB,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,oCAAoC;iBAC3C;gBACD;oBACE,KAAK,EAAE,SAAS;oBAChB,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,oCAAoC;iBAC3C;aACF;SACF,CAAC,CACH,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import * as childProcess from 'node:child_process';\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport { basename, isAbsolute, join, relative } from 'node:path';\nimport { setInterval } from 'node:timers';\nimport { URL } from 'node:url';\nimport axios from 'axios';\nimport chalk from 'chalk';\nimport opn from 'opn';\nimport { traceStep } from '../telemetry';\nimport { debug } from './debug';\nimport { type PackageDotJson, hasPackageInstalled } from './package-json';\nimport {\n type PackageManager,\n detectAllPackageManagers,\n packageManagers,\n} from './package-manager';\nimport { fulfillsVersionRange } from './semver';\nimport type { CloudRegion, Feature, WizardOptions } from './types';\nimport { getPackageVersion } from './package-json';\nimport {\n DEFAULT_HOST_URL,\n DUMMY_PROJECT_API_KEY,\n ISSUES_URL,\n type Integration,\n} from '../lib/constants';\nimport { analytics } from './analytics';\nimport clack from './clack';\nimport { getCloudUrlFromRegion } from './urls';\nimport { INTEGRATION_CONFIG } from '../lib/config';\n\ninterface ProjectData {\n projectApiKey: string;\n host: string;\n wizardHash: string;\n distinctId: string;\n}\n\nexport interface CliSetupConfig {\n filename: string;\n name: string;\n gitignore: boolean;\n\n likelyAlreadyHasAuthToken(contents: string): boolean;\n tokenContent(authToken: string): string;\n\n likelyAlreadyHasOrgAndProject(contents: string): boolean;\n orgAndProjContent(org: string, project: string): string;\n\n likelyAlreadyHasUrl?(contents: string): boolean;\n urlContent?(url: string): string;\n}\n\nexport interface CliSetupConfigContent {\n authToken: string;\n org?: string;\n project?: string;\n url?: string;\n}\n\nexport async function abort(message?: string, status?: number): Promise<never> {\n await analytics.shutdown('cancelled');\n\n clack.outro(message ?? 'Wizard setup cancelled.');\n return process.exit(status ?? 1);\n}\n\nexport async function abortIfCancelled<T>(\n input: T | Promise<T>,\n integration?: Integration,\n): Promise<Exclude<T, symbol>> {\n await analytics.shutdown('cancelled');\n\n if (clack.isCancel(await input)) {\n const docsUrl = integration\n ? INTEGRATION_CONFIG[integration].docsUrl\n : 'https://posthog.com/docs';\n\n clack.cancel(\n `Wizard setup cancelled. You can read the documentation for ${\n integration ?? 'PostHog'\n } at ${chalk.cyan(docsUrl)} to continue with the setup manually.`,\n );\n process.exit(0);\n } else {\n return input as Exclude<T, symbol>;\n }\n}\n\nexport function printWelcome(options: {\n wizardName: string;\n message?: string;\n}): void {\n // eslint-disable-next-line no-console\n console.log('');\n clack.intro(chalk.inverse(` ${options.wizardName} `));\n\n const welcomeText =\n options.message ||\n `The ${options.wizardName} will help you set up PostHog for your application.\\nThank you for using PostHog :)`;\n\n clack.note(welcomeText);\n}\n\nexport async function confirmContinueIfNoOrDirtyGitRepo(\n options: Pick<WizardOptions, 'default'>,\n): Promise<void> {\n return traceStep('check-git-status', async () => {\n if (!isInGitRepo()) {\n const continueWithoutGit = options.default\n ? true\n : await abortIfCancelled(\n clack.confirm({\n message:\n 'You are not inside a git repository. The wizard will create and update files. Do you want to continue anyway?',\n }),\n );\n\n analytics.setTag('continue-without-git', continueWithoutGit);\n\n if (!continueWithoutGit) {\n await abort(undefined, 0);\n }\n // return early to avoid checking for uncommitted files\n return;\n }\n\n const uncommittedOrUntrackedFiles = getUncommittedOrUntrackedFiles();\n if (uncommittedOrUntrackedFiles.length) {\n clack.log.warn(\n `You have uncommitted or untracked files in your repo:\n\n${uncommittedOrUntrackedFiles.join('\\n')}\n\nThe wizard will create and update files.`,\n );\n const continueWithDirtyRepo = await abortIfCancelled(\n clack.confirm({\n message: 'Do you want to continue anyway?',\n }),\n );\n\n analytics.setTag('continue-with-dirty-repo', continueWithDirtyRepo);\n\n if (!continueWithDirtyRepo) {\n await abort(undefined, 0);\n }\n }\n });\n}\n\nexport function isInGitRepo() {\n try {\n childProcess.execSync('git rev-parse --is-inside-work-tree', {\n stdio: 'ignore',\n });\n return true;\n } catch {\n return false;\n }\n}\n\nexport function getUncommittedOrUntrackedFiles(): string[] {\n try {\n const gitStatus = childProcess\n .execSync('git status --porcelain=v1', {\n // we only care about stdout\n stdio: ['ignore', 'pipe', 'ignore'],\n })\n .toString();\n\n const files = gitStatus\n .split(os.EOL)\n .map((line) => line.trim())\n .filter(Boolean)\n .map((f) => `- ${f.split(/\\s+/)[1]}`);\n\n return files;\n } catch {\n return [];\n }\n}\n\nexport async function askForItemSelection(\n items: string[],\n message: string,\n): Promise<{ value: string; index: number }> {\n const selection: { value: string; index: number } | symbol =\n await abortIfCancelled(\n clack.select({\n maxItems: 12,\n message: message,\n options: items.map((item, index) => {\n return {\n value: { value: item, index: index },\n label: item,\n };\n }),\n }),\n );\n\n return selection;\n}\n\nexport async function confirmContinueIfPackageVersionNotSupported({\n packageId,\n packageName,\n packageVersion,\n acceptableVersions,\n note,\n}: {\n packageId: string;\n packageName: string;\n packageVersion: string;\n acceptableVersions: string;\n note?: string;\n}): Promise<void> {\n return traceStep(`check-package-version`, async () => {\n analytics.setTag(`${packageName.toLowerCase()}-version`, packageVersion);\n const isSupportedVersion = fulfillsVersionRange({\n acceptableVersions,\n version: packageVersion,\n canBeLatest: true,\n });\n\n if (isSupportedVersion) {\n analytics.setTag(`${packageName.toLowerCase()}-supported`, true);\n return;\n }\n\n clack.log.warn(\n `You have an unsupported version of ${packageName} installed:\n\n ${packageId}@${packageVersion}`,\n );\n\n clack.note(\n note ??\n `Please upgrade to ${acceptableVersions} if you wish to use the PostHog wizard.`,\n );\n const continueWithUnsupportedVersion = await abortIfCancelled(\n clack.confirm({\n message: 'Do you want to continue anyway?',\n }),\n );\n analytics.setTag(\n `${packageName.toLowerCase()}-continue-with-unsupported-version`,\n continueWithUnsupportedVersion,\n );\n\n if (!continueWithUnsupportedVersion) {\n await abort(undefined, 0);\n }\n });\n}\n\nexport async function isReact19Installed({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<boolean> {\n try {\n const packageJson = await getPackageDotJson({ installDir });\n const reactVersion = getPackageVersion('react', packageJson);\n\n if (!reactVersion) {\n return false;\n }\n\n return fulfillsVersionRange({\n version: reactVersion,\n acceptableVersions: '>=19.0.0',\n canBeLatest: true,\n });\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Installs or updates a package with the user's package manager.\n *\n * IMPORTANT: This function modifies the `package.json`! Be sure to re-read\n * it if you make additional modifications to it after calling this function!\n */\nexport async function installPackage({\n packageName,\n alreadyInstalled,\n askBeforeUpdating = true,\n packageNameDisplayLabel,\n packageManager,\n forceInstall = false,\n integration,\n installDir,\n}: {\n /** The string that is passed to the package manager CLI as identifier to install (e.g. `posthog-js`, or `posthog-js@^1.100.0`) */\n packageName: string;\n alreadyInstalled: boolean;\n askBeforeUpdating?: boolean;\n /** Overrides what is shown in the installation logs in place of the `packageName` option. Useful if the `packageName` is ugly */\n packageNameDisplayLabel?: string;\n packageManager?: PackageManager;\n /** Add force install flag to command to skip install precondition fails */\n forceInstall?: boolean;\n /** The integration that is being used */\n integration?: string;\n /** The directory to install the package in */\n installDir: string;\n}): Promise<{ packageManager?: PackageManager }> {\n return traceStep('install-package', async () => {\n if (alreadyInstalled && askBeforeUpdating) {\n const shouldUpdatePackage = await abortIfCancelled(\n clack.confirm({\n message: `The ${chalk.bold.cyan(\n packageNameDisplayLabel ?? packageName,\n )} package is already installed. Do you want to update it to the latest version?`,\n }),\n );\n\n if (!shouldUpdatePackage) {\n return {};\n }\n }\n\n const sdkInstallSpinner = clack.spinner();\n\n const pkgManager =\n packageManager || (await getPackageManager({ installDir }));\n\n // Most packages aren't compatible with React 19 yet, skip strict peer dependency checks if needed.\n const isReact19 = await isReact19Installed({ installDir });\n const legacyPeerDepsFlag =\n isReact19 && pkgManager.name === 'npm' ? '--legacy-peer-deps' : '';\n\n sdkInstallSpinner.start(\n `${alreadyInstalled ? 'Updating' : 'Installing'} ${chalk.bold.cyan(\n packageNameDisplayLabel ?? packageName,\n )} with ${chalk.bold(pkgManager.label)}.`,\n );\n\n try {\n await new Promise<void>((resolve, reject) => {\n childProcess.exec(\n `${pkgManager.installCommand} ${packageName} ${pkgManager.flags} ${\n forceInstall ? pkgManager.forceInstallFlag : ''\n } ${legacyPeerDepsFlag}`.trim(),\n { cwd: installDir },\n (err, stdout, stderr) => {\n if (err) {\n // Write a log file so we can better troubleshoot issues\n fs.writeFileSync(\n join(\n process.cwd(),\n `posthog-wizard-installation-error-${Date.now()}.log`,\n ),\n JSON.stringify({\n stdout,\n stderr,\n }),\n { encoding: 'utf8' },\n );\n\n reject(err);\n } else {\n resolve();\n }\n },\n );\n });\n } catch (e) {\n sdkInstallSpinner.stop('Installation failed.');\n clack.log.error(\n `${chalk.red(\n 'Encountered the following error during installation:',\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n )}\\n\\n${e}\\n\\n${chalk.dim(\n `The wizard has created a \\`posthog-wizard-installation-error-*.log\\` file. If you think this issue is caused by the PostHog wizard, create an issue on GitHub and include the log file's content:\\n${ISSUES_URL}`,\n )}`,\n );\n await abort();\n }\n\n sdkInstallSpinner.stop(\n `${alreadyInstalled ? 'Updated' : 'Installed'} ${chalk.bold.cyan(\n packageNameDisplayLabel ?? packageName,\n )} with ${chalk.bold(pkgManager.label)}.`,\n );\n\n analytics.capture('wizard interaction', {\n action: 'package installed',\n package_name: packageName,\n package_manager: pkgManager.name,\n integration,\n });\n\n return { packageManager: pkgManager };\n });\n}\n\n/**\n * Checks if @param packageId is listed as a dependency in @param packageJson.\n * If not, it will ask users if they want to continue without the package.\n *\n * Use this function to check if e.g. a the framework of the SDK is installed\n *\n * @param packageJson the package.json object\n * @param packageId the npm name of the package\n * @param packageName a human readable name of the package\n */\nexport async function ensurePackageIsInstalled(\n packageJson: PackageDotJson,\n packageId: string,\n packageName: string,\n): Promise<void> {\n return traceStep('ensure-package-installed', async () => {\n const installed = hasPackageInstalled(packageId, packageJson);\n\n analytics.setTag(`${packageName.toLowerCase()}-installed`, installed);\n\n if (!installed) {\n const continueWithoutPackage = await abortIfCancelled(\n clack.confirm({\n message: `${packageName} does not seem to be installed. Do you still want to continue?`,\n initialValue: false,\n }),\n );\n\n if (!continueWithoutPackage) {\n await abort(undefined, 0);\n }\n }\n });\n}\n\nexport async function getPackageDotJson({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<PackageDotJson> {\n const packageJsonFileContents = await fs.promises\n .readFile(join(installDir, 'package.json'), 'utf8')\n .catch(() => {\n clack.log.error(\n 'Could not find package.json. Make sure to run the wizard in the root of your app!',\n );\n return abort();\n });\n\n let packageJson: PackageDotJson | undefined = undefined;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n packageJson = JSON.parse(packageJsonFileContents);\n } catch {\n clack.log.error(\n `Unable to parse your ${chalk.cyan(\n 'package.json',\n )}. Make sure it has a valid format!`,\n );\n\n await abort();\n }\n\n return packageJson || {};\n}\n\nexport async function updatePackageDotJson(\n packageDotJson: PackageDotJson,\n { installDir }: Pick<WizardOptions, 'installDir'>,\n): Promise<void> {\n try {\n await fs.promises.writeFile(\n join(installDir, 'package.json'),\n // TODO: maybe figure out the original indentation\n JSON.stringify(packageDotJson, null, 2),\n {\n encoding: 'utf8',\n flag: 'w',\n },\n );\n } catch {\n clack.log.error(`Unable to update your ${chalk.cyan('package.json')}.`);\n\n await abort();\n }\n}\n\nexport async function getPackageManager({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<PackageManager> {\n const detectedPackageManagers = detectAllPackageManagers({ installDir });\n\n // If exactly one package manager detected, use it automatically\n if (detectedPackageManagers.length === 1) {\n const detectedPackageManager = detectedPackageManagers[0];\n analytics.setTag('package-manager', detectedPackageManager.name);\n return detectedPackageManager;\n }\n\n // If multiple or no package managers detected, prompt user to select\n const options =\n detectedPackageManagers.length > 0\n ? detectedPackageManagers\n : packageManagers;\n\n const message =\n detectedPackageManagers.length > 1\n ? 'Multiple package managers detected. Please select one:'\n : 'Please select your package manager.';\n\n const selectedPackageManager: PackageManager | symbol =\n await abortIfCancelled(\n clack.select({\n message,\n options: options.map((packageManager) => ({\n value: packageManager,\n label: packageManager.label,\n })),\n }),\n );\n\n analytics.setTag('package-manager', selectedPackageManager.name);\n return selectedPackageManager;\n}\n\nexport function isUsingTypeScript({\n installDir,\n}: Pick<WizardOptions, 'installDir'>) {\n try {\n return fs.existsSync(join(installDir, 'tsconfig.json'));\n } catch {\n return false;\n }\n}\n\n/**\n *\n * Use this function to get project data for the wizard.\n *\n * @param options wizard options\n * @returns project data (token, url)\n */\nexport async function getOrAskForProjectData(\n _options: Pick<WizardOptions, 'signup'> & {\n cloudRegion: CloudRegion;\n },\n): Promise<{\n wizardHash: string;\n host: string;\n projectApiKey: string;\n}> {\n const cloudUrl = getCloudUrlFromRegion(_options.cloudRegion);\n const { host, projectApiKey, wizardHash } = await traceStep('login', () =>\n askForWizardLogin({\n url: cloudUrl,\n signup: _options.signup,\n }),\n );\n\n if (!projectApiKey) {\n clack.log.error(`Didn't receive a project API key. This shouldn't happen :(\n\nPlease let us know if you think this is a bug in the wizard:\n${chalk.cyan(ISSUES_URL)}`);\n\n clack.log\n .info(`In the meantime, we'll add a dummy project API key (${chalk.cyan(\n `\"${DUMMY_PROJECT_API_KEY}\"`,\n )}) for you to replace later.\nYou can find your Project API key here:\n${chalk.cyan(`${cloudUrl}/settings/project#variables`)}`);\n }\n\n return {\n wizardHash,\n host: host || DEFAULT_HOST_URL,\n projectApiKey: projectApiKey || DUMMY_PROJECT_API_KEY,\n };\n}\n\nasync function askForWizardLogin(options: {\n url: string;\n signup: boolean;\n}): Promise<ProjectData> {\n let wizardHash: string;\n\n try {\n wizardHash = (\n await axios.post<{ hash: string }>(`${options.url}/api/wizard/initialize`)\n ).data.hash;\n } catch (e: unknown) {\n clack.log.error('Loading wizard failed.');\n clack.log.info(JSON.stringify(e, null, 2));\n await abort(\n chalk.red(\n `Please try again in a few minutes and let us know if this issue persists: ${ISSUES_URL}`,\n ),\n );\n throw e;\n }\n\n const loginUrl = new URL(`${options.url}/wizard?hash=${wizardHash}`);\n\n const signupUrl = new URL(\n `${options.url}/signup?next=${encodeURIComponent(\n `/wizard?hash=${wizardHash}`,\n )}`,\n );\n\n const urlToOpen = options.signup ? signupUrl.toString() : loginUrl.toString();\n\n clack.log.info(\n `${chalk.bold(\n `If the browser window didn't open automatically, please open the following link to login into PostHog:`,\n )}\\n\\n${chalk.cyan(urlToOpen)}${\n options.signup\n ? `\\n\\nIf you already have an account, you can use this link:\\n\\n${chalk.cyan(\n loginUrl.toString(),\n )}`\n : ``\n }`,\n );\n\n if (process.env.NODE_ENV !== 'test') {\n opn(urlToOpen, { wait: false }).catch(() => {\n // opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here\n });\n }\n\n const loginSpinner = clack.spinner();\n\n loginSpinner.start('Waiting for you to log in using the link above');\n\n const data = await new Promise<ProjectData>((resolve) => {\n const pollingInterval = setInterval(() => {\n axios\n .get<{\n project_api_key: string;\n host: string;\n user_distinct_id: string;\n personal_api_key?: string;\n }>(`${options.url}/api/wizard/data`, {\n headers: {\n 'Accept-Encoding': 'deflate',\n 'X-PostHog-Wizard-Hash': wizardHash,\n },\n })\n .then((result) => {\n const data: ProjectData = {\n wizardHash,\n projectApiKey: result.data.project_api_key,\n host: result.data.host,\n distinctId: result.data.user_distinct_id,\n };\n\n resolve(data);\n clearTimeout(timeout);\n clearInterval(pollingInterval);\n })\n .catch(() => {\n // noop - just try again\n });\n }, 500);\n\n const timeout = setTimeout(() => {\n clearInterval(pollingInterval);\n loginSpinner.stop(\n 'Login timed out. No worries - it happens to the best of us.',\n );\n\n analytics.setTag('opened-wizard-link', false);\n void abort('Please restart the wizard and log in to complete the setup.');\n }, 180_000);\n });\n\n loginSpinner.stop(\n `Login complete. ${options.signup ? 'Welcome to PostHog! 🎉' : ''}`,\n );\n analytics.setTag('opened-wizard-link', true);\n analytics.setDistinctId(data.distinctId);\n\n return data;\n}\n\n/**\n * Asks users if they have a config file for @param tool (e.g. Vite).\n * If yes, asks users to specify the path to their config file.\n *\n * Use this helper function as a fallback mechanism if the lookup for\n * a config file with its most usual location/name fails.\n *\n * @param toolName Name of the tool for which we're looking for the config file\n * @param configFileName Name of the most common config file name (e.g. vite.config.js)\n *\n * @returns a user path to the config file or undefined if the user doesn't have a config file\n */\nexport async function askForToolConfigPath(\n toolName: string,\n configFileName: string,\n): Promise<string | undefined> {\n const hasConfig = await abortIfCancelled(\n clack.confirm({\n message: `Do you have a ${toolName} config file (e.g. ${chalk.cyan(\n configFileName,\n )})?`,\n initialValue: true,\n }),\n );\n\n if (!hasConfig) {\n return undefined;\n }\n\n return await abortIfCancelled(\n clack.text({\n message: `Please enter the path to your ${toolName} config file:`,\n placeholder: join('.', configFileName),\n validate: (value) => {\n if (!value) {\n return 'Please enter a path.';\n }\n\n try {\n fs.accessSync(value);\n } catch {\n return 'Could not access the file at this path.';\n }\n },\n }),\n );\n}\n\n/**\n * Prints copy/paste-able instructions to the console.\n * Afterwards asks the user if they added the code snippet to their file.\n *\n * While there's no point in providing a \"no\" answer here, it gives users time to fulfill the\n * task before the wizard continues with additional steps.\n *\n * Use this function if you want to show users instructions on how to add/modify\n * code in their file. This is helpful if automatic insertion failed or is not possible/feasible.\n *\n * @param filename the name of the file to which the code snippet should be applied.\n * If a path is provided, only the filename will be used.\n *\n * @param codeSnippet the snippet to be printed. Use {@link makeCodeSnippet} to create the\n * diff-like format for visually highlighting unchanged or modified lines of code.\n *\n * @param hint (optional) a hint to be printed after the main instruction to add\n * the code from @param codeSnippet to their @param filename.\n *\n * TODO: refactor copy paste instructions across different wizards to use this function.\n * this might require adding a custom message parameter to the function\n */\nexport async function showCopyPasteInstructions(\n filename: string,\n codeSnippet: string,\n hint?: string,\n): Promise<void> {\n clack.log.step(\n `Add the following code to your ${chalk.cyan(basename(filename))} file:${\n hint ? chalk.dim(` (${chalk.dim(hint)})`) : ''\n }`,\n );\n\n // Padding the code snippet to be printed with a \\n at the beginning and end\n // This makes it easier to distinguish the snippet from the rest of the output\n // Intentionally logging directly to console here so that the code can be copied/pasted directly\n // eslint-disable-next-line no-console\n console.log(`\\n${codeSnippet}\\n`);\n\n await abortIfCancelled(\n clack.select({\n message: 'Did you apply the snippet above?',\n options: [{ label: 'Yes, continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n\n/**\n * Callback that exposes formatting helpers for a code snippet.\n * @param unchanged - Formats text as old code.\n * @param plus - Formats text as new code.\n * @param minus - Formats text as removed code.\n */\ntype CodeSnippetFormatter = (\n unchanged: (txt: string) => string,\n plus: (txt: string) => string,\n minus: (txt: string) => string,\n) => string;\n\n/**\n * Crafts a code snippet that can be used to e.g.\n * - print copy/paste instructions to the console\n * - create a new config file.\n *\n * @param colors set this to true if you want the final snippet to be colored.\n * This is useful for printing the snippet to the console as part of copy/paste instructions.\n *\n * @param callback the callback that returns the formatted code snippet.\n * It exposes takes the helper functions for marking code as unchanged, new or removed.\n * These functions no-op if no special formatting should be applied\n * and otherwise apply the appropriate formatting/coloring.\n * (@see {@link CodeSnippetFormatter})\n *\n * @see {@link showCopyPasteInstructions} for the helper with which to display the snippet in the console.\n *\n * @returns a string containing the final, formatted code snippet.\n */\nexport function makeCodeSnippet(\n colors: boolean,\n callback: CodeSnippetFormatter,\n): string {\n const unchanged = (txt: string) => (colors ? chalk.grey(txt) : txt);\n const plus = (txt: string) => (colors ? chalk.greenBright(txt) : txt);\n const minus = (txt: string) => (colors ? chalk.redBright(txt) : txt);\n\n return callback(unchanged, plus, minus);\n}\n\n/**\n * Creates a new config file with the given @param filepath and @param codeSnippet.\n *\n * Use this function to create a new config file for users. This is useful\n * when users answered that they don't yet have a config file for a tool.\n *\n * (This doesn't mean that they don't yet have some other way of configuring\n * their tool but we can leave it up to them to figure out how to merge configs\n * here.)\n *\n * @param filepath absolute path to the new config file\n * @param codeSnippet the snippet to be inserted into the file\n * @param moreInformation (optional) the message to be printed after the file was created\n * For example, this can be a link to more information about configuring the tool.\n *\n * @returns true on success, false otherwise\n */\nexport async function createNewConfigFile(\n filepath: string,\n codeSnippet: string,\n { installDir }: Pick<WizardOptions, 'installDir'>,\n moreInformation?: string,\n): Promise<boolean> {\n if (!isAbsolute(filepath)) {\n debug(`createNewConfigFile: filepath is not absolute: ${filepath}`);\n return false;\n }\n\n const prettyFilename = chalk.cyan(relative(installDir, filepath));\n\n try {\n await fs.promises.writeFile(filepath, codeSnippet);\n\n clack.log.success(`Added new ${prettyFilename} file.`);\n\n if (moreInformation) {\n clack.log.info(chalk.gray(moreInformation));\n }\n\n return true;\n } catch (e) {\n debug(e);\n clack.log.warn(\n `Could not create a new ${prettyFilename} file. Please create one manually and follow the instructions below.`,\n );\n }\n\n return false;\n}\n\nexport async function featureSelectionPrompt<F extends ReadonlyArray<Feature>>(\n features: F,\n): Promise<{ [key in F[number]['id']]: boolean }> {\n return traceStep('feature-selection', async () => {\n const selectedFeatures: Record<string, boolean> = {};\n\n for (const feature of features) {\n const selected = await abortIfCancelled(\n clack.select({\n message: feature.prompt,\n initialValue: true,\n options: [\n {\n value: true,\n label: 'Yes',\n hint: feature.enabledHint,\n },\n {\n value: false,\n label: 'No',\n hint: feature.disabledHint,\n },\n ],\n }),\n );\n\n selectedFeatures[feature.id] = selected;\n }\n\n return selectedFeatures as { [key in F[number]['id']]: boolean };\n });\n}\n\nexport async function askShouldInstallPackage(\n pkgName: string,\n): Promise<boolean> {\n return traceStep(`ask-install-package`, () =>\n abortIfCancelled(\n clack.confirm({\n message: `Do you want to install ${chalk.cyan(pkgName)}?`,\n }),\n ),\n );\n}\n\nexport async function askShouldAddPackageOverride(\n pkgName: string,\n pkgVersion: string,\n): Promise<boolean> {\n return traceStep(`ask-add-package-override`, () =>\n abortIfCancelled(\n clack.confirm({\n message: `Do you want to add an override for ${chalk.cyan(\n pkgName,\n )} version ${chalk.cyan(pkgVersion)}?`,\n }),\n ),\n );\n}\n\nexport async function askForAIConsent(options: Pick<WizardOptions, 'default'>) {\n return await traceStep('ask-for-ai-consent', async () => {\n const aiConsent = options.default\n ? true\n : await abortIfCancelled(\n clack.select({\n message: 'This setup wizard uses AI, are you happy to continue? ✨',\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'We will use AI to help you setup PostHog quickly',\n },\n {\n label: 'No',\n value: false,\n hint: \"I don't like AI\",\n },\n ],\n initialValue: true,\n }),\n );\n\n return aiConsent;\n });\n}\n\nexport async function askForCloudRegion(): Promise<CloudRegion> {\n return await traceStep('ask-for-cloud-region', async () => {\n const cloudRegion: CloudRegion = await abortIfCancelled(\n clack.select({\n message: 'Select your PostHog Cloud region',\n options: [\n {\n label: 'US 🇺🇸',\n value: 'us',\n hint: 'Your data will be stored in the US',\n },\n {\n label: 'EU 🇪🇺',\n value: 'eu',\n hint: 'Your data will be stored in the EU',\n },\n ],\n }),\n );\n\n return cloudRegion;\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"clack-utils.js","sourceRoot":"","sources":["../../../src/utils/clack-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,sBAKC;AAED,4CAoBC;AAED,oCAaC;AAED,8EA6CC;AAED,kCASC;AAED,wEAmBC;AAED,kDAmBC;AAED,kGAkDC;AAED,gDAmBC;AAQD,wCAgHC;AAYD,4D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oBACD;wBACE,KAAK,EAAE,IAAI;wBACX,KAAK,EAAE,KAAK;wBACZ,IAAI,EAAE,iBAAiB;qBACxB;iBACF;gBACD,YAAY,EAAE,IAAI;aACnB,CAAC,CACH,CAAC;QAEN,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,iBAAiB;IACrC,OAAO,MAAM,IAAA,qBAAS,EAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,WAAW,GAAgB,MAAM,gBAAgB,CACrD,eAAK,CAAC,MAAM,CAAC;YACX,OAAO,EAAE,kCAAkC;YAC3C,OAAO,EAAE;gBACP;oBACE,KAAK,EAAE,SAAS;oBAChB,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,oCAAoC;iBAC3C;gBACD;oBACE,KAAK,EAAE,SAAS;oBAChB,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,oCAAoC;iBAC3C;aACF;SACF,CAAC,CACH,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import * as childProcess from 'node:child_process';\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport { basename, isAbsolute, join, relative } from 'node:path';\nimport { setInterval } from 'node:timers';\nimport { URL } from 'node:url';\nimport axios from 'axios';\nimport chalk from 'chalk';\nimport opn from 'opn';\nimport { traceStep } from '../telemetry';\nimport { debug } from './debug';\nimport { type PackageDotJson, hasPackageInstalled } from './package-json';\nimport {\n type PackageManager,\n detectAllPackageManagers,\n packageManagers,\n} from './package-manager';\nimport { fulfillsVersionRange } from './semver';\nimport type { CloudRegion, Feature, WizardOptions } from './types';\nimport { getPackageVersion } from './package-json';\nimport {\n DEFAULT_HOST_URL,\n DUMMY_PROJECT_API_KEY,\n ISSUES_URL,\n type Integration,\n} from '../lib/constants';\nimport { analytics } from './analytics';\nimport clack from './clack';\nimport { getCloudUrlFromRegion } from './urls';\nimport { INTEGRATION_CONFIG } from '../lib/config';\n\ninterface ProjectData {\n projectApiKey: string;\n host: string;\n wizardHash: string;\n distinctId: string;\n}\n\nexport interface CliSetupConfig {\n filename: string;\n name: string;\n gitignore: boolean;\n\n likelyAlreadyHasAuthToken(contents: string): boolean;\n tokenContent(authToken: string): string;\n\n likelyAlreadyHasOrgAndProject(contents: string): boolean;\n orgAndProjContent(org: string, project: string): string;\n\n likelyAlreadyHasUrl?(contents: string): boolean;\n urlContent?(url: string): string;\n}\n\nexport interface CliSetupConfigContent {\n authToken: string;\n org?: string;\n project?: string;\n url?: string;\n}\n\nexport async function abort(message?: string, status?: number): Promise<never> {\n await analytics.shutdown('cancelled');\n\n clack.outro(message ?? 'Wizard setup cancelled.');\n return process.exit(status ?? 1);\n}\n\nexport async function abortIfCancelled<T>(\n input: T | Promise<T>,\n integration?: Integration,\n): Promise<Exclude<T, symbol>> {\n await analytics.shutdown('cancelled');\n\n if (clack.isCancel(await input)) {\n const docsUrl = integration\n ? INTEGRATION_CONFIG[integration].docsUrl\n : 'https://posthog.com/docs';\n\n clack.cancel(\n `Wizard setup cancelled. You can read the documentation for ${\n integration ?? 'PostHog'\n } at ${chalk.cyan(docsUrl)} to continue with the setup manually.`,\n );\n process.exit(0);\n } else {\n return input as Exclude<T, symbol>;\n }\n}\n\nexport function printWelcome(options: {\n wizardName: string;\n message?: string;\n}): void {\n // eslint-disable-next-line no-console\n console.log('');\n clack.intro(chalk.inverse(` ${options.wizardName} `));\n\n const welcomeText =\n options.message ||\n `The ${options.wizardName} will help you set up PostHog for your application.\\nThank you for using PostHog :)`;\n\n clack.note(welcomeText);\n}\n\nexport async function confirmContinueIfNoOrDirtyGitRepo(\n options: Pick<WizardOptions, 'default'>,\n): Promise<void> {\n return traceStep('check-git-status', async () => {\n if (!isInGitRepo()) {\n const continueWithoutGit = options.default\n ? true\n : await abortIfCancelled(\n clack.confirm({\n message:\n 'You are not inside a git repository. The wizard will create and update files. Do you want to continue anyway?',\n }),\n );\n\n analytics.setTag('continue-without-git', continueWithoutGit);\n\n if (!continueWithoutGit) {\n await abort(undefined, 0);\n }\n // return early to avoid checking for uncommitted files\n return;\n }\n\n const uncommittedOrUntrackedFiles = getUncommittedOrUntrackedFiles();\n if (uncommittedOrUntrackedFiles.length) {\n clack.log.warn(\n `You have uncommitted or untracked files in your repo:\n\n${uncommittedOrUntrackedFiles.join('\\n')}\n\nThe wizard will create and update files.`,\n );\n const continueWithDirtyRepo = await abortIfCancelled(\n clack.confirm({\n message: 'Do you want to continue anyway?',\n }),\n );\n\n analytics.setTag('continue-with-dirty-repo', continueWithDirtyRepo);\n\n if (!continueWithDirtyRepo) {\n await abort(undefined, 0);\n }\n }\n });\n}\n\nexport function isInGitRepo() {\n try {\n childProcess.execSync('git rev-parse --is-inside-work-tree', {\n stdio: 'ignore',\n });\n return true;\n } catch {\n return false;\n }\n}\n\nexport function getUncommittedOrUntrackedFiles(): string[] {\n try {\n const gitStatus = childProcess\n .execSync('git status --porcelain=v1', {\n // we only care about stdout\n stdio: ['ignore', 'pipe', 'ignore'],\n })\n .toString();\n\n const files = gitStatus\n .split(os.EOL)\n .map((line) => line.trim())\n .filter(Boolean)\n .map((f) => `- ${f.split(/\\s+/)[1]}`);\n\n return files;\n } catch {\n return [];\n }\n}\n\nexport async function askForItemSelection(\n items: string[],\n message: string,\n): Promise<{ value: string; index: number }> {\n const selection: { value: string; index: number } | symbol =\n await abortIfCancelled(\n clack.select({\n maxItems: 12,\n message: message,\n options: items.map((item, index) => {\n return {\n value: { value: item, index: index },\n label: item,\n };\n }),\n }),\n );\n\n return selection;\n}\n\nexport async function confirmContinueIfPackageVersionNotSupported({\n packageId,\n packageName,\n packageVersion,\n acceptableVersions,\n note,\n}: {\n packageId: string;\n packageName: string;\n packageVersion: string;\n acceptableVersions: string;\n note?: string;\n}): Promise<void> {\n return traceStep(`check-package-version`, async () => {\n analytics.setTag(`${packageName.toLowerCase()}-version`, packageVersion);\n const isSupportedVersion = fulfillsVersionRange({\n acceptableVersions,\n version: packageVersion,\n canBeLatest: true,\n });\n\n if (isSupportedVersion) {\n analytics.setTag(`${packageName.toLowerCase()}-supported`, true);\n return;\n }\n\n clack.log.warn(\n `You have an unsupported version of ${packageName} installed:\n\n ${packageId}@${packageVersion}`,\n );\n\n clack.note(\n note ??\n `Please upgrade to ${acceptableVersions} if you wish to use the PostHog wizard.`,\n );\n const continueWithUnsupportedVersion = await abortIfCancelled(\n clack.confirm({\n message: 'Do you want to continue anyway?',\n }),\n );\n analytics.setTag(\n `${packageName.toLowerCase()}-continue-with-unsupported-version`,\n continueWithUnsupportedVersion,\n );\n\n if (!continueWithUnsupportedVersion) {\n await abort(undefined, 0);\n }\n });\n}\n\nexport async function isReact19Installed({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<boolean> {\n try {\n const packageJson = await getPackageDotJson({ installDir });\n const reactVersion = getPackageVersion('react', packageJson);\n\n if (!reactVersion) {\n return false;\n }\n\n return fulfillsVersionRange({\n version: reactVersion,\n acceptableVersions: '>=19.0.0',\n canBeLatest: true,\n });\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Installs or updates a package with the user's package manager.\n *\n * IMPORTANT: This function modifies the `package.json`! Be sure to re-read\n * it if you make additional modifications to it after calling this function!\n */\nexport async function installPackage({\n packageName,\n alreadyInstalled,\n askBeforeUpdating = true,\n packageNameDisplayLabel,\n packageManager,\n forceInstall = false,\n integration,\n installDir,\n}: {\n /** The string that is passed to the package manager CLI as identifier to install (e.g. `posthog-js`, or `posthog-js@^1.100.0`) */\n packageName: string;\n alreadyInstalled: boolean;\n askBeforeUpdating?: boolean;\n /** Overrides what is shown in the installation logs in place of the `packageName` option. Useful if the `packageName` is ugly */\n packageNameDisplayLabel?: string;\n packageManager?: PackageManager;\n /** Add force install flag to command to skip install precondition fails */\n forceInstall?: boolean;\n /** The integration that is being used */\n integration?: string;\n /** The directory to install the package in */\n installDir: string;\n}): Promise<{ packageManager?: PackageManager }> {\n return traceStep('install-package', async () => {\n if (alreadyInstalled && askBeforeUpdating) {\n const shouldUpdatePackage = await abortIfCancelled(\n clack.confirm({\n message: `The ${chalk.bold.cyan(\n packageNameDisplayLabel ?? packageName,\n )} package is already installed. Do you want to update it to the latest version?`,\n }),\n );\n\n if (!shouldUpdatePackage) {\n return {};\n }\n }\n\n const sdkInstallSpinner = clack.spinner();\n\n const pkgManager =\n packageManager || (await getPackageManager({ installDir }));\n\n // Most packages aren't compatible with React 19 yet, skip strict peer dependency checks if needed.\n const isReact19 = await isReact19Installed({ installDir });\n const legacyPeerDepsFlag =\n isReact19 && pkgManager.name === 'npm' ? '--legacy-peer-deps' : '';\n\n sdkInstallSpinner.start(\n `${alreadyInstalled ? 'Updating' : 'Installing'} ${chalk.bold.cyan(\n packageNameDisplayLabel ?? packageName,\n )} with ${chalk.bold(pkgManager.label)}.`,\n );\n\n try {\n await new Promise<void>((resolve, reject) => {\n childProcess.exec(\n `${pkgManager.installCommand} ${packageName} ${pkgManager.flags} ${\n forceInstall ? pkgManager.forceInstallFlag : ''\n } ${legacyPeerDepsFlag}`.trim(),\n { cwd: installDir },\n (err, stdout, stderr) => {\n if (err) {\n // Write a log file so we can better troubleshoot issues\n fs.writeFileSync(\n join(\n process.cwd(),\n `posthog-wizard-installation-error-${Date.now()}.log`,\n ),\n JSON.stringify({\n stdout,\n stderr,\n }),\n { encoding: 'utf8' },\n );\n\n reject(err);\n } else {\n resolve();\n }\n },\n );\n });\n } catch (e) {\n sdkInstallSpinner.stop('Installation failed.');\n clack.log.error(\n `${chalk.red(\n 'Encountered the following error during installation:',\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n )}\\n\\n${e}\\n\\n${chalk.dim(\n `The wizard has created a \\`posthog-wizard-installation-error-*.log\\` file. If you think this issue is caused by the PostHog wizard, create an issue on GitHub and include the log file's content:\\n${ISSUES_URL}`,\n )}`,\n );\n await abort();\n }\n\n sdkInstallSpinner.stop(\n `${alreadyInstalled ? 'Updated' : 'Installed'} ${chalk.bold.cyan(\n packageNameDisplayLabel ?? packageName,\n )} with ${chalk.bold(pkgManager.label)}.`,\n );\n\n analytics.capture('wizard interaction', {\n action: 'package installed',\n package_name: packageName,\n package_manager: pkgManager.name,\n integration,\n });\n\n return { packageManager: pkgManager };\n });\n}\n\n/**\n * Checks if @param packageId is listed as a dependency in @param packageJson.\n * If not, it will ask users if they want to continue without the package.\n *\n * Use this function to check if e.g. a the framework of the SDK is installed\n *\n * @param packageJson the package.json object\n * @param packageId the npm name of the package\n * @param packageName a human readable name of the package\n */\nexport async function ensurePackageIsInstalled(\n packageJson: PackageDotJson,\n packageId: string,\n packageName: string,\n): Promise<void> {\n return traceStep('ensure-package-installed', async () => {\n const installed = hasPackageInstalled(packageId, packageJson);\n\n analytics.setTag(`${packageName.toLowerCase()}-installed`, installed);\n\n if (!installed) {\n const continueWithoutPackage = await abortIfCancelled(\n clack.confirm({\n message: `${packageName} does not seem to be installed. Do you still want to continue?`,\n initialValue: false,\n }),\n );\n\n if (!continueWithoutPackage) {\n await abort(undefined, 0);\n }\n }\n });\n}\n\nexport async function getPackageDotJson({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<PackageDotJson> {\n const packageJsonFileContents = await fs.promises\n .readFile(join(installDir, 'package.json'), 'utf8')\n .catch(() => {\n clack.log.error(\n 'Could not find package.json. Make sure to run the wizard in the root of your app!',\n );\n return abort();\n });\n\n let packageJson: PackageDotJson | undefined = undefined;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n packageJson = JSON.parse(packageJsonFileContents);\n } catch {\n clack.log.error(\n `Unable to parse your ${chalk.cyan(\n 'package.json',\n )}. Make sure it has a valid format!`,\n );\n\n await abort();\n }\n\n return packageJson || {};\n}\n\nexport async function updatePackageDotJson(\n packageDotJson: PackageDotJson,\n { installDir }: Pick<WizardOptions, 'installDir'>,\n): Promise<void> {\n try {\n await fs.promises.writeFile(\n join(installDir, 'package.json'),\n // TODO: maybe figure out the original indentation\n JSON.stringify(packageDotJson, null, 2),\n {\n encoding: 'utf8',\n flag: 'w',\n },\n );\n } catch {\n clack.log.error(`Unable to update your ${chalk.cyan('package.json')}.`);\n\n await abort();\n }\n}\n\nexport async function getPackageManager({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<PackageManager> {\n const detectedPackageManagers = detectAllPackageManagers({ installDir });\n\n // If exactly one package manager detected, use it automatically\n if (detectedPackageManagers.length === 1) {\n const detectedPackageManager = detectedPackageManagers[0];\n analytics.setTag('package-manager', detectedPackageManager.name);\n return detectedPackageManager;\n }\n\n // If multiple or no package managers detected, prompt user to select\n const options =\n detectedPackageManagers.length > 0\n ? detectedPackageManagers\n : packageManagers;\n\n const message =\n detectedPackageManagers.length > 1\n ? 'Multiple package managers detected. Please select one:'\n : 'Please select your package manager.';\n\n const selectedPackageManager: PackageManager | symbol =\n await abortIfCancelled(\n clack.select({\n message,\n options: options.map((packageManager) => ({\n value: packageManager,\n label: packageManager.label,\n })),\n }),\n );\n\n analytics.setTag('package-manager', selectedPackageManager.name);\n return selectedPackageManager;\n}\n\nexport function isUsingTypeScript({\n installDir,\n}: Pick<WizardOptions, 'installDir'>) {\n try {\n return fs.existsSync(join(installDir, 'tsconfig.json'));\n } catch {\n return false;\n }\n}\n\n/**\n *\n * Use this function to get project data for the wizard.\n *\n * @param options wizard options\n * @returns project data (token, url)\n */\nexport async function getOrAskForProjectData(\n _options: Pick<WizardOptions, 'signup'> & {\n cloudRegion: CloudRegion;\n },\n): Promise<{\n wizardHash: string;\n host: string;\n projectApiKey: string;\n}> {\n const cloudUrl = getCloudUrlFromRegion(_options.cloudRegion);\n const { host, projectApiKey, wizardHash } = await traceStep('login', () =>\n askForWizardLogin({\n url: cloudUrl,\n signup: _options.signup,\n }),\n );\n\n if (!projectApiKey) {\n clack.log.error(`Didn't receive a project API key. This shouldn't happen :(\n\nPlease let us know if you think this is a bug in the wizard:\n${chalk.cyan(ISSUES_URL)}`);\n\n clack.log\n .info(`In the meantime, we'll add a dummy project API key (${chalk.cyan(\n `\"${DUMMY_PROJECT_API_KEY}\"`,\n )}) for you to replace later.\nYou can find your Project API key here:\n${chalk.cyan(`${cloudUrl}/settings/project#variables`)}`);\n }\n\n return {\n wizardHash,\n host: host || DEFAULT_HOST_URL,\n projectApiKey: projectApiKey || DUMMY_PROJECT_API_KEY,\n };\n}\n\nasync function askForWizardLogin(options: {\n url: string;\n signup: boolean;\n}): Promise<ProjectData> {\n let wizardHash: string;\n\n try {\n wizardHash = (\n await axios.post<{ hash: string }>(`${options.url}/api/wizard/initialize`)\n ).data.hash;\n } catch (e: unknown) {\n clack.log.error('Loading wizard failed.');\n clack.log.info(JSON.stringify(e, null, 2));\n await abort(\n chalk.red(\n `Please try again in a few minutes and let us know if this issue persists: ${ISSUES_URL}`,\n ),\n );\n throw e;\n }\n\n const loginUrl = new URL(`${options.url}/wizard?hash=${wizardHash}`);\n\n const signupUrl = new URL(\n `${options.url}/signup?next=${encodeURIComponent(\n `/wizard?hash=${wizardHash}`,\n )}`,\n );\n\n const urlToOpen = options.signup ? signupUrl.toString() : loginUrl.toString();\n\n clack.log.info(\n `${chalk.bold(\n `If the browser window didn't open automatically, please open the following link to login into PostHog:`,\n )}\\n\\n${chalk.cyan(urlToOpen)}${\n options.signup\n ? `\\n\\nIf you already have an account, you can use this link:\\n\\n${chalk.cyan(\n loginUrl.toString(),\n )}`\n : ``\n }`,\n );\n\n opn(urlToOpen, { wait: false }).catch(() => {\n // opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here\n });\n\n const loginSpinner = clack.spinner();\n\n loginSpinner.start('Waiting for you to log in using the link above');\n\n const data = await new Promise<ProjectData>((resolve) => {\n const pollingInterval = setInterval(() => {\n axios\n .get<{\n project_api_key: string;\n host: string;\n user_distinct_id: string;\n personal_api_key?: string;\n }>(`${options.url}/api/wizard/data`, {\n headers: {\n 'Accept-Encoding': 'deflate',\n 'X-PostHog-Wizard-Hash': wizardHash,\n },\n })\n .then((result) => {\n const data: ProjectData = {\n wizardHash,\n projectApiKey: result.data.project_api_key,\n host: result.data.host,\n distinctId: result.data.user_distinct_id,\n };\n\n resolve(data);\n clearTimeout(timeout);\n clearInterval(pollingInterval);\n })\n .catch(() => {\n // noop - just try again\n });\n }, 500);\n\n const timeout = setTimeout(() => {\n clearInterval(pollingInterval);\n loginSpinner.stop(\n 'Login timed out. No worries - it happens to the best of us.',\n );\n\n analytics.setTag('opened-wizard-link', false);\n void abort('Please restart the wizard and log in to complete the setup.');\n }, 180_000);\n });\n\n loginSpinner.stop(\n `Login complete. ${options.signup ? 'Welcome to PostHog! 🎉' : ''}`,\n );\n analytics.setTag('opened-wizard-link', true);\n analytics.setDistinctId(data.distinctId);\n\n return data;\n}\n\n/**\n * Asks users if they have a config file for @param tool (e.g. Vite).\n * If yes, asks users to specify the path to their config file.\n *\n * Use this helper function as a fallback mechanism if the lookup for\n * a config file with its most usual location/name fails.\n *\n * @param toolName Name of the tool for which we're looking for the config file\n * @param configFileName Name of the most common config file name (e.g. vite.config.js)\n *\n * @returns a user path to the config file or undefined if the user doesn't have a config file\n */\nexport async function askForToolConfigPath(\n toolName: string,\n configFileName: string,\n): Promise<string | undefined> {\n const hasConfig = await abortIfCancelled(\n clack.confirm({\n message: `Do you have a ${toolName} config file (e.g. ${chalk.cyan(\n configFileName,\n )})?`,\n initialValue: true,\n }),\n );\n\n if (!hasConfig) {\n return undefined;\n }\n\n return await abortIfCancelled(\n clack.text({\n message: `Please enter the path to your ${toolName} config file:`,\n placeholder: join('.', configFileName),\n validate: (value) => {\n if (!value) {\n return 'Please enter a path.';\n }\n\n try {\n fs.accessSync(value);\n } catch {\n return 'Could not access the file at this path.';\n }\n },\n }),\n );\n}\n\n/**\n * Prints copy/paste-able instructions to the console.\n * Afterwards asks the user if they added the code snippet to their file.\n *\n * While there's no point in providing a \"no\" answer here, it gives users time to fulfill the\n * task before the wizard continues with additional steps.\n *\n * Use this function if you want to show users instructions on how to add/modify\n * code in their file. This is helpful if automatic insertion failed or is not possible/feasible.\n *\n * @param filename the name of the file to which the code snippet should be applied.\n * If a path is provided, only the filename will be used.\n *\n * @param codeSnippet the snippet to be printed. Use {@link makeCodeSnippet} to create the\n * diff-like format for visually highlighting unchanged or modified lines of code.\n *\n * @param hint (optional) a hint to be printed after the main instruction to add\n * the code from @param codeSnippet to their @param filename.\n *\n * TODO: refactor copy paste instructions across different wizards to use this function.\n * this might require adding a custom message parameter to the function\n */\nexport async function showCopyPasteInstructions(\n filename: string,\n codeSnippet: string,\n hint?: string,\n): Promise<void> {\n clack.log.step(\n `Add the following code to your ${chalk.cyan(basename(filename))} file:${\n hint ? chalk.dim(` (${chalk.dim(hint)})`) : ''\n }`,\n );\n\n // Padding the code snippet to be printed with a \\n at the beginning and end\n // This makes it easier to distinguish the snippet from the rest of the output\n // Intentionally logging directly to console here so that the code can be copied/pasted directly\n // eslint-disable-next-line no-console\n console.log(`\\n${codeSnippet}\\n`);\n\n await abortIfCancelled(\n clack.select({\n message: 'Did you apply the snippet above?',\n options: [{ label: 'Yes, continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n\n/**\n * Callback that exposes formatting helpers for a code snippet.\n * @param unchanged - Formats text as old code.\n * @param plus - Formats text as new code.\n * @param minus - Formats text as removed code.\n */\ntype CodeSnippetFormatter = (\n unchanged: (txt: string) => string,\n plus: (txt: string) => string,\n minus: (txt: string) => string,\n) => string;\n\n/**\n * Crafts a code snippet that can be used to e.g.\n * - print copy/paste instructions to the console\n * - create a new config file.\n *\n * @param colors set this to true if you want the final snippet to be colored.\n * This is useful for printing the snippet to the console as part of copy/paste instructions.\n *\n * @param callback the callback that returns the formatted code snippet.\n * It exposes takes the helper functions for marking code as unchanged, new or removed.\n * These functions no-op if no special formatting should be applied\n * and otherwise apply the appropriate formatting/coloring.\n * (@see {@link CodeSnippetFormatter})\n *\n * @see {@link showCopyPasteInstructions} for the helper with which to display the snippet in the console.\n *\n * @returns a string containing the final, formatted code snippet.\n */\nexport function makeCodeSnippet(\n colors: boolean,\n callback: CodeSnippetFormatter,\n): string {\n const unchanged = (txt: string) => (colors ? chalk.grey(txt) : txt);\n const plus = (txt: string) => (colors ? chalk.greenBright(txt) : txt);\n const minus = (txt: string) => (colors ? chalk.redBright(txt) : txt);\n\n return callback(unchanged, plus, minus);\n}\n\n/**\n * Creates a new config file with the given @param filepath and @param codeSnippet.\n *\n * Use this function to create a new config file for users. This is useful\n * when users answered that they don't yet have a config file for a tool.\n *\n * (This doesn't mean that they don't yet have some other way of configuring\n * their tool but we can leave it up to them to figure out how to merge configs\n * here.)\n *\n * @param filepath absolute path to the new config file\n * @param codeSnippet the snippet to be inserted into the file\n * @param moreInformation (optional) the message to be printed after the file was created\n * For example, this can be a link to more information about configuring the tool.\n *\n * @returns true on success, false otherwise\n */\nexport async function createNewConfigFile(\n filepath: string,\n codeSnippet: string,\n { installDir }: Pick<WizardOptions, 'installDir'>,\n moreInformation?: string,\n): Promise<boolean> {\n if (!isAbsolute(filepath)) {\n debug(`createNewConfigFile: filepath is not absolute: ${filepath}`);\n return false;\n }\n\n const prettyFilename = chalk.cyan(relative(installDir, filepath));\n\n try {\n await fs.promises.writeFile(filepath, codeSnippet);\n\n clack.log.success(`Added new ${prettyFilename} file.`);\n\n if (moreInformation) {\n clack.log.info(chalk.gray(moreInformation));\n }\n\n return true;\n } catch (e) {\n debug(e);\n clack.log.warn(\n `Could not create a new ${prettyFilename} file. Please create one manually and follow the instructions below.`,\n );\n }\n\n return false;\n}\n\nexport async function featureSelectionPrompt<F extends ReadonlyArray<Feature>>(\n features: F,\n): Promise<{ [key in F[number]['id']]: boolean }> {\n return traceStep('feature-selection', async () => {\n const selectedFeatures: Record<string, boolean> = {};\n\n for (const feature of features) {\n const selected = await abortIfCancelled(\n clack.select({\n message: feature.prompt,\n initialValue: true,\n options: [\n {\n value: true,\n label: 'Yes',\n hint: feature.enabledHint,\n },\n {\n value: false,\n label: 'No',\n hint: feature.disabledHint,\n },\n ],\n }),\n );\n\n selectedFeatures[feature.id] = selected;\n }\n\n return selectedFeatures as { [key in F[number]['id']]: boolean };\n });\n}\n\nexport async function askShouldInstallPackage(\n pkgName: string,\n): Promise<boolean> {\n return traceStep(`ask-install-package`, () =>\n abortIfCancelled(\n clack.confirm({\n message: `Do you want to install ${chalk.cyan(pkgName)}?`,\n }),\n ),\n );\n}\n\nexport async function askShouldAddPackageOverride(\n pkgName: string,\n pkgVersion: string,\n): Promise<boolean> {\n return traceStep(`ask-add-package-override`, () =>\n abortIfCancelled(\n clack.confirm({\n message: `Do you want to add an override for ${chalk.cyan(\n pkgName,\n )} version ${chalk.cyan(pkgVersion)}?`,\n }),\n ),\n );\n}\n\nexport async function askForAIConsent(options: Pick<WizardOptions, 'default'>) {\n return await traceStep('ask-for-ai-consent', async () => {\n const aiConsent = options.default\n ? true\n : await abortIfCancelled(\n clack.select({\n message: 'This setup wizard uses AI, are you happy to continue? ✨',\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'We will use AI to help you setup PostHog quickly',\n },\n {\n label: 'No',\n value: false,\n hint: \"I don't like AI\",\n },\n ],\n initialValue: true,\n }),\n );\n\n return aiConsent;\n });\n}\n\nexport async function askForCloudRegion(): Promise<CloudRegion> {\n return await traceStep('ask-for-cloud-region', async () => {\n const cloudRegion: CloudRegion = await abortIfCancelled(\n clack.select({\n message: 'Select your PostHog Cloud region',\n options: [\n {\n label: 'US 🇺🇸',\n value: 'us',\n hint: 'Your data will be stored in the US',\n },\n {\n label: 'EU 🇪🇺',\n value: 'eu',\n hint: 'Your data will be stored in the EU',\n },\n ],\n }),\n );\n\n return cloudRegion;\n });\n}\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { ZodSchema } from 'zod';
|
|
2
2
|
import type { AIModel, CloudRegion } from './types';
|
|
3
|
-
export
|
|
3
|
+
export declare const query: <S>({ message, model, region, schema, wizardHash, }: {
|
|
4
4
|
message: string;
|
|
5
5
|
model?: AIModel;
|
|
6
6
|
region: CloudRegion;
|
|
7
7
|
schema: ZodSchema<S>;
|
|
8
8
|
wizardHash: string;
|
|
9
|
-
}
|
|
10
|
-
export declare const query: <S>({ message, model, region, schema, wizardHash, }: QueryOptions<S>) => Promise<S>;
|
|
9
|
+
}) => Promise<S>;
|
package/dist/src/utils/query.js
CHANGED
|
@@ -9,8 +9,6 @@ const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
|
9
9
|
const urls_1 = require("./urls");
|
|
10
10
|
const analytics_1 = require("./analytics");
|
|
11
11
|
const axios_2 = require("axios");
|
|
12
|
-
const fixture_tracker_1 = require("../../e2e-tests/mocks/fixture-tracker");
|
|
13
|
-
const handlers_1 = require("../../e2e-tests/mocks/handlers");
|
|
14
12
|
const query = async ({ message, model = 'o4-mini', region, schema, wizardHash, }) => {
|
|
15
13
|
const jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(schema, 'schema').definitions;
|
|
16
14
|
const response = await axios_1.default
|
|
@@ -21,9 +19,6 @@ const query = async ({ message, model = 'o4-mini', region, schema, wizardHash, }
|
|
|
21
19
|
}, {
|
|
22
20
|
headers: {
|
|
23
21
|
'X-PostHog-Wizard-Hash': wizardHash,
|
|
24
|
-
...(handlers_1.shouldRecord
|
|
25
|
-
? { 'X-PostHog-Wizard-Fixture-Generation': true }
|
|
26
|
-
: {}),
|
|
27
22
|
},
|
|
28
23
|
})
|
|
29
24
|
.catch((error) => {
|
|
@@ -42,14 +37,6 @@ const query = async ({ message, model = 'o4-mini', region, schema, wizardHash, }
|
|
|
42
37
|
if (!validation.success) {
|
|
43
38
|
throw new Error(`Invalid response from wizard: ${validation.error.message}`);
|
|
44
39
|
}
|
|
45
|
-
if (process.env.NODE_ENV === 'test') {
|
|
46
|
-
const requestBody = JSON.stringify({
|
|
47
|
-
message,
|
|
48
|
-
model,
|
|
49
|
-
json_schema: { ...jsonSchema, name: 'schema', strict: true },
|
|
50
|
-
});
|
|
51
|
-
fixture_tracker_1.fixtureTracker.saveQueryFixture(requestBody, validation.data);
|
|
52
|
-
}
|
|
53
40
|
return validation.data;
|
|
54
41
|
};
|
|
55
42
|
exports.query = query;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/utils/query.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,2DAAqD;AAErD,iCAA+C;AAC/C,2CAAwC;AACxC,iCAAmC;
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/utils/query.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,2DAAqD;AAErD,iCAA+C;AAC/C,2CAAwC;AACxC,iCAAmC;AAE5B,MAAM,KAAK,GAAG,KAAK,EAAK,EAC7B,OAAO,EACP,KAAK,GAAG,SAAS,EACjB,MAAM,EACN,MAAM,EACN,UAAU,GAOX,EAAc,EAAE;IACf,MAAM,UAAU,GAAG,IAAA,oCAAe,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,WAAW,CAAC;IAEjE,MAAM,QAAQ,GAAG,MAAM,eAAK;SACzB,IAAI,CACH,GAAG,IAAA,4BAAqB,EAAC,MAAM,CAAC,mBAAmB,EACnD;QACE,OAAO;QACP,KAAK;QACL,WAAW,EAAE,EAAE,GAAG,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;KAC7D,EACD;QACE,OAAO,EAAE;YACP,uBAAuB,EAAE,UAAU;SACpC;KACF,CACF;SACA,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,IAAI,KAAK,YAAY,kBAAU,EAAE,CAAC;YAChC,qBAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE;gBAChC,oBAAoB,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM;gBAC5C,OAAO;gBACP,KAAK;gBACL,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,oBAAoB;aAC3B,CAAC,CAAC;QACL,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IAEL,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAExD,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,iCAAiC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,CAC5D,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC,IAAI,CAAC;AACzB,CAAC,CAAC;AApDW,QAAA,KAAK,SAoDhB","sourcesContent":["import axios from 'axios';\nimport type { ZodSchema } from 'zod';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport type { AIModel, CloudRegion } from './types';\nimport { getCloudUrlFromRegion } from './urls';\nimport { analytics } from './analytics';\nimport { AxiosError } from 'axios';\n\nexport const query = async <S>({\n message,\n model = 'o4-mini',\n region,\n schema,\n wizardHash,\n}: {\n message: string;\n model?: AIModel;\n region: CloudRegion;\n schema: ZodSchema<S>;\n wizardHash: string;\n}): Promise<S> => {\n const jsonSchema = zodToJsonSchema(schema, 'schema').definitions;\n\n const response = await axios\n .post<{ data: unknown }>(\n `${getCloudUrlFromRegion(region)}/api/wizard/query`,\n {\n message,\n model,\n json_schema: { ...jsonSchema, name: 'schema', strict: true },\n },\n {\n headers: {\n 'X-PostHog-Wizard-Hash': wizardHash,\n },\n },\n )\n .catch((error) => {\n if (error instanceof AxiosError) {\n analytics.captureException(error, {\n response_status_code: error.response?.status,\n message,\n model,\n json_schema: jsonSchema,\n type: 'wizard_query_error',\n });\n }\n\n throw error;\n });\n\n const validation = schema.safeParse(response.data.data);\n\n if (!validation.success) {\n throw new Error(\n `Invalid response from wizard: ${validation.error.message}`,\n );\n }\n\n return validation.data;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/wizard",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
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",
|
|
@@ -75,7 +75,6 @@
|
|
|
75
75
|
"husky": "^9.1.7",
|
|
76
76
|
"jest": "^29.5.0",
|
|
77
77
|
"lint-staged": "^15.5.1",
|
|
78
|
-
"msw": "^2.10.4",
|
|
79
78
|
"prettier": "^2.8.7",
|
|
80
79
|
"rimraf": "^3.0.2",
|
|
81
80
|
"ts-jest": "^29.1.0",
|
|
@@ -121,7 +120,7 @@
|
|
|
121
120
|
"author": "PostHog",
|
|
122
121
|
"license": "MIT",
|
|
123
122
|
"volta": {
|
|
124
|
-
"node": "18.20.
|
|
123
|
+
"node": "18.20.6",
|
|
125
124
|
"pnpm": "9.15.5"
|
|
126
125
|
},
|
|
127
126
|
"scripts": {
|
|
@@ -138,7 +137,6 @@
|
|
|
138
137
|
"fix:eslint": "eslint . --format stylish --fix",
|
|
139
138
|
"test": "pnpm build && jest",
|
|
140
139
|
"test:e2e": "pnpm build && ./e2e-tests/run.sh",
|
|
141
|
-
"test:e2e-record": "export RECORD_FIXTURES=true && pnpm build && ./e2e-tests/run.sh",
|
|
142
140
|
"try": "tsx bin.ts",
|
|
143
141
|
"test:watch": "jest --watch"
|
|
144
142
|
}
|