@nexus-code/remote-protocol 0.0.0-stage → 0.2.0

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.
@@ -0,0 +1,273 @@
1
+ /**
2
+ * What the relay sees: the frames between a device and its account's room.
3
+ * A device sends sealed messages to another device of the account, or to
4
+ * all of them; the relay checks who sent it, stamps it, and passes it on.
5
+ * It cannot open what a message carries (see ./sealed.ts).
6
+ */
7
+ import { z } from "zod";
8
+ /** The version of the frames below; the relay refuses a device that speaks another. */
9
+ export declare const RELAY_VERSION = 1;
10
+ /** A device's id, as the server gave it when the device signed in. */
11
+ export declare const DeviceIdSchema: z.ZodString;
12
+ export type DeviceId = z.infer<typeof DeviceIdSchema>;
13
+ /** Every other device of the account that is in the room. */
14
+ export declare const ALL_DEVICES = "*";
15
+ /** Unpadded base64url, as the sealed bytes travel. */
16
+ export declare const Base64UrlSchema: z.ZodString;
17
+ /**
18
+ * A sealed message, as the sender gives it to the relay. `to` is one device
19
+ * or ALL_DEVICES. `seq` counts the sender's messages since it connected,
20
+ * from 1, so the other side can tell one lost or repeated. `kid` is the
21
+ * account key's version the message was sealed with.
22
+ */
23
+ export declare const OutgoingSchema: z.ZodObject<{
24
+ t: z.ZodLiteral<"send">;
25
+ to: z.ZodUnion<[z.ZodString, z.ZodLiteral<"*">]>;
26
+ seq: z.ZodNumber;
27
+ kid: z.ZodNumber;
28
+ nonce: z.ZodString;
29
+ box: z.ZodString;
30
+ }, "strip", z.ZodTypeAny, {
31
+ t: "send";
32
+ to: string;
33
+ seq: number;
34
+ kid: number;
35
+ nonce: string;
36
+ box: string;
37
+ }, {
38
+ t: "send";
39
+ to: string;
40
+ seq: number;
41
+ kid: number;
42
+ nonce: string;
43
+ box: string;
44
+ }>;
45
+ export type Outgoing = z.infer<typeof OutgoingSchema>;
46
+ /** A sealed message as the relay delivers it, with the sender it vouches for. */
47
+ export declare const DeliveredSchema: z.ZodObject<Omit<{
48
+ t: z.ZodLiteral<"send">;
49
+ to: z.ZodUnion<[z.ZodString, z.ZodLiteral<"*">]>;
50
+ seq: z.ZodNumber;
51
+ kid: z.ZodNumber;
52
+ nonce: z.ZodString;
53
+ box: z.ZodString;
54
+ }, "t"> & {
55
+ t: z.ZodLiteral<"message">;
56
+ from: z.ZodString;
57
+ }, "strip", z.ZodTypeAny, {
58
+ t: "message";
59
+ to: string;
60
+ seq: number;
61
+ kid: number;
62
+ nonce: string;
63
+ box: string;
64
+ from: string;
65
+ }, {
66
+ t: "message";
67
+ to: string;
68
+ seq: number;
69
+ kid: number;
70
+ nonce: string;
71
+ box: string;
72
+ from: string;
73
+ }>;
74
+ export type Delivered = z.infer<typeof DeliveredSchema>;
75
+ /** A device of the account, as the relay tells who is in the room. */
76
+ export declare const RoomDeviceSchema: z.ZodObject<{
77
+ id: z.ZodString;
78
+ name: z.ZodString;
79
+ /** darwin, win32, linux, ios, android, web. */
80
+ platform: z.ZodString;
81
+ online: z.ZodBoolean;
82
+ }, "strip", z.ZodTypeAny, {
83
+ id: string;
84
+ name: string;
85
+ platform: string;
86
+ online: boolean;
87
+ }, {
88
+ id: string;
89
+ name: string;
90
+ platform: string;
91
+ online: boolean;
92
+ }>;
93
+ export type RoomDevice = z.infer<typeof RoomDeviceSchema>;
94
+ /**
95
+ * Who is in the room: sent once a device joins, and again whenever a device
96
+ * comes or goes. `self` is the device it is sent to.
97
+ */
98
+ export declare const PresenceSchema: z.ZodObject<{
99
+ t: z.ZodLiteral<"presence">;
100
+ self: z.ZodString;
101
+ devices: z.ZodArray<z.ZodObject<{
102
+ id: z.ZodString;
103
+ name: z.ZodString;
104
+ /** darwin, win32, linux, ios, android, web. */
105
+ platform: z.ZodString;
106
+ online: z.ZodBoolean;
107
+ }, "strip", z.ZodTypeAny, {
108
+ id: string;
109
+ name: string;
110
+ platform: string;
111
+ online: boolean;
112
+ }, {
113
+ id: string;
114
+ name: string;
115
+ platform: string;
116
+ online: boolean;
117
+ }>, "many">;
118
+ }, "strip", z.ZodTypeAny, {
119
+ t: "presence";
120
+ self: string;
121
+ devices: {
122
+ id: string;
123
+ name: string;
124
+ platform: string;
125
+ online: boolean;
126
+ }[];
127
+ }, {
128
+ t: "presence";
129
+ self: string;
130
+ devices: {
131
+ id: string;
132
+ name: string;
133
+ platform: string;
134
+ online: boolean;
135
+ }[];
136
+ }>;
137
+ export type Presence = z.infer<typeof PresenceSchema>;
138
+ /**
139
+ * The relay could not take a frame: it was malformed, too big, sent to a
140
+ * device not in the room, or the device's sign-in ended (then the relay
141
+ * closes the socket after it).
142
+ */
143
+ export declare const RelayErrorSchema: z.ZodObject<{
144
+ t: z.ZodLiteral<"error">;
145
+ code: z.ZodEnum<["bad-frame", "too-big", "no-such-device", "unauthorized", "rate-limited"]>;
146
+ message: z.ZodString;
147
+ /** The seq of the frame it refuses, when it was a message. */
148
+ seq: z.ZodOptional<z.ZodNumber>;
149
+ }, "strip", z.ZodTypeAny, {
150
+ code: "bad-frame" | "too-big" | "no-such-device" | "unauthorized" | "rate-limited";
151
+ message: string;
152
+ t: "error";
153
+ seq?: number | undefined;
154
+ }, {
155
+ code: "bad-frame" | "too-big" | "no-such-device" | "unauthorized" | "rate-limited";
156
+ message: string;
157
+ t: "error";
158
+ seq?: number | undefined;
159
+ }>;
160
+ export type RelayError = z.infer<typeof RelayErrorSchema>;
161
+ /** What a device sends the relay. */
162
+ export declare const ClientFrameSchema: z.ZodObject<{
163
+ t: z.ZodLiteral<"send">;
164
+ to: z.ZodUnion<[z.ZodString, z.ZodLiteral<"*">]>;
165
+ seq: z.ZodNumber;
166
+ kid: z.ZodNumber;
167
+ nonce: z.ZodString;
168
+ box: z.ZodString;
169
+ }, "strip", z.ZodTypeAny, {
170
+ t: "send";
171
+ to: string;
172
+ seq: number;
173
+ kid: number;
174
+ nonce: string;
175
+ box: string;
176
+ }, {
177
+ t: "send";
178
+ to: string;
179
+ seq: number;
180
+ kid: number;
181
+ nonce: string;
182
+ box: string;
183
+ }>;
184
+ export type ClientFrame = z.infer<typeof ClientFrameSchema>;
185
+ /** What the relay sends a device. */
186
+ export declare const ServerFrameSchema: z.ZodDiscriminatedUnion<"t", [z.ZodObject<Omit<{
187
+ t: z.ZodLiteral<"send">;
188
+ to: z.ZodUnion<[z.ZodString, z.ZodLiteral<"*">]>;
189
+ seq: z.ZodNumber;
190
+ kid: z.ZodNumber;
191
+ nonce: z.ZodString;
192
+ box: z.ZodString;
193
+ }, "t"> & {
194
+ t: z.ZodLiteral<"message">;
195
+ from: z.ZodString;
196
+ }, "strip", z.ZodTypeAny, {
197
+ t: "message";
198
+ to: string;
199
+ seq: number;
200
+ kid: number;
201
+ nonce: string;
202
+ box: string;
203
+ from: string;
204
+ }, {
205
+ t: "message";
206
+ to: string;
207
+ seq: number;
208
+ kid: number;
209
+ nonce: string;
210
+ box: string;
211
+ from: string;
212
+ }>, z.ZodObject<{
213
+ t: z.ZodLiteral<"presence">;
214
+ self: z.ZodString;
215
+ devices: z.ZodArray<z.ZodObject<{
216
+ id: z.ZodString;
217
+ name: z.ZodString;
218
+ /** darwin, win32, linux, ios, android, web. */
219
+ platform: z.ZodString;
220
+ online: z.ZodBoolean;
221
+ }, "strip", z.ZodTypeAny, {
222
+ id: string;
223
+ name: string;
224
+ platform: string;
225
+ online: boolean;
226
+ }, {
227
+ id: string;
228
+ name: string;
229
+ platform: string;
230
+ online: boolean;
231
+ }>, "many">;
232
+ }, "strip", z.ZodTypeAny, {
233
+ t: "presence";
234
+ self: string;
235
+ devices: {
236
+ id: string;
237
+ name: string;
238
+ platform: string;
239
+ online: boolean;
240
+ }[];
241
+ }, {
242
+ t: "presence";
243
+ self: string;
244
+ devices: {
245
+ id: string;
246
+ name: string;
247
+ platform: string;
248
+ online: boolean;
249
+ }[];
250
+ }>, z.ZodObject<{
251
+ t: z.ZodLiteral<"error">;
252
+ code: z.ZodEnum<["bad-frame", "too-big", "no-such-device", "unauthorized", "rate-limited"]>;
253
+ message: z.ZodString;
254
+ /** The seq of the frame it refuses, when it was a message. */
255
+ seq: z.ZodOptional<z.ZodNumber>;
256
+ }, "strip", z.ZodTypeAny, {
257
+ code: "bad-frame" | "too-big" | "no-such-device" | "unauthorized" | "rate-limited";
258
+ message: string;
259
+ t: "error";
260
+ seq?: number | undefined;
261
+ }, {
262
+ code: "bad-frame" | "too-big" | "no-such-device" | "unauthorized" | "rate-limited";
263
+ message: string;
264
+ t: "error";
265
+ seq?: number | undefined;
266
+ }>]>;
267
+ export type ServerFrame = z.infer<typeof ServerFrameSchema>;
268
+ /**
269
+ * Most bytes one frame may take as JSON. A chat's whole transcript goes in
270
+ * pages under it (see ./rpc.ts).
271
+ */
272
+ export declare const MAX_FRAME_BYTES: number;
273
+ //# sourceMappingURL=relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,uFAAuF;AACvF,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,sEAAsE;AACtE,eAAO,MAAM,cAAc,aAA4B,CAAC;AACxD,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD,6DAA6D;AAC7D,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,sDAAsD;AACtD,eAAO,MAAM,eAAe,aAAuC,CAAC;AAEpE;;;;;GAKG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;EAOzB,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD,iFAAiF;AACjF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;EAG1B,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,sEAAsE;AACtE,eAAO,MAAM,gBAAgB;;;IAG3B,+CAA+C;;;;;;;;;;;;;EAG/C,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;;QAVzB,+CAA+C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAc/C,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;;;;IAI3B,8DAA8D;;;;;;;;;;;;EAE9D,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,qCAAqC;AACrC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;EAAiB,CAAC;AAChD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,qCAAqC;AACrC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QApC5B,+CAA+C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA0B/C,8DAA8D;;;;;;;;;;;;IAc9D,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAc,CAAC"}
package/dist/relay.js ADDED
@@ -0,0 +1,77 @@
1
+ /**
2
+ * What the relay sees: the frames between a device and its account's room.
3
+ * A device sends sealed messages to another device of the account, or to
4
+ * all of them; the relay checks who sent it, stamps it, and passes it on.
5
+ * It cannot open what a message carries (see ./sealed.ts).
6
+ */
7
+ import { z } from "zod";
8
+ /** The version of the frames below; the relay refuses a device that speaks another. */
9
+ export const RELAY_VERSION = 1;
10
+ /** A device's id, as the server gave it when the device signed in. */
11
+ export const DeviceIdSchema = z.string().min(1).max(64);
12
+ /** Every other device of the account that is in the room. */
13
+ export const ALL_DEVICES = "*";
14
+ /** Unpadded base64url, as the sealed bytes travel. */
15
+ export const Base64UrlSchema = z.string().regex(/^[A-Za-z0-9_-]*$/);
16
+ /**
17
+ * A sealed message, as the sender gives it to the relay. `to` is one device
18
+ * or ALL_DEVICES. `seq` counts the sender's messages since it connected,
19
+ * from 1, so the other side can tell one lost or repeated. `kid` is the
20
+ * account key's version the message was sealed with.
21
+ */
22
+ export const OutgoingSchema = z.object({
23
+ t: z.literal("send"),
24
+ to: z.union([DeviceIdSchema, z.literal(ALL_DEVICES)]),
25
+ seq: z.number().int().positive(),
26
+ kid: z.number().int().nonnegative(),
27
+ nonce: Base64UrlSchema,
28
+ box: Base64UrlSchema,
29
+ });
30
+ /** A sealed message as the relay delivers it, with the sender it vouches for. */
31
+ export const DeliveredSchema = OutgoingSchema.omit({ t: true }).extend({
32
+ t: z.literal("message"),
33
+ from: DeviceIdSchema,
34
+ });
35
+ /** A device of the account, as the relay tells who is in the room. */
36
+ export const RoomDeviceSchema = z.object({
37
+ id: DeviceIdSchema,
38
+ name: z.string(),
39
+ /** darwin, win32, linux, ios, android, web. */
40
+ platform: z.string(),
41
+ online: z.boolean(),
42
+ });
43
+ /**
44
+ * Who is in the room: sent once a device joins, and again whenever a device
45
+ * comes or goes. `self` is the device it is sent to.
46
+ */
47
+ export const PresenceSchema = z.object({
48
+ t: z.literal("presence"),
49
+ self: DeviceIdSchema,
50
+ devices: z.array(RoomDeviceSchema),
51
+ });
52
+ /**
53
+ * The relay could not take a frame: it was malformed, too big, sent to a
54
+ * device not in the room, or the device's sign-in ended (then the relay
55
+ * closes the socket after it).
56
+ */
57
+ export const RelayErrorSchema = z.object({
58
+ t: z.literal("error"),
59
+ code: z.enum(["bad-frame", "too-big", "no-such-device", "unauthorized", "rate-limited"]),
60
+ message: z.string(),
61
+ /** The seq of the frame it refuses, when it was a message. */
62
+ seq: z.number().int().positive().optional(),
63
+ });
64
+ /** What a device sends the relay. */
65
+ export const ClientFrameSchema = OutgoingSchema;
66
+ /** What the relay sends a device. */
67
+ export const ServerFrameSchema = z.discriminatedUnion("t", [
68
+ DeliveredSchema,
69
+ PresenceSchema,
70
+ RelayErrorSchema,
71
+ ]);
72
+ /**
73
+ * Most bytes one frame may take as JSON. A chat's whole transcript goes in
74
+ * pages under it (see ./rpc.ts).
75
+ */
76
+ export const MAX_FRAME_BYTES = 1024 * 1024;
77
+ //# sourceMappingURL=relay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.js","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,uFAAuF;AACvF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAE/B,sEAAsE;AACtE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAGxD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,sDAAsD;AACtD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;AAEpE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACpB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACrD,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAChC,GAAG,EAAE,CAAC,C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