|
1 | 1 | export const KEY_FILE_PATH = './permit.key'; |
2 | 2 | export const KEYSTORE_PERMIT_SERVICE_NAME = 'Permit.io'; |
3 | 3 | export const DEFAULT_PERMIT_KEYSTORE_ACCOUNT = 'PERMIT_DEFAULT_ENV'; |
4 | | -export const CLOUD_PDP_URL = 'https://cloudpdp.api.permit.io'; |
5 | | -export const PERMIT_API_URL = 'https://api.permit.io'; |
6 | | -export const PERMIT_API_STATISTICS_URL = |
7 | | - 'https://pdp-statistics.api.permit.io/v2/stats'; |
8 | | -export const API_URL = 'https://api.permit.io/v2/'; |
9 | | -export const FACTS_API_URL = `${API_URL}facts/`; |
10 | | -export const API_PDPS_CONFIG_URL = `${API_URL}pdps/me/config`; |
11 | | -export const PERMIT_ORIGIN_URL = 'https://app.permit.io'; |
| 4 | +export const REGION_KEYSTORE_ACCOUNT = 'PERMIT_REGION'; |
| 5 | + |
| 6 | +// Region type |
| 7 | +export type PermitRegion = 'us' | 'eu'; |
| 8 | + |
| 9 | +// Get region from environment variable or default to 'us' |
| 10 | +let currentRegion: PermitRegion = |
| 11 | + (process.env['PERMIT_REGION'] as PermitRegion) || 'us'; |
| 12 | + |
| 13 | +// Function to set the current region |
| 14 | +export const setRegion = (region: PermitRegion) => { |
| 15 | + currentRegion = region; |
| 16 | +}; |
| 17 | + |
| 18 | +// Function to get the current region |
| 19 | +export const getRegion = (): PermitRegion => { |
| 20 | + return currentRegion; |
| 21 | +}; |
| 22 | + |
| 23 | +// Function to get region-specific subdomain |
| 24 | +const getRegionSubdomain = (region: PermitRegion): string => { |
| 25 | + return region === 'eu' ? 'eu.' : ''; |
| 26 | +}; |
| 27 | + |
| 28 | +// Region-aware URL getters |
| 29 | +export const getPermitApiUrl = (): string => { |
| 30 | + const subdomain = getRegionSubdomain(currentRegion); |
| 31 | + return `https://api.${subdomain}permit.io`; |
| 32 | +}; |
| 33 | + |
| 34 | +export const getPermitOriginUrl = (): string => { |
| 35 | + const subdomain = getRegionSubdomain(currentRegion); |
| 36 | + return `https://app.${subdomain}permit.io`; |
| 37 | +}; |
| 38 | + |
| 39 | +export const getAuthPermitDomain = (): string => { |
| 40 | + const subdomain = getRegionSubdomain(currentRegion); |
| 41 | + return `app.${subdomain}permit.io`; |
| 42 | +}; |
| 43 | + |
| 44 | +export const getCloudPdpUrl = (): string => { |
| 45 | + if (currentRegion === 'eu') { |
| 46 | + return 'https://cloudpdp.api.eu-central-1.permit.io'; |
| 47 | + } |
| 48 | + return 'https://cloudpdp.api.permit.io'; |
| 49 | +}; |
| 50 | + |
| 51 | +export const getPermitApiStatisticsUrl = (): string => { |
| 52 | + if (currentRegion === 'eu') { |
| 53 | + return 'https://pdp-statistics.api.eu-central-1.permit.io/v2/stats'; |
| 54 | + } |
| 55 | + return 'https://pdp-statistics.api.permit.io/v2/stats'; |
| 56 | +}; |
| 57 | + |
| 58 | +export const getApiUrl = (): string => { |
| 59 | + return `${getPermitApiUrl()}/v2/`; |
| 60 | +}; |
| 61 | + |
| 62 | +export const getFactsApiUrl = (): string => { |
| 63 | + return `${getApiUrl()}facts/`; |
| 64 | +}; |
| 65 | + |
| 66 | +export const getApiPdpsConfigUrl = (): string => { |
| 67 | + return `${getApiUrl()}pdps/me/config`; |
| 68 | +}; |
| 69 | + |
| 70 | +export const getAuthApiUrl = (): string => { |
| 71 | + return `${getPermitApiUrl()}/v1/`; |
| 72 | +}; |
| 73 | + |
| 74 | +// Legacy exports (maintain backwards compatibility) |
| 75 | +export const CLOUD_PDP_URL = getCloudPdpUrl(); |
| 76 | +export const PERMIT_API_URL = getPermitApiUrl(); |
| 77 | +export const PERMIT_API_STATISTICS_URL = getPermitApiStatisticsUrl(); |
| 78 | +export const API_URL = getApiUrl(); |
| 79 | +export const FACTS_API_URL = getFactsApiUrl(); |
| 80 | +export const API_PDPS_CONFIG_URL = getApiPdpsConfigUrl(); |
| 81 | +export const PERMIT_ORIGIN_URL = getPermitOriginUrl(); |
| 82 | +export const AUTH_PERMIT_DOMAIN = getAuthPermitDomain(); |
| 83 | +export const AUTH_API_URL = getAuthApiUrl(); |
12 | 84 |
|
13 | 85 | export const AUTH_REDIRECT_HOST = 'localhost'; |
14 | 86 | export const AUTH_REDIRECT_PORT = 62419; |
15 | 87 | export const AUTH_REDIRECT_URI = `http://${AUTH_REDIRECT_HOST}:${AUTH_REDIRECT_PORT}`; |
16 | | -export const AUTH_PERMIT_DOMAIN = 'app.permit.io'; |
17 | | -export const AUTH_API_URL = 'https://api.permit.io/v1/'; |
| 88 | +// auth.permit.io is common for both regions |
18 | 89 | export const AUTH_PERMIT_URL = 'https://auth.permit.io'; |
| 90 | +export const AUTH0_AUDIENCE = 'https://api.permit.io/v1/'; // Auth0 audience is shared across all regions |
19 | 91 |
|
20 | 92 | export const TERRAFORM_PERMIT_URL = |
21 | 93 | 'https://permit-cli-terraform.up.railway.app'; |
0 commit comments