| 1 | import { GetProductFeature } from "@distilled.cloud/stripe/stripe"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as Binding from "../Binding.ts"; |
| 5 | import type { ResourceLike } from "../Resource.ts"; |
| 6 | import type { ProductFeature } from "./ProductFeature.ts"; |
| 7 | import { RetrieveProductFeature } from "./RetrieveProductFeature.ts"; |
| 8 | import { |
| 9 | asStringEffect, |
| 10 | attachStripeToken, |
| 11 | authorizeWith, |
| 12 | resolveStripeAuth, |
| 13 | } from "./StripeHttp.ts"; |
| 14 | |
| 15 | /** |
| 16 | * HTTP implementation of {@link RetrieveProductFeature}. The list-item |
| 17 | * retrieve takes both `product` and `id`. |
| 18 | * |
| 19 | * @layer |
| 20 | * @product Product |
| 21 | * @provides Stripe.RetrieveProductFeature |
| 22 | */ |
| 23 | export const RetrieveProductFeatureHttp = Layer.effect( |
| 24 | RetrieveProductFeature, |
| 25 | Effect.gen(function* () { |
| 26 | const ambient = yield* resolveStripeAuth; |
| 27 | |
| 28 | return Effect.fn(function* (feature: ProductFeature) { |
| 29 | const host = yield* Binding.Host; |
| 30 | const bound = yield* attachStripeToken( |
| 31 | feature as unknown as ResourceLike, |
| 32 | ["products_read"], |
| 33 | "Stripe.RetrieveProductFeature", |
| 34 | ); |
| 35 | const id = yield* asStringEffect(feature.id); |
| 36 | const product = yield* asStringEffect(feature.product); |
| 37 | const auth = |
| 38 | host !== undefined ? authorizeWith(bound) : ambient.authorize; |
| 39 | |
| 40 | return Effect.fn(`Stripe.RetrieveProductFeature(${feature.LogicalId})`)( |
| 41 | function* (request?: { expand?: string[] }) { |
| 42 | return yield* auth( |
| 43 | GetProductFeature({ |
| 44 | ...(request ?? {}), |
| 45 | id: yield* id, |
| 46 | product: yield* product, |
| 47 | }), |
| 48 | ); |
| 49 | }, |
| 50 | ); |
| 51 | }); |
| 52 | }), |
| 53 | ); |