UNPKG

@softr/sdk

Version:

The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.

78 lines (77 loc) • 3.28 kB
import { DatasourceAction, ReadShape } from "./action.js"; //#region src/search-engines.d.ts /** What a server route handler gets. Only the part these handlers read. */ type HandlerContext = { request: Request; }; type SitemapRecord = { id: string; fields: Record<string, unknown>; }; /** The pages of one public record page: the query that lists its records, and the path of one record's page. */ type SitemapRecordPages = { query: DatasourceAction<ReadShape>; path: (record: SitemapRecord) => string; /** * When the record last changed, for the sitemap's `lastmod`. A date, or a text that `Date` reads. Any other value * gives no `lastmod`. A "last modified" field can be empty for a record that nobody changed after it was made, so * fall back to the record's created date. */ lastModified?: (record: SitemapRecord) => unknown; }; /** What the sitemap lists. Only pages a signed-out visitor can open belong here. */ type SitemapSources = { /** * The paths of public pages that show no single record, like `"/"` or `"/bikes"`. Leave it out to list * every page that every visitor can open, read from the app's routes on each build of the sitemap. */ pages?: ReadonlyArray<string>; /** Each public record page, with one entry per record its query returns. */ records?: ReadonlyArray<SitemapRecordPages>; }; /** * Answers `/robots.txt`: search engines may crawl the app, AI training crawlers * may not, and the `Sitemap:` line points to the app's `/sitemap.xml`. An * app's own `public/robots.txt` wins over this route. * * @example * // src/routes/robots[.]txt.ts * export const Route = createFileRoute("/robots.txt")({ * server: { handlers: { GET: robotsTxt() } }, * }) */ declare function robotsTxt(): (ctx: HandlerContext) => Response; /** * Answers `/sitemap.xml` with the app's public pages and one page per public * record. It reads the records as a signed-out visitor and keeps the file for * a day, so search engines get only public records and the datasource is read * at most once a day per region. A new publish starts a new file. * * Without `pages`, it lists each page that every visitor can open, from the * app's routes: a page whose `guardRoute` and those of its layouts admit * signed-out and signed-in visitors, with no path parameter, and that does not * turn `searchEngineIndexing` off. A page whose `beforeLoad` is not * `guardRoute` alone, such as one that calls `assertRouteAccess`, is left out. * So is a page whose `searchEngineIndexing` is a function, because the * sitemap cannot know what it gives for each record. * A record path is then listed only when its page passes the same check. * * @example * // src/routes/sitemap[.]xml.ts * export const Route = createFileRoute("/sitemap.xml")({ * server: { * handlers: { * GET: sitemapXml({ * records: [{ * query: bikesQuery, * path: (bike) => `/bikes/${bike.id}`, * lastModified: (bike) => bike.fields.updatedAt ?? bike.fields.createdAt, * }], * }), * }, * }, * }) */ declare function sitemapXml(sources: SitemapSources): (ctx: HandlerContext) => Promise<Response>; //#endregion export { SitemapRecordPages, SitemapSources, robotsTxt, sitemapXml };