| 1 | import * as Alchemy from "alchemy"; |
| 2 | import * as GCP from "alchemy/GCP"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import Notes from "./src/Notes.ts"; |
| 5 | import { NotesDb } from "./src/resources.ts"; |
| 6 | |
| 7 | export default Alchemy.Stack( |
| 8 | "GcpCloudFunctionExample", |
| 9 | { providers: GCP.providers(), state: Alchemy.localState() }, |
| 10 | Effect.gen(function* () { |
| 11 | const db = yield* NotesDb; |
| 12 | const notes = yield* Notes; |
| 13 | |
| 14 | // A 2nd-gen function is served by a Cloud Run service. Granting |
| 15 | // `roles/run.invoker` to `allUsers` on that service makes the API |
| 16 | // public; drop this and callers need a Google identity token. |
| 17 | yield* GCP.IAM.Member("PublicInvoker", { |
| 18 | kind: "run.service", |
| 19 | name: notes.service.as<string>(), |
| 20 | role: "roles/run.invoker", |
| 21 | member: "allUsers", |
| 22 | }); |
| 23 | |
| 24 | return { |
| 25 | url: notes.url, |
| 26 | functionName: notes.name, |
| 27 | serviceName: notes.service, |
| 28 | databaseName: db.name, |
| 29 | }; |
| 30 | }), |
| 31 | ); |