@proveanything/smartlinks 2.1.46 → 2.2.0

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 (136) 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/dpp.d.ts +99 -0
  5. package/dist/api/dpp.js +194 -0
  6. package/dist/api/index.d.ts +1 -0
  7. package/dist/api/index.js +1 -0
  8. package/dist/api/shop.d.ts +5 -1
  9. package/dist/api/shop.js +7 -7
  10. package/dist/api/subscriptions.d.ts +2 -1
  11. package/dist/api/subscriptions.js +4 -12
  12. package/dist/apiVersion.d.ts +9 -0
  13. package/dist/apiVersion.js +15 -0
  14. package/dist/baseline.css +194 -194
  15. package/dist/docs/API_SUMMARY.md +1136 -809
  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/analytics.md +39 -39
  21. package/dist/docs/api-versions.md +76 -0
  22. package/dist/docs/app-data-storage.md +277 -277
  23. package/dist/docs/app-docs.md +73 -73
  24. package/dist/docs/app-manifest.md +852 -852
  25. package/dist/docs/app-records-pattern.md +388 -388
  26. package/dist/docs/appConfig.md +550 -550
  27. package/dist/docs/assistant-apps.md +172 -172
  28. package/dist/docs/assistant-context.md +119 -119
  29. package/dist/docs/bookings.md +442 -442
  30. package/dist/docs/comms.md +686 -686
  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/deploying-apps.md +340 -340
  35. package/dist/docs/dpp.md +115 -0
  36. package/dist/docs/entitlements.md +90 -90
  37. package/dist/docs/files.md +69 -69
  38. package/dist/docs/host-dependency-contract.md +210 -210
  39. package/dist/docs/i18n.md +9 -9
  40. package/dist/docs/integrations.md +322 -322
  41. package/dist/docs/interactions.md +545 -545
  42. package/dist/docs/item-context.md +181 -181
  43. package/dist/docs/knowledge.md +102 -102
  44. package/dist/docs/lots.md +111 -111
  45. package/dist/docs/loyalty.md +352 -352
  46. package/dist/docs/members.md +183 -183
  47. package/dist/docs/memberships.md +149 -149
  48. package/dist/docs/mobile-admin-container.md +693 -693
  49. package/dist/docs/operations.md +281 -281
  50. package/dist/docs/overview.md +485 -484
  51. package/dist/docs/proof-comms-triggers.md +142 -142
  52. package/dist/docs/proof-ownership-transfer.md +155 -155
  53. package/dist/docs/proof-product-data-scoping.md +462 -462
  54. package/dist/docs/proof-share-grants.md +305 -305
  55. package/dist/docs/realtime.md +138 -138
  56. package/dist/docs/records-admin-pattern.md +304 -304
  57. package/dist/docs/server-functions.md +1 -1
  58. package/dist/docs/service-accounts.md +64 -64
  59. package/dist/docs/standard-query.md +187 -187
  60. package/dist/docs/tag-codes.md +97 -97
  61. package/dist/docs/theme-tokens.md +252 -252
  62. package/dist/docs/wallet-passes.md +107 -107
  63. package/dist/docs/websites.md +123 -123
  64. package/dist/http.d.ts +14 -0
  65. package/dist/http.js +65 -3
  66. package/dist/index.d.ts +2 -1
  67. package/dist/index.js +3 -1
  68. package/dist/openapi.yaml +509 -3
  69. package/dist/theme-boot.js +82 -82
  70. package/dist/theme.css +75 -75
  71. package/dist/types/dpp.d.ts +273 -0
  72. package/dist/types/dpp.js +2 -0
  73. package/dist/types/index.d.ts +1 -0
  74. package/dist/types/index.js +1 -0
  75. package/dist/utils/index.d.ts +1 -0
  76. package/dist/utils/index.js +1 -0
  77. package/dist/utils/money.d.ts +15 -0
  78. package/dist/utils/money.js +72 -0
  79. package/dist/version.d.ts +1 -0
  80. package/dist/version.js +2 -0
  81. package/docs/API_SUMMARY.md +1136 -809
  82. package/docs/admin-cards.md +189 -189
  83. package/docs/agent-tools.md +156 -156
  84. package/docs/ai-tools-and-skills.md +180 -180
  85. package/docs/ai.md +1721 -1721
  86. package/docs/analytics.md +39 -39
  87. package/docs/api-versions.md +76 -0
  88. package/docs/app-data-storage.md +277 -277
  89. package/docs/app-docs.md +73 -73
  90. package/docs/app-manifest.md +852 -852
  91. package/docs/app-records-pattern.md +388 -388
  92. package/docs/appConfig.md +550 -550
  93. package/docs/assistant-apps.md +172 -172
  94. package/docs/assistant-context.md +119 -119
  95. package/docs/bookings.md +442 -442
  96. package/docs/comms.md +686 -686
  97. package/docs/connectors.md +340 -340
  98. package/docs/css-baseline.md +133 -133
  99. package/docs/customer-guide.md +70 -70
  100. package/docs/deploying-apps.md +340 -340
  101. package/docs/dpp.md +115 -0
  102. package/docs/entitlements.md +90 -90
  103. package/docs/files.md +69 -69
  104. package/docs/host-dependency-contract.md +210 -210
  105. package/docs/i18n.md +9 -9
  106. package/docs/integrations.md +322 -322
  107. package/docs/interactions.md +545 -545
  108. package/docs/item-context.md +181 -181
  109. package/docs/knowledge.md +102 -102
  110. package/docs/lots.md +111 -111
  111. package/docs/loyalty.md +352 -352
  112. package/docs/members.md +183 -183
  113. package/docs/memberships.md +149 -149
  114. package/docs/mobile-admin-container.md +693 -693
  115. package/docs/operations.md +281 -281
  116. package/docs/overview.md +485 -484
  117. package/docs/proof-comms-triggers.md +142 -142
  118. package/docs/proof-ownership-transfer.md +155 -155
  119. package/docs/proof-product-data-scoping.md +462 -462
  120. package/docs/proof-share-grants.md +305 -305
  121. package/docs/realtime.md +138 -138
  122. package/docs/server-functions.md +1 -1
  123. package/docs/service-accounts.md +64 -64
  124. package/docs/standard-query.md +187 -187
  125. package/docs/tag-codes.md +97 -97
  126. package/docs/theme-lookbook.v1.json +120 -120
  127. package/docs/theme-tokens.md +252 -252
  128. package/docs/wallet-passes.md +107 -107
  129. package/docs/websites.md +123 -123
  130. package/openapi.yaml +509 -3
  131. package/package.json +87 -87
  132. package/scripts/headless-check.mjs +87 -87
  133. package/scripts/lib/bare-imports.mjs +57 -57
  134. package/scripts/lib/keyed-app-data.mjs +21 -21
  135. package/scripts/publish.mjs +272 -272
  136. 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 |
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.