@softr/sdk 1.3.0 → 1.3.2-alpha.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,11 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Send the visitor's IP, signed, with calls to the Softr platform, so apps can log users out when the country they use the app from changes.
8
+
3
9
  ## 1.3.0
4
10
 
5
11
  ### Minor Changes
@@ -14,9 +14,9 @@ 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 { getRequestHeader } from "@tanstack/react-start/server";
17
18
  import { createContext, useContext } from "react";
18
19
  import { createMiddleware, createServerFn } from "@tanstack/react-start";
19
- import { getRequestHeader } from "@tanstack/react-start/server";
20
20
  import { rootRouteId, useRouteContext } from "@tanstack/react-router";
21
21
  import { jsx } from "react/jsx-runtime";
22
22
 
@@ -3,10 +3,10 @@ import { expireCookie, expireOtherCopy, readRequestCookies, serializeCookie, wri
3
3
  import { sessionConfig } from "./config.js";
4
4
  import { makePlatform } from "./platform.js";
5
5
  import { userSchema } from "./user.js";
6
+ import { getRequestProtocol } from "@tanstack/react-start/server";
6
7
  import { z } from "zod";
7
8
  import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
8
9
  import { AsyncLocalStorage } from "node:async_hooks";
9
- import { getRequestProtocol } from "@tanstack/react-start/server";
10
10
 
11
11
  //#region src/auth/session.ts
12
12
  const SESSION_TOKEN = "session_token";
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 react0 from "react";
2
+ import * as react2 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
- }): react0.FunctionComponentElement<react0.ProviderProps<Scope>>;
99
+ }): react2.FunctionComponentElement<react2.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
- }): react0.FunctionComponentElement<react0.FragmentProps> | null;
121
+ }): react2.FunctionComponentElement<react2.FragmentProps> | null;
122
122
  //#endregion
123
123
  export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DatasourceAction } from "./action.js";
2
- import * as _tanstack_react_start10 from "@tanstack/react-start";
2
+ import * as _tanstack_react_start9 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_start10.RequestMiddlewareAfterServer<{}, undefined, undefined>;
34
+ declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start9.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";
2
+ var version = "1.3.2-alpha.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react4 from "react";
1
+ import * as react0 from "react";
2
2
  import "@tanstack/react-start";
3
3
 
4
4
  //#region src/pwa.d.ts
@@ -24,7 +24,7 @@ import "@tanstack/react-start";
24
24
  * )
25
25
  * }
26
26
  */
27
- declare function SoftrPwaHead(): react4.FunctionComponentElement<react4.FragmentProps>;
27
+ declare function SoftrPwaHead(): react0.FunctionComponentElement<react0.FragmentProps>;
28
28
  type PwaPlatform = "ios" | "android" | "desktop";
29
29
  type PwaInstall = {
30
30
  available: false;
package/package.json CHANGED
@@ -1,16 +1,38 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.2-alpha.0",
4
4
  "type": "module",
5
5
  "exports": {
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" },
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
+ },
14
36
  "scripts": {
15
37
  "build": "tsdown",
16
38
  "test": "node --import ./src/test-utils/setup.ts --test",
@@ -42,7 +64,9 @@
42
64
  "optional": true
43
65
  }
44
66
  },
45
- "keywords": ["tanstack-intent"],
67
+ "keywords": [
68
+ "tanstack-intent"
69
+ ],
46
70
  "intent": {
47
71
  "version": 1,
48
72
  "repo": "@softr/sdk",
@@ -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
@@ -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.
@@ -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
@@ -36,6 +36,8 @@ type User = {
36
36
  }
37
37
  ```
38
38
 
39
+ `avatarUrl` is the picture column the app's users connection maps, and the only place the visitor's photo comes from. `null` means the connection maps no picture column: show initials, and never read the visitor's row in the Users table for a photo instead. The user maps that column in Studio, in the app's users settings, and every place that shows the visitor follows.
40
+
39
41
  ## Core Patterns
40
42
 
41
43
  ### In a component: `useCurrentUser()`
@@ -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
@@ -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
  # Installing the app
@@ -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.