@softr/sdk 1.12.0 → 1.13.0

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,17 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - `LogoIcon`, from the new `@softr/sdk/logo-icon` entrypoint, is the Lucide icon that `logo.icon` in `softr.json` names, or `layers` when Lucide has none by that name. The `softr()` Vite plugin picks it when the app builds, so the app ships that one icon and the server renders it.
8
+
9
+ ## 1.12.1
10
+
11
+ ### Patch Changes
12
+
13
+ - When single sign-on fails, the SSO page (`auth.routes.sso`) gets the path the visitor wanted in the login redirect param, as it already did for an authenticator code. When the sign-in has expired there may be no path, and the param is left out. An SSO page that ignores the param works as before. Action: on that page, link "Try again" to `ssoSignInHref(toReturnPath(location).href)` and keep the redirect param on the login link.
14
+
3
15
  ## 1.12.0
4
16
 
5
17
  ### Minor Changes
package/dist/auth/sso.js CHANGED
@@ -48,13 +48,16 @@ function ssoMiddleware() {
48
48
  const code = url.searchParams.get("code");
49
49
  const binding = readSsoBinding();
50
50
  clearSsoBinding();
51
- if (code === null) return toSsoPage({ error: "idp" });
51
+ if (code === null) return toSsoPage({
52
+ error: "idp",
53
+ returnPath: binding?.returnPath
54
+ });
52
55
  if (binding === null) return toSsoPage({ error: "expired" });
53
56
  return await finish(await platform().signInWithOpenId({
54
57
  code,
55
58
  state: url.searchParams.get("state") ?? "",
56
59
  ...binding
57
- }));
60
+ }), binding.returnPath);
58
61
  }
59
62
  case SAML_CALLBACK_PATH: {
60
63
  if (request.method !== "POST") return methodNotAllowed("POST");
@@ -62,25 +65,32 @@ function ssoMiddleware() {
62
65
  const samlResponse = form?.get("SAMLResponse");
63
66
  const binding = readSsoBinding();
64
67
  clearSsoBinding();
65
- if (typeof samlResponse !== "string" || samlResponse === "") return toSsoPage({ error: "idp" });
68
+ if (typeof samlResponse !== "string" || samlResponse === "") return toSsoPage({
69
+ error: "idp",
70
+ returnPath: binding?.returnPath
71
+ });
66
72
  if (binding === null) return toSsoPage({ error: "expired" });
67
73
  const relayState = form?.get("RelayState");
68
74
  return await finish(await platform().signInWithSaml({
69
75
  samlResponse,
70
76
  relayState: typeof relayState === "string" ? relayState : "",
71
77
  ...binding
72
- }));
78
+ }), binding.returnPath);
73
79
  }
74
80
  default: return await next();
75
81
  }
76
82
  });
77
83
  }
78
84
  async function start(url) {
85
+ const returnPath = resolveReturnPath(url.searchParams.get("return"));
79
86
  const result = await platform().ssoStart({
80
87
  origin: url.origin,
81
- returnPath: resolveReturnPath(url.searchParams.get("return"))
88
+ returnPath
89
+ });
90
+ if (!result.ok) return toSsoPage({
91
+ ...failure(result),
92
+ returnPath
82
93
  });
83
- if (!result.ok) return toSsoPage(failure(result));
84
94
  const started = result.data;
85
95
  const binding = makeSsoBindingCookie({
86
96
  bindingToken: started.bindingToken,
@@ -101,8 +111,15 @@ async function start(url) {
101
111
  writeCookies([binding]);
102
112
  return samlForm(started.formAction, started.samlRequest, started.relayState);
103
113
  }
104
- async function finish(result) {
105
- if (!result.ok) return toSsoPage(failure(result));
114
+ /**
115
+ * `startedFor` is where the visitor wanted to go, so a retry after a failure
116
+ * gets there.
117
+ */
118
+ async function finish(result, startedFor) {
119
+ if (!result.ok) return toSsoPage({
120
+ ...failure(result),
121
+ returnPath: startedFor
122
+ });
106
123
  const { result: signIn, returnPath } = result.data;
107
124
  if (signIn.status === "MFA_REQUIRED") {
108
125
  const { mfa } = signIn;
@@ -110,7 +127,7 @@ async function finish(result) {
110
127
  writeCookies([makePendingAuthCookie(mfa.challengeToken)]);
111
128
  return toSsoPage({
112
129
  authenticator: mfa.action === "VERIFICATION_REQUIRED" ? "verify" : mfa.action === "SETUP_REQUIRED" ? "setup" : "setupOptional",
113
- returnPath: resolveReturnPath(returnPath)
130
+ returnPath
114
131
  });
115
132
  }
116
133
  const { session } = signIn;
@@ -140,17 +157,16 @@ function failure(result) {
140
157
  }
141
158
  /**
142
159
  * The app's SSO page, for a second factor or a failure. The return path rides
143
- * in the login page's redirect param, where the page's own "done" step looks
144
- * for it.
160
+ * in the login page's redirect param. The page's "done" step, its "Try again"
161
+ * and its login link all read it from there. Without the binding cookie there
162
+ * is no path, and the visitor lands where any sign-in does.
145
163
  */
146
164
  function toSsoPage(search) {
147
165
  const { routes } = softrConfig().auth;
148
166
  const params = new URLSearchParams();
149
167
  if ("error" in search) params.set("error", search.error);
150
- else {
151
- params.set("authenticator", search.authenticator);
152
- params.set(routes.login.redirectParam, search.returnPath);
153
- }
168
+ else params.set("authenticator", search.authenticator);
169
+ if (search.returnPath !== void 0) params.set(routes.login.redirectParam, resolveReturnPath(search.returnPath));
154
170
  return seeOther(`${routes.sso?.path ?? DEFAULT_SSO_PATH}?${params}`);
155
171
  }
156
172
  function seeOther(location) {
@@ -0,0 +1,16 @@
1
+ import { ComponentType, SVGProps } from "react";
2
+
3
+ //#region src/logo-icon.d.ts
4
+ /** What the logo's icon takes: a Lucide icon's props. */
5
+ type LogoIconProps = SVGProps<SVGSVGElement> & {
6
+ size?: number | string;
7
+ strokeWidth?: number | string;
8
+ absoluteStrokeWidth?: boolean;
9
+ };
10
+ /**
11
+ * The Lucide icon `logo.icon` in softr.json names, or "layers" when Lucide has none by that name.
12
+ * It is picked when the app builds, so it renders on the server and only that icon ships.
13
+ */
14
+ declare const LogoIcon: ComponentType<LogoIconProps>;
15
+ //#endregion
16
+ export { LogoIcon, LogoIconProps };
@@ -0,0 +1,11 @@
1
+ import icon from "virtual:softr/logo-icon";
2
+
3
+ //#region src/logo-icon.ts
4
+ /**
5
+ * The Lucide icon `logo.icon` in softr.json names, or "layers" when Lucide has none by that name.
6
+ * It is picked when the app builds, so it renders on the server and only that icon ships.
7
+ */
8
+ const LogoIcon = icon;
9
+
10
+ //#endregion
11
+ export { LogoIcon };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.12.0";
2
+ var version = "1.13.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/vite.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { SOFTR_CONFIG_FILE, loadSoftrConfig } from "./softr-config.schema.js";
2
+ import { createRequire } from "node:module";
2
3
  import path from "node:path";
3
4
 
4
5
  //#region src/vite.ts
5
6
  function softr() {
6
- return [softrConfig()];
7
+ return [softrConfig(), softrLogoIcon()];
7
8
  }
8
9
  function softrConfig() {
9
10
  let root;
@@ -22,6 +23,35 @@ function softrConfig() {
22
23
  }
23
24
  };
24
25
  }
26
+ const LOGO_ICON = "virtual:softr/logo-icon";
27
+ const RESOLVED_LOGO_ICON = `\0${LOGO_ICON}`;
28
+ const DEFAULT_LOGO_ICON = "layers";
29
+ function softrLogoIcon() {
30
+ let root;
31
+ return {
32
+ name: "softr:logo-icon",
33
+ configResolved(config) {
34
+ root = config.root;
35
+ },
36
+ resolveId(id) {
37
+ return id === LOGO_ICON ? RESOLVED_LOGO_ICON : void 0;
38
+ },
39
+ load(id) {
40
+ if (id !== RESOLVED_LOGO_ICON) return void 0;
41
+ const lucide = createRequire(path.join(root, "package.json"))("lucide-react");
42
+ const exported = [loadSoftrConfig(root).logo.icon, DEFAULT_LOGO_ICON].map(exportName).find((name) => Object.hasOwn(lucide, name));
43
+ if (exported === void 0) throw new Error(`lucide-react in ${root} has no "${DEFAULT_LOGO_ICON}" icon to draw the logo with`);
44
+ return `export { ${exported} as default } from "lucide-react";`;
45
+ }
46
+ };
47
+ }
48
+ /**
49
+ * The name lucide-react exports this icon under: "paw-print" is PawPrintIcon. Every icon and alias has
50
+ * one. Lucide's one other export that ends in Icon is Icon itself, and no icon name maps to it.
51
+ */
52
+ function exportName(icon) {
53
+ return `${icon.replace(/(?:^|-)([a-z0-9])/g, (_, letter) => letter.toUpperCase())}Icon`;
54
+ }
25
55
 
26
56
  //#endregion
27
57
  export { softr };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
7
7
  "./client": { "types": "./dist/client.d.ts", "import": "./dist/client.js" },
8
8
  "./server": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
9
- "./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" }
9
+ "./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" },
10
+ "./logo-icon": { "types": "./dist/logo-icon.d.ts", "import": "./dist/logo-icon.js" }
10
11
  },
11
12
  "bin": { "softr-sdk": "./dist/cli.js" },
12
13
  "files": ["dist", "schema", "skills", "!skills/_artifacts", "CHANGELOG.md"],
@@ -1,24 +1,24 @@
1
1
  ---
2
2
  name: softr-sdk
3
3
  description: >-
4
- Entry point for @softr/sdk: its four entrypoints (@softr/sdk, /server,
5
- /client, /vite) and their client-server boundary, softrAuthMiddleware and the
6
- Softr context, embedding the app in another site's iframe, the app's favicon,
7
- the app's logo in softr.json, and which sub-skill covers each task. Load it
8
- when unsure which sub-skill applies, when touching the wiring, when the user
9
- wants the app embedded elsewhere, when the favicon set in Studio does not
10
- show, or when the app's logo changes.
4
+ Entry point for @softr/sdk: its five entrypoints (@softr/sdk, /server,
5
+ /client, /vite, /logo-icon) and their client-server boundary,
6
+ softrAuthMiddleware and the Softr context, embedding the app in another site's
7
+ iframe, the app's favicon, the app's logo in softr.json, and which sub-skill
8
+ covers each task. Load it when unsure which sub-skill applies, when touching
9
+ the wiring, when the user wants the app embedded elsewhere, when the favicon
10
+ set in Studio does not show, or when the app's logo changes.
11
11
  metadata:
12
12
  type: core
13
13
  library: softr-sdk
14
- library_version: 1.12.0
14
+ library_version: 1.13.0
15
15
  ---
16
16
 
17
17
  # Softr SDK core
18
18
 
19
19
  `@softr/sdk` is how a Softr application talks to Softr. The visitor's identity, who may see a route, records in a datasource, signing in: all of it goes through this package. Everything else is an ordinary TanStack Start app. Routes, server functions, loaders and middleware are Start's, not Softr's.
20
20
 
21
- > **CRITICAL**: The SDK is split across four entrypoints and the split is enforced. `ds` and `auth` exist only on `@softr/sdk/server` and only run inside a `createServerFn` handler. Importing them anywhere else fails the build.
21
+ > **CRITICAL**: The SDK is split across five entrypoints and the split is enforced. `ds` and `auth` exist only on `@softr/sdk/server` and only run inside a `createServerFn` handler. Importing them anywhere else fails the build.
22
22
  >
23
23
  > **CRITICAL**: Every route file must declare its settings with `definePage`, guard itself with them in `beforeLoad` and render them in `head`. There is no default and nothing is inherited from a sibling.
24
24
  >
@@ -38,6 +38,7 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
38
38
  | `@softr/sdk/server` | Server only | `ds`, `auth`, `workflow`, `integration`, `ai` |
39
39
  | `@softr/sdk/client` | Browser only | `useFileUpload` |
40
40
  | `@softr/sdk/vite` | Build | `softr()`, already in `vite.config.ts` |
41
+ | `@softr/sdk/logo-icon` | Both, built by `softr()` | `LogoIcon` |
41
42
 
42
43
  ## Sub-Skills
43
44
 
@@ -199,6 +200,6 @@ The app's logo is `logo` in `softr.json`. The Logo field in Studio writes it, an
199
200
  ```
200
201
 
201
202
  - `source` is what the app shows, `"image"` or `"icon"`. The file keeps both, so a switch back loses nothing.
202
- - `icon` is a Lucide icon name in kebab case, like `"layers"`. It is always set, and it shows when `source` is `"image"` and no image fits.
203
+ - `icon` is a Lucide icon name in kebab case, like `"layers"`. It is always set, and it shows when `source` is `"image"` and no image fits. `LogoIcon` from `@softr/sdk/logo-icon` draws it: the `softr()` Vite plugin picks that one icon when the app builds, or `layers` when Lucide has none by that name. Draw the logo's icon with it, never with a Lucide icon looked up by name.
203
204
  - `image.square` is the logo without the app's name, about square. `image.horizontal` is the logo with the name in it, wide. Either may be missing. Each has `onLight`, and `onDark` for dark backgrounds, which falls back to `onLight`. A file is a path under `public/`, like `"/logo.svg"`, or an https URL.
204
205
  - An app without the key gets `{ "source": "icon", "icon": "layers", "image": {} }`. A field this SDK does not know is ignored, and an unknown `source` shows the icon. An `icon` that is not a kebab-case name, an image without `onLight` or a file that is neither a path under `public/` nor an https URL fails the build, naming the key.
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 1.12.0
16
+ library_version: 1.13.0
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.12.0
13
+ library_version: 1.13.0
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.
@@ -20,12 +20,12 @@ A plain `<a href>`, never `<Link>` or `navigate`: the visitor leaves the app for
20
20
 
21
21
  Sign-in starts in the app, always. A sign-in started at the identity provider, from an app tile on its dashboard, is not supported: it arrives without the app's record of having started and ends in `expired`.
22
22
 
23
- When single sign-on needs more from the visitor, or fails, they come back to the page `auth.routes.sso.path` in `softr.json` names, `/sso-authentication` when it is not set. That page must exist. It reads two search params:
23
+ When single sign-on needs more from the visitor, or fails, they come back to the page `auth.routes.sso.path` in `softr.json` names, `/sso-authentication` when it is not set. That page must exist. It reads two search params, and the login page's redirect param (`auth.routes.login.redirectParam`) with the path the visitor wanted:
24
24
 
25
25
  | Param | Means | Show |
26
26
  | --- | --- | --- |
27
27
  | `authenticator` | `'verify'`, `'setup'` or `'setupOptional'`: the app asks for an authenticator app as well | the second-factor step, as for `authenticatorRequired` and its `step`. Finish with the same calls, then `toReturnPath(location)` |
28
- | `error` | why it did not finish, one of the codes below | a message, a "Try again" link to `ssoSignInHref()`, and a link to the login page |
28
+ | `error` | why it did not finish, one of the codes below | a message, a "Try again" link to `ssoSignInHref(toReturnPath(location).href)`, and a link to the login page that keeps the redirect param, so either way the visitor ends where they wanted |
29
29
 
30
30
  | `error` | Means |
31
31
  | --- | --- |
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.12.0
13
+ library_version: 1.13.0
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.12.0
14
+ library_version: 1.13.0
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.12.0
15
+ library_version: 1.13.0
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.12.0
10
+ library_version: 1.13.0
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.12.0
11
+ library_version: 1.13.0
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.12.0
10
+ library_version: 1.13.0
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.0
12
+ library_version: 1.13.0
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.12.0
12
+ library_version: 1.13.0
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.12.0
13
+ library_version: 1.13.0
14
14
  ---
15
15
 
16
16
  # 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.12.0
13
+ library_version: 1.13.0
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.12.0
14
+ library_version: 1.13.0
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.12.0
12
+ library_version: 1.13.0
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.12.0
12
+ library_version: 1.13.0
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.12.0
12
+ library_version: 1.13.0
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.