@betterstore/react 0.1.1 → 0.1.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - architecture redone
8
+
3
9
  ## 0.1.1
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,8 @@
1
+ import BetterStore from "@betterstore/sdk";
2
+ import React from "react";
3
+ declare function CheckoutEmbed({ betterStore, checkoutId, }: {
4
+ betterStore: InstanceType<typeof BetterStore>;
5
+ checkoutId: string;
6
+ }): React.JSX.Element;
7
+ declare const _default: React.MemoExoticComponent<typeof CheckoutEmbed>;
8
+ export default _default;
@@ -0,0 +1,3 @@
1
+ export { default as CheckoutEmbed } from "./checkout-embed";
2
+ export { default as PaymentElement } from "./payment-element";
3
+ export { useCheckout } from "./payment-element/useCheckout";
package/dist/index.cjs.js CHANGED
@@ -76,18 +76,38 @@ function CheckoutSummary({ lineItems, shipping, tax, currency, }) {
76
76
  React.createElement("span", { className: "text-2xl font-bold" }, formatPrice(total)))))));
77
77
  }
78
78
 
79
- function CheckoutEmbed(_a) {
80
- return __awaiter(this, arguments, void 0, function* ({ betterStore, checkoutId, }) {
81
- const checkout = yield betterStore.checkout.retrieve(checkoutId);
82
- if (!checkout) {
83
- return React.createElement("div", null, "Checkout not found");
79
+ function CheckoutEmbed({ betterStore, checkoutId, }) {
80
+ const [checkout, setCheckout] = React.useState(null);
81
+ const [loading, setLoading] = React.useState(true);
82
+ React.useEffect(() => {
83
+ function fetchCheckout() {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ try {
86
+ const data = yield betterStore.checkout.retrieve(checkoutId);
87
+ setCheckout(data);
88
+ }
89
+ catch (error) {
90
+ console.error("Failed to fetch checkout:", error);
91
+ }
92
+ finally {
93
+ setLoading(false);
94
+ }
95
+ });
84
96
  }
85
- return (React.createElement("div", { className: "grid md:grid-cols-2 gap-4" },
86
- React.createElement("div", null, "forms heres"),
87
- React.createElement("div", null,
88
- React.createElement(CheckoutSummary, { currency: checkout.currency, lineItems: checkout.lineItems, shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax }))));
89
- });
97
+ fetchCheckout();
98
+ }, [betterStore, checkoutId]);
99
+ if (loading) {
100
+ return React.createElement("div", null, "Loading...");
101
+ }
102
+ if (!checkout) {
103
+ return React.createElement("div", null, "Checkout not found");
104
+ }
105
+ return (React.createElement("div", { className: "grid md:grid-cols-2 gap-4" },
106
+ React.createElement("div", null, "forms here"),
107
+ React.createElement("div", null,
108
+ React.createElement(CheckoutSummary, { currency: checkout.currency, lineItems: checkout.lineItems, shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax }))));
90
109
  }
110
+ var index$1 = React.memo(CheckoutEmbed);
91
111
 
92
112
  function getDefaultExportFromCjs (x) {
93
113
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -2285,8 +2305,8 @@ function PaymentElement({ paymentSecret, checkoutAppearance, onSuccess, onError,
2285
2305
  return (React.createElement(Elements, { stripe: stripePromise, options: options },
2286
2306
  React.createElement(CheckoutForm$1, { onSuccess: onSuccess, onError: onError, children: children })));
2287
2307
  }
2288
- var paymentElement = React.memo(PaymentElement);
2308
+ var index = React.memo(PaymentElement);
2289
2309
 
2290
- exports.CheckoutEmbed = CheckoutEmbed;
2291
- exports.PaymentElement = paymentElement;
2310
+ exports.CheckoutEmbed = index$1;
2311
+ exports.PaymentElement = index;
2292
2312
  exports.useCheckout = useCheckout;
package/dist/index.d.ts CHANGED
@@ -1,3 +1 @@
1
- export { default as CheckoutEmbed } from "./checkout-embed";
2
- export { default as PaymentElement } from "./checkout/payment-element";
3
- export { useCheckout } from "./checkout/useCheckout";
1
+ export * from "./components";
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { memo, useState } from 'react';
1
+ import React, { memo, useState, useEffect } from 'react';
2
2
 
3
3
  /******************************************************************************
4
4
  Copyright (c) Microsoft Corporation.
@@ -74,18 +74,38 @@ function CheckoutSummary({ lineItems, shipping, tax, currency, }) {
74
74
  React.createElement("span", { className: "text-2xl font-bold" }, formatPrice(total)))))));
75
75
  }
76
76
 
77
- function CheckoutEmbed(_a) {
78
- return __awaiter(this, arguments, void 0, function* ({ betterStore, checkoutId, }) {
79
- const checkout = yield betterStore.checkout.retrieve(checkoutId);
80
- if (!checkout) {
81
- return React.createElement("div", null, "Checkout not found");
77
+ function CheckoutEmbed({ betterStore, checkoutId, }) {
78
+ const [checkout, setCheckout] = useState(null);
79
+ const [loading, setLoading] = useState(true);
80
+ useEffect(() => {
81
+ function fetchCheckout() {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ try {
84
+ const data = yield betterStore.checkout.retrieve(checkoutId);
85
+ setCheckout(data);
86
+ }
87
+ catch (error) {
88
+ console.error("Failed to fetch checkout:", error);
89
+ }
90
+ finally {
91
+ setLoading(false);
92
+ }
93
+ });
82
94
  }
83
- return (React.createElement("div", { className: "grid md:grid-cols-2 gap-4" },
84
- React.createElement("div", null, "forms heres"),
85
- React.createElement("div", null,
86
- React.createElement(CheckoutSummary, { currency: checkout.currency, lineItems: checkout.lineItems, shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax }))));
87
- });
95
+ fetchCheckout();
96
+ }, [betterStore, checkoutId]);
97
+ if (loading) {
98
+ return React.createElement("div", null, "Loading...");
99
+ }
100
+ if (!checkout) {
101
+ return React.createElement("div", null, "Checkout not found");
102
+ }
103
+ return (React.createElement("div", { className: "grid md:grid-cols-2 gap-4" },
104
+ React.createElement("div", null, "forms here"),
105
+ React.createElement("div", null,
106
+ React.createElement(CheckoutSummary, { currency: checkout.currency, lineItems: checkout.lineItems, shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax }))));
88
107
  }
108
+ var index$1 = memo(CheckoutEmbed);
89
109
 
90
110
  function getDefaultExportFromCjs (x) {
91
111
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -2283,6 +2303,6 @@ function PaymentElement({ paymentSecret, checkoutAppearance, onSuccess, onError,
2283
2303
  return (React.createElement(Elements, { stripe: stripePromise, options: options },
2284
2304
  React.createElement(CheckoutForm$1, { onSuccess: onSuccess, onError: onError, children: children })));
2285
2305
  }
2286
- var paymentElement = memo(PaymentElement);
2306
+ var index = memo(PaymentElement);
2287
2307
 
2288
- export { CheckoutEmbed, paymentElement as PaymentElement, useCheckout };
2308
+ export { index$1 as CheckoutEmbed, index as PaymentElement, useCheckout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/react",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -1,6 +0,0 @@
1
- import BetterStore from "@betterstore/sdk";
2
- import React from "react";
3
- export default function CheckoutEmbed({ betterStore, checkoutId, }: {
4
- betterStore: InstanceType<typeof BetterStore>;
5
- checkoutId: string;
6
- }): Promise<React.JSX.Element>;