@gfean/react-native-bundle-drop 0.4.6 → 0.6.0
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 +168 -4
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +69 -0
- package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
- package/ios/BundleDropBridge.m +18 -0
- package/ios/BundleDropLocator.swift +48 -2
- package/ios/BundleDropModule.swift +75 -0
- package/ios/BundleDropRuntimeCrypto.swift +45 -0
- package/lib/CLI/cli.d.ts +1 -0
- package/lib/CLI/cli.js +166 -79
- package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
- package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
- package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
- package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
- package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
- package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
- package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
- package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
- package/lib/CLI/scripts/aipowered/init-project-config.js +228 -43
- package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
- package/lib/CLI/scripts/aipowered/scanner.js +164 -32
- package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
- package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
- package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
- package/lib/CLI/scripts/bare-metro-config.js +24 -32
- package/lib/CLI/scripts/doctor.js +143 -22
- package/lib/CLI/scripts/expo/configure-expo.js +51 -60
- package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
- package/lib/CLI/scripts/expo/package-manager.js +63 -25
- package/lib/CLI/scripts/init-config.d.ts +7 -7
- package/lib/CLI/scripts/init-config.js +246 -32
- package/lib/CLI/scripts/login-cli.js +35 -10
- package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
- package/lib/CLI/scripts/metro-config-authority.js +303 -0
- package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
- package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
- package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
- package/lib/CLI/scripts/native-setup-contract.js +63 -33
- package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
- package/lib/CLI/scripts/native-startup-validator.js +964 -0
- package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
- package/lib/CLI/scripts/safe-file-transaction.js +159 -0
- package/lib/CLI/scripts/sight-artifacts.d.ts +17 -0
- package/lib/CLI/scripts/sight-artifacts.js +204 -0
- package/lib/CLI/scripts/sight-cli.d.ts +10 -0
- package/lib/CLI/scripts/sight-cli.js +127 -0
- package/lib/CLI/scripts/sight-session.d.ts +14 -0
- package/lib/CLI/scripts/sight-session.js +192 -0
- package/lib/api/clientApi.d.ts +3 -1
- package/lib/api/clientApi.js +14 -0
- package/lib/api/types.d.ts +39 -0
- package/lib/context.d.ts +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/install/installFromZip.d.ts +3 -0
- package/lib/install/installFromZip.js +10 -1
- package/lib/loadConfig.d.ts +17 -1
- package/lib/loadConfig.js +16 -0
- package/lib/manager/downloadAndInstall.d.ts +3 -2
- package/lib/manager/downloadAndInstall.js +111 -46
- package/lib/manager/rollbackState.d.ts +3 -1
- package/lib/manager/rollbackState.js +2 -2
- package/lib/manager/updateCheck.d.ts +1 -0
- package/lib/manager/updateCheck.js +218 -78
- package/lib/metro.d.ts +8 -1
- package/lib/metro.js +68 -19
- package/lib/native/bundleDropNative.js +2 -1
- package/lib/native/fs.d.ts +6 -0
- package/lib/native/fs.js +24 -0
- package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
- package/lib/patch-engine/installFromPatchSet.js +14 -3
- package/lib/patch-engine/patchTransport.d.ts +2 -0
- package/lib/patch-engine/patchTransport.js +9 -0
- package/lib/runtime/initState.d.ts +5 -0
- package/lib/runtime/initState.js +4 -0
- package/lib/runtime/service.js +60 -3
- package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
- package/lib/runtime-delivery/artifactCapability.js +32 -0
- package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
- package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
- package/lib/runtime-delivery/bootstrapConfig.d.ts +50 -0
- package/lib/runtime-delivery/bootstrapConfig.js +217 -0
- package/lib/runtime-delivery/diagnostics.d.ts +17 -0
- package/lib/runtime-delivery/diagnostics.js +58 -0
- package/lib/runtime-delivery/encoding.d.ts +5 -0
- package/lib/runtime-delivery/encoding.js +132 -0
- package/lib/runtime-delivery/heartbeat.d.ts +3 -0
- package/lib/runtime-delivery/heartbeat.js +88 -0
- package/lib/runtime-delivery/localResolver.d.ts +23 -0
- package/lib/runtime-delivery/localResolver.js +81 -0
- package/lib/runtime-delivery/manifestState.d.ts +9 -0
- package/lib/runtime-delivery/manifestState.js +102 -0
- package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
- package/lib/runtime-delivery/manifestVerifier.js +329 -0
- package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
- package/lib/runtime-delivery/runtimeDelivery.js +375 -0
- package/lib/runtime-delivery/types.d.ts +87 -0
- package/lib/runtime-delivery/types.js +6 -0
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ const installId_1 = require("../fs/installId");
|
|
|
6
6
|
const clientApi_1 = require("../api/clientApi");
|
|
7
7
|
const installFromPatchSet_1 = require("./installFromPatchSet");
|
|
8
8
|
const patchOperations_1 = require("./patchOperations");
|
|
9
|
+
const artifactCapability_1 = require("../runtime-delivery/artifactCapability");
|
|
9
10
|
const PATCH_FAILURE_REPORT_TIMEOUT_MS = 1500;
|
|
10
11
|
const reportPatchInstallFailure = async ({ projectSlug, platform, runtimeVersionValue, baseHash, targetHash, algorithm, error, }) => {
|
|
11
12
|
try {
|
|
@@ -59,11 +60,19 @@ const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtime
|
|
|
59
60
|
baseHash: target.baseHash,
|
|
60
61
|
targetHash: target.hash,
|
|
61
62
|
algorithm: target.patchSet.algorithm,
|
|
63
|
+
...(target.expectedManifestHash
|
|
64
|
+
? { expectedManifestHash: target.expectedManifestHash }
|
|
65
|
+
: {}),
|
|
66
|
+
...(target.expectedJsBundleHash
|
|
67
|
+
? { expectedJsBundleHash: target.expectedJsBundleHash }
|
|
68
|
+
: {}),
|
|
62
69
|
platform,
|
|
63
70
|
statusCb,
|
|
64
71
|
});
|
|
65
72
|
}
|
|
66
73
|
catch (e) {
|
|
74
|
+
if ((0, artifactCapability_1.isArtifactCapabilityRejected)(e))
|
|
75
|
+
throw e;
|
|
67
76
|
await reportPatchInstallFailureBeforeFallback({
|
|
68
77
|
projectSlug,
|
|
69
78
|
platform,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { UpdatePolicy } from '../types';
|
|
2
|
+
import type { RuntimeDeliveryDiagnosticEvent } from '../runtime-delivery/diagnostics';
|
|
2
3
|
export declare const BUNDLE_DROP_NOT_INITIALIZED_MESSAGE = "BundleDrop has not been initialized. Call BundleDrop.init({ environment, ... }) before using OTA APIs or useBundleDrop().";
|
|
3
4
|
export declare const BUNDLE_DROP_DISABLED_MESSAGE = "BundleDrop is disabled. OTA APIs are running in no-op mode because BundleDrop.init({ enabled: false, ... }) was used.";
|
|
4
5
|
/**
|
|
@@ -15,6 +16,8 @@ export type BundleDropInitOptions = {
|
|
|
15
16
|
policy?: UpdatePolicy;
|
|
16
17
|
/** Optional listener for human-readable status messages emitted during checks, downloads, and apply flow. */
|
|
17
18
|
onStatusUpdate?: (status: string) => void;
|
|
19
|
+
/** Optional sink for structured runtime-delivery diagnostic counter events. */
|
|
20
|
+
onRuntimeDeliveryDiagnostic?: (event: RuntimeDeliveryDiagnosticEvent) => void;
|
|
18
21
|
/** When `true`, startup performs only a resolve/check and skips download/apply even if policy would normally do more. */
|
|
19
22
|
checkOnly?: boolean;
|
|
20
23
|
};
|
|
@@ -32,6 +35,8 @@ export type BundleDropRuntimeConfig = {
|
|
|
32
35
|
policy: UpdatePolicy;
|
|
33
36
|
/** Optional listener receiving status messages from runtime actions. */
|
|
34
37
|
onStatusUpdate?: (status: string) => void;
|
|
38
|
+
/** Optional sink receiving structured runtime-delivery diagnostic counter events. */
|
|
39
|
+
onRuntimeDeliveryDiagnostic?: (event: RuntimeDeliveryDiagnosticEvent) => void;
|
|
35
40
|
/** Whether startup is limited to a resolve/check without downloading or applying. */
|
|
36
41
|
checkOnly: boolean;
|
|
37
42
|
};
|
package/lib/runtime/initState.js
CHANGED
|
@@ -53,6 +53,7 @@ function resolveBundleDropRuntimeConfig(options) {
|
|
|
53
53
|
channelName,
|
|
54
54
|
policy: options.policy || 'manual',
|
|
55
55
|
onStatusUpdate: options.onStatusUpdate,
|
|
56
|
+
onRuntimeDeliveryDiagnostic: options.onRuntimeDeliveryDiagnostic,
|
|
56
57
|
checkOnly: !!options.checkOnly,
|
|
57
58
|
};
|
|
58
59
|
}
|
|
@@ -66,6 +67,7 @@ function initializeBundleDropRuntime(options) {
|
|
|
66
67
|
initialChannelName: nextConfig.channelName,
|
|
67
68
|
policy: nextConfig.policy,
|
|
68
69
|
onStatusUpdate: nextConfig.onStatusUpdate,
|
|
70
|
+
onRuntimeDeliveryDiagnostic: nextConfig.onRuntimeDeliveryDiagnostic,
|
|
69
71
|
checkOnly: nextConfig.checkOnly,
|
|
70
72
|
};
|
|
71
73
|
runtimeConfigKey = nextKey;
|
|
@@ -78,6 +80,7 @@ function initializeBundleDropRuntime(options) {
|
|
|
78
80
|
initConfig = {
|
|
79
81
|
...initConfig,
|
|
80
82
|
onStatusUpdate: nextConfig.onStatusUpdate,
|
|
83
|
+
onRuntimeDeliveryDiagnostic: nextConfig.onRuntimeDeliveryDiagnostic,
|
|
81
84
|
};
|
|
82
85
|
return { config: assertBundleDropInitialized(), alreadyInitialized: true };
|
|
83
86
|
}
|
|
@@ -91,6 +94,7 @@ function getBundleDropRuntimeConfig() {
|
|
|
91
94
|
channelName: runtimeChannelName,
|
|
92
95
|
policy: initConfig.policy,
|
|
93
96
|
onStatusUpdate: initConfig.onStatusUpdate,
|
|
97
|
+
onRuntimeDeliveryDiagnostic: initConfig.onRuntimeDeliveryDiagnostic,
|
|
94
98
|
checkOnly: initConfig.checkOnly,
|
|
95
99
|
};
|
|
96
100
|
}
|
package/lib/runtime/service.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.waitForBundleDropStartupForTests = waitForBundleDropStartupForTests;
|
|
|
27
27
|
const bundleInfo_1 = require("../bundleInfo");
|
|
28
28
|
const context_1 = require("../context");
|
|
29
29
|
const fsUtils_1 = require("../fs/fsUtils");
|
|
30
|
+
const loadConfig_1 = require("../loadConfig");
|
|
30
31
|
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
31
32
|
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
32
33
|
const downloadAndInstall_1 = require("../manager/downloadAndInstall");
|
|
@@ -39,6 +40,13 @@ const DISABLED_STATUS = 'BundleDrop is disabled';
|
|
|
39
40
|
const EXPO_DEVELOPMENT_FALLBACK_WARNING = '[BundleDrop] OTA startup is unavailable in this Expo runtime. ' +
|
|
40
41
|
'Expo Go and standard Debug/development-client builds keep Metro priority, so OTA features are disabled. ' +
|
|
41
42
|
'Use a non-Debug/Release native build to test Bundle Drop updates.';
|
|
43
|
+
const CURRENT_REVOKED_ROLLBACK_REASONS = new Set([
|
|
44
|
+
'CURRENT_REVOKED_NO_COMPATIBLE_TARGET',
|
|
45
|
+
'CURRENT_REVOKED_NO_SAFE_TARGET',
|
|
46
|
+
'CURRENT_REVOKED_ORIGIN_UNAVAILABLE',
|
|
47
|
+
]);
|
|
48
|
+
const MANAGED_LIST_INSTALL_NOT_AUTHORIZED_STATUS = '⚠️ Selected bundle is not authorized by the current runtime delivery decision';
|
|
49
|
+
const MANAGED_DIRECT_INSTALL_NOT_AUTHORIZED_STATUS = '⚠️ Direct URL installs are unavailable with managed runtime delivery; use downloadUpdate or a bundle-list item';
|
|
42
50
|
let updateFlowActive = false;
|
|
43
51
|
let startupPromise = null;
|
|
44
52
|
let localStartupPromise = null;
|
|
@@ -110,6 +118,9 @@ function getEnabledRuntime(extraStatusHandler) {
|
|
|
110
118
|
function isSameStatus(current, next) {
|
|
111
119
|
return !!current && current === next;
|
|
112
120
|
}
|
|
121
|
+
function isCurrentRevokedRollback(reason) {
|
|
122
|
+
return !!reason && CURRENT_REVOKED_ROLLBACK_REASONS.has(reason);
|
|
123
|
+
}
|
|
113
124
|
function getCheckStatus(response) {
|
|
114
125
|
if (!response)
|
|
115
126
|
return '⚠️ Unable to check for updates. Try again.';
|
|
@@ -167,6 +178,15 @@ function requestRuntimeRestart() {
|
|
|
167
178
|
runtimeRestartRequested = true;
|
|
168
179
|
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
169
180
|
}
|
|
181
|
+
async function applyAuthoritativeRollback(reason) {
|
|
182
|
+
if (isCurrentRevokedRollback(reason)) {
|
|
183
|
+
await (0, rollbackState_1.rollbackToPreviousOrNative)({ forceNative: true });
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
await (0, rollbackState_1.rollbackToPreviousOrNative)();
|
|
187
|
+
}
|
|
188
|
+
requestRuntimeRestart();
|
|
189
|
+
}
|
|
170
190
|
async function markActiveCandidateHealthy(expectedHash) {
|
|
171
191
|
if (runtimeRestartRequested) {
|
|
172
192
|
return false;
|
|
@@ -302,8 +322,7 @@ async function runStartupFlow() {
|
|
|
302
322
|
return;
|
|
303
323
|
if (decision.action === 'ROLLBACK') {
|
|
304
324
|
emitStatus('↩️ Server requested rollback...');
|
|
305
|
-
await (
|
|
306
|
-
requestRuntimeRestart();
|
|
325
|
+
await applyAuthoritativeRollback(decision.reason);
|
|
307
326
|
return;
|
|
308
327
|
}
|
|
309
328
|
if (decision.action === 'NOOP' || runtime.policy === 'manual' || runtime.checkOnly) {
|
|
@@ -312,7 +331,7 @@ async function runStartupFlow() {
|
|
|
312
331
|
const downloadUrl = decision.mode === 'patch'
|
|
313
332
|
? decision.fallback?.downloadUrl
|
|
314
333
|
: decision.downloadUrl;
|
|
315
|
-
if (!downloadUrl || !decision.hash) {
|
|
334
|
+
if ((!downloadUrl && !decision.runtimeDelivery) || !decision.hash) {
|
|
316
335
|
emitStatus('⚠️ Update available but missing download URL');
|
|
317
336
|
return;
|
|
318
337
|
}
|
|
@@ -327,11 +346,17 @@ async function runStartupFlow() {
|
|
|
327
346
|
baseHash: decision.baseHash,
|
|
328
347
|
patchSet: decision.patchSet,
|
|
329
348
|
fallback: decision.fallback,
|
|
349
|
+
...(decision.runtimeDelivery ? { runtimeDelivery: decision.runtimeDelivery } : {}),
|
|
330
350
|
};
|
|
331
351
|
const downloadResult = await (0, downloadAndInstall_1.downloadUpdate)({
|
|
332
352
|
channelName: runtime.channelName,
|
|
333
353
|
resolvedTarget,
|
|
334
354
|
}, statusCb);
|
|
355
|
+
if (downloadResult.status === 'rollback') {
|
|
356
|
+
emitStatus('↩️ Server requested rollback...');
|
|
357
|
+
await applyAuthoritativeRollback(downloadResult.reason);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
335
360
|
if (runtime.policy === 'on-next-launch') {
|
|
336
361
|
if (downloadResult.status === 'staged') {
|
|
337
362
|
emitStatus('✅ Update downloaded for next launch');
|
|
@@ -465,6 +490,9 @@ async function downloadAndStage(extraStatusHandler) {
|
|
|
465
490
|
await waitForStartupIfNeeded();
|
|
466
491
|
return withBusy(async () => {
|
|
467
492
|
const result = await (0, downloadAndInstall_1.downloadUpdate)({ channelName: runtime.channelName }, status => emitStatus(status, extraStatusHandler));
|
|
493
|
+
if (result.status === 'rollback') {
|
|
494
|
+
await applyAuthoritativeRollback(result.reason);
|
|
495
|
+
}
|
|
468
496
|
const status = getDownloadStatus(result);
|
|
469
497
|
if (status) {
|
|
470
498
|
emitStatus(status, extraStatusHandler);
|
|
@@ -560,8 +588,27 @@ async function installBundleFromListItem(bundle) {
|
|
|
560
588
|
}
|
|
561
589
|
return withBusy(async () => {
|
|
562
590
|
const resolvedDecision = await (0, updateCheck_1.checkForUpdate)(runtime.channelName, emitStatus).catch(() => null);
|
|
591
|
+
const usesManagedRuntimeDelivery = (0, loadConfig_1.isRuntimeDeliveryConfigured)(context_1.config.runtimeDelivery);
|
|
563
592
|
const canUseResolvedTransport = resolvedDecision?.action === 'INSTALL' &&
|
|
564
593
|
(resolvedDecision.bundleHash ?? resolvedDecision.hash) === bundle.hash;
|
|
594
|
+
if (usesManagedRuntimeDelivery && resolvedDecision?.action === 'ROLLBACK') {
|
|
595
|
+
const result = {
|
|
596
|
+
status: 'rollback',
|
|
597
|
+
reason: resolvedDecision.reason,
|
|
598
|
+
};
|
|
599
|
+
await applyAuthoritativeRollback(result.reason);
|
|
600
|
+
const status = getDownloadStatus(result);
|
|
601
|
+
if (status)
|
|
602
|
+
emitStatus(status);
|
|
603
|
+
return { result, status };
|
|
604
|
+
}
|
|
605
|
+
if (usesManagedRuntimeDelivery && !canUseResolvedTransport) {
|
|
606
|
+
emitStatus(MANAGED_LIST_INSTALL_NOT_AUTHORIZED_STATUS);
|
|
607
|
+
return {
|
|
608
|
+
result: { status: 'incompatible' },
|
|
609
|
+
status: MANAGED_LIST_INSTALL_NOT_AUTHORIZED_STATUS,
|
|
610
|
+
};
|
|
611
|
+
}
|
|
565
612
|
const result = canUseResolvedTransport
|
|
566
613
|
? await (0, downloadAndInstall_1.downloadUpdate)({
|
|
567
614
|
channelName: runtime.channelName,
|
|
@@ -578,12 +625,18 @@ async function installBundleFromListItem(bundle) {
|
|
|
578
625
|
baseHash: resolvedDecision.baseHash,
|
|
579
626
|
patchSet: resolvedDecision.patchSet,
|
|
580
627
|
fallback: resolvedDecision.fallback,
|
|
628
|
+
...(resolvedDecision.runtimeDelivery
|
|
629
|
+
? { runtimeDelivery: resolvedDecision.runtimeDelivery }
|
|
630
|
+
: {}),
|
|
581
631
|
},
|
|
582
632
|
}, emitStatus)
|
|
583
633
|
: await (0, downloadAndInstall_1.installBundle)(bundle.hash, downloadUrl, bundle.bundleVersion, bundle.version, bundle.runtimeVersion, {
|
|
584
634
|
channelName: runtime.channelName,
|
|
585
635
|
onStatusUpdate: emitStatus,
|
|
586
636
|
});
|
|
637
|
+
if (usesManagedRuntimeDelivery && result.status === 'rollback') {
|
|
638
|
+
await applyAuthoritativeRollback(result.reason);
|
|
639
|
+
}
|
|
587
640
|
if (result.status === 'staged') {
|
|
588
641
|
const status = `✅ v${bundle.bundleVersion} downloaded. Will apply on next launch or when you call applyUpdate.`;
|
|
589
642
|
emitStatus(status);
|
|
@@ -708,6 +761,10 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
|
|
|
708
761
|
return { status: 'disabled' };
|
|
709
762
|
}
|
|
710
763
|
await waitForStartupIfNeeded();
|
|
764
|
+
if ((0, loadConfig_1.isRuntimeDeliveryConfigured)(context_1.config.runtimeDelivery)) {
|
|
765
|
+
emitStatus(MANAGED_DIRECT_INSTALL_NOT_AUTHORIZED_STATUS, onStatusUpdate);
|
|
766
|
+
return { status: 'incompatible' };
|
|
767
|
+
}
|
|
711
768
|
return withBusy(async () => {
|
|
712
769
|
const result = await (0, downloadAndInstall_1.installBundle)(hash, downloadUrl, bundleVersion, version, runtimeVersion, {
|
|
713
770
|
channelName: runtime.channelName,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isArtifactCapabilityRejected(error: unknown): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isArtifactCapabilityRejected = isArtifactCapabilityRejected;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const CAPABILITY_HTTP_STATUS = /(?:^|\b)HTTP\s+(401|403)(?:\b|:)/i;
|
|
6
|
+
function readHttpStatus(error, depth = 0) {
|
|
7
|
+
if (depth > 5 || !error)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (typeof error === 'string') {
|
|
10
|
+
const match = CAPABILITY_HTTP_STATUS.exec(error);
|
|
11
|
+
return match ? Number(match[1]) : undefined;
|
|
12
|
+
}
|
|
13
|
+
if (typeof error !== 'object')
|
|
14
|
+
return undefined;
|
|
15
|
+
const value = error;
|
|
16
|
+
for (const candidate of [value.status, value.statusCode, value.httpStatus]) {
|
|
17
|
+
if (candidate === 401 || candidate === 403)
|
|
18
|
+
return candidate;
|
|
19
|
+
}
|
|
20
|
+
const messageStatus = readHttpStatus(value.message, depth + 1);
|
|
21
|
+
if (messageStatus)
|
|
22
|
+
return messageStatus;
|
|
23
|
+
const nested = (0, errors_1.isInstallPhaseError)(error)
|
|
24
|
+
? error.originalCause
|
|
25
|
+
: value.cause ?? value.error ?? value.userInfo;
|
|
26
|
+
return readHttpStatus(nested, depth + 1);
|
|
27
|
+
}
|
|
28
|
+
function isArtifactCapabilityRejected(error) {
|
|
29
|
+
return (0, errors_1.isInstallPhaseError)(error) &&
|
|
30
|
+
error.phase === 'download' &&
|
|
31
|
+
Boolean(readHttpStatus(error.originalCause));
|
|
32
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type RuntimeDeliveryAuthorityLease, type RuntimeDeliveryAuthorityLeaseV1, type RuntimeDeliveryPublicKey } from './types';
|
|
2
|
+
export declare const MAX_RUNTIME_DELIVERY_AUTHORITY_LEASE_MS = 15000;
|
|
3
|
+
export declare function verifyRuntimeDeliveryAuthorityLease(serializedJws: string, expectedManifestOrigin: string, publicKeys: Record<string, RuntimeDeliveryPublicKey>, now?: number): Promise<RuntimeDeliveryAuthorityLease | RuntimeDeliveryAuthorityLeaseV1>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_RUNTIME_DELIVERY_AUTHORITY_LEASE_MS = void 0;
|
|
4
|
+
exports.verifyRuntimeDeliveryAuthorityLease = verifyRuntimeDeliveryAuthorityLease;
|
|
5
|
+
const encoding_1 = require("./encoding");
|
|
6
|
+
const manifestVerifier_1 = require("./manifestVerifier");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
exports.MAX_RUNTIME_DELIVERY_AUTHORITY_LEASE_MS = 15000;
|
|
9
|
+
const MAX_CLOCK_SKEW_MS = 5000;
|
|
10
|
+
const isRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
11
|
+
function normalizeDnsOrIpv4Host(value) {
|
|
12
|
+
const host = value.toLowerCase();
|
|
13
|
+
if (host.length > 253 || !/^[a-z0-9.-]+$/.test(host))
|
|
14
|
+
return undefined;
|
|
15
|
+
const labels = host.split('.');
|
|
16
|
+
if (labels.some(label => !label ||
|
|
17
|
+
label.length > 63 ||
|
|
18
|
+
label.startsWith('-') ||
|
|
19
|
+
label.endsWith('-'))) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (labels.every(label => /^\d+$/.test(label))) {
|
|
23
|
+
if (labels.length !== 4 || labels.some(label => Number(label) > 255))
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return host;
|
|
27
|
+
}
|
|
28
|
+
function normalizeManifestOrigin(value) {
|
|
29
|
+
const match = /^https:\/\/([^/?#@]+)\/?$/i.exec(value);
|
|
30
|
+
if (!match)
|
|
31
|
+
return undefined;
|
|
32
|
+
const authority = match[1];
|
|
33
|
+
const authorityMatch = /^([^:]+)(?::(\d{1,5}))?$/.exec(authority);
|
|
34
|
+
if (!authorityMatch)
|
|
35
|
+
return undefined;
|
|
36
|
+
const host = normalizeDnsOrIpv4Host(authorityMatch[1]);
|
|
37
|
+
const port = authorityMatch[2] ? Number(authorityMatch[2]) : 443;
|
|
38
|
+
if (!host || port < 1 || port > 65535)
|
|
39
|
+
return undefined;
|
|
40
|
+
return `https://${host}${port === 443 ? '' : `:${port}`}`;
|
|
41
|
+
}
|
|
42
|
+
function authorityError(error, fallbackMessage) {
|
|
43
|
+
if (error instanceof manifestVerifier_1.RuntimeDeliveryManifestError) {
|
|
44
|
+
const mapped = {
|
|
45
|
+
body_too_large: 'authority_body_too_large',
|
|
46
|
+
invalid_signature: 'authority_invalid_signature',
|
|
47
|
+
unknown_key: 'authority_unknown_key',
|
|
48
|
+
}[error.code];
|
|
49
|
+
if (mapped)
|
|
50
|
+
return new manifestVerifier_1.RuntimeDeliveryManifestError(mapped, error.message, { cause: error });
|
|
51
|
+
}
|
|
52
|
+
return new manifestVerifier_1.RuntimeDeliveryManifestError('authority_invalid', fallbackMessage, { cause: error });
|
|
53
|
+
}
|
|
54
|
+
async function verifyRuntimeDeliveryAuthorityLease(serializedJws, expectedManifestOrigin, publicKeys, now = Date.now()) {
|
|
55
|
+
let payloadValue;
|
|
56
|
+
try {
|
|
57
|
+
payloadValue = await (0, manifestVerifier_1.verifyRuntimeDeliverySignedPayload)(serializedJws, types_1.RUNTIME_DELIVERY_AUTHORITY_LEASE_JWS_TYPE, publicKeys);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw authorityError(error, 'Runtime delivery authority lease signature is invalid');
|
|
61
|
+
}
|
|
62
|
+
let payload;
|
|
63
|
+
try {
|
|
64
|
+
payload = JSON.parse((0, encoding_1.decodeBase64UrlUtf8)(payloadValue));
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw authorityError(error, 'Runtime delivery authority lease payload is invalid');
|
|
68
|
+
}
|
|
69
|
+
const schemaVersion = isRecord(payload) ? payload.schemaVersion : undefined;
|
|
70
|
+
const expectedKeys = schemaVersion === 2
|
|
71
|
+
? ['clientAuthority', 'expiresAt', 'generatedAt', 'manifestOrigin', 'schemaVersion', 'type']
|
|
72
|
+
: ['expiresAt', 'generatedAt', 'manifestOrigin', 'schemaVersion', 'type'];
|
|
73
|
+
if (!isRecord(payload) ||
|
|
74
|
+
Object.keys(payload).sort().join(',') !== expectedKeys.join(',') ||
|
|
75
|
+
(payload.schemaVersion !== 1 && payload.schemaVersion !== 2) ||
|
|
76
|
+
payload.type !== 'publisher-lease' ||
|
|
77
|
+
typeof payload.manifestOrigin !== 'string' ||
|
|
78
|
+
typeof payload.generatedAt !== 'string' ||
|
|
79
|
+
typeof payload.expiresAt !== 'string' ||
|
|
80
|
+
(payload.schemaVersion === 2 &&
|
|
81
|
+
payload.clientAuthority !== 'enabled' &&
|
|
82
|
+
payload.clientAuthority !== 'disabled')) {
|
|
83
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_invalid', 'Runtime delivery authority lease payload is invalid');
|
|
84
|
+
}
|
|
85
|
+
const manifestOrigin = normalizeManifestOrigin(payload.manifestOrigin);
|
|
86
|
+
const expectedOrigin = normalizeManifestOrigin(expectedManifestOrigin);
|
|
87
|
+
if (!manifestOrigin || !expectedOrigin || manifestOrigin !== expectedOrigin) {
|
|
88
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_origin_mismatch', 'Runtime delivery authority lease manifest origin mismatch');
|
|
89
|
+
}
|
|
90
|
+
const generatedAt = Date.parse(payload.generatedAt);
|
|
91
|
+
const expiresAt = Date.parse(payload.expiresAt);
|
|
92
|
+
if (!Number.isFinite(generatedAt) ||
|
|
93
|
+
!Number.isFinite(expiresAt) ||
|
|
94
|
+
expiresAt <= generatedAt ||
|
|
95
|
+
expiresAt - generatedAt > exports.MAX_RUNTIME_DELIVERY_AUTHORITY_LEASE_MS ||
|
|
96
|
+
generatedAt > now + MAX_CLOCK_SKEW_MS) {
|
|
97
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_invalid', 'Runtime delivery authority lease validity window is invalid');
|
|
98
|
+
}
|
|
99
|
+
if (expiresAt <= now) {
|
|
100
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_expired', 'Runtime delivery authority lease is expired');
|
|
101
|
+
}
|
|
102
|
+
if (payload.schemaVersion === 2 && payload.clientAuthority === 'disabled') {
|
|
103
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_disabled', 'Runtime delivery client authority is disabled by the operator');
|
|
104
|
+
}
|
|
105
|
+
return payload;
|
|
106
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION = 1;
|
|
2
|
+
export declare const RUNTIME_DELIVERY_BOOTSTRAP_PATH: string;
|
|
3
|
+
export declare const RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = "!.bundle-drop/runtime-delivery.generated.json";
|
|
4
|
+
export type RuntimeDeliveryPublicKey = {
|
|
5
|
+
kty: 'EC';
|
|
6
|
+
crv: 'P-256';
|
|
7
|
+
x: string;
|
|
8
|
+
y: string;
|
|
9
|
+
};
|
|
10
|
+
export type RuntimeDeliveryConfig = {
|
|
11
|
+
manifestBaseUrl: string;
|
|
12
|
+
manifestAccessId: string;
|
|
13
|
+
publicKeys: Record<string, RuntimeDeliveryPublicKey>;
|
|
14
|
+
};
|
|
15
|
+
export type RuntimeDeliveryProjectIdentity = {
|
|
16
|
+
serverUrl: string;
|
|
17
|
+
orgSlug: string;
|
|
18
|
+
projectSlug: string;
|
|
19
|
+
projectId?: string;
|
|
20
|
+
orgId?: string;
|
|
21
|
+
};
|
|
22
|
+
export type GeneratedRuntimeDeliveryBootstrap = {
|
|
23
|
+
schemaVersion: typeof RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION;
|
|
24
|
+
project: RuntimeDeliveryProjectIdentity;
|
|
25
|
+
runtimeDelivery: RuntimeDeliveryConfig;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Accepts the current backend-authorized trust shape and the temporary legacy
|
|
29
|
+
* wire shape. Explicit legacy non-authoritative modes must never create a
|
|
30
|
+
* package-managed bootstrap.
|
|
31
|
+
*/
|
|
32
|
+
export declare function normalizeRuntimeDeliveryBootstrap(value: unknown): RuntimeDeliveryConfig | undefined;
|
|
33
|
+
export declare function createGeneratedRuntimeDeliveryBootstrap(params: {
|
|
34
|
+
identity: RuntimeDeliveryProjectIdentity;
|
|
35
|
+
runtimeDelivery: unknown;
|
|
36
|
+
}): GeneratedRuntimeDeliveryBootstrap | undefined;
|
|
37
|
+
export declare function parseGeneratedRuntimeDeliveryBootstrap(value: unknown, expectedIdentity?: RuntimeDeliveryProjectIdentity): GeneratedRuntimeDeliveryBootstrap;
|
|
38
|
+
export declare function runtimeDeliveryBootstrapPath(projectRoot: string): string;
|
|
39
|
+
export declare function addRuntimeDeliveryBootstrapGitignoreRules(content: string): string;
|
|
40
|
+
export declare function readGeneratedRuntimeDeliveryBootstrap(params: {
|
|
41
|
+
projectRoot: string;
|
|
42
|
+
expectedIdentity?: RuntimeDeliveryProjectIdentity;
|
|
43
|
+
}): GeneratedRuntimeDeliveryBootstrap | null;
|
|
44
|
+
export declare function serializeGeneratedRuntimeDeliveryBootstrap(bootstrap: GeneratedRuntimeDeliveryBootstrap): string;
|
|
45
|
+
export declare function writeGeneratedRuntimeDeliveryBootstrap(params: {
|
|
46
|
+
projectRoot: string;
|
|
47
|
+
bootstrap: GeneratedRuntimeDeliveryBootstrap;
|
|
48
|
+
}): Promise<string>;
|
|
49
|
+
export declare function removeGeneratedRuntimeDeliveryBootstrap(projectRoot: string): Promise<string | null>;
|
|
50
|
+
export declare function ensureRuntimeDeliveryBootstrapGitignore(projectRoot: string): Promise<string>;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH = exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION = void 0;
|
|
7
|
+
exports.normalizeRuntimeDeliveryBootstrap = normalizeRuntimeDeliveryBootstrap;
|
|
8
|
+
exports.createGeneratedRuntimeDeliveryBootstrap = createGeneratedRuntimeDeliveryBootstrap;
|
|
9
|
+
exports.parseGeneratedRuntimeDeliveryBootstrap = parseGeneratedRuntimeDeliveryBootstrap;
|
|
10
|
+
exports.runtimeDeliveryBootstrapPath = runtimeDeliveryBootstrapPath;
|
|
11
|
+
exports.addRuntimeDeliveryBootstrapGitignoreRules = addRuntimeDeliveryBootstrapGitignoreRules;
|
|
12
|
+
exports.readGeneratedRuntimeDeliveryBootstrap = readGeneratedRuntimeDeliveryBootstrap;
|
|
13
|
+
exports.serializeGeneratedRuntimeDeliveryBootstrap = serializeGeneratedRuntimeDeliveryBootstrap;
|
|
14
|
+
exports.writeGeneratedRuntimeDeliveryBootstrap = writeGeneratedRuntimeDeliveryBootstrap;
|
|
15
|
+
exports.removeGeneratedRuntimeDeliveryBootstrap = removeGeneratedRuntimeDeliveryBootstrap;
|
|
16
|
+
exports.ensureRuntimeDeliveryBootstrapGitignore = ensureRuntimeDeliveryBootstrapGitignore;
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const safe_file_transaction_1 = require("../CLI/scripts/safe-file-transaction");
|
|
20
|
+
exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION = 1;
|
|
21
|
+
exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH = path_1.default.join('.bundle-drop', 'runtime-delivery.generated.json');
|
|
22
|
+
exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = '!.bundle-drop/runtime-delivery.generated.json';
|
|
23
|
+
const RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_BLOCK = [
|
|
24
|
+
'# Bundle Drop: commit the public trust bootstrap; ignore generated runtime artifacts.',
|
|
25
|
+
'!.bundle-drop/',
|
|
26
|
+
'.bundle-drop/*',
|
|
27
|
+
exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER,
|
|
28
|
+
].join('\n');
|
|
29
|
+
const isRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
30
|
+
const normalizeUrl = (value) => value.trim().replace(/\/+$/, '');
|
|
31
|
+
const isP256Coordinate = (value) => typeof value === 'string' &&
|
|
32
|
+
/^[A-Za-z0-9_-]{43}$/.test(value) &&
|
|
33
|
+
Buffer.from(value, 'base64url').length === 32;
|
|
34
|
+
const normalizeHttpUrl = (value) => {
|
|
35
|
+
if (typeof value !== 'string' || !value.trim())
|
|
36
|
+
return null;
|
|
37
|
+
try {
|
|
38
|
+
const url = new URL(value);
|
|
39
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:')
|
|
40
|
+
return null;
|
|
41
|
+
return normalizeUrl(value);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const normalizePublicKeys = (value) => {
|
|
48
|
+
if (!isRecord(value))
|
|
49
|
+
return null;
|
|
50
|
+
const entries = Object.entries(value);
|
|
51
|
+
if (!entries.length)
|
|
52
|
+
return null;
|
|
53
|
+
const publicKeys = {};
|
|
54
|
+
for (const [kid, candidate] of entries) {
|
|
55
|
+
if (!kid.trim() || !isRecord(candidate))
|
|
56
|
+
return null;
|
|
57
|
+
if (Object.keys(candidate).sort().join(',') !== 'crv,kty,x,y')
|
|
58
|
+
return null;
|
|
59
|
+
if (candidate.kty !== 'EC' ||
|
|
60
|
+
candidate.crv !== 'P-256' ||
|
|
61
|
+
!isP256Coordinate(candidate.x) ||
|
|
62
|
+
!isP256Coordinate(candidate.y)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
publicKeys[kid] = {
|
|
66
|
+
kty: 'EC',
|
|
67
|
+
crv: 'P-256',
|
|
68
|
+
x: candidate.x,
|
|
69
|
+
y: candidate.y,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return publicKeys;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Accepts the current backend-authorized trust shape and the temporary legacy
|
|
76
|
+
* wire shape. Explicit legacy non-authoritative modes must never create a
|
|
77
|
+
* package-managed bootstrap.
|
|
78
|
+
*/
|
|
79
|
+
function normalizeRuntimeDeliveryBootstrap(value) {
|
|
80
|
+
if (!isRecord(value))
|
|
81
|
+
return undefined;
|
|
82
|
+
if (value.mode !== undefined && value.mode !== 'v2')
|
|
83
|
+
return undefined;
|
|
84
|
+
const manifestBaseUrl = normalizeHttpUrl(value.manifestBaseUrl);
|
|
85
|
+
if (!manifestBaseUrl)
|
|
86
|
+
return undefined;
|
|
87
|
+
if (typeof value.manifestAccessId !== 'string' ||
|
|
88
|
+
!/^[A-Za-z0-9_-]{22,128}$/.test(value.manifestAccessId)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const publicKeys = normalizePublicKeys(value.publicKeys);
|
|
92
|
+
if (!publicKeys)
|
|
93
|
+
return undefined;
|
|
94
|
+
return {
|
|
95
|
+
manifestBaseUrl,
|
|
96
|
+
manifestAccessId: value.manifestAccessId,
|
|
97
|
+
publicKeys,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function createGeneratedRuntimeDeliveryBootstrap(params) {
|
|
101
|
+
const runtimeDelivery = normalizeRuntimeDeliveryBootstrap(params.runtimeDelivery);
|
|
102
|
+
const serverUrl = normalizeHttpUrl(params.identity.serverUrl);
|
|
103
|
+
const orgSlug = params.identity.orgSlug.trim();
|
|
104
|
+
const projectSlug = params.identity.projectSlug.trim();
|
|
105
|
+
const projectId = params.identity.projectId?.trim();
|
|
106
|
+
const orgId = params.identity.orgId?.trim();
|
|
107
|
+
if (!runtimeDelivery || !serverUrl || !orgSlug || !projectSlug)
|
|
108
|
+
return undefined;
|
|
109
|
+
if (Boolean(projectId) !== Boolean(orgId))
|
|
110
|
+
return undefined;
|
|
111
|
+
return {
|
|
112
|
+
schemaVersion: exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION,
|
|
113
|
+
project: {
|
|
114
|
+
serverUrl,
|
|
115
|
+
orgSlug,
|
|
116
|
+
projectSlug,
|
|
117
|
+
...(projectId && orgId ? { projectId, orgId } : {}),
|
|
118
|
+
},
|
|
119
|
+
runtimeDelivery,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function parseGeneratedRuntimeDeliveryBootstrap(value, expectedIdentity) {
|
|
123
|
+
if (!isRecord(value) || value.schemaVersion !== exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION) {
|
|
124
|
+
throw new Error(`Runtime delivery bootstrap must use schemaVersion ${exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION}.`);
|
|
125
|
+
}
|
|
126
|
+
if (!isRecord(value.project)) {
|
|
127
|
+
throw new Error('Runtime delivery bootstrap is missing its project identity.');
|
|
128
|
+
}
|
|
129
|
+
const hasProjectId = Object.prototype.hasOwnProperty.call(value.project, 'projectId');
|
|
130
|
+
const hasOrgId = Object.prototype.hasOwnProperty.call(value.project, 'orgId');
|
|
131
|
+
if (hasProjectId !== hasOrgId ||
|
|
132
|
+
(hasProjectId &&
|
|
133
|
+
(typeof value.project.projectId !== 'string' ||
|
|
134
|
+
!value.project.projectId.trim() ||
|
|
135
|
+
typeof value.project.orgId !== 'string' ||
|
|
136
|
+
!value.project.orgId.trim()))) {
|
|
137
|
+
throw new Error('Runtime delivery bootstrap contains an invalid stable project identity.');
|
|
138
|
+
}
|
|
139
|
+
const bootstrap = createGeneratedRuntimeDeliveryBootstrap({
|
|
140
|
+
identity: {
|
|
141
|
+
serverUrl: typeof value.project.serverUrl === 'string' ? value.project.serverUrl : '',
|
|
142
|
+
orgSlug: typeof value.project.orgSlug === 'string' ? value.project.orgSlug : '',
|
|
143
|
+
projectSlug: typeof value.project.projectSlug === 'string' ? value.project.projectSlug : '',
|
|
144
|
+
projectId: typeof value.project.projectId === 'string' ? value.project.projectId : undefined,
|
|
145
|
+
orgId: typeof value.project.orgId === 'string' ? value.project.orgId : undefined,
|
|
146
|
+
},
|
|
147
|
+
runtimeDelivery: value.runtimeDelivery,
|
|
148
|
+
});
|
|
149
|
+
if (!bootstrap) {
|
|
150
|
+
throw new Error('Runtime delivery bootstrap contains invalid trust configuration.');
|
|
151
|
+
}
|
|
152
|
+
if (expectedIdentity) {
|
|
153
|
+
const expected = {
|
|
154
|
+
serverUrl: normalizeUrl(expectedIdentity.serverUrl),
|
|
155
|
+
orgSlug: expectedIdentity.orgSlug.trim(),
|
|
156
|
+
projectSlug: expectedIdentity.projectSlug.trim(),
|
|
157
|
+
};
|
|
158
|
+
if (bootstrap.project.serverUrl !== expected.serverUrl ||
|
|
159
|
+
bootstrap.project.orgSlug !== expected.orgSlug ||
|
|
160
|
+
bootstrap.project.projectSlug !== expected.projectSlug ||
|
|
161
|
+
(expectedIdentity.projectId !== undefined &&
|
|
162
|
+
bootstrap.project.projectId !== expectedIdentity.projectId.trim()) ||
|
|
163
|
+
(expectedIdentity.orgId !== undefined &&
|
|
164
|
+
bootstrap.project.orgId !== expectedIdentity.orgId.trim())) {
|
|
165
|
+
throw new Error('Runtime delivery bootstrap belongs to a different server, organization, or project.');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return bootstrap;
|
|
169
|
+
}
|
|
170
|
+
function runtimeDeliveryBootstrapPath(projectRoot) {
|
|
171
|
+
return path_1.default.join(projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH);
|
|
172
|
+
}
|
|
173
|
+
function addRuntimeDeliveryBootstrapGitignoreRules(content) {
|
|
174
|
+
if (content.includes(exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER))
|
|
175
|
+
return content;
|
|
176
|
+
const prefix = content.trimEnd();
|
|
177
|
+
return `${prefix}${prefix ? '\n\n' : ''}${RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_BLOCK}\n`;
|
|
178
|
+
}
|
|
179
|
+
function readGeneratedRuntimeDeliveryBootstrap(params) {
|
|
180
|
+
const bootstrapPath = runtimeDeliveryBootstrapPath(params.projectRoot);
|
|
181
|
+
if (!fs_extra_1.default.existsSync(bootstrapPath))
|
|
182
|
+
return null;
|
|
183
|
+
let value;
|
|
184
|
+
try {
|
|
185
|
+
value = fs_extra_1.default.readJsonSync(bootstrapPath);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
throw new Error(`Runtime delivery bootstrap is not valid JSON: ${bootstrapPath}`);
|
|
189
|
+
}
|
|
190
|
+
return parseGeneratedRuntimeDeliveryBootstrap(value, params.expectedIdentity);
|
|
191
|
+
}
|
|
192
|
+
function serializeGeneratedRuntimeDeliveryBootstrap(bootstrap) {
|
|
193
|
+
return `${JSON.stringify(bootstrap, null, 2)}\n`;
|
|
194
|
+
}
|
|
195
|
+
async function writeGeneratedRuntimeDeliveryBootstrap(params) {
|
|
196
|
+
const bootstrapPath = runtimeDeliveryBootstrapPath(params.projectRoot);
|
|
197
|
+
(0, safe_file_transaction_1.writeProjectFileAtomically)(params.projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH, serializeGeneratedRuntimeDeliveryBootstrap(params.bootstrap));
|
|
198
|
+
return bootstrapPath;
|
|
199
|
+
}
|
|
200
|
+
async function removeGeneratedRuntimeDeliveryBootstrap(projectRoot) {
|
|
201
|
+
const bootstrapPath = runtimeDeliveryBootstrapPath(projectRoot);
|
|
202
|
+
if (!(0, safe_file_transaction_1.inspectProjectFile)(projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH).exists)
|
|
203
|
+
return null;
|
|
204
|
+
(0, safe_file_transaction_1.removeProjectFile)(projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH);
|
|
205
|
+
return bootstrapPath;
|
|
206
|
+
}
|
|
207
|
+
async function ensureRuntimeDeliveryBootstrapGitignore(projectRoot) {
|
|
208
|
+
const gitignorePath = path_1.default.join(projectRoot, '.gitignore');
|
|
209
|
+
const original = fs_extra_1.default.existsSync(gitignorePath)
|
|
210
|
+
? await fs_extra_1.default.readFile(gitignorePath, 'utf8')
|
|
211
|
+
: '';
|
|
212
|
+
const updated = addRuntimeDeliveryBootstrapGitignoreRules(original);
|
|
213
|
+
if (updated !== original) {
|
|
214
|
+
(0, safe_file_transaction_1.writeProjectFileAtomically)(projectRoot, '.gitignore', updated);
|
|
215
|
+
}
|
|
216
|
+
return gitignorePath;
|
|
217
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const RUNTIME_DELIVERY_DIAGNOSTIC_NAMES: readonly ["manifest_hit", "dynamic_manifest", "origin_fallback", "invalid_signature", "unknown_key", "lane_mismatch", "generation_regression", "generation_equivocation", "manifest_http_error", "manifest_network_error", "manifest_timeout", "manifest_too_large", "manifest_invalid", "manifest_stream_unavailable", "authority_lease_http_error", "authority_lease_network_error", "authority_lease_timeout", "authority_lease_too_large", "authority_lease_invalid", "authority_lease_invalid_signature", "authority_lease_unknown_key", "authority_lease_expired", "authority_lease_origin_mismatch", "authority_lease_disabled"];
|
|
2
|
+
export type RuntimeDeliveryDiagnosticName = typeof RUNTIME_DELIVERY_DIAGNOSTIC_NAMES[number];
|
|
3
|
+
export type RuntimeDeliveryDiagnosticDetails = {
|
|
4
|
+
channelName?: string;
|
|
5
|
+
reason?: string;
|
|
6
|
+
status?: number;
|
|
7
|
+
};
|
|
8
|
+
export type RuntimeDeliveryDiagnosticEvent = {
|
|
9
|
+
name: RuntimeDeliveryDiagnosticName;
|
|
10
|
+
count: number;
|
|
11
|
+
timestamp: string;
|
|
12
|
+
details?: RuntimeDeliveryDiagnosticDetails;
|
|
13
|
+
};
|
|
14
|
+
export type RuntimeDeliveryDiagnosticCounters = Record<RuntimeDeliveryDiagnosticName, number>;
|
|
15
|
+
export declare function recordRuntimeDeliveryDiagnostic(name: RuntimeDeliveryDiagnosticName, details?: RuntimeDeliveryDiagnosticDetails): void;
|
|
16
|
+
export declare function getRuntimeDeliveryDiagnosticCounters(): RuntimeDeliveryDiagnosticCounters;
|
|
17
|
+
export declare function resetRuntimeDeliveryDiagnosticsForTests(): void;
|