Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class NativeCustomerIOModule(
?.let { flushInterval(it) }
packageConfig.getTypedValue<Boolean>(Keys.Config.TRACK_APP_LIFECYCLE_EVENTS)
?.let { trackApplicationLifecycleEvents(it) }
packageConfig.getTypedValue<String>(Keys.Config.API_HOST)
?.let { apiHost(it) }
packageConfig.getTypedValue<String>(Keys.Config.CDN_HOST)
?.let { cdnHost(it) }

// Configure push messaging module based on config provided by customer app
packageConfig.getTypedValue<Map<String, Any>>(key = "push").let { pushConfig ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal object Keys {
const val FLUSH_AT = "flushAt"
const val FLUSH_INTERVAL = "flushInterval"
const val SCREEN_VIEW_USE = "screenViewUse"
const val API_HOST = "apiHost"
const val CDN_HOST = "cdnHost"
// Push messaging
const val PUSH_CLICK_BEHAVIOR = "pushClickBehavior"
}
Expand Down
2 changes: 2 additions & 0 deletions api-extractor-output/customerio-reactnative.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type CioConfig = {
migrationSiteId?: string;
region?: CioRegion;
logLevel?: CioLogLevel;
apiHost?: string;
cdnHost?: string;
flushAt?: number;
flushInterval?: number;
screenViewUse?: ScreenView;
Expand Down
32 changes: 18 additions & 14 deletions example/src/screens/internal-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import {
LargeBoldText,
TextField,
} from '@components';
import { InternalSettings, Storage } from '@services';
import { Storage } from '@services';
import React, { useState } from 'react';
import { ScrollView, StyleSheet, View } from 'react-native';
import { showMessage } from 'react-native-flash-message';

const validateSettings = (config: InternalSettings) => {
if (!config.apiHost || !config.cdnHost) {
type HostOverrides = {
apiHost?: string;
cdnHost?: string;
};

const validateSettings = (overrides: HostOverrides) => {
if (!overrides.apiHost || !overrides.cdnHost) {
throw Error('CDN and API host values are missing');
} else if (!config.cdnHost) {
throw Error('CDB Host value is missing');
} else if (!config.apiHost) {
throw Error('API Host value is missing');
}
};

export const InternalSettingsScreen = () => {
const [config, setConfig] = useState<InternalSettings>(
Storage.instance.getInternalDevConfig() || {
cdnHost: '',
apiHost: '',
}
);
const initialConfig = Storage.instance.getCioConfig();
const [config, setConfig] = useState<HostOverrides>({
apiHost: initialConfig?.apiHost ?? '',
cdnHost: initialConfig?.cdnHost ?? '',
});

return (
<ScrollView>
Expand Down Expand Up @@ -56,7 +56,11 @@ export const InternalSettingsScreen = () => {
onPress={async () => {
try {
validateSettings(config);
Storage.instance.setInternalDevConfig(config);
await Storage.instance.setCioConfig({
...Storage.instance.getCioConfig(),
apiHost: config.apiHost,
cdnHost: config.cdnHost,
});

showMessage({
message: 'Internal Settings saved successfully',
Expand Down
45 changes: 7 additions & 38 deletions example/src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import { Env } from '../env';

const USER_STORAGE_KEY = 'user';
const CIO_CONFIG_STORAGE_KEY = 'cioConfig';
export type InternalSettings = {
cdnHost: string;
apiHost: string;
};

type Config = Partial<CioConfig> & { qa?: InternalSettings };
type Config = Partial<CioConfig>;

const createDefaultConfig = (env: Env | null | undefined): Config => {
return {
Expand Down Expand Up @@ -73,11 +69,7 @@ export class Storage {
};

readonly setCioConfig = async (cioConfig: CioConfig) => {
const config = cioConfig as Config;
this.config = {
...config,
qa: config.qa ?? Storage.defaultConfig.qa,
};
this.config = cioConfig as Config;
await AsyncStorage.setItem(
CIO_CONFIG_STORAGE_KEY,
JSON.stringify(this.config)
Expand All @@ -93,34 +85,11 @@ export class Storage {
};

readonly resetCioConfig = async () => {
if (this.config === null) {
this.config = Storage.defaultConfig;
} else {
this.config = {
...this.config,
...Storage.defaultConfig,
qa: this.config.qa,
};
}

await AsyncStorage.setItem(
CIO_CONFIG_STORAGE_KEY,
JSON.stringify(this.config)
);
};

readonly getInternalDevConfig = (): InternalSettings | undefined => {
return this.config?.qa ?? Storage.defaultConfig.qa;
};

readonly setInternalDevConfig = async (
internalSettings: InternalSettings
) => {
if (this.config === null) {
this.config = { ...Storage.defaultConfig, qa: internalSettings };
} else {
this.config = { ...this.config, qa: internalSettings };
}
this.config = {
...Storage.defaultConfig,
apiHost: this.config?.apiHost,
cdnHost: this.config?.cdnHost,
};

await AsyncStorage.setItem(
CIO_CONFIG_STORAGE_KEY,
Expand Down
6 changes: 2 additions & 4 deletions ios/wrappers/utils/CioConfigUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ extension SDKConfigBuilder {
Config.screenViewUse.ifNotNil(in: config, thenPassItTo: builder.screenViewUse) { ScreenView.getScreenView($0) }
Config.trackApplicationLifecycleEvents.ifNotNil(in: config, thenPassItTo: builder.trackApplicationLifecycleEvents)
Config.autoTrackDeviceAttributes.ifNotNil(in: config, thenPassItTo: builder.autoTrackDeviceAttributes)

let qaConfig = config["qa"] as? [String: Any?]
Config.apiHost.ifNotNil(in: qaConfig, thenPassItTo: builder.apiHost)
Config.cdnHost.ifNotNil(in: qaConfig, thenPassItTo: builder.cdnHost)
Config.apiHost.ifNotNil(in: config, thenPassItTo: builder.apiHost)
Config.cdnHost.ifNotNil(in: config, thenPassItTo: builder.cdnHost)

return builder
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/data-pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface IdentifyParams {
* @param migrationSiteId - Legacy site ID for migrating from tracking API
* @param region - Data center region (US or EU)
* @param logLevel - SDK logging verbosity level
* @param apiHost - Override the CDP API host. Use to route SDK traffic through a first-party proxy.
* @param cdnHost - Override the CDN host. Use to route SDK traffic through a first-party proxy.
* @param flushAt - Number of events to batch before sending
* @param flushInterval - Time interval (seconds) to flush events
* @param screenViewUse - How to handle screen view tracking
Expand All @@ -55,6 +57,8 @@ export type CioConfig = {
migrationSiteId?: string;
region?: CioRegion;
logLevel?: CioLogLevel;
apiHost?: string;
cdnHost?: string;
flushAt?: number;
flushInterval?: number;
screenViewUse?: ScreenView;
Expand Down
Loading