@tapi-dev/sdk 0.1.11 → 0.1.12
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/dist/cli.d.ts +2 -0
- package/dist/cli.js +38 -0
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export interface ServiceStatus {
|
|
|
71
71
|
pathName?: string;
|
|
72
72
|
installedVersion?: string;
|
|
73
73
|
}
|
|
74
|
+
type FetchLike = typeof fetch;
|
|
74
75
|
export declare function runCli(argv?: string[]): Promise<number>;
|
|
75
76
|
export declare function parseStudioOptions(args: string[]): StudioCliOptions;
|
|
76
77
|
export declare function installedServiceVersionFromPathName(pathName: string): string | undefined;
|
|
@@ -94,5 +95,6 @@ export declare function getStudioExecutableCandidates(): string[];
|
|
|
94
95
|
export declare function validateStudioManifest(input: unknown): StudioReleaseManifest;
|
|
95
96
|
export declare function validateServiceReleaseManifest(input: unknown): ServiceReleaseManifest;
|
|
96
97
|
export declare function compareVersions(left: string, right: string): number;
|
|
98
|
+
export declare function waitForHttpOk(url: string, timeoutMs?: number, intervalMs?: number, fetchImpl?: FetchLike): Promise<void>;
|
|
97
99
|
export declare function findPortableStudioServerExe(releaseDir: string, manifest: StudioReleaseManifest): string | undefined;
|
|
98
100
|
export {};
|
package/dist/cli.js
CHANGED
|
@@ -20,6 +20,8 @@ const DEFAULT_FIREBASE_API_KEY = "AIzaSyCDZR8lWyVQcWYfFdNZa4vuL4IWEC0h6gE";
|
|
|
20
20
|
const DEFAULT_CHANNEL = "pilot";
|
|
21
21
|
const SUPPORTED_STUDIO_PLATFORM = "windows-x86_64";
|
|
22
22
|
const DEFAULT_INSTALL_AUTH_TIMEOUT_MS = 120_000;
|
|
23
|
+
const PORTABLE_STUDIO_SERVER_READY_TIMEOUT_MS = 30_000;
|
|
24
|
+
const PORTABLE_STUDIO_SERVER_READY_INTERVAL_MS = 250;
|
|
23
25
|
const MAX_WIDE_EVENT_PROCESS_ROOTS = 5;
|
|
24
26
|
class StudioInstallApprovalError extends Error {
|
|
25
27
|
code;
|
|
@@ -1028,10 +1030,19 @@ async function fetchServiceManifestForEnsure(options) {
|
|
|
1028
1030
|
await event.finish(false, {
|
|
1029
1031
|
error: errorDetails(error),
|
|
1030
1032
|
});
|
|
1033
|
+
if (isProtectedServiceManifestAuthError(error)) {
|
|
1034
|
+
throw error;
|
|
1035
|
+
}
|
|
1031
1036
|
console.warn(`Could not check for Tapi Service updates: ${formatError(error)}`);
|
|
1032
1037
|
return null;
|
|
1033
1038
|
}
|
|
1034
1039
|
}
|
|
1040
|
+
function isProtectedServiceManifestAuthError(error) {
|
|
1041
|
+
const message = formatError(error);
|
|
1042
|
+
return (message.includes("Failed to fetch protected Tapi Service manifest: HTTP 401")
|
|
1043
|
+
|| message.includes("Failed to fetch protected Tapi Service manifest: HTTP 403")
|
|
1044
|
+
|| message.includes("Worker bootstrap secret required"));
|
|
1045
|
+
}
|
|
1035
1046
|
export function installedServiceVersionFromPathName(pathName) {
|
|
1036
1047
|
const normalized = String(pathName || "").replace(/\\/g, "/");
|
|
1037
1048
|
const parts = normalized
|
|
@@ -1844,9 +1855,36 @@ async function launchPortableStudioServer(exePath, options) {
|
|
|
1844
1855
|
});
|
|
1845
1856
|
child.unref();
|
|
1846
1857
|
const url = `http://${host}:${port}`;
|
|
1858
|
+
await waitForHttpOk(`${url}/healthz`, PORTABLE_STUDIO_SERVER_READY_TIMEOUT_MS, PORTABLE_STUDIO_SERVER_READY_INTERVAL_MS);
|
|
1847
1859
|
openBrowser(url);
|
|
1848
1860
|
console.log(`Opened Tapi Studio: ${url}`);
|
|
1849
1861
|
}
|
|
1862
|
+
export async function waitForHttpOk(url, timeoutMs = PORTABLE_STUDIO_SERVER_READY_TIMEOUT_MS, intervalMs = PORTABLE_STUDIO_SERVER_READY_INTERVAL_MS, fetchImpl = fetch) {
|
|
1863
|
+
const startedAt = performance.now();
|
|
1864
|
+
let lastError = "";
|
|
1865
|
+
while (performance.now() - startedAt < timeoutMs) {
|
|
1866
|
+
try {
|
|
1867
|
+
const response = await fetchImpl(url, {
|
|
1868
|
+
headers: { Accept: "application/json" },
|
|
1869
|
+
});
|
|
1870
|
+
if (response.ok) {
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
lastError = `HTTP ${response.status}`;
|
|
1874
|
+
}
|
|
1875
|
+
catch (error) {
|
|
1876
|
+
lastError = formatError(error);
|
|
1877
|
+
}
|
|
1878
|
+
await delay(intervalMs);
|
|
1879
|
+
}
|
|
1880
|
+
const suffix = lastError ? ` Last error: ${lastError}.` : "";
|
|
1881
|
+
throw new Error(`Tapi Studio server did not become ready at ${url} within ${Math.ceil(timeoutMs / 1000)}s.${suffix}`);
|
|
1882
|
+
}
|
|
1883
|
+
function delay(ms) {
|
|
1884
|
+
return new Promise((resolvePromise) => {
|
|
1885
|
+
setTimeout(resolvePromise, Math.max(0, ms));
|
|
1886
|
+
});
|
|
1887
|
+
}
|
|
1850
1888
|
async function chooseStudioPort(preferred = 18766) {
|
|
1851
1889
|
for (let port = preferred; port < preferred + 25; port += 1) {
|
|
1852
1890
|
if (await isPortAvailable(port)) {
|