@softr/sdk 0.0.89-alpha.4 → 0.0.90-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.
@@ -1,8 +1,8 @@
1
1
  import { assert } from "../assertions.js";
2
+ import { softrApiUrl } from "../softr-api.js";
2
3
  import { fetch } from "../fetch.js";
3
4
  import { sessionConfig } from "../auth/config.js";
4
5
  import { readSessionToken } from "../auth/session.js";
5
- import { softrApiUrl } from "../softr-api.js";
6
6
  import { describeFailure, refererHeader } from "../datasource/record.js";
7
7
  import { z } from "zod";
8
8
  import { createServerFn } from "@tanstack/react-start";
@@ -1,8 +1,8 @@
1
1
  import { assert, panic } from "../assertions.js";
2
+ import { softrApiUrl } from "../softr-api.js";
2
3
  import { fetch } from "../fetch.js";
3
4
  import { softrConfig } from "../softr-config.js";
4
5
  import { permissionsSchema } from "./permissions.js";
5
- import { softrApiUrl } from "../softr-api.js";
6
6
  import { z } from "zod";
7
7
 
8
8
  //#region src/auth/platform.ts
@@ -1,7 +1,8 @@
1
+ import { softrApiUrl } from "../softr-api.js";
1
2
  import { fetch } from "../fetch.js";
2
3
  import { sessionConfig } from "../auth/config.js";
3
4
  import { readSessionToken } from "../auth/session.js";
4
- import { softrApiUrl } from "../softr-api.js";
5
+ import { describeFailure } from "../datasource/record.js";
5
6
  import { randomUUID } from "node:crypto";
6
7
 
7
8
  //#region src/core/file-upload.ts
@@ -18,7 +19,7 @@ async function upload(action, file) {
18
19
  headers: token ? { Authorization: `Bearer ${token}` } : {},
19
20
  body: formData
20
21
  });
21
- if (!res.ok) throw new Error(`File upload failed: ${res.status}`);
22
+ if (!res.ok) throw new Error(`File upload failed: ${await describeFailure(res)}`);
22
23
  const resultJSON = await res.json();
23
24
  return {
24
25
  url: resultJSON.url,
@@ -1,7 +1,8 @@
1
+ import { softrApiUrl } from "../softr-api.js";
1
2
  import { fetch } from "../fetch.js";
2
3
  import { sessionConfig } from "../auth/config.js";
3
4
  import { readSessionToken } from "../auth/session.js";
4
- import { softrApiUrl } from "../softr-api.js";
5
+ import { describeFailure } from "../datasource/record.js";
5
6
 
6
7
  //#region src/core/workflow.ts
7
8
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -14,7 +15,7 @@ async function triggerWorkflow(action, payload) {
14
15
  },
15
16
  body: JSON.stringify({ input: payload ?? {} })
16
17
  });
17
- if (!triggerRes.ok) throw new Error(`Workflow trigger failed: ${triggerRes.status}`);
18
+ if (!triggerRes.ok) throw new Error(`Workflow trigger failed: ${await describeFailure(triggerRes)}`);
18
19
  let details = await triggerRes.json();
19
20
  while (details.status !== "FINISHED") {
20
21
  if (details.status === "PENDING_INTERACTION") for (const interaction of details.nextInteractions) {
@@ -23,11 +24,11 @@ async function triggerWorkflow(action, payload) {
23
24
  headers: { "Content-Type": "application/json" },
24
25
  body: "{}"
25
26
  });
26
- if (!interactionRes.ok) throw new Error(`Workflow interaction failed: ${interactionRes.status}`);
27
+ if (!interactionRes.ok) throw new Error(`Workflow interaction failed: ${await describeFailure(interactionRes)}`);
27
28
  }
28
29
  await sleep(1e3);
29
30
  const detailsRes = await fetch(`${softrApiUrl("SOFTR_WORKFLOWS_API_URL")}/v1/workflows/${action.resource.workflowId}/executions/${details.id}/details`);
30
- if (!detailsRes.ok) throw new Error(`Workflow status check failed: ${detailsRes.status}`);
31
+ if (!detailsRes.ok) throw new Error(`Workflow status check failed: ${await describeFailure(detailsRes)}`);
31
32
  details = await detailsRes.json();
32
33
  }
33
34
  }
@@ -1,8 +1,8 @@
1
1
  import { assert, panic } from "../assertions.js";
2
+ import { softrApiUrl } from "../softr-api.js";
2
3
  import { fetch } from "../fetch.js";
3
4
  import { readUserTimezone } from "../cookies.js";
4
5
  import { readSessionToken } from "../auth/session.js";
5
- import { softrApiUrl } from "../softr-api.js";
6
6
  import { isDatasourceAction } from "../action.js";
7
7
  import { buildFilterCriteria, buildOrderBy, dealiasFilterCriteria, dealiasOrderBy } from "./filter.js";
8
8
  import { andAll, makeFieldSet, makeSortSet } from "./fields.js";
package/dist/fetch.js CHANGED
@@ -1,9 +1,29 @@
1
+ import { version } from "./package.js";
2
+ import { assert, requireDefined } from "./assertions.js";
1
3
  import { logger } from "./logger.js";
4
+ import { softrApiUrl } from "./softr-api.js";
2
5
 
3
6
  //#region src/fetch.ts
4
7
  const fetch = async (input, init) => {
5
- if (process.env.NODE_ENV === "production") return globalThis.fetch(input, init);
6
8
  const url = input instanceof Request ? input.url : String(input);
9
+ if ([
10
+ softrApiUrl("SOFTR_PLATFORM_API_URL"),
11
+ softrApiUrl("SOFTR_DATASOURCE_API_URL"),
12
+ softrApiUrl("SOFTR_WORKFLOWS_API_URL")
13
+ ].some((base) => url.startsWith(`${base}/`))) {
14
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
15
+ headers.set("user-agent", `softr-sdk/${version}`);
16
+ init = {
17
+ ...init,
18
+ headers
19
+ };
20
+ const signed = await sign(input, init);
21
+ if (signed) {
22
+ input = signed;
23
+ init = void 0;
24
+ }
25
+ }
26
+ if (process.env.NODE_ENV === "production") return globalThis.fetch(input, init);
7
27
  const method = init?.method ?? (input instanceof Request ? input.method : "GET");
8
28
  const started = Date.now();
9
29
  try {
@@ -16,6 +36,48 @@ const fetch = async (input, init) => {
16
36
  throw error;
17
37
  }
18
38
  };
39
+ /**
40
+ * RFC 9421 signature over the request, with the key Studio handed the app at publish or session start. The SDK
41
+ * never derives, rotates or inspects the key: Softr derives it from a master key and the app's nonce, and the key
42
+ * id (`<environment>/<applicationId>/<master number>`) is copied into the signature as is so the verifier can
43
+ * derive the same key.
44
+ *
45
+ * The signature covers the method, authority, path, query and, when sent, the Authorization header. The body is
46
+ * not covered: TLS protects it in transit, and signing is there to tell the app's own server from anyone holding a
47
+ * user token, which needs no body coverage. So nothing is buffered here and the body streams through as given.
48
+ */
49
+ async function sign(input, init) {
50
+ const key = process.env.SOFTR_REQUEST_SIGNING_KEY;
51
+ const keyId = process.env.SOFTR_REQUEST_SIGNING_KEY_ID;
52
+ if (!key || !keyId) return void 0;
53
+ assert(/^[0-9a-f]{64}$/i.test(key), "SOFTR_REQUEST_SIGNING_KEY must be 64 hex characters");
54
+ assert(!/["\\]/.test(keyId), "SOFTR_REQUEST_SIGNING_KEY_ID must not contain quotes or backslashes");
55
+ const request = new Request(input, init);
56
+ const headers = new Headers(request.headers);
57
+ const { host, pathname, search } = new URL(request.url);
58
+ const derived = {
59
+ "@method": request.method,
60
+ "@authority": host,
61
+ "@path": pathname,
62
+ "@query": search || "?"
63
+ };
64
+ const fields = Object.keys(derived);
65
+ if (headers.has("authorization")) fields.push("authorization");
66
+ const created = Math.floor(Date.now() / 1e3);
67
+ const params = `(${fields.map((field) => `"${field}"`).join(" ")});created=${created};keyid="${keyId}";tag="softr-code-app"`;
68
+ const base = [...fields.map((field) => `"${field}": ${derived[field] ?? requireDefined(headers.get(field), field)}`), `"@signature-params": ${params}`].join("\n");
69
+ const hmacKey = await crypto.subtle.importKey("raw", Uint8Array.from(key.match(/../g) ?? [], (byte) => parseInt(byte, 16)), {
70
+ name: "HMAC",
71
+ hash: "SHA-256"
72
+ }, false, ["sign"]);
73
+ const signature = base64(await crypto.subtle.sign("HMAC", hmacKey, new TextEncoder().encode(base)));
74
+ headers.set("signature-input", `softr=${params}`);
75
+ headers.set("signature", `softr=:${signature}:`);
76
+ return new Request(request, { headers });
77
+ }
78
+ function base64(bytes) {
79
+ return btoa(String.fromCharCode(...new Uint8Array(bytes)));
80
+ }
19
81
 
20
82
  //#endregion
21
83
  export { fetch };
@@ -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
@@ -94,7 +94,7 @@ declare function FormattingScope({
94
94
  /** A BCP 47 locale, such as `de-DE`. It drops the app's fixed date format inside the scope. */
95
95
  locale?: string;
96
96
  children?: ReactNode;
97
- }): react2.FunctionComponentElement<react2.ProviderProps<Scope>>;
97
+ }): react0.FunctionComponentElement<react0.ProviderProps<Scope>>;
98
98
  /**
99
99
  * A date in the app's format, safe to render on the server. A timestamp whose
100
100
  * zone is not known yet renders `fallback` until the browser supplies it, so
@@ -115,6 +115,6 @@ declare function FormattedDate({
115
115
  time?: boolean;
116
116
  /** What renders while the visitor's zone is unknown. */
117
117
  fallback?: ReactNode;
118
- }): react2.FunctionComponentElement<react2.FragmentProps>;
118
+ }): react0.FunctionComponentElement<react0.FragmentProps>;
119
119
  //#endregion
120
120
  export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { useFileUpload } from "./core/use-file-upload.js";
2
1
  import { defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
2
+ import { useFileUpload } from "./core/use-file-upload.js";
3
3
  import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.js";
4
4
  import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
5
5
  import { definePage, pageHead } from "./route/page.js";
@@ -1,8 +1,8 @@
1
1
  import { logger } from "./logger.js";
2
+ import { softrApiUrl } from "./softr-api.js";
2
3
  import { fetch } from "./fetch.js";
3
4
  import { readRequestCookies, serializeCookie, writeCookies } from "./cookies.js";
4
5
  import { sessionConfig } from "./auth/config.js";
5
- import { softrApiUrl } from "./softr-api.js";
6
6
  import { localeSettingsSchema } from "./formatting.js";
7
7
  import { getRequestProtocol } from "@tanstack/react-start/server";
8
8
 
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DatasourceAction } from "./action.js";
2
- import * as _tanstack_react_start0 from "@tanstack/react-start";
2
+ import * as _tanstack_react_start6 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_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>;
34
+ declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start6.RequestMiddlewareAfterServer<{}, undefined, undefined>;
35
35
  //#endregion
36
36
  export { softrMcpMiddleware };
package/dist/mcp.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { assert } from "./assertions.js";
2
+ import { softrApiUrl } from "./softr-api.js";
2
3
  import { fetch } from "./fetch.js";
3
4
  import { softrConfig } from "./softr-config.js";
4
5
  import { sessionConfig } from "./auth/config.js";
5
6
  import { readSessionToken, withSessionToken } from "./auth/session.js";
6
- import { softrApiUrl } from "./softr-api.js";
7
7
  import { isDatasourceAction } from "./action.js";
8
8
  import { makePlatform } from "./auth/platform.js";
9
9
  import { ds } from "./datasource/datasource.js";
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.89-alpha.4";
2
+ var version = "0.0.90-alpha.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.d.ts CHANGED
@@ -1,4 +1,4 @@
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
@@ -23,7 +23,7 @@ import "@tanstack/react-start";
23
23
  * )
24
24
  * }
25
25
  */
26
- declare function SoftrPwaHead(): react0.FunctionComponentElement<react0.FragmentProps>;
26
+ declare function SoftrPwaHead(): react4.FunctionComponentElement<react4.FragmentProps>;
27
27
  type PwaPlatform = "ios" | "android" | "desktop";
28
28
  type PwaInstall = {
29
29
  available: false;
package/dist/pwa.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { logger } from "./logger.js";
2
+ import { softrApiUrl } from "./softr-api.js";
2
3
  import { fetch } from "./fetch.js";
3
4
  import { sessionConfig } from "./auth/config.js";
4
- import { softrApiUrl } from "./softr-api.js";
5
5
  import { z } from "zod";
6
6
  import { Fragment, createElement, useEffect, useState } from "react";
7
7
  import { createMiddleware } from "@tanstack/react-start";
@@ -125,7 +125,7 @@ function usePwaInstall() {
125
125
  useEffect(() => {
126
126
  if (window.matchMedia("(display-mode: standalone)").matches || "standalone" in navigator && navigator.standalone === true) return;
127
127
  let cancelled = false;
128
- fetch(INSTALL_PATH, { headers: { accept: "application/json" } }).then(async (response) => {
128
+ globalThis.fetch(INSTALL_PATH, { headers: { accept: "application/json" } }).then(async (response) => {
129
129
  if (!response.ok) return;
130
130
  const parsed = installSchema.safeParse(await response.json());
131
131
  if (!parsed.success || cancelled) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "0.0.89-alpha.4",
3
+ "version": "0.0.90-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: 0.0.89-alpha.4
12
+ library_version: 0.0.90-alpha.0
13
13
  ---
14
14
 
15
15
  # Softr SDK core
@@ -12,7 +12,7 @@ description: >-
12
12
  metadata:
13
13
  type: sub-skill
14
14
  library: softr-sdk
15
- library_version: 0.0.89-alpha.4
15
+ library_version: 0.0.90-alpha.0
16
16
  ---
17
17
 
18
18
  **Boundary.** `listAgents` and `useAgentChat` live on `@softr/sdk`. `listAgents` runs in a route loader, `useAgentChat` in a component. Neither needs a route, server function or registration of its own. It chats as the signed-in visitor, or anonymously when no one is signed in.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.89-alpha.4
12
+ library_version: 0.0.90-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.89-alpha.4
12
+ library_version: 0.0.90-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: 0.0.89-alpha.4
12
+ library_version: 0.0.90-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: 0.0.89-alpha.4
10
+ library_version: 0.0.90-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: 0.0.89-alpha.4
11
+ library_version: 0.0.90-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: 0.0.89-alpha.4
10
+ library_version: 0.0.90-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.89-alpha.4
12
+ library_version: 0.0.90-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.89-alpha.4
12
+ library_version: 0.0.90-alpha.0
13
13
  ---
14
14
 
15
15
  # Installing the app
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 0.0.89-alpha.4
11
+ library_version: 0.0.90-alpha.0
12
12
  ---
13
13
 
14
14
  **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.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.89-alpha.4
12
+ library_version: 0.0.90-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. 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.89-alpha.4
12
+ library_version: 0.0.90-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: 0.0.89-alpha.4
12
+ library_version: 0.0.90-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.89-alpha.4
12
+ library_version: 0.0.90-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.