indraq_cli 2.7.9 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -11
- package/cloud-api/dist/index.js +76 -21
- package/cloud-api/package.json +1 -1
- package/cloud-api/sql/014_mobile_native_build_history.sql +50 -0
- package/cloud-api/src/index.ts +63 -19
- package/dist/cli/help-content.js +1 -1
- package/dist/modules/cloud/services/cloud-api.service.d.ts.map +1 -1
- package/dist/modules/cloud/services/cloud-api.service.js +53 -15
- package/dist/modules/cloud/services/cloud-api.service.js.map +1 -1
- package/dist/modules/mobile/commands/build-mobile.command.d.ts.map +1 -1
- package/dist/modules/mobile/commands/build-mobile.command.js +18 -0
- package/dist/modules/mobile/commands/build-mobile.command.js.map +1 -1
- package/dist/modules/mobile/commands/mobile-prebuild.command.d.ts.map +1 -1
- package/dist/modules/mobile/commands/mobile-prebuild.command.js +3 -0
- package/dist/modules/mobile/commands/mobile-prebuild.command.js.map +1 -1
- package/dist/modules/mobile/commands/ota.command.d.ts.map +1 -1
- package/dist/modules/mobile/commands/ota.command.js +196 -79
- package/dist/modules/mobile/commands/ota.command.js.map +1 -1
- package/dist/modules/mobile/commands/testers.command.d.ts +1 -0
- package/dist/modules/mobile/commands/testers.command.d.ts.map +1 -1
- package/dist/modules/mobile/commands/testers.command.js +28 -5
- package/dist/modules/mobile/commands/testers.command.js.map +1 -1
- package/dist/modules/mobile/index.d.ts.map +1 -1
- package/dist/modules/mobile/index.js +9 -0
- package/dist/modules/mobile/index.js.map +1 -1
- package/dist/modules/mobile/services/mobile-cloud.service.d.ts +22 -0
- package/dist/modules/mobile/services/mobile-cloud.service.d.ts.map +1 -1
- package/dist/modules/mobile/services/mobile-cloud.service.js +5 -1
- package/dist/modules/mobile/services/mobile-cloud.service.js.map +1 -1
- package/dist/modules/mobile/services/ota-apk-validator.service.d.ts +18 -0
- package/dist/modules/mobile/services/ota-apk-validator.service.d.ts.map +1 -0
- package/dist/modules/mobile/services/ota-apk-validator.service.js +205 -0
- package/dist/modules/mobile/services/ota-apk-validator.service.js.map +1 -0
- package/dist/modules/mobile/services/ota-setup.service.d.ts.map +1 -1
- package/dist/modules/mobile/services/ota-setup.service.js +10 -7
- package/dist/modules/mobile/services/ota-setup.service.js.map +1 -1
- package/dist/shared/process/run-npx.d.ts +7 -0
- package/dist/shared/process/run-npx.d.ts.map +1 -1
- package/dist/shared/process/run-npx.js +42 -1
- package/dist/shared/process/run-npx.js.map +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# IndraQ CLI — developer guide (v2.
|
|
1
|
+
# IndraQ CLI — developer guide (v2.8.0)
|
|
2
2
|
|
|
3
3
|
> **Mobile Jenkins safety policy:** IndraQ CLI **never creates, edits, replaces, repairs, or deletes** the shared mobile Jenkins Pipeline. Both `indraq mobile prebuild` and `indraq mobile build` check the existing manually managed `Mobile app Cli build` job **read-only**. If the job is missing, disabled, or has incorrect/missing parameters, the command stops; an administrator fixes Jenkins manually. Only an actual build request sends `POST /buildWithParameters` with the expected inputs.
|
|
4
4
|
|
|
@@ -9,12 +9,31 @@
|
|
|
9
9
|
|
|
10
10
|
**One command-line workspace for creating, connecting, building, deploying, and maintaining web and mobile projects.**
|
|
11
11
|
|
|
12
|
-
`v2.
|
|
12
|
+
`v2.8.0` · `Node.js 22+` · `Windows / macOS / Linux` · `IndraQ Cloud` · `Jenkins` · `Docker` · `Expo / React Native`
|
|
13
13
|
</div>
|
|
14
14
|
|
|
15
|
-
> **Start here:** This guide assumes you have never used IndraQ CLI before. No familiarity with Jenkins, AWS, Docker registries, or deployment pipelines is required for the developer quick start. Screens and command names reflect the **v2.
|
|
15
|
+
> **Start here:** This guide assumes you have never used IndraQ CLI before. No familiarity with Jenkins, AWS, Docker registries, or deployment pipelines is required for the developer quick start. Screens and command names reflect the **v2.8.0 CLI source**. This README is intentionally a fresh user manual, not a historical changelog.
|
|
16
16
|
|
|
17
|
-
## OTA
|
|
17
|
+
## Version-based OTA publishing (new in v2.8.0)
|
|
18
|
+
|
|
19
|
+
**Select a successfully built APK first; select the recipient group or device second.** `indraq mobile send update` shows verified IndraQ Cloud native-build records (e.g., Barakah 0.4 Jenkins #19, runtime `0.4-indraq-prod`), not the next local version (0.5) that prebuild prepared. The CLI temporarily configures the selected runtime **and the selected APK's version/versionCode metadata** while hashing native dependencies and exporting JavaScript, then restores your working project's `app.json`, `package.json`, generated OTA files, and `.indraq/mobile.json` even when export/publish fails. A fingerprint mismatch blocks publishing. Reusing the same runtime with conflicting native fingerprints is also blocked at Cloud.
|
|
20
|
+
|
|
21
|
+
Successful Jenkins builds are retained in **Cloud API v1.3.7** table `mobile_native_builds`. Migration `014_mobile_native_build_history.sql` runs automatically at Cloud startup and recovers previously recorded builds from verified `mobile.native-build.record` audit events where possible, including a successful 0.4 build whose single-slot baseline was invalidated by a later 0.5 prebuild. It cannot recover builds if their audit records were deleted. `indraq mobile prebuild` no longer destroys old native build history; the OTA manifest endpoint can serve all registered successful runtimes.
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
indraq mobile send update
|
|
25
|
+
# Choose successful installed version/build → Android/iOS → recipient audience
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Reliable Cloud publishing:** Expo exports run asynchronously (avoiding `spawnSync` stalls). The API reports underlying network errors, retries transient network failures only for safe/idempotent operations, and generates one stable idempotency key per release attempt to avoid duplicate drafts. Exports are saved before upload in `.indraq/ota-outbox/<request-id>`; if Cloud goes offline, run `indraq mobile send update` again and select **Resume** to upload the identical immutable bundles without repeating Metro. The outbox directory contains a `.gitignore` and is cleared only after finalization succeeds. Avoid changing the assets in an outbox manually.
|
|
29
|
+
|
|
30
|
+
**Tester identity across upgrades:** Installation IDs are generated once and stored in the app's AsyncStorage; a normal in-place APK update with the same Android package/signing identity preserves that ID, enrollment and group access. The server continuously updates the recorded runtime and eligibility as each build opens. Deleting app data or uninstalling can reset the installation ID; distinct IDs with similar labels cannot be safely merged automatically. `indraq mobile testers rename` (WRITE access) changes only a display name. Device menus show the label, platform, runtime, and a short ID suffix to differentiate old and new installations; only currently compatible devices are offered for targeted delivery.
|
|
31
|
+
|
|
32
|
+
**Rollout:** Back up Cloud Postgres, deploy Cloud API v1.3.7 first (migration 014), then install CLI v2.8.0. Existing native binaries do not need a rebuild for the server/CLI publishing logic. The existing generated app bootstrap retains the same anonymous Installation ID and QR enrollment behavior. Do not edit the Jenkins Pipeline; it remains read-only to IndraQ.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## OTA activation reliability (v2.8.0)
|
|
18
37
|
|
|
19
38
|
Prebuild defaults to an anonymous, persistent per-installation ID. Optional saved-profile targeting can be enabled later with `indraq mobile identity configure`; it is not required for installation-based OTA.
|
|
20
39
|
|
|
@@ -24,7 +43,7 @@ A native `ExpoUpdates.reload` rejection cannot be repaired solely by changing Ja
|
|
|
24
43
|
|
|
25
44
|
For a project created with an older CLI, run `indraq mobile prebuild` to regenerate the app-side bootstrap, review and commit the generated files, and distribute the updated JavaScript through a compatible OTA release or a fresh native build. The change is not retroactive to previously installed binaries.
|
|
26
45
|
|
|
27
|
-
## Automatic device enrollment & targeting (v2.
|
|
46
|
+
## Automatic device enrollment & targeting (v2.8.0)
|
|
28
47
|
|
|
29
48
|
**No login-screen imports, no app email/phone assumptions, no hand-entered installation IDs.** Every installed production app reports a persistent, anonymous Installation ID. Developers can enroll named QA devices using a short-lived, one-time QR invitation generated by IndraQ Cloud.
|
|
30
49
|
|
|
@@ -66,6 +85,7 @@ indraq mobile testers list
|
|
|
66
85
|
indraq mobile testers installations
|
|
67
86
|
indraq mobile testers group create
|
|
68
87
|
indraq mobile testers revoke
|
|
88
|
+
indraq mobile testers rename
|
|
69
89
|
indraq mobile send update
|
|
70
90
|
```
|
|
71
91
|
|
|
@@ -83,7 +103,7 @@ During **Send update**, pick **Tester groups**, **Named testers**, **Selected in
|
|
|
83
103
|
|
|
84
104
|
---
|
|
85
105
|
|
|
86
|
-
## Automatic OTA audience identities (v2.
|
|
106
|
+
## Automatic OTA audience identities (v2.8.0)
|
|
87
107
|
|
|
88
108
|
The primary workflow now uses **per-installation QR enrollment** and does **not** inspect or require each application's login users. The earlier profile adapter remains optional for legacy email/phone targeting: `indraq mobile prebuild` defaults to anonymous installation identity and reuses existing `indraq-ota/identity.json`. Only a developer deliberately running `indraq mobile identity configure` is asked to select saved profile keys.
|
|
89
109
|
|
|
@@ -103,7 +123,7 @@ The adapter reads only the configured profile key, extracts `userId`, `username`
|
|
|
103
123
|
|
|
104
124
|
**Jenkins protection remains absolute:** `mobile prebuild`, `mobile identity` and `mobile build` never create, replace, or edit the Jenkins Pipeline. They only validate the existing job and submit build parameters.
|
|
105
125
|
|
|
106
|
-
## Live provider account checks and self-hosted OTA troubleshooting (v2.
|
|
126
|
+
## Live provider account checks and self-hosted OTA troubleshooting (v2.8.0)
|
|
107
127
|
|
|
108
128
|
A **Cloud scope assignment does not guarantee a working provider login**. Provider accounts can be deleted or changed directly in Jenkins, NPM, or AWS after IndraQ initially provisions them.
|
|
109
129
|
|
|
@@ -585,6 +605,7 @@ mindmap
|
|
|
585
605
|
| `indraq mobile testers installations` | Show installations registered with OTA |
|
|
586
606
|
| `indraq mobile testers group create` | Create a named tester group (WRITE) |
|
|
587
607
|
| `indraq mobile testers revoke` | Revoke enrolled tester access (WRITE) |
|
|
608
|
+
| `indraq mobile testers rename` | Rename an enrolled device without new QR (WRITE) |
|
|
588
609
|
| `indraq mobile send update` | Export an OTA update; select groups, named testers, installations, percentage or everyone |
|
|
589
610
|
| `indraq mobile release update` | Promote a tested immutable OTA release to everyone |
|
|
590
611
|
| `indraq mobile pause` | Pause a selected OTA release |
|
|
@@ -1482,7 +1503,7 @@ Only publish after a clean dependency-backed TypeScript build, tests, and an npm
|
|
|
1482
1503
|
|
|
1483
1504
|
**IndraQ CLI — build once, deploy deliberately, and manage infrastructure with clear permissions.**
|
|
1484
1505
|
|
|
1485
|
-
Maintained by **IndraQ Innovations Private Limited** · Documented for CLI **v2.
|
|
1506
|
+
Maintained by **IndraQ Innovations Private Limited** · Documented for CLI **v2.8.0**
|
|
1486
1507
|
|
|
1487
1508
|
</div>
|
|
1488
1509
|
|
|
@@ -1496,7 +1517,7 @@ Mobile build uses `indraq mobile build`. In v2.7.9, the CLI checks that the chos
|
|
|
1496
1517
|
If you still see HTTP 400, have a Jenkins administrator check that the job is parameterized and the File Parameter plugin is active. IndraQ will not attempt automatic repair.
|
|
1497
1518
|
|
|
1498
1519
|
|
|
1499
|
-
## Jenkins mobile Pipeline protection (v2.
|
|
1520
|
+
## Jenkins mobile Pipeline protection (v2.8.0)
|
|
1500
1521
|
|
|
1501
1522
|
For the existing shared job `Mobile app Cli build`, **IndraQ never replaces your Jenkins Pipeline script** during `indraq mobile prebuild` or `indraq mobile build`.
|
|
1502
1523
|
|
|
@@ -1505,7 +1526,7 @@ For the existing shared job `Mobile app Cli build`, **IndraQ never replaces your
|
|
|
1505
1526
|
- If a required parameter already exists with an incompatible type or choice list, prebuild **stops instead of overwriting it**. An administrator should resolve the conflict explicitly in Jenkins.
|
|
1506
1527
|
- Updating the Pipeline script remains a manual Jenkins operation. The CLI does **not** automatically deploy new pipeline script revisions into an existing job.
|
|
1507
1528
|
|
|
1508
|
-
> Deployment: deploy Cloud API **v1.3.
|
|
1529
|
+
> Deployment: deploy Cloud API **v1.3.7** before using CLI **v2.8.0**.
|
|
1509
1530
|
|
|
1510
1531
|
### Mobile Jenkins job: manual setup and repair
|
|
1511
1532
|
|
|
@@ -1523,4 +1544,4 @@ Before using IndraQ mobile prebuild/build, an administrator must configure an ex
|
|
|
1523
1544
|
|
|
1524
1545
|
The CLI reads the job type, enabled/buildable status, parameters, file types and choices. If invalid, it prints what needs manual repair **before uploading any source**. If valid, the build uses only Jenkins' `buildWithParameters` endpoint, streams the output, and leaves job configuration untouched. A real build naturally creates build history/artifacts, not Jenkins job configuration changes.
|
|
1525
1546
|
|
|
1526
|
-
**Older CLI versions:**
|
|
1547
|
+
**Older CLI versions:** Cloud API v1.3.7 retains the Jenkins read-only protections introduced in v1.3.5. It rejects the legacy create/repair mobile operations with HTTP 409, so older CLI clients cannot modify the shared mobile job through IndraQ Cloud either.
|
package/cloud-api/dist/index.js
CHANGED
|
@@ -3168,6 +3168,23 @@ app.get('/mobile/apps/:appId/enrollments', auth, async (req, res) => {
|
|
|
3168
3168
|
FROM ota_enrollment_invitations WHERE app_id=$1 ORDER BY created_at DESC LIMIT 100`, [appRow.id])).rows;
|
|
3169
3169
|
res.json(rows);
|
|
3170
3170
|
});
|
|
3171
|
+
app.patch('/mobile/apps/:appId/testers/:installationId', auth, async (req, res) => {
|
|
3172
|
+
const appRow = await mobileAppForUser(routeParam(req.params.appId), req.auth, true);
|
|
3173
|
+
if (!appRow) {
|
|
3174
|
+
res.status(404).json({ error: 'Mobile app not found or WRITE access denied.' });
|
|
3175
|
+
return;
|
|
3176
|
+
}
|
|
3177
|
+
const label = textValue(req.body?.label, 'Device name', 80);
|
|
3178
|
+
const installationId = routeParam(req.params.installationId);
|
|
3179
|
+
const row = (await pool.query(`UPDATE ota_tester_installations SET label=$1
|
|
3180
|
+
WHERE app_id=$2 AND installation_id=$3 AND revoked_at IS NULL RETURNING installation_id,label`, [label, appRow.id, installationId])).rows[0];
|
|
3181
|
+
if (!row) {
|
|
3182
|
+
res.status(404).json({ error: 'Active tester device not found.' });
|
|
3183
|
+
return;
|
|
3184
|
+
}
|
|
3185
|
+
await audit(req.auth.id, 'ota.testers.rename', 'mobile-app', appRow.id, 'Rename enrolled tester device', { installationId, label });
|
|
3186
|
+
res.json(row);
|
|
3187
|
+
});
|
|
3171
3188
|
app.delete('/mobile/apps/:appId/testers/:installationId', auth, async (req, res) => {
|
|
3172
3189
|
const appRow = await mobileAppForUser(routeParam(req.params.appId), req.auth, true);
|
|
3173
3190
|
if (!appRow) {
|
|
@@ -3332,9 +3349,12 @@ app.get('/projects/:projectId/mobile', auth, async (req, res) => {
|
|
|
3332
3349
|
}
|
|
3333
3350
|
const appRow = (await pool.query(`SELECT ma.id,ma.project_id,ma.app_name,ma.project_type,ma.android_package,ma.ios_bundle_identifier,ma.enrollment_scheme,ma.runtime_policy,ma.update_path,ma.signing_key_id,ma.signing_certificate,
|
|
3334
3351
|
me.id environment_id,me.name environment_name,me.slug environment_slug,me.build_type,me.jenkins_stage,me.ota_channel,mae.runtime_version,mae.enabled,
|
|
3335
|
-
|
|
3352
|
+
nb.native_fingerprint,nb.app_version AS native_build_version,nb.version_code AS native_build_version_code,nb.build_number AS native_build_number,nb.build_url AS native_build_url,nb.source_sha256 AS native_build_source_sha256,nb.built_at AS native_built_at
|
|
3336
3353
|
FROM mobile_apps ma
|
|
3337
3354
|
LEFT JOIN mobile_app_environments mae ON mae.app_id=ma.id
|
|
3355
|
+
LEFT JOIN LATERAL (SELECT b.* FROM mobile_native_builds b
|
|
3356
|
+
WHERE b.app_id=mae.app_id AND b.mobile_environment_id=mae.mobile_environment_id AND b.runtime_version=mae.runtime_version
|
|
3357
|
+
ORDER BY b.built_at DESC LIMIT 1) nb ON true
|
|
3338
3358
|
LEFT JOIN mobile_environments me ON me.id=mae.mobile_environment_id
|
|
3339
3359
|
WHERE ma.project_id=$1 ORDER BY me.name`, [projectId])).rows;
|
|
3340
3360
|
if (!appRow.length) {
|
|
@@ -3395,13 +3415,8 @@ app.post('/projects/:projectId/mobile/register', auth, async (req, res) => {
|
|
|
3395
3415
|
const appRow = appResult.rows[0];
|
|
3396
3416
|
await pool.query(`INSERT INTO mobile_app_environments(app_id,mobile_environment_id,runtime_version) VALUES($1,$2,$3)
|
|
3397
3417
|
ON CONFLICT(app_id,mobile_environment_id) DO UPDATE SET
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
native_build_version_code=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_build_version_code END,
|
|
3401
|
-
native_build_number=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_build_number END,
|
|
3402
|
-
native_build_url=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_build_url END,
|
|
3403
|
-
native_build_source_sha256=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_build_source_sha256 END,
|
|
3404
|
-
native_built_at=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_built_at END,
|
|
3418
|
+
-- Keep the last successful native baseline as a historical pointer.
|
|
3419
|
+
-- Prebuild NEVER clears a successful binary's fingerprint.
|
|
3405
3420
|
runtime_version=excluded.runtime_version,enabled=true,updated_at=now()`, [appRow.id, environmentId, runtimeVersion]);
|
|
3406
3421
|
await audit(req.auth.id, 'mobile.app.register', 'mobile-app', appRow.id, reason, { projectId, environmentId, runtimeVersion, projectType });
|
|
3407
3422
|
res.json({ id: appRow.id, projectId, appName: appRow.app_name, projectType: appRow.project_type, updateUrl: `${publicApiUrl}/ota/v1/manifest/${appRow.update_path}`, keyId: appRow.signing_key_id, certificate: appRow.signing_certificate, environment: { id: env.id, name: env.name, slug: env.slug, buildType: env.build_type, jenkinsStage: env.jenkins_stage, otaChannel: env.ota_channel, runtimeVersion } });
|
|
@@ -3448,10 +3463,30 @@ app.post('/mobile/apps/:appId/environments/:environmentId/native-build', auth, a
|
|
|
3448
3463
|
res.status(400).json({ error: 'sourceSha256 must be a 64-character SHA-256 hex value.' });
|
|
3449
3464
|
return;
|
|
3450
3465
|
}
|
|
3466
|
+
// Persist every successful build. A future prebuild cannot invalidate it.
|
|
3467
|
+
const savedBuild = (await pool.query(`INSERT INTO mobile_native_builds
|
|
3468
|
+
(app_id,mobile_environment_id,runtime_version,native_fingerprint,app_version,version_code,build_number,build_url,source_sha256,built_at,recorded_by)
|
|
3469
|
+
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,now(),$10)
|
|
3470
|
+
ON CONFLICT (app_id,mobile_environment_id,build_number) WHERE build_number IS NOT NULL
|
|
3471
|
+
DO UPDATE SET build_url=EXCLUDED.build_url
|
|
3472
|
+
RETURNING id`, [appRow.id, environmentId, runtimeVersion, nativeFingerprint, appVersion, versionCode, buildNumber, buildUrl, sourceSha || null, req.auth.id])).rows[0];
|
|
3451
3473
|
const row = (await pool.query(`UPDATE mobile_app_environments SET native_fingerprint=$1,native_build_version=$2,native_build_version_code=$3,native_build_number=$4,native_build_url=$5,native_build_source_sha256=$6,native_built_at=now(),updated_at=now()
|
|
3452
3474
|
WHERE app_id=$7 AND mobile_environment_id=$8 RETURNING runtime_version,native_fingerprint,native_build_version,native_build_version_code,native_build_number,native_build_url,native_build_source_sha256,native_built_at`, [nativeFingerprint, appVersion, versionCode, buildNumber, buildUrl, sourceSha || null, appRow.id, environmentId])).rows[0];
|
|
3453
3475
|
await audit(req.auth.id, 'mobile.native-build.record', 'mobile-app', appRow.id, reason, { environmentId, runtimeVersion, nativeFingerprint, appVersion, versionCode, buildNumber, sourceSha256: sourceSha || null });
|
|
3454
|
-
res.json({ runtimeVersion: row.runtime_version, nativeFingerprint: row.native_fingerprint, nativeBuildVersion: row.native_build_version, nativeBuildVersionCode: row.native_build_version_code === null ? null : Number(row.native_build_version_code), nativeBuildNumber: row.native_build_number, nativeBuildUrl: row.native_build_url, nativeBuildSourceSha256: row.native_build_source_sha256, nativeBuiltAt: row.native_built_at });
|
|
3476
|
+
res.json({ nativeBuildId: savedBuild.id, runtimeVersion: row.runtime_version, nativeFingerprint: row.native_fingerprint, nativeBuildVersion: row.native_build_version, nativeBuildVersionCode: row.native_build_version_code === null ? null : Number(row.native_build_version_code), nativeBuildNumber: row.native_build_number, nativeBuildUrl: row.native_build_url, nativeBuildSourceSha256: row.native_build_source_sha256, nativeBuiltAt: row.native_built_at });
|
|
3477
|
+
});
|
|
3478
|
+
app.get('/mobile/apps/:appId/native-builds', auth, async (req, res) => {
|
|
3479
|
+
const appRow = await mobileAppForUser(routeParam(req.params.appId), req.auth);
|
|
3480
|
+
if (!appRow) {
|
|
3481
|
+
res.status(404).json({ error: 'Mobile app not found or access denied.' });
|
|
3482
|
+
return;
|
|
3483
|
+
}
|
|
3484
|
+
const rows = (await pool.query(`SELECT b.id,b.mobile_environment_id environment_id,me.name environment_name,
|
|
3485
|
+
me.slug environment_slug,me.ota_channel,b.runtime_version,b.native_fingerprint,b.app_version,
|
|
3486
|
+
b.version_code,b.build_number,b.build_url,b.source_sha256,b.built_at
|
|
3487
|
+
FROM mobile_native_builds b JOIN mobile_environments me ON me.id=b.mobile_environment_id
|
|
3488
|
+
WHERE b.app_id=$1 ORDER BY b.built_at DESC LIMIT 200`, [appRow.id])).rows;
|
|
3489
|
+
res.json(rows);
|
|
3455
3490
|
});
|
|
3456
3491
|
app.get('/mobile/apps/:appId/releases', auth, async (req, res) => {
|
|
3457
3492
|
const appRow = await mobileAppForUser(routeParam(req.params.appId), req.auth);
|
|
@@ -3478,23 +3513,31 @@ app.post('/mobile/apps/:appId/releases', auth, async (req, res) => {
|
|
|
3478
3513
|
res.status(400).json({ error: 'This mobile environment is not registered for the app. Run mobile prebuild first.' });
|
|
3479
3514
|
return;
|
|
3480
3515
|
}
|
|
3481
|
-
const
|
|
3482
|
-
|
|
3483
|
-
|
|
3516
|
+
const buildId = ensureUuid(String(req.body?.nativeBuildId || ''), 'Verified native build ID');
|
|
3517
|
+
const baseline = (await pool.query(`SELECT * FROM mobile_native_builds
|
|
3518
|
+
WHERE id=$1 AND app_id=$2 AND mobile_environment_id=$3`, [buildId, appRow.id, environmentId])).rows[0];
|
|
3519
|
+
if (!baseline) {
|
|
3520
|
+
res.status(409).json({ error: 'Selected successful native build does not exist for this app/environment.' });
|
|
3484
3521
|
return;
|
|
3485
3522
|
}
|
|
3486
|
-
const
|
|
3487
|
-
if (
|
|
3488
|
-
res.status(409).json({ error: '
|
|
3523
|
+
const runtimeVersion = textValue(req.body?.runtimeVersion || baseline.runtime_version, 'Runtime version', 100);
|
|
3524
|
+
if (runtimeVersion !== baseline.runtime_version) {
|
|
3525
|
+
res.status(409).json({ error: 'Selected build/runtime mismatch. Re-select the native build.' });
|
|
3489
3526
|
return;
|
|
3490
3527
|
}
|
|
3491
3528
|
const requestedFingerprint = String(req.body?.nativeFingerprint || '').trim().toLowerCase();
|
|
3492
3529
|
if (!/^[a-f0-9]{64}$/.test(requestedFingerprint)) {
|
|
3493
|
-
res.status(400).json({ error: 'nativeFingerprint
|
|
3530
|
+
res.status(400).json({ error: 'nativeFingerprint must be SHA-256 hex.' });
|
|
3494
3531
|
return;
|
|
3495
3532
|
}
|
|
3496
|
-
if (requestedFingerprint !== String(
|
|
3497
|
-
res.status(409).json({ error: 'Native
|
|
3533
|
+
if (requestedFingerprint !== String(baseline.native_fingerprint).toLowerCase()) {
|
|
3534
|
+
res.status(409).json({ error: 'Native dependency fingerprint differs from selected successful build. Build a new APK before publishing this OTA.' });
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3537
|
+
// Different native capabilities must never share a runtime (runtime is the Expo safety boundary).
|
|
3538
|
+
const conflicts = (await pool.query(`SELECT 1 FROM mobile_native_builds WHERE app_id=$1 AND mobile_environment_id=$2 AND runtime_version=$3 AND native_fingerprint<>$4 LIMIT 1`, [appRow.id, environmentId, runtimeVersion, requestedFingerprint])).rowCount;
|
|
3539
|
+
if (conflicts) {
|
|
3540
|
+
res.status(409).json({ error: 'Different native fingerprints share this runtime. Publishing is blocked; create a distinct runtime.' });
|
|
3498
3541
|
return;
|
|
3499
3542
|
}
|
|
3500
3543
|
const message = textValue(req.body?.message, 'Update message', 500);
|
|
@@ -3533,13 +3576,25 @@ app.post('/mobile/apps/:appId/releases', auth, async (req, res) => {
|
|
|
3533
3576
|
}
|
|
3534
3577
|
rollout = candidate;
|
|
3535
3578
|
}
|
|
3579
|
+
const clientRequestId = ensureUuid(String(req.body?.clientRequestId || ''), 'OTA publish request ID');
|
|
3580
|
+
const existingRelease = (await pool.query(`SELECT r.*,json_agg(json_build_object('id',u.id,'platform',u.platform)) updates
|
|
3581
|
+
FROM ota_releases r LEFT JOIN ota_updates u ON u.release_id=r.id
|
|
3582
|
+
WHERE r.app_id=$1 AND r.client_request_id=$2 GROUP BY r.id`, [appRow.id, clientRequestId])).rows[0];
|
|
3583
|
+
if (existingRelease) {
|
|
3584
|
+
if (existingRelease.runtime_version !== runtimeVersion || existingRelease.message !== message) {
|
|
3585
|
+
res.status(409).json({ error: 'OTA request ID was previously used for a different update.' });
|
|
3586
|
+
return;
|
|
3587
|
+
}
|
|
3588
|
+
res.json({ release: existingRelease, updates: existingRelease.updates, environment: binding, reused: true });
|
|
3589
|
+
return;
|
|
3590
|
+
}
|
|
3536
3591
|
// Keep partially uploaded releases invisible to clients until finalize succeeds.
|
|
3537
3592
|
const status = 'draft';
|
|
3538
3593
|
const client = await pool.connect();
|
|
3539
3594
|
try {
|
|
3540
3595
|
await client.query('BEGIN');
|
|
3541
|
-
const release = (await client.query(`INSERT INTO ota_releases(app_id,mobile_environment_id,runtime_version,message,status,audience_type,audience,rollout_percent,promoted_at,created_by)
|
|
3542
|
-
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) RETURNING *`, [appRow.id, environmentId, runtimeVersion, message, status, audienceType, req.body?.audience || {}, rollout, null, req.auth.id])).rows[0];
|
|
3596
|
+
const release = (await client.query(`INSERT INTO ota_releases(app_id,mobile_environment_id,runtime_version,message,status,audience_type,audience,rollout_percent,promoted_at,created_by,client_request_id)
|
|
3597
|
+
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11) RETURNING *`, [appRow.id, environmentId, runtimeVersion, message, status, audienceType, req.body?.audience || {}, rollout, null, req.auth.id, clientRequestId])).rows[0];
|
|
3543
3598
|
const updates = [];
|
|
3544
3599
|
for (const platform of platforms) {
|
|
3545
3600
|
updates.push((await client.query('INSERT INTO ota_updates(release_id,platform) VALUES($1,$2) RETURNING id,platform,created_at', [release.id, platform])).rows[0]);
|
|
@@ -3751,7 +3806,7 @@ app.get('/ota/v1/manifest/:updatePath', async (req, res) => {
|
|
|
3751
3806
|
res.status(204).end();
|
|
3752
3807
|
return;
|
|
3753
3808
|
}
|
|
3754
|
-
const binding = (await pool.query(
|
|
3809
|
+
const binding = (await pool.query(`SELECT 1 FROM mobile_native_builds b JOIN mobile_app_environments mae ON mae.app_id=b.app_id AND mae.mobile_environment_id=b.mobile_environment_id AND mae.enabled=true WHERE b.app_id=$1 AND b.mobile_environment_id=$2 AND b.runtime_version=$3 LIMIT 1`, [appRow.id, env.id, runtimeVersion])).rowCount;
|
|
3755
3810
|
if (!binding) {
|
|
3756
3811
|
res.status(204).end();
|
|
3757
3812
|
return;
|
package/cloud-api/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
-- v2.8.0: a successful native binary is immutable history, independent of the
|
|
2
|
+
-- version currently being prepared by prebuild.
|
|
3
|
+
CREATE TABLE IF NOT EXISTS mobile_native_builds (
|
|
4
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
5
|
+
app_id uuid NOT NULL REFERENCES mobile_apps(id) ON DELETE CASCADE,
|
|
6
|
+
mobile_environment_id uuid NOT NULL REFERENCES mobile_environments(id) ON DELETE CASCADE,
|
|
7
|
+
runtime_version text NOT NULL,
|
|
8
|
+
native_fingerprint char(64) NOT NULL CHECK (native_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
9
|
+
app_version text NOT NULL,
|
|
10
|
+
version_code bigint,
|
|
11
|
+
build_number integer,
|
|
12
|
+
build_url text,
|
|
13
|
+
source_sha256 text,
|
|
14
|
+
built_at timestamptz NOT NULL DEFAULT now(),
|
|
15
|
+
recorded_by uuid REFERENCES users(id) ON DELETE SET NULL
|
|
16
|
+
);
|
|
17
|
+
CREATE INDEX IF NOT EXISTS mobile_native_builds_by_runtime ON mobile_native_builds(app_id,mobile_environment_id,runtime_version,built_at DESC);
|
|
18
|
+
CREATE UNIQUE INDEX IF NOT EXISTS mobile_native_builds_jenkins_id ON mobile_native_builds(app_id,mobile_environment_id,build_number) WHERE build_number IS NOT NULL;
|
|
19
|
+
|
|
20
|
+
-- Recover verified native-build records from the existing *successful-build*
|
|
21
|
+
-- audit trail, including runtimes that old prebuilds already cleared.
|
|
22
|
+
INSERT INTO mobile_native_builds(app_id,mobile_environment_id,runtime_version,native_fingerprint,app_version,version_code,build_number,source_sha256,built_at,recorded_by)
|
|
23
|
+
SELECT DISTINCT ON (ma.id,me.id,(al.metadata->>'buildNumber'))
|
|
24
|
+
ma.id, me.id, al.metadata->>'runtimeVersion', lower(al.metadata->>'nativeFingerprint'),
|
|
25
|
+
COALESCE(NULLIF(al.metadata->>'appVersion',''),al.metadata->>'runtimeVersion'),
|
|
26
|
+
CASE WHEN (al.metadata->>'versionCode') ~ '^[0-9]+$' THEN (al.metadata->>'versionCode')::bigint ELSE NULL END,
|
|
27
|
+
(al.metadata->>'buildNumber')::integer,
|
|
28
|
+
CASE WHEN (al.metadata->>'sourceSha256') ~ '^[0-9a-fA-F]{64}$' THEN lower(al.metadata->>'sourceSha256') ELSE NULL END,
|
|
29
|
+
al.created_at,al.actor_id
|
|
30
|
+
FROM audit_logs al JOIN mobile_apps ma ON ma.id::text=al.resource_id
|
|
31
|
+
JOIN mobile_environments me ON me.id::text=(al.metadata->>'environmentId')
|
|
32
|
+
WHERE al.action='mobile.native-build.record'
|
|
33
|
+
AND (al.metadata->>'nativeFingerprint') ~ '^[0-9a-fA-F]{64}$'
|
|
34
|
+
AND (al.metadata->>'runtimeVersion') IS NOT NULL
|
|
35
|
+
AND (al.metadata->>'buildNumber') ~ '^[0-9]+$'
|
|
36
|
+
ORDER BY ma.id,me.id,(al.metadata->>'buildNumber'),al.created_at DESC
|
|
37
|
+
ON CONFLICT DO NOTHING;
|
|
38
|
+
|
|
39
|
+
-- Also preserve any current baseline not captured in an earlier audit.
|
|
40
|
+
INSERT INTO mobile_native_builds(app_id,mobile_environment_id,runtime_version,native_fingerprint,app_version,version_code,build_number,build_url,source_sha256,built_at)
|
|
41
|
+
SELECT app_id,mobile_environment_id,runtime_version,lower(native_fingerprint),
|
|
42
|
+
COALESCE(native_build_version,runtime_version),native_build_version_code,native_build_number,
|
|
43
|
+
native_build_url,native_build_source_sha256,COALESCE(native_built_at,now())
|
|
44
|
+
FROM mobile_app_environments
|
|
45
|
+
WHERE native_fingerprint ~ '^[0-9a-fA-F]{64}$'
|
|
46
|
+
ON CONFLICT DO NOTHING;
|
|
47
|
+
|
|
48
|
+
-- One publishing attempt has one stable key even if Node retries after a lost HTTP response.
|
|
49
|
+
ALTER TABLE ota_releases ADD COLUMN IF NOT EXISTS client_request_id uuid;
|
|
50
|
+
CREATE UNIQUE INDEX IF NOT EXISTS ota_release_request_id_unique ON ota_releases(app_id,client_request_id) WHERE client_request_id IS NOT NULL;
|
package/cloud-api/src/index.ts
CHANGED
|
@@ -2609,6 +2609,19 @@ app.get('/mobile/apps/:appId/enrollments', auth, async (req: AuthedRequest,res)
|
|
|
2609
2609
|
res.json(rows);
|
|
2610
2610
|
});
|
|
2611
2611
|
|
|
2612
|
+
app.patch('/mobile/apps/:appId/testers/:installationId', auth, async (req: AuthedRequest,res) => {
|
|
2613
|
+
const appRow=await mobileAppForUser(routeParam(req.params.appId),req.auth!,true);
|
|
2614
|
+
if(!appRow){res.status(404).json({error:'Mobile app not found or WRITE access denied.'});return;}
|
|
2615
|
+
const label=textValue(req.body?.label,'Device name',80);
|
|
2616
|
+
const installationId=routeParam(req.params.installationId);
|
|
2617
|
+
const row=(await pool.query(`UPDATE ota_tester_installations SET label=$1
|
|
2618
|
+
WHERE app_id=$2 AND installation_id=$3 AND revoked_at IS NULL RETURNING installation_id,label`,
|
|
2619
|
+
[label,appRow.id,installationId])).rows[0];
|
|
2620
|
+
if(!row){res.status(404).json({error:'Active tester device not found.'});return;}
|
|
2621
|
+
await audit(req.auth!.id,'ota.testers.rename','mobile-app',appRow.id,'Rename enrolled tester device',{installationId,label});
|
|
2622
|
+
res.json(row);
|
|
2623
|
+
});
|
|
2624
|
+
|
|
2612
2625
|
app.delete('/mobile/apps/:appId/testers/:installationId', auth, async (req: AuthedRequest,res) => {
|
|
2613
2626
|
const appRow=await mobileAppForUser(routeParam(req.params.appId),req.auth!,true);
|
|
2614
2627
|
if(!appRow){res.status(404).json({error:'Mobile app not found or WRITE access denied.'});return;}
|
|
@@ -2733,9 +2746,12 @@ app.get('/projects/:projectId/mobile', auth, async (req: AuthedRequest, res) =>
|
|
|
2733
2746
|
const appRow = (await pool.query(
|
|
2734
2747
|
`SELECT ma.id,ma.project_id,ma.app_name,ma.project_type,ma.android_package,ma.ios_bundle_identifier,ma.enrollment_scheme,ma.runtime_policy,ma.update_path,ma.signing_key_id,ma.signing_certificate,
|
|
2735
2748
|
me.id environment_id,me.name environment_name,me.slug environment_slug,me.build_type,me.jenkins_stage,me.ota_channel,mae.runtime_version,mae.enabled,
|
|
2736
|
-
|
|
2749
|
+
nb.native_fingerprint,nb.app_version AS native_build_version,nb.version_code AS native_build_version_code,nb.build_number AS native_build_number,nb.build_url AS native_build_url,nb.source_sha256 AS native_build_source_sha256,nb.built_at AS native_built_at
|
|
2737
2750
|
FROM mobile_apps ma
|
|
2738
2751
|
LEFT JOIN mobile_app_environments mae ON mae.app_id=ma.id
|
|
2752
|
+
LEFT JOIN LATERAL (SELECT b.* FROM mobile_native_builds b
|
|
2753
|
+
WHERE b.app_id=mae.app_id AND b.mobile_environment_id=mae.mobile_environment_id AND b.runtime_version=mae.runtime_version
|
|
2754
|
+
ORDER BY b.built_at DESC LIMIT 1) nb ON true
|
|
2739
2755
|
LEFT JOIN mobile_environments me ON me.id=mae.mobile_environment_id
|
|
2740
2756
|
WHERE ma.project_id=$1 ORDER BY me.name`,[projectId]
|
|
2741
2757
|
)).rows;
|
|
@@ -2779,13 +2795,8 @@ app.post('/projects/:projectId/mobile/register', auth, async (req: AuthedRequest
|
|
|
2779
2795
|
await pool.query(
|
|
2780
2796
|
`INSERT INTO mobile_app_environments(app_id,mobile_environment_id,runtime_version) VALUES($1,$2,$3)
|
|
2781
2797
|
ON CONFLICT(app_id,mobile_environment_id) DO UPDATE SET
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
native_build_version_code=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_build_version_code END,
|
|
2785
|
-
native_build_number=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_build_number END,
|
|
2786
|
-
native_build_url=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_build_url END,
|
|
2787
|
-
native_build_source_sha256=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_build_source_sha256 END,
|
|
2788
|
-
native_built_at=CASE WHEN mobile_app_environments.runtime_version IS DISTINCT FROM excluded.runtime_version THEN NULL ELSE mobile_app_environments.native_built_at END,
|
|
2798
|
+
-- Keep the last successful native baseline as a historical pointer.
|
|
2799
|
+
-- Prebuild NEVER clears a successful binary's fingerprint.
|
|
2789
2800
|
runtime_version=excluded.runtime_version,enabled=true,updated_at=now()`,
|
|
2790
2801
|
[appRow.id,environmentId,runtimeVersion]
|
|
2791
2802
|
);
|
|
@@ -2812,13 +2823,31 @@ app.post('/mobile/apps/:appId/environments/:environmentId/native-build', auth, a
|
|
|
2812
2823
|
const buildUrl=req.body?.buildUrl?String(req.body.buildUrl).trim().slice(0,2000):null;
|
|
2813
2824
|
const sourceSha=String(req.body?.sourceSha256||'').trim().toLowerCase();
|
|
2814
2825
|
if(sourceSha&&!/^[a-f0-9]{64}$/.test(sourceSha)){res.status(400).json({error:'sourceSha256 must be a 64-character SHA-256 hex value.'});return;}
|
|
2826
|
+
// Persist every successful build. A future prebuild cannot invalidate it.
|
|
2827
|
+
const savedBuild=(await pool.query(`INSERT INTO mobile_native_builds
|
|
2828
|
+
(app_id,mobile_environment_id,runtime_version,native_fingerprint,app_version,version_code,build_number,build_url,source_sha256,built_at,recorded_by)
|
|
2829
|
+
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,now(),$10)
|
|
2830
|
+
ON CONFLICT (app_id,mobile_environment_id,build_number) WHERE build_number IS NOT NULL
|
|
2831
|
+
DO UPDATE SET build_url=EXCLUDED.build_url
|
|
2832
|
+
RETURNING id`,[appRow.id,environmentId,runtimeVersion,nativeFingerprint,appVersion,versionCode,buildNumber,buildUrl,sourceSha||null,req.auth!.id])).rows[0];
|
|
2815
2833
|
const row=(await pool.query(
|
|
2816
2834
|
`UPDATE mobile_app_environments SET native_fingerprint=$1,native_build_version=$2,native_build_version_code=$3,native_build_number=$4,native_build_url=$5,native_build_source_sha256=$6,native_built_at=now(),updated_at=now()
|
|
2817
2835
|
WHERE app_id=$7 AND mobile_environment_id=$8 RETURNING runtime_version,native_fingerprint,native_build_version,native_build_version_code,native_build_number,native_build_url,native_build_source_sha256,native_built_at`,
|
|
2818
2836
|
[nativeFingerprint,appVersion,versionCode,buildNumber,buildUrl,sourceSha||null,appRow.id,environmentId]
|
|
2819
2837
|
)).rows[0];
|
|
2820
2838
|
await audit(req.auth!.id,'mobile.native-build.record','mobile-app',appRow.id,reason,{environmentId,runtimeVersion,nativeFingerprint,appVersion,versionCode,buildNumber,sourceSha256:sourceSha||null});
|
|
2821
|
-
res.json({runtimeVersion:row.runtime_version,nativeFingerprint:row.native_fingerprint,nativeBuildVersion:row.native_build_version,nativeBuildVersionCode:row.native_build_version_code===null?null:Number(row.native_build_version_code),nativeBuildNumber:row.native_build_number,nativeBuildUrl:row.native_build_url,nativeBuildSourceSha256:row.native_build_source_sha256,nativeBuiltAt:row.native_built_at});
|
|
2839
|
+
res.json({nativeBuildId:savedBuild.id,runtimeVersion:row.runtime_version,nativeFingerprint:row.native_fingerprint,nativeBuildVersion:row.native_build_version,nativeBuildVersionCode:row.native_build_version_code===null?null:Number(row.native_build_version_code),nativeBuildNumber:row.native_build_number,nativeBuildUrl:row.native_build_url,nativeBuildSourceSha256:row.native_build_source_sha256,nativeBuiltAt:row.native_built_at});
|
|
2840
|
+
});
|
|
2841
|
+
|
|
2842
|
+
app.get('/mobile/apps/:appId/native-builds', auth, async (req: AuthedRequest,res) => {
|
|
2843
|
+
const appRow=await mobileAppForUser(routeParam(req.params.appId),req.auth!);
|
|
2844
|
+
if(!appRow){res.status(404).json({error:'Mobile app not found or access denied.'});return;}
|
|
2845
|
+
const rows=(await pool.query(`SELECT b.id,b.mobile_environment_id environment_id,me.name environment_name,
|
|
2846
|
+
me.slug environment_slug,me.ota_channel,b.runtime_version,b.native_fingerprint,b.app_version,
|
|
2847
|
+
b.version_code,b.build_number,b.build_url,b.source_sha256,b.built_at
|
|
2848
|
+
FROM mobile_native_builds b JOIN mobile_environments me ON me.id=b.mobile_environment_id
|
|
2849
|
+
WHERE b.app_id=$1 ORDER BY b.built_at DESC LIMIT 200`,[appRow.id])).rows;
|
|
2850
|
+
res.json(rows);
|
|
2822
2851
|
});
|
|
2823
2852
|
|
|
2824
2853
|
app.get('/mobile/apps/:appId/releases', auth, async (req: AuthedRequest,res) => {
|
|
@@ -2840,13 +2869,20 @@ app.post('/mobile/apps/:appId/releases', auth, async (req: AuthedRequest,res) =>
|
|
|
2840
2869
|
WHERE mae.app_id=$1 AND mae.mobile_environment_id=$2 AND mae.enabled=true AND me.is_active=true`,[appRow.id,environmentId]
|
|
2841
2870
|
)).rows[0];
|
|
2842
2871
|
if(!binding){res.status(400).json({error:'This mobile environment is not registered for the app. Run mobile prebuild first.'});return;}
|
|
2843
|
-
const
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
if(!
|
|
2872
|
+
const buildId=ensureUuid(String(req.body?.nativeBuildId||''),'Verified native build ID');
|
|
2873
|
+
const baseline=(await pool.query(`SELECT * FROM mobile_native_builds
|
|
2874
|
+
WHERE id=$1 AND app_id=$2 AND mobile_environment_id=$3`,[buildId,appRow.id,environmentId])).rows[0];
|
|
2875
|
+
if(!baseline){res.status(409).json({error:'Selected successful native build does not exist for this app/environment.'});return;}
|
|
2876
|
+
const runtimeVersion=textValue(req.body?.runtimeVersion||baseline.runtime_version,'Runtime version',100);
|
|
2877
|
+
if(runtimeVersion!==baseline.runtime_version){res.status(409).json({error:'Selected build/runtime mismatch. Re-select the native build.'});return;}
|
|
2847
2878
|
const requestedFingerprint=String(req.body?.nativeFingerprint||'').trim().toLowerCase();
|
|
2848
|
-
if(!/^[a-f0-9]{64}$/.test(requestedFingerprint)){res.status(400).json({error:'nativeFingerprint
|
|
2849
|
-
if(requestedFingerprint!==String(
|
|
2879
|
+
if(!/^[a-f0-9]{64}$/.test(requestedFingerprint)){res.status(400).json({error:'nativeFingerprint must be SHA-256 hex.'});return;}
|
|
2880
|
+
if(requestedFingerprint!==String(baseline.native_fingerprint).toLowerCase()){
|
|
2881
|
+
res.status(409).json({error:'Native dependency fingerprint differs from selected successful build. Build a new APK before publishing this OTA.'});return;
|
|
2882
|
+
}
|
|
2883
|
+
// Different native capabilities must never share a runtime (runtime is the Expo safety boundary).
|
|
2884
|
+
const conflicts=(await pool.query(`SELECT 1 FROM mobile_native_builds WHERE app_id=$1 AND mobile_environment_id=$2 AND runtime_version=$3 AND native_fingerprint<>$4 LIMIT 1`,[appRow.id,environmentId,runtimeVersion,requestedFingerprint])).rowCount;
|
|
2885
|
+
if(conflicts){res.status(409).json({error:'Different native fingerprints share this runtime. Publishing is blocked; create a distinct runtime.'});return;}
|
|
2850
2886
|
const message=textValue(req.body?.message,'Update message',500);
|
|
2851
2887
|
const audienceType=String(req.body?.audienceType||'test');
|
|
2852
2888
|
if(!['test','all','percentage'].includes(audienceType)){res.status(400).json({error:'audienceType must be test, all, or percentage.'});return;}
|
|
@@ -2868,15 +2904,23 @@ app.post('/mobile/apps/:appId/releases', auth, async (req: AuthedRequest,res) =>
|
|
|
2868
2904
|
if(!Number.isInteger(candidate)||candidate<1||candidate>100){res.status(400).json({error:'rolloutPercent must be 1-100.'});return;}
|
|
2869
2905
|
rollout=candidate;
|
|
2870
2906
|
}
|
|
2907
|
+
const clientRequestId=ensureUuid(String(req.body?.clientRequestId||''),'OTA publish request ID');
|
|
2908
|
+
const existingRelease=(await pool.query(`SELECT r.*,json_agg(json_build_object('id',u.id,'platform',u.platform)) updates
|
|
2909
|
+
FROM ota_releases r LEFT JOIN ota_updates u ON u.release_id=r.id
|
|
2910
|
+
WHERE r.app_id=$1 AND r.client_request_id=$2 GROUP BY r.id`,[appRow.id,clientRequestId])).rows[0];
|
|
2911
|
+
if(existingRelease){
|
|
2912
|
+
if(existingRelease.runtime_version!==runtimeVersion || existingRelease.message!==message){res.status(409).json({error:'OTA request ID was previously used for a different update.'});return;}
|
|
2913
|
+
res.json({release:existingRelease,updates:existingRelease.updates,environment:binding,reused:true});return;
|
|
2914
|
+
}
|
|
2871
2915
|
// Keep partially uploaded releases invisible to clients until finalize succeeds.
|
|
2872
2916
|
const status='draft';
|
|
2873
2917
|
const client=await pool.connect();
|
|
2874
2918
|
try{
|
|
2875
2919
|
await client.query('BEGIN');
|
|
2876
2920
|
const release=(await client.query(
|
|
2877
|
-
`INSERT INTO ota_releases(app_id,mobile_environment_id,runtime_version,message,status,audience_type,audience,rollout_percent,promoted_at,created_by)
|
|
2878
|
-
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) RETURNING *`,
|
|
2879
|
-
[appRow.id,environmentId,runtimeVersion,message,status,audienceType,req.body?.audience||{},rollout,null,req.auth!.id]
|
|
2921
|
+
`INSERT INTO ota_releases(app_id,mobile_environment_id,runtime_version,message,status,audience_type,audience,rollout_percent,promoted_at,created_by,client_request_id)
|
|
2922
|
+
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11) RETURNING *`,
|
|
2923
|
+
[appRow.id,environmentId,runtimeVersion,message,status,audienceType,req.body?.audience||{},rollout,null,req.auth!.id,clientRequestId]
|
|
2880
2924
|
)).rows[0];
|
|
2881
2925
|
const updates:any[]=[];
|
|
2882
2926
|
for(const platform of platforms){updates.push((await client.query('INSERT INTO ota_updates(release_id,platform) VALUES($1,$2) RETURNING id,platform,created_at',[release.id,platform])).rows[0]);}
|
|
@@ -3022,7 +3066,7 @@ app.get('/ota/v1/manifest/:updatePath', async (req,res) => {
|
|
|
3022
3066
|
res.setHeader('expo-protocol-version','1');res.setHeader('expo-sfv-version','0');res.setHeader('cache-control','private, max-age=0');
|
|
3023
3067
|
const env=(await pool.query('SELECT * FROM mobile_environments WHERE is_active=true AND (lower(ota_channel)=lower($1) OR lower(slug)=lower($1))',[channel])).rows[0];
|
|
3024
3068
|
if(!env){res.status(204).end();return;}
|
|
3025
|
-
const binding=(await pool.query(
|
|
3069
|
+
const binding=(await pool.query(`SELECT 1 FROM mobile_native_builds b JOIN mobile_app_environments mae ON mae.app_id=b.app_id AND mae.mobile_environment_id=b.mobile_environment_id AND mae.enabled=true WHERE b.app_id=$1 AND b.mobile_environment_id=$2 AND b.runtime_version=$3 LIMIT 1`,[appRow.id,env.id,runtimeVersion])).rowCount;
|
|
3026
3070
|
if(!binding){res.status(204).end();return;}
|
|
3027
3071
|
const identity=requestIdentity(req);
|
|
3028
3072
|
if(identity.installationId){
|
package/dist/cli/help-content.js
CHANGED
|
@@ -9,7 +9,7 @@ const heading = (value) => chalk_1.default.bold(value);
|
|
|
9
9
|
const command = (value) => chalk_1.default.cyan(value);
|
|
10
10
|
const note = (value) => chalk_1.default.gray(value);
|
|
11
11
|
const fullCommandReference = () => `
|
|
12
|
-
${heading('IndraQ CLI v2.
|
|
12
|
+
${heading('IndraQ CLI v2.8.1 — web + mobile deployment and self-hosted OTA')}
|
|
13
13
|
|
|
14
14
|
${heading('Start here')}
|
|
15
15
|
${command('indraq setup')} Guided first-time project onboarding
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-api.service.d.ts","sourceRoot":"","sources":["../../../../src/modules/cloud/services/cloud-api.service.ts"],"names":[],"mappings":"AAEA,qBAAa,aAAc,SAAQ,KAAK;aACO,MAAM,EAAE,MAAM;gBAA/C,OAAO,EAAE,MAAM,EAAkB,MAAM,EAAE,MAAM;CAC5D;
|
|
1
|
+
{"version":3,"file":"cloud-api.service.d.ts","sourceRoot":"","sources":["../../../../src/modules/cloud/services/cloud-api.service.ts"],"names":[],"mappings":"AAEA,qBAAa,aAAc,SAAQ,KAAK;aACO,MAAM,EAAE,MAAM;gBAA/C,OAAO,EAAE,MAAM,EAAkB,MAAM,EAAE,MAAM;CAC5D;AAoBD,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAoB;YAEpB,SAAS;IAuCvB,OAAO,CAAC,WAAW;IAKnB,6EAA6E;YAC/D,wBAAwB;YASxB,cAAc;IAYtB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,CAAC;IAY5D,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAKpE,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IA+B3F,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,kBAAkB,EAAE,OAAO,CAAA;KAAE,CAAC;IAMvI,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;CAejC"}
|
|
@@ -10,6 +10,26 @@ class CloudApiError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.CloudApiError = CloudApiError;
|
|
13
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
14
|
+
const networkDetail = (error) => {
|
|
15
|
+
const e = error;
|
|
16
|
+
return [e?.message || String(error), e?.cause?.code || e?.code, e?.cause?.message].filter(Boolean).join(' | ').slice(0, 350);
|
|
17
|
+
};
|
|
18
|
+
// POST retries are safe only when Cloud supports an immutable clientRequestId.
|
|
19
|
+
const retryableJsonRequest = (path, init) => {
|
|
20
|
+
const method = String(init.method || 'GET').toUpperCase();
|
|
21
|
+
if (method === 'GET' || method === 'HEAD' || method === 'PUT' || method === 'DELETE')
|
|
22
|
+
return true;
|
|
23
|
+
if (method === 'POST' && /^\/mobile\/apps\/[^/]+\/releases$/.test(path)) {
|
|
24
|
+
try {
|
|
25
|
+
return /^[0-9a-f-]{36}$/i.test(String(JSON.parse(String(init.body || '{}')).clientRequestId || ''));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
13
33
|
class CloudApiService {
|
|
14
34
|
config = (0, cloud_config_1.getCloudConfig)();
|
|
15
35
|
async fetchJson(path, init = {}, token = this.config.token) {
|
|
@@ -20,12 +40,25 @@ class CloudApiService {
|
|
|
20
40
|
if (token)
|
|
21
41
|
headers.authorization = `Bearer ${token}`;
|
|
22
42
|
let response;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
43
|
+
const retry = retryableJsonRequest(path, init);
|
|
44
|
+
for (let attempt = 0; attempt < (retry ? 3 : 1); attempt++) {
|
|
45
|
+
try {
|
|
46
|
+
// Explicit close prevents a pooled connection held idle during Metro export
|
|
47
|
+
// from being blindly reused on Windows/OpenResty deployments.
|
|
48
|
+
response = await fetch(`${this.config.apiUrl.replace(/\/$/, '')}${path}`, {
|
|
49
|
+
...init, headers: { ...headers, connection: 'close' },
|
|
50
|
+
signal: init.signal || AbortSignal.timeout(30000)
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (attempt === (retry ? 2 : 0))
|
|
56
|
+
throw new Error(`Unable to reach IndraQ Cloud at ${this.config.apiUrl}: ${networkDetail(error)}`);
|
|
57
|
+
await wait(350 * (attempt + 1));
|
|
58
|
+
}
|
|
28
59
|
}
|
|
60
|
+
if (!response)
|
|
61
|
+
throw new Error('IndraQ Cloud connection failed.');
|
|
29
62
|
const text = await response.text();
|
|
30
63
|
let body = {};
|
|
31
64
|
if (text) {
|
|
@@ -96,17 +129,22 @@ class CloudApiService {
|
|
|
96
129
|
await this.upgradePersistentSession();
|
|
97
130
|
const send = async () => {
|
|
98
131
|
let response;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
132
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
133
|
+
try {
|
|
134
|
+
response = await fetch(`${this.config.apiUrl.replace(/\/$/, '')}${path}`, {
|
|
135
|
+
method: 'PUT', headers: { ...headers, ...(attempt ? { connection: 'close' } : {}), ...(this.config.token ? { authorization: `Bearer ${this.config.token}` } : {}) },
|
|
136
|
+
body: Uint8Array.from(body), signal: AbortSignal.timeout(180000)
|
|
137
|
+
});
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
if (attempt === 2)
|
|
142
|
+
throw new Error(`Unable to reach IndraQ Cloud at ${this.config.apiUrl}: ${networkDetail(error)}`);
|
|
143
|
+
await wait(500 * (attempt + 1));
|
|
144
|
+
}
|
|
109
145
|
}
|
|
146
|
+
if (!response)
|
|
147
|
+
throw new Error('IndraQ Cloud upload connection failed.');
|
|
110
148
|
const text = await response.text();
|
|
111
149
|
let parsed = {};
|
|
112
150
|
if (text) {
|