@softr/sdk 1.3.0-alpha.0 → 1.3.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 (43) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/auth/isomorphic.d.ts +11 -4
  3. package/dist/auth/isomorphic.js +5 -2
  4. package/dist/auth/methods/sso.d.ts +19 -0
  5. package/dist/auth/methods/sso.js +28 -0
  6. package/dist/auth/platform.js +46 -2
  7. package/dist/auth/returnPath.js +17 -15
  8. package/dist/auth/server.d.ts +2 -0
  9. package/dist/auth/server.js +2 -0
  10. package/dist/auth/session.js +45 -2
  11. package/dist/auth/sso.d.ts +24 -0
  12. package/dist/auth/sso.js +204 -0
  13. package/dist/cookies.js +2 -2
  14. package/dist/fetch.js +13 -2
  15. package/dist/formatting.d.ts +3 -3
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +2 -2
  18. package/dist/mcp.d.ts +2 -2
  19. package/dist/package.js +1 -1
  20. package/dist/pwa.d.ts +5 -4
  21. package/dist/pwa.js +54 -9
  22. package/dist/softr-config.schema.js +2 -1
  23. package/package.json +10 -34
  24. package/schema/softr.schema.json +10 -1
  25. package/skills/softr-sdk/SKILL.md +2 -2
  26. package/skills/softr-sdk/ai/SKILL.md +1 -1
  27. package/skills/softr-sdk/auth/SKILL.md +1 -1
  28. package/skills/softr-sdk/auth/references/single-sign-on.md +50 -0
  29. package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
  30. package/skills/softr-sdk/current-user/SKILL.md +1 -1
  31. package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
  32. package/skills/softr-sdk/formatting/SKILL.md +1 -1
  33. package/skills/softr-sdk/integrations/SKILL.md +1 -1
  34. package/skills/softr-sdk/mcp/SKILL.md +1 -1
  35. package/skills/softr-sdk/push-notifications/SKILL.md +1 -1
  36. package/skills/softr-sdk/pwa/SKILL.md +7 -7
  37. package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
  38. package/skills/softr-sdk/record-queries/SKILL.md +1 -1
  39. package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
  40. package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
  41. package/skills/softr-sdk/workflows/SKILL.md +1 -1
  42. package/dist/auth/idle-timeout.d.ts +0 -17
  43. package/dist/auth/idle-timeout.js +0 -200
package/dist/fetch.js CHANGED
@@ -2,17 +2,27 @@ import { version } from "./package.js";
2
2
  import { assert, requireDefined } from "./assertions.js";
3
3
  import { logger } from "./logger.js";
4
4
  import { softrApiUrl } from "./softr-api.js";
5
+ import { getRequestHeader } from "@tanstack/react-start/server";
5
6
 
6
7
  //#region src/fetch.ts
8
+ const CLIENT_IP_HEADER = "x-softr-client-ip";
7
9
  const fetch = async (input, init) => {
8
10
  const url = input instanceof Request ? input.url : String(input);
11
+ const platformBase = softrApiUrl("SOFTR_PLATFORM_API_URL");
9
12
  if ([
10
- softrApiUrl("SOFTR_PLATFORM_API_URL"),
13
+ platformBase,
11
14
  softrApiUrl("SOFTR_DATASOURCE_API_URL"),
12
15
  softrApiUrl("SOFTR_WORKFLOWS_API_URL")
13
16
  ].some((base) => url.startsWith(`${base}/`))) {
14
17
  const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
15
18
  headers.set("user-agent", `softr-sdk/${version}`);
19
+ headers.delete(CLIENT_IP_HEADER);
20
+ const isPlatformCall = url.startsWith(`${platformBase}/`);
21
+ const isProduction = process.env.NODE_ENV === "production";
22
+ if (isPlatformCall && isProduction) try {
23
+ const clientIp = getRequestHeader("cf-connecting-ip");
24
+ if (clientIp) headers.set(CLIENT_IP_HEADER, clientIp);
25
+ } catch {}
16
26
  init = {
17
27
  ...init,
18
28
  headers
@@ -42,7 +52,7 @@ const fetch = async (input, init) => {
42
52
  * id (`<environment>/<applicationId>/<master number>`) is copied into the signature as is so the verifier can
43
53
  * derive the same key.
44
54
  *
45
- * The signature covers the method, authority, path, query and, when sent, the Authorization header. The body is
55
+ * The signature covers the method, authority, path, query and, when sent, the Authorization and client IP headers. The body is
46
56
  * not covered: TLS protects it in transit, and signing is there to tell the app's own server from anyone holding a
47
57
  * user token, which needs no body coverage. So nothing is buffered here and the body streams through as given.
48
58
  */
@@ -63,6 +73,7 @@ async function sign(input, init) {
63
73
  };
64
74
  const fields = Object.keys(derived);
65
75
  if (headers.has("authorization")) fields.push("authorization");
76
+ if (headers.has(CLIENT_IP_HEADER)) fields.push(CLIENT_IP_HEADER);
66
77
  const created = Math.floor(Date.now() / 1e3);
67
78
  const params = `(${fields.map((field) => `"${field}"`).join(" ")});created=${created};keyid="${keyId}";tag="softr-code-app"`;
68
79
  const base = [...fields.map((field) => `"${field}": ${derived[field] ?? requireDefined(headers.get(field), field)}`), `"@signature-params": ${params}`].join("\n");
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import * as react2 from "react";
2
+ import * as react0 from "react";
3
3
  import { ReactNode } from "react";
4
4
 
5
5
  //#region src/formatting.d.ts
@@ -96,7 +96,7 @@ declare function FormattingScope({
96
96
  /** A BCP 47 locale, such as `de-DE`. It drops the app's fixed date format inside the scope. */
97
97
  locale?: string;
98
98
  children?: ReactNode;
99
- }): react2.FunctionComponentElement<react2.ProviderProps<Scope>>;
99
+ }): react0.FunctionComponentElement<react0.ProviderProps<Scope>>;
100
100
  /**
101
101
  * A date in the app's format, safe to render on the server. A timestamp whose
102
102
  * zone is not known yet renders `fallback` until the browser supplies it, so
@@ -118,6 +118,6 @@ declare function FormattedDate({
118
118
  time?: boolean;
119
119
  /** What renders while the visitor's zone is unknown. */
120
120
  fallback?: ReactNode;
121
- }): react2.FunctionComponentElement<react2.FragmentProps> | null;
121
+ }): react0.FunctionComponentElement<react0.FragmentProps> | null;
122
122
  //#endregion
123
123
  export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };
package/dist/index.d.ts CHANGED
@@ -10,8 +10,8 @@ import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.
10
10
  import { Page, PageSettings, definePage, pageHead } from "./route/page.js";
11
11
  import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
12
12
  import { toReturnPath } from "./auth/returnPath.js";
13
+ import { SsoError, ssoSignInHref } from "./auth/sso.js";
13
14
  import { AuthOptions, AuthSettingsProvider, getAuthSettings, getSoftrContext, initialSoftrContext, softrAuthMiddleware, useAuthSettings, useCurrentUser } from "./auth/isomorphic.js";
14
- import { useIdleTimeout } from "./auth/idle-timeout.js";
15
15
  import { softrMcpMiddleware } from "./mcp.js";
16
16
  import { FieldShape, SoftrFieldRegistry, fieldShape, formatDuration, formatField, formatValue, registerSoftrFields } from "./fields/format.js";
17
17
  import { useOverrides } from "./core/use-overrides.js";
@@ -20,4 +20,4 @@ import { PwaInstall, PwaPlatform, SoftrPwaHead, usePwaInstall } from "./pwa.js";
20
20
  import { PushNotifications, PushPrompt, usePushNotifications } from "./push.js";
21
21
  import { DefaultErrorOverlay } from "./default-error-overlay.js";
22
22
  import { Audience } from "./route/audience.js";
23
- export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Page, type PageSettings, type PushNotifications, type PushPrompt, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
23
+ export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Page, type PageSettings, type PushNotifications, type PushPrompt, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type SsoError, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
package/dist/index.js CHANGED
@@ -4,11 +4,11 @@ import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.
4
4
  import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
5
5
  import { definePage, pageHead } from "./route/page.js";
6
6
  import { toReturnPath } from "./auth/returnPath.js";
7
+ import { ssoSignInHref } from "./auth/sso.js";
7
8
  import { FormattedDate, FormattingScope, formatDate, formatDateTime, formatNumber, useFormatting } from "./formatting.js";
8
9
  import { SoftrPwaHead, usePwaInstall } from "./pwa.js";
9
10
  import { usePushNotifications } from "./push.js";
10
11
  import { AuthSettingsProvider, getAuthSettings, getSoftrContext, initialSoftrContext, softrAuthMiddleware, useAuthSettings, useCurrentUser } from "./auth/isomorphic.js";
11
- import { useIdleTimeout } from "./auth/idle-timeout.js";
12
12
  import { softrMcpMiddleware } from "./mcp.js";
13
13
  import { fieldShape, formatDuration, formatField, formatValue, registerSoftrFields } from "./fields/format.js";
14
14
  import { useOverrides } from "./core/use-overrides.js";
@@ -16,4 +16,4 @@ import { useUserTimezone } from "./timezone.js";
16
16
  import { DefaultErrorOverlay } from "./default-error-overlay.js";
17
17
  import { Audience } from "./route/audience.js";
18
18
 
19
- export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useIdleTimeout, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
19
+ export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, ssoSignInHref, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePushNotifications, usePwaInstall, useUserTimezone };
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DatasourceAction } from "./action.js";
2
- import * as _tanstack_react_start8 from "@tanstack/react-start";
2
+ import * as _tanstack_react_start0 from "@tanstack/react-start";
3
3
 
4
4
  //#region src/mcp.d.ts
5
5
 
@@ -31,6 +31,6 @@ type SoftrMcpOptions = {
31
31
  * ],
32
32
  * }))
33
33
  */
34
- declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start8.RequestMiddlewareAfterServer<{}, undefined, undefined>;
34
+ declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>;
35
35
  //#endregion
36
36
  export { softrMcpMiddleware };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.3.0-alpha.0";
2
+ var version = "1.3.1";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import * as react0 from "react";
1
+ import * as react4 from "react";
2
2
  import "@tanstack/react-start";
3
3
 
4
4
  //#region src/pwa.d.ts
5
5
 
6
6
  /**
7
- * The links that make the app installable: its manifest and its home screen
8
- * icon. Render it once, in `<head>` in the root route's `RootDocument`.
7
+ * The tags that make the app installable: its manifest, its home screen icon,
8
+ * and, while the app is installable, the name and launch screens iOS shows.
9
+ * Render it once, in `<head>` in the root route's `RootDocument`.
9
10
  *
10
11
  * @example
11
12
  * function RootDocument({ children }: { children: React.ReactNode }) {
@@ -23,7 +24,7 @@ import "@tanstack/react-start";
23
24
  * )
24
25
  * }
25
26
  */
26
- declare function SoftrPwaHead(): react0.FunctionComponentElement<react0.FragmentProps>;
27
+ declare function SoftrPwaHead(): react4.FunctionComponentElement<react4.FragmentProps>;
27
28
  type PwaPlatform = "ios" | "android" | "desktop";
28
29
  type PwaInstall = {
29
30
  available: false;
package/dist/pwa.js CHANGED
@@ -18,8 +18,13 @@ const pwaSchema = z.object({
18
18
  install: z.object({
19
19
  name: z.string(),
20
20
  iconUrl: z.string()
21
- })
21
+ }),
22
+ startupImages: z.array(z.object({
23
+ media: z.string(),
24
+ href: z.string()
25
+ })).default([])
22
26
  });
27
+ const iosHeadSchema = pwaSchema.pick({ startupImages: true }).extend({ name: z.string() });
23
28
  let cached;
24
29
  /** The app's PWA, or `null` when it is not installable right now. */
25
30
  function readPwa() {
@@ -49,7 +54,10 @@ function pwaMiddleware() {
49
54
  "content-type": "application/manifest+json",
50
55
  "cache-control": CACHE_CONTROL
51
56
  } });
52
- if (pathname === INSTALL_PATH) return Response.json(pwa.install, { headers: { "cache-control": CACHE_CONTROL } });
57
+ if (pathname === INSTALL_PATH) return Response.json({
58
+ ...pwa.install,
59
+ startupImages: pwa.startupImages
60
+ }, { headers: { "cache-control": CACHE_CONTROL } });
53
61
  try {
54
62
  const iconResponse = await fetch(pwa.install.iconUrl);
55
63
  if (!iconResponse.ok) return new Response(null, { status: 404 });
@@ -63,9 +71,21 @@ function pwaMiddleware() {
63
71
  }
64
72
  });
65
73
  }
74
+ let pendingInstallInfo;
66
75
  /**
67
- * The links that make the app installable: its manifest and its home screen
68
- * icon. Render it once, in `<head>` in the root route's `RootDocument`.
76
+ * What `/_softr/pwa.json` answers, or `null` when it does not. Callers that ask
77
+ * while a request is in flight share it; the next caller after it settles asks again.
78
+ */
79
+ function fetchInstallInfo() {
80
+ pendingInstallInfo ??= globalThis.fetch(INSTALL_PATH, { headers: { accept: "application/json" } }).then((response) => response.ok ? response.json() : null).catch(() => null).finally(() => {
81
+ pendingInstallInfo = void 0;
82
+ });
83
+ return pendingInstallInfo;
84
+ }
85
+ /**
86
+ * The tags that make the app installable: its manifest, its home screen icon,
87
+ * and, while the app is installable, the name and launch screens iOS shows.
88
+ * Render it once, in `<head>` in the root route's `RootDocument`.
69
89
  *
70
90
  * @example
71
91
  * function RootDocument({ children }: { children: React.ReactNode }) {
@@ -84,13 +104,39 @@ function pwaMiddleware() {
84
104
  * }
85
105
  */
86
106
  function SoftrPwaHead() {
107
+ const [iosHead, setIosHead] = useState(null);
108
+ useEffect(() => {
109
+ if (detectPlatform() !== "ios") return;
110
+ let cancelled = false;
111
+ fetchInstallInfo().then((installInfo) => {
112
+ const parsed = iosHeadSchema.safeParse(installInfo);
113
+ if (!parsed.success || cancelled) return;
114
+ setIosHead(parsed.data);
115
+ });
116
+ return () => {
117
+ cancelled = true;
118
+ };
119
+ }, []);
87
120
  return createElement(Fragment, null, createElement("link", {
88
121
  rel: "manifest",
89
122
  href: MANIFEST_PATH
90
123
  }), createElement("link", {
91
124
  rel: "apple-touch-icon",
92
125
  href: ICON_PATH
93
- }));
126
+ }), ...iosHead === null ? [] : [createElement("meta", {
127
+ key: "capable",
128
+ name: "apple-mobile-web-app-capable",
129
+ content: "yes"
130
+ }), createElement("meta", {
131
+ key: "title",
132
+ name: "apple-mobile-web-app-title",
133
+ content: iosHead.name
134
+ })], ...(iosHead?.startupImages ?? []).map((image) => createElement("link", {
135
+ key: image.href,
136
+ rel: "apple-touch-startup-image",
137
+ media: image.media,
138
+ href: image.href
139
+ })));
94
140
  }
95
141
  const installSchema = pwaSchema.shape.install;
96
142
  /**
@@ -111,16 +157,15 @@ function usePwaInstall() {
111
157
  useEffect(() => {
112
158
  if (isStandalone()) return;
113
159
  let cancelled = false;
114
- globalThis.fetch(INSTALL_PATH, { headers: { accept: "application/json" } }).then(async (response) => {
115
- if (!response.ok) return;
116
- const parsed = installSchema.safeParse(await response.json());
160
+ fetchInstallInfo().then((installInfo) => {
161
+ const parsed = installSchema.safeParse(installInfo);
117
162
  if (!parsed.success || cancelled) return;
118
163
  setInstall({
119
164
  available: true,
120
165
  platform: detectPlatform(),
121
166
  ...parsed.data
122
167
  });
123
- }).catch(() => {});
168
+ });
124
169
  return () => {
125
170
  cancelled = true;
126
171
  };
@@ -40,7 +40,8 @@ const SoftrConfigSchema = z.object({
40
40
  magicLink: z.strictObject({
41
41
  path: AppPath,
42
42
  tokenParam: z.string()
43
- })
43
+ }),
44
+ sso: z.strictObject({ path: AppPath }).optional()
44
45
  }),
45
46
  guard: z.strictObject({
46
47
  unauthenticated: AccessBehaviour,
package/package.json CHANGED
@@ -1,38 +1,16 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.3.0-alpha.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "exports": {
6
- ".": {
7
- "types": "./dist/index.d.ts",
8
- "import": "./dist/index.js"
9
- },
10
- "./client": {
11
- "types": "./dist/client.d.ts",
12
- "import": "./dist/client.js"
13
- },
14
- "./server": {
15
- "types": "./dist/server.d.ts",
16
- "import": "./dist/server.js"
17
- },
18
- "./vite": {
19
- "types": "./dist/vite.d.ts",
20
- "import": "./dist/vite.js"
21
- }
22
- },
23
- "bin": {
24
- "softr-sdk": "./dist/cli.js"
25
- },
26
- "files": [
27
- "dist",
28
- "schema",
29
- "skills",
30
- "!skills/_artifacts",
31
- "CHANGELOG.md"
32
- ],
33
- "publishConfig": {
34
- "access": "public"
35
- },
6
+ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
7
+ "./client": { "types": "./dist/client.d.ts", "import": "./dist/client.js" },
8
+ "./server": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
9
+ "./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" }
10
+ },
11
+ "bin": { "softr-sdk": "./dist/cli.js" },
12
+ "files": ["dist", "schema", "skills", "!skills/_artifacts", "CHANGELOG.md"],
13
+ "publishConfig": { "access": "public" },
36
14
  "scripts": {
37
15
  "build": "tsdown",
38
16
  "test": "node --import ./src/test-utils/setup.ts --test",
@@ -64,9 +42,7 @@
64
42
  "optional": true
65
43
  }
66
44
  },
67
- "keywords": [
68
- "tanstack-intent"
69
- ],
45
+ "keywords": ["tanstack-intent"],
70
46
  "intent": {
71
47
  "version": 1,
72
48
  "repo": "@softr/sdk",
@@ -26,7 +26,16 @@
26
26
  },
27
27
  "resetPassword": { "$ref": "#/$defs/tokenRoute", "description": "The page a password reset email links to." },
28
28
  "acceptInvitation": { "$ref": "#/$defs/tokenRoute", "description": "The page an invitation email links to." },
29
- "magicLink": { "$ref": "#/$defs/tokenRoute", "description": "The page a magic link email links to." }
29
+ "magicLink": { "$ref": "#/$defs/tokenRoute", "description": "The page a magic link email links to." },
30
+ "sso": {
31
+ "type": "object",
32
+ "description": "The page single sign-on comes back to when it needs an authenticator code or failed. Defaults to /sso-authentication.",
33
+ "properties": {
34
+ "path": { "$ref": "#/$defs/appPath" }
35
+ },
36
+ "required": ["path"],
37
+ "additionalProperties": false
38
+ }
30
39
  },
31
40
  "required": ["login", "resetPassword", "acceptInvitation", "magicLink"],
32
41
  "additionalProperties": false
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: core
12
12
  library: softr-sdk
13
- library_version: 1.3.0
13
+ library_version: 1.3.1
14
14
  ---
15
15
 
16
16
  # Softr SDK core
@@ -33,7 +33,7 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
33
33
 
34
34
  | Import | Runs | Holds |
35
35
  | --- | --- | --- |
36
- | `@softr/sdk` | Both | `defineQuery`, `defineMutation`, `defineAiAction`, `definePage`, `pageHead`, `defineVisibility`, `guardRoute`, `assertRouteAccess`, `isAuthorized`, `checkAccess`, `Audience`, `useCurrentUser`, `useUserTimezone`, `useIdleTimeout`, `FormattedDate`, `FormattingScope`, `useFormatting`, `formatDate`, `formatDateTime`, `formatNumber`, `formatValue`, `formatField`, `fieldShape`, `registerSoftrFields`, `useOverrides`, `SoftrPwaHead`, `usePwaInstall`, `usePushNotifications`, `getSoftrContext`, `initialSoftrContext`, `softrAuthMiddleware`, the error predicates, and every type |
36
+ | `@softr/sdk` | Both | `defineQuery`, `defineMutation`, `defineAiAction`, `definePage`, `pageHead`, `defineVisibility`, `guardRoute`, `assertRouteAccess`, `isAuthorized`, `checkAccess`, `Audience`, `useCurrentUser`, `useUserTimezone`, `FormattedDate`, `FormattingScope`, `useFormatting`, `formatDate`, `formatDateTime`, `formatNumber`, `formatValue`, `formatField`, `fieldShape`, `registerSoftrFields`, `useOverrides`, `SoftrPwaHead`, `usePwaInstall`, `usePushNotifications`, `getSoftrContext`, `initialSoftrContext`, `softrAuthMiddleware`, the error predicates, and every type |
37
37
  | `@softr/sdk/server` | Server only | `ds`, `auth`, `workflow`, `integration`, `ai` |
38
38
  | `@softr/sdk/client` | Browser only | `useFileUpload` |
39
39
  | `@softr/sdk/vite` | Build | `softr()`, already in `vite.config.ts` |
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 1.3.0
16
+ library_version: 1.3.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.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.3.0
12
+ library_version: 1.3.1
13
13
  ---
14
14
 
15
15
  **Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
@@ -0,0 +1,50 @@
1
+ # Single sign-on
2
+
3
+ The visitor signs in at the app's identity provider (Okta, Entra ID, Google Workspace and the like), which the builder set up in Softr. There is no server function to write. A link starts it, and the visitor comes back signed in:
4
+
5
+ ```tsx
6
+ import { useLocation } from '@tanstack/react-router'
7
+ import { ssoSignInHref, toReturnPath, useAuthSettings } from '@softr/sdk'
8
+
9
+ const options = useAuthSettings()
10
+ const location = useLocation()
11
+
12
+ {options.sso ? (
13
+ <Button nativeButton={false} render={<a href={ssoSignInHref(toReturnPath(location).href)} />}>
14
+ Continue with SSO
15
+ </Button>
16
+ ) : null}
17
+ ```
18
+
19
+ A plain `<a href>`, never `<Link>` or `navigate`: the visitor leaves the app for the identity provider. They land on the path passed in, which only works for a path on this app. Without one, they land where `auth.guard.alreadyAuthenticated` in `softr.json` points, as after any other sign-in.
20
+
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
+
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:
24
+
25
+ | Param | Means | Show |
26
+ | --- | --- | --- |
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 |
29
+
30
+ | `error` | Means |
31
+ | --- | --- |
32
+ | `host` | Single sign-on works only on the published app, not in the preview. Say so. Never link to a URL from the search params: anyone can put one there |
33
+ | `idp` | The identity provider refused or the visitor cancelled there |
34
+ | `not-enabled` | Single sign-on is off or not set up completely |
35
+ | `sign-up-disabled` | No account for this visitor, and the app does not let new people sign up |
36
+ | `restricted` | The account is deactivated, or the app has no room for another user |
37
+ | `expired` | It took too long, another tab started a newer sign-in, or the sign-in started at the identity provider rather than in the app |
38
+ | `failed` | Anything else |
39
+
40
+ With neither param, redirect to `toReturnPath(location)`.
41
+
42
+ An app whose only way in is single sign-on still has a login page, with the button on it.
43
+
44
+ ## Three login pages
45
+
46
+ Three ways to put it on the login page. Build the one the builder asks for:
47
+
48
+ 1. **A button**, as above, next to the other methods. The default.
49
+ 2. **Email first.** Ask for the email, then call `auth.discoverSso({ email })` from a server function. It answers a `Result` of `{ sso: boolean }`, decided by the email's domain alone, and fails only with `tooManyAttempts`. On `sso: true` send the visitor to `ssoSignInHref(...)` with `window.location.assign`, otherwise carry on with the password or code step. Never hardcode the domains: the builder changes them in Softr, and the app would not follow.
50
+ 3. **Straight to the identity provider** when single sign-on is the only method: send the visitor to `ssoSignInHref(...)` as the login page loads. Skip it when the login page has a `signedOut` search param, or the visitor is signed straight back in after signing out, since the identity provider still knows them. The sign-out server function adds it: `throw redirect({ to: '/login', search: { signedOut: true } })`, and so does the login link on the single sign-on page, or an error there sends the visitor to the identity provider and back to the same error. Keep the button on the page for that case.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.3.0
12
+ library_version: 1.3.1
13
13
  ---
14
14
 
15
15
  **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.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.3.0
12
+ library_version: 1.3.1
13
13
  ---
14
14
 
15
15
  # The current user
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 1.3.0
10
+ library_version: 1.3.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.3.0
11
+ library_version: 1.3.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.3.0
10
+ library_version: 1.3.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.3.0
12
+ library_version: 1.3.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.3.0
12
+ library_version: 1.3.1
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -2,21 +2,21 @@
2
2
  name: pwa
3
3
  description: >-
4
4
  Let visitors install the app on their home screen: SoftrPwaHead for the
5
- manifest and icon links, usePwaInstall to decide whether to show an install
6
- button and which platform's steps to show, the PwaInstall and PwaPlatform
7
- types, and how to check that the app is installable. The manifest and icon are
8
- already served; never write them.
5
+ manifest, icon, iOS name and launch screen tags, usePwaInstall to decide
6
+ whether to show an install button and which platform's steps to show, the
7
+ PwaInstall and PwaPlatform types, and how to check that the app is
8
+ installable. The manifest and icon are already served; never write them.
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.3.0
12
+ library_version: 1.3.1
13
13
  ---
14
14
 
15
15
  # Installing the app
16
16
 
17
17
  The builder turns installing on in Studio, under Settings → Mobile app, and sets the name, colour and icon there. The app already answers with its manifest and icon once they do. What the app adds is two things: the links that point the browser at them, and a button that tells visitors how to install.
18
18
 
19
- > **CRITICAL**: Never write a web app manifest, icon files, a service worker, or `manifest` / `apple-touch-icon` links of your own, in `public/` or in `head()`. The app already serves them from Studio's settings, and a file of your own shadows those settings.
19
+ > **CRITICAL**: Never write a web app manifest, icon files, a service worker, or `manifest` / `apple-touch-icon` / `apple-touch-startup-image` links or an `apple-mobile-web-app-title` meta of your own, in `public/` or in `head()`. The app already serves them from Studio's settings, and a file or tag of your own shadows those settings.
20
20
  >
21
21
  > **CRITICAL**: Render an install button only while `usePwaInstall()` returns `available: true`. Never show it unconditionally, never cache the answer, never replace the check with your own. Softr can switch installing off for an app, and this check is the only way that reaches the button.
22
22
 
@@ -48,7 +48,7 @@ The builder switches installing on in Studio, and `usePwaInstall()` reads that s
48
48
 
49
49
  ### The links: `<SoftrPwaHead />`
50
50
 
51
- Render it once, in `<head>` next to `<HeadContent />`, in `RootDocument` in `src/routes/__root.tsx`.
51
+ Render it once, in `<head>` next to `<HeadContent />`, in `RootDocument` in `src/routes/__root.tsx`. While the app is installable it also renders the name iOS puts under the home screen icon and the iOS launch screens, so an installed app opens on its own splash screen instead of white.
52
52
 
53
53
  ```tsx
54
54
  function RootDocument({ children }: { children: React.ReactNode }) {
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.3.0
12
+ library_version: 1.3.1
13
13
  ---
14
14
 
15
15
  **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.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 1.3.0
13
+ library_version: 1.3.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. 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.3.0
12
+ library_version: 1.3.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.3.0
12
+ library_version: 1.3.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.3.0
12
+ library_version: 1.3.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.
@@ -1,17 +0,0 @@
1
- //#region src/auth/idle-timeout.d.ts
2
- /**
3
- * Signs the visitor out of this browser after the idle time set in Studio's
4
- * "End session if idle", and sends them to `/`. Activity in any tab of the app
5
- * keeps the session alive. Does nothing for anonymous visitors.
6
- *
7
- * Call it once, in the root route's document component.
8
- *
9
- * @example
10
- * function RootDocument({ children }: { children: React.ReactNode }) {
11
- * useIdleTimeout()
12
- * // ...
13
- * }
14
- */
15
- declare function useIdleTimeout(): void;
16
- //#endregion
17
- export { useIdleTimeout };