@rebuy/rebuy-hydrogen 3.0.0-beta.6 → 3.0.0-beta.8
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.js +27 -19
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +27 -19
- package/dist/index.mjs.map +3 -3
- package/dist/providers/RebuyHydrogenContextProvider.d.ts +1 -1
- package/dist/providers/RebuyHydrogenContextProvider.d.ts.map +1 -1
- package/dist/providers/types.d.ts +6 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/types/rebuyCustom.d.ts +1 -0
- package/dist/types/rebuyCustom.d.ts.map +1 -1
- package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -1
- package/package.json +1 -19
package/dist/index.mjs
CHANGED
@@ -133,31 +133,31 @@ var getRebuyConfig = async (rebuyKey, storeDomain) => {
|
|
133
133
|
|
134
134
|
// src/providers/RebuyHydrogenContextProvider.tsx
|
135
135
|
import { jsx } from "react/jsx-runtime";
|
136
|
-
var PUBLIC_PRIMARY_DOMAIN = import.meta.env.PUBLIC_PRIMARY_DOMAIN;
|
137
|
-
var PUBLIC_REBUY_API_KEY = import.meta.env.PUBLIC_REBUY_API_KEY;
|
138
|
-
var PUBLIC_STORE_DOMAIN = import.meta.env.PUBLIC_STORE_DOMAIN;
|
139
136
|
var RebuyHydrogenContext = ({
|
137
|
+
apiKey,
|
140
138
|
cartAttributes,
|
141
139
|
cartCost,
|
142
140
|
cartId,
|
143
141
|
cartLines,
|
144
142
|
cartNote,
|
145
143
|
cartQuantity,
|
146
|
-
children
|
144
|
+
children,
|
145
|
+
publicStoreDomain,
|
146
|
+
shop
|
147
147
|
}) => {
|
148
148
|
const [rebuyConfig, setRebuyConfig] = useState(null);
|
149
149
|
const location = useLocation();
|
150
150
|
const queryObject = Utilities2.queryStringToObject(location.search);
|
151
|
-
const windowUrl = `${
|
151
|
+
const windowUrl = `${shop}${location.pathname}${location.search}`;
|
152
152
|
useEffect(() => {
|
153
153
|
const initConfig = async () => {
|
154
|
-
const config = await getRebuyConfig(
|
154
|
+
const config = await getRebuyConfig(apiKey, publicStoreDomain);
|
155
155
|
setRebuyConfig(config);
|
156
156
|
};
|
157
157
|
if (!rebuyConfig?.shop) {
|
158
158
|
initConfig();
|
159
159
|
}
|
160
|
-
}, [rebuyConfig
|
160
|
+
}, [rebuyConfig]);
|
161
161
|
const contextParameters = useMemo(
|
162
162
|
() => createContextParameters({
|
163
163
|
cacheKey: rebuyConfig?.shop?.cache_key,
|
@@ -181,18 +181,27 @@ var RebuyHydrogenContext = ({
|
|
181
181
|
);
|
182
182
|
return /* @__PURE__ */ jsx(RebuyContext.Provider, { value: contextValue, children });
|
183
183
|
};
|
184
|
-
var RebuyHydrogenContextProvider = ({
|
184
|
+
var RebuyHydrogenContextProvider = ({
|
185
|
+
apiKey,
|
186
|
+
cart,
|
187
|
+
children,
|
188
|
+
publicStoreDomain,
|
189
|
+
shop
|
190
|
+
}) => {
|
185
191
|
return /* @__PURE__ */ jsx(Await, { resolve: cart, children: (resolvedCart) => {
|
186
192
|
const cart2 = resolvedCart;
|
187
193
|
return /* @__PURE__ */ jsx(
|
188
194
|
RebuyHydrogenContext,
|
189
195
|
{
|
196
|
+
apiKey,
|
190
197
|
cartAttributes: cart2?.attributes,
|
191
198
|
cartCost: cart2?.cost?.subtotalAmount?.amount,
|
192
199
|
cartId: cart2?.id,
|
193
200
|
cartLines: cart2?.lines?.nodes,
|
194
201
|
cartNote: cart2?.note,
|
195
202
|
cartQuantity: cart2?.totalQuantity,
|
203
|
+
publicStoreDomain,
|
204
|
+
shop,
|
196
205
|
children
|
197
206
|
}
|
198
207
|
);
|
@@ -668,26 +677,26 @@ var CART_FRAGMENT = `#graphql
|
|
668
677
|
|
669
678
|
// src/providers/RebuyHydrogenReactContextProvider.tsx
|
670
679
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
671
|
-
var
|
672
|
-
var
|
673
|
-
var
|
680
|
+
var PUBLIC_PRIMARY_DOMAIN = import.meta.env.PUBLIC_PRIMARY_DOMAIN;
|
681
|
+
var PUBLIC_REBUY_API_KEY = import.meta.env.PUBLIC_REBUY_API_KEY;
|
682
|
+
var PUBLIC_STORE_DOMAIN = import.meta.env.PUBLIC_STORE_DOMAIN;
|
674
683
|
var PUBLIC_STOREFRONT_ID = import.meta.env.PUBLIC_STOREFRONT_ID;
|
675
684
|
var PUBLIC_STOREFRONT_API_TOKEN = import.meta.env.PUBLIC_STOREFRONT_API_TOKEN || "";
|
676
685
|
var RebuyHydrogenReactContext = ({ children }) => {
|
677
686
|
const [rebuyConfig, setRebuyConfig] = useState2(null);
|
678
687
|
const location = useLocation2();
|
679
688
|
const queryObject = Utilities3.queryStringToObject(location.search);
|
680
|
-
const windowUrl = `${
|
689
|
+
const windowUrl = `${PUBLIC_PRIMARY_DOMAIN}${location.pathname}${location.search}`;
|
681
690
|
const cart = useCart();
|
682
691
|
useEffect2(() => {
|
683
692
|
const initConfig = async () => {
|
684
|
-
const config = await getRebuyConfig(
|
693
|
+
const config = await getRebuyConfig(PUBLIC_REBUY_API_KEY, PUBLIC_STORE_DOMAIN);
|
685
694
|
setRebuyConfig(config);
|
686
695
|
};
|
687
696
|
if (!rebuyConfig?.shop) {
|
688
697
|
initConfig();
|
689
698
|
}
|
690
|
-
}, [rebuyConfig,
|
699
|
+
}, [rebuyConfig, PUBLIC_REBUY_API_KEY, PUBLIC_STORE_DOMAIN]);
|
691
700
|
const contextParameters = useMemo2(
|
692
701
|
() => createContextParameters({
|
693
702
|
cacheKey: rebuyConfig?.shop?.cache_key,
|
@@ -759,7 +768,7 @@ var RebuyHydrogenReactContextProvider = ({
|
|
759
768
|
{
|
760
769
|
countryIsoCode,
|
761
770
|
languageIsoCode,
|
762
|
-
storeDomain:
|
771
|
+
storeDomain: PUBLIC_STORE_DOMAIN,
|
763
772
|
storefrontApiVersion,
|
764
773
|
storefrontId: PUBLIC_STOREFRONT_ID,
|
765
774
|
storefrontToken: PUBLIC_STOREFRONT_API_TOKEN,
|
@@ -801,7 +810,7 @@ import * as Utilities4 from "@rebuy/rebuy/utilities";
|
|
801
810
|
import { flattenConnection } from "@shopify/hydrogen";
|
802
811
|
import React, { useContext, useEffect as useEffect3, useMemo as useMemo3, useState as useState3 } from "react";
|
803
812
|
var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
804
|
-
const { collection, collectionId, dataSource, limit, options, product, productId, variant, variantId } = props;
|
813
|
+
const { apiKey, collection, collectionId, dataSource, limit, options, product, productId, variant, variantId } = props;
|
805
814
|
const contextParameters = useContext(RebuyContext);
|
806
815
|
const [Rebuy, setRebuy] = useState3(null);
|
807
816
|
const [initialized, setInitialized] = useState3(false);
|
@@ -810,10 +819,9 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
|
810
819
|
const shopifyCollectionId = collection?.id ?? collectionId ?? null;
|
811
820
|
const [products, setProducts] = useState3([]);
|
812
821
|
const [metadata, setMetadata] = useState3();
|
813
|
-
const REBUY_API_KEY = import.meta.env.PUBLIC_REBUY_API_KEY;
|
814
822
|
useEffect3(() => {
|
815
823
|
if (!Rebuy) {
|
816
|
-
const client = new RebuyClient2(
|
824
|
+
const client = new RebuyClient2(apiKey);
|
817
825
|
client.setContextParameters(
|
818
826
|
contextParameters
|
819
827
|
// TODO: fix this type when @rebuy/rebuy is moved to typescript
|
@@ -824,7 +832,7 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
|
824
832
|
setRebuy(client);
|
825
833
|
setInitialized(true);
|
826
834
|
}
|
827
|
-
}, [
|
835
|
+
}, [apiKey, Rebuy, contextParameters, options]);
|
828
836
|
useEffect3(() => {
|
829
837
|
if (!Rebuy) return;
|
830
838
|
Rebuy.setContextParameters(
|