@softr/sdk 1.4.1 → 1.4.3
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 +12 -0
- package/dist/default-error-overlay.d.ts +2 -2
- package/dist/formatting.d.ts +7 -5
- package/dist/formatting.js +20 -6
- package/dist/mcp.js +5 -3
- package/dist/package.js +1 -1
- package/dist/pwa.d.ts +2 -2
- 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 +4 -4
- 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 +26 -6
- 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 +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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @softr/sdk
|
|
2
2
|
|
|
3
|
+
## 1.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- The MCP consent page shows where the client document lives and the host the browser goes to with the code, so a user can tell a real client from one with a look-alike name.
|
|
8
|
+
|
|
9
|
+
## 1.4.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Fix: `FormattedDate` no longer fails hydration in Safari and iOS. It now renders the date in a `<span>`.
|
|
14
|
+
|
|
3
15
|
## 1.4.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react7 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): react7.JSX.Element;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { DefaultErrorOverlay };
|
package/dist/formatting.d.ts
CHANGED
|
@@ -98,10 +98,10 @@ declare function FormattingScope({
|
|
|
98
98
|
children?: ReactNode;
|
|
99
99
|
}): react0.FunctionComponentElement<react0.ProviderProps<Scope>>;
|
|
100
100
|
/**
|
|
101
|
-
* A date in the app's format, safe to render on the server. A
|
|
102
|
-
* zone is not known yet renders `fallback` until the browser
|
|
103
|
-
* the visitor never sees a UTC time. A `null` or `undefined`
|
|
104
|
-
* nothing, so a record's nullable date field needs no guard.
|
|
101
|
+
* A date in the app's format, in a `<span>`, safe to render on the server. A
|
|
102
|
+
* timestamp whose zone is not known yet renders `fallback` until the browser
|
|
103
|
+
* supplies it, so the visitor never sees a UTC time. A `null` or `undefined`
|
|
104
|
+
* value renders nothing, so a record's nullable date field needs no guard.
|
|
105
105
|
*
|
|
106
106
|
* @example
|
|
107
107
|
* <FormattedDate value={bug.fields.created} />
|
|
@@ -118,6 +118,8 @@ declare function FormattedDate({
|
|
|
118
118
|
time?: boolean;
|
|
119
119
|
/** What renders while the visitor's zone is unknown. */
|
|
120
120
|
fallback?: ReactNode;
|
|
121
|
-
}): react0.FunctionComponentElement<react0.FragmentProps> |
|
|
121
|
+
}): react0.FunctionComponentElement<react0.FragmentProps> | react0.DetailedReactHTMLElement<{
|
|
122
|
+
suppressHydrationWarning: true;
|
|
123
|
+
}, HTMLElement> | null;
|
|
122
124
|
//#endregion
|
|
123
125
|
export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };
|
package/dist/formatting.js
CHANGED
|
@@ -122,7 +122,7 @@ function useFormatting() {
|
|
|
122
122
|
select: (context) => context.formatting
|
|
123
123
|
});
|
|
124
124
|
const scope = useContext(ScopeContext);
|
|
125
|
-
const hydrated =
|
|
125
|
+
const hydrated = useHydrated();
|
|
126
126
|
return useMemo(() => {
|
|
127
127
|
const scoped = {
|
|
128
128
|
...resolved,
|
|
@@ -172,10 +172,10 @@ function FormattingScope({ timeZone, locale, children }) {
|
|
|
172
172
|
return createElement(ScopeContext.Provider, { value }, children);
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
-
* A date in the app's format, safe to render on the server. A
|
|
176
|
-
* zone is not known yet renders `fallback` until the browser
|
|
177
|
-
* the visitor never sees a UTC time. A `null` or `undefined`
|
|
178
|
-
* nothing, so a record's nullable date field needs no guard.
|
|
175
|
+
* A date in the app's format, in a `<span>`, safe to render on the server. A
|
|
176
|
+
* timestamp whose zone is not known yet renders `fallback` until the browser
|
|
177
|
+
* supplies it, so the visitor never sees a UTC time. A `null` or `undefined`
|
|
178
|
+
* value renders nothing, so a record's nullable date field needs no guard.
|
|
179
179
|
*
|
|
180
180
|
* @example
|
|
181
181
|
* <FormattedDate value={bug.fields.created} />
|
|
@@ -183,13 +183,27 @@ function FormattingScope({ timeZone, locale, children }) {
|
|
|
183
183
|
*/
|
|
184
184
|
function FormattedDate({ value, time = false, fallback = null,...options }) {
|
|
185
185
|
const formatting = useFormatting();
|
|
186
|
+
const hydrated = useHydrated();
|
|
186
187
|
if (value === null || value === void 0) return null;
|
|
187
188
|
if (!isCalendarDay(value) && zoneFor(formatting, options) === null) return createElement(Fragment, null, fallback);
|
|
188
|
-
return createElement(
|
|
189
|
+
return createElement("span", { suppressHydrationWarning: true }, !hydrated && typeof document !== "undefined" ? "" : (time ? formatDateTime : formatDate)(value, formatting, options));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* False on the server and while React hydrates, true after. The callbacks live at module level, so React
|
|
193
|
+
* does not schedule a snapshot check on each render.
|
|
194
|
+
*/
|
|
195
|
+
function useHydrated() {
|
|
196
|
+
return useSyncExternalStore(subscribeNever, snapshotHydrated, snapshotServer);
|
|
189
197
|
}
|
|
190
198
|
function subscribeNever() {
|
|
191
199
|
return () => {};
|
|
192
200
|
}
|
|
201
|
+
function snapshotHydrated() {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
function snapshotServer() {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
193
207
|
const CALENDAR_DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
194
208
|
/** A calendar day such as `2026-10-06` names the same day in every zone, so it needs none. */
|
|
195
209
|
function isCalendarDay(value) {
|
package/dist/mcp.js
CHANGED
|
@@ -103,7 +103,7 @@ async function authorize(request, login) {
|
|
|
103
103
|
if (user === null || sessionToken === null) return html(200, signInPage(url, login));
|
|
104
104
|
const client = await platformConsent(query.data);
|
|
105
105
|
if (!client.ok) return html(400, page("We can't connect this right now", escapeHtml(client.message)));
|
|
106
|
-
if (request.method === "GET") return html(200, consentPage(user, url, client.name));
|
|
106
|
+
if (request.method === "GET") return html(200, consentPage(user, url, client.name, query.data));
|
|
107
107
|
const form = await request.formData();
|
|
108
108
|
const decision = await platformApprove(sessionToken, query.data, form.get("decision") === "allow");
|
|
109
109
|
if (!decision.ok) return html(502, page("We could not finish this", decision.message));
|
|
@@ -534,8 +534,10 @@ function html(status, body) {
|
|
|
534
534
|
}
|
|
535
535
|
});
|
|
536
536
|
}
|
|
537
|
-
function consentPage(user, url, clientName) {
|
|
538
|
-
|
|
537
|
+
function consentPage(user, url, clientName, query) {
|
|
538
|
+
const clientHost = query.client_id.startsWith("https://") ? `Client registered at ${escapeHtml(new URL(query.client_id).host)}. ` : "";
|
|
539
|
+
const redirectHost = `It will send you back to ${escapeHtml(new URL(query.redirect_uri).host)}.`;
|
|
540
|
+
return page("Connect to this app?", `<strong>${escapeHtml(clientName)}</strong> is asking to use this app as <strong>${escapeHtml(user.fullName || user.email)}</strong>. It will see only what you can see.<br><small>${clientHost}${redirectHost}</small>`, `<form method="post" action="${escapeHtml(url.pathname + url.search)}">
|
|
539
541
|
<button type="submit" name="decision" value="allow" class="primary">Allow</button>
|
|
540
542
|
<button type="submit" name="decision" value="deny">Cancel</button>
|
|
541
543
|
</form>`);
|
package/dist/package.js
CHANGED
package/dist/pwa.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react5 from "react";
|
|
2
2
|
import "@tanstack/react-start";
|
|
3
3
|
|
|
4
4
|
//#region src/pwa.d.ts
|
|
@@ -24,7 +24,7 @@ import "@tanstack/react-start";
|
|
|
24
24
|
* )
|
|
25
25
|
* }
|
|
26
26
|
*/
|
|
27
|
-
declare function SoftrPwaHead():
|
|
27
|
+
declare function SoftrPwaHead(): react5.FunctionComponentElement<react5.FragmentProps>;
|
|
28
28
|
type PwaPlatform = "ios" | "android" | "desktop";
|
|
29
29
|
type PwaInstall = {
|
|
30
30
|
available: false;
|
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.4.
|
|
16
|
+
library_version: 1.4.3
|
|
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.
|
|
@@ -4,13 +4,13 @@ description: >-
|
|
|
4
4
|
Sign a visitor in, out or up from a server function with auth from
|
|
5
5
|
@softr/sdk/server: password, code, Google and magic link, sign-up and its
|
|
6
6
|
confirmation, the emailed-code and authenticator-app steps, password reset
|
|
7
|
-
links, updateProfile, getAuthSettings and useAuthSettings, and
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
links, updateProfile, getAuthSettings and useAuthSettings, and useIdleTimeout
|
|
8
|
+
for "End session if idle". Covers the Result shape, its error codes, and
|
|
9
|
+
toReturnPath.
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.4.
|
|
13
|
+
library_version: 1.4.3
|
|
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.4.
|
|
13
|
+
library_version: 1.4.3
|
|
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. `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: 1.4.
|
|
10
|
+
library_version: 1.4.3
|
|
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,16 +8,18 @@ description: >-
|
|
|
8
8
|
metadata:
|
|
9
9
|
type: sub-skill
|
|
10
10
|
library: softr-sdk
|
|
11
|
-
library_version: 1.4.
|
|
11
|
+
library_version: 1.4.3
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
# Dates, times and numbers
|
|
15
15
|
|
|
16
|
-
Softr stores every date and time as UTC. The builder chooses in Studio how the app shows dates, times and numbers: in each visitor's own format and zone (the default), or in one fixed format or zone for everyone. The SDK resolves that choice once per request. The server and the browser then format with the same values, so the page the server renders and the page the browser hydrates
|
|
16
|
+
Softr stores every date and time as UTC. The builder chooses in Studio how the app shows dates, times and numbers: in each visitor's own format and zone (the default), or in one fixed format or zone for everyone. The SDK resolves that choice once per request. The server and the browser then format with the same values, so the page the server renders and the page the browser hydrates use the same settings.
|
|
17
17
|
|
|
18
18
|
> **CRITICAL**: Never call `toLocaleDateString`, `toLocaleTimeString`, `toLocaleString` or `new Intl.DateTimeFormat` / `new Intl.NumberFormat` in code that renders. The server and the browser have different locales and time zones, so the text differs and React throws a hydration mismatch. A hard-coded `'en-US'` or `timeZone: 'UTC'` hides the error but ignores the builder's settings and shows the wrong format and day to most visitors.
|
|
19
19
|
>
|
|
20
|
-
> **CRITICAL**: Format with the helpers below and nothing else. They follow the app's settings
|
|
20
|
+
> **CRITICAL**: Format with the helpers below and nothing else. They follow the app's settings.
|
|
21
|
+
>
|
|
22
|
+
> **CRITICAL**: Show a date in JSX with `<FormattedDate />`, never with `formatDate` or `formatDateTime`. Each browser engine has its own locale data, so Safari writes `1 Sep 2026` where the server writes `1 Sept 2026`, and `Sep 1, 2026 at 3:05 PM` where the server writes `Sep 1, 2026, 3:05 PM`. A string from the functions in JSX fails hydration in those browsers, and `<FormattedDate />` does not.
|
|
21
23
|
|
|
22
24
|
## Setup
|
|
23
25
|
|
|
@@ -56,7 +58,7 @@ type DateOptions = {
|
|
|
56
58
|
<FormattedDate value={task.fields.due} dateStyle="medium" />
|
|
57
59
|
```
|
|
58
60
|
|
|
59
|
-
A timestamp (`DATETIME`, `CREATED_AT`, `UPDATED_AT`) is a UTC instant and needs a time zone. On a visitor's first page load their zone can be unknown, and then `FormattedDate` renders its `fallback` (nothing by default) until the browser supplies it. A calendar day (`DATE`, such as `2026-10-06`) names the same day everywhere and always renders at once. `dateStyle` applies only when the app uses the visitor's format; a fixed format ignores it.
|
|
61
|
+
It renders the date in a `<span>`. A timestamp (`DATETIME`, `CREATED_AT`, `UPDATED_AT`) is a UTC instant and needs a time zone. On a visitor's first page load their zone can be unknown, and then `FormattedDate` renders its `fallback` (nothing by default) until the browser supplies it. A calendar day (`DATE`, such as `2026-10-06`) names the same day everywhere and always renders at once. `dateStyle` applies only when the app uses the visitor's format; a fixed format ignores it.
|
|
60
62
|
|
|
61
63
|
There is no `timeStyle`. `time` and `formatDateTime` add the time in the app's style, with or without `dateStyle`. For the time alone, use `parts`.
|
|
62
64
|
|
|
@@ -98,7 +100,7 @@ Say which zone a fixed-zone time is in, so a visitor elsewhere does not read it
|
|
|
98
100
|
|
|
99
101
|
### Text outside JSX: `useFormatting()` and the format functions
|
|
100
102
|
|
|
101
|
-
Use these for a string prop, an `aria-label`, a chart axis, or a sort key shown to the visitor.
|
|
103
|
+
Use these for a string prop, an `aria-label`, a chart axis, or a sort key shown to the visitor. A date in the page's text still goes through `<FormattedDate />`.
|
|
102
104
|
|
|
103
105
|
```tsx
|
|
104
106
|
function BugRow({ bug }: { bug: Bug }) {
|
|
@@ -107,6 +109,7 @@ function BugRow({ bug }: { bug: Bug }) {
|
|
|
107
109
|
<li title={`Created ${formatDateTime(bug.fields.created, formatting)}`}>
|
|
108
110
|
{bug.fields.title}
|
|
109
111
|
<span>{formatNumber(bug.fields.votes, formatting)}</span>
|
|
112
|
+
<FormattedDate value={bug.fields.created} dateStyle="medium" />
|
|
110
113
|
</li>
|
|
111
114
|
)
|
|
112
115
|
}
|
|
@@ -121,7 +124,7 @@ formatNumber(99, formatting, { style: 'currency', currency: 'EUR' })
|
|
|
121
124
|
|
|
122
125
|
The currency comes from the field or from the user, never from the locale. A German visitor looking at a price in dollars still sees dollars.
|
|
123
126
|
|
|
124
|
-
`formatDate` and `formatDateTime` show a timestamp in UTC while `formatting.timeZone` is `null`.
|
|
127
|
+
`formatDate` and `formatDateTime` show a timestamp in UTC while `formatting.timeZone` is `null`. `<FormattedDate />` waits instead. A `null` or `undefined` value returns `''` from the functions and renders nothing from `<FormattedDate />`, so a record's nullable date field needs no guard.
|
|
125
128
|
|
|
126
129
|
### A field's own text: `formatValue`
|
|
127
130
|
|
|
@@ -199,6 +202,23 @@ Correct:
|
|
|
199
202
|
|
|
200
203
|
The server renders `10/6/2026` and a browser in Europe renders `06/10/2026`. React rejects the page, and the builder's date settings are ignored on both sides.
|
|
201
204
|
|
|
205
|
+
### CRITICAL: A date string in JSX
|
|
206
|
+
|
|
207
|
+
Wrong:
|
|
208
|
+
|
|
209
|
+
```tsx
|
|
210
|
+
const formatting = useFormatting()
|
|
211
|
+
<span>{formatDateTime(bug.fields.created, formatting, { dateStyle: 'medium' })}</span>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Correct:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
<FormattedDate value={bug.fields.created} time dateStyle="medium" />
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Safari and every iOS browser write some dates differently from the server, such as `Sep` for `Sept` or `at` for a comma. React rejects the page in those browsers.
|
|
221
|
+
|
|
202
222
|
### HIGH: Forcing one locale or zone to silence the mismatch
|
|
203
223
|
|
|
204
224
|
Wrong:
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.4.
|
|
10
|
+
library_version: 1.4.3
|
|
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.4.
|
|
12
|
+
library_version: 1.4.3
|
|
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.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.4.
|
|
13
|
+
library_version: 1.4.3
|
|
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.4.
|
|
14
|
+
library_version: 1.4.3
|
|
15
15
|
---
|
|
16
16
|
|
|
17
17
|
**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.4.
|
|
12
|
+
library_version: 1.4.3
|
|
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.
|