バンドル
このプラグインのインストール手順とフルマークダウンガイドを含むセットアッププロンプトをコピーできます。
Bundles are the core update packages in Capgo. Each bundle contains the web assets (HTML, CSS, JS) that make up your app’s content. The Bundles API allows you to manage these update packages, including listing and deleting them.
Understanding Bundles
「バンドルの理解」バンドルは、特定のバージョンのアプリのウェブコンテンツを表し、次の情報を含みます:
- バンドル (バージョン): バンドルのバージョン番号 バンドルのバージョン
- チェックサム: バンドルの整合性を検証する一意のハッシュ
- ストレージ情報: バンドルがどの場所にどのように保存されているかについての詳細
- ネイティブ要件: ネイティブアプリの最低バージョン要件
- メタデータ: __CAPGO_KEEP_0__の作成日時、所有権、その他の追跡情報
CLIの手動作成 (Without CLI)
「CLIの手動作成 (Without CLI)」ここでは、Capgo CLIを使用せずに、Capgo CLIを手動で作成してアップロードする方法を説明します。
ステップ 1: アプリをビルドする
「ステップ 1: アプリをビルドする」まず、アプリのウェブアセットをビルドしてください。
npm run buildステップ 2: Capgo CLIと同じパッケージを使用してバンドル ZIP を作成する
「ステップ 2: Capgo CLIと同じパッケージを使用してバンドル ZIP を作成する」重要な注意事項: Capgo CLI の内部で使用している同じ JavaScript パッケージを使用して、互換性を確保します。
必要なパッケージをインストールする
「必要なパッケージをインストールする」のセクションnpm install adm-zip @tomasklaen/checksumJavaScript で Capgo CLI と同じように ZIP バンドルを作成する
「JavaScript で Capgo CLI と同じように ZIP バンドルを作成する」のセクション下の例では、 version refers to the bundle (version) name used by the API.
const fs = require('node:fs');const path = require('node:path');const os = require('node:os');const AdmZip = require('adm-zip');const { checksum: getChecksum } = require('@tomasklaen/checksum');
// Exact same implementation as Capgo CLIfunction zipFileUnix(filePath) { const zip = new AdmZip(); zip.addLocalFolder(filePath); return zip.toBuffer();}
async function zipFileWindows(filePath) { console.log('Zipping file windows mode'); const zip = new AdmZip();
const addToZip = (folderPath, zipPath) => { const items = fs.readdirSync(folderPath);
for (const item of items) { const itemPath = path.join(folderPath, item); const stats = fs.statSync(itemPath);
if (stats.isFile()) { const fileContent = fs.readFileSync(itemPath); zip.addFile(path.join(zipPath, item).split(path.sep).join('/'), fileContent); } else if (stats.isDirectory()) { addToZip(itemPath, path.join(zipPath, item)); } } };
addToZip(filePath, ''); return zip.toBuffer();}
// Main zipFile function (exact same logic as CLI)async function zipFile(filePath) { if (os.platform() === 'win32') { return zipFileWindows(filePath); } else { return zipFileUnix(filePath); }}
async function createBundle(inputPath, outputPath, version) { // Create zip using exact same method as Capgo CLI const zipped = await zipFile(inputPath);
// Write to file fs.writeFileSync(outputPath, zipped);
// Calculate checksum using exact same package as CLI const checksum = await getChecksum(zipped, 'sha256');
return { filename: path.basename(outputPath), version: version, size: zipped.length, checksum: checksum };}
// Usageasync function main() { try { const result = await createBundle('./dist', './my-app-1.2.3.zip', '1.2.3'); console.log('Bundle info:', JSON.stringify(result, null, 2)); } catch (error) { console.error('Error creating bundle:', error); }}
main();Step 3: Calculate SHA256 Checksum Using Same Package as CLI
Step 3: CLI と同じパッケージを使用して SHA256 チェックサムを計算するconst fs = require('node:fs');const { checksum: getChecksum } = require('@tomasklaen/checksum');
async function calculateChecksum(filePath) { const fileBuffer = fs.readFileSync(filePath); // Use exact same package and method as Capgo CLI const checksum = await getChecksum(fileBuffer, 'sha256'); return checksum;}
// Usageasync function main() { const checksum = await calculateChecksum('./my-app-1.2.3.zip'); console.log('Checksum:', checksum);}
main();ステップ 4: バンドルを自分のストレージにアップロード
セクションのタイトル “ステップ 4: バンドルを自分のストレージにアップロード”zip ファイルを任意の Web アクセス可能なストレージにアップロードしてください:
# Example: Upload to your server via scpscp my-app-1.2.3.zip user@your-server.com:/var/www/bundles/
# Example: Upload to S3 using AWS CLIaws s3 cp my-app-1.2.3.zip s3://your-bucket/bundles/
# Example: Upload via curl to a custom endpointcurl -X POST https://your-storage-api.com/upload \ -H "Authorization: Bearer YOUR_TOKEN" \ -F "file=@my-app-1.2.3.zip"重要コンテキスト: Bug bounty プログラムのページ。役割: UI ラベル。ページ bug-bounty.astro で見られる。メッセージキー `bug_bounty_important_label` (Bug Bounty Important Label)。 : バンドルは via HTTPS URL (no authentication required). Capgo’s servers need to download the bundle from this URL.
https 経由の URL (認証なし) でアクセスできる必要があります。__CAPGO_KEEP_0__ のサーバーは、この URL からバンドルをダウンロードする必要があります。
https://your-storage.com/bundles/my-app-1.2.3.ziphttps://github.com/username/repo/releases/download/v1.2.3/bundle.ziphttps://cdn.jsdelivr.net/gh/username/repo@v1.2.3/dist.zip
Step 5: Register Bundle with Capgo API
Section titled “Step 5: エコタインター、バースタイン、Capgo API”Capgoにバースタインを上バースタイン、Capgo に参数を上バースタイン、API 参数を会だ。
async function registerWithCapgo(appId, version, bundleUrl, checksum, apiKey) { const fetch = require('node-fetch');
// Create bundle (version) const response = await fetch('https://api.capgo.app/bundle/', { method: 'POST', headers: { 'Content-Type': 'application/json', 'authorization': apiKey }, body: JSON.stringify({ app_id: appId, version: version, external_url: bundleUrl, checksum: checksum }) });
if (!response.ok) { throw new Error(`Failed to create bundle: ${response.statusText}`); }
const data = await response.json(); console.log('Bundle created:', data);
return data;}API バースタインを上。
Section titled “API バースタイン”| バースタイン | タイン | 、のバースタイン |
|---|---|---|
app_id | バースタインを上。 | バースタイン、バースタインを上。 |
version | バースタイン、バースタインを上。 バースタイン、バースタインを上。 (例:「1.2.3」) | はい |
external_url | パブリックにアクセス可能 HTTPS URL で Bundle をダウンロードできる場所 (認証なし) | はい |
checksum | zip ファイルの SHA256 チェックサム | はい |
Bundle Structure Requirements
「Bundle Structure Requirements」のセクションあなたの Bundle zip は次の要件を満たす必要があります:
- Root Index File: 必ず
index.htmlrootレベルで - Capacitor統合: 必ず呼び出す
notifyAppReady()アプリケーション内でcode - アセットパス: アセットのすべてのパスを相対パスで使用する
有効なバンドル構造
セクション「有効なバンドル構造」bundle.zip├── index.html├── assets/│ ├── app.js│ └── styles.css└── images/完全な手動ワークフロー例
セクション「完全な手動ワークフロー例」Node.jsスクリプトを簡単に作成して、Capgoにアップロードする:
const fs = require('node:fs');const os = require('node:os');const AdmZip = require('adm-zip');const { checksum: getChecksum } = require('@tomasklaen/checksum');const fetch = require('node-fetch');
async function deployToCapgo() { const APP_ID = 'com.example.app'; const VERSION = '1.2.3'; const BUNDLE_URL = 'https://your-storage.com/bundles/app-1.2.3.zip'; const API_KEY = process.env.CAPGO_API_KEY;
// 1. Create zip (same as Capgo CLI) const zip = new AdmZip(); zip.addLocalFolder('./dist'); const zipped = zip.toBuffer();
// 2. Calculate checksum (same as Capgo CLI) const checksum = await getChecksum(zipped, 'sha256'); console.log('Checksum:', checksum);
// 3. Upload to your storage (replace with your upload logic) // fs.writeFileSync('./bundle.zip', zipped); // ... upload bundle.zip to your storage ...
// 4. Register with Capgo API const response = await fetch('https://api.capgo.app/bundle/', { method: 'POST', headers: { 'Content-Type': 'application/json', 'authorization': API_KEY }, body: JSON.stringify({ app_id: APP_ID, version: VERSION, external_url: BUNDLE_URL, checksum: checksum }) });
if (!response.ok) { throw new Error(`Failed: ${response.statusText}`); }
console.log('Bundle registered with Capgo!');}
deployToCapgo().catch(console.error);依存関係をインストール:
npm install adm-zip @tomasklaen/checksum node-fetchチェックサム検証
「チェックサム検証」のセクションCapgo CLI で内部で使用するパッケージとメソッドをそのまま使用してください:
「Capgo CLI で内部で使用するパッケージとメソッドをそのまま使用してください:」のセクションCapgo CLI で内部で使用するパッケージとメソッドをそのまま使用してください:
const fs = require('node:fs');const { checksum: getChecksum } = require('@tomasklaen/checksum');
async function calculateChecksum(filePath) { const fileBuffer = fs.readFileSync(filePath); // Use exact same package and method as Capgo CLI const checksum = await getChecksum(fileBuffer, 'sha256'); return checksum;}
// Verify checksum matchesasync function verifyChecksum(filePath, expectedChecksum) { const actualChecksum = await calculateChecksum(filePath); const isValid = actualChecksum === expectedChecksum;
console.log(`File: ${filePath}`); console.log(`Expected: ${expectedChecksum}`); console.log(`Actual: ${actualChecksum}`); console.log(`Valid: ${isValid}`);
return isValid;}
// Usageasync function main() { const bundleChecksum = await calculateChecksum('./my-app-1.2.3.zip'); console.log('SHA256 Checksum:', bundleChecksum);}
main();チェックサムの重要性
「チェックサムの重要性」のセクション- バンドル統合: 転送中のバンドルが破損していないことを確認します
- API 検証: Capgo はチェックサムを検証し、バンドルを受け入れる前にチェックします
- プラグイン検証: モバイル プラグインはアップデートを適用する前にチェックサムを検証します
ベスト プラクティス
セクション "ベスト プラクティス"- バンドル (バージョン) 管理: シームレス バージョニング 一貫して
- ストレージ最適化: 不要なバンドルを定期的に削除する
- バンドル(バージョン)互換性: 適切なネイティブ最小バージョン要件を設定する
- バックアップ戦略: 重要なバンドル(バージョン)のバックアップを維持する
エンドポイント
エンドポイントバンドル情報を取得する。1ページあたり50バンドルを返します。
クエリパラメータhttps://api.capgo.app/bundle/
protectedTokens
pagePath
セクションのタイトル “クエリ パラメータ””app_id: 必須。アプリの IDpage: 任意。ページネーションのページ番号
レスポンスのタイプ
セクションのタイトル “レスポンスのタイプ””interface Bundle { app_id: string bucket_id: string | null checksum: string | null created_at: string | null deleted: boolean external_url: string | null id: number minUpdateVersion: string | null name: string native_packages: Json[] | null owner_org: string r2_path: string | null session_key: string | null storage_provider: string updated_at: string | null user_id: string | null}例のリクエスト
セクションのタイトル “例のリクエスト””# Get all bundlescurl -H "authorization: your-api-key" \ "https://api.capgo.app/bundle/?app_id=app_123"
# Get next pagecurl -H "authorization: your-api-key" \ "https://api.capgo.app/bundle/?app_id=app_123&page=1"例のレスポンス
セクションのタイトル “例のレスポンス””{ "data": [ { "id": 1, "app_id": "app_123", "name": "1.0.0", "checksum": "abc123...", "minUpdateVersion": "1.0.0", "storage_provider": "r2", "created_at": "2024-01-01T00:00:00Z", "updated_at": "2024-01-01T00:00:00Z", "deleted": false, "owner_org": "org_123", "user_id": "user_123" } ]}DELETE
「DELETE」のセクションhttps://api.capgo.app/bundle/
アプリのバンドルを1つまたはすべて削除します。削除は取り消すことができませんので、注意してください。
クエリパラメータ
「クエリパラメータ」のセクション特定のバンドルを削除する場合:
interface BundleDelete { app_id: string version: string}すべてのバンドルを削除する場合:
interface BundleDeleteAll { app_id: string}例のリクエスト
「例のリクエスト」のセクション# Delete specific bundlecurl -X DELETE \ -H "authorization: your-api-key" \ -H "Content-Type: application/json" \ -d '{ "app_id": "app_123", "version": "1.0.0" }' \ https://api.capgo.app/bundle/
# Delete all bundlescurl -X DELETE \ -H "authorization: your-api-key" \ -H "Content-Type: application/json" \ -d '{ "app_id": "app_123" }' \ https://api.capgo.app/bundle/成功応答
「成功応答」のセクション{ "status": "ok"}POST
「POST」のセクションhttps://api.capgo.app/bundle/
外部URLで新しいバンドルを作成します。
リクエストボディ
「リクエストボディ」のセクションinterface CreateBundleBody { app_id: string version: string external_url: string // Must be publicly accessible HTTPS URL checksum: string}サンプルリクエスト
Section titled “サンプルリクエスト”curl -X POST \ -H "authorization: your-api-key" \ -H "Content-Type: application/json" \ -d '{ "app_id": "com.example.app", "version": "1.2.3", "external_url": "https://your-storage.com/bundles/app-1.2.3.zip", "checksum": "a1b2c3d4e5f6789abcdef123456789abcdef123456789abcdef123456789abcd" }' \ https://api.capgo.app/bundle/成功レスポンス
Section titled “成功レスポンス”{ "status": "ok"}POST (メタデータ)
Section titled “POST (メタデータ)”https://api.capgo.app/bundle/metadata
バンドルメタデータの更新(リンクやコメント情報など)
リクエストボディ
Section titled “リクエストボディ”interface UpdateMetadataBody { app_id: string version_id: number // bundle (version) id link?: string comment?: string}例のリクエスト
「例のリクエスト」のセクションcurl -X POST \ -H "authorization: your-api-key" \ -H "Content-Type: application/json" \ -d '{ "app_id": "app_123", "version_id": 456, "link": "https://github.com/myorg/myapp/releases/tag/v1.0.0", "comment": "Fixed critical bug in authentication" }' \ https://api.capgo.app/bundle/metadata成功レスポンス
「成功レスポンス」のセクション{ "status": "success"}https://api.capgo.app/bundle/
リクエストボディ
「リクエストボディ」のセクション
バンドルを特定のチャンネルに設定するには、バンドル(バージョン)を配布用のチャンネルに結び付ける必要があります。interface SetChannelBody { app_id: string version_id: number // bundle (version) id channel_id: number}例のリクエスト
「例のリクエスト」のセクションcurl -X PUT \ -H "authorization: your-api-key" \ -H "Content-Type: application/json" \ -d '{ "app_id": "app_123", "version_id": 456, "channel_id": 789 }' \ https://api.capgo.app/bundle/成功レスポンス
「成功レスポンス」のセクション{ "status": "success", "message": "Bundle 1.0.0 set to channel production"}エラー処理
「エラー処理」のセクション一般的なエラーシナリオとそのレスポンス:
// Bundle not found{ "error": "Bundle not found", "status": "KO"}
// Invalid bundle (version) format{ "error": "Invalid version format", "status": "KO"}
// Storage error{ "error": "Failed to delete bundle from storage", "status": "KO"}
// Permission denied{ "error": "Insufficient permissions to manage bundles", "status": "KO"}一般的な使用例
「一般的な使用例」セクション- 古いバンドルを削除 (バージョン)
// Delete outdated beta bundles (versions){ "app_id": "app_123", "version": "1.0.0-beta.1"}- アプリケーション リセット
// Remove all bundles to start fresh{ "app_id": "app_123"}ストレージの考慮事項
「ストレージの考慮事項」セクション- 保持ポリシー:古いバンドルを保持する期間を定義する
- サイズ管理:バンドルサイズとストレージ使用量を監視する
- バックアップ戦略: 重要なバンドル (バージョン) をバックアップすることを検討してください
- コスト最適化: 必要ないバンドルを削除してストレージコストを最適化する
バンドルから続ける
バンドルから続けるセクションあなたが使用している バンドル ストレージとファイルの管理を計画するために使用している場合 @capgo/capacitor-data-storage-sqlite @capgo/capacitor-data-storage-sqlite ストレージの実装詳細については、@capgo/capacitor-data-storage-sqliteを参照してください Capacitorデータストレージのネイティブ機能のために@capgo/capacitor-data-storage-sqliteを使用します。 @capgo/capacitor-file Capacitorファイルの実装詳細のために@capgo/capacitor-fileを使用します。 Using @capgo/capacitor-file for the native capability in Using @capgo/capacitor-file, and @capgo/capacitor-uploader Capacitorアップローダーの実装詳細のために@capgo/capacitor-uploaderを使用します。