native-update 3.1.0 → 3.1.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/cli/AGENTS.md +9 -0
- package/cli/CLAUDE.md +9 -0
- package/dist/esm/app-update/app-update-checker.d.ts +19 -0
- package/dist/esm/app-update/app-update-checker.js +19 -0
- package/dist/esm/background-update/background-scheduler.d.ts +21 -0
- package/dist/esm/background-update/background-scheduler.js +47 -24
- package/dist/esm/core/update-check.d.ts +89 -0
- package/dist/esm/core/update-check.js +86 -0
- package/dist/esm/definitions.d.ts +11 -1
- package/dist/esm/live-update/version-manager.js +43 -27
- package/dist/esm/plugin.js +14 -20
- package/dist/esm/types/rollout.d.ts +9 -3
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/AGENTS.md +9 -0
- package/docs/CHANGELOG.md +16 -0
- package/docs/CLAUDE.md +9 -0
- package/docs/DEPLOY_NOTES.md +117 -0
- package/docs/MANUAL-TASKS.md +18 -5
- package/docs/api/background-update-api.md +14 -1
- package/docs/features/e2e-full-verification/00-overview.md +99 -0
- package/docs/features/e2e-full-verification/00-tracker.json +284 -0
- package/docs/features/e2e-full-verification/phase01-backend-schema-fixes.md +183 -0
- package/docs/features/e2e-full-verification/phase02-test-auth.md +176 -0
- package/docs/features/e2e-full-verification/phase03-api-test-coverage.md +63 -0
- package/docs/features/e2e-full-verification/phase04-frontend-package-contract-audit.md +73 -0
- package/docs/features/e2e-full-verification/phase05-browser-e2e-matrix.md +69 -0
- package/docs/features/e2e-full-verification/phase06-deploy-prod-smoke.md +51 -0
- package/docs/features/e2e-full-verification/results/phase01-drift-report.md +50 -0
- package/docs/features/e2e-full-verification/results/phase03-coverage-matrix.md +215 -0
- package/docs/features/e2e-full-verification/results/phase04-frontend-contract.md +139 -0
- package/docs/features/e2e-full-verification/results/phase05-e2e-results.md +99 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-01-dashboard.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-02-signup.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-03-settings-persisted.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-04a-app-created.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-04b-duplicate-bundle-422.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-05-plan-limit-403.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-08a-upload-graceful-fail.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-08b-builds-list.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-10-rollout-25pct.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-11-analytics.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-12-drive-disconnected.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-13-pricing.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-14-isolation-403.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-15a-admin-overview.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-15b-regular-user-admin-redirect.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-16a-delete-dialog.png +0 -0
- package/docs/features/e2e-full-verification/results/phase05-evidence/e2e-17-mobile-375.png +0 -0
- package/docs/features/e2e-full-verification/results/route-list.json +1 -0
- package/docs/features/queues-and-emails/00-overview.md +41 -0
- package/docs/features/queues-and-emails/00-tracker.json +99 -0
- package/docs/features/queues-and-emails/phase01-foundation.md +15 -0
- package/docs/features/queues-and-emails/phase02-queued-jobs.md +19 -0
- package/docs/features/queues-and-emails/phase03-transactional-emails.md +16 -0
- package/docs/features/queues-and-emails/phase04-quota-ops.md +17 -0
- package/docs/features/queues-and-emails/phase05-async-build-processing-DECISION.md +16 -0
- package/docs/features/queues-and-emails/phase06-verify-deploy.md +17 -0
- package/docs/server-requirements.md +41 -11
- package/package.json +1 -1
package/cli/AGENTS.md
CHANGED
|
@@ -41,3 +41,12 @@ Full rule + private/public protocol: `~/.claude/rules/project-config.md`.
|
|
|
41
41
|
Gitignore Last Verified: 2026-06-24
|
|
42
42
|
|
|
43
43
|
**Last Updated**: 2026-04-25
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Sub-agents & Skills — Main-Context-First (IRON-SOLID)
|
|
47
|
+
Default/built-in sub-agents (`general-purpose`, `Explore`, `Plan`, `claude`, `fork`, …) do NOT have
|
|
48
|
+
access to `/skills`, so delegating to them silently SKIPS the skills RULE #0 requires. Do all
|
|
49
|
+
skill-relevant work in the **MAIN context**; use a sub-agent ONLY when a **custom** agent exists in
|
|
50
|
+
`.claude/agents/` for that job; a default `Explore`/`Plan` agent is allowed ONLY for read-only,
|
|
51
|
+
no-skill search/exploration. When a relevant skill is missing, **install/enable it** rather than
|
|
52
|
+
proceeding skill-less. (Owner directive 2026-07-11; full text in `~/.claude/CLAUDE.md`.)
|
package/cli/CLAUDE.md
CHANGED
|
@@ -63,3 +63,12 @@ Full rule + private/public protocol: `~/.claude/rules/project-config.md`.
|
|
|
63
63
|
Gitignore Last Verified: 2026-06-24
|
|
64
64
|
|
|
65
65
|
**Last Updated**: 2026-04-25
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Sub-agents & Skills — Main-Context-First (IRON-SOLID)
|
|
69
|
+
Default/built-in sub-agents (`general-purpose`, `Explore`, `Plan`, `claude`, `fork`, …) do NOT have
|
|
70
|
+
access to `/skills`, so delegating to them silently SKIPS the skills RULE #0 requires. Do all
|
|
71
|
+
skill-relevant work in the **MAIN context**; use a sub-agent ONLY when a **custom** agent exists in
|
|
72
|
+
`.claude/agents/` for that job; a default `Explore`/`Plan` agent is allowed ONLY for read-only,
|
|
73
|
+
no-skill search/exploration. When a relevant skill is missing, **install/enable it** rather than
|
|
74
|
+
proceeding skill-less. (Owner directive 2026-07-11; full text in `~/.claude/CLAUDE.md`.)
|
|
@@ -13,6 +13,25 @@ export declare class AppUpdateChecker {
|
|
|
13
13
|
private cachedAppInfo;
|
|
14
14
|
private readonly CACHE_DURATION;
|
|
15
15
|
constructor(config: PluginConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Query an OPTIONAL custom app-version endpoint for a newer native
|
|
18
|
+
* app-store binary. This is a self-hoster extension point, independent
|
|
19
|
+
* of the Native Update (Laravel) OTA backend — configure it via
|
|
20
|
+
* `updateUrl`. When `updateUrl` is unset (the default) this is a no-op.
|
|
21
|
+
*
|
|
22
|
+
* Contract the custom server must implement:
|
|
23
|
+
* ```
|
|
24
|
+
* GET {updateUrl}/app-version?platform={ios|android|web}¤t={ver}[&channel={ch}]
|
|
25
|
+
* X-App-Version: <installed version> X-App-Platform: <platform>
|
|
26
|
+
* → 200 {
|
|
27
|
+
* "version": "2.1.0", // latest store version
|
|
28
|
+
* "priority": 3, // optional update priority
|
|
29
|
+
* "releaseNotes": "…", // optional
|
|
30
|
+
* "size": 12345, // optional bytes
|
|
31
|
+
* "downloadUrl": "https://…" // optional store/deeplink URL
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
16
35
|
checkServerVersion(_?: AppUpdateOptions): Promise<Partial<AppUpdateInfo>>;
|
|
17
36
|
compareVersions(version1: string, version2: string): number;
|
|
18
37
|
isUpdateRequired(currentVersion: string, availableVersion: string, minimumVersion?: string): boolean;
|
|
@@ -6,6 +6,25 @@ export class AppUpdateChecker {
|
|
|
6
6
|
this.config = config;
|
|
7
7
|
this.logger = new Logger('AppUpdateChecker');
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Query an OPTIONAL custom app-version endpoint for a newer native
|
|
11
|
+
* app-store binary. This is a self-hoster extension point, independent
|
|
12
|
+
* of the Native Update (Laravel) OTA backend — configure it via
|
|
13
|
+
* `updateUrl`. When `updateUrl` is unset (the default) this is a no-op.
|
|
14
|
+
*
|
|
15
|
+
* Contract the custom server must implement:
|
|
16
|
+
* ```
|
|
17
|
+
* GET {updateUrl}/app-version?platform={ios|android|web}¤t={ver}[&channel={ch}]
|
|
18
|
+
* X-App-Version: <installed version> X-App-Platform: <platform>
|
|
19
|
+
* → 200 {
|
|
20
|
+
* "version": "2.1.0", // latest store version
|
|
21
|
+
* "priority": 3, // optional update priority
|
|
22
|
+
* "releaseNotes": "…", // optional
|
|
23
|
+
* "size": 12345, // optional bytes
|
|
24
|
+
* "downloadUrl": "https://…" // optional store/deeplink URL
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
9
28
|
async checkServerVersion(_) {
|
|
10
29
|
if (!this.config.updateUrl) {
|
|
11
30
|
return {};
|
|
@@ -22,6 +22,27 @@ export declare class BackgroundScheduler {
|
|
|
22
22
|
getStatus(): BackgroundUpdateStatus;
|
|
23
23
|
performCheck(): Promise<BackgroundCheckResult>;
|
|
24
24
|
private checkForUpdates;
|
|
25
|
+
/**
|
|
26
|
+
* Check whether a newer NATIVE app-store binary is available.
|
|
27
|
+
*
|
|
28
|
+
* Primary path: the platform `AppUpdateManager` (Play Core / App Store).
|
|
29
|
+
*
|
|
30
|
+
* Fallback path: a GET to `{serverUrl}/app-version`. This is a
|
|
31
|
+
* deliberate **custom-backend extension point**, NOT part of the Native
|
|
32
|
+
* Update (Laravel) backend — that backend ships OTA bundles, it has no
|
|
33
|
+
* concept of the store binary version. A self-hoster who wants
|
|
34
|
+
* server-driven native-update prompts implements this endpoint:
|
|
35
|
+
*
|
|
36
|
+
* ```
|
|
37
|
+
* GET {serverUrl}/app-version
|
|
38
|
+
* X-Current-Version: <installed app version>
|
|
39
|
+
* X-Platform: ios | android | web
|
|
40
|
+
* → 200 { "version": "2.1.0", "priority": 3 } // or { "latestVersion": … }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* If the endpoint is absent the fallback just fails closed
|
|
44
|
+
* (updateAvailable=false). See `docs/api/background-update-api.md`.
|
|
45
|
+
*/
|
|
25
46
|
private checkAppUpdate;
|
|
26
47
|
private checkLiveUpdate;
|
|
27
48
|
private sendNotification;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BackgroundUpdateType, UpdateErrorCode } from '../definitions';
|
|
2
2
|
import { Logger } from '../core/logger';
|
|
3
3
|
import { ConfigManager } from '../core/config';
|
|
4
|
+
import { checkForUpdate } from '../core/update-check';
|
|
4
5
|
export class BackgroundScheduler {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.config = null;
|
|
@@ -97,6 +98,27 @@ export class BackgroundScheduler {
|
|
|
97
98
|
notificationSent,
|
|
98
99
|
};
|
|
99
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Check whether a newer NATIVE app-store binary is available.
|
|
103
|
+
*
|
|
104
|
+
* Primary path: the platform `AppUpdateManager` (Play Core / App Store).
|
|
105
|
+
*
|
|
106
|
+
* Fallback path: a GET to `{serverUrl}/app-version`. This is a
|
|
107
|
+
* deliberate **custom-backend extension point**, NOT part of the Native
|
|
108
|
+
* Update (Laravel) backend — that backend ships OTA bundles, it has no
|
|
109
|
+
* concept of the store binary version. A self-hoster who wants
|
|
110
|
+
* server-driven native-update prompts implements this endpoint:
|
|
111
|
+
*
|
|
112
|
+
* ```
|
|
113
|
+
* GET {serverUrl}/app-version
|
|
114
|
+
* X-Current-Version: <installed app version>
|
|
115
|
+
* X-Platform: ios | android | web
|
|
116
|
+
* → 200 { "version": "2.1.0", "priority": 3 } // or { "latestVersion": … }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* If the endpoint is absent the fallback just fails closed
|
|
120
|
+
* (updateAvailable=false). See `docs/api/background-update-api.md`.
|
|
121
|
+
*/
|
|
100
122
|
async checkAppUpdate() {
|
|
101
123
|
// Use AppUpdateManager if available
|
|
102
124
|
if (this.deps.appUpdateManager) {
|
|
@@ -107,7 +129,7 @@ export class BackgroundScheduler {
|
|
|
107
129
|
this.logger.error('Failed to check app update via manager', error);
|
|
108
130
|
}
|
|
109
131
|
}
|
|
110
|
-
// Fallback:
|
|
132
|
+
// Fallback: optional custom `/app-version` endpoint (see method JSDoc).
|
|
111
133
|
const serverUrl = this.configManager.get('baseUrl') || this.configManager.get('serverUrl');
|
|
112
134
|
if (serverUrl) {
|
|
113
135
|
try {
|
|
@@ -145,6 +167,7 @@ export class BackgroundScheduler {
|
|
|
145
167
|
};
|
|
146
168
|
}
|
|
147
169
|
async checkLiveUpdate() {
|
|
170
|
+
var _a;
|
|
148
171
|
// Get current bundle version
|
|
149
172
|
let currentVersion = '1.0.0';
|
|
150
173
|
if (this.deps.bundleManager) {
|
|
@@ -154,7 +177,7 @@ export class BackgroundScheduler {
|
|
|
154
177
|
currentVersion = activeBundle.version;
|
|
155
178
|
}
|
|
156
179
|
}
|
|
157
|
-
catch (
|
|
180
|
+
catch (_b) {
|
|
158
181
|
// Use default version
|
|
159
182
|
}
|
|
160
183
|
}
|
|
@@ -175,31 +198,31 @@ export class BackgroundScheduler {
|
|
|
175
198
|
this.logger.error('Failed to check live update via VersionManager', error);
|
|
176
199
|
}
|
|
177
200
|
}
|
|
178
|
-
// Fallback:
|
|
201
|
+
// Fallback: check the Native Update backend directly via the shared
|
|
202
|
+
// /v1/updates/check contract (same endpoint plugin.checkForUpdate() and
|
|
203
|
+
// VersionManager use). The old `/updates/latest` path was never served
|
|
204
|
+
// by the backend, so this fallback previously always failed silently.
|
|
179
205
|
const serverUrl = this.configManager.get('baseUrl') || this.configManager.get('serverUrl');
|
|
180
|
-
|
|
206
|
+
const apiKey = this.configManager.get('apiKey');
|
|
207
|
+
if (serverUrl && apiKey) {
|
|
181
208
|
try {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
209
|
+
const channel = this.configManager.get('channel') || 'production';
|
|
210
|
+
const data = await checkForUpdate(serverUrl, {
|
|
211
|
+
apiKey,
|
|
212
|
+
channel,
|
|
213
|
+
currentVersion,
|
|
214
|
+
deviceId: 'web-client',
|
|
215
|
+
platform: this.getPlatform(),
|
|
216
|
+
appVersion: currentVersion,
|
|
188
217
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
url: updateAvailable ? data.url : undefined,
|
|
198
|
-
notes: data.notes || data.releaseNotes,
|
|
199
|
-
size: data.size,
|
|
200
|
-
checksum: data.checksum,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
218
|
+
return {
|
|
219
|
+
available: data.available,
|
|
220
|
+
version: data.version,
|
|
221
|
+
url: data.available ? data.downloadUrl : undefined,
|
|
222
|
+
notes: (_a = data.releaseNotes) !== null && _a !== void 0 ? _a : undefined,
|
|
223
|
+
size: data.size,
|
|
224
|
+
checksum: data.checksum,
|
|
225
|
+
};
|
|
203
226
|
}
|
|
204
227
|
catch (error) {
|
|
205
228
|
this.logger.error('Failed to check live update via server', error);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the Native Update backend update-check
|
|
3
|
+
* contract.
|
|
4
|
+
*
|
|
5
|
+
* Every "does the Laravel backend have a newer bundle for me?" call in the
|
|
6
|
+
* plugin funnels through {@link checkForUpdate} so the wire shape — path,
|
|
7
|
+
* headers, query, and response fields — is defined in exactly one place.
|
|
8
|
+
* Before this helper existed, three modules each rolled their own request
|
|
9
|
+
* against paths the backend does not serve (`/check`, `/updates/latest`),
|
|
10
|
+
* so background + version-manager update checks silently never worked.
|
|
11
|
+
*
|
|
12
|
+
* ## Wire contract (implemented by `UpdateController@check` in the backend)
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* GET {baseUrl}/v1/updates/check?channel={channel}
|
|
16
|
+
* X-API-Key: nu_app_… (required; ValidateApiKey middleware → 401 without it)
|
|
17
|
+
* X-Device-ID: stable per-device hash (required; 400 without it)
|
|
18
|
+
* X-Current-Version: the currently-installed bundle version
|
|
19
|
+
* X-Platform: ios | android | web
|
|
20
|
+
* X-App-Version: native app version (optional)
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Response (200):
|
|
24
|
+
* ```jsonc
|
|
25
|
+
* // no update:
|
|
26
|
+
* { "available": false, "message": "…" }
|
|
27
|
+
* // update available:
|
|
28
|
+
* {
|
|
29
|
+
* "available": true,
|
|
30
|
+
* "version": "1.2.3",
|
|
31
|
+
* "bundleId": "…uuid…",
|
|
32
|
+
* "downloadUrl": "https://…signed…",
|
|
33
|
+
* "checksum": "…sha256…",
|
|
34
|
+
* "signature": "…|null",
|
|
35
|
+
* "size": 123456,
|
|
36
|
+
* "mandatory": false,
|
|
37
|
+
* "releaseNotes": "…|null",
|
|
38
|
+
* "minNativeVersion": "…|null",
|
|
39
|
+
* "expiresAt": "ISO-8601"
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* Custom backends must return these exact field names — see
|
|
44
|
+
* `docs/server-requirements.md`.
|
|
45
|
+
*/
|
|
46
|
+
/** Request inputs for a single backend update check. */
|
|
47
|
+
export interface UpdateCheckRequest {
|
|
48
|
+
/** API key issued by the dashboard; sent as `X-API-Key`. Required. */
|
|
49
|
+
apiKey: string;
|
|
50
|
+
/** Release channel (`production` | `staging` | `development`). */
|
|
51
|
+
channel: string;
|
|
52
|
+
/** Currently-installed bundle version; sent as `X-Current-Version`. */
|
|
53
|
+
currentVersion: string;
|
|
54
|
+
/** Stable device identifier; sent as `X-Device-ID`. Required by the backend. */
|
|
55
|
+
deviceId: string;
|
|
56
|
+
/** Device platform (`ios` | `android` | `web`); sent as `X-Platform`. */
|
|
57
|
+
platform: string;
|
|
58
|
+
/** Native app version; sent as `X-App-Version` when present. */
|
|
59
|
+
appVersion?: string;
|
|
60
|
+
/** Optional abort signal so callers can time the request out. */
|
|
61
|
+
signal?: AbortSignal;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Normalized response from `GET {baseUrl}/v1/updates/check`. Field names
|
|
65
|
+
* mirror the backend JSON verbatim (already camelCase on the wire).
|
|
66
|
+
*/
|
|
67
|
+
export interface BackendUpdateCheckResponse {
|
|
68
|
+
available: boolean;
|
|
69
|
+
version?: string;
|
|
70
|
+
bundleId?: string;
|
|
71
|
+
downloadUrl?: string;
|
|
72
|
+
checksum?: string;
|
|
73
|
+
signature?: string | null;
|
|
74
|
+
size?: number;
|
|
75
|
+
mandatory?: boolean;
|
|
76
|
+
releaseNotes?: string | null;
|
|
77
|
+
minNativeVersion?: string | null;
|
|
78
|
+
expiresAt?: string;
|
|
79
|
+
message?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Perform one update check against the Native Update backend.
|
|
83
|
+
*
|
|
84
|
+
* Returns `{ available: false }` for any non-2xx response (the backend
|
|
85
|
+
* uses 200 for "no update" and reserves 4xx for auth/validation failures,
|
|
86
|
+
* which are non-actionable for an update check). Network failures reject —
|
|
87
|
+
* callers decide whether to swallow or surface them.
|
|
88
|
+
*/
|
|
89
|
+
export declare function checkForUpdate(baseUrl: string, req: UpdateCheckRequest): Promise<BackendUpdateCheckResponse>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the Native Update backend update-check
|
|
3
|
+
* contract.
|
|
4
|
+
*
|
|
5
|
+
* Every "does the Laravel backend have a newer bundle for me?" call in the
|
|
6
|
+
* plugin funnels through {@link checkForUpdate} so the wire shape — path,
|
|
7
|
+
* headers, query, and response fields — is defined in exactly one place.
|
|
8
|
+
* Before this helper existed, three modules each rolled their own request
|
|
9
|
+
* against paths the backend does not serve (`/check`, `/updates/latest`),
|
|
10
|
+
* so background + version-manager update checks silently never worked.
|
|
11
|
+
*
|
|
12
|
+
* ## Wire contract (implemented by `UpdateController@check` in the backend)
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* GET {baseUrl}/v1/updates/check?channel={channel}
|
|
16
|
+
* X-API-Key: nu_app_… (required; ValidateApiKey middleware → 401 without it)
|
|
17
|
+
* X-Device-ID: stable per-device hash (required; 400 without it)
|
|
18
|
+
* X-Current-Version: the currently-installed bundle version
|
|
19
|
+
* X-Platform: ios | android | web
|
|
20
|
+
* X-App-Version: native app version (optional)
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Response (200):
|
|
24
|
+
* ```jsonc
|
|
25
|
+
* // no update:
|
|
26
|
+
* { "available": false, "message": "…" }
|
|
27
|
+
* // update available:
|
|
28
|
+
* {
|
|
29
|
+
* "available": true,
|
|
30
|
+
* "version": "1.2.3",
|
|
31
|
+
* "bundleId": "…uuid…",
|
|
32
|
+
* "downloadUrl": "https://…signed…",
|
|
33
|
+
* "checksum": "…sha256…",
|
|
34
|
+
* "signature": "…|null",
|
|
35
|
+
* "size": 123456,
|
|
36
|
+
* "mandatory": false,
|
|
37
|
+
* "releaseNotes": "…|null",
|
|
38
|
+
* "minNativeVersion": "…|null",
|
|
39
|
+
* "expiresAt": "ISO-8601"
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* Custom backends must return these exact field names — see
|
|
44
|
+
* `docs/server-requirements.md`.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Perform one update check against the Native Update backend.
|
|
48
|
+
*
|
|
49
|
+
* Returns `{ available: false }` for any non-2xx response (the backend
|
|
50
|
+
* uses 200 for "no update" and reserves 4xx for auth/validation failures,
|
|
51
|
+
* which are non-actionable for an update check). Network failures reject —
|
|
52
|
+
* callers decide whether to swallow or surface them.
|
|
53
|
+
*/
|
|
54
|
+
export async function checkForUpdate(baseUrl, req) {
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
const url = `${baseUrl.replace(/\/$/, '')}/v1/updates/check?channel=${encodeURIComponent(req.channel)}`;
|
|
57
|
+
const headers = {
|
|
58
|
+
'Content-Type': 'application/json',
|
|
59
|
+
'X-API-Key': req.apiKey,
|
|
60
|
+
'X-Device-ID': req.deviceId,
|
|
61
|
+
'X-Current-Version': req.currentVersion,
|
|
62
|
+
'X-Platform': req.platform,
|
|
63
|
+
};
|
|
64
|
+
if (req.appVersion) {
|
|
65
|
+
headers['X-App-Version'] = req.appVersion;
|
|
66
|
+
}
|
|
67
|
+
const response = await fetch(url, { method: 'GET', headers, signal: req.signal });
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
return { available: false };
|
|
70
|
+
}
|
|
71
|
+
const data = (await response.json());
|
|
72
|
+
return {
|
|
73
|
+
available: Boolean(data.available),
|
|
74
|
+
version: data.version,
|
|
75
|
+
bundleId: data.bundleId,
|
|
76
|
+
downloadUrl: data.downloadUrl,
|
|
77
|
+
checksum: data.checksum,
|
|
78
|
+
signature: (_a = data.signature) !== null && _a !== void 0 ? _a : undefined,
|
|
79
|
+
size: data.size,
|
|
80
|
+
mandatory: data.mandatory,
|
|
81
|
+
releaseNotes: (_b = data.releaseNotes) !== null && _b !== void 0 ? _b : undefined,
|
|
82
|
+
minNativeVersion: (_c = data.minNativeVersion) !== null && _c !== void 0 ? _c : undefined,
|
|
83
|
+
expiresAt: data.expiresAt,
|
|
84
|
+
message: data.message,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -197,6 +197,12 @@ export interface UpdateConfig {
|
|
|
197
197
|
}
|
|
198
198
|
export interface LiveUpdateConfig {
|
|
199
199
|
appId: string;
|
|
200
|
+
/**
|
|
201
|
+
* Base URL of the Native Update backend. OTA update checks are issued as
|
|
202
|
+
* `GET {serverUrl}/v1/updates/check` (API-key auth via `X-API-Key`); the
|
|
203
|
+
* self-host contract for that endpoint is in `docs/server-requirements.md`.
|
|
204
|
+
* Must be HTTPS in production (the plugin rejects non-HTTPS base URLs).
|
|
205
|
+
*/
|
|
200
206
|
serverUrl?: string;
|
|
201
207
|
channel?: string;
|
|
202
208
|
autoUpdate?: boolean;
|
|
@@ -703,7 +709,11 @@ export interface PluginInitConfig {
|
|
|
703
709
|
*/
|
|
704
710
|
enableLogging?: boolean;
|
|
705
711
|
/**
|
|
706
|
-
*
|
|
712
|
+
* Base URL of the Native Update backend for OTA update checks.
|
|
713
|
+
* The plugin appends the versioned path: `GET {serverUrl}/v1/updates/check`
|
|
714
|
+
* with `X-API-Key` / `X-Device-ID` / `X-Current-Version` / `X-Platform`
|
|
715
|
+
* headers. See `docs/server-requirements.md` for the full wire contract
|
|
716
|
+
* (and `core/update-check.ts`, the single implementation of it).
|
|
707
717
|
*/
|
|
708
718
|
serverUrl?: string;
|
|
709
719
|
/**
|
|
@@ -2,6 +2,7 @@ import { ConfigManager } from '../core/config';
|
|
|
2
2
|
import { Logger } from '../core/logger';
|
|
3
3
|
import { SecurityValidator } from '../core/security';
|
|
4
4
|
import { ValidationError, ErrorCode } from '../core/errors';
|
|
5
|
+
import { checkForUpdate } from '../core/update-check';
|
|
5
6
|
/**
|
|
6
7
|
* Manages version checking and comparison
|
|
7
8
|
*/
|
|
@@ -79,6 +80,7 @@ export class VersionManager {
|
|
|
79
80
|
* Check for latest version from server
|
|
80
81
|
*/
|
|
81
82
|
async checkForUpdates(serverUrl, channel, currentVersion, appId) {
|
|
83
|
+
var _a;
|
|
82
84
|
// Validate inputs
|
|
83
85
|
this.securityValidator.validateUrl(serverUrl);
|
|
84
86
|
this.securityValidator.validateVersion(currentVersion);
|
|
@@ -97,46 +99,60 @@ export class VersionManager {
|
|
|
97
99
|
});
|
|
98
100
|
return cached.data;
|
|
99
101
|
}
|
|
102
|
+
// The Native Update backend serves update checks at
|
|
103
|
+
// `/v1/updates/check` (API-key auth), NOT `/check`. Route through the
|
|
104
|
+
// shared helper so this path matches plugin.checkForUpdate() exactly.
|
|
105
|
+
// Without an API key the backend returns 401, so bail early with null.
|
|
106
|
+
const apiKey = this.configManager.get('apiKey');
|
|
107
|
+
if (!apiKey) {
|
|
108
|
+
this.logger.warn('VersionManager.checkForUpdates: no apiKey configured — the Native Update backend requires X-API-Key');
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
100
111
|
try {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
'X-App-Version': currentVersion,
|
|
111
|
-
'X-App-Id': appId,
|
|
112
|
-
},
|
|
112
|
+
const data = await checkForUpdate(serverUrl, {
|
|
113
|
+
apiKey,
|
|
114
|
+
channel,
|
|
115
|
+
currentVersion,
|
|
116
|
+
// JS-layer fallback identity; native background checks run through
|
|
117
|
+
// the native scheduler with the real device id + platform.
|
|
118
|
+
deviceId: 'web-client',
|
|
119
|
+
platform: 'web',
|
|
120
|
+
appVersion: currentVersion,
|
|
113
121
|
signal: AbortSignal.timeout(this.configManager.get('downloadTimeout')),
|
|
114
122
|
});
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
const latest = {
|
|
124
|
+
available: data.available,
|
|
125
|
+
version: data.version,
|
|
126
|
+
url: data.downloadUrl,
|
|
127
|
+
mandatory: data.mandatory,
|
|
128
|
+
notes: (_a = data.releaseNotes) !== null && _a !== void 0 ? _a : undefined,
|
|
129
|
+
size: data.size,
|
|
130
|
+
checksum: data.checksum,
|
|
131
|
+
};
|
|
132
|
+
// No update is a normal, non-error outcome — return it as-is.
|
|
133
|
+
if (!latest.available) {
|
|
134
|
+
return latest;
|
|
117
135
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (!data.version) {
|
|
136
|
+
// Validate the actionable fields before we cache/return them.
|
|
137
|
+
if (!latest.version) {
|
|
121
138
|
throw new ValidationError(ErrorCode.INVALID_BUNDLE_FORMAT, 'No version in server response');
|
|
122
139
|
}
|
|
123
|
-
this.securityValidator.validateVersion(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.securityValidator.validateUrl(data.bundleUrl);
|
|
140
|
+
this.securityValidator.validateVersion(latest.version);
|
|
141
|
+
if (latest.url) {
|
|
142
|
+
this.securityValidator.validateUrl(latest.url);
|
|
127
143
|
}
|
|
128
|
-
if (data.
|
|
129
|
-
this.securityValidator.validateVersion(data.
|
|
144
|
+
if (data.minNativeVersion) {
|
|
145
|
+
this.securityValidator.validateVersion(data.minNativeVersion);
|
|
130
146
|
}
|
|
131
147
|
// Cache the result
|
|
132
|
-
await this.cacheVersionInfo(cacheKey, channel,
|
|
148
|
+
await this.cacheVersionInfo(cacheKey, channel, latest);
|
|
133
149
|
this.logger.info('Version check completed', {
|
|
134
150
|
channel,
|
|
135
151
|
currentVersion,
|
|
136
|
-
latestVersion:
|
|
137
|
-
updateAvailable: this.isNewerVersion(
|
|
152
|
+
latestVersion: latest.version,
|
|
153
|
+
updateAvailable: this.isNewerVersion(latest.version, currentVersion),
|
|
138
154
|
});
|
|
139
|
-
return
|
|
155
|
+
return latest;
|
|
140
156
|
}
|
|
141
157
|
catch (error) {
|
|
142
158
|
this.logger.error('Failed to check for updates', error);
|
package/dist/esm/plugin.js
CHANGED
|
@@ -2,6 +2,7 @@ import { registerPlugin } from '@capacitor/core';
|
|
|
2
2
|
import { SyncStatus, BundleStatus, UpdateErrorCode } from './definitions';
|
|
3
3
|
import { PluginManager } from './core/plugin-manager';
|
|
4
4
|
import { NativeUpdateError, ErrorCode } from './core/errors';
|
|
5
|
+
import { checkForUpdate } from './core/update-check';
|
|
5
6
|
/**
|
|
6
7
|
* Web implementation of the Native Update Plugin
|
|
7
8
|
*/
|
|
@@ -275,6 +276,7 @@ class NativeUpdatePluginWeb {
|
|
|
275
276
|
* Check for available updates (convenience wrapper around getLatest + current version)
|
|
276
277
|
*/
|
|
277
278
|
async checkForUpdate() {
|
|
279
|
+
var _a, _b;
|
|
278
280
|
const bundleManager = this.pluginManager.getBundleManager();
|
|
279
281
|
const configManager = this.pluginManager.getConfigManager();
|
|
280
282
|
try {
|
|
@@ -297,25 +299,17 @@ class NativeUpdatePluginWeb {
|
|
|
297
299
|
}
|
|
298
300
|
const channel = configManager.get('channel') || 'production';
|
|
299
301
|
const deviceInfo = this.getDeviceInfo(currentVersion);
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
},
|
|
302
|
+
// Delegate the wire contract to the shared helper so plugin.ts,
|
|
303
|
+
// version-manager, and background-scheduler all hit the same
|
|
304
|
+
// /v1/updates/check endpoint with identical headers.
|
|
305
|
+
const data = await checkForUpdate(baseUrl, {
|
|
306
|
+
apiKey,
|
|
307
|
+
channel,
|
|
308
|
+
currentVersion,
|
|
309
|
+
deviceId: deviceInfo.deviceId,
|
|
310
|
+
platform: deviceInfo.platform,
|
|
311
|
+
appVersion: deviceInfo.appVersion,
|
|
311
312
|
});
|
|
312
|
-
if (!response.ok) {
|
|
313
|
-
return {
|
|
314
|
-
available: false,
|
|
315
|
-
currentVersion,
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
const data = await response.json();
|
|
319
313
|
if (!data.available) {
|
|
320
314
|
return {
|
|
321
315
|
available: false,
|
|
@@ -328,10 +322,10 @@ class NativeUpdatePluginWeb {
|
|
|
328
322
|
latestVersion: data.version,
|
|
329
323
|
url: data.downloadUrl,
|
|
330
324
|
mandatory: data.mandatory,
|
|
331
|
-
notes: data.releaseNotes,
|
|
325
|
+
notes: (_a = data.releaseNotes) !== null && _a !== void 0 ? _a : undefined,
|
|
332
326
|
size: data.size,
|
|
333
327
|
checksum: data.checksum,
|
|
334
|
-
signature: data.signature,
|
|
328
|
+
signature: (_b = data.signature) !== null && _b !== void 0 ? _b : undefined,
|
|
335
329
|
};
|
|
336
330
|
}
|
|
337
331
|
catch (error) {
|
|
@@ -59,9 +59,15 @@ export interface DeviceInfo {
|
|
|
59
59
|
locale: string;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
62
|
+
* Extended, delta-aware LOCAL model of an update check, used by the
|
|
63
|
+
* delta-update pipeline (`delta-processor.ts`).
|
|
64
|
+
*
|
|
65
|
+
* NOTE: this is NOT the raw wire shape. The backend `GET /v1/updates/check`
|
|
66
|
+
* returns `available` / `downloadUrl` / `releaseNotes` (see
|
|
67
|
+
* {@link BackendUpdateCheckResponse} in `core/update-check.ts`), whereas
|
|
68
|
+
* this interface uses `updateAvailable` / `bundleUrl` and adds the
|
|
69
|
+
* client-computed `delta` / `rolloutEligible` fields. Map from the wire
|
|
70
|
+
* response into this shape when driving a delta update.
|
|
65
71
|
*/
|
|
66
72
|
export interface UpdateCheckResponse {
|
|
67
73
|
updateAvailable: boolean;
|