@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 52 lines 1.7 KB
Raw
1 import { GetProduct } from "@distilled.cloud/stripe/stripe";
2 import * as Binding from "alchemy/Binding";
3 import type { ResourceLike } from "alchemy/Resource";
4 import * as Effect from "effect/Effect";
5 import * as Layer from "effect/Layer";
6 import type { Product } from "./Product.ts";
7 import { RetrieveProduct } from "./RetrieveProduct.ts";
8 import {
9 asStringEffect,
10 attachStripeToken,
11 authorizeWith,
12 resolveStripeAuth,
13 } from "./StripeHttp.ts";
14
15 type ProductInput = string | Product;
16
17 /**
18 * HTTP implementation of {@link RetrieveProduct}. Provide it on the
19 * Function or Worker Effect. Accepts a Product resource, a `prod_…` id
20 * string, or an Effect resolving to a Product.
21 *
22 * @layer
23 * @product Product
24 * @provides Stripe.RetrieveProduct
25 */
26 export const RetrieveProductHttp = Layer.effect(
27 RetrieveProduct,
28 Effect.gen(function* () {
29 const ambient = yield* resolveStripeAuth;
30
31 return Effect.fn(function* (product: ProductInput) {
32 const host = yield* Binding.Host;
33 const isId = typeof product === "string";
34 const resource = isId ? undefined : (product as unknown as ResourceLike);
35 const bound = yield* attachStripeToken(resource, ["products_read"], "Stripe.RetrieveProduct");
36 const id = yield* asStringEffect(isId ? product : (product as Product).id);
37 const auth = host !== undefined ? authorizeWith(bound) : ambient.authorize;
38 const label = isId ? product : (product as Product).LogicalId;
39
40 return Effect.fn(`Stripe.RetrieveProduct(${label})`)(function* (request?: {
41 expand?: string[];
42 }) {
43 return yield* auth(
44 GetProduct({
45 ...request,
46 id: yield* id,
47 }),
48 );
49 });
50 });
51 }),
52 );