@softr/sdk 0.0.83 → 0.0.85-alpha.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.
@@ -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 nothing but the session cookie.
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;
@@ -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 nothing but the session cookie.
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()
@@ -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/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,7 +37,7 @@ function serializeCookie(name, value, { maxAge, secure }) {
36
37
  return parts.join("; ");
37
38
  }
38
39
  function sameSiteAttributes(secure) {
39
- if (secure && process.env.NODE_ENV !== "production") return ["SameSite=None", "Partitioned"];
40
+ if (secure && (process.env.NODE_ENV !== "production" || softrConfig().allowEmbedding === true)) return ["SameSite=None", "Partitioned"];
40
41
  return ["SameSite=Lax"];
41
42
  }
42
43
  const USER_TIMEZONE_COOKIE = "user-timezone";
@@ -1,4 +1,4 @@
1
- import * as react6 from "react";
1
+ import * as react4 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): react6.JSX.Element;
11
+ }: Props): react4.JSX.Element;
12
12
  //#endregion
13
13
  export { DefaultErrorOverlay };
@@ -0,0 +1,24 @@
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, unless
7
+ * softr.json sets `allowEmbedding`.
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
+ if (softrConfig().allowEmbedding === true) return result;
17
+ const response = new Response(result.response.body, result.response);
18
+ response.headers.set("content-security-policy", "frame-ancestors 'self'");
19
+ return response;
20
+ });
21
+ }
22
+
23
+ //#endregion
24
+ export { embeddingMiddleware };
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DatasourceAction } from "./action.js";
2
- import * as _tanstack_react_start5 from "@tanstack/react-start";
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): _tanstack_react_start5.RequestMiddlewareAfterServer<{}, undefined, undefined>;
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";
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.83";
2
+ var version = "0.0.85-alpha.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react4 from "react";
1
+ import * as react5 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(): react4.FunctionComponentElement<react4.FragmentProps>;
26
+ declare function SoftrPwaHead(): react5.FunctionComponentElement<react5.FragmentProps>;
27
27
  type PwaPlatform = "ios" | "android" | "desktop";
28
28
  type PwaInstall = {
29
29
  available: false;
@@ -14,6 +14,8 @@ type HeadContext = {
14
14
  };
15
15
  type HeadSetting<T> = T | ((ctx: HeadContext) => T | undefined);
16
16
  type PageSettings = {
17
+ /** Studio's label for the page, separate from its title. */
18
+ name?: string;
17
19
  visibility?: VisibilityRule;
18
20
  title?: HeadSetting<string>;
19
21
  description?: HeadSetting<string>;
@@ -29,7 +31,7 @@ type Page<S extends PageSettings = PageSettings> = S & {
29
31
  readonly [pageBrand]: "page";
30
32
  };
31
33
  /**
32
- * Declares a route's settings: who may open it, its title and its SEO tags.
34
+ * Declares a route's settings: its name in Studio, who may open it, its title and its SEO tags.
33
35
  *
34
36
  * One call per route file, at module scope, with an object literal. Studio
35
37
  * reads and rewrites each setting written out as a literal; a computed one is
@@ -1,6 +1,6 @@
1
1
  //#region src/route/page.ts
2
2
  /**
3
- * Declares a route's settings: who may open it, its title and its SEO tags.
3
+ * Declares a route's settings: its name in Studio, who may open it, its title and its SEO tags.
4
4
  *
5
5
  * One call per route file, at module scope, with an object literal. Studio
6
6
  * reads and rewrites each setting written out as a literal; a computed one is
@@ -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
@@ -47,7 +47,8 @@ const SoftrConfigSchema = z.object({
47
47
  alreadyAuthenticated: AccessBehaviour
48
48
  })
49
49
  }),
50
- user: z.strictObject({ properties: z.record(z.string(), z.string()) }).optional()
50
+ user: z.strictObject({ properties: z.record(z.string(), z.string()) }).optional(),
51
+ allowEmbedding: z.boolean().optional()
51
52
  });
52
53
  function loadSoftrConfig(root) {
53
54
  const file = path.join(root, SOFTR_CONFIG_FILE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "0.0.83",
3
+ "version": "0.0.85-alpha.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -67,6 +67,10 @@
67
67
  },
68
68
  "required": ["properties"],
69
69
  "additionalProperties": false
70
+ },
71
+ "allowEmbedding": {
72
+ "type": "boolean",
73
+ "description": "Lets other sites show the published app in an iframe, signed-in pages included. Off by default."
70
74
  }
71
75
  },
72
76
  "required": ["auth"],
@@ -145,3 +145,7 @@ type User = {
145
145
  userGroupIds: Array<SoftrUserGroupId> // the app's own group ids
146
146
  }
147
147
  ```
148
+
149
+ ## Embedding the app in another site
150
+
151
+ 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, set `"allowEmbedding": true` in `softr.json`. Remove it to block embedding again. Sign-in then works inside the embed, with two 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.