@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 108 lines 4.04 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { LicenseConfiguration } from "./LicenseConfiguration.ts";
4
5 /**
6 * Shared HTTP scaffolding for the AWS License Manager runtime bindings.
7 *
8 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
9 * thin `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the builders
10 * below. Everything except the operation, the IAM action, and (for the
11 * configuration-scoped builder) the injected ARN is boilerplate.
12 *
13 * Per the `license-manager` service authorization reference, only the
14 * `license-configuration` resource type supports resource-level scoping;
15 * every other action (the checkout data plane, license/grant reads, the
16 * resource inventory) authorizes on `Resource: ["*"]`.
17 */
18
19 /**
20 * Build the impl Effect for an account-level License Manager operation (the
21 * license checkout data plane, license/grant reads, resource inventory, and
22 * license-specification operations — none of which are resource-scoped in
23 * IAM).
24 */
25 export const makeLicenseManagerHttpBinding = <I extends object, A, E, R>(options: {
26 /**
27 * Short capability name used in the binding sid and runtime span, e.g.
28 * `"CheckoutLicense"`.
29 */
30 capability: string;
31 /** IAM actions granted on `Resource: ["*"]`. */
32 iamActions: readonly string[];
33 /** The distilled operation implementing the capability. */
34 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
35 }) =>
36 Effect.gen(function* () {
37 const bind = yield* AWSBindings.Bind;
38 const op = yield* AWSBindings.withCredentials(options.operation);
39
40 return Effect.fn(function* () {
41 if (!globalThis.__ALCHEMY_RUNTIME__) {
42 yield* bind`AWS.LicenseManager.${options.capability}()`({
43 policyStatements: [
44 {
45 Effect: "Allow",
46 Action: [...options.iamActions],
47 Resource: ["*"],
48 },
49 ],
50 });
51 }
52 return Effect.fn(`AWS.LicenseManager.${options.capability}`)(function* (request?: I) {
53 return yield* op((request ?? {}) as I);
54 });
55 });
56 });
57
58 /**
59 * Build the impl Effect for a License Manager operation scoped to one
60 * {@link LicenseConfiguration}: the deploy-time half grants `iamActions` on
61 * the bound configuration's ARN (the `license-configuration` resource type
62 * supports resource-level authorization), and the runtime half injects the
63 * configuration's ARN as the request's `LicenseConfigurationArn`.
64 */
65 export const makeLicenseConfigurationHttpBinding = <
66 I extends { LicenseConfigurationArn?: string },
67 A,
68 E,
69 R,
70 >(options: {
71 /**
72 * Short capability name used in the binding sid and runtime span, e.g.
73 * `"ListUsageForLicenseConfiguration"`.
74 */
75 capability: string;
76 /** IAM actions granted on the bound configuration's ARN. */
77 iamActions: readonly string[];
78 /** The distilled operation; `LicenseConfigurationArn` is injected. */
79 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
80 }) =>
81 Effect.gen(function* () {
82 const bind = yield* AWSBindings.Bind;
83 const op = yield* AWSBindings.withCredentials(options.operation);
84
85 return Effect.fn(function* (configuration: LicenseConfiguration) {
86 // Output yields a DEFERRED effect — resolve again per invocation below.
87 const ConfigurationArn = yield* configuration.licenseConfigurationArn;
88 if (!globalThis.__ALCHEMY_RUNTIME__) {
89 yield* bind`AWS.LicenseManager.${options.capability}(${configuration})`({
90 policyStatements: [
91 {
92 Effect: "Allow",
93 Action: [...options.iamActions],
94 Resource: [configuration.licenseConfigurationArn],
95 },
96 ],
97 });
98 }
99 return Effect.fn(`AWS.LicenseManager.${options.capability}(${configuration.LogicalId})`)(
100 function* (request?: Omit<I, "LicenseConfigurationArn">) {
101 return yield* op({
102 ...request,
103 LicenseConfigurationArn: yield* ConfigurationArn,
104 } as I);
105 },
106 );
107 });
108 });