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

main
ts 39 lines 1.4 KB
Raw
1 import { CreateTaxSettings } 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 { attachStripeToken, authorizeWith, resolveStripeAuth } from "./StripeHttp.ts";
7 import type { TaxSettings } from "./TaxSettings.ts";
8 import { UpdateTaxSettings, type UpdateTaxSettingsRequest } from "./UpdateTaxSettings.ts";
9
10 /**
11 * HTTP implementation of {@link UpdateTaxSettings}. 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.UpdateTaxSettings
18 */
19 export const UpdateTaxSettingsHttp = Layer.effect(
20 UpdateTaxSettings,
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_write"],
29 "Stripe.UpdateTaxSettings",
30 );
31 const auth = host !== undefined ? authorizeWith(bound) : ambient.authorize;
32 return Effect.fn(`Stripe.UpdateTaxSettings(${settings.LogicalId})`)(function* (
33 request?: UpdateTaxSettingsRequest,
34 ) {
35 return yield* auth(CreateTaxSettings(request ?? {}));
36 });
37 });
38 }),
39 );