@softr/sdk 1.14.0 → 1.15.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 +16 -0
- package/dist/auth/methods/authenticator.js +8 -1
- package/dist/auth/methods/code.js +3 -1
- package/dist/auth/methods/emailCode2fa.js +3 -1
- package/dist/auth/methods/magicLink.js +2 -1
- package/dist/auth/methods/password.js +3 -1
- package/dist/auth/methods/passwordLink.js +3 -1
- package/dist/auth/methods/profile.js +3 -1
- package/dist/auth/methods/signup.js +3 -1
- package/dist/auth/methods/social.js +2 -1
- package/dist/auth/platform.js +14 -8
- package/dist/auth/session.js +18 -3
- package/dist/core/email.js +2 -1
- package/dist/core/file-upload.js +2 -1
- package/dist/core/integration.js +4 -2
- package/dist/core/workflow.js +2 -1
- package/dist/datasource/record.js +4 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/mcp.d.ts +9 -2
- package/dist/mcp.js +102 -22
- package/dist/package.js +1 -1
- package/dist/tool.d.ts +64 -0
- package/dist/tool.js +51 -0
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +1 -1
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +1 -1
- 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 +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 +75 -17
- 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 +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,5 +1,21 @@
|
|
|
1
1
|
# @softr/sdk
|
|
2
2
|
|
|
3
|
+
## 1.15.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Skills: the formatting and record-mutations examples check a nullable field before they use it, so they pass the type check as written.
|
|
8
|
+
|
|
9
|
+
## 1.15.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- `defineTool` declares an MCP tool that runs the app's own logic as the signed-in user, labelled read-only or not.
|
|
14
|
+
- `softrMcpMiddleware` takes `tools` next to `actions`.
|
|
15
|
+
- A read-only tool cannot change data or send anything through `ds`, `email`, `workflow`, `upload`, an `integration` call that is not a GET or HEAD, or an `auth` call that changes data, sends an email or signs somebody in.
|
|
16
|
+
- Tools built from `actions` carry read-only and destructive hints. An update or a delete is marked destructive.
|
|
17
|
+
- The MCP `whoami` tool names the user's groups, once the platform sends the names.
|
|
18
|
+
|
|
3
19
|
## 1.14.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -2,7 +2,7 @@ import { assert, panic } from "../../assertions.js";
|
|
|
2
2
|
import { writeCookies } from "../../cookies.js";
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
|
-
import { clearPendingAuth, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken, readSessionToken } from "../session.js";
|
|
5
|
+
import { assertCanChange, clearPendingAuth, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken, readSessionToken } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/authenticator.ts
|
|
@@ -19,6 +19,7 @@ import { authError } from "./utils.js";
|
|
|
19
19
|
* one. Only the newest one enrols them.
|
|
20
20
|
*/
|
|
21
21
|
async function startAuthenticatorSetup() {
|
|
22
|
+
assertCanChange("auth.startAuthenticatorSetup");
|
|
22
23
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupInit(readPendingAuthToken() ?? readSessionToken());
|
|
23
24
|
if (!result.ok) {
|
|
24
25
|
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
@@ -38,6 +39,7 @@ async function startAuthenticatorSetup() {
|
|
|
38
39
|
* once. Nothing fetches them again, so render them before leaving the page.
|
|
39
40
|
*/
|
|
40
41
|
async function confirmAuthenticatorSetup(details) {
|
|
42
|
+
assertCanChange("auth.confirmAuthenticatorSetup");
|
|
41
43
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupComplete(readPendingAuthToken() ?? readSessionToken(), details.code);
|
|
42
44
|
if (!result.ok) {
|
|
43
45
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
@@ -63,6 +65,7 @@ async function confirmAuthenticatorSetup(details) {
|
|
|
63
65
|
* Later sign-ins stop asking.
|
|
64
66
|
*/
|
|
65
67
|
async function skipAuthenticatorSetup() {
|
|
68
|
+
assertCanChange("auth.skipAuthenticatorSetup");
|
|
66
69
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupDismiss(readPendingAuthToken() ?? readSessionToken());
|
|
67
70
|
if (!result.ok) {
|
|
68
71
|
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
@@ -86,6 +89,7 @@ async function skipAuthenticatorSetup() {
|
|
|
86
89
|
* Each backup code works once.
|
|
87
90
|
*/
|
|
88
91
|
async function verifyAuthenticator(credentials) {
|
|
92
|
+
assertCanChange("auth.verifyAuthenticator");
|
|
89
93
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorVerify(readPendingAuthToken() ?? readSessionToken(), "code" in credentials ? { totpCode: credentials.code } : { backupCode: credentials.backupCode });
|
|
90
94
|
if (!result.ok) {
|
|
91
95
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
@@ -110,6 +114,7 @@ async function verifyAuthenticator(credentials) {
|
|
|
110
114
|
* on top of being signed in.
|
|
111
115
|
*/
|
|
112
116
|
async function sendAuthenticatorResetCode() {
|
|
117
|
+
assertCanChange("auth.sendAuthenticatorResetCode");
|
|
113
118
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorSendResetCode(readSessionToken());
|
|
114
119
|
if (!result.ok) {
|
|
115
120
|
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
@@ -129,6 +134,7 @@ async function sendAuthenticatorResetCode() {
|
|
|
129
134
|
* `code` is the one {@link sendAuthenticatorResetCode} emailed.
|
|
130
135
|
*/
|
|
131
136
|
async function resetAuthenticator(details) {
|
|
137
|
+
assertCanChange("auth.resetAuthenticator");
|
|
132
138
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorReset(readSessionToken(), details.code);
|
|
133
139
|
if (!result.ok) {
|
|
134
140
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
@@ -149,6 +155,7 @@ async function resetAuthenticator(details) {
|
|
|
149
155
|
* sign-in.
|
|
150
156
|
*/
|
|
151
157
|
async function removeAuthenticator(details) {
|
|
158
|
+
assertCanChange("auth.removeAuthenticator");
|
|
152
159
|
const result = await makePlatform(sessionConfig().applicationId).authenticatorRemove(readSessionToken(), details.code);
|
|
153
160
|
if (!result.ok) {
|
|
154
161
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
@@ -2,7 +2,7 @@ import { assert, panic } from "../../assertions.js";
|
|
|
2
2
|
import { writeCookies } from "../../cookies.js";
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
|
-
import { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
5
|
+
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/code.ts
|
|
@@ -15,6 +15,7 @@ const SEND_CODE_ERRORS = new Map([["No account exists for this email.", "noAccou
|
|
|
15
15
|
* `accountDeactivated`, so the visitor is not left waiting for an email.
|
|
16
16
|
*/
|
|
17
17
|
async function sendSignInCode(details) {
|
|
18
|
+
assertCanChange("auth.sendSignInCode");
|
|
18
19
|
const result = await makePlatform(sessionConfig().applicationId).sendSignInCode(details.email);
|
|
19
20
|
if (!result.ok) {
|
|
20
21
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
@@ -35,6 +36,7 @@ async function sendSignInCode(details) {
|
|
|
35
36
|
* to send them to next.
|
|
36
37
|
*/
|
|
37
38
|
async function signInWithCode(credentials) {
|
|
39
|
+
assertCanChange("auth.signInWithCode");
|
|
38
40
|
const result = await makePlatform(sessionConfig().applicationId).signInWithCode(credentials);
|
|
39
41
|
if (!result.ok) {
|
|
40
42
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
@@ -2,7 +2,7 @@ import { assert, panic } from "../../assertions.js";
|
|
|
2
2
|
import { writeCookies } from "../../cookies.js";
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
|
-
import { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken } from "../session.js";
|
|
5
|
+
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/emailCode2fa.ts
|
|
@@ -15,6 +15,7 @@ import { authError } from "./utils.js";
|
|
|
15
15
|
* to send them to next.
|
|
16
16
|
*/
|
|
17
17
|
async function verifyEmailCode(details) {
|
|
18
|
+
assertCanChange("auth.verifyEmailCode");
|
|
18
19
|
const result = await makePlatform(sessionConfig().applicationId).emailCodeVerify(readPendingAuthToken(), details.code);
|
|
19
20
|
if (!result.ok) {
|
|
20
21
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
@@ -51,6 +52,7 @@ async function verifyEmailCode(details) {
|
|
|
51
52
|
* short wait sends nothing and still succeeds.
|
|
52
53
|
*/
|
|
53
54
|
async function resendEmailCode() {
|
|
55
|
+
assertCanChange("auth.resendEmailCode");
|
|
54
56
|
const result = await makePlatform(sessionConfig().applicationId).emailCodeResend(readPendingAuthToken());
|
|
55
57
|
if (!result.ok) {
|
|
56
58
|
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
@@ -2,7 +2,7 @@ import { assert, panic } from "../../assertions.js";
|
|
|
2
2
|
import { writeCookies } from "../../cookies.js";
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
|
-
import { makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
5
|
+
import { assertCanChange, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/magicLink.ts
|
|
@@ -15,6 +15,7 @@ import { authError } from "./utils.js";
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
async function signInWithMagicLink(credentials) {
|
|
18
|
+
assertCanChange("auth.signInWithMagicLink");
|
|
18
19
|
const result = await makePlatform(sessionConfig().applicationId).signInWithMagicLink(credentials);
|
|
19
20
|
if (!result.ok) {
|
|
20
21
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
@@ -2,7 +2,7 @@ import { assert, panic, softAssert } from "../../assertions.js";
|
|
|
2
2
|
import { writeCookies } from "../../cookies.js";
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
|
-
import { clearPendingAuth, clearSession, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readSessionToken } from "../session.js";
|
|
5
|
+
import { assertCanChange, clearPendingAuth, clearSession, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readSessionToken } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/password.ts
|
|
@@ -15,6 +15,7 @@ import { authError } from "./utils.js";
|
|
|
15
15
|
* `emailCodeRequired`; `verifyEmailCode` finishes it.
|
|
16
16
|
*/
|
|
17
17
|
async function signIn(credentials) {
|
|
18
|
+
assertCanChange("auth.signIn");
|
|
18
19
|
const result = await makePlatform(sessionConfig().applicationId).tokens(credentials);
|
|
19
20
|
if (!result.ok) {
|
|
20
21
|
if (result.status === 401) return authError("invalidCredentials", result.message);
|
|
@@ -57,6 +58,7 @@ async function signIn(credentials) {
|
|
|
57
58
|
* is no per-device sign-out.
|
|
58
59
|
*/
|
|
59
60
|
async function signOut() {
|
|
61
|
+
assertCanChange("auth.signOut");
|
|
60
62
|
const token = readSessionToken();
|
|
61
63
|
clearSession();
|
|
62
64
|
if (!token) return;
|
|
@@ -2,7 +2,7 @@ import { assert, panic } from "../../assertions.js";
|
|
|
2
2
|
import { writeCookies } from "../../cookies.js";
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
|
-
import { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
5
|
+
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/passwordLink.ts
|
|
@@ -13,6 +13,7 @@ import { authError } from "./utils.js";
|
|
|
13
13
|
* it has none.
|
|
14
14
|
*/
|
|
15
15
|
async function requestPasswordReset(details) {
|
|
16
|
+
assertCanChange("auth.requestPasswordReset");
|
|
16
17
|
const result = await makePlatform(sessionConfig().applicationId).forgotPassword(details);
|
|
17
18
|
if (!result.ok) {
|
|
18
19
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
@@ -47,6 +48,7 @@ async function checkPasswordLink(details) {
|
|
|
47
48
|
* the visitor's other sessions.
|
|
48
49
|
*/
|
|
49
50
|
async function setPasswordWithLink(details) {
|
|
51
|
+
assertCanChange("auth.setPasswordWithLink");
|
|
50
52
|
const result = await makePlatform(sessionConfig().applicationId).setPassword(details);
|
|
51
53
|
if (!result.ok) {
|
|
52
54
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assert, panic } from "../../assertions.js";
|
|
2
2
|
import { sessionConfig } from "../config.js";
|
|
3
3
|
import { makePlatform } from "../platform.js";
|
|
4
|
-
import { clearSessionData, readSessionToken } from "../session.js";
|
|
4
|
+
import { assertCanChange, clearSessionData, readSessionToken } from "../session.js";
|
|
5
5
|
import { authError } from "./utils.js";
|
|
6
6
|
|
|
7
7
|
//#region src/auth/methods/profile.ts
|
|
@@ -25,6 +25,7 @@ import { authError } from "./utils.js";
|
|
|
25
25
|
* const result = await auth.updateProfile({ avatar: file })
|
|
26
26
|
*/
|
|
27
27
|
async function updateProfile(changes) {
|
|
28
|
+
assertCanChange("auth.updateProfile");
|
|
28
29
|
assert(changes.fullName !== void 0 || changes.avatar !== void 0, "updateProfile needs a name or a photo to change");
|
|
29
30
|
const token = readSessionToken();
|
|
30
31
|
if (token === null) return authError("notAuthenticated", "Nobody is signed in.");
|
|
@@ -44,6 +45,7 @@ async function updateProfile(changes) {
|
|
|
44
45
|
* const result = await auth.removeAvatar()
|
|
45
46
|
*/
|
|
46
47
|
async function removeAvatar() {
|
|
48
|
+
assertCanChange("auth.removeAvatar");
|
|
47
49
|
const token = readSessionToken();
|
|
48
50
|
if (token === null) return authError("notAuthenticated", "Nobody is signed in.");
|
|
49
51
|
return answer(await makePlatform(sessionConfig().applicationId).removeAvatar(token), "invalidPhoto");
|
|
@@ -2,7 +2,7 @@ import { assert, panic } from "../../assertions.js";
|
|
|
2
2
|
import { writeCookies } from "../../cookies.js";
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
|
-
import { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
5
|
+
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/methods/signup.ts
|
|
@@ -12,6 +12,7 @@ import { authError } from "./utils.js";
|
|
|
12
12
|
* User only exists once `confirmSignUp` returns the code.
|
|
13
13
|
*/
|
|
14
14
|
async function signUp(details) {
|
|
15
|
+
assertCanChange("auth.signUp");
|
|
15
16
|
const result = await makePlatform(sessionConfig().applicationId).sendSignUpCode(details);
|
|
16
17
|
if (!result.ok) {
|
|
17
18
|
if (result.status === 409) return authError("emailTaken", result.message);
|
|
@@ -39,6 +40,7 @@ async function signUp(details) {
|
|
|
39
40
|
* to send them to next.
|
|
40
41
|
*/
|
|
41
42
|
async function confirmSignUp(details) {
|
|
43
|
+
assertCanChange("auth.confirmSignUp");
|
|
42
44
|
const platform = makePlatform(sessionConfig().applicationId);
|
|
43
45
|
const { password,...rest } = details;
|
|
44
46
|
const result = password === void 0 ? await platform.signUpWithCode(rest) : await platform.signUpWithPassword({
|
|
@@ -2,7 +2,7 @@ import { assert, panic } from "../../assertions.js";
|
|
|
2
2
|
import { writeCookies } from "../../cookies.js";
|
|
3
3
|
import { sessionConfig } from "../config.js";
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
|
-
import { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
5
|
+
import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
|
|
@@ -24,6 +24,7 @@ const errorBodySchema = z.object({ code: z.string() });
|
|
|
24
24
|
* sign-in, as after a downgrade.
|
|
25
25
|
*/
|
|
26
26
|
async function signInWithGoogle(credentials) {
|
|
27
|
+
assertCanChange("auth.signInWithGoogle");
|
|
27
28
|
const result = await makePlatform(sessionConfig().applicationId).signInWithGoogle(credentials);
|
|
28
29
|
if (!result.ok) {
|
|
29
30
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
package/dist/auth/platform.js
CHANGED
|
@@ -72,16 +72,18 @@ function makePlatform(applicationId) {
|
|
|
72
72
|
}),
|
|
73
73
|
returnPath: z.string()
|
|
74
74
|
});
|
|
75
|
+
async function readSession(token, user) {
|
|
76
|
+
const result = await request(`/v1/vibe/applications/${applicationId}/users/session${withAttributes}`, {
|
|
77
|
+
method: "GET",
|
|
78
|
+
token
|
|
79
|
+
}, z.object({ user: user.nullable() }));
|
|
80
|
+
if (result.status === 404) panic(`Application ${applicationId} not found. Check SOFTR_APPLICATION_ID.`);
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
75
83
|
return {
|
|
76
84
|
authSettings: () => request(`/v1/vibe/applications/${applicationId}/users/auth-settings`, { method: "GET" }, authSettingsSchema),
|
|
77
|
-
session:
|
|
78
|
-
|
|
79
|
-
method: "GET",
|
|
80
|
-
token
|
|
81
|
-
}, z.object({ user: userSchema.nullable() }));
|
|
82
|
-
if (result.status === 404) panic(`Application ${applicationId} not found. Check SOFTR_APPLICATION_ID.`);
|
|
83
|
-
return result;
|
|
84
|
-
},
|
|
85
|
+
session: (token) => readSession(token, userSchema),
|
|
86
|
+
sessionWithGroupNames: (token) => readSession(token, z.intersection(userSchema, userGroupNamesSchema)),
|
|
85
87
|
tokens: (credentials) => request(`/v1/vibe/applications/${applicationId}/users/tokens${withAttributes}`, {
|
|
86
88
|
method: "POST",
|
|
87
89
|
json: credentials
|
|
@@ -369,6 +371,10 @@ function makePlatform(applicationId) {
|
|
|
369
371
|
};
|
|
370
372
|
}
|
|
371
373
|
const errorSchema = z.object({ message: z.string() });
|
|
374
|
+
const userGroupNamesSchema = z.object({ userGroups: z.array(z.object({
|
|
375
|
+
id: z.string(),
|
|
376
|
+
name: z.string().nullable()
|
|
377
|
+
})).optional() });
|
|
372
378
|
async function request(path, init, schema, parse = (response$1) => response$1.json()) {
|
|
373
379
|
assert(init.json === void 0 || init.form === void 0, "A platform request carries a JSON body or a form, not both");
|
|
374
380
|
const response = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}${path}`, {
|
package/dist/auth/session.js
CHANGED
|
@@ -47,8 +47,23 @@ function sessionCookie(base) {
|
|
|
47
47
|
* For requests that carry who they are somewhere other than the cookie: an MCP
|
|
48
48
|
* call authenticates with a bearer token and has no cookie at all.
|
|
49
49
|
*/
|
|
50
|
-
function withSessionToken(token, fn) {
|
|
51
|
-
return standIn.run({
|
|
50
|
+
function withSessionToken(token, fn, options = {}) {
|
|
51
|
+
return standIn.run({
|
|
52
|
+
token,
|
|
53
|
+
readOnly: options.readOnly === true,
|
|
54
|
+
user: options.user && Promise.resolve(options.user)
|
|
55
|
+
}, fn);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Throws inside a read-only {@link withSessionToken} scope. Every SDK call that
|
|
59
|
+
* changes data, sends something or signs somebody in calls it first.
|
|
60
|
+
*
|
|
61
|
+
* An MCP tool marked read-only runs in such a scope. So an assistant the user
|
|
62
|
+
* approved to read only can't change data through those calls, whatever the
|
|
63
|
+
* tool's code does. The SDK `mcp` skill lists what is covered and what is not.
|
|
64
|
+
*/
|
|
65
|
+
function assertCanChange(what) {
|
|
66
|
+
if (standIn.getStore()?.readOnly === true) panic(`${what} is not allowed in a read-only tool.`);
|
|
52
67
|
}
|
|
53
68
|
/**
|
|
54
69
|
* The visitor of the token that {@link withSessionToken} stands in, fetched once
|
|
@@ -284,4 +299,4 @@ function openEnvelope(raw, purpose) {
|
|
|
284
299
|
}
|
|
285
300
|
|
|
286
301
|
//#endregion
|
|
287
|
-
export { clearPendingAuth, clearSession, clearSessionData, clearSsoBinding, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, makeSsoBindingCookie, readFreshUser, readPendingAuthToken, readSessionData, readSessionToken, readSsoBinding, readStandInUser, withSessionToken };
|
|
302
|
+
export { assertCanChange, clearPendingAuth, clearSession, clearSessionData, clearSsoBinding, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, makeSsoBindingCookie, readFreshUser, readPendingAuthToken, readSessionData, readSessionToken, readSsoBinding, readStandInUser, withSessionToken };
|
package/dist/core/email.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { softrApiUrl } from "../softr-api.js";
|
|
2
2
|
import { fetch } from "../fetch.js";
|
|
3
3
|
import { sessionConfig } from "../auth/config.js";
|
|
4
|
-
import { readSessionToken } from "../auth/session.js";
|
|
4
|
+
import { assertCanChange, readSessionToken } from "../auth/session.js";
|
|
5
5
|
|
|
6
6
|
//#region src/core/email.ts
|
|
7
7
|
const EMAIL_ERROR_CODES = [
|
|
@@ -46,6 +46,7 @@ var EmailError = class extends Error {
|
|
|
46
46
|
};
|
|
47
47
|
/** Sends one email through the action. Never retries by itself. */
|
|
48
48
|
async function sendEmail(action, init) {
|
|
49
|
+
assertCanChange(`Email "${action.id}"`);
|
|
49
50
|
const { to, cc, bcc, replyTo, subject, body } = init;
|
|
50
51
|
const sessionToken = readSessionToken();
|
|
51
52
|
let res;
|
package/dist/core/file-upload.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { softrApiUrl } from "../softr-api.js";
|
|
2
2
|
import { fetch } from "../fetch.js";
|
|
3
3
|
import { sessionConfig } from "../auth/config.js";
|
|
4
|
-
import { readSessionToken } from "../auth/session.js";
|
|
4
|
+
import { assertCanChange, readSessionToken } from "../auth/session.js";
|
|
5
5
|
import { describeFailure } from "../datasource/record.js";
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
|
|
8
8
|
//#region src/core/file-upload.ts
|
|
9
9
|
async function upload(action, file) {
|
|
10
|
+
assertCanChange(`Upload "${action.id}"`);
|
|
10
11
|
const { applicationId } = sessionConfig();
|
|
11
12
|
const baseUrl = softrApiUrl("SOFTR_PLATFORM_API_URL");
|
|
12
13
|
const uploadUrl = new URL(`${baseUrl}/v1/vibe/applications/${applicationId}/actions/${action.id}/uploads`);
|
package/dist/core/integration.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { fetch } from "../fetch.js";
|
|
2
|
-
import { readSessionToken } from "../auth/session.js";
|
|
2
|
+
import { assertCanChange, readSessionToken } from "../auth/session.js";
|
|
3
3
|
import { dsUrl, refererHeader } from "../datasource/record.js";
|
|
4
4
|
|
|
5
5
|
//#region src/core/integration.ts
|
|
6
6
|
async function integrationFetch(action, { params, query, headers = {}, body, signal } = {}) {
|
|
7
7
|
if (signal?.aborted) throw signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
8
|
+
const method = action.resource.method;
|
|
9
|
+
if (method !== "GET" && method !== "HEAD") assertCanChange(`Integration "${action.id}"`);
|
|
8
10
|
const payload = {
|
|
9
|
-
method
|
|
11
|
+
method,
|
|
10
12
|
url: buildUrl(action.resource.url, params, query),
|
|
11
13
|
headers
|
|
12
14
|
};
|
package/dist/core/workflow.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { softrApiUrl } from "../softr-api.js";
|
|
2
2
|
import { fetch } from "../fetch.js";
|
|
3
3
|
import { sessionConfig } from "../auth/config.js";
|
|
4
|
-
import { readSessionToken } from "../auth/session.js";
|
|
4
|
+
import { assertCanChange, readSessionToken } from "../auth/session.js";
|
|
5
5
|
import { describeFailure } from "../datasource/record.js";
|
|
6
6
|
|
|
7
7
|
//#region src/core/workflow.ts
|
|
8
8
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
9
|
async function triggerWorkflow(action, payload) {
|
|
10
|
+
assertCanChange(`Workflow "${action.id}"`);
|
|
10
11
|
const triggerRes = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/workflow`, {
|
|
11
12
|
method: "POST",
|
|
12
13
|
headers: {
|
|
@@ -3,7 +3,7 @@ import { softrApiUrl } from "../softr-api.js";
|
|
|
3
3
|
import { fetch } from "../fetch.js";
|
|
4
4
|
import { softrConfig } from "../softr-config.js";
|
|
5
5
|
import { readUserTimezone } from "../cookies.js";
|
|
6
|
-
import { readFreshUser, readSessionToken, readStandInUser } from "../auth/session.js";
|
|
6
|
+
import { assertCanChange, readFreshUser, readSessionToken, readStandInUser } from "../auth/session.js";
|
|
7
7
|
import { andGroups, buildFilterCriteria, buildOrderBy, dealiasFilterCriteria, dealiasOrderBy } from "./filter.js";
|
|
8
8
|
import { andAll, makeFieldSet, makeSortSet } from "./fields.js";
|
|
9
9
|
import { filterForVisitor, readsVisitor } from "./enforced-filter.js";
|
|
@@ -283,6 +283,7 @@ async function executeGet(query, id, filters) {
|
|
|
283
283
|
* })
|
|
284
284
|
*/
|
|
285
285
|
async function createRecord(action, options) {
|
|
286
|
+
assertCanChange(`ds.create "${action.id}"`);
|
|
286
287
|
const { actionId, select } = resolveTarget(action, "create");
|
|
287
288
|
const data = options.data;
|
|
288
289
|
const rawFields = dealiasData(data, select);
|
|
@@ -313,6 +314,7 @@ async function createRecord(action, options) {
|
|
|
313
314
|
* })
|
|
314
315
|
*/
|
|
315
316
|
async function updateRecord(action, options) {
|
|
317
|
+
assertCanChange(`ds.update "${action.id}"`);
|
|
316
318
|
if (!options.id) throw new Error(`datasource update: id must not be empty`);
|
|
317
319
|
const target = resolveTarget(action, "update");
|
|
318
320
|
const { actionId, select } = target;
|
|
@@ -343,6 +345,7 @@ async function updateRecord(action, options) {
|
|
|
343
345
|
* await ds.delete(removePost, { id: "record-id" })
|
|
344
346
|
*/
|
|
345
347
|
async function deleteRecord(action, options) {
|
|
348
|
+
assertCanChange(`ds.delete "${action.id}"`);
|
|
346
349
|
const target = resolveTarget(action, "delete");
|
|
347
350
|
const { actionId } = target;
|
|
348
351
|
await requireFilterMatch(target, options.id, "delete");
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { toReturnPath } from "./auth/returnPath.js";
|
|
|
14
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
|
+
import { Tool, ToolDefinition, defineTool } from "./tool.js";
|
|
17
18
|
import { softrMcpMiddleware } from "./mcp.js";
|
|
18
19
|
import { FieldShape, SoftrFieldRegistry, fieldShape, formatDuration, formatField, formatValue, registerSoftrFields } from "./fields/format.js";
|
|
19
20
|
import { useOverrides } from "./core/use-overrides.js";
|
|
@@ -24,4 +25,4 @@ import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
|
24
25
|
import { Audience } from "./route/audience.js";
|
|
25
26
|
import { Logo, LogoFile } from "./softr-config.schema.js";
|
|
26
27
|
import { getLogo } from "./softr-config.js";
|
|
27
|
-
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 User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, 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 };
|
|
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
|
@@ -11,6 +11,7 @@ import { SoftrPwaHead, usePwaInstall } from "./pwa.js";
|
|
|
11
11
|
import { usePushNotifications } from "./push.js";
|
|
12
12
|
import { AuthSettingsProvider, getAuthSettings, getSoftrContext, initialSoftrContext, softrAuthMiddleware, useAuthSettings, useCurrentUser } from "./auth/isomorphic.js";
|
|
13
13
|
import { useIdleTimeout } from "./auth/idle-timeout.js";
|
|
14
|
+
import { defineTool } from "./tool.js";
|
|
14
15
|
import { softrMcpMiddleware } from "./mcp.js";
|
|
15
16
|
import { fieldShape, formatDuration, formatField, formatValue, registerSoftrFields } from "./fields/format.js";
|
|
16
17
|
import { useOverrides } from "./core/use-overrides.js";
|
|
@@ -18,4 +19,4 @@ import { useUserTimezone } from "./timezone.js";
|
|
|
18
19
|
import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
19
20
|
import { Audience } from "./route/audience.js";
|
|
20
21
|
|
|
21
|
-
export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, 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 };
|
|
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,4 +1,5 @@
|
|
|
1
1
|
import { DatasourceAction } from "./action.js";
|
|
2
|
+
import { Tool } from "./tool.js";
|
|
2
3
|
import * as _tanstack_react_start10 from "@tanstack/react-start";
|
|
3
4
|
|
|
4
5
|
//#region src/mcp.d.ts
|
|
@@ -12,6 +13,11 @@ type SoftrMcpOptions = {
|
|
|
12
13
|
* decide who may run the ones that are listed.
|
|
13
14
|
*/
|
|
14
15
|
actions?: Array<DatasourceAction>;
|
|
16
|
+
/**
|
|
17
|
+
* Tools that run the app's own logic, from `defineTool`. Listed the same way
|
|
18
|
+
* as `actions`, and their names share one namespace with the action ids.
|
|
19
|
+
*/
|
|
20
|
+
tools?: Array<Tool>;
|
|
15
21
|
};
|
|
16
22
|
/**
|
|
17
23
|
* Serves the MCP endpoint and its OAuth flow from the app's own origin.
|
|
@@ -22,11 +28,12 @@ type SoftrMcpOptions = {
|
|
|
22
28
|
* request. Everything else passes straight through.
|
|
23
29
|
*
|
|
24
30
|
* @example
|
|
25
|
-
* import { publishedPosts
|
|
31
|
+
* import { publishedPosts } from './actions'
|
|
32
|
+
* import { createIssue } from './mcp-tools'
|
|
26
33
|
*
|
|
27
34
|
* export const startInstance = createStart(() => ({
|
|
28
35
|
* requestMiddleware: [
|
|
29
|
-
* softrMcpMiddleware({ actions: [publishedPosts,
|
|
36
|
+
* softrMcpMiddleware({ actions: [publishedPosts], tools: [createIssue] }),
|
|
30
37
|
* softrAuthMiddleware(),
|
|
31
38
|
* ],
|
|
32
39
|
* }))
|