@base44-preview/sdk 0.8.22-pr.144.d5f4c16 → 0.8.22-pr.146.a67f1ad

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.
@@ -17,7 +17,9 @@ export type FunctionName = keyof FunctionNameRegistry extends never ? string : k
17
17
  /**
18
18
  * Options for {@linkcode FunctionsModule.fetch}.
19
19
  *
20
- * Uses native `fetch` options directly.
20
+ * Alias of the native [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) type.
21
+ * Any option accepted by the browser `fetch` API is valid (`method`, `headers`, `body`, `signal`, etc.).
22
+ * Auth headers are merged in automatically; you do not need to set them.
21
23
  */
22
24
  export type FunctionsFetchInit = RequestInit;
23
25
  /**
@@ -48,11 +50,13 @@ export interface FunctionsModule {
48
50
  /**
49
51
  * Invokes a custom backend function by name.
50
52
  *
51
- * Calls a custom backend function deployed to the app.
53
+ * Sends a POST request to a custom backend function deployed to the app.
52
54
  * The function receives the provided data as named parameters and returns
53
55
  * the result. If any parameter is a `File` object, the request will automatically be
54
56
  * sent as `multipart/form-data`. Otherwise, it will be sent as JSON.
55
57
  *
58
+ * For streaming responses, non-POST methods, or raw response access, use {@linkcode fetch | fetch()} instead.
59
+ *
56
60
  * @param functionName - The name of the function to invoke.
57
61
  * @param data - An object containing named parameters for the function.
58
62
  * @returns Promise resolving to the function's response. The `data` property contains the data returned by the function, if there is any.
@@ -85,19 +89,62 @@ export interface FunctionsModule {
85
89
  /**
86
90
  * Performs a direct HTTP request to a backend function path and returns the native `Response`.
87
91
  *
88
- * Use this method when you need low-level control over the request/response that the higher-level
89
- * `invoke()` abstraction doesn't provide, such as:
90
- * - Streaming responses (SSE, chunked text, NDJSON)
91
- * - Custom HTTP methods (PUT, PATCH, DELETE, etc.)
92
- * - Custom headers or request configuration
93
- * - Access to raw response metadata (status, headers)
94
- * - Direct control over request/response bodies
92
+ * Use `fetch()` when you need low-level control that {@linkcode invoke | invoke()} doesn't provide, such as:
93
+ * - Streaming responses, like SSE, chunked text, or NDJSON
94
+ * - Custom HTTP methods, like PUT, PATCH, or DELETE
95
+ * - Raw response access, including status codes, headers, and binary bodies
96
+ *
97
+ * @param path - Function path. Leading slash is optional, so `/chat` and `chat` are equivalent. For example, `'/streaming_demo'` or `'reports/export'`.
98
+ * @param init - Optional [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) options such as `method`, `headers`, `body`, and `signal`. Auth headers are added automatically.
99
+ * @returns Promise resolving to a native [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // Stream an SSE response
104
+ * const response = await base44.functions.fetch('/chat', {
105
+ * method: 'POST',
106
+ * headers: { 'Content-Type': 'application/json' },
107
+ * body: JSON.stringify({ prompt: 'Hello!' }),
108
+ * });
109
+ *
110
+ * const reader = response.body!.getReader();
111
+ * const decoder = new TextDecoder();
95
112
  *
96
- * Requests are sent to `/api/functions/<path>`.
113
+ * while (true) {
114
+ * const { done, value } = await reader.read();
115
+ * if (done) break;
116
+ * console.log(decoder.decode(value, { stream: true }));
117
+ * }
118
+ * ```
97
119
  *
98
- * @param path - Function path, e.g. `/streaming_demo` or `/streaming_demo/deep/path`
99
- * @param init - Native fetch options.
100
- * @returns Promise resolving to a native fetch `Response`
120
+ * @example
121
+ * ```typescript
122
+ * // PUT request
123
+ * const response = await base44.functions.fetch('/users/profile', {
124
+ * method: 'PUT',
125
+ * headers: { 'Content-Type': 'application/json' },
126
+ * body: JSON.stringify({ name: 'Jane', role: 'admin' }),
127
+ * });
128
+ *
129
+ * if (!response.ok) {
130
+ * throw new Error(`Request failed: ${response.status}`);
131
+ * }
132
+ *
133
+ * const updated = await response.json();
134
+ * ```
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Download a binary file
139
+ * const response = await base44.functions.fetch('/export/report');
140
+ * const blob = await response.blob();
141
+ *
142
+ * const url = URL.createObjectURL(blob);
143
+ * const a = document.createElement('a');
144
+ * a.href = url;
145
+ * a.download = 'report.pdf';
146
+ * a.click();
147
+ * ```
101
148
  */
102
149
  fetch(path: string, init?: FunctionsFetchInit): Promise<Response>;
103
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.22-pr.144.d5f4c16",
3
+ "version": "0.8.22-pr.146.a67f1ad",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",