@fave1/create-app 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/dist/reserved-ids.js +1 -1
- package/package.json +1 -1
- package/templates/break/README.md +13 -5
- package/templates/break/types/fave1.d.ts +169 -4
- package/templates/minimal/README.md +13 -5
- package/templates/minimal/types/fave1.d.ts +169 -4
- package/templates/panel/README.md +13 -5
- package/templates/panel/types/fave1.d.ts +169 -4
- package/templates/storage/README.md +13 -5
- package/templates/storage/types/fave1.d.ts +169 -4
package/dist/reserved-ids.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
module.exports = ["admin", "api", "apps", "auth", "bridge", "buddy", "chomp", "cram", "developers", "docs", "fave1", "favorites", "get-started", "hello", "home", "images", "
|
|
2
|
+
module.exports = ["admin", "api", "apps", "auth", "bridge", "buddy", "chomp", "collab", "cram", "developers", "docs", "fave1", "favorites", "fonts", "get-started", "hello", "home", "images", "lucky-ladder", "myapps", "notes", "page-break", "party", "quotebook", "screenshot", "settings", "share", "show-me", "signin", "site-quake", "site-raid", "slugger", "sticky", "vibes", "www"];
|
package/package.json
CHANGED
|
@@ -16,12 +16,13 @@ npm run dev # serves your app at http://localhost:7300 — leave it runnin
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Open Fave1 from your bookmarks bar on any shop or article, hold the Fave1 logo,
|
|
19
|
-
paste `http://localhost:7300` and
|
|
19
|
+
paste `http://localhost:7300` and Add. Your app shows up first with a DEV badge.
|
|
20
20
|
Chrome asks once per site to allow local network access — allow it, and press
|
|
21
|
-
|
|
21
|
+
Add again if the panel already said it found nothing. Save a file, reopen the
|
|
22
22
|
app, and it's the new build. Changed
|
|
23
23
|
`manifest.json`? Close Fave1 and click it in your bookmarks bar again — reopening
|
|
24
|
-
the app isn't enough.
|
|
24
|
+
the app isn't enough. Building another app at the same time? Its `npm run dev` takes the
|
|
25
|
+
next free port (7301, 7302…) — add that address too, and they all show up.
|
|
25
26
|
Leave that terminal running and type everything else — `npm run submit` too — in a
|
|
26
27
|
second one; a command typed where the dev server runs does nothing.
|
|
27
28
|
|
|
@@ -48,8 +49,15 @@ npm run submit -- --whats-new "Remembers your place" # with a line for the sto
|
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
It prints a **Test** link — your app on its own home (`{{id}}.fave1.app`), in any
|
|
51
|
-
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
52
|
-
|
|
52
|
+
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
53
|
+
on a phone or in Safari. On your laptop, every build you added as a DEV source also
|
|
54
|
+
shows up in [My Fave1](https://www.fave1.com/myapps) — open it there to try its home
|
|
55
|
+
in a window.
|
|
56
|
+
|
|
57
|
+
That window opens phone-size. Built your home to use more room? Add
|
|
58
|
+
`"window": "medium"` (760 wide) or `"window": "wide"` (1120) to `manifest.json` — it
|
|
59
|
+
opens that wide when the screen allows, and people can still resize it. Phones always
|
|
60
|
+
get the full screen.
|
|
53
61
|
|
|
54
62
|
An exported `FAVE1_KEY` in your terminal or CI wins over `.env.local`, which wins
|
|
55
63
|
over `.env`.
|
|
@@ -94,6 +94,9 @@ type Fave1ErrorCode =
|
|
|
94
94
|
| 'too-large' | 'quota' | 'invalid'
|
|
95
95
|
| 'rate' // too fast — pub writes in a row, file uploads (`err.scope` 'hour' | 'month') or file reads ('read'): wait, then carry on
|
|
96
96
|
| 'cancelled' // they said "Not now"
|
|
97
|
+
| 'conflict' // shared.set() with a stale base — err.current is the row now; merge and set() again
|
|
98
|
+
| 'not-found' // shared.access() · delete() on a link that isn't yours or is gone · room.direct() to a sid that isn't in the room
|
|
99
|
+
| 'declined' // room.direct(): their app doesn't take direct lines (no room.on('direct') and no direct() back within 3 s)
|
|
97
100
|
| 'unreachable' | 'timeout' | 'server';
|
|
98
101
|
|
|
99
102
|
/** What `ctx` rejects with — an `Error` carrying a `code`. `catch (err) { const e = err as Fave1Error; … }` */
|
|
@@ -107,16 +110,16 @@ interface Fave1Error extends Error {
|
|
|
107
110
|
* (more on paid plans): it won't clear today, so tell them. From `files.get()`: `'read'` — 600 reads in a minute, all apps
|
|
108
111
|
* together: back off, it clears within the minute.
|
|
109
112
|
* An older runtime may leave it out; read `quota` as `'account'`, `rate` from `put()` as `'hour'` and from `get()` as `'read'`. */
|
|
110
|
-
scope?: 'app' | 'account' | 'hour' | 'month' | 'read';
|
|
113
|
+
scope?: 'app' | 'account' | 'hour' | 'month' | 'read' | 'shared';
|
|
114
|
+
/** On `conflict` from `shared.set()`: the row as it is now (its `v` is the base to use next). */
|
|
115
|
+
current?: Shared;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
/** One person's public value, as `pub.list()` returns it. */
|
|
114
119
|
interface PubRow<T = any> {
|
|
115
120
|
/** Opaque and per app — the same person has a different id in another app. */
|
|
116
121
|
id: string;
|
|
117
|
-
/**
|
|
118
|
-
name: string | null;
|
|
119
|
-
/** One letter for an avatar, yours included. */
|
|
122
|
+
/** One letter for an avatar, yours included. Public rows never carry a name — show "You" on your own row. */
|
|
120
123
|
initial: string;
|
|
121
124
|
/** Their avatar gradient, ready for CSS `background`. */
|
|
122
125
|
color: string;
|
|
@@ -164,6 +167,122 @@ interface Pub<T = any> {
|
|
|
164
167
|
report(id: string, reason?: PubReportReason, details?: string): Promise<void>;
|
|
165
168
|
}
|
|
166
169
|
|
|
170
|
+
/** Someone in a live room — `room.peers()`, and `peer` on `peer` events. */
|
|
171
|
+
interface LivePeer {
|
|
172
|
+
/** One socket — a person with two tabs open is two peers. */
|
|
173
|
+
sid: string;
|
|
174
|
+
/** Opaque and per app — the same value as `ctx.user.id` for them, and as rows in `ctx.pub`. */
|
|
175
|
+
id: string;
|
|
176
|
+
/** One letter for an avatar. No names in rooms. */
|
|
177
|
+
initial: string;
|
|
178
|
+
/** Their avatar gradient, ready for CSS `background`. */
|
|
179
|
+
color: string;
|
|
180
|
+
/** The last thing they sent with `room.cursor(…)` — `null` until they do. */
|
|
181
|
+
data: unknown;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A change to the room's table — your own writes come through here too (`me: true`), before the server confirms them. */
|
|
185
|
+
interface LiveChange {
|
|
186
|
+
key: string;
|
|
187
|
+
/** `undefined` when the key was deleted. */
|
|
188
|
+
value: unknown;
|
|
189
|
+
/** Who did it — `null` for the table the room handed you on join (or after a reconnect). */
|
|
190
|
+
by: { sid: string; id: string } | null;
|
|
191
|
+
me: boolean;
|
|
192
|
+
/** The room's change counter after this change. */
|
|
193
|
+
seq: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A direct line to one other person in a room — `room.direct(sid)`, or `room.on('direct', …)` when they opened one to you.
|
|
197
|
+
* A WebRTC data channel between the two browsers, so a message arrives in a few milliseconds instead of a trip through Fave1 —
|
|
198
|
+
* for what has to be fast and may be thrown away: inputs at 60 Hz, a shared pointer, "typing". Nothing is kept, nobody else in the
|
|
199
|
+
* room sees it, and whoever joins later sees nothing. Fave1 opens the connection inside its own frame (the page never sees addresses
|
|
200
|
+
* or credentials) and, when it can't be opened in 8 s (a firewall, a browser with WebRTC off), the same line opens **through the room**
|
|
201
|
+
* instead — `via` says which. If the direct connection drops later, the line stays open and moves to the room (`via` becomes `'room'`).
|
|
202
|
+
* A line opens only between two apps that both take it — one side calls `direct()`, the other listens with `room.on('direct')` (or calls
|
|
203
|
+
* `direct()` back). Each side can see the other's network (IP) address, as on any video call. Messages are JSON up to 1 KB, like `cursor()`. */
|
|
204
|
+
interface DirectLine {
|
|
205
|
+
/** The other person's socket — one tab. Key what you draw by this. */
|
|
206
|
+
sid: string;
|
|
207
|
+
/** Their app-scoped id (`ctx.user.id` for them) — `''` until the room knows them. */
|
|
208
|
+
id: string;
|
|
209
|
+
/** Lossy lines drop a late message instead of waiting for it — right for per-frame inputs, wrong for a chat. Set with `direct(sid, { lossy: true })`;
|
|
210
|
+
* the side that opened the line decides. */
|
|
211
|
+
readonly lossy: boolean;
|
|
212
|
+
readonly open: boolean;
|
|
213
|
+
/** `'direct'` — browser to browser; `'relay'` — through a TURN relay (still not through Fave1's room); `'room'` — the fallback, through the
|
|
214
|
+
* room's server. `null` until open. Read it live: a direct line that drops moves to `'room'` without closing. */
|
|
215
|
+
readonly via: 'direct' | 'relay' | 'room' | null;
|
|
216
|
+
/** Round trip in milliseconds, measured every 2 s once open — `null` until the first answer, and on a `'room'` line. */
|
|
217
|
+
readonly rtt: number | null;
|
|
218
|
+
/** Send one JSON value (up to 1 KB). Returns `false` — and sends nothing — when the line isn't open or the value is too big
|
|
219
|
+
* (an `error` event says which). Never waits, never throws. `true` means Fave1 has it; on a lossy line it can still be dropped on the way. */
|
|
220
|
+
send(data: unknown): boolean;
|
|
221
|
+
on(type: 'message', handler: (data: unknown) => void): () => void;
|
|
222
|
+
on(type: 'open', handler: (ev: { via: 'direct' | 'relay' | 'room' }) => void): () => void;
|
|
223
|
+
/** `closed` — either side called `close()`; `left` — they left the room; `lost` — your own room connection dropped (Fave1 reconnects the room
|
|
224
|
+
* and they come back with a new sid — open a new line then); `gone` — the app closed. A dropped direct connection is not a close: the line
|
|
225
|
+
* moves to the room (`via`). */
|
|
226
|
+
on(type: 'close', handler: (ev: { reason: 'closed' | 'left' | 'lost' | 'gone' }) => void): () => void;
|
|
227
|
+
on(type: 'error', handler: (ev: { code: 'too-large' | 'rate' | 'invalid' }) => void): () => void;
|
|
228
|
+
close(): void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** A room you joined — one shared table of `key → value`, kept on Fave1 and pushed to everyone in it the moment it changes. */
|
|
232
|
+
interface LiveRoom {
|
|
233
|
+
/** The room's wire name (a hash of what you passed to `join`). */
|
|
234
|
+
id: string;
|
|
235
|
+
/** What you passed to `join`. */
|
|
236
|
+
name: string;
|
|
237
|
+
/** You in this room — `id` is your app-scoped id, `sid` this tab's socket (both filled in once the room is open), and the
|
|
238
|
+
* initial and color the others see you as. */
|
|
239
|
+
me: { id: string | null; sid: string | null; initial: string; color: string };
|
|
240
|
+
/** Connected right now. Writes while closed are kept locally and dropped — wait for `open`. */
|
|
241
|
+
readonly open: boolean;
|
|
242
|
+
readonly seq: number;
|
|
243
|
+
get(key: string): unknown;
|
|
244
|
+
/** A copy of the whole table. */
|
|
245
|
+
all(): Record<string, unknown>;
|
|
246
|
+
/** Set one key for everyone. Applied here at once (a `change` with `me: true`), then sent. Values are JSON up to 8 KB; the room
|
|
247
|
+
* holds up to 2,000 keys / 256 KB. When two people set the same key at the same moment, the one the server gets last wins. */
|
|
248
|
+
set(key: string, value: unknown): Promise<void>;
|
|
249
|
+
del(key: string): Promise<void>;
|
|
250
|
+
/** Share where you are or what you're doing — a cursor, a selection, "typing". Not saved; sent to the others at most every 40 ms,
|
|
251
|
+
* last value wins. Up to 1 KB as JSON. */
|
|
252
|
+
cursor(data: unknown): void;
|
|
253
|
+
peers(): LivePeer[];
|
|
254
|
+
/** A direct line to one person in the room (`DirectLine`). Resolves once it's open — browser to browser, or through the room after 8 s when it
|
|
255
|
+
* can't be (`line.via`). Their app has to take it: it listens with `room.on('direct')`, or calls `direct()` to you — otherwise this rejects
|
|
256
|
+
* with `declined` after 3 s (also when they already hold 8 lines). The same `sid` always gives the same line; up to 8 at once, counting lines
|
|
257
|
+
* opened to you (`quota`). Also rejects with `not-found` when nobody
|
|
258
|
+
* has that `sid`, `invalid` for your own, `unreachable` when the room is closed, `timeout` after 20 s. `{ lossy: true }` for per-frame inputs. */
|
|
259
|
+
direct(sid: string, opts?: { lossy?: boolean }): Promise<DirectLine>;
|
|
260
|
+
on(type: 'change', handler: (change: LiveChange) => void): () => void;
|
|
261
|
+
on(type: 'peer', handler: (ev: { type: 'join' | 'leave' | 'cursor'; peer: LivePeer }) => void): () => void;
|
|
262
|
+
/** Someone in the room opened a direct line to you — it is already open. **Registering this is how your app takes direct lines**: without it,
|
|
263
|
+
* lines from others are declined (unless you call `direct()` to that person yourself). Register it right after `join()`. */
|
|
264
|
+
on(type: 'direct', handler: (line: DirectLine) => void): () => void;
|
|
265
|
+
/** Fires after a reconnect (`join()` itself resolves once the room is open) — the table may have moved on; `change` events for the
|
|
266
|
+
* differences come first. */
|
|
267
|
+
on(type: 'open', handler: (ev: { reconnected: true }) => void): () => void;
|
|
268
|
+
/** `lost` — dropped, Fave1 is reconnecting; `left` — you called `leave()`; `server` — the room closed it (idle for 45 days, or the
|
|
269
|
+
* socket's ticket ran out); `gone` — the app closed. */
|
|
270
|
+
on(type: 'close', handler: (ev: { code: number; reason: 'lost' | 'left' | 'server' | 'gone' }) => void): () => void;
|
|
271
|
+
/** The room refused something — `too-large`, `quota` (room full of keys/bytes), `rate` (over 40 writes a second), `invalid`. */
|
|
272
|
+
on(type: 'error', handler: (ev: { code: string; key?: string }) => void): () => void;
|
|
273
|
+
leave(): Promise<void>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** `live` — rooms where people edit the same thing at the same time, Figma-style. Uses the `pub` permission (no new one): needs a
|
|
277
|
+
* signed-in person who hasn't switched `pub` off, and on someone else's site the first join asks once ("Join the room on …?") —
|
|
278
|
+
* the same yes that covers posting. Anyone who joins a room with the same name sees the same table, so put something only your
|
|
279
|
+
* people know into the name (an invite code, a link). DEV builds get a sandbox room in this browser — tabs on the same site share it. */
|
|
280
|
+
interface Live {
|
|
281
|
+
/** `what` names what people are joining in the permission line — `Join the {what} on <your app>?` — one word, default `room`
|
|
282
|
+
* (a Collab calls it a project). Older launchers ignore it. */
|
|
283
|
+
join(room: string, opts?: { what?: string }): Promise<LiveRoom>;
|
|
284
|
+
}
|
|
285
|
+
|
|
167
286
|
/** One of this person's files for your app, as `files.put()` and `files.list()` return it. */
|
|
168
287
|
interface FileInfo {
|
|
169
288
|
id: string;
|
|
@@ -247,6 +366,48 @@ interface PageAccess {
|
|
|
247
366
|
/** `page` undeclared or switched off in Fave1 settings — none of it is there. */
|
|
248
367
|
type NoPageAccess = { [K in keyof PageAccess]?: undefined };
|
|
249
368
|
|
|
369
|
+
/** A value your app shares by link, as `shared.create()` · `get()` return it. */
|
|
370
|
+
interface Shared<T = unknown> {
|
|
371
|
+
/** The link's two halves. `ref` is `"<id>.<key>"` — the string you put in a URL and pass back to `get()` · `set()`. */
|
|
372
|
+
id: string; key: string; ref: string;
|
|
373
|
+
value: T;
|
|
374
|
+
/** Changes with every write. Pass it as `base` to `set()` so an edit made in between isn't lost. */
|
|
375
|
+
v: number;
|
|
376
|
+
/** Can people with the link write, not just read? The owner sets it with `create()` and `access()`. */
|
|
377
|
+
edit: boolean;
|
|
378
|
+
updatedAt: string;
|
|
379
|
+
/** This person made it. */
|
|
380
|
+
mine: boolean;
|
|
381
|
+
/** Who made it, and who wrote last (if someone other than the owner did) — first letter and avatar color, never a name. */
|
|
382
|
+
owner: { initial: string; color: string } | null;
|
|
383
|
+
editor: { initial: string; color: string } | null;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** `shared` — one value shared by one link: a note, a list, a board. Declared with `storage` (no new permission).
|
|
387
|
+
* The owner creates it; anyone with the link reads it — signed out, or without your app added; and if the owner turned
|
|
388
|
+
* `edit` on, any signed-in person with the link can write. The owner can change that or take the link back at any time.
|
|
389
|
+
* Values up to 64 KB, 100 per person per app; they count toward the owner's Fave1 storage. The link is the secret —
|
|
390
|
+
* put `ref` in a URL your app opens with (`<id>.fave1.app/#s=<ref>`) and never post it anywhere public yourself.
|
|
391
|
+
* Owner calls (`create` · `access` · `list` · `delete`) follow the storage rules: a signed-in person, one OK on a new
|
|
392
|
+
* site, never at home. DEV builds keep it in this browser — a link made there opens nowhere else. */
|
|
393
|
+
interface SharedApi {
|
|
394
|
+
/** Share a value. `edit` lets people with the link write (default read-only). Rejects with `quota` — `err.scope` `'shared'`
|
|
395
|
+
* at 100 shared values, `'account'` when their Fave1 storage is full. */
|
|
396
|
+
create<T = unknown>(value: T, opts?: { edit?: boolean }): Promise<Shared<T>>;
|
|
397
|
+
/** Read by link. `null` when it's gone or the link is wrong — never throws for that. Works signed out. */
|
|
398
|
+
get<T = unknown>(ref: string): Promise<Shared<T> | null>;
|
|
399
|
+
/** Write by link — as the owner, or as a signed-in person when `edit` is on (`denied` otherwise, `signed-out` with no account).
|
|
400
|
+
* Pass `base` (the `v` you read) and, if someone wrote in between, it rejects with `conflict` carrying `err.current`
|
|
401
|
+
* (the row now): merge, then call `set()` again with its `v`. Without `base` it overwrites. */
|
|
402
|
+
set<T = unknown>(ref: string, value: T, opts?: { base?: number }): Promise<{ v: number }>;
|
|
403
|
+
/** Owner only: let people with the link write, or stop that. Takes the `id` or the `ref`. */
|
|
404
|
+
access(idOrRef: string, opts: { edit: boolean }): Promise<void>;
|
|
405
|
+
/** Everything this person shares from your app — with the keys, so you can show the links again. */
|
|
406
|
+
list(): Promise<Shared[]>;
|
|
407
|
+
/** Owner only: take the link back. Whoever has it gets `null` from then on. Resolves even if it was already gone. */
|
|
408
|
+
delete(idOrRef: string): Promise<void>;
|
|
409
|
+
}
|
|
410
|
+
|
|
250
411
|
interface Ctx {
|
|
251
412
|
ui: Ui;
|
|
252
413
|
/** Where you're running: `'page'` — on someone's site, opened from the bookmarklet;
|
|
@@ -288,7 +449,11 @@ interface Ctx {
|
|
|
288
449
|
};
|
|
289
450
|
/** Files on the account — declared with `storage`, like the JSON above. */
|
|
290
451
|
files: Files;
|
|
452
|
+
/** Values shared by link — declared with `storage` too. */
|
|
453
|
+
shared: SharedApi;
|
|
291
454
|
pub: Pub;
|
|
455
|
+
/** Live rooms — the same table, edited by several people at once (uses `pub`). */
|
|
456
|
+
live: Live;
|
|
292
457
|
/** Is this permission live right now? `pub` also needs a signed-in person who hasn't switched it off. */
|
|
293
458
|
can(permission: Permission): boolean;
|
|
294
459
|
/** Opens this app's permission screen in Fave1 settings. Only the person can turn things on. */
|
|
@@ -16,12 +16,13 @@ npm run dev # serves your app at http://localhost:7300 — leave it runnin
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Open Fave1 from your bookmarks bar on any shop or article, hold the Fave1 logo,
|
|
19
|
-
paste `http://localhost:7300` and
|
|
19
|
+
paste `http://localhost:7300` and Add. Your app shows up first with a DEV badge.
|
|
20
20
|
Chrome asks once per site to allow local network access — allow it, and press
|
|
21
|
-
|
|
21
|
+
Add again if the panel already said it found nothing. Save a file, reopen the
|
|
22
22
|
app, and it's the new build. Changed
|
|
23
23
|
`manifest.json`? Close Fave1 and click it in your bookmarks bar again — reopening
|
|
24
|
-
the app isn't enough.
|
|
24
|
+
the app isn't enough. Building another app at the same time? Its `npm run dev` takes the
|
|
25
|
+
next free port (7301, 7302…) — add that address too, and they all show up.
|
|
25
26
|
Leave that terminal running and type everything else — `npm run submit` too — in a
|
|
26
27
|
second one; a command typed where the dev server runs does nothing.
|
|
27
28
|
|
|
@@ -48,8 +49,15 @@ npm run submit -- --whats-new "Remembers your place" # with a line for the sto
|
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
It prints a **Test** link — your app on its own home (`{{id}}.fave1.app`), in any
|
|
51
|
-
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
52
|
-
|
|
52
|
+
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
53
|
+
on a phone or in Safari. On your laptop, every build you added as a DEV source also
|
|
54
|
+
shows up in [My Fave1](https://www.fave1.com/myapps) — open it there to try its home
|
|
55
|
+
in a window.
|
|
56
|
+
|
|
57
|
+
That window opens phone-size. Built your home to use more room? Add
|
|
58
|
+
`"window": "medium"` (760 wide) or `"window": "wide"` (1120) to `manifest.json` — it
|
|
59
|
+
opens that wide when the screen allows, and people can still resize it. Phones always
|
|
60
|
+
get the full screen.
|
|
53
61
|
|
|
54
62
|
An exported `FAVE1_KEY` in your terminal or CI wins over `.env.local`, which wins
|
|
55
63
|
over `.env`.
|
|
@@ -94,6 +94,9 @@ type Fave1ErrorCode =
|
|
|
94
94
|
| 'too-large' | 'quota' | 'invalid'
|
|
95
95
|
| 'rate' // too fast — pub writes in a row, file uploads (`err.scope` 'hour' | 'month') or file reads ('read'): wait, then carry on
|
|
96
96
|
| 'cancelled' // they said "Not now"
|
|
97
|
+
| 'conflict' // shared.set() with a stale base — err.current is the row now; merge and set() again
|
|
98
|
+
| 'not-found' // shared.access() · delete() on a link that isn't yours or is gone · room.direct() to a sid that isn't in the room
|
|
99
|
+
| 'declined' // room.direct(): their app doesn't take direct lines (no room.on('direct') and no direct() back within 3 s)
|
|
97
100
|
| 'unreachable' | 'timeout' | 'server';
|
|
98
101
|
|
|
99
102
|
/** What `ctx` rejects with — an `Error` carrying a `code`. `catch (err) { const e = err as Fave1Error; … }` */
|
|
@@ -107,16 +110,16 @@ interface Fave1Error extends Error {
|
|
|
107
110
|
* (more on paid plans): it won't clear today, so tell them. From `files.get()`: `'read'` — 600 reads in a minute, all apps
|
|
108
111
|
* together: back off, it clears within the minute.
|
|
109
112
|
* An older runtime may leave it out; read `quota` as `'account'`, `rate` from `put()` as `'hour'` and from `get()` as `'read'`. */
|
|
110
|
-
scope?: 'app' | 'account' | 'hour' | 'month' | 'read';
|
|
113
|
+
scope?: 'app' | 'account' | 'hour' | 'month' | 'read' | 'shared';
|
|
114
|
+
/** On `conflict` from `shared.set()`: the row as it is now (its `v` is the base to use next). */
|
|
115
|
+
current?: Shared;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
/** One person's public value, as `pub.list()` returns it. */
|
|
114
119
|
interface PubRow<T = any> {
|
|
115
120
|
/** Opaque and per app — the same person has a different id in another app. */
|
|
116
121
|
id: string;
|
|
117
|
-
/**
|
|
118
|
-
name: string | null;
|
|
119
|
-
/** One letter for an avatar, yours included. */
|
|
122
|
+
/** One letter for an avatar, yours included. Public rows never carry a name — show "You" on your own row. */
|
|
120
123
|
initial: string;
|
|
121
124
|
/** Their avatar gradient, ready for CSS `background`. */
|
|
122
125
|
color: string;
|
|
@@ -164,6 +167,122 @@ interface Pub<T = any> {
|
|
|
164
167
|
report(id: string, reason?: PubReportReason, details?: string): Promise<void>;
|
|
165
168
|
}
|
|
166
169
|
|
|
170
|
+
/** Someone in a live room — `room.peers()`, and `peer` on `peer` events. */
|
|
171
|
+
interface LivePeer {
|
|
172
|
+
/** One socket — a person with two tabs open is two peers. */
|
|
173
|
+
sid: string;
|
|
174
|
+
/** Opaque and per app — the same value as `ctx.user.id` for them, and as rows in `ctx.pub`. */
|
|
175
|
+
id: string;
|
|
176
|
+
/** One letter for an avatar. No names in rooms. */
|
|
177
|
+
initial: string;
|
|
178
|
+
/** Their avatar gradient, ready for CSS `background`. */
|
|
179
|
+
color: string;
|
|
180
|
+
/** The last thing they sent with `room.cursor(…)` — `null` until they do. */
|
|
181
|
+
data: unknown;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A change to the room's table — your own writes come through here too (`me: true`), before the server confirms them. */
|
|
185
|
+
interface LiveChange {
|
|
186
|
+
key: string;
|
|
187
|
+
/** `undefined` when the key was deleted. */
|
|
188
|
+
value: unknown;
|
|
189
|
+
/** Who did it — `null` for the table the room handed you on join (or after a reconnect). */
|
|
190
|
+
by: { sid: string; id: string } | null;
|
|
191
|
+
me: boolean;
|
|
192
|
+
/** The room's change counter after this change. */
|
|
193
|
+
seq: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A direct line to one other person in a room — `room.direct(sid)`, or `room.on('direct', …)` when they opened one to you.
|
|
197
|
+
* A WebRTC data channel between the two browsers, so a message arrives in a few milliseconds instead of a trip through Fave1 —
|
|
198
|
+
* for what has to be fast and may be thrown away: inputs at 60 Hz, a shared pointer, "typing". Nothing is kept, nobody else in the
|
|
199
|
+
* room sees it, and whoever joins later sees nothing. Fave1 opens the connection inside its own frame (the page never sees addresses
|
|
200
|
+
* or credentials) and, when it can't be opened in 8 s (a firewall, a browser with WebRTC off), the same line opens **through the room**
|
|
201
|
+
* instead — `via` says which. If the direct connection drops later, the line stays open and moves to the room (`via` becomes `'room'`).
|
|
202
|
+
* A line opens only between two apps that both take it — one side calls `direct()`, the other listens with `room.on('direct')` (or calls
|
|
203
|
+
* `direct()` back). Each side can see the other's network (IP) address, as on any video call. Messages are JSON up to 1 KB, like `cursor()`. */
|
|
204
|
+
interface DirectLine {
|
|
205
|
+
/** The other person's socket — one tab. Key what you draw by this. */
|
|
206
|
+
sid: string;
|
|
207
|
+
/** Their app-scoped id (`ctx.user.id` for them) — `''` until the room knows them. */
|
|
208
|
+
id: string;
|
|
209
|
+
/** Lossy lines drop a late message instead of waiting for it — right for per-frame inputs, wrong for a chat. Set with `direct(sid, { lossy: true })`;
|
|
210
|
+
* the side that opened the line decides. */
|
|
211
|
+
readonly lossy: boolean;
|
|
212
|
+
readonly open: boolean;
|
|
213
|
+
/** `'direct'` — browser to browser; `'relay'` — through a TURN relay (still not through Fave1's room); `'room'` — the fallback, through the
|
|
214
|
+
* room's server. `null` until open. Read it live: a direct line that drops moves to `'room'` without closing. */
|
|
215
|
+
readonly via: 'direct' | 'relay' | 'room' | null;
|
|
216
|
+
/** Round trip in milliseconds, measured every 2 s once open — `null` until the first answer, and on a `'room'` line. */
|
|
217
|
+
readonly rtt: number | null;
|
|
218
|
+
/** Send one JSON value (up to 1 KB). Returns `false` — and sends nothing — when the line isn't open or the value is too big
|
|
219
|
+
* (an `error` event says which). Never waits, never throws. `true` means Fave1 has it; on a lossy line it can still be dropped on the way. */
|
|
220
|
+
send(data: unknown): boolean;
|
|
221
|
+
on(type: 'message', handler: (data: unknown) => void): () => void;
|
|
222
|
+
on(type: 'open', handler: (ev: { via: 'direct' | 'relay' | 'room' }) => void): () => void;
|
|
223
|
+
/** `closed` — either side called `close()`; `left` — they left the room; `lost` — your own room connection dropped (Fave1 reconnects the room
|
|
224
|
+
* and they come back with a new sid — open a new line then); `gone` — the app closed. A dropped direct connection is not a close: the line
|
|
225
|
+
* moves to the room (`via`). */
|
|
226
|
+
on(type: 'close', handler: (ev: { reason: 'closed' | 'left' | 'lost' | 'gone' }) => void): () => void;
|
|
227
|
+
on(type: 'error', handler: (ev: { code: 'too-large' | 'rate' | 'invalid' }) => void): () => void;
|
|
228
|
+
close(): void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** A room you joined — one shared table of `key → value`, kept on Fave1 and pushed to everyone in it the moment it changes. */
|
|
232
|
+
interface LiveRoom {
|
|
233
|
+
/** The room's wire name (a hash of what you passed to `join`). */
|
|
234
|
+
id: string;
|
|
235
|
+
/** What you passed to `join`. */
|
|
236
|
+
name: string;
|
|
237
|
+
/** You in this room — `id` is your app-scoped id, `sid` this tab's socket (both filled in once the room is open), and the
|
|
238
|
+
* initial and color the others see you as. */
|
|
239
|
+
me: { id: string | null; sid: string | null; initial: string; color: string };
|
|
240
|
+
/** Connected right now. Writes while closed are kept locally and dropped — wait for `open`. */
|
|
241
|
+
readonly open: boolean;
|
|
242
|
+
readonly seq: number;
|
|
243
|
+
get(key: string): unknown;
|
|
244
|
+
/** A copy of the whole table. */
|
|
245
|
+
all(): Record<string, unknown>;
|
|
246
|
+
/** Set one key for everyone. Applied here at once (a `change` with `me: true`), then sent. Values are JSON up to 8 KB; the room
|
|
247
|
+
* holds up to 2,000 keys / 256 KB. When two people set the same key at the same moment, the one the server gets last wins. */
|
|
248
|
+
set(key: string, value: unknown): Promise<void>;
|
|
249
|
+
del(key: string): Promise<void>;
|
|
250
|
+
/** Share where you are or what you're doing — a cursor, a selection, "typing". Not saved; sent to the others at most every 40 ms,
|
|
251
|
+
* last value wins. Up to 1 KB as JSON. */
|
|
252
|
+
cursor(data: unknown): void;
|
|
253
|
+
peers(): LivePeer[];
|
|
254
|
+
/** A direct line to one person in the room (`DirectLine`). Resolves once it's open — browser to browser, or through the room after 8 s when it
|
|
255
|
+
* can't be (`line.via`). Their app has to take it: it listens with `room.on('direct')`, or calls `direct()` to you — otherwise this rejects
|
|
256
|
+
* with `declined` after 3 s (also when they already hold 8 lines). The same `sid` always gives the same line; up to 8 at once, counting lines
|
|
257
|
+
* opened to you (`quota`). Also rejects with `not-found` when nobody
|
|
258
|
+
* has that `sid`, `invalid` for your own, `unreachable` when the room is closed, `timeout` after 20 s. `{ lossy: true }` for per-frame inputs. */
|
|
259
|
+
direct(sid: string, opts?: { lossy?: boolean }): Promise<DirectLine>;
|
|
260
|
+
on(type: 'change', handler: (change: LiveChange) => void): () => void;
|
|
261
|
+
on(type: 'peer', handler: (ev: { type: 'join' | 'leave' | 'cursor'; peer: LivePeer }) => void): () => void;
|
|
262
|
+
/** Someone in the room opened a direct line to you — it is already open. **Registering this is how your app takes direct lines**: without it,
|
|
263
|
+
* lines from others are declined (unless you call `direct()` to that person yourself). Register it right after `join()`. */
|
|
264
|
+
on(type: 'direct', handler: (line: DirectLine) => void): () => void;
|
|
265
|
+
/** Fires after a reconnect (`join()` itself resolves once the room is open) — the table may have moved on; `change` events for the
|
|
266
|
+
* differences come first. */
|
|
267
|
+
on(type: 'open', handler: (ev: { reconnected: true }) => void): () => void;
|
|
268
|
+
/** `lost` — dropped, Fave1 is reconnecting; `left` — you called `leave()`; `server` — the room closed it (idle for 45 days, or the
|
|
269
|
+
* socket's ticket ran out); `gone` — the app closed. */
|
|
270
|
+
on(type: 'close', handler: (ev: { code: number; reason: 'lost' | 'left' | 'server' | 'gone' }) => void): () => void;
|
|
271
|
+
/** The room refused something — `too-large`, `quota` (room full of keys/bytes), `rate` (over 40 writes a second), `invalid`. */
|
|
272
|
+
on(type: 'error', handler: (ev: { code: string; key?: string }) => void): () => void;
|
|
273
|
+
leave(): Promise<void>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** `live` — rooms where people edit the same thing at the same time, Figma-style. Uses the `pub` permission (no new one): needs a
|
|
277
|
+
* signed-in person who hasn't switched `pub` off, and on someone else's site the first join asks once ("Join the room on …?") —
|
|
278
|
+
* the same yes that covers posting. Anyone who joins a room with the same name sees the same table, so put something only your
|
|
279
|
+
* people know into the name (an invite code, a link). DEV builds get a sandbox room in this browser — tabs on the same site share it. */
|
|
280
|
+
interface Live {
|
|
281
|
+
/** `what` names what people are joining in the permission line — `Join the {what} on <your app>?` — one word, default `room`
|
|
282
|
+
* (a Collab calls it a project). Older launchers ignore it. */
|
|
283
|
+
join(room: string, opts?: { what?: string }): Promise<LiveRoom>;
|
|
284
|
+
}
|
|
285
|
+
|
|
167
286
|
/** One of this person's files for your app, as `files.put()` and `files.list()` return it. */
|
|
168
287
|
interface FileInfo {
|
|
169
288
|
id: string;
|
|
@@ -247,6 +366,48 @@ interface PageAccess {
|
|
|
247
366
|
/** `page` undeclared or switched off in Fave1 settings — none of it is there. */
|
|
248
367
|
type NoPageAccess = { [K in keyof PageAccess]?: undefined };
|
|
249
368
|
|
|
369
|
+
/** A value your app shares by link, as `shared.create()` · `get()` return it. */
|
|
370
|
+
interface Shared<T = unknown> {
|
|
371
|
+
/** The link's two halves. `ref` is `"<id>.<key>"` — the string you put in a URL and pass back to `get()` · `set()`. */
|
|
372
|
+
id: string; key: string; ref: string;
|
|
373
|
+
value: T;
|
|
374
|
+
/** Changes with every write. Pass it as `base` to `set()` so an edit made in between isn't lost. */
|
|
375
|
+
v: number;
|
|
376
|
+
/** Can people with the link write, not just read? The owner sets it with `create()` and `access()`. */
|
|
377
|
+
edit: boolean;
|
|
378
|
+
updatedAt: string;
|
|
379
|
+
/** This person made it. */
|
|
380
|
+
mine: boolean;
|
|
381
|
+
/** Who made it, and who wrote last (if someone other than the owner did) — first letter and avatar color, never a name. */
|
|
382
|
+
owner: { initial: string; color: string } | null;
|
|
383
|
+
editor: { initial: string; color: string } | null;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** `shared` — one value shared by one link: a note, a list, a board. Declared with `storage` (no new permission).
|
|
387
|
+
* The owner creates it; anyone with the link reads it — signed out, or without your app added; and if the owner turned
|
|
388
|
+
* `edit` on, any signed-in person with the link can write. The owner can change that or take the link back at any time.
|
|
389
|
+
* Values up to 64 KB, 100 per person per app; they count toward the owner's Fave1 storage. The link is the secret —
|
|
390
|
+
* put `ref` in a URL your app opens with (`<id>.fave1.app/#s=<ref>`) and never post it anywhere public yourself.
|
|
391
|
+
* Owner calls (`create` · `access` · `list` · `delete`) follow the storage rules: a signed-in person, one OK on a new
|
|
392
|
+
* site, never at home. DEV builds keep it in this browser — a link made there opens nowhere else. */
|
|
393
|
+
interface SharedApi {
|
|
394
|
+
/** Share a value. `edit` lets people with the link write (default read-only). Rejects with `quota` — `err.scope` `'shared'`
|
|
395
|
+
* at 100 shared values, `'account'` when their Fave1 storage is full. */
|
|
396
|
+
create<T = unknown>(value: T, opts?: { edit?: boolean }): Promise<Shared<T>>;
|
|
397
|
+
/** Read by link. `null` when it's gone or the link is wrong — never throws for that. Works signed out. */
|
|
398
|
+
get<T = unknown>(ref: string): Promise<Shared<T> | null>;
|
|
399
|
+
/** Write by link — as the owner, or as a signed-in person when `edit` is on (`denied` otherwise, `signed-out` with no account).
|
|
400
|
+
* Pass `base` (the `v` you read) and, if someone wrote in between, it rejects with `conflict` carrying `err.current`
|
|
401
|
+
* (the row now): merge, then call `set()` again with its `v`. Without `base` it overwrites. */
|
|
402
|
+
set<T = unknown>(ref: string, value: T, opts?: { base?: number }): Promise<{ v: number }>;
|
|
403
|
+
/** Owner only: let people with the link write, or stop that. Takes the `id` or the `ref`. */
|
|
404
|
+
access(idOrRef: string, opts: { edit: boolean }): Promise<void>;
|
|
405
|
+
/** Everything this person shares from your app — with the keys, so you can show the links again. */
|
|
406
|
+
list(): Promise<Shared[]>;
|
|
407
|
+
/** Owner only: take the link back. Whoever has it gets `null` from then on. Resolves even if it was already gone. */
|
|
408
|
+
delete(idOrRef: string): Promise<void>;
|
|
409
|
+
}
|
|
410
|
+
|
|
250
411
|
interface Ctx {
|
|
251
412
|
ui: Ui;
|
|
252
413
|
/** Where you're running: `'page'` — on someone's site, opened from the bookmarklet;
|
|
@@ -288,7 +449,11 @@ interface Ctx {
|
|
|
288
449
|
};
|
|
289
450
|
/** Files on the account — declared with `storage`, like the JSON above. */
|
|
290
451
|
files: Files;
|
|
452
|
+
/** Values shared by link — declared with `storage` too. */
|
|
453
|
+
shared: SharedApi;
|
|
291
454
|
pub: Pub;
|
|
455
|
+
/** Live rooms — the same table, edited by several people at once (uses `pub`). */
|
|
456
|
+
live: Live;
|
|
292
457
|
/** Is this permission live right now? `pub` also needs a signed-in person who hasn't switched it off. */
|
|
293
458
|
can(permission: Permission): boolean;
|
|
294
459
|
/** Opens this app's permission screen in Fave1 settings. Only the person can turn things on. */
|
|
@@ -16,12 +16,13 @@ npm run dev # serves your app at http://localhost:7300 — leave it runnin
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Open Fave1 from your bookmarks bar on any shop or article, hold the Fave1 logo,
|
|
19
|
-
paste `http://localhost:7300` and
|
|
19
|
+
paste `http://localhost:7300` and Add. Your app shows up first with a DEV badge.
|
|
20
20
|
Chrome asks once per site to allow local network access — allow it, and press
|
|
21
|
-
|
|
21
|
+
Add again if the panel already said it found nothing. Save a file, reopen the
|
|
22
22
|
app, and it's the new build. Changed
|
|
23
23
|
`manifest.json`? Close Fave1 and click it in your bookmarks bar again — reopening
|
|
24
|
-
the app isn't enough.
|
|
24
|
+
the app isn't enough. Building another app at the same time? Its `npm run dev` takes the
|
|
25
|
+
next free port (7301, 7302…) — add that address too, and they all show up.
|
|
25
26
|
Leave that terminal running and type everything else — `npm run submit` too — in a
|
|
26
27
|
second one; a command typed where the dev server runs does nothing.
|
|
27
28
|
|
|
@@ -48,8 +49,15 @@ npm run submit -- --whats-new "Remembers your place" # with a line for the sto
|
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
It prints a **Test** link — your app on its own home (`{{id}}.fave1.app`), in any
|
|
51
|
-
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
52
|
-
|
|
52
|
+
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
53
|
+
on a phone or in Safari. On your laptop, every build you added as a DEV source also
|
|
54
|
+
shows up in [My Fave1](https://www.fave1.com/myapps) — open it there to try its home
|
|
55
|
+
in a window.
|
|
56
|
+
|
|
57
|
+
That window opens phone-size. Built your home to use more room? Add
|
|
58
|
+
`"window": "medium"` (760 wide) or `"window": "wide"` (1120) to `manifest.json` — it
|
|
59
|
+
opens that wide when the screen allows, and people can still resize it. Phones always
|
|
60
|
+
get the full screen.
|
|
53
61
|
|
|
54
62
|
An exported `FAVE1_KEY` in your terminal or CI wins over `.env.local`, which wins
|
|
55
63
|
over `.env`.
|
|
@@ -94,6 +94,9 @@ type Fave1ErrorCode =
|
|
|
94
94
|
| 'too-large' | 'quota' | 'invalid'
|
|
95
95
|
| 'rate' // too fast — pub writes in a row, file uploads (`err.scope` 'hour' | 'month') or file reads ('read'): wait, then carry on
|
|
96
96
|
| 'cancelled' // they said "Not now"
|
|
97
|
+
| 'conflict' // shared.set() with a stale base — err.current is the row now; merge and set() again
|
|
98
|
+
| 'not-found' // shared.access() · delete() on a link that isn't yours or is gone · room.direct() to a sid that isn't in the room
|
|
99
|
+
| 'declined' // room.direct(): their app doesn't take direct lines (no room.on('direct') and no direct() back within 3 s)
|
|
97
100
|
| 'unreachable' | 'timeout' | 'server';
|
|
98
101
|
|
|
99
102
|
/** What `ctx` rejects with — an `Error` carrying a `code`. `catch (err) { const e = err as Fave1Error; … }` */
|
|
@@ -107,16 +110,16 @@ interface Fave1Error extends Error {
|
|
|
107
110
|
* (more on paid plans): it won't clear today, so tell them. From `files.get()`: `'read'` — 600 reads in a minute, all apps
|
|
108
111
|
* together: back off, it clears within the minute.
|
|
109
112
|
* An older runtime may leave it out; read `quota` as `'account'`, `rate` from `put()` as `'hour'` and from `get()` as `'read'`. */
|
|
110
|
-
scope?: 'app' | 'account' | 'hour' | 'month' | 'read';
|
|
113
|
+
scope?: 'app' | 'account' | 'hour' | 'month' | 'read' | 'shared';
|
|
114
|
+
/** On `conflict` from `shared.set()`: the row as it is now (its `v` is the base to use next). */
|
|
115
|
+
current?: Shared;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
/** One person's public value, as `pub.list()` returns it. */
|
|
114
119
|
interface PubRow<T = any> {
|
|
115
120
|
/** Opaque and per app — the same person has a different id in another app. */
|
|
116
121
|
id: string;
|
|
117
|
-
/**
|
|
118
|
-
name: string | null;
|
|
119
|
-
/** One letter for an avatar, yours included. */
|
|
122
|
+
/** One letter for an avatar, yours included. Public rows never carry a name — show "You" on your own row. */
|
|
120
123
|
initial: string;
|
|
121
124
|
/** Their avatar gradient, ready for CSS `background`. */
|
|
122
125
|
color: string;
|
|
@@ -164,6 +167,122 @@ interface Pub<T = any> {
|
|
|
164
167
|
report(id: string, reason?: PubReportReason, details?: string): Promise<void>;
|
|
165
168
|
}
|
|
166
169
|
|
|
170
|
+
/** Someone in a live room — `room.peers()`, and `peer` on `peer` events. */
|
|
171
|
+
interface LivePeer {
|
|
172
|
+
/** One socket — a person with two tabs open is two peers. */
|
|
173
|
+
sid: string;
|
|
174
|
+
/** Opaque and per app — the same value as `ctx.user.id` for them, and as rows in `ctx.pub`. */
|
|
175
|
+
id: string;
|
|
176
|
+
/** One letter for an avatar. No names in rooms. */
|
|
177
|
+
initial: string;
|
|
178
|
+
/** Their avatar gradient, ready for CSS `background`. */
|
|
179
|
+
color: string;
|
|
180
|
+
/** The last thing they sent with `room.cursor(…)` — `null` until they do. */
|
|
181
|
+
data: unknown;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A change to the room's table — your own writes come through here too (`me: true`), before the server confirms them. */
|
|
185
|
+
interface LiveChange {
|
|
186
|
+
key: string;
|
|
187
|
+
/** `undefined` when the key was deleted. */
|
|
188
|
+
value: unknown;
|
|
189
|
+
/** Who did it — `null` for the table the room handed you on join (or after a reconnect). */
|
|
190
|
+
by: { sid: string; id: string } | null;
|
|
191
|
+
me: boolean;
|
|
192
|
+
/** The room's change counter after this change. */
|
|
193
|
+
seq: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A direct line to one other person in a room — `room.direct(sid)`, or `room.on('direct', …)` when they opened one to you.
|
|
197
|
+
* A WebRTC data channel between the two browsers, so a message arrives in a few milliseconds instead of a trip through Fave1 —
|
|
198
|
+
* for what has to be fast and may be thrown away: inputs at 60 Hz, a shared pointer, "typing". Nothing is kept, nobody else in the
|
|
199
|
+
* room sees it, and whoever joins later sees nothing. Fave1 opens the connection inside its own frame (the page never sees addresses
|
|
200
|
+
* or credentials) and, when it can't be opened in 8 s (a firewall, a browser with WebRTC off), the same line opens **through the room**
|
|
201
|
+
* instead — `via` says which. If the direct connection drops later, the line stays open and moves to the room (`via` becomes `'room'`).
|
|
202
|
+
* A line opens only between two apps that both take it — one side calls `direct()`, the other listens with `room.on('direct')` (or calls
|
|
203
|
+
* `direct()` back). Each side can see the other's network (IP) address, as on any video call. Messages are JSON up to 1 KB, like `cursor()`. */
|
|
204
|
+
interface DirectLine {
|
|
205
|
+
/** The other person's socket — one tab. Key what you draw by this. */
|
|
206
|
+
sid: string;
|
|
207
|
+
/** Their app-scoped id (`ctx.user.id` for them) — `''` until the room knows them. */
|
|
208
|
+
id: string;
|
|
209
|
+
/** Lossy lines drop a late message instead of waiting for it — right for per-frame inputs, wrong for a chat. Set with `direct(sid, { lossy: true })`;
|
|
210
|
+
* the side that opened the line decides. */
|
|
211
|
+
readonly lossy: boolean;
|
|
212
|
+
readonly open: boolean;
|
|
213
|
+
/** `'direct'` — browser to browser; `'relay'` — through a TURN relay (still not through Fave1's room); `'room'` — the fallback, through the
|
|
214
|
+
* room's server. `null` until open. Read it live: a direct line that drops moves to `'room'` without closing. */
|
|
215
|
+
readonly via: 'direct' | 'relay' | 'room' | null;
|
|
216
|
+
/** Round trip in milliseconds, measured every 2 s once open — `null` until the first answer, and on a `'room'` line. */
|
|
217
|
+
readonly rtt: number | null;
|
|
218
|
+
/** Send one JSON value (up to 1 KB). Returns `false` — and sends nothing — when the line isn't open or the value is too big
|
|
219
|
+
* (an `error` event says which). Never waits, never throws. `true` means Fave1 has it; on a lossy line it can still be dropped on the way. */
|
|
220
|
+
send(data: unknown): boolean;
|
|
221
|
+
on(type: 'message', handler: (data: unknown) => void): () => void;
|
|
222
|
+
on(type: 'open', handler: (ev: { via: 'direct' | 'relay' | 'room' }) => void): () => void;
|
|
223
|
+
/** `closed` — either side called `close()`; `left` — they left the room; `lost` — your own room connection dropped (Fave1 reconnects the room
|
|
224
|
+
* and they come back with a new sid — open a new line then); `gone` — the app closed. A dropped direct connection is not a close: the line
|
|
225
|
+
* moves to the room (`via`). */
|
|
226
|
+
on(type: 'close', handler: (ev: { reason: 'closed' | 'left' | 'lost' | 'gone' }) => void): () => void;
|
|
227
|
+
on(type: 'error', handler: (ev: { code: 'too-large' | 'rate' | 'invalid' }) => void): () => void;
|
|
228
|
+
close(): void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** A room you joined — one shared table of `key → value`, kept on Fave1 and pushed to everyone in it the moment it changes. */
|
|
232
|
+
interface LiveRoom {
|
|
233
|
+
/** The room's wire name (a hash of what you passed to `join`). */
|
|
234
|
+
id: string;
|
|
235
|
+
/** What you passed to `join`. */
|
|
236
|
+
name: string;
|
|
237
|
+
/** You in this room — `id` is your app-scoped id, `sid` this tab's socket (both filled in once the room is open), and the
|
|
238
|
+
* initial and color the others see you as. */
|
|
239
|
+
me: { id: string | null; sid: string | null; initial: string; color: string };
|
|
240
|
+
/** Connected right now. Writes while closed are kept locally and dropped — wait for `open`. */
|
|
241
|
+
readonly open: boolean;
|
|
242
|
+
readonly seq: number;
|
|
243
|
+
get(key: string): unknown;
|
|
244
|
+
/** A copy of the whole table. */
|
|
245
|
+
all(): Record<string, unknown>;
|
|
246
|
+
/** Set one key for everyone. Applied here at once (a `change` with `me: true`), then sent. Values are JSON up to 8 KB; the room
|
|
247
|
+
* holds up to 2,000 keys / 256 KB. When two people set the same key at the same moment, the one the server gets last wins. */
|
|
248
|
+
set(key: string, value: unknown): Promise<void>;
|
|
249
|
+
del(key: string): Promise<void>;
|
|
250
|
+
/** Share where you are or what you're doing — a cursor, a selection, "typing". Not saved; sent to the others at most every 40 ms,
|
|
251
|
+
* last value wins. Up to 1 KB as JSON. */
|
|
252
|
+
cursor(data: unknown): void;
|
|
253
|
+
peers(): LivePeer[];
|
|
254
|
+
/** A direct line to one person in the room (`DirectLine`). Resolves once it's open — browser to browser, or through the room after 8 s when it
|
|
255
|
+
* can't be (`line.via`). Their app has to take it: it listens with `room.on('direct')`, or calls `direct()` to you — otherwise this rejects
|
|
256
|
+
* with `declined` after 3 s (also when they already hold 8 lines). The same `sid` always gives the same line; up to 8 at once, counting lines
|
|
257
|
+
* opened to you (`quota`). Also rejects with `not-found` when nobody
|
|
258
|
+
* has that `sid`, `invalid` for your own, `unreachable` when the room is closed, `timeout` after 20 s. `{ lossy: true }` for per-frame inputs. */
|
|
259
|
+
direct(sid: string, opts?: { lossy?: boolean }): Promise<DirectLine>;
|
|
260
|
+
on(type: 'change', handler: (change: LiveChange) => void): () => void;
|
|
261
|
+
on(type: 'peer', handler: (ev: { type: 'join' | 'leave' | 'cursor'; peer: LivePeer }) => void): () => void;
|
|
262
|
+
/** Someone in the room opened a direct line to you — it is already open. **Registering this is how your app takes direct lines**: without it,
|
|
263
|
+
* lines from others are declined (unless you call `direct()` to that person yourself). Register it right after `join()`. */
|
|
264
|
+
on(type: 'direct', handler: (line: DirectLine) => void): () => void;
|
|
265
|
+
/** Fires after a reconnect (`join()` itself resolves once the room is open) — the table may have moved on; `change` events for the
|
|
266
|
+
* differences come first. */
|
|
267
|
+
on(type: 'open', handler: (ev: { reconnected: true }) => void): () => void;
|
|
268
|
+
/** `lost` — dropped, Fave1 is reconnecting; `left` — you called `leave()`; `server` — the room closed it (idle for 45 days, or the
|
|
269
|
+
* socket's ticket ran out); `gone` — the app closed. */
|
|
270
|
+
on(type: 'close', handler: (ev: { code: number; reason: 'lost' | 'left' | 'server' | 'gone' }) => void): () => void;
|
|
271
|
+
/** The room refused something — `too-large`, `quota` (room full of keys/bytes), `rate` (over 40 writes a second), `invalid`. */
|
|
272
|
+
on(type: 'error', handler: (ev: { code: string; key?: string }) => void): () => void;
|
|
273
|
+
leave(): Promise<void>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** `live` — rooms where people edit the same thing at the same time, Figma-style. Uses the `pub` permission (no new one): needs a
|
|
277
|
+
* signed-in person who hasn't switched `pub` off, and on someone else's site the first join asks once ("Join the room on …?") —
|
|
278
|
+
* the same yes that covers posting. Anyone who joins a room with the same name sees the same table, so put something only your
|
|
279
|
+
* people know into the name (an invite code, a link). DEV builds get a sandbox room in this browser — tabs on the same site share it. */
|
|
280
|
+
interface Live {
|
|
281
|
+
/** `what` names what people are joining in the permission line — `Join the {what} on <your app>?` — one word, default `room`
|
|
282
|
+
* (a Collab calls it a project). Older launchers ignore it. */
|
|
283
|
+
join(room: string, opts?: { what?: string }): Promise<LiveRoom>;
|
|
284
|
+
}
|
|
285
|
+
|
|
167
286
|
/** One of this person's files for your app, as `files.put()` and `files.list()` return it. */
|
|
168
287
|
interface FileInfo {
|
|
169
288
|
id: string;
|
|
@@ -247,6 +366,48 @@ interface PageAccess {
|
|
|
247
366
|
/** `page` undeclared or switched off in Fave1 settings — none of it is there. */
|
|
248
367
|
type NoPageAccess = { [K in keyof PageAccess]?: undefined };
|
|
249
368
|
|
|
369
|
+
/** A value your app shares by link, as `shared.create()` · `get()` return it. */
|
|
370
|
+
interface Shared<T = unknown> {
|
|
371
|
+
/** The link's two halves. `ref` is `"<id>.<key>"` — the string you put in a URL and pass back to `get()` · `set()`. */
|
|
372
|
+
id: string; key: string; ref: string;
|
|
373
|
+
value: T;
|
|
374
|
+
/** Changes with every write. Pass it as `base` to `set()` so an edit made in between isn't lost. */
|
|
375
|
+
v: number;
|
|
376
|
+
/** Can people with the link write, not just read? The owner sets it with `create()` and `access()`. */
|
|
377
|
+
edit: boolean;
|
|
378
|
+
updatedAt: string;
|
|
379
|
+
/** This person made it. */
|
|
380
|
+
mine: boolean;
|
|
381
|
+
/** Who made it, and who wrote last (if someone other than the owner did) — first letter and avatar color, never a name. */
|
|
382
|
+
owner: { initial: string; color: string } | null;
|
|
383
|
+
editor: { initial: string; color: string } | null;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** `shared` — one value shared by one link: a note, a list, a board. Declared with `storage` (no new permission).
|
|
387
|
+
* The owner creates it; anyone with the link reads it — signed out, or without your app added; and if the owner turned
|
|
388
|
+
* `edit` on, any signed-in person with the link can write. The owner can change that or take the link back at any time.
|
|
389
|
+
* Values up to 64 KB, 100 per person per app; they count toward the owner's Fave1 storage. The link is the secret —
|
|
390
|
+
* put `ref` in a URL your app opens with (`<id>.fave1.app/#s=<ref>`) and never post it anywhere public yourself.
|
|
391
|
+
* Owner calls (`create` · `access` · `list` · `delete`) follow the storage rules: a signed-in person, one OK on a new
|
|
392
|
+
* site, never at home. DEV builds keep it in this browser — a link made there opens nowhere else. */
|
|
393
|
+
interface SharedApi {
|
|
394
|
+
/** Share a value. `edit` lets people with the link write (default read-only). Rejects with `quota` — `err.scope` `'shared'`
|
|
395
|
+
* at 100 shared values, `'account'` when their Fave1 storage is full. */
|
|
396
|
+
create<T = unknown>(value: T, opts?: { edit?: boolean }): Promise<Shared<T>>;
|
|
397
|
+
/** Read by link. `null` when it's gone or the link is wrong — never throws for that. Works signed out. */
|
|
398
|
+
get<T = unknown>(ref: string): Promise<Shared<T> | null>;
|
|
399
|
+
/** Write by link — as the owner, or as a signed-in person when `edit` is on (`denied` otherwise, `signed-out` with no account).
|
|
400
|
+
* Pass `base` (the `v` you read) and, if someone wrote in between, it rejects with `conflict` carrying `err.current`
|
|
401
|
+
* (the row now): merge, then call `set()` again with its `v`. Without `base` it overwrites. */
|
|
402
|
+
set<T = unknown>(ref: string, value: T, opts?: { base?: number }): Promise<{ v: number }>;
|
|
403
|
+
/** Owner only: let people with the link write, or stop that. Takes the `id` or the `ref`. */
|
|
404
|
+
access(idOrRef: string, opts: { edit: boolean }): Promise<void>;
|
|
405
|
+
/** Everything this person shares from your app — with the keys, so you can show the links again. */
|
|
406
|
+
list(): Promise<Shared[]>;
|
|
407
|
+
/** Owner only: take the link back. Whoever has it gets `null` from then on. Resolves even if it was already gone. */
|
|
408
|
+
delete(idOrRef: string): Promise<void>;
|
|
409
|
+
}
|
|
410
|
+
|
|
250
411
|
interface Ctx {
|
|
251
412
|
ui: Ui;
|
|
252
413
|
/** Where you're running: `'page'` — on someone's site, opened from the bookmarklet;
|
|
@@ -288,7 +449,11 @@ interface Ctx {
|
|
|
288
449
|
};
|
|
289
450
|
/** Files on the account — declared with `storage`, like the JSON above. */
|
|
290
451
|
files: Files;
|
|
452
|
+
/** Values shared by link — declared with `storage` too. */
|
|
453
|
+
shared: SharedApi;
|
|
291
454
|
pub: Pub;
|
|
455
|
+
/** Live rooms — the same table, edited by several people at once (uses `pub`). */
|
|
456
|
+
live: Live;
|
|
292
457
|
/** Is this permission live right now? `pub` also needs a signed-in person who hasn't switched it off. */
|
|
293
458
|
can(permission: Permission): boolean;
|
|
294
459
|
/** Opens this app's permission screen in Fave1 settings. Only the person can turn things on. */
|
|
@@ -16,12 +16,13 @@ npm run dev # serves your app at http://localhost:7300 — leave it runnin
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Open Fave1 from your bookmarks bar on any shop or article, hold the Fave1 logo,
|
|
19
|
-
paste `http://localhost:7300` and
|
|
19
|
+
paste `http://localhost:7300` and Add. Your app shows up first with a DEV badge.
|
|
20
20
|
Chrome asks once per site to allow local network access — allow it, and press
|
|
21
|
-
|
|
21
|
+
Add again if the panel already said it found nothing. Save a file, reopen the
|
|
22
22
|
app, and it's the new build. Changed
|
|
23
23
|
`manifest.json`? Close Fave1 and click it in your bookmarks bar again — reopening
|
|
24
|
-
the app isn't enough.
|
|
24
|
+
the app isn't enough. Building another app at the same time? Its `npm run dev` takes the
|
|
25
|
+
next free port (7301, 7302…) — add that address too, and they all show up.
|
|
25
26
|
Leave that terminal running and type everything else — `npm run submit` too — in a
|
|
26
27
|
second one; a command typed where the dev server runs does nothing.
|
|
27
28
|
|
|
@@ -53,8 +54,15 @@ npm run submit -- --whats-new "Remembers your place" # with a line for the sto
|
|
|
53
54
|
```
|
|
54
55
|
|
|
55
56
|
It prints a **Test** link — your app on its own home (`{{id}}.fave1.app`), in any
|
|
56
|
-
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
57
|
-
|
|
57
|
+
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
58
|
+
on a phone or in Safari. On your laptop, every build you added as a DEV source also
|
|
59
|
+
shows up in [My Fave1](https://www.fave1.com/myapps) — open it there to try its home
|
|
60
|
+
in a window.
|
|
61
|
+
|
|
62
|
+
That window opens phone-size. Built your home to use more room? Add
|
|
63
|
+
`"window": "medium"` (760 wide) or `"window": "wide"` (1120) to `manifest.json` — it
|
|
64
|
+
opens that wide when the screen allows, and people can still resize it. Phones always
|
|
65
|
+
get the full screen.
|
|
58
66
|
|
|
59
67
|
An exported `FAVE1_KEY` in your terminal or CI wins over `.env.local`, which wins
|
|
60
68
|
over `.env`.
|
|
@@ -94,6 +94,9 @@ type Fave1ErrorCode =
|
|
|
94
94
|
| 'too-large' | 'quota' | 'invalid'
|
|
95
95
|
| 'rate' // too fast — pub writes in a row, file uploads (`err.scope` 'hour' | 'month') or file reads ('read'): wait, then carry on
|
|
96
96
|
| 'cancelled' // they said "Not now"
|
|
97
|
+
| 'conflict' // shared.set() with a stale base — err.current is the row now; merge and set() again
|
|
98
|
+
| 'not-found' // shared.access() · delete() on a link that isn't yours or is gone · room.direct() to a sid that isn't in the room
|
|
99
|
+
| 'declined' // room.direct(): their app doesn't take direct lines (no room.on('direct') and no direct() back within 3 s)
|
|
97
100
|
| 'unreachable' | 'timeout' | 'server';
|
|
98
101
|
|
|
99
102
|
/** What `ctx` rejects with — an `Error` carrying a `code`. `catch (err) { const e = err as Fave1Error; … }` */
|
|
@@ -107,16 +110,16 @@ interface Fave1Error extends Error {
|
|
|
107
110
|
* (more on paid plans): it won't clear today, so tell them. From `files.get()`: `'read'` — 600 reads in a minute, all apps
|
|
108
111
|
* together: back off, it clears within the minute.
|
|
109
112
|
* An older runtime may leave it out; read `quota` as `'account'`, `rate` from `put()` as `'hour'` and from `get()` as `'read'`. */
|
|
110
|
-
scope?: 'app' | 'account' | 'hour' | 'month' | 'read';
|
|
113
|
+
scope?: 'app' | 'account' | 'hour' | 'month' | 'read' | 'shared';
|
|
114
|
+
/** On `conflict` from `shared.set()`: the row as it is now (its `v` is the base to use next). */
|
|
115
|
+
current?: Shared;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
/** One person's public value, as `pub.list()` returns it. */
|
|
114
119
|
interface PubRow<T = any> {
|
|
115
120
|
/** Opaque and per app — the same person has a different id in another app. */
|
|
116
121
|
id: string;
|
|
117
|
-
/**
|
|
118
|
-
name: string | null;
|
|
119
|
-
/** One letter for an avatar, yours included. */
|
|
122
|
+
/** One letter for an avatar, yours included. Public rows never carry a name — show "You" on your own row. */
|
|
120
123
|
initial: string;
|
|
121
124
|
/** Their avatar gradient, ready for CSS `background`. */
|
|
122
125
|
color: string;
|
|
@@ -164,6 +167,122 @@ interface Pub<T = any> {
|
|
|
164
167
|
report(id: string, reason?: PubReportReason, details?: string): Promise<void>;
|
|
165
168
|
}
|
|
166
169
|
|
|
170
|
+
/** Someone in a live room — `room.peers()`, and `peer` on `peer` events. */
|
|
171
|
+
interface LivePeer {
|
|
172
|
+
/** One socket — a person with two tabs open is two peers. */
|
|
173
|
+
sid: string;
|
|
174
|
+
/** Opaque and per app — the same value as `ctx.user.id` for them, and as rows in `ctx.pub`. */
|
|
175
|
+
id: string;
|
|
176
|
+
/** One letter for an avatar. No names in rooms. */
|
|
177
|
+
initial: string;
|
|
178
|
+
/** Their avatar gradient, ready for CSS `background`. */
|
|
179
|
+
color: string;
|
|
180
|
+
/** The last thing they sent with `room.cursor(…)` — `null` until they do. */
|
|
181
|
+
data: unknown;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A change to the room's table — your own writes come through here too (`me: true`), before the server confirms them. */
|
|
185
|
+
interface LiveChange {
|
|
186
|
+
key: string;
|
|
187
|
+
/** `undefined` when the key was deleted. */
|
|
188
|
+
value: unknown;
|
|
189
|
+
/** Who did it — `null` for the table the room handed you on join (or after a reconnect). */
|
|
190
|
+
by: { sid: string; id: string } | null;
|
|
191
|
+
me: boolean;
|
|
192
|
+
/** The room's change counter after this change. */
|
|
193
|
+
seq: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A direct line to one other person in a room — `room.direct(sid)`, or `room.on('direct', …)` when they opened one to you.
|
|
197
|
+
* A WebRTC data channel between the two browsers, so a message arrives in a few milliseconds instead of a trip through Fave1 —
|
|
198
|
+
* for what has to be fast and may be thrown away: inputs at 60 Hz, a shared pointer, "typing". Nothing is kept, nobody else in the
|
|
199
|
+
* room sees it, and whoever joins later sees nothing. Fave1 opens the connection inside its own frame (the page never sees addresses
|
|
200
|
+
* or credentials) and, when it can't be opened in 8 s (a firewall, a browser with WebRTC off), the same line opens **through the room**
|
|
201
|
+
* instead — `via` says which. If the direct connection drops later, the line stays open and moves to the room (`via` becomes `'room'`).
|
|
202
|
+
* A line opens only between two apps that both take it — one side calls `direct()`, the other listens with `room.on('direct')` (or calls
|
|
203
|
+
* `direct()` back). Each side can see the other's network (IP) address, as on any video call. Messages are JSON up to 1 KB, like `cursor()`. */
|
|
204
|
+
interface DirectLine {
|
|
205
|
+
/** The other person's socket — one tab. Key what you draw by this. */
|
|
206
|
+
sid: string;
|
|
207
|
+
/** Their app-scoped id (`ctx.user.id` for them) — `''` until the room knows them. */
|
|
208
|
+
id: string;
|
|
209
|
+
/** Lossy lines drop a late message instead of waiting for it — right for per-frame inputs, wrong for a chat. Set with `direct(sid, { lossy: true })`;
|
|
210
|
+
* the side that opened the line decides. */
|
|
211
|
+
readonly lossy: boolean;
|
|
212
|
+
readonly open: boolean;
|
|
213
|
+
/** `'direct'` — browser to browser; `'relay'` — through a TURN relay (still not through Fave1's room); `'room'` — the fallback, through the
|
|
214
|
+
* room's server. `null` until open. Read it live: a direct line that drops moves to `'room'` without closing. */
|
|
215
|
+
readonly via: 'direct' | 'relay' | 'room' | null;
|
|
216
|
+
/** Round trip in milliseconds, measured every 2 s once open — `null` until the first answer, and on a `'room'` line. */
|
|
217
|
+
readonly rtt: number | null;
|
|
218
|
+
/** Send one JSON value (up to 1 KB). Returns `false` — and sends nothing — when the line isn't open or the value is too big
|
|
219
|
+
* (an `error` event says which). Never waits, never throws. `true` means Fave1 has it; on a lossy line it can still be dropped on the way. */
|
|
220
|
+
send(data: unknown): boolean;
|
|
221
|
+
on(type: 'message', handler: (data: unknown) => void): () => void;
|
|
222
|
+
on(type: 'open', handler: (ev: { via: 'direct' | 'relay' | 'room' }) => void): () => void;
|
|
223
|
+
/** `closed` — either side called `close()`; `left` — they left the room; `lost` — your own room connection dropped (Fave1 reconnects the room
|
|
224
|
+
* and they come back with a new sid — open a new line then); `gone` — the app closed. A dropped direct connection is not a close: the line
|
|
225
|
+
* moves to the room (`via`). */
|
|
226
|
+
on(type: 'close', handler: (ev: { reason: 'closed' | 'left' | 'lost' | 'gone' }) => void): () => void;
|
|
227
|
+
on(type: 'error', handler: (ev: { code: 'too-large' | 'rate' | 'invalid' }) => void): () => void;
|
|
228
|
+
close(): void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** A room you joined — one shared table of `key → value`, kept on Fave1 and pushed to everyone in it the moment it changes. */
|
|
232
|
+
interface LiveRoom {
|
|
233
|
+
/** The room's wire name (a hash of what you passed to `join`). */
|
|
234
|
+
id: string;
|
|
235
|
+
/** What you passed to `join`. */
|
|
236
|
+
name: string;
|
|
237
|
+
/** You in this room — `id` is your app-scoped id, `sid` this tab's socket (both filled in once the room is open), and the
|
|
238
|
+
* initial and color the others see you as. */
|
|
239
|
+
me: { id: string | null; sid: string | null; initial: string; color: string };
|
|
240
|
+
/** Connected right now. Writes while closed are kept locally and dropped — wait for `open`. */
|
|
241
|
+
readonly open: boolean;
|
|
242
|
+
readonly seq: number;
|
|
243
|
+
get(key: string): unknown;
|
|
244
|
+
/** A copy of the whole table. */
|
|
245
|
+
all(): Record<string, unknown>;
|
|
246
|
+
/** Set one key for everyone. Applied here at once (a `change` with `me: true`), then sent. Values are JSON up to 8 KB; the room
|
|
247
|
+
* holds up to 2,000 keys / 256 KB. When two people set the same key at the same moment, the one the server gets last wins. */
|
|
248
|
+
set(key: string, value: unknown): Promise<void>;
|
|
249
|
+
del(key: string): Promise<void>;
|
|
250
|
+
/** Share where you are or what you're doing — a cursor, a selection, "typing". Not saved; sent to the others at most every 40 ms,
|
|
251
|
+
* last value wins. Up to 1 KB as JSON. */
|
|
252
|
+
cursor(data: unknown): void;
|
|
253
|
+
peers(): LivePeer[];
|
|
254
|
+
/** A direct line to one person in the room (`DirectLine`). Resolves once it's open — browser to browser, or through the room after 8 s when it
|
|
255
|
+
* can't be (`line.via`). Their app has to take it: it listens with `room.on('direct')`, or calls `direct()` to you — otherwise this rejects
|
|
256
|
+
* with `declined` after 3 s (also when they already hold 8 lines). The same `sid` always gives the same line; up to 8 at once, counting lines
|
|
257
|
+
* opened to you (`quota`). Also rejects with `not-found` when nobody
|
|
258
|
+
* has that `sid`, `invalid` for your own, `unreachable` when the room is closed, `timeout` after 20 s. `{ lossy: true }` for per-frame inputs. */
|
|
259
|
+
direct(sid: string, opts?: { lossy?: boolean }): Promise<DirectLine>;
|
|
260
|
+
on(type: 'change', handler: (change: LiveChange) => void): () => void;
|
|
261
|
+
on(type: 'peer', handler: (ev: { type: 'join' | 'leave' | 'cursor'; peer: LivePeer }) => void): () => void;
|
|
262
|
+
/** Someone in the room opened a direct line to you — it is already open. **Registering this is how your app takes direct lines**: without it,
|
|
263
|
+
* lines from others are declined (unless you call `direct()` to that person yourself). Register it right after `join()`. */
|
|
264
|
+
on(type: 'direct', handler: (line: DirectLine) => void): () => void;
|
|
265
|
+
/** Fires after a reconnect (`join()` itself resolves once the room is open) — the table may have moved on; `change` events for the
|
|
266
|
+
* differences come first. */
|
|
267
|
+
on(type: 'open', handler: (ev: { reconnected: true }) => void): () => void;
|
|
268
|
+
/** `lost` — dropped, Fave1 is reconnecting; `left` — you called `leave()`; `server` — the room closed it (idle for 45 days, or the
|
|
269
|
+
* socket's ticket ran out); `gone` — the app closed. */
|
|
270
|
+
on(type: 'close', handler: (ev: { code: number; reason: 'lost' | 'left' | 'server' | 'gone' }) => void): () => void;
|
|
271
|
+
/** The room refused something — `too-large`, `quota` (room full of keys/bytes), `rate` (over 40 writes a second), `invalid`. */
|
|
272
|
+
on(type: 'error', handler: (ev: { code: string; key?: string }) => void): () => void;
|
|
273
|
+
leave(): Promise<void>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** `live` — rooms where people edit the same thing at the same time, Figma-style. Uses the `pub` permission (no new one): needs a
|
|
277
|
+
* signed-in person who hasn't switched `pub` off, and on someone else's site the first join asks once ("Join the room on …?") —
|
|
278
|
+
* the same yes that covers posting. Anyone who joins a room with the same name sees the same table, so put something only your
|
|
279
|
+
* people know into the name (an invite code, a link). DEV builds get a sandbox room in this browser — tabs on the same site share it. */
|
|
280
|
+
interface Live {
|
|
281
|
+
/** `what` names what people are joining in the permission line — `Join the {what} on <your app>?` — one word, default `room`
|
|
282
|
+
* (a Collab calls it a project). Older launchers ignore it. */
|
|
283
|
+
join(room: string, opts?: { what?: string }): Promise<LiveRoom>;
|
|
284
|
+
}
|
|
285
|
+
|
|
167
286
|
/** One of this person's files for your app, as `files.put()` and `files.list()` return it. */
|
|
168
287
|
interface FileInfo {
|
|
169
288
|
id: string;
|
|
@@ -247,6 +366,48 @@ interface PageAccess {
|
|
|
247
366
|
/** `page` undeclared or switched off in Fave1 settings — none of it is there. */
|
|
248
367
|
type NoPageAccess = { [K in keyof PageAccess]?: undefined };
|
|
249
368
|
|
|
369
|
+
/** A value your app shares by link, as `shared.create()` · `get()` return it. */
|
|
370
|
+
interface Shared<T = unknown> {
|
|
371
|
+
/** The link's two halves. `ref` is `"<id>.<key>"` — the string you put in a URL and pass back to `get()` · `set()`. */
|
|
372
|
+
id: string; key: string; ref: string;
|
|
373
|
+
value: T;
|
|
374
|
+
/** Changes with every write. Pass it as `base` to `set()` so an edit made in between isn't lost. */
|
|
375
|
+
v: number;
|
|
376
|
+
/** Can people with the link write, not just read? The owner sets it with `create()` and `access()`. */
|
|
377
|
+
edit: boolean;
|
|
378
|
+
updatedAt: string;
|
|
379
|
+
/** This person made it. */
|
|
380
|
+
mine: boolean;
|
|
381
|
+
/** Who made it, and who wrote last (if someone other than the owner did) — first letter and avatar color, never a name. */
|
|
382
|
+
owner: { initial: string; color: string } | null;
|
|
383
|
+
editor: { initial: string; color: string } | null;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** `shared` — one value shared by one link: a note, a list, a board. Declared with `storage` (no new permission).
|
|
387
|
+
* The owner creates it; anyone with the link reads it — signed out, or without your app added; and if the owner turned
|
|
388
|
+
* `edit` on, any signed-in person with the link can write. The owner can change that or take the link back at any time.
|
|
389
|
+
* Values up to 64 KB, 100 per person per app; they count toward the owner's Fave1 storage. The link is the secret —
|
|
390
|
+
* put `ref` in a URL your app opens with (`<id>.fave1.app/#s=<ref>`) and never post it anywhere public yourself.
|
|
391
|
+
* Owner calls (`create` · `access` · `list` · `delete`) follow the storage rules: a signed-in person, one OK on a new
|
|
392
|
+
* site, never at home. DEV builds keep it in this browser — a link made there opens nowhere else. */
|
|
393
|
+
interface SharedApi {
|
|
394
|
+
/** Share a value. `edit` lets people with the link write (default read-only). Rejects with `quota` — `err.scope` `'shared'`
|
|
395
|
+
* at 100 shared values, `'account'` when their Fave1 storage is full. */
|
|
396
|
+
create<T = unknown>(value: T, opts?: { edit?: boolean }): Promise<Shared<T>>;
|
|
397
|
+
/** Read by link. `null` when it's gone or the link is wrong — never throws for that. Works signed out. */
|
|
398
|
+
get<T = unknown>(ref: string): Promise<Shared<T> | null>;
|
|
399
|
+
/** Write by link — as the owner, or as a signed-in person when `edit` is on (`denied` otherwise, `signed-out` with no account).
|
|
400
|
+
* Pass `base` (the `v` you read) and, if someone wrote in between, it rejects with `conflict` carrying `err.current`
|
|
401
|
+
* (the row now): merge, then call `set()` again with its `v`. Without `base` it overwrites. */
|
|
402
|
+
set<T = unknown>(ref: string, value: T, opts?: { base?: number }): Promise<{ v: number }>;
|
|
403
|
+
/** Owner only: let people with the link write, or stop that. Takes the `id` or the `ref`. */
|
|
404
|
+
access(idOrRef: string, opts: { edit: boolean }): Promise<void>;
|
|
405
|
+
/** Everything this person shares from your app — with the keys, so you can show the links again. */
|
|
406
|
+
list(): Promise<Shared[]>;
|
|
407
|
+
/** Owner only: take the link back. Whoever has it gets `null` from then on. Resolves even if it was already gone. */
|
|
408
|
+
delete(idOrRef: string): Promise<void>;
|
|
409
|
+
}
|
|
410
|
+
|
|
250
411
|
interface Ctx {
|
|
251
412
|
ui: Ui;
|
|
252
413
|
/** Where you're running: `'page'` — on someone's site, opened from the bookmarklet;
|
|
@@ -288,7 +449,11 @@ interface Ctx {
|
|
|
288
449
|
};
|
|
289
450
|
/** Files on the account — declared with `storage`, like the JSON above. */
|
|
290
451
|
files: Files;
|
|
452
|
+
/** Values shared by link — declared with `storage` too. */
|
|
453
|
+
shared: SharedApi;
|
|
291
454
|
pub: Pub;
|
|
455
|
+
/** Live rooms — the same table, edited by several people at once (uses `pub`). */
|
|
456
|
+
live: Live;
|
|
292
457
|
/** Is this permission live right now? `pub` also needs a signed-in person who hasn't switched it off. */
|
|
293
458
|
can(permission: Permission): boolean;
|
|
294
459
|
/** Opens this app's permission screen in Fave1 settings. Only the person can turn things on. */
|