()
| 58 | }; |
| 59 | |
| 60 | export const cloudTarget = (): Target => ({ |
| 61 | name: "cloud", |
| 62 | baseUrl: CLOUD_BASE_URL, |
| 63 | mcpUrl: `${CLOUD_BASE_URL}/mcp`, |
| 64 | capabilities: new Set(["api", "browser", "billing", "mcp-oauth"]), |
| 65 | // Cloud's authorization server is the WorkOS emulator, so token-expiry |
| 66 | // scenarios can compress the lifecycle (the TtlControl service). |
| 67 | setAccessTokenTtl: (seconds) => |
| 68 | Effect.promise(async () => { |
| 69 | const workos = await connectEmulator({ |
| 70 | baseUrl: `http://127.0.0.1:${WORKOS_EMULATOR_PORT}`, |
| 71 | }); |
| 72 | await workos.seed({ oauth: { default_access_token_ttl_seconds: seconds } }); |
| 73 | }), |
| 74 | newIdentity: ({ org = true } = {}) => |
| 75 | Effect.promise(async (): Promise<Identity> => { |
| 76 | const label = `user-${randomUUID().slice(0, 8)}`; |
| 77 | const email = `${label}@e2e.test`; |
| 78 | let session = await signIn(email); |
| 79 | if (org) { |
| 80 | // The real create-organization flow; the refreshed sealed session in |
| 81 | // the response carries the new org. |
| 82 | const response = await fetch(new URL("/api/auth/create-organization", CLOUD_BASE_URL), { |
| 83 | method: "POST", |
| 84 | headers: { |
| 85 | "content-type": "application/json", |
| 86 | origin: new URL(CLOUD_BASE_URL).origin, |
| 87 | cookie: session, |
| 88 | }, |
| 89 | body: JSON.stringify({ name: `Org ${label}` }), |
| 90 | }); |
| 91 | if (!response.ok) { |
| 92 | throw new Error(`cloud newIdentity: create-organization failed (${response.status})`); |
| 93 | } |
| 94 | session = cookiePair(response, "wos-session") ?? session; |
| 95 | } |
| 96 | const [name, value] = session.split(/=(.*)/s); |
| 97 | return { |
| 98 | label: email, |
| 99 | headers: { cookie: session }, |
| 100 | cookies: [{ name: name!, value: value! }], |
| 101 | credentials: { email, password: "emulated" }, |
| 102 | }; |
| 103 | }), |
| 104 | // MCP OAuth against the emulator's authorization server: complete the |
| 105 | // hosted flow headlessly as this identity. |
| 106 | mcpConsent: (identity) => async (request) => { |
| 107 | const authorizeUrl = new URL(request.authorizationUrl); |
| 108 | authorizeUrl.searchParams.set("login_hint", identity.credentials?.email ?? "mcp@e2e.test"); |
| 109 | const response = await fetch(authorizeUrl, { redirect: "manual" }); |
| 110 | const location = response.headers.get("location"); |
| 111 | if (response.status !== 302 || !location) { |
| 112 | throw new Error(`cloud mcpConsent: authorize did not redirect (${response.status})`); |
| 113 | } |
| 114 | const code = new URL(location).searchParams.get("code"); |
| 115 | if (!code) throw new Error("cloud mcpConsent: no code in redirect"); |
| 116 | return { code }; |
| 117 | }, |
nothing calls this directly
no test coverage detected