Work with new Zalvena Service project
This commit is contained in:
parent
7416341746
commit
4b49a22257
16 changed files with 883 additions and 44 deletions
|
@ -6,14 +6,14 @@ let _sessionId = newSessionId();
|
|||
let _lastTouched = new Date();
|
||||
|
||||
const _hosts: { [region: string]: string } = {
|
||||
US: 'https://us.aptabase.com', // Operated by Aptabase in North America
|
||||
EU: 'https://eu.aptabase.com', // Operated by Aptabase in Europe
|
||||
SV: 'https://events.sudovanilla.org', // Owned and operated by SudoVanilla in North America
|
||||
DEV: 'https://localhost:3000', // Local Development
|
||||
SH: '', // Selfhost
|
||||
US: 'https://us.aptabase.com',
|
||||
EU: 'https://eu.aptabase.com',
|
||||
DEV: 'https://localhost:3000',
|
||||
ZV: 'https://beta.events.sudovanilla.org',
|
||||
SH: ''
|
||||
};
|
||||
|
||||
export type AptabaseOptions = {
|
||||
export type ZalvenaOptions = {
|
||||
// Custom host for self-hosted Aptabase.
|
||||
host?: string;
|
||||
// Custom path for API endpoint. Useful when using reverse proxy.
|
||||
|
@ -25,13 +25,12 @@ export type AptabaseOptions = {
|
|||
};
|
||||
|
||||
export function inMemorySessionId(timeout: number): string {
|
||||
let now = new Date();
|
||||
const diffInMs = now.getTime() - _lastTouched.getTime();
|
||||
const diffInMs = new Date().getTime() - _lastTouched.getTime();
|
||||
const diffInSec = Math.floor(diffInMs / 1000);
|
||||
if (diffInSec > timeout) {
|
||||
_sessionId = newSessionId();
|
||||
}
|
||||
_lastTouched = now;
|
||||
_lastTouched = new Date();
|
||||
|
||||
return _sessionId;
|
||||
}
|
||||
|
@ -54,7 +53,7 @@ export function validateAppKey(appKey: string): boolean {
|
|||
return true;
|
||||
}
|
||||
|
||||
export function getApiUrl(appKey: string, options?: AptabaseOptions): string | undefined {
|
||||
export function getApiUrl(appKey: string, options?: ZalvenaOptions): string | undefined {
|
||||
const region = appKey.split('-')[1];
|
||||
if (region === 'SH') {
|
||||
if (!options?.host) {
|
||||
|
@ -81,12 +80,12 @@ export async function sendEvent(opts: {
|
|||
props?: Record<string, string | number | boolean>;
|
||||
}): Promise<void> {
|
||||
if (!isInBrowser) {
|
||||
console.warn(`Aptabase: trackEvent requires a browser environment. Event "${opts.eventName}" will be discarded.`);
|
||||
console.warn(`Zalvena: trackEvent requires a browser environment. Event "${opts.eventName}" will be discarded.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!opts.appKey) {
|
||||
console.warn(`Aptabase: init must be called before trackEvent. Event "${opts.eventName}" will be discarded.`);
|
||||
console.warn(`Zalvena: init must be called before trackEvent. Event "${opts.eventName}" will be discarded.`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -140,22 +139,14 @@ function getBrowserLocale(): string | undefined {
|
|||
return defaultLocale;
|
||||
}
|
||||
|
||||
// If the environment is on the `localhost` URL,
|
||||
// send debug data instead of release.
|
||||
function getIsDebug(): boolean {
|
||||
if (defaultIsDebug !== undefined) {
|
||||
return defaultIsDebug;
|
||||
if (location.hostname === 'localhost') {
|
||||
defaultIsDebug = true
|
||||
return defaultIsDebug
|
||||
} else {
|
||||
defaultIsDebug = false
|
||||
return defaultIsDebug
|
||||
}
|
||||
|
||||
if (process.env['NODE_ENV'] === 'development') {
|
||||
defaultIsDebug = true;
|
||||
return defaultIsDebug;
|
||||
}
|
||||
|
||||
if (typeof location === 'undefined') {
|
||||
defaultIsDebug = false;
|
||||
return defaultIsDebug;
|
||||
}
|
||||
|
||||
defaultIsDebug = location.hostname === 'localhost';
|
||||
|
||||
return defaultIsDebug;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue