@softr/sdk 1.0.0 → 1.0.1-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.0.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.0.0
4
10
 
5
11
  ### Major Changes
@@ -12,9 +12,9 @@ import { pushMiddleware } from "../push.js";
12
12
  import { faviconMiddleware } from "../favicon.js";
13
13
  import { embeddingMiddleware } from "../embedding.js";
14
14
  import { appIdentityMiddleware } from "../app-identity.js";
15
+ import { getRequestHeader } from "@tanstack/react-start/server";
15
16
  import { createContext, useContext } from "react";
16
17
  import { createMiddleware, createServerFn, getGlobalStartContext } from "@tanstack/react-start";
17
- import { getRequestHeader } from "@tanstack/react-start/server";
18
18
  import { rootRouteId, useRouteContext } from "@tanstack/react-router";
19
19
  import { jsx } from "react/jsx-runtime";
20
20
 
@@ -1,10 +1,10 @@
1
1
  import { expireCookie, expireOtherCopy, readRequestCookies, serializeCookie, writeCookies } from "../cookies.js";
2
2
  import { sessionConfig } from "./config.js";
3
3
  import { userSchema } from "./user.js";
4
+ import { getRequestProtocol } from "@tanstack/react-start/server";
4
5
  import { z } from "zod";
5
6
  import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
6
7
  import { AsyncLocalStorage } from "node:async_hooks";
7
- import { getRequestProtocol } from "@tanstack/react-start/server";
8
8
 
9
9
  //#region src/auth/session.ts
10
10
  const SESSION_TOKEN = "session_token";
@@ -1,4 +1,4 @@
1
- import * as react6 from "react";
1
+ import * as react2 from "react";
2
2
 
3
3
  //#region src/default-error-overlay.d.ts
4
4
  type Props = {
@@ -8,6 +8,6 @@ type Props = {
8
8
  declare function DefaultErrorOverlay({
9
9
  error,
10
10
  reset
11
- }: Props): react6.JSX.Element;
11
+ }: Props): react2.JSX.Element;
12
12
  //#endregion
13
13
  export { DefaultErrorOverlay };
package/dist/fetch.js CHANGED
@@ -2,8 +2,10 @@ 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);
9
11
  if ([
@@ -13,6 +15,10 @@ const fetch = async (input, init) => {
13
15
  ].some((base) => url.startsWith(`${base}/`))) {
14
16
  const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
15
17
  headers.set("user-agent", `softr-sdk/${version}`);
18
+ headers.delete(CLIENT_IP_HEADER);
19
+ const clientIp = readClientIp();
20
+ const isPlatformCall = url.startsWith(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/`);
21
+ if (clientIp && isPlatformCall) headers.set(CLIENT_IP_HEADER, clientIp);
16
22
  init = {
17
23
  ...init,
18
24
  headers
@@ -42,7 +48,7 @@ const fetch = async (input, init) => {
42
48
  * id (`<environment>/<applicationId>/<master number>`) is copied into the signature as is so the verifier can
43
49
  * derive the same key.
44
50
  *
45
- * The signature covers the method, authority, path, query and, when sent, the Authorization header. The body is
51
+ * The signature covers the method, authority, path, query and, when sent, the Authorization and client IP headers. The body is
46
52
  * not covered: TLS protects it in transit, and signing is there to tell the app's own server from anyone holding a
47
53
  * user token, which needs no body coverage. So nothing is buffered here and the body streams through as given.
48
54
  */
@@ -63,6 +69,7 @@ async function sign(input, init) {
63
69
  };
64
70
  const fields = Object.keys(derived);
65
71
  if (headers.has("authorization")) fields.push("authorization");
72
+ if (headers.has(CLIENT_IP_HEADER)) fields.push(CLIENT_IP_HEADER);
66
73
  const created = Math.floor(Date.now() / 1e3);
67
74
  const params = `(${fields.map((field) => `"${field}"`).join(" ")});created=${created};keyid="${keyId}";tag="softr-code-app"`;
68
75
  const base = [...fields.map((field) => `"${field}": ${derived[field] ?? requireDefined(headers.get(field), field)}`), `"@signature-params": ${params}`].join("\n");
@@ -75,6 +82,13 @@ async function sign(input, init) {
75
82
  headers.set("signature", `softr=:${signature}:`);
76
83
  return new Request(request, { headers });
77
84
  }
85
+ function readClientIp() {
86
+ try {
87
+ return getRequestHeader("cf-connecting-ip");
88
+ } catch {
89
+ return;
90
+ }
91
+ }
78
92
  function base64(bytes) {
79
93
  return btoa(String.fromCharCode(...new Uint8Array(bytes)));
80
94
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import * as react0 from "react";
2
+ import * as react3 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
+ }): react3.FunctionComponentElement<react3.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
+ }): react3.FunctionComponentElement<react3.FragmentProps> | null;
122
122
  //#endregion
123
123
  export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.0.0";
2
+ var version = "1.0.1-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
@@ -23,7 +23,7 @@ import "@tanstack/react-start";
23
23
  * )
24
24
  * }
25
25
  */
26
- declare function SoftrPwaHead(): react4.FunctionComponentElement<react4.FragmentProps>;
26
+ declare function SoftrPwaHead(): react0.FunctionComponentElement<react0.FragmentProps>;
27
27
  type PwaPlatform = "ios" | "android" | "desktop";
28
28
  type PwaInstall = {
29
29
  available: false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-alpha.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: core
11
11
  library: softr-sdk
12
- library_version: 1.0.0
12
+ library_version: 1.0.1-alpha.0
13
13
  ---
14
14
 
15
15
  # 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.0.0
16
+ library_version: 1.0.1-alpha.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.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.0.0
12
+ library_version: 1.0.1-alpha.0
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.0.0
12
+ library_version: 1.0.1-alpha.0
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.0.0
12
+ library_version: 1.0.1-alpha.0
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.0.0
10
+ library_version: 1.0.1-alpha.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.0.0
11
+ library_version: 1.0.1-alpha.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.0.0
10
+ library_version: 1.0.1-alpha.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.0.0
12
+ library_version: 1.0.1-alpha.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.0.0
12
+ library_version: 1.0.1-alpha.0
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.0.0
12
+ library_version: 1.0.1-alpha.0
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.0.0
12
+ library_version: 1.0.1-alpha.0
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.0.0
13
+ library_version: 1.0.1-alpha.0
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.0.0
12
+ library_version: 1.0.1-alpha.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.0.0
12
+ library_version: 1.0.1-alpha.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.0.0
12
+ library_version: 1.0.1-alpha.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.