@softr/sdk 0.0.101-alpha.0 → 0.0.101-seo.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 (40) hide show
  1. package/dist/auth/context.d.ts +5 -0
  2. package/dist/auth/isomorphic.d.ts +2 -1
  3. package/dist/auth/isomorphic.js +4 -4
  4. package/dist/auth/session.d.ts +14 -0
  5. package/dist/auth/session.js +11 -1
  6. package/dist/formatting.d.ts +3 -3
  7. package/dist/index.d.ts +2 -3
  8. package/dist/index.js +2 -3
  9. package/dist/mcp.d.ts +2 -2
  10. package/dist/origin.js +16 -0
  11. package/dist/package.js +1 -1
  12. package/dist/pwa.d.ts +2 -2
  13. package/dist/pwa.js +19 -8
  14. package/dist/route/page.d.ts +41 -3
  15. package/dist/route/page.js +102 -25
  16. package/dist/server.d.ts +3 -1
  17. package/dist/server.js +3 -1
  18. package/dist/sitemap.d.ts +35 -0
  19. package/dist/sitemap.js +56 -0
  20. package/package.json +33 -10
  21. package/skills/softr-sdk/SKILL.md +8 -7
  22. package/skills/softr-sdk/ai/SKILL.md +2 -2
  23. package/skills/softr-sdk/auth/SKILL.md +1 -1
  24. package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
  25. package/skills/softr-sdk/current-user/SKILL.md +1 -1
  26. package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
  27. package/skills/softr-sdk/formatting/SKILL.md +1 -1
  28. package/skills/softr-sdk/integrations/SKILL.md +1 -1
  29. package/skills/softr-sdk/mcp/SKILL.md +1 -1
  30. package/skills/softr-sdk/pwa/SKILL.md +1 -1
  31. package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
  32. package/skills/softr-sdk/record-queries/SKILL.md +1 -1
  33. package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
  34. package/skills/softr-sdk/routes-and-visibility/SKILL.md +90 -4
  35. package/skills/softr-sdk/sitemap/SKILL.md +112 -0
  36. package/skills/softr-sdk/workflows/SKILL.md +1 -1
  37. package/dist/cache.js +0 -25
  38. package/dist/push.d.ts +0 -52
  39. package/dist/push.js +0 -292
  40. package/skills/softr-sdk/push-notifications/SKILL.md +0 -140
package/package.json CHANGED
@@ -1,16 +1,37 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "0.0.101-alpha.0",
3
+ "version": "0.0.101-seo.0",
4
4
  "type": "module",
5
5
  "exports": {
6
- ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
7
- "./client": { "types": "./dist/client.d.ts", "import": "./dist/client.js" },
8
- "./server": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
9
- "./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" }
10
- },
11
- "bin": { "softr-sdk": "./dist/cli.js" },
12
- "files": ["dist", "schema", "skills", "!skills/_artifacts"],
13
- "publishConfig": { "access": "public" },
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js"
9
+ },
10
+ "./client": {
11
+ "types": "./dist/client.d.ts",
12
+ "import": "./dist/client.js"
13
+ },
14
+ "./server": {
15
+ "types": "./dist/server.d.ts",
16
+ "import": "./dist/server.js"
17
+ },
18
+ "./vite": {
19
+ "types": "./dist/vite.d.ts",
20
+ "import": "./dist/vite.js"
21
+ }
22
+ },
23
+ "bin": {
24
+ "softr-sdk": "./dist/cli.js"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "schema",
29
+ "skills",
30
+ "!skills/_artifacts"
31
+ ],
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
14
35
  "scripts": {
15
36
  "build": "tsdown",
16
37
  "test": "node --import ./src/test-utils/setup.ts --test",
@@ -42,7 +63,9 @@
42
63
  "optional": true
43
64
  }
44
65
  },
45
- "keywords": ["tanstack-intent"],
66
+ "keywords": [
67
+ "tanstack-intent"
68
+ ],
46
69
  "intent": {
47
70
  "version": 1,
48
71
  "repo": "@softr/sdk",
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: core
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  # Softr SDK core
@@ -32,8 +32,8 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
32
32
 
33
33
  | Import | Runs | Holds |
34
34
  | --- | --- | --- |
35
- | `@softr/sdk` | Both | `defineQuery`, `defineMutation`, `defineAiAction`, `definePage`, `pageHead`, `defineVisibility`, `guardRoute`, `assertRouteAccess`, `isAuthorized`, `checkAccess`, `Audience`, `useCurrentUser`, `useUserTimezone`, `FormattedDate`, `FormattingScope`, `useFormatting`, `formatDate`, `formatDateTime`, `formatNumber`, `formatValue`, `formatField`, `fieldShape`, `registerSoftrFields`, `useOverrides`, `SoftrPwaHead`, `usePwaInstall`, `usePushNotifications`, `getSoftrContext`, `initialSoftrContext`, `softrAuthMiddleware`, the error predicates, and every type |
36
- | `@softr/sdk/server` | Server only | `ds`, `auth`, `workflow`, `integration`, `ai` |
35
+ | `@softr/sdk` | Both | `defineQuery`, `defineMutation`, `defineAiAction`, `definePage`, `pageHead`, `excerpt`, `jsonLdScript`, `defineVisibility`, `guardRoute`, `assertRouteAccess`, `isAuthorized`, `checkAccess`, `Audience`, `useCurrentUser`, `useUserTimezone`, `FormattedDate`, `FormattingScope`, `useFormatting`, `formatDate`, `formatDateTime`, `formatNumber`, `formatValue`, `formatField`, `fieldShape`, `registerSoftrFields`, `useOverrides`, `SoftrPwaHead`, `usePwaInstall`, `getSoftrContext`, `initialSoftrContext`, `softrAuthMiddleware`, the error predicates, and every type |
36
+ | `@softr/sdk/server` | Server only | `ds`, `auth`, `workflow`, `integration`, `ai`, `sitemapXml`, `asSignedOutVisitor` |
37
37
  | `@softr/sdk/client` | Browser only | `useFileUpload` |
38
38
  | `@softr/sdk/vite` | Build | `softr()`, already in `vite.config.ts` |
39
39
 
@@ -42,6 +42,7 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
42
42
  | Task | Sub-Skill |
43
43
  | --- | --- |
44
44
  | Add a route, or change who can see one | [routes-and-visibility/SKILL.md](./routes-and-visibility/SKILL.md) |
45
+ | List the public pages in `/sitemap.xml` | [sitemap/SKILL.md](./sitemap/SKILL.md) |
45
46
  | Show part of a page to some visitors only | [region-visibility/SKILL.md](./region-visibility/SKILL.md) |
46
47
  | Read the signed-in visitor | [current-user/SKILL.md](./current-user/SKILL.md) |
47
48
  | Fetch records from a datasource | [record-queries/SKILL.md](./record-queries/SKILL.md) |
@@ -53,7 +54,6 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
53
54
  | Call a connected third-party API (Slack, Stripe, Gmail, …), or an AI model on the user's own provider account | [integrations/SKILL.md](./integrations/SKILL.md) |
54
55
  | Open the app to AI assistants over MCP | [mcp/SKILL.md](./mcp/SKILL.md) |
55
56
  | Let visitors install the app on their home screen | [pwa/SKILL.md](./pwa/SKILL.md) |
56
- | Let visitors turn on push notifications | [push-notifications/SKILL.md](./push-notifications/SKILL.md) |
57
57
  | Show a date, a time or a number | [formatting/SKILL.md](./formatting/SKILL.md) |
58
58
 
59
59
  ## Quick Decision Tree
@@ -62,6 +62,9 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
62
62
  Adding a page, or changing who may see one?
63
63
  load softr-sdk/routes-and-visibility
64
64
 
65
+ Serving /sitemap.xml, or adding a public page or public record page to it?
66
+ load softr-sdk/sitemap
67
+
65
68
  Hiding a region of a page from some visitors?
66
69
  load softr-sdk/region-visibility
67
70
 
@@ -98,9 +101,6 @@ Opening the app to an AI assistant over MCP?
98
101
  Adding an install button, or making the app installable?
99
102
  load softr-sdk/pwa
100
103
 
101
- Letting visitors turn on push notifications, or "notify users when …"?
102
- load softr-sdk/push-notifications
103
-
104
104
  Showing a date, a time or a number on a page?
105
105
  load softr-sdk/formatting
106
106
 
@@ -153,6 +153,7 @@ export function getRouter() {
153
153
  ```ts
154
154
  type SoftrContext = {
155
155
  user: User | null // null means signed out
156
+ origin?: string // the app's address, such as https://acme.com
156
157
  }
157
158
 
158
159
  type User = {
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 0.0.101-alpha.0
16
+ library_version: 0.0.101-seo.0
17
17
  ---
18
18
 
19
19
  **Boundary.** `ai` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineAiAction` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -26,7 +26,7 @@ An app asks a model through an AI action. Softr runs the call on its own provide
26
26
 
27
27
  Never choose silently between Softr AI and the user's own account. Decide for each AI feature, before you write its code, in this order:
28
28
 
29
- 1. The user said who runs it: follow it. "My OpenAI key" or "our Anthropic account", with exactly one integration of that type in `integration_list`: use that one, without asking. A new key of a provider they named — they asked for a new one, or the workspace holds none of that type — is one `requestinput` of type `integration` for that type: its card connects one. A connected key runs the feature; a skipped request means Softr AI, and you say so. Several keys of that type, or "my own key" with no provider: ask (step 4). A provider or a model named without "my" or "our" ("use Claude", "summarise with GPT") is a model preference on Softr AI, not a reason to ask.
29
+ 1. The user said who runs it: follow it. "My OpenAI key" or "our Anthropic account", with exactly one integration of that type in `integration_list`: use that one, without asking. A new account of a provider they named — they asked for another one, or the workspace holds none of that type — is one `requestinput` of type `integration` for that type: its card connects one. A connected key runs the feature; a skipped request means Softr AI, and you say so. Several keys of that type, or "my own key" with no provider: ask (step 4). A provider or a model named without "my" or "our" ("use Claude", "summarise with GPT") is a model preference on Softr AI, not a reason to ask.
30
30
  2. The app already has AI features: follow the choice they made, and say so in one line.
31
31
  3. `integration_list` shows no `OPEN_AI`, `ANTHROPIC_AI` or `GEMINI_AI` integration: use Softr AI, and say so in one line. Call the tool; do not assume the answer.
32
32
  4. Otherwise ask with one `requestinput` of type `aiProvider`. Its card lists every key the workspace holds and every provider to connect, unfiltered. The answer is Softr AI, or the integration with its id and type: follow it, even when it is another provider than the one the user named. A declined request means Softr AI: use it, and say so in one line.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  # The current user
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 0.0.101-alpha.0
10
+ library_version: 0.0.101-seo.0
11
11
  ---
12
12
 
13
13
  **Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk` and run in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 0.0.101-alpha.0
11
+ library_version: 0.0.101-seo.0
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 0.0.101-alpha.0
10
+ library_version: 0.0.101-seo.0
11
11
  ---
12
12
 
13
13
  **Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  # Installing the app
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineMutation` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 0.0.101-alpha.0
13
+ library_version: 0.0.101-seo.0
14
14
  ---
15
15
 
16
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. The same holds for any helper that calls `ds`: declare it inside the handler. A function at module level that calls `ds` keeps the server-only import in the browser bundle, and every page stops loading until it moves. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -5,14 +5,16 @@ description: >-
5
5
  (LOGGED_IN_USERS, NON_LOGGED_IN_USERS and customGroups) and its title,
6
6
  guardRoute or assertRouteAccess in beforeLoad, pageHead in head, isAuthorized
7
7
  and checkAccess anywhere, rendering an access error, and the lint rules that
8
- require the declaration.
8
+ require the declaration. Also a head built from the loader's data with
9
+ pageHead, the canonical and social tags every page gets, excerpt for a
10
+ description taken from a record, and jsonLdScript for structured data.
9
11
  metadata:
10
12
  type: sub-skill
11
13
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
14
+ library_version: 0.0.101-seo.0
13
15
  ---
14
16
 
15
- **Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
17
+ **Boundary.** `definePage`, `pageHead`, `excerpt`, `jsonLdScript`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
16
18
 
17
19
  # Route visibility
18
20
 
@@ -50,7 +52,7 @@ These constraints hold, because Softr reads the file rather than running it:
50
52
  - The import must be a direct named import from `@softr/sdk`.
51
53
  - A route file has one `definePage`. The route names it in `beforeLoad` and in `head`. A page imported from elsewhere is rejected.
52
54
  - Every value inside the literal is written there too. A group id taken from a `const`, a spread or an import still type-checks, but Studio can no longer change that setting. Repeat the id on each route, even when two routes share it.
53
- - A head setting that depends on the route's data is a function of its head context: `title: ({ loaderData }) => loaderData?.name`.
55
+ - The literals are the page's fallbacks. A title or description that comes from the route's data goes in a `head` written after `loader`, as [Head tags from the route's data](#head-tags-from-the-routes-data) shows.
54
56
  - Never state `visibility` on `__root.tsx`. The root cannot carry an audience, so a rule there would gate nothing while looking like it does. Its `definePage` holds the app-wide head defaults only. Put the rule on a layout below the root instead.
55
57
 
56
58
  `userGroupTypes` is a set, so a rule names one audience or several:
@@ -229,9 +231,93 @@ function StaffNote() {
229
231
 
230
232
  To show or hide a part of a page, `Audience` is simpler: see [region-visibility/SKILL.md](../region-visibility/SKILL.md).
231
233
 
234
+ ### Tags every page gets
235
+
236
+ `pageHead` renders these from the settings, unless the page sets its own:
237
+
238
+ | Tag | Value | Set your own with |
239
+ | --- | --- | --- |
240
+ | `<link rel="canonical">` | the page's own full URL, with no trailing slash and only the `page` query parameter kept | `canonicalUrl` |
241
+ | `og:url` | the same URL as the canonical | follows `canonicalUrl` |
242
+ | `og:title` | `title` | `socialTitle` |
243
+ | `og:description` | `description` | `socialDescription` |
244
+ | `og:image` | `socialImage` as a full URL | `socialImage` |
245
+
246
+ Only the page the visitor is on renders a canonical and an `og:url`, never a layout above it. `canonicalUrl` takes a path, such as `'/pricing'`, or a full URL, rendered as written. A path in `socialImage` becomes a full URL the same way.
247
+
248
+ Name a list's pagination search parameter `page`, so each page of the list keeps its own canonical: `/blog?page=2`.
249
+
250
+ ### Head tags from the route's data
251
+
252
+ A record page takes its title and description from the record. Write `head` after `loader` and call `pageHead` with the page's own settings spread in, then the values from `ctx.loaderData`. The literals in `definePage` stay as the fallbacks, used before the data loads and when it fails, and they are what Studio shows and edits.
253
+
254
+ ```tsx
255
+ import { createFileRoute, notFound } from '@tanstack/react-router'
256
+ import { definePage, excerpt, guardRoute, pageHead } from '@softr/sdk'
257
+ import { getArticle } from '#/server/articles.ts'
258
+
259
+ const pageSettings = definePage({
260
+ visibility: { userGroupTypes: ['NON_LOGGED_IN_USERS', 'LOGGED_IN_USERS'] },
261
+ title: 'Article | Acme',
262
+ description: 'An article from the Acme blog.',
263
+ })
264
+
265
+ export const Route = createFileRoute('/blog/$articleId')({
266
+ beforeLoad: guardRoute(pageSettings),
267
+ loader: async ({ params }) => {
268
+ const article = await getArticle({ data: { articleId: params.articleId } })
269
+ if (article === null) throw notFound()
270
+ return article
271
+ },
272
+ head: (ctx) =>
273
+ pageHead({
274
+ ...pageSettings,
275
+ title: ctx.loaderData?.fields.title ? `${ctx.loaderData.fields.title} | Acme` : pageSettings.title,
276
+ description: excerpt(ctx.loaderData?.fields.body) ?? pageSettings.description,
277
+ })(ctx),
278
+ component: Article,
279
+ })
280
+ ```
281
+
282
+ `head` comes after `loader`, so `ctx.loaderData` carries the loader's types and a field the query does not declare fails to type check. Read the record's fields directly.
283
+
284
+ `excerpt(text, maxLength = 155)` turns a long text field into a description: it drops markdown and HTML, collapses whitespace and cuts at a word boundary with an ellipsis. It takes `string | null | undefined` and returns `undefined` when nothing is left, so `?? pageSettings.description` picks the fallback.
285
+
286
+ Keep `socialImage` to the page's own image or the app's. A record's attachment URL stops working within hours, long before link previews refresh.
287
+
288
+ ### Structured data
289
+
290
+ `jsonLdScript(data)` turns a schema.org object into a `head` script. It escapes the JSON so a record's text cannot break out of the script tag. Return it in `scripts` next to what `pageHead` gave:
291
+
292
+ ```tsx
293
+ head: (ctx) => {
294
+ const article = ctx.loaderData
295
+ const head = pageHead({
296
+ ...pageSettings,
297
+ title: article?.fields.title ? `${article.fields.title} | Acme` : pageSettings.title,
298
+ description: excerpt(article?.fields.body) ?? pageSettings.description,
299
+ })(ctx)
300
+ if (article === undefined) return head
301
+ return {
302
+ ...head,
303
+ scripts: [
304
+ jsonLdScript({
305
+ '@context': 'https://schema.org',
306
+ '@type': 'Article',
307
+ headline: article.fields.title,
308
+ datePublished: article.fields.publishedAt,
309
+ }),
310
+ ],
311
+ }
312
+ },
313
+ ```
314
+
315
+ The landing page names the business the same way, with literals: an `Organization` with its name, logo and URL, and a `WebSite`.
316
+
232
317
  ## References
233
318
 
234
319
  - [current-user/SKILL.md](../current-user/SKILL.md): reading the visitor a guard has just admitted
235
320
  - [record-queries/SKILL.md](../record-queries/SKILL.md): a guard covers the page, not the server function behind it
236
321
  - [auth/SKILL.md](../auth/SKILL.md): `NON_LOGGED_IN_USERS` and the sign-in flow it fronts
237
322
  - [region-visibility/SKILL.md](../region-visibility/SKILL.md): showing part of a page to some of the visitors the route admits
323
+ - [sitemap/SKILL.md](../sitemap/SKILL.md): listing the public pages, record pages included, in `/sitemap.xml`
@@ -0,0 +1,112 @@
1
+ ---
2
+ name: sitemap
3
+ description: >-
4
+ Serve /sitemap.xml from a server route: sitemapXml from @softr/sdk/server
5
+ turns a list of paths or entries into the response, one ds.list loop per
6
+ public record route pages through nextOffset, and asSignedOutVisitor makes
7
+ every read list only what a signed-out visitor may see. Covers the
8
+ SitemapEntry fields and keeping the list in step with the app's public pages.
9
+ metadata:
10
+ type: sub-skill
11
+ library: softr-sdk
12
+ library_version: 0.0.101-seo.0
13
+ ---
14
+
15
+ **Boundary.** `sitemapXml`, `asSignedOutVisitor` and `ds` come from `@softr/sdk/server` and run only in server code: here, a route's server handler.
16
+
17
+ # Sitemap
18
+
19
+ The sitemap lists every page a signed-out visitor can open: the public static pages, and one URL per record on each public record page. The app builds it on each request, so a record added after publish is listed straight away.
20
+
21
+ ## Setup
22
+
23
+ ```ts
24
+ import { asSignedOutVisitor, ds, sitemapXml } from '@softr/sdk/server'
25
+ import type { SitemapEntry } from '@softr/sdk/server'
26
+ ```
27
+
28
+ ```ts
29
+ sitemapXml(request: Request, entries: Array<SitemapEntry>): Response
30
+ asSignedOutVisitor<T>(fn: () => T): Promise<Awaited<T>>
31
+ ```
32
+
33
+ ## Core Patterns
34
+
35
+ ### The sitemap route
36
+
37
+ ```ts
38
+ // src/routes/sitemap[.]xml.ts
39
+ import { createFileRoute } from '@tanstack/react-router'
40
+ import { asSignedOutVisitor, ds, sitemapXml } from '@softr/sdk/server'
41
+ import { articlesQuery } from '#/server/articles.ts'
42
+ import { toolsQuery } from '#/server/tools.ts'
43
+
44
+ export const Route = createFileRoute('/sitemap.xml')({
45
+ server: {
46
+ handlers: {
47
+ GET: ({ request }) =>
48
+ asSignedOutVisitor(async () => {
49
+ const articlePaths: Array<string> = []
50
+ let articleOffset: number | null = 0
51
+ while (articleOffset !== null) {
52
+ const page = await ds.list(articlesQuery).limit(100).offset(articleOffset)
53
+ for (const article of page.records) articlePaths.push(`/blog/${article.fields.slug}`)
54
+ articleOffset = page.nextOffset
55
+ }
56
+
57
+ const toolPaths: Array<string> = []
58
+ let toolOffset: number | null = 0
59
+ while (toolOffset !== null) {
60
+ const page = await ds.list(toolsQuery).limit(100).offset(toolOffset)
61
+ for (const tool of page.records) toolPaths.push(`/tools/${tool.id}`)
62
+ toolOffset = page.nextOffset
63
+ }
64
+
65
+ return sitemapXml(request, ['/', '/pricing', '/blog', ...articlePaths, ...toolPaths])
66
+ }),
67
+ },
68
+ },
69
+ })
70
+ ```
71
+
72
+ - The `[.]` in the file name makes the route's path `/sitemap.xml`. The route has a server handler and no component.
73
+ - List the public static pages by hand, as paths. A page behind sign-in stays out.
74
+ - Add one loop per public record page. `ds.list` returns at most 100 records at a time, so each loop follows `nextOffset` until it is `null`. Build each path the way the record page's route builds it.
75
+ - `asSignedOutVisitor` wraps the whole handler. Every `ds` read inside it returns what a signed-out visitor may see, whoever requested the sitemap, so the sitemap never lists a private record.
76
+ - Each query a loop reads names `NON_LOGGED_IN_USERS` in its `permissions`, as the public record page's own query does.
77
+ - A path becomes a full URL on the app's address. A full URL is kept as written.
78
+
79
+ When the app gains or loses a public page or a public record page, change this route in the same edit.
80
+
81
+ ### More than a path
82
+
83
+ An entry is a path or an object. Use the object form for a page that needs more:
84
+
85
+ ```ts
86
+ type SitemapEntry =
87
+ | string
88
+ | {
89
+ loc: string
90
+ lastmod?: string | Date
91
+ changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never'
92
+ priority?: number
93
+ alternateRefs?: Array<{ href: string; hreflang: string }>
94
+ images?: Array<{ loc: string; caption?: string; title?: string }>
95
+ news?: { publication: { name: string; language: string }; publicationDate: string | Date; title: string }
96
+ }
97
+ ```
98
+
99
+ ```ts
100
+ const articleEntries: Array<SitemapEntry> = []
101
+ // inside the loop
102
+ articleEntries.push({ loc: `/blog/${article.fields.slug}`, lastmod: article.fields.updatedAt ?? undefined })
103
+ ```
104
+
105
+ Set `lastmod` only from a date the record really holds, such as its last-updated field. Leave it out otherwise.
106
+
107
+ A sitemap lists at most 50,000 URLs.
108
+
109
+ ## References
110
+
111
+ - [record-queries/SKILL.md](../record-queries/SKILL.md): declaring the query each loop reads, and `nextOffset`
112
+ - [routes-and-visibility/SKILL.md](../routes-and-visibility/SKILL.md): which pages are public, and the canonical URL each page renders
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.101-alpha.0
12
+ library_version: 0.0.101-seo.0
13
13
  ---
14
14
 
15
15
  **Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere.
package/dist/cache.js DELETED
@@ -1,25 +0,0 @@
1
- import { logger } from "./logger.js";
2
-
3
- //#region src/cache.ts
4
- /**
5
- * Reads through a short cache. Never rejects: a failure is logged, reads as
6
- * `null` and is not remembered, so the next request tries again.
7
- */
8
- function readCached(what, ttlMs, current, store, load) {
9
- const now = Date.now();
10
- const cached = current();
11
- if (cached !== void 0 && cached.expires > now) return cached.value;
12
- const entry = {
13
- expires: now + ttlMs,
14
- value: load().catch((error) => {
15
- logger.warn(`Could not read ${what}:`, error);
16
- if (current() === entry) store(void 0);
17
- return null;
18
- })
19
- };
20
- store(entry);
21
- return entry.value;
22
- }
23
-
24
- //#endregion
25
- export { readCached };
package/dist/push.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import "@tanstack/react-start";
2
-
3
- //#region src/push.d.ts
4
-
5
- /** What the builder wrote in Studio for the prompt. Any of it may be missing. */
6
- type PushPrompt = {
7
- title: string | null;
8
- message: string | null;
9
- enableButtonLabel: string | null;
10
- };
11
- type PushNotifications = /** Loading, signed out, push off for this app or device, or a browser without push. */
12
- {
13
- status: "unavailable";
14
- }
15
- /** iPhone and iPad offer push only inside the installed app. */ | {
16
- status: "install-first";
17
- prompt: PushPrompt;
18
- } | {
19
- status: "ask";
20
- prompt: PushPrompt;
21
- /** The visitor skipped the prompt recently, within the builder's skip days. Hide the prompt. */
22
- dismissed: boolean;
23
- /** Asks the browser for permission and subscribes. Call it from a click. */
24
- subscribe: () => Promise<void>;
25
- /** Hides the prompt for as long as the builder set in Studio. */
26
- dismiss: () => void;
27
- } | {
28
- status: "subscribed";
29
- unsubscribe: () => Promise<void>;
30
- }
31
- /** The visitor blocked notifications in the browser. Only they can undo it, in the browser's settings. */ | {
32
- status: "blocked";
33
- };
34
- /**
35
- * Push notifications for the signed-in visitor. Call it once, in the one
36
- * component that shows the prompt, rendered once in the root route's
37
- * `RootDocument`, so this browser stays registered. Each call keeps state of
38
- * its own, so a second call does not see a subscribe made through the first.
39
- * Show a prompt only while `status` is `ask`
40
- * and the prompt is not `dismissed`.
41
- *
42
- * @example
43
- * function EnableNotifications() {
44
- * const push = usePushNotifications()
45
- * if (push.status !== "ask" || push.dismissed) return null
46
- * const turnOn = () => push.subscribe().catch(() => toast.error("Notifications could not be turned on."))
47
- * return <button onClick={turnOn}>{push.prompt.enableButtonLabel ?? "Turn on"}</button>
48
- * }
49
- */
50
- declare function usePushNotifications(): PushNotifications;
51
- //#endregion
52
- export { PushNotifications, PushPrompt, usePushNotifications };