Skip to content

Commit b5fe7ea

Browse files
committed
docs: add functions.fetch() JSDoc and fix external link stripping
Add @example blocks and improved descriptions for the fetch() method. Update invoke() to mention it uses POST and cross-reference fetch(). Fix removeNonExposedTypeLinks stripping external URLs (e.g. MDN links). Add functions method ordering to method-order.json. Made-with: Cursor
1 parent 27061fd commit b5fe7ea

3 files changed

Lines changed: 85 additions & 13 deletions

File tree

scripts/mintlify-post-processing/file-processing/file-processing.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,11 @@ function removeNonExposedTypeLinks(content, exposedTypeNames) {
18341834
const updatedContent = content.replace(
18351835
linkRegex,
18361836
(match, backtick, typeName, linkPath) => {
1837+
// Preserve external links (e.g. MDN docs) — only strip internal type refs
1838+
if (/^https?:\/\//.test(linkPath)) {
1839+
return match;
1840+
}
1841+
18371842
// Check if this looks like a type doc link (path ends with the type name)
18381843
const pathEnd = linkPath
18391844
.split("/")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"entities": [
3+
"get",
4+
"list",
5+
"filter",
6+
"create",
7+
"bulkCreate",
8+
"importEntities",
9+
"update",
10+
"updateMany",
11+
"bulkUpdate",
12+
"delete",
13+
"deleteMany",
14+
"subscribe"
15+
],
16+
"functions": [
17+
"invoke",
18+
"fetch"
19+
]
20+
}

src/modules/functions.types.ts

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export type FunctionName = keyof FunctionNameRegistry extends never
2020
/**
2121
* Options for {@linkcode FunctionsModule.fetch}.
2222
*
23-
* Uses native `fetch` options directly.
23+
* Alias of the native [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) type.
24+
* Any option accepted by the browser `fetch` API is valid (`method`, `headers`, `body`, `signal`, etc.).
25+
* Auth headers are merged in automatically; you do not need to set them.
2426
*/
2527
export type FunctionsFetchInit = RequestInit;
2628

@@ -53,11 +55,13 @@ export interface FunctionsModule {
5355
/**
5456
* Invokes a custom backend function by name.
5557
*
56-
* Calls a custom backend function deployed to the app.
58+
* Sends a POST request to a custom backend function deployed to the app.
5759
* The function receives the provided data as named parameters and returns
5860
* the result. If any parameter is a `File` object, the request will automatically be
5961
* sent as `multipart/form-data`. Otherwise, it will be sent as JSON.
6062
*
63+
* For streaming responses, non-POST methods, or raw response access, use {@linkcode fetch | fetch()} instead.
64+
*
6165
* @param functionName - The name of the function to invoke.
6266
* @param data - An object containing named parameters for the function.
6367
* @returns Promise resolving to the function's response. The `data` property contains the data returned by the function, if there is any.
@@ -91,19 +95,62 @@ export interface FunctionsModule {
9195
/**
9296
* Performs a direct HTTP request to a backend function path and returns the native `Response`.
9397
*
94-
* Use this method when you need low-level control over the request/response that the higher-level
95-
* `invoke()` abstraction doesn't provide, such as:
96-
* - Streaming responses (SSE, chunked text, NDJSON)
97-
* - Custom HTTP methods (PUT, PATCH, DELETE, etc.)
98-
* - Custom headers or request configuration
99-
* - Access to raw response metadata (status, headers)
100-
* - Direct control over request/response bodies
98+
* Use `fetch()` when you need low-level control that {@linkcode invoke | invoke()} doesn't provide, such as:
99+
* - Streaming responses, like SSE, chunked text, or NDJSON
100+
* - Custom HTTP methods, like PUT, PATCH, or DELETE
101+
* - Raw response access, including status codes, headers, and binary bodies
102+
*
103+
* @param path - Function path. Leading slash is optional, so `/chat` and `chat` are equivalent. For example, `'/streaming_demo'` or `'reports/export'`.
104+
* @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.
105+
* @returns Promise resolving to a native [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
106+
*
107+
* @example
108+
* ```typescript
109+
* // Stream an SSE response
110+
* const response = await base44.functions.fetch('/chat', {
111+
* method: 'POST',
112+
* headers: { 'Content-Type': 'application/json' },
113+
* body: JSON.stringify({ prompt: 'Hello!' }),
114+
* });
115+
*
116+
* const reader = response.body!.getReader();
117+
* const decoder = new TextDecoder();
101118
*
102-
* Requests are sent to `/api/functions/<path>`.
119+
* while (true) {
120+
* const { done, value } = await reader.read();
121+
* if (done) break;
122+
* console.log(decoder.decode(value, { stream: true }));
123+
* }
124+
* ```
103125
*
104-
* @param path - Function path, e.g. `/streaming_demo` or `/streaming_demo/deep/path`
105-
* @param init - Native fetch options.
106-
* @returns Promise resolving to a native fetch `Response`
126+
* @example
127+
* ```typescript
128+
* // PUT request
129+
* const response = await base44.functions.fetch('/users/profile', {
130+
* method: 'PUT',
131+
* headers: { 'Content-Type': 'application/json' },
132+
* body: JSON.stringify({ name: 'Jane', role: 'admin' }),
133+
* });
134+
*
135+
* if (!response.ok) {
136+
* throw new Error(`Request failed: ${response.status}`);
137+
* }
138+
*
139+
* const updated = await response.json();
140+
* ```
141+
*
142+
* @example
143+
* ```typescript
144+
* // Download a binary file
145+
* const response = await base44.functions.fetch('/export/report');
146+
* const blob = await response.blob();
147+
*
148+
* const url = URL.createObjectURL(blob);
149+
* const a = document.createElement('a');
150+
* a.href = url;
151+
* a.download = 'report.pdf';
152+
* a.click();
153+
* ```
107154
*/
108155
fetch(path: string, init?: FunctionsFetchInit): Promise<Response>;
109156
}

0 commit comments

Comments
 (0)