export aptabaseoptions
This commit is contained in:
parent
e104dd53dc
commit
47042f043b
6 changed files with 24 additions and 61 deletions
1
packages/node/src/global.d.ts
vendored
1
packages/node/src/global.d.ts
vendored
|
@ -1,5 +1,6 @@
|
|||
type AptabaseState = {
|
||||
appKey?: string;
|
||||
options?: import('./types').AptabaseOptions;
|
||||
};
|
||||
|
||||
declare var __APTABASE__: AptabaseState;
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
export function init(appKey) {
|
||||
globalThis.__APTABASE__ = { appKey };
|
||||
}
|
||||
export function trackEvent(req, eventName, props) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const appKey = globalThis.__APTABASE__.appKey;
|
||||
if (!appKey)
|
||||
return Promise.resolve();
|
||||
const userAgent = (_a = req.headers['user-agent']) !== null && _a !== void 0 ? _a : '';
|
||||
const body = JSON.stringify({
|
||||
timestamp: new Date().toISOString(),
|
||||
sessionId: 'CHANGE-THIS',
|
||||
eventName: eventName,
|
||||
systemProps: {
|
||||
isDebug: true,
|
||||
locale: 'en',
|
||||
appVersion: '',
|
||||
sdkVersion: 'aptabase-node@0.1.0',
|
||||
},
|
||||
props: props,
|
||||
});
|
||||
try {
|
||||
const response = yield fetch('http://localhost:3000/api/v0/event', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'User-Agent': userAgent,
|
||||
'Content-Type': 'application/json',
|
||||
'App-Key': appKey,
|
||||
},
|
||||
credentials: 'omit',
|
||||
body,
|
||||
});
|
||||
if (response.status >= 300) {
|
||||
const responseBody = yield response.text();
|
||||
console.warn(`Failed to send event "${eventName}": ${response.status} ${responseBody}`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`Failed to send event "${eventName}": ${e}`);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,5 +1,9 @@
|
|||
export function init(appKey: string) {
|
||||
globalThis.__APTABASE__ = { appKey };
|
||||
import { AptabaseOptions } from './types';
|
||||
|
||||
export { AptabaseOptions };
|
||||
|
||||
export function init(appKey: string, options?: AptabaseOptions) {
|
||||
globalThis.__APTABASE__ = { appKey, options };
|
||||
}
|
||||
|
||||
// We only need the headers from the request object
|
||||
|
|
11
packages/node/src/types.ts
Normal file
11
packages/node/src/types.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export type AptabaseOptions = {
|
||||
host?: string;
|
||||
appVersion?: string;
|
||||
};
|
||||
|
||||
type AptabaseState = {
|
||||
appKey?: string;
|
||||
options?: AptabaseOptions;
|
||||
};
|
||||
|
||||
declare var __APTABASE__: AptabaseState;
|
Loading…
Add table
Add a link
Reference in a new issue