IMPORTANT: remove next/node packages
This commit is contained in:
parent
8d3891f30f
commit
61eb7bd9e1
33 changed files with 213 additions and 1351 deletions
|
@ -1,8 +1,6 @@
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
experimental: {
|
experimental: {},
|
||||||
instrumentationHook: true,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = nextConfig;
|
module.exports = nextConfig;
|
||||||
|
|
|
@ -16,6 +16,6 @@
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"typescript": "5.2.2",
|
"typescript": "5.2.2",
|
||||||
"@aptabase/nextjs": "*"
|
"@aptabase/react": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useAptabase } from '@aptabase/nextjs/client';
|
import { useAptabase } from '@aptabase/react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
export function Counter() {
|
export function Counter() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { AptabaseProvider } from '@aptabase/nextjs/client';
|
import { AptabaseProvider } from '@aptabase/react';
|
||||||
|
|
||||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { trackEvent } from '@aptabase/nextjs/server';
|
|
||||||
import { Counter } from './Counter';
|
import { Counter } from './Counter';
|
||||||
|
|
||||||
export default async function Home() {
|
export default async function Home() {
|
||||||
await trackEvent('page_view', { page: 'home' });
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
Aptabase + Next.js App Router <br /> <Counter />
|
Aptabase + Next.js App Router <br /> <Counter />
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
import { init } from '@aptabase/nextjs/server';
|
|
||||||
|
|
||||||
export function register() {
|
|
||||||
init('A-US-5431775171');
|
|
||||||
}
|
|
|
@ -1,9 +1,7 @@
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
experimental: {
|
experimental: {},
|
||||||
instrumentationHook: true,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = nextConfig;
|
module.exports = nextConfig;
|
||||||
|
|
|
@ -16,6 +16,6 @@
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"typescript": "5.2.2",
|
"typescript": "5.2.2",
|
||||||
"@aptabase/nextjs": "*"
|
"@aptabase/react": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useAptabase } from '@aptabase/nextjs/client';
|
import { useAptabase } from '@aptabase/react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
export function Counter() {
|
export function Counter() {
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
import { init } from '@aptabase/nextjs/server';
|
|
||||||
|
|
||||||
export function register() {
|
|
||||||
init('A-DEV-0000000000');
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { AptabaseProvider } from '@aptabase/nextjs/client';
|
import { AptabaseProvider } from '@aptabase/react';
|
||||||
import type { AppProps } from 'next/app';
|
import type { AppProps } from 'next/app';
|
||||||
|
|
||||||
export default function App({ Component, pageProps }: AppProps) {
|
export default function App({ Component, pageProps }: AppProps) {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { trackEvent } from '@aptabase/nextjs/server';
|
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
type Data = {
|
type Data = {
|
||||||
|
@ -6,6 +5,5 @@ type Data = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
|
||||||
await trackEvent('hello', { name: 'John Doe' }, req);
|
|
||||||
res.status(200).json({ name: 'John Doe' });
|
res.status(200).json({ name: 'John Doe' });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import { Counter } from '@/components/Counter';
|
import { Counter } from '@/components/Counter';
|
||||||
import { trackEvent } from '@aptabase/nextjs/server';
|
|
||||||
import { GetServerSideProps } from 'next';
|
import { GetServerSideProps } from 'next';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
||||||
await trackEvent('page_view', { page: 'home' }, req);
|
|
||||||
return { props: {} };
|
return { props: {} };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
1174
package-lock.json
generated
1174
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2023 Sumbit Labs Ltd.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
|
@ -1,59 +0,0 @@
|
||||||
{
|
|
||||||
"name": "@aptabase/nextjs",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"type": "module",
|
|
||||||
"description": "Next.js SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
|
|
||||||
"sideEffects": false,
|
|
||||||
"exports": {
|
|
||||||
"./package.json": "./package.json",
|
|
||||||
".": {
|
|
||||||
"import": "./dist/index.js",
|
|
||||||
"require": "./dist/index.cjs",
|
|
||||||
"types": "./dist/index.d.ts"
|
|
||||||
},
|
|
||||||
"./client": {
|
|
||||||
"import": "./dist/client.js",
|
|
||||||
"require": "./dist/client.cjs",
|
|
||||||
"types": "./dist/client.d.ts"
|
|
||||||
},
|
|
||||||
"./server": {
|
|
||||||
"import": "./dist/server.js",
|
|
||||||
"require": "./dist/server.cjs",
|
|
||||||
"types": "./dist/server.d.ts"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"typesVersions": {
|
|
||||||
"*": {
|
|
||||||
"*": [
|
|
||||||
"dist/*"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/aptabase/aptabase-js.git",
|
|
||||||
"directory": "packages/nextjs"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/aptabase/aptabase-js/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/aptabase/aptabase-js",
|
|
||||||
"license": "MIT",
|
|
||||||
"scripts": {
|
|
||||||
"build": "tsup"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"README.md",
|
|
||||||
"LICENSE",
|
|
||||||
"dist",
|
|
||||||
"package.json"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"@aptabase/node": "*",
|
|
||||||
"@aptabase/react": "*"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"react": "^18.0.0",
|
|
||||||
"next": "^13.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
export * from '@aptabase/react';
|
|
||||||
|
|
||||||
globalThis.__APTABASE_SDK_VERSION__ = `aptabase-nextjs@${process.env.PKG_VERSION}`;
|
|
1
packages/nextjs/src/global.d.ts
vendored
1
packages/nextjs/src/global.d.ts
vendored
|
@ -1 +0,0 @@
|
||||||
declare var __APTABASE_SDK_VERSION__: string;
|
|
|
@ -1 +0,0 @@
|
||||||
export type README = 'Use @aptabase/next/server or @aptabase/next/client instead.';
|
|
|
@ -1,42 +0,0 @@
|
||||||
import * as node from '@aptabase/node';
|
|
||||||
import { type AptabaseOptions } from '@aptabase/node';
|
|
||||||
import { type NextIncomingMessage } from 'next/dist/server/request-meta';
|
|
||||||
import { headers } from 'next/headers';
|
|
||||||
|
|
||||||
globalThis.__APTABASE_SDK_VERSION__ = `aptabase-nextjs@${process.env.PKG_VERSION}`;
|
|
||||||
|
|
||||||
export function init(appKey: string, options?: AptabaseOptions): void {
|
|
||||||
node.init(appKey, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function trackEvent(
|
|
||||||
eventName: string,
|
|
||||||
props?: Record<string, string | number | boolean>,
|
|
||||||
req?: NextIncomingMessage,
|
|
||||||
): Promise<void> {
|
|
||||||
const headers = getHeaders(req);
|
|
||||||
if (!headers) return Promise.resolve();
|
|
||||||
|
|
||||||
return node.trackEvent({ headers }, eventName, props);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHeaders(req?: NextIncomingMessage): Headers | undefined {
|
|
||||||
if (req) {
|
|
||||||
return new Headers({
|
|
||||||
'accept-language': req.headers['accept-language'] ?? '',
|
|
||||||
'user-agent': req.headers['user-agent'] ?? '',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// headers() might throw an error if called outside of a request context.
|
|
||||||
try {
|
|
||||||
return headers();
|
|
||||||
} catch {}
|
|
||||||
|
|
||||||
// If we're here, the app is probably using the Pages Router and the developer forgot to pass the req parameter.
|
|
||||||
if (!req) {
|
|
||||||
console.warn("Aptabase: The 'req' parameter of trackEvent is required when using Pages Router.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es6",
|
|
||||||
"strict": true,
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"types": ["@types"]
|
|
||||||
},
|
|
||||||
"declaration": true,
|
|
||||||
"declarationDir": "./dist"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
import { defineConfig } from 'tsup';
|
|
||||||
const { version } = require('./package.json');
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
entry: ['src/index.ts', 'src/server.ts', 'src/client.tsx'],
|
|
||||||
format: ['cjs', 'esm'],
|
|
||||||
dts: true,
|
|
||||||
splitting: false,
|
|
||||||
minify: true,
|
|
||||||
sourcemap: true,
|
|
||||||
clean: true,
|
|
||||||
env: {
|
|
||||||
PKG_VERSION: version,
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2023 Sumbit Labs Ltd.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
|
@ -1,35 +0,0 @@
|
||||||
{
|
|
||||||
"name": "@aptabase/node",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"type": "module",
|
|
||||||
"description": "Node.js SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
|
|
||||||
"main": "./dist/index.cjs",
|
|
||||||
"module": "./dist/index.js",
|
|
||||||
"types": "./dist/index.d.ts",
|
|
||||||
"exports": {
|
|
||||||
".": {
|
|
||||||
"require": "./dist/index.cjs",
|
|
||||||
"import": "./dist/index.js",
|
|
||||||
"types": "./dist/index.d.ts"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/aptabase/aptabase-js.git",
|
|
||||||
"directory": "packages/node"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/aptabase/aptabase-js/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/aptabase/aptabase-js",
|
|
||||||
"license": "MIT",
|
|
||||||
"scripts": {
|
|
||||||
"build": "tsup"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"README.md",
|
|
||||||
"LICENSE",
|
|
||||||
"dist",
|
|
||||||
"package.json"
|
|
||||||
]
|
|
||||||
}
|
|
8
packages/node/src/global.d.ts
vendored
8
packages/node/src/global.d.ts
vendored
|
@ -1,8 +0,0 @@
|
||||||
type AptabaseState = {
|
|
||||||
appKey: string;
|
|
||||||
apiUrl: string;
|
|
||||||
options?: import('./types').AptabaseOptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
declare var __APTABASE__: AptabaseState;
|
|
||||||
declare var __APTABASE_SDK_VERSION__: string;
|
|
|
@ -1,94 +0,0 @@
|
||||||
import { AptabaseOptions } from './types';
|
|
||||||
|
|
||||||
export { AptabaseOptions };
|
|
||||||
|
|
||||||
const isDebug = process.env.NODE_ENV === 'development';
|
|
||||||
|
|
||||||
const _hosts: { [region: string]: string } = {
|
|
||||||
US: 'https://us.aptabase.com',
|
|
||||||
EU: 'https://eu.aptabase.com',
|
|
||||||
DEV: 'http://localhost:3000',
|
|
||||||
SH: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function init(appKey: string, options?: AptabaseOptions) {
|
|
||||||
const parts = appKey.split('-');
|
|
||||||
if (parts.length !== 3 || _hosts[parts[1]] === undefined) {
|
|
||||||
console.warn(`Aptabase: The App Key "${appKey}" is invalid. Tracking will be disabled.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseUrl = getBaseUrl(parts[1], options);
|
|
||||||
const apiUrl = `${baseUrl}/api/v0/event`;
|
|
||||||
globalThis.__APTABASE__ = { appKey, apiUrl, options };
|
|
||||||
}
|
|
||||||
|
|
||||||
// We only need the headers from the request object
|
|
||||||
type PartialRequest = Pick<Request, 'headers'>;
|
|
||||||
|
|
||||||
export async function trackEvent(
|
|
||||||
req: PartialRequest,
|
|
||||||
eventName: string,
|
|
||||||
props?: Record<string, string | number | boolean>,
|
|
||||||
): Promise<void> {
|
|
||||||
const { appKey, apiUrl, options } = globalThis.__APTABASE__ || {};
|
|
||||||
if (!appKey) return Promise.resolve();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(apiUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'User-Agent': req.headers.get('user-agent') ?? '',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'App-Key': appKey,
|
|
||||||
},
|
|
||||||
credentials: 'omit',
|
|
||||||
body: JSON.stringify({
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
sessionId: 'CHANGE-THIS',
|
|
||||||
eventName: eventName,
|
|
||||||
systemProps: {
|
|
||||||
isDebug,
|
|
||||||
locale: extractLocale(req.headers.get('accept-language')),
|
|
||||||
appVersion: options,
|
|
||||||
sdkVersion: globalThis.__APTABASE_SDK_VERSION__ ?? `aptabase-node@${process.env.PKG_VERSION}`,
|
|
||||||
},
|
|
||||||
props: props,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status >= 300) {
|
|
||||||
const responseBody = await response.text();
|
|
||||||
console.warn(`Failed to send event "${eventName}": ${response.status} ${responseBody}`);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn(`Failed to send event "${eventName}"`);
|
|
||||||
console.warn(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBaseUrl(region: string, options?: AptabaseOptions): string | undefined {
|
|
||||||
if (region === 'SH') {
|
|
||||||
if (!options?.host) {
|
|
||||||
console.warn(`Host parameter must be defined when using Self-Hosted App Key. Tracking will be disabled.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return options.host;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _hosts[region];
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractLocale(locale: string | null): string | null {
|
|
||||||
if (!locale) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const languageLocales = locale.split(',');
|
|
||||||
const firstLanguageLocale = languageLocales[0];
|
|
||||||
if (!firstLanguageLocale) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const [language] = firstLanguageLocale.split(';');
|
|
||||||
return language || null;
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
export type AptabaseOptions = {
|
|
||||||
host?: string;
|
|
||||||
appVersion?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type AptabaseState = {
|
|
||||||
appKey?: string;
|
|
||||||
options?: AptabaseOptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
declare var __APTABASE__: AptabaseState;
|
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es6",
|
|
||||||
"strict": true,
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"types": ["@types"]
|
|
||||||
},
|
|
||||||
"declaration": true,
|
|
||||||
"declarationDir": "./dist"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
import { defineConfig } from 'tsup';
|
|
||||||
const { version } = require('./package.json');
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
entry: ['src/index.ts'],
|
|
||||||
format: ['cjs', 'esm'],
|
|
||||||
dts: true,
|
|
||||||
splitting: false,
|
|
||||||
minify: true,
|
|
||||||
sourcemap: true,
|
|
||||||
clean: true,
|
|
||||||
env: {
|
|
||||||
PKG_VERSION: version,
|
|
||||||
},
|
|
||||||
});
|
|
Loading…
Add table
Add a link
Reference in a new issue