import type * as Effect from "effect/Effect"; import { listAccounts, type ListAccountsResponse, type ListAccountsError, } from "@distilled.cloud/cloudflare/accounts"; import { cloudflare } from "../control-plane/cloudflare-sdk.ts"; import { accounts, type Account } from "../control-plane/cloudflare.ts"; import { configuration, type Env, type OAuthConfiguration, } from "../control-plane/config.ts"; import { authenticatedPrincipal, authorizedGrant, vault, } from "../control-plane/session.ts"; import { startInstallation } from "../control-plane/start-installation.ts"; import { setupDomain } from "../control-plane/domain-setup.ts"; import { setupOpenRouter } from "../control-plane/provider-setup.ts"; import { handleOAuth } from "../control-plane/http.ts"; import { handleInstallations } from "../control-plane/installations.ts"; import type { OAuthError } from "../control-plane/errors.ts"; import type { RegistryFailure } from "../control-plane/installation-errors.ts"; import type { DeploymentFailure } from "../control-plane/deployment-errors.ts"; import type { Installation } from "../control-plane/installation-metadata.ts"; import type { Grant, Principal } from "../control-plane/vault.ts"; import type { InstallationCommand } from "../control-plane/start-installation.ts"; import type { WorkerUploadBindings } from "../control-plane/worker-api.ts"; const recoveryWithTarget: InstallationCommand = { action: "recover", // @ts-expect-error Recovery cannot select a new release. target: {}, }; const mixedUpload: WorkerUploadBindings = { kind: "bootstrap", secret: "fixture", // @ts-expect-error Fresh uploads cannot also inherit an existing version. versionId: "existing", }; // Compile with the real SDK and native binding types. Application programs must // retain precise results/failures and have no unsatisfied service requirements. function contracts( env: Env, request: Request, principal: Principal, network: typeof fetch, ) { const sdk: Effect.Effect = cloudflare( listAccounts({ page: 1, perPage: 50 }), "fixture-token", network, ); const config: Effect.Effect = configuration(env); const identity: Effect.Effect = authenticatedPrincipal( request, env, ); const grant: Effect.Effect = authorizedGrant( env, principal, ); const stored: Effect.Effect = vault( env, "grant", principal.grantRef, ).grant(principal.subject); const available: Effect.Effect = accounts( "fixture-token", network, ); const start: Effect.Effect< Installation, RegistryFailure | DeploymentFailure | OAuthError > = startInstallation(request, env, "id", "request-id", network); const oauth: Effect.Effect = handleOAuth( request, env, network, ); const installations: Effect.Effect = handleInstallations( request, env, network, ); return { sdk, config, identity, grant, stored, available, start, oauth, installations, }; } type AssertNever = T; type DomainRequirements = AssertNever< Effect.Services> >; type ProviderRequirements = AssertNever< Effect.Services> >;