@eetech-commerce/cart-react 0.4.3 → 0.4.4

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
@@ -1,5 +1,6 @@
1
1
  import * as _tanstack_react_query from '@tanstack/react-query';
2
2
  import { QueryClient } from '@tanstack/react-query';
3
+ import { loadStripe } from '@stripe/stripe-js';
3
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
  import react from 'react';
5
6
 
@@ -662,7 +663,16 @@ declare function useUpdateShippingSelections(): {
662
663
  error: Error | null;
663
664
  };
664
665
 
665
- declare function useStripePromise(): Promise<unknown> | null;
666
+ /**
667
+ * Type for the loadStripe function from @stripe/stripe-js
668
+ */
669
+ type LoadStripeFn = typeof loadStripe;
670
+ /**
671
+ * Hook to initialize Stripe with the tenant's publishable key.
672
+ * @param loadStripe - The loadStripe function from @stripe/stripe-js
673
+ * @returns A promise that resolves to the Stripe instance, or null if not ready
674
+ */
675
+ declare function useStripePromise(loadStripe: LoadStripeFn): ReturnType<LoadStripeFn> | null;
666
676
  declare function useCreateEmbeddedCheckoutSession(): {
667
677
  createEmbeddedCheckoutSession: (params: CreateEmbeddedPaymentSessionDto, callbacks?: MutationCallbacks<EmbeddedPaymentSessionResponseDto>) => void;
668
678
  isPending: boolean;
@@ -698,4 +708,4 @@ interface CartProviderProps {
698
708
  }
699
709
  declare function CartProvider({ children, tenantSlug, cartApiUrl, storageAdapter, autoInitialize, queryClient, }: CartProviderProps): react_jsx_runtime.JSX.Element;
700
710
 
701
- export { type CartContextValue, CartProvider, type CartProviderProps, type CartResponseDto, type CreateCheckoutDto, type CreateEmbeddedPaymentSessionDto, type EmbeddedPaymentSessionResponseDto, type LineItemResponseDto, type MutationCallbacks, type ShippingOptionDto, type ShippingSelectionDto, type StorageAdapter, type VerificationResultDto, cartKeys, localStorageAdapter, paymentKeys, shippingKeys, useAddToCart, useCart, useCartContext, useClearCart, useCreateCart, useCreateCheckoutSession, useCreateEmbeddedCheckoutSession, useInitializeCart, usePaymentSession, useRemoveItem, useShippingOptions, useStripePromise, useUpdateItemQty, useUpdateShippingSelections, useVerifyCart };
711
+ export { type CartContextValue, CartProvider, type CartProviderProps, type CartResponseDto, type CreateCheckoutDto, type CreateEmbeddedPaymentSessionDto, type EmbeddedPaymentSessionResponseDto, type LineItemResponseDto, type LoadStripeFn, type MutationCallbacks, type ShippingOptionDto, type ShippingSelectionDto, type StorageAdapter, type VerificationResultDto, cartKeys, localStorageAdapter, paymentKeys, shippingKeys, useAddToCart, useCart, useCartContext, useClearCart, useCreateCart, useCreateCheckoutSession, useCreateEmbeddedCheckoutSession, useInitializeCart, usePaymentSession, useRemoveItem, useShippingOptions, useStripePromise, useUpdateItemQty, useUpdateShippingSelections, useVerifyCart };
package/dist/index.js CHANGED
@@ -1,10 +1,3 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
1
  // src/adapters/localStorage.ts
9
2
  var localStorageAdapter = {
10
3
  get(key) {
@@ -1520,23 +1513,7 @@ function useUpdateShippingSelections() {
1520
1513
  // src/hooks/payment.ts
1521
1514
  import { useMutation as useMutation3, useQuery as useQuery3 } from "@tanstack/react-query";
1522
1515
  import { useCallback as useCallback3, useMemo } from "react";
1523
- var _loadStripe = null;
1524
- var _stripeLoadAttempted = false;
1525
- function getStripeLoader() {
1526
- if (_stripeLoadAttempted) {
1527
- return _loadStripe;
1528
- }
1529
- _stripeLoadAttempted = true;
1530
- try {
1531
- const { loadStripe } = __require("@stripe/stripe-js");
1532
- _loadStripe = loadStripe;
1533
- return _loadStripe;
1534
- } catch {
1535
- _loadStripe = null;
1536
- return null;
1537
- }
1538
- }
1539
- function useStripePromise() {
1516
+ function useStripePromise(loadStripe) {
1540
1517
  const { tenantSlug, cartApiUrl } = useCartContext();
1541
1518
  const { data: tenantPublicKey } = useQuery3({
1542
1519
  ...tenantPublicControllerGetPublicKeyV1Options({
@@ -1551,15 +1528,8 @@ function useStripePromise() {
1551
1528
  const stripePromise = useMemo(() => {
1552
1529
  const publishableKey = tenantPublicKey?.value;
1553
1530
  if (!publishableKey) return null;
1554
- const loadStripe = getStripeLoader();
1555
- if (!loadStripe) {
1556
- console.error(
1557
- "useStripePromise: @stripe/stripe-js is not installed. Install it with: npm install @stripe/stripe-js"
1558
- );
1559
- return null;
1560
- }
1561
1531
  return loadStripe(publishableKey);
1562
- }, [tenantPublicKey?.value]);
1532
+ }, [tenantPublicKey?.value, loadStripe]);
1563
1533
  return stripePromise;
1564
1534
  }
1565
1535
  function useCreateEmbeddedCheckoutSession() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eetech-commerce/cart-react",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -40,6 +40,7 @@
40
40
  "devDependencies": {
41
41
  "@hey-api/client-fetch": "^0.13.0",
42
42
  "@hey-api/openapi-ts": "0.87.5",
43
+ "@stripe/stripe-js": ">=2.0.0",
43
44
  "@testing-library/react": "^16.0.0",
44
45
  "@types/react": "^18.0.0",
45
46
  "@types/react-dom": "^18.0.0",