effect-vercel 0.3.0 → 0.4.0

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/src/VercelOidc.ts DELETED
@@ -1,86 +0,0 @@
1
- /**
2
- * The OIDC token Vercel issues to a deployment.
3
- *
4
- * In Functions the token arrives on each request as the `x-vercel-oidc-token`
5
- * header and rotates, so it is read on every run of `token`/`find`, never
6
- * cached. In builds and after `vercel env pull` it is `VERCEL_OIDC_TOKEN`.
7
- * Use it to authenticate to the AI Gateway, or exchange it for cloud
8
- * credentials (AWS `AssumeRoleWithWebIdentity`, GCP workload identity
9
- * federation).
10
- *
11
- * @example
12
- * ```ts
13
- * import { VercelOidc } from "effect-vercel/oidc"
14
- * import { Effect, Redacted } from "effect"
15
- *
16
- * const program = Effect.gen(function* () {
17
- * const token = yield* VercelOidc.token
18
- * // pass Redacted.value(token) as the web identity token
19
- * })
20
- * ```
21
- */
22
-
23
- import { Config, Data, Effect, Option, Redacted } from "effect"
24
-
25
- /** The environment variable read when no request carries a token. */
26
- export const TOKEN_ENV = "VERCEL_OIDC_TOKEN"
27
-
28
- /** No usable OIDC token. */
29
- export class VercelOidcError extends Data.TaggedError("VercelOidcError")<{
30
- readonly message: string
31
- readonly hints: ReadonlyArray<string>
32
- readonly cause?: unknown
33
- }> {}
34
-
35
- /** How to make a token available. */
36
- export const hints: ReadonlyArray<string> = [
37
- "Run on Vercel, where each request carries an OIDC token.",
38
- `Or run \`vercel env pull\` locally to populate ${TOKEN_ENV}.`,
39
- ]
40
-
41
- /**
42
- * Vercel exposes the current request's context on a well-known global symbol.
43
- * In Functions, the `x-vercel-oidc-token` header of the request lives there.
44
- * Mirrors `@vercel/oidc`'s `getVercelOidcTokenSync`, minus the dev-time
45
- * refresh that package also offers.
46
- */
47
- const REQUEST_CONTEXT = Symbol.for("@vercel/request-context")
48
-
49
- type RequestContext = { readonly headers?: Record<string, string | undefined> }
50
-
51
- const fromRequestContext = Effect.sync(() => {
52
- const holder = globalThis as typeof globalThis & {
53
- [REQUEST_CONTEXT]?: { get?: () => RequestContext | undefined }
54
- }
55
- return Option.fromNullishOr(
56
- holder[REQUEST_CONTEXT]?.get?.()?.headers?.["x-vercel-oidc-token"],
57
- ).pipe(Option.map(Redacted.make))
58
- })
59
-
60
- const fromEnv = Config.option(Config.Redacted(TOKEN_ENV)).pipe(
61
- Effect.catchTag(
62
- "ConfigError",
63
- (cause) => new VercelOidcError({ message: `Failed to read ${TOKEN_ENV}.`, hints, cause }),
64
- ),
65
- )
66
-
67
- /**
68
- * The token if one is available: the request header, else `VERCEL_OIDC_TOKEN`.
69
- * `None` means neither is set, so a caller can fall back to something else.
70
- */
71
- export const find: Effect.Effect<
72
- Option.Option<Redacted.Redacted<string>>,
73
- VercelOidcError
74
- > = Effect.flatMap(fromRequestContext, (found) =>
75
- Option.isSome(found) ? Effect.succeed(found) : fromEnv,
76
- )
77
-
78
- /** Like `find`, but fails when no token is available. */
79
- export const token: Effect.Effect<Redacted.Redacted<string>, VercelOidcError> = Effect.flatMap(
80
- find,
81
- Option.match({
82
- onNone: () =>
83
- Effect.fail(new VercelOidcError({ message: "No Vercel OIDC token is available.", hints })),
84
- onSome: Effect.succeed,
85
- }),
86
- )
package/src/ai-gateway.ts DELETED
@@ -1,2 +0,0 @@
1
- export * as AiGateway from "./AiGateway.js"
2
- export * as AiGatewayCredentials from "./AiGatewayCredentials.js"
package/src/oidc.ts DELETED
@@ -1 +0,0 @@
1
- export * as VercelOidc from "./VercelOidc.js"
@@ -1 +0,0 @@
1
- export * as VercelRuntimeCache from "./VercelRuntimeCache.js"