@softr/sdk 0.0.91-alpha.1 → 0.0.92-emailotc.0
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/dist/auth/methods/emailCode2fa.d.ts +34 -0
- package/dist/auth/methods/emailCode2fa.js +71 -0
- package/dist/auth/methods/password.d.ts +4 -1
- package/dist/auth/methods/password.js +6 -1
- package/dist/auth/platform.js +25 -0
- package/dist/auth/server.d.ts +3 -0
- package/dist/auth/server.js +4 -1
- package/dist/datasource/record.js +3 -12
- package/dist/default-error-overlay.d.ts +2 -2
- package/dist/formatting.d.ts +3 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/mcp.d.ts +4 -17
- package/dist/mcp.js +18 -61
- package/dist/package.js +1 -1
- package/package.json +33 -10
- package/skills/softr-sdk/SKILL.md +1 -5
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +31 -3
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
- package/skills/softr-sdk/current-user/SKILL.md +5 -3
- package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
- package/skills/softr-sdk/formatting/SKILL.md +1 -1
- package/skills/softr-sdk/integrations/SKILL.md +11 -9
- package/skills/softr-sdk/mcp/SKILL.md +1 -16
- package/skills/softr-sdk/pwa/SKILL.md +1 -1
- package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
- package/skills/softr-sdk/record-queries/SKILL.md +1 -1
- package/skills/softr-sdk/record-queries/references/filters-and-sorting.md +2 -0
- package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +6 -4
- package/skills/softr-sdk/workflows/SKILL.md +1 -1
- package/dist/agent/agent-fns.d.ts +0 -30
- package/dist/agent/agent-fns.js +0 -215
- package/dist/agent/use-agent-chat.d.ts +0 -106
- package/dist/agent/use-agent-chat.js +0 -486
- package/skills/softr-sdk/agent-chat/SKILL.md +0 -110
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { User } from "../user.js";
|
|
2
|
+
import { AuthError, Result } from "./utils.js";
|
|
3
|
+
|
|
4
|
+
//#region src/auth/methods/emailCode2fa.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Finishes a sign-in that answered `emailCodeRequired`, with the code emailed
|
|
8
|
+
* to the visitor.
|
|
9
|
+
*
|
|
10
|
+
* A `signedIn` result means the visitor is signed in. An app that also asks for
|
|
11
|
+
* an authenticator app answers `authenticatorRequired` instead, naming the step
|
|
12
|
+
* to send them to next.
|
|
13
|
+
*/
|
|
14
|
+
declare function verifyEmailCode(details: {
|
|
15
|
+
code: string;
|
|
16
|
+
}): Promise<Result<{
|
|
17
|
+
status: "signedIn";
|
|
18
|
+
user: User;
|
|
19
|
+
} | {
|
|
20
|
+
status: "authenticatorRequired";
|
|
21
|
+
/**
|
|
22
|
+
* `verify`: they have an authenticator app and owe a code.
|
|
23
|
+
* `setup`: the app requires one and they have none yet.
|
|
24
|
+
* `setupOptional`: same, except they may skip it instead.
|
|
25
|
+
*/
|
|
26
|
+
step: "verify" | "setup" | "setupOptional";
|
|
27
|
+
}, AuthError>>;
|
|
28
|
+
/**
|
|
29
|
+
* Emails the code for {@link verifyEmailCode} again. Asking again within a
|
|
30
|
+
* short wait sends nothing and still succeeds.
|
|
31
|
+
*/
|
|
32
|
+
declare function resendEmailCode(): Promise<Result<null, AuthError>>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { resendEmailCode, verifyEmailCode };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { assert, panic } from "../../assertions.js";
|
|
2
|
+
import { writeCookies } from "../../cookies.js";
|
|
3
|
+
import { sessionConfig } from "../config.js";
|
|
4
|
+
import { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken } from "../session.js";
|
|
5
|
+
import { makePlatform } from "../platform.js";
|
|
6
|
+
import { authError } from "./utils.js";
|
|
7
|
+
|
|
8
|
+
//#region src/auth/methods/emailCode2fa.ts
|
|
9
|
+
/**
|
|
10
|
+
* Finishes a sign-in that answered `emailCodeRequired`, with the code emailed
|
|
11
|
+
* to the visitor.
|
|
12
|
+
*
|
|
13
|
+
* A `signedIn` result means the visitor is signed in. An app that also asks for
|
|
14
|
+
* an authenticator app answers `authenticatorRequired` instead, naming the step
|
|
15
|
+
* to send them to next.
|
|
16
|
+
*/
|
|
17
|
+
async function verifyEmailCode(details) {
|
|
18
|
+
const result = await makePlatform(sessionConfig().applicationId).emailCodeVerify(readPendingAuthToken(), details.code);
|
|
19
|
+
if (!result.ok) {
|
|
20
|
+
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
21
|
+
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
22
|
+
if (result.status >= 500) panic(`Expected to verify the emailed code, but got ${result.status}: ` + result.message);
|
|
23
|
+
throw new Error(`${result.message}. Check SOFTR_APPLICATION_ID and that the app asks for an emailed code at sign-in.`);
|
|
24
|
+
}
|
|
25
|
+
if (result.data.status === "MFA_REQUIRED") {
|
|
26
|
+
const { mfa } = result.data;
|
|
27
|
+
assert(mfa, "Expected a challenge from verification, but got none");
|
|
28
|
+
writeCookies([makePendingAuthCookie(mfa.challengeToken)]);
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
data: {
|
|
32
|
+
status: "authenticatorRequired",
|
|
33
|
+
step: mfa.action === "VERIFICATION_REQUIRED" ? "verify" : mfa.action === "SETUP_REQUIRED" ? "setup" : "setupOptional"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const { session } = result.data;
|
|
38
|
+
assert(session, "Expected a session from verification, but got none");
|
|
39
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
40
|
+
user: session.user,
|
|
41
|
+
permissions: session.permissions
|
|
42
|
+
}, session.jwt)]);
|
|
43
|
+
clearPendingAuth();
|
|
44
|
+
return {
|
|
45
|
+
success: true,
|
|
46
|
+
data: {
|
|
47
|
+
status: "signedIn",
|
|
48
|
+
user: session.user
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Emails the code for {@link verifyEmailCode} again. Asking again within a
|
|
54
|
+
* short wait sends nothing and still succeeds.
|
|
55
|
+
*/
|
|
56
|
+
async function resendEmailCode() {
|
|
57
|
+
const result = await makePlatform(sessionConfig().applicationId).emailCodeResend(readPendingAuthToken());
|
|
58
|
+
if (!result.ok) {
|
|
59
|
+
if (result.status === 401) return authError("notAuthenticated", result.message);
|
|
60
|
+
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
61
|
+
if (result.status >= 500) panic(`Expected the code to be emailed again, but got ${result.status}: ` + result.message);
|
|
62
|
+
throw new Error(`${result.message}. Check SOFTR_APPLICATION_ID and that the app asks for an emailed code at sign-in.`);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
success: true,
|
|
66
|
+
data: null
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { resendEmailCode, verifyEmailCode };
|
|
@@ -8,7 +8,8 @@ import { AuthError, Result } from "./utils.js";
|
|
|
8
8
|
*
|
|
9
9
|
* A `signedIn` result means the visitor is signed in. An app that also asks for
|
|
10
10
|
* an authenticator app answers `authenticatorRequired` instead, naming the step
|
|
11
|
-
* to send them to next.
|
|
11
|
+
* to send them to next. An app that also asks for an emailed code answers
|
|
12
|
+
* `emailCodeRequired`; `verifyEmailCode` finishes it.
|
|
12
13
|
*/
|
|
13
14
|
declare function signIn(credentials: {
|
|
14
15
|
email: string;
|
|
@@ -24,6 +25,8 @@ declare function signIn(credentials: {
|
|
|
24
25
|
* `setupOptional`: same, except they may skip it instead.
|
|
25
26
|
*/
|
|
26
27
|
step: "verify" | "setup" | "setupOptional";
|
|
28
|
+
} | {
|
|
29
|
+
status: "emailCodeRequired";
|
|
27
30
|
}, AuthError>>;
|
|
28
31
|
/**
|
|
29
32
|
* Signs the visitor out.
|
|
@@ -11,7 +11,8 @@ import { authError } from "./utils.js";
|
|
|
11
11
|
*
|
|
12
12
|
* A `signedIn` result means the visitor is signed in. An app that also asks for
|
|
13
13
|
* an authenticator app answers `authenticatorRequired` instead, naming the step
|
|
14
|
-
* to send them to next.
|
|
14
|
+
* to send them to next. An app that also asks for an emailed code answers
|
|
15
|
+
* `emailCodeRequired`; `verifyEmailCode` finishes it.
|
|
15
16
|
*/
|
|
16
17
|
async function signIn(credentials) {
|
|
17
18
|
const result = await makePlatform(sessionConfig().applicationId).tokens(credentials);
|
|
@@ -25,6 +26,10 @@ async function signIn(credentials) {
|
|
|
25
26
|
const { mfa } = result.data;
|
|
26
27
|
assert(mfa, "Expected a challenge from sign-in, but got none");
|
|
27
28
|
writeCookies([makePendingAuthCookie(mfa.challengeToken)]);
|
|
29
|
+
if (mfa.action === "EMAIL_CODE_REQUIRED") return {
|
|
30
|
+
success: true,
|
|
31
|
+
data: { status: "emailCodeRequired" }
|
|
32
|
+
};
|
|
28
33
|
return {
|
|
29
34
|
success: true,
|
|
30
35
|
data: {
|
package/dist/auth/platform.js
CHANGED
|
@@ -71,6 +71,27 @@ function makePlatform(applicationId) {
|
|
|
71
71
|
tokens: (credentials) => request(`/v1/vibe/applications/${applicationId}/users/tokens${withAttributes}`, {
|
|
72
72
|
method: "POST",
|
|
73
73
|
json: credentials
|
|
74
|
+
}, z.object({
|
|
75
|
+
status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
|
|
76
|
+
session: z.object({
|
|
77
|
+
jwt: z.string(),
|
|
78
|
+
user: userSchema,
|
|
79
|
+
permissions: permissionsSchema
|
|
80
|
+
}).nullish(),
|
|
81
|
+
mfa: z.object({
|
|
82
|
+
action: z.enum([
|
|
83
|
+
"VERIFICATION_REQUIRED",
|
|
84
|
+
"SETUP_REQUIRED",
|
|
85
|
+
"SETUP_OPTIONAL",
|
|
86
|
+
"EMAIL_CODE_REQUIRED"
|
|
87
|
+
]),
|
|
88
|
+
challengeToken: z.string()
|
|
89
|
+
}).nullish()
|
|
90
|
+
})),
|
|
91
|
+
emailCodeVerify: (token, code) => request(`/v1/vibe/applications/${applicationId}/users/tokens/email-code/verify${withAttributes}`, {
|
|
92
|
+
method: "POST",
|
|
93
|
+
token,
|
|
94
|
+
json: { code }
|
|
74
95
|
}, z.object({
|
|
75
96
|
status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
|
|
76
97
|
session: z.object({
|
|
@@ -87,6 +108,10 @@ function makePlatform(applicationId) {
|
|
|
87
108
|
challengeToken: z.string()
|
|
88
109
|
}).nullish()
|
|
89
110
|
})),
|
|
111
|
+
emailCodeResend: (token) => request(`/v1/vibe/applications/${applicationId}/users/tokens/email-code/resend`, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
token
|
|
114
|
+
}, z.null()),
|
|
90
115
|
sendSignInCode: (email) => request(`/v1/vibe/applications/${applicationId}/users/tokens/send-code`, {
|
|
91
116
|
method: "POST",
|
|
92
117
|
json: { email }
|
package/dist/auth/server.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { confirmAuthenticatorSetup, removeAuthenticator, resetAuthenticator, sendAuthenticatorResetCode, skipAuthenticatorSetup, startAuthenticatorSetup, verifyAuthenticator } from "./methods/authenticator.js";
|
|
2
2
|
import { sendSignInCode, signInWithCode } from "./methods/code.js";
|
|
3
|
+
import { resendEmailCode, verifyEmailCode } from "./methods/emailCode2fa.js";
|
|
3
4
|
import { signInWithMagicLink } from "./methods/magicLink.js";
|
|
4
5
|
import { signIn, signOut } from "./methods/password.js";
|
|
5
6
|
import { checkPasswordLink, requestPasswordReset, setPasswordWithLink } from "./methods/passwordLink.js";
|
|
@@ -34,6 +35,8 @@ declare const auth: {
|
|
|
34
35
|
sendAuthenticatorResetCode: typeof sendAuthenticatorResetCode;
|
|
35
36
|
resetAuthenticator: typeof resetAuthenticator;
|
|
36
37
|
removeAuthenticator: typeof removeAuthenticator;
|
|
38
|
+
verifyEmailCode: typeof verifyEmailCode;
|
|
39
|
+
resendEmailCode: typeof resendEmailCode;
|
|
37
40
|
settings: typeof settings;
|
|
38
41
|
updateProfile: typeof updateProfile;
|
|
39
42
|
removeAvatar: typeof removeAvatar;
|
package/dist/auth/server.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { settings } from "./methods/settings.js";
|
|
2
|
-
import { currentUserRow } from "./current-user-row.js";
|
|
3
2
|
import { confirmAuthenticatorSetup, removeAuthenticator, resetAuthenticator, sendAuthenticatorResetCode, skipAuthenticatorSetup, startAuthenticatorSetup, verifyAuthenticator } from "./methods/authenticator.js";
|
|
4
3
|
import { sendSignInCode, signInWithCode } from "./methods/code.js";
|
|
4
|
+
import { resendEmailCode, verifyEmailCode } from "./methods/emailCode2fa.js";
|
|
5
5
|
import { signInWithMagicLink } from "./methods/magicLink.js";
|
|
6
6
|
import { signIn, signOut } from "./methods/password.js";
|
|
7
7
|
import { checkPasswordLink, requestPasswordReset, setPasswordWithLink } from "./methods/passwordLink.js";
|
|
8
8
|
import { confirmSignUp, signUp } from "./methods/signup.js";
|
|
9
9
|
import { signInWithGoogle } from "./methods/social.js";
|
|
10
10
|
import { removeAvatar, updateProfile } from "./methods/profile.js";
|
|
11
|
+
import { currentUserRow } from "./current-user-row.js";
|
|
11
12
|
import "@tanstack/react-start/server-only";
|
|
12
13
|
|
|
13
14
|
//#region src/auth/server.ts
|
|
@@ -33,6 +34,8 @@ const auth = {
|
|
|
33
34
|
sendAuthenticatorResetCode,
|
|
34
35
|
resetAuthenticator,
|
|
35
36
|
removeAuthenticator,
|
|
37
|
+
verifyEmailCode,
|
|
38
|
+
resendEmailCode,
|
|
36
39
|
settings,
|
|
37
40
|
updateProfile,
|
|
38
41
|
removeAvatar,
|
|
@@ -30,15 +30,6 @@ function refererHeader() {
|
|
|
30
30
|
const referer = getRequestHeader("referer");
|
|
31
31
|
return { Referer: referer !== void 0 && URL.parse(referer)?.origin === page.origin ? referer : page.href };
|
|
32
32
|
}
|
|
33
|
-
/** A datasource call the service refused. `status` is its HTTP status. */
|
|
34
|
-
var DatasourceError = class extends Error {
|
|
35
|
-
status;
|
|
36
|
-
constructor(message, status) {
|
|
37
|
-
super(message);
|
|
38
|
-
this.name = "DatasourceError";
|
|
39
|
-
this.status = status;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
33
|
async function describeFailure(res) {
|
|
43
34
|
const body = await res.json().catch(() => null);
|
|
44
35
|
const message = typeof body === "object" && body !== null && "message" in body ? body.message : null;
|
|
@@ -244,7 +235,7 @@ async function updateRecord(action, options) {
|
|
|
244
235
|
},
|
|
245
236
|
body: JSON.stringify({ fields: rawFields })
|
|
246
237
|
});
|
|
247
|
-
if (!res.ok) throw new
|
|
238
|
+
if (!res.ok) throw new Error(`datasource update failed for action "${actionId}": ${await describeFailure(res)}`);
|
|
248
239
|
const record = await res.json();
|
|
249
240
|
return {
|
|
250
241
|
id: record.id,
|
|
@@ -266,7 +257,7 @@ async function deleteRecord(action, options) {
|
|
|
266
257
|
...refererHeader()
|
|
267
258
|
}
|
|
268
259
|
});
|
|
269
|
-
if (!res.ok) throw new
|
|
260
|
+
if (!res.ok) throw new Error(`datasource delete failed for action "${actionId}": ${await describeFailure(res)}`);
|
|
270
261
|
}
|
|
271
262
|
function resolveTarget(subject, operation) {
|
|
272
263
|
const declaredBy = operation === "read" ? "defineQuery" : "defineMutation";
|
|
@@ -290,4 +281,4 @@ function dealiasData(data, select) {
|
|
|
290
281
|
}
|
|
291
282
|
|
|
292
283
|
//#endregion
|
|
293
|
-
export {
|
|
284
|
+
export { createRecord, deleteRecord, describeFailure, dsUrl, getRecord, listRecords, refererHeader, resolveTarget, updateRecord };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react2 from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/default-error-overlay.d.ts
|
|
4
4
|
type Props = {
|
|
@@ -8,6 +8,6 @@ type Props = {
|
|
|
8
8
|
declare function DefaultErrorOverlay({
|
|
9
9
|
error,
|
|
10
10
|
reset
|
|
11
|
-
}: Props):
|
|
11
|
+
}: Props): react2.JSX.Element;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { DefaultErrorOverlay };
|
package/dist/formatting.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react3 from "react";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
|
|
5
5
|
//#region src/formatting.d.ts
|
|
@@ -94,7 +94,7 @@ declare function FormattingScope({
|
|
|
94
94
|
/** A BCP 47 locale, such as `de-DE`. It drops the app's fixed date format inside the scope. */
|
|
95
95
|
locale?: string;
|
|
96
96
|
children?: ReactNode;
|
|
97
|
-
}):
|
|
97
|
+
}): react3.FunctionComponentElement<react3.ProviderProps<Scope>>;
|
|
98
98
|
/**
|
|
99
99
|
* A date in the app's format, safe to render on the server. A timestamp whose
|
|
100
100
|
* zone is not known yet renders `fallback` until the browser supplies it, so
|
|
@@ -115,6 +115,6 @@ declare function FormattedDate({
|
|
|
115
115
|
time?: boolean;
|
|
116
116
|
/** What renders while the visitor's zone is unknown. */
|
|
117
117
|
fallback?: ReactNode;
|
|
118
|
-
}):
|
|
118
|
+
}): react3.FunctionComponentElement<react3.FragmentProps>;
|
|
119
119
|
//#endregion
|
|
120
120
|
export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,5 @@ import { useOverrides } from "./core/use-overrides.js";
|
|
|
17
17
|
import { useUserTimezone } from "./timezone.js";
|
|
18
18
|
import { PwaInstall, PwaPlatform, SoftrPwaHead, usePwaInstall } from "./pwa.js";
|
|
19
19
|
import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
20
|
-
import { Agent, AgentChatSummary, listAgents } from "./agent/agent-fns.js";
|
|
21
|
-
import { AgentBlock, AgentChat, AgentChatOptions, AgentMessage, AgentQuestion, AgentTodo, AgentToolCall, useAgentChat } from "./agent/use-agent-chat.js";
|
|
22
20
|
import { Audience } from "./route/audience.js";
|
|
23
|
-
export { type ActionPermissions, type
|
|
21
|
+
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 FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Page, type PageSettings, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
|
package/dist/index.js
CHANGED
|
@@ -12,8 +12,6 @@ import { fieldShape, formatDuration, formatField, formatValue, registerSoftrFiel
|
|
|
12
12
|
import { useOverrides } from "./core/use-overrides.js";
|
|
13
13
|
import { useUserTimezone } from "./timezone.js";
|
|
14
14
|
import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
15
|
-
import { listAgents } from "./agent/agent-fns.js";
|
|
16
|
-
import { useAgentChat } from "./agent/use-agent-chat.js";
|
|
17
15
|
import { Audience } from "./route/audience.js";
|
|
18
16
|
|
|
19
|
-
export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError,
|
|
17
|
+
export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DatasourceAction
|
|
2
|
-
import * as
|
|
1
|
+
import { DatasourceAction } from "./action.js";
|
|
2
|
+
import * as _tanstack_react_start6 from "@tanstack/react-start";
|
|
3
3
|
|
|
4
4
|
//#region src/mcp.d.ts
|
|
5
5
|
|
|
6
|
-
type SoftrMcpOptions
|
|
6
|
+
type SoftrMcpOptions = {
|
|
7
7
|
/**
|
|
8
8
|
* The actions to expose as tools, from `defineQuery` and `defineMutation`.
|
|
9
9
|
*
|
|
@@ -12,19 +12,6 @@ type SoftrMcpOptions<TUsers extends ReadShape = ReadShape> = {
|
|
|
12
12
|
* decide who may run the ones that are listed.
|
|
13
13
|
*/
|
|
14
14
|
actions?: Array<DatasourceAction>;
|
|
15
|
-
/**
|
|
16
|
-
* Fills the owner of a person's record from who is calling, the way the app's
|
|
17
|
-
* pages do with `auth.currentUserRow`. The field is left out of the tool, so
|
|
18
|
-
* the assistant can't leave it wrong or name someone else.
|
|
19
|
-
*/
|
|
20
|
-
owner?: SoftrMcpOwner<TUsers>;
|
|
21
|
-
};
|
|
22
|
-
type SoftrMcpOwner<TUsers extends ReadShape = ReadShape> = {
|
|
23
|
-
/** The people table, and its email field, to find the caller's row in. */
|
|
24
|
-
users: DatasourceAction<TUsers>;
|
|
25
|
-
email: keyof TUsers["fields"] & string;
|
|
26
|
-
/** Listed create or update action id to the field that links to the caller's row. */
|
|
27
|
-
fields: Record<string, string>;
|
|
28
15
|
};
|
|
29
16
|
/**
|
|
30
17
|
* Serves the MCP endpoint and its OAuth flow from the app's own origin.
|
|
@@ -44,6 +31,6 @@ type SoftrMcpOwner<TUsers extends ReadShape = ReadShape> = {
|
|
|
44
31
|
* ],
|
|
45
32
|
* }))
|
|
46
33
|
*/
|
|
47
|
-
declare function softrMcpMiddleware
|
|
34
|
+
declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start6.RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
48
35
|
//#endregion
|
|
49
36
|
export { softrMcpMiddleware };
|
package/dist/mcp.js
CHANGED
|
@@ -5,10 +5,8 @@ import { softrConfig } from "./softr-config.js";
|
|
|
5
5
|
import { sessionConfig } from "./auth/config.js";
|
|
6
6
|
import { readSessionToken, withSessionToken } from "./auth/session.js";
|
|
7
7
|
import { isDatasourceAction } from "./action.js";
|
|
8
|
-
import { DatasourceError } from "./datasource/record.js";
|
|
9
8
|
import { makePlatform } from "./auth/platform.js";
|
|
10
9
|
import { ds } from "./datasource/datasource.js";
|
|
11
|
-
import { currentUserRow } from "./auth/current-user-row.js";
|
|
12
10
|
import { z } from "zod";
|
|
13
11
|
import { createMiddleware } from "@tanstack/react-start";
|
|
14
12
|
|
|
@@ -50,14 +48,6 @@ function softrMcpMiddleware(options = {}) {
|
|
|
50
48
|
assert(!actions.has(value.id), `two actions share the id "${value.id}"`);
|
|
51
49
|
actions.set(value.id, value);
|
|
52
50
|
}
|
|
53
|
-
const owner = options.owner;
|
|
54
|
-
for (const [actionId, field] of Object.entries(owner?.fields ?? {})) {
|
|
55
|
-
const action = actions.get(actionId);
|
|
56
|
-
assert(action, `owner names "${actionId}", which is not a listed action`);
|
|
57
|
-
const { operation, fields } = action.resource;
|
|
58
|
-
assert(operation === "create" || operation === "update", `owner fills "${actionId}", which is a ${operation}`);
|
|
59
|
-
assert(field in (fields ?? {}), `"${actionId}" has no field "${field}" for the owner`);
|
|
60
|
-
}
|
|
61
51
|
return createMiddleware({ type: "request" }).server(async ({ next, request }) => {
|
|
62
52
|
const url = new URL(request.url);
|
|
63
53
|
const origin = url.origin;
|
|
@@ -81,7 +71,7 @@ function softrMcpMiddleware(options = {}) {
|
|
|
81
71
|
});
|
|
82
72
|
case AUTHORIZE_PATH: return await authorize(request, login);
|
|
83
73
|
case TOKEN_PATH: return await issueToken(request);
|
|
84
|
-
case MCP_PATH: return await rpc(request, origin, actions
|
|
74
|
+
case MCP_PATH: return await rpc(request, origin, actions);
|
|
85
75
|
default: return await next();
|
|
86
76
|
}
|
|
87
77
|
});
|
|
@@ -254,8 +244,7 @@ const WHOAMI = {
|
|
|
254
244
|
type: "object",
|
|
255
245
|
properties: {},
|
|
256
246
|
additionalProperties: false
|
|
257
|
-
}
|
|
258
|
-
annotations: { readOnlyHint: true }
|
|
247
|
+
}
|
|
259
248
|
};
|
|
260
249
|
/** How many records a read returns when the caller does not say. */
|
|
261
250
|
const DEFAULT_LIMIT = 20;
|
|
@@ -268,16 +257,14 @@ const MAX_LIMIT = 100;
|
|
|
268
257
|
* that only ever reads one datasource exposes one read, even though its
|
|
269
258
|
* credentials would allow more.
|
|
270
259
|
*/
|
|
271
|
-
function describeTool(action
|
|
260
|
+
function describeTool(action) {
|
|
272
261
|
const { operation, fields } = action.resource;
|
|
273
262
|
const names = Object.keys(fields ?? {});
|
|
274
|
-
const
|
|
275
|
-
const fieldProps = Object.fromEntries(writable.map((name) => [name, { description: `The "${name}" field.` }]));
|
|
263
|
+
const fieldProps = Object.fromEntries(names.map((name) => [name, { description: `The "${name}" field.` }]));
|
|
276
264
|
switch (operation) {
|
|
277
265
|
case "read": return {
|
|
278
266
|
name: action.id,
|
|
279
267
|
description: `Read records from "${action.id}". Returns the fields ${names.join(", ")}. Only records the signed-in user may see come back.`,
|
|
280
|
-
annotations: { readOnlyHint: true },
|
|
281
268
|
inputSchema: {
|
|
282
269
|
type: "object",
|
|
283
270
|
properties: {
|
|
@@ -298,7 +285,7 @@ function describeTool(action, ownerField) {
|
|
|
298
285
|
};
|
|
299
286
|
case "create": return {
|
|
300
287
|
name: action.id,
|
|
301
|
-
description: `Create a record with "${action.id}". Writable fields: ${
|
|
288
|
+
description: `Create a record with "${action.id}". Writable fields: ${names.join(", ")}.`,
|
|
302
289
|
inputSchema: {
|
|
303
290
|
type: "object",
|
|
304
291
|
properties: fieldProps,
|
|
@@ -307,7 +294,7 @@ function describeTool(action, ownerField) {
|
|
|
307
294
|
};
|
|
308
295
|
case "update": return {
|
|
309
296
|
name: action.id,
|
|
310
|
-
description: `Update a record with "${action.id}". Writable fields: ${
|
|
297
|
+
description: `Update a record with "${action.id}". Writable fields: ${names.join(", ")}.`,
|
|
311
298
|
inputSchema: {
|
|
312
299
|
type: "object",
|
|
313
300
|
properties: {
|
|
@@ -343,7 +330,7 @@ function describeTool(action, ownerField) {
|
|
|
343
330
|
* visitor's user groups exactly as it would a click in the app. Nothing here
|
|
344
331
|
* decides what is allowed.
|
|
345
332
|
*/
|
|
346
|
-
async function runTool(action, args
|
|
333
|
+
async function runTool(action, args) {
|
|
347
334
|
const typed = action;
|
|
348
335
|
switch (action.resource.operation) {
|
|
349
336
|
case "read": {
|
|
@@ -355,21 +342,13 @@ async function runTool(action, args, owner) {
|
|
|
355
342
|
nextOffset: result$1.nextOffset
|
|
356
343
|
};
|
|
357
344
|
}
|
|
358
|
-
case "create": {
|
|
359
|
-
const data = writableFields(action, args, owner?.field);
|
|
360
|
-
if (owner !== null) {
|
|
361
|
-
const row = await owner.row();
|
|
362
|
-
if (row === null) throw new Error("The visitor has no row in the people table, so this record can't be created for them.");
|
|
363
|
-
data[owner.field] = { id: row.id };
|
|
364
|
-
}
|
|
365
|
-
return await ds.create(typed, { data });
|
|
366
|
-
}
|
|
345
|
+
case "create": return await ds.create(typed, { data: writableFields(action, args) });
|
|
367
346
|
case "update": {
|
|
368
347
|
const { id,...data } = args;
|
|
369
348
|
assert(typeof id === "string" && id !== "", "update needs a record id");
|
|
370
349
|
return await ds.update(typed, {
|
|
371
350
|
id,
|
|
372
|
-
data: writableFields(action, data
|
|
351
|
+
data: writableFields(action, data)
|
|
373
352
|
});
|
|
374
353
|
}
|
|
375
354
|
case "delete": {
|
|
@@ -380,19 +359,8 @@ async function runTool(action, args, owner) {
|
|
|
380
359
|
}
|
|
381
360
|
}
|
|
382
361
|
}
|
|
383
|
-
function ownerFieldOf(owner, actionId) {
|
|
384
|
-
return owner !== void 0 && Object.hasOwn(owner.fields, actionId) ? owner.fields[actionId] : void 0;
|
|
385
|
-
}
|
|
386
|
-
function ownerFill(owner, actionId, sessionToken) {
|
|
387
|
-
const field = ownerFieldOf(owner, actionId);
|
|
388
|
-
if (owner === void 0 || field === void 0) return null;
|
|
389
|
-
return {
|
|
390
|
-
field,
|
|
391
|
-
row: async () => currentUserRow(await resolveUser(sessionToken), owner.users, owner.email)
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
362
|
/**
|
|
395
|
-
* Only the fields the action declared
|
|
363
|
+
* Only the fields the action declared.
|
|
396
364
|
*
|
|
397
365
|
* `additionalProperties: false` in the tool schema is a hint to the model, not
|
|
398
366
|
* a check — a client can send whatever it likes. An unlisted key reaches the
|
|
@@ -400,18 +368,9 @@ function ownerFill(owner, actionId, sessionToken) {
|
|
|
400
368
|
* straight through. So the action's field list gets enforced here, or it isn't
|
|
401
369
|
* a boundary at all.
|
|
402
370
|
*/
|
|
403
|
-
function writableFields(action, args
|
|
371
|
+
function writableFields(action, args) {
|
|
404
372
|
const allowed = action.resource.fields ?? {};
|
|
405
|
-
return Object.fromEntries(Object.entries(args).filter(([name]) => name in allowed
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* The error as the assistant should read it. A row rule that keeps the caller
|
|
409
|
-
* from changing a record answers 404, the same as a deleted record, so a bare
|
|
410
|
-
* "not found" would leave the assistant guessing.
|
|
411
|
-
*/
|
|
412
|
-
function describeError(error) {
|
|
413
|
-
if (error instanceof DatasourceError && error.status === 404) return "Refused: this record doesn't exist, or the visitor's user group may not change it. If it still shows in a read, it is a permission. Tell the visitor they don't have access to this action, and that the app's builder can grant it.";
|
|
414
|
-
return error instanceof Error ? error.message : String(error);
|
|
373
|
+
return Object.fromEntries(Object.entries(args).filter(([name]) => name in allowed));
|
|
415
374
|
}
|
|
416
375
|
function clampLimit(raw) {
|
|
417
376
|
if (typeof raw !== "number" || !Number.isInteger(raw)) return DEFAULT_LIMIT;
|
|
@@ -421,15 +380,13 @@ function clampOffset(raw) {
|
|
|
421
380
|
if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 0) return null;
|
|
422
381
|
return raw;
|
|
423
382
|
}
|
|
424
|
-
async function rpc(request, origin, actions
|
|
383
|
+
async function rpc(request, origin, actions) {
|
|
425
384
|
if (request.method !== "POST") return methodNotAllowed("POST");
|
|
426
385
|
const token = bearerToken(request);
|
|
427
386
|
if (token === null) return unauthorized(origin);
|
|
428
387
|
const session = await platformSession(token);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
else if (session.refused && await resolveUser(token) !== null) sessionToken = token;
|
|
432
|
-
else return session.refused ? unauthorized(origin) : unavailable();
|
|
388
|
+
if (!session.ok) return session.refused ? unauthorized(origin) : unavailable();
|
|
389
|
+
const { sessionToken } = session;
|
|
433
390
|
const body = await readJson(request);
|
|
434
391
|
const message = z.object({
|
|
435
392
|
id: z.union([z.string(), z.number()]).optional(),
|
|
@@ -458,7 +415,7 @@ async function rpc(request, origin, actions, owner) {
|
|
|
458
415
|
}
|
|
459
416
|
});
|
|
460
417
|
}
|
|
461
|
-
case "tools/list": return result(id, { tools: [WHOAMI, ...[...actions.values()].map(
|
|
418
|
+
case "tools/list": return result(id, { tools: [WHOAMI, ...[...actions.values()].map(describeTool)] });
|
|
462
419
|
case "tools/call": {
|
|
463
420
|
const name = params?.name;
|
|
464
421
|
const args = typeof params?.arguments === "object" && params.arguments !== null ? params.arguments : {};
|
|
@@ -470,13 +427,13 @@ async function rpc(request, origin, actions, owner) {
|
|
|
470
427
|
const action = typeof name === "string" ? actions.get(name) : void 0;
|
|
471
428
|
if (action === void 0) return failure(id, -32602, `Unknown tool: ${String(name)}`);
|
|
472
429
|
try {
|
|
473
|
-
return result(id, toolResult(await withSessionToken(sessionToken, () => runTool(action, args
|
|
430
|
+
return result(id, toolResult(await withSessionToken(sessionToken, () => runTool(action, args))));
|
|
474
431
|
} catch (error) {
|
|
475
432
|
return result(id, {
|
|
476
433
|
isError: true,
|
|
477
434
|
content: [{
|
|
478
435
|
type: "text",
|
|
479
|
-
text:
|
|
436
|
+
text: error instanceof Error ? error.message : String(error)
|
|
480
437
|
}]
|
|
481
438
|
});
|
|
482
439
|
}
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softr/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.92-emailotc.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"softr-sdk": "./dist/cli.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"schema",
|
|
29
|
+
"skills",
|
|
30
|
+
"!skills/_artifacts"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
14
35
|
"scripts": {
|
|
15
36
|
"build": "tsdown",
|
|
16
37
|
"test": "node --import ./src/test-utils/setup.ts --test",
|
|
@@ -42,7 +63,9 @@
|
|
|
42
63
|
"optional": true
|
|
43
64
|
}
|
|
44
65
|
},
|
|
45
|
-
"keywords": [
|
|
66
|
+
"keywords": [
|
|
67
|
+
"tanstack-intent"
|
|
68
|
+
],
|
|
46
69
|
"intent": {
|
|
47
70
|
"version": 1,
|
|
48
71
|
"repo": "@softr/sdk",
|