__CAPGO_KEEP_0__ 채널

채널 API 엔드포인트

GitHub

Capgo에서 앱 업데이트를 관리하는 핵심 메커니즘인 채널에 대한 이해가 필요합니다. 자체 호스팅 모드에서는 디바이스 할당, 채널 쿼리 및 채널 관리 작업을 처리하기 위해 채널 엔드포인트를 implement해야합니다.

채널을 사용하면:

  • 업데이트 배포를 제어할 수 있습니다.다양한 사용자 그룹에 다른 앱 버전을 assign할 수 있습니다.
  • A/B 테스트특정 사용자 세그먼트와 함께 새로운 기능을 테스트할 수 있습니다.
  • 배포 준비 중인 출시: Gradually deploy updates to minimize risk
  • 환경 분리: Separate development, staging, and production updates

설정에서 채널 엔드포인트 URL을 구성합니다. capacitor.config.json:

{
"plugins": {
"CapacitorUpdater": {
"channelUrl": "https://myserver.com/api/channel_self"
}
}
}

플러그인은 엔드포인트가 처리해야 하는 채널 연산을 수행합니다.

1. 호환 가능한 채널 목록 조회 (GET 요청)

1. 호환 가능한 채널 목록 (GET 요청)

플러그인이 호출할 때 listChannels(), 이 요청을 보내어 호환 가능한 모든 채널을 가져옵니다. 이 요청은 기기의 환경 (개발/운영, 시뮬레이터/실제 기기)과 공공 접근 허용 또는 자체 할당을 허용하는 채널을 반환합니다.

요청 형식

요청 형식
// GET /api/channel_self
// Headers:
{
"Content-Type": "application/json"
}
// Query parameters:
interface ListChannelsRequest {
app_id: string
platform: "ios" | "android" | "electron"
is_emulator: boolean
is_prod: boolean
key_id?: string
}

응답 형식

응답 형식
[
{
"id": 1,
"name": "production",
"public": true,
"allow_self_set": false
},
{
"id": 2,
"name": "beta",
"public": false,
"allow_self_set": true
}
]

채널 유형 이해

채널 유형 이해

응답에는 각 채널에 대한 두 가지 중요한 플래그가 포함됩니다.

  • public: true: 이 채널은 기본 채널입니다.이 채널은 setChannel()을 사용하여 장치가 자동으로 할당되지 않습니다. unsetChannel()대신, 장치가 채널 할당을 제거하는 경우 (

  • allow_self_set: true을 사용하여), 장치가 채널의 조건과 일치하는 경우 이 공용 채널에서 업데이트를 자동으로 받습니다. : 이 채널은 자동 할당이 가능한 채널입니다. setChannel()장치가 이 채널에 자동으로 할당되지 않습니다.

2. 채널 가져오기 (PUT 요청)

제목 ‘2. 채널 가져오기 (PUT 요청)’

플러그인이 호출할 때 getChannel(), 이 요청을 보냅니다. 기기의 현재 채널 할당을 가져오기 위해 PUT 요청을 보냅니다.

// PUT /api/channel_self
// Headers:
{
"Content-Type": "application/json"
}
// Body:
interface GetChannelRequest {
device_id: string
app_id: string
platform: "ios" | "android" | "electron"
plugin_version: string
version_build: string
version_code: string
version_name: string
is_emulator: boolean
is_prod: boolean
defaultChannel?: string
channel?: string // For newer plugin versions, contains local channel override
}
{
"status": "ok",
"channel": "production",
"allowSet": true,
"message": "",
"error": ""
}

3. 채널 설정 (POST 요청)

3. 채널 설정 (POST 요청) 섹션

플러그인이 호출될 때 setChannel()이때 플러그인은 특정 채널에 장치를 할당하기 위해 POST 요청을 보냅니다.

// POST /api/channel_self
interface SetChannelRequest {
device_id: string
app_id: string
channel: string
platform: "ios" | "android" | "electron"
plugin_version: string
version_build: string
version_code: string
version_name: string
is_emulator: boolean
is_prod: boolean
}
{
"status": "ok",
"message": "Device assigned to channel successfully",
"error": ""
}

장치가 채널을 할당하려고 할 때 공개 채널 (공개 채널) public: true에 대한 에러를 반환해야 합니다.

{
"status": "error",
"error": "public_channel_self_set_not_allowed",
"message": "This channel is public and does not allow device self-assignment. Unset the channel and the device will automatically use the public channel."
}

장치가 자체 할당을 허용하지 않는 채널에 할당하려고 할 때:

{
"status": "error",
"error": "channel_self_set_not_allowed",
"message": "This channel does not allow devices to self associate"
}

4. 채널 해제 (DELETE 요청)

제목 '4. 채널 해제 (DELETE 요청)'

플러그인이 unsetChannel()를 호출하면

장치의 채널 할당을 삭제하기 위해 DELETE 요청을 보냅니다.

Section titled “Request Format”
// DELETE /api/channel_self
interface UnsetChannelRequest {
device_id: string
app_id: string
platform: "ios" | "android" | "electron"
plugin_version: string
version_build: string
version_code: string
version_name: string
}

채널 엔드포인트를 구현하는 자바스크립트 예제입니다.

interface ChannelRequest {
device_id: string
app_id: string
channel?: string
platform: "ios" | "android" | "electron"
plugin_version: string
version_build: string
version_code: string
version_name: string
}
interface ChannelResponse {
status: "ok" | "error"
channel?: string
allowSet?: boolean
message?: string
error?: string
}
export const handler = async (event) => {
const method = event.httpMethod || event.method
const body = JSON.parse(event.body || '{}') as ChannelRequest
const { device_id, app_id, channel, platform } = body
try {
switch (method) {
case 'GET':
return await getDeviceChannel(device_id, app_id)
case 'POST':
return await setDeviceChannel(device_id, app_id, channel!, platform)
case 'DELETE':
return await unsetDeviceChannel(device_id, app_id)
default:
return {
status: "error",
error: "Method not allowed"
}
}
} catch (error) {
return {
status: "error",
error: error.message
}
}
}
async function getDeviceChannel(deviceId: string, appId: string): Promise<ChannelResponse> {
// Query your database for device channel assignment
const assignment = await database.getDeviceChannel(deviceId, appId)
if (assignment) {
return {
status: "ok",
channel: assignment.channel,
allowSet: assignment.allowSelfAssign
}
}
// Return default channel if no assignment found
return {
status: "ok",
channel: "production", // Your default channel
allowSet: true
}
}
async function setDeviceChannel(
deviceId: string,
appId: string,
channel: string,
platform: string
): Promise<ChannelResponse> {
// Validate channel exists and allows self-assignment
const channelConfig = await database.getChannelConfig(channel, appId)
if (!channelConfig) {
return {
status: "error",
error: "Channel not found"
}
}
if (!channelConfig.allowDeviceSelfSet) {
return {
status: "error",
error: "Channel does not allow self-assignment"
}
}
// Check platform restrictions
if (platform === "ios" && !channelConfig.ios) {
return {
status: "error",
error: "Channel not available for iOS"
}
}
if (platform === "android" && !channelConfig.android) {
return {
status: "error",
error: "Channel not available for Android"
}
}
if (platform === "electron" && !channelConfig.electron) {
return {
status: "error",
error: "Channel not available for Electron"
}
}
// Save the assignment
await database.setDeviceChannel(deviceId, appId, channel)
return {
status: "ok",
message: "Device assigned to channel successfully"
}
}
async function unsetDeviceChannel(deviceId: string, appId: string): Promise<ChannelResponse> {
// Remove device channel assignment
await database.removeDeviceChannel(deviceId, appId)
return {
status: "ok",
message: "Device channel assignment removed"
}
}

채널 시스템은 다음 설정 옵션을 지원해야 합니다.

interface ChannelConfig {
name: string
appId: string
// Platform targeting
ios: boolean // Allow updates to iOS devices
android: boolean // Allow updates to Android devices
electron: boolean // Allow updates to Electron apps
// Device type restrictions
allow_emulator: boolean // Allow updates on emulator/simulator devices
allow_device: boolean // Allow updates on real/physical devices
// Build type restrictions
allow_dev: boolean // Allow updates on development builds (is_prod=false)
allow_prod: boolean // Allow updates on production builds (is_prod=true)
// Channel assignment
public: boolean // Default channel - devices fall back to this when no override
allowDeviceSelfSet: boolean // Allow devices to self-assign via setChannel()
// Update policies
disableAutoUpdate: "major" | "minor" | "version_number" | "none"
disableAutoUpdateUnderNative: boolean
}

Compatible 채널 목록을 표시할 때 (GET 요청), 다음 조건에 따라 채널을 필터링해야 합니다:

  1. 플랫폼 확인: 채널은 기기의 플랫폼을 허용해야 합니다 (ios, android, 또는 electron)
  2. 기기 종류 확인:
    • 만약 is_emulator=true: 채널은 allow_emulator=true
    • 만약 is_emulator=false: 채널은 allow_device=true
  3. 빌드 타입 확인:
    • 만약 is_prod=true: 채널은 allow_prod=true
    • 만약 is_prod=false: 채널은 allow_dev=true
  4. 가시성 확인: 채널은 public=true 또는 allow_device_self_set=true
// Example filtering logic
function getCompatibleChannels(
platform: 'ios' | 'android' | 'electron',
isEmulator: boolean,
isProd: boolean,
channels: ChannelConfig[]
): ChannelConfig[] {
return channels.filter(channel => {
// Platform check
if (!channel[platform]) return false
// Device type check
if (isEmulator && !channel.allow_emulator) return false
if (!isEmulator && !channel.allow_device) return false
// Build type check
if (isProd && !channel.allow_prod) return false
if (!isProd && !channel.allow_dev) return false
// Must be accessible (public or self-assignable)
if (!channel.public && !channel.allowDeviceSelfSet) return false
return true
})
}

채널 설정과 장치 할당을 저장해야 합니다:

-- Channels table
CREATE TABLE channels (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
app_id VARCHAR(255) NOT NULL,
-- Platform targeting
ios BOOLEAN DEFAULT true,
android BOOLEAN DEFAULT true,
electron BOOLEAN DEFAULT true,
-- Device type restrictions
allow_emulator BOOLEAN DEFAULT true, -- Allow emulator/simulator devices
allow_device BOOLEAN DEFAULT true, -- Allow real/physical devices
-- Build type restrictions
allow_dev BOOLEAN DEFAULT true, -- Allow development builds
allow_prod BOOLEAN DEFAULT true, -- Allow production builds
-- Channel assignment
public BOOLEAN DEFAULT false, -- Default channel (fallback)
allow_device_self_set BOOLEAN DEFAULT false, -- Allow self-assignment
-- Update policies
disable_auto_update VARCHAR(50) DEFAULT 'none',
disable_auto_update_under_native BOOLEAN DEFAULT false,
created_at TIMESTAMP DEFAULT NOW(),
UNIQUE(name, app_id)
);
-- Device channel assignments table
CREATE TABLE device_channels (
id SERIAL PRIMARY KEY,
device_id VARCHAR(255) NOT NULL,
app_id VARCHAR(255) NOT NULL,
channel_name VARCHAR(255) NOT NULL,
assigned_at TIMESTAMP DEFAULT NOW(),
UNIQUE(device_id, app_id)
);

일반 오류 상황을 처리하는 방법:

// Channel not found
{
"status": "error",
"error": "Channel 'beta' not found"
}
// Self-assignment not allowed
{
"status": "error",
"error": "Channel does not allow device self-assignment"
}
// Platform not supported
{
"status": "error",
"error": "Channel not available for this platform"
}
// Invalid request
{
"status": "error",
"error": "Missing required field: device_id"
}
  1. 보안Context: Page/area: Enterprise product/pricing page. Role: UI label. Seen in: page enterprise.astro. Message key `enterprise_hero_security_label` (Enterprise Hero Security Label).
  2. 채널 assignments를 모든 비즈니스 규칙과 일치시켜야 합니다.로그
  3. Context: : Log all channel operations for auditing and debugging성능
  4. Context: Page/area: Homepage problem/solution section. Role: Section or page heading. Seen in: page premium-support.astro. Message key `ps_help_performance_title` (Ps Help Performance Title).채널 설정을 캐시하여 데이터베이스 쿼리 수를 줄입니다.
  5. 제한 속도: 사용자 남용을 방지하기 위해 제한 속도를 구현하세요.

채널 assignments은 사용자 업데이트 API 엔드포인트. 장치가 업데이트를 요청할 때, 채널 assignments을 확인하여 어떤 버전을 제공할지 결정하세요:

async function getUpdateForDevice(deviceId: string, appId: string) {
// Get device's channel assignment
const channelAssignment = await getDeviceChannel(deviceId, appId)
const channel = channelAssignment.channel || 'production'
// Get the version assigned to this channel
const channelVersion = await getChannelVersion(channel, appId)
return {
version: channelVersion.version,
url: channelVersion.url,
checksum: channelVersion.checksum
}
}

이것은 완전한 자체 호스팅 채널 관리 시스템을 만듭니다. 사용자에게 업데이트가 어떻게 분배되는지에 대한 완전한 제어권을 제공합니다.

채널 API 엔드포인트에서 계속

제목 ‘채널 API 엔드포인트에서 계속’

이것은 사용 중인 채널 API 엔드포인트 __CAPGO_KEEP_0__을 연결하여 채널 라우팅과 단계별 롤아웃을 계획하세요. 자연스러운 네이티브 기능을 사용하기 위해 @capgo/capacitor-업데이터를 사용하세요. 자연스러운 네이티브 기능을 사용하기 위해 @capgo/capacitor-업데이터를 사용하세요. 채널 채널 채널 채널 채널 베타 테스트 솔루션 베타 테스트 솔루션의 제품 워크플로우를 위해 __CAPGO_KEEP_0__