@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 +15 -0
- package/cli.js +659 -29
- package/index.cjs +557 -26
- package/index.d.cts +25 -2
- package/index.d.ts +25 -2
- package/index.js +555 -26
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type SubscribeOptions, Subscription } from "./stream.ts";
|
|
2
|
+
export { type StreamCondition, StreamError, type StreamEvent, type StreamFilter, type StreamGap, type StreamState, type SubscribeOptions, Subscription, } from "./stream.ts";
|
|
1
3
|
/** Thrown when the plaintext message exceeds 2 KiB. */
|
|
2
4
|
export declare class PayloadTooLargeError extends Error {
|
|
3
5
|
constructor(size: number);
|
|
@@ -120,7 +122,7 @@ export type Topic = {
|
|
|
120
122
|
};
|
|
121
123
|
export type TopicList = {
|
|
122
124
|
topics: Topic[];
|
|
123
|
-
/** The key
|
|
125
|
+
/** The key may create topics: it has “Can create topics” (and access to all topics), set in the dashboard. */
|
|
124
126
|
canCreate: boolean;
|
|
125
127
|
};
|
|
126
128
|
export type CreateTopic = {
|
|
@@ -140,6 +142,13 @@ export type TopicDevice = {
|
|
|
140
142
|
lastSeenAt: string | null;
|
|
141
143
|
subscribedAt: string;
|
|
142
144
|
};
|
|
145
|
+
/** A topic with its name filled in (see `Relay.topic()`). */
|
|
146
|
+
export type TopicHandle = {
|
|
147
|
+
name: string;
|
|
148
|
+
send(m: Omit<Message, "topic">): Promise<SendResult>;
|
|
149
|
+
devices(): Promise<TopicDevice[]>;
|
|
150
|
+
subscribe(o: SubscribeOptions): Subscription;
|
|
151
|
+
};
|
|
143
152
|
export declare class Relay {
|
|
144
153
|
private readonly opts;
|
|
145
154
|
private readonly base;
|
|
@@ -151,11 +160,25 @@ export declare class Relay {
|
|
|
151
160
|
constructor(opts: RelayOptions);
|
|
152
161
|
/** Reads `RELAY_API_KEY` and, optionally, `RELAY_API_URL`; `overrides` win over the environment. */
|
|
153
162
|
static fromEnv(env?: Record<string, string | undefined>, overrides?: Partial<RelayOptions>): Relay;
|
|
163
|
+
/** A new consumer key for `subscribe()`: 43 characters, shown once. Store it as `RELAY_CONSUMER_KEY`; Relay never sees it and cannot recover it. */
|
|
164
|
+
static generateConsumerKey(): string;
|
|
165
|
+
/** One topic by its full name (`<org>-<slug>`): send to it, list its phones, or subscribe to its events from a server. */
|
|
166
|
+
topic(name: string): TopicHandle;
|
|
167
|
+
/**
|
|
168
|
+
* Receive a topic's events on a server (Relay Streams): webhooks Relay received for this topic, delivered over one long-lived
|
|
169
|
+
* connection, sealed to your consumer key so only this process can open them. Needs an API key with “Can receive events” for the
|
|
170
|
+
* topic. Reconnects by itself, and **at-least-once**: events wait for you (for your plan's retention) until acknowledged, so a
|
|
171
|
+
* restart loses nothing; repeats are possible, so use `ev.id` to ignore ones you have handled.
|
|
172
|
+
*
|
|
173
|
+
* const sub = relay.topic("acme-github-api").subscribe({ name: "deploy-bot" }); // key from RELAY_CONSUMER_KEY
|
|
174
|
+
* for await (const ev of sub) { if (ev.type === "push") deploy(ev.json()); }
|
|
175
|
+
*/
|
|
176
|
+
subscribe(topic: string, o: SubscribeOptions): Subscription;
|
|
154
177
|
/** The topics this key may send to (its `trigger:*` / `trigger:<slug>` permissions), and whether it may create more. */
|
|
155
178
|
topics(): Promise<TopicList>;
|
|
156
179
|
/**
|
|
157
180
|
* Create a topic. Needs the **Can create topics** permission on the key (`scope_denied` otherwise) and counts against the plan's
|
|
158
|
-
* topic limit (`topic_limit`).
|
|
181
|
+
* topic limit (`topic_limit`). Only keys that can send to all topics can have this permission, so the new topic is usable straight away. Not retried automatically:
|
|
159
182
|
* a second attempt would only answer `slug_taken`.
|
|
160
183
|
*/
|
|
161
184
|
createTopic(t: CreateTopic): Promise<Topic>;
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type SubscribeOptions, Subscription } from "./stream.ts";
|
|
2
|
+
export { type StreamCondition, StreamError, type StreamEvent, type StreamFilter, type StreamGap, type StreamState, type SubscribeOptions, Subscription, } from "./stream.ts";
|
|
1
3
|
/** Thrown when the plaintext message exceeds 2 KiB. */
|
|
2
4
|
export declare class PayloadTooLargeError extends Error {
|
|
3
5
|
constructor(size: number);
|
|
@@ -120,7 +122,7 @@ export type Topic = {
|
|
|
120
122
|
};
|
|
121
123
|
export type TopicList = {
|
|
122
124
|
topics: Topic[];
|
|
123
|
-
/** The key
|
|
125
|
+
/** The key may create topics: it has “Can create topics” (and access to all topics), set in the dashboard. */
|
|
124
126
|
canCreate: boolean;
|
|
125
127
|
};
|
|
126
128
|
export type CreateTopic = {
|
|
@@ -140,6 +142,13 @@ export type TopicDevice = {
|
|
|
140
142
|
lastSeenAt: string | null;
|
|
141
143
|
subscribedAt: string;
|
|
142
144
|
};
|
|
145
|
+
/** A topic with its name filled in (see `Relay.topic()`). */
|
|
146
|
+
export type TopicHandle = {
|
|
147
|
+
name: string;
|
|
148
|
+
send(m: Omit<Message, "topic">): Promise<SendResult>;
|
|
149
|
+
devices(): Promise<TopicDevice[]>;
|
|
150
|
+
subscribe(o: SubscribeOptions): Subscription;
|
|
151
|
+
};
|
|
143
152
|
export declare class Relay {
|
|
144
153
|
private readonly opts;
|
|
145
154
|
private readonly base;
|
|
@@ -151,11 +160,25 @@ export declare class Relay {
|
|
|
151
160
|
constructor(opts: RelayOptions);
|
|
152
161
|
/** Reads `RELAY_API_KEY` and, optionally, `RELAY_API_URL`; `overrides` win over the environment. */
|
|
153
162
|
static fromEnv(env?: Record<string, string | undefined>, overrides?: Partial<RelayOptions>): Relay;
|
|
163
|
+
/** A new consumer key for `subscribe()`: 43 characters, shown once. Store it as `RELAY_CONSUMER_KEY`; Relay never sees it and cannot recover it. */
|
|
164
|
+
static generateConsumerKey(): string;
|
|
165
|
+
/** One topic by its full name (`<org>-<slug>`): send to it, list its phones, or subscribe to its events from a server. */
|
|
166
|
+
topic(name: string): TopicHandle;
|
|
167
|
+
/**
|
|
168
|
+
* Receive a topic's events on a server (Relay Streams): webhooks Relay received for this topic, delivered over one long-lived
|
|
169
|
+
* connection, sealed to your consumer key so only this process can open them. Needs an API key with “Can receive events” for the
|
|
170
|
+
* topic. Reconnects by itself, and **at-least-once**: events wait for you (for your plan's retention) until acknowledged, so a
|
|
171
|
+
* restart loses nothing; repeats are possible, so use `ev.id` to ignore ones you have handled.
|
|
172
|
+
*
|
|
173
|
+
* const sub = relay.topic("acme-github-api").subscribe({ name: "deploy-bot" }); // key from RELAY_CONSUMER_KEY
|
|
174
|
+
* for await (const ev of sub) { if (ev.type === "push") deploy(ev.json()); }
|
|
175
|
+
*/
|
|
176
|
+
subscribe(topic: string, o: SubscribeOptions): Subscription;
|
|
154
177
|
/** The topics this key may send to (its `trigger:*` / `trigger:<slug>` permissions), and whether it may create more. */
|
|
155
178
|
topics(): Promise<TopicList>;
|
|
156
179
|
/**
|
|
157
180
|
* Create a topic. Needs the **Can create topics** permission on the key (`scope_denied` otherwise) and counts against the plan's
|
|
158
|
-
* topic limit (`topic_limit`).
|
|
181
|
+
* topic limit (`topic_limit`). Only keys that can send to all topics can have this permission, so the new topic is usable straight away. Not retried automatically:
|
|
159
182
|
* a second attempt would only answer `slug_taken`.
|
|
160
183
|
*/
|
|
161
184
|
createTopic(t: CreateTopic): Promise<Topic>;
|