@softr/sdk 1.16.0-alpha.2 → 1.16.0-se23079.1
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.
- package/CHANGELOG.md +22 -2
- package/dist/auth/isomorphic.d.ts +1 -3
- package/dist/auth/isomorphic.js +3 -2
- package/dist/auth/methods/authenticator.js +8 -1
- package/dist/auth/methods/code.js +5 -1
- package/dist/auth/methods/emailCode2fa.js +4 -1
- package/dist/auth/methods/magicLink.js +4 -1
- package/dist/auth/methods/password.js +3 -1
- package/dist/auth/methods/passwordLink.js +5 -1
- package/dist/auth/methods/signup.js +7 -1
- package/dist/auth/methods/social.js +4 -5
- package/dist/auth/methods/utils.d.ts +4 -1
- package/dist/auth/methods/utils.js +30 -1
- package/dist/auth/platform.d.ts +0 -1
- package/dist/auth/platform.js +1 -14
- package/dist/auth/sso.d.ts +1 -24
- package/dist/auth/sso.js +9 -79
- package/dist/datasource/chart.js +5 -0
- package/dist/datasource/record.js +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/route/access-denied-status.js +25 -0
- package/dist/route/route.js +15 -3
- package/dist/tool.d.ts +7 -2
- package/dist/tool.js +1 -0
- package/package.json +43 -16
- package/skills/softr-sdk/SKILL.md +1 -1
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +4 -4
- package/skills/softr-sdk/auth/references/single-sign-on.md +0 -25
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +3 -1
- package/skills/softr-sdk/current-user/SKILL.md +1 -1
- package/skills/softr-sdk/email/SKILL.md +1 -1
- package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
- package/skills/softr-sdk/formatting/SKILL.md +6 -5
- package/skills/softr-sdk/integrations/SKILL.md +1 -1
- package/skills/softr-sdk/mcp/SKILL.md +26 -12
- package/skills/softr-sdk/push-notifications/SKILL.md +1 -1
- package/skills/softr-sdk/pwa/SKILL.md +1 -1
- package/skills/softr-sdk/record-mutations/SKILL.md +4 -2
- package/skills/softr-sdk/record-queries/SKILL.md +21 -1
- package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/workflows/SKILL.md +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.
|
|
|
11
11
|
import { Page, PageSettings, definePage, pageHead } from "./route/page.js";
|
|
12
12
|
import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
|
|
13
13
|
import { toReturnPath } from "./auth/returnPath.js";
|
|
14
|
-
import {
|
|
14
|
+
import { SsoError, ssoSignInHref } from "./auth/sso.js";
|
|
15
15
|
import { AuthOptions, AuthSettingsProvider, getAuthSettings, getSoftrContext, initialSoftrContext, softrAuthMiddleware, useAuthSettings, useCurrentUser } from "./auth/isomorphic.js";
|
|
16
16
|
import { useIdleTimeout } from "./auth/idle-timeout.js";
|
|
17
17
|
import { Tool, ToolDefinition, defineTool } from "./tool.js";
|
|
@@ -25,4 +25,4 @@ import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
|
25
25
|
import { Audience } from "./route/audience.js";
|
|
26
26
|
import { Logo, LogoFile } from "./softr-config.schema.js";
|
|
27
27
|
import { getLogo } from "./softr-config.js";
|
|
28
|
-
export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type EmailErrorCode, type EmailSendInit, type EmailSent, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Logo, type LogoFile, type Page, type PageSettings, type PushNotifications, type PushPrompt, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry,
|
|
28
|
+
export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type EmailErrorCode, type EmailSendInit, type EmailSent, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Logo, type LogoFile, type Page, type PageSettings, type PushNotifications, type PushPrompt, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type SsoError, type Tool, type ToolDefinition, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineTool, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getLogo, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.
|
|
|
5
5
|
import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
|
|
6
6
|
import { definePage, pageHead } from "./route/page.js";
|
|
7
7
|
import { toReturnPath } from "./auth/returnPath.js";
|
|
8
|
-
import {
|
|
8
|
+
import { ssoSignInHref } from "./auth/sso.js";
|
|
9
9
|
import { FormattedDate, FormattingScope, formatDate, formatDateTime, formatNumber, useFormatting } from "./formatting.js";
|
|
10
10
|
import { SoftrPwaHead, usePwaInstall } from "./pwa.js";
|
|
11
11
|
import { usePushNotifications } from "./push.js";
|
|
@@ -19,4 +19,4 @@ import { useUserTimezone } from "./timezone.js";
|
|
|
19
19
|
import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
20
20
|
import { Audience } from "./route/audience.js";
|
|
21
21
|
|
|
22
|
-
export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineTool, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getLogo, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware,
|
|
22
|
+
export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineTool, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getLogo, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DatasourceAction } from "./action.js";
|
|
2
2
|
import { Tool } from "./tool.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _tanstack_react_start11 from "@tanstack/react-start";
|
|
4
4
|
|
|
5
5
|
//#region src/mcp.d.ts
|
|
6
6
|
|
|
@@ -38,6 +38,6 @@ type SoftrMcpOptions = {
|
|
|
38
38
|
* ],
|
|
39
39
|
* }))
|
|
40
40
|
*/
|
|
41
|
-
declare function softrMcpMiddleware(options?: SoftrMcpOptions):
|
|
41
|
+
declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start11.RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
42
42
|
//#endregion
|
|
43
43
|
export { softrMcpMiddleware };
|
package/dist/package.js
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ACCESS_DENIED_HEADER } from "./route.js";
|
|
2
|
+
import { getResponseHeader } from "@tanstack/react-start/server";
|
|
3
|
+
import { createMiddleware } from "@tanstack/react-start";
|
|
4
|
+
|
|
5
|
+
//#region src/route/access-denied-status.ts
|
|
6
|
+
/**
|
|
7
|
+
* Answers 403 for a page a guard refused by throwing, with the guard's mark.
|
|
8
|
+
* TanStack answers any thrown value with 500, which reads as a server error.
|
|
9
|
+
*/
|
|
10
|
+
function accessDeniedStatusMiddleware() {
|
|
11
|
+
return createMiddleware({ type: "request" }).server(async ({ next }) => {
|
|
12
|
+
const result = await next();
|
|
13
|
+
const reason = getResponseHeader(ACCESS_DENIED_HEADER);
|
|
14
|
+
if (result.response.status !== 500 || reason === void 0) return result;
|
|
15
|
+
const headers = new Headers(result.response.headers);
|
|
16
|
+
headers.set(ACCESS_DENIED_HEADER, reason);
|
|
17
|
+
return new Response(result.response.body, {
|
|
18
|
+
status: 403,
|
|
19
|
+
headers
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { accessDeniedStatusMiddleware };
|
package/dist/route/route.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { panic } from "../assertions.js";
|
|
2
|
-
import { logger } from "../logger.js";
|
|
3
2
|
import { softrConfig } from "../softr-config.js";
|
|
4
3
|
import { ACCESS_REASONS, checkRule } from "./visibility.js";
|
|
4
|
+
import { setResponseHeader } from "@tanstack/react-start/server";
|
|
5
|
+
import { createIsomorphicFn } from "@tanstack/react-start";
|
|
5
6
|
import { redirect } from "@tanstack/react-router";
|
|
6
7
|
|
|
7
8
|
//#region src/route/route.ts
|
|
9
|
+
/**
|
|
10
|
+
* Marks the answer of a page a guard refused by throwing, with the reason as its
|
|
11
|
+
* value. The pod reads it to tell a refusal from a server error, so its name and
|
|
12
|
+
* values stay as they are.
|
|
13
|
+
*/
|
|
14
|
+
const ACCESS_DENIED_HEADER = "x-softr-access-denied";
|
|
15
|
+
const markRefused = createIsomorphicFn().server((reason) => {
|
|
16
|
+
try {
|
|
17
|
+
setResponseHeader(ACCESS_DENIED_HEADER, reason);
|
|
18
|
+
} catch {}
|
|
19
|
+
});
|
|
8
20
|
function isAccessReason(value) {
|
|
9
21
|
return ACCESS_REASONS.some((reason) => reason === value);
|
|
10
22
|
}
|
|
@@ -62,7 +74,7 @@ function thrownFor(reason, overrides, location) {
|
|
|
62
74
|
type: "access_error",
|
|
63
75
|
reason
|
|
64
76
|
};
|
|
65
|
-
|
|
77
|
+
markRefused(reason);
|
|
66
78
|
return error;
|
|
67
79
|
}
|
|
68
80
|
function ruleOf(page) {
|
|
@@ -104,4 +116,4 @@ function assertRouteAccess(page, opts) {
|
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
//#endregion
|
|
107
|
-
export { ACCESS_DENIED_MESSAGES, assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError };
|
|
119
|
+
export { ACCESS_DENIED_HEADER, ACCESS_DENIED_MESSAGES, assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError };
|
package/dist/tool.d.ts
CHANGED
|
@@ -37,8 +37,12 @@ type ToolDefinition<TInput extends z.ZodObject, TOutput> = {
|
|
|
37
37
|
*/
|
|
38
38
|
destructive?: boolean;
|
|
39
39
|
/**
|
|
40
|
-
* Runs the tool as the signed-in user. `ds` calls
|
|
41
|
-
* with their groups, as a click in the app would. Return JSON.
|
|
40
|
+
* Runs the tool as the signed-in user. The `ds` calls it reaches act as that
|
|
41
|
+
* user, with their groups, as a click in the app would. Return JSON.
|
|
42
|
+
*
|
|
43
|
+
* Never call `ds`, or anything else from `@softr/sdk/server`, in the handler
|
|
44
|
+
* itself: the production build fails. Call a helper wrapped in
|
|
45
|
+
* `createServerOnlyFn` from `@tanstack/react-start`.
|
|
42
46
|
*/
|
|
43
47
|
handler: (input: z.output<TInput>, context: {
|
|
44
48
|
user: User;
|
|
@@ -48,6 +52,7 @@ type ToolDefinition<TInput extends z.ZodObject, TOutput> = {
|
|
|
48
52
|
* An MCP tool that runs the app's own logic, for `softrMcpMiddleware({ tools })`.
|
|
49
53
|
*
|
|
50
54
|
* @example
|
|
55
|
+
* // createIssueFor is wrapped in createServerOnlyFn, and calls `ds`.
|
|
51
56
|
* export const createIssue = defineTool({
|
|
52
57
|
* name: 'create_issue',
|
|
53
58
|
* description: 'Create an issue in a project. Returns the new issue with its key.',
|
package/dist/tool.js
CHANGED
|
@@ -8,6 +8,7 @@ const TOOL_NAME = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
|
8
8
|
* An MCP tool that runs the app's own logic, for `softrMcpMiddleware({ tools })`.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
+
* // createIssueFor is wrapped in createServerOnlyFn, and calls `ds`.
|
|
11
12
|
* export const createIssue = defineTool({
|
|
12
13
|
* name: 'create_issue',
|
|
13
14
|
* description: 'Create an issue in a project. Returns the new issue with its key.',
|
package/package.json
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softr/sdk",
|
|
3
|
-
"version": "1.16.0-
|
|
3
|
+
"version": "1.16.0-se23079.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"./
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
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
|
+
"./logo-icon": {
|
|
23
|
+
"types": "./dist/logo-icon.d.ts",
|
|
24
|
+
"import": "./dist/logo-icon.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"softr-sdk": "./dist/cli.js"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"schema",
|
|
33
|
+
"skills",
|
|
34
|
+
"!skills/_artifacts",
|
|
35
|
+
"CHANGELOG.md"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
19
39
|
},
|
|
20
40
|
"dependencies": {
|
|
21
41
|
"zod": "^4.4.3"
|
|
@@ -43,10 +63,17 @@
|
|
|
43
63
|
"optional": true
|
|
44
64
|
}
|
|
45
65
|
},
|
|
46
|
-
"keywords": [
|
|
66
|
+
"keywords": [
|
|
67
|
+
"tanstack-intent"
|
|
68
|
+
],
|
|
47
69
|
"intent": {
|
|
48
70
|
"version": 1,
|
|
49
71
|
"repo": "@softr/sdk",
|
|
50
72
|
"docs": "https://www.npmjs.com/package/@softr/sdk"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "tsdown",
|
|
76
|
+
"test": "node --import ./src/test-utils/setup.ts --test",
|
|
77
|
+
"typecheck": "tsc --noEmit"
|
|
51
78
|
}
|
|
52
|
-
}
|
|
79
|
+
}
|
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 1.16.0
|
|
16
|
+
library_version: 1.16.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.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.16.0
|
|
13
|
+
library_version: 1.16.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
|
|
@@ -134,10 +134,11 @@ type AuthErrorCode =
|
|
|
134
134
|
| 'notAuthenticated' // a call that needs a signed-in visitor, made by one who is not
|
|
135
135
|
| 'emailDomainNotAllowed' // signUp, signInWithGoogle: the app lets only some email domains sign up, and this is not one
|
|
136
136
|
| 'linkExpired' // checkPasswordLink, setPasswordWithLink: the link is used, expired or no longer valid
|
|
137
|
-
| 'notEnabled'
|
|
137
|
+
| 'notEnabled' | 'secondFactorNotEnabled' // the app's plan no longer includes this way in (Google, an emailed code), or the second step this visitor owes (an emailed code after the password, the authenticator app)
|
|
138
|
+
| 'userLimitReached' // any call that signs a visitor in or up: the plan of the app's workspace has no room for this user
|
|
138
139
|
```
|
|
139
140
|
|
|
140
|
-
Branch on `error.code` with a `switch` and write your own wording. Never put `error.message` in front of the visitor. The one exception is `invalidDetails` from `setPasswordWithLink` and `confirmSignUp`. Show its message: it names the password rule that failed.
|
|
141
|
+
Branch on `error.code` with a `switch` and write your own wording. Never put `error.message` in front of the visitor. The one exception is `invalidDetails` from `setPasswordWithLink` and `confirmSignUp`. Show its message: it names the password rule that failed. On `userLimitReached` the visitor did nothing wrong, and a retry does not help. Say the app has reached its user limit and that the app owner can fix it. Give it its own `case` on the login and sign-up pages, so it does not fall to a "wrong password" or "wrong code" message. Do the same for `secondFactorNotEnabled`: no other way to sign in works for this visitor, so do not offer one. Say that sign-in is not available on the app's plan and that the app owner can fix it.
|
|
141
142
|
|
|
142
143
|
`code` is typed as every code the SDK produces, not the ones a given call can answer, so a `switch` needs a `default` even when the cases above it are complete. Give it a message rather than leaving it out.
|
|
143
144
|
|
|
@@ -176,7 +177,6 @@ Each field names the `auth` call it unlocks:
|
|
|
176
177
|
| `emailCode` | sign-in with a code, `auth.sendSignInCode` |
|
|
177
178
|
| `magicLink` | the route that calls `auth.signInWithMagicLink` |
|
|
178
179
|
| `google` | a Google button started with `google.clientId`. `null` means no Google. Never hardcode a client id. |
|
|
179
|
-
| `softr` | a "Continue with Softr" link to `softrSignInHref(...)`, for people who sign in with their Softr Studio account. See [references/single-sign-on.md](./references/single-sign-on.md#log-in-with-softr) |
|
|
180
180
|
| `signUp` | sign-up, `auth.signUp` |
|
|
181
181
|
| `strongPasswords` | the strong-password rules, on every form that sets a new password. Check the password against them before submitting. |
|
|
182
182
|
|
|
@@ -26,7 +26,6 @@ When single sign-on needs more from the visitor, or fails, they come back to the
|
|
|
26
26
|
| --- | --- | --- |
|
|
27
27
|
| `authenticator` | `'verify'`, `'setup'` or `'setupOptional'`: the app asks for an authenticator app as well | the second-factor step, as for `authenticatorRequired` and its `step`. Finish with the same calls, then `toReturnPath(location)` |
|
|
28
28
|
| `error` | why it did not finish, one of the codes below | a message, a "Try again" link to `ssoSignInHref(toReturnPath(location).href)`, and a link to the login page that keeps the redirect param, so either way the visitor ends where they wanted |
|
|
29
|
-
| `method` | `'softr'` when [log in with Softr](#log-in-with-softr) failed, absent for single sign-on | the "Try again" link goes to `softrSignInHref(toReturnPath(location).href)` instead |
|
|
30
29
|
|
|
31
30
|
| `error` | Means |
|
|
32
31
|
| --- | --- |
|
|
@@ -37,8 +36,6 @@ When single sign-on needs more from the visitor, or fails, they come back to the
|
|
|
37
36
|
| `restricted` | The account is deactivated, or the app has no room for another user |
|
|
38
37
|
| `expired` | It took too long, another tab started a newer sign-in, or the sign-in started at the identity provider rather than in the app |
|
|
39
38
|
| `failed` | Anything else |
|
|
40
|
-
| `softr-rejected` | Log in with Softr only: Softr did not let this account in |
|
|
41
|
-
| `softr-sso-account` | Log in with Softr only: this account signs in with single sign-on. Link to `ssoSignInHref(toReturnPath(location).href)` |
|
|
42
39
|
|
|
43
40
|
With neither param, redirect to `toReturnPath(location)`.
|
|
44
41
|
|
|
@@ -51,25 +48,3 @@ Three ways to put it on the login page. Build the one the builder asks for:
|
|
|
51
48
|
1. **A button**, as above, next to the other methods. The default.
|
|
52
49
|
2. **Email first.** Ask for the email, then call `auth.discoverSso({ email })` from a server function. It answers a `Result` of `{ sso: boolean }`, decided by the email's domain alone, and fails only with `tooManyAttempts`. On `sso: true` send the visitor to `ssoSignInHref(...)` with `window.location.assign`, otherwise carry on with the password or code step. Never hardcode the domains: the builder changes them in Softr, and the app would not follow.
|
|
53
50
|
3. **Straight to the identity provider** when single sign-on is the only method: send the visitor to `ssoSignInHref(...)` as the login page loads. Skip it when the login page has a `signedOut` search param, or the visitor is signed straight back in after signing out, since the identity provider still knows them. The sign-out server function adds it: `throw redirect({ to: '/login', search: { signedOut: true } })`, and so does the login link on the single sign-on page, or an error there sends the visitor to the identity provider and back to the same error. Keep the button on the page for that case.
|
|
54
|
-
|
|
55
|
-
## Log in with Softr
|
|
56
|
-
|
|
57
|
-
People in the audience the builder chose in Softr sign in with their Softr Studio account. Softr Studio is their identity provider, so it works like single sign-on: a link starts it, and there is no server function to write.
|
|
58
|
-
|
|
59
|
-
```tsx
|
|
60
|
-
import { useLocation } from '@tanstack/react-router'
|
|
61
|
-
import { softrSignInHref, toReturnPath, useAuthSettings } from '@softr/sdk'
|
|
62
|
-
|
|
63
|
-
const options = useAuthSettings()
|
|
64
|
-
const location = useLocation()
|
|
65
|
-
|
|
66
|
-
{options.softr ? (
|
|
67
|
-
<Button nativeButton={false} render={<a href={softrSignInHref(toReturnPath(location).href)} />}>
|
|
68
|
-
Continue with Softr
|
|
69
|
-
</Button>
|
|
70
|
-
) : null}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
The same rules as `ssoSignInHref` apply: a plain `<a href>`, a return path on this app, or none. It comes back to the same page as single sign-on, with `method=softr` next to `error`, and with the same `authenticator` step. The other codes above can also come with `method=softr`, so name the method from `method`, not "single sign-on". Show `softr-rejected` as "you do not have access to this app", and offer no "Try again": only the app owner can change it.
|
|
74
|
-
|
|
75
|
-
An app whose only way in is log in with Softr still has a login page, with the button on it. Do not send visitors to Softr as the page loads.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.16.0
|
|
13
|
+
library_version: 1.16.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A helper that calls `ds` outside a handler goes in `createServerOnlyFn` from `@tanstack/react-start` (the `record-queries` boundary). `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -195,6 +195,8 @@ A chart can group, aggregate and `where` only on `fields`, not on `filterFields`
|
|
|
195
195
|
|
|
196
196
|
`groupBy` comes first and exactly once; a chart cannot be awaited before it. `metrics` follows, at most once, or not at all for distinct values. `where` can be chained anywhere, repeatedly, and calling it more than once ands the filters together. `orderBy` sorts by the chart's own keys, group and metric alike, and only sees the keys declared so far, so call it last.
|
|
197
197
|
|
|
198
|
+
A builder is for one read. `where` adds to the builder it is called on, so a `ds.chart` or `ds.metric` kept in a variable and read again carries the filters of the earlier read. Start each figure from its own `ds.chart` or `ds.metric`, as the dashboard load above does.
|
|
199
|
+
|
|
198
200
|
## References
|
|
199
201
|
|
|
200
202
|
- [references/aggregations.md](./references/aggregations.md): every bucket interval and its value type, and which aggregations each kind of field offers. Load it when choosing a bucket or when a field does not offer the aggregation you expected.
|
|
@@ -12,7 +12,7 @@ description: >-
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: sub-skill
|
|
14
14
|
library: softr-sdk
|
|
15
|
-
library_version: 1.16.0
|
|
15
|
+
library_version: 1.16.0
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
**Boundary.** `email` and `EmailError` live on `@softr/sdk/server` and run only inside a `createServerFn` handler — importing them into a component fails the build. `defineEmailAction` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.16.0
|
|
10
|
+
library_version: 1.16.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: 1.16.0
|
|
11
|
+
library_version: 1.16.0
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
# Dates, times and numbers
|
|
@@ -93,7 +93,7 @@ For a page or an area, wrap it in `FormattingScope`. Every `FormattedDate` and `
|
|
|
93
93
|
For one value, pass `timeZone`. It wins over a scope. Use it for an event that shows in its own zone, from a record field or a DATETIME field whose `options` in the datasource schema name a `timezone` and a `timezoneType` other than `LOCAL`.
|
|
94
94
|
|
|
95
95
|
```tsx
|
|
96
|
-
<FormattedDate value={event.fields.starts} time timeZone={event.fields.zone} />
|
|
96
|
+
<FormattedDate value={event.fields.starts} time timeZone={event.fields.zone ?? undefined} />
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
Say which zone a fixed-zone time is in, so a visitor elsewhere does not read it as theirs: add `timeZoneName: 'short'` to `parts`, or write the zone next to it. An unknown zone or locale is ignored with a warning, so a bad record never breaks the page.
|
|
@@ -108,7 +108,7 @@ function BugRow({ bug }: { bug: Bug }) {
|
|
|
108
108
|
return (
|
|
109
109
|
<li title={`Created ${formatDateTime(bug.fields.created, formatting)}`}>
|
|
110
110
|
{bug.fields.title}
|
|
111
|
-
<span>{formatNumber(bug.fields.votes, formatting)}</span>
|
|
111
|
+
<span>{bug.fields.votes === null ? '—' : formatNumber(bug.fields.votes, formatting)}</span>
|
|
112
112
|
<FormattedDate value={bug.fields.created} dateStyle="medium" />
|
|
113
113
|
</li>
|
|
114
114
|
)
|
|
@@ -166,10 +166,11 @@ For a shape the helpers do not give, such as a range (`Oct 6 – 8`), use `Intl`
|
|
|
166
166
|
|
|
167
167
|
```tsx
|
|
168
168
|
const formatting = useFormatting()
|
|
169
|
-
const
|
|
169
|
+
const { starts, ends } = trip.fields
|
|
170
|
+
const range = formatting.timeZone === null || starts === null || ends === null
|
|
170
171
|
? null
|
|
171
172
|
: new Intl.DateTimeFormat(formatting.dateLocale, { month: 'short', day: 'numeric', timeZone: formatting.timeZone })
|
|
172
|
-
.formatRange(new Date(
|
|
173
|
+
.formatRange(new Date(starts), new Date(ends))
|
|
173
174
|
```
|
|
174
175
|
|
|
175
176
|
### Relative time and now
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.16.0
|
|
10
|
+
library_version: 1.16.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.
|
|
@@ -11,10 +11,10 @@ description: >-
|
|
|
11
11
|
metadata:
|
|
12
12
|
type: sub-skill
|
|
13
13
|
library: softr-sdk
|
|
14
|
-
library_version: 1.16.0
|
|
14
|
+
library_version: 1.16.0
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
**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. The tools you hand it come from `defineTool`, also on `@softr/sdk`, and call the same server logic the pages do.
|
|
17
|
+
**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. The tools you hand it come from `defineTool`, also on `@softr/sdk`, and call the same server logic the pages do. `src/start.ts` is part of the browser bundle, so a tool's handler never calls `ds` itself: it calls a helper wrapped in `createServerOnlyFn` from `@tanstack/react-start` (the `record-queries` boundary).
|
|
18
18
|
|
|
19
19
|
# MCP
|
|
20
20
|
|
|
@@ -57,10 +57,8 @@ An action is one list, create, update or delete on one datasource. When the app
|
|
|
57
57
|
```ts
|
|
58
58
|
// src/mcp-tools.ts
|
|
59
59
|
import { defineTool } from '@softr/sdk'
|
|
60
|
-
import { ds } from '@softr/sdk/server'
|
|
61
60
|
import { z } from 'zod'
|
|
62
|
-
import { createIssueFor } from './issues'
|
|
63
|
-
import { projectIssues } from './actions'
|
|
61
|
+
import { createIssueFor, listIssues } from './issues'
|
|
64
62
|
|
|
65
63
|
export const createIssue = defineTool({
|
|
66
64
|
name: 'create_issue',
|
|
@@ -83,16 +81,30 @@ export const findIssues = defineTool({
|
|
|
83
81
|
status: z.enum(['open', 'done']).optional().describe('Only issues with this status.'),
|
|
84
82
|
}),
|
|
85
83
|
readOnly: true,
|
|
86
|
-
handler: async (input) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
handler: async (input) => ({ issues: await listIssues(input) }),
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The `ds` calls live in helpers wrapped in `createServerOnlyFn`, in a file of their own:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
// src/issues.ts
|
|
92
|
+
import { createServerOnlyFn } from '@tanstack/react-start'
|
|
93
|
+
import { ds } from '@softr/sdk/server'
|
|
94
|
+
import { projectIssues } from './actions'
|
|
95
|
+
|
|
96
|
+
export const listIssues = createServerOnlyFn(async ({ projectId, status }: { projectId: string; status?: 'open' | 'done' }) => {
|
|
97
|
+
let list = ds.list(projectIssues).where((q) => q.project.isOneOf([projectId]))
|
|
98
|
+
if (status) list = list.where((q) => q.status.is(status))
|
|
99
|
+
const { records } = await list.orderBy((q) => q.createdAt.desc).limit(50)
|
|
100
|
+
return records.map((r) => ({ id: r.id, ...r.fields }))
|
|
92
101
|
})
|
|
93
102
|
```
|
|
94
103
|
|
|
95
|
-
|
|
104
|
+
`createIssueFor` is wrapped the same way.
|
|
105
|
+
|
|
106
|
+
- **`handler` runs as the signed-in user.** The `ds` calls its helpers make act as that user, with their groups, as a click in the app would. `user` is the same `User` a server function reads from `context.user`. Move logic a server function and a tool share into a function that takes the user, and pass `context.user` from the server function and `user` from the tool.
|
|
107
|
+
- **`handler` never calls `ds` itself.** Nor anything else from `@softr/sdk/server`. Each such call goes in a helper wrapped in `createServerOnlyFn`, and the handler calls the helper. A helper the app's server functions already use is fine as long as it is wrapped.
|
|
96
108
|
- **`readOnly` is required.** `true` only when the tool changes nothing. A read-only tool that calls `ds.create`, `ds.update`, `ds.delete`, `email`, `workflow`, `upload` or an `integration` action whose method is not `GET` or `HEAD` from `@softr/sdk/server` fails with an error, and nothing is written or sent. An integration that reads with `POST`, such as a search or GraphQL API, fails too: make that tool `readOnly: false`. So does every `auth` call that is not a plain read: a sign-in, a sign-up, a password reset, a sign-out, a profile change or an authenticator change. Your own calls to other services are not stopped, so keep them out of a read-only tool too. An `ai` call is not stopped either: it changes no data, but it spends the workspace's AI credits for an assistant approved to read only, so use it there on purpose.
|
|
97
109
|
- **`destructive`** says whether a tool that is not read-only deletes or overwrites data: `true` when it does, `false` when it only adds. The assistant may ask the user before it runs a destructive one. Left out, the assistant is told neither and treats the tool as one that may delete or overwrite, so set it on every tool that is not read-only.
|
|
98
110
|
- **`input` is a zod object.** Describe each field with `.describe()`: the assistant reads it. Use types JSON can carry: a string for a date, not `z.date()`, which fails when the tool is defined. A top-level argument the schema does not name is refused with a message saying which, and the handler does not run. Inside a nested object an unknown key is dropped without a word, so declare a nested object with `z.strictObject` to have it refused too.
|
|
@@ -125,6 +137,8 @@ Connecting starts with an approval page the app serves. Most people hit it signe
|
|
|
125
137
|
|
|
126
138
|
**A write as an action, where the app has logic around it.** The record is written and everything the app does around it is skipped: no counter, no log entry, no email, no author. Write it as a `defineTool` that calls that logic.
|
|
127
139
|
|
|
140
|
+
**A tool handler that calls `ds` directly fails the production build.** `src/start.ts` imports the tool, so the server-only import reaches the browser bundle. The preview may still work, and publishing fails. Move the call into a `createServerOnlyFn` helper.
|
|
141
|
+
|
|
128
142
|
**Marking a tool read-only that changes data.** Its writes fail when it runs. Set `readOnly: false`.
|
|
129
143
|
|
|
130
144
|
**Registering after `softrAuthMiddleware`.** Not a supported order. Put the MCP middleware first.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.16.0
|
|
13
|
+
library_version: 1.16.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**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.
|
|
@@ -202,9 +202,11 @@ const projectDetail = defineQuery({
|
|
|
202
202
|
})
|
|
203
203
|
|
|
204
204
|
const project = await ds.get(projectDetail, { id })
|
|
205
|
+
if (project === null) throw notFound()
|
|
206
|
+
const status = project.fields.status
|
|
205
207
|
await ds.update(updateProject, {
|
|
206
208
|
id,
|
|
207
|
-
data: { status: { id:
|
|
209
|
+
data: { status: status === null ? null : { id: status.id } },
|
|
208
210
|
})
|
|
209
211
|
```
|
|
210
212
|
|
|
@@ -11,7 +11,7 @@ description: >-
|
|
|
11
11
|
metadata:
|
|
12
12
|
type: sub-skill
|
|
13
13
|
library: softr-sdk
|
|
14
|
-
library_version: 1.16.0
|
|
14
|
+
library_version: 1.16.0
|
|
15
15
|
---
|
|
16
16
|
|
|
17
17
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A route `loader` also runs in the browser, so it calls a server function, never `ds`. A helper that calls `ds` outside a handler, in this file or in another one, goes in `createServerOnlyFn` from `@tanstack/react-start`, or inside the handler. An exported helper without it keeps the server-only import in the browser bundle, and every page stops loading until it moves. Do not make such a helper a server function when it takes an id: any visitor can call a server function with any id. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -99,6 +99,26 @@ Calling `.where` more than once ands the filters together, and the query's `filt
|
|
|
99
99
|
.orderBy((q) => [q.views.desc, q.title.asc]) // array for tie-breakers
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
### One builder, one read
|
|
103
|
+
|
|
104
|
+
`where` and `orderBy` add to the builder they are called on and return that same builder. A builder kept in a variable carries its filters and sorts into every later read, with no error. Start each read from its own `ds.list`, `ds.get` or `ds.export`:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
// Wrong: the second read asks for open AND closed, and returns no records.
|
|
108
|
+
const list = ds.list(orders)
|
|
109
|
+
const open = await list.where((q) => q.status.is('open'))
|
|
110
|
+
const closed = await list.where((q) => q.status.is('closed'))
|
|
111
|
+
|
|
112
|
+
// Right: one builder for each read.
|
|
113
|
+
const open = await ds.list(orders).where((q) => q.status.is('open'))
|
|
114
|
+
const closed = await ds.list(orders).where((q) => q.status.is('closed'))
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- A loop with one filter per pass, such as one count per tab, starts a new builder on each pass.
|
|
118
|
+
- A second `orderBy` on the same builder only breaks the ties of the first.
|
|
119
|
+
- A reused `ds.export` builder writes a file with only the records that match every filter it collected.
|
|
120
|
+
- To add a filter only when an input is set, reassign the builder before its one read: `if (search) list = list.where(...)`, as in [Keep a large table on the server](#keep-a-large-table-on-the-server).
|
|
121
|
+
|
|
102
122
|
### Get one record
|
|
103
123
|
|
|
104
124
|
```ts
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 1.16.0
|
|
12
|
+
library_version: 1.16.0
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 1.16.0
|
|
12
|
+
library_version: 1.16.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.
|