The best way to control Claude Code, Codex and more from any computer or phone

main
ts 39 lines 1.41 KB
Raw
1 import { GetTaxSettings } 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 { RetrieveTaxSettings, type RetrieveTaxSettingsRequest } from "./RetrieveTaxSettings.ts";
7 import { attachStripeToken, authorizeWith, resolveStripeAuth } from "./StripeHttp.ts";
8 import type { TaxSettings } from "./TaxSettings.ts";
9
10 /**
11 * HTTP implementation of {@link RetrieveTaxSettings}. Provide it on the
12 * Function or Worker Effect. Tax Settings has no Stripe id — only the API
13 * key is bound.
14 *
15 * @layer
16 * @product Tax
17 * @provides Stripe.RetrieveTaxSettings
18 */
19 export const RetrieveTaxSettingsHttp = Layer.effect(
20 RetrieveTaxSettings,
21 Effect.gen(function* () {
22 const ambient = yield* resolveStripeAuth;
23
24 return Effect.fn(function* (settings: TaxSettings) {
25 const host = yield* Binding.Host;
26 const bound = yield* attachStripeToken(
27 settings as unknown as ResourceLike,
28 ["tax_read"],
29 "Stripe.RetrieveTaxSettings",
30 );
31 const auth = host !== undefined ? authorizeWith(bound) : ambient.authorize;
32 return Effect.fn(`Stripe.RetrieveTaxSettings(${settings.LogicalId})`)(function* (
33 request?: RetrieveTaxSettingsRequest,
34 ) {
35 return yield* auth(GetTaxSettings(request ?? {}));
36 });
37 });
38 }),
39 );