@softr/sdk 0.0.80 → 0.0.81

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.
@@ -2,9 +2,9 @@ import { assert, panic, requireDefined } from "../assertions.js";
2
2
  import { readUserTimezone, writeCookies } from "../cookies.js";
3
3
  import { sessionConfig } from "./config.js";
4
4
  import { clearSession, makeSessionDataCookie, readSessionData, readSessionToken } from "./session.js";
5
- import { makePlatform } from "./platform.js";
6
5
  import { defaultFormatting, resolveFormatting } from "../formatting.js";
7
6
  import { readLocaleSettings } from "../locale-settings.js";
7
+ import { makePlatform } from "./platform.js";
8
8
  import { settings } from "./methods/settings.js";
9
9
  import { bootErrorMiddleware } from "../boot-error.js";
10
10
  import { pwaMiddleware } from "../pwa.js";
@@ -1,9 +1,8 @@
1
1
  import { assert, panic } from "../assertions.js";
2
2
  import { fetch } from "../fetch.js";
3
3
  import { permissionsSchema } from "./permissions.js";
4
- import { sessionConfig } from "./config.js";
5
- import { softrConfig } from "../softr-config.js";
6
4
  import { softrApiUrl } from "../softr-api.js";
5
+ import { softrConfig } from "../softr-config.js";
7
6
  import { z } from "zod";
8
7
 
9
8
  //#region src/auth/platform.ts
@@ -308,7 +307,7 @@ function makePlatform(applicationId) {
308
307
  const errorSchema = z.object({ message: z.string() });
309
308
  async function request(path, init, schema, parse = (response$1) => response$1.json()) {
310
309
  assert(init.json === void 0 || init.form === void 0, "A platform request carries a JSON body or a form, not both");
311
- const response = await fetch(`${await platformApiUrl()}${path}`, {
310
+ const response = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}${path}`, {
312
311
  method: init.method,
313
312
  headers: {
314
313
  accept: "application/json",
@@ -334,35 +333,6 @@ async function request(path, init, schema, parse = (response$1) => response$1.js
334
333
  data: parsed.data
335
334
  };
336
335
  }
337
- let cached;
338
- async function platformApiUrl() {
339
- cached ??= resolvePlatformApiUrl().catch((error) => {
340
- cached = void 0;
341
- throw error;
342
- });
343
- return cached;
344
- }
345
- const contextSchema = z.object({ platformApiUrl: z.string() });
346
- async function resolvePlatformApiUrl() {
347
- const studioApiUrl = process.env.SOFTR_STUDIO_API_URL;
348
- if (process.env.SOFTR_PLATFORM_API_URL || !studioApiUrl || process.env.NODE_ENV === "production") return softrApiUrl("SOFTR_PLATFORM_API_URL");
349
- const { applicationId } = sessionConfig();
350
- const url = `${withoutTrailingSlash(studioApiUrl)}/v1/api/applications/${applicationId}/context/public`;
351
- let response;
352
- try {
353
- response = await fetch(url, { headers: { accept: "application/json" } });
354
- } catch {
355
- panic(`Could not reach ${url}`);
356
- }
357
- if (response.status === 404) panic(`Unknown application ${applicationId}`);
358
- if (!response.ok) panic(`${url} answered ${response.status}`);
359
- const body = contextSchema.safeParse(await response.json().catch(() => null));
360
- if (!body.success) panic(`No platformApiUrl at ${url}`);
361
- return withoutTrailingSlash(body.data.platformApiUrl);
362
- }
363
- function withoutTrailingSlash(url) {
364
- return url.replace(/\/+$/, "");
365
- }
366
336
 
367
337
  //#endregion
368
- export { makePlatform, platformApiUrl };
338
+ export { makePlatform };
@@ -2,7 +2,7 @@ import { assert } from "../assertions.js";
2
2
  import { fetch } from "../fetch.js";
3
3
  import { sessionConfig } from "../auth/config.js";
4
4
  import { readSessionToken } from "../auth/session.js";
5
- import { platformApiUrl } from "../auth/platform.js";
5
+ import { softrApiUrl } from "../softr-api.js";
6
6
  import { describeFailure } from "../datasource/record.js";
7
7
  import { z } from "zod";
8
8
  import { Marked } from "marked";
@@ -78,7 +78,7 @@ async function request(action, path, init) {
78
78
  const headers = {};
79
79
  if (token !== null) headers.Authorization = `Bearer ${token}`;
80
80
  if (init.body !== void 0) headers["Content-Type"] = "application/json";
81
- return fetch(`${await platformApiUrl()}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${encodeURIComponent(action.id)}/comments${path}`, {
81
+ return fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${encodeURIComponent(action.id)}/comments${path}`, {
82
82
  method: init.method,
83
83
  headers,
84
84
  body: init.body === void 0 ? void 0 : JSON.stringify(init.body)
@@ -1,7 +1,7 @@
1
1
  import { fetch } from "../fetch.js";
2
2
  import { sessionConfig } from "../auth/config.js";
3
3
  import { readSessionToken } from "../auth/session.js";
4
- import { platformApiUrl } from "../auth/platform.js";
4
+ import { softrApiUrl } from "../softr-api.js";
5
5
  import { randomUUID } from "node:crypto";
6
6
 
7
7
  //#region src/core/file-upload.ts
@@ -11,7 +11,7 @@ import { randomUUID } from "node:crypto";
11
11
  */
12
12
  async function upload(action, file) {
13
13
  const { applicationId } = sessionConfig();
14
- const baseUrl = await platformApiUrl();
14
+ const baseUrl = softrApiUrl("SOFTR_PLATFORM_API_URL");
15
15
  const uploadUrl = new URL(`${baseUrl}/v1/vibe/applications/${applicationId}/actions/${action.id}/uploads`);
16
16
  uploadUrl.searchParams.set("fileName", file.name);
17
17
  const formData = new FormData();
@@ -2,12 +2,11 @@ import { fetch } from "../fetch.js";
2
2
  import { sessionConfig } from "../auth/config.js";
3
3
  import { readSessionToken } from "../auth/session.js";
4
4
  import { softrApiUrl } from "../softr-api.js";
5
- import { platformApiUrl } from "../auth/platform.js";
6
5
 
7
6
  //#region src/core/workflow.ts
8
7
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
9
8
  async function triggerWorkflow(action, payload) {
10
- const triggerRes = await fetch(`${await platformApiUrl()}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/workflow`, {
9
+ const triggerRes = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/workflow`, {
11
10
  method: "POST",
12
11
  headers: {
13
12
  Authorization: `Bearer ${readSessionToken()}`,
@@ -2,7 +2,7 @@ import { logger } from "./logger.js";
2
2
  import { fetch } from "./fetch.js";
3
3
  import { readRequestCookies, serializeCookie, writeCookies } from "./cookies.js";
4
4
  import { sessionConfig } from "./auth/config.js";
5
- import { platformApiUrl } from "./auth/platform.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
 
@@ -42,7 +42,7 @@ function parseLocaleSettings(cookie) {
42
42
  }
43
43
  async function fetchLocaleSettings() {
44
44
  const { applicationId } = sessionConfig();
45
- const response = await fetch(`${await platformApiUrl()}/v1/vibe/applications/${applicationId}/locale-settings`, { headers: { accept: "application/json" } });
45
+ const response = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${applicationId}/locale-settings`, { headers: { accept: "application/json" } });
46
46
  if (!response.ok) throw new Error(`The platform answered ${response.status}`);
47
47
  return localeSettingsSchema.parse(await response.json());
48
48
  }
package/dist/mcp.js CHANGED
@@ -2,9 +2,10 @@ import { assert } from "./assertions.js";
2
2
  import { fetch } from "./fetch.js";
3
3
  import { sessionConfig } from "./auth/config.js";
4
4
  import { readSessionToken, withSessionToken } from "./auth/session.js";
5
- import { softrConfig } from "./softr-config.js";
6
- import { makePlatform, platformApiUrl } from "./auth/platform.js";
5
+ import { softrApiUrl } from "./softr-api.js";
7
6
  import { isDatasourceAction } from "./action.js";
7
+ import { softrConfig } from "./softr-config.js";
8
+ import { makePlatform } from "./auth/platform.js";
8
9
  import { ds } from "./datasource/datasource.js";
9
10
  import { z } from "zod";
10
11
  import { createMiddleware } from "@tanstack/react-start";
@@ -146,7 +147,7 @@ const APPLICATION_ID_HEADER = "Softr-Application-ID";
146
147
  async function platformFetch(path, init) {
147
148
  const { applicationId } = sessionConfig();
148
149
  try {
149
- return await fetch(`${await platformApiUrl()}${path}`, {
150
+ return await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}${path}`, {
150
151
  method: init.method,
151
152
  headers: {
152
153
  accept: "application/json",
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.80";
2
+ var version = "0.0.81";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { logger } from "./logger.js";
2
2
  import { fetch } from "./fetch.js";
3
3
  import { sessionConfig } from "./auth/config.js";
4
- import { platformApiUrl } from "./auth/platform.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";
@@ -41,7 +41,7 @@ function readPwa() {
41
41
  }
42
42
  async function fetchPwa() {
43
43
  const { applicationId } = sessionConfig();
44
- const response = await fetch(`${await platformApiUrl()}/v1/vibe/applications/${applicationId}/pwa`, { headers: { accept: "application/json" } });
44
+ const response = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${applicationId}/pwa`, { headers: { accept: "application/json" } });
45
45
  if (response.status === 404) return null;
46
46
  if (!response.ok) throw new Error(`The platform answered ${response.status}`);
47
47
  return pwaSchema.parse(await response.json());
@@ -1,6 +1,6 @@
1
1
  import { panic } from "../assertions.js";
2
- import { softrConfig } from "../softr-config.js";
3
2
  import { ACCESS_REASONS, checkRule } from "./visibility.js";
3
+ import { softrConfig } from "../softr-config.js";
4
4
  import { redirect } from "@tanstack/react-router";
5
5
 
6
6
  //#region src/route/route.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "0.0.80",
3
+ "version": "0.0.81",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: core
10
10
  library: softr-sdk
11
- library_version: 0.0.80
11
+ library_version: 0.0.81
12
12
  ---
13
13
 
14
14
  # Softr SDK core
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.80
12
+ library_version: 0.0.81
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.80
12
+ library_version: 0.0.81
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.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 0.0.80
11
+ library_version: 0.0.81
12
12
  ---
13
13
 
14
14
  **Boundary.** `comments` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler. Importing it into a component fails the build. `useCommentComposer` lives on `@softr/sdk/client` and runs in components. `defineComments` comes 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.80
12
+ library_version: 0.0.81
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.80
10
+ library_version: 0.0.81
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.80
11
+ library_version: 0.0.81
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.80
10
+ library_version: 0.0.81
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.80
12
+ library_version: 0.0.81
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.80
12
+ library_version: 0.0.81
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.80
11
+ library_version: 0.0.81
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.80
12
+ library_version: 0.0.81
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.80
12
+ library_version: 0.0.81
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 0.0.80
11
+ library_version: 0.0.81
12
12
  ---
13
13
 
14
14
  **Boundary.** `defineVisibility`, 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.80
12
+ library_version: 0.0.81
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.