The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as codeartifact from "@distilled.cloud/aws/codeartifact"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as AWSBindings from "../AWSBindings.ts"; |
| 5 | import { domainWideArns } from "./BindingHttp.ts"; |
| 6 | import { CopyPackageVersions, type CopyPackageVersionsRequest } from "./CopyPackageVersions.ts"; |
| 7 | import type { Repository } from "./Repository.ts"; |
| 8 | |
| 9 | /** |
| 10 | * HTTP implementation of {@link CopyPackageVersions} over the CodeArtifact |
| 11 | * API. Bespoke (not the shared repository scaffolding): the bound repository |
| 12 | * is injected as `destinationRepository`, and the copy also reads from the |
| 13 | * caller-chosen source repository, so the grant spans every repository and |
| 14 | * package in the domain. |
| 15 | */ |
| 16 | export const CopyPackageVersionsHttp = Layer.effect( |
| 17 | CopyPackageVersions, |
| 18 | Effect.gen(function* () { |
| 19 | const bind = yield* AWSBindings.Bind; |
| 20 | const op = yield* AWSBindings.withCredentials(codeartifact.copyPackageVersions); |
| 21 | |
| 22 | return Effect.fn(function* (repository: Repository) { |
| 23 | const DomainName = yield* repository.domainName; |
| 24 | const DomainOwner = yield* repository.domainOwner; |
| 25 | const RepositoryName = yield* repository.repositoryName; |
| 26 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 27 | yield* bind`AWS.CodeArtifact.CopyPackageVersions(${repository})`({ |
| 28 | policyStatements: [ |
| 29 | { |
| 30 | Effect: "Allow", |
| 31 | Action: [ |
| 32 | "codeartifact:CopyPackageVersions", |
| 33 | // The copy reads version metadata and assets from the |
| 34 | // source repository on the caller's behalf. |
| 35 | "codeartifact:ReadFromRepository", |
| 36 | "codeartifact:DescribePackageVersion", |
| 37 | ], |
| 38 | Resource: domainWideArns(repository), |
| 39 | }, |
| 40 | ], |
| 41 | }); |
| 42 | } |
| 43 | return Effect.fn(`AWS.CodeArtifact.CopyPackageVersions(${repository.LogicalId})`)(function* ( |
| 44 | request: CopyPackageVersionsRequest, |
| 45 | ) { |
| 46 | const owner = yield* DomainOwner; |
| 47 | return yield* op({ |
| 48 | ...request, |
| 49 | domain: yield* DomainName, |
| 50 | ...(owner === "" ? {} : { domainOwner: owner }), |
| 51 | destinationRepository: yield* RepositoryName, |
| 52 | }); |
| 53 | }); |
| 54 | }); |
| 55 | }), |
| 56 | ); |