@base44-preview/sdk 0.8.46-pr.277.118e9c8 → 0.8.46-pr.278.85a6f80

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 path such as `/api/orders`, not a full URL. An absolute URL, a protocol-relative path, or anything else that resolves to another origin throws. To call a Base44 backend function, use {@linkcode FunctionsModule.fetch | functions.fetch()}; for another origin, use plain `fetch()`.
148
- *
149
- * When no user is signed in the request is sent without an `Authorization` header, so routes that allow anonymous access keep working.
150
- *
151
- * This method is browser-only. In server code, read the caller's token from the incoming request instead.
152
- *
153
- * @param path - A 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` resolves to a different origin, or when called outside the browser.
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.118e9c8",
3
+ "version": "0.8.46-pr.278.85a6f80",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,11 +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, restricted to 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.
9
- * @internal
10
- */
11
- export declare function createFetchWithAuth(axios: AxiosInstance): (path: string, init?: RequestInit) => Promise<Response>;
@@ -1,52 +0,0 @@
1
- /**
2
- * Builds the client's `fetchWithAuth`: a `fetch` that attaches the signed-in
3
- * user's access token, restricted to 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.
8
- * @internal
9
- */
10
- export function createFetchWithAuth(axios) {
11
- const currentToken = () => {
12
- const header = axios.defaults.headers.common["Authorization"];
13
- if (typeof header !== "string" || !header.startsWith("Bearer ")) {
14
- return null;
15
- }
16
- return header.slice("Bearer ".length) || null;
17
- };
18
- return async function fetchWithAuth(path, init = {}) {
19
- const url = resolveSameOriginUrl(path);
20
- const headers = new Headers(init.headers);
21
- const token = currentToken();
22
- if (token && !headers.has("Authorization")) {
23
- headers.set("Authorization", `Bearer ${token}`);
24
- }
25
- return fetch(url, { ...init, headers });
26
- };
27
- }
28
- function resolveSameOriginUrl(path) {
29
- if (typeof path !== "string" || path === "") {
30
- throw new Error("fetchWithAuth() requires a path, such as '/api/orders'.");
31
- }
32
- const location = typeof window !== "undefined" ? window.location : undefined;
33
- if (!(location === null || location === void 0 ? void 0 : location.href)) {
34
- throw new Error("fetchWithAuth() is only available in the browser. In server code, read the caller's token from the request instead — see createClientFromRequest().");
35
- }
36
- let pageUrl;
37
- let resolved;
38
- try {
39
- pageUrl = new URL(location.href);
40
- resolved = new URL(path, pageUrl);
41
- }
42
- catch (_a) {
43
- throw new Error(`fetchWithAuth() received an invalid path: "${path}".`);
44
- }
45
- // Resolving before comparing is what makes this safe: a protocol-relative
46
- // path ("//evil.example"), a backslash ("/\\evil.example") and an absolute URL
47
- // all land on another origin here, and are rejected the same way.
48
- if (resolved.origin !== pageUrl.origin) {
49
- throw new Error(`fetchWithAuth() only sends requests to your app's own origin, so the access token never reaches a third party. "${path}" resolves to ${resolved.origin}. Use base44.functions.fetch() to call a Base44 backend function, or plain fetch() for another origin.`);
50
- }
51
- return resolved.toString();
52
- }