Merge upstream/main into josh/desktop-wsl-parallel-backends (auth migration)
Brings in upstream's desktop-auth to Clerk-bridge migration (#3092) plus 9 other commits. Resolution preserves the WSL parallel-backends work while adopting the new primary-auth flow. Contracts / IPC: keep our plural getLocalEnvironmentBootstraps; add upstream's new getLocalEnvironmentBearerToken (primary bearer token) across the bridge, preload, and the IPC channel / method / handlers. Desktop: - DesktopLocalEnvironmentAuth (upstream's new primary-auth service) now reads the primary instance from our DesktopBackendPool instead of the removed legacy DesktopBackendManager. - main.ts composes both our WSL backend layer and the new local-environment-auth and Clerk layers. - DesktopWindow adopts upstream's local-client window loading (getDesktopUrl / t3:// scheme) rather than loading the backend URL, dropping the now-obsolete backend-URL plumbing. The "Connecting to WSL" splash is kept, re-pointed onto the existing backend-ready latch (upstream's DesktopState.backendReady addition did not land in this merge; the backend pool drives readiness through handleBackendReady / handleBackendNotReady). Web: keep our Layer.effect platform source (primary plus WSL secondaries); the primary now authenticates via upstream's primaryEnvironmentHttpLayer and the secondaries via FetchHttpClient. Verified: typecheck (web, desktop), web tests (connection / provider / authBootstrap / desktopAuth), desktop tests (DesktopWindow splash, DesktopLocalEnvironmentAuth), and lint all pass.
This commit is contained in:
commit
bb6fafc16a
115 files changed
+3070
-3804
No files matched your search
@@ -8,7 +8,11 @@ import * as Option from "effect/Option";
|
||||
import {
|
||||
createStageWorkspaceConfig,
|
||||
createStagePnpmConfig,
|
||||
createBuildConfig,
|
||||
DESKTOP_ASAR_UNPACK,
|
||||
renderMacPasskeyEntitlements,
|
||||
resolveClerkPasskeyNativeArtifacts,
|
||||
resolveMacPasskeySigningConfiguration,
|
||||
resolveDesktopRuntimeDependencies,
|
||||
resolveFffNativeDependencies,
|
||||
resolveBuildOptions,
|
||||
@@ -185,6 +189,86 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
assert.deepStrictEqual(DESKTOP_ASAR_UNPACK, ["node_modules/@ff-labs/fff-bin-*/**/*"]);
|
||||
});
|
||||
|
||||
it("derives macOS passkey signing configuration from the Clerk publishable key", () => {
|
||||
const configuration = resolveMacPasskeySigningConfiguration({
|
||||
T3CODE_APPLE_TEAM_ID: "abc1234567",
|
||||
T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
|
||||
T3CODE_CLERK_PUBLISHABLE_KEY: `pk_test_${btoa("example.clerk.accounts.dev$")}`,
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(configuration, {
|
||||
appId: "com.t3tools.t3code",
|
||||
teamId: "ABC1234567",
|
||||
rpDomains: ["example.clerk.accounts.dev"],
|
||||
provisioningProfilePath: "/tmp/t3code.provisionprofile",
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes explicit macOS passkey RP domains and renders required entitlements", () => {
|
||||
const configuration = resolveMacPasskeySigningConfiguration({
|
||||
T3CODE_APPLE_TEAM_ID: "ABC1234567",
|
||||
T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
|
||||
T3CODE_CLERK_PASSKEY_RP_DOMAINS:
|
||||
" Clerk.Example.com,example.clerk.accounts.dev,clerk.example.com ",
|
||||
});
|
||||
const entitlements = renderMacPasskeyEntitlements(configuration);
|
||||
|
||||
assert.deepStrictEqual(configuration.rpDomains, [
|
||||
"clerk.example.com",
|
||||
"example.clerk.accounts.dev",
|
||||
]);
|
||||
assert.include(entitlements, "<string>ABC1234567.com.t3tools.t3code</string>");
|
||||
assert.include(entitlements, "<string>webcredentials:clerk.example.com</string>");
|
||||
assert.include(entitlements, "<string>webcredentials:example.clerk.accounts.dev</string>");
|
||||
assert.include(entitlements, "<key>com.apple.security.cs.allow-jit</key>");
|
||||
});
|
||||
|
||||
it("rejects incomplete macOS passkey signing configuration", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
resolveMacPasskeySigningConfiguration({
|
||||
T3CODE_APPLE_TEAM_ID: "ABC1234567",
|
||||
T3CODE_CLERK_PASSKEY_RP_DOMAINS: "example.clerk.accounts.dev",
|
||||
}),
|
||||
/T3CODE_MACOS_PROVISIONING_PROFILE/u,
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
resolveMacPasskeySigningConfiguration({
|
||||
T3CODE_APPLE_TEAM_ID: "ABC1234567",
|
||||
T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
|
||||
T3CODE_CLERK_PASSKEY_RP_DOMAINS: "https://example.clerk.accounts.dev/path",
|
||||
}),
|
||||
/Invalid passkey RP domain/u,
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
resolveMacPasskeySigningConfiguration({
|
||||
T3CODE_APPLE_TEAM_ID: "ABC1234567",
|
||||
T3CODE_MACOS_PROVISIONING_PROFILE: "/tmp/t3code.provisionprofile",
|
||||
T3CODE_CLERK_PASSKEY_RP_DOMAINS: "example.clerk.accounts.dev:8443",
|
||||
}),
|
||||
/Invalid passkey RP domain/u,
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("adds passkey entitlements and both renderer protocols to signed macOS builds", () =>
|
||||
Effect.gen(function* () {
|
||||
const config = yield* createBuildConfig("mac", "dmg", "1.2.3", true, false, undefined, {
|
||||
entitlementsPath: "/tmp/entitlements.mac.plist",
|
||||
provisioningProfilePath: "/tmp/t3code.provisionprofile",
|
||||
});
|
||||
|
||||
const mac = config.mac as Record<string, unknown>;
|
||||
assert.equal(config.appId, "com.t3tools.t3code");
|
||||
assert.equal(mac.entitlements, "/tmp/entitlements.mac.plist");
|
||||
assert.equal(mac.provisioningProfile, "/tmp/t3code.provisionprofile");
|
||||
assert.deepStrictEqual(mac.protocols, [
|
||||
{ name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
|
||||
]);
|
||||
}).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
|
||||
);
|
||||
|
||||
it("promotes target fff binaries to direct staged dependencies", () => {
|
||||
assert.deepStrictEqual(resolveFffNativeDependencies("mac", "arm64", "0.9.4"), {
|
||||
"@ff-labs/fff-bin-darwin-arm64": "0.9.4",
|
||||
@@ -202,6 +286,26 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves target Clerk passkey native artifacts", () => {
|
||||
assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("mac", "universal"), [
|
||||
{
|
||||
packageName: "@clerk/electron-passkeys-darwin-arm64",
|
||||
binaryFileName: "electron-passkeys.darwin-arm64.node",
|
||||
},
|
||||
{
|
||||
packageName: "@clerk/electron-passkeys-darwin-x64",
|
||||
binaryFileName: "electron-passkeys.darwin-x64.node",
|
||||
},
|
||||
]);
|
||||
assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("win", "x64"), [
|
||||
{
|
||||
packageName: "@clerk/electron-passkeys-win32-x64-msvc",
|
||||
binaryFileName: "electron-passkeys.win32-x64-msvc.node",
|
||||
},
|
||||
]);
|
||||
assert.deepStrictEqual(resolveClerkPasskeyNativeArtifacts("linux", "x64"), []);
|
||||
});
|
||||
|
||||
it("falls back to the default mock update port when the configured port is blank", () => {
|
||||
assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
|
||||
assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
import { fromYaml } from "@t3tools/shared/schemaYaml";
|
||||
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
|
||||
import { clerkFrontendApiHostnameFromPublishableKey } from "@t3tools/shared/relayAuth";
|
||||
import { resolveSpawnCommand } from "@t3tools/shared/shell";
|
||||
import rootPackageJson from "../package.json" with { type: "json" };
|
||||
import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
|
||||
@@ -9,6 +12,7 @@ import serverPackageJson from "../apps/server/package.json" with { type: "json"
|
||||
|
||||
import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
|
||||
import { getDefaultBuildArch } from "./lib/build-target-arch.ts";
|
||||
import { loadRepoEnv } from "./lib/public-config.ts";
|
||||
import { resolveCatalogDependencies } from "./lib/resolve-catalog.ts";
|
||||
|
||||
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
||||
@@ -27,6 +31,8 @@ import { Command, Flag } from "effect/unstable/cli";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
const LINUX_ICON_SIZES = [16, 22, 24, 32, 48, 64, 128, 256, 512] as const;
|
||||
const DESKTOP_APP_ID = "com.t3tools.t3code";
|
||||
const APPLE_TEAM_ID_PATTERN = /^[A-Z0-9]{10}$/u;
|
||||
|
||||
const BuildPlatform = Schema.Literals(["mac", "linux", "win"]);
|
||||
const BuildArch = Schema.Literals(["arm64", "x64", "universal"]);
|
||||
@@ -299,6 +305,121 @@ interface StagePackageJson {
|
||||
export const STAGE_INSTALL_ARGS = ["install", "--prod"] as const;
|
||||
export const DESKTOP_ASAR_UNPACK = ["node_modules/@ff-labs/fff-bin-*/**/*"] as const;
|
||||
|
||||
export interface MacPasskeySigningConfiguration {
|
||||
readonly appId: string;
|
||||
readonly teamId: string;
|
||||
readonly rpDomains: readonly string[];
|
||||
readonly provisioningProfilePath: string;
|
||||
}
|
||||
|
||||
function normalizePasskeyRpDomain(value: string): string {
|
||||
const normalized = value.trim().toLowerCase();
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(`https://${normalized}`);
|
||||
} catch {
|
||||
throw new Error(`Invalid passkey RP domain: ${value}`);
|
||||
}
|
||||
|
||||
if (
|
||||
normalized.length === 0 ||
|
||||
parsed.host !== normalized ||
|
||||
parsed.username.length > 0 ||
|
||||
parsed.password.length > 0 ||
|
||||
parsed.port.length > 0 ||
|
||||
parsed.pathname !== "/" ||
|
||||
parsed.search.length > 0 ||
|
||||
parsed.hash.length > 0
|
||||
) {
|
||||
throw new Error(`Invalid passkey RP domain: ${value}`);
|
||||
}
|
||||
|
||||
return parsed.hostname;
|
||||
}
|
||||
|
||||
export function resolveMacPasskeySigningConfiguration(
|
||||
env: Readonly<Record<string, string | undefined>>,
|
||||
): MacPasskeySigningConfiguration {
|
||||
const teamId = env.T3CODE_APPLE_TEAM_ID?.trim().toUpperCase() ?? "";
|
||||
if (!APPLE_TEAM_ID_PATTERN.test(teamId)) {
|
||||
throw new Error("T3CODE_APPLE_TEAM_ID must be a 10-character Apple Developer Team ID.");
|
||||
}
|
||||
|
||||
const provisioningProfilePath = env.T3CODE_MACOS_PROVISIONING_PROFILE?.trim() ?? "";
|
||||
if (provisioningProfilePath.length === 0) {
|
||||
throw new Error(
|
||||
"T3CODE_MACOS_PROVISIONING_PROFILE must point to an Associated Domains provisioning profile.",
|
||||
);
|
||||
}
|
||||
|
||||
const configuredRpDomains = env.T3CODE_CLERK_PASSKEY_RP_DOMAINS?.trim();
|
||||
let rpDomains: readonly string[];
|
||||
if (configuredRpDomains) {
|
||||
rpDomains = configuredRpDomains.split(",").map(normalizePasskeyRpDomain);
|
||||
} else {
|
||||
const publishableKey = env.T3CODE_CLERK_PUBLISHABLE_KEY?.trim();
|
||||
if (!publishableKey) {
|
||||
throw new Error(
|
||||
"T3CODE_CLERK_PUBLISHABLE_KEY or T3CODE_CLERK_PASSKEY_RP_DOMAINS is required for signed macOS passkey builds.",
|
||||
);
|
||||
}
|
||||
rpDomains = [
|
||||
normalizePasskeyRpDomain(clerkFrontendApiHostnameFromPublishableKey(publishableKey)),
|
||||
];
|
||||
}
|
||||
|
||||
const uniqueRpDomains = [...new Set(rpDomains)];
|
||||
if (uniqueRpDomains.length === 0) {
|
||||
throw new Error("At least one Clerk passkey RP domain is required.");
|
||||
}
|
||||
|
||||
return {
|
||||
appId: DESKTOP_APP_ID,
|
||||
teamId,
|
||||
rpDomains: uniqueRpDomains,
|
||||
provisioningProfilePath,
|
||||
};
|
||||
}
|
||||
|
||||
function escapeXml(value: string): string {
|
||||
return value
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">")
|
||||
.replaceAll('"', """)
|
||||
.replaceAll("'", "'");
|
||||
}
|
||||
|
||||
export function renderMacPasskeyEntitlements(
|
||||
configuration: MacPasskeySigningConfiguration,
|
||||
): string {
|
||||
const associatedDomains = configuration.rpDomains
|
||||
.map((domain) => ` <string>webcredentials:${escapeXml(domain)}</string>`)
|
||||
.join("\n");
|
||||
|
||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.application-identifier</key>
|
||||
<string>${escapeXml(`${configuration.teamId}.${configuration.appId}`)}</string>
|
||||
<key>com.apple.developer.team-identifier</key>
|
||||
<string>${escapeXml(configuration.teamId)}</string>
|
||||
<key>com.apple.developer.associated-domains</key>
|
||||
<array>
|
||||
${associatedDomains}
|
||||
</array>
|
||||
<key>com.apple.security.cs.allow-jit</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.disable-library-validation</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
`;
|
||||
}
|
||||
|
||||
export function resolveFffNativeDependencies(
|
||||
platform: typeof BuildPlatform.Type,
|
||||
arch: typeof BuildArch.Type,
|
||||
@@ -325,6 +446,63 @@ export function resolveFffNativeDependencies(
|
||||
);
|
||||
}
|
||||
|
||||
export interface ClerkPasskeyNativeArtifact {
|
||||
readonly packageName: string;
|
||||
readonly binaryFileName: string;
|
||||
}
|
||||
|
||||
export function resolveClerkPasskeyNativeArtifacts(
|
||||
platform: typeof BuildPlatform.Type,
|
||||
arch: typeof BuildArch.Type,
|
||||
): readonly ClerkPasskeyNativeArtifact[] {
|
||||
const architectures = arch === "universal" ? (["arm64", "x64"] as const) : [arch];
|
||||
|
||||
if (platform === "mac") {
|
||||
return architectures.map((architecture) => ({
|
||||
packageName: `@clerk/electron-passkeys-darwin-${architecture}`,
|
||||
binaryFileName: `electron-passkeys.darwin-${architecture}.node`,
|
||||
}));
|
||||
}
|
||||
|
||||
if (platform === "win") {
|
||||
return architectures.map((architecture) => ({
|
||||
packageName: `@clerk/electron-passkeys-win32-${architecture}-msvc`,
|
||||
binaryFileName: `electron-passkeys.win32-${architecture}-msvc.node`,
|
||||
}));
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
// pnpm nests the architecture package under @clerk/electron-passkeys, while electron-builder only
|
||||
// retains collected top-level dependencies. The SDK loader checks beside index.js first, so stage
|
||||
// the binary there and let electron-builder's native-addon handling unpack it from the ASAR.
|
||||
const stageClerkPasskeyNativeBinaries = Effect.fn("stageClerkPasskeyNativeBinaries")(function* (
|
||||
stageAppDir: string,
|
||||
platform: typeof BuildPlatform.Type,
|
||||
arch: typeof BuildArch.Type,
|
||||
) {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const packageEntryPath = yield* fs.realPath(
|
||||
path.join(stageAppDir, "node_modules", "@clerk", "electron-passkeys", "index.js"),
|
||||
);
|
||||
const packageDir = path.dirname(packageEntryPath);
|
||||
const packageRequire = createRequire(packageEntryPath);
|
||||
|
||||
for (const artifact of resolveClerkPasskeyNativeArtifacts(platform, arch)) {
|
||||
const sourcePath = yield* Effect.try({
|
||||
try: () => packageRequire.resolve(artifact.packageName),
|
||||
catch: (cause) =>
|
||||
new BuildScriptError({
|
||||
message: `Clerk passkey native package is missing: ${artifact.packageName}`,
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
yield* fs.copyFile(sourcePath, path.join(packageDir, artifact.binaryFileName));
|
||||
}
|
||||
});
|
||||
|
||||
export function createStageWorkspaceConfig(
|
||||
platform: typeof BuildPlatform.Type,
|
||||
arch: typeof BuildArch.Type,
|
||||
@@ -770,16 +948,22 @@ export function resolveDesktopProductName(version: string): string {
|
||||
: (desktopPackageJson.productName ?? "T3 Code");
|
||||
}
|
||||
|
||||
const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
platform: typeof BuildPlatform.Type,
|
||||
target: string,
|
||||
version: string,
|
||||
signed: boolean,
|
||||
mockUpdates: boolean,
|
||||
mockUpdateServerPort: number | undefined,
|
||||
macPasskeySigning:
|
||||
| {
|
||||
readonly entitlementsPath: string;
|
||||
readonly provisioningProfilePath: string;
|
||||
}
|
||||
| undefined,
|
||||
) {
|
||||
const buildConfig: Record<string, unknown> = {
|
||||
appId: "com.t3tools.t3code",
|
||||
appId: DESKTOP_APP_ID,
|
||||
productName: resolveDesktopProductName(version),
|
||||
artifactName: "T3-Code-${version}-${arch}.${ext}",
|
||||
directories: {
|
||||
@@ -821,9 +1005,15 @@ const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
protocols: [
|
||||
{
|
||||
name: "T3 Code",
|
||||
schemes: ["t3code"],
|
||||
schemes: ["t3code", "t3code-dev"],
|
||||
},
|
||||
],
|
||||
...(macPasskeySigning
|
||||
? {
|
||||
entitlements: macPasskeySigning.entitlementsPath,
|
||||
provisioningProfile: macPasskeySigning.provisioningProfilePath,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1069,6 +1259,38 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
// electron-builder is filtering out stageResourcesDir directory in the AppImage for production
|
||||
yield* fs.copy(stageResourcesDir, path.join(stageAppDir, "apps/desktop/prod-resources"));
|
||||
|
||||
const configuredMacPasskeySigning =
|
||||
options.platform === "mac" && options.signed
|
||||
? yield* Effect.try({
|
||||
try: () => resolveMacPasskeySigningConfiguration(loadRepoEnv({ repoRoot })),
|
||||
catch: (cause) =>
|
||||
new BuildScriptError({
|
||||
message: cause instanceof Error ? cause.message : String(cause),
|
||||
cause,
|
||||
}),
|
||||
})
|
||||
: undefined;
|
||||
const macPasskeySigning = configuredMacPasskeySigning
|
||||
? {
|
||||
...configuredMacPasskeySigning,
|
||||
provisioningProfilePath: path.resolve(
|
||||
repoRoot,
|
||||
configuredMacPasskeySigning.provisioningProfilePath,
|
||||
),
|
||||
}
|
||||
: undefined;
|
||||
const macEntitlementsPath = macPasskeySigning
|
||||
? path.join(stageAppDir, "entitlements.mac.plist")
|
||||
: undefined;
|
||||
if (macPasskeySigning && macEntitlementsPath) {
|
||||
if (!(yield* fs.exists(macPasskeySigning.provisioningProfilePath))) {
|
||||
return yield* new BuildScriptError({
|
||||
message: `macOS provisioning profile not found: ${macPasskeySigning.provisioningProfilePath}`,
|
||||
});
|
||||
}
|
||||
yield* fs.writeFileString(macEntitlementsPath, renderMacPasskeyEntitlements(macPasskeySigning));
|
||||
}
|
||||
|
||||
const stageDependencies = {
|
||||
...resolvedServerDependencies,
|
||||
...resolvedDesktopRuntimeDependencies,
|
||||
@@ -1103,6 +1325,12 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
options.signed,
|
||||
options.mockUpdates,
|
||||
options.mockUpdateServerPort,
|
||||
macPasskeySigning && macEntitlementsPath
|
||||
? {
|
||||
entitlementsPath: macEntitlementsPath,
|
||||
provisioningProfilePath: macPasskeySigning.provisioningProfilePath,
|
||||
}
|
||||
: undefined,
|
||||
),
|
||||
dependencies: stageDependencies,
|
||||
devDependencies: {
|
||||
@@ -1134,6 +1362,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
}),
|
||||
{ label: "vp install --prod", verbose: options.verbose },
|
||||
);
|
||||
yield* stageClerkPasskeyNativeBinaries(stageAppDir, options.platform, options.arch);
|
||||
|
||||
// WSL is Windows-only, so only the Windows artifact carries the Linux backend
|
||||
// binary; other platforms ignore the prebuild input.
|
||||
|
||||
Reference in new issue
Block a user