@phuzle/relay 0.1.0 → 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 +26 -0
- package/cli.js +741 -32
- package/index.cjs +579 -25
- package/index.d.cts +67 -0
- package/index.d.ts +67 -0
- package/index.js +577 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,12 +31,38 @@ try {
|
|
|
31
31
|
- Buttons (`actions`), images, scheduling (`deliverAt`, `delaySeconds`), `repeat` until acknowledged and `escalate` to another topic are supported.
|
|
32
32
|
- Point `baseUrl` at a local, staging or self-hosted Relay (default `https://relay.phuzle.com`).
|
|
33
33
|
|
|
34
|
+
## Topics and devices
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const { topics, canCreate } = await relay.topics(); // topics this key may send to (fullName is what send() takes)
|
|
38
|
+
const t = await relay.createTopic({ slug: "deploys", name: "Deploys" }); // needs "Can create topics" on the key
|
|
39
|
+
const phones = await relay.devices("acme-alerts"); // nickname, model, appVersion, lastSeenAt…
|
|
40
|
+
```
|
|
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
|
+
|
|
34
55
|
## Command line
|
|
35
56
|
|
|
36
57
|
```bash
|
|
37
58
|
export RELAY_API_KEY=rly_...
|
|
38
59
|
npx @phuzle/relay send --topic acme-alerts --title "Backup finished" --body "412 GB in 6 min"
|
|
39
60
|
# installed globally: relay send …
|
|
61
|
+
relay topics # what this key can send to (add --json for scripts)
|
|
62
|
+
relay topics create deploys --name "Deploys" # if the key has "Can create topics"
|
|
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
|
|
40
66
|
```
|
|
41
67
|
|
|
42
68
|
Exit code `0` on success, `1` with a one-line reason on failure. `relay` with no arguments prints every option.
|