@vibes.diy/prompts 14.3.274 → 14.3.276
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/llms/maps.md +81 -1
- package/llms/stripe.js +1 -1
- package/llms/stripe.js.map +1 -1
- package/llms/stripe.md +122 -59
- package/llms/ui-storefront.md +2 -2
- package/llms/use-vibe.md +54 -1
- package/package.json +6 -6
- package/system-prompt-initial-oneshot.md +1 -1
- package/system-prompt-initial.md +1 -1
- package/system-prompt.md +1 -1
package/llms/maps.md
CHANGED
|
@@ -93,6 +93,31 @@ The area comes from, in order: the area the person picked last time (kept in
|
|
|
93
93
|
answers. Write all three steps in the app. A fixed starting city ("downtown San
|
|
94
94
|
Francisco") is the last rung of that ladder, never the opening view, so the
|
|
95
95
|
map opens wherever the person is.
|
|
96
|
+
|
|
97
|
+
**A guess is city-level when it names a `city`.** Some connections answer with
|
|
98
|
+
only a country, and its coordinates are the middle of that country (37.751,
|
|
99
|
+
-97.822 for the United States, a field in Kansas), so a guess counts only with
|
|
100
|
+
its `city` and otherwise the ladder moves on to the well-known city:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
const FALLBACK = { label: "Portland, Oregon", lat: 45.523, lng: -122.676, how: "a starting city" };
|
|
104
|
+
|
|
105
|
+
export async function pickArea() {
|
|
106
|
+
try {
|
|
107
|
+
const kept = JSON.parse(localStorage.getItem("area") || "null");
|
|
108
|
+
if (kept) return { ...kept, how: "the area you picked" };
|
|
109
|
+
} catch {}
|
|
110
|
+
try {
|
|
111
|
+
const geo = await (await fetch("https://get.geojs.io/v1/ip/geo.json")).json();
|
|
112
|
+
if (geo.city) {
|
|
113
|
+
const label = [geo.city, geo.region].filter(Boolean).join(", ");
|
|
114
|
+
return { label, lat: Number(geo.latitude), lng: Number(geo.longitude), how: "a guess from your connection" };
|
|
115
|
+
}
|
|
116
|
+
} catch {}
|
|
117
|
+
return FALLBACK;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
96
121
|
One line beside the results says what it shows and how the area was chosen: "18
|
|
97
122
|
spots within 5 mi of Portland, Oregon (a guess from your connection)".
|
|
98
123
|
|
|
@@ -282,6 +307,60 @@ const notesFor = (place, notes) => notes.filter((n) => metersApart(n, place.loca
|
|
|
282
307
|
Every signed-in friend writes as themselves; pins the owner adds by hand join
|
|
283
308
|
the feed with their own note.
|
|
284
309
|
|
|
310
|
+
**The feed is the places, numbered like the pins.** Saved spots and nearby
|
|
311
|
+
places are one list, and that one list feeds both the pins and the feed: the
|
|
312
|
+
spots the friends rated first, then every other place the search found, so the
|
|
313
|
+
feed is full whenever the map has places. Hand the same array to `PlaceMap`
|
|
314
|
+
and to the feed, and pin 3 is row 3:
|
|
315
|
+
|
|
316
|
+
```jsx
|
|
317
|
+
// One list: rated spots first, then the rest of the nearby places. Only notes inside the
|
|
318
|
+
// searched circle join, so the map frames this area; notes elsewhere feed the "saved spots
|
|
319
|
+
// around …" line. Notes within 50 m of each other are one spot: one pin, one row.
|
|
320
|
+
export function feedItems({ places, notes, center, radius }) {
|
|
321
|
+
const here = notes.filter((n) => metersApart(n, center) <= radius);
|
|
322
|
+
const listed = places.map((place) => {
|
|
323
|
+
const at = place.location.toJSON();
|
|
324
|
+
return { id: place.id, displayName: place.displayName, location: at, place, notes: here.filter((n) => metersApart(n, at) <= 50) };
|
|
325
|
+
});
|
|
326
|
+
const ownPins = [];
|
|
327
|
+
for (const n of here) {
|
|
328
|
+
if (listed.some((item) => metersApart(n, item.location) <= 50)) continue;
|
|
329
|
+
const spot = ownPins.find((item) => metersApart(n, item.location) <= 50);
|
|
330
|
+
if (spot) spot.notes.push(n);
|
|
331
|
+
else ownPins.push({ id: n._id, displayName: n.name, location: { lat: n.lat, lng: n.lng }, place: null, notes: [n] });
|
|
332
|
+
}
|
|
333
|
+
return [...ownPins, ...listed.filter((item) => item.notes.length > 0), ...listed.filter((item) => item.notes.length === 0)];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function Feed({ items, selectedId, onPick }) {
|
|
337
|
+
return <Stack gap={2}>{items.map((item, i) => (
|
|
338
|
+
<RowCard key={item.id} selected={item.id === selectedId} onClick={() => onPick(item.id)}>
|
|
339
|
+
<Row gap={3}>
|
|
340
|
+
<Badge tone="info">{i + 1}</Badge>
|
|
341
|
+
<Stack gap={1}>
|
|
342
|
+
<Text>{item.displayName}</Text>
|
|
343
|
+
<Text size="sm" muted>{item.notes.length > 0 ? `${item.notes.length} ${item.notes.length === 1 ? "note" : "notes"} from friends` : item.place?.formattedAddress}</Text>
|
|
344
|
+
</Stack>
|
|
345
|
+
</Row>
|
|
346
|
+
</RowCard>
|
|
347
|
+
))}</Stack>;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// const items = feedItems({ places, notes, center, radius }); // the same center and radius as findPlaces
|
|
351
|
+
// <PlaceMap places={items} center={center} selectedId={selectedId} onPick={setSelectedId} />
|
|
352
|
+
// <Feed items={items} selectedId={selectedId} onPick={setSelectedId} />
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Example spots sit where the map opens with no guess.** `seed.json` places
|
|
356
|
+
its example ratings and notes around the app's well-known city, at the same
|
|
357
|
+
coordinates as `FALLBACK`, each on a real, well-known place there with its name
|
|
358
|
+
and address.
|
|
359
|
+
When the person's area holds none of their saved spots and they have some
|
|
360
|
+
elsewhere, the line under the feed names where they are and moves the map
|
|
361
|
+
there on a tap: "7 saved spots around Portland, Oregon". Every visitor sees the
|
|
362
|
+
nearby places in the feed, and the friends' spots are one tap away.
|
|
363
|
+
|
|
285
364
|
**Directions open the phone's maps app**:
|
|
286
365
|
`https://www.google.com/maps/dir/?api=1&destination=<lat>,<lng>&travelmode=driving`,
|
|
287
366
|
or `https://maps.apple.com/?daddr=<lat>,<lng>&dirflg=d` on Apple devices. A place
|
|
@@ -289,6 +368,7 @@ shares as the app's public address with `#place=<id>&at=<lat>,<lng>` in the
|
|
|
289
368
|
fragment. A friend opening it lands on that area with the place open.
|
|
290
369
|
|
|
291
370
|
Verify the first preview at phone width. The map paints, the numbered pins match
|
|
292
|
-
the feed, and tapping a pin brings its card
|
|
371
|
+
the feed, the feed lists the nearby places, and tapping a pin brings its card
|
|
372
|
+
into view. The location prompt
|
|
293
373
|
appears only after "Use my location". A typed zip moves the map, and the map
|
|
294
374
|
shows its credit line.
|
package/llms/stripe.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const stripeConfig = {
|
|
2
2
|
name: "stripe",
|
|
3
3
|
label: "Stripe payments",
|
|
4
|
-
description: "Taking real money through Stripe Checkout: load it whenever the person asks for money to move — pay the bill, split the check, a restaurant check, pay at the table or at the counter, a tip or a tip jar, donate or a donation page, sell tickets, sell products buyers pay for, buy now or purchase online, a charge, a deposit, dues, a checkout, a client paying an invoice online (pay an invoice, bill a client), pay with Stripe, the word Stripe, or a named payment app buyers pay through (Apple Pay, Cash App, Zelle, Venmo, Chime: card, Apple Pay and Cash App Pay ride Checkout, and a P2P app the person keeps is a manual lane beside it whose handle the owner types) — one-time charges into the owner's own Stripe account through ctx.stripe, connected once with Connect Stripe (a monthly or yearly subscription is the stripe-subscriptions skill): what is for sale and its price is the owner's product catalog, product records in the app's database that only the owner writes (access.js) from the app's own Products screen, starting empty with the owner's first product, and backend.js charges the price it reads from the product the buyer names, never an amount from the browser or a constant in backend.js;
|
|
4
|
+
description: "Taking real money through Stripe Checkout: load it whenever the person asks for money to move — pay the bill, split the check, a restaurant check, pay at the table or at the counter, a tip or a tip jar, donate or a donation page, sell tickets, sell products buyers pay for, buy now or purchase online, a charge, a deposit, dues, a checkout, a client paying an invoice online (pay an invoice, bill a client), pay with Stripe, the word Stripe, or a named payment app buyers pay through (Apple Pay, Cash App, Zelle, Venmo, Chime: card, Apple Pay and Cash App Pay ride Checkout, and a P2P app the person keeps is a manual lane beside it whose handle the owner types) — one-time charges into the owner's own Stripe account through ctx.stripe, connected once with Connect Stripe (a monthly or yearly subscription is the stripe-subscriptions skill): what is for sale and its price is the owner's product catalog, product records in the app's database that only the owner writes (access.js) from the app's own Products screen, starting empty with the owner's first product, and backend.js charges the price it reads from the product the buyer names, never an amount from the browser or a constant in backend.js; anyone pays by default, signed in or not (a guest's order is written by backend.js for them, and sign-in only when the owner asks for it: members only, a roster, a my-orders page), a venue's guest checkout (a check, a tip, a donation, an invoice paid by link with a pay-by date and an overdue state — the payment keyed to the thing paid and its session), one payer paying the whole check by default with splitting as a second choice and the balance reserved with a revision-checked write before any session opens, the Connect Stripe setup item read from ctx.stripe.status(), test mode first with the order's mode passed on every call and live once the owner takes this app live, every Stripe call in backend.js with no Stripe.js in the page, one pending order then one Checkout Session opened in a new tab, an order marked paid only after the backend reads the session back from Stripe and matches it to the order, integer amounts in cents, and a scheduled sweep that settles orders whose buyer never came back. A storefront, plans page, booking page or invoice maker that only records orders or marks invoices paid by hand takes no payment and does not need this; offer it as the [pay] option instead",
|
|
5
5
|
cues: [
|
|
6
6
|
"stripe",
|
|
7
7
|
"take payments",
|
package/llms/stripe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../jsr/llms/stripe.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,YAAY,GAAc;IACrC,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,iBAAiB;IACxB,WAAW,EACT,
|
|
1
|
+
{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../jsr/llms/stripe.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,YAAY,GAAc;IACrC,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,iBAAiB;IACxB,WAAW,EACT,u2EAAu2E;IACz2E,IAAI,EAAE;QACJ,QAAQ;QACR,eAAe;QACf,cAAc;QACd,iBAAiB;QACjB,eAAe;QACf,cAAc;QACd,aAAa;QACb,UAAU;QACV,SAAS;QACT,MAAM;QACN,cAAc;QACd,SAAS;QACT,YAAY;QACZ,iBAAiB;QACjB,iBAAiB;QACjB,QAAQ;QACR,SAAS;QACT,cAAc;QACd,iBAAiB;QACjB,kBAAkB;QAClB,kBAAkB;QAClB,oBAAoB;QACpB,SAAS;QACT,QAAQ;QACR,UAAU;QACV,WAAW;QACX,iBAAiB;QAIjB,WAAW;QACX,UAAU;QACV,OAAO;QACP,OAAO;QAGP,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;QACd,mBAAmB;QACnB,gBAAgB;QAChB,iBAAiB;QACjB,kBAAkB;QAClB,eAAe;QACf,cAAc;QACd,iBAAiB;KAClB;IAKD,SAAS,EAAE;QACT,aAAa;QACb,gBAAgB;QAChB,YAAY;QACZ,cAAc;QACd,iBAAiB;QACjB,gBAAgB;QAChB,aAAa;QACb,cAAc;QACd,eAAe;QACf,cAAc;QACd,eAAe;QACf,eAAe;QACf,iBAAiB;KAClB;IAGD,aAAa,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,CAAC;CACjG,CAAC"}
|
package/llms/stripe.md
CHANGED
|
@@ -78,26 +78,35 @@ Products is a page of its own too, beside them: the owner opens **Setup** to fin
|
|
|
78
78
|
to see every order and subscriber, and **Products** to change the list, each
|
|
79
79
|
from one press in the header. A buyer sees none of those buttons.
|
|
80
80
|
|
|
81
|
-
**Who pays:
|
|
81
|
+
**Who pays: anyone, signed in or not, unless the owner asks for sign-in.**
|
|
82
|
+
|
|
83
|
+
Anyone can pay: checkout takes a guest by default, so a visitor with no Vibes DIY account fills the bag and presses Pay, and sign-in is asked for only when the owner's own request asks for it.
|
|
84
|
+
|
|
85
|
+
Stripe's own page asks every buyer for their email and sends the receipt, and
|
|
86
|
+
security rests on Stripe, not on a sign-in: the backend reads every session
|
|
87
|
+
back from Stripe before anything counts as paid. So a shop, a bag, tickets, a
|
|
88
|
+
class, a print, a preorder — every one-time sale — opens to whoever arrives.
|
|
89
|
+
The order records the buyer's handle when they happen to be signed in, and a
|
|
90
|
+
guest's order is just as real: the owner sees it on **Orders** with Stripe's
|
|
91
|
+
receipt behind it, and the guest's return page thanks them for it.
|
|
92
|
+
*Complete backend.js* below is that recipe, and *A shop with a bag* builds on
|
|
93
|
+
it.
|
|
82
94
|
|
|
83
95
|
A payment to a venue is guest checkout: the payer needs no Vibes DIY account, the payment record is keyed to the thing being paid and its Checkout Session, and backend.js writes it on the guest's behalf.
|
|
84
96
|
|
|
85
97
|
A restaurant check, a split-the-check page, a tip jar, a donation page, a
|
|
86
|
-
pay-at-the-counter page,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
reads every session back from Stripe before anything counts as paid.
|
|
91
|
-
*Guest checkout at a venue* at the end of this page is that recipe, with a
|
|
92
|
-
table's check as the worked example, and *Invoices* after it is the same
|
|
98
|
+
pay-at-the-counter page, a client paying an invoice — the payer is a guest at
|
|
99
|
+
the owner's place, and the record belongs to the thing being paid rather than
|
|
100
|
+
to a buyer. *Guest checkout at a venue* at the end of this page is that recipe,
|
|
101
|
+
with a table's check as the worked example, and *Invoices* after it is the same
|
|
93
102
|
recipe for a client paying a bill.
|
|
94
103
|
|
|
95
|
-
Sign-in is the
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
hold for
|
|
104
|
+
Sign-in is the owner's choice to make. When the request asks for it — members
|
|
105
|
+
only, a dues roster that lists who paid, a "my orders" or "my tickets" page
|
|
106
|
+
people come back to on any device — `/checkout` adds its one sign-in line (shown
|
|
107
|
+
in the recipe) and the page offers sign-in beside Pay. Every subscription signs
|
|
108
|
+
in too, because the subscriber manages it later (the `stripe-subscriptions`
|
|
109
|
+
skill). Sections 1 to 6 hold for every shape.
|
|
101
110
|
|
|
102
111
|
## 1. The setup item: Connect Stripe
|
|
103
112
|
|
|
@@ -221,11 +230,13 @@ start two purchases.
|
|
|
221
230
|
|
|
222
231
|
## 3. One order, then one Checkout Session
|
|
223
232
|
|
|
224
|
-
The order exists before the money moves.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
only then asks Stripe for a session for exactly that order. A guest's
|
|
233
|
+
The order exists before the money moves. The `/checkout` route runs as
|
|
234
|
+
whoever pressed Pay (the page calls it with `apiFetch`, so `ctx.userInfo` is
|
|
235
|
+
set when they are signed in), writes an `order` document in `pending` with the
|
|
236
|
+
buyer's handle when there is one, the title, the amount and the mode it is made
|
|
237
|
+
in, and only then asks Stripe for a session for exactly that order. A guest's
|
|
238
|
+
order carries `buyerHandle: null` and a `guestKey`, the random id their page
|
|
239
|
+
keeps for them, so their second press finds the same attempt. A guest's payment
|
|
229
240
|
goes the same way once it has reserved its share of the check (*Guest
|
|
230
241
|
checkout at a venue*).
|
|
231
242
|
|
|
@@ -260,9 +271,10 @@ Every order records the mode it was made in, and every ctx.stripe.fetch call for
|
|
|
260
271
|
|
|
261
272
|
The routes read the `orders` database, which `access.js` binds, so `backend.js`
|
|
262
273
|
declares `config.fetch.unfilteredReads` for it — the obligation that comes
|
|
263
|
-
with it is yours:
|
|
274
|
+
with it is yours: every route checks a signed-in buyer's
|
|
264
275
|
`order.buyerHandle` against the caller before it returns or settles anything,
|
|
265
|
-
|
|
276
|
+
a guest's order answers only its own status to the order id the return page
|
|
277
|
+
names, a venue page's routes answer only about the check and the payment the
|
|
266
278
|
request names, and no route lists orders for anyone.
|
|
267
279
|
The owner's view of every order is the page's own live query, which the
|
|
268
280
|
access function's `orders` channel already scopes to the owner role.
|
|
@@ -351,9 +363,9 @@ reading Stripe. A buyer never edits an order; they make a new one.
|
|
|
351
363
|
- A signed-in buyer sees their own orders and each one's state — *pending*
|
|
352
364
|
with a "Finish paying" link that reuses the session URL while it is open,
|
|
353
365
|
*paid* with the date, *expired* with a fresh "Pay" button that makes a new
|
|
354
|
-
order. A guest sees the
|
|
355
|
-
|
|
356
|
-
|
|
366
|
+
order. A guest sees a thank-you the moment they come back from Stripe and
|
|
367
|
+
gets Stripe's receipt by email; at a venue they also see the thing they paid
|
|
368
|
+
toward: the table's check moving to *Paid in full*, the tip jar's total rising.
|
|
357
369
|
- The owner hears about every sale the moment it settles.
|
|
358
370
|
|
|
359
371
|
When an order settles as paid, backend.js tells the owner with ctx.notify — toHandle ctx.appInfo.ownerHandle, a body that says what sold and for how much, and a dedupeKey built from the order's id — so each sale reaches the owner once, however many times it settles.
|
|
@@ -388,8 +400,11 @@ and hand the reason to the page, which reads it as *Checkout is not open yet*.
|
|
|
388
400
|
|
|
389
401
|
## Complete backend.js
|
|
390
402
|
|
|
391
|
-
The
|
|
392
|
-
|
|
403
|
+
The default recipe: anyone pays, signed in or not. The worked example is a
|
|
404
|
+
club's dues, open to whoever pays them: a signed-in member's order carries
|
|
405
|
+
their handle, a guest's order lands on the owner's **Orders** all the same, and
|
|
406
|
+
Stripe emails every payer their receipt. An owner who asks for members only
|
|
407
|
+
gets the one sign-in line the `/checkout` route shows in a comment.
|
|
393
408
|
|
|
394
409
|
### `backend.js`
|
|
395
410
|
```js app=stripe-dues
|
|
@@ -399,7 +414,7 @@ export const config = {
|
|
|
399
414
|
scheduled: { interval: "5m" },
|
|
400
415
|
// The routes read a buyer's own order back; access.js binds the database, so the fetch lane
|
|
401
416
|
// needs this declaration, and the routes owe the buyerHandle check it waives.
|
|
402
|
-
fetch: { unfilteredReads: { dbs: ["orders"], why: "the /checkout route reads the product the buyer names from the owner's catalog
|
|
417
|
+
fetch: { unfilteredReads: { dbs: ["orders"], why: "the /checkout route reads the product the buyer names from the owner's catalog; /checkout and /confirm read the buyer's own order, a signed-in buyer's checked by buyerHandle and a guest's answering only its status to the order id their return page names" } },
|
|
403
418
|
};
|
|
404
419
|
|
|
405
420
|
const DB = "orders";
|
|
@@ -534,7 +549,8 @@ async function settle(ctx, order) {
|
|
|
534
549
|
throw err;
|
|
535
550
|
}
|
|
536
551
|
if (next.status === "paid") {
|
|
537
|
-
|
|
552
|
+
const buyer = next.buyerHandle ? `@${next.buyerHandle}` : "a guest";
|
|
553
|
+
await tellOwner(ctx, { id: next._id, mode: next.mode, amount: next.amountPaid, currency: next.currency, what: `${next.title} to ${buyer}` });
|
|
538
554
|
}
|
|
539
555
|
return next;
|
|
540
556
|
}
|
|
@@ -569,12 +585,14 @@ export async function fetch(request, ctx) {
|
|
|
569
585
|
return json({ ok: true, mode: "live" });
|
|
570
586
|
}
|
|
571
587
|
|
|
572
|
-
// Start a purchase: the order first, then a Checkout Session for exactly that order.
|
|
588
|
+
// Start a purchase: the order first, then a Checkout Session for exactly that order. Anyone pays:
|
|
589
|
+
// a signed-in buyer's order carries their handle, a guest's carries the key their page keeps.
|
|
590
|
+
// (An owner who asked for members only adds: if (!me) return json({ ok: false, reason: "sign-in" }, 401);)
|
|
573
591
|
if (url.pathname === "/checkout" && request.method === "POST") {
|
|
574
|
-
const me = ctx.userInfo?.userHandle;
|
|
575
|
-
if (!me) return json({ ok: false, reason: "sign-in" }, 401);
|
|
592
|
+
const me = ctx.userInfo?.userHandle ?? null;
|
|
576
593
|
const { mode, open, state } = await checkoutMode(ctx);
|
|
577
|
-
const { lines: bag, mode: shown } = await request.json();
|
|
594
|
+
const { lines: bag, mode: shown, guestKey } = await request.json();
|
|
595
|
+
if (!me && !(typeof guestKey === "string" && /^guest-[\w-]{8,64}$/.test(guestKey))) return json({ ok: false, reason: "bad-request" }, 400);
|
|
578
596
|
// The buyer pays in the mode their page showed them, or not at all: a page that still shows
|
|
579
597
|
// the other mode refreshes first.
|
|
580
598
|
if (shown !== mode) return json({ ok: false, reason: "mode-changed", mode }, 409);
|
|
@@ -588,7 +606,8 @@ export async function fetch(request, ctx) {
|
|
|
588
606
|
// a reload, all land on the session already open rather than minting another order. A bag
|
|
589
607
|
// that changed, or a price the owner changed since, is a new attempt.
|
|
590
608
|
const pending = await ctx.db.query({ db: DB, field: "status", key: "pending", limit: 100 });
|
|
591
|
-
const
|
|
609
|
+
const same = (o) => (me ? o.buyerHandle === me : o.guestKey === guestKey);
|
|
610
|
+
const attempt = pending.find((o) => same(o) && o.bagKey === priced.key && o.currency === priced.currency && o.mode === mode && o.sessionUrl && Date.now() - o.createdAt < SESSION_TTL_MS);
|
|
592
611
|
if (attempt) return json({ ok: true, orderId: attempt._id, url: attempt.sessionUrl });
|
|
593
612
|
|
|
594
613
|
const id = "order-" + crypto.randomUUID();
|
|
@@ -601,7 +620,8 @@ export async function fetch(request, ctx) {
|
|
|
601
620
|
title: priced.lines.length === 1 ? priced.lines[0].title : `${priced.lines[0].title} and ${priced.lines.length - 1} more`,
|
|
602
621
|
amount: priced.amount,
|
|
603
622
|
currency: priced.currency,
|
|
604
|
-
buyerHandle: me,
|
|
623
|
+
buyerHandle: me, // null for a guest; Stripe's page collects their email and sends the receipt
|
|
624
|
+
...(me ? {} : { guestKey }),
|
|
605
625
|
mode, // the account this order is made in; every later call for it passes the same mode
|
|
606
626
|
status: "pending",
|
|
607
627
|
createdAt: Date.now(),
|
|
@@ -632,13 +652,13 @@ export async function fetch(request, ctx) {
|
|
|
632
652
|
return json({ ok: true, orderId: id, url: session.body.url });
|
|
633
653
|
}
|
|
634
654
|
|
|
635
|
-
// The buyer is back: read the session, move the order to what Stripe says.
|
|
655
|
+
// The buyer is back: read the session, move the order to what Stripe says. A signed-in buyer's
|
|
656
|
+
// order answers to them alone; a guest's answers its status to the order id their return page holds.
|
|
636
657
|
if (url.pathname === "/confirm" && request.method === "POST") {
|
|
637
|
-
const me = ctx.userInfo?.userHandle;
|
|
638
|
-
if (!me) return json({ ok: false, reason: "sign-in" }, 401);
|
|
658
|
+
const me = ctx.userInfo?.userHandle ?? null;
|
|
639
659
|
const { orderId } = await request.json();
|
|
640
|
-
const order = await ctx.db.get(orderId, { db: DB });
|
|
641
|
-
if (
|
|
660
|
+
const order = typeof orderId === "string" && orderId.startsWith("order-") ? await ctx.db.get(orderId, { db: DB }) : null;
|
|
661
|
+
if (order?.type !== "order" || (order.buyerHandle && order.buyerHandle !== me)) return json({ ok: false, reason: "not-found" }, 404);
|
|
642
662
|
const settled = await settle(ctx, order);
|
|
643
663
|
return json({ ok: true, status: settled.status });
|
|
644
664
|
}
|
|
@@ -667,7 +687,8 @@ export async function scheduled(event, ctx) {
|
|
|
667
687
|
### `access.js`
|
|
668
688
|
```js app=stripe-dues
|
|
669
689
|
export function orders(doc, oldDoc, user, ctx) {
|
|
670
|
-
|
|
690
|
+
// Orders come from backend.js for whoever paid, guests included; everything else needs a sign-in.
|
|
691
|
+
if (!user?.userHandle && doc.type !== "order") throw { forbidden: "sign in" };
|
|
671
692
|
// The catalog: the owner lists each product and sets its price from the app's own screen, and
|
|
672
693
|
// anyone reads it. backend.js charges the price on this record, so the owner alone writes one.
|
|
673
694
|
if (doc.type === "product") {
|
|
@@ -693,12 +714,15 @@ export function orders(doc, oldDoc, user, ctx) {
|
|
|
693
714
|
throw { forbidden: "an order keeps its buyer, its price and its mode" };
|
|
694
715
|
}
|
|
695
716
|
} else {
|
|
696
|
-
|
|
717
|
+
// A signed-in buyer's order names them; a guest's names nobody.
|
|
718
|
+
if (doc.buyerHandle !== (user?.userHandle ?? null)) throw { forbidden: "an order belongs to its buyer" };
|
|
697
719
|
if (doc.status !== "pending") throw { forbidden: "an order starts pending" };
|
|
698
720
|
ctx.requireBackend("fetch"); // the /checkout route writes it, so the amount is the server's
|
|
699
721
|
}
|
|
722
|
+
// allowAnonymous: backend.js writes a guest's order while serving a buyer who has no account.
|
|
723
|
+
if (!doc.buyerHandle) return { channels: ["orders"], grant: { roles: { owner: ["orders"] } }, allowAnonymous: true };
|
|
700
724
|
const mine = `user:${doc.buyerHandle}`;
|
|
701
|
-
return { channels: [mine, "orders"], grant: { users: { [doc.buyerHandle]: [mine] }, roles: { owner: ["orders"] } } };
|
|
725
|
+
return { channels: [mine, "orders"], grant: { users: { [doc.buyerHandle]: [mine] }, roles: { owner: ["orders"] } }, allowAnonymous: true };
|
|
702
726
|
}
|
|
703
727
|
```
|
|
704
728
|
|
|
@@ -882,7 +906,8 @@ export default function App() {
|
|
|
882
906
|
apiFetch("/confirm", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ orderId }) })
|
|
883
907
|
.then((r) => r.json())
|
|
884
908
|
.then((d) => {
|
|
885
|
-
|
|
909
|
+
// A guest reads no orders, so /confirm's answer is the status their line shows.
|
|
910
|
+
setBack({ orderId, thanks, confirming: d.status !== "paid", status: d.status });
|
|
886
911
|
})
|
|
887
912
|
.catch(() => setBack({ orderId, thanks, confirming: true }));
|
|
888
913
|
};
|
|
@@ -892,6 +917,16 @@ export default function App() {
|
|
|
892
917
|
}, []);
|
|
893
918
|
|
|
894
919
|
const [busy, setBusy] = useState(false);
|
|
920
|
+
// Anyone pays. A guest's page keeps one random key, so a second press finds the checkout already open.
|
|
921
|
+
const [guestKey] = useState(() => {
|
|
922
|
+
try {
|
|
923
|
+
const kept = localStorage.getItem("guestKey") ?? "guest-" + crypto.randomUUID();
|
|
924
|
+
localStorage.setItem("guestKey", kept);
|
|
925
|
+
return kept;
|
|
926
|
+
} catch {
|
|
927
|
+
return "guest-" + crypto.randomUUID();
|
|
928
|
+
}
|
|
929
|
+
});
|
|
895
930
|
// `lines` is a bag: [{ productId, qty }]. A lone Pay button sends a bag of one.
|
|
896
931
|
const pay = async (lines) => {
|
|
897
932
|
setError(null);
|
|
@@ -904,7 +939,7 @@ export default function App() {
|
|
|
904
939
|
try {
|
|
905
940
|
// The page names the products and how many, never a price; the mode it shows rides along, so
|
|
906
941
|
// the buyer pays in the mode they saw.
|
|
907
|
-
const res = await apiFetch("/checkout", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ lines, mode: setup.mode }) });
|
|
942
|
+
const res = await apiFetch("/checkout", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ lines, mode: setup.mode, guestKey }) });
|
|
908
943
|
const data = await res.json();
|
|
909
944
|
if (!data.ok) {
|
|
910
945
|
tab.close();
|
|
@@ -925,7 +960,7 @@ export default function App() {
|
|
|
925
960
|
const ready = setup?.ready === true;
|
|
926
961
|
const forSale = products.filter((p) => p.onSale);
|
|
927
962
|
// Only orders made in the app's current mode count: after going live, test orders are rehearsals.
|
|
928
|
-
const mine = orders.filter((o) => o.buyerHandle === me
|
|
963
|
+
const mine = me ? orders.filter((o) => o.buyerHandle === me.userHandle && o.mode === setup?.mode) : [];
|
|
929
964
|
// The owner with nothing listed starts on Products, the form for their first product in front.
|
|
930
965
|
const screen = picked ?? (setup?.owner && products.length === 0 ? "products" : "shop");
|
|
931
966
|
return (
|
|
@@ -953,7 +988,7 @@ export default function App() {
|
|
|
953
988
|
) : (
|
|
954
989
|
<ul>
|
|
955
990
|
{orders.map((o) => (
|
|
956
|
-
<li key={o._id}
|
|
991
|
+
<li key={o._id}>{o.buyerHandle ? `@${o.buyerHandle}` : "Guest"} · {o.title} · {money(o.amount, o.currency)} · {o.status}{o.mode === setup.mode ? "" : ` · ${o.mode} rehearsal`}</li>
|
|
957
992
|
))}
|
|
958
993
|
</ul>
|
|
959
994
|
)}
|
|
@@ -965,7 +1000,7 @@ export default function App() {
|
|
|
965
1000
|
{back && (
|
|
966
1001
|
<Text>
|
|
967
1002
|
{(() => {
|
|
968
|
-
const status = orders.find((o) => o._id === back.orderId)?.status;
|
|
1003
|
+
const status = orders.find((o) => o._id === back.orderId)?.status ?? back.status;
|
|
969
1004
|
if (status === "expired") return "That checkout closed before it was paid. Press Pay to start a fresh one.";
|
|
970
1005
|
if (back.confirming && status !== "paid") return "Your payment is still confirming. It shows here as paid in a moment.";
|
|
971
1006
|
return back.thanks;
|
|
@@ -1029,7 +1064,7 @@ too, unless backend.js prices shipping as a line of its own.
|
|
|
1029
1064
|
|
|
1030
1065
|
A shop's bag is a record in the `orders` database that the buyer writes as they shop, and its Pay is one link, `/_api/pay?bag=<_id>&rev=<rev>`, that prices that exact version of the bag in backend.js and sends the buyer to Stripe Checkout.
|
|
1031
1066
|
|
|
1032
|
-
A record rather than page state, because
|
|
1067
|
+
A record rather than page state, because a signed-in buyer's bag is theirs, not the
|
|
1033
1068
|
tab's: it is there on their phone after they filled it on their laptop, and
|
|
1034
1069
|
anyone helping them shop (their own agent filling the bag in a conversation,
|
|
1035
1070
|
say) writes the same record the page does and hands them the same link. The
|
|
@@ -1057,6 +1092,13 @@ A line's options are the shop's to price: `priceBag` reads them off the line
|
|
|
1057
1092
|
and adds what the owner's product record says they cost, so a modifier is
|
|
1058
1093
|
priced in exactly one place, the same place as the product.
|
|
1059
1094
|
|
|
1095
|
+
A guest's bag lives on the page, kept in `localStorage` so a reload keeps it, and their Pay sends its lines to `/checkout` with the page's `guestKey`, so a visitor who never signs in fills the bag and pays.
|
|
1096
|
+
|
|
1097
|
+
A signed-out write stays on the device until sign-in, so a guest's bag never
|
|
1098
|
+
reaches `/pay`; `/checkout` prices the same lines through the same `priceBag`
|
|
1099
|
+
instead. Same bag, same order, same Stripe page: the only difference is where
|
|
1100
|
+
the bag is kept while they shop.
|
|
1101
|
+
|
|
1060
1102
|
### `access.js`
|
|
1061
1103
|
```js partial
|
|
1062
1104
|
// Added before the `order` rule: the buyer's own bag, and its lines when they are records. A record
|
|
@@ -1076,12 +1118,13 @@ if (doc.type === "bag" || doc.type === "line") {
|
|
|
1076
1118
|
```
|
|
1077
1119
|
|
|
1078
1120
|
The `order` rule takes one change: a Pay link arrives as a plain link, so
|
|
1079
|
-
`/pay` writes the order while nobody is signed in
|
|
1080
|
-
the signed-in writer when there is one
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1121
|
+
`/pay` writes the order while nobody is signed in, naming the bag's buyer. The
|
|
1122
|
+
new order's buyer is the signed-in writer when there is one and otherwise the
|
|
1123
|
+
bag's `buyerHandle`, `ctx.requireBackend("fetch")` still gates its creation,
|
|
1124
|
+
and the rule already returns `allowAnonymous: true` for the guest orders
|
|
1125
|
+
`/checkout` writes. That is all a write from the app's own backend needs: the
|
|
1126
|
+
app's anonymous-write setting gates browsers, not backend.js, so the owner has
|
|
1127
|
+
no step to take.
|
|
1085
1128
|
|
|
1086
1129
|
### `backend.js`
|
|
1087
1130
|
```js partial
|
|
@@ -1146,11 +1189,29 @@ answer, and the page puts the bag on it.
|
|
|
1146
1189
|
// The buyer's open bag: theirs alone (access.js routes it to their own channel), and the newest one
|
|
1147
1190
|
// no paid order names. Every Add is a put of the whole bag with a fresh rev.
|
|
1148
1191
|
const { docs: bags } = useLiveQuery("type", { key: "bag" });
|
|
1149
|
-
const bag = bags.filter((b) => b.buyerHandle === me
|
|
1150
|
-
|
|
1192
|
+
const bag = me && bags.filter((b) => b.buyerHandle === me.userHandle && !orders.some((o) => o.bagId === b._id && o.status === "paid")).sort((a, b) => b.touchedAt - a.touchedAt)[0];
|
|
1193
|
+
// A guest's bag: page state kept in localStorage, emptied when their payment comes back paid.
|
|
1194
|
+
const [guestLines, setGuestLines] = useState(() => {
|
|
1195
|
+
try {
|
|
1196
|
+
return JSON.parse(localStorage.getItem("bag") ?? "[]");
|
|
1197
|
+
} catch {
|
|
1198
|
+
return [];
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
useEffect(() => {
|
|
1202
|
+
try {
|
|
1203
|
+
localStorage.setItem("bag", JSON.stringify(guestLines));
|
|
1204
|
+
} catch {}
|
|
1205
|
+
}, [guestLines]);
|
|
1206
|
+
// The return page's /confirm answered paid: the guest's bag is bought, so it empties here and in storage.
|
|
1207
|
+
useEffect(() => {
|
|
1208
|
+
if (!me && back?.status === "paid") setGuestLines([]);
|
|
1209
|
+
}, [me, back?.status]);
|
|
1210
|
+
const lines = ((me ? bag?.lines : guestLines) ?? []).filter((l) => forSale.some((p) => p._id === l.productId));
|
|
1151
1211
|
const add = (productId) => {
|
|
1152
|
-
const kept = bag?.lines ?? [];
|
|
1212
|
+
const kept = (me ? bag?.lines : guestLines) ?? [];
|
|
1153
1213
|
const next = kept.some((l) => l.productId === productId) ? kept.map((l) => (l.productId === productId ? { ...l, qty: l.qty + 1 } : l)) : [...kept, { productId, qty: 1 }];
|
|
1214
|
+
if (!me) return setGuestLines(next);
|
|
1154
1215
|
database.put({ ...(bag ?? { _id: "bag-" + crypto.randomUUID(), type: "bag", buyerHandle: me.userHandle }), lines: next, rev: crypto.randomUUID(), touchedAt: Date.now() });
|
|
1155
1216
|
};
|
|
1156
1217
|
// The same address anyone helping the buyer would hand them. The subtotal is a preview; /pay prices it.
|
|
@@ -1159,7 +1220,8 @@ const payUrl = bag && setup?.pay && `${setup.pay}?bag=${encodeURIComponent(bag._
|
|
|
1159
1220
|
// Pay waits for the server to hold this version: a put lands on this device first, and a link to a
|
|
1160
1221
|
// rev the server has not accepted yet would come back as "bag changed".
|
|
1161
1222
|
const saving = bag?._synced && bag._synced.status !== "accepted";
|
|
1162
|
-
|
|
1223
|
+
// A guest pays the same lines through /checkout: `pay` from the sketch above, with the page's guestKey.
|
|
1224
|
+
<Button onClick={() => (me ? window.open(payUrl, "_blank") : pay(lines))} disabled={(me && !payUrl) || lines.length === 0 || saving || busy}>
|
|
1163
1225
|
Pay {money(subtotal, CURRENCY)} — Stripe opens in a new tab
|
|
1164
1226
|
</Button>
|
|
1165
1227
|
```
|
|
@@ -1170,7 +1232,8 @@ with `#bag-problem=` when the bag moved, something went off sale or checkout
|
|
|
1170
1232
|
is closed, and the page says so in the shop's words (*Your bag changed: check
|
|
1171
1233
|
it and press Pay again*). The bag stays the buyer's until an order naming it
|
|
1172
1234
|
comes back paid; a buyer who closes Stripe's tab still has their bag, and a
|
|
1173
|
-
paid bag drops out of the live query, so the next Add starts a fresh one.
|
|
1235
|
+
paid bag drops out of the live query, so the next Add starts a fresh one. A
|
|
1236
|
+
guest's bag empties when their return page's `/confirm` answers paid.
|
|
1174
1237
|
|
|
1175
1238
|
A product listed with a period renews, so it sells on the `stripe-subscriptions` recipe: a line like *Monthly coffee bag, $22* or *Bread club, $30 a month* checks out in subscription mode with `price_data[recurring][interval]`, never as a one-time line in a payment-mode bag.
|
|
1176
1239
|
|
package/llms/ui-storefront.md
CHANGED
|
@@ -10,7 +10,7 @@ Two screens, one job each. The **Shop** fills the bag and places the order: a `N
|
|
|
10
10
|
|
|
11
11
|
The **Products** screen is the owner's, behind `can.create` on a product draft: a form for the name, price, short line, category and photo, then one row per product whose price edits in place and whose `On sale` checkbox puts it in front of buyers or takes it away. The catalogue starts empty, and an owner who opens an empty shop lands on this screen with "Add the first thing you sell"; a visitor sees a warm `Empty` until the first product goes on sale. Every price is a whole number in the currency's smallest unit (cents for usd, whole yen for jpy) beside its `currency`, the unit card payments charge in, and the page shows, edits and adds prices through that unit.
|
|
12
12
|
|
|
13
|
-
An order is one document holding a snapshot of each line's title, unit price and quantity, the totals, the currency and the buyer's handle, so a later price change never rewrites an order already placed; the person's own orders list under the bag, each with a `Badge` for its status (`info` received, `warn` ready to collect, `up` collected). Checkout waits on its `can` verdict from `useVibe("orders")`: a `Skeleton` inside an `aria-busy` wrapper while it resolves, a sentence in the app's own words when ordering is closed, and for a visitor who has not signed in a `Sign in to place your order` lead wired to `useViewer().requestLogin()`, with the bag they filled kept in place. Sign-in is required here, unlike a local-first note, because a signed-out write stays on the device until sign-in: an order placed that way would never reach the shop.
|
|
13
|
+
An order is one document holding a snapshot of each line's title, unit price and quantity, the totals, the currency and the buyer's handle, so a later price change never rewrites an order already placed; the person's own orders list under the bag, each with a `Badge` for its status (`info` received, `warn` ready to collect, `up` collected). Checkout waits on its `can` verdict from `useVibe("orders")`: a `Skeleton` inside an `aria-busy` wrapper while it resolves, a sentence in the app's own words when ordering is closed, and for a visitor who has not signed in a `Sign in to place your order` lead wired to `useViewer().requestLogin()`, with the bag they filled kept in place. Sign-in is required here, unlike a local-first note, because a signed-out write stays on the device until sign-in: an order placed that way would never reach the shop. That sign-in lead belongs to the pay-when-you-collect order alone: a shop that takes card payment with the `stripe` skill shows Pay to every visitor, signed in or not, because Stripe's own page takes the buyer's email and sends the receipt, and it asks for sign-in only when the owner asked for it.
|
|
14
14
|
|
|
15
15
|
### `App.jsx`
|
|
16
16
|
```jsx
|
|
@@ -467,7 +467,7 @@ export default function App() {
|
|
|
467
467
|
- Product records belong to the owner: `access.js` takes a `product` only from the owner (`ctx.requireRole("owner")`), with an `amount` that is a positive whole number, a three-letter lowercase `currency` and an `onSale` true or false, and puts it on a channel every visitor reads. Keep the `orders` database and the field names `title`, `amount`, `currency` and `onSale`: they are the `stripe` skill's, so its checkout reads these records and prices this bag unchanged.
|
|
468
468
|
- Keep the order a snapshot of titles, unit prices and quantities: an order is a record of what was agreed, so a later price change must not touch it.
|
|
469
469
|
- Orders hold who bought what, so `access.js` and the app's sharing should keep each order between its buyer and the shop: a buyer creates and reads their own, the shop reads them all and moves each through `ORDER_STATUS` behind `can.edit(order)`.
|
|
470
|
-
- Card payment is the `stripe` skill, and it comes in when the person asks to take money: its checkout replaces `Place order` with one `pay(...)` that sends each product and its quantity, `backend.js` prices every line from these records, and the order becomes the one `/checkout` writes. Until then, keep the pay-when-you-collect line truthful, and offer `▸ [pay] Take card payments with Stripe` as the capability option.
|
|
470
|
+
- Card payment is the `stripe` skill, and it comes in when the person asks to take money: its checkout replaces `Place order` with one `pay(...)` that sends each product and its quantity, `backend.js` prices every line from these records, and the order becomes the one `/checkout` writes. Anyone pays: the `Sign in to place your order` lead goes away with `Place order`, and a guest's bag stays on the page until they pay. Until then, keep the pay-when-you-collect line truthful, and offer `▸ [pay] Take card payments with Stripe` as the capability option.
|
|
471
471
|
- A new write surface gets its own verdict: `can.create(draft)` with the fields the write stamps, `can.edit(doc)` or `can.delete(doc)` on the document it changes, always on `useVibe` of the database it writes.
|
|
472
472
|
|
|
473
473
|
Adapted from 1st-Pouf (MIT) https://1st-pouf.worksonmy.dev/r/storefront.json
|
package/llms/use-vibe.md
CHANGED
|
@@ -39,9 +39,62 @@ Stamp `authorHandle: me.userHandle` inside the write an allowed verdict renders
|
|
|
39
39
|
|
|
40
40
|
**Build the candidate from the doc you'll actually write.** `can.create(draft)` runs the access function against `draft`, so `draft` must carry the fields the function checks — `authorHandle`, `channelId`, etc. A bare `can.create({ type: "post" })` gets denied (e.g. `"not author"`) and hides the form even from users who could post. Stamp the same fields you'll `put`: `can.create({ type: "post", channelId, authorHandle: me?.userHandle })`. And gate the **same database** you write to — `useVibe(dbName)` selects the access function and grants by `dbName`, so a gate on a different db won't reflect server enforcement.
|
|
41
41
|
|
|
42
|
+
## A form behind a button
|
|
43
|
+
|
|
44
|
+
Many write surfaces open from a button: a volunteer sheet's **Take a shift**, an open slot's **Claim**, an **Add** that opens a Dialog or Sheet. The verdict lives at the form's Save, where the draft holds what the person typed, so the button that opens the form stays pressable and the form opens with its fields ready. Save is the control gated on `can.create(draft)`.
|
|
45
|
+
|
|
46
|
+
The opening button is also where a visitor meets the ask. You wrote this app's `access.js`, so you know whether a writer has to be signed in; when they do, a settled signed-out visitor's opening button is the sign-in ask itself, named for the action ("Sign in to claim a slot"), wired to `useViewer().requestLogin()`. Their first press goes somewhere useful, and once they are back the same button opens the form. That branch only places the ask; whether the record may be written stays with `can.create(draft)` at Save. When the rules let a visitor write, the opening button opens the form for them too. If Save meets a resolved denial for a settled signed-out visitor, the same sign-in button sits beside Save and the words they typed stay in the fields.
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
import { useState } from "react";
|
|
50
|
+
import { useVibe, useViewer } from "use-vibes";
|
|
51
|
+
import { Button, ErrorNote, Field, Input, Skeleton, Text } from "@vibes.diy/ui";
|
|
52
|
+
import { Dialog } from "@vibes.diy/ui/interactive";
|
|
53
|
+
|
|
54
|
+
function TakeAShift({ database }) {
|
|
55
|
+
const { can, me, ready } = useVibe("gardenShifts");
|
|
56
|
+
const { viewer, isViewerPending, requestLogin } = useViewer();
|
|
57
|
+
const [open, setOpen] = useState(false);
|
|
58
|
+
const [day, setDay] = useState("");
|
|
59
|
+
const [task, setTask] = useState("");
|
|
60
|
+
const [saveError, setSaveError] = useState("");
|
|
61
|
+
const draft = { type: "shift", day: day.trim(), task: task.trim(), volunteerHandle: me?.userHandle };
|
|
62
|
+
const verdict = can.create(draft);
|
|
63
|
+
if (isViewerPending) return <Skeleton variant="row" />;
|
|
64
|
+
// This app's access.js asks for a signed-in writer, so the visitor's button is the ask.
|
|
65
|
+
if (!viewer) return <Button onClick={() => requestLogin()}>Sign in to take a shift</Button>;
|
|
66
|
+
const save = async (event) => {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
if (!ready || !verdict.ok) return;
|
|
69
|
+
setOpen(false);
|
|
70
|
+
setSaveError("");
|
|
71
|
+
const { ok } = await database.put(draft);
|
|
72
|
+
if (ok) {
|
|
73
|
+
setDay("");
|
|
74
|
+
setTask("");
|
|
75
|
+
} else {
|
|
76
|
+
setSaveError("Your shift didn't save yet. Press Save to try again.");
|
|
77
|
+
setOpen(true);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return (
|
|
81
|
+
<Dialog title="Take a shift" open={open} onOpenChange={setOpen} trigger={<Button>Take a shift</Button>}>
|
|
82
|
+
<form onSubmit={save}>
|
|
83
|
+
<Field label="Day">{(id, describedBy) => <Input id={id} describedBy={describedBy} value={day} onChange={setDay} />}</Field>
|
|
84
|
+
<Field label="What you'll do">{(id, describedBy) => <Input id={id} describedBy={describedBy} value={task} onChange={setTask} />}</Field>
|
|
85
|
+
<Button type="submit" disabled={!ready || !verdict.ok}>Save my shift</Button>
|
|
86
|
+
{/* This app's access.js asks for a day and a task; say so in the app's words, never verdict.reason. */}
|
|
87
|
+
{ready && !verdict.ok && !verdict.pending && <Text size="sm" muted>Add a day and what you'll do to save your shift.</Text>}
|
|
88
|
+
{saveError && <ErrorNote>{saveError}</ErrorNote>}
|
|
89
|
+
</form>
|
|
90
|
+
</Dialog>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
42
95
|
## The rule
|
|
43
96
|
|
|
44
|
-
Gate every write affordance on `can
|
|
97
|
+
Gate every write affordance on `can.*`; for a form behind a button, that affordance is the form's Save. Hold it while `pending`, and write your own copy when denied. Never branch write permission on `viewer`, `access.hasRole()`/`access.hasChannel()`, or document fields — those drift from what `access.js` actually does. Rendering **other** users (authors, rosters) is `useViewer()`'s `<ViewerTag userHandle={...} />`, not `useVibe`. The current viewer's own pill and the "signed in as" label are system chrome in the Vibes Switch (the logo) — don't build them into the app. Asking an anonymous visitor to sign in is a different thing and it IS yours: `useViewer().requestLogin()`, at the moment their work becomes worth keeping (see use-viewer docs). A resolved denial is one such moment — write the sign-in copy in your app's own words and wire it to that callable, never to a sentence about the logo. (The one exception is inline avatar self-edit: a guarded no-prop `{viewer && <ViewerTag />}` lets any signed-in member change their own photo in place — see use-viewer docs.)
|
|
45
98
|
|
|
46
99
|
### `App.jsx`
|
|
47
100
|
```jsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibes.diy/prompts",
|
|
3
|
-
"version": "14.3.
|
|
3
|
+
"version": "14.3.276",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"exports": {
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@adviser/cement": "~0.5.34",
|
|
42
|
-
"@vibes.diy/api-types": "14.3.
|
|
43
|
-
"@vibes.diy/call-ai-v2": "14.3.
|
|
44
|
-
"@vibes.diy/identity": "14.3.
|
|
45
|
-
"@vibes.diy/use-vibes-types": "14.3.
|
|
46
|
-
"arktype": "~2.2.
|
|
42
|
+
"@vibes.diy/api-types": "14.3.276",
|
|
43
|
+
"@vibes.diy/call-ai-v2": "14.3.276",
|
|
44
|
+
"@vibes.diy/identity": "14.3.276",
|
|
45
|
+
"@vibes.diy/use-vibes-types": "14.3.276",
|
|
46
|
+
"arktype": "~2.2.9",
|
|
47
47
|
"json-schema-faker": "~0.6.3"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
@@ -104,7 +104,7 @@ Every feature you described above should work when this one block lands. Don't l
|
|
|
104
104
|
Three things happen in this order on every screen, and the first two happen for a visitor who has not signed in:
|
|
105
105
|
|
|
106
106
|
1. **Reading comes first.** Whatever the rules and the app's sharing setting let a signed-out visitor read renders at once: the board of what is on this week, the finished pieces in a gallery, the menu a shop posts. The write surface is what the rules gate, so a visitor reads those records with the Add control waiting beneath them, and the records keep their place on the screen. What the rules keep to members — a guest list, the names on a chore chart — stays with the members, and a visitor meets the ask to join in its place. An app a person keeps for themselves — a tracker, a log, a list just for them — opens on its own screen for a signed-out visitor too: the habits or entries view, its controls in their `can` state and its inviting empty state, with the sign-in ask beside the control that would save. Its first screen is the app itself, with the ask beside it.
|
|
107
|
-
2. **The write surface is gated on `can`.** `useVibe(dbName).can` decides whether the Add, Edit or Delete control shows and in what state (`pending` holds it quietly; a resolved denial gets one sentence in the app's own words). Nothing else on the screen waits on it.
|
|
107
|
+
2. **The write surface is gated on `can`.** `useVibe(dbName).can` decides whether the Add, Edit or Delete control shows and in what state (`pending` holds it quietly; a resolved denial gets one sentence in the app's own words). Nothing else on the screen waits on it. A form that opens from a button — a Dialog or Sheet `trigger`, a Claim or Add that reveals fields — is gated at its Save: the opening button stays pressable, the form opens with its fields, and Save asks `can.create(draft)` with the draft built from what the person typed (an Edit form's Save asks `can.edit(doc)` of the record it changes). When the app's own access rules ask a writer to sign in, a settled signed-out visitor's opening button is the sign-in ask itself, named for the action ("Sign in to claim a slot"), so their first press goes somewhere.
|
|
108
108
|
3. **The ask is a button, at the moment of value.** The sign-in ask is one `Button` wired to `useViewer().requestLogin()`, shown once identity has settled (`!isViewerPending && !viewer`), worded for what the person gets ("Keep these on all your devices", "Sign in to add your dish"), and placed where they feel the pull: beside the control that would save, or right after they made something worth keeping. Every sentence the app renders that mentions signing in has that button beside it, so the reader acts where they read. The use-viewer skill's _Asking a visitor to sign in_ has the worked example.
|
|
109
109
|
- **Commit to one layout stance, built for a thumb.** Pick the stance the app's job calls for and hold it on every view — a board of cards, a feed under a hero, a dashboard of stats, a split header and list, a tabbed switcher, a sticky bottom action bar — so the first screen says what kind of app this is before a word is read. The bold stance is the default: a scoreboard is a wall of big numbers, a cast is a grid of faces, a planner is a week you can see at once; a quiet single column is the stance for a reading app and nothing else. Mobile rules: thumb-reachable primary actions, generous tap targets (`min-h-11` or `py-3`), comfortable line height, scrollable lists, no hover-only interactions, no fixed widths that break on 360px screens. Mobile-first, then `md:` / `lg:` for larger viewports.
|
|
110
110
|
- **Touch controls belong to the finger on a phone.** A 3D or canvas scene, a joystick or D-pad, a drag surface, or any button someone presses and holds carries `select-none touch-none` on the control area **and** its container (the HUD and labels around it too), so a press or drag steers the app while nearby text stays put — no selection highlight, no copy callout, no page scroll or zoom. Drive holds with `onPointerDown` / `onPointerUp` / `onPointerCancel` (mouse and touch in one path), and give a hold button `onContextMenu={(e) => e.preventDefault()}` so a long press keeps holding. Every hint names what a thumb does — swipe, tap, hold — never a key or a mouse.
|
package/system-prompt-initial.md
CHANGED
|
@@ -98,7 +98,7 @@ The sandbox serves raw ES modules, so `App.jsx` can import local `.js`/`.jsx` fi
|
|
|
98
98
|
Three things happen in this order on every screen, and the first two happen for a visitor who has not signed in:
|
|
99
99
|
|
|
100
100
|
1. **Reading comes first.** Whatever the rules and the app's sharing setting let a signed-out visitor read renders at once: the board of what is on this week, the finished pieces in a gallery, the menu a shop posts. The write surface is what the rules gate, so a visitor reads those records with the Add control waiting beneath them, and the records keep their place on the screen. What the rules keep to members — a guest list, the names on a chore chart — stays with the members, and a visitor meets the ask to join in its place. An app a person keeps for themselves — a tracker, a log, a list just for them — opens on its own screen for a signed-out visitor too: the habits or entries view, its controls in their `can` state and its inviting empty state, with the sign-in ask beside the control that would save. Its first screen is the app itself, with the ask beside it.
|
|
101
|
-
2. **The write surface is gated on `can`.** `useVibe(dbName).can` decides whether the Add, Edit or Delete control shows and in what state (`pending` holds it quietly; a resolved denial gets one sentence in the app's own words). Nothing else on the screen waits on it.
|
|
101
|
+
2. **The write surface is gated on `can`.** `useVibe(dbName).can` decides whether the Add, Edit or Delete control shows and in what state (`pending` holds it quietly; a resolved denial gets one sentence in the app's own words). Nothing else on the screen waits on it. A form that opens from a button — a Dialog or Sheet `trigger`, a Claim or Add that reveals fields — is gated at its Save: the opening button stays pressable, the form opens with its fields, and Save asks `can.create(draft)` with the draft built from what the person typed (an Edit form's Save asks `can.edit(doc)` of the record it changes). When the app's own access rules ask a writer to sign in, a settled signed-out visitor's opening button is the sign-in ask itself, named for the action ("Sign in to claim a slot"), so their first press goes somewhere.
|
|
102
102
|
3. **The ask is a button, at the moment of value.** The sign-in ask is one `Button` wired to `useViewer().requestLogin()`, shown once identity has settled (`!isViewerPending && !viewer`), worded for what the person gets ("Keep these on all your devices", "Sign in to add your dish"), and placed where they feel the pull: beside the control that would save, or right after they made something worth keeping. Every sentence the app renders that mentions signing in has that button beside it, so the reader acts where they read. The use-viewer skill's _Asking a visitor to sign in_ has the worked example.
|
|
103
103
|
- **Commit to one layout stance, built for a thumb.** Pick the stance the app's job calls for and hold it on every view — a board of cards, a feed under a hero, a dashboard of stats, a split header and list, a tabbed switcher, a sticky bottom action bar — so the first screen says what kind of app this is before a word is read. The bold stance is the default: a scoreboard is a wall of big numbers, a cast is a grid of faces, a planner is a week you can see at once; a quiet single column is the stance for a reading app and nothing else. Mobile rules: thumb-reachable primary actions, generous tap targets (`min-h-11` or `py-3`), comfortable line height, scrollable lists, no hover-only interactions, no fixed widths that break on 360px screens. Mobile-first, then `md:` / `lg:` for larger viewports.
|
|
104
104
|
- **Touch controls belong to the finger on a phone.** A 3D or canvas scene, a joystick or D-pad, a drag surface, or any button someone presses and holds carries `select-none touch-none` on the control area **and** its container (the HUD and labels around it too), so a press or drag steers the app while nearby text stays put — no selection highlight, no copy callout, no page scroll or zoom. Drive holds with `onPointerDown` / `onPointerUp` / `onPointerCancel` (mouse and touch in one path), and give a hold button `onContextMenu={(e) => e.preventDefault()}` so a long press keeps holding. Every hint names what a thumb does — swipe, tap, hold — never a key or a mouse.
|
package/system-prompt.md
CHANGED
|
@@ -98,7 +98,7 @@ The sandbox serves raw ES modules, so `App.jsx` can import local `.js`/`.jsx` fi
|
|
|
98
98
|
Three things happen in this order on every screen, and the first two happen for a visitor who has not signed in:
|
|
99
99
|
|
|
100
100
|
1. **Reading comes first.** Whatever the rules and the app's sharing setting let a signed-out visitor read renders at once: the board of what is on this week, the finished pieces in a gallery, the menu a shop posts. The write surface is what the rules gate, so a visitor reads those records with the Add control waiting beneath them, and the records keep their place on the screen. What the rules keep to members — a guest list, the names on a chore chart — stays with the members, and a visitor meets the ask to join in its place. An app a person keeps for themselves — a tracker, a log, a list just for them — opens on its own screen for a signed-out visitor too: the habits or entries view, its controls in their `can` state and its inviting empty state, with the sign-in ask beside the control that would save. Its first screen is the app itself, with the ask beside it.
|
|
101
|
-
2. **The write surface is gated on `can`.** `useVibe(dbName).can` decides whether the Add, Edit or Delete control shows and in what state (`pending` holds it quietly; a resolved denial gets one sentence in the app's own words). Nothing else on the screen waits on it.
|
|
101
|
+
2. **The write surface is gated on `can`.** `useVibe(dbName).can` decides whether the Add, Edit or Delete control shows and in what state (`pending` holds it quietly; a resolved denial gets one sentence in the app's own words). Nothing else on the screen waits on it. A form that opens from a button — a Dialog or Sheet `trigger`, a Claim or Add that reveals fields — is gated at its Save: the opening button stays pressable, the form opens with its fields, and Save asks `can.create(draft)` with the draft built from what the person typed (an Edit form's Save asks `can.edit(doc)` of the record it changes). When the app's own access rules ask a writer to sign in, a settled signed-out visitor's opening button is the sign-in ask itself, named for the action ("Sign in to claim a slot"), so their first press goes somewhere.
|
|
102
102
|
3. **The ask is a button, at the moment of value.** The sign-in ask is one `Button` wired to `useViewer().requestLogin()`, shown once identity has settled (`!isViewerPending && !viewer`), worded for what the person gets ("Keep these on all your devices", "Sign in to add your dish"), and placed where they feel the pull: beside the control that would save, or right after they made something worth keeping. Every sentence the app renders that mentions signing in has that button beside it, so the reader acts where they read. The use-viewer skill's _Asking a visitor to sign in_ has the worked example.
|
|
103
103
|
- **Commit to one layout stance, built for a thumb.** Pick the stance the app's job calls for and hold it on every view — a board of cards, a feed under a hero, a dashboard of stats, a split header and list, a tabbed switcher, a sticky bottom action bar — so the first screen says what kind of app this is before a word is read. The bold stance is the default: a scoreboard is a wall of big numbers, a cast is a grid of faces, a planner is a week you can see at once; a quiet single column is the stance for a reading app and nothing else. Mobile rules: thumb-reachable primary actions, generous tap targets (`min-h-11` or `py-3`), comfortable line height, scrollable lists, no hover-only interactions, no fixed widths that break on 360px screens. Mobile-first, then `md:` / `lg:` for larger viewports.
|
|
104
104
|
- **Touch controls belong to the finger on a phone.** A 3D or canvas scene, a joystick or D-pad, a drag surface, or any button someone presses and holds carries `select-none touch-none` on the control area **and** its container (the HUD and labels around it too), so a press or drag steers the app while nearby text stays put — no selection highlight, no copy callout, no page scroll or zoom. Drive holds with `onPointerDown` / `onPointerUp` / `onPointerCancel` (mouse and touch in one path), and give a hold button `onContextMenu={(e) => e.preventDefault()}` so a long press keeps holding. Every hint names what a thumb does — swipe, tap, hold — never a key or a mouse.
|