@base44-preview/sdk 0.8.58-pr.368.f587f1e → 0.8.59-pr.361.4a9433a

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/index.d.ts CHANGED
@@ -14,7 +14,7 @@ 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, 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";
17
+ export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalCheckoutOnClick, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
18
18
  export type { BrowserModule, BrowserSession, BrowserSessionOptions, } from "./modules/browser.types.js";
19
19
  export { Actor, type Conn } from "./actor.js";
20
20
  export type { ConnectorsModule, UserConnectorsModule, ConnectorApiRequest, ConnectorApiResponse, ConnectorApiResponsePhase, } from "./modules/connectors.types.js";
@@ -193,7 +193,7 @@ export interface AgentsModuleConfig {
193
193
  *
194
194
  * This module is available to use with a client in all authentication modes:
195
195
  *
196
- * - **Anonymous or User authentication** (`base44.agents`): Access is scoped to the current user's permissions. Users must be authenticated to create and access conversations.
196
+ * - **Anonymous or User authentication** (`base44.agents`): Access is scoped to the current user's permissions. Users must be authenticated to create and access conversations. Each user can read and add messages only to conversations they created, even if the user is an admin.
197
197
  * - **Service role authentication** (`base44.asServiceRole.agents`): Operations are invoked with the service role for backend code that needs elevated permissions.
198
198
  *
199
199
  * ## Generated Types
@@ -202,15 +202,15 @@ export interface AgentsModuleConfig {
202
202
  */
203
203
  export interface AgentsModule {
204
204
  /**
205
- * Gets all conversations from all agents in the app.
205
+ * Gets the current user's conversations with all agents in the app.
206
206
  *
207
- * Retrieves all conversations. Use {@linkcode listConversations | listConversations()} to filter which conversations are returned, apply sorting, or paginate results. Use {@linkcode getConversation | getConversation()} to retrieve a specific conversation by ID.
207
+ * Retrieves every conversation the current user started, across all agents. Conversations that other users started aren't included, even if the user is an admin. Use {@linkcode listConversations | listConversations()} to filter which conversations are returned, apply sorting, or paginate results. Use {@linkcode getConversation | getConversation()} to retrieve a specific conversation by ID.
208
208
  *
209
209
  * @returns Promise resolving to an array of conversations.
210
210
  *
211
211
  * @example
212
212
  * ```typescript
213
- * // Get all conversations
213
+ * // Get the current user's conversations
214
214
  * const conversations = await base44.agents.getConversations();
215
215
  * console.log(`Total conversations: ${conversations.length}`);
216
216
  * ```
@@ -222,13 +222,15 @@ export interface AgentsModule {
222
222
  /**
223
223
  * Gets a specific conversation by ID.
224
224
  *
225
- * Retrieves a single conversation using its unique identifier. To retrieve
226
- * all conversations, use {@linkcode getConversations | getConversations()}. To filter, sort, or paginate conversations, use {@linkcode listConversations | listConversations()}.
225
+ * Retrieves a single conversation using its unique identifier. The conversation must belong to the current user. If another user created it, the request fails with a `403` error. If no conversation has that ID, the request fails with a `404` error. To retrieve
226
+ * all of the current user's conversations, use {@linkcode getConversations | getConversations()}. To filter, sort, or paginate conversations, use {@linkcode listConversations | listConversations()}.
227
227
  *
228
228
  * This function returns the complete stored conversation including full tool call results, even for large responses.
229
229
  *
230
+ * A user can access only their own conversations. Other users' conversations aren't available through this method.
231
+ *
230
232
  * @param conversationId - The unique identifier of the conversation.
231
- * @returns Promise resolving to the conversation, or undefined if not found.
233
+ * @returns Promise resolving to the conversation.
232
234
  *
233
235
  * @example
234
236
  * ```typescript
@@ -239,14 +241,14 @@ export interface AgentsModule {
239
241
  * }
240
242
  * ```
241
243
  *
242
- * @see {@linkcode getConversations | getConversations()} for retrieving all conversations
244
+ * @see {@linkcode getConversations | getConversations()} for retrieving all of the current user's conversations
243
245
  * @see {@linkcode listConversations | listConversations()} for filtering and sorting conversations
244
246
  */
245
247
  getConversation(conversationId: string): Promise<AgentConversation | undefined>;
246
248
  /**
247
- * Lists conversations with filtering, sorting, and pagination.
249
+ * Lists the current user's conversations with filtering, sorting, and pagination.
248
250
  *
249
- * Provides querying capabilities including filtering by fields, sorting, pagination, and field selection. For cases where you need all conversations without filtering, use {@linkcode getConversations | getConversations()}. To retrieve a specific conversation by ID, use {@linkcode getConversation | getConversation()}.
251
+ * Provides querying capabilities including filtering by fields, sorting, pagination, and field selection. Results only include conversations the current user created, even with a filter on `created_by_id`. For cases where you need all of the current user's conversations without filtering, use {@linkcode getConversations | getConversations()}. To retrieve a specific conversation by ID, use {@linkcode getConversation | getConversation()}.
250
252
  *
251
253
  * @param filterParams - Filter parameters for querying conversations.
252
254
  * @returns Promise resolving to an array of filtered conversations.
@@ -273,13 +275,15 @@ export interface AgentsModule {
273
275
  * });
274
276
  * ```
275
277
  *
276
- * @see {@linkcode getConversations | getConversations()} for retrieving all conversations without filtering
278
+ * @see {@linkcode getConversations | getConversations()} for retrieving all of the current user's conversations without filtering
277
279
  * @see {@linkcode getConversation | getConversation()} for retrieving a specific conversation by ID
278
280
  */
279
281
  listConversations(filterParams: ModelFilterParams): Promise<AgentConversation[]>;
280
282
  /**
281
283
  * Creates a new conversation with an agent.
282
284
  *
285
+ * The conversation belongs to the current user. Only that user can read it or add messages to it.
286
+ *
283
287
  * @param conversation - Conversation details including agent name and optional metadata.
284
288
  * @returns Promise resolving to the created conversation.
285
289
  *
@@ -301,9 +305,11 @@ export interface AgentsModule {
301
305
  /**
302
306
  * Adds a message to a conversation.
303
307
  *
304
- * Sends a message to the agent and updates the conversation. This method
308
+ * Sends a message to the agent and updates the conversation. You can only add messages to conversations the current user created. This method
305
309
  * also updates the realtime socket to notify any subscribers.
306
310
  *
311
+ * A user can add messages only to their own conversations. Other users' conversations aren't available through this method.
312
+ *
307
313
  * @param conversation - The conversation to add the message to.
308
314
  * @param message - The message to add.
309
315
  * @returns Promise resolving to the created message.
@@ -323,9 +329,11 @@ export interface AgentsModule {
323
329
  * Subscribes to realtime updates for a conversation.
324
330
  *
325
331
  * Establishes a WebSocket connection to receive instant updates when new
326
- * messages are added to the conversation. Returns an unsubscribe function
332
+ * messages are added to the conversation. You can only subscribe to conversations the current user created. Returns an unsubscribe function
327
333
  * to clean up the connection.
328
334
  *
335
+ * A user can subscribe only to their own conversations. Other users' conversations aren't available through this method.
336
+ *
329
337
  * <Note>
330
338
  * When receiving messages through this function, tool call data is truncated for efficiency. The `arguments_string` is limited to 500 characters and `results` to 50 characters. The complete tool call data is always saved in storage and can be retrieved by calling {@linkcode getConversation | getConversation()} after the message completes.
331
339
  * </Note>
@@ -45,7 +45,7 @@ export interface DeleteManyResult {
45
45
  export interface UpdateManyResult {
46
46
  /** Whether the operation was successful. */
47
47
  success: boolean;
48
- /** Number of entities that were updated. */
48
+ /** Number of entities that were updated. This includes records that already held the new values, because every update refreshes `updated_date`. */
49
49
  updated: number;
50
50
  /** Whether there are more entities matching the query that were not updated in this batch. When `true`, call `updateMany` again with the same query to update the next batch. */
51
51
  has_more: boolean;
@@ -777,6 +777,8 @@ export interface EntityHandler<T = any> {
777
777
  * records first and then updates them. Learn more about
778
778
  * [concurrent updates](/developers/backend/resources/entities/entity-schemas#concurrent-updates).
779
779
  *
780
+ * This method isn't available for the built-in `User` entity, and calling it fails with a 405 error.
781
+ *
780
782
  * To update a single record by ID, use {@linkcode update | update()} instead. To update
781
783
  * multiple specific records with different data each, use {@linkcode bulkUpdate | bulkUpdate()}.
782
784
  *
@@ -1017,8 +1019,19 @@ export interface EntityHandler<T = any> {
1017
1019
  *
1018
1020
  * You can update up to 500 records per request.
1019
1021
  *
1020
- * This isn't a transaction. Each record is written on its own, so if the call
1021
- * fails partway, the records already written stay written. Learn more about
1022
+ * This method isn't available for the built-in `User` entity, and calling it fails with a 405 error.
1023
+ *
1024
+ * This isn't a transaction. Before writing, the call validates each record and checks that:
1025
+ *
1026
+ * - The `id` matches an existing record that the entity's
1027
+ * [row-level security](/developers/backend/resources/entities/security#row-level-security-rls)
1028
+ * update rule lets you update.
1029
+ * - Each change passes the entity's
1030
+ * [field-level security](/developers/backend/resources/entities/security#field-level-security-fls)
1031
+ * write rules.
1032
+ * - The record matches the entity's schema.
1033
+ *
1034
+ * After validation, each record is updated independently. Learn more about
1022
1035
  * [concurrent updates](/developers/backend/resources/entities/entity-schemas#concurrent-updates).
1023
1036
  *
1024
1037
  * To apply the same update to all records matching a query, use
@@ -1,4 +1,4 @@
1
- import type { CheckoutElement, CheckoutMount, CompleteCheckoutResult, MountableCheckout, MountCheckoutOptions } from "./payments.types.js";
1
+ import type { CheckoutElement, CheckoutMount, CompleteCheckoutResult, MountableCheckout, MountCheckoutOptions, PayPalCheckoutOnClick, PayPalEmbeddedCheckout } from "./payments.types.js";
2
2
  /** @internal */
3
3
  export type LoadScript = (src: string) => Promise<void>;
4
4
  /**
@@ -8,11 +8,13 @@ export type LoadScript = (src: string) => Promise<void>;
8
8
  export interface PaymentsCheckoutConfig {
9
9
  paypal?: {
10
10
  script_url?: string;
11
+ button?: PayPalButtonConfig | null;
11
12
  };
12
13
  stripe?: {
13
14
  script_url?: string;
14
15
  };
15
16
  }
17
+ type PayPalButtonConfig = Pick<PayPalEmbeddedCheckout, "client_id" | "merchant_id" | "partner_attribution_id">;
16
18
  /** @internal */
17
19
  export interface MountCheckoutDeps {
18
20
  completeCheckout: (checkoutId: string) => Promise<CompleteCheckoutResult>;
@@ -33,4 +35,5 @@ export declare function preloadCheckout(provider: "paypal" | "stripe", deps: Pic
33
35
  * Mounts the embedded checkout that createCheckout() returned.
34
36
  * @internal
35
37
  */
36
- export declare function mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options: MountCheckoutOptions, deps: MountCheckoutDeps): Promise<CheckoutMount>;
38
+ export declare function mountCheckout(element: CheckoutElement, checkout: MountableCheckout | PayPalCheckoutOnClick, options: MountCheckoutOptions, deps: MountCheckoutDeps): Promise<CheckoutMount>;
39
+ export {};
@@ -103,6 +103,8 @@ function mountStripe(element, scriptUrl, embedded, deps) {
103
103
  activeStripeCheckout = null;
104
104
  checkout.destroy();
105
105
  },
106
+ // Stripe's own form has no single button to disable.
107
+ setDisabled: () => undefined,
106
108
  };
107
109
  activeStripeCheckout = handle;
108
110
  return handle;
@@ -110,7 +112,9 @@ function mountStripe(element, scriptUrl, embedded, deps) {
110
112
  stripeQueue = mount.catch(() => undefined);
111
113
  return mount;
112
114
  }
113
- async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, options, deps) {
115
+ async function mountPayPal(element, scriptUrl, currency, embedded,
116
+ // A created checkout's id, or what an on-click checkout calls inside the click to create one.
117
+ checkout, options, deps) {
114
118
  var _a;
115
119
  const paypal = await loadGlobal(scriptUrl, () => browserGlobals().paypal, deps.loadScript);
116
120
  if (typeof paypal.createInstance !== "function") {
@@ -142,6 +146,10 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
142
146
  }
143
147
  let destroyed = false;
144
148
  let completing = false;
149
+ // Set once a payment goes through: another click would create and charge a second order.
150
+ let paid = false;
151
+ let starting = false;
152
+ let checkoutId = typeof checkout === "string" ? checkout : undefined;
145
153
  // App callbacks run only while mounted, and their own errors never reach PayPal or onError.
146
154
  const notify = (callback) => {
147
155
  if (destroyed)
@@ -161,6 +169,8 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
161
169
  button.disabled = true;
162
170
  let result;
163
171
  try {
172
+ if (!checkoutId)
173
+ throw new Error("PayPal approved a checkout that wasn't created");
164
174
  // Runs even after destroy(), so an approved payment is still captured.
165
175
  result = await deps.completeCheckout(checkoutId);
166
176
  }
@@ -172,6 +182,7 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
172
182
  return;
173
183
  }
174
184
  completing = false;
185
+ paid = true;
175
186
  notify(() => { var _a; return (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options, result); });
176
187
  },
177
188
  onCancel() {
@@ -183,15 +194,26 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
183
194
  });
184
195
  button.setAttribute("type", subscription ? "subscribe" : "pay");
185
196
  const onClick = () => {
186
- if (completing)
197
+ if (paid || completing || starting || button.disabled)
187
198
  return;
199
+ starting = true;
188
200
  // Not awaited before start(), which must run inside the click to open PayPal's popup.
189
- const id = Promise.resolve(subscription ? { subscriptionId: checkoutId } : { orderId: checkoutId });
201
+ const id = Promise.resolve()
202
+ .then(typeof checkout === "string" ? () => checkout : checkout)
203
+ .then((resolved) => {
204
+ checkoutId = resolved;
205
+ return subscription ? { subscriptionId: resolved } : { orderId: resolved };
206
+ });
190
207
  const report = (error) => notify(() => { var _a; return (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error); });
191
208
  try {
192
- Promise.resolve(session.start({ presentationMode: "auto" }, id)).catch(report);
209
+ Promise.resolve(session.start({ presentationMode: "auto" }, id))
210
+ .catch(report)
211
+ .finally(() => {
212
+ starting = false;
213
+ });
193
214
  }
194
215
  catch (error) {
216
+ starting = false;
195
217
  report(error);
196
218
  }
197
219
  };
@@ -207,6 +229,26 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
207
229
  button.remove();
208
230
  (_a = session.destroy) === null || _a === void 0 ? void 0 : _a.call(session);
209
231
  },
232
+ setDisabled(disabled) {
233
+ // A payment being completed, or already made, keeps the button off whatever the app asks.
234
+ if (!completing && !paid)
235
+ button.disabled = disabled;
236
+ },
237
+ };
238
+ }
239
+ /** The new checkout's id, refused unless it is the checkout the button was drawn for. */
240
+ function onClickCheckoutId(spec, button) {
241
+ return async () => {
242
+ var _a;
243
+ const checkout = await spec.createCheckout();
244
+ const embedded = checkout === null || checkout === void 0 ? void 0 : checkout.embedded;
245
+ if ((embedded === null || embedded === void 0 ? void 0 : embedded.provider) !== "paypal" ||
246
+ embedded.intent !== spec.intent ||
247
+ embedded.merchant_id !== button.merchant_id ||
248
+ ((_a = checkout.currency) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== spec.currency.toLowerCase()) {
249
+ throw new Error("createCheckout() returned a checkout that doesn't match the PayPal button. Check its provider, intent and currency.");
250
+ }
251
+ return checkout.checkout_id;
210
252
  };
211
253
  }
212
254
  /**
@@ -237,6 +279,9 @@ export async function mountCheckout(element, checkout, options, deps) {
237
279
  if (!element) {
238
280
  throw new Error("mountCheckout() requires an element to render in");
239
281
  }
282
+ if ("createCheckout" in checkout) {
283
+ return mountPayPalOnClick(element, checkout, options, deps);
284
+ }
240
285
  const embedded = checkout === null || checkout === void 0 ? void 0 : checkout.embedded;
241
286
  if (!embedded) {
242
287
  throw new Error("This checkout isn't embedded. Create it with presentation: 'embedded', or send the buyer to its redirect_url.");
@@ -245,8 +290,21 @@ export async function mountCheckout(element, checkout, options, deps) {
245
290
  case "stripe":
246
291
  return mountStripe(element, await scriptUrlFor("stripe", deps), embedded, deps);
247
292
  case "paypal":
248
- return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.checkout_id, checkout.currency, embedded, options, deps);
293
+ return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.currency, embedded, checkout.checkout_id, options, deps);
249
294
  default:
250
295
  throw new Error(`Embedded checkout isn't supported for provider ${embedded.provider}`);
251
296
  }
252
297
  }
298
+ async function mountPayPalOnClick(element, spec, options, deps) {
299
+ var _a, _b;
300
+ if (spec.provider !== "paypal" || typeof spec.createCheckout !== "function") {
301
+ throw new Error("Only PayPal can create its checkout on click");
302
+ }
303
+ const scriptUrl = await scriptUrlFor("paypal", deps);
304
+ const button = (_b = (_a = (await deps.getConfig())) === null || _a === void 0 ? void 0 : _a.paypal) === null || _b === void 0 ? void 0 : _b.button;
305
+ if (!(button === null || button === void 0 ? void 0 : button.client_id) || !button.merchant_id) {
306
+ throw new Error("PayPal isn't ready to take payments in this app yet");
307
+ }
308
+ const embedded = { provider: "paypal", ...button, intent: spec.intent };
309
+ return mountPayPal(element, scriptUrl, spec.currency, embedded, onClickCheckoutId(spec, button), options, deps);
310
+ }
@@ -350,12 +350,29 @@ export interface MountableCheckout {
350
350
  /** Data for the embedded checkout. Mounting rejects when it's `null`. */
351
351
  embedded: EmbeddedCheckout | null;
352
352
  }
353
+ /**
354
+ * A PayPal checkout that [`mountCheckout()`](#mountcheckout) creates when the buyer clicks PayPal's button. The button shows as soon as the page loads, the buyer clicks once, and no order is created until they do.
355
+ */
356
+ export interface PayPalCheckoutOnClick {
357
+ /** Payment provider. Only PayPal can create its checkout on click. */
358
+ provider: "paypal";
359
+ /** Three-letter ISO currency code the checkout uses, such as `'usd'`. */
360
+ currency: string;
361
+ /** Whether the checkout is a one-time payment or a subscription. */
362
+ intent: "capture" | "subscription";
363
+ /**
364
+ * Creates the checkout when the buyer clicks, usually by calling the backend function that calls [`createCheckout()`](#createcheckout). Resolve with its result. It must be an embedded PayPal checkout with the same `currency` and `intent` you set here, or `onError` receives an error. Reject to stop, for example when a required form field is empty. PayPal's window then closes and `onError` receives the error.
365
+ */
366
+ createCheckout: () => Promise<MountableCheckout>;
367
+ }
353
368
  /**
354
369
  * A mounted embedded checkout.
355
370
  */
356
371
  export interface CheckoutMount {
357
372
  /** Removes the checkout from the page. Call it when the component that holds it unmounts. For Stripe, mounting another checkout destroys this one for you. */
358
373
  destroy: () => void;
374
+ /** Grays out PayPal's button and ignores clicks, for example until a required form is filled in. After a payment completes the button stays off, so `setDisabled(false)` can't start a second payment. Stripe ignores it. */
375
+ setDisabled: (disabled: boolean) => void;
359
376
  }
360
377
  /**
361
378
  * Payments module for accepting one-time payments and subscriptions in your app through its connected payment provider.
@@ -408,7 +425,7 @@ export interface PaymentsModule {
408
425
  /**
409
426
  * Renders an embedded checkout inside an element on the page.
410
427
  *
411
- * Pass the result of a {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()} call made with `presentation: 'embedded'`. Because only the service role can create checkouts, create it in a backend function and return the result to the page.
428
+ * Pass the result of a {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()} call made with `presentation: 'embedded'`. Because only the service role can create checkouts, create it in a backend function and return the result to the page. For PayPal, you can instead pass a {@linkcode PayPalCheckoutOnClick} to show the button before any checkout exists. The SDK creates the checkout only when the buyer clicks the button, so visitors who don't buy don't leave unused checkouts behind.
412
429
  *
413
430
  * The SDK loads the provider's library and renders the checkout for you:
414
431
  * - PayPal: Renders a PayPal button. When the buyer approves the payment, the SDK calls {@linkcode completeCheckout | completeCheckout()} and then `onComplete`.
@@ -416,12 +433,12 @@ export interface PaymentsModule {
416
433
  *
417
434
  * To make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.
418
435
  *
419
- * Requires a browser environment and can't be used in the backend. Rejects when the checkout isn't embedded, when the payments config can't be fetched or has no valid script URL for the provider, when the provider's library fails to load, or when PayPal isn't available for the checkout's currency.
436
+ * Requires a browser environment and can't be used in the backend. Rejects when the checkout isn't embedded, when an on-click PayPal checkout is mounted before the app's PayPal can take payments, when the payments config can't be fetched or has no valid script URL for the provider, when the provider's library fails to load, or when PayPal isn't available for the checkout's currency.
420
437
  *
421
438
  * The checkout's callbacks run in the buyer's browser, where they can be faked. Grant access to what the buyer paid for only after your backend confirms the purchase, for example with [`listPurchases()`](#service-role-methods) in a backend function.
422
439
  *
423
440
  * @param element - Element to render the checkout in. It should be empty.
424
- * @param checkout - The result of {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}.
441
+ * @param checkout - The result of {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}, or for PayPal a {@linkcode PayPalCheckoutOnClick} that creates it when the buyer clicks.
425
442
  * @param options - Callbacks for the checkout's outcome.
426
443
  * @returns Promise resolving to the mounted checkout once it renders.
427
444
  *
@@ -445,6 +462,25 @@ export interface PaymentsModule {
445
462
  * ```
446
463
  *
447
464
  * @example
465
+ * ```typescript
466
+ * // Create a PayPal checkout on click
467
+ * const mount = await base44.payments.mountCheckout(
468
+ * document.getElementById('paypal')!,
469
+ * {
470
+ * provider: 'paypal',
471
+ * currency: 'usd',
472
+ * intent: 'capture',
473
+ * createCheckout: async () =>
474
+ * (await base44.functions.invoke('createCheckout', { productId })).data,
475
+ * },
476
+ * { onComplete: ({ checkout_id }) => confirmPurchase(checkout_id) }
477
+ * );
478
+ *
479
+ * // Gray out the button until the shipping form is valid
480
+ * mount.setDisabled(!formIsValid);
481
+ * ```
482
+ *
483
+ * @example
448
484
  * ```tsx
449
485
  * // React component
450
486
  * function Checkout({ checkout }: { checkout: CreateCheckoutResult }) {
@@ -467,7 +503,7 @@ export interface PaymentsModule {
467
503
  * }
468
504
  * ```
469
505
  */
470
- mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options?: MountCheckoutOptions): Promise<CheckoutMount>;
506
+ mountCheckout(element: CheckoutElement, checkout: MountableCheckout | PayPalCheckoutOnClick, options?: MountCheckoutOptions): Promise<CheckoutMount>;
471
507
  /**
472
508
  * Completes a PayPal checkout after the buyer approves it.
473
509
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.58-pr.368.f587f1e",
3
+ "version": "0.8.59-pr.361.4a9433a",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",