fix sdk version

This commit is contained in:
goenning 2023-09-01 15:24:42 +01:00
parent 47042f043b
commit ce24e8f4fb
12 changed files with 31 additions and 7 deletions

View file

@ -1 +1,3 @@
export * from '@aptabase/react'; export * from '@aptabase/react';
globalThis.__APTABASE_SDK_VERSION__ = `aptabase-nextjs@${process.env.PKG_VERSION}`;

1
packages/nextjs/src/global.d.ts vendored Normal file
View file

@ -0,0 +1 @@
declare var __APTABASE_SDK_VERSION__: string;

View file

@ -3,6 +3,8 @@ import { type AptabaseOptions } from '@aptabase/node';
import { type NextIncomingMessage } from 'next/dist/server/request-meta'; import { type NextIncomingMessage } from 'next/dist/server/request-meta';
import { headers } from 'next/headers'; import { headers } from 'next/headers';
globalThis.__APTABASE_SDK_VERSION__ = `aptabase-nextjs@${process.env.PKG_VERSION}`;
export function init(appKey: string, options?: AptabaseOptions): void { export function init(appKey: string, options?: AptabaseOptions): void {
node.init(appKey, options); node.init(appKey, options);
} }

View file

@ -1,4 +1,5 @@
import { defineConfig } from 'tsup'; import { defineConfig } from 'tsup';
const { version } = require('./package.json');
export default defineConfig({ export default defineConfig({
entry: ['src/index.ts', 'src/server.ts', 'src/client.tsx'], entry: ['src/index.ts', 'src/server.ts', 'src/client.tsx'],
@ -8,4 +9,7 @@ export default defineConfig({
minify: true, minify: true,
sourcemap: true, sourcemap: true,
clean: true, clean: true,
env: {
PKG_VERSION: version,
},
}); });

View file

@ -4,3 +4,4 @@ type AptabaseState = {
}; };
declare var __APTABASE__: AptabaseState; declare var __APTABASE__: AptabaseState;
declare var __APTABASE_SDK_VERSION__: string;

View file

@ -14,7 +14,8 @@ export async function trackEvent(
eventName: string, eventName: string,
props?: Record<string, string | number | boolean>, props?: Record<string, string | number | boolean>,
): Promise<void> { ): Promise<void> {
const appKey = globalThis.__APTABASE__?.appKey; const { appKey } = globalThis.__APTABASE__ || {};
if (!appKey) return Promise.resolve(); if (!appKey) return Promise.resolve();
const userAgent = req.headers.get('user-agent') ?? ''; const userAgent = req.headers.get('user-agent') ?? '';
@ -27,7 +28,7 @@ export async function trackEvent(
isDebug: true, isDebug: true,
locale: 'en', locale: 'en',
appVersion: '', appVersion: '',
sdkVersion: 'aptabase-node@0.1.0', sdkVersion: globalThis.__APTABASE_SDK_VERSION__ ?? `aptabase-node@${process.env.PKG_VERSION}`,
}, },
props: props, props: props,
}); });

View file

@ -1,4 +1,5 @@
import { defineConfig } from 'tsup'; import { defineConfig } from 'tsup';
const { version } = require('./package.json');
export default defineConfig({ export default defineConfig({
entry: ['src/index.ts'], entry: ['src/index.ts'],
@ -8,4 +9,7 @@ export default defineConfig({
minify: true, minify: true,
sourcemap: true, sourcemap: true,
clean: true, clean: true,
env: {
PKG_VERSION: version,
},
}); });

1
packages/react/src/global.d.ts vendored Normal file
View file

@ -0,0 +1 @@
declare var __APTABASE_SDK_VERSION__: string;

View file

@ -3,9 +3,12 @@
import { init, trackEvent, type AptabaseOptions } from '@aptabase/web'; import { init, trackEvent, type AptabaseOptions } from '@aptabase/web';
import { createContext, useContext, useEffect } from 'react'; import { createContext, useContext, useEffect } from 'react';
globalThis.__APTABASE_SDK_VERSION__ = `aptabase-react@${process.env.PKG_VERSION}`;
type ContextProps = { type ContextProps = {
appKey?: string; appKey?: string;
} & AptabaseOptions; options?: AptabaseOptions;
};
export type AptabaseClient = { export type AptabaseClient = {
trackEvent: typeof trackEvent; trackEvent: typeof trackEvent;
@ -24,7 +27,7 @@ export function AptabaseProvider({ appKey, options, children }: Props) {
init(appKey, options); init(appKey, options);
}, [appKey, options]); }, [appKey, options]);
return <AptabaseContext.Provider value={{ appKey, ...options }}>{children}</AptabaseContext.Provider>; return <AptabaseContext.Provider value={{ appKey, options }}>{children}</AptabaseContext.Provider>;
} }
export function useAptabase(): AptabaseClient { export function useAptabase(): AptabaseClient {

View file

@ -1,4 +1,5 @@
import { defineConfig } from 'tsup'; import { defineConfig } from 'tsup';
const { version } = require('./package.json');
export default defineConfig({ export default defineConfig({
entry: ['src/index.tsx'], entry: ['src/index.tsx'],
@ -8,4 +9,7 @@ export default defineConfig({
minify: true, minify: true,
sourcemap: true, sourcemap: true,
clean: true, clean: true,
env: {
PKG_VERSION: version,
},
}); });

1
packages/web/src/global.d.ts vendored Normal file
View file

@ -0,0 +1 @@
declare var __APTABASE_SDK_VERSION__: string;

View file

@ -1,9 +1,9 @@
// env.PKG_VERSION is replaced by rollup during build phase const sdkVersion = ;
const sdkVersion = `aptabase-web@${process.env.PKG_VERSION}`;
export type AptabaseOptions = { export type AptabaseOptions = {
host?: string; host?: string;
appVersion?: string; appVersion?: string;
__sdkVersion?: string;
}; };
let _appKey = ''; let _appKey = '';
@ -64,7 +64,7 @@ export function trackEvent(eventName: string, props?: Record<string, string | nu
isDebug: _isDebug, isDebug: _isDebug,
locale: _locale, locale: _locale,
appVersion: _options?.appVersion ?? '', appVersion: _options?.appVersion ?? '',
sdkVersion, sdkVersion: globalThis.__APTABASE_SDK_VERSION__ ?? `aptabase-web@${process.env.PKG_VERSION}`,
}, },
props: props, props: props,
}); });