@softr/sdk 0.0.87-alpha.0 → 0.0.87-alpha.2
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/isomorphic.d.ts +3 -2
- package/dist/auth/isomorphic.js +4 -1
- package/dist/auth/methods/authenticator.js +3 -3
- package/dist/auth/methods/code.js +1 -1
- package/dist/auth/methods/magicLink.js +1 -1
- package/dist/auth/methods/password.js +1 -1
- package/dist/auth/methods/passwordLink.js +1 -1
- package/dist/auth/methods/signup.js +1 -1
- package/dist/auth/methods/social.js +1 -1
- package/dist/auth/platform.js +1 -1
- package/dist/auth/session.js +8 -7
- package/dist/cookies.js +29 -3
- package/dist/default-error-overlay.d.ts +2 -2
- package/dist/embedding.js +33 -0
- package/dist/formatting.d.ts +3 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +3 -5
- package/dist/package.js +1 -1
- package/dist/pwa.d.ts +2 -2
- package/dist/route/route.js +1 -1
- package/dist/softr-config.schema.js +3 -1
- package/package.json +1 -1
- package/schema/softr.schema.json +5 -0
- package/skills/softr-sdk/SKILL.md +8 -7
- 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/file-uploads/SKILL.md +1 -1
- 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 +1 -1
- 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/region-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/workflows/SKILL.md +1 -1
- package/dist/agent/agent-fns.d.ts +0 -12
- package/dist/agent/agent-fns.js +0 -148
- package/dist/agent/use-agent-chat.d.ts +0 -94
- package/dist/agent/use-agent-chat.js +0 -367
- package/skills/softr-sdk/agent-chat/SKILL.md +0 -103
|
@@ -14,14 +14,15 @@ import * as _tanstack_react_start0 from "@tanstack/react-start";
|
|
|
14
14
|
* to read.
|
|
15
15
|
*
|
|
16
16
|
* Register it once, as a global request middleware in the app's `src/start.ts`.
|
|
17
|
-
* It writes
|
|
17
|
+
* It writes the session cookie, and in production a header that stops other
|
|
18
|
+
* sites from embedding the app.
|
|
18
19
|
*
|
|
19
20
|
* @example
|
|
20
21
|
* export const startInstance = createStart(() => ({
|
|
21
22
|
* requestMiddleware: [softrAuthMiddleware()],
|
|
22
23
|
* }))
|
|
23
24
|
*/
|
|
24
|
-
declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
|
|
25
|
+
declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
|
|
25
26
|
user: User | null;
|
|
26
27
|
permissions: Permissions;
|
|
27
28
|
formatting: Formatting;
|
package/dist/auth/isomorphic.js
CHANGED
|
@@ -9,6 +9,7 @@ import { settings } from "./methods/settings.js";
|
|
|
9
9
|
import { bootErrorMiddleware } from "../boot-error.js";
|
|
10
10
|
import { pwaMiddleware } from "../pwa.js";
|
|
11
11
|
import { faviconMiddleware } from "../favicon.js";
|
|
12
|
+
import { embeddingMiddleware } from "../embedding.js";
|
|
12
13
|
import { createContext, useContext } from "react";
|
|
13
14
|
import { createMiddleware, createServerFn, getGlobalStartContext } from "@tanstack/react-start";
|
|
14
15
|
import { getRequestHeader } from "@tanstack/react-start/server";
|
|
@@ -22,7 +23,8 @@ import { jsx } from "react/jsx-runtime";
|
|
|
22
23
|
* to read.
|
|
23
24
|
*
|
|
24
25
|
* Register it once, as a global request middleware in the app's `src/start.ts`.
|
|
25
|
-
* It writes
|
|
26
|
+
* It writes the session cookie, and in production a header that stops other
|
|
27
|
+
* sites from embedding the app.
|
|
26
28
|
*
|
|
27
29
|
* @example
|
|
28
30
|
* export const startInstance = createStart(() => ({
|
|
@@ -31,6 +33,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
31
33
|
*/
|
|
32
34
|
function softrAuthMiddleware() {
|
|
33
35
|
return createMiddleware({ type: "request" }).middleware([
|
|
36
|
+
embeddingMiddleware(),
|
|
34
37
|
bootErrorMiddleware(),
|
|
35
38
|
pwaMiddleware(),
|
|
36
39
|
faviconMiddleware()
|
|
@@ -46,7 +46,7 @@ async function confirmAuthenticatorSetup(details) {
|
|
|
46
46
|
throw new Error(`${result.message}. Check SOFTR_APPLICATION_ID and that the app allows an authenticator app.`);
|
|
47
47
|
}
|
|
48
48
|
const { session, backupCodes } = result.data;
|
|
49
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
49
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
50
50
|
user: session.user,
|
|
51
51
|
permissions: session.permissions
|
|
52
52
|
}, session.jwt)]);
|
|
@@ -75,7 +75,7 @@ async function skipAuthenticatorSetup() {
|
|
|
75
75
|
}
|
|
76
76
|
const { session } = result.data;
|
|
77
77
|
assert(session, "Expected a session from skipping setup, but got none");
|
|
78
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
78
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
79
79
|
user: session.user,
|
|
80
80
|
permissions: session.permissions
|
|
81
81
|
}, session.jwt)]);
|
|
@@ -101,7 +101,7 @@ async function verifyAuthenticator(credentials) {
|
|
|
101
101
|
}
|
|
102
102
|
const { session } = result.data;
|
|
103
103
|
assert(session, "Expected a session from verification, but got none");
|
|
104
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
104
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
105
105
|
user: session.user,
|
|
106
106
|
permissions: session.permissions
|
|
107
107
|
}, session.jwt)]);
|
|
@@ -56,7 +56,7 @@ async function signInWithCode(credentials) {
|
|
|
56
56
|
}
|
|
57
57
|
const { session } = result.data;
|
|
58
58
|
assert(session, "Expected a session from sign-in, but got none");
|
|
59
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
59
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
60
60
|
user: session.user,
|
|
61
61
|
permissions: session.permissions
|
|
62
62
|
}, session.jwt)]);
|
|
@@ -36,7 +36,7 @@ async function signInWithMagicLink(credentials) {
|
|
|
36
36
|
}
|
|
37
37
|
const { session } = result.data;
|
|
38
38
|
assert(session, "Expected a session from magic-link sign-in, but got none");
|
|
39
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
39
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
40
40
|
user: session.user,
|
|
41
41
|
permissions: session.permissions
|
|
42
42
|
}, session.jwt)]);
|
|
@@ -35,7 +35,7 @@ async function signIn(credentials) {
|
|
|
35
35
|
}
|
|
36
36
|
const { session } = result.data;
|
|
37
37
|
assert(session, "Expected a session from sign-in, but got none");
|
|
38
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
38
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
39
39
|
user: session.user,
|
|
40
40
|
permissions: session.permissions
|
|
41
41
|
}, session.jwt)]);
|
|
@@ -68,7 +68,7 @@ async function setPasswordWithLink(details) {
|
|
|
68
68
|
}
|
|
69
69
|
const { session } = result.data;
|
|
70
70
|
assert(session, "Expected a session from setting a password, but got none");
|
|
71
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
71
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
72
72
|
user: session.user,
|
|
73
73
|
permissions: session.permissions
|
|
74
74
|
}, session.jwt)]);
|
|
@@ -66,7 +66,7 @@ async function confirmSignUp(details) {
|
|
|
66
66
|
}
|
|
67
67
|
const { session } = result.data;
|
|
68
68
|
assert(session, "Expected a session from sign-up, but got none");
|
|
69
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
69
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
70
70
|
user: session.user,
|
|
71
71
|
permissions: session.permissions
|
|
72
72
|
}, session.jwt)]);
|
|
@@ -41,7 +41,7 @@ async function signInWithGoogle(credentials) {
|
|
|
41
41
|
}
|
|
42
42
|
const { session } = result.data;
|
|
43
43
|
assert(session, "Expected a session from Google sign-in, but got none");
|
|
44
|
-
writeCookies([makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
44
|
+
writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
|
|
45
45
|
user: session.user,
|
|
46
46
|
permissions: session.permissions
|
|
47
47
|
}, session.jwt)]);
|
package/dist/auth/platform.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assert, panic } from "../assertions.js";
|
|
2
2
|
import { fetch } from "../fetch.js";
|
|
3
|
+
import { softrConfig } from "../softr-config.js";
|
|
3
4
|
import { permissionsSchema } from "./permissions.js";
|
|
4
5
|
import { softrApiUrl } from "../softr-api.js";
|
|
5
|
-
import { softrConfig } from "../softr-config.js";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
|
|
8
8
|
//#region src/auth/platform.ts
|
package/dist/auth/session.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readRequestCookies, serializeCookie, writeCookies } from "../cookies.js";
|
|
1
|
+
import { expireCookie, expireOtherCopy, readRequestCookies, serializeCookie, writeCookies } from "../cookies.js";
|
|
2
2
|
import { permissionsSchema } from "./permissions.js";
|
|
3
3
|
import { sessionConfig } from "./config.js";
|
|
4
4
|
import { userSchema } from "./user.js";
|
|
@@ -65,12 +65,16 @@ function readSessionData(sessionToken) {
|
|
|
65
65
|
permissions: payload.permissions
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The token cookie, after a deletion of any copy from before `allowEmbedding`
|
|
70
|
+
* changed. Both would be sent, and the old one could be read instead.
|
|
71
|
+
*/
|
|
68
72
|
function makeSessionTokenCookie(token) {
|
|
69
73
|
const { name, secure } = sessionCookie(SESSION_TOKEN);
|
|
70
|
-
return serializeCookie(name, sealEnvelope(token, SESSION_TOKEN), {
|
|
74
|
+
return [...expireOtherCopy(name, secure), serializeCookie(name, sealEnvelope(token, SESSION_TOKEN), {
|
|
71
75
|
maxAge: sessionConfig().sessionMaxAge,
|
|
72
76
|
secure
|
|
73
|
-
});
|
|
77
|
+
})];
|
|
74
78
|
}
|
|
75
79
|
function makeSessionDataCookie(session, sessionToken) {
|
|
76
80
|
const { name, secure } = sessionCookie(SESSION_DATA);
|
|
@@ -141,10 +145,7 @@ const sessionDataSchema = z.object({
|
|
|
141
145
|
*/
|
|
142
146
|
function clearCookies(bases) {
|
|
143
147
|
const secure = requestIsSecure();
|
|
144
|
-
writeCookies(bases.flatMap((base) => secure ? [sessionCookieName(base, secure), base] : [base]).
|
|
145
|
-
maxAge: 0,
|
|
146
|
-
secure
|
|
147
|
-
})));
|
|
148
|
+
writeCookies(bases.flatMap((base) => secure ? [sessionCookieName(base, secure), base] : [base]).flatMap((name) => expireCookie(name, secure)));
|
|
148
149
|
}
|
|
149
150
|
/**
|
|
150
151
|
* Over the plaintext token, never the cookie value: that is resealed with a
|
package/dist/cookies.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { softAssert } from "./assertions.js";
|
|
2
|
+
import { softrConfig } from "./softr-config.js";
|
|
2
3
|
import { getRequestHeader, getResponseHeaders, setResponseHeader } from "@tanstack/react-start/server";
|
|
3
4
|
|
|
4
5
|
//#region src/cookies.ts
|
|
@@ -36,8 +37,33 @@ function serializeCookie(name, value, { maxAge, secure }) {
|
|
|
36
37
|
return parts.join("; ");
|
|
37
38
|
}
|
|
38
39
|
function sameSiteAttributes(secure) {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
return partitions(secure) ? ["SameSite=None", "Partitioned"] : ["SameSite=Lax"];
|
|
41
|
+
}
|
|
42
|
+
function partitions(secure) {
|
|
43
|
+
return secure && (process.env.NODE_ENV !== "production" || (softrConfig().allowEmbedding ?? []).length > 0);
|
|
44
|
+
}
|
|
45
|
+
function expired(name, partitioned) {
|
|
46
|
+
return partitioned ? `${name}=; Path=/; HttpOnly; Secure; SameSite=None; Partitioned; Max-Age=0` : `${name}=; Path=/; HttpOnly; Secure; SameSite=Lax; Max-Age=0`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The deletions for one cookie. A browser keeps a partitioned and a plain
|
|
50
|
+
* cookie of one name apart, and sends both. Which one the app wrote can change
|
|
51
|
+
* between sign-in and sign-out, when `allowEmbedding` changes. So over https,
|
|
52
|
+
* delete both. The one left behind would keep the visitor signed in.
|
|
53
|
+
*/
|
|
54
|
+
function expireCookie(name, secure) {
|
|
55
|
+
if (!secure) return [serializeCookie(name, "", {
|
|
56
|
+
maxAge: 0,
|
|
57
|
+
secure
|
|
58
|
+
})];
|
|
59
|
+
return [expired(name, false), expired(name, true)];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The deletion of the copy the other mode would write. Sent with a new cookie,
|
|
63
|
+
* so a copy from before `allowEmbedding` changed can't be read in its place.
|
|
64
|
+
*/
|
|
65
|
+
function expireOtherCopy(name, secure) {
|
|
66
|
+
return secure ? [expired(name, !partitions(secure))] : [];
|
|
41
67
|
}
|
|
42
68
|
const USER_TIMEZONE_COOKIE = "user-timezone";
|
|
43
69
|
function readUserTimezone() {
|
|
@@ -56,4 +82,4 @@ function writeCookies(cookies) {
|
|
|
56
82
|
}
|
|
57
83
|
|
|
58
84
|
//#endregion
|
|
59
|
-
export { readRequestCookies, readUserTimezone, serializeCookie, writeCookies };
|
|
85
|
+
export { expireCookie, expireOtherCopy, readRequestCookies, readUserTimezone, serializeCookie, writeCookies };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react0 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): react0.JSX.Element;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { DefaultErrorOverlay };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { softrConfig } from "./softr-config.js";
|
|
2
|
+
import { createMiddleware } from "@tanstack/react-start";
|
|
3
|
+
|
|
4
|
+
//#region src/embedding.ts
|
|
5
|
+
/**
|
|
6
|
+
* Stops other sites from showing the published app in an iframe. The origins
|
|
7
|
+
* softr.json lists in `allowEmbedding` still can.
|
|
8
|
+
*
|
|
9
|
+
* Production only. The dev server runs in the preview pod, and Studio shows
|
|
10
|
+
* that preview in an iframe on another site.
|
|
11
|
+
*/
|
|
12
|
+
function embeddingMiddleware() {
|
|
13
|
+
return createMiddleware({ type: "request" }).server(async ({ next }) => {
|
|
14
|
+
const result = await next();
|
|
15
|
+
if (process.env.NODE_ENV !== "production") return result;
|
|
16
|
+
const policy = [
|
|
17
|
+
"frame-ancestors",
|
|
18
|
+
"'self'",
|
|
19
|
+
...softrConfig().allowEmbedding ?? []
|
|
20
|
+
].join(" ");
|
|
21
|
+
try {
|
|
22
|
+
result.response.headers.append("content-security-policy", policy);
|
|
23
|
+
return result;
|
|
24
|
+
} catch {
|
|
25
|
+
const response = new Response(result.response.body, result.response);
|
|
26
|
+
response.headers.append("content-security-policy", policy);
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { embeddingMiddleware };
|
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
|
@@ -16,7 +16,5 @@ import { useOverrides } from "./core/use-overrides.js";
|
|
|
16
16
|
import { useUserTimezone } from "./timezone.js";
|
|
17
17
|
import { PwaInstall, PwaPlatform, SoftrPwaHead, usePwaInstall } from "./pwa.js";
|
|
18
18
|
import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
19
|
-
import { AgentChatSummary } from "./agent/agent-fns.js";
|
|
20
|
-
import { AgentBlock, AgentChat, AgentChatOptions, AgentMessage, AgentQuestion, AgentTodo, AgentToolCall, useAgentChat } from "./agent/use-agent-chat.js";
|
|
21
19
|
import { Audience } from "./route/audience.js";
|
|
22
|
-
export { type ActionPermissions,
|
|
20
|
+
export { type ActionPermissions, 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, 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,7 +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 { useAgentChat } from "./agent/use-agent-chat.js";
|
|
16
15
|
import { Audience } from "./route/audience.js";
|
|
17
16
|
|
|
18
|
-
export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, 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,
|
|
17
|
+
export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, 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,5 +1,5 @@
|
|
|
1
1
|
import { DatasourceAction } from "./action.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _tanstack_react_start6 from "@tanstack/react-start";
|
|
3
3
|
|
|
4
4
|
//#region src/mcp.d.ts
|
|
5
5
|
|
|
@@ -31,6 +31,6 @@ type SoftrMcpOptions = {
|
|
|
31
31
|
* ],
|
|
32
32
|
* }))
|
|
33
33
|
*/
|
|
34
|
-
declare function softrMcpMiddleware(options?: SoftrMcpOptions):
|
|
34
|
+
declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start6.RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
35
35
|
//#endregion
|
|
36
36
|
export { softrMcpMiddleware };
|
package/dist/mcp.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { assert } from "./assertions.js";
|
|
2
2
|
import { fetch } from "./fetch.js";
|
|
3
|
+
import { softrConfig } from "./softr-config.js";
|
|
3
4
|
import { sessionConfig } from "./auth/config.js";
|
|
4
5
|
import { readSessionToken, withSessionToken } from "./auth/session.js";
|
|
5
6
|
import { softrApiUrl } from "./softr-api.js";
|
|
6
7
|
import { isDatasourceAction } from "./action.js";
|
|
7
|
-
import { softrConfig } from "./softr-config.js";
|
|
8
8
|
import { makePlatform } from "./auth/platform.js";
|
|
9
9
|
import { ds } from "./datasource/datasource.js";
|
|
10
10
|
import { z } from "zod";
|
|
@@ -385,10 +385,8 @@ async function rpc(request, origin, actions) {
|
|
|
385
385
|
const token = bearerToken(request);
|
|
386
386
|
if (token === null) return unauthorized(origin);
|
|
387
387
|
const session = await platformSession(token);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
else if (session.refused && await resolveUser(token) !== null) sessionToken = token;
|
|
391
|
-
else return session.refused ? unauthorized(origin) : unavailable();
|
|
388
|
+
if (!session.ok) return session.refused ? unauthorized(origin) : unavailable();
|
|
389
|
+
const { sessionToken } = session;
|
|
392
390
|
const body = await readJson(request);
|
|
393
391
|
const message = z.object({
|
|
394
392
|
id: z.union([z.string(), z.number()]).optional(),
|
package/dist/package.js
CHANGED
package/dist/pwa.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react1 from "react";
|
|
2
2
|
import "@tanstack/react-start";
|
|
3
3
|
|
|
4
4
|
//#region src/pwa.d.ts
|
|
@@ -23,7 +23,7 @@ import "@tanstack/react-start";
|
|
|
23
23
|
* )
|
|
24
24
|
* }
|
|
25
25
|
*/
|
|
26
|
-
declare function SoftrPwaHead():
|
|
26
|
+
declare function SoftrPwaHead(): react1.FunctionComponentElement<react1.FragmentProps>;
|
|
27
27
|
type PwaPlatform = "ios" | "android" | "desktop";
|
|
28
28
|
type PwaInstall = {
|
|
29
29
|
available: false;
|
package/dist/route/route.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { panic } from "../assertions.js";
|
|
2
|
-
import { ACCESS_REASONS, checkRule } from "./visibility.js";
|
|
3
2
|
import { softrConfig } from "../softr-config.js";
|
|
3
|
+
import { ACCESS_REASONS, checkRule } from "./visibility.js";
|
|
4
4
|
import { redirect } from "@tanstack/react-router";
|
|
5
5
|
|
|
6
6
|
//#region src/route/route.ts
|
|
@@ -21,6 +21,7 @@ const AccessBehaviour = z.union([
|
|
|
21
21
|
z.object({ strategy: z.literal("throw") })
|
|
22
22
|
], { error: "must be a path like \"/login\", { \"strategy\": \"redirect\", \"to\": \"/login\" } or { \"strategy\": \"throw\" }" });
|
|
23
23
|
const AppPath = z.string().refine((path$1) => path$1.startsWith("/") && !path$1.includes("?") && !path$1.includes("#") && new URL(path$1, "https://app.invalid").origin === "https://app.invalid", { error: "must be a path on this app like \"/login\", with no \"?\" or \"#\"" });
|
|
24
|
+
const Origin = z.string().refine((origin) => origin === "*" || URL.canParse(origin) && new URL(origin).origin === origin && origin.startsWith("https://"), { error: "must be an https origin like \"https://partner.com\", with no path or trailing \"/\", or \"*\" for any site" });
|
|
24
25
|
const SoftrConfigSchema = z.object({
|
|
25
26
|
auth: z.strictObject({
|
|
26
27
|
routes: z.strictObject({
|
|
@@ -47,7 +48,8 @@ const SoftrConfigSchema = z.object({
|
|
|
47
48
|
alreadyAuthenticated: AccessBehaviour
|
|
48
49
|
})
|
|
49
50
|
}),
|
|
50
|
-
user: z.strictObject({ properties: z.record(z.string(), z.string()) }).optional()
|
|
51
|
+
user: z.strictObject({ properties: z.record(z.string(), z.string()) }).optional(),
|
|
52
|
+
allowEmbedding: z.array(Origin).optional()
|
|
51
53
|
});
|
|
52
54
|
function loadSoftrConfig(root) {
|
|
53
55
|
const file = path.join(root, SOFTR_CONFIG_FILE);
|
package/package.json
CHANGED
package/schema/softr.schema.json
CHANGED
|
@@ -67,6 +67,11 @@
|
|
|
67
67
|
},
|
|
68
68
|
"required": ["properties"],
|
|
69
69
|
"additionalProperties": false
|
|
70
|
+
},
|
|
71
|
+
"allowEmbedding": {
|
|
72
|
+
"type": "array",
|
|
73
|
+
"description": "Sites that may show the published app in an iframe, signed-in pages included, as https origins like \"https://partner.com\", or \"*\" for any site. Any other site is still blocked. With at least one, session cookies use SameSite=None, which drops the browser's CSRF protection. Empty by default.",
|
|
74
|
+
"items": { "type": "string", "pattern": "^(\\*|https://[^/?#]+)$" }
|
|
70
75
|
}
|
|
71
76
|
},
|
|
72
77
|
"required": ["auth"],
|
|
@@ -3,12 +3,13 @@ name: softr-sdk
|
|
|
3
3
|
description: >-
|
|
4
4
|
Entry point for @softr/sdk: its four entrypoints (@softr/sdk, /server,
|
|
5
5
|
/client, /vite) and their client-server boundary, softrAuthMiddleware and the
|
|
6
|
-
Softr context,
|
|
7
|
-
sub-skill applies,
|
|
6
|
+
Softr context, embedding the app in another site's iframe, and which sub-skill
|
|
7
|
+
covers each task. Load it when unsure which sub-skill applies, when touching
|
|
8
|
+
the wiring, or when the user wants the app embedded elsewhere.
|
|
8
9
|
metadata:
|
|
9
10
|
type: core
|
|
10
11
|
library: softr-sdk
|
|
11
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.87-alpha.2
|
|
12
13
|
---
|
|
13
14
|
|
|
14
15
|
# Softr SDK core
|
|
@@ -48,7 +49,6 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
|
|
|
48
49
|
| Sign a visitor in, out, or up | [auth/SKILL.md](./auth/SKILL.md) |
|
|
49
50
|
| Call a connected third-party API (Slack, Stripe, Gmail, …) | [integrations/SKILL.md](./integrations/SKILL.md) |
|
|
50
51
|
| Open the app to AI assistants over MCP | [mcp/SKILL.md](./mcp/SKILL.md) |
|
|
51
|
-
| Let visitors chat with a Softr agent | [agent-chat/SKILL.md](./agent-chat/SKILL.md) |
|
|
52
52
|
| Let visitors install the app on their home screen | [pwa/SKILL.md](./pwa/SKILL.md) |
|
|
53
53
|
| Show a date, a time or a number | [formatting/SKILL.md](./formatting/SKILL.md) |
|
|
54
54
|
|
|
@@ -85,9 +85,6 @@ Calling a connected third-party API (Slack, Stripe, Gmail, Google Calendar, …)
|
|
|
85
85
|
Opening the app to an AI assistant over MCP?
|
|
86
86
|
load softr-sdk/mcp
|
|
87
87
|
|
|
88
|
-
Adding a chat with one of the app's Softr agents?
|
|
89
|
-
load softr-sdk/agent-chat
|
|
90
|
-
|
|
91
88
|
Adding an install button, or making the app installable?
|
|
92
89
|
load softr-sdk/pwa
|
|
93
90
|
|
|
@@ -152,3 +149,7 @@ type User = {
|
|
|
152
149
|
userGroupIds: Array<SoftrUserGroupId> // the app's own group ids
|
|
153
150
|
}
|
|
154
151
|
```
|
|
152
|
+
|
|
153
|
+
## Embedding the app in another site
|
|
154
|
+
|
|
155
|
+
The published app refuses to load inside another site's iframe. The Studio preview is not affected. When the user asks to embed the app on their site, list that site's origin in `softr.json`: `"allowEmbedding": ["https://partner.com"]`. Ask for the exact origin if you don't have it. Only listed sites can embed the app. Use `["*"]` only when the user wants any site to embed it. Remove the list to block embedding again. Sign-in then works inside the embed. Session cookies switch from SameSite=Lax to None, so the app loses the browser's CSRF protection. Only set it when the user asks. There are two more limits to tell the user: Safari may not keep the visitor signed in, and links from emails (magic link, password reset) open the app in a new tab, not in the embed.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.87-alpha.2
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.87-alpha.2
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 0.0.
|
|
10
|
+
library_version: 0.0.87-alpha.2
|
|
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.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 0.0.
|
|
10
|
+
library_version: 0.0.87-alpha.2
|
|
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: 0.0.
|
|
12
|
+
library_version: 0.0.87-alpha.2
|
|
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.
|
|
@@ -8,7 +8,7 @@ description: >-
|
|
|
8
8
|
metadata:
|
|
9
9
|
type: sub-skill
|
|
10
10
|
library: softr-sdk
|
|
11
|
-
library_version: 0.0.
|
|
11
|
+
library_version: 0.0.87-alpha.2
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
**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.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.87-alpha.2
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. The same holds for any helper that calls `ds`: declare it inside the handler. A function at module level that calls `ds` keeps the server-only import in the browser bundle, and every page stops loading until it moves. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -8,7 +8,7 @@ description: >-
|
|
|
8
8
|
metadata:
|
|
9
9
|
type: sub-skill
|
|
10
10
|
library: softr-sdk
|
|
11
|
-
library_version: 0.0.
|
|
11
|
+
library_version: 0.0.87-alpha.2
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
**Boundary.** `defineVisibility`, 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: 0.0.
|
|
12
|
+
library_version: 0.0.87-alpha.2
|
|
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.
|