@softr/sdk 1.16.0-alpha.2 → 1.16.0-se23079.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +22 -2
  2. package/dist/auth/isomorphic.d.ts +1 -3
  3. package/dist/auth/isomorphic.js +3 -2
  4. package/dist/auth/methods/authenticator.js +8 -1
  5. package/dist/auth/methods/code.js +5 -1
  6. package/dist/auth/methods/emailCode2fa.js +4 -1
  7. package/dist/auth/methods/magicLink.js +4 -1
  8. package/dist/auth/methods/password.js +3 -1
  9. package/dist/auth/methods/passwordLink.js +5 -1
  10. package/dist/auth/methods/signup.js +7 -1
  11. package/dist/auth/methods/social.js +4 -5
  12. package/dist/auth/methods/utils.d.ts +4 -1
  13. package/dist/auth/methods/utils.js +30 -1
  14. package/dist/auth/platform.d.ts +0 -1
  15. package/dist/auth/platform.js +1 -14
  16. package/dist/auth/sso.d.ts +1 -24
  17. package/dist/auth/sso.js +9 -79
  18. package/dist/datasource/chart.js +5 -0
  19. package/dist/datasource/record.js +1 -0
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.js +2 -2
  22. package/dist/mcp.d.ts +2 -2
  23. package/dist/package.js +1 -1
  24. package/dist/route/access-denied-status.js +25 -0
  25. package/dist/route/route.js +15 -3
  26. package/dist/tool.d.ts +7 -2
  27. package/dist/tool.js +1 -0
  28. package/package.json +43 -16
  29. package/skills/softr-sdk/SKILL.md +1 -1
  30. package/skills/softr-sdk/ai/SKILL.md +1 -1
  31. package/skills/softr-sdk/auth/SKILL.md +4 -4
  32. package/skills/softr-sdk/auth/references/single-sign-on.md +0 -25
  33. package/skills/softr-sdk/charts-and-metrics/SKILL.md +3 -1
  34. package/skills/softr-sdk/current-user/SKILL.md +1 -1
  35. package/skills/softr-sdk/email/SKILL.md +1 -1
  36. package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
  37. package/skills/softr-sdk/formatting/SKILL.md +6 -5
  38. package/skills/softr-sdk/integrations/SKILL.md +1 -1
  39. package/skills/softr-sdk/mcp/SKILL.md +26 -12
  40. package/skills/softr-sdk/push-notifications/SKILL.md +1 -1
  41. package/skills/softr-sdk/pwa/SKILL.md +1 -1
  42. package/skills/softr-sdk/record-mutations/SKILL.md +4 -2
  43. package/skills/softr-sdk/record-queries/SKILL.md +21 -1
  44. package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
  45. package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
  46. package/skills/softr-sdk/workflows/SKILL.md +1 -1
package/CHANGELOG.md CHANGED
@@ -1,10 +1,30 @@
1
1
  # @softr/sdk
2
2
 
3
- ## 1.16.0-alpha.2
3
+ ## 1.16.0
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - Log in with Softr: workspace members sign in to the app with their Softr account. `softrSignInHref(returnPath?)` gives the link, and `AuthOptions.softr` tells the login page to show the button. A failed Softr login lands on the SSO page with `method=softr`, the login redirect param and an `error`, which is `softr-rejected` (type `SoftrLoginError`) when Softr did not let the account in, or `softr-sso-account` when the account signs in with the single sign-on that the app also offers. Action: on the SSO page, when `method` is `softr`, link "Try again" to `softrSignInHref(toReturnPath(location).href)`.
7
+ - Every `auth` call that signs a visitor in or up fails as `userLimitReached` when the plan of the app's workspace has no room for this user. Before, `auth.signIn` threw, and the other calls answered `invalidCode`, `invalidCredentials`, `invalidDetails` or `linkExpired`. Action: on the login and sign-up pages, give `userLimitReached` its own `case` and say the app has reached its user limit and the app owner can fix it.
8
+ - `auth.sendSignInCode`, `auth.signInWithCode`, and `auth.signUp` and `auth.confirmSignUp` without a password fail as `notEnabled` when the plan of the app's workspace does not include one-time email codes, as after a downgrade. Before, these calls worked on every plan. Action: on the login and sign-up pages, give `notEnabled` its own `case`, say this way to sign in is not available, and offer the other ways in.
9
+ - New error code `secondFactorNotEnabled`: the visitor owes a second step that the plan of the app's workspace does not include, as after a downgrade. Every call that signs a visitor in answers it in an app that asks that visitor for an authenticator step, and so does `auth.startAuthenticatorSetup`. `auth.signIn`, `auth.verifyEmailCode` and `auth.resendEmailCode` answer it in an app that asks for an emailed code after the password. Before, these calls worked on every plan. Action: give `secondFactorNotEnabled` its own `case` on the pages that sign a visitor in and on the page that sets up an authenticator. Say sign-in is not available on the app's plan and the app owner can fix it. Do not offer another way to sign in, because no way works.
10
+
11
+ ## 1.15.4
12
+
13
+ ### Patch Changes
14
+
15
+ - Skills: the mcp skill and the `defineTool` docs now say that a tool's handler never calls `ds`, or anything else from `@softr/sdk/server`, itself. `src/start.ts` imports the tools and is part of the browser bundle, so such a handler fails the production build. Action: move each such call into a helper wrapped in `createServerOnlyFn` from `@tanstack/react-start`, and call the helper from the handler.
16
+
17
+ ## 1.15.3
18
+
19
+ ### Patch Changes
20
+
21
+ - A `ds.get`, `ds.chart` or `ds.metric` builder reads again after a call such as `where` changes it, the same as `ds.list` and `ds.export`. Before, it answered the result of its first read and left out the new filter. Skills: record-queries and charts-and-metrics say that one builder is for one read, because `where` and `orderBy` add to the builder they are called on. No action is needed.
22
+
23
+ ## 1.15.2
24
+
25
+ ### Patch Changes
26
+
27
+ - A page that a route guard refuses with the `throw` strategy (`guardRoute`, `assertRouteAccess`) answers 403 instead of 500 when `softrAuthMiddleware` is registered, with an `x-softr-access-denied` header that names the reason. The page still shows the route's `errorComponent`. The guard no longer logs the refusal as an error, on the server or in the browser. Without `softrAuthMiddleware`, a refused page still answers 500. No action is needed.
8
28
 
9
29
  ## 1.15.1
10
30
 
@@ -21,7 +21,7 @@ import * as _tanstack_react_start0 from "@tanstack/react-start";
21
21
  * requestMiddleware: [softrAuthMiddleware()],
22
22
  * }))
23
23
  */
24
- declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
24
+ declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
25
25
  user: User | null;
26
26
  permissions: {
27
27
  datasources: {};
@@ -77,8 +77,6 @@ type AuthOptions = {
77
77
  sso: {
78
78
  type: "SAML" | "OPEN_ID";
79
79
  } | null;
80
- /** Sign-in with a Softr Studio account: a link to `softrSignInHref`. */
81
- softr: boolean;
82
80
  /** `auth.signUp`, then `auth.confirmSignUp` */
83
81
  signUp: boolean;
84
82
  /** The builder asked for strong passwords whenever a visitor sets one. */
@@ -14,6 +14,7 @@ import { pushMiddleware } from "../push.js";
14
14
  import { faviconMiddleware } from "../favicon.js";
15
15
  import { embeddingMiddleware } from "../embedding.js";
16
16
  import { appIdentityMiddleware } from "../app-identity.js";
17
+ import { accessDeniedStatusMiddleware } from "../route/access-denied-status.js";
17
18
  import { getRequestHeader } from "@tanstack/react-start/server";
18
19
  import { createContext, useContext } from "react";
19
20
  import { createMiddleware, createServerFn } from "@tanstack/react-start";
@@ -43,7 +44,8 @@ function softrAuthMiddleware() {
43
44
  pwaMiddleware(),
44
45
  pushMiddleware(),
45
46
  faviconMiddleware(),
46
- ssoMiddleware()
47
+ ssoMiddleware(),
48
+ accessDeniedStatusMiddleware()
47
49
  ]).server(async ({ next }) => {
48
50
  async function getSession() {
49
51
  const token = readSessionToken();
@@ -132,7 +134,6 @@ const getAuthSettings = createServerFn({ method: "GET" }).handler(async () => {
132
134
  magicLink: on("MAGIC_LINK"),
133
135
  google: on("GOOGLE") && clientId ? { clientId } : null,
134
136
  sso: on("SSO") && raw.sso?.type ? { type: raw.sso.type } : null,
135
- softr: raw.loginEnabled && raw.softrLogin === true,
136
137
  signUp: raw.loginEnabled && (raw.signUpPolicy === "OPEN_TO_PUBLIC" || raw.signUpPolicy === "DOMAIN_RESTRICTED"),
137
138
  strongPasswords: on("EMAIL") && (raw.emailAuth?.strongPasswords ?? false)
138
139
  };
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
3
3
  import { sessionConfig } from "../config.js";
4
4
  import { makePlatform } from "../platform.js";
5
5
  import { assertCanChange, clearPendingAuth, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken, readSessionToken } from "../session.js";
6
- import { authError } from "./utils.js";
6
+ import { authError, isAuthenticatorNotInPlan, isUserLimitReached } from "./utils.js";
7
7
 
8
8
  //#region src/auth/methods/authenticator.ts
9
9
  /**
@@ -22,6 +22,7 @@ async function startAuthenticatorSetup() {
22
22
  assertCanChange("auth.startAuthenticatorSetup");
23
23
  const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupInit(readPendingAuthToken() ?? readSessionToken());
24
24
  if (!result.ok) {
25
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
25
26
  if (result.status === 401) return authError("notAuthenticated", result.message);
26
27
  if (result.status === 429) return authError("tooManyAttempts", result.message);
27
28
  if (result.status >= 500) panic(`Expected authenticator setup to start, but got ${result.status}: ` + result.message);
@@ -42,6 +43,8 @@ async function confirmAuthenticatorSetup(details) {
42
43
  assertCanChange("auth.confirmAuthenticatorSetup");
43
44
  const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupComplete(readPendingAuthToken() ?? readSessionToken(), details.code);
44
45
  if (!result.ok) {
46
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
47
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
45
48
  if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
46
49
  if (result.status === 429) return authError("tooManyAttempts", result.message);
47
50
  if (result.status >= 500) panic(`Expected authenticator setup to finish, but got ${result.status}: ` + result.message);
@@ -68,6 +71,8 @@ async function skipAuthenticatorSetup() {
68
71
  assertCanChange("auth.skipAuthenticatorSetup");
69
72
  const result = await makePlatform(sessionConfig().applicationId).authenticatorSetupDismiss(readPendingAuthToken() ?? readSessionToken());
70
73
  if (!result.ok) {
74
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
75
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
71
76
  if (result.status === 401) return authError("notAuthenticated", result.message);
72
77
  if (result.status === 429) return authError("tooManyAttempts", result.message);
73
78
  if (result.status >= 500) panic(`Expected to skip authenticator setup, but got ${result.status}: ` + result.message);
@@ -92,6 +97,8 @@ async function verifyAuthenticator(credentials) {
92
97
  assertCanChange("auth.verifyAuthenticator");
93
98
  const result = await makePlatform(sessionConfig().applicationId).authenticatorVerify(readPendingAuthToken() ?? readSessionToken(), "code" in credentials ? { totpCode: credentials.code } : { backupCode: credentials.backupCode });
94
99
  if (!result.ok) {
100
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
101
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
95
102
  if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
96
103
  if (result.status === 429) return authError("tooManyAttempts", result.message);
97
104
  if (result.status >= 500) panic(`Expected to verify the authenticator, but got ${result.status}: ` + result.message);
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
3
3
  import { sessionConfig } from "../config.js";
4
4
  import { makePlatform } from "../platform.js";
5
5
  import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
6
- import { authError } from "./utils.js";
6
+ import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
7
7
 
8
8
  //#region src/auth/methods/code.ts
9
9
  const SEND_CODE_ERRORS = new Map([["No account exists for this email.", "noAccount"], ["This account is deactivated. Please contact the application owner.", "accountDeactivated"]]);
@@ -18,6 +18,7 @@ async function sendSignInCode(details) {
18
18
  assertCanChange("auth.sendSignInCode");
19
19
  const result = await makePlatform(sessionConfig().applicationId).sendSignInCode(details.email);
20
20
  if (!result.ok) {
21
+ if (isNotInPlan(result)) return authError("notEnabled", result.message);
21
22
  if (result.status === 429) return authError("tooManyAttempts", result.message);
22
23
  if (result.status === 400) return authError(SEND_CODE_ERRORS.get(result.message) ?? "invalidDetails", result.message);
23
24
  if (result.status >= 500) panic(`Expected the sign-in code to be emailed, but got ${result.status}: ` + result.message);
@@ -39,6 +40,9 @@ async function signInWithCode(credentials) {
39
40
  assertCanChange("auth.signInWithCode");
40
41
  const result = await makePlatform(sessionConfig().applicationId).signInWithCode(credentials);
41
42
  if (!result.ok) {
43
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
44
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
45
+ if (isNotInPlan(result)) return authError("notEnabled", result.message);
42
46
  if (result.status === 429) return authError("tooManyAttempts", result.message);
43
47
  if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
44
48
  if (result.status >= 500) panic(`Expected sign-in to succeed, but got ${result.status}: ` + result.message);
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
3
3
  import { sessionConfig } from "../config.js";
4
4
  import { makePlatform } from "../platform.js";
5
5
  import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken } from "../session.js";
6
- import { authError } from "./utils.js";
6
+ import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
7
7
 
8
8
  //#region src/auth/methods/emailCode2fa.ts
9
9
  /**
@@ -18,6 +18,8 @@ async function verifyEmailCode(details) {
18
18
  assertCanChange("auth.verifyEmailCode");
19
19
  const result = await makePlatform(sessionConfig().applicationId).emailCodeVerify(readPendingAuthToken(), details.code);
20
20
  if (!result.ok) {
21
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
22
+ if (isAuthenticatorNotInPlan(result) || isNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
21
23
  if (result.status === 400 || result.status === 401) return authError("invalidCode", result.message);
22
24
  if (result.status === 429) return authError("tooManyAttempts", result.message);
23
25
  if (result.status >= 500) panic(`Expected to verify the emailed code, but got ${result.status}: ` + result.message);
@@ -55,6 +57,7 @@ async function resendEmailCode() {
55
57
  assertCanChange("auth.resendEmailCode");
56
58
  const result = await makePlatform(sessionConfig().applicationId).emailCodeResend(readPendingAuthToken());
57
59
  if (!result.ok) {
60
+ if (isAuthenticatorNotInPlan(result) || isNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
58
61
  if (result.status === 401) return authError("notAuthenticated", result.message);
59
62
  if (result.status === 429) return authError("tooManyAttempts", result.message);
60
63
  if (result.status >= 500) panic(`Expected the code to be emailed again, but got ${result.status}: ` + result.message);
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
3
3
  import { sessionConfig } from "../config.js";
4
4
  import { makePlatform } from "../platform.js";
5
5
  import { assertCanChange, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
6
- import { authError } from "./utils.js";
6
+ import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
7
7
 
8
8
  //#region src/auth/methods/magicLink.ts
9
9
  /**
@@ -18,6 +18,9 @@ async function signInWithMagicLink(credentials) {
18
18
  assertCanChange("auth.signInWithMagicLink");
19
19
  const result = await makePlatform(sessionConfig().applicationId).signInWithMagicLink(credentials);
20
20
  if (!result.ok) {
21
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
22
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
23
+ if (isNotInPlan(result)) return authError("notEnabled", result.message);
21
24
  if (result.status === 429) return authError("tooManyAttempts", result.message);
22
25
  if (result.status === 400 || result.status === 401) return authError("invalidCredentials", result.message);
23
26
  if (result.status >= 500) panic(`Expected magic-link sign-in to succeed, but got ${result.status}: ` + result.message);
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
3
3
  import { sessionConfig } from "../config.js";
4
4
  import { makePlatform } from "../platform.js";
5
5
  import { assertCanChange, clearPendingAuth, clearSession, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readSessionToken } from "../session.js";
6
- import { authError } from "./utils.js";
6
+ import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
7
7
 
8
8
  //#region src/auth/methods/password.ts
9
9
  /**
@@ -18,6 +18,8 @@ async function signIn(credentials) {
18
18
  assertCanChange("auth.signIn");
19
19
  const result = await makePlatform(sessionConfig().applicationId).tokens(credentials);
20
20
  if (!result.ok) {
21
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
22
+ if (isAuthenticatorNotInPlan(result) || isNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
21
23
  if (result.status === 401) return authError("invalidCredentials", result.message);
22
24
  if (result.status === 429) return authError("tooManyAttempts", result.message);
23
25
  if (result.status >= 500) panic(`Expected sign-in to succeed, but got ${result.status}: ` + result.message);
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
3
3
  import { sessionConfig } from "../config.js";
4
4
  import { makePlatform } from "../platform.js";
5
5
  import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
6
- import { authError } from "./utils.js";
6
+ import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
7
7
 
8
8
  //#region src/auth/methods/passwordLink.ts
9
9
  /**
@@ -31,6 +31,7 @@ async function requestPasswordReset(details) {
31
31
  async function checkPasswordLink(details) {
32
32
  const result = await makePlatform(sessionConfig().applicationId).checkPasswordToken(details);
33
33
  if (!result.ok) {
34
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
34
35
  if (result.status === 429) return authError("tooManyAttempts", result.message);
35
36
  if (result.status === 400 || result.status === 401) return authError("linkExpired", result.message);
36
37
  panic(`Expected the link to be checked, but got ${result.status}: ${result.message}.`);
@@ -51,6 +52,9 @@ async function setPasswordWithLink(details) {
51
52
  assertCanChange("auth.setPasswordWithLink");
52
53
  const result = await makePlatform(sessionConfig().applicationId).setPassword(details);
53
54
  if (!result.ok) {
55
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
56
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
57
+ if (isNotInPlan(result)) return authError("notEnabled", result.message);
54
58
  if (result.status === 429) return authError("tooManyAttempts", result.message);
55
59
  if (result.status === 400 && result.message.startsWith("Password must be at least")) return authError("invalidDetails", result.message);
56
60
  if (result.status === 400 || result.status === 401) return authError("linkExpired", result.message);
@@ -3,7 +3,7 @@ import { writeCookies } from "../../cookies.js";
3
3
  import { sessionConfig } from "../config.js";
4
4
  import { makePlatform } from "../platform.js";
5
5
  import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
6
- import { authError } from "./utils.js";
6
+ import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
7
7
 
8
8
  //#region src/auth/methods/signup.ts
9
9
  /**
@@ -15,6 +15,9 @@ async function signUp(details) {
15
15
  assertCanChange("auth.signUp");
16
16
  const result = await makePlatform(sessionConfig().applicationId).sendSignUpCode(details);
17
17
  if (!result.ok) {
18
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
19
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
20
+ if (isNotInPlan(result)) return authError("notEnabled", result.message);
18
21
  if (result.status === 409) return authError("emailTaken", result.message);
19
22
  if (result.status === 429) return authError("tooManyAttempts", result.message);
20
23
  if (result.status === 400) return authError("invalidDetails", result.message);
@@ -48,6 +51,9 @@ async function confirmSignUp(details) {
48
51
  password
49
52
  });
50
53
  if (!result.ok) {
54
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
55
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
56
+ if (isNotInPlan(result)) return authError("notEnabled", result.message);
51
57
  if (result.status === 409) return authError("emailTaken", result.message);
52
58
  if (result.status === 429) return authError("tooManyAttempts", result.message);
53
59
  if (result.status === 400 && result.message.startsWith("Password must be at least")) return authError("invalidDetails", result.message);
@@ -3,11 +3,9 @@ import { writeCookies } from "../../cookies.js";
3
3
  import { sessionConfig } from "../config.js";
4
4
  import { makePlatform } from "../platform.js";
5
5
  import { assertCanChange, clearPendingAuth, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie } from "../session.js";
6
- import { authError } from "./utils.js";
7
- import { z } from "zod";
6
+ import { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached } from "./utils.js";
8
7
 
9
8
  //#region src/auth/methods/social.ts
10
- const errorBodySchema = z.object({ code: z.string() });
11
9
  /**
12
10
  * Signs a visitor in with a Google token the browser obtained, creating their
13
11
  * account the first time.
@@ -27,9 +25,10 @@ async function signInWithGoogle(credentials) {
27
25
  assertCanChange("auth.signInWithGoogle");
28
26
  const result = await makePlatform(sessionConfig().applicationId).signInWithGoogle(credentials);
29
27
  if (!result.ok) {
28
+ if (isUserLimitReached(result)) return authError("userLimitReached", result.message);
29
+ if (isAuthenticatorNotInPlan(result)) return authError("secondFactorNotEnabled", result.message);
30
+ if (isNotInPlan(result)) return authError("notEnabled", result.message);
30
31
  if (result.status === 429) return authError("tooManyAttempts", result.message);
31
- const body = errorBodySchema.safeParse(result.body);
32
- if (body.success && body.data.code === "GOOGLE_NOT_IN_PLAN") return authError("notEnabled", result.message);
33
32
  if (result.status === 400 && result.message.startsWith("Emails with ") && result.message.endsWith(" domain is not allowed to signup.")) return authError("emailDomainNotAllowed", result.message);
34
33
  if (result.status === 400 || result.status === 401) return authError("invalidCredentials", result.message);
35
34
  if (result.status >= 500) panic(`Expected Google sign-in to succeed, but got ${result.status}: ` + result.message);
@@ -10,6 +10,9 @@ type AuthError = {
10
10
  code: AuthErrorCode;
11
11
  message: string;
12
12
  };
13
- type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "noAccount" | "accountDeactivated" | "notAuthenticated" | "emailDomainNotAllowed" | "notEnabled" | "linkExpired" | "invalidName" | "invalidPhoto" | "fileTooLarge" | "notAnImage" | "avatarNotSupported";
13
+ type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "noAccount" | "accountDeactivated" | "notAuthenticated" | "emailDomainNotAllowed"
14
+ /** The plan of the app's workspace no longer includes this way to sign in, as after a downgrade. Another way in can still work. */ | "notEnabled" | "linkExpired" | "invalidName" | "invalidPhoto" | "fileTooLarge" | "notAnImage" | "avatarNotSupported"
15
+ /** Any call that signs a visitor in or up: the plan of the app's workspace has no room for this user. */ | "userLimitReached"
16
+ /** The visitor owes a second step that the plan of the app's workspace no longer includes. No way in works until the app owner changes the plan. */ | "secondFactorNotEnabled";
14
17
  //#endregion
15
18
  export { AuthError, Result };
@@ -1,3 +1,5 @@
1
+ import { z } from "zod";
2
+
1
3
  //#region src/auth/methods/utils.ts
2
4
  function authError(code, message) {
3
5
  return {
@@ -8,6 +10,33 @@ function authError(code, message) {
8
10
  }
9
11
  };
10
12
  }
13
+ const errorBodySchema = z.object({ code: z.string() });
14
+ /**
15
+ * True when Softr refused because the plan of the app's workspace has no room
16
+ * for this user. It arrives as a 400, like a wrong code, so the status cannot
17
+ * tell them apart.
18
+ */
19
+ function isUserLimitReached(result) {
20
+ const body = errorBodySchema.safeParse(result.body);
21
+ return body.success && body.data.code === "USER_LIMIT_REACHED";
22
+ }
23
+ /**
24
+ * True when Softr refused because the plan of the app's workspace does not
25
+ * include this way to sign in: Google sign-in or the one-time email code, as
26
+ * after a downgrade.
27
+ */
28
+ function isNotInPlan(result) {
29
+ const body = errorBodySchema.safeParse(result.body);
30
+ return body.success && (body.data.code === "GOOGLE_NOT_IN_PLAN" || body.data.code === "EMAIL_CODE_NOT_IN_PLAN");
31
+ }
32
+ /**
33
+ * True when Softr refused because the visitor owes an authenticator app step
34
+ * that the plan of the app's workspace does not include, as after a downgrade.
35
+ */
36
+ function isAuthenticatorNotInPlan(result) {
37
+ const body = errorBodySchema.safeParse(result.body);
38
+ return body.success && body.data.code === "AUTHENTICATOR_NOT_IN_PLAN";
39
+ }
11
40
 
12
41
  //#endregion
13
- export { authError };
42
+ export { authError, isAuthenticatorNotInPlan, isNotInPlan, isUserLimitReached };
@@ -39,7 +39,6 @@ declare const authSettingsSchema: z.ZodObject<{
39
39
  OPEN_ID: "OPEN_ID";
40
40
  }>>;
41
41
  }, z.core.$strip>>;
42
- softrLogin: z.ZodOptional<z.ZodBoolean>;
43
42
  }, z.core.$strip>;
44
43
  type AuthSettings = z.infer<typeof authSettingsSchema>;
45
44
  //#endregion
@@ -29,8 +29,7 @@ const authSettingsSchema = z.object({
29
29
  clientId: z.string().nullable(),
30
30
  userType: z.enum(["INTERNAL", "EXTERNAL"]).nullable()
31
31
  }).nullable(),
32
- sso: z.object({ type: z.enum(["SAML", "OPEN_ID"]).nullable() }).nullable(),
33
- softrLogin: z.boolean().optional()
32
+ sso: z.object({ type: z.enum(["SAML", "OPEN_ID"]).nullable() }).nullable()
34
33
  });
35
34
  function makePlatform(applicationId) {
36
35
  const aliases = Object.entries(softrConfig().user?.properties ?? {});
@@ -217,18 +216,6 @@ function makePlatform(applicationId) {
217
216
  method: "POST",
218
217
  json: body
219
218
  }, ssoSignInSchema),
220
- softrLoginStart: (body) => request(`/v1/vibe/applications/${applicationId}/users/softr-login/start`, {
221
- method: "POST",
222
- json: body
223
- }, z.object({
224
- bindingToken: z.string(),
225
- returnPath: z.string(),
226
- redirectUrl: z.string()
227
- })),
228
- signInWithSoftr: (body) => request(`/v1/vibe/applications/${applicationId}/users/tokens/with-softr${withAttributes}`, {
229
- method: "POST",
230
- json: body
231
- }, ssoSignInSchema),
232
219
  ssoDiscover: (body) => request(`/v1/vibe/applications/${applicationId}/users/sso/discover`, {
233
220
  method: "POST",
234
221
  json: body
@@ -14,34 +14,11 @@ import "@tanstack/react-start";
14
14
  * <a href={ssoSignInHref(toReturnPath(location).href)}>Continue with SSO</a>
15
15
  */
16
16
  declare function ssoSignInHref(returnPath?: string): string;
17
- /**
18
- * Where a link or button sends a visitor to sign in with their Softr Studio
19
- * account. They come back to `returnPath` once signed in. Without one, they
20
- * land where `auth.guard.alreadyAuthenticated` in softr.json points, as after
21
- * any sign-in.
22
- *
23
- * A full page load, not a router navigation: the visitor leaves the app for
24
- * Softr Studio.
25
- *
26
- * @example
27
- * <a href={softrSignInHref(toReturnPath(location).href)}>Continue with Softr</a>
28
- */
29
- declare function softrSignInHref(returnPath?: string): string;
30
17
  /**
31
18
  * Why single sign-on did not finish, as the `error` search param of the SSO
32
19
  * page. Never the platform's own message: that is for the builder, and it would
33
20
  * sit in the visitor's address bar.
34
21
  */
35
22
  type SsoError = "host" | "idp" | "not-enabled" | "sign-up-disabled" | "restricted" | "expired" | "failed";
36
- /**
37
- * The extra reasons a sign-in with a Softr Studio account can fail, besides
38
- * the {@link SsoError} values. `softr-rejected`: Softr did not let this
39
- * account in. `softr-sso-account`: the account signs in with single sign-on,
40
- * which the app also offers. It is a separate type so that an existing
41
- * `Record<SsoError, ...>` keeps compiling.
42
- *
43
- * The SSO page gets it as its `error` search param, with `method=softr`.
44
- */
45
- type SoftrLoginError = "softr-rejected" | "softr-sso-account";
46
23
  //#endregion
47
- export { SoftrLoginError, SsoError, softrSignInHref, ssoSignInHref };
24
+ export { SsoError, ssoSignInHref };
package/dist/auth/sso.js CHANGED
@@ -11,8 +11,6 @@ import { createMiddleware } from "@tanstack/react-start";
11
11
 
12
12
  //#region src/auth/sso.ts
13
13
  const START_PATH = "/_softr/sso/start";
14
- const SOFTR_START_PATH = "/_softr/softr-login/start";
15
- const SOFTR_CALLBACK_PATH = "/_softr/softr-login/callback";
16
14
  const OPEN_ID_CALLBACK_PATH = "/open-id/code";
17
15
  const SAML_CALLBACK_PATH = "/saml/SSO";
18
16
  const DEFAULT_SSO_PATH = "/sso-authentication";
@@ -31,28 +29,12 @@ function ssoSignInHref(returnPath) {
31
29
  return returnPath ? `${START_PATH}?return=${encodeURIComponent(returnPath)}` : START_PATH;
32
30
  }
33
31
  /**
34
- * Where a link or button sends a visitor to sign in with their Softr Studio
35
- * account. They come back to `returnPath` once signed in. Without one, they
36
- * land where `auth.guard.alreadyAuthenticated` in softr.json points, as after
37
- * any sign-in.
38
- *
39
- * A full page load, not a router navigation: the visitor leaves the app for
40
- * Softr Studio.
41
- *
42
- * @example
43
- * <a href={softrSignInHref(toReturnPath(location).href)}>Continue with Softr</a>
44
- */
45
- function softrSignInHref(returnPath) {
46
- return returnPath ? `${SOFTR_START_PATH}?return=${encodeURIComponent(returnPath)}` : SOFTR_START_PATH;
47
- }
48
- /**
49
32
  * Starts single sign-on and finishes it when the identity provider answers.
50
- * It does the same for a sign-in with a Softr Studio account, where Studio is
51
- * the identity provider. Every other request passes through.
33
+ * Every other request passes through.
52
34
  *
53
35
  * The start is a GET the visitor's browser makes, so a link can begin it. The
54
36
  * identity provider answers OpenID Connect with a redirect, and SAML with a
55
- * form it posts from its own site. Studio answers with a redirect.
37
+ * form it posts from its own site.
56
38
  */
57
39
  function ssoMiddleware() {
58
40
  return createMiddleware({ type: "request" }).server(async ({ next, request, pathname }) => {
@@ -77,30 +59,6 @@ function ssoMiddleware() {
77
59
  ...binding
78
60
  }), binding.returnPath);
79
61
  }
80
- case SOFTR_START_PATH:
81
- if (request.method !== "GET") return methodNotAllowed("GET");
82
- return await softrStart(new URL(request.url));
83
- case SOFTR_CALLBACK_PATH: {
84
- if (request.method !== "GET") return methodNotAllowed("GET");
85
- const url = new URL(request.url);
86
- const code = url.searchParams.get("code");
87
- const binding = readSsoBinding();
88
- clearSsoBinding();
89
- if (code === null) return toSsoPage({
90
- error: "failed",
91
- returnPath: binding?.returnPath,
92
- method: "softr"
93
- });
94
- if (binding === null) return toSsoPage({
95
- error: "expired",
96
- method: "softr"
97
- });
98
- return await finish(await platform().signInWithSoftr({
99
- code,
100
- state: url.searchParams.get("state") ?? "",
101
- ...binding
102
- }), binding.returnPath, "softr");
103
- }
104
62
  case SAML_CALLBACK_PATH: {
105
63
  if (request.method !== "POST") return methodNotAllowed("POST");
106
64
  const form = await request.formData().catch(() => null);
@@ -153,39 +111,14 @@ async function start(url) {
153
111
  writeCookies([binding]);
154
112
  return samlForm(started.formAction, started.samlRequest, started.relayState);
155
113
  }
156
- async function softrStart(url) {
157
- const returnPath = resolveReturnPath(url.searchParams.get("return"));
158
- const result = await platform().softrLoginStart({
159
- origin: url.origin,
160
- returnPath
161
- });
162
- if (!result.ok) return toSsoPage({
163
- ...failure(result),
164
- returnPath,
165
- method: "softr"
166
- });
167
- const started = result.data;
168
- writeCookies([makeSsoBindingCookie({
169
- bindingToken: started.bindingToken,
170
- returnPath: started.returnPath
171
- })]);
172
- return new Response(null, {
173
- status: 302,
174
- headers: {
175
- location: started.redirectUrl,
176
- "cache-control": "no-store"
177
- }
178
- });
179
- }
180
114
  /**
181
115
  * `startedFor` is where the visitor wanted to go, so a retry after a failure
182
116
  * gets there.
183
117
  */
184
- async function finish(result, startedFor, method = "sso") {
118
+ async function finish(result, startedFor) {
185
119
  if (!result.ok) return toSsoPage({
186
120
  ...failure(result),
187
- returnPath: startedFor,
188
- method
121
+ returnPath: startedFor
189
122
  });
190
123
  const { result: signIn, returnPath } = result.data;
191
124
  if (signIn.status === "MFA_REQUIRED") {
@@ -212,13 +145,12 @@ function failure(result) {
212
145
  case "SSO_IDP_REJECTED": return { error: "idp" };
213
146
  case "SSO_NOT_ENABLED":
214
147
  case "SSO_NOT_IN_PLAN":
215
- case "SSO_MISCONFIGURED": return { error: "not-enabled" };
148
+ case "SSO_MISCONFIGURED":
149
+ case "AUTHENTICATOR_NOT_IN_PLAN": return { error: "not-enabled" };
216
150
  case "SSO_SIGN_UP_DISABLED": return { error: "sign-up-disabled" };
217
151
  case "USER_DEACTIVATED":
218
152
  case "SIGN_IN_RESTRICTED": return { error: "restricted" };
219
153
  case "SSO_BINDING_INVALID": return { error: "expired" };
220
- case "SOFTR_LOGIN_REJECTED": return { error: "softr-rejected" };
221
- case "SOFTR_LOGIN_SSO_ACCOUNT": return { error: "softr-sso-account" };
222
154
  default:
223
155
  logger.warn(`Single sign-on failed with ${result.status} ${code ?? "(no code)"}: ${result.message}`);
224
156
  return { error: "failed" };
@@ -233,10 +165,8 @@ function failure(result) {
233
165
  function toSsoPage(search) {
234
166
  const { routes } = softrConfig().auth;
235
167
  const params = new URLSearchParams();
236
- if ("error" in search) {
237
- params.set("error", search.error);
238
- if (search.method === "softr") params.set("method", "softr");
239
- } else params.set("authenticator", search.authenticator);
168
+ if ("error" in search) params.set("error", search.error);
169
+ else params.set("authenticator", search.authenticator);
240
170
  if (search.returnPath !== void 0) params.set(routes.login.redirectParam, resolveReturnPath(search.returnPath));
241
171
  return seeOther(`${routes.sso?.path ?? DEFAULT_SSO_PATH}?${params}`);
242
172
  }
@@ -288,4 +218,4 @@ function platform() {
288
218
  }
289
219
 
290
220
  //#endregion
291
- export { softrSignInHref, ssoMiddleware, ssoSignInHref };
221
+ export { ssoMiddleware, ssoSignInHref };
@@ -100,6 +100,7 @@ function chart(query) {
100
100
  const groups = entries;
101
101
  assert(groups.length < 2 || groups[0][1].fieldId !== groups[1][1].fieldId, "a chart may group by a field only once");
102
102
  state.groups = groups;
103
+ result = void 0;
103
104
  return builder;
104
105
  },
105
106
  metrics(build) {
@@ -114,15 +115,18 @@ function chart(query) {
114
115
  seen.add(pair);
115
116
  }
116
117
  state.metrics = metrics;
118
+ result = void 0;
117
119
  return builder;
118
120
  },
119
121
  where(build) {
120
122
  state.filters.push(build(makeFieldSet(aliases)));
123
+ result = void 0;
121
124
  return builder;
122
125
  },
123
126
  orderBy(build) {
124
127
  const sorting = build(makeSortSet([...state.groups ?? [], ...state.metrics ?? []].map(([key]) => key)));
125
128
  state.orderBys.push(...buildOrderBy(Array.isArray(sorting) ? sorting : [sorting]));
129
+ result = void 0;
126
130
  return builder;
127
131
  },
128
132
  then(onfulfilled, onrejected) {
@@ -238,6 +242,7 @@ function metric(query, pick) {
238
242
  [Symbol.toStringTag]: "MetricQuery",
239
243
  where(build) {
240
244
  filters.push(build(makeFieldSet(aliases)));
245
+ result = void 0;
241
246
  return builder;
242
247
  },
243
248
  then(onfulfilled, onrejected) {
@@ -228,6 +228,7 @@ function getRecord(query, options) {
228
228
  [Symbol.toStringTag]: "RecordFetch",
229
229
  where(build) {
230
230
  filters.push(build(makeFieldSet(aliases)));
231
+ record = void 0;
231
232
  return builder;
232
233
  },
233
234
  then(onfulfilled, onrejected) {