@vibes.diy/prompts 14.3.300 → 14.3.301
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/index.d.ts +2 -1
- package/llms/index.js +3 -0
- package/llms/index.js.map +1 -1
- package/llms/square.d.ts +2 -0
- package/llms/square.js +33 -0
- package/llms/square.js.map +1 -0
- package/llms/square.md +794 -0
- package/llms/stripe.js +20 -1
- package/llms/stripe.js.map +1 -1
- package/package.json +5 -5
package/llms/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export { socialPostConfig } from "./social-post.js";
|
|
|
41
41
|
export { youtubeConfig } from "./youtube.js";
|
|
42
42
|
export { blueskyConfig } from "./bluesky.js";
|
|
43
43
|
export { spotifyConfig } from "./spotify.js";
|
|
44
|
+
export { squareConfig } from "./square.js";
|
|
44
45
|
export { stripeConfig } from "./stripe.js";
|
|
45
46
|
export { stripeSubscriptionsConfig } from "./stripe-subscriptions.js";
|
|
46
47
|
export { blocklyConfig } from "./blockly.js";
|
|
@@ -82,7 +83,7 @@ export { uiTestimonialsConfig } from "./ui-testimonials.js";
|
|
|
82
83
|
export type { LlmConfig, SkillCredential, SkillEgress } from "./types.js";
|
|
83
84
|
export { cueMatches, cueMatchedSkills, type CueCatalogEntry } from "./cues.js";
|
|
84
85
|
export { expandSkills, onSkillMenu, skillGraphProblems, universalSkillNames, type NeedsCatalogEntry } from "./needs.js";
|
|
85
|
-
export declare const allConfigs: readonly [LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig];
|
|
86
|
+
export declare const allConfigs: readonly [LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig];
|
|
86
87
|
export { mapsConfig } from "./maps.js";
|
|
87
88
|
export declare const SKILL_ALIASES: ReadonlyMap<string, string>;
|
|
88
89
|
export declare function canonicalSkillName(name: string): string;
|
package/llms/index.js
CHANGED
|
@@ -41,6 +41,7 @@ import { socialPostConfig } from "./social-post.js";
|
|
|
41
41
|
import { youtubeConfig } from "./youtube.js";
|
|
42
42
|
import { blueskyConfig } from "./bluesky.js";
|
|
43
43
|
import { spotifyConfig } from "./spotify.js";
|
|
44
|
+
import { squareConfig } from "./square.js";
|
|
44
45
|
import { stripeConfig } from "./stripe.js";
|
|
45
46
|
import { stripeSubscriptionsConfig } from "./stripe-subscriptions.js";
|
|
46
47
|
import { blocklyConfig } from "./blockly.js";
|
|
@@ -121,6 +122,7 @@ export { socialPostConfig } from "./social-post.js";
|
|
|
121
122
|
export { youtubeConfig } from "./youtube.js";
|
|
122
123
|
export { blueskyConfig } from "./bluesky.js";
|
|
123
124
|
export { spotifyConfig } from "./spotify.js";
|
|
125
|
+
export { squareConfig } from "./square.js";
|
|
124
126
|
export { stripeConfig } from "./stripe.js";
|
|
125
127
|
export { stripeSubscriptionsConfig } from "./stripe-subscriptions.js";
|
|
126
128
|
export { blocklyConfig } from "./blockly.js";
|
|
@@ -205,6 +207,7 @@ export const allConfigs = [
|
|
|
205
207
|
weatherConfig,
|
|
206
208
|
stripeConfig,
|
|
207
209
|
stripeSubscriptionsConfig,
|
|
210
|
+
squareConfig,
|
|
208
211
|
groupPlanConfig,
|
|
209
212
|
blocklyConfig,
|
|
210
213
|
strudelConfig,
|
package/llms/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../jsr/llms/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,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,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/llms/square.d.ts
ADDED
package/llms/square.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const squareConfig = {
|
|
2
|
+
name: "square",
|
|
3
|
+
label: "Square payments",
|
|
4
|
+
description: "Taking real money through Square, for an owner who already sells on Square: load it only when the person names Square — Square, my Square account, pay with Square, Square checkout, sell on Square, a Square payment link — and every other ask to take money, with no Square in the words, is the stripe skill. One-time payments into the owner's own Square account on the owner's own Square access token, pasted once into the vibe's Secrets as SQUARE_ACCESS_TOKEN (SQUARE_ENV=sandbox for Square's developer sandbox): the setup steps the app shows until the token is in, linking the Square Developer Console's Credentials page; every Square call in backend.js with ctx.fetch, never from the page; the first active location that takes cards and its currency; the owner's product catalog as records only the owner writes, priced in the currency's smallest unit (cents for USD, yen for JPY), and backend.js pricing every line from those records; one pending order then one Square payment link opened in a new tab; an order marked paid only after backend.js reads Square's order back and matches our reference_id, total, a tender and nothing left to pay; a scheduled sweep that settles orders whose buyer closed the tab; a notice to the owner per sale; refunds in the Square Dashboard",
|
|
5
|
+
cues: [
|
|
6
|
+
"with square",
|
|
7
|
+
"through square",
|
|
8
|
+
"via square",
|
|
9
|
+
"using square",
|
|
10
|
+
"square account",
|
|
11
|
+
"my square account",
|
|
12
|
+
"pay with square",
|
|
13
|
+
"square checkout",
|
|
14
|
+
"square payment",
|
|
15
|
+
"square payments",
|
|
16
|
+
"square payment link",
|
|
17
|
+
"sell on square",
|
|
18
|
+
"square pos",
|
|
19
|
+
],
|
|
20
|
+
needs: ["owner-secret"],
|
|
21
|
+
credential: "owner-secret",
|
|
22
|
+
egress: [
|
|
23
|
+
{ url: "https://connect.squareup.com/v2/merchants/me", via: "platform" },
|
|
24
|
+
{ url: "https://connect.squareup.com/v2/locations", via: "platform" },
|
|
25
|
+
{ url: "https://connect.squareup.com/v2/online-checkout/payment-links", method: "POST", via: "platform" },
|
|
26
|
+
{ url: "https://connect.squareup.com/v2/orders/sq-order-id", via: "platform" },
|
|
27
|
+
{ url: "https://connect.squareupsandbox.com/v2/merchants/me", via: "platform" },
|
|
28
|
+
{ url: "https://connect.squareupsandbox.com/v2/locations", via: "platform" },
|
|
29
|
+
{ url: "https://connect.squareupsandbox.com/v2/online-checkout/payment-links", method: "POST", via: "platform" },
|
|
30
|
+
{ url: "https://connect.squareupsandbox.com/v2/orders/sq-order-id", via: "platform" },
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=square.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"square.js","sourceRoot":"","sources":["../../jsr/llms/square.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,YAAY,GAAc;IACrC,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,iBAAiB;IACxB,WAAW,EACT,4vCAA4vC;IAC9vC,IAAI,EAAE;QACJ,aAAa;QACb,gBAAgB;QAChB,YAAY;QACZ,cAAc;QACd,gBAAgB;QAChB,mBAAmB;QACnB,iBAAiB;QACjB,iBAAiB;QACjB,gBAAgB;QAChB,iBAAiB;QACjB,qBAAqB;QACrB,gBAAgB;QAChB,YAAY;KACb;IACD,KAAK,EAAE,CAAC,cAAc,CAAC;IACvB,UAAU,EAAE,cAAc;IAG1B,MAAM,EAAE;QACN,EAAE,GAAG,EAAE,8CAA8C,EAAE,GAAG,EAAE,UAAU,EAAE;QACxE,EAAE,GAAG,EAAE,2CAA2C,EAAE,GAAG,EAAE,UAAU,EAAE;QACrE,EAAE,GAAG,EAAE,+DAA+D,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE;QACzG,EAAE,GAAG,EAAE,oDAAoD,EAAE,GAAG,EAAE,UAAU,EAAE;QAC9E,EAAE,GAAG,EAAE,qDAAqD,EAAE,GAAG,EAAE,UAAU,EAAE;QAC/E,EAAE,GAAG,EAAE,kDAAkD,EAAE,GAAG,EAAE,UAAU,EAAE;QAC5E,EAAE,GAAG,EAAE,sEAAsE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE;QAChH,EAAE,GAAG,EAAE,2DAA2D,EAAE,GAAG,EAAE,UAAU,EAAE;KACtF;CACF,CAAC"}
|
package/llms/square.md
ADDED
|
@@ -0,0 +1,794 @@
|
|
|
1
|
+
# Square payments — take real money into the owner's own Square account
|
|
2
|
+
|
|
3
|
+
When someone asks to take money **with Square** — "I sell on Square", "my
|
|
4
|
+
Square account", "pay with Square", "Square checkout" — build it on a
|
|
5
|
+
**Square payment link** from `backend.js`. The owner pastes their own Square
|
|
6
|
+
access token into the vibe's Secrets once, and backend.js calls Square with it.
|
|
7
|
+
This page is for owners who already sell on Square: their sales land beside
|
|
8
|
+
their counter sales in the Square Dashboard they already use. Every other ask
|
|
9
|
+
to take money, with no Square in the words, is the `stripe` skill.
|
|
10
|
+
|
|
11
|
+
This is a `backend.js` feature, and the token is the owner's own key (the
|
|
12
|
+
owner-key rules that load with this page). This page is the recipe that keeps
|
|
13
|
+
every Square call on the server, keeps "paid" a fact only Square can
|
|
14
|
+
establish, and keeps every order honest about where it is.
|
|
15
|
+
|
|
16
|
+
**The price list is the owner's, and it lives in the app.**
|
|
17
|
+
|
|
18
|
+
Each thing for sale is a product record in the app's own database that only the owner writes, from the app's own Products screen, priced in its currency's smallest unit (cents for USD, yen for JPY), and backend.js prices every line from the owner's product records and never from an amount the browser sends.
|
|
19
|
+
|
|
20
|
+
The owner lists what they sell, sets each price, changes it next week and takes
|
|
21
|
+
a thing off sale, all from the app's **Products** screen with no new build.
|
|
22
|
+
`access.js` takes a `product` record from the owner alone and checks its price
|
|
23
|
+
is a whole number of the currency's smallest unit. The live catalog starts
|
|
24
|
+
empty: the owner's first view is the form for their first product, and a buyer
|
|
25
|
+
sees *Nothing for sale yet* until there is one. Square's own item catalog is
|
|
26
|
+
left as it is: the order sent to Square carries each line's name, quantity and
|
|
27
|
+
price, so the owner keeps one list, here.
|
|
28
|
+
|
|
29
|
+
**Anyone pays, signed in or not.** Square's page collects the card, asks the
|
|
30
|
+
buyer for their email and sends the receipt, so a visitor with no Vibes DIY
|
|
31
|
+
account fills the bag and pays. The order records the buyer's handle when they
|
|
32
|
+
happen to be signed in, and a guest's order is just as real. Sign-in is asked
|
|
33
|
+
for only when the owner's own request asks for it (members only, a "my orders"
|
|
34
|
+
page).
|
|
35
|
+
|
|
36
|
+
**One-time payments.** A payment link takes one payment for one order. Sell a
|
|
37
|
+
period as a one-time item (a season pass, this month's class) and say so; a
|
|
38
|
+
renewing Square subscription needs plans in the owner's Square catalog, which
|
|
39
|
+
is beyond this recipe.
|
|
40
|
+
|
|
41
|
+
**The first sale is real money.** The owner's production token charges real
|
|
42
|
+
cards, so the Setup screen says so plainly and suggests the owner buy their
|
|
43
|
+
cheapest item once and refund it from the Square Dashboard. Square's developer
|
|
44
|
+
sandbox is the rehearsal space: an `SQUARE_ENV` secret of `sandbox` with the
|
|
45
|
+
sandbox token sends every call to Square's sandbox, where the payment page
|
|
46
|
+
carries a **Test Payment** button that pays like a buyer would.
|
|
47
|
+
|
|
48
|
+
## 1. The setup item: the owner's Square access token
|
|
49
|
+
|
|
50
|
+
The Square item is the access token: the backend answers missing-key while ctx.secrets.SQUARE_ACCESS_TOKEN is absent, and its steps link the Square Developer Console by URL and name SQUARE_ACCESS_TOKEN in so many words.
|
|
51
|
+
|
|
52
|
+
The Setup surface the item lands on (the owner-only entry in the app's
|
|
53
|
+
navigation, the verdict from `/setup`, the re-read on focus that unlocks Pay in
|
|
54
|
+
place) is the use-vibe docs' *Some apps need setup before they work*; this
|
|
55
|
+
recipe contributes one item to it. The steps are written for someone who sells
|
|
56
|
+
on Square and has never opened its developer site, so each one links the exact
|
|
57
|
+
page and uses that page's own words:
|
|
58
|
+
|
|
59
|
+
1. Open the Square Developer Console, <https://developer.squareup.com/apps>,
|
|
60
|
+
and sign in with the Square account you sell with.
|
|
61
|
+
2. Press **+** (Create an application), give it any name, such as this
|
|
62
|
+
app's, and save.
|
|
63
|
+
3. Open the application, choose **Credentials**, switch the toggle at the top
|
|
64
|
+
to **Production**, and copy the **Production Access token** (press
|
|
65
|
+
**Show**, then copy).
|
|
66
|
+
4. Save it under **Secrets** on this vibe's Settings tab as
|
|
67
|
+
`SQUARE_ACCESS_TOKEN`, then come back: the owner-key steps every item ends
|
|
68
|
+
with.
|
|
69
|
+
|
|
70
|
+
The item is done when the token is saved **and** Square answered with a
|
|
71
|
+
location that takes cards. `/setup` asks Square on the owner's call alone
|
|
72
|
+
(`GET /v2/merchants/me` and `GET /v2/locations`) and keeps the answer in a
|
|
73
|
+
`setup` record the backend writes: the business name, the location's name and
|
|
74
|
+
its currency. A visitor's read takes the kept record, so visitor traffic spends
|
|
75
|
+
nothing of the owner's Square account, and the owner sees *Connected to
|
|
76
|
+
<business> · <location> · USD* on the Setup screen once it works. A token that
|
|
77
|
+
Square refuses leaves the item *To do* with Square's own sentence beside it.
|
|
78
|
+
|
|
79
|
+
## 2. Square stays on the server
|
|
80
|
+
|
|
81
|
+
Every Square request is made in backend.js with ctx.fetch and ctx.secrets.SQUARE_ACCESS_TOKEN; App.jsx never calls connect.squareup.com.
|
|
82
|
+
|
|
83
|
+
Square's API sends no CORS headers, so the browser could not reach it anyway,
|
|
84
|
+
and the token rides only the backend's request: `Authorization: Bearer
|
|
85
|
+
<token>`, `Square-Version: 2025-10-16`, and a JSON body. The host is
|
|
86
|
+
`https://connect.squareup.com`, or `https://connect.squareupsandbox.com` when
|
|
87
|
+
`ctx.secrets.SQUARE_ENV` is `sandbox`.
|
|
88
|
+
|
|
89
|
+
backend.js calls only the four Square endpoints the platform admits: GET /v2/merchants/me, GET /v2/locations, POST /v2/online-checkout/payment-links and GET /v2/orders/{order_id}.
|
|
90
|
+
|
|
91
|
+
Those four are a whole shop: who the business is, where it sells, a hosted
|
|
92
|
+
checkout for one order, and that order read back. Square's own page takes the
|
|
93
|
+
card, so the app never creates a payment, and refunds stay in the Square
|
|
94
|
+
Dashboard, where the owner already makes them.
|
|
95
|
+
|
|
96
|
+
A payment link names one **location**, and the order is charged in that
|
|
97
|
+
location's currency. Pick the first location whose `status` is `ACTIVE` and
|
|
98
|
+
whose `capabilities` include `CREDIT_CARD_PROCESSING`. Products are priced in
|
|
99
|
+
that currency's smallest unit (cents for USD, whole yen for JPY: read the digits from
|
|
100
|
+
`Intl.NumberFormat`, never a fixed 100), and the page shows prices in the
|
|
101
|
+
currency `/setup` hands it.
|
|
102
|
+
|
|
103
|
+
Checkout opens in a new tab with `window.open`, because the app runs inside a
|
|
104
|
+
frame that cannot navigate the page around it. Open the tab inside the click,
|
|
105
|
+
before any `await`, and say so on the button: *Pay $24 — Square opens in a new
|
|
106
|
+
tab*.
|
|
107
|
+
|
|
108
|
+
## 3. One order, then one payment link
|
|
109
|
+
|
|
110
|
+
The order exists before the money moves. `/checkout` takes the bag, *which
|
|
111
|
+
products and how many of each*, prices every line from the owner's records,
|
|
112
|
+
writes an `order` in `pending`, and only then asks Square for a payment link
|
|
113
|
+
for exactly that order:
|
|
114
|
+
|
|
115
|
+
```js partial
|
|
116
|
+
const r = await square(ctx, "POST", "/v2/online-checkout/payment-links", {
|
|
117
|
+
idempotency_key: order._id, // a retried request makes one link, not two
|
|
118
|
+
order: {
|
|
119
|
+
location_id: location.id,
|
|
120
|
+
reference_id: order._id, // Square keeps our order id, so the read-back proves whose order it is
|
|
121
|
+
line_items: order.lines.map((l) => ({
|
|
122
|
+
name: l.title,
|
|
123
|
+
quantity: String(l.qty), // Square takes the quantity as a string
|
|
124
|
+
base_price_money: { amount: l.unitAmount, currency: order.currency },
|
|
125
|
+
})),
|
|
126
|
+
},
|
|
127
|
+
checkout_options: { redirect_url: appUrl(ctx, `#paid=${order._id}`) },
|
|
128
|
+
});
|
|
129
|
+
// r.body.payment_link: { id, url, order_id }. Keep url and order_id on our order.
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- Our order id is `"order-"` and a fresh UUID with its dashes removed, 38
|
|
133
|
+
characters, because Square caps `reference_id` at 40.
|
|
134
|
+
- Keep `payment_link.order_id` (Square's order) and `payment_link.url` on our
|
|
135
|
+
order, with the Square env (`production` or `sandbox`) and the location id it
|
|
136
|
+
was made in. A second press of Pay on the same bag at the same prices, while
|
|
137
|
+
that order is pending in the same env and location, reuses its link rather
|
|
138
|
+
than making another order. Look for it on every page of the pending query,
|
|
139
|
+
which filters after its limit.
|
|
140
|
+
- Amounts are integers in the currency's smallest unit: $12.50 is `1250`,
|
|
141
|
+
never `12.5`, and ¥1,000 is `1000`, in the product record, the order and
|
|
142
|
+
Square's `amount`. The product keeps its currency too, and `/checkout` sells
|
|
143
|
+
only products priced in the location's.
|
|
144
|
+
- A bag is capped at a sensible number of lines and a quantity per line.
|
|
145
|
+
|
|
146
|
+
The routes read the `orders` database, which `access.js` binds, so `backend.js`
|
|
147
|
+
declares `config.fetch.unfilteredReads` for it, and owes what that waives:
|
|
148
|
+
`/confirm` answers a signed-in buyer about their own order only, a guest only
|
|
149
|
+
the status of the order id their return page names, and no route lists orders
|
|
150
|
+
for anyone. The owner's view of every order is the page's own live query.
|
|
151
|
+
|
|
152
|
+
## 4. "Paid" is a fact the backend reads back from Square
|
|
153
|
+
|
|
154
|
+
An order is marked paid only after backend.js reads it back with GET /v2/orders/{order_id} and finds our reference_id, our total, a tender and nothing left to pay.
|
|
155
|
+
|
|
156
|
+
```js partial
|
|
157
|
+
const so = (await square(ctx, "GET", `/v2/orders/${encodeURIComponent(order.squareOrderId)}`)).body?.order;
|
|
158
|
+
const ours = so?.reference_id === order._id && so?.total_money?.amount === order.amount && so?.total_money?.currency === order.currency;
|
|
159
|
+
const paid = ours && (so.tenders ?? []).length > 0 && so.net_amount_due_money?.amount === 0;
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Square adds nothing to the return address, so the page names its own order
|
|
163
|
+
(`#paid=<orderId>`) and asks `/confirm`, which reads Square's copy and moves the
|
|
164
|
+
order to `paid`. The address only says which order to ask about: someone who
|
|
165
|
+
types `#paid=` into their own address bar fools only themselves.
|
|
166
|
+
|
|
167
|
+
A scheduled sweep every 5 minutes settles the orders whose buyer closed Square's tab.
|
|
168
|
+
|
|
169
|
+
A payment link never expires, so the sweep reads every pending order, however
|
|
170
|
+
old: an order leaves `pending` only when Square's copy says paid, or `CANCELED`.
|
|
171
|
+
|
|
172
|
+
Settling is idempotent: an order that is no longer pending comes back as it
|
|
173
|
+
is. When an order settles as paid, backend.js tells the owner with `ctx.notify`
|
|
174
|
+
(`toHandle` the owner, a body naming what sold and for how much, and a
|
|
175
|
+
`dedupeKey` from the order id), so each sale reaches the owner once however
|
|
176
|
+
many times it settles. A notice that cannot be delivered is logged and never
|
|
177
|
+
undoes the sale. `access.js` makes the rest structural: only backend.js writes
|
|
178
|
+
an order, and an order keeps its buyer and its price.
|
|
179
|
+
|
|
180
|
+
## 5. What the buyer and the owner each see
|
|
181
|
+
|
|
182
|
+
- The buyer presses **Pay**, Square's page opens in a new tab, and when they
|
|
183
|
+
come back the page reads *Paid. Thank you!* once `/confirm` answers, or
|
|
184
|
+
*Your payment is still confirming* while it asks `/confirm` again on a short
|
|
185
|
+
backoff and whenever the page comes back into view, until it reads paid. Square emails
|
|
186
|
+
their receipt.
|
|
187
|
+
- The owner's **Orders** lists every order: who, what, how much, its status,
|
|
188
|
+
and for a paid one the line *Also in your Square Dashboard*, where refunds,
|
|
189
|
+
payouts and reports live.
|
|
190
|
+
- The owner's **Products** is the price list, and **Setup** shows which Square
|
|
191
|
+
business and location the app sells through.
|
|
192
|
+
|
|
193
|
+
## 6. Errors keep their reason
|
|
194
|
+
|
|
195
|
+
Square answers a refusal with `{ errors: [{ category, code, detail }] }`. Keep
|
|
196
|
+
`detail` and return `{ ok: false, reason, message }` so the page can say why:
|
|
197
|
+
|
|
198
|
+
- `missing-key`: the token is not saved yet. A visitor reads *Checkout is not
|
|
199
|
+
open yet*; the owner sees the Setup item.
|
|
200
|
+
- `401` (`UNAUTHORIZED`): Square refused the token. The item reads *To do*
|
|
201
|
+
with Square's sentence, and the fix is a fresh production token saved under
|
|
202
|
+
the same name.
|
|
203
|
+
- `no-location`: the account has no active location that takes cards; the
|
|
204
|
+
Setup item says so in those words.
|
|
205
|
+
- anything else: Square's own `detail`.
|
|
206
|
+
|
|
207
|
+
Wrap every route in `try`/`catch` and answer with a reason, because an uncaught
|
|
208
|
+
throw reaches the page as a bare `500` that names nothing the owner can fix.
|
|
209
|
+
|
|
210
|
+
## Complete backend.js
|
|
211
|
+
|
|
212
|
+
The worked example is a bakery's preorder page: the owner lists the week's
|
|
213
|
+
boxes, anyone pays on Square's page, and every sale lands in the bakery's
|
|
214
|
+
Square Dashboard.
|
|
215
|
+
|
|
216
|
+
### `backend.js`
|
|
217
|
+
```js app=square-shop
|
|
218
|
+
// Square payment links for one merchant: the owner's own Square access token, Square's hosted
|
|
219
|
+
// checkout page, and orders settled by reading each one back from Square.
|
|
220
|
+
export const config = {
|
|
221
|
+
scheduled: { interval: "5m" },
|
|
222
|
+
// The routes read the owner's catalog and a buyer's own order; access.js binds the database, so
|
|
223
|
+
// the fetch lane needs this declaration, and the routes owe the buyerHandle check it waives.
|
|
224
|
+
fetch: { unfilteredReads: { dbs: ["orders"], why: "/checkout reads the products the buyer names from the owner's catalog; /confirm reads 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; /setup reads the kept Square setup record" } },
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const DB = "orders";
|
|
228
|
+
const SETUP_ID = "setup:square";
|
|
229
|
+
const SQUARE_VERSION = "2025-10-16";
|
|
230
|
+
const LINK_TTL_MS = 24 * 60 * 60 * 1000; // a pending order's link is reused for a day
|
|
231
|
+
|
|
232
|
+
function json(body, status = 200) {
|
|
233
|
+
return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function appUrl(ctx, hash) {
|
|
237
|
+
return `https://vibes.diy/vibe/${ctx.appInfo.ownerHandle}/${ctx.appInfo.appSlug}${hash}`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Production unless the owner set SQUARE_ENV to "sandbox" with a sandbox token. Each order keeps the
|
|
241
|
+
// env it was made in, since a sandbox order lives on the sandbox host alone.
|
|
242
|
+
function squareEnv(ctx) {
|
|
243
|
+
return ctx.secrets.SQUARE_ENV === "sandbox" ? "sandbox" : "production";
|
|
244
|
+
}
|
|
245
|
+
function squareHost(ctx) {
|
|
246
|
+
return squareEnv(ctx) === "sandbox" ? "https://connect.squareupsandbox.com" : "https://connect.squareup.com";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Amounts are in the currency's smallest unit, the one Square charges in: cents for USD, whole yen
|
|
250
|
+
// for JPY. Read and show them through that unit, never a fixed 100.
|
|
251
|
+
const digits = (currency) => new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits;
|
|
252
|
+
|
|
253
|
+
// One Square call on the owner's account. The token rides only this request; Square's own
|
|
254
|
+
// sentence is kept when it refuses.
|
|
255
|
+
async function square(ctx, method, path, body) {
|
|
256
|
+
const token = ctx.secrets.SQUARE_ACCESS_TOKEN;
|
|
257
|
+
if (!token) return { ok: false, reason: "missing-key" };
|
|
258
|
+
const res = await ctx.fetch(`${squareHost(ctx)}${path}`, {
|
|
259
|
+
method,
|
|
260
|
+
headers: { authorization: `Bearer ${token}`, "square-version": SQUARE_VERSION, "content-type": "application/json" },
|
|
261
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
262
|
+
});
|
|
263
|
+
const out = await res.json().catch(() => null);
|
|
264
|
+
if (!res.ok) return { ok: false, reason: res.status === 401 ? "unauthorized" : "square", status: res.status, message: out?.errors?.[0]?.detail ?? `HTTP ${res.status}` };
|
|
265
|
+
return { ok: true, body: out };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// The location a payment link names: the first active one that takes cards. Its currency prices the order.
|
|
269
|
+
async function mainLocation(ctx) {
|
|
270
|
+
const r = await square(ctx, "GET", "/v2/locations");
|
|
271
|
+
if (!r.ok) return r;
|
|
272
|
+
const loc = (r.body.locations ?? []).find((l) => l.status === "ACTIVE" && (l.capabilities ?? []).includes("CREDIT_CARD_PROCESSING"));
|
|
273
|
+
if (!loc) return { ok: false, reason: "no-location", message: "This Square account has no active location that takes cards." };
|
|
274
|
+
return { ok: true, location: { id: loc.id, name: loc.name, currency: loc.currency } };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// What is for sale is the owner's catalog: `product` records written by the owner alone (access.js).
|
|
278
|
+
// The browser names a product and a quantity, never an amount.
|
|
279
|
+
const MAX_LINES = 20;
|
|
280
|
+
const MAX_QTY = 99;
|
|
281
|
+
async function priceBag(ctx, bag, currency) {
|
|
282
|
+
if (!Array.isArray(bag) || bag.length === 0 || bag.length > MAX_LINES) return null;
|
|
283
|
+
if (!bag.every((item) => Number.isInteger(item?.qty) && item.qty >= 1 && item.qty <= MAX_QTY)) return null;
|
|
284
|
+
if (new Set(bag.map((item) => item.productId)).size !== bag.length) return null;
|
|
285
|
+
const products = await Promise.all(
|
|
286
|
+
bag.map(async (item) => {
|
|
287
|
+
if (typeof item.productId !== "string" || !item.productId.startsWith("product-")) return null;
|
|
288
|
+
const p = await ctx.db.get(item.productId, { db: DB });
|
|
289
|
+
// A product priced in another currency (the owner's location changed since) is not for sale here.
|
|
290
|
+
return p?.type === "product" && p.onSale === true && p.currency === currency && Number.isInteger(p.amount) && p.amount > 0 ? p : null;
|
|
291
|
+
})
|
|
292
|
+
);
|
|
293
|
+
if (products.some((p) => !p)) return null;
|
|
294
|
+
const lines = products.map((p, i) => ({ productId: p._id, title: p.title, unitAmount: p.amount, qty: bag[i].qty }));
|
|
295
|
+
const key = lines.map((l) => `${l.productId}:${l.qty}:${l.unitAmount}`).sort().join(",");
|
|
296
|
+
return { lines, amount: lines.reduce((n, l) => n + l.unitAmount * l.qty, 0), key };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// The owner hears about each sale once: the dedupeKey is the order.
|
|
300
|
+
async function tellOwner(ctx, order) {
|
|
301
|
+
const price = new Intl.NumberFormat("en-US", { style: "currency", currency: order.currency }).format(order.amount / 10 ** digits(order.currency));
|
|
302
|
+
const buyer = order.buyerHandle ? `@${order.buyerHandle}` : "a guest";
|
|
303
|
+
try {
|
|
304
|
+
await ctx.notify({ toHandle: ctx.appInfo.ownerHandle, body: `Square sale: ${order.title} to ${buyer}, ${price}`.slice(0, 500), dedupeKey: `sale-${order._id}` });
|
|
305
|
+
} catch (err) {
|
|
306
|
+
ctx.log("warn", "sale notice not delivered", { id: order._id, reason: err.message }); // the sale stands either way
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Move one pending order to what Square says about it. Paid = Square's own copy of the order,
|
|
311
|
+
// carrying our order id and our total, with a tender and nothing left to pay. A payment link never
|
|
312
|
+
// expires, so an order stays pending (and swept) until Square has it paid or canceled.
|
|
313
|
+
async function settle(ctx, order) {
|
|
314
|
+
if (order.status !== "pending" || !order.squareOrderId) return order;
|
|
315
|
+
// The token on hand reads its own env only; an order from the other env settles once the owner switches back.
|
|
316
|
+
if ((order.env ?? "production") !== squareEnv(ctx)) return order;
|
|
317
|
+
const r = await square(ctx, "GET", `/v2/orders/${encodeURIComponent(order.squareOrderId)}`);
|
|
318
|
+
if (!r.ok) return order; // a refusal settles nothing; the next read tries again
|
|
319
|
+
const so = r.body?.order;
|
|
320
|
+
const ours = so?.reference_id === order._id && so?.total_money?.amount === order.amount && so?.total_money?.currency === order.currency;
|
|
321
|
+
const paid = ours && (so.tenders ?? []).length > 0 && so.net_amount_due_money?.amount === 0;
|
|
322
|
+
if (!paid) return ours && so.state === "CANCELED" ? (await move(ctx, order, { status: "canceled", canceledAt: Date.now() })).order : order;
|
|
323
|
+
const { order: next, moved } = await move(ctx, order, { status: "paid", paidAt: Date.now() });
|
|
324
|
+
if (moved) await tellOwner(ctx, next);
|
|
325
|
+
return next;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// One pending order to its settled state, on the revision we read. When another call settled it
|
|
329
|
+
// first, its record stands and this call moved nothing.
|
|
330
|
+
async function move(ctx, order, change) {
|
|
331
|
+
const next = { ...order, ...change };
|
|
332
|
+
try {
|
|
333
|
+
await ctx.db.put(next, { db: DB, id: order._id, ifRev: order._rev });
|
|
334
|
+
return { order: next, moved: true };
|
|
335
|
+
} catch (err) {
|
|
336
|
+
if (err.code !== "conflict" && err.code !== "access-denied") throw err;
|
|
337
|
+
const stored = await ctx.db.get(order._id, { db: DB });
|
|
338
|
+
if (stored && stored.status !== "pending") return { order: stored, moved: false };
|
|
339
|
+
throw err;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export async function fetch(request, ctx) {
|
|
344
|
+
const url = new URL(request.url);
|
|
345
|
+
// An uncaught throw reaches the app as a bare 500 naming only the error class, so every route answers with a reason.
|
|
346
|
+
try {
|
|
347
|
+
// The setup verdict: ready and the currency for everyone, the item (and the handle + slug the
|
|
348
|
+
// Setup screen links with) for the owner alone. Square is asked on the owner's call only; a
|
|
349
|
+
// visitor's read takes the kept record.
|
|
350
|
+
if (url.pathname === "/setup" && request.method === "GET") {
|
|
351
|
+
const owner = ctx.userInfo?.userHandle === ctx.appInfo.ownerHandle;
|
|
352
|
+
const hasKey = Boolean(ctx.secrets.SQUARE_ACCESS_TOKEN);
|
|
353
|
+
let kept = await ctx.db.get(SETUP_ID, { db: DB });
|
|
354
|
+
let problem = hasKey ? null : { reason: "missing-key" };
|
|
355
|
+
if (owner && hasKey) {
|
|
356
|
+
const [merchant, loc] = await Promise.all([square(ctx, "GET", "/v2/merchants/me"), mainLocation(ctx)]);
|
|
357
|
+
if (merchant.ok && loc.ok) {
|
|
358
|
+
kept = { _id: SETUP_ID, type: "setup", business: merchant.body.merchant?.business_name ?? null, location: loc.location, checkedAt: Date.now() };
|
|
359
|
+
await ctx.db.put(kept, { db: DB, id: SETUP_ID });
|
|
360
|
+
} else {
|
|
361
|
+
problem = merchant.ok ? loc : merchant;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const done = hasKey && !problem && Boolean(kept?.location);
|
|
365
|
+
const items = [{ id: "square-token", label: "Your Square access token", done, problem: problem?.message ?? null }];
|
|
366
|
+
const ready = items.every((item) => item.done);
|
|
367
|
+
const currency = kept?.location?.currency ?? "USD";
|
|
368
|
+
if (!owner) return json({ ok: true, ready, owner, currency });
|
|
369
|
+
return json({ ok: true, ready, owner, currency, items, square: done ? { business: kept.business, location: kept.location.name, sandbox: ctx.secrets.SQUARE_ENV === "sandbox" } : null, ownerHandle: ctx.appInfo.ownerHandle, appSlug: ctx.appInfo.appSlug });
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Start a purchase: the order first, priced from the owner's catalog, then a payment link for
|
|
373
|
+
// exactly that order. Anyone pays: a signed-in buyer's order carries their handle, a guest's
|
|
374
|
+
// the key their page keeps. (Members only adds: if (!me) return json({ ok: false, reason: "sign-in" }, 401);)
|
|
375
|
+
if (url.pathname === "/checkout" && request.method === "POST") {
|
|
376
|
+
const me = ctx.userInfo?.userHandle ?? null;
|
|
377
|
+
const { lines: bag, guestKey } = await request.json();
|
|
378
|
+
if (!me && !(typeof guestKey === "string" && /^guest-[\w-]{8,64}$/.test(guestKey))) return json({ ok: false, reason: "bad-request" }, 400);
|
|
379
|
+
const loc = await mainLocation(ctx);
|
|
380
|
+
if (!loc.ok) return json(loc, 503);
|
|
381
|
+
const priced = await priceBag(ctx, bag, loc.location.currency);
|
|
382
|
+
if (!priced) return json({ ok: false, reason: "unknown-item" }, 400);
|
|
383
|
+
const env = squareEnv(ctx);
|
|
384
|
+
|
|
385
|
+
// One attempt per buyer per bag at these prices, in this env and location: a second press reuses
|
|
386
|
+
// the link already made. Every page: the query filters after its limit, so a page can come back
|
|
387
|
+
// short or empty with more behind it.
|
|
388
|
+
const same = (o) =>
|
|
389
|
+
(me ? o.buyerHandle === me : o.guestKey === guestKey) &&
|
|
390
|
+
o.bagKey === priced.key &&
|
|
391
|
+
o.currency === loc.location.currency &&
|
|
392
|
+
o.env === env &&
|
|
393
|
+
o.locationId === loc.location.id &&
|
|
394
|
+
o.linkUrl &&
|
|
395
|
+
Date.now() - o.createdAt < LINK_TTL_MS;
|
|
396
|
+
let attempt;
|
|
397
|
+
let after;
|
|
398
|
+
do {
|
|
399
|
+
const page = await ctx.db.query({ db: DB, field: "status", key: "pending", limit: 100, after });
|
|
400
|
+
attempt = page.find(same);
|
|
401
|
+
after = page.next;
|
|
402
|
+
} while (!attempt && after);
|
|
403
|
+
if (attempt) return json({ ok: true, orderId: attempt._id, url: attempt.linkUrl });
|
|
404
|
+
|
|
405
|
+
const id = "order-" + crypto.randomUUID().replaceAll("-", ""); // Square caps reference_id at 40 characters; this is 38
|
|
406
|
+
const order = {
|
|
407
|
+
_id: id,
|
|
408
|
+
type: "order",
|
|
409
|
+
lines: priced.lines,
|
|
410
|
+
bagKey: priced.key,
|
|
411
|
+
title: priced.lines.length === 1 ? priced.lines[0].title : `${priced.lines[0].title} and ${priced.lines.length - 1} more`,
|
|
412
|
+
amount: priced.amount,
|
|
413
|
+
currency: loc.location.currency,
|
|
414
|
+
env,
|
|
415
|
+
locationId: loc.location.id,
|
|
416
|
+
buyerHandle: me, // null for a guest; Square's page collects their email and sends the receipt
|
|
417
|
+
...(me ? {} : { guestKey }),
|
|
418
|
+
status: "pending",
|
|
419
|
+
createdAt: Date.now(),
|
|
420
|
+
};
|
|
421
|
+
await ctx.db.put(order, { db: DB, id });
|
|
422
|
+
|
|
423
|
+
const r = await square(ctx, "POST", "/v2/online-checkout/payment-links", {
|
|
424
|
+
idempotency_key: id,
|
|
425
|
+
order: {
|
|
426
|
+
location_id: loc.location.id,
|
|
427
|
+
reference_id: id,
|
|
428
|
+
line_items: order.lines.map((l) => ({ name: l.title, quantity: String(l.qty), base_price_money: { amount: l.unitAmount, currency: order.currency } })),
|
|
429
|
+
},
|
|
430
|
+
checkout_options: { redirect_url: appUrl(ctx, `#paid=${id}`) },
|
|
431
|
+
});
|
|
432
|
+
if (!r.ok) {
|
|
433
|
+
await ctx.db.put({ ...order, status: "failed", problem: r.message }, { db: DB, id });
|
|
434
|
+
return json(r, 502);
|
|
435
|
+
}
|
|
436
|
+
const link = r.body.payment_link;
|
|
437
|
+
await ctx.db.put({ ...order, squareOrderId: link.order_id, linkUrl: link.url }, { db: DB, id });
|
|
438
|
+
return json({ ok: true, orderId: id, url: link.url });
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// The buyer is back: read the order from Square. A signed-in buyer's order answers to them alone;
|
|
442
|
+
// a guest's answers its status to the order id their return page holds.
|
|
443
|
+
if (url.pathname === "/confirm" && request.method === "POST") {
|
|
444
|
+
const me = ctx.userInfo?.userHandle ?? null;
|
|
445
|
+
const { orderId } = await request.json();
|
|
446
|
+
const order = typeof orderId === "string" && orderId.startsWith("order-") ? await ctx.db.get(orderId, { db: DB }) : null;
|
|
447
|
+
if (order?.type !== "order" || (order.buyerHandle && order.buyerHandle !== me)) return json({ ok: false, reason: "not-found" }, 404);
|
|
448
|
+
const settled = await settle(ctx, order);
|
|
449
|
+
return json({ ok: true, status: settled.status });
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return json({ ok: false, reason: "not-found" }, 404);
|
|
453
|
+
} catch (err) {
|
|
454
|
+
ctx.log("error", "square route failed", { path: url.pathname, message: String(err?.message ?? err) });
|
|
455
|
+
return json({ ok: false, reason: "handler-failed", message: "Something went wrong reaching Square." }, 500);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// The sweep: a buyer who paid and closed Square's tab is still marked paid within minutes.
|
|
460
|
+
export async function scheduled(event, ctx) {
|
|
461
|
+
let after;
|
|
462
|
+
let paid = 0;
|
|
463
|
+
do {
|
|
464
|
+
const page = await ctx.db.query({ db: DB, field: "status", key: "pending", limit: 100, after });
|
|
465
|
+
for (const order of page) {
|
|
466
|
+
const next = await settle(ctx, order);
|
|
467
|
+
if (next.status === "paid") paid += 1;
|
|
468
|
+
}
|
|
469
|
+
after = page.next;
|
|
470
|
+
} while (after);
|
|
471
|
+
ctx.log("info", "square sweep", { paid, at: event.scheduledTime });
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
## access.js — only the backend writes an order
|
|
476
|
+
|
|
477
|
+
### `access.js`
|
|
478
|
+
```js app=square-shop
|
|
479
|
+
export function orders(doc, oldDoc, user, ctx) {
|
|
480
|
+
if (oldDoc && oldDoc.type !== doc.type) throw { forbidden: "a record keeps its type" };
|
|
481
|
+
// The catalog: the owner lists each product and sets its price from the app's own screen, and
|
|
482
|
+
// anyone reads it. backend.js charges the price on this record, so the owner alone writes one.
|
|
483
|
+
if (doc.type === "product") {
|
|
484
|
+
ctx.requireRole("owner");
|
|
485
|
+
const named = doc._id?.startsWith("product-") && typeof doc.title === "string" && doc.title.trim() !== "";
|
|
486
|
+
const priced = typeof doc.currency === "string" && Number.isInteger(doc.amount) && doc.amount > 0;
|
|
487
|
+
if (!named || !priced || typeof doc.onSale !== "boolean") {
|
|
488
|
+
throw { forbidden: "a product has a name, a currency and a whole price in its smallest unit" };
|
|
489
|
+
}
|
|
490
|
+
return { channels: ["catalog"], grant: { public: ["catalog"] } };
|
|
491
|
+
}
|
|
492
|
+
// The kept Square answer (business, location, currency): written by backend.js on the owner's /setup call.
|
|
493
|
+
if (doc.type === "setup") {
|
|
494
|
+
ctx.requireBackend("fetch");
|
|
495
|
+
return { channels: ["orders"], grant: { roles: { owner: ["orders"] } } };
|
|
496
|
+
}
|
|
497
|
+
if (doc.type !== "order") throw { forbidden: "unknown document type" };
|
|
498
|
+
// Orders come only from backend.js, guests included, and an order keeps its buyer and its price.
|
|
499
|
+
ctx.requireBackend();
|
|
500
|
+
if (oldDoc && (doc.buyerHandle !== oldDoc.buyerHandle || doc.amount !== oldDoc.amount || doc.currency !== oldDoc.currency)) {
|
|
501
|
+
throw { forbidden: "an order keeps its buyer and its price" };
|
|
502
|
+
}
|
|
503
|
+
// allowAnonymous: backend.js writes a guest's order while serving a buyer who has no account.
|
|
504
|
+
if (!doc.buyerHandle) return { channels: ["orders"], grant: { roles: { owner: ["orders"] } }, allowAnonymous: true };
|
|
505
|
+
const mine = `user:${doc.buyerHandle}`;
|
|
506
|
+
return { channels: [mine, "orders"], grant: { users: { [doc.buyerHandle]: [mine] }, roles: { owner: ["orders"] } }, allowAnonymous: true };
|
|
507
|
+
}
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
## App.jsx sketch
|
|
511
|
+
|
|
512
|
+
### `App.jsx`
|
|
513
|
+
```jsx app=square-shop
|
|
514
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
515
|
+
import { useFireproof } from "use-fireproof";
|
|
516
|
+
import { apiFetch, useVibe } from "use-vibes";
|
|
517
|
+
import { Badge, Button, Field, Heading, Input, Row, Stack, Text } from "@vibes.diy/ui";
|
|
518
|
+
|
|
519
|
+
// Amounts are in the currency's smallest unit, the one Square charges in: cents for USD, whole yen
|
|
520
|
+
// for JPY. Show and read them through that unit, never a fixed 100.
|
|
521
|
+
const digits = (currency) => new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits;
|
|
522
|
+
const money = (amount, currency) => new Intl.NumberFormat(undefined, { style: "currency", currency }).format(amount / 10 ** digits(currency));
|
|
523
|
+
const toMinor = (text, currency) => Math.round(Number(text) * 10 ** digits(currency));
|
|
524
|
+
|
|
525
|
+
// The setup verdict, read on mount and again whenever the app comes back into view: the owner saves
|
|
526
|
+
// the token in another tab and returns, and Pay unlocks without a reload.
|
|
527
|
+
function useSetup() {
|
|
528
|
+
const [setup, setSetup] = useState(null); // { ready, owner, currency, items?, square?, ownerHandle?, appSlug? }
|
|
529
|
+
const latest = useRef(0);
|
|
530
|
+
useEffect(() => {
|
|
531
|
+
// Mount, focus and visibility reads overlap; only the latest one may land, or a slow stale
|
|
532
|
+
// answer overwrites a fresh one.
|
|
533
|
+
const load = () => {
|
|
534
|
+
const n = ++latest.current;
|
|
535
|
+
apiFetch("/setup").then((r) => r.json()).catch(() => ({ ready: false, owner: false })).then((s) => { if (n === latest.current) setSetup(s); });
|
|
536
|
+
};
|
|
537
|
+
load();
|
|
538
|
+
const onVisible = () => { if (document.visibilityState === "visible") load(); };
|
|
539
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
540
|
+
window.addEventListener("focus", load);
|
|
541
|
+
return () => { document.removeEventListener("visibilitychange", onVisible); window.removeEventListener("focus", load); };
|
|
542
|
+
}, []);
|
|
543
|
+
return setup;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// The item's steps: each one a link to the exact page, in that page's own words, with this vibe's
|
|
547
|
+
// real handle and slug filled in.
|
|
548
|
+
function setupSteps(vibe) {
|
|
549
|
+
return [
|
|
550
|
+
{ href: "https://developer.squareup.com/apps", link: "Square Developer Console", text: ": sign in with the Square account you sell with, press + to create an application, and give it any name." },
|
|
551
|
+
{ href: "https://developer.squareup.com/apps", link: "your application's Credentials", text: ": switch the toggle at the top to Production, press Show beside Production Access token, and copy it." },
|
|
552
|
+
{ href: `https://vibes.diy/vibes/mine/${vibe}/settings`, link: "this vibe's Settings tab", text: `: under Secrets, enter SQUARE_ACCESS_TOKEN, paste the token, and save. Or run npx vibes-diy secrets set SQUARE_ACCESS_TOKEN --vibe ${vibe}.` },
|
|
553
|
+
];
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// The Setup surface, the owner's alone.
|
|
557
|
+
function SetupScreen({ setup }) {
|
|
558
|
+
const item = setup.items.find((i) => i.id === "square-token");
|
|
559
|
+
return (
|
|
560
|
+
<Stack>
|
|
561
|
+
<Heading>Setup</Heading>
|
|
562
|
+
<Row gap={2}>
|
|
563
|
+
<Text>{item.label}</Text>
|
|
564
|
+
<Badge tone={item.done ? "up" : "info"}>{item.done ? "Done" : "To do"}</Badge>
|
|
565
|
+
</Row>
|
|
566
|
+
{setup.square && (
|
|
567
|
+
<Text>
|
|
568
|
+
Selling through {setup.square.business} · {setup.square.location} · {setup.currency}
|
|
569
|
+
{setup.square.sandbox ? " (Square sandbox)" : ""}
|
|
570
|
+
</Text>
|
|
571
|
+
)}
|
|
572
|
+
{item.problem && <Text>Square said: {item.problem}</Text>}
|
|
573
|
+
<ol>
|
|
574
|
+
{setupSteps(`${setup.ownerHandle}/${setup.appSlug}`).map((step) => (
|
|
575
|
+
<li key={step.link}>
|
|
576
|
+
Open <a href={step.href} target="_blank" rel="noreferrer">{step.link}</a>
|
|
577
|
+
{step.text}
|
|
578
|
+
</li>
|
|
579
|
+
))}
|
|
580
|
+
</ol>
|
|
581
|
+
<Text muted>
|
|
582
|
+
The token stays on the server. Your first sale is real money: buy your cheapest item once and refund it from your Square Dashboard to see the whole trip.
|
|
583
|
+
</Text>
|
|
584
|
+
</Stack>
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// The owner's price list. Each save is a `product` record that access.js takes from the owner alone,
|
|
589
|
+
// and the price on it is the price /checkout charges.
|
|
590
|
+
function Products({ products, currency }) {
|
|
591
|
+
const { database } = useFireproof("orders");
|
|
592
|
+
const [title, setTitle] = useState("");
|
|
593
|
+
const [price, setPrice] = useState("");
|
|
594
|
+
const [error, setError] = useState(null);
|
|
595
|
+
// A put lands on this device at once; the server's verdict arrives on its receipt. A refused save
|
|
596
|
+
// converges back to what the server holds, and the owner gets their draft and the reason back.
|
|
597
|
+
const save = async (product, undo) => {
|
|
598
|
+
setError(null);
|
|
599
|
+
const { synced } = await database.put(product);
|
|
600
|
+
synced.on((s) => {
|
|
601
|
+
if (s.status !== "refused") return;
|
|
602
|
+
undo?.();
|
|
603
|
+
setError(s.message ?? "That did not save: a product needs a name and a price like 12.50.");
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
const add = () => {
|
|
607
|
+
const amount = toMinor(price, currency);
|
|
608
|
+
if (!title.trim() || !Number.isInteger(amount) || amount <= 0) return setError("Give it a name and a price like 12.50.");
|
|
609
|
+
const product = { _id: "product-" + crypto.randomUUID(), type: "product", title: title.trim(), amount, currency, onSale: true, createdAt: Date.now() };
|
|
610
|
+
// The form empties as the owner presses Add; the draft comes back only if the write is refused.
|
|
611
|
+
const draft = price;
|
|
612
|
+
setTitle("");
|
|
613
|
+
setPrice("");
|
|
614
|
+
save(product, () => { setTitle(product.title); setPrice(draft); });
|
|
615
|
+
};
|
|
616
|
+
return (
|
|
617
|
+
<Stack>
|
|
618
|
+
<Heading>{products.length === 0 ? "Add the first thing you sell" : "Products"}</Heading>
|
|
619
|
+
<Row gap={2}>
|
|
620
|
+
<Field label="Name">{(id, describedBy) => <Input id={id} describedBy={describedBy} value={title} onChange={setTitle} placeholder="Box of six croissants" />}</Field>
|
|
621
|
+
<Field label="Price">{(id, describedBy) => <Input id={id} describedBy={describedBy} value={price} onChange={setPrice} placeholder="18.00" inputMode="decimal" />}</Field>
|
|
622
|
+
<Button onClick={add}>Add</Button>
|
|
623
|
+
</Row>
|
|
624
|
+
{error && <Text>{error}</Text>}
|
|
625
|
+
{products.map((p) => (
|
|
626
|
+
<Row key={p._id} gap={2}>
|
|
627
|
+
<Text>{p.title} · {money(p.amount, currency)}</Text>
|
|
628
|
+
<Button variant="quiet" onClick={() => save({ ...p, onSale: !p.onSale })}>{p.onSale ? "Take off sale" : "Put on sale"}</Button>
|
|
629
|
+
</Row>
|
|
630
|
+
))}
|
|
631
|
+
</Stack>
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
export default function App() {
|
|
636
|
+
const { me } = useVibe("orders");
|
|
637
|
+
const { useLiveQuery } = useFireproof("orders");
|
|
638
|
+
const { docs: orders } = useLiveQuery("type", { key: "order" });
|
|
639
|
+
const { docs: products } = useLiveQuery("type", { key: "product" });
|
|
640
|
+
const setup = useSetup();
|
|
641
|
+
const [picked, setPicked] = useState(null);
|
|
642
|
+
const [error, setError] = useState(null);
|
|
643
|
+
const [busy, setBusy] = useState(false);
|
|
644
|
+
const [back, setBack] = useState(null); // the order the buyer just came back from
|
|
645
|
+
const [guestKey] = useState(() => {
|
|
646
|
+
try {
|
|
647
|
+
const kept = localStorage.getItem("guestKey") ?? "guest-" + crypto.randomUUID();
|
|
648
|
+
localStorage.setItem("guestKey", kept);
|
|
649
|
+
return kept;
|
|
650
|
+
} catch {
|
|
651
|
+
return "guest-" + crypto.randomUUID();
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
// Back from Square: the address names the order. Read the hash now AND on every change, since the
|
|
656
|
+
// wrapper can hand it over just after the first render, and keep the order id once the hash is cleared.
|
|
657
|
+
useEffect(() => {
|
|
658
|
+
const arrive = () => {
|
|
659
|
+
const orderId = new URLSearchParams(location.hash.slice(1)).get("paid");
|
|
660
|
+
if (!orderId) return;
|
|
661
|
+
history.replaceState(null, "", location.pathname);
|
|
662
|
+
setBack({ orderId, status: "checking" });
|
|
663
|
+
};
|
|
664
|
+
arrive();
|
|
665
|
+
window.addEventListener("hashchange", arrive);
|
|
666
|
+
return () => window.removeEventListener("hashchange", arrive);
|
|
667
|
+
}, []);
|
|
668
|
+
|
|
669
|
+
// /confirm reads Square's copy of the order. A guest's live query never holds the order (only the
|
|
670
|
+
// owner reads orders), so while it is pending the page asks again on a short backoff and whenever it
|
|
671
|
+
// comes back into view, and stops once it reads paid.
|
|
672
|
+
const backId = back?.orderId;
|
|
673
|
+
useEffect(() => {
|
|
674
|
+
if (!backId) return;
|
|
675
|
+
let done = false;
|
|
676
|
+
let timer;
|
|
677
|
+
let asking = false; // one ask at a time, so a focus during a slow answer starts no second chain
|
|
678
|
+
let delay = 3000;
|
|
679
|
+
const ask = () => {
|
|
680
|
+
if (asking) return;
|
|
681
|
+
asking = true;
|
|
682
|
+
clearTimeout(timer);
|
|
683
|
+
apiFetch("/confirm", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ orderId: backId }) })
|
|
684
|
+
.then((r) => r.json())
|
|
685
|
+
.catch(() => ({}))
|
|
686
|
+
.then((d) => {
|
|
687
|
+
asking = false;
|
|
688
|
+
if (done) return;
|
|
689
|
+
const status = d.status ?? "pending";
|
|
690
|
+
setBack({ orderId: backId, status });
|
|
691
|
+
if (status !== "pending") return (done = true);
|
|
692
|
+
timer = setTimeout(ask, delay);
|
|
693
|
+
delay = Math.min(delay * 2, 60000);
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
const onVisible = () => { if (!done && document.visibilityState === "visible") ask(); };
|
|
697
|
+
ask();
|
|
698
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
699
|
+
window.addEventListener("focus", onVisible);
|
|
700
|
+
return () => {
|
|
701
|
+
done = true;
|
|
702
|
+
clearTimeout(timer);
|
|
703
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
704
|
+
window.removeEventListener("focus", onVisible);
|
|
705
|
+
};
|
|
706
|
+
}, [backId]);
|
|
707
|
+
|
|
708
|
+
// `lines` is a bag: [{ productId, qty }]. The page names products and quantities, never a price.
|
|
709
|
+
const pay = async (lines) => {
|
|
710
|
+
setError(null);
|
|
711
|
+
const tab = window.open("", "_blank"); // opened inside the click, before any await, so it is not a popup
|
|
712
|
+
if (!tab) return setError("Your browser blocked the Square tab. Allow pop-ups for this page and press Pay again.");
|
|
713
|
+
setBusy(true);
|
|
714
|
+
try {
|
|
715
|
+
const res = await apiFetch("/checkout", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ lines, guestKey }) });
|
|
716
|
+
const data = await res.json();
|
|
717
|
+
if (!data.ok) {
|
|
718
|
+
tab.close();
|
|
719
|
+
setError(data.reason === "unknown-item" ? "Something in your order is no longer for sale. Refresh and try again." : data.message ?? "Checkout is not open yet.");
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
tab.location.href = data.url;
|
|
723
|
+
} finally {
|
|
724
|
+
setBusy(false);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
const ready = setup?.ready === true;
|
|
729
|
+
const currency = setup?.currency ?? "USD";
|
|
730
|
+
const forSale = products.filter((p) => p.onSale);
|
|
731
|
+
const screen = picked ?? (setup?.owner && products.length === 0 ? "products" : "shop");
|
|
732
|
+
const backStatus = back && (orders.find((o) => o._id === back.orderId)?.status ?? back.status);
|
|
733
|
+
return (
|
|
734
|
+
<Stack>
|
|
735
|
+
<Row gap={2}>
|
|
736
|
+
<Button variant="quiet" onClick={() => setPicked("shop")}>Shop</Button>
|
|
737
|
+
{setup?.owner && <Button variant="quiet" onClick={() => setPicked("products")}>Products</Button>}
|
|
738
|
+
{setup?.owner && <Button variant="quiet" onClick={() => setPicked("orders")}>Orders</Button>}
|
|
739
|
+
{setup?.owner && (
|
|
740
|
+
<Button variant={ready ? "quiet" : "solid"} onClick={() => setPicked("setup")}>
|
|
741
|
+
Setup{ready ? "" : " · to do"}
|
|
742
|
+
</Button>
|
|
743
|
+
)}
|
|
744
|
+
</Row>
|
|
745
|
+
{screen === "setup" && setup?.owner ? (
|
|
746
|
+
<SetupScreen setup={setup} />
|
|
747
|
+
) : screen === "products" && setup?.owner ? (
|
|
748
|
+
<Products products={products} currency={currency} />
|
|
749
|
+
) : screen === "orders" && setup?.owner ? (
|
|
750
|
+
<Stack>
|
|
751
|
+
<Heading>Orders</Heading>
|
|
752
|
+
{orders.length === 0 ? (
|
|
753
|
+
<Text muted>No orders yet. Each one shows here the moment someone pays.</Text>
|
|
754
|
+
) : (
|
|
755
|
+
<ul>
|
|
756
|
+
{orders.map((o) => (
|
|
757
|
+
<li key={o._id}>
|
|
758
|
+
{o.buyerHandle ? `@${o.buyerHandle}` : "Guest"} · {o.title} · {money(o.amount, o.currency)} · {o.status}
|
|
759
|
+
{o.status === "paid" ? " · Also in your Square Dashboard" : ""}
|
|
760
|
+
</li>
|
|
761
|
+
))}
|
|
762
|
+
</ul>
|
|
763
|
+
)}
|
|
764
|
+
</Stack>
|
|
765
|
+
) : (
|
|
766
|
+
<Stack>
|
|
767
|
+
<Heading>Preorder</Heading>
|
|
768
|
+
{back && <Text>{backStatus === "paid" ? "Paid. Thank you!" : backStatus === "checking" ? "Asking Square about your payment…" : "Your payment is still confirming. It shows here as paid in a moment."}</Text>}
|
|
769
|
+
{forSale.length === 0 ? (
|
|
770
|
+
<Text muted>{setup?.owner ? "Nothing is for sale yet. Add what you sell under Products." : "Nothing for sale yet."}</Text>
|
|
771
|
+
) : ready ? (
|
|
772
|
+
forSale.map((p) => (
|
|
773
|
+
<Row key={p._id} gap={2}>
|
|
774
|
+
<Text>{p.title}</Text>
|
|
775
|
+
<Button onClick={() => pay([{ productId: p._id, qty: 1 }])} disabled={busy} loading={busy}>
|
|
776
|
+
Pay {money(p.amount, currency)} — Square opens in a new tab
|
|
777
|
+
</Button>
|
|
778
|
+
</Row>
|
|
779
|
+
))
|
|
780
|
+
) : (
|
|
781
|
+
<Text muted>Checkout is not open yet.</Text>
|
|
782
|
+
)}
|
|
783
|
+
{error && <Text>{error}</Text>}
|
|
784
|
+
</Stack>
|
|
785
|
+
)}
|
|
786
|
+
</Stack>
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
A shop with a bag keeps this backend: its Pay sends every line of the bag to
|
|
792
|
+
`/checkout` in one call, and the payment link carries one Square line item per
|
|
793
|
+
bag line, so the buyer's receipt lists what they bought. The `ui-storefront`
|
|
794
|
+
block's page swaps its **Place order** for this `pay`.
|
package/llms/stripe.js
CHANGED
|
@@ -58,8 +58,27 @@ export const stripeConfig = {
|
|
|
58
58
|
"card payment",
|
|
59
59
|
"card payments",
|
|
60
60
|
"take payments",
|
|
61
|
+
"takes payments",
|
|
61
62
|
"accept payments",
|
|
63
|
+
"accepts payments",
|
|
64
|
+
],
|
|
65
|
+
routeBlockers: [
|
|
66
|
+
"subscribe",
|
|
67
|
+
"subscription",
|
|
68
|
+
"subscriptions",
|
|
69
|
+
"a month",
|
|
70
|
+
"per month",
|
|
71
|
+
"monthly",
|
|
72
|
+
"through square",
|
|
73
|
+
"via square",
|
|
74
|
+
"square account",
|
|
75
|
+
"pay with square",
|
|
76
|
+
"square checkout",
|
|
77
|
+
"square payment",
|
|
78
|
+
"square payments",
|
|
79
|
+
"square payment link",
|
|
80
|
+
"sell on square",
|
|
81
|
+
"square pos",
|
|
62
82
|
],
|
|
63
|
-
routeBlockers: ["subscribe", "subscription", "subscriptions", "a month", "per month", "monthly"],
|
|
64
83
|
};
|
|
65
84
|
//# sourceMappingURL=stripe.js.map
|
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,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;
|
|
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,gBAAgB;QAChB,iBAAiB;QACjB,kBAAkB;KACnB;IAOD,aAAa,EAAE;QACb,WAAW;QACX,cAAc;QACd,eAAe;QACf,SAAS;QACT,WAAW;QACX,SAAS;QACT,gBAAgB;QAChB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,iBAAiB;QACjB,gBAAgB;QAChB,iBAAiB;QACjB,qBAAqB;QACrB,gBAAgB;QAChB,YAAY;KACb;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibes.diy/prompts",
|
|
3
|
-
"version": "14.3.
|
|
3
|
+
"version": "14.3.301",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"exports": {
|
|
@@ -39,10 +39,10 @@
|
|
|
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.
|
|
42
|
+
"@vibes.diy/api-types": "14.3.301",
|
|
43
|
+
"@vibes.diy/call-ai-v2": "14.3.301",
|
|
44
|
+
"@vibes.diy/identity": "14.3.301",
|
|
45
|
+
"@vibes.diy/use-vibes-types": "14.3.301",
|
|
46
46
|
"arktype": "~2.2.9",
|
|
47
47
|
"json-schema-faker": "~0.6.3"
|
|
48
48
|
},
|