@base44-preview/sdk 0.8.55-pr.346.138d91a → 0.8.56-pr.347.bba12e2
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 +2 -1
- 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/dist/modules/payments.types.d.ts +36 -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
|
@@ -14,7 +14,8 @@ export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
|
14
14
|
export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from "./modules/app.types.js";
|
|
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
|
-
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";
|
|
17
|
+
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, 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";
|
|
@@ -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 {};
|
|
@@ -58,6 +58,36 @@ export interface CheckoutBuyer {
|
|
|
58
58
|
/** Buyer's phone number. */
|
|
59
59
|
phone?: string;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* A shipping address. Returned on a purchase whether your app or the provider collected it.
|
|
63
|
+
*/
|
|
64
|
+
export interface ShippingAddress {
|
|
65
|
+
/** Recipient's full name, 1 to 300 characters. */
|
|
66
|
+
name: string;
|
|
67
|
+
/** Street address, 1 to 300 characters. */
|
|
68
|
+
line1: string;
|
|
69
|
+
/** Apartment, suite or building, up to 300 characters. */
|
|
70
|
+
line2?: string | null;
|
|
71
|
+
/** City, up to 120 characters. Some countries address by region and postal code alone. */
|
|
72
|
+
city?: string | null;
|
|
73
|
+
/** State, province or region, up to 300 characters. */
|
|
74
|
+
region?: string | null;
|
|
75
|
+
/** Postal or ZIP code, up to 60 characters. */
|
|
76
|
+
postal_code?: string | null;
|
|
77
|
+
/** Two-letter ISO 3166-1 country code, such as `'US'`. */
|
|
78
|
+
country: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Shipping for a checkout with at least one `shippable` item. Supported for PayPal one-time checkouts only.
|
|
82
|
+
*
|
|
83
|
+
* Compute the fee on your server, never in the browser. When the fee depends on the address, such as by distance or zone, collect the address in your app and pass it in `address`: PayPal shows it to the buyer locked, so the order ships where the fee was computed for. When the fee doesn't depend on the address, pass only `amount` and PayPal asks the buyer for the address.
|
|
84
|
+
*/
|
|
85
|
+
export interface CheckoutShipping {
|
|
86
|
+
/** Address your app collected. Omit it to let the provider ask the buyer. */
|
|
87
|
+
address?: ShippingAddress;
|
|
88
|
+
/** Shipping fee in minor units, shown to the buyer as its own shipping line. Omit it for free shipping. */
|
|
89
|
+
amount?: number;
|
|
90
|
+
}
|
|
61
91
|
/**
|
|
62
92
|
* How the buyer pays.
|
|
63
93
|
*
|
|
@@ -85,6 +115,8 @@ export interface CreateCheckoutParams {
|
|
|
85
115
|
idempotency_key?: string;
|
|
86
116
|
/** How the buyer pays. Defaults to `'redirect'`. PayPal apps must pass `'embedded'`, and Wix Payments supports only `'redirect'`. */
|
|
87
117
|
presentation?: CheckoutPresentation;
|
|
118
|
+
/** Shipping address and fee. Allowed only when at least one item is `shippable`. Supported for PayPal one-time checkouts only; other providers and subscriptions reject it with `invalid_request`. */
|
|
119
|
+
shipping?: CheckoutShipping;
|
|
88
120
|
}
|
|
89
121
|
/**
|
|
90
122
|
* Data that Stripe Embedded Checkout needs to render.
|
|
@@ -184,6 +216,10 @@ export interface Purchase {
|
|
|
184
216
|
metadata?: Record<string, string> | null;
|
|
185
217
|
/** ID of the subscription, for recurring purchases. */
|
|
186
218
|
subscription_id?: string | null;
|
|
219
|
+
/** Where the order ships, whether your app or the provider collected the address. Always `null` unless you call with the service role. Save it on your order record. */
|
|
220
|
+
shipping_address?: ShippingAddress | null;
|
|
221
|
+
/** Shipping fee in minor units, when the checkout charged one. */
|
|
222
|
+
shipping_amount?: number | null;
|
|
187
223
|
/** ID of the payment to pass to [`refund()`](/developers/references/sdk/docs/interfaces/service-role-payments#refund). For a PayPal subscription it's the latest charge, returned only with the service role: read it when you start a refund and reuse it on retries. It's `null` where the provider doesn't name a payment, such as a PayPal subscription whose latest charge is already refunded. */
|
|
188
224
|
payment_id?: string | null;
|
|
189
225
|
}
|