From ce24e8f4fbf5fd1127a367751904db9bf4e38557 Mon Sep 17 00:00:00 2001 From: goenning Date: Fri, 1 Sep 2023 15:24:42 +0100 Subject: [PATCH] fix sdk version --- packages/nextjs/src/client.tsx | 2 ++ packages/nextjs/src/global.d.ts | 1 + packages/nextjs/src/server.ts | 2 ++ packages/nextjs/tsup.config.ts | 4 ++++ packages/node/src/global.d.ts | 1 + packages/node/src/index.ts | 5 +++-- packages/node/tsup.config.ts | 4 ++++ packages/react/src/global.d.ts | 1 + packages/react/src/index.tsx | 7 +++++-- packages/react/tsup.config.ts | 4 ++++ packages/web/src/global.d.ts | 1 + packages/web/src/index.ts | 6 +++--- 12 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 packages/nextjs/src/global.d.ts create mode 100644 packages/react/src/global.d.ts create mode 100644 packages/web/src/global.d.ts diff --git a/packages/nextjs/src/client.tsx b/packages/nextjs/src/client.tsx index faf287d..ff63a32 100644 --- a/packages/nextjs/src/client.tsx +++ b/packages/nextjs/src/client.tsx @@ -1 +1,3 @@ export * from '@aptabase/react'; + +globalThis.__APTABASE_SDK_VERSION__ = `aptabase-nextjs@${process.env.PKG_VERSION}`; diff --git a/packages/nextjs/src/global.d.ts b/packages/nextjs/src/global.d.ts new file mode 100644 index 0000000..4dbd621 --- /dev/null +++ b/packages/nextjs/src/global.d.ts @@ -0,0 +1 @@ +declare var __APTABASE_SDK_VERSION__: string; diff --git a/packages/nextjs/src/server.ts b/packages/nextjs/src/server.ts index 3610311..0a568de 100644 --- a/packages/nextjs/src/server.ts +++ b/packages/nextjs/src/server.ts @@ -3,6 +3,8 @@ 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); } diff --git a/packages/nextjs/tsup.config.ts b/packages/nextjs/tsup.config.ts index 6c9e25e..b4ddcd5 100644 --- a/packages/nextjs/tsup.config.ts +++ b/packages/nextjs/tsup.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'tsup'; +const { version } = require('./package.json'); export default defineConfig({ entry: ['src/index.ts', 'src/server.ts', 'src/client.tsx'], @@ -8,4 +9,7 @@ export default defineConfig({ minify: true, sourcemap: true, clean: true, + env: { + PKG_VERSION: version, + }, }); diff --git a/packages/node/src/global.d.ts b/packages/node/src/global.d.ts index c15685e..8754882 100644 --- a/packages/node/src/global.d.ts +++ b/packages/node/src/global.d.ts @@ -4,3 +4,4 @@ type AptabaseState = { }; declare var __APTABASE__: AptabaseState; +declare var __APTABASE_SDK_VERSION__: string; diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index c24f993..2c87252 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -14,7 +14,8 @@ export async function trackEvent( eventName: string, props?: Record, ): Promise { - const appKey = globalThis.__APTABASE__?.appKey; + const { appKey } = globalThis.__APTABASE__ || {}; + if (!appKey) return Promise.resolve(); const userAgent = req.headers.get('user-agent') ?? ''; @@ -27,7 +28,7 @@ export async function trackEvent( isDebug: true, locale: 'en', appVersion: '', - sdkVersion: 'aptabase-node@0.1.0', + sdkVersion: globalThis.__APTABASE_SDK_VERSION__ ?? `aptabase-node@${process.env.PKG_VERSION}`, }, props: props, }); diff --git a/packages/node/tsup.config.ts b/packages/node/tsup.config.ts index 1a6f630..a45a921 100644 --- a/packages/node/tsup.config.ts +++ b/packages/node/tsup.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'tsup'; +const { version } = require('./package.json'); export default defineConfig({ entry: ['src/index.ts'], @@ -8,4 +9,7 @@ export default defineConfig({ minify: true, sourcemap: true, clean: true, + env: { + PKG_VERSION: version, + }, }); diff --git a/packages/react/src/global.d.ts b/packages/react/src/global.d.ts new file mode 100644 index 0000000..4dbd621 --- /dev/null +++ b/packages/react/src/global.d.ts @@ -0,0 +1 @@ +declare var __APTABASE_SDK_VERSION__: string; diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx index ade4987..a742cdf 100644 --- a/packages/react/src/index.tsx +++ b/packages/react/src/index.tsx @@ -3,9 +3,12 @@ import { init, trackEvent, type AptabaseOptions } from '@aptabase/web'; import { createContext, useContext, useEffect } from 'react'; +globalThis.__APTABASE_SDK_VERSION__ = `aptabase-react@${process.env.PKG_VERSION}`; + type ContextProps = { appKey?: string; -} & AptabaseOptions; + options?: AptabaseOptions; +}; export type AptabaseClient = { trackEvent: typeof trackEvent; @@ -24,7 +27,7 @@ export function AptabaseProvider({ appKey, options, children }: Props) { init(appKey, options); }, [appKey, options]); - return {children}; + return {children}; } export function useAptabase(): AptabaseClient { diff --git a/packages/react/tsup.config.ts b/packages/react/tsup.config.ts index ba10a4d..4150359 100644 --- a/packages/react/tsup.config.ts +++ b/packages/react/tsup.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'tsup'; +const { version } = require('./package.json'); export default defineConfig({ entry: ['src/index.tsx'], @@ -8,4 +9,7 @@ export default defineConfig({ minify: true, sourcemap: true, clean: true, + env: { + PKG_VERSION: version, + }, }); diff --git a/packages/web/src/global.d.ts b/packages/web/src/global.d.ts new file mode 100644 index 0000000..4dbd621 --- /dev/null +++ b/packages/web/src/global.d.ts @@ -0,0 +1 @@ +declare var __APTABASE_SDK_VERSION__: string; diff --git a/packages/web/src/index.ts b/packages/web/src/index.ts index fb0a5e7..2675149 100644 --- a/packages/web/src/index.ts +++ b/packages/web/src/index.ts @@ -1,9 +1,9 @@ -// env.PKG_VERSION is replaced by rollup during build phase -const sdkVersion = `aptabase-web@${process.env.PKG_VERSION}`; +const sdkVersion = ; export type AptabaseOptions = { host?: string; appVersion?: string; + __sdkVersion?: string; }; let _appKey = ''; @@ -64,7 +64,7 @@ export function trackEvent(eventName: string, props?: Record