@softr/sdk 1.7.7 → 1.8.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/CHANGELOG.md +6 -0
- package/dist/package.js +1 -1
- package/dist/pwa.d.ts +18 -1
- package/dist/pwa.js +49 -5
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +1 -1
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +1 -1
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
- package/skills/softr-sdk/current-user/SKILL.md +1 -1
- package/skills/softr-sdk/email/SKILL.md +1 -1
- package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
- package/skills/softr-sdk/formatting/SKILL.md +1 -1
- package/skills/softr-sdk/integrations/SKILL.md +1 -1
- package/skills/softr-sdk/mcp/SKILL.md +1 -1
- package/skills/softr-sdk/push-notifications/SKILL.md +1 -1
- package/skills/softr-sdk/pwa/SKILL.md +19 -4
- 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/CHANGELOG.md
CHANGED
package/dist/package.js
CHANGED
package/dist/pwa.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ import "@tanstack/react-start";
|
|
|
26
26
|
*/
|
|
27
27
|
declare function SoftrPwaHead(): react5.FunctionComponentElement<react5.FragmentProps>;
|
|
28
28
|
type PwaPlatform = "ios" | "android" | "desktop";
|
|
29
|
+
type InstallChoice = "accepted" | "dismissed";
|
|
29
30
|
type PwaInstall = {
|
|
30
31
|
available: false;
|
|
31
32
|
} | {
|
|
@@ -36,6 +37,12 @@ type PwaInstall = {
|
|
|
36
37
|
name: string;
|
|
37
38
|
/** The icon the home screen will show. */
|
|
38
39
|
iconUrl: string;
|
|
40
|
+
/**
|
|
41
|
+
* Opens the browser's own install dialog. Only there while the browser offers one: never in
|
|
42
|
+
* iOS, Safari, Firefox or the Studio preview, and not again once the visitor has closed it.
|
|
43
|
+
* Call it from a click, and show the steps for `platform` while it is missing or rejects.
|
|
44
|
+
*/
|
|
45
|
+
install?: () => Promise<InstallChoice>;
|
|
39
46
|
};
|
|
40
47
|
/**
|
|
41
48
|
* Whether to offer installing the app, and on which platform. Render an
|
|
@@ -47,7 +54,17 @@ type PwaInstall = {
|
|
|
47
54
|
* function InstallButton() {
|
|
48
55
|
* const install = usePwaInstall()
|
|
49
56
|
* if (!install.available) return null
|
|
50
|
-
* return
|
|
57
|
+
* return (
|
|
58
|
+
* <button
|
|
59
|
+
* onClick={() =>
|
|
60
|
+
* install.install
|
|
61
|
+
* ? install.install().catch(() => openSteps(install.platform))
|
|
62
|
+
* : openSteps(install.platform)
|
|
63
|
+
* }
|
|
64
|
+
* >
|
|
65
|
+
* Install {install.name}
|
|
66
|
+
* </button>
|
|
67
|
+
* )
|
|
51
68
|
* }
|
|
52
69
|
*/
|
|
53
70
|
declare function usePwaInstall(): PwaInstall;
|
package/dist/pwa.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fetch } from "./fetch.js";
|
|
|
4
4
|
import { sessionConfig } from "./auth/config.js";
|
|
5
5
|
import { readCached } from "./cache.js";
|
|
6
6
|
import { z } from "zod";
|
|
7
|
-
import { Fragment, createElement, useEffect, useState } from "react";
|
|
7
|
+
import { Fragment, createElement, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
8
8
|
import { createMiddleware } from "@tanstack/react-start";
|
|
9
9
|
|
|
10
10
|
//#region src/pwa.ts
|
|
@@ -139,6 +139,22 @@ function SoftrPwaHead() {
|
|
|
139
139
|
href: image.href
|
|
140
140
|
})));
|
|
141
141
|
}
|
|
142
|
+
function isInstallPromptEvent(event) {
|
|
143
|
+
return "prompt" in event && typeof event.prompt === "function" && "userChoice" in event;
|
|
144
|
+
}
|
|
145
|
+
let offeredPrompt = null;
|
|
146
|
+
const offerListeners = /* @__PURE__ */ new Set();
|
|
147
|
+
function setOfferedPrompt(next) {
|
|
148
|
+
offeredPrompt = next;
|
|
149
|
+
for (const listener of offerListeners) listener();
|
|
150
|
+
}
|
|
151
|
+
if (typeof window !== "undefined") {
|
|
152
|
+
window.addEventListener("beforeinstallprompt", (event) => {
|
|
153
|
+
if (!isInstallPromptEvent(event)) return;
|
|
154
|
+
setOfferedPrompt(event);
|
|
155
|
+
});
|
|
156
|
+
window.addEventListener("appinstalled", () => setOfferedPrompt(null));
|
|
157
|
+
}
|
|
142
158
|
const installSchema = pwaSchema.shape.install;
|
|
143
159
|
/**
|
|
144
160
|
* Whether to offer installing the app, and on which platform. Render an
|
|
@@ -150,21 +166,38 @@ const installSchema = pwaSchema.shape.install;
|
|
|
150
166
|
* function InstallButton() {
|
|
151
167
|
* const install = usePwaInstall()
|
|
152
168
|
* if (!install.available) return null
|
|
153
|
-
* return
|
|
169
|
+
* return (
|
|
170
|
+
* <button
|
|
171
|
+
* onClick={() =>
|
|
172
|
+
* install.install
|
|
173
|
+
* ? install.install().catch(() => openSteps(install.platform))
|
|
174
|
+
* : openSteps(install.platform)
|
|
175
|
+
* }
|
|
176
|
+
* >
|
|
177
|
+
* Install {install.name}
|
|
178
|
+
* </button>
|
|
179
|
+
* )
|
|
154
180
|
* }
|
|
155
181
|
*/
|
|
156
182
|
function usePwaInstall() {
|
|
157
183
|
const [install, setInstall] = useState({ available: false });
|
|
184
|
+
const offered = useSyncExternalStore((listener) => {
|
|
185
|
+
offerListeners.add(listener);
|
|
186
|
+
return () => offerListeners.delete(listener);
|
|
187
|
+
}, () => offeredPrompt, () => null);
|
|
158
188
|
useEffect(() => {
|
|
159
189
|
if (isStandalone()) return;
|
|
160
190
|
let cancelled = false;
|
|
161
191
|
const standaloneQuery = window.matchMedia(STANDALONE_QUERY);
|
|
162
|
-
const
|
|
163
|
-
if (!standaloneQuery.matches) return;
|
|
192
|
+
const hide = () => {
|
|
164
193
|
cancelled = true;
|
|
165
194
|
setInstall({ available: false });
|
|
166
195
|
};
|
|
196
|
+
const hideOnceStandalone = () => {
|
|
197
|
+
if (standaloneQuery.matches) hide();
|
|
198
|
+
};
|
|
167
199
|
standaloneQuery.addEventListener("change", hideOnceStandalone);
|
|
200
|
+
window.addEventListener("appinstalled", hide);
|
|
168
201
|
fetchInstallInfo().then((installInfo) => {
|
|
169
202
|
const parsed = installSchema.safeParse(installInfo);
|
|
170
203
|
if (!parsed.success || cancelled) return;
|
|
@@ -177,9 +210,20 @@ function usePwaInstall() {
|
|
|
177
210
|
return () => {
|
|
178
211
|
cancelled = true;
|
|
179
212
|
standaloneQuery.removeEventListener("change", hideOnceStandalone);
|
|
213
|
+
window.removeEventListener("appinstalled", hide);
|
|
180
214
|
};
|
|
181
215
|
}, []);
|
|
182
|
-
return
|
|
216
|
+
return useMemo(() => {
|
|
217
|
+
if (!install.available || offered === null) return install;
|
|
218
|
+
return {
|
|
219
|
+
...install,
|
|
220
|
+
install: async () => {
|
|
221
|
+
await offered.prompt();
|
|
222
|
+
setOfferedPrompt(null);
|
|
223
|
+
return (await offered.userChoice).outcome;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}, [install, offered]);
|
|
183
227
|
}
|
|
184
228
|
function detectPlatform() {
|
|
185
229
|
const userAgent = navigator.userAgent;
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 1.
|
|
16
|
+
library_version: 1.8.0
|
|
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.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.
|
|
13
|
+
library_version: 1.8.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.
|
|
13
|
+
library_version: 1.8.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A helper that calls `ds` outside a handler goes in `createServerOnlyFn` from `@tanstack/react-start` (the `record-queries` boundary). `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -12,7 +12,7 @@ description: >-
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: sub-skill
|
|
14
14
|
library: softr-sdk
|
|
15
|
-
library_version: 1.
|
|
15
|
+
library_version: 1.8.0
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
**Boundary.** `email` and `EmailError` live on `@softr/sdk/server` and run only inside a `createServerFn` handler — importing them into a component fails the build. `defineEmailAction` 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: 1.
|
|
10
|
+
library_version: 1.8.0
|
|
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: 1.
|
|
10
|
+
library_version: 1.8.0
|
|
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.
|
|
12
|
+
library_version: 1.8.0
|
|
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.
|
|
@@ -3,13 +3,13 @@ name: pwa
|
|
|
3
3
|
description: >-
|
|
4
4
|
Let visitors install the app on their home screen: SoftrPwaHead for the
|
|
5
5
|
manifest, icon, iOS name and launch screen tags, usePwaInstall to decide
|
|
6
|
-
whether to show an install button
|
|
7
|
-
PwaInstall and PwaPlatform types, and how to check that the app is
|
|
6
|
+
whether to show an install button, which platform's steps to show and, when
|
|
7
|
+
the browser offers it, install() for its own install dialog, the PwaInstall and PwaPlatform types, and how to check that the app is
|
|
8
8
|
installable. The manifest and icon are already served; never write them.
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 1.
|
|
12
|
+
library_version: 1.8.0
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
# Installing the app
|
|
@@ -37,6 +37,7 @@ type PwaInstall =
|
|
|
37
37
|
platform: PwaPlatform // which steps install the app on this device
|
|
38
38
|
name: string // what the home screen will show
|
|
39
39
|
iconUrl: string // the icon the home screen will show
|
|
40
|
+
install?: () => Promise<'accepted' | 'dismissed'> // the browser's own install dialog, when offered
|
|
40
41
|
}
|
|
41
42
|
```
|
|
42
43
|
|
|
@@ -71,7 +72,21 @@ function RootDocument({ children }: { children: React.ReactNode }) {
|
|
|
71
72
|
|
|
72
73
|
It fetches after mount, so the first render, the server render included, always says `available: false`. It stays unavailable when the app is not installable, when the request fails, and when the app already runs installed from the home screen. Inside the Studio preview it says available, so the builder can see the button; installing itself only works on the published app.
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
`install` is there only while the browser offers its own install dialog: Chrome and Edge, on desktop and Android, and not in the Studio preview. Call it from a click. It rejects when the browser refuses the prompt, so open the steps then. It resolves with what the visitor chose, and the button disappears by itself once the app is installed. The browser shows its dialog only once per offer, so after the visitor closes it, `install` is gone until the browser offers again.
|
|
76
|
+
|
|
77
|
+
When `install` is missing, the button opens steps for `platform` instead: Share, then Add to Home Screen on iOS; the browser menu's Install app on Android and desktop. Safari and Firefox never offer the dialog. `name` and `iconUrl` tell the visitor what they are adding.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
<button
|
|
81
|
+
onClick={() =>
|
|
82
|
+
install.install
|
|
83
|
+
? install.install().catch(() => openSteps(install.platform))
|
|
84
|
+
: openSteps(install.platform)
|
|
85
|
+
}
|
|
86
|
+
>
|
|
87
|
+
Install {install.name}
|
|
88
|
+
</button>
|
|
89
|
+
```
|
|
75
90
|
|
|
76
91
|
## References
|
|
77
92
|
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.
|
|
13
|
+
library_version: 1.8.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**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.
|
|
@@ -11,7 +11,7 @@ description: >-
|
|
|
11
11
|
metadata:
|
|
12
12
|
type: sub-skill
|
|
13
13
|
library: softr-sdk
|
|
14
|
-
library_version: 1.
|
|
14
|
+
library_version: 1.8.0
|
|
15
15
|
---
|
|
16
16
|
|
|
17
17
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A route `loader` also runs in the browser, so it calls a server function, never `ds`. A helper that calls `ds` outside a handler, in this file or in another one, goes in `createServerOnlyFn` from `@tanstack/react-start`, or inside the handler. An exported helper without it keeps the server-only import in the browser bundle, and every page stops loading until it moves. Do not make such a helper a server function when it takes an id: any visitor can call a server function with any id. `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.
|
|
12
|
+
library_version: 1.8.0
|
|
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.
|