The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type * as iamcredentials from "@distilled.cloud/gcp/iamcredentials_v1"; |
| 2 | import * as Binding from "alchemy/Binding"; |
| 3 | import type { RuntimeContext } from "alchemy/RuntimeContext"; |
| 4 | import * as Data from "effect/Data"; |
| 5 | import type * as Effect from "effect/Effect"; |
| 6 | import type { Bucket } from "./Bucket.ts"; |
| 7 | |
| 8 | export interface SignGetObjectUrlRequest { |
| 9 | /** Object name (key) to mint a signed download URL for. */ |
| 10 | object: string; |
| 11 | /** Serve this generation instead of the live one. */ |
| 12 | generation?: string; |
| 13 | /** |
| 14 | * Seconds the URL stays valid (at most 604800, seven days). |
| 15 | * @default 900 |
| 16 | */ |
| 17 | expiresIn?: number; |
| 18 | /** Override the `Content-Type` Cloud Storage responds with. */ |
| 19 | contentType?: string; |
| 20 | } |
| 21 | |
| 22 | /** The runtime could not resolve its own service account to sign with. */ |
| 23 | export class SignedUrlFailed extends Data.TaggedError("GCP.Storage.SignedUrlFailed")<{ |
| 24 | message: string; |
| 25 | cause?: unknown; |
| 26 | }> {} |
| 27 | |
| 28 | export type SignGetObjectUrlError = |
| 29 | | SignedUrlFailed |
| 30 | | iamcredentials.SignBlobProjectsServiceAccountsError; |
| 31 | |
| 32 | /** |
| 33 | * Mint V4 signed download (GET) URLs for objects in a Cloud Storage |
| 34 | * {@link Bucket}, so a browser can fetch an object without Google |
| 35 | * credentials. |
| 36 | * |
| 37 | * The URL is signed with the host's own runtime service account through |
| 38 | * the IAM Credentials `signBlob` API (no key file). The binding grants the |
| 39 | * host `roles/storage.objectViewer` on the bucket (a signed URL carries the |
| 40 | * signer's permissions) and `roles/iam.serviceAccountTokenCreator` on its |
| 41 | * own service account only. See the [signed URL |
| 42 | * guide](https://cloud.google.com/storage/docs/access-control/signed-urls). |
| 43 | * |
| 44 | * ### Signing Download URLs |
| 45 | * **Example:** Mint a signed GET URL |
| 46 | * ```typescript |
| 47 | * const signGetObjectUrl = yield* GCP.Storage.SignGetObjectUrl(bucket); |
| 48 | * const url = yield* signGetObjectUrl({ object: "reports/2026.pdf" }); |
| 49 | * // hand `url` to a browser — it downloads the object without credentials |
| 50 | * // …provided with Effect.provide(GCP.Storage.SignGetObjectUrlHttp) |
| 51 | * ``` |
| 52 | * |
| 53 | * **Example:** Custom expiry and response Content-Type |
| 54 | * ```typescript |
| 55 | * const url = yield* signGetObjectUrl({ |
| 56 | * object: "reports/2026.pdf", |
| 57 | * expiresIn: 3600, |
| 58 | * contentType: "application/pdf", |
| 59 | * }); |
| 60 | * ``` |
| 61 | * |
| 62 | * @binding |
| 63 | * @category Storage |
| 64 | */ |
| 65 | export interface SignGetObjectUrl extends Binding.Service< |
| 66 | SignGetObjectUrl, |
| 67 | "GCP.Storage.SignGetObjectUrl", |
| 68 | ( |
| 69 | bucket: Bucket, |
| 70 | ) => Effect.Effect< |
| 71 | ( |
| 72 | request: SignGetObjectUrlRequest, |
| 73 | ) => Effect.Effect<string, SignGetObjectUrlError, RuntimeContext> |
| 74 | > |
| 75 | > {} |
| 76 | |
| 77 | export const SignGetObjectUrl = Binding.Service<SignGetObjectUrl>("GCP.Storage.SignGetObjectUrl"); |