sdk changes

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-02-11 21:31:12 +01:00
parent 484a6b1d41
commit 447fa5896e
65 changed files with 9428 additions and 723 deletions

View File

@@ -1,21 +1,46 @@
import type { NewMixanOptions } from '@mixan/sdk';
import { AppState, Platform } from 'react-native';
import * as Application from 'expo-application';
import Constants from 'expo-constants';
import * as Network from 'expo-network';
import type { MixanOptions } from '@mixan/sdk';
import { Mixan } from '@mixan/sdk';
export class MixanNative extends Mixan {
constructor(options: NewMixanOptions) {
type MixanNativeOptions = MixanOptions & {
ipUrl?: string;
};
export class MixanNative extends Mixan<MixanNativeOptions> {
constructor(options: MixanNativeOptions) {
super(options);
this.api.headers['X-Forwarded-For'] = Network.getIpAddressAsync();
this.api.headers['User-Agent'] = Constants.getWebViewUserAgentAsync();
AppState.addEventListener('change', (state) => {
if (state === 'active') {
this.setProperties();
}
});
this.setProperties();
}
init(properties?: Record<string, unknown>) {
super.init({
...(properties ?? {}),
private async setProperties() {
this.setGlobalProperties({
version: Application.nativeApplicationVersion,
buildNumber: Application.nativeBuildVersion,
referrer:
Platform.OS === 'android'
? await Application.getInstallReferrerAsync()
: undefined,
});
}
screenView(route: string, properties?: Record<string, unknown>): void {
public screenView(route: string, properties?: Record<string, unknown>): void {
super.event('screen_view', {
...properties,
route: route,
path: route,
});
}
}

View File

@@ -21,6 +21,12 @@
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"peerDependencies": {
"react-native": "^0.72.5",
"expo-application": "~5.3.0",
"expo-constants": "~14.4.2",
"expo-network": "~5.8.0"
},
"eslintConfig": {
"root": true,
"extends": [

View File

@@ -1,7 +1,8 @@
import { defineConfig } from 'tsup';
import config from '@mixan/tsconfig/tsup.config.json' assert {
type: 'json'
}
import config from '@mixan/tsconfig/tsup.config.json' assert { type: 'json' };
export default defineConfig(config as any);
export default defineConfig({
...(config as any),
minify: false,
});