- Rename apiPath to apiUrl

This commit is contained in:
goenning 2023-12-29 09:38:24 -03:00
parent c980afd786
commit 9002311059
7 changed files with 20 additions and 10 deletions

View file

@ -1,3 +1,11 @@
## 0.3.3
- Rename `apiPath` to `apiUrl`
## 0.3.2
- Fix error when running on chrome
## 0.3.1 ## 0.3.1
- Support for custom API path - Support for custom API path

View file

@ -1,6 +1,6 @@
{ {
"name": "@aptabase/react", "name": "@aptabase/react",
"version": "0.3.1", "version": "0.3.3",
"type": "module", "type": "module",
"description": "React SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps", "description": "React SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"main": "./dist/index.cjs", "main": "./dist/index.cjs",

View file

@ -19,7 +19,7 @@ type ContextProps = {
function init(appKey: string, options?: AptabaseOptions) { function init(appKey: string, options?: AptabaseOptions) {
if (!validateAppKey(appKey)) return; if (!validateAppKey(appKey)) return;
_apiUrl = getApiUrl(appKey, options); _apiUrl = options?.apiUrl ?? getApiUrl(appKey, options);
_appKey = appKey; _appKey = appKey;
_options = options; _options = options;
} }

View file

@ -1,7 +1,7 @@
const defaultLocale = getBrowserLocale(); const defaultLocale = getBrowserLocale();
const defaultIsDebug = getIsDebug(); const defaultIsDebug = getIsDebug();
const isInBrowser = typeof window !== 'undefined' && typeof window.fetch !== 'undefined'; const isInBrowser = typeof window !== 'undefined' && typeof window.fetch !== 'undefined';
const isInBrowserExtension = typeof chrome !== 'undefined' && !!chrome.runtime.id; const isInBrowserExtension = typeof chrome !== 'undefined' && !!chrome.runtime?.id;
let _sessionId = newSessionId(); let _sessionId = newSessionId();
let _lastTouched = new Date(); let _lastTouched = new Date();
@ -17,7 +17,7 @@ export type AptabaseOptions = {
// Custom host for self-hosted Aptabase. // Custom host for self-hosted Aptabase.
host?: string; host?: string;
// Custom path for API endpoint. Useful when using reverse proxy. // Custom path for API endpoint. Useful when using reverse proxy.
apiPath?: string; apiUrl?: string;
// Defines the app version. // Defines the app version.
appVersion?: string; appVersion?: string;
// Defines whether the app is running on debug mode. // Defines whether the app is running on debug mode.
@ -55,8 +55,6 @@ export function validateAppKey(appKey: string): boolean {
} }
export function getApiUrl(appKey: string, options?: AptabaseOptions): string | undefined { export function getApiUrl(appKey: string, options?: AptabaseOptions): string | undefined {
const apiPath = options?.apiPath ?? '/api/v0/event';
const region = appKey.split('-')[1]; const region = appKey.split('-')[1];
if (region === 'SH') { if (region === 'SH') {
if (!options?.host) { if (!options?.host) {
@ -64,11 +62,11 @@ export function getApiUrl(appKey: string, options?: AptabaseOptions): string | u
return; return;
} }
return `${options.host}${apiPath}`; return `${options.host}/api/v0/event`;
} }
const host = options?.host ?? _hosts[region]; const host = options?.host ?? _hosts[region];
return `${host}${apiPath}`; return `${host}/api/v0/event`;
} }
export async function sendEvent(opts: { export async function sendEvent(opts: {

View file

@ -1,3 +1,7 @@
## 0.4.2
- Fix error when running on chrome
## 0.4.1 ## 0.4.1
- Support for custom API path - Support for custom API path

View file

@ -1,6 +1,6 @@
{ {
"name": "@aptabase/web", "name": "@aptabase/web",
"version": "0.4.1", "version": "0.4.2",
"type": "module", "type": "module",
"description": "JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps", "description": "JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"main": "./dist/index.cjs", "main": "./dist/index.cjs",

View file

@ -13,7 +13,7 @@ export { type AptabaseOptions };
export function init(appKey: string, options?: AptabaseOptions) { export function init(appKey: string, options?: AptabaseOptions) {
if (!validateAppKey(appKey)) return; if (!validateAppKey(appKey)) return;
_apiUrl = getApiUrl(appKey, options); _apiUrl = options?.apiUrl ?? getApiUrl(appKey, options);
_appKey = appKey; _appKey = appKey;
_options = options; _options = options;
} }