@softr/sdk 1.2.1-alpha.0 → 1.2.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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - `SoftrPwaHead` now gives iOS the app's home screen name and launch screens, so an installed app opens on its splash screen instead of white and Add to Home Screen suggests the app's name, not the page title. An app already on an iPhone home screen picks this up only after it is removed and added again.
7
+ - `softrAuthMiddleware` serves the favicon set in Studio, Settings → General → Favicon, at `/favicon.ico`. Without one, it serves the Softr icon. An icon link or `public/favicon.ico` in the app still wins.
8
8
 
9
9
  ## 1.2.0
10
10
 
package/dist/favicon.js CHANGED
@@ -1,13 +1,34 @@
1
1
  import { logger } from "./logger.js";
2
+ import { softrApiUrl } from "./softr-api.js";
2
3
  import { fetch } from "./fetch.js";
4
+ import { sessionConfig } from "./auth/config.js";
5
+ import { readCached } from "./cache.js";
6
+ import { z } from "zod";
3
7
  import { createMiddleware } from "@tanstack/react-start";
4
8
 
5
9
  //#region src/favicon.ts
6
10
  const FAVICON_PATH = "/favicon.ico";
7
11
  const DEFAULT_FAVICON_URL = "https://assets.softr-files.com/assets/images/favicon.ico";
8
- const CACHE_CONTROL = "public, max-age=86400";
12
+ const TTL_MS = 6e4;
13
+ const CACHE_CONTROL = "public, max-age=60";
14
+ const faviconSchema = z.object({ url: z.string() });
15
+ let cached;
9
16
  /**
10
- * Serves the default Softr favicon at `/favicon.ico`. Every other request
17
+ * The URL of the favicon set in Studio, or `null` when there is none. A
18
+ * failure also reads as `null`, so the app shows the default icon.
19
+ */
20
+ function readStudioFaviconUrl() {
21
+ return readCached("the favicon setting", TTL_MS, () => cached, (entry) => cached = entry, async () => {
22
+ const { applicationId } = sessionConfig();
23
+ const response = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${applicationId}/favicon`, { headers: { accept: "application/json" } });
24
+ if (response.status === 404) return null;
25
+ if (!response.ok) throw new Error(`The platform answered ${response.status}`);
26
+ return faviconSchema.parse(await response.json()).url;
27
+ });
28
+ }
29
+ /**
30
+ * Serves the app's favicon at `/favicon.ico`: the one the builder set in
31
+ * Studio, or the default Softr favicon when there is none. Every other request
11
32
  * passes through untouched.
12
33
  *
13
34
  * Proxied, not redirected: some clients do not follow a redirect for an icon.
@@ -19,15 +40,16 @@ const CACHE_CONTROL = "public, max-age=86400";
19
40
  function faviconMiddleware() {
20
41
  return createMiddleware({ type: "request" }).server(async ({ next, pathname }) => {
21
42
  if (pathname !== FAVICON_PATH) return next();
43
+ const iconUrl = await readStudioFaviconUrl() ?? DEFAULT_FAVICON_URL;
22
44
  try {
23
- const iconResponse = await fetch(DEFAULT_FAVICON_URL);
45
+ const iconResponse = await fetch(iconUrl);
24
46
  if (!iconResponse.ok) return new Response(null, { status: 404 });
25
- return new Response(iconResponse.body, { headers: {
26
- "content-type": "image/x-icon",
27
- "cache-control": CACHE_CONTROL
28
- } });
47
+ const headers = new Headers({ "cache-control": CACHE_CONTROL });
48
+ const contentType = iconResponse.headers.get("content-type");
49
+ if (contentType !== null) headers.set("content-type", contentType);
50
+ return new Response(iconResponse.body, { headers });
29
51
  } catch (error) {
30
- logger.warn("Could not fetch the default favicon:", error);
52
+ logger.warn("Could not fetch the favicon:", error);
31
53
  return new Response(null, { status: 404 });
32
54
  }
33
55
  });
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.2.1-alpha.0";
2
+ var version = "1.2.1";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.d.ts CHANGED
@@ -4,9 +4,8 @@ import "@tanstack/react-start";
4
4
  //#region src/pwa.d.ts
5
5
 
6
6
  /**
7
- * The tags that make the app installable: its manifest, its home screen icon,
8
- * and, while the app is installable, the name and launch screens iOS shows.
9
- * Render it once, in `<head>` in the root route's `RootDocument`.
7
+ * The links that make the app installable: its manifest and its home screen
8
+ * icon. Render it once, in `<head>` in the root route's `RootDocument`.
10
9
  *
11
10
  * @example
12
11
  * function RootDocument({ children }: { children: React.ReactNode }) {
package/dist/pwa.js CHANGED
@@ -18,13 +18,8 @@ const pwaSchema = z.object({
18
18
  install: z.object({
19
19
  name: z.string(),
20
20
  iconUrl: z.string()
21
- }),
22
- startupImages: z.array(z.object({
23
- media: z.string(),
24
- href: z.string()
25
- })).default([])
21
+ })
26
22
  });
27
- const iosHeadSchema = pwaSchema.pick({ startupImages: true }).extend({ name: z.string() });
28
23
  let cached;
29
24
  /** The app's PWA, or `null` when it is not installable right now. */
30
25
  function readPwa() {
@@ -54,10 +49,7 @@ function pwaMiddleware() {
54
49
  "content-type": "application/manifest+json",
55
50
  "cache-control": CACHE_CONTROL
56
51
  } });
57
- if (pathname === INSTALL_PATH) return Response.json({
58
- ...pwa.install,
59
- startupImages: pwa.startupImages
60
- }, { headers: { "cache-control": CACHE_CONTROL } });
52
+ if (pathname === INSTALL_PATH) return Response.json(pwa.install, { headers: { "cache-control": CACHE_CONTROL } });
61
53
  try {
62
54
  const iconResponse = await fetch(pwa.install.iconUrl);
63
55
  if (!iconResponse.ok) return new Response(null, { status: 404 });
@@ -72,9 +64,8 @@ function pwaMiddleware() {
72
64
  });
73
65
  }
74
66
  /**
75
- * The tags that make the app installable: its manifest, its home screen icon,
76
- * and, while the app is installable, the name and launch screens iOS shows.
77
- * Render it once, in `<head>` in the root route's `RootDocument`.
67
+ * The links that make the app installable: its manifest and its home screen
68
+ * icon. Render it once, in `<head>` in the root route's `RootDocument`.
78
69
  *
79
70
  * @example
80
71
  * function RootDocument({ children }: { children: React.ReactNode }) {
@@ -93,40 +84,13 @@ function pwaMiddleware() {
93
84
  * }
94
85
  */
95
86
  function SoftrPwaHead() {
96
- const [iosHead, setIosHead] = useState(null);
97
- useEffect(() => {
98
- if (detectPlatform() !== "ios") return;
99
- let cancelled = false;
100
- globalThis.fetch(INSTALL_PATH, { headers: { accept: "application/json" } }).then(async (response) => {
101
- if (!response.ok) return;
102
- const parsed = iosHeadSchema.safeParse(await response.json());
103
- if (!parsed.success || cancelled) return;
104
- setIosHead(parsed.data);
105
- }).catch(() => {});
106
- return () => {
107
- cancelled = true;
108
- };
109
- }, []);
110
87
  return createElement(Fragment, null, createElement("link", {
111
88
  rel: "manifest",
112
89
  href: MANIFEST_PATH
113
90
  }), createElement("link", {
114
91
  rel: "apple-touch-icon",
115
92
  href: ICON_PATH
116
- }), ...iosHead === null ? [] : [createElement("meta", {
117
- key: "capable",
118
- name: "apple-mobile-web-app-capable",
119
- content: "yes"
120
- }), createElement("meta", {
121
- key: "title",
122
- name: "apple-mobile-web-app-title",
123
- content: iosHead.name
124
- })], ...(iosHead?.startupImages ?? []).map((image) => createElement("link", {
125
- key: image.href,
126
- rel: "apple-touch-startup-image",
127
- media: image.media,
128
- href: image.href
129
- })));
93
+ }));
130
94
  }
131
95
  const installSchema = pwaSchema.shape.install;
132
96
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.2.1-alpha.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -3,13 +3,14 @@ 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, 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.
6
+ Softr context, embedding the app in another site's iframe, the app's favicon,
7
+ and which sub-skill covers each task. Load it when unsure which sub-skill
8
+ applies, when touching the wiring, when the user wants the app embedded
9
+ elsewhere, or when the favicon set in Studio does not show.
9
10
  metadata:
10
11
  type: core
11
12
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
13
+ library_version: 1.2.1
13
14
  ---
14
15
 
15
16
  # Softr SDK core
@@ -104,6 +105,9 @@ Letting visitors turn on push notifications, or "notify users when …"?
104
105
  Showing a date, a time or a number on a page?
105
106
  load softr-sdk/formatting
106
107
 
108
+ The favicon set in Studio does not show?
109
+ read "The app's favicon" below
110
+
107
111
  Writing a server function, loader, or middleware in general?
108
112
  not a Softr concern. Use the TanStack Start skills.
109
113
  ```
@@ -166,3 +170,11 @@ type User = {
166
170
  ## Embedding the app in another site
167
171
 
168
172
  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.
173
+
174
+ ## The app's favicon
175
+
176
+ The app's favicon is a Studio setting: Settings → General → Favicon. The app shows it, and shows the Softr icon while the setting is empty. The preview shows a change with no publish. The published app shows it after the next publish.
177
+
178
+ A `rel: 'icon'` link in `head.links` or a `public/favicon.ico` file wins over the setting. While the code has one, the Studio setting has no effect.
179
+
180
+ When the user asks why the Studio favicon does not show, check the code for an icon. When only the published app lacks it, the app needs a new publish. The published app keeps the code, the SDK and the favicon of its last publish.
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 1.2.1-alpha.0
16
+ library_version: 1.2.1
17
17
  ---
18
18
 
19
19
  **Boundary.** `ai` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineAiAction` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
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: 1.2.1-alpha.0
12
+ library_version: 1.2.1
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.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
13
13
  ---
14
14
 
15
15
  # The current user
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.2.1-alpha.0
10
+ library_version: 1.2.1
11
11
  ---
12
12
 
13
13
  **Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk` and run in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 1.2.1-alpha.0
11
+ library_version: 1.2.1
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.2.1-alpha.0
10
+ library_version: 1.2.1
11
11
  ---
12
12
 
13
13
  **Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -2,21 +2,21 @@
2
2
  name: pwa
3
3
  description: >-
4
4
  Let visitors install the app on their home screen: SoftrPwaHead for the
5
- manifest, icon, iOS name and launch screen tags, usePwaInstall to decide
6
- whether to show an install button and which platform's steps to show, the
7
- PwaInstall and PwaPlatform types, and how to check that the app is
8
- installable. The manifest and icon are already served; never write them.
5
+ manifest and icon links, usePwaInstall to decide whether to show an install
6
+ button and which platform's steps to show, the PwaInstall and PwaPlatform
7
+ types, and how to check that the app is installable. The manifest and icon are
8
+ already served; never write them.
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
13
13
  ---
14
14
 
15
15
  # Installing the app
16
16
 
17
17
  The builder turns installing on in Studio, under Settings → Mobile app, and sets the name, colour and icon there. The app already answers with its manifest and icon once they do. What the app adds is two things: the links that point the browser at them, and a button that tells visitors how to install.
18
18
 
19
- > **CRITICAL**: Never write a web app manifest, icon files, a service worker, or `manifest` / `apple-touch-icon` / `apple-touch-startup-image` links or an `apple-mobile-web-app-title` meta of your own, in `public/` or in `head()`. The app already serves them from Studio's settings, and a file or tag of your own shadows those settings.
19
+ > **CRITICAL**: Never write a web app manifest, icon files, a service worker, or `manifest` / `apple-touch-icon` links of your own, in `public/` or in `head()`. The app already serves them from Studio's settings, and a file of your own shadows those settings.
20
20
  >
21
21
  > **CRITICAL**: Render an install button only while `usePwaInstall()` returns `available: true`. Never show it unconditionally, never cache the answer, never replace the check with your own. Softr can switch installing off for an app, and this check is the only way that reaches the button.
22
22
 
@@ -48,7 +48,7 @@ The builder switches installing on in Studio, and `usePwaInstall()` reads that s
48
48
 
49
49
  ### The links: `<SoftrPwaHead />`
50
50
 
51
- Render it once, in `<head>` next to `<HeadContent />`, in `RootDocument` in `src/routes/__root.tsx`. While the app is installable it also renders the name iOS puts under the home screen icon and the iOS launch screens, so an installed app opens on its own splash screen instead of white.
51
+ Render it once, in `<head>` next to `<HeadContent />`, in `RootDocument` in `src/routes/__root.tsx`.
52
52
 
53
53
  ```tsx
54
54
  function RootDocument({ children }: { children: React.ReactNode }) {
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
13
13
  ---
14
14
 
15
15
  **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.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.2.1-alpha.0
13
+ library_version: 1.2.1
14
14
  ---
15
15
 
16
16
  **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.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.2.1-alpha.0
12
+ library_version: 1.2.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere.