@base44-preview/sdk 0.8.57-pr.355.b5f7fe5 → 0.8.57-pr.357.4227057

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.
@@ -24,6 +24,11 @@ export interface MountCheckoutDeps {
24
24
  * @internal
25
25
  */
26
26
  export declare const loadScript: LoadScript;
27
+ /**
28
+ * Fetches the payments config and loads the provider's script ahead of mountCheckout().
29
+ * @internal
30
+ */
31
+ export declare function preloadCheckout(provider: "paypal" | "stripe", deps: Pick<MountCheckoutDeps, "getConfig" | "loadScript">): Promise<void>;
27
32
  /**
28
33
  * Mounts the embedded checkout that createCheckout() returned.
29
34
  * @internal
@@ -209,6 +209,23 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
209
209
  },
210
210
  };
211
211
  }
212
+ /**
213
+ * Fetches the payments config and loads the provider's script ahead of mountCheckout().
214
+ * @internal
215
+ */
216
+ export async function preloadCheckout(provider, deps) {
217
+ if (typeof window === "undefined" || typeof document === "undefined")
218
+ return;
219
+ const read = () => (provider === "paypal" ? browserGlobals().paypal : browserGlobals().Stripe);
220
+ try {
221
+ if (!read()) {
222
+ await deps.loadScript(await scriptUrlFor(provider, deps));
223
+ }
224
+ }
225
+ catch (_a) {
226
+ // A hint only: mountCheckout() fetches and loads again and reports the failure.
227
+ }
228
+ }
212
229
  /**
213
230
  * Mounts the embedded checkout that createCheckout() returned.
214
231
  * @internal
@@ -1,4 +1,4 @@
1
- import { loadScript, mountCheckout, } from "./payments-checkout.js";
1
+ import { loadScript, mountCheckout, preloadCheckout, } from "./payments-checkout.js";
2
2
  function requireId(value, name) {
3
3
  if (!value || typeof value !== "string") {
4
4
  throw new Error(`${name} is required and must be a string`);
@@ -64,6 +64,9 @@ export function createPaymentsModule(axios, appId) {
64
64
  loadScript,
65
65
  });
66
66
  },
67
+ preloadCheckout(provider) {
68
+ return preloadCheckout(provider, { getConfig, loadScript });
69
+ },
67
70
  };
68
71
  }
69
72
  /**
@@ -492,6 +492,25 @@ export interface PaymentsModule {
492
492
  * ```
493
493
  */
494
494
  mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options?: MountCheckoutOptions): Promise<CheckoutMount>;
495
+ /**
496
+ * Loads the provider's checkout script before you mount a checkout.
497
+ *
498
+ * Call it when the checkout page or form opens, while the buyer is still filling it in. A later {@linkcode mountCheckout | mountCheckout()} then skips loading the script and renders sooner.
499
+ *
500
+ * It never rejects, so you don't need to await it or catch errors. If the script can't load, `mountCheckout()` tries again and rejects with the error. In the backend it does nothing.
501
+ *
502
+ * @param provider - The provider the app is connected to.
503
+ * @returns Promise resolving once the script has loaded or failed to load.
504
+ *
505
+ * @example
506
+ * ```tsx
507
+ * // Start loading PayPal when the checkout form opens
508
+ * useEffect(() => {
509
+ * base44.payments.preloadCheckout('paypal');
510
+ * }, []);
511
+ * ```
512
+ */
513
+ preloadCheckout(provider: "paypal" | "stripe"): Promise<void>;
495
514
  }
496
515
  /**
497
516
  * Payments module with service role authentication, for backend functions.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.57-pr.355.b5f7fe5",
3
+ "version": "0.8.57-pr.357.4227057",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",