docs / ctx.shared
api reference

ctx.shared

One value, one link. The owner makes it; anyone with the link reads it — signed out, or without your app; and if the owner says so, signed-in people write to it. For a note, a list or a board that one person starts and others join.

storagebetween storage and pub

Calls

ctx.shared
const row = await ctx.shared.create(value, { edit: false });   // → { id, key, ref, value, v, edit, mine, owner, editor, updatedAt }
const link = `https://my-app.fave1.app/#s=${row.ref}`;                 // ref is "id.key" — the link is the secret

const got = await ctx.shared.get(ref);                             // the row, or null when it's gone — works signed out
const { v } = await ctx.shared.set(ref, value, { base: got.v });   // write; base guards against lost edits
await ctx.shared.access(row.id, { edit: true });                   // owner only — let people with the link write
await ctx.shared.list();                                           // this person's links from your app — { id, key, ref, v, edit, bytes, edited, updatedAt, mine, owner } — no value: get(ref) one to read it
await ctx.shared.delete(row.id);                                   // owner only — the link stops working for everyone

Declared with storage — no new permission. A value is JSON up to 64 KB, one person shares up to 100 per app, and they count toward the owner’s Fave1 storage. The owner’s calls (create · access · list · delete) follow ctx.storage’s rules: a signed-in person who added your app, one OK on a new site, never in app mode. get() is the odd one out — it works for anyone who has the link.

Where it sits

PlaceWho reads · who writesNeeds
ctx.storageThis person only. Notes, settings, the list itself. ctx.storagestorage
ctx.sharedWhoever has the link reads; the owner writes, and signed-in people with the link if the owner lets them. No list of who.storage
ctx.pubEveryone using your app reads one value per person; each person writes their own. ctx.pubpub
ctx.liveEveryone in a room reads and writes one table, pushed the moment it changes. ctx.livepub

Pick by who should see it. A note for one friend is shared. A board for everyone is pub. Two people typing on the same thing right now is live — shared is not pushed; readers ask for it (Keeping it fresh).

What a row looks like

a shared row
{
  id: 'k3f9q2m8x1pz',          // 12 characters — names the value; the owner uses it for access() and delete()
  key: 'qw8rt2yu6io0pa4sd7fg9h', // 22 lowercase letters and digits — unlocks it
  ref: 'k3f9q2m8x1pz.qw8rt2yu6io0pa4sd7fg9h',   // id.key — what goes in the link, and back into get() · set()
  value: { title: 'Packing list', items: [/* … */] },
  v: 7,                        // changes with every write — pass it as base to set()
  edit: true,                  // can people with the link write?
  updatedAt: '2026-10-26T09:41:12.000Z',
  mine: false,                 // did this person make it?
  owner: { initial: 'M', color: 'linear-gradient(…)', avatar: 'data:image/svg+xml,…', avatarStill: 'data:image/svg+xml,…' },   // who made it — a letter, a color and their avatar, never a name
  editor: { initial: 'J', color: 'linear-gradient(…)', avatar: 'data:image/svg+xml,…', avatarStill: 'data:image/svg+xml,…' },  // who wrote last, if someone other than the owner did — else null
}

mine is how app mode knows whether to draw the owner’s controls (Stop sharing, Let people edit) or the reader’s (Keep a copy). owner and editor are a first letter, an avatar color and the avatar they picked each — enough for “Shared by M · edited by J”, and never a name. v is a counter, not a time: compare it to the v you last saw to know whether anything changed.

ref is id.key: twelve characters that name the value and twenty-two that unlock it. Put it in a URL your app opens with — #s=<ref> in app mode is the pattern Fave1’s own apps use, and a hash never reaches any server — and read it back with get(). Anyone who has the link has the value; there is no list of who. Don’t post a ref anywhere public from your code, and let the owner take it back with delete().

get() works for everyone — signed out, or someone who never added your app — because the key is the door. It resolves null when the key is wrong or the owner took it back — the two look the same on purpose — and rejects with invalid only when what you pass isn’t shaped like id.key at all. It still needs storage in your manifest, and a signed-in reader who switched storage off for your app gets denied like any other storage call. Reads are counted per network address — a page that polls a link in a tight loop gets rate.

Links don’t expire on their own. They stop when the owner deletes them, removes your app, clears your app in Fave1 Settings › Storage, or deletes their account.

A note, start to finish

The shape that holds up: the owner keeps the note in ctx.storage as before, and sharing adds a link next to it. Every save goes to both. Readers open the link in app mode.

src/index.ts
type Note = { title: string; body: string };

// 1. Share — once, when the owner presses Share. Keep the link next to the note.
const note = (await ctx.storage.get('note:abc')) as Note | undefined;
if (!note) return;
const row = await ctx.shared.create<Note>(note, { edit: false });
await ctx.storage.set('note:abc:link', { id: row.id, ref: row.ref });
const link = `https://my-app.fave1.app/#s=${row.ref}`;   // show it, copy it, hand it to navigator.share

// 2. Save — every time the owner edits. Their copy first, then the link.
async function saveNote(next: Note) {
  await ctx.storage.set('note:abc', next);
  await ctx.shared.set(row.ref, next);        // no base: the owner overwrites — nobody else can edit this one
}

// 3. Stop sharing — the link goes dead for everyone; the note stays in ctx.storage.
async function stopSharing() {
  await ctx.shared.delete(row.id);
  await ctx.storage.delete('note:abc:link');
}
src/index.ts — in app mode
type Note = { title: string; body: string };

// A link opens straight to the shared note — signed in or not.
if (ctx.surface === 'app' && location.hash.startsWith('#s=')) {
  const ref = location.hash.slice(3);
  const got = await ctx.shared.get<Note>(ref);
  if (!got) { ctx.ui.render([ctx.ui.text('This link isn’t live any more.')]); return; }
  showNote(got.value, { mine: got.mine, canEdit: got.edit && ctx.user.signedIn, by: got.owner });

  // "Keep a copy" — into this reader's own storage, with the ref so you can pull updates later.
  if (!got.mine && ctx.can('storage')) {
    ctx.ui.render([ctx.ui.button('Keep in my notes', {
      onClick: () => ctx.storage.set(`kept:${got.id}`, { ref, note: got.value, v: got.v }),
    })]);
  }
}

Signed-out readers see the note and nothing else — ctx.can('storage') is false, so there’s no Keep and no editing. Say so instead of hiding it: a line like Sign in to keep this turns a reader into an account.

Letting people write

With edit on, any signed-in person with the link can call set(). Off (the default), only the owner can; others get denied. Someone signed out gets signed-out. On a site that hasn’t said yes to your app, the first write from a non-owner asks once, like storage does; in app mode it never asks. The owner flips it any time with access(id, { edit }) — turning it off doesn’t undo what was written.

src/index.ts
type Item = { id: string; text: string; done: boolean };
type List = { items: Item[] };

// Save what this person changed, without losing what someone else saved in between.
async function saveList(ref: string, mine: List, base: number): Promise<number> {
  try {
    return (await ctx.shared.set(ref, mine, { base })).v;
  } catch (err) {
    const e = err as Fave1Error;
    if (e.code !== 'conflict' || !e.current) throw err;
    const theirs = e.current.value as List;
    const byId = new Map<string, Item>(theirs.items.map((it) => [it.id, it]));
    for (const it of mine.items) byId.set(it.id, it);   // mine win per item; theirs stay where I never touched
    const merged: List = { items: [...byId.values()] };
    return (await ctx.shared.set(ref, merged, { base: e.current.v })).v;
  }
}

Always pass base — the v you read. If someone wrote in between, set() rejects with conflict and err.current is the row as it is now; merge and write again with its v. The merge is yours to write because only your app knows its shape — a list merges by item, a note by paragraph, a counter by taking the larger. Without base it overwrites, which is right only for the owner pushing a value nobody else can edit.

Two people typing in the same paragraph at the same moment still collide — this is a value, not a shared cursor. If that is the product, open a ctx.live room on top and use the link only to find it.

Keeping it fresh

Nothing is pushed. A reader sees what get() returned, until you call it again. Ask when it matters — when the tab comes back, and every few seconds while they are looking — and redraw only if v moved. The owner does the same for a link with edit on, so their own copy picks up what others wrote.

src/index.ts
type Note = { title: string; body: string };
const ref = location.hash.slice(3);
const got = await ctx.shared.get<Note>(ref);
if (!got) return;
let seen = got.v;

async function refresh() {
  const now = await ctx.shared.get<Note>(ref);
  if (!now) { ctx.ui.toast('The owner stopped sharing this.', 'error'); return; }
  if (now.v === seen) return;
  seen = now.v;
  showNote(now.value, { by: now.editor ?? now.owner });
}
const onShow = () => { if (!document.hidden) refresh(); };
document.addEventListener('visibilitychange', onShow);
const timer = setInterval(refresh, 12000);
// In onDestroy: clearInterval(timer); document.removeEventListener('visibilitychange', onShow);

Twelve seconds is plenty for a note or a list; reads are cheap but counted. Stop the timer and remove the listener in onDestroy — on a site, document is the page’s and outlives your app — and don’t poll from the page surface while the panel is minimized — nobody is looking.

Limits and errors

64 KB

Per value

Measured as JSON text — the same cap as a storage value. Over it, too-large before anything leaves the page.

100

Per person, per app

Links one person has open at once. The 101st create() fails with quota, scope 'shared' — let them delete one.

their storage

Counted

Shared values live on the owner’s Fave1 storage, next to app data and files — a full account can still read and delete.

counted

Reads

get() is open to the world, so it is rate-limited per network address. Poll gently.

CodeWhat happenedTry
conflictset() with a stale base — err.current.value and err.current.v are the row now; merge with those two onlymerge, set again
deniedWriting someone else’s value whose edit is off — or storage isn’t in your manifest, or they switched it offctx.perms.open()
not-foundset() · access() on a link that’s gone or isn’t theirs. get() gives null instead, and delete() resolves anywaysay so
signed-outNobody’s signed in — everything but get() needs an accountfold the feature
not-installedThey haven’t added your app — a sideloaded run; get() still workssay so
cancelledThey chose Not now on the first-use prompt of a siteleave it
too-largeA value over 64 KBtrim it
quotaerr.scope 'shared' — 100 links already; 'account' — their Fave1 storage is fulldelete() · ctx.files.manage()
invalidNot a ref (id.key), or a value that isn’t JSONfix it
rateToo many reads from one network address in a minuteback off
unreachableThis page blocks Fave1 from reaching the accountsay so
timeoutNo answer in 15 secondsretry
serverFave1 had a problem on its sideretry later

When the owner removes your app or deletes their account, their shared values go too. They can also clear everything your app keeps — shared values included — in Fave1 Settings › Storage; a reader then gets null, the same as a deleted link.

While you build

DEV builds keep shared values in this browser, like the rest of the sandbox — create(), get() and set() all work, and conflict shows up as it would for real. A link you make there opens in this browser only. Switch Data to My account to make a real link, then open it in another browser (or signed out) to see the reader’s side.