The best way to control Claude Code, Codex and more from any computer or phone

main
ts 108 lines 3.87 KB
Raw
1 import type * as zeroTrust from "@distilled.cloud/cloudflare/zero-trust";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import type * as Effect from "effect/Effect";
5 import type { CloudflareEnvironment } from "../CloudflareEnvironment.ts";
6 import type { IdentityProviderAttributes, IdentityProviderType } from "./IdentityProvider.ts";
7
8 /**
9 * Filters for looking up an existing Access identity provider. At least
10 * one of `name` or `type` is required; when both are given the IdP must
11 * match both. The first match wins (names are not unique on Cloudflare's
12 * side).
13 */
14 export type FindIdentityProviderOptions = {
15 /**
16 * Zone to search (legacy zone-level Access). When omitted, the
17 * account-level (Zero Trust organization) IdPs are searched.
18 */
19 zoneId?: string;
20 } & (
21 | {
22 /** Exact display name to match. `""` matches the managed WARP IdP. */
23 name: string;
24 /** IdP type to match, e.g. `"cloudflare"` or `"okta"`. */
25 type?: IdentityProviderType;
26 }
27 | {
28 /** Exact display name to match. `""` matches the managed WARP IdP. */
29 name?: string;
30 /** IdP type to match, e.g. `"cloudflare"` or `"okta"`. */
31 type: IdentityProviderType;
32 }
33 );
34
35 /**
36 * Looks up an existing Access identity provider by display name and/or
37 * type, returning its attributes — or `undefined` when nothing matches.
38 *
39 * As a **data source**, invoke it at plan time via
40 * {@link getIdentityProvider} — the result is an `Output` resolved during
41 * plan/deploy and inert inside deployed bundles. Useful for referencing
42 * IdPs that are managed outside the stack (e.g. the dashboard-provisioned
43 * `cloudflare` WARP login method, whose display name is often `""`).
44 * The implementation is registered by `Cloudflare.providers()`.
45 *
46 * As a **runtime binding** inside a Worker, provide
47 * {@link GetIdentityProviderHttp} — it mints a scoped
48 * {@link AccountApiToken} with the `Access: Organizations, Identity
49 * Providers, and Groups Read` permission and binds it into the Worker so
50 * the lookup can run at runtime.
51 * ### Looking Up Identity Providers
52 * **Example:** Restrict an Access application to the managed WARP IdP
53 * ```typescript
54 * const warpIdp = Cloudflare.Access.getIdentityProvider({
55 * type: "cloudflare",
56 * });
57 *
58 * yield* Cloudflare.Access.Application("Admin", {
59 * domain: "admin.example.com",
60 * allowedIdps: [warpIdp.identityProviderId.as<string>()],
61 * });
62 * ```
63 * **Example:** Look up an IdP by display name
64 * ```typescript
65 * const okta = Cloudflare.Access.getIdentityProvider({ name: "Okta SSO" });
66 * ```
67 * **Example:** Look up an IdP at runtime inside a Worker
68 * ```typescript
69 * // init — bind the lookup
70 * const findWarpIdp = yield* Cloudflare.Access.GetIdentityProvider({
71 * type: "cloudflare",
72 * });
73 *
74 * // runtime — resolve the IdP
75 * const warp = yield* findWarpIdp();
76 * ```
77 *
78 * @binding
79 */
80 export interface GetIdentityProvider extends Binding.Service<
81 GetIdentityProvider,
82 "Cloudflare.Access.GetIdentityProvider",
83 (
84 options: FindIdentityProviderOptions,
85 ) => Effect.Effect<
86 () => Effect.Effect<
87 IdentityProviderAttributes | undefined,
88 zeroTrust.ListIdentityProvidersForAccountError | zeroTrust.ListIdentityProvidersForZoneError,
89 RuntimeContext
90 >,
91 never,
92 CloudflareEnvironment
93 >
94 > {}
95
96 export const GetIdentityProvider = Binding.Service<GetIdentityProvider>(
97 "Cloudflare.Access.GetIdentityProvider",
98 );
99
100 /**
101 * Plan-time identity-provider lookup — the data-source form of
102 * {@link GetIdentityProvider} (what Terraform calls a data source and
103 * Pulumi an invoke). Returns an
104 * `Output<IdentityProviderAttributes | undefined>` resolved during
105 * plan/deploy; safe to call from composition code that is re-executed
106 * inside a deployed runtime bundle.
107 */
108 export const getIdentityProvider = GetIdentityProvider.execute.bind(GetIdentityProvider);