@softr/sdk 0.0.102 → 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 +13 -0
- package/README.md +4 -2
- package/dist/auth/isomorphic.js +1 -1
- package/dist/auth/session.js +1 -1
- package/dist/default-error-overlay.d.ts +2 -2
- package/dist/fetch.js +15 -1
- package/dist/formatting.d.ts +3 -3
- package/dist/package.js +1 -1
- package/dist/pwa.d.ts +2 -2
- package/package.json +2 -2
- package/skills/softr-sdk/SKILL.md +1 -1
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +1 -1
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
- package/skills/softr-sdk/current-user/SKILL.md +1 -1
- package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
- package/skills/softr-sdk/formatting/SKILL.md +1 -1
- package/skills/softr-sdk/integrations/SKILL.md +1 -1
- package/skills/softr-sdk/mcp/SKILL.md +1 -1
- package/skills/softr-sdk/push-notifications/SKILL.md +1 -1
- package/skills/softr-sdk/pwa/SKILL.md +1 -1
- package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
- package/skills/softr-sdk/record-queries/SKILL.md +1 -1
- package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/workflows/SKILL.md +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @softr/sdk
|
|
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
|
+
|
|
9
|
+
## 1.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- First stable release.
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @softr/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
The docs are agent skills in the package's `skills/` folder. They are versioned with the package, so a coding agent always reads the docs for the version the app has installed. Run `npx @tanstack/intent@latest install` in the app to point your agent at them.
|
package/dist/auth/isomorphic.js
CHANGED
|
@@ -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
|
|
package/dist/auth/session.js
CHANGED
|
@@ -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
|
|
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):
|
|
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
|
|
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
|
}
|
package/dist/formatting.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import * as
|
|
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
|
-
}):
|
|
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
|
-
}):
|
|
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
package/dist/pwa.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
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():
|
|
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": "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 @@
|
|
|
9
9
|
"./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" }
|
|
10
10
|
},
|
|
11
11
|
"bin": { "softr-sdk": "./dist/cli.js" },
|
|
12
|
-
"files": ["dist", "schema", "skills", "!skills/_artifacts"],
|
|
12
|
+
"files": ["dist", "schema", "skills", "!skills/_artifacts", "CHANGELOG.md"],
|
|
13
13
|
"publishConfig": { "access": "public" },
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsdown",
|
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 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: 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: 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.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 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.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 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: 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: 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: 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: 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: 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.
|