@softr/sdk 1.12.0 → 1.12.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.12.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 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.
8
+
3
9
  ## 1.12.0
4
10
 
5
11
  ### 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) {
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.12.0";
2
+ var version = "1.12.1";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: core
13
13
  library: softr-sdk
14
- library_version: 1.12.0
14
+ library_version: 1.12.1
15
15
  ---
16
16
 
17
17
  # 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.12.0
16
+ library_version: 1.12.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.12.0
13
+ library_version: 1.12.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.
@@ -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.12.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. 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.12.1
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.12.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.12.0
10
+ library_version: 1.12.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.
@@ -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.12.1
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.12.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.0
12
+ library_version: 1.12.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.
@@ -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.12.1
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.12.1
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.12.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.12.0
14
+ library_version: 1.12.1
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.12.1
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.12.1
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.12.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.