1import type * as codeartifact from "@distilled.cloud/aws/codeartifact";
2import type * as Duration from "effect/Duration";
3import type * as Effect from "effect/Effect";
4import * as Binding from "../../Binding.ts";
5import type { Domain } from "./Domain.ts";
6
7/**
8 * Request for {@link GetAuthorizationToken} — `domain` and `domainOwner` are
9 * injected from the bound {@link Domain}.
10 */
11export interface GetAuthorizationTokenRequest {
12 /**
13 * How long the token remains valid. Between 15 minutes and 12 hours, or
14 * exactly `0` to match the remaining duration of the caller's role session.
15 * @default 12 hours
16 */
17 duration?: Duration.Input;
18}
19
20/**
21 * Runtime binding for `codeartifact:GetAuthorizationToken`.
22 *
23 * Mints a temporary authorization token for the bound domain — the credential
24 * package managers (npm, pip, maven, …) present to a CodeArtifact repository
25 * endpoint. The deploy-time half grants `codeartifact:GetAuthorizationToken`
26 * on the domain plus the `sts:GetServiceBearerToken` call CodeArtifact
27 * performs on the caller's behalf. Provide the implementation with
28 * `Effect.provide(AWS.CodeArtifact.GetAuthorizationTokenHttp)`.
29 *
30 * The returned `authorizationToken` is wrapped in `Redacted` so it never
31 * leaks into logs — unwrap with `Redacted.value(...)` at the point of use.
32 *
33 * ### Authenticating Package Managers
34 * **Example:** Mint a Token for npm
35 * ```typescript
36 * import * as Redacted from "effect/Redacted";
37 *
38 * const getToken = yield* AWS.CodeArtifact.GetAuthorizationToken(domain);
39 *
40 * const res = yield* getToken({ duration: "1 hour" });
41 * const token = Redacted.isRedacted(res.authorizationToken)
42 * ? Redacted.value(res.authorizationToken)
43 * : res.authorizationToken; // pass to `npm config set //…:_authToken=`
44 * ```
45 *
46 * @binding
47 */
48export interface GetAuthorizationToken extends Binding.Service<
49 GetAuthorizationToken,
50 "AWS.CodeArtifact.GetAuthorizationToken",
51 (
52 domain: Domain,
53 ) => Effect.Effect<
54 (
55 request?: GetAuthorizationTokenRequest,
56 ) => Effect.Effect<
57 codeartifact.GetAuthorizationTokenResult,
58 codeartifact.GetAuthorizationTokenError
59 >
60 >
61> {}
62
63export const GetAuthorizationToken = Binding.Service<GetAuthorizationToken>(
64 "AWS.CodeArtifact.GetAuthorizationToken",
65);