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.

305 lines (163 loc) • 17.1 kB
# @softr/sdk ## 1.19.0 ### Minor Changes - New optional `seo` key in softr.json. With `"seo": { "enabled": true }`, `pageHead` adds a canonical link, `og:url`, `og:title` and `og:description` from `title` and `description`, and a full `og:image` address, when the page states nothing else. Without the key, `pageHead` renders the same tags as before. - New `jsonLdScript(data)`: structured data for `head`. Record text in it cannot close the script tag. - New `robotsTxt()` in `@softr/sdk/server`: the `GET` handler of a `/robots.txt` route. - New `sitemapXml({ pages, records })` in `@softr/sdk/server`: the `GET` handler of a `/sitemap.xml` route. It lists only what a signed-out visitor can open, and a new record shows in it within a day. - New optional `origin` in `SoftrContext`: the address the visitor opened the app at. - Action: in a public app, add `"seo": { "enabled": true }` to softr.json, and add the `/robots.txt` and `/sitemap.xml` routes. ## 1.18.0 ### Minor Changes - `AiError.retryAfter` carries the seconds Softr asks to wait when it refuses an AI call with a 429. `ai.generate` and `ai.stream` wait out a short 429 themselves before they throw. No action is needed. - Skills: the ai skill lists Softr's limits on AI calls and how to run a batch of them. Action: put several records in one AI call instead of one call per record, and stop a batch on a 429. - `ai.stream` throws a 402 before the stream starts when the workspace has no AI credits, instead of sending an `{error}` event. Softr's servers do this whatever the SDK version. No action is needed. ## 1.17.0 ### Minor Changes - Every `auth` call that signs a visitor in or up fails as `userLimitReached` when the plan of the app's workspace has no room for this user. Before, `auth.signIn` threw, and the other calls answered `invalidCode`, `invalidCredentials`, `invalidDetails` or `linkExpired`. Action: on the login and sign-up pages, give `userLimitReached` its own `case` and say the app has reached its user limit and the app owner can fix it. - `auth.sendSignInCode`, `auth.signInWithCode`, and `auth.signUp` and `auth.confirmSignUp` without a password fail as `notEnabled` when the plan of the app's workspace does not include one-time email codes, as after a downgrade. Before, these calls worked on every plan. Action: on the login and sign-up pages, give `notEnabled` its own `case`, say this way to sign in is not available, and offer the other ways in. - New error code `secondFactorNotEnabled`: the visitor owes a second step that the plan of the app's workspace does not include, as after a downgrade. Every call that signs a visitor in answers it in an app that asks that visitor for an authenticator step, and so does `auth.startAuthenticatorSetup`. `auth.signIn`, `auth.verifyEmailCode` and `auth.resendEmailCode` answer it in an app that asks for an emailed code after the password. Before, these calls worked on every plan. Action: give `secondFactorNotEnabled` its own `case` on the pages that sign a visitor in and on the page that sets up an authenticator. Say sign-in is not available on the app's plan and the app owner can fix it. Do not offer another way to sign in, because no way works. ## 1.16.0 ### Minor Changes - Add `useOfflineMode()`: the published app opens without internet and shows the pages and data the visitor last loaded, read only. Call it once in `RootDocument`; `useOfflineMode({ enabled: false })` turns it off and deletes what browsers kept. ## 1.15.4 ### Patch Changes - Skills: the mcp skill and the `defineTool` docs now say that a tool's handler never calls `ds`, or anything else from `@softr/sdk/server`, itself. `src/start.ts` imports the tools and is part of the browser bundle, so such a handler fails the production build. Action: move each such call into a helper wrapped in `createServerOnlyFn` from `@tanstack/react-start`, and call the helper from the handler. ## 1.15.3 ### Patch Changes - A `ds.get`, `ds.chart` or `ds.metric` builder reads again after a call such as `where` changes it, the same as `ds.list` and `ds.export`. Before, it answered the result of its first read and left out the new filter. Skills: record-queries and charts-and-metrics say that one builder is for one read, because `where` and `orderBy` add to the builder they are called on. No action is needed. ## 1.15.2 ### Patch Changes - A page that a route guard refuses with the `throw` strategy (`guardRoute`, `assertRouteAccess`) answers 403 instead of 500 when `softrAuthMiddleware` is registered, with an `x-softr-access-denied` header that names the reason. The page still shows the route's `errorComponent`. The guard no longer logs the refusal as an error, on the server or in the browser. Without `softrAuthMiddleware`, a refused page still answers 500. No action is needed. ## 1.15.1 ### Patch Changes - Skills: the formatting and record-mutations examples check a nullable field before they use it, so they pass the type check as written. ## 1.15.0 ### Minor Changes - `defineTool` declares an MCP tool that runs the app's own logic as the signed-in user, labelled read-only or not. - `softrMcpMiddleware` takes `tools` next to `actions`. - A read-only tool cannot change data or send anything through `ds`, `email`, `workflow`, `upload`, an `integration` call that is not a GET or HEAD, or an `auth` call that changes data, sends an email or signs somebody in. - Tools built from `actions` carry read-only and destructive hints. An update or a delete is marked destructive. - The MCP `whoami` tool names the user's groups, once the platform sends the names. ## 1.14.0 ### Minor Changes - `ds.export` reads every record that matches a query, with the same `where` and `orderBy` as `ds.list`, for a file the visitor downloads. It returns `{ records }`. Each call to the datasource reads 1,000 records, and `.pageSize()` sets fewer for a datasource whose API refuses pages that big. `ds.list` still reads at most 100 records a call. The record-queries skill keeps a large table on the server: a list reads one page, and figures come from `ds.metric` and `ds.chart`. ## 1.13.2 ### Patch Changes - A `ds.list` builder reads again after `where`, `orderBy`, `limit` or `offset` changes it. Before, it answered the first page it had read, so a loop that paged with one builder (`await list.offset(page.nextOffset)`) never ended and stopped the app's server. Awaiting an unchanged builder two times still reads one time. No action is needed. ## 1.13.1 ### Patch Changes - The "Stack trace" button on the development error page (`DefaultErrorOverlay`) is readable in a dark theme. Its background was always white, so its light text in a dark theme did not show. No action is needed. ## 1.13.0 ### Minor Changes - `LogoIcon`, from the new `@softr/sdk/logo-icon` entrypoint, is the Lucide icon that `logo.icon` in `softr.json` names, or `layers` when Lucide has none by that name. The `softr()` Vite plugin picks it when the app builds, so the app ships that one icon and the server renders it. ## 1.12.1 ### Patch Changes - When single sign-on fails, the SSO page (`auth.routes.sso`) gets the path the visitor wanted in the login redirect param, as it already did for an authenticator code. When the sign-in has expired there may be no path, and the param is left out. An SSO page that ignores the param works as before. Action: on that page, link "Try again" to `ssoSignInHref(toReturnPath(location).href)` and keep the redirect param on the login link. ## 1.12.0 ### Minor Changes - `logo` in `softr.json` is the app's logo: an icon or images, with a file for dark backgrounds. `getLogo()` reads it, with the `layers` icon when the key is missing, and the `Logo` and `LogoFile` types describe it. A field this version does not know is ignored and an unknown `source` shows the icon, so a newer Studio cannot break the build. An image without `onLight`, an icon name that is not kebab case or a file that is not a path or an https URL fails the build. ## 1.11.1 ### Patch Changes - `softrMcpMiddleware` lets Softr choose the access for an assistant that asks for none, instead of choosing it itself. Such an assistant still gets read and write access. No action is needed. ## 1.11.0 ### Minor Changes - `ds.list` pages a datasource that answers its own cursor instead of a row position (BigQuery). `nextOffset` is now `number | string | null`: a cursor comes back as the string the datasource answered, where it was `null` before, and `offset()` takes it back unchanged. A numeric offset is still a number. A cursor on a page with no records comes back as `null`, so a loop that reads all pages always stops. `ds.options` keeps paging by row position only. Action: where app code gives a page's `nextOffset` a type of its own, such as `number | null` or a `Promise<{ records; nextOffset }>` that a `ds.list` call must fit, widen it to `number | string | null`. - The MCP list tool takes a string `offset`, so a cursor from `nextOffset` reads the next page. ## 1.10.0 ### Minor Changes - `auth.updateProfile` and `auth.removeAvatar` answer `invalidPhoto` when the platform refuses a photo, instead of `invalidName`. Action: where a photo is saved or removed, handle `invalidPhoto` and say the photo cannot be used. ## 1.9.1 ### Patch Changes - record-mutations skill: write only the fields a form may change. email and file-uploads examples name each written field. ## 1.9.0 ### Minor Changes - `softrMcpMiddleware` holds an assistant to the access its user approved. A connection approved to read only lists only the read actions and `whoami`, and a call to any other action returns an error without writing. A connection approved to make changes works as before, and so does one whose assistant asked for no particular access: it is approved for everything. A connection that can no longer make changes after the upgrade works again once you reconnect it. ## 1.8.1 ### Patch Changes - `ds.get` returns `null` when a synced datasource answers that the record is not found or is outside the filter, as it does for Softr Tables, instead of throwing. ## 1.8.0 ### Minor Changes - `usePwaInstall` returns `install()` while the browser offers its own install dialog (Chrome and Edge), and turns unavailable once the app is installed. ## 1.7.7 ### Patch Changes - `docs/user-groups.md` names the custom user groups past the workspace's plan limit, in a section of their own. A page or an action gated on one of them admits nobody. - `DefaultErrorOverlay` shows why a guard denied the page in development, not `[object Object]`. - `guardRoute` and `assertRouteAccess` print why they denied the page in development when they throw an access error. ## 1.7.6 ### Patch Changes - `usePwaInstall` turns unavailable when the open tab moves into the installed app's window, as Chrome's "Open in app" does, so the install button no longer shows inside the installed app. ## 1.7.5 ### Patch Changes - `ds.list` returns `nextOffset` as a number when the datasource answers the offset as a string. ## 1.7.4 ### Patch Changes - The `record-queries` and `charts-and-metrics` skills now say that a helper calling `ds` outside a server function handler goes in `createServerOnlyFn`, and that a route loader calls a server function, never `ds`. ## 1.7.3 ### Patch Changes - The `make-the-app-installable` skill accepts a square PNG or JPEG icon from 512 to 2048 px, and turns installing on without an icon, asking for one after the button is built. The `pwa` skill says `/_softr/pwa.json` returns 404 only when installing is off. ## 1.7.2 ### Patch Changes - The `file-uploads` skill maps a record's attachments to `FileAttachment` before `initialAttachments`, giving a file without an id its url as id. - The `file-uploads`, `record-mutations` and `record-queries` skills write a one-file attachment field as one value or `null`. - The `file-uploads` skill sets the read, upload and write shapes of an attachment side by side. ## 1.7.1 ### Patch Changes - `auth.confirmSignUp` returns `invalidDetails`, not `invalidCode`, when Softr rejects the password. ## 1.7.0 ### Minor Changes - `auth.signInWithGoogle` fails as `notEnabled`, not `invalidCredentials`, when the app's plan no longer includes Google sign-in. Action: on that code, say Google sign-in is not available and offer the other ways in. ## 1.6.1 ### Patch Changes - `auth.setPasswordWithLink` returns `invalidDetails`, not `linkExpired`, when the app's strong-password rules reject the password. ## 1.6.0 ### Minor Changes - Add `defineEmailAction` to declare an email the app sends, and `email.send` and `EmailError` on `@softr/sdk/server` to send it. ## 1.5.1 ### Patch Changes - The `integrations` skill lists the base URLs of Microsoft Planner, Tally, Trello and Typeform. ## 1.5.0 ### Minor Changes - `auth.sendSignInCode` fails as `noAccount` when no account has the email, and as `accountDeactivated` for a deactivated account, instead of succeeding without sending anything. Action: on the login page, send the code from the email step and say so there, and point the visitor to sign-up on `noAccount` where the app has it. Open the code inputs only once the code is sent. - `auth.signInMethod({ email })` says whether an email has an account, and which ways in work for it. Action: on a login page that asks for the email first, go to the step for the first of `methods`, or say there is no account, instead of always asking for a password. On a `password` method with `passwordSet` false, the account has no password yet: say so and link to the password reset. - Codes Softr emails, for sign-in, sign-up and a second factor, are six digits. Action: give code fields `inputMode="numeric"` and `autoComplete="one-time-code"`, and accept digits only. ## 1.4.3 ### Patch Changes - The MCP consent page shows where the client document lives and the host the browser goes to with the code, so a user can tell a real client from one with a look-alike name. ## 1.4.2 ### Patch Changes - Fix: `FormattedDate` no longer fails hydration in Safari and iOS. It now renders the date in a `<span>`. ## 1.4.1 ### Patch Changes - The `auth` skill's sign-out snippet redirects to `/login` with `signedOut: true`, so a login page that goes straight to single sign-on does not sign the visitor back in. - The `record-queries`, `record-mutations`, `charts-and-metrics` and `current-user` skills teach `filter` on `defineQuery` and `defineMutation` as the way to keep each visitor to their own records, with `user.properties` for the Record ID of a link to Users, one action per role, and the errors a filter can throw. ## 1.4.0 ### Minor Changes - Add `useIdleTimeout()`, which signs the visitor out of this browser after the idle time set in Studio's "End session if idle", and sends them to `/`. Action: call it once in the root route's document component, next to `useUserTimezone()`. ## 1.3.2 ### Patch Changes - The current-user skill says `avatarUrl` is the only source of the visitor's photo: the picture column the app's users connection maps, set in Studio's users settings, never the visitor's row in the Users table. ## 1.3.1 ### Patch Changes - Send the visitor's IP, signed, with calls to the Softr platform, so apps can log users out when the country they use the app from changes. ## 1.3.0 ### Minor Changes - Single sign-on: `ssoSignInHref`, `useAuthSettings().sso`, `auth.discoverSso` and the optional `auth.routes.sso` page (default `/sso-authentication`). Action: add the `/sso-authentication` page, and show a "Continue with SSO" link to `ssoSignInHref(...)` on the login page when `sso` is set. ## 1.2.2 ### Patch Changes - `SoftrPwaHead` now gives iOS the app's home screen name and launch screens, so an installed app opens on its splash screen instead of white and Add to Home Screen suggests the app's name, not the page title. An app already on an iPhone home screen picks this up only after it is removed and added again. ## 1.2.1 ### Patch Changes - `softrAuthMiddleware` serves the favicon set in Studio, Settings → General → Favicon, at `/favicon.ico`. Without one, it serves the Softr icon. An icon link or `public/favicon.ico` in the app still wins. ## 1.2.0 ### Minor Changes - `defineMutation` takes an optional `filter` with its `filterFields` on an update or a delete. `ds.update` and `ds.delete` first check that the record matches the filter. A record that does not match throws "not found", and nothing is written. An update cannot list in `fields` a field that its filter compares with a user token. ## 1.1.1 ### Patch Changes - The formatting skill names the keys `parts` takes and says there is no `timeStyle`. ## 1.1.0 ### Minor Changes - `defineQuery` takes an optional `filter` with its `filterFields`. Every read of the query, with `ds.list`, `ds.get`, `chart` and `metric`, returns only the records that match the filter. A read returns only `fields`, not `filterFields`. ## 1.0.0 ### Major Changes - First stable release.