@posthog/nuxt 1.7.82 → 1.7.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -3
- package/dist/runtime/nitro-plugin-v2.d.ts +2 -0
- package/dist/runtime/nitro-plugin-v2.js +12 -0
- package/dist/runtime/nitro-plugin-v3.d.ts +2 -0
- package/dist/runtime/nitro-plugin-v3.js +19 -0
- package/dist/runtime/nitro-plugin.d.ts +12 -2
- package/dist/runtime/nitro-plugin.js +11 -11
- package/dist/runtime/vue-plugin.js +1 -1
- package/package.json +6 -6
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addPlugin, addServerPlugin, addImportsDir } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addPlugin, getNuxtVersion, addServerPlugin, addImportsDir } from '@nuxt/kit';
|
|
2
2
|
import { resolveBinaryPath, spawnLocal } from '@posthog/plugin-utils';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { dirname } from 'node:path';
|
|
@@ -34,8 +34,9 @@ const module$1 = defineNuxtModule({
|
|
|
34
34
|
const resolver = createResolver(import.meta.url);
|
|
35
35
|
const normalizedPublicKey = normalizeApiKey(options.publicKey);
|
|
36
36
|
const normalizedHost = normalizeHost(options.host);
|
|
37
|
-
addPlugin(resolver.resolve("./runtime/vue-plugin"));
|
|
38
|
-
|
|
37
|
+
addPlugin({ src: resolver.resolve("./runtime/vue-plugin"), mode: "client" });
|
|
38
|
+
const nitroPlugin = Number.parseInt(getNuxtVersion(nuxt), 10) >= 5 ? "nitro-plugin-v3" : "nitro-plugin-v2";
|
|
39
|
+
addServerPlugin(resolver.resolve(`./runtime/${nitroPlugin}`));
|
|
39
40
|
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
40
41
|
Object.assign(nuxt.options.runtimeConfig.public, {
|
|
41
42
|
posthog: {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
|
|
2
|
+
import { setupPostHogNitroPlugin } from "./nitro-plugin.js";
|
|
3
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
4
|
+
setupPostHogNitroPlugin({
|
|
5
|
+
useRuntimeConfig,
|
|
6
|
+
onError: (handler) => nitroApp.hooks.hook(
|
|
7
|
+
"error",
|
|
8
|
+
(error, { event }) => handler(error, event ? { path: event.path, method: event.method } : void 0)
|
|
9
|
+
),
|
|
10
|
+
onClose: (handler) => nitroApp.hooks.hook("close", handler)
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { definePlugin } from "nitro";
|
|
2
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
3
|
+
import { setupPostHogNitroPlugin } from "./nitro-plugin.js";
|
|
4
|
+
export default definePlugin((nitroApp) => {
|
|
5
|
+
setupPostHogNitroPlugin({
|
|
6
|
+
useRuntimeConfig,
|
|
7
|
+
onError: (handler) => nitroApp.hooks.hook(
|
|
8
|
+
"error",
|
|
9
|
+
(error, { event }) => handler(
|
|
10
|
+
error,
|
|
11
|
+
event ? {
|
|
12
|
+
path: new URL(event.req.url).pathname,
|
|
13
|
+
method: event.req.method
|
|
14
|
+
} : void 0
|
|
15
|
+
)
|
|
16
|
+
),
|
|
17
|
+
onClose: (handler) => nitroApp.hooks.hook("close", handler)
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type RequestContext = {
|
|
2
|
+
path?: string;
|
|
3
|
+
method?: string;
|
|
4
|
+
};
|
|
5
|
+
type ErrorHandler = (error: unknown, request?: RequestContext) => Promise<void>;
|
|
6
|
+
type NitroBindings = {
|
|
7
|
+
useRuntimeConfig: () => unknown;
|
|
8
|
+
onError: (handler: ErrorHandler) => void;
|
|
9
|
+
onClose: (handler: () => Promise<void>) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function setupPostHogNitroPlugin({ useRuntimeConfig, onError, onClose }: NitroBindings): void;
|
|
12
|
+
export {};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { PostHog } from "posthog-node";
|
|
2
2
|
import { uuidv7 } from "@posthog/core/vendor/uuidv7";
|
|
3
|
-
|
|
4
|
-
import { useRuntimeConfig } from "#imports";
|
|
5
|
-
export default defineNitroPlugin((nitroApp) => {
|
|
3
|
+
export function setupPostHogNitroPlugin({ useRuntimeConfig, onError, onClose }) {
|
|
6
4
|
const runtimeConfig = useRuntimeConfig();
|
|
7
5
|
const posthogCommon = runtimeConfig.public.posthog;
|
|
8
6
|
const posthogServerConfig = runtimeConfig.posthogServerConfig;
|
|
9
|
-
const debug = posthogCommon.debug;
|
|
7
|
+
const debug = posthogCommon.debug === true;
|
|
10
8
|
const client = new PostHog(posthogCommon.publicKey, {
|
|
11
9
|
host: posthogCommon.host,
|
|
12
10
|
...posthogServerConfig
|
|
@@ -15,20 +13,22 @@ export default defineNitroPlugin((nitroApp) => {
|
|
|
15
13
|
client.debug(true);
|
|
16
14
|
}
|
|
17
15
|
if (posthogServerConfig.enableExceptionAutocapture) {
|
|
18
|
-
|
|
16
|
+
onError((error, request) => {
|
|
19
17
|
const props = {
|
|
20
18
|
$process_person_profile: false
|
|
21
19
|
};
|
|
22
|
-
if (
|
|
23
|
-
props.path =
|
|
20
|
+
if (request?.path) {
|
|
21
|
+
props.path = request.path;
|
|
24
22
|
}
|
|
25
|
-
if (
|
|
26
|
-
props.method =
|
|
23
|
+
if (request?.method) {
|
|
24
|
+
props.method = request.method;
|
|
27
25
|
}
|
|
28
26
|
client.captureException(error, uuidv7(), props);
|
|
27
|
+
return client.flush().catch(() => {
|
|
28
|
+
});
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
onClose(async () => {
|
|
32
32
|
await client.shutdown();
|
|
33
33
|
});
|
|
34
|
-
}
|
|
34
|
+
}
|
|
@@ -6,7 +6,7 @@ export default defineNuxtPlugin({
|
|
|
6
6
|
const runtimeConfig = useRuntimeConfig();
|
|
7
7
|
const posthogCommon = runtimeConfig.public.posthog;
|
|
8
8
|
const posthogClientConfig = runtimeConfig.public.posthogClientConfig;
|
|
9
|
-
if (
|
|
9
|
+
if (posthog.__loaded) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
posthog.init(posthogCommon.publicKey, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/nuxt",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.83",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@posthog/cli": "~0.11.1",
|
|
30
30
|
"@nuxt/kit": ">=3.7.0",
|
|
31
|
-
"posthog-node": "^5.49.
|
|
32
|
-
"@posthog/core": "^1.48.
|
|
33
|
-
"@posthog/plugin-utils": "^1.1.
|
|
34
|
-
"posthog-js": "^1.
|
|
31
|
+
"posthog-node": "^5.49.1",
|
|
32
|
+
"@posthog/core": "^1.48.2",
|
|
33
|
+
"@posthog/plugin-utils": "^1.1.3",
|
|
34
|
+
"posthog-js": "^1.417.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^20.0.0",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"build": "nuxt-module-build build",
|
|
47
47
|
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz",
|
|
48
48
|
"lint": "eslint .",
|
|
49
|
-
"test:unit": "node tests/vue-plugin.test.mjs && node tests/sourcemaps-ssr.test.mjs"
|
|
49
|
+
"test:unit": "node tests/vue-plugin.test.mjs && node tests/nitro-plugin.test.mjs && node tests/sourcemaps-ssr.test.mjs && node tests/nuxt5-consumer.test.mjs"
|
|
50
50
|
}
|
|
51
51
|
}
|