@base44-preview/sdk 0.8.54-pr.344.ece486e → 0.8.55-pr.328.bc88e75
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 +2 -0
- package/dist/client.types.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/modules/auth.js +25 -12
- package/dist/modules/browser.d.ts +10 -0
- package/dist/modules/browser.js +42 -0
- package/dist/modules/browser.types.d.ts +130 -0
- package/dist/modules/browser.types.js +1 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createEntitiesModule } from "./modules/entities.js";
|
|
|
3
3
|
import { createIntegrationsModule } from "./modules/integrations.js";
|
|
4
4
|
import { createAuthModule } from "./modules/auth.js";
|
|
5
5
|
import { createSsoModule } from "./modules/sso.js";
|
|
6
|
+
import { createBrowserModule } from "./modules/browser.js";
|
|
6
7
|
import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
|
|
7
8
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
8
9
|
import { createFetchWithAuth } from "./utils/fetch-with-auth.js";
|
|
@@ -228,6 +229,7 @@ export function createClient(config) {
|
|
|
228
229
|
}),
|
|
229
230
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
230
231
|
sso: createSsoModule(serviceRoleAxiosClient, appId),
|
|
232
|
+
browser: createBrowserModule(serviceRoleAxiosClient),
|
|
231
233
|
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
|
|
232
234
|
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId, {
|
|
233
235
|
getAuthHeaders: () => {
|
package/dist/client.types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { EntitiesModule } from "./modules/entities.types.js";
|
|
|
2
2
|
import type { IntegrationsModule } from "./modules/integrations.types.js";
|
|
3
3
|
import type { AuthModule } from "./modules/auth.types.js";
|
|
4
4
|
import type { SsoModule } from "./modules/sso.types.js";
|
|
5
|
+
import type { BrowserModule } from "./modules/browser.types.js";
|
|
5
6
|
import type { PaymentsModule, ServiceRolePaymentsModule } from "./modules/payments.types.js";
|
|
6
7
|
import type { ConnectorsModule, UserConnectorsModule } from "./modules/connectors.types.js";
|
|
7
8
|
import type { FunctionsModule } from "./modules/functions.types.js";
|
|
@@ -228,6 +229,8 @@ export interface Base44Client {
|
|
|
228
229
|
aiGateway: AiGatewayModule;
|
|
229
230
|
/** {@link AppLogsModule | App logs module} with elevated permissions. */
|
|
230
231
|
appLogs: AppLogsModule;
|
|
232
|
+
/** {@link BrowserModule | Browser module} for remote browser sessions. */
|
|
233
|
+
browser: BrowserModule;
|
|
231
234
|
/** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
|
|
232
235
|
connectors: ConnectorsModule;
|
|
233
236
|
/** {@link EntitiesModule | Entities module} with elevated permissions. */
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from ".
|
|
|
15
15
|
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
16
16
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
17
17
|
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
|
|
18
|
+
export type { BrowserModule, BrowserSession, BrowserSessionOptions, } from "./modules/browser.types.js";
|
|
18
19
|
export { Actor, type Conn } from "./actor.js";
|
|
19
20
|
export type { ConnectorsModule, UserConnectorsModule, ConnectorApiRequest, ConnectorApiResponse, ConnectorApiResponsePhase, } from "./modules/connectors.types.js";
|
|
20
21
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
package/dist/modules/auth.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getAccessToken, removeAccessToken } from "../utils/auth-utils.js";
|
|
1
2
|
import { resetAnalyticsSessionContext } from "./analytics.js";
|
|
2
3
|
function isInsideIframe() {
|
|
3
4
|
if (typeof window === "undefined")
|
|
@@ -53,6 +54,21 @@ function loginViaPopup(url, redirectUrl, expectedOrigin) {
|
|
|
53
54
|
}, 500);
|
|
54
55
|
window.addEventListener("message", onMessage);
|
|
55
56
|
}
|
|
57
|
+
// "token" is the key the platform-v2 built-in SDK wrote.
|
|
58
|
+
function removeStoredAccessTokens() {
|
|
59
|
+
removeAccessToken({});
|
|
60
|
+
removeAccessToken({ storageKey: "token" });
|
|
61
|
+
}
|
|
62
|
+
const isStoredAccessToken = (authorization) => authorization ===
|
|
63
|
+
`Bearer ${getAccessToken({ saveToStorage: false, removeFromUrl: false })}`;
|
|
64
|
+
// A rejected token left in storage boots the next page with it, and an app
|
|
65
|
+
// whose own /login does that loops 401 → /login. A token stored since the
|
|
66
|
+
// request went out (a login in this or another tab) is not the rejected one.
|
|
67
|
+
function clearTokenOnRejection(error, sentAuthorization) {
|
|
68
|
+
if (error.status === 401 && isStoredAccessToken(sentAuthorization)) {
|
|
69
|
+
removeStoredAccessTokens();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
56
72
|
/**
|
|
57
73
|
* Creates the auth module for the Base44 SDK.
|
|
58
74
|
*
|
|
@@ -88,7 +104,14 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
88
104
|
},
|
|
89
105
|
// Get current user information
|
|
90
106
|
async me() {
|
|
91
|
-
const
|
|
107
|
+
const sentAuthorization = axios.defaults.headers.common["Authorization"];
|
|
108
|
+
const request = pendingMe !== null && pendingMe !== void 0 ? pendingMe : axios
|
|
109
|
+
.get(`/apps/${appId}/entities/User/me`)
|
|
110
|
+
.catch((error) => {
|
|
111
|
+
clearTokenOnRejection(error, sentAuthorization);
|
|
112
|
+
throw error;
|
|
113
|
+
})
|
|
114
|
+
.finally(() => {
|
|
92
115
|
// Only retire this request if it is still the shared one. An identity
|
|
93
116
|
// change mid-flight clears `pendingMe` and the next caller starts a
|
|
94
117
|
// fresh request; an unconditional clear here would retire that newer
|
|
@@ -154,17 +177,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
154
177
|
hasAccessToken = false;
|
|
155
178
|
// Only do the rest if in a browser environment
|
|
156
179
|
if (typeof window !== "undefined") {
|
|
157
|
-
|
|
158
|
-
if (window.localStorage) {
|
|
159
|
-
try {
|
|
160
|
-
window.localStorage.removeItem("base44_access_token");
|
|
161
|
-
// Remove "token" that is set by the built-in SDK of platform version 2
|
|
162
|
-
window.localStorage.removeItem("token");
|
|
163
|
-
}
|
|
164
|
-
catch (e) {
|
|
165
|
-
console.error("Failed to remove token from localStorage:", e);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
180
|
+
removeStoredAccessTokens();
|
|
168
181
|
// Determine the from_url parameter
|
|
169
182
|
const fromUrl = redirectUrl || window.location.href;
|
|
170
183
|
// Redirect to server-side logout endpoint to clear HTTP-only cookies
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { BrowserModule } from "./browser.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates the Browser module for the Base44 SDK.
|
|
5
|
+
*
|
|
6
|
+
* @param axios - Axios instance (should be service role client)
|
|
7
|
+
* @returns Browser module with methods to create and end remote browser sessions
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function createBrowserModule(axios: AxiosInstance): BrowserModule;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the Browser module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* @param axios - Axios instance (should be service role client)
|
|
5
|
+
* @returns Browser module with methods to create and end remote browser sessions
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export function createBrowserModule(axios) {
|
|
9
|
+
const endSession = async (sessionId) => {
|
|
10
|
+
if (!sessionId || typeof sessionId !== "string") {
|
|
11
|
+
throw new Error("Session ID is required and must be a string");
|
|
12
|
+
}
|
|
13
|
+
await axios.delete(`/v1/browser-sessions/${encodeURIComponent(sessionId)}`);
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
async getSession(options = {}) {
|
|
17
|
+
var _a;
|
|
18
|
+
// The app is derived from the service token, so the route isn't app-scoped.
|
|
19
|
+
const response = await axios.post("/v1/browser-sessions", {
|
|
20
|
+
capture_debug_artifacts: (_a = options.captureDebugArtifacts) !== null && _a !== void 0 ? _a : true,
|
|
21
|
+
// Omit when unset so the backend applies its configured default.
|
|
22
|
+
...(options.sessionTimeoutSeconds !== undefined && {
|
|
23
|
+
session_timeout_seconds: options.sessionTimeoutSeconds,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
const data = response;
|
|
27
|
+
return {
|
|
28
|
+
sessionId: data.session_id,
|
|
29
|
+
connectionUrl: data.connection_url,
|
|
30
|
+
connectionScope: data.connection_scope,
|
|
31
|
+
...(data.connection_expires_at && {
|
|
32
|
+
connectionExpiresAt: data.connection_expires_at,
|
|
33
|
+
}),
|
|
34
|
+
...(data.session_expires_at && {
|
|
35
|
+
sessionExpiresAt: data.session_expires_at,
|
|
36
|
+
}),
|
|
37
|
+
end: () => endSession(data.session_id),
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
endSession,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@linkcode BrowserModule.getSession | getSession()}.
|
|
3
|
+
*/
|
|
4
|
+
export interface BrowserSessionOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to capture browser recordings and diagnostic logs for the session.
|
|
7
|
+
*
|
|
8
|
+
* Captured artifacts stay with the remote browser provider and can't be retrieved through the SDK. Defaults to `true`.
|
|
9
|
+
*/
|
|
10
|
+
captureDebugArtifacts?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Maximum lifetime of the session, in whole seconds.
|
|
13
|
+
*
|
|
14
|
+
* The session ends when the timeout expires, even if it's still in use. Base44 sets minimum and maximum allowed values and clamps the timeout to that range. When omitted, Base44 applies a default timeout.
|
|
15
|
+
*/
|
|
16
|
+
sessionTimeoutSeconds?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A remote browser session returned by {@linkcode BrowserModule.getSession | getSession()}.
|
|
20
|
+
*/
|
|
21
|
+
export interface BrowserSession {
|
|
22
|
+
/**
|
|
23
|
+
* Opaque session identifier issued to your app.
|
|
24
|
+
*
|
|
25
|
+
* Pass it unchanged to {@linkcode BrowserModule.endSession | endSession()} to end the session from a different request.
|
|
26
|
+
*/
|
|
27
|
+
sessionId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Signed WebSocket URL for connecting to the browser over the Chrome DevTools Protocol (CDP).
|
|
30
|
+
*
|
|
31
|
+
* Treat the complete URL as a credential. Don't log it or send it to the frontend.
|
|
32
|
+
*/
|
|
33
|
+
connectionUrl: string;
|
|
34
|
+
/**
|
|
35
|
+
* Scope of the CDP connection.
|
|
36
|
+
*
|
|
37
|
+
* - `'browser'`: The socket controls the whole browser.
|
|
38
|
+
* - `'page'`: The socket controls a single page.
|
|
39
|
+
*/
|
|
40
|
+
connectionScope: "browser" | "page";
|
|
41
|
+
/** ISO 8601 timestamp when the connection URL expires. Omitted when the provider doesn't expose it. */
|
|
42
|
+
connectionExpiresAt?: string;
|
|
43
|
+
/** ISO 8601 timestamp when the browser session expires. Omitted when the provider doesn't expose it. */
|
|
44
|
+
sessionExpiresAt?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Ends the session. Equivalent to calling {@linkcode BrowserModule.endSession | endSession()} with this session's ID.
|
|
47
|
+
*/
|
|
48
|
+
end: () => Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Browser module for running browser automation from your backend.
|
|
52
|
+
*
|
|
53
|
+
* This module creates remote browser sessions that you can control with a CDP client library such as Playwright or Puppeteer. Base44 doesn't store browser state, so each session is independent. End each session when you're done with it. Otherwise it keeps running until its timeout expires. To change the timeout, pass the `sessionTimeoutSeconds` option to {@linkcode BrowserModule.getSession | getSession()}.
|
|
54
|
+
*
|
|
55
|
+
* This module is only available to use with a client in service role authentication mode, which means it can only be used in backend environments.
|
|
56
|
+
*/
|
|
57
|
+
export interface BrowserModule {
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new remote browser session and returns its connection details.
|
|
60
|
+
*
|
|
61
|
+
* Each call creates a fresh session. Calls aren't retried automatically, and repeating a failed call doesn't resume a previous session. Session creation is rate limited per app.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Optional session settings.
|
|
64
|
+
* @returns Promise resolving to the new browser session.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Open a page in a remote browser with Playwright
|
|
69
|
+
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
70
|
+
* import { chromium } from 'npm:playwright-core';
|
|
71
|
+
*
|
|
72
|
+
* Deno.serve(async (req) => {
|
|
73
|
+
* const base44 = createClientFromRequest(req);
|
|
74
|
+
* const session = await base44.asServiceRole.browser.getSession();
|
|
75
|
+
*
|
|
76
|
+
* try {
|
|
77
|
+
* const browser = await chromium.connectOverCDP(session.connectionUrl);
|
|
78
|
+
* const page = browser.contexts()[0]?.pages()[0] ?? (await browser.newPage());
|
|
79
|
+
* await page.goto('https://example.com');
|
|
80
|
+
* const title = await page.title();
|
|
81
|
+
* await browser.close();
|
|
82
|
+
*
|
|
83
|
+
* return Response.json({ title });
|
|
84
|
+
* } finally {
|
|
85
|
+
* await session.end();
|
|
86
|
+
* }
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Turn off recordings and diagnostic logs
|
|
93
|
+
* const session = await base44.asServiceRole.browser.getSession({
|
|
94
|
+
* captureDebugArtifacts: false,
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Request a custom session timeout
|
|
101
|
+
* const session = await base44.asServiceRole.browser.getSession({
|
|
102
|
+
* sessionTimeoutSeconds: 600,
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
getSession(options?: BrowserSessionOptions): Promise<BrowserSession>;
|
|
107
|
+
/**
|
|
108
|
+
* Ends a browser session created by your app.
|
|
109
|
+
*
|
|
110
|
+
* Use this when the session was created in a different request. Otherwise call `end()` on the session returned by {@linkcode getSession | getSession()}. Ending a session that has already ended succeeds, so it's safe to call more than once. The call fails with the `browser_session_not_found` error code if the ID wasn't issued to your app.
|
|
111
|
+
*
|
|
112
|
+
* @param sessionId - The `sessionId` returned by {@linkcode getSession | getSession()}, unchanged.
|
|
113
|
+
* @returns Promise that resolves when the session has ended.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // End a session whose ID was saved by an earlier request
|
|
118
|
+
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
119
|
+
*
|
|
120
|
+
* Deno.serve(async (req) => {
|
|
121
|
+
* const base44 = createClientFromRequest(req);
|
|
122
|
+
* const { sessionId } = await req.json();
|
|
123
|
+
* await base44.asServiceRole.browser.endSession(sessionId);
|
|
124
|
+
*
|
|
125
|
+
* return new Response(null, { status: 204 });
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
endSession(sessionId: string): Promise<void>;
|
|
130
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|