-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildConfig.js
More file actions
89 lines (75 loc) · 2.91 KB
/
buildConfig.js
File metadata and controls
89 lines (75 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Platform } from 'react-native';
import { storage, StorageKeys } from '../../services/storage';
import NativeAppVersion from '../../specs/NativeAppVersion';
// ---------- env + domain ----------
export const ENV = __DEV__ ? 'local' : 'live';
// Backend URLs — replace with your own.
// `local` should point at your dev API (e.g. `http://<your-lan-ip>:3002`
// so a physical device on the same Wi-Fi can reach it; use `localhost`
// for the simulator).
// `live` should point at your production API.
// The companion backend lives at https://github.com/SameerArora497/Wavee-Backend.
export const DOMAINS = {
local: 'http://localhost:3002',
live: 'https://your-backend.example.com',
};
export const getDomain = () => DOMAINS[ENV];
/**
* Build a full web URL for the public site (CMS Pages, blog posts, etc.).
* webUrl('disclaimer') -> http://localhost:3002/disclaimer (dev)
* -> https://your-backend.example.com/disclaimer (live)
* Used by ProfileScreen / LoginScreen / WebView openers so legal/help URLs
* track the active environment automatically.
*/
export const webUrl = (path = '') => {
const slug = String(path).replace(/^\/+/, '');
return slug ? `${getDomain()}/${slug}` : getDomain();
};
const safeGet = fn => {
try {
return fn() ?? '';
} catch {
return '';
}
};
export const APP_VERSION = NativeAppVersion
? safeGet(() => NativeAppVersion.getAppVersion())
: '';
export const BUILD_VERSION = NativeAppVersion
? safeGet(() => NativeAppVersion.getBuildVersion())
: '';
export const BUNDLE_ID = NativeAppVersion
? safeGet(() => NativeAppVersion.getBundleIdentifier())
: '';
// ---------- HTTP identity ----------
const PLATFORM_LABEL = { android: 'android', ios: 'ios', web: 'web' };
// Static User-Agent: just a "this is us" stamp. Real identity info
// (version, build, platform) rides on custom X-* headers — those are
// never stripped by Android OEMs.
export const USER_AGENT = 'Wavee-Agent';
export const getUserAgent = () => USER_AGENT;
export const getApiHeaders = () => ({
'X-App-Version': APP_VERSION,
'X-Build-Number': BUILD_VERSION,
'X-Platform': PLATFORM_LABEL[Platform.OS] || 'unknown',
});
// ---------- auth token + profile (MMKV-backed) ----------
export const getAuthToken = () => storage.getString(StorageKeys.authToken);
export const setAuthToken = token => storage.set(StorageKeys.authToken, token);
export const clearAuthToken = () => storage.remove(StorageKeys.authToken);
export const getAuthProfile = () => {
const raw = storage.getString(StorageKeys.authProfile);
if (!raw) return null;
try {
return JSON.parse(raw);
} catch {
return null;
}
};
export const setAuthProfile = profile =>
storage.set(StorageKeys.authProfile, JSON.stringify(profile));
export const clearAuthProfile = () => storage.remove(StorageKeys.authProfile);
export const clearAuthAll = () => {
clearAuthToken();
clearAuthProfile();
};