From 02148083ec2a7a583a0228c0fe7dce92a7e646b1 Mon Sep 17 00:00:00 2001 From: Shahroz Khan Date: Thu, 5 Jun 2025 19:13:51 +0500 Subject: [PATCH 1/3] added app specific env --- example/src/App.tsx | 19 +++++++++++++++---- example/src/env.ts.sample | 18 ++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index f7a6eabb..266fbd98 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -11,17 +11,28 @@ import FlashMessage, { showMessage } from 'react-native-flash-message'; import { AppEnvValues } from './env'; export default function App({ appName }: { appName: string }) { + const appNameKey = appName.toLocaleLowerCase(); const env = - AppEnvValues[appName.toLocaleLowerCase() as keyof typeof AppEnvValues] ?? + AppEnvValues[appNameKey as keyof typeof AppEnvValues] ?? AppEnvValues['default']; + if (!env) { console.error( - `No default preset environment variables found nor environment variables for the app: ${appName}. The env.ts contains environment values for case-insenetive app names: ${Object.keys( + `No environment variables found for app: "${appName}" (key: "${appNameKey}"). Available environments: ${Object.keys( AppEnvValues - ).join(', ')}` + ).join(', ')}. Falling back to default environment.` ); + // Ensure we always have an environment, even if it's the default + const fallbackEnv = AppEnvValues['default'] || { + API_KEY: 'fallback_api_key', + SITE_ID: 'fallback_site_id', + buildTimestamp: 0, + }; + Storage.setEnv(fallbackEnv); + } else { + console.log(`Using environment for "${appNameKey}":`, env); + Storage.setEnv(env); } - Storage.setEnv(env); const [isLoading, setIsLoading] = React.useState(true); diff --git a/example/src/env.ts.sample b/example/src/env.ts.sample index 9295ced9..faed3860 100644 --- a/example/src/env.ts.sample +++ b/example/src/env.ts.sample @@ -1,31 +1,33 @@ export type Env = { API_KEY: string; SITE_ID: string; + buildTimestamp?: number; }; export const AppEnvValues = { 'default': { API_KEY: '', SITE_ID: '', + buildTimestamp: 0, } satisfies Env, /** - * If you are switching between Firebase and APN frequently for development, - * Comment out the Env struct above and uncomment the one below - * which will allow you to set API for FCM and APN separately. + * Environment configurations for different app variants + * The keys must match the app names (converted to lowercase) used in the builds */ - /* - 'apn': { + 'react native apn': { API_KEY: '', SITE_ID: '', + buildTimestamp: 0, } satisfies Env, - 'fcm': { + 'react native fcm': { API_KEY: '', SITE_ID: '', + buildTimestamp: 0, } satisfies Env, - 'android fcm': { + 'react native android': { API_KEY: '', SITE_ID: '', + buildTimestamp: 0, } satisfies Env, - */ }; From 5f0a8f7c5c18d753a6482e176d5fccf0c9e8f5bb Mon Sep 17 00:00:00 2001 From: Shahroz Khan Date: Thu, 5 Jun 2025 19:54:06 +0500 Subject: [PATCH 2/3] debug --- .../Env.swift.sample | 6 ++-- example/src/App.tsx | 28 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/example/ios/NotificationServiceExtension/Env.swift.sample b/example/ios/NotificationServiceExtension/Env.swift.sample index 4f2157d8..f6536c0d 100644 --- a/example/ios/NotificationServiceExtension/Env.swift.sample +++ b/example/ios/NotificationServiceExtension/Env.swift.sample @@ -1,5 +1,5 @@ struct Env { - static let CDP_API_KEY = "" + static let CDP_API_KEY: String = "" } /** @@ -11,9 +11,9 @@ struct Env { /* struct Env { #if USE_FCM - static let CDP_API_KEY = "" + static let CDP_API_KEY: String = "" #else - static let CDP_API_KEY = "" + static let CDP_API_KEY: String = "" #endif } */ \ No newline at end of file diff --git a/example/src/App.tsx b/example/src/App.tsx index 266fbd98..62164d12 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -16,22 +16,20 @@ export default function App({ appName }: { appName: string }) { AppEnvValues[appNameKey as keyof typeof AppEnvValues] ?? AppEnvValues['default']; + // For debugging - this will be visible in the app + const [debugInfo, setDebugInfo] = useState(`App: "${appName}" -> Key: "${appNameKey}"`); + if (!env) { - console.error( - `No environment variables found for app: "${appName}" (key: "${appNameKey}"). Available environments: ${Object.keys( - AppEnvValues - ).join(', ')}. Falling back to default environment.` - ); - // Ensure we always have an environment, even if it's the default const fallbackEnv = AppEnvValues['default'] || { API_KEY: 'fallback_api_key', SITE_ID: 'fallback_site_id', buildTimestamp: 0, }; Storage.setEnv(fallbackEnv); + setDebugInfo(`❌ No env found for "${appNameKey}". Using fallback.`); } else { - console.log(`Using environment for "${appNameKey}":`, env); Storage.setEnv(env); + setDebugInfo(`✅ Found env for "${appNameKey}". API_KEY: ${env.API_KEY.substring(0, 10)}...`); } const [isLoading, setIsLoading] = React.useState(true); @@ -61,7 +59,15 @@ export default function App({ appName }: { appName: string }) { 'Initializing CustomerIO on app start with config', cioConfig ); - CustomerIO.initialize(cioConfig); + try { + CustomerIO.initialize(cioConfig); + console.log('CustomerIO initialized successfully'); + } catch (error) { + console.error('Failed to initialize CustomerIO:', error); + // Don't throw - let the app continue to run + } + } else { + console.error('No CustomerIO config found in storage'); } }; loadFromStorage(); @@ -70,6 +76,12 @@ export default function App({ appName }: { appName: string }) { return ( <> {isLoading && Loading....} + {/* Debug info - remove this after fixing the issue */} + {!isLoading && ( + + {debugInfo} + + )} {!isLoading && ( Date: Thu, 5 Jun 2025 20:49:13 +0500 Subject: [PATCH 3/3] hardcoded test --- example/src/App.tsx | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index 62164d12..2df360c5 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -8,29 +8,28 @@ import { Storage } from '@services'; import { appTheme } from '@utils'; import { CioConfig, CioPushPermissionStatus, CustomerIO } from 'customerio-reactnative'; import FlashMessage, { showMessage } from 'react-native-flash-message'; -import { AppEnvValues } from './env'; + + +// Define minimal type inline since we're bypassing env.ts +type SimpleEnv = { + API_KEY: string; + SITE_ID: string; + buildTimestamp?: number; +}; export default function App({ appName }: { appName: string }) { - const appNameKey = appName.toLocaleLowerCase(); - const env = - AppEnvValues[appNameKey as keyof typeof AppEnvValues] ?? - AppEnvValues['default']; + // BYPASS ENVIRONMENT FILE COMPLETELY - USE HARDCODED VALUES + const hardcodedEnv: SimpleEnv = { + API_KEY: 'hardcoded_dummy_api_key_12345', + SITE_ID: 'hardcoded_dummy_site_id_67890', + buildTimestamp: 1699999999, + }; - // For debugging - this will be visible in the app - const [debugInfo, setDebugInfo] = useState(`App: "${appName}" -> Key: "${appNameKey}"`); + // Simple debug string + const debugInfo = `App="${appName}" 🔧HARDCODED_ENV 🔑${hardcodedEnv.API_KEY.substring(0, 10)}...`; - if (!env) { - const fallbackEnv = AppEnvValues['default'] || { - API_KEY: 'fallback_api_key', - SITE_ID: 'fallback_site_id', - buildTimestamp: 0, - }; - Storage.setEnv(fallbackEnv); - setDebugInfo(`❌ No env found for "${appNameKey}". Using fallback.`); - } else { - Storage.setEnv(env); - setDebugInfo(`✅ Found env for "${appNameKey}". API_KEY: ${env.API_KEY.substring(0, 10)}...`); - } + // Set the hardcoded environment + Storage.setEnv(hardcodedEnv); const [isLoading, setIsLoading] = React.useState(true); @@ -78,7 +77,7 @@ export default function App({ appName }: { appName: string }) { {isLoading && Loading....} {/* Debug info - remove this after fixing the issue */} {!isLoading && ( - + {debugInfo} )}