@softr/sdk 1.7.6 → 1.7.7

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.7.7
4
+
5
+ ### Patch Changes
6
+
7
+ - `docs/user-groups.md` names the custom user groups past the workspace's plan limit, in a section of their own. A page or an action gated on one of them admits nobody.
8
+ - `DefaultErrorOverlay` shows why a guard denied the page in development, not `[object Object]`.
9
+ - `guardRoute` and `assertRouteAccess` print why they denied the page in development when they throw an access error.
10
+
3
11
  ## 1.7.6
4
12
 
5
13
  ### Patch Changes
@@ -19,12 +19,21 @@ function renderUserGroupsDoc(groups) {
19
19
  "This app has no user groups.",
20
20
  ""
21
21
  ].join("\n");
22
+ const pastLimit = groups.filter((group) => group.exceedsPlanLimit === true);
22
23
  return [
23
24
  ...heading,
24
25
  "User groups available in this app:",
25
26
  "",
26
27
  ...groups.map(({ id, name, type }) => `- ${name} (${id}), ${type.toLowerCase()}`),
27
- ""
28
+ "",
29
+ ...pastLimit.length === 0 ? [] : [
30
+ "## Not available on the workspace's plan",
31
+ "",
32
+ "The plan allows fewer custom user groups than this app has. The groups below are kept with their members, but nobody counts as a member of them until the plan is upgraded, so a page or an action limited to one of them admits no user:",
33
+ "",
34
+ ...pastLimit.map(({ id, name }) => `- ${name} (${id})`),
35
+ ""
36
+ ]
28
37
  ].join("\n");
29
38
  }
30
39
 
@@ -1,3 +1,4 @@
1
+ import { ACCESS_DENIED_MESSAGES, isAccessError } from "./route/route.js";
1
2
  import { useEffect, useRef, useState, useSyncExternalStore } from "react";
2
3
  import { useRouter } from "@tanstack/react-router";
3
4
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -66,7 +67,7 @@ function DevView({ error, reset }) {
66
67
  ]);
67
68
  const shown = !running && !retryPending;
68
69
  useEffect(() => {
69
- if (shown) reportError(error);
70
+ if (shown) reportError(error instanceof Error ? error : new Error(messageOf(error)));
70
71
  }, [shown, error]);
71
72
  if (!shown) return /* @__PURE__ */ jsx(UpdatingView, {});
72
73
  return /* @__PURE__ */ jsx("div", {
@@ -92,7 +93,7 @@ function DevView({ error, reset }) {
92
93
  ] }),
93
94
  /* @__PURE__ */ jsx("pre", {
94
95
  style: s.message,
95
- children: error instanceof Error ? error.message : String(error)
96
+ children: messageOf(error)
96
97
  }),
97
98
  error instanceof Error && error.stack && /* @__PURE__ */ jsx(StackTrace, { stack: error.stack }),
98
99
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(RetryButton, { onClick: reset }) })
@@ -100,6 +101,15 @@ function DevView({ error, reset }) {
100
101
  })
101
102
  });
102
103
  }
104
+ function messageOf(error) {
105
+ if (error instanceof Error) return error.message;
106
+ if (isAccessError(error)) return ACCESS_DENIED_MESSAGES[error.reason];
107
+ try {
108
+ return JSON.stringify(error) ?? String(error);
109
+ } catch {
110
+ return String(error);
111
+ }
112
+ }
103
113
  function UpdatingView() {
104
114
  return /* @__PURE__ */ jsx("div", {
105
115
  style: s.overlay,
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.7.6";
2
+ var version = "1.7.7";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -1,4 +1,5 @@
1
1
  import { panic } from "../assertions.js";
2
+ import { logger } from "../logger.js";
2
3
  import { softrConfig } from "../softr-config.js";
3
4
  import { ACCESS_REASONS, checkRule } from "./visibility.js";
4
5
  import { redirect } from "@tanstack/react-router";
@@ -33,6 +34,15 @@ function isForbiddenError(error) {
33
34
  function isAlreadyAuthenticatedError(error) {
34
35
  return isReason(error, "alreadyAuthenticated");
35
36
  }
37
+ /**
38
+ * Why a guard denied the visitor, for the builder who reads it in the preview.
39
+ * Plain words: the builder does not write code.
40
+ */
41
+ const ACCESS_DENIED_MESSAGES = {
42
+ unauthenticated: "This page is only for signed-in users, and nobody is signed in.",
43
+ forbidden: "You are signed in, but your account is not in any user group this page is open to.",
44
+ alreadyAuthenticated: "This page is only for signed-out visitors, and you are signed in."
45
+ };
36
46
  /** What a guard throws for a reason: a redirect, or an {@link AccessError}. */
37
47
  function thrownFor(reason, overrides, location) {
38
48
  const behaviour = overrides?.[reason] ?? softrConfig().auth.guard[reason];
@@ -48,10 +58,12 @@ function thrownFor(reason, overrides, location) {
48
58
  search: { [redirectParam]: location.href }
49
59
  });
50
60
  }
51
- return {
61
+ const error = {
52
62
  type: "access_error",
53
63
  reason
54
64
  };
65
+ logger.error(/* @__PURE__ */ new Error(`Access to ${location.href} denied: ${ACCESS_DENIED_MESSAGES[reason]}`));
66
+ return error;
55
67
  }
56
68
  function ruleOf(page) {
57
69
  return page.visibility ?? panic("the page states no visibility rule to guard it with");
@@ -92,4 +104,4 @@ function assertRouteAccess(page, opts) {
92
104
  }
93
105
 
94
106
  //#endregion
95
- export { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError };
107
+ export { ACCESS_DENIED_MESSAGES, assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: core
12
12
  library: softr-sdk
13
- library_version: 1.7.6
13
+ library_version: 1.7.7
14
14
  ---
15
15
 
16
16
  # Softr SDK core
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 1.7.6
16
+ library_version: 1.7.7
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.6
13
+ library_version: 1.7.7
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.7.6
13
+ library_version: 1.7.7
14
14
  ---
15
15
 
16
16
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A helper that calls `ds` outside a handler goes in `createServerOnlyFn` from `@tanstack/react-start` (the `record-queries` boundary). `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 1.7.6
14
+ library_version: 1.7.7
15
15
  ---
16
16
 
17
17
  # The current user
@@ -12,7 +12,7 @@ description: >-
12
12
  metadata:
13
13
  type: sub-skill
14
14
  library: softr-sdk
15
- library_version: 1.7.6
15
+ library_version: 1.7.7
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.6
10
+ library_version: 1.7.7
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,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 1.7.6
11
+ library_version: 1.7.7
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.7.6
10
+ library_version: 1.7.7
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.6
12
+ library_version: 1.7.7
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.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.7.6
12
+ library_version: 1.7.7
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.7.6
12
+ library_version: 1.7.7
13
13
  ---
14
14
 
15
15
  # Installing the app
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.7.6
13
+ library_version: 1.7.7
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.7.6
14
+ library_version: 1.7.7
15
15
  ---
16
16
 
17
17
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. A route `loader` also runs in the browser, so it calls a server function, never `ds`. A helper that calls `ds` outside a handler, in this file or in another one, goes in `createServerOnlyFn` from `@tanstack/react-start`, or inside the handler. An exported helper without it keeps the server-only import in the browser bundle, and every page stops loading until it moves. Do not make such a helper a server function when it takes an id: any visitor can call a server function with any id. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.7.6
12
+ library_version: 1.7.7
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.7.6
12
+ library_version: 1.7.7
13
13
  ---
14
14
 
15
15
  **Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.7.6
12
+ library_version: 1.7.7
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.