@base44/sdk
Advanced tools
+6
-2
@@ -95,5 +95,9 @@ import { createAxiosClient } from "./utils/axios-client.js"; | ||
| }); | ||
| const serviceRoleHeaders = { | ||
| ...headers, | ||
| ...(token ? { "on-behalf-of": `Bearer ${token}` } : {}), | ||
| }; | ||
| const serviceRoleAxiosClient = createAxiosClient({ | ||
| baseURL: `${serverUrl}/api`, | ||
| headers, | ||
| headers: serviceRoleHeaders, | ||
| token: serviceToken, | ||
@@ -162,3 +166,3 @@ onError: options === null || options === void 0 ? void 0 : options.onError, | ||
| integrations: createIntegrationsModule(serviceRoleAxiosClient, appId), | ||
| sso: createSsoModule(serviceRoleAxiosClient, appId, token), | ||
| sso: createSsoModule(serviceRoleAxiosClient, appId), | ||
| connectors: createConnectorsModule(serviceRoleAxiosClient, appId), | ||
@@ -165,0 +169,0 @@ functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId, { |
@@ -36,2 +36,10 @@ /** | ||
| }, | ||
| async getCurrentAppUserAccessToken(connectorId) { | ||
| if (!connectorId || typeof connectorId !== "string") { | ||
| throw new Error("Connector ID is required and must be a string"); | ||
| } | ||
| const response = await axios.get(`/apps/${appId}/app-user-auth/connectors/${connectorId}/token`); | ||
| const data = response; | ||
| return data.access_token; | ||
| }, | ||
| }; | ||
@@ -49,10 +57,2 @@ } | ||
| return { | ||
| async getCurrentAppUserAccessToken(connectorId) { | ||
| if (!connectorId || typeof connectorId !== "string") { | ||
| throw new Error("Connector ID is required and must be a string"); | ||
| } | ||
| const response = await axios.get(`/apps/${appId}/app-user-auth/connectors/${connectorId}/token`); | ||
| const data = response; | ||
| return data.access_token; | ||
| }, | ||
| async connectAppUser(connectorId) { | ||
@@ -59,0 +59,0 @@ if (!connectorId || typeof connectorId !== "string") { |
@@ -226,16 +226,2 @@ /** | ||
| getConnection(integrationType: ConnectorIntegrationType): Promise<ConnectorConnectionResponse>; | ||
| } | ||
| /** | ||
| * User-scoped connectors module for managing app-user OAuth connections. | ||
| * | ||
| * This module provides methods for app-user OAuth flows: initiating an OAuth connection, | ||
| * retrieving the end user's access token, and disconnecting the end user's connection. | ||
| * | ||
| * Unlike {@link ConnectorsModule | ConnectorsModule} which manages app-scoped tokens, | ||
| * this module manages tokens scoped to individual end users. Methods are keyed on | ||
| * the connector ID (the OrgConnector's database ID) rather than the integration type. | ||
| * | ||
| * Available via `base44.connectors`. | ||
| */ | ||
| export interface UserConnectorsModule { | ||
| /** | ||
@@ -253,3 +239,3 @@ * Retrieves an OAuth access token for an end user's connection to a specific connector. | ||
| * // Get the end user's access token for a connector | ||
| * const token = await base44.connectors.getCurrentAppUserAccessToken('abc123def'); | ||
| * const token = await base44.asServiceRole.connectors.getCurrentAppUserAccessToken('abc123def'); | ||
| * | ||
@@ -262,2 +248,16 @@ * const response = await fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', { | ||
| getCurrentAppUserAccessToken(connectorId: string): Promise<string>; | ||
| } | ||
| /** | ||
| * User-scoped connectors module for managing app-user OAuth connections. | ||
| * | ||
| * This module provides methods for app-user OAuth flows: initiating an OAuth connection, | ||
| * retrieving the end user's access token, and disconnecting the end user's connection. | ||
| * | ||
| * Unlike {@link ConnectorsModule | ConnectorsModule} which manages app-scoped tokens, | ||
| * this module manages tokens scoped to individual end users. Methods are keyed on | ||
| * the connector ID (the OrgConnector's database ID) rather than the integration type. | ||
| * | ||
| * Available via `base44.connectors`. | ||
| */ | ||
| export interface UserConnectorsModule { | ||
| /** | ||
@@ -264,0 +264,0 @@ * Initiates the app-user OAuth flow for a specific connector. |
@@ -43,3 +43,3 @@ /** | ||
| /** | ||
| * Result returned when updating multiple entities via a query. | ||
| * Result returned when updating multiple entities using a query. | ||
| */ | ||
@@ -283,2 +283,7 @@ export interface UpdateManyResult { | ||
| * | ||
| * To update a single record by ID, use this method. To apply the same | ||
| * update to many records matching a query, use {@linkcode updateMany | updateMany()}. | ||
| * To update multiple specific records with different data each, use | ||
| * {@linkcode bulkUpdate | bulkUpdate()}. | ||
| * | ||
| * @param id - The unique identifier of the record to update. | ||
@@ -365,19 +370,28 @@ * @param data - Object containing the fields to update. | ||
| /** | ||
| * Updates multiple records matching a query using a MongoDB update operator. | ||
| * Applies the same update to all records that match a query. | ||
| * | ||
| * Applies the same update operation to all records matching the query. | ||
| * The `data` parameter must contain one or more MongoDB update operators | ||
| * (e.g., `$set`, `$inc`, `$push`). Multiple operators can be combined in a | ||
| * single call, but each field may only appear in one operator. | ||
| * Use this when you need to make the same change across all records that | ||
| * match specific criteria. For example, you could set every completed order | ||
| * to "archived", or increment a counter on all active users. | ||
| * | ||
| * Results are batched in groups of up to 500 — when `has_more` is `true` | ||
| * Results are batched in groups of up to 500. When `has_more` is `true` | ||
| * in the response, call `updateMany` again with the same query to update | ||
| * the next batch. | ||
| * the next batch. Make sure the query excludes already-updated records | ||
| * so you don't re-process the same entities on each iteration. For | ||
| * example, filter by `status: 'pending'` when setting status to `'processed'`. | ||
| * | ||
| * @param query - Query object to filter which records to update. Records matching all | ||
| * specified criteria will be updated. | ||
| * @param data - Update operation object containing one or more MongoDB update operators. | ||
| * To update a single record by ID, use {@linkcode update | update()} instead. To update | ||
| * multiple specific records with different data each, use {@linkcode bulkUpdate | bulkUpdate()}. | ||
| * | ||
| * @param query - Query object to filter which records to update. Use field-value | ||
| * pairs for exact matches, or | ||
| * [MongoDB query operators](https://www.mongodb.com/docs/manual/reference/operator/query/) | ||
| * for advanced filtering. Supported query operators include `$eq`, `$ne`, `$gt`, | ||
| * `$gte`, `$lt`, `$lte`, `$in`, `$nin`, `$and`, `$or`, `$not`, `$nor`, | ||
| * `$exists`, `$regex`, `$all`, `$elemMatch`, and `$size`. | ||
| * @param data - Update operation object containing one or more | ||
| * [MongoDB update operators](https://www.mongodb.com/docs/manual/reference/operator/update/). | ||
| * Each field may only appear in one operator per call. | ||
| * Supported operators: `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`, | ||
| * `$currentDate`, `$addToSet`, `$push`, `$pull`. | ||
| * Supported update operators include `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`, | ||
| * `$currentDate`, `$addToSet`, `$push`, and `$pull`. | ||
| * @returns Promise resolving to the update result. | ||
@@ -387,4 +401,5 @@ * | ||
| * ```typescript | ||
| * // Set status to 'archived' for all completed records | ||
| * const result = await base44.entities.MyEntity.updateMany( | ||
| * // Basic usage | ||
| * // Archive all completed orders | ||
| * const result = await base44.entities.Order.updateMany( | ||
| * { status: 'completed' }, | ||
@@ -398,4 +413,15 @@ * { $set: { status: 'archived' } } | ||
| * ```typescript | ||
| * // Combine multiple operators in a single call | ||
| * const result = await base44.entities.MyEntity.updateMany( | ||
| * // Multiple query operators | ||
| * // Flag urgent items that haven't been handled yet | ||
| * const result = await base44.entities.Task.updateMany( | ||
| * { priority: { $in: ['high', 'critical'] }, status: { $ne: 'done' } }, | ||
| * { $set: { flagged: true } } | ||
| * ); | ||
| * ``` | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // Multiple update operators | ||
| * // Close out sales records and bump the view count | ||
| * const result = await base44.entities.Deal.updateMany( | ||
| * { category: 'sales' }, | ||
@@ -408,7 +434,10 @@ * { $set: { status: 'done' }, $inc: { view_count: 1 } } | ||
| * ```typescript | ||
| * // Handle batched updates for large datasets | ||
| * // Batched updates | ||
| * // Process all pending items in batches of 500. | ||
| * // The query filters by 'pending', so updated records (now 'processed') | ||
| * // are automatically excluded from the next batch. | ||
| * let hasMore = true; | ||
| * let totalUpdated = 0; | ||
| * while (hasMore) { | ||
| * const result = await base44.entities.MyEntity.updateMany( | ||
| * const result = await base44.entities.Job.updateMany( | ||
| * { status: 'pending' }, | ||
@@ -424,23 +453,38 @@ * { $set: { status: 'processed' } } | ||
| /** | ||
| * Updates multiple records in a single request, each with its own update data. | ||
| * Updates the specified records in a single request, each with its own data. | ||
| * | ||
| * Unlike `updateMany` which applies the same update to all matching records, | ||
| * `bulkUpdate` allows different updates for each record. Each item in the | ||
| * array must include an `id` field identifying which record to update. | ||
| * Use this when you already know which records to update and each one needs | ||
| * different field values. For example, you could update the status and amount | ||
| * on three separate invoices in one call. | ||
| * | ||
| * **Note:** Maximum 500 items per request. | ||
| * You can update up to 500 records per request. | ||
| * | ||
| * @param data - Array of update objects (max 500). Each object must have an `id` field | ||
| * and any number of fields to update. | ||
| * @returns Promise resolving to an array of updated records. | ||
| * To apply the same update to all records matching a query, use | ||
| * {@linkcode updateMany | updateMany()}. To update a single record by ID, use | ||
| * {@linkcode update | update()}. | ||
| * | ||
| * @param data - Array of objects to update. Each object must contain an `id` field identifying which record to update and any fields to change. | ||
| * @returns Promise resolving to an array of the updated records. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // Update multiple records with different data | ||
| * const updated = await base44.entities.MyEntity.bulkUpdate([ | ||
| * { id: 'entity-1', status: 'paid', amount: 999 }, | ||
| * { id: 'entity-2', status: 'cancelled' }, | ||
| * { id: 'entity-3', name: 'Renamed Item' } | ||
| * // Basic usage | ||
| * // Update three invoices with different statuses and amounts | ||
| * const updated = await base44.entities.Invoice.bulkUpdate([ | ||
| * { id: 'inv-1', status: 'paid', amount: 999 }, | ||
| * { id: 'inv-2', status: 'cancelled' }, | ||
| * { id: 'inv-3', amount: 450 } | ||
| * ]); | ||
| * ``` | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // More than 500 items | ||
| * // Reassign each task to a different owner in batches | ||
| * const allUpdates = reassignments.map(r => ({ id: r.taskId, owner: r.newOwner })); | ||
| * for (let i = 0; i < allUpdates.length; i += 500) { | ||
| * const batch = allUpdates.slice(i, i + 500); | ||
| * await base44.entities.Task.bulkUpdate(batch); | ||
| * } | ||
| * ``` | ||
| */ | ||
@@ -447,0 +491,0 @@ bulkUpdate(data: (Partial<T> & { |
@@ -20,3 +20,5 @@ /** | ||
| * | ||
| * Uses native `fetch` options directly. | ||
| * Alias of the native [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) type. | ||
| * Any option accepted by the browser `fetch` API is valid (`method`, `headers`, `body`, `signal`, etc.). | ||
| * Auth headers are merged in automatically; you do not need to set them. | ||
| */ | ||
@@ -52,3 +54,3 @@ export type FunctionsFetchInit = RequestInit; | ||
| * | ||
| * Calls a custom backend function deployed to the app. | ||
| * Sends a POST request to a custom backend function deployed to the app. | ||
| * The function receives the provided data as named parameters and returns | ||
@@ -58,2 +60,4 @@ * the result. If any parameter is a `File` object, the request will automatically be | ||
| * | ||
| * For streaming responses, non-POST methods, or raw response access, use {@linkcode fetch | fetch()} instead. | ||
| * | ||
| * @param functionName - The name of the function to invoke. | ||
@@ -91,17 +95,60 @@ * @param data - An object containing named parameters for the function. | ||
| * | ||
| * Use this method when you need low-level control over the request/response that the higher-level | ||
| * `invoke()` abstraction doesn't provide, such as: | ||
| * - Streaming responses (SSE, chunked text, NDJSON) | ||
| * - Custom HTTP methods (PUT, PATCH, DELETE, etc.) | ||
| * - Custom headers or request configuration | ||
| * - Access to raw response metadata (status, headers) | ||
| * - Direct control over request/response bodies | ||
| * Use `fetch()` when you need low-level control that {@linkcode invoke | invoke()} doesn't provide, such as: | ||
| * - Streaming responses, like SSE, chunked text, or NDJSON | ||
| * - Custom HTTP methods, like PUT, PATCH, or DELETE | ||
| * - Raw response access, including status codes, headers, and binary bodies | ||
| * | ||
| * Requests are sent to `/api/functions/<path>`. | ||
| * @param path - Function path. Leading slash is optional, so `/chat` and `chat` are equivalent. For example, `'/streaming_demo'` or `'reports/export'`. | ||
| * @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. | ||
| * @returns Promise resolving to a native [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response). | ||
| * | ||
| * @param path - Function path, e.g. `/streaming_demo` or `/streaming_demo/deep/path` | ||
| * @param init - Native fetch options. | ||
| * @returns Promise resolving to a native fetch `Response` | ||
| * @example | ||
| * ```typescript | ||
| * // Stream an SSE response | ||
| * const response = await base44.functions.fetch('/chat', { | ||
| * method: 'POST', | ||
| * headers: { 'Content-Type': 'application/json' }, | ||
| * body: JSON.stringify({ prompt: 'Hello!' }), | ||
| * }); | ||
| * | ||
| * const reader = response.body!.getReader(); | ||
| * const decoder = new TextDecoder(); | ||
| * | ||
| * while (true) { | ||
| * const { done, value } = await reader.read(); | ||
| * if (done) break; | ||
| * console.log(decoder.decode(value, { stream: true })); | ||
| * } | ||
| * ``` | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // PUT request | ||
| * const response = await base44.functions.fetch('/users/profile', { | ||
| * method: 'PUT', | ||
| * headers: { 'Content-Type': 'application/json' }, | ||
| * body: JSON.stringify({ name: 'Jane', role: 'admin' }), | ||
| * }); | ||
| * | ||
| * if (!response.ok) { | ||
| * throw new Error(`Request failed: ${response.status}`); | ||
| * } | ||
| * | ||
| * const updated = await response.json(); | ||
| * ``` | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // Download a binary file | ||
| * const response = await base44.functions.fetch('/export/report'); | ||
| * const blob = await response.blob(); | ||
| * | ||
| * const url = URL.createObjectURL(blob); | ||
| * const a = document.createElement('a'); | ||
| * a.href = url; | ||
| * a.download = 'report.pdf'; | ||
| * a.click(); | ||
| * ``` | ||
| */ | ||
| fetch(path: string, init?: FunctionsFetchInit): Promise<Response>; | ||
| } |
@@ -12,2 +12,2 @@ import { AxiosInstance } from "axios"; | ||
| */ | ||
| export declare function createSsoModule(axios: AxiosInstance, appId: string, userToken?: string): SsoModule; | ||
| export declare function createSsoModule(axios: AxiosInstance, appId: string): SsoModule; |
@@ -10,3 +10,3 @@ /** | ||
| */ | ||
| export function createSsoModule(axios, appId, userToken) { | ||
| export function createSsoModule(axios, appId) { | ||
| return { | ||
@@ -16,10 +16,5 @@ // Get SSO access token for a specific user | ||
| const url = `/apps/${appId}/auth/sso/accesstoken/${userid}`; | ||
| // Prepare headers with both tokens if available | ||
| const headers = {}; | ||
| if (userToken) { | ||
| headers["on-behalf-of"] = `Bearer ${userToken}`; | ||
| } | ||
| return axios.get(url, { headers }); | ||
| return axios.get(url); | ||
| }, | ||
| }; | ||
| } |
+1
-1
| { | ||
| "name": "@base44/sdk", | ||
| "version": "0.8.22", | ||
| "version": "0.8.23", | ||
| "description": "JavaScript SDK for Base44 API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
222627
1.82%5622
1.63%12
9.09%22
22.22%