native-update 2.0.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/Readme.md +28 -14
- package/android/manifest-additions.xml +28 -0
- package/android/src/main/AndroidManifest.xml +3 -7
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +21 -13
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +196 -29
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +21 -36
- package/cli/AGENTS.md +24 -1
- package/cli/CLAUDE.md +24 -1
- package/cli/commands/backend-create.js +56 -15
- package/cli/commands/bundle-create.js +39 -7
- package/cli/commands/monitor.js +72 -51
- package/cli/index.js +10 -24
- package/cli/package.json +11 -3
- package/dist/esm/app-review/app-review-manager.js +0 -1
- package/dist/esm/app-review/index.js +0 -1
- package/dist/esm/app-review/platform-review-handler.js +0 -1
- package/dist/esm/app-review/review-conditions-checker.js +0 -1
- package/dist/esm/app-review/review-rate-limiter.js +0 -1
- package/dist/esm/app-review/types.js +0 -1
- package/dist/esm/app-update/app-update-checker.d.ts +19 -0
- package/dist/esm/app-update/app-update-checker.js +19 -1
- package/dist/esm/app-update/app-update-installer.d.ts +1 -0
- package/dist/esm/app-update/app-update-installer.js +19 -8
- package/dist/esm/app-update/app-update-manager.js +0 -1
- package/dist/esm/app-update/app-update-notifier.js +0 -1
- package/dist/esm/app-update/index.js +0 -1
- package/dist/esm/app-update/platform-app-update.js +12 -3
- package/dist/esm/app-update/types.js +0 -1
- package/dist/esm/background-update/background-scheduler.d.ts +21 -0
- package/dist/esm/background-update/background-scheduler.js +47 -25
- package/dist/esm/background-update/index.js +0 -1
- package/dist/esm/background-update/notification-manager.js +0 -1
- package/dist/esm/config/support.js +0 -1
- package/dist/esm/core/analytics.d.ts +13 -0
- package/dist/esm/core/analytics.js +15 -1
- package/dist/esm/core/cache-manager.js +0 -1
- package/dist/esm/core/config.d.ts +0 -15
- package/dist/esm/core/config.js +0 -4
- package/dist/esm/core/errors.d.ts +1 -0
- package/dist/esm/core/errors.js +1 -1
- package/dist/esm/core/event-emitter.d.ts +0 -3
- package/dist/esm/core/event-emitter.js +8 -3
- package/dist/esm/core/logger.js +0 -1
- package/dist/esm/core/performance.js +0 -1
- package/dist/esm/core/plugin-manager.js +3 -1
- package/dist/esm/core/security.d.ts +11 -0
- package/dist/esm/core/security.js +27 -1
- 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 -12
- package/dist/esm/definitions.js +0 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +3 -1
- package/dist/esm/live-update/bundle-manager.d.ts +8 -0
- package/dist/esm/live-update/bundle-manager.js +20 -1
- package/dist/esm/live-update/certificate-pinning.js +0 -1
- package/dist/esm/live-update/delta-processor.d.ts +1 -1
- package/dist/esm/live-update/delta-processor.js +3 -1
- package/dist/esm/live-update/download-manager.js +9 -2
- package/dist/esm/live-update/rollout-checker.d.ts +1 -1
- package/dist/esm/live-update/rollout-checker.js +5 -6
- package/dist/esm/live-update/update-manager.js +0 -1
- package/dist/esm/live-update/version-manager.d.ts +0 -12
- package/dist/esm/live-update/version-manager.js +43 -95
- package/dist/esm/plugin.js +71 -51
- package/dist/esm/security/crypto.js +11 -7
- package/dist/esm/security/validator.js +0 -1
- package/dist/esm/types/rollout.d.ts +91 -0
- package/dist/esm/types/rollout.js +25 -0
- package/dist/esm/web.d.ts +8 -0
- package/dist/esm/web.js +148 -54
- package/dist/plugin.cjs.js +1 -2
- package/dist/plugin.esm.js +1 -2
- package/dist/plugin.js +2 -3
- package/docs/AGENTS.md +9 -0
- package/docs/CHANGELOG.md +140 -0
- package/docs/CLAUDE.md +10 -1
- package/docs/DEPLOY_NOTES.md +117 -0
- package/docs/MANUAL-TASKS.md +30 -0
- package/docs/MARKETING_WEBSITE_TRACKER.md +18 -2
- package/docs/MIGRATION.md +83 -0
- package/docs/PACKAGES.md +167 -0
- package/docs/PERFORMANCE.md +110 -0
- package/docs/PROJECT_COMPLETION_TRACKER.md +4 -35
- package/docs/README.md +0 -1
- package/docs/REMAINING_FEATURES.md +123 -76
- package/docs/ROADMAP.md +200 -120
- package/docs/SECURITY-IF-REPO-PUBLIC.md +232 -0
- package/docs/TESTING_REQUIREMENTS.md +1 -112
- package/docs/ai-knowledge-base/00-project-profile.md +38 -0
- package/docs/ai-knowledge-base/01-features.md +46 -0
- package/docs/ai-knowledge-base/02-routes.md +72 -0
- package/docs/ai-knowledge-base/03-tech-stack.md +57 -0
- package/docs/ai-knowledge-base/README.md +23 -0
- package/docs/analytics-tracking.md +37 -0
- package/docs/api/background-update-api.md +14 -1
- package/docs/capacitor-official-plugins.md +46 -0
- package/docs/capawesome-plugins.md +29 -0
- package/docs/deployment/HOSTINGER_DEPLOY.md +75 -34
- package/docs/deployment/PRODUCTION-DEPLOY-CHECKLIST.md +184 -0
- package/docs/docs-site/plan.md +201 -0
- package/docs/docs-site/scope.md +127 -0
- package/docs/docs-site/tracker.json +235 -0
- package/docs/error-handling-tracking.md +37 -0
- 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/guides/testing-guide.md +15 -41
- package/docs/package-audit.md +41 -0
- package/docs/play-store/ASO-METADATA.md +5 -0
- package/docs/play-store/DATA-SAFETY.md +5 -0
- package/docs/play-store/DECLARATIONS.md +5 -0
- package/docs/play-store/README.md +27 -0
- package/docs/play-store/RELEASE-NOTES.md +99 -0
- package/docs/play-store/RELEASE-STEPS.md +6 -0
- package/docs/play-store/STORE-LISTING.md +7 -0
- package/docs/play-store/SUBMISSION-CHECKLIST.md +5 -0
- package/docs/production-readiness.md +1 -1
- package/docs/project-audit/2026-05-16/00-FINALIZATION-PLAN.md +123 -0
- package/docs/project-audit/2026-05-16/01-BATCH-PLAN.md +227 -0
- package/docs/project-audit/2026-05-16/02-AUDIT-FINDINGS.md +144 -0
- package/docs/project-audit/2026-05-16/sessions/batch-01.md +42 -0
- package/docs/project-audit/2026-05-16/sessions/batch-02.md +74 -0
- package/docs/project-audit/2026-05-16/sessions/batch-03.md +71 -0
- package/docs/project-audit/2026-05-16/sessions/batch-04.md +88 -0
- package/docs/project-audit/2026-05-16/sessions/batch-05.md +63 -0
- package/docs/project-audit/2026-05-16/sessions/batch-06.md +103 -0
- package/docs/project-audit/2026-05-16/sessions/batch-07.md +61 -0
- package/docs/project-audit/2026-05-16/sessions/batch-08.md +101 -0
- package/docs/project-audit/2026-05-16/sessions/batch-09.md +105 -0
- package/docs/project-audit/2026-05-16/sessions/batch-10.md +102 -0
- package/docs/project-audit/AUDIT-HISTORY.md +74 -0
- package/docs/project-audit/BATCH-PLAN.md +168 -0
- package/docs/project-audit/MARKETING-WEBSITE-FINDINGS-2026-05-11.md +73 -0
- package/docs/project-audit/PRODUCTION-READINESS-AUDIT-2026-05-08.md +275 -0
- package/docs/project-finalization/00-tracker.json +60 -0
- package/docs/project-knowledge-base/01-system-overview.md +39 -30
- package/docs/project-knowledge-base/02-routes-pages-forms-users.md +87 -81
- package/docs/project-knowledge-base/03-tech-stack-modules-services.md +140 -108
- package/docs/project-knowledge-base/04-data-models-integrations.md +191 -254
- package/docs/project-knowledge-base/05-docs-corpus-inventory.md +83 -20
- package/docs/project-knowledge-base/06-operations-testing-legal-content.md +67 -29
- package/docs/project-knowledge-base/README.md +27 -14
- package/docs/project-profiles/native-update-capacitor-update-platform-project-profile-last-updated-2026-05-19.md +81 -0
- package/docs/rules-tracker.md +102 -0
- package/docs/security/PRE-LAUNCH-PENTEST-CHECKLIST.md +116 -0
- package/docs/server-requirements.md +41 -11
- package/docs/social-media-marketing/README.md +81 -0
- package/docs/social-media-marketing/posts-batch-01.md +613 -0
- package/docs/social-media-marketing/posts-batch-02.md +528 -0
- package/docs/social-media-marketing/whatsapp-messages-batch-01.md +458 -0
- package/docs/social-media-marketing/whatsapp-status-batch-01.md +355 -0
- package/docs/tracking/finalization-2026-05-16-tracker.json +346 -0
- package/docs/tracking/full-audit-tracker.json +121 -0
- package/docs/tracking/production-readiness-audit-tracker.json +429 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +16 -3
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +71 -47
- package/ios/Plugin/NativeUpdatePlugin.swift +14 -9
- package/package.json +29 -29
- package/cli/node_modules/.yarn-integrity +0 -16
- package/cli/node_modules/commander/LICENSE +0 -22
- package/cli/node_modules/commander/Readme.md +0 -1148
- package/cli/node_modules/commander/esm.mjs +0 -16
- package/cli/node_modules/commander/index.js +0 -26
- package/cli/node_modules/commander/lib/argument.js +0 -145
- package/cli/node_modules/commander/lib/command.js +0 -2179
- package/cli/node_modules/commander/lib/error.js +0 -43
- package/cli/node_modules/commander/lib/help.js +0 -462
- package/cli/node_modules/commander/lib/option.js +0 -329
- package/cli/node_modules/commander/lib/suggestSimilar.js +0 -100
- package/cli/node_modules/commander/package-support.json +0 -16
- package/cli/node_modules/commander/package.json +0 -80
- package/cli/node_modules/commander/typings/esm.d.mts +0 -3
- package/cli/node_modules/commander/typings/index.d.ts +0 -884
- package/cli/yarn.lock +0 -8
- package/dist/esm/__tests__/bundle-manager.test.d.ts +0 -1
- package/dist/esm/__tests__/bundle-manager.test.js +0 -151
- package/dist/esm/__tests__/bundle-manager.test.js.map +0 -1
- package/dist/esm/__tests__/config.test.d.ts +0 -1
- package/dist/esm/__tests__/config.test.js +0 -70
- package/dist/esm/__tests__/config.test.js.map +0 -1
- package/dist/esm/__tests__/delta-processor.test.d.ts +0 -1
- package/dist/esm/__tests__/delta-processor.test.js +0 -77
- package/dist/esm/__tests__/delta-processor.test.js.map +0 -1
- package/dist/esm/__tests__/firestore-schema.test.d.ts +0 -1
- package/dist/esm/__tests__/firestore-schema.test.js +0 -74
- package/dist/esm/__tests__/firestore-schema.test.js.map +0 -1
- package/dist/esm/__tests__/integration.test.d.ts +0 -1
- package/dist/esm/__tests__/integration.test.js +0 -78
- package/dist/esm/__tests__/integration.test.js.map +0 -1
- package/dist/esm/__tests__/manifest-reader.test.d.ts +0 -1
- package/dist/esm/__tests__/manifest-reader.test.js +0 -271
- package/dist/esm/__tests__/manifest-reader.test.js.map +0 -1
- package/dist/esm/__tests__/rollout-checker.test.d.ts +0 -1
- package/dist/esm/__tests__/rollout-checker.test.js +0 -210
- package/dist/esm/__tests__/rollout-checker.test.js.map +0 -1
- package/dist/esm/__tests__/security-enforcement.test.d.ts +0 -1
- package/dist/esm/__tests__/security-enforcement.test.js +0 -95
- package/dist/esm/__tests__/security-enforcement.test.js.map +0 -1
- package/dist/esm/__tests__/security.test.d.ts +0 -1
- package/dist/esm/__tests__/security.test.js +0 -54
- package/dist/esm/__tests__/security.test.js.map +0 -1
- package/dist/esm/__tests__/version-manager.test.d.ts +0 -1
- package/dist/esm/__tests__/version-manager.test.js +0 -45
- package/dist/esm/__tests__/version-manager.test.js.map +0 -1
- package/dist/esm/app-review/app-review-manager.js.map +0 -1
- package/dist/esm/app-review/index.js.map +0 -1
- package/dist/esm/app-review/platform-review-handler.js.map +0 -1
- package/dist/esm/app-review/review-conditions-checker.js.map +0 -1
- package/dist/esm/app-review/review-rate-limiter.js.map +0 -1
- package/dist/esm/app-review/types.js.map +0 -1
- package/dist/esm/app-update/app-update-checker.js.map +0 -1
- package/dist/esm/app-update/app-update-installer.js.map +0 -1
- package/dist/esm/app-update/app-update-manager.js.map +0 -1
- package/dist/esm/app-update/app-update-notifier.js.map +0 -1
- package/dist/esm/app-update/index.js.map +0 -1
- package/dist/esm/app-update/platform-app-update.js.map +0 -1
- package/dist/esm/app-update/types.js.map +0 -1
- package/dist/esm/background-update/background-scheduler.js.map +0 -1
- package/dist/esm/background-update/index.js.map +0 -1
- package/dist/esm/background-update/notification-manager.js.map +0 -1
- package/dist/esm/config/support.js.map +0 -1
- package/dist/esm/core/analytics.js.map +0 -1
- package/dist/esm/core/cache-manager.js.map +0 -1
- package/dist/esm/core/config.js.map +0 -1
- package/dist/esm/core/errors.js.map +0 -1
- package/dist/esm/core/event-emitter.js.map +0 -1
- package/dist/esm/core/logger.js.map +0 -1
- package/dist/esm/core/performance.js.map +0 -1
- package/dist/esm/core/plugin-manager.js.map +0 -1
- package/dist/esm/core/security.js.map +0 -1
- package/dist/esm/definitions.js.map +0 -1
- package/dist/esm/firestore/firestore-client.d.ts +0 -109
- package/dist/esm/firestore/firestore-client.js +0 -264
- package/dist/esm/firestore/firestore-client.js.map +0 -1
- package/dist/esm/firestore/index.d.ts +0 -11
- package/dist/esm/firestore/index.js +0 -11
- package/dist/esm/firestore/index.js.map +0 -1
- package/dist/esm/firestore/manifest-reader.d.ts +0 -87
- package/dist/esm/firestore/manifest-reader.js +0 -294
- package/dist/esm/firestore/manifest-reader.js.map +0 -1
- package/dist/esm/firestore/schema.d.ts +0 -507
- package/dist/esm/firestore/schema.js +0 -73
- package/dist/esm/firestore/schema.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/live-update/bundle-manager.js.map +0 -1
- package/dist/esm/live-update/certificate-pinning.js.map +0 -1
- package/dist/esm/live-update/delta-processor.js.map +0 -1
- package/dist/esm/live-update/download-manager.js.map +0 -1
- package/dist/esm/live-update/rollout-checker.js.map +0 -1
- package/dist/esm/live-update/update-manager.js.map +0 -1
- package/dist/esm/live-update/version-manager.js.map +0 -1
- package/dist/esm/plugin.js.map +0 -1
- package/dist/esm/security/crypto.js.map +0 -1
- package/dist/esm/security/validator.js.map +0 -1
- package/dist/esm/web.js.map +0 -1
- package/dist/plugin.cjs.js.map +0 -1
- package/dist/plugin.esm.js.map +0 -1
- package/dist/plugin.js.map +0 -1
- package/docs/FIREBASE_INTEGRATION_TRACKER.md +0 -321
- package/docs/FIREBASE_QUERIES_AND_INDEXES_AUDIT.md +0 -221
- package/docs/examples/firebase-backend-example.md +0 -27
- package/docs/features/laravel-nova-backend/credentials.ignore.md +0 -34
- package/docs/guides/no-cost-backend-implementation-plan.md +0 -77
- package/docs/guides/no-cost-firestore-google-drive-backend.md +0 -60
- package/docs/project-profiles/native-update-capacitor-update-platform-project-profile-last-updated-2026-03-16.md +0 -454
- package/docs/project-profiles/native-update-capacitor-update-platform-project-profile-last-updated-2026-03-24.md +0 -66
- package/docs/project-profiles/native-update-capacitor-update-platform-project-profile-last-updated-2026-03-25.md +0 -67
- /package/docs/{MARKETING_WEBSITE_PLAN.md → archive/MARKETING_WEBSITE_PLAN.md} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Logger } from '../core/logger';
|
|
2
2
|
import { Capacitor } from '@capacitor/core';
|
|
3
|
+
import { SecurityValidator } from '../core/security';
|
|
3
4
|
export class PlatformAppUpdate {
|
|
4
5
|
constructor(config) {
|
|
5
6
|
this.config = config;
|
|
@@ -31,13 +32,19 @@ export class PlatformAppUpdate {
|
|
|
31
32
|
// Web platform - check configured update URL
|
|
32
33
|
if (this.config.webUpdateUrl) {
|
|
33
34
|
try {
|
|
35
|
+
SecurityValidator.validateDownloadUrl(this.config.webUpdateUrl);
|
|
34
36
|
const response = await fetch(this.config.webUpdateUrl);
|
|
35
37
|
const data = await response.json();
|
|
36
38
|
if (data.version && data.version !== versionInfo.currentVersion) {
|
|
37
39
|
updateInfo.updateAvailable = true;
|
|
38
40
|
updateInfo.availableVersion = data.version;
|
|
39
41
|
updateInfo.releaseNotes = data.releaseNotes;
|
|
40
|
-
|
|
42
|
+
// Validate downloadUrl scheme — server-controlled value, must
|
|
43
|
+
// not be allowed to smuggle javascript: into a later openUrl.
|
|
44
|
+
if (data.downloadUrl) {
|
|
45
|
+
SecurityValidator.validateStoreUrl(data.downloadUrl);
|
|
46
|
+
updateInfo.updateURL = data.downloadUrl;
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
catch (error) {
|
|
@@ -85,8 +92,11 @@ export class PlatformAppUpdate {
|
|
|
85
92
|
return { url, platform: platform };
|
|
86
93
|
}
|
|
87
94
|
async openUrl(url) {
|
|
95
|
+
// Reject any non-HTTPS / non-store URL — protects against
|
|
96
|
+
// `javascript:` payloads handed back from a compromised server.
|
|
97
|
+
SecurityValidator.validateStoreUrl(url);
|
|
88
98
|
if (typeof window !== 'undefined' && window.open) {
|
|
89
|
-
window.open(url, '_blank');
|
|
99
|
+
window.open(url, '_blank', 'noopener,noreferrer');
|
|
90
100
|
}
|
|
91
101
|
else {
|
|
92
102
|
throw new Error('Cannot open URL on this platform');
|
|
@@ -126,4 +136,3 @@ export class PlatformAppUpdate {
|
|
|
126
136
|
return capabilities;
|
|
127
137
|
}
|
|
128
138
|
}
|
|
129
|
-
//# sourceMappingURL=platform-app-update.js.map
|
|
@@ -9,4 +9,3 @@ export var AppUpdateInstallStatus;
|
|
|
9
9
|
AppUpdateInstallStatus[AppUpdateInstallStatus["CANCELED"] = 6] = "CANCELED";
|
|
10
10
|
AppUpdateInstallStatus[AppUpdateInstallStatus["DOWNLOADED"] = 11] = "DOWNLOADED";
|
|
11
11
|
})(AppUpdateInstallStatus || (AppUpdateInstallStatus = {}));
|
|
12
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -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);
|
|
@@ -307,4 +330,3 @@ export class BackgroundScheduler {
|
|
|
307
330
|
return 0;
|
|
308
331
|
}
|
|
309
332
|
}
|
|
310
|
-
//# sourceMappingURL=background-scheduler.js.map
|
|
@@ -60,6 +60,19 @@ export declare class Analytics {
|
|
|
60
60
|
/**
|
|
61
61
|
* Console analytics provider for development
|
|
62
62
|
*/
|
|
63
|
+
/**
|
|
64
|
+
* Default analytics provider that writes events directly to the
|
|
65
|
+
* browser/native console. Production apps should swap this for a real
|
|
66
|
+
* provider (Firebase Analytics, Amplitude, Sentry, …) via
|
|
67
|
+
* `setAnalyticsProvider()`.
|
|
68
|
+
*
|
|
69
|
+
* The two `console.*` calls below are intentional and on-brand for this
|
|
70
|
+
* class — `ConsoleAnalyticsProvider` IS the "send to console" sink. They
|
|
71
|
+
* are NOT a violation of the centralized-logger rule (which targets
|
|
72
|
+
* incidental logging, not analytics dispatch). Do not replace with the
|
|
73
|
+
* Logger — it would create a circular relationship between analytics
|
|
74
|
+
* and logging surfaces.
|
|
75
|
+
*/
|
|
63
76
|
export declare class ConsoleAnalyticsProvider implements AnalyticsProvider {
|
|
64
77
|
private userId?;
|
|
65
78
|
private properties;
|
|
@@ -111,14 +111,29 @@ export class Analytics {
|
|
|
111
111
|
/**
|
|
112
112
|
* Console analytics provider for development
|
|
113
113
|
*/
|
|
114
|
+
/**
|
|
115
|
+
* Default analytics provider that writes events directly to the
|
|
116
|
+
* browser/native console. Production apps should swap this for a real
|
|
117
|
+
* provider (Firebase Analytics, Amplitude, Sentry, …) via
|
|
118
|
+
* `setAnalyticsProvider()`.
|
|
119
|
+
*
|
|
120
|
+
* The two `console.*` calls below are intentional and on-brand for this
|
|
121
|
+
* class — `ConsoleAnalyticsProvider` IS the "send to console" sink. They
|
|
122
|
+
* are NOT a violation of the centralized-logger rule (which targets
|
|
123
|
+
* incidental logging, not analytics dispatch). Do not replace with the
|
|
124
|
+
* Logger — it would create a circular relationship between analytics
|
|
125
|
+
* and logging surfaces.
|
|
126
|
+
*/
|
|
114
127
|
export class ConsoleAnalyticsProvider {
|
|
115
128
|
constructor() {
|
|
116
129
|
this.properties = {};
|
|
117
130
|
}
|
|
118
131
|
async trackEvent(event) {
|
|
132
|
+
// ConsoleAnalyticsProvider intentionally writes to console — see class header.
|
|
119
133
|
console.log('[Analytics]', event.type, Object.assign(Object.assign({}, event), { userId: this.userId, properties: this.properties }));
|
|
120
134
|
}
|
|
121
135
|
async trackError(error, context) {
|
|
136
|
+
// ConsoleAnalyticsProvider intentionally writes to console — see class header.
|
|
122
137
|
console.error('[Analytics Error]', {
|
|
123
138
|
error: error.message,
|
|
124
139
|
stack: error.stack,
|
|
@@ -134,4 +149,3 @@ export class ConsoleAnalyticsProvider {
|
|
|
134
149
|
this.properties = Object.assign(Object.assign({}, this.properties), properties);
|
|
135
150
|
}
|
|
136
151
|
}
|
|
137
|
-
//# sourceMappingURL=analytics.js.map
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { Filesystem } from '@capacitor/filesystem';
|
|
2
2
|
import type { Preferences } from '@capacitor/preferences';
|
|
3
3
|
import type { UpdateStrategy, ChecksumAlgorithm, SecurityConfig } from '../definitions';
|
|
4
|
-
import type { FirestoreConfig } from '../firestore/schema';
|
|
5
|
-
/**
|
|
6
|
-
* Backend type for update checking
|
|
7
|
-
*/
|
|
8
|
-
export type BackendType = 'http' | 'firestore';
|
|
9
4
|
export interface PluginConfig {
|
|
10
5
|
filesystem?: typeof Filesystem;
|
|
11
6
|
preferences?: typeof Preferences;
|
|
@@ -44,16 +39,6 @@ export interface PluginConfig {
|
|
|
44
39
|
packageName?: string;
|
|
45
40
|
webReviewUrl?: string;
|
|
46
41
|
minimumVersion?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Backend type for update checking
|
|
49
|
-
* - 'http': Traditional HTTP server (default)
|
|
50
|
-
* - 'firestore': Google Firestore (free tier)
|
|
51
|
-
*/
|
|
52
|
-
backendType?: BackendType;
|
|
53
|
-
/**
|
|
54
|
-
* Firestore configuration (required if backendType is 'firestore')
|
|
55
|
-
*/
|
|
56
|
-
firestore?: FirestoreConfig;
|
|
57
42
|
/**
|
|
58
43
|
* Enable delta updates (binary patching)
|
|
59
44
|
* Reduces download size by 50-90%
|
package/dist/esm/core/config.js
CHANGED
|
@@ -49,9 +49,6 @@ export class ConfigManager {
|
|
|
49
49
|
packageName: '',
|
|
50
50
|
webReviewUrl: '',
|
|
51
51
|
minimumVersion: '1.0.0',
|
|
52
|
-
// Firestore backend configuration
|
|
53
|
-
backendType: 'http',
|
|
54
|
-
firestore: null,
|
|
55
52
|
enableDeltaUpdates: true,
|
|
56
53
|
enableStagedRollouts: true,
|
|
57
54
|
};
|
|
@@ -91,4 +88,3 @@ export class ConfigManager {
|
|
|
91
88
|
return !!(this.config.filesystem && this.config.preferences);
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -7,6 +7,7 @@ export declare enum ErrorCode {
|
|
|
7
7
|
DOWNLOAD_FAILED = "DOWNLOAD_FAILED",
|
|
8
8
|
DOWNLOAD_TIMEOUT = "DOWNLOAD_TIMEOUT",
|
|
9
9
|
INVALID_URL = "INVALID_URL",
|
|
10
|
+
INSECURE_URL = "INSECURE_URL",
|
|
10
11
|
UNAUTHORIZED_HOST = "UNAUTHORIZED_HOST",
|
|
11
12
|
BUNDLE_TOO_LARGE = "BUNDLE_TOO_LARGE",
|
|
12
13
|
CHECKSUM_MISMATCH = "CHECKSUM_MISMATCH",
|
package/dist/esm/core/errors.js
CHANGED
|
@@ -11,6 +11,7 @@ export var ErrorCode;
|
|
|
11
11
|
ErrorCode["DOWNLOAD_FAILED"] = "DOWNLOAD_FAILED";
|
|
12
12
|
ErrorCode["DOWNLOAD_TIMEOUT"] = "DOWNLOAD_TIMEOUT";
|
|
13
13
|
ErrorCode["INVALID_URL"] = "INVALID_URL";
|
|
14
|
+
ErrorCode["INSECURE_URL"] = "INSECURE_URL";
|
|
14
15
|
ErrorCode["UNAUTHORIZED_HOST"] = "UNAUTHORIZED_HOST";
|
|
15
16
|
ErrorCode["BUNDLE_TOO_LARGE"] = "BUNDLE_TOO_LARGE";
|
|
16
17
|
// Validation errors
|
|
@@ -82,4 +83,3 @@ export class UpdateError extends NativeUpdateError {
|
|
|
82
83
|
this.name = 'UpdateError';
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Centralized event emitter for the Native Update plugin
|
|
2
|
+
* Centralized event emitter for the Native Update plugin.
|
|
3
|
+
*
|
|
4
|
+
* Listener errors are sent to the plugin Logger so they respect the
|
|
5
|
+
* runtime log-level switch and the secret-redaction filter — never raw
|
|
6
|
+
* console.* calls. See src/core/logger.ts.
|
|
3
7
|
*/
|
|
8
|
+
import { Logger } from './logger';
|
|
9
|
+
const logger = new Logger('NativeUpdate.EventEmitter');
|
|
4
10
|
export class EventEmitter {
|
|
5
11
|
constructor() {
|
|
6
12
|
this.listeners = new Map();
|
|
@@ -41,7 +47,7 @@ export class EventEmitter {
|
|
|
41
47
|
listener(data);
|
|
42
48
|
}
|
|
43
49
|
catch (error) {
|
|
44
|
-
|
|
50
|
+
logger.error(`Error in event listener for ${eventName}`, error);
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
53
|
}
|
|
@@ -72,4 +78,3 @@ export class EventEmitter {
|
|
|
72
78
|
return Array.from(this.listeners.keys());
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
|
-
//# sourceMappingURL=event-emitter.js.map
|
package/dist/esm/core/logger.js
CHANGED
|
@@ -56,6 +56,9 @@ export class PluginManager {
|
|
|
56
56
|
await this.bundleManager.initialize();
|
|
57
57
|
this.downloadManager = new DownloadManager();
|
|
58
58
|
await this.downloadManager.initialize();
|
|
59
|
+
// Bundle manager needs the download manager so deleteBundle can
|
|
60
|
+
// also remove the on-disk blob (otherwise old bundles leak forever).
|
|
61
|
+
this.bundleManager.setDownloadManager(this.downloadManager);
|
|
59
62
|
this.versionManager = new VersionManager();
|
|
60
63
|
await this.versionManager.initialize();
|
|
61
64
|
this.appUpdateManager = new AppUpdateManager({
|
|
@@ -217,4 +220,3 @@ export class PluginManager {
|
|
|
217
220
|
});
|
|
218
221
|
}
|
|
219
222
|
}
|
|
220
|
-
//# sourceMappingURL=plugin-manager.js.map
|
|
@@ -8,6 +8,17 @@ export declare class SecurityValidator {
|
|
|
8
8
|
* Validate URL is HTTPS
|
|
9
9
|
*/
|
|
10
10
|
static validateUrl(url: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Reject any URL that is not HTTPS (or known native-app schemes
|
|
13
|
+
* `market:` / `itms-apps:` for opening the app store). Throws so
|
|
14
|
+
* callers can't silently fall through to a `javascript:` payload.
|
|
15
|
+
*/
|
|
16
|
+
static validateDownloadUrl(url: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Validate URL whose only acceptable schemes are HTTPS, `market:` (Play
|
|
19
|
+
* Store), or `itms-apps:` (App Store). Used by `openAppStore`.
|
|
20
|
+
*/
|
|
21
|
+
static validateStoreUrl(url: string): void;
|
|
11
22
|
/**
|
|
12
23
|
* Validate checksum format
|
|
13
24
|
*/
|
|
@@ -24,6 +24,33 @@ export class SecurityValidator {
|
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Reject any URL that is not HTTPS (or known native-app schemes
|
|
29
|
+
* `market:` / `itms-apps:` for opening the app store). Throws so
|
|
30
|
+
* callers can't silently fall through to a `javascript:` payload.
|
|
31
|
+
*/
|
|
32
|
+
static validateDownloadUrl(url) {
|
|
33
|
+
if (!this.validateUrl(url)) {
|
|
34
|
+
throw new ValidationError(ErrorCode.INSECURE_URL, `Refusing non-HTTPS URL: ${url}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validate URL whose only acceptable schemes are HTTPS, `market:` (Play
|
|
39
|
+
* Store), or `itms-apps:` (App Store). Used by `openAppStore`.
|
|
40
|
+
*/
|
|
41
|
+
static validateStoreUrl(url) {
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = new URL(url);
|
|
45
|
+
}
|
|
46
|
+
catch (_a) {
|
|
47
|
+
throw new ValidationError(ErrorCode.INSECURE_URL, `Invalid URL: ${url}`);
|
|
48
|
+
}
|
|
49
|
+
const allowed = ['https:', 'market:', 'itms-apps:'];
|
|
50
|
+
if (!allowed.includes(parsed.protocol)) {
|
|
51
|
+
throw new ValidationError(ErrorCode.INSECURE_URL, `Refusing URL scheme ${parsed.protocol}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
27
54
|
/**
|
|
28
55
|
* Validate checksum format
|
|
29
56
|
*/
|
|
@@ -335,4 +362,3 @@ export class SecurityValidator {
|
|
|
335
362
|
}
|
|
336
363
|
}
|
|
337
364
|
}
|
|
338
|
-
//# sourceMappingURL=security.js.map
|
|
@@ -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
|
+
}
|