@softr/sdk 1.7.0 → 1.7.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/CHANGELOG.md +14 -0
- package/dist/auth/methods/signup.js +1 -0
- package/dist/package.js +1 -1
- 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 +5 -6
- 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 +80 -13
- 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 +1 -1
- package/skills/softr-sdk/record-mutations/SKILL.md +2 -2
- package/skills/softr-sdk/record-queries/SKILL.md +1 -1
- package/skills/softr-sdk/record-queries/references/field-types.md +2 -0
- 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,19 @@
|
|
|
1
1
|
# @softr/sdk
|
|
2
2
|
|
|
3
|
+
## 1.7.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- The `file-uploads` skill maps a record's attachments to `FileAttachment` before `initialAttachments`, giving a file without an id its url as id.
|
|
8
|
+
- The `file-uploads`, `record-mutations` and `record-queries` skills write a one-file attachment field as one value or `null`.
|
|
9
|
+
- The `file-uploads` skill sets the read, upload and write shapes of an attachment side by side.
|
|
10
|
+
|
|
11
|
+
## 1.7.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- `auth.confirmSignUp` returns `invalidDetails`, not `invalidCode`, when Softr rejects the password.
|
|
16
|
+
|
|
3
17
|
## 1.7.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -48,6 +48,7 @@ async function confirmSignUp(details) {
|
|
|
48
48
|
if (!result.ok) {
|
|
49
49
|
if (result.status === 409) return authError("emailTaken", result.message);
|
|
50
50
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
51
|
+
if (result.status === 400 && result.message.startsWith("Password must be at least")) return authError("invalidDetails", result.message);
|
|
51
52
|
if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
|
|
52
53
|
if (result.status >= 500) panic(`Expected sign-up to succeed, but got ${result.status}: ` + result.message);
|
|
53
54
|
throw new Error(`${result.message}. Check SOFTR_APPLICATION_ID and that the app allows sign-up.`);
|
package/dist/package.js
CHANGED
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.7.
|
|
16
|
+
library_version: 1.7.2
|
|
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.7.
|
|
13
|
+
library_version: 1.7.2
|
|
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.
|
|
@@ -128,7 +128,7 @@ type AuthErrorCode =
|
|
|
128
128
|
| 'invalidCredentials' // signIn, signInWithGoogle, signInWithMagicLink: wrong password, or a token Softr would not take
|
|
129
129
|
| 'tooManyAttempts' // any call: rate limited
|
|
130
130
|
| 'emailTaken' // signUp, confirmSignUp: that email already has an account
|
|
131
|
-
| 'invalidDetails' // signUp, sendSignInCode, setPasswordWithLink: details Softr rejected
|
|
131
|
+
| 'invalidDetails' // signUp, sendSignInCode, setPasswordWithLink, confirmSignUp: details Softr rejected
|
|
132
132
|
| 'invalidCode' // any call that takes a code: wrong or expired
|
|
133
133
|
| 'noAccount' | 'accountDeactivated' // sendSignInCode: no account has that email, or it is deactivated
|
|
134
134
|
| 'notAuthenticated' // a call that needs a signed-in visitor, made by one who is not
|
|
@@ -137,7 +137,7 @@ type AuthErrorCode =
|
|
|
137
137
|
| 'notEnabled' // signInWithGoogle: the app's plan no longer includes Google sign-in
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
Branch on `error.code` with a `switch` and write your own wording. Never put `error.message` in front of the visitor.
|
|
140
|
+
Branch on `error.code` with a `switch` and write your own wording. Never put `error.message` in front of the visitor. The one exception is `invalidDetails` from `setPasswordWithLink` and `confirmSignUp`. Show its message: it names the password rule that failed.
|
|
141
141
|
|
|
142
142
|
`code` is typed as every code the SDK produces, not the ones a given call can answer, so a `switch` needs a `default` even when the cases above it are complete. Give it a message rather than leaving it out.
|
|
143
143
|
|
|
@@ -329,9 +329,7 @@ const link = await auth.checkPasswordLink({ token })
|
|
|
329
329
|
const result = await auth.setPasswordWithLink({ token, password })
|
|
330
330
|
```
|
|
331
331
|
|
|
332
|
-
Say "check your email" after `requestPasswordReset` either way, and never branch the UI on it.
|
|
333
|
-
|
|
334
|
-
`setPasswordWithLink` uses up the link on any success, `authenticatorRequired` included, and signs the visitor out everywhere else.
|
|
332
|
+
Say "check your email" after `requestPasswordReset` either way, and never branch the UI on it. `setPasswordWithLink` uses up the link on any success, `authenticatorRequired` included, and signs the visitor out everywhere else.
|
|
335
333
|
|
|
336
334
|
### Sign out
|
|
337
335
|
|
|
@@ -385,6 +383,7 @@ const finishSignUp = createServerFn({ method: 'POST' })
|
|
|
385
383
|
return { message: 'That email already has an account. Please sign in instead.' }
|
|
386
384
|
case 'invalidCode':
|
|
387
385
|
return { message: 'That code is not valid. Please try again.' }
|
|
386
|
+
case 'invalidDetails': return { message: result.error.message } // the password rule that failed
|
|
388
387
|
case 'tooManyAttempts':
|
|
389
388
|
return { message: 'Too many attempts. Please try again in a few minutes.' }
|
|
390
389
|
default:
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.7.
|
|
13
|
+
library_version: 1.7.2
|
|
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.
|
|
@@ -12,7 +12,7 @@ description: >-
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: sub-skill
|
|
14
14
|
library: softr-sdk
|
|
15
|
-
library_version: 1.7.
|
|
15
|
+
library_version: 1.7.2
|
|
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.7.
|
|
10
|
+
library_version: 1.7.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.
|
|
@@ -47,8 +47,9 @@ function ApplicationForm() {
|
|
|
47
47
|
<form onSubmit={async (e) => {
|
|
48
48
|
e.preventDefault()
|
|
49
49
|
if (isUploading) return
|
|
50
|
-
const resume = files.filter(f => f.status === 'done')
|
|
51
|
-
|
|
50
|
+
const resume = files.filter(f => f.status === 'done')
|
|
51
|
+
const name = String(new FormData(e.currentTarget).get('name') ?? '')
|
|
52
|
+
await submitApplication({ data: { name, resume } })
|
|
52
53
|
}}>
|
|
53
54
|
<input name="name" />
|
|
54
55
|
<input type="file" onChange={(e) => { const f = e.target.files?.[0]; if (f) upload(f) }} />
|
|
@@ -79,7 +80,23 @@ type FileAttachment = {
|
|
|
79
80
|
}
|
|
80
81
|
```
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
## Attachment shapes: read, upload and write
|
|
84
|
+
|
|
85
|
+
An attachment value has three shapes, and none of them is the other:
|
|
86
|
+
|
|
87
|
+
| Where the value comes from | Its shape |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| A record you read, `record.fields.photo` | `{ id, filename, type, url, expiresAt }` plus optional `size` and `thumbnails`. `id`, `filename` and `type` can each be `null` |
|
|
90
|
+
| An upload: a `done` item of `useFileUpload`, or what `upload` returns | `FileAttachment`: `url`, `filename` and `id` are strings |
|
|
91
|
+
| A write, the `data` of `ds.create` / `ds.update` | `{ url }`, optionally with `filename`, `id` and `type` |
|
|
92
|
+
|
|
93
|
+
Whether the field holds one file or several decides the rest. `docs/datasources/` types a one-file field `ATTACHMENT` and a several-file field `ATTACHMENT[]`.
|
|
94
|
+
|
|
95
|
+
- A one-file field reads one attachment or `null`, never an array. Its write takes one object, or `null` to clear it. Never index it with `[0]`, and never wrap it in an array.
|
|
96
|
+
- A several-file field reads an array, and its write takes an array.
|
|
97
|
+
- A read attachment and a `FileAttachment` are both valid write values as they are. Copying a file from one record to another needs no mapping.
|
|
98
|
+
- A function or schema of your own that takes attachments types `filename`, `id` and `type` as `string | null`, the way a record reads them; in zod that is `.nullish()`, not `.optional()`. A parameter typed `filename: string` refuses every attachment a record reads, and a `type` that is only optional refuses an uploaded `FileAttachment`.
|
|
99
|
+
- `initialAttachments` takes `FileAttachment[]`, which a read attachment is not. Map it first, as the edit form below does.
|
|
83
100
|
|
|
84
101
|
## FileItem shape
|
|
85
102
|
|
|
@@ -88,13 +105,13 @@ Pass `attachments` as the field value in `ds.create` / `ds.update`.
|
|
|
88
105
|
```ts
|
|
89
106
|
type FileItem =
|
|
90
107
|
| { status: 'uploading'; id: string; filename: string; progress: number; cancel: () => void }
|
|
91
|
-
| { status: 'done'
|
|
108
|
+
| (FileAttachment & { status: 'done' })
|
|
92
109
|
| { status: 'error'; id: string; filename: string; error: Error }
|
|
93
110
|
```
|
|
94
111
|
|
|
95
112
|
Items appear in insertion order and transition in place — a completed upload stays at its original position rather than moving to a separate list.
|
|
96
113
|
|
|
97
|
-
For form submission, filter to `done` items: `files.filter(f => f.status === 'done')
|
|
114
|
+
For form submission, filter to `done` items: `files.filter(f => f.status === 'done')` is a `FileAttachment[]` with no cast. A one-file field sends the first of them, `done[0] ?? null`, not the array.
|
|
98
115
|
|
|
99
116
|
## Blocking form submission
|
|
100
117
|
|
|
@@ -102,14 +119,58 @@ For form submission, filter to `done` items: `files.filter(f => f.status === 'do
|
|
|
102
119
|
|
|
103
120
|
## Edit forms: pre-loading existing attachments
|
|
104
121
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
122
|
+
A record's attachments can have a `null` id or filename, and `initialAttachments` wants strings, so map each one to a `FileAttachment` first. The upload control tells its files apart by id, so a file without one takes its url as id: two files sharing `''` would be removed together. `ds` runs only on the server, so the page loads and saves the record through server functions. Here `resume` holds several files and `photo` holds one:
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
const loadApplication = createServerFn({ method: 'GET' })
|
|
126
|
+
.validator((id: string) => id)
|
|
127
|
+
.handler(async ({ data: id }) => {
|
|
128
|
+
const record = await ds.get(applicationDetail, { id })
|
|
129
|
+
if (!record) throw notFound()
|
|
130
|
+
return record
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const saveApplication = createServerFn({ method: 'POST' })
|
|
134
|
+
.validator((data: { id: string; resume: FileAttachment[]; photo: FileAttachment | null }) => data)
|
|
135
|
+
.handler(async ({ data }) => {
|
|
136
|
+
await ds.update(updateApplication, { id: data.id, data: { resume: data.resume, photo: data.photo } })
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
export const Route = createFileRoute('/_app/applications/$id')({
|
|
140
|
+
loader: ({ params }) => loadApplication({ data: params.id }),
|
|
141
|
+
component: EditApplication,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
type ReadFile = { url: string; filename: string | null; id: string | null }
|
|
145
|
+
|
|
146
|
+
function filesOf(files: ReadFile[] | null): FileAttachment[] {
|
|
147
|
+
return (files ?? []).map((file) => ({ url: file.url, filename: file.filename ?? '', id: file.id ?? file.url }))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function EditApplication() {
|
|
151
|
+
const record = Route.useLoaderData()
|
|
152
|
+
const resume = useFileUpload(updateApplication, { initialAttachments: filesOf(record.fields.resume) })
|
|
153
|
+
const photo = useFileUpload(updateApplication, {
|
|
154
|
+
initialAttachments: filesOf(record.fields.photo === null ? null : [record.fields.photo]),
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
// the several-file field sends every done file, the one-file field its first or null
|
|
158
|
+
async function save() {
|
|
159
|
+
const photoFiles = photo.files.filter((f) => f.status === 'done')
|
|
160
|
+
const resumeFiles = resume.files.filter((f) => f.status === 'done')
|
|
161
|
+
await saveApplication({ data: { id: record.id, resume: resumeFiles, photo: photoFiles[0] ?? null } })
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// render resume.files and photo.files as in the core pattern above
|
|
165
|
+
return (
|
|
166
|
+
<button type="button" disabled={resume.isUploading || photo.isUploading} onClick={() => void save()}>
|
|
167
|
+
Save
|
|
168
|
+
</button>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
110
171
|
```
|
|
111
172
|
|
|
112
|
-
Pre-loaded attachments appear as `status: 'done'` items at the start of `files`.
|
|
173
|
+
Pre-loaded attachments appear as `status: 'done'` items at the start of `files`.
|
|
113
174
|
|
|
114
175
|
## Server-side uploads and plain forms
|
|
115
176
|
|
|
@@ -123,7 +184,7 @@ const submitResume = createServerFn({ method: 'POST' })
|
|
|
123
184
|
.handler(async ({ data }) => {
|
|
124
185
|
const uploaded = await upload(createApplication, data.get('cv') as File)
|
|
125
186
|
await ds.create(createApplication, {
|
|
126
|
-
data: { fullName: data.get('fullName') as string, cv: [uploaded] },
|
|
187
|
+
data: { fullName: data.get('fullName') as string, cv: [uploaded] }, // cv holds several files; a one-file field takes `uploaded` itself
|
|
127
188
|
})
|
|
128
189
|
return new Response(null, { status: 303, headers: { Location: '/thank-you' } })
|
|
129
190
|
})
|
|
@@ -145,6 +206,12 @@ function ApplyForm() {
|
|
|
145
206
|
|
|
146
207
|
**Not passing `initialAttachments` on an edit form.** The hook starts with an empty list. Without pre-loading, the first save erases existing attachments.
|
|
147
208
|
|
|
209
|
+
**Passing a record's attachments straight to `initialAttachments`.** Their `id` and `filename` can be `null`, and `FileAttachment` wants strings, so type-checking refuses them. Map them with `filesOf` as in the edit form above.
|
|
210
|
+
|
|
211
|
+
**Filling every missing attachment id with `''`.** Files that share an id are one file to the upload control: removing one removes them all, and the save drops them.
|
|
212
|
+
|
|
213
|
+
**Treating a one-file field as an array.** A one-file field reads one attachment or `null` and writes one object or `null`. Indexing it with `[0]`, or writing `[file]` or the whole `done` list to it, fails type-checking.
|
|
214
|
+
|
|
148
215
|
## References
|
|
149
216
|
|
|
150
217
|
- [record-mutations/SKILL.md](../record-mutations/SKILL.md): creating and updating records with the collected attachments
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.7.
|
|
10
|
+
library_version: 1.7.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: 1.7.
|
|
12
|
+
library_version: 1.7.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.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 1.7.
|
|
13
|
+
library_version: 1.7.2
|
|
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.
|
|
@@ -208,7 +208,7 @@ Each key of `data` accepts exactly what its field takes (see [record-queries](..
|
|
|
208
208
|
|
|
209
209
|
- SELECT and LINKED_RECORD take `{ id }`. Not a bare string, and not the `{ id, label }` a read returns; the label is display data and a write does not accept it. For a form select that should follow the field's choices in Studio, read them with `ds.choices` (see [record-queries](../record-queries/SKILL.md)).
|
|
210
210
|
- CHECKBOX takes a boolean. Dates take ISO strings, never `Date` instances.
|
|
211
|
-
- ATTACHMENT takes `{ url }`, optionally with `filename`, `id` and `type
|
|
211
|
+
- ATTACHMENT takes `{ url }`, optionally with `filename`, `id` and `type`: one object, or `null`, for a one-file field. A record's attachment and an uploaded file are both written as they are. [file-uploads](../file-uploads/SKILL.md#attachment-shapes-read-upload-and-write) sets the read, upload and write shapes side by side.
|
|
212
212
|
- A multi-entry field takes an array of the value.
|
|
213
213
|
|
|
214
214
|
## References
|
|
@@ -11,7 +11,7 @@ description: >-
|
|
|
11
11
|
metadata:
|
|
12
12
|
type: sub-skill
|
|
13
13
|
library: softr-sdk
|
|
14
|
-
library_version: 1.7.
|
|
14
|
+
library_version: 1.7.2
|
|
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.
|
|
@@ -60,6 +60,8 @@ Every scalar above is `| null` on the record unless the field allows multiple en
|
|
|
60
60
|
|
|
61
61
|
**USER** can lack a name or an email: show `owner?.name ?? owner?.email ?? '—'`, never assume either is there.
|
|
62
62
|
|
|
63
|
+
**ATTACHMENT** can have a `null` `id`, `filename` or `type`, so show the name as `file.filename ?? 'Untitled file'`, and type a function of your own that takes attachments the same way. A one-file field is one attachment or `null`, never an array; only an `ATTACHMENT[]` field is an array. An upload's `FileAttachment` is a different shape; see [file-uploads](../../file-uploads/SKILL.md#attachment-shapes-read-upload-and-write).
|
|
64
|
+
|
|
63
65
|
**DURATION** is milliseconds, whatever format the field displays in: `3600000` is one hour.
|
|
64
66
|
|
|
65
67
|
**DATETIME at date precision** is generated as a `DATE` field and holds `'2026-03-14'`, not a timestamp.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 1.7.
|
|
12
|
+
library_version: 1.7.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.
|