@proveanything/smartlinks 3.0.0-alpha.2 → 3.0.0-alpha.3

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 (151) hide show
  1. package/README.md +741 -741
  2. package/dist/README.md +573 -573
  3. package/dist/adminCardsView.js +55 -55
  4. package/dist/api/bookings.d.ts +49 -2
  5. package/dist/api/bookings.js +59 -2
  6. package/dist/api/index.d.ts +1 -0
  7. package/dist/api/index.js +1 -0
  8. package/dist/api/payments.d.ts +60 -0
  9. package/dist/api/payments.js +94 -0
  10. package/dist/api/realtime.d.ts +3 -0
  11. package/dist/api/realtime.js +10 -2
  12. package/dist/baseline.css +194 -194
  13. package/dist/dataChanged.d.ts +74 -0
  14. package/dist/dataChanged.js +162 -0
  15. package/dist/docs/API_SUMMARY.md +1086 -858
  16. package/dist/docs/admin-cards.md +189 -189
  17. package/dist/docs/agent-tools.md +156 -156
  18. package/dist/docs/ai-tools-and-skills.md +180 -180
  19. package/dist/docs/ai.md +1721 -1721
  20. package/dist/docs/api-versions.md +85 -85
  21. package/dist/docs/app-data-storage.md +277 -277
  22. package/dist/docs/app-docs.md +73 -73
  23. package/dist/docs/app-manifest.md +852 -852
  24. package/dist/docs/app-records-pattern.md +388 -388
  25. package/dist/docs/appConfig.md +550 -550
  26. package/dist/docs/assistant-apps.md +172 -172
  27. package/dist/docs/assistant-context.md +119 -119
  28. package/dist/docs/bookings.md +105 -8
  29. package/dist/docs/caching.md +32 -3
  30. package/dist/docs/comms.md +689 -689
  31. package/dist/docs/connectors.md +340 -340
  32. package/dist/docs/css-baseline.md +133 -133
  33. package/dist/docs/customer-guide.md +70 -70
  34. package/dist/docs/data-changed.md +91 -0
  35. package/dist/docs/deploying-apps.md +340 -340
  36. package/dist/docs/dpp.md +115 -115
  37. package/dist/docs/entitlements.md +90 -90
  38. package/dist/docs/files.md +69 -69
  39. package/dist/docs/host-dependency-contract.md +252 -252
  40. package/dist/docs/iframe-responder.md +11 -0
  41. package/dist/docs/integrations.md +322 -322
  42. package/dist/docs/interactions.md +544 -544
  43. package/dist/docs/item-context.md +181 -181
  44. package/dist/docs/knowledge.md +105 -105
  45. package/dist/docs/lists.md +157 -157
  46. package/dist/docs/lots.md +112 -112
  47. package/dist/docs/loyalty.md +348 -348
  48. package/dist/docs/members.md +183 -183
  49. package/dist/docs/memberships.md +150 -150
  50. package/dist/docs/mobile-admin-container.md +693 -693
  51. package/dist/docs/operations.md +281 -281
  52. package/dist/docs/overview.md +487 -485
  53. package/dist/docs/payments.md +94 -0
  54. package/dist/docs/proof-comms-triggers.md +142 -142
  55. package/dist/docs/proof-ownership-transfer.md +155 -155
  56. package/dist/docs/proof-product-data-scoping.md +462 -462
  57. package/dist/docs/proof-share-grants.md +305 -305
  58. package/dist/docs/realtime.md +149 -139
  59. package/dist/docs/records-admin-pattern.md +304 -304
  60. package/dist/docs/service-accounts.md +64 -64
  61. package/dist/docs/standard-query.md +196 -187
  62. package/dist/docs/tag-codes.md +97 -97
  63. package/dist/docs/tag-ranges.md +106 -106
  64. package/dist/docs/theme-tokens.md +252 -252
  65. package/dist/docs/upgrading-to-3.md +550 -532
  66. package/dist/docs/wallet-passes.md +107 -107
  67. package/dist/docs/websites.md +123 -123
  68. package/dist/http.d.ts +6 -3
  69. package/dist/http.js +48 -19
  70. package/dist/iframeResponder.d.ts +7 -0
  71. package/dist/iframeResponder.js +10 -0
  72. package/dist/index.d.ts +2 -0
  73. package/dist/index.js +2 -0
  74. package/dist/openapi.yaml +426 -3
  75. package/dist/testing/bookingsMemory.d.ts +29 -1
  76. package/dist/testing/bookingsMemory.js +89 -1
  77. package/dist/testing/index.js +4 -1
  78. package/dist/theme-boot.js +82 -82
  79. package/dist/theme.css +75 -75
  80. package/dist/types/appManifest.d.ts +26 -4
  81. package/dist/types/bookings.d.ts +99 -1
  82. package/dist/types/index.d.ts +1 -0
  83. package/dist/types/index.js +1 -0
  84. package/dist/types/payments.d.ts +101 -0
  85. package/dist/types/payments.js +5 -0
  86. package/dist/types/realtime.d.ts +5 -1
  87. package/dist/version.d.ts +1 -1
  88. package/dist/version.js +1 -1
  89. package/docs/API_SUMMARY.md +1086 -858
  90. package/docs/admin-cards.md +189 -189
  91. package/docs/agent-tools.md +156 -156
  92. package/docs/ai-tools-and-skills.md +180 -180
  93. package/docs/ai.md +1721 -1721
  94. package/docs/api-versions.md +85 -85
  95. package/docs/app-data-storage.md +277 -277
  96. package/docs/app-docs.md +73 -73
  97. package/docs/app-manifest.md +852 -852
  98. package/docs/app-records-pattern.md +388 -388
  99. package/docs/appConfig.md +550 -550
  100. package/docs/assistant-apps.md +172 -172
  101. package/docs/assistant-context.md +119 -119
  102. package/docs/bookings.md +105 -8
  103. package/docs/caching.md +32 -3
  104. package/docs/comms.md +689 -689
  105. package/docs/connectors.md +340 -340
  106. package/docs/css-baseline.md +133 -133
  107. package/docs/customer-guide.md +70 -70
  108. package/docs/data-changed.md +91 -0
  109. package/docs/deploying-apps.md +340 -340
  110. package/docs/dpp.md +115 -115
  111. package/docs/entitlements.md +90 -90
  112. package/docs/files.md +69 -69
  113. package/docs/host-dependency-contract.md +252 -252
  114. package/docs/iframe-responder.md +11 -0
  115. package/docs/integrations.md +322 -322
  116. package/docs/interactions.md +544 -544
  117. package/docs/item-context.md +181 -181
  118. package/docs/knowledge.md +105 -105
  119. package/docs/lists.md +157 -157
  120. package/docs/lots.md +112 -112
  121. package/docs/loyalty.md +348 -348
  122. package/docs/members.md +183 -183
  123. package/docs/memberships.md +150 -150
  124. package/docs/mobile-admin-container.md +693 -693
  125. package/docs/operations.md +281 -281
  126. package/docs/overview.md +487 -485
  127. package/docs/payments.md +94 -0
  128. package/docs/proof-comms-triggers.md +142 -142
  129. package/docs/proof-ownership-transfer.md +155 -155
  130. package/docs/proof-product-data-scoping.md +462 -462
  131. package/docs/proof-share-grants.md +305 -305
  132. package/docs/realtime.md +149 -139
  133. package/docs/service-accounts.md +64 -64
  134. package/docs/standard-query.md +196 -187
  135. package/docs/tag-codes.md +97 -97
  136. package/docs/tag-ranges.md +106 -106
  137. package/docs/theme-lookbook.v1.json +120 -120
  138. package/docs/theme-tokens.md +252 -252
  139. package/docs/upgrading-to-3.md +550 -532
  140. package/docs/wallet-passes.md +107 -107
  141. package/docs/websites.md +123 -123
  142. package/openapi.yaml +426 -3
  143. package/package.json +91 -91
  144. package/scripts/headless-check.mjs +87 -87
  145. package/scripts/lib/bare-imports.mjs +57 -57
  146. package/scripts/lib/keyed-app-data.mjs +21 -21
  147. package/scripts/lib/upgrade.mjs +708 -668
  148. package/scripts/publish.mjs +272 -272
  149. package/scripts/register-release.mjs +91 -91
  150. package/scripts/upgrade.mjs +79 -79
  151. package/upgrade/3.json +2 -2
@@ -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: `{ items, nextCursor: null }`.
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: `{ items, nextCursor: null }`.
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 |
package/docs/websites.md CHANGED
@@ -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.