@softr/sdk 0.0.80-envvars.0 → 0.0.80

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";
5
6
  import { defaultFormatting, resolveFormatting } from "../formatting.js";
6
7
  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,8 +1,9 @@
1
1
  import { assert, panic } from "../assertions.js";
2
2
  import { fetch } from "../fetch.js";
3
3
  import { permissionsSchema } from "./permissions.js";
4
- import { softrApiUrl } from "../softr-api.js";
4
+ import { sessionConfig } from "./config.js";
5
5
  import { softrConfig } from "../softr-config.js";
6
+ import { softrApiUrl } from "../softr-api.js";
6
7
  import { z } from "zod";
7
8
 
8
9
  //#region src/auth/platform.ts
@@ -307,7 +308,7 @@ function makePlatform(applicationId) {
307
308
  const errorSchema = z.object({ message: z.string() });
308
309
  async function request(path, init, schema, parse = (response$1) => response$1.json()) {
309
310
  assert(init.json === void 0 || init.form === void 0, "A platform request carries a JSON body or a form, not both");
310
- const response = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}${path}`, {
311
+ const response = await fetch(`${await platformApiUrl()}${path}`, {
311
312
  method: init.method,
312
313
  headers: {
313
314
  accept: "application/json",
@@ -333,6 +334,35 @@ async function request(path, init, schema, parse = (response$1) => response$1.js
333
334
  data: parsed.data
334
335
  };
335
336
  }
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
+ }
336
366
 
337
367
  //#endregion
338
- export { makePlatform };
368
+ export { makePlatform, platformApiUrl };
@@ -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 { softrApiUrl } from "../softr-api.js";
5
+ import { platformApiUrl } from "../auth/platform.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(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${encodeURIComponent(action.id)}/comments${path}`, {
81
+ return fetch(`${await platformApiUrl()}/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 { softrApiUrl } from "../softr-api.js";
4
+ import { platformApiUrl } from "../auth/platform.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 = softrApiUrl("SOFTR_PLATFORM_API_URL");
14
+ const baseUrl = await platformApiUrl();
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,11 +2,12 @@ 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";
5
6
 
6
7
  //#region src/core/workflow.ts
7
8
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
8
9
  async function triggerWorkflow(action, payload) {
9
- const triggerRes = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/workflow`, {
10
+ const triggerRes = await fetch(`${await platformApiUrl()}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/workflow`, {
10
11
  method: "POST",
11
12
  headers: {
12
13
  Authorization: `Bearer ${readSessionToken()}`,
@@ -1,4 +1,4 @@
1
- import * as react4 from "react";
1
+ import * as react6 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): react4.JSX.Element;
11
+ }: Props): react6.JSX.Element;
12
12
  //#endregion
13
13
  export { DefaultErrorOverlay };
@@ -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 { softrApiUrl } from "./softr-api.js";
5
+ import { platformApiUrl } from "./auth/platform.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(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${applicationId}/locale-settings`, { headers: { accept: "application/json" } });
45
+ const response = await fetch(`${await platformApiUrl()}/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.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_start5 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_start5.RequestMiddlewareAfterServer<{}, undefined, undefined>;
35
35
  //#endregion
36
36
  export { softrMcpMiddleware };
package/dist/mcp.js CHANGED
@@ -2,10 +2,9 @@ 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 { softrApiUrl } from "./softr-api.js";
6
- import { isDatasourceAction } from "./action.js";
7
5
  import { softrConfig } from "./softr-config.js";
8
- import { makePlatform } from "./auth/platform.js";
6
+ import { makePlatform, platformApiUrl } from "./auth/platform.js";
7
+ import { isDatasourceAction } from "./action.js";
9
8
  import { ds } from "./datasource/datasource.js";
10
9
  import { z } from "zod";
11
10
  import { createMiddleware } from "@tanstack/react-start";
@@ -147,7 +146,7 @@ const APPLICATION_ID_HEADER = "Softr-Application-ID";
147
146
  async function platformFetch(path, init) {
148
147
  const { applicationId } = sessionConfig();
149
148
  try {
150
- return await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}${path}`, {
149
+ return await fetch(`${await platformApiUrl()}${path}`, {
151
150
  method: init.method,
152
151
  headers: {
153
152
  accept: "application/json",
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.80-envvars.0";
2
+ var version = "0.0.80";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react5 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(): react5.FunctionComponentElement<react5.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
2
  import { fetch } from "./fetch.js";
3
3
  import { sessionConfig } from "./auth/config.js";
4
- import { softrApiUrl } from "./softr-api.js";
4
+ import { platformApiUrl } from "./auth/platform.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(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${applicationId}/pwa`, { headers: { accept: "application/json" } });
44
+ const response = await fetch(`${await platformApiUrl()}/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 { ACCESS_REASONS, checkRule } from "./visibility.js";
3
2
  import { softrConfig } from "../softr-config.js";
3
+ import { ACCESS_REASONS, checkRule } from "./visibility.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-envvars.0",
3
+ "version": "0.0.80",
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-envvars.0
11
+ library_version: 0.0.80
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-envvars.0
12
+ library_version: 0.0.80
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-envvars.0
12
+ library_version: 0.0.80
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-envvars.0
11
+ library_version: 0.0.80
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-envvars.0
12
+ library_version: 0.0.80
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-envvars.0
10
+ library_version: 0.0.80
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-envvars.0
11
+ library_version: 0.0.80
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-envvars.0
10
+ library_version: 0.0.80
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-envvars.0
12
+ library_version: 0.0.80
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-envvars.0
12
+ library_version: 0.0.80
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-envvars.0
11
+ library_version: 0.0.80
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-envvars.0
12
+ library_version: 0.0.80
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-envvars.0
12
+ library_version: 0.0.80
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-envvars.0
11
+ library_version: 0.0.80
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-envvars.0
12
+ library_version: 0.0.80
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.