Bundle
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
BundleはCapgoのコアとなる更新パッケージです。各Bundleには、アプリのコンテンツを構成するWebアセット(HTML、CSS、JS)が含まれます。Bundles API を使用すると、これらの更新パッケージのリスト表示や削除などの管理を行うことができます。
Bundleの理解
セクション「Bundleの理解」Bundleは、アプリのWebコンテンツの特定のバージョンを表し、以下を含みます:
- Bundle (バージョン): セマンティックバージョン番号 バンドル用
- チェックサム: bundleの整合性を検証する一意のハッシュ
- ストレージ情報: bundleの保存場所と保存方法の詳細
- ネイティブ要件: ネイティブアプリの最小バージョン要件
- メタデータ: 作成日時、所有権、その他の追跡情報
手動でのbundle作成(CLIを使用しない場合)
「手動でのbundle作成(CLIを使用しない場合)」というセクションCapgo CLI を使用せずに、手動でbundleを作成してuploadする方法は次のとおりです:
ステップ 1: アプリのビルド
セクション「ステップ 1: アプリのビルド」まず、アプリの Web アセットをビルドしてください:
npm run buildステップ 2: Capgo CLI と同じパッケージで Bundle Zip を作成
セクション「ステップ 2: Capgo CLI と同じパッケージで Bundle Zip を作成」重要: 互換性を確保するため、Capgo CLI が内部で使用している JavaScript パッケージとまったく同じものを使用してください。
必要なパッケージのインストール
セクション「必要なパッケージのインストール」npm install adm-zip @tomasklaen/checksumJavaScriptでZip Bundleを作成する (Capgo CLI と同様)
「JavaScriptでZip Bundleを作成する (Capgo CLI と同様)」セクション注意: 以下の例では、 version は API で使用される bundle (version) 名を指します。
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();ステップ 3: CLI と同じパッケージで SHA256 チェックサムを計算
「ステップ 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: ストレージに Bundle をアップロード
「ステップ 4: ストレージに Bundle を upload する」セクションzip ファイルを Web からアクセス可能な任意のストレージに upload してください:
# 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"重要:バンドルは パブリックにアクセス可能 な HTTPS URL(認証不要)である必要があります。Capgo のサーバーがこの URL からバンドルをダウンロードする必要があります。
有効なパブリック 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
ステップ 5: Capgo API に Bundle を登録
「ステップ 5: Capgo API にバンドルを登録」セクション直接の API 呼び出しを使用して、Capgo に外部バンドルを登録します:
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 パラメータ
セクション「API パラメータ」| パラメータ | 説明 | 必須 |
|---|---|---|
app_id | アプリの識別子 | はい |
version | Bundle (バージョン) セマンティックバージョン (例: “1.2.3”) | はい |
external_url | 公開アクセス可能 BundleをダウンロードできるHTTPS URL (認証不要) | はい |
checksum | zipファイルのSHA256チェックサム | はい |
Bundle の構造要件
「Bundle構造の要件」セクションbundleのzipファイルは以下の要件を満たす必要があります:
- ルートインデックスファイル:必ず含める
index.htmlルートレベルに - Capacitor の統合:呼び出しが必要
notifyAppReady()アプリ内で code を - アセットパスすべてのアセットに相対パスを使用します
有効な Bundle 構造
セクション「有効なバンドル構造」bundle.zip├── index.html├── assets/│ ├── app.js│ └── styles.css└── images/手動ワークフローの完全な例
セクション「完全な手動ワークフローの例」zip 化、チェックサム計算、Capgo へのアップロードを行うシンプルな Node.js スクリプト:
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チェックサムの検証
「チェックサム検証」セクションJavaScript によるチェックサム計算 (Capgo CLI と同様)
「JavaScript チェックサム計算(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();チェックサムの重要性
「チェックサムの重要性」セクション- Bundleの整合性:転送中にバンドルが破損していないことを保証します
- API 検証:Capgo はバンドルを受け入れる前にチェックサムを検証します
- プラグインの検証:モバイルプラグインは更新を適用する前にチェックサムを検証します
ベストプラクティス
「ベストプラクティス」セクション- バンドル(バージョン)管理: 使用する セマンティックバージョニング 一貫して
- ストレージの最適化:未使用のバンドルを定期的に削除します
- バンドル(バージョン)の互換性: 適切なネイティブバージョンの最低要件を設定します
- バックアップ戦略: 重要なbundle(バージョン)のバックアップを保持します
エンドポイント
「Endpoints」セクションGET
「GET」セクションhttps://api.capgo.app/bundle/
bundle情報を取得します。フィルタなしの場合、1ページあたり50件のbundleを返します。フィルタを version または id使用した場合は、0件または1件のbundleを含む同じJSON配列形式で返されます。
クエリパラメータ
「Query Parameters」セクションapp_id: 必須。アプリのIDpage: 任意。ページネーション用のページ番号(versionまたはidが設定されています)version:任意。正確なバンドルバージョン名 (app_versions.name、例えば1.2.3)。0件または1件のアイテムを含むJSON配列を返します。id:任意。数値のバンドルID (app_versions.id)。0件または1件のアイテムを含むJSON配列を返します。
同じ authorization ヘッダーと API キーのアプリスコープをページネーション付きリストと同様に使用します。クエリスキーマの検証で拒否された値は invalid_query エラー。
バージョンの存在確認 (CI)
セクション「バージョンの存在確認 (CI)」アップロードやチャネル割り当ての前に、CLI の代わりに HTTP チェックが必要なときに使います:
curl -H "authorization: YOUR_API_KEY" \ "https://api.capgo.app/bundle/?app_id=com.example.app&version=1.2.3"空でない JSON 配列は、そのバージョンがアプリに既に存在することを意味します。空の配列は存在しないことを意味します。
アップロードワークフローでは、Capgo の CLI フラグ bundle upload --version-exists-ok は、ターゲットバージョンが存在する場合に既に正常終了するため、このエンドポイントを呼び出さずに多くの CI ジョブをカバーできます。
レスポンス型
「Response Type」セクション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"
# Look up one bundle by version namecurl -H "authorization: your-api-key" \ "https://api.capgo.app/bundle/?app_id=app_123&version=1.0.0"
# Look up one bundle by idcurl -H "authorization: your-api-key" \ "https://api.capgo.app/bundle/?app_id=app_123&id=456"レスポンス例
「レスポンス例」というタイトルのセクション[ { "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" }]https://api.capgo.app/bundle/
アプリのbundleを単一または一括で削除します。この操作は取り消せないため、実行には十分注意してください。
クエリパラメータ
「Query Parameters」セクション特定のbundleを削除する場合:
interface BundleDelete { app_id: string version: string}すべてのbundleを削除する場合:
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を使用して新しいbundleを作成します。
リクエストボディ
「リクエストボディ」のセクションinterface CreateBundleBody { app_id: string version: string external_url: string // Must be publicly accessible HTTPS URL checksum: string}リクエスト例
「リクエスト例」のセクション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/成功時のレスポンス
「成功時のレスポンス」のセクション{ "status": "ok"}POST (メタデータ)
「POST (メタデータ)」セクションhttps://api.capgo.app/bundle/metadata
リンクやコメント情報などのバンドルメタデータを更新します。
リクエストボディ
「リクエストボディ」のセクション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"}PUT
「PUT」のセクションhttps://api.capgo.app/bundle/
バンドルを特定のチャネルに設定します。これにより、バンドル(バージョン)が配布用のチャネルにリンクされます。
リクエストボディ
「リクエストボディ」のセクションinterface SetChannelBody { app_id: string version_id: number // bundle (version) id channel_id: number target?: "auto" | "stable" | "rollout" // default: auto}target チャネルに段階的ロールアウトが設定されている場合、バンドルがどこにリンクされるかを制御します:
auto— 段階的ロールアウトが設定されている場合のロールアウト対象。それ以外の場合は stable(デフォルト)。rollout— 常にロールアウト対象を設定します。stable のフォールバックは変更されません。stable— stable のフォールバックを置き換えます(エスケープハッチ)。
リクエスト例
「リクエスト例」のセクション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"}エラーハンドリング
「エラーハンドリング」セクションすべてのエラーは、以下で説明する標準エラー形式に従います API の概要.
よくあるエラーシナリオとそのレスポンス:
// app_id is not a reverse-domain identifier{ "error": "invalid_app_id", "message": "App ID must be a reverse domain string", "moreInfo": { "app_id": "my app" }}
// Deleting a bundle without access to the app{ "error": "cannot_delete_bundle", "message": "You can't access this app", "moreInfo": { "app_id": "com.example.app" }}
// Deleting a bundle that a channel still uses{ "error": "cannot_delete_linked_version", "message": "Cannot delete a bundle linked to a channel", "moreInfo": { "app_id": "com.example.app", "version": "1.0.0" }}
// Creating a bundle whose version is not valid semver{ "error": "invalid_version_format", "message": "Version must be valid semver format (e.g., 1.0.0, 1.0.0-alpha.1)", "moreInfo": { "version": "v1" }}
// Setting a channel to a bundle that does not exist{ "error": "cannot_find_version", "message": "Cannot find version", "moreInfo": {}}よくあるユースケース
「よくあるユースケース」セクション- 古いBundle(バージョン)のクリーンアップ
// 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"}ストレージの考慮事項
「ストレージの考慮事項」セクション- 保持ポリシー: 古いbundleの保持期間を定義します
- サイズ管理: bundleのサイズとストレージ使用量を監視します
- バックアップ戦略: 重要なbundle(バージョン)のバックアップを検討してください
- コスト最適化: 不要なbundleを削除してストレージコストを最適化する
Bundles から続ける
「Bundles から続ける」というセクション使用している場合 Bundle ストレージとファイル処理を計画するには、以下と連携してください: @capgo/capacitor-data-storage-sqlite @capgo/capacitor-data-storage-sqlite の実装の詳細については、 @capgo/capacitor-data-storage-sqlite の使い方 「@capgo/capacitor-data-storage-sqliteの使用方法」におけるネイティブ機能について、 @capgo/capacitor-file @capgo/capacitor-file の実装の詳細については、 @capgo/capacitor-file の使い方 「@capgo/capacitor-file の使用」のネイティブ機能については、および @capgo/capacitor-uploader @capgo/capacitor-uploader. の実装の詳細については