1import type * as iotdata from "@distilled.cloud/aws/iot-data-plane";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4
5export interface PublishRequest extends iotdata.PublishRequest {}
6
7/**
8 * A capability that lets a Function publish MQTT messages to AWS IoT Core
9 * topics via the IoT data plane.
10 *
11 * Binding to a topic filter grants the host `iot:Publish` on matching topics
12 * (or on all topics when the filter is omitted) and returns a runtime callable
13 * for the data-plane `Publish` API. Provide the {@link PublishHttp} layer on
14 * the Function.
15 *
16 * ### Publishing Messages
17 * **Example:** Publish MQTT Messages from a Lambda
18 * ```typescript
19 * export default TelemetryFunction.make(
20 * { main: import.meta.url, functionUrl: true },
21 * Effect.gen(function* () {
22 * // grants iot:Publish on sensors/* to this function
23 * const publish = yield* AWS.IoT.Publish("sensors/*");
24 *
25 * return {
26 * fetch: Effect.gen(function* () {
27 * yield* publish({
28 * topic: "sensors/1/telemetry",
29 * payload: JSON.stringify({ t: 22.5 }),
30 * });
31 * return HttpServerResponse.json({ ok: true });
32 * }).pipe(Effect.orDie),
33 * };
34 * }).pipe(Effect.provide(AWS.IoT.PublishHttp)),
35 * );
36 * ```
37 *
38 * @binding
39 */
40export interface Publish extends Binding.Service<
41 Publish,
42 "AWS.IoT.Publish",
43 (
44 topicFilter?: string,
45 ) => Effect.Effect<
46 (
47 request: PublishRequest,
48 ) => Effect.Effect<iotdata.PublishResponse, iotdata.PublishError>
49 >
50> {}
51
52export const Publish = Binding.Service<Publish>("AWS.IoT.Publish");