meowtify-sdk-ts
v0.1.0
Published
TypeScript SDK for the Meowtify API
Readme
meowtify-sdk-ts
TypeScript SDK for Meowtify. It provides the shared environment types plus exactly three high-level classes:
Clientfor subscription management.Producerfor notification publishing and provider lifecycle.Consumerfor receiving delivery jobs from RabbitMQ.
Install
npm install meowtify-sdk-tsArchitecture
flowchart LR
Producer[Producer SDK] -->|Notify| API[Meowtify API]
Client[Client SDK] -->|Subscribe / Unsubscribe| API
API -->|Match subscriptions| Links[(Links)]
API -->|Publish delivery jobs| Rabbit[(RabbitMQ)]
Rabbit -->|OnNotification| Consumer[Consumer SDK]Client
Use Client when an application wants to list, create, or delete subscriptions.
import { Client } from "meowtify-sdk-ts";
const client = new Client({
apiUrl: "http://localhost:8080",
clientToken: "dev-client-token",
});
const link = await client.Subscribe(
"twitch",
"channel-42",
{ display_name: "Streamer" },
"discord",
"discord:123456789",
{ channel_id: "123456789" },
{ event_type: "stream.online" },
);
const subscriptions = await client.Subscriptions({
producer_type: "twitch",
consumer_type: "discord",
});
await client.Unsubscribe(link.id);consumer_id is passed to Subscribe because one client may manage several consumer destinations. Subscriptions can still filter by consumer_id through its options. The misspelled Subcriptions method remains available for backward compatibility.
Producer
Use Producer inside a service that emits notifications.
import { Producer } from "meowtify-sdk-ts";
const producer = new Producer({
apiUrl: "http://localhost:8080",
producerToken: "dev-provider-token",
producerType: "twitch",
});
await producer.Register({
type: "twitch",
id: "eventsub",
display_name: "meowtify-p-twitch",
base_url: "https://producer.example.com",
});
await producer.Notify({
producer_id: "channel-42",
producer_data: { display_name: "Streamer" },
type: "stream.online",
title: "Streamer is live",
text: "Building a new integration",
link: "https://twitch.tv/streamer",
data: {
category: "Science & Technology",
},
});
const response = producer.healthcheck();
await producer.Unregister("eventsub");healthcheck() returns a Fetch Response with {"status":"ok"} so it can be mounted directly in Fetch-compatible runtimes.
Consumer
Use Consumer in delivery workers that receive notifications from RabbitMQ.
import { Consumer } from "meowtify-sdk-ts";
const consumer = new Consumer({
queueUrl: "amqp://guest:guest@localhost:5672/",
consumerToken: "dev-consumer-token",
exchangeName: "meowtify.deliveries",
queueName: "meowtify.discord.deliveries",
routingKey: "consumer.discord",
prefetch: 10,
requeueOnError: false,
});
await consumer.OnNotification(async (delivery) => {
console.log(delivery.notification.type, delivery.consumer.consumer_id);
});