@base44-preview/sdk 0.8.46-pr.277.5cc15f3 → 0.8.46-pr.278.d5b4fe4

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/dist/client.js CHANGED
@@ -5,7 +5,6 @@ import { createAuthModule } from "./modules/auth.js";
5
5
  import { createSsoModule } from "./modules/sso.js";
6
6
  import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
7
7
  import { getAccessToken } from "./utils/auth-utils.js";
8
- import { createFetchWithAuth } from "./utils/fetch-with-auth.js";
9
8
  import { createFunctionsModule } from "./modules/functions.js";
10
9
  import { createAgentsModule } from "./modules/agents.js";
11
10
  import { createAiGatewayModule } from "./modules/ai-gateway.js";
@@ -261,8 +260,6 @@ export function createClient(config) {
261
260
  // Assemble and return the client
262
261
  const client = {
263
262
  ...userModules,
264
- /** See {@link Base44Client.fetchWithAuth}. */
265
- fetchWithAuth: createFetchWithAuth(axiosClient),
266
263
  /**
267
264
  * Sets a new authentication token for all subsequent requests.
268
265
  *
@@ -139,44 +139,6 @@ export interface Base44Client {
139
139
  integrations: IntegrationsModule;
140
140
  /** Cleanup function to disconnect WebSocket connections. Call when you're done with the client. */
141
141
  cleanup: () => void;
142
- /**
143
- * Calls one of your app's own server routes with the signed-in user's access token attached.
144
- *
145
- * Base44 keeps the user's access token in the browser's local storage, so a plain `fetch()` to your app's server routes arrives without it and the route sees an anonymous caller. `fetchWithAuth()` is the same `fetch()` with the `Authorization: Bearer <token>` header added, which is what lets a server route act on behalf of the signed-in user.
146
- *
147
- * Requests are restricted to your app's own origin so the token is never sent to a third party: pass a relative path beginning with a single `/`, such as `/api/orders`. An absolute URL, a protocol-relative `//host`, or anything else that a URL parser would read as another origin throws. To call a Base44 backend function, use {@linkcode FunctionsModule.fetch | functions.fetch()}; for another origin, use plain `fetch()`.
148
- *
149
- * The path is passed to `fetch` unchanged, so this also works in server code, where the runtime's `fetch` decides what a relative path means — a server-side client from {@linkcode createClientFromRequest | createClientFromRequest()} carries the caller's own token. Note that only the `Authorization` header is added: a route that builds its own client from the incoming request also needs the platform's `Base44-App-Id` and `Base44-Api-Url`, which a request you construct yourself does not have.
150
- *
151
- * When no user is signed in the request is sent without an `Authorization` header, so routes that allow anonymous access keep working.
152
- *
153
- * @param path - A relative path on your app's own origin, such as `/api/orders`.
154
- * @param init - Optional [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) options such as `method`, `headers`, `body`, and `signal`. The auth header is added automatically; an `Authorization` header you set yourself is kept.
155
- * @returns Promise resolving to a native [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
156
- * @throws {Error} When `path` is not a relative path on your app's own origin.
157
- *
158
- * @example
159
- * ```typescript
160
- * // Call your app's own server route as the signed-in user
161
- * const response = await base44.fetchWithAuth('/api/orders');
162
- * const orders = await response.json();
163
- * ```
164
- *
165
- * @example
166
- * ```typescript
167
- * // POST with a JSON body
168
- * const response = await base44.fetchWithAuth('/api/orders', {
169
- * method: 'POST',
170
- * headers: { 'Content-Type': 'application/json' },
171
- * body: JSON.stringify({ productId: 'abc', quantity: 2 }),
172
- * });
173
- *
174
- * if (!response.ok) {
175
- * throw new Error(`Request failed: ${response.status}`);
176
- * }
177
- * ```
178
- */
179
- fetchWithAuth(path: string, init?: RequestInit): Promise<Response>;
180
142
  /**
181
143
  * Sets a new authentication token for all subsequent requests.
182
144
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.46-pr.277.5cc15f3",
3
+ "version": "0.8.46-pr.278.d5b4fe4",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,12 +0,0 @@
1
- import type { AxiosInstance } from "axios";
2
- /**
3
- * Builds the client's `fetchWithAuth`: a `fetch` that attaches the signed-in
4
- * user's access token to a request for the app's own origin.
5
- *
6
- * @param axios - The user-scoped axios instance. Its `Authorization` default is
7
- * the live token: it follows `setToken()` and is deleted on `logout()`, so a
8
- * request never carries a token the user no longer has. In a server-side client
9
- * from `createClientFromRequest()` it holds the caller's own token.
10
- * @internal
11
- */
12
- export declare function createFetchWithAuth(axios: AxiosInstance): (path: string, init?: RequestInit) => Promise<Response>;
@@ -1,49 +0,0 @@
1
- /**
2
- * Builds the client's `fetchWithAuth`: a `fetch` that attaches the signed-in
3
- * user's access token to a request for the app's own origin.
4
- *
5
- * @param axios - The user-scoped axios instance. Its `Authorization` default is
6
- * the live token: it follows `setToken()` and is deleted on `logout()`, so a
7
- * request never carries a token the user no longer has. In a server-side client
8
- * from `createClientFromRequest()` it holds the caller's own token.
9
- * @internal
10
- */
11
- export function createFetchWithAuth(axios) {
12
- const currentToken = () => {
13
- const header = axios.defaults.headers.common["Authorization"];
14
- if (typeof header !== "string" || !header.startsWith("Bearer ")) {
15
- return null;
16
- }
17
- return header.slice("Bearer ".length) || null;
18
- };
19
- return async function fetchWithAuth(path, init = {}) {
20
- assertOwnOriginPath(path);
21
- const headers = new Headers(init.headers);
22
- const token = currentToken();
23
- if (token && !headers.has("Authorization")) {
24
- headers.set("Authorization", `Bearer ${token}`);
25
- }
26
- // Passed through untouched: resolving it here would need a document, and a
27
- // root-relative path is already what a runtime that dispatches in-process
28
- // (Nitro's `fetch`) expects.
29
- return fetch(path, { ...init, headers });
30
- };
31
- }
32
- function assertOwnOriginPath(path) {
33
- if (typeof path !== "string" || path === "") {
34
- throw new Error("fetchWithAuth() requires a path, such as '/api/orders'.");
35
- }
36
- // Check what a URL parser would see, not the raw string: it drops every ASCII
37
- // tab/newline anywhere in the input and trims leading C0/space, so
38
- // "/<tab>/evil.example" would pass a naive prefix check and then resolve to
39
- // another host.
40
- const asParsed = path.replace(/[\t\n\r]/g, "").replace(/^[\x00-\x20]+/, "");
41
- // One leading slash is the whole rule: it cannot carry a scheme, and it rules
42
- // out the two forms that reach another origin — "//host" and, since URL
43
- // parsing treats a backslash as a slash, "/\host".
44
- if (!asParsed.startsWith("/") ||
45
- asParsed.startsWith("//") ||
46
- asParsed.startsWith("/\\")) {
47
- throw new Error(`fetchWithAuth() only sends requests to your app's own origin, so the access token never reaches a third party. "${path}" is not a path on it — pass a relative path such as '/api/orders'. Use base44.functions.fetch() to call a Base44 backend function, or plain fetch() for another origin.`);
48
- }
49
- }