Bundles
Bundles sind die Kernaktualisierungspakete in Capgo. Jedes Bundle enthält die Web-Assets (HTML, CSS, JS), aus denen der Inhalt Ihrer App besteht. Mit den Bundles API können Sie diese Update-Pakete verwalten, einschließlich deren Auflistung und Löschung.
Bundles verstehen
Section titled “Bundles verstehen”Ein Bundle stellt ein bestimmtes Bundle (Version) des Webinhalts Ihrer App dar und umfasst:
- Bundle (Version): Semantische Versionsnummer für das Bundle
- Prüfsumme: Eindeutiger Hash zur Überprüfung der Bundle-Integrität
- Speicherinformationen: Details darüber, wo und wie das Bundle gespeichert wird
- Native Anforderungen: Mindestanforderungen an die native App-Version
- Metadaten: Erstellungszeit, Eigentum und andere Tracking-Informationen
Manuelle Bundle-Erstellung (ohne CLI)
Section titled “Manuelle Bundle-Erstellung (ohne CLI)”So erstellen und laden Sie Bundles manuell ohne Verwendung von Capgo CLI:
Schritt 1: Erstellen Sie Ihre App
Section titled “Schritt 1: Erstellen Sie Ihre App”Erstellen Sie zunächst die Web-Assets Ihrer App:
npm run buildSchritt 2: Bundle-Zip mit denselben Paketen wie Capgo CLI erstellen
Section titled “Schritt 2: Bundle-Zip mit denselben Paketen wie Capgo CLI erstellen”Wichtig: Verwenden Sie genau die gleichen JavaScript-Pakete, die Capgo CLI intern verwendet, um die Kompatibilität sicherzustellen.
Erforderliche Pakete installieren
Section titled “Erforderliche Pakete installieren”npm install adm-zip @tomasklaen/checksumErstellen Sie ein Zip-Bundle mit JavaScript (dasselbe wie Capgo CLI)
Section titled “Erstellen Sie ein Zip-Bundle mit JavaScript (dasselbe wie Capgo CLI)”Hinweis: In den folgenden Beispielen bezieht sich version auf den Bundle-(Versions-)Namen, der von API verwendet wird.
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();Schritt 3: Berechnen Sie die SHA256-Prüfsumme mit demselben Paket wie CLI
Section titled “Schritt 3: Berechnen Sie die SHA256-Prüfsumme mit demselben Paket wie 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;}
// Usageasync function main() { const checksum = await calculateChecksum('./my-app-1.2.3.zip'); console.log('Checksum:', checksum);}
main();Schritt 4: Bundle in Ihren Speicher hochladen
Section titled “Schritt 4: Bundle in Ihren Speicher hochladen”Laden Sie Ihre ZIP-Datei in einen beliebigen über das Internet zugänglichen Speicher hoch:
# 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"Wichtig: Ihr Bundle muss über eine HTTPS-URL öffentlich zugänglich sein (keine Authentifizierung erforderlich). Die Server von Capgo müssen das Paket von dieser URL herunterladen.
Beispiele für gültige öffentliche URLs:
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
Schritt 5: Bundle registrieren bei Capgo API
Section titled “Schritt 5: Bundle registrieren bei Capgo API”Registrieren Sie das externe Bundle bei Capgo mit direkten API-Aufrufen:
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 Parameter
Section titled “API Parameter”| Parameter | Beschreibung | Erforderlich |
|---|---|---|
app_id | Ihre App-ID | Ja |
version | Bundle (Version) semantische Version (z. B. „1.2.3“) | Ja |
external_url | Öffentlich zugänglich HTTPS-URL, unter der das Bundle heruntergeladen werden kann (keine Authentifizierung erforderlich) | Ja |
checksum | SHA256-Prüfsumme der ZIP-Datei | Ja |
Anforderungen an die Bundle-Struktur
Section titled “Anforderungen an die Bundle-Struktur”Ihre Bundle-Zip-Datei muss diesen Anforderungen entsprechen:
- Root-Indexdatei: Muss
index.htmlauf der Root-Ebene haben - Capacitor-Integration: Muss
notifyAppReady()in Ihrem App-Code aufrufen - Asset-Pfade: Verwenden Sie relative Pfade für alle Assets
Gültige Bundle-Struktur
Section titled “Gültige Bundle-Struktur”bundle.zip├── index.html├── assets/│ ├── app.js│ └── styles.css└── images/Vollständiges Beispiel für einen manuellen Workflow
Section titled “Vollständiges Beispiel für einen manuellen Workflow”Einfaches Node.js-Skript zum Komprimieren, Prüfen der Summe und Hochladen nach 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);Abhängigkeiten installieren:
npm install adm-zip @tomasklaen/checksum node-fetchPrüfsummenüberprüfung
Section titled “Prüfsummenüberprüfung”JavaScript Prüfsummenberechnung (wie Capgo CLI)
Section titled “JavaScript Prüfsummenberechnung (wie Capgo CLI)”Verwenden Sie genau dasselbe Paket und dieselbe Methode, die Capgo CLI intern verwendet:
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();```### Prüfsummen-Wichtigkeit
- **Bundle-Integrität**: Stellt sicher, dass das Bundle während der Übertragung nicht beschädigt wurde- **API Überprüfung**: Capgo überprüft Prüfsummen, bevor Pakete akzeptiert werden- **Plugin-Überprüfung**: Das mobile Plugin überprüft Prüfsummen, bevor Updates angewendet werden
## Bewährte Methoden
1. **Bundle-(Versions-)Management**: Semantische Versionierung konsequent verwenden2. **Speicheroptimierung**: Entfernen Sie nicht verwendete Bundles regelmäßig3. **Bundle-(Versions-)Kompatibilität**: Legen Sie entsprechende Mindestanforderungen für die native Version fest4. **Backup-Strategie**: Backups kritischer Bundles (Versionen) verwalten
## Endpunkte
### GET
`https://api.capgo.app/bundle/`
Paketinformationen abrufen. Gibt 50 Bundles pro Seite zurück.
#### Abfrageparameter- `app_id`: Erforderlich. Die ID Ihrer App- `page`: Optional. Seitenzahl für die Paginierung
#### Antworttyp
```typescriptinterface 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}Beispielanfrage
Section titled “Beispielanfrage”# 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"Beispielantwort
Section titled “Beispielantwort”{ "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" } ]}LÖSCHEN
Section titled “LÖSCHEN”https://api.capgo.app/bundle/
Löschen Sie ein oder alle Bundles für eine App. Seien Sie vorsichtig, da diese Aktion nicht rückgängig gemacht werden kann.
Abfrageparameter
Section titled “Abfrageparameter”So löschen Sie ein bestimmtes Bundle:
interface BundleDelete { app_id: string version: string}Zum Löschen aller Bundles:
interface BundleDeleteAll { app_id: string}Beispielanfragen
Section titled “Beispielanfragen”# 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/Erfolgsantwort
Section titled “Erfolgsantwort”{ "status": "ok"}https://api.capgo.app/bundle/
Erstellen Sie ein neues Bundle mit externer URL.
Anforderungstext
Section titled “Anforderungstext”interface CreateBundleBody { app_id: string version: string external_url: string // Must be publicly accessible HTTPS URL checksum: string}Beispielanfrage
Section titled “Beispielanfrage”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/Erfolgsantwort
Section titled “Erfolgsantwort”{ "status": "ok"}POST (Metadaten)
Section titled “POST (Metadaten)”https://api.capgo.app/bundle/metadata
Aktualisieren Sie Bundle-Metadaten wie Link- und Kommentarinformationen.
Anforderungstext
Section titled “Anforderungstext”interface UpdateMetadataBody { app_id: string version_id: number // bundle (version) id link?: string comment?: string}Beispielanfrage
Section titled “Beispielanfrage”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/metadataErfolgsantwort
Section titled “Erfolgsantwort”{ "status": "success"}https://api.capgo.app/bundle/
Legen Sie ein Bundle auf einen bestimmten Kanal fest. Dadurch wird ein Bundle (eine Version) mit einem Vertriebskanal verknüpft.
Anforderungstext
Section titled “Anforderungstext”interface SetChannelBody { app_id: string version_id: number // bundle (version) id channel_id: number}Beispielanfrage
Section titled “Beispielanfrage”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/Erfolgsantwort
Section titled “Erfolgsantwort”{ "status": "success", "message": "Bundle 1.0.0 set to channel production"}Fehlerbehandlung
Section titled “Fehlerbehandlung”Häufige Fehlerszenarien und ihre Antworten:
// 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"}Häufige Anwendungsfälle
Section titled “Häufige Anwendungsfälle”- Alte Bundles (Versionen) bereinigen
// Delete outdated beta bundles (versions){ "app_id": "app_123", "version": "1.0.0-beta.1"}- App-Reset
// Remove all bundles to start fresh{ "app_id": "app_123"}Überlegungen zur Lagerung
Section titled “Überlegungen zur Lagerung”- Aufbewahrungsrichtlinie: Legen Sie fest, wie lange alte Bundles aufbewahrt werden sollen
- Größenverwaltung: Überwachen Sie Bundle-Größen und Speichernutzung
- Backup-Strategie: Erwägen Sie die Sicherung kritischer Bundles (Versionen)
- Kostenoptimierung: Entfernen Sie unnötige Bundles, um die Speicherkosten zu optimieren