1import { Endpoint } from "@distilled.cloud/aws";
2import * as Region from "@distilled.cloud/aws/Region";
3import * as sfn from "@distilled.cloud/aws/sfn";
4import * as Effect from "effect/Effect";
5import * as Layer from "effect/Layer";
6import { makeStateMachineArnHttpBinding } from "./BindingHttp.ts";
7import { StartSyncExecution } from "./StartSyncExecution.ts";
8
9/**
10 * `StartSyncExecution` must target the `sync-states.{region}` endpoint
11 * (the Smithy `hostPrefix: "sync-"` endpoint trait) — the regular
12 * `states.{region}` endpoint rejects it. distilled applies the host
13 * prefix itself; the explicit Endpoint here additionally pins the
14 * correct host for runtimes bundled against a distilled build that
15 * predates host-prefix support.
16 */
17const startSyncExecutionOnSyncEndpoint = Effect.gen(function* () {
18 const regionEffect = yield* Region.Region;
19 const syncStatesEndpoint: Effect.Effect<string | undefined> = Effect.map(
20 regionEffect,
21 (region) => `https://sync-states.${region}.amazonaws.com`,
22 );
23 const op = yield* sfn.startSyncExecution;
24 // The endpoint must be pinned per call, not around the yield: the
25 // yield-time snapshot is only a fallback — the calling fiber's ambient
26 // `Endpoint` (e.g. the runtime's `Endpoint.fromEnv`) wins over it.
27 return (input: sfn.StartSyncExecutionInput) =>
28 op(input).pipe(
29 Effect.provideService(Endpoint.Endpoint, syncStatesEndpoint),
30 );
31});
32
33export const StartSyncExecutionHttp = Layer.effect(
34 StartSyncExecution,
35 makeStateMachineArnHttpBinding({
36 tag: "AWS.StepFunctions.StartSyncExecution",
37 operation: startSyncExecutionOnSyncEndpoint,
38 actions: ["states:StartSyncExecution"],
39 }),
40);