@proveanything/smartlinks 2.1.40 → 2.1.41

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.
Files changed (104) hide show
  1. package/README.md +754 -754
  2. package/dist/README.md +573 -573
  3. package/dist/adminCardsView.js +55 -55
  4. package/dist/api/collection.d.ts +8 -1
  5. package/dist/api/collection.js +10 -0
  6. package/dist/baseline.css +194 -194
  7. package/dist/docs/API_SUMMARY.md +863 -835
  8. package/dist/docs/admin-cards.md +189 -189
  9. package/dist/docs/agent-tools.md +156 -156
  10. package/dist/docs/ai-tools-and-skills.md +180 -180
  11. package/dist/docs/ai.md +1721 -1721
  12. package/dist/docs/analytics.md +39 -39
  13. package/dist/docs/app-data-storage.md +277 -277
  14. package/dist/docs/app-docs.md +73 -73
  15. package/dist/docs/app-manifest.md +852 -852
  16. package/dist/docs/app-records-pattern.md +388 -388
  17. package/dist/docs/appConfig.md +550 -550
  18. package/dist/docs/assistant-apps.md +172 -172
  19. package/dist/docs/assistant-context.md +119 -119
  20. package/dist/docs/bookings.md +442 -442
  21. package/dist/docs/comms.md +686 -686
  22. package/dist/docs/connectors.md +340 -340
  23. package/dist/docs/css-baseline.md +133 -133
  24. package/dist/docs/customer-guide.md +70 -70
  25. package/dist/docs/deploying-apps.md +340 -340
  26. package/dist/docs/entitlements.md +90 -90
  27. package/dist/docs/files.md +69 -69
  28. package/dist/docs/host-dependency-contract.md +210 -210
  29. package/dist/docs/integrations.md +322 -322
  30. package/dist/docs/interactions.md +545 -545
  31. package/dist/docs/item-context.md +181 -181
  32. package/dist/docs/knowledge.md +102 -102
  33. package/dist/docs/lots.md +111 -111
  34. package/dist/docs/loyalty.md +352 -352
  35. package/dist/docs/members.md +182 -182
  36. package/dist/docs/mobile-admin-container.md +693 -693
  37. package/dist/docs/operations.md +281 -281
  38. package/dist/docs/overview.md +482 -482
  39. package/dist/docs/proof-comms-triggers.md +142 -142
  40. package/dist/docs/proof-ownership-transfer.md +155 -155
  41. package/dist/docs/proof-product-data-scoping.md +462 -462
  42. package/dist/docs/proof-share-grants.md +305 -305
  43. package/dist/docs/realtime.md +138 -138
  44. package/dist/docs/records-admin-pattern.md +304 -304
  45. package/dist/docs/standard-query.md +187 -187
  46. package/dist/docs/tag-codes.md +97 -97
  47. package/dist/docs/theme-tokens.md +252 -252
  48. package/dist/docs/wallet-passes.md +107 -107
  49. package/dist/docs/websites.md +123 -123
  50. package/dist/openapi.yaml +80 -3
  51. package/dist/theme-boot.js +78 -78
  52. package/dist/theme.css +75 -75
  53. package/dist/types/appManifest.d.ts +21 -0
  54. package/dist/types/collection.d.ts +26 -0
  55. package/docs/API_SUMMARY.md +863 -835
  56. package/docs/admin-cards.md +189 -189
  57. package/docs/agent-tools.md +156 -156
  58. package/docs/ai-tools-and-skills.md +180 -180
  59. package/docs/ai.md +1721 -1721
  60. package/docs/analytics.md +39 -39
  61. package/docs/app-data-storage.md +277 -277
  62. package/docs/app-docs.md +73 -73
  63. package/docs/app-manifest.md +852 -852
  64. package/docs/app-records-pattern.md +388 -388
  65. package/docs/appConfig.md +550 -550
  66. package/docs/assistant-apps.md +172 -172
  67. package/docs/assistant-context.md +119 -119
  68. package/docs/bookings.md +442 -442
  69. package/docs/comms.md +686 -686
  70. package/docs/connectors.md +340 -340
  71. package/docs/css-baseline.md +133 -133
  72. package/docs/customer-guide.md +70 -70
  73. package/docs/deploying-apps.md +340 -340
  74. package/docs/entitlements.md +90 -90
  75. package/docs/files.md +69 -69
  76. package/docs/host-dependency-contract.md +210 -210
  77. package/docs/integrations.md +322 -322
  78. package/docs/interactions.md +545 -545
  79. package/docs/item-context.md +181 -181
  80. package/docs/knowledge.md +102 -102
  81. package/docs/lots.md +111 -111
  82. package/docs/loyalty.md +352 -352
  83. package/docs/members.md +182 -182
  84. package/docs/mobile-admin-container.md +693 -693
  85. package/docs/operations.md +281 -281
  86. package/docs/overview.md +482 -482
  87. package/docs/proof-comms-triggers.md +142 -142
  88. package/docs/proof-ownership-transfer.md +155 -155
  89. package/docs/proof-product-data-scoping.md +462 -462
  90. package/docs/proof-share-grants.md +305 -305
  91. package/docs/realtime.md +138 -138
  92. package/docs/standard-query.md +187 -187
  93. package/docs/tag-codes.md +97 -97
  94. package/docs/theme-lookbook.v1.json +120 -120
  95. package/docs/theme-tokens.md +252 -252
  96. package/docs/wallet-passes.md +107 -107
  97. package/docs/websites.md +123 -123
  98. package/openapi.yaml +80 -3
  99. package/package.json +87 -87
  100. package/scripts/headless-check.mjs +87 -87
  101. package/scripts/lib/bare-imports.mjs +57 -57
  102. package/scripts/lib/keyed-app-data.mjs +21 -21
  103. package/scripts/publish.mjs +272 -272
  104. package/scripts/register-release.mjs +91 -91
@@ -1,107 +1,107 @@
1
- # Wallet passes
2
-
3
- Put an **event ticket**, a **booking**, a **membership card** or a **loyalty card** in the person's Apple Wallet or
4
- Google Wallet. SmartLinks is the issuer and signs the passes. Each pass is branded from your site's name, logo and
5
- colour, and your app decides what it says.
6
-
7
- - **Who gets one:** only someone the business knows. A pass is issued to the signed-in owner of what it's for, or
8
- by your app's own server function.
9
- - **What the phone does:** the pass shows its QR code offline, appears near the time (and place, if you give
10
- `venue.lat` / `lng`), and updates when you change it.
11
- - **Bookings look after themselves:** when a booking is moved its pass shows the new time, and when it's cancelled
12
- the pass is voided.
13
-
14
- ## In a page: "Add to Wallet"
15
-
16
- ```typescript
17
- import { wallet } from '@proveanything/smartlinks'
18
-
19
- // The signed-in person's booking, membership card, or a pass your app issued them
20
- const { pass } = await wallet.addLinks(collectionId, { type: 'booking', id: booking.id })
21
- // pass.links.apple → opens the .pkpass on an iPhone
22
- // pass.links.google → opens Google's "Save to Google Wallet" page
23
- ```
24
-
25
- - `{ type: 'booking', id }` and `{ type: 'contact', id: 'me' }` are made on first ask:
26
- - a booking pass, from the booking's date and time
27
- - a membership card, from the person's `level` and `memberUntil` fields
28
- - For anything else (an event ticket with your own title, a loyalty card with points), issue the pass in your server
29
- function first. `addLinks` then returns that pass for its owner.
30
- - Show the official "Add to Apple Wallet" and "Add to Google Wallet" badges, and only the one that suits the
31
- device. A wallet that isn't set up yet is left out of `links`.
32
- - `wallet.mine(collectionId)` lists the person's passes.
33
-
34
- ## In a server function: issue, change, void, message
35
-
36
- Declare `sl:wallet:write` in the function's capabilities.
37
-
38
- ```typescript
39
- // An event ticket
40
- const pass = await ctx.sl.wallet.issue({
41
- ref: { type: 'booking', id: booking.id }, // what it's for; issuing again changes the same pass
42
- pass: {
43
- kind: 'event',
44
- title: 'Jazz on the Terrace',
45
- start: '2026-12-24T19:00:00Z', end: '2026-12-24T22:00:00Z', timezone: 'Europe/London',
46
- venue: { name: 'The Terrace', address: '1 High St, Bath', lat: 51.38, lng: -2.36 },
47
- holder: 'Sam Lee', number: 'T-0042',
48
- fields: [{ label: 'Seat', value: 'Table 6' }],
49
- },
50
- })
51
- return { links: pass.links } // hand these to the page
52
-
53
- // A loyalty card, kept up to date
54
- await ctx.sl.wallet.issue({ ref: { type: 'loyalty', id: accountId }, pass: { kind: 'loyalty', title: 'Bloom Rewards', points: 120, holder: 'Sam' } })
55
- await ctx.sl.wallet.update(passId, { points: 145 })
56
-
57
- await ctx.sl.wallet.void(passId, 'refunded')
58
- await ctx.sl.wallet.message(passId, { header: 'Doors open', body: 'Doors open at 7pm. See you soon!' })
59
- // Everyone holding a ticket for this event
60
- await ctx.sl.wallet.messageAll({ type: 'event', id: eventId }, { header: 'Running late', body: 'We start at 7:30 tonight.' })
61
- ```
62
-
63
- - **Contact:** `contactId` defaults to the caller's contact.
64
- - **Reading:** `ctx.sl.wallet.get(passId)`, `forRef(ref)`, `byCode(code)` and `mine()` need only `sl:wallet:read`.
65
- - **Messages:** you can also send a message to wallet with `ctx.sl.messages` and `channel: 'wallet'`. It goes to the
66
- person's passes about the message's `about`, otherwise to your app's own passes for them. It's worded from the
67
- template's push version.
68
-
69
- ## Knowing who added it
70
-
71
- Every pass belongs to a known person, so you can tell who has actually put it in their wallet:
72
-
73
- - **Apple:** the phone registers the pass with SmartLinks when it's added, and unregisters it when it's removed.
74
- - **Google:** Google sends a signed "saved" or "deleted" notice.
75
-
76
- The pass's `inWallet` shows `{ apple: { saved, savedAt }, google: { saved, savedAt } }`. Each change raises an
77
- event for the pass holder, so a flow in your app's blueprint can react, for example by sending a "see you there"
78
- email when someone adds their ticket:
79
-
80
- | Event | When |
81
- |---|---|
82
- | `wallet.pass_added` | the person added the pass to Apple or Google Wallet |
83
- | `wallet.pass_removed` | they removed it |
84
-
85
- Google's notices are best-effort, so treat them as a good signal rather than a guarantee.
86
-
87
- ## Checking a pass at the door
88
-
89
- The QR holds the pass's own code, never an id. Scan it, then:
90
-
91
- ```typescript
92
- const { pass, valid } = await wallet.byCode(collectionId, scanned) // admin
93
- // or in a function: await ctx.sl.wallet.byCode(scanned)
94
- ```
95
-
96
- ## What a pass can show
97
-
98
- | Field | Use |
99
- |---|---|
100
- | `kind` | `event`, `booking`, `membership` or `loyalty` |
101
- | `title` / `subtitle` | the main line and a second line |
102
- | `start` / `end` / `timezone` | when; the pass surfaces near `start` |
103
- | `venue` | `name`, `address`, and `lat` / `lng` for the lock screen nearby |
104
- | `holder`, `number`, `level`, `points`, `validUntil` | the person, a reference or member number, a level, a balance, an end date |
105
- | `fields` (up to 4), `back` | extra lines on the front and the back |
106
- | `image`, `url` | https only: a picture, a link back to your site |
107
- | `barcode` | your own QR value, instead of the pass's code |
1
+ # Wallet passes
2
+
3
+ Put an **event ticket**, a **booking**, a **membership card** or a **loyalty card** in the person's Apple Wallet or
4
+ Google Wallet. SmartLinks is the issuer and signs the passes. Each pass is branded from your site's name, logo and
5
+ colour, and your app decides what it says.
6
+
7
+ - **Who gets one:** only someone the business knows. A pass is issued to the signed-in owner of what it's for, or
8
+ by your app's own server function.
9
+ - **What the phone does:** the pass shows its QR code offline, appears near the time (and place, if you give
10
+ `venue.lat` / `lng`), and updates when you change it.
11
+ - **Bookings look after themselves:** when a booking is moved its pass shows the new time, and when it's cancelled
12
+ the pass is voided.
13
+
14
+ ## In a page: "Add to Wallet"
15
+
16
+ ```typescript
17
+ import { wallet } from '@proveanything/smartlinks'
18
+
19
+ // The signed-in person's booking, membership card, or a pass your app issued them
20
+ const { pass } = await wallet.addLinks(collectionId, { type: 'booking', id: booking.id })
21
+ // pass.links.apple → opens the .pkpass on an iPhone
22
+ // pass.links.google → opens Google's "Save to Google Wallet" page
23
+ ```
24
+
25
+ - `{ type: 'booking', id }` and `{ type: 'contact', id: 'me' }` are made on first ask:
26
+ - a booking pass, from the booking's date and time
27
+ - a membership card, from the person's `level` and `memberUntil` fields
28
+ - For anything else (an event ticket with your own title, a loyalty card with points), issue the pass in your server
29
+ function first. `addLinks` then returns that pass for its owner.
30
+ - Show the official "Add to Apple Wallet" and "Add to Google Wallet" badges, and only the one that suits the
31
+ device. A wallet that isn't set up yet is left out of `links`.
32
+ - `wallet.mine(collectionId)` lists the person's passes.
33
+
34
+ ## In a server function: issue, change, void, message
35
+
36
+ Declare `sl:wallet:write` in the function's capabilities.
37
+
38
+ ```typescript
39
+ // An event ticket
40
+ const pass = await ctx.sl.wallet.issue({
41
+ ref: { type: 'booking', id: booking.id }, // what it's for; issuing again changes the same pass
42
+ pass: {
43
+ kind: 'event',
44
+ title: 'Jazz on the Terrace',
45
+ start: '2026-12-24T19:00:00Z', end: '2026-12-24T22:00:00Z', timezone: 'Europe/London',
46
+ venue: { name: 'The Terrace', address: '1 High St, Bath', lat: 51.38, lng: -2.36 },
47
+ holder: 'Sam Lee', number: 'T-0042',
48
+ fields: [{ label: 'Seat', value: 'Table 6' }],
49
+ },
50
+ })
51
+ return { links: pass.links } // hand these to the page
52
+
53
+ // A loyalty card, kept up to date
54
+ await ctx.sl.wallet.issue({ ref: { type: 'loyalty', id: accountId }, pass: { kind: 'loyalty', title: 'Bloom Rewards', points: 120, holder: 'Sam' } })
55
+ await ctx.sl.wallet.update(passId, { points: 145 })
56
+
57
+ await ctx.sl.wallet.void(passId, 'refunded')
58
+ await ctx.sl.wallet.message(passId, { header: 'Doors open', body: 'Doors open at 7pm. See you soon!' })
59
+ // Everyone holding a ticket for this event
60
+ await ctx.sl.wallet.messageAll({ type: 'event', id: eventId }, { header: 'Running late', body: 'We start at 7:30 tonight.' })
61
+ ```
62
+
63
+ - **Contact:** `contactId` defaults to the caller's contact.
64
+ - **Reading:** `ctx.sl.wallet.get(passId)`, `forRef(ref)`, `byCode(code)` and `mine()` need only `sl:wallet:read`.
65
+ - **Messages:** you can also send a message to wallet with `ctx.sl.messages` and `channel: 'wallet'`. It goes to the
66
+ person's passes about the message's `about`, otherwise to your app's own passes for them. It's worded from the
67
+ template's push version.
68
+
69
+ ## Knowing who added it
70
+
71
+ Every pass belongs to a known person, so you can tell who has actually put it in their wallet:
72
+
73
+ - **Apple:** the phone registers the pass with SmartLinks when it's added, and unregisters it when it's removed.
74
+ - **Google:** Google sends a signed "saved" or "deleted" notice.
75
+
76
+ The pass's `inWallet` shows `{ apple: { saved, savedAt }, google: { saved, savedAt } }`. Each change raises an
77
+ event for the pass holder, so a flow in your app's blueprint can react, for example by sending a "see you there"
78
+ email when someone adds their ticket:
79
+
80
+ | Event | When |
81
+ |---|---|
82
+ | `wallet.pass_added` | the person added the pass to Apple or Google Wallet |
83
+ | `wallet.pass_removed` | they removed it |
84
+
85
+ Google's notices are best-effort, so treat them as a good signal rather than a guarantee.
86
+
87
+ ## Checking a pass at the door
88
+
89
+ The QR holds the pass's own code, never an id. Scan it, then:
90
+
91
+ ```typescript
92
+ const { pass, valid } = await wallet.byCode(collectionId, scanned) // admin
93
+ // or in a function: await ctx.sl.wallet.byCode(scanned)
94
+ ```
95
+
96
+ ## What a pass can show
97
+
98
+ | Field | Use |
99
+ |---|---|
100
+ | `kind` | `event`, `booking`, `membership` or `loyalty` |
101
+ | `title` / `subtitle` | the main line and a second line |
102
+ | `start` / `end` / `timezone` | when; the pass surfaces near `start` |
103
+ | `venue` | `name`, `address`, and `lat` / `lng` for the lock screen nearby |
104
+ | `holder`, `number`, `level`, `points`, `validUntil` | the person, a reference or member number, a level, a balance, an end date |
105
+ | `fields` (up to 4), `back` | extra lines on the front and the back |
106
+ | `image`, `url` | https only: a picture, a link back to your site |
107
+ | `barcode` | your own QR value, instead of the pass's code |
@@ -1,123 +1,123 @@
1
- # Websites: server-rendered on the SmartLinks site runtime
2
-
3
- A website built on SmartLinks is an app whose public side is a **server-rendered site** at its own
4
- address: an automatic `*.smartlinks.host` name, a chosen name, or the business's own domain. Every
5
- page arrives as finished HTML, so search engines, AI crawlers and link previews see the real
6
- content, and visitors see it before any JavaScript runs.
7
-
8
- ## How a request is served
9
-
10
- ```
11
- visitor / crawler / agent
12
- └─► SmartLinks site router (edge)
13
- ├─ /robots.txt, /sitemap.xml, /llms.txt made by the platform (site-seo.md)
14
- ├─ a file in your build (has an extension) served from the build, cached at the edge
15
- └─ anything else your site's server renders it
16
- • runs in an isolated worker, close to the SmartLinks API
17
- • may call the SmartLinks API and the hosts you declare, nothing else
18
- • request header x-sl-site says which site it is (SL.site.fromRequest)
19
- ```
20
-
21
- The router also adds the canonical or noindex header, the security headers, and
22
- `window.__SMARTLINKS_SITE__` to every HTML page (read in the browser with `SL.site.current()` or
23
- `SL.readContext()`).
24
-
25
- ## The build
26
-
27
- The website template (TanStack Start) produces this; you don't write it by hand.
28
-
29
- ```
30
- dist/
31
- ├── index.html? / assets/… the client build (hashed files: cached for a year)
32
- ├── sitemap-paths.txt your pages, "<path> [Title]" per line (site-seo.md)
33
- ├── _server/ the server bundle: one ES module entry + its chunks
34
- │ └── index.mjs exports default { fetch(request, env, ctx) } (WinterTC)
35
- └── app.manifest.json
36
- ```
37
-
38
- Manifest:
39
-
40
- ```jsonc
41
- "site": {
42
- "server": {
43
- "main": "_server/index.mjs", // the server entry, inside the build
44
- "compatibilityFlags": ["nodejs_compat"] // allowed: nodejs_compat, nodejs_compat_v2, nodejs_als
45
- },
46
- "network": ["api.example-weather.com"] // other hosts the server may call (optional)
47
- }
48
- ```
49
-
50
- On publish, the server folder becomes the site's server for that channel. Promote copies the same
51
- bytes. `_server/` is never served to visitors.
52
-
53
- ## The server's rules
54
-
55
- - **Which site:** `const site = SL.site.fromRequest(request)` gives `{ host, collectionId, appId,
56
- channel, canonicalHost }`. One build serves every site it's installed on, so always take the
57
- collection from here, never from a constant.
58
- - **Data:** call the SmartLinks API with the SDK as you would in the browser. The server reads what
59
- an anonymous visitor could read on that site, and only that collection. It holds no keys and no
60
- signed-in user.
61
- - **Writes** (contact forms, entries, sign-ups) go to your app's **server functions**
62
- (server-functions.md), called from the browser as today. Their capabilities, secrets and limits
63
- apply.
64
- - **Other hosts:** only those in `site.network`. Anything else is refused (`403 Blocked`).
65
- - **Limits per request:** a CPU-time budget and a cap on outgoing calls. A page that needs more is
66
- doing work that belongs in a server function or a scheduled job.
67
- - **No secrets** in the server bundle and no Node built-ins beyond `nodejs_compat`.
68
-
69
- ## Using another app's pages
70
-
71
- Some apps do a job a site shouldn't rebuild: a booking journey holds the time rules, the clash
72
- handling and the confirmation; "my bookings" holds who may change what. Those apps declare their pages
73
- in `linkable` (app-manifest.md), each with a stable `id`, a `path` and the params it `accepts`. A site
74
- embeds one with **`IframeResponder`** (iframe-responder.md), from the browser:
75
-
76
- ```typescript
77
- const site = SL.site.current()
78
- const responder = new SL.IframeResponder({
79
- collectionId: site.collectionId,
80
- appId: 'appointments', // the app's id on this collection
81
- initialPath: '/my-bookings', // the page's `path`
82
- params: { service: 'svc_123' }, // what the page `accepts`
83
- autoHeight: { minHeight: 480 }, // the iframe is as tall as the page: your page scrolls, never the iframe
84
- })
85
- iframe.src = await responder.attach(iframe)
86
- ```
87
-
88
- - **Size it with `autoHeight`, not by hand.** The responder sets the iframe's height from the page's own
89
- height and counts the iframe's border and padding, so there's nothing left to scroll. Setting
90
- `iframe.style.height` from `onResize` yourself goes wrong in a site: `onResize` also fires on every
91
- window resize with "the window below the iframe" (for a full-screen host), and a bordered iframe
92
- (Tailwind's border-box) ends up a few pixels short — a scrollbar inside the frame.
93
-
94
- - **The visitor's session goes with it.** The page's API calls are proxied through the site, so it
95
- acts as whoever is signed in to the site (or as a guest). Never pass a token in the URL.
96
- - **The app must be installed** on the site's collection; its address comes from there.
97
- - **Show the app's content natively where you can** (its `headless` data: services, staff, events)
98
- for your own design and SEO, and embed the page only for the part that does the work.
99
- - Pages render on the client, after load: they aren't part of the server-rendered HTML.
100
-
101
- ## Caching
102
-
103
- The router keeps a rendered page at the edge when your response says it may:
104
-
105
- | Your response | At the edge |
106
- |---|---|
107
- | `Cache-Control: public, s-maxage=300` (the template's default for pages) | kept up to 5 minutes |
108
- | `private`, `no-store`, `no-cache`, or a `Set-Cookie` | never kept |
109
- | no `Cache-Control` | never kept |
110
-
111
- Cached pages are keyed by the release and the collection's **content generation**: when products,
112
- public app records, app settings or the collection change, the generation moves and every page of
113
- the collection's sites re-renders on its next visit (within about 30 seconds). Publishing a release
114
- does the same. Tracking parameters (`utm_*`, `gclid`, `fbclid`…) don't create separate entries.
115
-
116
- Keep pages the same for every visitor. Anything personal (a signed-in owner's products, a basket)
117
- renders in the browser after load.
118
-
119
- ## Locally
120
-
121
- `npm run dev` runs the site with your dev collection (`.env`: `VITE_SL_COLLECTION_ID`), because
122
- there's no router to say which site it is: `SL.site.fromRequest()` is null, so fall back to it.
123
- Forge's preview runs the same server code the site runtime does.
1
+ # Websites: server-rendered on the SmartLinks site runtime
2
+
3
+ A website built on SmartLinks is an app whose public side is a **server-rendered site** at its own
4
+ address: an automatic `*.smartlinks.host` name, a chosen name, or the business's own domain. Every
5
+ page arrives as finished HTML, so search engines, AI crawlers and link previews see the real
6
+ content, and visitors see it before any JavaScript runs.
7
+
8
+ ## How a request is served
9
+
10
+ ```
11
+ visitor / crawler / agent
12
+ └─► SmartLinks site router (edge)
13
+ ├─ /robots.txt, /sitemap.xml, /llms.txt made by the platform (site-seo.md)
14
+ ├─ a file in your build (has an extension) served from the build, cached at the edge
15
+ └─ anything else your site's server renders it
16
+ • runs in an isolated worker, close to the SmartLinks API
17
+ • may call the SmartLinks API and the hosts you declare, nothing else
18
+ • request header x-sl-site says which site it is (SL.site.fromRequest)
19
+ ```
20
+
21
+ The router also adds the canonical or noindex header, the security headers, and
22
+ `window.__SMARTLINKS_SITE__` to every HTML page (read in the browser with `SL.site.current()` or
23
+ `SL.readContext()`).
24
+
25
+ ## The build
26
+
27
+ The website template (TanStack Start) produces this; you don't write it by hand.
28
+
29
+ ```
30
+ dist/
31
+ ├── index.html? / assets/… the client build (hashed files: cached for a year)
32
+ ├── sitemap-paths.txt your pages, "<path> [Title]" per line (site-seo.md)
33
+ ├── _server/ the server bundle: one ES module entry + its chunks
34
+ │ └── index.mjs exports default { fetch(request, env, ctx) } (WinterTC)
35
+ └── app.manifest.json
36
+ ```
37
+
38
+ Manifest:
39
+
40
+ ```jsonc
41
+ "site": {
42
+ "server": {
43
+ "main": "_server/index.mjs", // the server entry, inside the build
44
+ "compatibilityFlags": ["nodejs_compat"] // allowed: nodejs_compat, nodejs_compat_v2, nodejs_als
45
+ },
46
+ "network": ["api.example-weather.com"] // other hosts the server may call (optional)
47
+ }
48
+ ```
49
+
50
+ On publish, the server folder becomes the site's server for that channel. Promote copies the same
51
+ bytes. `_server/` is never served to visitors.
52
+
53
+ ## The server's rules
54
+
55
+ - **Which site:** `const site = SL.site.fromRequest(request)` gives `{ host, collectionId, appId,
56
+ channel, canonicalHost }`. One build serves every site it's installed on, so always take the
57
+ collection from here, never from a constant.
58
+ - **Data:** call the SmartLinks API with the SDK as you would in the browser. The server reads what
59
+ an anonymous visitor could read on that site, and only that collection. It holds no keys and no
60
+ signed-in user.
61
+ - **Writes** (contact forms, entries, sign-ups) go to your app's **server functions**
62
+ (server-functions.md), called from the browser as today. Their capabilities, secrets and limits
63
+ apply.
64
+ - **Other hosts:** only those in `site.network`. Anything else is refused (`403 Blocked`).
65
+ - **Limits per request:** a CPU-time budget and a cap on outgoing calls. A page that needs more is
66
+ doing work that belongs in a server function or a scheduled job.
67
+ - **No secrets** in the server bundle and no Node built-ins beyond `nodejs_compat`.
68
+
69
+ ## Using another app's pages
70
+
71
+ Some apps do a job a site shouldn't rebuild: a booking journey holds the time rules, the clash
72
+ handling and the confirmation; "my bookings" holds who may change what. Those apps declare their pages
73
+ in `linkable` (app-manifest.md), each with a stable `id`, a `path` and the params it `accepts`. A site
74
+ embeds one with **`IframeResponder`** (iframe-responder.md), from the browser:
75
+
76
+ ```typescript
77
+ const site = SL.site.current()
78
+ const responder = new SL.IframeResponder({
79
+ collectionId: site.collectionId,
80
+ appId: 'appointments', // the app's id on this collection
81
+ initialPath: '/my-bookings', // the page's `path`
82
+ params: { service: 'svc_123' }, // what the page `accepts`
83
+ autoHeight: { minHeight: 480 }, // the iframe is as tall as the page: your page scrolls, never the iframe
84
+ })
85
+ iframe.src = await responder.attach(iframe)
86
+ ```
87
+
88
+ - **Size it with `autoHeight`, not by hand.** The responder sets the iframe's height from the page's own
89
+ height and counts the iframe's border and padding, so there's nothing left to scroll. Setting
90
+ `iframe.style.height` from `onResize` yourself goes wrong in a site: `onResize` also fires on every
91
+ window resize with "the window below the iframe" (for a full-screen host), and a bordered iframe
92
+ (Tailwind's border-box) ends up a few pixels short — a scrollbar inside the frame.
93
+
94
+ - **The visitor's session goes with it.** The page's API calls are proxied through the site, so it
95
+ acts as whoever is signed in to the site (or as a guest). Never pass a token in the URL.
96
+ - **The app must be installed** on the site's collection; its address comes from there.
97
+ - **Show the app's content natively where you can** (its `headless` data: services, staff, events)
98
+ for your own design and SEO, and embed the page only for the part that does the work.
99
+ - Pages render on the client, after load: they aren't part of the server-rendered HTML.
100
+
101
+ ## Caching
102
+
103
+ The router keeps a rendered page at the edge when your response says it may:
104
+
105
+ | Your response | At the edge |
106
+ |---|---|
107
+ | `Cache-Control: public, s-maxage=300` (the template's default for pages) | kept up to 5 minutes |
108
+ | `private`, `no-store`, `no-cache`, or a `Set-Cookie` | never kept |
109
+ | no `Cache-Control` | never kept |
110
+
111
+ Cached pages are keyed by the release and the collection's **content generation**: when products,
112
+ public app records, app settings or the collection change, the generation moves and every page of
113
+ the collection's sites re-renders on its next visit (within about 30 seconds). Publishing a release
114
+ does the same. Tracking parameters (`utm_*`, `gclid`, `fbclid`…) don't create separate entries.
115
+
116
+ Keep pages the same for every visitor. Anything personal (a signed-in owner's products, a basket)
117
+ renders in the browser after load.
118
+
119
+ ## Locally
120
+
121
+ `npm run dev` runs the site with your dev collection (`.env`: `VITE_SL_COLLECTION_ID`), because
122
+ there's no router to say which site it is: `SL.site.fromRequest()` is null, so fall back to it.
123
+ Forge's preview runs the same server code the site runtime does.
package/dist/openapi.yaml CHANGED
@@ -6562,7 +6562,7 @@ paths:
6562
6562
  post:
6563
6563
  tags:
6564
6564
  - order
6565
- summary: Get comprehensive scan analytics for all tags in an order.
6565
+ summary: order.getAnalytics
6566
6566
  operationId: order_getAnalytics
6567
6567
  security:
6568
6568
  - bearerAuth: []
@@ -7251,7 +7251,7 @@ paths:
7251
7251
  post:
7252
7252
  tags:
7253
7253
  - product
7254
- summary: Create a new product for a collection (admin only).
7254
+ summary: product.create
7255
7255
  operationId: product_create
7256
7256
  security:
7257
7257
  - bearerAuth: []
@@ -8475,7 +8475,7 @@ paths:
8475
8475
  post:
8476
8476
  tags:
8477
8477
  - proof
8478
- summary: "The standard query on proofs (admin only): filter, sort, page, count and total a collection's proofs in one call, and follow a proof to its `product` and its `owner` (the owner's contact)."
8478
+ summary: proof.query
8479
8479
  operationId: proof_query
8480
8480
  security:
8481
8481
  - bearerAuth: []
@@ -8504,6 +8504,33 @@ paths:
8504
8504
  application/json:
8505
8505
  schema:
8506
8506
  $ref: "#/components/schemas/StandardQuery"
8507
+ /admin/collection/{collectionId}/readiness:
8508
+ get:
8509
+ tags:
8510
+ - collection
8511
+ summary: "What the collection's installed apps need and whether it's there (sign-in, customers, products, something to claim), in plain words, each with the screen that fixes it."
8512
+ operationId: collection_readiness
8513
+ security:
8514
+ - bearerAuth: []
8515
+ parameters:
8516
+ - name: collectionId
8517
+ in: path
8518
+ required: true
8519
+ schema:
8520
+ type: string
8521
+ responses:
8522
+ 200:
8523
+ description: Success
8524
+ content:
8525
+ application/json:
8526
+ schema:
8527
+ $ref: "#/components/schemas/CollectionReadiness"
8528
+ 400:
8529
+ description: Bad request
8530
+ 401:
8531
+ description: Unauthorized
8532
+ 404:
8533
+ description: Not found
8507
8534
  /admin/collection/{collectionId}/research/fetch:
8508
8535
  post:
8509
8536
  tags:
@@ -22081,6 +22108,10 @@ components:
22081
22108
  type: array
22082
22109
  items:
22083
22110
  $ref: "#/components/schemas/AdminView"
22111
+ requires:
22112
+ type: array
22113
+ items:
22114
+ $ref: "#/components/schemas/AppRequirement"
22084
22115
  executor:
22085
22116
  $ref: "#/components/schemas/AppManifestExecutor"
22086
22117
  functions:
@@ -22636,6 +22667,16 @@ components:
22636
22667
  - admin
22637
22668
  - customer
22638
22669
  - developer
22670
+ AppNeed:
22671
+ type: string
22672
+ enum:
22673
+ - signIn
22674
+ - crm
22675
+ - products
22676
+ - claimableItems
22677
+ AppRequirement:
22678
+ type: object
22679
+ additionalProperties: true
22639
22680
  PaginatedResponse:
22640
22681
  type: object
22641
22682
  properties:
@@ -28260,6 +28301,42 @@ components:
28260
28301
  required:
28261
28302
  - email
28262
28303
  - access
28304
+ ReadinessItem:
28305
+ type: object
28306
+ properties:
28307
+ level:
28308
+ type: string
28309
+ enum:
28310
+ - problem
28311
+ - warning
28312
+ - info
28313
+ code:
28314
+ type: string
28315
+ message:
28316
+ type: string
28317
+ app:
28318
+ type: string
28319
+ appName:
28320
+ type: string
28321
+ fix:
28322
+ type: object
28323
+ additionalProperties: true
28324
+ required:
28325
+ - level
28326
+ - code
28327
+ - message
28328
+ CollectionReadiness:
28329
+ type: object
28330
+ properties:
28331
+ ready:
28332
+ type: boolean
28333
+ items:
28334
+ type: array
28335
+ items:
28336
+ $ref: "#/components/schemas/ReadinessItem"
28337
+ required:
28338
+ - ready
28339
+ - items
28263
28340
  CollectionResponse:
28264
28341
  $ref: "#/components/schemas/Collection"
28265
28342
  CollectionCreateRequest: