@softr/sdk 1.16.0-se23079.0 → 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 +8 -1
- package/dist/auth/methods/authenticator.js +5 -4
- package/dist/auth/methods/code.d.ts +0 -3
- package/dist/auth/methods/code.js +2 -4
- package/dist/auth/methods/emailCode2fa.js +3 -3
- package/dist/auth/methods/magicLink.js +2 -1
- package/dist/auth/methods/password.js +2 -2
- package/dist/auth/methods/passwordLink.js +2 -1
- package/dist/auth/methods/signup.js +3 -1
- package/dist/auth/methods/social.js +2 -5
- package/dist/auth/methods/utils.d.ts +3 -2
- package/dist/auth/methods/utils.js +11 -3
- package/dist/package.js +1 -1
- package/dist/tool.d.ts +7 -2
- package/dist/tool.js +1 -0
- package/package.json +43 -16
- package/skills/softr-sdk/auth/SKILL.md +2 -2
- package/skills/softr-sdk/mcp/SKILL.md +25 -11
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,14 @@
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- 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.
|
|
8
|
-
-
|
|
8
|
+
- `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.
|
|
9
|
+
- 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.
|
|
10
|
+
|
|
11
|
+
## 1.15.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 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.
|
|
9
16
|
|
|
10
17
|
## 1.15.3
|
|
11
18
|
|
|
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
|
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { assertCanChange, clearPendingAuth, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken, readSessionToken } from "../session.js";
|
|
6
|
-
import { authError,
|
|
6
|
+
import { authError, isAuthenticatorNotInPlan, isUserLimitReached } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/authenticator.ts
|
|
9
9
|
/**
|
|
@@ -22,6 +22,7 @@ async function startAuthenticatorSetup() {
|
|
|
22
22
|
assertCanChange("auth.startAuthenticatorSetup");
|
|
23
23
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupInit(readPendingAuthToken() ?? readSessionToken());
|
|
24
24
|
if (!result.ok) {
|
|
25
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
25
26
|
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
26
27
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
27
28
|
if (result.status >= 500) panic(`Expected authenticator setup to start, but got ${result.status}: ` + result.message);
|
|
@@ -43,7 +44,7 @@ async function confirmAuthenticatorSetup(details) {
|
|
|
43
44
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupComplete(readPendingAuthToken() ?? readSessionToken(), details.code);
|
|
44
45
|
if (!result.ok) {
|
|
45
46
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
46
|
-
if (
|
|
47
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
47
48
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
48
49
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
49
50
|
if (result.status >= 500) panic(`Expected authenticator setup to finish, but got ${result.status}: ` + result.message);
|
|
@@ -71,7 +72,7 @@ async function skipAuthenticatorSetup() {
|
|
|
71
72
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupDismiss(readPendingAuthToken() ?? readSessionToken());
|
|
72
73
|
if (!result.ok) {
|
|
73
74
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
74
|
-
if (
|
|
75
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
75
76
|
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
76
77
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
77
78
|
if (result.status >= 500) panic(`Expected to skip authenticator setup, but got ${result.status}: ` + result.message);
|
|
@@ -97,7 +98,7 @@ async function verifyAuthenticator(credentials) {
|
|
|
97
98
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorVerify(readPendingAuthToken() ?? readSessionToken(), "code" in credentials ? { totpCode: credentials.code } : { backupCode: credentials.backupCode });
|
|
98
99
|
if (!result.ok) {
|
|
99
100
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
100
|
-
if (
|
|
101
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
101
102
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
102
103
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
103
104
|
if (result.status >= 500) panic(`Expected to verify the authenticator, but got ${result.status}: ` + result.message);
|
|
@@ -9,9 +9,6 @@ import { AuthError, Result } from "./utils.js";
|
|
|
9
9
|
*
|
|
10
10
|
* An address with no account fails as `noAccount`, and a deactivated one as
|
|
11
11
|
* `accountDeactivated`, so the visitor is not left waiting for an email.
|
|
12
|
-
*
|
|
13
|
-
* It fails as `notEnabled` when the app's plan no longer includes one-time
|
|
14
|
-
* email codes, as after a downgrade.
|
|
15
12
|
*/
|
|
16
13
|
declare function sendSignInCode(details: {
|
|
17
14
|
email: string;
|
|
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
|
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
6
|
+
import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/code.ts
|
|
9
9
|
const SEND_CODE_ERRORS = new Map([["No account exists for this email.", "noAccount"], ["This account is deactivated. Please contact the application owner.", "accountDeactivated"]]);
|
|
@@ -13,9 +13,6 @@ const SEND_CODE_ERRORS = new Map([["No account exists for this email.", "noAccou
|
|
|
13
13
|
*
|
|
14
14
|
* An address with no account fails as `noAccount`, and a deactivated one as
|
|
15
15
|
* `accountDeactivated`, so the visitor is not left waiting for an email.
|
|
16
|
-
*
|
|
17
|
-
* It fails as `notEnabled` when the app's plan no longer includes one-time
|
|
18
|
-
* email codes, as after a downgrade.
|
|
19
16
|
*/
|
|
20
17
|
async function sendSignInCode(details) {
|
|
21
18
|
assertCanChange("auth.sendSignInCode");
|
|
@@ -44,6 +41,7 @@ async function signInWithCode(credentials) {
|
|
|
44
41
|
const result = await makePlatform(sessionConfig().applicationId).signInWithCode(credentials);
|
|
45
42
|
if (!result.ok) {
|
|
46
43
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
44
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
47
45
|
if (isNotInPlan(result)) return authError("notEnabled", result.message);
|
|
48
46
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
49
47
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
|
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken } from "../session.js";
|
|
6
|
-
import { authError, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
6
|
+
import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/emailCode2fa.ts
|
|
9
9
|
/**
|
|
@@ -19,7 +19,7 @@ async function verifyEmailCode(details) {
|
|
|
19
19
|
const result = await makePlatform(sessionConfig().applicationId).emailCodeVerify(readPendingAuthToken(), details.code);
|
|
20
20
|
if (!result.ok) {
|
|
21
21
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
22
|
-
if (isNotInPlan(result)) return authError("
|
|
22
|
+
if (isAuthenticatorNotInPlan(result) || isNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
23
23
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
24
24
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
25
25
|
if (result.status >= 500) panic(`Expected to verify the emailed code, but got ${result.status}: ` + result.message);
|
|
@@ -57,7 +57,7 @@ async function resendEmailCode() {
|
|
|
57
57
|
assertCanChange("auth.resendEmailCode");
|
|
58
58
|
const result = await makePlatform(sessionConfig().applicationId).emailCodeResend(readPendingAuthToken());
|
|
59
59
|
if (!result.ok) {
|
|
60
|
-
if (isNotInPlan(result)) return authError("
|
|
60
|
+
if (isAuthenticatorNotInPlan(result) || isNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
61
61
|
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
62
62
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
63
63
|
if (result.status >= 500) panic(`Expected the code to be emailed again, but got ${result.status}: ` + result.message);
|
|
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
|
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { assertCanChange, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
6
|
+
import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/magicLink.ts
|
|
9
9
|
/**
|
|
@@ -19,6 +19,7 @@ async function signInWithMagicLink(credentials) {
|
|
|
19
19
|
const result = await makePlatform(sessionConfig().applicationId).signInWithMagicLink(credentials);
|
|
20
20
|
if (!result.ok) {
|
|
21
21
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
22
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
22
23
|
if (isNotInPlan(result)) return authError("notEnabled", result.message);
|
|
23
24
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
24
25
|
if (result.status === 400 || result.status === 401) return authError("invalidCredentials", result.message);
|
|
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
|
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { assertCanChange, clearPendingAuth, clearSession, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readSessionToken } from "../session.js";
|
|
6
|
-
import { authError, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
6
|
+
import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/password.ts
|
|
9
9
|
/**
|
|
@@ -19,7 +19,7 @@ async function signIn(credentials) {
|
|
|
19
19
|
const result = await makePlatform(sessionConfig().applicationId).tokens(credentials);
|
|
20
20
|
if (!result.ok) {
|
|
21
21
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
22
|
-
if (isNotInPlan(result)) return authError("
|
|
22
|
+
if (isAuthenticatorNotInPlan(result) || isNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
23
23
|
if (result.status === 401) return authError("invalidCredentials", result.message);
|
|
24
24
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
25
25
|
if (result.status >= 500) panic(`Expected sign-in to succeed, but got ${result.status}: ` + result.message);
|
|
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
|
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
6
|
+
import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/passwordLink.ts
|
|
9
9
|
/**
|
|
@@ -53,6 +53,7 @@ async function setPasswordWithLink(details) {
|
|
|
53
53
|
const result = await makePlatform(sessionConfig().applicationId).setPassword(details);
|
|
54
54
|
if (!result.ok) {
|
|
55
55
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
56
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
56
57
|
if (isNotInPlan(result)) return authError("notEnabled", result.message);
|
|
57
58
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
58
59
|
if (result.status === 400 && result.message.startsWith("Password must be at least")) return authError("invalidDetails", result.message);
|
|
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
|
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
6
|
+
import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/signup.ts
|
|
9
9
|
/**
|
|
@@ -16,6 +16,7 @@ async function signUp(details) {
|
|
|
16
16
|
const result = await makePlatform(sessionConfig().applicationId).sendSignUpCode(details);
|
|
17
17
|
if (!result.ok) {
|
|
18
18
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
19
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
19
20
|
if (isNotInPlan(result)) return authError("notEnabled", result.message);
|
|
20
21
|
if (result.status === 409) return authError("emailTaken", result.message);
|
|
21
22
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
@@ -51,6 +52,7 @@ async function confirmSignUp(details) {
|
|
|
51
52
|
});
|
|
52
53
|
if (!result.ok) {
|
|
53
54
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
55
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
54
56
|
if (isNotInPlan(result)) return authError("notEnabled", result.message);
|
|
55
57
|
if (result.status === 409) return authError("emailTaken", result.message);
|
|
56
58
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
@@ -3,11 +3,9 @@ import { writeCookies } from "../../cookies.js";
|
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
7
|
-
import { z } from "zod";
|
|
6
|
+
import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
|
|
8
7
|
|
|
9
8
|
//#region src/auth/methods/social.ts
|
|
10
|
-
const errorBodySchema = z.object({ code: z.string() });
|
|
11
9
|
/**
|
|
12
10
|
* Signs a visitor in with a Google token the browser obtained, creating their
|
|
13
11
|
* account the first time.
|
|
@@ -28,10 +26,9 @@ async function signInWithGoogle(credentials) {
|
|
|
28
26
|
const result = await makePlatform(sessionConfig().applicationId).signInWithGoogle(credentials);
|
|
29
27
|
if (!result.ok) {
|
|
30
28
|
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
29
|
+
if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
|
|
31
30
|
if (isNotInPlan(result)) return authError("notEnabled", result.message);
|
|
32
31
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
33
|
-
const body = errorBodySchema.safeParse(result.body);
|
|
34
|
-
if (body.success && body.data.code === "GOOGLE_NOT_IN_PLAN") return authError("notEnabled", result.message);
|
|
35
32
|
if (result.status === 400 && result.message.startsWith("Emails with ") && result.message.endsWith(" domain is not allowed to signup.")) return authError("emailDomainNotAllowed", result.message);
|
|
36
33
|
if (result.status === 400 || result.status === 401) return authError("invalidCredentials", result.message);
|
|
37
34
|
if (result.status >= 500) panic(`Expected Google sign-in to succeed, but got ${result.status}: ` + result.message);
|
|
@@ -11,7 +11,8 @@ type AuthError = {
|
|
|
11
11
|
message: string;
|
|
12
12
|
};
|
|
13
13
|
type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "noAccount" | "accountDeactivated" | "notAuthenticated" | "emailDomainNotAllowed"
|
|
14
|
-
/** The plan of the app's workspace no longer includes this way to sign in, as after a downgrade. */ | "notEnabled" | "linkExpired" | "invalidName" | "invalidPhoto" | "fileTooLarge" | "notAnImage" | "avatarNotSupported"
|
|
15
|
-
/** Any call that signs a visitor in or up: the plan of the app's workspace has no room for this user. */ | "userLimitReached"
|
|
14
|
+
/** The plan of the app's workspace no longer includes this way to sign in, as after a downgrade. Another way in can still work. */ | "notEnabled" | "linkExpired" | "invalidName" | "invalidPhoto" | "fileTooLarge" | "notAnImage" | "avatarNotSupported"
|
|
15
|
+
/** Any call that signs a visitor in or up: the plan of the app's workspace has no room for this user. */ | "userLimitReached"
|
|
16
|
+
/** The visitor owes a second step that the plan of the app's workspace no longer includes. No way in works until the app owner changes the plan. */ | "secondFactorNotEnabled";
|
|
16
17
|
//#endregion
|
|
17
18
|
export { AuthError, Result };
|
|
@@ -22,13 +22,21 @@ function isUserLimitReached(result) {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* True when Softr refused because the plan of the app's workspace does not
|
|
25
|
-
* include
|
|
25
|
+
* include this way to sign in: Google sign-in or the one-time email code, as
|
|
26
26
|
* after a downgrade.
|
|
27
27
|
*/
|
|
28
28
|
function isNotInPlan(result) {
|
|
29
29
|
const body = errorBodySchema.safeParse(result.body);
|
|
30
|
-
return body.success && (body.data.code === "
|
|
30
|
+
return body.success && (body.data.code === "GOOGLE_NOT_IN_PLAN" || body.data.code === "EMAIL_CODE_NOT_IN_PLAN");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* True when Softr refused because the visitor owes an authenticator app step
|
|
34
|
+
* that the plan of the app's workspace does not include, as after a downgrade.
|
|
35
|
+
*/
|
|
36
|
+
function isAuthenticatorNotInPlan(result) {
|
|
37
|
+
const body = errorBodySchema.safeParse(result.body);
|
|
38
|
+
return body.success && body.data.code === "AUTHENTICATOR_NOT_IN_PLAN";
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
//#endregion
|
|
34
|
-
export { authError, isNotInPlan, isUserLimitReached };
|
|
42
|
+
export { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached };
|
package/dist/package.js
CHANGED
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-se23079.
|
|
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
|
+
}
|
|
@@ -134,11 +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
138
|
| 'userLimitReached' // any call that signs a visitor in or up: the plan of the app's workspace has no room for this user
|
|
139
139
|
```
|
|
140
140
|
|
|
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.
|
|
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.
|
|
142
142
|
|
|
143
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.
|
|
144
144
|
|
|
@@ -14,7 +14,7 @@ metadata:
|
|
|
14
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.
|