Remove Aptabase official servers and update isDebug function

This commit is contained in:
Korbs 2025-02-20 18:03:58 -05:00
parent b063577663
commit 84a50710ef
Signed by: Korbs
SSH key fingerprint: SHA256:Q0b0KraMldpAO9oKa+w+gcsXsOTykQ4UkAKn0ByGn5U

View file

@ -1,27 +1,24 @@
let defaultLocale: string | undefined;
let defaultIsDebug: boolean | undefined;
let defaultIsDevelopment: boolean | undefined;
const isInBrowser = true;
let _sessionId = newSessionId();
let _lastTouched = new Date();
const _hosts: { [region: string]: string } = {
US: 'https://us.aptabase.com',
EU: 'https://eu.aptabase.com',
DEV: 'https://localhost:3000',
ZV: 'https://beta.events.sudovanilla.org',
SH: ''
ZV: 'https://events.sudovanilla.org',
SH: '',
};
export type ZalvenaOptions = {
// Custom host for self-hosted Aptabase.
// Custom host for self-hosted Zalvena.
host?: string;
// Custom path for API endpoint. Useful when using reverse proxy.
apiUrl?: string;
// Defines the app version.
appVersion?: string;
// Defines whether the app is running on debug mode.
isDebug?: boolean;
// Defines whether the app is running in development mode.
isDevelopment?: boolean;
};
export function inMemorySessionId(timeout: number): string {
@ -47,7 +44,7 @@ export function newSessionId(): string {
export function validateAppKey(appKey: string): boolean {
const parts = appKey.split('-');
if (parts.length !== 3 || _hosts[parts[1]] === undefined) {
console.warn(`The Aptabase App Key "${appKey}" is invalid. Tracking will be disabled.`);
console.warn(`The Zalvena App Key "${appKey}" is invalid. Tracking will be disabled.`);
return false;
}
return true;
@ -73,7 +70,7 @@ export async function sendEvent(opts: {
appKey?: string;
sessionId: string;
locale?: string;
isDebug?: boolean;
isDevelopment?: boolean;
appVersion?: string;
sdkVersion: string;
eventName: string;
@ -103,7 +100,7 @@ export async function sendEvent(opts: {
eventName: opts.eventName,
systemProps: {
locale: opts.locale ?? getBrowserLocale(),
isDebug: opts.isDebug ?? getIsDebug(),
isDebug: opts.isDevelopment ?? getIsDevelopment(),
appVersion: opts.appVersion ?? '',
sdkVersion: opts.sdkVersion,
},
@ -140,13 +137,13 @@ function getBrowserLocale(): string | undefined {
}
// If the environment is on the `localhost` URL,
// send debug data instead of release.
function getIsDebug(): boolean {
// send development data instead of production
function getIsDevelopment(): boolean {
if (location.hostname === 'localhost') {
defaultIsDebug = true
return defaultIsDebug
defaultIsDevelopment = true;
return defaultIsDevelopment;
} else {
defaultIsDebug = false
return defaultIsDebug
defaultIsDevelopment = false;
return defaultIsDevelopment;
}
}