Skip to content
This repository was archived by the owner on May 1, 2026. It is now read-only.
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
6 changes: 3 additions & 3 deletions src/channel/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function addChannelInternal(channelId: string, appId: string, optio
intro('Create channel')

options.apikey = options.apikey || findSavedKey()
const extConfig = await getConfig().catch(() => undefined)
const extConfig = await getConfig(silent).catch(() => undefined)
appId = getAppId(appId, extConfig?.config)

if (!options.apikey) {
Expand All @@ -34,15 +34,15 @@ export async function addChannelInternal(channelId: string, appId: string, optio
throw new Error('Missing appId')
}

const supabase = await createSupabaseClient(options.apikey, options.supaHost, options.supaAnon)
const supabase = await createSupabaseClient(options.apikey, options.supaHost, options.supaAnon, silent)
await check2FAComplianceForApp(supabase, appId, silent)
await verifyUser(supabase, options.apikey, ['write', 'all'])
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.admin, silent, true)

if (!silent)
log.info(`Creating channel ${appId}#${channelId} to Capgo`)

const data = await findUnknownVersion(supabase, appId)
const data = await findUnknownVersion(supabase, appId, { silent })
if (!data) {
if (!silent)
log.error('Cannot find default version for channel creation, please contact Capgo support 🀨')
Expand Down
38 changes: 23 additions & 15 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,19 +488,21 @@ export async function getAllPackagesDependencies(f: string = findRoot(cwd()), fi
return dependencies
}

export async function getConfig() {
export async function getConfig(silent = false) {
try {
const extConfig = await loadConfig()
if (!extConfig) {
const message = 'No capacitor config file found, run `cap init` first'
log.error(message)
if (!silent)
log.error(message)
throw new Error(message)
}
return extConfig
}
catch (err) {
const message = `No capacitor config file found, run \`cap init\` first ${formatError(err)}`
log.error(message)
if (!silent)
log.error(message)
throw new Error(message)
}
}
Expand All @@ -527,9 +529,9 @@ export async function updateConfigUpdater(newConfig: any): Promise<ExtConfigPair
return updateConfigbyKey('CapacitorUpdater', newConfig)
}

export async function getLocalConfig() {
export async function getLocalConfig(silent = false) {
try {
const extConfig = await getConfig()
const extConfig = await getConfig(silent)
const capConfig: CapgoConfig = {
host: (extConfig?.config?.plugins?.CapacitorUpdater?.localHost || defaultHost) as string,
hostWeb: (extConfig?.config?.plugins?.CapacitorUpdater?.localWebHost || defaultHostWeb) as string,
Expand All @@ -538,7 +540,8 @@ export async function getLocalConfig() {
}

if (extConfig?.config?.plugins?.CapacitorUpdater?.localSupa && extConfig?.config?.plugins?.CapacitorUpdater?.localSupaAnon) {
log.info('Using custom supabase instance from capacitor.config.json')
if (!silent)
log.info('Using custom supabase instance from capacitor.config.json')
capConfig.supaKey = extConfig?.config?.plugins?.CapacitorUpdater?.localSupaAnon
capConfig.supaHost = extConfig?.config?.plugins?.CapacitorUpdater?.localSupa
}
Expand All @@ -564,9 +567,9 @@ interface CapgoConfig {
hostFilesApi: string
hostApi: string
}
export async function getRemoteConfig() {
export async function getRemoteConfig(silent = false) {
// call host + /api/get_config and parse the result as json using fetch
const localConfig = await getLocalConfig()
const localConfig = await getLocalConfig(silent)
try {
const response = await fetch(`${localConfig.hostApi}/private/config`)
if (!response.ok) {
Expand All @@ -576,7 +579,8 @@ export async function getRemoteConfig() {
return { ...data, ...localConfig } as CapgoConfig
}
catch {
log.info(`Local config ${formatError(localConfig)}`)
if (!silent)
log.info(`Local config ${formatError(localConfig)}`)
return localConfig
}
}
Expand Down Expand Up @@ -614,15 +618,17 @@ export async function getRemoteFileConfig() {
}
}

export async function createSupabaseClient(apikey: string, supaHost?: string, supaKey?: string) {
const config = await getRemoteConfig()
export async function createSupabaseClient(apikey: string, supaHost?: string, supaKey?: string, silent = false) {
const config = await getRemoteConfig(silent)
if (supaHost && supaKey) {
log.info('Using custom supabase instance from provided options')
if (!silent)
log.info('Using custom supabase instance from provided options')
config.supaHost = supaHost
config.supaKey = supaKey
}
if (!config.supaHost || !config.supaKey) {
log.error('Cannot connect to server please try again later')
if (!silent)
log.error('Cannot connect to server please try again later')
throw new Error('Cannot connect to server please try again later')
}
return createClient<Database>(config.supaHost, config.supaKey, {
Expand Down Expand Up @@ -1395,7 +1401,9 @@ export async function sendEvent(capgkey: string, payload: TrackOptions & { notif
if (verbose) {
log.info(`Get remove config: for ${payload.event}`)
}
const config = await getRemoteConfig()
// Always fetch remote config silently β€” sendEvent is telemetry and must
// not bypass an Ink-controlled stdout (e.g. during `capgo init`).
const config = await getRemoteConfig(true)
if (verbose) {
log.info(`Sending LogSnag event: ${JSON.stringify(payload)}`)
}
Expand All @@ -1421,7 +1429,7 @@ export async function sendEvent(capgkey: string, payload: TrackOptions & { notif

const response = await fetchResponse.json() as { error?: string }

if (response.error) {
if (response.error && verbose) {
log.error(`Failed to send LogSnag event: ${response.error}`)
}
}
Expand Down
Loading