@phuzle/relay 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,6 +39,19 @@ const t = await relay.createTopic({ slug: "deploys", name: "Deploys" }); // need
39
39
  const phones = await relay.devices("acme-alerts"); // nickname, model, appVersion, lastSeenAt…
40
40
  ```
41
41
 
42
+ ## Receive webhooks on a server (Relay Streams)
43
+
44
+ ```ts
45
+ // RELAY_CONSUMER_KEY comes from `relay key` (43 characters; keep it secret)
46
+ const sub = relay.topic("acme-github-api").subscribe({ name: "deploy-bot" });
47
+ for await (const ev of sub) {
48
+ if (ev.type === "push") await deploy(ev.json()); // ev.body, ev.headers, ev.source, ev.deliveryId…
49
+ }
50
+ ```
51
+
52
+ Turn on **Servers** for an integration in the console and give an API key “Can receive events from”. The stream reconnects
53
+ by itself and is at-least-once: events wait for you (for your plan's retention) and come back until acknowledged, which the default `ack: "auto"` does when your loop moves on to the next event. Pass `filter: { types, where, ignoreWhen, project, collapseKey }` to have Relay drop, cut down or collapse events before storing them for you. Handle repeats by `ev.id`; see the Relay Streams guide for `ack: "manual"`, `prefetch`, `from` and the `gap` event.
54
+
42
55
  ## Command line
43
56
 
44
57
  ```bash
@@ -48,6 +61,8 @@ npx @phuzle/relay send --topic acme-alerts --title "Backup finished" --body "412
48
61
  relay topics # what this key can send to (add --json for scripts)
49
62
  relay topics create deploys --name "Deploys" # if the key has "Can create topics"
50
63
  relay devices --topic acme-alerts
64
+ relay listen --topic acme-github-api --forward http://localhost:3000/webhooks/github # a webhook tunnel
65
+ relay key # a new consumer key
51
66
  ```
52
67
 
53
68
  Exit code `0` on success, `1` with a one-line reason on failure. `relay` with no arguments prints every option.