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/README.md +29 -23
- package/dist/AiGateway.d.ts +44 -0
- package/dist/{ai-gateway.js → AiGateway.js} +5 -106
- package/dist/AiGateway.js.map +1 -0
- package/dist/AiGatewayCredentials.d.ts +45 -0
- package/dist/AiGatewayCredentials.js +94 -0
- package/dist/AiGatewayCredentials.js.map +1 -0
- package/dist/Oidc.d.ts +23 -0
- package/dist/Oidc.js +59 -0
- package/dist/Oidc.js.map +1 -0
- package/dist/{runtime-cache.d.ts → RuntimeCache.d.ts} +5 -8
- package/dist/{runtime-cache.js → RuntimeCache.js} +5 -11
- package/dist/RuntimeCache.js.map +1 -0
- package/package.json +5 -4
- package/src/AiGateway.ts +1 -1
- package/src/AiGatewayCredentials.ts +53 -55
- package/src/Oidc.ts +75 -0
- package/src/{VercelRuntimeCache.ts → RuntimeCache.ts} +2 -2
- package/dist/VercelOidc-DCkdXW3E.js +0 -70
- package/dist/VercelOidc-DCkdXW3E.js.map +0 -1
- package/dist/ai-gateway.d.ts +0 -87
- package/dist/ai-gateway.js.map +0 -1
- package/dist/oidc.d.ts +0 -27
- package/dist/oidc.js +0 -2
- package/dist/rolldown-runtime-D7D4PA-g.js +0 -13
- package/dist/runtime-cache.js.map +0 -1
- package/src/VercelOidc.ts +0 -86
- package/src/ai-gateway.ts +0 -2
- package/src/oidc.ts +0 -1
- package/src/runtime-cache.ts +0 -1
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
package/src/oidc.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as VercelOidc from "./VercelOidc.js"
|
package/src/runtime-cache.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as VercelRuntimeCache from "./VercelRuntimeCache.js"
|