Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: use latest sdks and proxy both request and op1.js in public

Carl-Gerhard Lindesvärde4fac81d271f
diff --git a/apps/public/app/api/[...op]/route.ts b/apps/public/app/api/[...op]/route.ts
index 3660ba622..82945e540 100644
--- a/apps/public/app/api/[...op]/route.ts
+++ b/apps/public/app/api/[...op]/route.ts
@@ -1,67 +1,7 @@
-import { createHash } from 'node:crypto';
-import { getClientIpFromHeaders } from '@openpanel/common/server/get-client-ip';
-// adding .js next/script import fixes an issues
-// with esm and nextjs (when using pages dir)
-import { NextResponse } from 'next/server.js';
+import {
+ createNextRouteHandler,
+ createScriptHandler,
+} from '@openpanel/nextjs/server';
-type CreateNextRouteHandlerOptions = {
- apiUrl?: string;
-};
-
-function createNextRouteHandler(options: CreateNextRouteHandlerOptions) {
- return async function POST(req: Request) {
- const apiUrl = options.apiUrl ?? 'https://api.openpanel.dev';
- const headers = new Headers(req.headers);
- const clientIp = getClientIpFromHeaders(headers);
- console.log('debug', {
- clientIp,
- userAgent: req.headers.get('user-agent'),
- });
- try {
- const res = await fetch(`${apiUrl}/track`, {
- method: 'POST',
- headers,
- body: JSON.stringify(await req.json()),
- });
- return NextResponse.json(await res.text(), { status: res.status });
- } catch (e) {
- return NextResponse.json(e);
- }
- };
-}
-
-function createScriptHandler() {
- return async function GET(req: Request) {
- if (!req.url.endsWith('op1.js')) {
- return NextResponse.json({ error: 'Not found' }, { status: 404 });
- }
-
- const scriptUrl = 'https://openpanel.dev/op1.js';
- try {
- const res = await fetch(scriptUrl, {
- next: { revalidate: 86400 },
- });
- const text = await res.text();
- const etag = `"${createHash('md5').update(text).digest('hex')}"`;
- return new NextResponse(text, {
- headers: {
- 'Content-Type': 'text/javascript',
- 'Cache-Control':
- 'public, max-age=86400, stale-while-revalidate=86400',
- ETag: etag,
- },
- });
- } catch (e) {
- return NextResponse.json(
- {
- error: 'Failed to fetch script',
- message: e instanceof Error ? e.message : String(e),
- },
- { status: 500 },
- );
- }
- };
-}
-
-export const POST = createNextRouteHandler({});
+export const POST = createNextRouteHandler();
export const GET = createScriptHandler();
diff --git a/apps/public/package.json b/apps/public/package.json
index 728988886..174c3d3bd 100644
--- a/apps/public/package.json
+++ b/apps/public/package.json
@@ -14,7 +14,7 @@
"@hyperdx/node-opentelemetry": "^0.8.1",
"@number-flow/react": "0.3.5",
"@openpanel/common": "workspace:*",
- "@openpanel/nextjs": "^1.0.5",
+ "@openpanel/nextjs": "^1.0.12",
"@openpanel/payments": "workspace:^",
"@openpanel/sdk-info": "workspace:^",
"@openstatus/react": "0.0.3",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c0e8c665f..00214c30f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -275,8 +275,8 @@ importers:
specifier: workspace:*
version: link:../../packages/common
'@openpanel/nextjs':
- specifier: ^1.0.5
+ specifier: ^1.0.12
'@openpanel/payments':
specifier: workspace:^
version: link:../../packages/payments
@@ -312,22 +312,22 @@ importers:
fumadocs-core:
specifier: 14.1.1
fumadocs-mdx:
specifier: 11.1.1
fumadocs-ui:
specifier: 14.1.1
geist:
specifier: 1.3.1
lucide-react:
specifier: 0.454.0
version: 0.454.0([email protected])
next:
specifier: 15.0.3
react:
specifier: 'catalog:'
version: 19.1.1
@@ -4797,12 +4797,12 @@ packages:
resolution: {integrity: sha512-T8TbSnGsxo6TDBJx/Sgv/BlVJL3tshxZP7Aq5R1mSnM5OcHY2dQaxLMu2+E8u3gN0MLOzdjurqN4ZRVuzQycOQ==}
engines: {node: '>=8.0'}
- '@openpanel/[email protected]':
- resolution: {integrity: sha512-+Zdrl5fC8Iczub/pVvX8Xp9q6mQvApNXGenCEkdiAZk9nT7xpaLfzkdHnwx7XHxp5H50zdwgqWDGiwLMqRWjKA==}
+ '@openpanel/[email protected]':
+ resolution: {integrity: sha512-uGNTsjQ37/rN07tGd2joUkXXWIWRFTNlMYq7P7H1hyQ4xnifRC4kZqKS4ocFWoO4yg6qfoDjCHgx15C7j6BZZQ==}
peerDependencies:
- next: ^12.0.0 || ^13.0.0 || ^14.0.0
- react: ^16.8.0 || ^17.0.0 || ^18.0.0
- react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
+ next: ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0
+ react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
+ react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
'@openpanel/[email protected]':
resolution: {integrity: sha512-FNmmfjdXoC/VHEjA+WkrQ4lyM5lxEmV7xDd57uj4E+lIS0sU3DLG2mV/dpS8AscnZbUvuMn3kPhiLCqYzuv/gg==}
@@ -4810,6 +4810,9 @@ packages:
'@openpanel/[email protected]':
resolution: {integrity: sha512-cVZ7Kr9SicczJ/RDIfEtZs8+1iGDzwkabVA/j3NqSl8VSucsC8m1+LVbjmCDzCJNnK4yVn6tEcc9PJRi2rtllw==}
+ '@openpanel/[email protected]':
+ resolution: {integrity: sha512-vU9Z9Kc0dxyE4abTi9KAu2zDE2/z4RDcHDLk9NwNRgrZGDlYereOatwKNnvrwfU96066bjfOrSd+vbjmkmsOoA==}
+
'@openstatus/[email protected]':
resolution: {integrity: sha512-uDiegz7e3H67pG8lTT+op+6w5keTT7XpcENrREaqlWl5j53TYyO8nheOG1PeNw2/Qgd5KaGeRJJFn1crhTUSYw==}
peerDependencies:
@@ -19907,10 +19910,10 @@ snapshots:
'@oozcitak/[email protected]': {}
dependencies:
- '@openpanel/web': 1.0.1
+ '@openpanel/web': 1.0.2
react: 19.1.1
react-dom: 19.1.1([email protected])
@@ -19920,6 +19923,10 @@ snapshots:
dependencies:
'@openpanel/sdk': 1.0.0
+ '@openpanel/[email protected]':
+ dependencies:
+ '@openpanel/sdk': 1.0.0
+
dependencies:
react: 19.1.1
@@ -27760,7 +27767,7 @@ snapshots:
optional: true
dependencies:
'@formatjs/intl-localematcher': 0.5.6
'@orama/orama': 3.0.1
@@ -27778,14 +27785,14 @@ snapshots:
unist-util-visit: 5.0.0
optionalDependencies:
algoliasearch: 4.24.0
react: 19.1.1
react-dom: 19.1.1([email protected])
transitivePeerDependencies:
- '@types/react'
- supports-color
dependencies:
'@mdx-js/mdx': 3.1.0([email protected])
chokidar: 4.0.1
@@ -27793,16 +27800,16 @@ snapshots:
esbuild: 0.24.0
estree-util-value-to-estree: 3.1.2
fast-glob: 3.3.2
gray-matter: 4.0.3
micromatch: 4.0.8
zod: 3.24.2
transitivePeerDependencies:
- acorn
- supports-color
dependencies:
@@ -27816,8 +27823,8 @@ snapshots:
'@tailwindcss/typography': 0.5.15([email protected])
class-variance-authority: 0.7.1
react: 19.1.1
react-dom: 19.1.1([email protected])
@@ -27865,9 +27872,9 @@ snapshots:
- encoding
- supports-color
dependencies:
@@ -30292,6 +30299,32 @@ snapshots:
- '@babel/core'
- babel-plugin-macros
+ dependencies:
+ '@next/env': 15.0.3
+ '@swc/counter': 0.1.3
+ '@swc/helpers': 0.5.13
+ busboy: 1.6.0
+ caniuse-lite: 1.0.30001674
+ postcss: 8.4.31
+ react: 19.1.1
+ react-dom: 19.1.1([email protected])
+ styled-jsx: 5.1.6([email protected])
+ optionalDependencies:
+ '@next/swc-darwin-arm64': 15.0.3
+ '@next/swc-darwin-x64': 15.0.3
+ '@next/swc-linux-arm64-gnu': 15.0.3
+ '@next/swc-linux-arm64-musl': 15.0.3
+ '@next/swc-linux-x64-gnu': 15.0.3
+ '@next/swc-linux-x64-musl': 15.0.3
+ '@next/swc-win32-arm64-msvc': 15.0.3
+ '@next/swc-win32-x64-msvc': 15.0.3
+ '@opentelemetry/api': 1.8.0
+ sharp: 0.33.5
+ transitivePeerDependencies:
+ - '@babel/core'
+ - babel-plugin-macros
+
dependencies:
'@next/env': 15.0.3