@softr/sdk 1.6.1 → 1.7.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 +12 -0
- package/dist/auth/methods/signup.js +1 -0
- package/dist/auth/methods/social.d.ts +3 -0
- package/dist/auth/methods/social.js +7 -0
- package/dist/auth/methods/utils.d.ts +1 -1
- 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 +7 -7
- 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 +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.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- `auth.confirmSignUp` returns `invalidDetails`, not `invalidCode`, when Softr rejects the password.
|
|
8
|
+
|
|
9
|
+
## 1.7.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- `auth.signInWithGoogle` fails as `notEnabled`, not `invalidCredentials`, when the app's plan no longer includes Google sign-in. Action: on that code, say Google sign-in is not available and offer the other ways in.
|
|
14
|
+
|
|
3
15
|
## 1.6.1
|
|
4
16
|
|
|
5
17
|
### Patch 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.`);
|
|
@@ -14,6 +14,9 @@ import { AuthError, Result } from "./utils.js";
|
|
|
14
14
|
* A `signedIn` result means the visitor is signed in. An app that also asks for
|
|
15
15
|
* an authenticator app answers `authenticatorRequired` instead, naming the step
|
|
16
16
|
* to send them to next.
|
|
17
|
+
*
|
|
18
|
+
* It fails as `notEnabled` when the app's plan no longer includes Google
|
|
19
|
+
* sign-in, as after a downgrade.
|
|
17
20
|
*/
|
|
18
21
|
declare function signInWithGoogle(credentials: {
|
|
19
22
|
email: string;
|
|
@@ -4,8 +4,10 @@ import { sessionConfig } from "../config.js";
|
|
|
4
4
|
import { makePlatform } from "../platform.js";
|
|
5
5
|
import { clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
|
|
6
6
|
import { authError } from "./utils.js";
|
|
7
|
+
import { z } from "zod";
|
|
7
8
|
|
|
8
9
|
//#region src/auth/methods/social.ts
|
|
10
|
+
const errorBodySchema = z.object({ code: z.string() });
|
|
9
11
|
/**
|
|
10
12
|
* Signs a visitor in with a Google token the browser obtained, creating their
|
|
11
13
|
* account the first time.
|
|
@@ -17,11 +19,16 @@ import { authError } from "./utils.js";
|
|
|
17
19
|
* A `signedIn` result means the visitor is signed in. An app that also asks for
|
|
18
20
|
* an authenticator app answers `authenticatorRequired` instead, naming the step
|
|
19
21
|
* to send them to next.
|
|
22
|
+
*
|
|
23
|
+
* It fails as `notEnabled` when the app's plan no longer includes Google
|
|
24
|
+
* sign-in, as after a downgrade.
|
|
20
25
|
*/
|
|
21
26
|
async function signInWithGoogle(credentials) {
|
|
22
27
|
const result = await makePlatform(sessionConfig().applicationId).signInWithGoogle(credentials);
|
|
23
28
|
if (!result.ok) {
|
|
24
29
|
if (result.status === 429) return authError("tooManyAttempts", result.message);
|
|
30
|
+
const body = errorBodySchema.safeParse(result.body);
|
|
31
|
+
if (body.success && body.data.code === "GOOGLE_NOT_IN_PLAN") return authError("notEnabled", result.message);
|
|
25
32
|
if (result.status === 400 && result.message.startsWith("Emails with ") && result.message.endsWith(" domain is not allowed to signup.")) return authError("emailDomainNotAllowed", result.message);
|
|
26
33
|
if (result.status === 400 || result.status === 401) return authError("invalidCredentials", result.message);
|
|
27
34
|
if (result.status >= 500) panic(`Expected Google sign-in to succeed, but got ${result.status}: ` + result.message);
|
|
@@ -10,6 +10,6 @@ type AuthError = {
|
|
|
10
10
|
code: AuthErrorCode;
|
|
11
11
|
message: string;
|
|
12
12
|
};
|
|
13
|
-
type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "noAccount" | "accountDeactivated" | "notAuthenticated" | "emailDomainNotAllowed" | "linkExpired" | "invalidName" | "fileTooLarge" | "notAnImage" | "avatarNotSupported";
|
|
13
|
+
type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "noAccount" | "accountDeactivated" | "notAuthenticated" | "emailDomainNotAllowed" | "notEnabled" | "linkExpired" | "invalidName" | "fileTooLarge" | "notAnImage" | "avatarNotSupported";
|
|
14
14
|
//#endregion
|
|
15
15
|
export { AuthError, Result };
|
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.
|
|
16
|
+
library_version: 1.7.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.
|
|
@@ -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.7.1
|
|
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,15 +128,16 @@ 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
|
|
135
135
|
| 'emailDomainNotAllowed' // signUp, signInWithGoogle: the app lets only some email domains sign up, and this is not one
|
|
136
136
|
| 'linkExpired' // checkPasswordLink, setPasswordWithLink: the link is used, expired or no longer valid
|
|
137
|
+
| 'notEnabled' // signInWithGoogle: the app's plan no longer includes Google sign-in
|
|
137
138
|
```
|
|
138
139
|
|
|
139
|
-
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.
|
|
140
141
|
|
|
141
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.
|
|
142
143
|
|
|
@@ -300,7 +301,7 @@ const result = await auth.signInWithGoogle({
|
|
|
300
301
|
})
|
|
301
302
|
```
|
|
302
303
|
|
|
303
|
-
Only an id token works. An access token, a token minted for another app, and an email that does not match it all fail as `invalidCredentials`.
|
|
304
|
+
Only an id token works. An access token, a token minted for another app, and an email that does not match it all fail as `invalidCredentials`. On a plan without Google sign-in, it fails as `notEnabled`: say Google sign-in is not available and offer the other ways in.
|
|
304
305
|
|
|
305
306
|
### Sign in with a magic link
|
|
306
307
|
|
|
@@ -328,9 +329,7 @@ const link = await auth.checkPasswordLink({ token })
|
|
|
328
329
|
const result = await auth.setPasswordWithLink({ token, password })
|
|
329
330
|
```
|
|
330
331
|
|
|
331
|
-
Say "check your email" after `requestPasswordReset` either way, and never branch the UI on it.
|
|
332
|
-
|
|
333
|
-
`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.
|
|
334
333
|
|
|
335
334
|
### Sign out
|
|
336
335
|
|
|
@@ -384,6 +383,7 @@ const finishSignUp = createServerFn({ method: 'POST' })
|
|
|
384
383
|
return { message: 'That email already has an account. Please sign in instead.' }
|
|
385
384
|
case 'invalidCode':
|
|
386
385
|
return { message: 'That code is not valid. Please try again.' }
|
|
386
|
+
case 'invalidDetails': return { message: result.error.message } // the password rule that failed
|
|
387
387
|
case 'tooManyAttempts':
|
|
388
388
|
return { message: 'Too many attempts. Please try again in a few minutes.' }
|
|
389
389
|
default:
|
|
@@ -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.7.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. `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.7.1
|
|
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.7.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.
|
|
@@ -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.7.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.
|
|
12
|
+
library_version: 1.7.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.
|
|
@@ -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.7.1
|
|
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.7.1
|
|
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.
|
|
12
|
+
library_version: 1.7.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.
|