@softr/sdk 1.9.0-alpha.0 → 1.9.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 +13 -1
- package/dist/auth/methods/authenticator.js +1 -4
- package/dist/auth/methods/code.js +1 -2
- package/dist/auth/methods/emailCode2fa.js +1 -2
- package/dist/auth/methods/magicLink.js +1 -2
- package/dist/auth/methods/password.js +1 -2
- package/dist/auth/methods/passwordLink.js +1 -3
- package/dist/auth/methods/signup.js +1 -3
- package/dist/auth/methods/social.js +1 -2
- package/dist/auth/methods/utils.d.ts +1 -1
- package/dist/auth/methods/utils.js +1 -13
- package/dist/datasource/record.js +4 -0
- package/dist/mcp.js +31 -11
- package/dist/package.js +1 -1
- package/package.json +10 -34
- package/skills/softr-sdk/SKILL.md +1 -1
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +2 -3
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
- package/skills/softr-sdk/current-user/SKILL.md +1 -1
- package/skills/softr-sdk/email/SKILL.md +4 -2
- package/skills/softr-sdk/file-uploads/SKILL.md +19 -7
- package/skills/softr-sdk/formatting/SKILL.md +1 -1
- package/skills/softr-sdk/integrations/SKILL.md +1 -1
- package/skills/softr-sdk/mcp/SKILL.md +2 -1
- 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 +26 -2
- package/skills/softr-sdk/record-queries/SKILL.md +1 -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/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
# @softr/sdk
|
|
2
2
|
|
|
3
|
+
## 1.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- record-mutations skill: write only the fields a form may change. email and file-uploads examples name each written field.
|
|
8
|
+
|
|
3
9
|
## 1.9.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
6
12
|
|
|
7
|
-
-
|
|
13
|
+
- `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.
|
|
14
|
+
|
|
15
|
+
## 1.8.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- `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.
|
|
8
20
|
|
|
9
21
|
## 1.8.0
|
|
10
22
|
|
|
@@ -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 { clearPendingAuth, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken, readSessionToken } from "../session.js";
|
|
6
|
-
import { authError
|
|
6
|
+
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/authenticator.ts
|
|
9
9
|
/**
|
|
@@ -40,7 +40,6 @@ async function startAuthenticatorSetup() {
|
|
|
40
40
|
async function confirmAuthenticatorSetup(details) {
|
|
41
41
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupComplete(readPendingAuthToken() ?? readSessionToken(), details.code);
|
|
42
42
|
if (!result.ok) {
|
|
43
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
44
43
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
45
44
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
46
45
|
if (result.status >= 500) panic(`Expected authenticator setup to finish, but got ${result.status}: ` + result.message);
|
|
@@ -66,7 +65,6 @@ async function confirmAuthenticatorSetup(details) {
|
|
|
66
65
|
async function skipAuthenticatorSetup() {
|
|
67
66
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupDismiss(readPendingAuthToken() ?? readSessionToken());
|
|
68
67
|
if (!result.ok) {
|
|
69
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
70
68
|
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
71
69
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
72
70
|
if (result.status >= 500) panic(`Expected to skip authenticator setup, but got ${result.status}: ` + result.message);
|
|
@@ -90,7 +88,6 @@ async function skipAuthenticatorSetup() {
|
|
|
90
88
|
async function verifyAuthenticator(credentials) {
|
|
91
89
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorVerify(readPendingAuthToken() ?? readSessionToken(), "code" in credentials ? { totpCode: credentials.code } : { backupCode: credentials.backupCode });
|
|
92
90
|
if (!result.ok) {
|
|
93
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
94
91
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
95
92
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
96
93
|
if (result.status >= 500) panic(`Expected to verify the authenticator, 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 { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError
|
|
6
|
+
import { authError } 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"]]);
|
|
@@ -37,7 +37,6 @@ async function sendSignInCode(details) {
|
|
|
37
37
|
async function signInWithCode(credentials) {
|
|
38
38
|
const result = await makePlatform(sessionConfig().applicationId).signInWithCode(credentials);
|
|
39
39
|
if (!result.ok) {
|
|
40
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
41
40
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
42
41
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
43
42
|
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 { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken } from "../session.js";
|
|
6
|
-
import { authError
|
|
6
|
+
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/emailCode2fa.ts
|
|
9
9
|
/**
|
|
@@ -17,7 +17,6 @@ import { authError, isUserLimitReached } from "./utils.js";
|
|
|
17
17
|
async function verifyEmailCode(details) {
|
|
18
18
|
const result = await makePlatform(sessionConfig().applicationId).emailCodeVerify(readPendingAuthToken(), details.code);
|
|
19
19
|
if (!result.ok) {
|
|
20
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
21
20
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
22
21
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
23
22
|
if (result.status >= 500) panic(`Expected to verify the emailed code, 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 { makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError
|
|
6
|
+
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/magicLink.ts
|
|
9
9
|
/**
|
|
@@ -17,7 +17,6 @@ import { authError, isUserLimitReached } from "./utils.js";
|
|
|
17
17
|
async function signInWithMagicLink(credentials) {
|
|
18
18
|
const result = await makePlatform(sessionConfig().applicationId).signInWithMagicLink(credentials);
|
|
19
19
|
if (!result.ok) {
|
|
20
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
21
20
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
22
21
|
if (result.status === 400 || result.status === 401) return authError("invalidCredentials", result.message);
|
|
23
22
|
if (result.status >= 500) panic(`Expected magic-link 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 { clearPendingAuth, clearSession, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readSessionToken } from "../session.js";
|
|
6
|
-
import { authError
|
|
6
|
+
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/password.ts
|
|
9
9
|
/**
|
|
@@ -17,7 +17,6 @@ import { authError, isUserLimitReached } from "./utils.js";
|
|
|
17
17
|
async function signIn(credentials) {
|
|
18
18
|
const result = await makePlatform(sessionConfig().applicationId).tokens(credentials);
|
|
19
19
|
if (!result.ok) {
|
|
20
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
21
20
|
if (result.status === 401) return authError("invalidCredentials", result.message);
|
|
22
21
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
23
22
|
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 { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError
|
|
6
|
+
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/passwordLink.ts
|
|
9
9
|
/**
|
|
@@ -30,7 +30,6 @@ async function requestPasswordReset(details) {
|
|
|
30
30
|
async function checkPasswordLink(details) {
|
|
31
31
|
const result = await makePlatform(sessionConfig().applicationId).checkPasswordToken(details);
|
|
32
32
|
if (!result.ok) {
|
|
33
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
34
33
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
35
34
|
if (result.status === 400 || result.status === 401) return authError("linkExpired", result.message);
|
|
36
35
|
panic(`Expected the link to be checked, but got ${result.status}: ${result.message}.`);
|
|
@@ -50,7 +49,6 @@ async function checkPasswordLink(details) {
|
|
|
50
49
|
async function setPasswordWithLink(details) {
|
|
51
50
|
const result = await makePlatform(sessionConfig().applicationId).setPassword(details);
|
|
52
51
|
if (!result.ok) {
|
|
53
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
54
52
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
55
53
|
if (result.status === 400 && result.message.startsWith("Password must be at least")) return authError("invalidDetails", result.message);
|
|
56
54
|
if (result.status === 400 || result.status === 401) return authError("linkExpired", 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 { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError
|
|
6
|
+
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/signup.ts
|
|
9
9
|
/**
|
|
@@ -14,7 +14,6 @@ import { authError, isUserLimitReached } from "./utils.js";
|
|
|
14
14
|
async function signUp(details) {
|
|
15
15
|
const result = await makePlatform(sessionConfig().applicationId).sendSignUpCode(details);
|
|
16
16
|
if (!result.ok) {
|
|
17
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
18
17
|
if (result.status === 409) return authError("emailTaken", result.message);
|
|
19
18
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
20
19
|
if (result.status === 400) return authError("invalidDetails", result.message);
|
|
@@ -47,7 +46,6 @@ async function confirmSignUp(details) {
|
|
|
47
46
|
password
|
|
48
47
|
});
|
|
49
48
|
if (!result.ok) {
|
|
50
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
51
49
|
if (result.status === 409) return authError("emailTaken", result.message);
|
|
52
50
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
53
51
|
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 { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
|
-
import { authError
|
|
6
|
+
import { authError } from "./utils.js";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
|
|
9
9
|
//#region src/auth/methods/social.ts
|
|
@@ -26,7 +26,6 @@ const errorBodySchema = z.object({ code: z.string() });
|
|
|
26
26
|
async function signInWithGoogle(credentials) {
|
|
27
27
|
const result = await makePlatform(sessionConfig().applicationId).signInWithGoogle(credentials);
|
|
28
28
|
if (!result.ok) {
|
|
29
|
-
if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
|
|
30
29
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
31
30
|
const body = errorBodySchema.safeParse(result.body);
|
|
32
31
|
if (body.success && body.data.code === "GOOGLE_NOT_IN_PLAN") return authError("notEnabled", result.message);
|
|
@@ -10,6 +10,6 @@ type AuthError = {
|
|
|
10
10
|
code: AuthErrorCode;
|
|
11
11
|
message: string;
|
|
12
12
|
};
|
|
13
|
-
type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "noAccount" | "accountDeactivated" | "notAuthenticated" | "emailDomainNotAllowed" | "notEnabled" | "linkExpired" | "invalidName" | "fileTooLarge" | "notAnImage" | "avatarNotSupported"
|
|
13
|
+
type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "noAccount" | "accountDeactivated" | "notAuthenticated" | "emailDomainNotAllowed" | "notEnabled" | "linkExpired" | "invalidName" | "fileTooLarge" | "notAnImage" | "avatarNotSupported";
|
|
14
14
|
//#endregion
|
|
15
15
|
export { AuthError, Result };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
1
|
//#region src/auth/methods/utils.ts
|
|
4
2
|
function authError(code, message) {
|
|
5
3
|
return {
|
|
@@ -10,16 +8,6 @@ function authError(code, message) {
|
|
|
10
8
|
}
|
|
11
9
|
};
|
|
12
10
|
}
|
|
13
|
-
const errorBodySchema = z.object({ code: z.string() });
|
|
14
|
-
/**
|
|
15
|
-
* True when Softr refused because the plan of the app's workspace has no room
|
|
16
|
-
* for this user. It arrives as a 400, like a wrong code, so the status cannot
|
|
17
|
-
* tell them apart.
|
|
18
|
-
*/
|
|
19
|
-
function isUserLimitReached(result) {
|
|
20
|
-
const body = errorBodySchema.safeParse(result.body);
|
|
21
|
-
return body.success && body.data.code === "USER_LIMIT_REACHED";
|
|
22
|
-
}
|
|
23
11
|
|
|
24
12
|
//#endregion
|
|
25
|
-
export { authError
|
|
13
|
+
export { authError };
|
|
@@ -187,6 +187,10 @@ async function executeGet(query, id, filters) {
|
|
|
187
187
|
filterCriteria
|
|
188
188
|
})
|
|
189
189
|
});
|
|
190
|
+
if (res.status === 404) {
|
|
191
|
+
const body = await res.clone().json().catch(() => null);
|
|
192
|
+
if (typeof body === "object" && body !== null && "type" in body && body.type === "RECORD") return null;
|
|
193
|
+
}
|
|
190
194
|
if (!res.ok) throw new Error(`datasource get failed for action "${actionId}": ${await describeFailure(res)}`);
|
|
191
195
|
const contentLength = res.headers.get("Content-Length");
|
|
192
196
|
if (contentLength && parseInt(contentLength, 10) === 0) return null;
|
package/dist/mcp.js
CHANGED
|
@@ -16,10 +16,16 @@ const AUTHORIZE_PATH = "/_softr/oauth/authorize";
|
|
|
16
16
|
const TOKEN_PATH = "/_softr/oauth/token";
|
|
17
17
|
const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource";
|
|
18
18
|
const AUTHORIZATION_SERVER_PATH = "/.well-known/oauth-authorization-server";
|
|
19
|
+
/** The scope that lets a caller run an action that is not a read. */
|
|
20
|
+
const WRITE_SCOPE = "mcp:write";
|
|
19
21
|
/** What the platform grants. Advertised here so a client asks for the same. */
|
|
20
|
-
const SCOPES = ["mcp:read",
|
|
21
|
-
/**
|
|
22
|
-
|
|
22
|
+
const SCOPES = ["mcp:read", WRITE_SCOPE];
|
|
23
|
+
/**
|
|
24
|
+
* What a client that named no scope gets: everything. Such a client chose
|
|
25
|
+
* nothing, and the Allow page never offered less. A client that wants less
|
|
26
|
+
* asks for less.
|
|
27
|
+
*/
|
|
28
|
+
const DEFAULT_SCOPE = SCOPES.join(" ");
|
|
23
29
|
const SUPPORTED_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26"];
|
|
24
30
|
/**
|
|
25
31
|
* Serves the MCP endpoint and its OAuth flow from the app's own origin.
|
|
@@ -227,14 +233,20 @@ async function platformSession(accessToken) {
|
|
|
227
233
|
ok: false,
|
|
228
234
|
refused: response.status === 401 || response.status === 403
|
|
229
235
|
};
|
|
230
|
-
const parsed = z.object({
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
236
|
+
const parsed = z.object({
|
|
237
|
+
sessionJwt: z.string(),
|
|
238
|
+
scope: z.string().nullish()
|
|
239
|
+
}).safeParse(await response.json().catch(() => null));
|
|
240
|
+
if (!parsed.success) return {
|
|
235
241
|
ok: false,
|
|
236
242
|
refused: false
|
|
237
243
|
};
|
|
244
|
+
const scopes = parsed.data.scope?.split(" ") ?? [];
|
|
245
|
+
return {
|
|
246
|
+
ok: true,
|
|
247
|
+
sessionToken: parsed.data.sessionJwt,
|
|
248
|
+
canWrite: scopes.includes(WRITE_SCOPE)
|
|
249
|
+
};
|
|
238
250
|
}
|
|
239
251
|
const WHOAMI = {
|
|
240
252
|
name: "whoami",
|
|
@@ -386,7 +398,8 @@ async function rpc(request, origin, actions) {
|
|
|
386
398
|
if (token === null) return unauthorized(origin);
|
|
387
399
|
const session = await platformSession(token);
|
|
388
400
|
if (!session.ok) return session.refused ? unauthorized(origin) : unavailable();
|
|
389
|
-
const { sessionToken } = session;
|
|
401
|
+
const { sessionToken, canWrite } = session;
|
|
402
|
+
const allowed = (action) => canWrite || action.resource.operation === "read";
|
|
390
403
|
const body = await readJson(request);
|
|
391
404
|
const message = z.object({
|
|
392
405
|
id: z.union([z.string(), z.number()]).optional(),
|
|
@@ -415,7 +428,7 @@ async function rpc(request, origin, actions) {
|
|
|
415
428
|
}
|
|
416
429
|
});
|
|
417
430
|
}
|
|
418
|
-
case "tools/list": return result(id, { tools: [WHOAMI, ...[...actions.values()].map(describeTool)] });
|
|
431
|
+
case "tools/list": return result(id, { tools: [WHOAMI, ...[...actions.values()].filter(allowed).map(describeTool)] });
|
|
419
432
|
case "tools/call": {
|
|
420
433
|
const name = params?.name;
|
|
421
434
|
const args = typeof params?.arguments === "object" && params.arguments !== null ? params.arguments : {};
|
|
@@ -426,6 +439,13 @@ async function rpc(request, origin, actions) {
|
|
|
426
439
|
}
|
|
427
440
|
const action = typeof name === "string" ? actions.get(name) : void 0;
|
|
428
441
|
if (action === void 0) return failure(id, -32602, `Unknown tool: ${String(name)}`);
|
|
442
|
+
if (!allowed(action)) return result(id, {
|
|
443
|
+
isError: true,
|
|
444
|
+
content: [{
|
|
445
|
+
type: "text",
|
|
446
|
+
text: `"${action.id}" changes data, and this assistant's connection allows reading only, so it cannot run it.`
|
|
447
|
+
}]
|
|
448
|
+
});
|
|
429
449
|
try {
|
|
430
450
|
return result(id, toolResult(await withSessionToken(sessionToken, () => runTool(action, args))));
|
|
431
451
|
} catch (error) {
|
|
@@ -472,7 +492,7 @@ function unauthorized(origin) {
|
|
|
472
492
|
status: 401,
|
|
473
493
|
headers: {
|
|
474
494
|
"content-type": "application/json",
|
|
475
|
-
"www-authenticate": `Bearer resource_metadata="${origin}${PROTECTED_RESOURCE_PATH}", scope="${
|
|
495
|
+
"www-authenticate": `Bearer resource_metadata="${origin}${PROTECTED_RESOURCE_PATH}", scope="${DEFAULT_SCOPE}"`
|
|
476
496
|
}
|
|
477
497
|
});
|
|
478
498
|
}
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,38 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softr/sdk",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"./server": {
|
|
15
|
-
"types": "./dist/server.d.ts",
|
|
16
|
-
"import": "./dist/server.js"
|
|
17
|
-
},
|
|
18
|
-
"./vite": {
|
|
19
|
-
"types": "./dist/vite.d.ts",
|
|
20
|
-
"import": "./dist/vite.js"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"bin": {
|
|
24
|
-
"softr-sdk": "./dist/cli.js"
|
|
25
|
-
},
|
|
26
|
-
"files": [
|
|
27
|
-
"dist",
|
|
28
|
-
"schema",
|
|
29
|
-
"skills",
|
|
30
|
-
"!skills/_artifacts",
|
|
31
|
-
"CHANGELOG.md"
|
|
32
|
-
],
|
|
33
|
-
"publishConfig": {
|
|
34
|
-
"access": "public"
|
|
35
|
-
},
|
|
6
|
+
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
|
|
7
|
+
"./client": { "types": "./dist/client.d.ts", "import": "./dist/client.js" },
|
|
8
|
+
"./server": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
|
|
9
|
+
"./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" }
|
|
10
|
+
},
|
|
11
|
+
"bin": { "softr-sdk": "./dist/cli.js" },
|
|
12
|
+
"files": ["dist", "schema", "skills", "!skills/_artifacts", "CHANGELOG.md"],
|
|
13
|
+
"publishConfig": { "access": "public" },
|
|
36
14
|
"scripts": {
|
|
37
15
|
"build": "tsdown",
|
|
38
16
|
"test": "node --import ./src/test-utils/setup.ts --test",
|
|
@@ -64,9 +42,7 @@
|
|
|
64
42
|
"optional": true
|
|
65
43
|
}
|
|
66
44
|
},
|
|
67
|
-
"keywords": [
|
|
68
|
-
"tanstack-intent"
|
|
69
|
-
],
|
|
45
|
+
"keywords": ["tanstack-intent"],
|
|
70
46
|
"intent": {
|
|
71
47
|
"version": 1,
|
|
72
48
|
"repo": "@softr/sdk",
|
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 1.9.
|
|
16
|
+
library_version: 1.9.1
|
|
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.9.
|
|
13
|
+
library_version: 1.9.1
|
|
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.
|
|
@@ -135,10 +135,9 @@ type AuthErrorCode =
|
|
|
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
137
|
| 'notEnabled' // signInWithGoogle: the app's plan no longer includes Google sign-in
|
|
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
138
|
```
|
|
140
139
|
|
|
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.
|
|
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.
|
|
142
141
|
|
|
143
142
|
`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
143
|
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.9.
|
|
13
|
+
library_version: 1.9.1
|
|
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.
|
|
@@ -12,7 +12,7 @@ description: >-
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: sub-skill
|
|
14
14
|
library: softr-sdk
|
|
15
|
-
library_version: 1.9.
|
|
15
|
+
library_version: 1.9.1
|
|
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.
|
|
@@ -97,7 +97,9 @@ Declare one action per kind of email: the owner's notification and the client's
|
|
|
97
97
|
const submit = createServerFn({ method: 'POST' })
|
|
98
98
|
.validator(contactSchema)
|
|
99
99
|
.handler(async ({ data }) => {
|
|
100
|
-
const saved = await ds.create(saveSubmission, {
|
|
100
|
+
const saved = await ds.create(saveSubmission, {
|
|
101
|
+
data: { name: data.name, email: data.email, message: data.message },
|
|
102
|
+
})
|
|
101
103
|
try {
|
|
102
104
|
await email.send(notifyOwner, {
|
|
103
105
|
subject: `New message from ${data.name}`,
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.9.
|
|
10
|
+
library_version: 1.9.1
|
|
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.
|
|
@@ -19,6 +19,7 @@ metadata:
|
|
|
19
19
|
## Setup
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
+
import { z } from 'zod'
|
|
22
23
|
import { defineMutation, type FileAttachment, useFileUpload, type FileItem } from '@softr/sdk'
|
|
23
24
|
import { ds } from '@softr/sdk/server'
|
|
24
25
|
```
|
|
@@ -35,9 +36,15 @@ const createApplication = defineMutation({
|
|
|
35
36
|
})
|
|
36
37
|
|
|
37
38
|
const submitApplication = createServerFn({ method: 'POST' })
|
|
38
|
-
.validator(
|
|
39
|
+
.validator(
|
|
40
|
+
z.object({
|
|
41
|
+
name: z.string(),
|
|
42
|
+
// Zod drops a field the schema leaves out. `.nullish()` is how a record's attachment reads.
|
|
43
|
+
resume: z.array(z.object({ url: z.string(), filename: z.string().nullish(), id: z.string().nullish(), type: z.string().nullish() })),
|
|
44
|
+
}),
|
|
45
|
+
)
|
|
39
46
|
.handler(async ({ data }) => {
|
|
40
|
-
await ds.create(createApplication, { data })
|
|
47
|
+
await ds.create(createApplication, { data: { name: data.name, resume: data.resume } })
|
|
41
48
|
})
|
|
42
49
|
|
|
43
50
|
function ApplicationForm() {
|
|
@@ -130,8 +137,10 @@ const loadApplication = createServerFn({ method: 'GET' })
|
|
|
130
137
|
return record
|
|
131
138
|
})
|
|
132
139
|
|
|
140
|
+
const Attachment = z.object({ url: z.string(), filename: z.string().nullish(), id: z.string().nullish(), type: z.string().nullish() })
|
|
141
|
+
|
|
133
142
|
const saveApplication = createServerFn({ method: 'POST' })
|
|
134
|
-
.validator((
|
|
143
|
+
.validator(z.object({ id: z.string(), resume: z.array(Attachment), photo: Attachment.nullable() }))
|
|
135
144
|
.handler(async ({ data }) => {
|
|
136
145
|
await ds.update(updateApplication, { id: data.id, data: { resume: data.resume, photo: data.photo } })
|
|
137
146
|
})
|
|
@@ -177,14 +186,17 @@ Pre-loaded attachments appear as `status: 'done'` items at the start of `files`.
|
|
|
177
186
|
For server-side use (no progress tracking needed) or plain HTML forms, use `upload` directly:
|
|
178
187
|
|
|
179
188
|
```ts
|
|
189
|
+
import { z } from 'zod'
|
|
180
190
|
import { upload, ds } from '@softr/sdk/server'
|
|
181
191
|
|
|
192
|
+
const Application = z.object({ fullName: z.string().min(1), cv: z.instanceof(File) })
|
|
193
|
+
|
|
182
194
|
const submitResume = createServerFn({ method: 'POST' })
|
|
183
|
-
.validator((fields: FormData) => fields)
|
|
195
|
+
.validator((fields: FormData) => Application.parse({ fullName: fields.get('fullName'), cv: fields.get('cv') }))
|
|
184
196
|
.handler(async ({ data }) => {
|
|
185
|
-
const uploaded = await upload(createApplication, data.
|
|
197
|
+
const uploaded = await upload(createApplication, data.cv)
|
|
186
198
|
await ds.create(createApplication, {
|
|
187
|
-
data: { fullName: data.
|
|
199
|
+
data: { fullName: data.fullName, cv: [uploaded] }, // cv holds several files; a one-file field takes `uploaded` itself
|
|
188
200
|
})
|
|
189
201
|
return new Response(null, { status: 303, headers: { Location: '/thank-you' } })
|
|
190
202
|
})
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.9.
|
|
10
|
+
library_version: 1.9.1
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
**Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 1.9.
|
|
12
|
+
library_version: 1.9.1
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP.
|
|
@@ -53,6 +53,7 @@ The list is the whole tool surface. Write it out:
|
|
|
53
53
|
|
|
54
54
|
- An action you leave out is invisible to the assistant, even where the app's pages use it freely.
|
|
55
55
|
- An action you list still obeys its own `permissions`. Listing it does not widen who may run it — the assistant runs as whoever signed in, with that user's groups.
|
|
56
|
+
- A write reaches only an assistant the user allowed to make changes when they connected it. One allowed to read only sees the reads and `whoami`.
|
|
56
57
|
- Two actions with the same `id` throw at startup. So does anything that is not a `defineQuery` or `defineMutation` value.
|
|
57
58
|
|
|
58
59
|
Reads first. Add a write only when the user asked for one, and name it back to them.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.9.
|
|
13
|
+
library_version: 1.9.1
|
|
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.
|
|
@@ -28,7 +28,7 @@ import { defineMutation } from '@softr/sdk'
|
|
|
28
28
|
import { ds } from '@softr/sdk/server'
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
A write's input arrives from the client, so validate it
|
|
31
|
+
A write's input arrives from the client, so validate it with a zod schema. Pass the schema straight to `.validator`; Start accepts it and types `data` from it. A typed function such as `(data: T) => data` checks nothing.
|
|
32
32
|
|
|
33
33
|
## Declare the write
|
|
34
34
|
|
|
@@ -142,6 +142,30 @@ A visitor who is signed out, or a user with no value for the token, changes noth
|
|
|
142
142
|
|
|
143
143
|
A create into a table that belongs to the visitor through its parent, such as a message in a chat, reads the parent through its filtered query before `ds.create` (see [record-queries](../record-queries/SKILL.md#a-table-that-belongs-to-the-visitor-through-its-parent)).
|
|
144
144
|
|
|
145
|
+
### Write only what the form may change
|
|
146
|
+
|
|
147
|
+
The browser can send any key. The datasource accepts every field the mutation declares. A form that shows two fields can therefore set a third one the mutation declares.
|
|
148
|
+
|
|
149
|
+
Declare one mutation per form, with only the fields that form edits. A second form that edits other fields gets its own mutation.
|
|
150
|
+
|
|
151
|
+
Validate with a zod schema that lists exactly those fields. Then name each field in `data`. Never pass the input on whole, and never spread it. Set a field the visitor must not choose, such as the owner, a status or a price, on the server, from `context` or a constant.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
// Wrong: the input goes in whole, so the browser decides every field the mutation declares.
|
|
155
|
+
const saveProfile = createServerFn({ method: 'POST' })
|
|
156
|
+
.validator((data: { id: string; name: string }) => data)
|
|
157
|
+
.handler(({ data }) => ds.update(updateProfile, { id: data.id, data }))
|
|
158
|
+
|
|
159
|
+
// Right: the schema lists the form's fields, and `data` names each one.
|
|
160
|
+
const ProfileForm = z.object({ id: z.string(), name: z.string(), bio: z.string() })
|
|
161
|
+
|
|
162
|
+
const saveProfile = createServerFn({ method: 'POST' })
|
|
163
|
+
.validator(ProfileForm)
|
|
164
|
+
.handler(({ data }) => ds.update(updateProfile, { id: data.id, data: { name: data.name, bio: data.bio } }))
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The lint rules `@softr/write-require-validator` and `@softr/write-no-raw-input` warn about both mistakes.
|
|
168
|
+
|
|
145
169
|
### Only the roles that change a table
|
|
146
170
|
|
|
147
171
|
Often fewer roles change a table than read it. A mutation's `customGroups` names only the roles that may change the table, also when more roles read it. In a barber app, every client reads the free hours, but only barbers open or close them. A barber also changes only their own slots. The read of slots has no filter, because every client reads every slot, so the update filters on the slot's barber:
|
|
@@ -11,7 +11,7 @@ description: >-
|
|
|
11
11
|
metadata:
|
|
12
12
|
type: sub-skill
|
|
13
13
|
library: softr-sdk
|
|
14
|
-
library_version: 1.9.
|
|
14
|
+
library_version: 1.9.1
|
|
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.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 1.9.
|
|
12
|
+
library_version: 1.9.1
|
|
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.9.
|
|
12
|
+
library_version: 1.9.1
|
|
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.
|