Better proxy handling

This commit is contained in:
Eric Bailey
2025-02-03 10:24:40 -06:00
parent 0fc2668b5a
commit f056b81e32
3 changed files with 54 additions and 41 deletions
+47 -34
View File
@@ -1,21 +1,65 @@
import {Did} from '@atproto/api'
/**
* The env the app is running in e.g. development, testflight, production
*/
export const EXPO_PUBLIC_ENV = process.env.EXPO_PUBLIC_ENV
/**
* Indicates whether the app is running in TestFlight mode
*/
export const IS_TESTFLIGHT = process.env.EXPO_PUBLIC_ENV === 'testflight'
export const IS_TESTFLIGHT = EXPO_PUBLIC_ENV === 'testflight'
/**
* Indicates whether the app is __DEV__ or TestFlight
*/
export const IS_INTERNAL = __DEV__ || IS_TESTFLIGHT
/**
* The commit hash that the current bundle was made from. The user can see the
* commit hash in the app's settings along with the other version info. Useful
* for debugging/reporting.
*/
export const BUNDLE_IDENTIFIER: string =
process.env.EXPO_PUBLIC_BUNDLE_IDENTIFIER ?? ''
/**
* This will always be in the format of YYMMDD, so that it always increases for
* each build. This should only be used for Statsig reporting and shouldn't be
* used to identify a specific bundle.
*/
export const BUNDLE_DATE: number = IS_INTERNAL
? 0
: Number(process.env.EXPO_PUBLIC_BUNDLE_DATE)
/**
* The DID of the appview service to proxy to. If undefined, use Bluesky's
* default app view.
*/
export const APPVIEW_DID: Did | undefined =
process.env.EXPO_PUBLIC_APPVIEW_PROXY_DID
export const APPVIEW_PROXY_DID: Did =
process.env.EXPO_PUBLIC_APPVIEW_PROXY_DID || 'did:web:api.bsky.app'
/**
* The appview service to proxy to, derived from the APPVIEW_PROXY_DID.
* Otherwise defaults to Bluesky's default app view.
*/
export const PUBLIC_APPVIEW_SERVICE: string = APPVIEW_PROXY_DID
? 'https://' + APPVIEW_PROXY_DID.split(':')[2]
: 'https://public.api.bsky.app'
/**
* The log level for the app.
*/
export const LOG_LEVEL = (process.env.EXPO_PUBLIC_LOG_LEVEL || 'info') as
| 'debug'
| 'info'
| 'warn'
| 'error'
/**
* Currently unused. Enable debug for a subset of the debug logs.
*/
export const LOG_DEBUG: string = process.env.EXPO_PUBLIC_LOG_DEBUG || ''
/**
* The DID of the chat service to proxy to. If undefined, chat should be
@@ -34,34 +78,3 @@ export const BITDRIFT_API_KEY: string | undefined =
*/
export const SENTRY_API_KEY: string | undefined =
process.env.EXPO_PUBLIC_SENTRY_API_KEY
/**
* The log level for the app.
*/
export const LOG_LEVEL = (process.env.EXPO_PUBLIC_LOG_LEVEL || 'info') as
| 'debug'
| 'info'
| 'warn'
| 'error'
/**
* Currently unused. Enable debug for a subset of the debug logs.
*/
export const LOG_DEBUG: string = process.env.EXPO_PUBLIC_LOG_DEBUG || ''
/**
* The commit hash that the current bundle was made from. The user can see the
* commit hash in the app's settings along with the other version info. Useful
* for debugging/reporting.
*/
export const BUNDLE_IDENTIFIER: string =
process.env.EXPO_PUBLIC_BUNDLE_IDENTIFIER ?? ''
/**
* This will always be in the format of YYMMDD, so that it always increases for
* each build. This should only be used for Statsig reporting and shouldn't be
* used to identify a specific bundle.
*/
export const BUNDLE_DATE: number = IS_INTERNAL
? 0
: Number(process.env.EXPO_PUBLIC_BUNDLE_DATE)
+1 -1
View File
@@ -4,7 +4,7 @@ import {AppBskyActorDefs} from '@atproto/api'
export const LOCAL_DEV_SERVICE =
Platform.OS === 'android' ? 'http://10.0.2.2:2583' : 'http://localhost:2583'
export const STAGING_SERVICE = 'https://staging.bsky.dev'
export const BSKY_SERVICE = 'http://localhost:3000' // TODO add to env
export const BSKY_SERVICE = 'https://bsky.social'
export const PUBLIC_BSKY_SERVICE = 'https://public.api.bsky.app'
export const DEFAULT_SERVICE = BSKY_SERVICE
const HELP_DESK_LANG = 'en-us'
+6 -6
View File
@@ -6,14 +6,14 @@ import {
BSKY_SERVICE,
DISCOVER_SAVED_FEED,
IS_PROD_SERVICE,
PUBLIC_BSKY_SERVICE,
TIMELINE_SAVED_FEED,
} from '#/lib/constants'
import {tryFetchGates} from '#/lib/statsig/statsig'
import {getAge} from '#/lib/strings/time'
import {logger} from '#/logger'
import {snoozeEmailConfirmationPrompt} from '#/state/shell/reminders'
import {APPVIEW_DID} from '#/env'
import {PUBLIC_APPVIEW_SERVICE} from '#/env'
import {APPVIEW_PROXY_DID} from '#/env'
import {emitNetworkConfirmed, emitNetworkLost} from '../events'
import {addSessionErrorLog} from './logging'
import {
@@ -26,7 +26,7 @@ import {isSessionExpired, isSignupQueued} from './util'
export function createPublicAgent() {
configureModerationForGuest() // Side effect but only relevant for tests
// TODO logged out view
return new BskyAppAgent({service: PUBLIC_BSKY_SERVICE})
return new BskyAppAgent({service: PUBLIC_APPVIEW_SERVICE})
}
export async function createAgentAndResume(
@@ -38,7 +38,7 @@ export async function createAgentAndResume(
) => void,
) {
const agent = new BskyAppAgent({service: storedAccount.service})
agent.configureProxy(`${APPVIEW_DID}#bsky_appview`)
agent.configureProxy(`${APPVIEW_PROXY_DID}#bsky_appview`)
if (storedAccount.pdsUrl) {
agent.sessionManager.pdsUrl = new URL(storedAccount.pdsUrl)
}
@@ -86,7 +86,7 @@ export async function createAgentAndLogin(
) => void,
) {
const agent = new BskyAppAgent({service})
agent.configureProxy(`${APPVIEW_DID}#bsky_appview`)
agent.configureProxy(`${APPVIEW_PROXY_DID}#bsky_appview`)
await agent.login({identifier, password, authFactorToken})
const account = agentToSessionAccountOrThrow(agent)
@@ -122,7 +122,7 @@ export async function createAgentAndCreateAccount(
) => void,
) {
const agent = new BskyAppAgent({service})
agent.configureProxy(`${APPVIEW_DID}#bsky_appview`)
agent.configureProxy(`${APPVIEW_PROXY_DID}#bsky_appview`)
await agent.createAccount({
email,
password,