@cardonjs/realtime-do 0.0.0-stage → 0.3.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.
- package/LICENSE +21 -0
- package/README.md +804 -2
- package/dist/client.d.ts +65 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +338 -0
- package/dist/client.js.map +1 -0
- package/dist/connect.d.ts +29 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +83 -0
- package/dist/connect.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/presence.d.ts +68 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +88 -0
- package/dist/presence.js.map +1 -0
- package/dist/protocol.d.ts +70 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +106 -0
- package/dist/protocol.js.map +1 -0
- package/dist/publisher.d.ts +39 -0
- package/dist/publisher.d.ts.map +1 -0
- package/dist/publisher.js +101 -0
- package/dist/publisher.js.map +1 -0
- package/dist/room.d.ts +58 -0
- package/dist/room.d.ts.map +1 -0
- package/dist/room.js +604 -0
- package/dist/room.js.map +1 -0
- package/dist/testing.d.ts +65 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +99 -0
- package/dist/testing.js.map +1 -0
- package/dist/ticket.d.ts +64 -0
- package/dist/ticket.d.ts.map +1 -0
- package/dist/ticket.js +178 -0
- package/dist/ticket.js.map +1 -0
- package/dist/validation.d.ts +46 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +113 -0
- package/dist/validation.js.map +1 -0
- package/llms.txt +233 -0
- package/package.json +59 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only in-memory publisher. Never use it in production: nothing is delivered anywhere.
|
|
3
|
+
* Import it from `@cardonjs/realtime-do/testing`.
|
|
4
|
+
*/
|
|
5
|
+
import { type PresenceQuery } from "./presence.js";
|
|
6
|
+
import { type RoomIdentity } from "./protocol.js";
|
|
7
|
+
import type { RealtimePublisher } from "./publisher.js";
|
|
8
|
+
import { type RealtimeEvent } from "./validation.js";
|
|
9
|
+
export type { PresenceQuery } from "./presence.js";
|
|
10
|
+
export interface PublishedEvent {
|
|
11
|
+
readonly room: string;
|
|
12
|
+
readonly event: RealtimeEvent;
|
|
13
|
+
}
|
|
14
|
+
export interface DisconnectCall {
|
|
15
|
+
readonly room: string;
|
|
16
|
+
/** Only `id` and `kind`, frozen. */
|
|
17
|
+
readonly identity: RoomIdentity;
|
|
18
|
+
}
|
|
19
|
+
export interface PresenceQueryCall {
|
|
20
|
+
readonly room: string;
|
|
21
|
+
/**
|
|
22
|
+
* The validated query (frozen): only the options given, the identity as `id` and `kind`, and
|
|
23
|
+
* `limit` filled in (default 100).
|
|
24
|
+
*/
|
|
25
|
+
readonly query: PresenceQuery;
|
|
26
|
+
}
|
|
27
|
+
/** A connection the fake reports through `presence` (see `setPresence`). */
|
|
28
|
+
export interface FakeConnection {
|
|
29
|
+
readonly identity: RoomIdentity;
|
|
30
|
+
readonly channels: readonly string[];
|
|
31
|
+
readonly connectedAt: Date;
|
|
32
|
+
/** Default `connectedAt` (no `"ping"` answered yet). Not before `connectedAt`, not after now. */
|
|
33
|
+
readonly lastSeenAt?: Date;
|
|
34
|
+
}
|
|
35
|
+
export interface MemoryRealtime extends RealtimePublisher {
|
|
36
|
+
/** Every publish, in order, with the validated (frozen) event. */
|
|
37
|
+
readonly published: readonly PublishedEvent[];
|
|
38
|
+
/** Every disconnect, in order. */
|
|
39
|
+
readonly disconnected: readonly DisconnectCall[];
|
|
40
|
+
/** Every presence query, in order (only the valid ones). */
|
|
41
|
+
readonly presenceQueries: readonly PresenceQueryCall[];
|
|
42
|
+
/** What `count(room)` resolves with, and what `publish` reports as delivered. Default 0. */
|
|
43
|
+
setCount(room: string, count: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* The open connections `presence(room)` sees, replacing any set before. `presence` applies the
|
|
46
|
+
* same filters, order and limit as the room, with `activeWithinSeconds` measured against
|
|
47
|
+
* `Date.now()` (fake timers apply). Independent of `setCount`. Times after `Date.now()` are
|
|
48
|
+
* rejected: the room never reports them.
|
|
49
|
+
*/
|
|
50
|
+
setPresence(room: string, connections: readonly FakeConnection[]): void;
|
|
51
|
+
/** Forgets the recorded calls (presence queries included), counts and connections. */
|
|
52
|
+
clear(): void;
|
|
53
|
+
}
|
|
54
|
+
export interface MemoryRealtimeOptions {
|
|
55
|
+
/** The room's `maxEventBytes`. Default 16 384. */
|
|
56
|
+
readonly maxEventBytes?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* **Test-only.** A `RealtimePublisher` that validates every call with the same rules as the
|
|
60
|
+
* real one and records it. There are no real connections or channels: `publish` reports the
|
|
61
|
+
* room's count (set with `setCount`) as delivered, `disconnect` reports 0 closed, and `presence`
|
|
62
|
+
* lists what `setPresence` set.
|
|
63
|
+
*/
|
|
64
|
+
export declare function memoryRealtime(options?: MemoryRealtimeOptions): MemoryRealtime;
|
|
65
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;CAC/B;A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,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only in-memory publisher. Never use it in production: nothing is delivered anywhere.
|
|
3
|
+
* Import it from `@cardonjs/realtime-do/testing`.
|
|
4
|
+
*/
|
|
5
|
+
import { isTime, presenceConnection, selectPresence, validPresenceQuery, } from "./presence.js";
|
|
6
|
+
import { validIdentity } from "./protocol.js";
|
|
7
|
+
import { assertValidChannels, assertValidRoom, DEFAULT_MAX_EVENT_BYTES, validEvent, } from "./validation.js";
|
|
8
|
+
/**
|
|
9
|
+
* **Test-only.** A `RealtimePublisher` that validates every call with the same rules as the
|
|
10
|
+
* real one and records it. There are no real connections or channels: `publish` reports the
|
|
11
|
+
* room's count (set with `setCount`) as delivered, `disconnect` reports 0 closed, and `presence`
|
|
12
|
+
* lists what `setPresence` set.
|
|
13
|
+
*/
|
|
14
|
+
export function memoryRealtime(options = {}) {
|
|
15
|
+
const maxEventBytes = options.maxEventBytes ?? DEFAULT_MAX_EVENT_BYTES;
|
|
16
|
+
const published = [];
|
|
17
|
+
const disconnected = [];
|
|
18
|
+
const presenceQueries = [];
|
|
19
|
+
const counts = new Map();
|
|
20
|
+
const connections = new Map();
|
|
21
|
+
return {
|
|
22
|
+
published,
|
|
23
|
+
disconnected,
|
|
24
|
+
presenceQueries,
|
|
25
|
+
async publish(room, event) {
|
|
26
|
+
assertValidRoom(room);
|
|
27
|
+
const valid = validEvent(event, maxEventBytes);
|
|
28
|
+
published.push(Object.freeze({ room, event: valid }));
|
|
29
|
+
return { delivered: counts.get(room) ?? 0 };
|
|
30
|
+
},
|
|
31
|
+
async count(room) {
|
|
32
|
+
assertValidRoom(room);
|
|
33
|
+
return counts.get(room) ?? 0;
|
|
34
|
+
},
|
|
35
|
+
async disconnect(room, identity) {
|
|
36
|
+
assertValidRoom(room);
|
|
37
|
+
const valid = validIdentity(identity);
|
|
38
|
+
disconnected.push(Object.freeze({ room, identity: valid }));
|
|
39
|
+
return { closed: 0 };
|
|
40
|
+
},
|
|
41
|
+
async presence(room, options) {
|
|
42
|
+
assertValidRoom(room);
|
|
43
|
+
const query = validPresenceQuery(options);
|
|
44
|
+
presenceQueries.push(Object.freeze({ room, query }));
|
|
45
|
+
const selected = selectPresence(connections.get(room) ?? [], query, Date.now());
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
connections: Object.freeze(selected.records.map(presenceConnection)),
|
|
48
|
+
total: selected.total,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
setPresence(room, list) {
|
|
52
|
+
assertValidRoom(room);
|
|
53
|
+
if (!Array.isArray(list)) {
|
|
54
|
+
throw new TypeError("memoryRealtime: connections must be an array.");
|
|
55
|
+
}
|
|
56
|
+
const now = Date.now();
|
|
57
|
+
const records = list.map((connection) => {
|
|
58
|
+
if (typeof connection !== "object" || connection === null) {
|
|
59
|
+
throw new TypeError("memoryRealtime: each connection must be an object.");
|
|
60
|
+
}
|
|
61
|
+
const identity = validIdentity(connection.identity);
|
|
62
|
+
assertValidChannels(connection.channels);
|
|
63
|
+
const connectedAt = timeOf(connection.connectedAt);
|
|
64
|
+
const lastSeenAt = connection.lastSeenAt === undefined ? connectedAt : timeOf(connection.lastSeenAt);
|
|
65
|
+
if (connectedAt === undefined || lastSeenAt === undefined || lastSeenAt < connectedAt) {
|
|
66
|
+
throw new TypeError("memoryRealtime: connectedAt must be a valid Date and lastSeenAt one not before it.");
|
|
67
|
+
}
|
|
68
|
+
if (lastSeenAt > now) {
|
|
69
|
+
// lastSeenAt >= connectedAt, so this covers both. The room never reports a future time,
|
|
70
|
+
// and one would pass every activeWithinSeconds filter.
|
|
71
|
+
throw new TypeError("memoryRealtime: connectedAt and lastSeenAt must not be after now.");
|
|
72
|
+
}
|
|
73
|
+
return { identity, channels: [...connection.channels], connectedAt, lastSeenAt };
|
|
74
|
+
});
|
|
75
|
+
connections.set(room, records);
|
|
76
|
+
},
|
|
77
|
+
setCount(room, count) {
|
|
78
|
+
assertValidRoom(room);
|
|
79
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
80
|
+
throw new TypeError("memoryRealtime: count must be a non-negative integer.");
|
|
81
|
+
}
|
|
82
|
+
counts.set(room, count);
|
|
83
|
+
},
|
|
84
|
+
clear() {
|
|
85
|
+
published.length = 0;
|
|
86
|
+
disconnected.length = 0;
|
|
87
|
+
presenceQueries.length = 0;
|
|
88
|
+
counts.clear();
|
|
89
|
+
connections.clear();
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function timeOf(value) {
|
|
94
|
+
if (!(value instanceof Date))
|
|
95
|
+
return undefined;
|
|
96
|
+
const time = value.getTime();
|
|
97
|
+
return isTime(time) ? time : undefined;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,MAAM,EAGN,kBAAkB,EAClB,cAAc,EACd,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAqB,aAAa,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EAEvB,UAAU,GACX,MAAM,iBAAiB,CAAC;AA0DzB;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAO,GAA0B,EAAE;IAChE,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,uBAAuB,CAAC;IACvE,MAAM,SAAS,GAAqB,EAAE,CAAC;IACvC,MAAM,YAAY,GAAqB,EAAE,CAAC;IAC1C,MAAM,eAAe,GAAwB,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAqC,CAAC;IAEjE,OAAO;QACL,SAAS;QACT,YAAY;QACZ,eAAe;QACf,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,K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AC3F,CAAC;gBACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;YACnF,CAAC,CAAC,CAAC;YACH,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,QAAQ,CAAC,IAAI,EAAE,KAAK;YAClB,eAAe,CAAC,IAAI,CAAC,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBAC9C,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAC;YAC/E,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,KAAK;YACH,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;YACrB,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;YACxB,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;YAC3B,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;IAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACzC,CAAC"}
|
package/dist/ticket.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type RoomIdentity } from "./protocol.js";
|
|
2
|
+
export interface RoomTicketOptions {
|
|
3
|
+
readonly identity: RoomIdentity;
|
|
4
|
+
/** Chosen by the server; a client cannot subscribe to anything. 1 to 8, no repeats. */
|
|
5
|
+
readonly channels: readonly string[];
|
|
6
|
+
/** How long the ticket can be used, in seconds. Default 30, 5 to 120. */
|
|
7
|
+
readonly ttlSeconds?: number;
|
|
8
|
+
/**
|
|
9
|
+
* The socket opened with the ticket is closed with 4000 (re-authenticate) from this time on,
|
|
10
|
+
* if earlier than the room's `maxConnectionAgeSeconds`: the expiry of the credential that was
|
|
11
|
+
* exchanged (an access token's `expiresAt`). The ticket itself never outlives it either. Must
|
|
12
|
+
* be later than now.
|
|
13
|
+
*/
|
|
14
|
+
readonly connectionExpiresAt?: Date;
|
|
15
|
+
}
|
|
16
|
+
export interface RoomTicket {
|
|
17
|
+
/** `crt_` and 43 characters. Hand it to the client once; never log or store it. */
|
|
18
|
+
readonly ticket: string;
|
|
19
|
+
/** After this the ticket is refused. Never after `connectionExpiresAt`. */
|
|
20
|
+
readonly expiresAt: Date;
|
|
21
|
+
}
|
|
22
|
+
export interface TicketConnectOptions {
|
|
23
|
+
/** Exact origins allowed to open the socket, e.g. ["https://shop.example.com"]. Required. */
|
|
24
|
+
readonly allowedOrigins: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Asks the room for a ticket bound to it, to `identity` and to `channels`. Resolves with the
|
|
28
|
+
* ticket (shown once) and when it expires.
|
|
29
|
+
*
|
|
30
|
+
* Authenticate the caller and authorize the room in the route before calling this, and answer
|
|
31
|
+
* with `Cache-Control: no-store`.
|
|
32
|
+
*
|
|
33
|
+
* - The room already holds 1000 pending tickets, the identity 5, or `disconnect` revoked the
|
|
34
|
+
* identity less than 60 seconds ago: `RateLimitedError` (429).
|
|
35
|
+
* - The room class is not SQLite-backed: an `Error` saying so (tickets need its synchronous
|
|
36
|
+
* storage).
|
|
37
|
+
*
|
|
38
|
+
* Invalid arguments (room, identity, channels, ttlSeconds, a connectionExpiresAt that is not a
|
|
39
|
+
* Date later than now, binding) are programming errors and throw a `TypeError` before anything
|
|
40
|
+
* else.
|
|
41
|
+
*/
|
|
42
|
+
export declare function issueRoomTicket(namespace: DurableObjectNamespace, room: string, options: RoomTicketOptions): Promise<RoomTicket>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks the upgrade, the `Origin` and the offered ticket, then asks the room to consume the
|
|
45
|
+
* ticket and open a socket with the identity and channels it was issued for. Resolves with the
|
|
46
|
+
* 101 response to return from the route; it selects the `cardon.ticket.v1` subprotocol.
|
|
47
|
+
*
|
|
48
|
+
* - Not a `GET` WebSocket upgrade: `ValidationError` (400).
|
|
49
|
+
* - `Origin` missing or not exactly in `allowedOrigins`: `ForbiddenError` (403).
|
|
50
|
+
* - No ticket, a malformed, unknown, used or expired one, one for another room, or other
|
|
51
|
+
* subprotocol entries: `UnauthorizedError` (401), the same message for all.
|
|
52
|
+
* - The room is full, the identity has too many connections, or `disconnect` revoked it less
|
|
53
|
+
* than 60 seconds ago: `RateLimitedError` (429). The ticket is used up all the same.
|
|
54
|
+
* - The room class is not SQLite-backed: an `Error` saying so (a 500 for the client).
|
|
55
|
+
*
|
|
56
|
+
* The ticket is the route's authorization: list the route as public in `requireAuth`. The
|
|
57
|
+
* room name comes from the route, as for `connectToRoom`; a ticket only exists in the room it
|
|
58
|
+
* was issued by.
|
|
59
|
+
*
|
|
60
|
+
* Invalid arguments (room, origins, binding) are programming errors and throw a `TypeError`
|
|
61
|
+
* before anything else.
|
|
62
|
+
*/
|
|
63
|
+
export declare function connectToRoomWithTicket(namespace: DurableObjectNamespace, room: string, request: Request, options: TicketConnectOptions): Promise<Response>;
|
|
64
|
+
//# sourceMappingURL=ticket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket.d.ts","sourceRoot":"","sources":["../src/ticket.ts"],"names":[],"mappings":"AAiBA,OAAO,EAML,KAAK,YAAY,EAGlB,MAAM,eAAe,CAAC;AAQvB,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,uFAAuF;IACvF,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,yEAAyE;IACzE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,UAAU;IACzB,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,6FAA6F;IAC7F,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;AAuCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,eAAe,CACnC,SAAS,EAAE,sBAAsB,EACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,UAAU,CAAC,CAiDrB;AAeD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,sBAAsB,EACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAoCnB"}
|
package/dist/ticket.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time tickets, for clients that cannot authenticate the upgrade with a same-site cookie
|
|
3
|
+
* (the holder of an access token, a page on another site). Runs in the Worker; the room keeps
|
|
4
|
+
* its own pending tickets, by hash, and consumes each one once.
|
|
5
|
+
*
|
|
6
|
+
* 1. An exchange route authenticates the caller by its own means, authorizes the room and calls
|
|
7
|
+
* `issueRoomTicket`.
|
|
8
|
+
* 2. The browser opens the socket offering `["cardon.ticket.v1", ticket]` as subprotocols (the
|
|
9
|
+
* only header a page can set on an upgrade); a public route calls `connectToRoomWithTicket`.
|
|
10
|
+
*/
|
|
11
|
+
import { ForbiddenError, RateLimitedError, UnauthorizedError, ValidationError, } from "@cardonjs/core";
|
|
12
|
+
import { validOrigins } from "./connect.js";
|
|
13
|
+
import { asciiJson, assertNamespace, CONNECT_HEADER, INTERNAL_ORIGIN, PATH, roomStub, validIdentity, } from "./protocol.js";
|
|
14
|
+
import { assertValidChannels, assertValidRoom, TICKET_PATTERN, TICKET_PROTOCOL, } from "./validation.js";
|
|
15
|
+
const DEFAULT_TTL_SECONDS = 30;
|
|
16
|
+
const MIN_TTL_SECONDS = 5;
|
|
17
|
+
const MAX_TTL_SECONDS = 120;
|
|
18
|
+
/** The one answer for every ticket failure: the client cannot tell which one it was. */
|
|
19
|
+
const TICKET_REFUSED = "A valid ticket is required.";
|
|
20
|
+
function validTtl(value) {
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return DEFAULT_TTL_SECONDS;
|
|
23
|
+
if (typeof value !== "number" ||
|
|
24
|
+
!Number.isInteger(value) ||
|
|
25
|
+
value < MIN_TTL_SECONDS ||
|
|
26
|
+
value > MAX_TTL_SECONDS) {
|
|
27
|
+
throw new TypeError(`issueRoomTicket: ttlSeconds must be an integer from ${MIN_TTL_SECONDS} to ${MAX_TTL_SECONDS}.`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function validExpiry(value) {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
const time = value instanceof Date ? value.getTime() : Number.NaN;
|
|
35
|
+
// Later than now: a credential that has already expired gets no ticket.
|
|
36
|
+
if (!Number.isFinite(time) || time <= Date.now()) {
|
|
37
|
+
throw new TypeError("issueRoomTicket: connectionExpiresAt must be a valid Date later than now.");
|
|
38
|
+
}
|
|
39
|
+
return time;
|
|
40
|
+
}
|
|
41
|
+
/** What the room answers (501) when its class is not SQLite-backed. */
|
|
42
|
+
const NO_SQLITE = "tickets need a SQLite-backed room class (new_sqlite_classes in the Wrangler migrations).";
|
|
43
|
+
/**
|
|
44
|
+
* Asks the room for a ticket bound to it, to `identity` and to `channels`. Resolves with the
|
|
45
|
+
* ticket (shown once) and when it expires.
|
|
46
|
+
*
|
|
47
|
+
* Authenticate the caller and authorize the room in the route before calling this, and answer
|
|
48
|
+
* with `Cache-Control: no-store`.
|
|
49
|
+
*
|
|
50
|
+
* - The room already holds 1000 pending tickets, the identity 5, or `disconnect` revoked the
|
|
51
|
+
* identity less than 60 seconds ago: `RateLimitedError` (429).
|
|
52
|
+
* - The room class is not SQLite-backed: an `Error` saying so (tickets need its synchronous
|
|
53
|
+
* storage).
|
|
54
|
+
*
|
|
55
|
+
* Invalid arguments (room, identity, channels, ttlSeconds, a connectionExpiresAt that is not a
|
|
56
|
+
* Date later than now, binding) are programming errors and throw a `TypeError` before anything
|
|
57
|
+
* else.
|
|
58
|
+
*/
|
|
59
|
+
export async function issueRoomTicket(namespace, room, options) {
|
|
60
|
+
assertNamespace(namespace, "issueRoomTicket");
|
|
61
|
+
assertValidRoom(room);
|
|
62
|
+
if (typeof options !== "object" || options === null) {
|
|
63
|
+
throw new TypeError("issueRoomTicket: options must be an object.");
|
|
64
|
+
}
|
|
65
|
+
const identity = validIdentity(options.identity);
|
|
66
|
+
assertValidChannels(options.channels);
|
|
67
|
+
const channels = [...options.channels];
|
|
68
|
+
const ttlSeconds = validTtl(options.ttlSeconds);
|
|
69
|
+
const connectionExpiresAt = validExpiry(options.connectionExpiresAt);
|
|
70
|
+
const response = await roomStub(namespace, room).fetch(`${INTERNAL_ORIGIN}${PATH.ticket}`, {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: { "content-type": "application/json" },
|
|
73
|
+
body: JSON.stringify({
|
|
74
|
+
room,
|
|
75
|
+
identity,
|
|
76
|
+
channels,
|
|
77
|
+
ttlSeconds,
|
|
78
|
+
...(connectionExpiresAt === undefined ? {} : { connectionExpiresAt }),
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
if (response.status === 429) {
|
|
82
|
+
await response.body?.cancel();
|
|
83
|
+
throw new RateLimitedError();
|
|
84
|
+
}
|
|
85
|
+
if (response.status !== 200) {
|
|
86
|
+
await response.body?.cancel();
|
|
87
|
+
if (response.status === 501)
|
|
88
|
+
throw new Error(`issueRoomTicket: ${NO_SQLITE}`);
|
|
89
|
+
throw new Error(`issueRoomTicket: the room refused the ticket (status ${response.status}).`);
|
|
90
|
+
}
|
|
91
|
+
let body;
|
|
92
|
+
try {
|
|
93
|
+
body = await response.json();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
body = undefined;
|
|
97
|
+
}
|
|
98
|
+
const { ticket, expiresAt } = (body ?? {});
|
|
99
|
+
if (typeof ticket !== "string" ||
|
|
100
|
+
!TICKET_PATTERN.test(ticket) ||
|
|
101
|
+
typeof expiresAt !== "number" ||
|
|
102
|
+
!Number.isFinite(expiresAt)) {
|
|
103
|
+
// Never includes the body: it may hold a ticket.
|
|
104
|
+
throw new Error("issueRoomTicket: the room answered a malformed ticket.");
|
|
105
|
+
}
|
|
106
|
+
return Object.freeze({ ticket, expiresAt: new Date(expiresAt) });
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The ticket offered with the upgrade: `Sec-WebSocket-Protocol` must be exactly
|
|
110
|
+
* `cardon.ticket.v1, <ticket>`, in this order. Anything else is `undefined`.
|
|
111
|
+
*/
|
|
112
|
+
function offeredTicket(request) {
|
|
113
|
+
const header = request.headers.get("sec-websocket-protocol");
|
|
114
|
+
if (header === null)
|
|
115
|
+
return undefined;
|
|
116
|
+
const entries = header.split(",").map((entry) => entry.trim());
|
|
117
|
+
if (entries.length !== 2 || entries[0] !== TICKET_PROTOCOL)
|
|
118
|
+
return undefined;
|
|
119
|
+
const ticket = entries[1];
|
|
120
|
+
return TICKET_PATTERN.test(ticket) ? ticket : undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Checks the upgrade, the `Origin` and the offered ticket, then asks the room to consume the
|
|
124
|
+
* ticket and open a socket with the identity and channels it was issued for. Resolves with the
|
|
125
|
+
* 101 response to return from the route; it selects the `cardon.ticket.v1` subprotocol.
|
|
126
|
+
*
|
|
127
|
+
* - Not a `GET` WebSocket upgrade: `ValidationError` (400).
|
|
128
|
+
* - `Origin` missing or not exactly in `allowedOrigins`: `ForbiddenError` (403).
|
|
129
|
+
* - No ticket, a malformed, unknown, used or expired one, one for another room, or other
|
|
130
|
+
* subprotocol entries: `UnauthorizedError` (401), the same message for all.
|
|
131
|
+
* - The room is full, the identity has too many connections, or `disconnect` revoked it less
|
|
132
|
+
* than 60 seconds ago: `RateLimitedError` (429). The ticket is used up all the same.
|
|
133
|
+
* - The room class is not SQLite-backed: an `Error` saying so (a 500 for the client).
|
|
134
|
+
*
|
|
135
|
+
* The ticket is the route's authorization: list the route as public in `requireAuth`. The
|
|
136
|
+
* room name comes from the route, as for `connectToRoom`; a ticket only exists in the room it
|
|
137
|
+
* was issued by.
|
|
138
|
+
*
|
|
139
|
+
* Invalid arguments (room, origins, binding) are programming errors and throw a `TypeError`
|
|
140
|
+
* before anything else.
|
|
141
|
+
*/
|
|
142
|
+
export async function connectToRoomWithTicket(namespace, room, request, options) {
|
|
143
|
+
assertNamespace(namespace, "connectToRoomWithTicket");
|
|
144
|
+
assertValidRoom(room);
|
|
145
|
+
if (typeof options !== "object" || options === null) {
|
|
146
|
+
throw new TypeError("connectToRoomWithTicket: options must be an object.");
|
|
147
|
+
}
|
|
148
|
+
const allowedOrigins = validOrigins(options.allowedOrigins, "connectToRoomWithTicket");
|
|
149
|
+
if (request.method !== "GET" || request.headers.get("upgrade")?.toLowerCase() !== "websocket") {
|
|
150
|
+
throw new ValidationError("A WebSocket upgrade is required.");
|
|
151
|
+
}
|
|
152
|
+
const origin = request.headers.get("origin");
|
|
153
|
+
if (origin === null || !allowedOrigins.includes(origin))
|
|
154
|
+
throw new ForbiddenError();
|
|
155
|
+
const ticket = offeredTicket(request);
|
|
156
|
+
if (ticket === undefined)
|
|
157
|
+
throw new UnauthorizedError(TICKET_REFUSED);
|
|
158
|
+
// A new request: no client header reaches the room; the ticket travels only in the binding.
|
|
159
|
+
const response = await roomStub(namespace, room).fetch(`${INTERNAL_ORIGIN}${PATH.ticketConnect}`, {
|
|
160
|
+
headers: {
|
|
161
|
+
upgrade: "websocket",
|
|
162
|
+
// Cannot throw: the room name and the ticket are printable ASCII.
|
|
163
|
+
[CONNECT_HEADER]: asciiJson({ room, ticket }),
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
if (response.status === 101 && response.webSocket)
|
|
167
|
+
return response;
|
|
168
|
+
await response.body?.cancel();
|
|
169
|
+
if (response.status === 401)
|
|
170
|
+
throw new UnauthorizedError(TICKET_REFUSED);
|
|
171
|
+
if (response.status === 429)
|
|
172
|
+
throw new RateLimitedError();
|
|
173
|
+
// A misconfiguration, not a ticket failure: a 500 for the client, the reason in the app's log.
|
|
174
|
+
if (response.status === 501)
|
|
175
|
+
throw new Error(`connectToRoomWithTicket: ${NO_SQLITE}`);
|
|
176
|
+
throw new Error(`connectToRoomWithTicket: the room refused the connection (status ${response.status}).`);
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=ticket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket.js","sourceRoot":"","sources":["../src/ticket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,SAAS,EACT,eAAe,EACf,cAAc,EACd,eAAe,EACf,IAAI,EAEJ,QAAQ,EACR,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC;AA6BzB,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,eAAe,GAAG,CAAC,CAAC;A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CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;SAC9C;KACF,CACF,CAAC;IACF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,SAAS;QAAE,OAAO,QAAQ,CAAC;IACnE,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAC9B,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,MAAM,IAAI,iBAAiB,CAAC,cAAc,CAAC,CAAC;IACzE,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,MAAM,IAAI,gBAAgB,EAAE,CAAC;IAC1D,+FAA+F;IAC/F,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,SAAS,EAAE,CAAC,CAAC;IACtF,MAAM,IAAI,KAAK,CACb,oEAAoE,QAAQ,CAAC,MAAM,IAAI,CACxF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names and events, validated the same way by the room, the publisher, the fake and the client.
|
|
3
|
+
* No imports and no runtime-specific APIs: this module also ships in the browser client.
|
|
4
|
+
*
|
|
5
|
+
* Every failure is a programming error (the values are built by the server), so it is a plain
|
|
6
|
+
* `TypeError` whose message never includes the value.
|
|
7
|
+
*/
|
|
8
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
9
|
+
[key: string]: JsonValue;
|
|
10
|
+
};
|
|
11
|
+
/** What a client receives. The WebSocket only signals "something changed"; reload the data. */
|
|
12
|
+
export interface RealtimeEvent {
|
|
13
|
+
readonly channel: string;
|
|
14
|
+
/** e.g. `"order.updated"`. */
|
|
15
|
+
readonly type: string;
|
|
16
|
+
/** A small hint (ids), never the record itself. */
|
|
17
|
+
readonly data?: JsonValue;
|
|
18
|
+
}
|
|
19
|
+
/** Room and channel names. */
|
|
20
|
+
export declare const NAME_PATTERN: RegExp;
|
|
21
|
+
/** Event types. */
|
|
22
|
+
export declare const EVENT_TYPE_PATTERN: RegExp;
|
|
23
|
+
/** Channels a connection may join. */
|
|
24
|
+
export declare const MAX_CHANNELS = 8;
|
|
25
|
+
/** Default and smallest-common size of a serialized frame, in UTF-8 bytes. */
|
|
26
|
+
export declare const DEFAULT_MAX_EVENT_BYTES = 16384;
|
|
27
|
+
/** Upper bound for `maxEventBytes` (the frame also travels in a request to the room). */
|
|
28
|
+
export declare const MAX_EVENT_BYTES_LIMIT = 1048576;
|
|
29
|
+
/**
|
|
30
|
+
* The WebSocket subprotocol that carries a one-time ticket: the client offers exactly
|
|
31
|
+
* `[TICKET_PROTOCOL, ticket]`, and the 101 response selects `TICKET_PROTOCOL`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const TICKET_PROTOCOL = "cardon.ticket.v1";
|
|
34
|
+
/** A ticket: `crt_` and 32 random bytes in base64url without padding (43 characters). */
|
|
35
|
+
export declare const TICKET_PATTERN: RegExp;
|
|
36
|
+
export declare function assertValidRoom(room: unknown): asserts room is string;
|
|
37
|
+
export declare function assertValidChannel(channel: unknown): asserts channel is string;
|
|
38
|
+
export declare function assertValidChannels(channels: unknown): asserts channels is readonly string[];
|
|
39
|
+
/** The frame sent to clients: `{"channel":…,"type":…,"data":…}`, `data` omitted when absent. */
|
|
40
|
+
export declare function eventFrame(event: RealtimeEvent): string;
|
|
41
|
+
/**
|
|
42
|
+
* Returns a frozen, validated copy of `event` (only `channel`, `type` and `data` are kept).
|
|
43
|
+
* The serialized frame must be at most `maxEventBytes` UTF-8 bytes (default 16 384).
|
|
44
|
+
*/
|
|
45
|
+
export declare function validEvent(event: unknown, maxEventBytes?: number): RealtimeEvent;
|
|
46
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,SAAS,GACjB,MAAM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the same way by the room, the publisher, the fake and the client.
|
|
3
|
+
* No imports and no runtime-specific APIs: this module also ships in the browser client.
|
|
4
|
+
*
|
|
5
|
+
* Every failure is a programming error (the values are built by the server), so it is a plain
|
|
6
|
+
* `TypeError` whose message never includes the value.
|
|
7
|
+
*/
|
|
8
|
+
/** Room and channel names. */
|
|
9
|
+
export const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,127}$/;
|
|
10
|
+
/** Event types. */
|
|
11
|
+
export const EVENT_TYPE_PATTERN = /^[a-z0-9][a-z0-9._:-]{0,63}$/;
|
|
12
|
+
/** Channels a connection may join. */
|
|
13
|
+
export const MAX_CHANNELS = 8;
|
|
14
|
+
/** Default and smallest-common size of a serialized frame, in UTF-8 bytes. */
|
|
15
|
+
export const DEFAULT_MAX_EVENT_BYTES = 16_384;
|
|
16
|
+
/** Upper bound for `maxEventBytes` (the frame also travels in a request to the room). */
|
|
17
|
+
export const MAX_EVENT_BYTES_LIMIT = 1_048_576;
|
|
18
|
+
/**
|
|
19
|
+
* The WebSocket subprotocol that carries a one-time ticket: the client offers exactly
|
|
20
|
+
* `[TICKET_PROTOCOL, ticket]`, and the 101 response selects `TICKET_PROTOCOL`.
|
|
21
|
+
*/
|
|
22
|
+
export const TICKET_PROTOCOL = "cardon.ticket.v1";
|
|
23
|
+
/** A ticket: `crt_` and 32 random bytes in base64url without padding (43 characters). */
|
|
24
|
+
export const TICKET_PATTERN = /^crt_[A-Za-z0-9_-]{43}$/;
|
|
25
|
+
const MAX_DEPTH = 32;
|
|
26
|
+
const encoder = new TextEncoder();
|
|
27
|
+
export function assertValidRoom(room) {
|
|
28
|
+
if (typeof room !== "string" || !NAME_PATTERN.test(room)) {
|
|
29
|
+
throw new TypeError("realtime: the room name must be 1 to 128 characters of A-Z, a-z, 0-9, ':', '.', '_' or '-', starting with a letter or digit.");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function assertValidChannel(channel) {
|
|
33
|
+
if (typeof channel !== "string" || !NAME_PATTERN.test(channel)) {
|
|
34
|
+
throw new TypeError("realtime: a channel name must be 1 to 128 characters of A-Z, a-z, 0-9, ':', '.', '_' or '-', starting with a letter or digit.");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function assertValidChannels(channels) {
|
|
38
|
+
if (!Array.isArray(channels) || channels.length < 1 || channels.length > MAX_CHANNELS) {
|
|
39
|
+
throw new TypeError(`realtime: channels must be an array of 1 to ${MAX_CHANNELS} names.`);
|
|
40
|
+
}
|
|
41
|
+
for (const channel of channels)
|
|
42
|
+
assertValidChannel(channel);
|
|
43
|
+
if (new Set(channels).size !== channels.length) {
|
|
44
|
+
throw new TypeError("realtime: channels must not repeat.");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function isPlainObject(value) {
|
|
48
|
+
const proto = Object.getPrototypeOf(value);
|
|
49
|
+
return proto === Object.prototype || proto === null;
|
|
50
|
+
}
|
|
51
|
+
function copyJson(value, depth, seen) {
|
|
52
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
53
|
+
return value;
|
|
54
|
+
if (typeof value === "number") {
|
|
55
|
+
if (!Number.isFinite(value)) {
|
|
56
|
+
throw new TypeError("realtime: event data must not hold NaN or infinite numbers.");
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
if (typeof value !== "object") {
|
|
61
|
+
throw new TypeError("realtime: event data must be JSON (no undefined, functions, symbols or bigints).");
|
|
62
|
+
}
|
|
63
|
+
if (depth >= MAX_DEPTH) {
|
|
64
|
+
throw new TypeError(`realtime: event data must not nest deeper than ${MAX_DEPTH} levels.`);
|
|
65
|
+
}
|
|
66
|
+
if (seen.has(value))
|
|
67
|
+
throw new TypeError("realtime: event data must not hold cycles.");
|
|
68
|
+
seen.add(value);
|
|
69
|
+
let copy;
|
|
70
|
+
if (Array.isArray(value)) {
|
|
71
|
+
copy = Object.freeze(value.map((item) => copyJson(item, depth + 1, seen)));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
if (!isPlainObject(value)) {
|
|
75
|
+
throw new TypeError("realtime: event data must hold only plain objects and arrays.");
|
|
76
|
+
}
|
|
77
|
+
// `fromEntries` defines own properties, so a "__proto__" key stays a plain key.
|
|
78
|
+
copy = Object.freeze(Object.fromEntries(Object.keys(value).map((key) => [
|
|
79
|
+
key,
|
|
80
|
+
copyJson(value[key], depth + 1, seen),
|
|
81
|
+
])));
|
|
82
|
+
}
|
|
83
|
+
seen.delete(value);
|
|
84
|
+
return copy;
|
|
85
|
+
}
|
|
86
|
+
/** The frame sent to clients: `{"channel":…,"type":…,"data":…}`, `data` omitted when absent. */
|
|
87
|
+
export function eventFrame(event) {
|
|
88
|
+
return JSON.stringify(event.data === undefined
|
|
89
|
+
? { channel: event.channel, type: event.type }
|
|
90
|
+
: { channel: event.channel, type: event.type, data: event.data });
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns a frozen, validated copy of `event` (only `channel`, `type` and `data` are kept).
|
|
94
|
+
* The serialized frame must be at most `maxEventBytes` UTF-8 bytes (default 16 384).
|
|
95
|
+
*/
|
|
96
|
+
export function validEvent(event, maxEventBytes = DEFAULT_MAX_EVENT_BYTES) {
|
|
97
|
+
if (typeof event !== "object" || event === null || Array.isArray(event)) {
|
|
98
|
+
throw new TypeError("realtime: the event must be an object with channel, type and data.");
|
|
99
|
+
}
|
|
100
|
+
const { channel, type, data } = event;
|
|
101
|
+
assertValidChannel(channel);
|
|
102
|
+
if (typeof type !== "string" || !EVENT_TYPE_PATTERN.test(type)) {
|
|
103
|
+
throw new TypeError("realtime: the event type must be 1 to 64 characters of a-z, 0-9, '.', '_', ':' or '-', starting with a letter or digit.");
|
|
104
|
+
}
|
|
105
|
+
const copy = Object.freeze(data === undefined
|
|
106
|
+
? { channel, type }
|
|
107
|
+
: { channel, type, data: copyJson(data, 0, new Set()) });
|
|
108
|
+
if (encoder.encode(eventFrame(copy)).byteLength > maxEventBytes) {
|
|
109
|
+
throw new TypeError(`realtime: the serialized event is larger than ${maxEventBytes} bytes.`);
|
|
110
|
+
}
|
|
111
|
+
return copy;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmBH,8BAA8B;AAC9B,MAAM,CAAC,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAClE,mBAAmB;AACnB,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AACjE,sCAAsC;AACtC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,8EAA8E;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAC9C,yFAAyF;AACzF,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAClD,yFAAyF;AACzF,MAAM,CAAC,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAExD,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,SAAS,CACjB,8HAA8H,CAC/H,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,SAAS,CACjB,+HAA+H,CAChI,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBA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