| 1 | import * as Cloudflare from "@/Cloudflare/index.ts"; |
| 2 | import * as Stripe from "@/Stripe/index.ts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 5 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 6 | |
| 7 | export default class StripeBindingWorker extends Cloudflare.Worker<StripeBindingWorker>()( |
| 8 | "StripeBindingWorker", |
| 9 | { |
| 10 | main: import.meta.url, |
| 11 | }, |
| 12 | Effect.gen(function* () { |
| 13 | const product = yield* Stripe.Product("BoundProduct", { |
| 14 | name: "Alchemy Bound Product", |
| 15 | description: "Worker binding coverage", |
| 16 | }); |
| 17 | const retrieveProduct = yield* Stripe.RetrieveProduct(product); |
| 18 | |
| 19 | return { |
| 20 | fetch: Effect.gen(function* () { |
| 21 | const request = yield* HttpServerRequest; |
| 22 | if (request.url.startsWith("/product")) { |
| 23 | const live = yield* retrieveProduct().pipe(Effect.orDie); |
| 24 | return yield* HttpServerResponse.json({ |
| 25 | id: live.id, |
| 26 | name: live.name, |
| 27 | }); |
| 28 | } |
| 29 | return HttpServerResponse.text("ok"); |
| 30 | }), |
| 31 | }; |
| 32 | }).pipe(Effect.provide(Stripe.RetrieveProductHttp)), |
| 33 | ) {} |