@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.js
CHANGED
@@ -175,31 +175,31 @@ var getRebuyConfig = async (rebuyKey, storeDomain) => {
|
|
175
175
|
|
176
176
|
// src/providers/RebuyHydrogenContextProvider.tsx
|
177
177
|
var import_jsx_runtime = require("react/jsx-runtime");
|
178
|
-
var PUBLIC_PRIMARY_DOMAIN = process.env.PUBLIC_PRIMARY_DOMAIN;
|
179
|
-
var PUBLIC_REBUY_API_KEY = process.env.PUBLIC_REBUY_API_KEY;
|
180
|
-
var PUBLIC_STORE_DOMAIN = process.env.PUBLIC_STORE_DOMAIN;
|
181
178
|
var RebuyHydrogenContext = ({
|
179
|
+
apiKey,
|
182
180
|
cartAttributes,
|
183
181
|
cartCost,
|
184
182
|
cartId,
|
185
183
|
cartLines,
|
186
184
|
cartNote,
|
187
185
|
cartQuantity,
|
188
|
-
children
|
186
|
+
children,
|
187
|
+
publicStoreDomain,
|
188
|
+
shop
|
189
189
|
}) => {
|
190
190
|
const [rebuyConfig, setRebuyConfig] = (0, import_react3.useState)(null);
|
191
191
|
const location = (0, import_react2.useLocation)();
|
192
192
|
const queryObject = Utilities2.queryStringToObject(location.search);
|
193
|
-
const windowUrl = `${
|
193
|
+
const windowUrl = `${shop}${location.pathname}${location.search}`;
|
194
194
|
(0, import_react3.useEffect)(() => {
|
195
195
|
const initConfig = async () => {
|
196
|
-
const config = await getRebuyConfig(
|
196
|
+
const config = await getRebuyConfig(apiKey, publicStoreDomain);
|
197
197
|
setRebuyConfig(config);
|
198
198
|
};
|
199
199
|
if (!rebuyConfig?.shop) {
|
200
200
|
initConfig();
|
201
201
|
}
|
202
|
-
}, [rebuyConfig
|
202
|
+
}, [rebuyConfig]);
|
203
203
|
const contextParameters = (0, import_react3.useMemo)(
|
204
204
|
() => createContextParameters({
|
205
205
|
cacheKey: rebuyConfig?.shop?.cache_key,
|
@@ -223,18 +223,27 @@ var RebuyHydrogenContext = ({
|
|
223
223
|
);
|
224
224
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RebuyContext.Provider, { value: contextValue, children });
|
225
225
|
};
|
226
|
-
var RebuyHydrogenContextProvider = ({
|
226
|
+
var RebuyHydrogenContextProvider = ({
|
227
|
+
apiKey,
|
228
|
+
cart,
|
229
|
+
children,
|
230
|
+
publicStoreDomain,
|
231
|
+
shop
|
232
|
+
}) => {
|
227
233
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.Await, { resolve: cart, children: (resolvedCart) => {
|
228
234
|
const cart2 = resolvedCart;
|
229
235
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
230
236
|
RebuyHydrogenContext,
|
231
237
|
{
|
238
|
+
apiKey,
|
232
239
|
cartAttributes: cart2?.attributes,
|
233
240
|
cartCost: cart2?.cost?.subtotalAmount?.amount,
|
234
241
|
cartId: cart2?.id,
|
235
242
|
cartLines: cart2?.lines?.nodes,
|
236
243
|
cartNote: cart2?.note,
|
237
244
|
cartQuantity: cart2?.totalQuantity,
|
245
|
+
publicStoreDomain,
|
246
|
+
shop,
|
238
247
|
children
|
239
248
|
}
|
240
249
|
);
|
@@ -710,26 +719,26 @@ var CART_FRAGMENT = `#graphql
|
|
710
719
|
|
711
720
|
// src/providers/RebuyHydrogenReactContextProvider.tsx
|
712
721
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
713
|
-
var
|
714
|
-
var
|
715
|
-
var
|
722
|
+
var PUBLIC_PRIMARY_DOMAIN = process.env.PUBLIC_PRIMARY_DOMAIN;
|
723
|
+
var PUBLIC_REBUY_API_KEY = process.env.PUBLIC_REBUY_API_KEY;
|
724
|
+
var PUBLIC_STORE_DOMAIN = process.env.PUBLIC_STORE_DOMAIN;
|
716
725
|
var PUBLIC_STOREFRONT_ID = process.env.PUBLIC_STOREFRONT_ID;
|
717
726
|
var PUBLIC_STOREFRONT_API_TOKEN = process.env.PUBLIC_STOREFRONT_API_TOKEN || "";
|
718
727
|
var RebuyHydrogenReactContext = ({ children }) => {
|
719
728
|
const [rebuyConfig, setRebuyConfig] = (0, import_react5.useState)(null);
|
720
729
|
const location = (0, import_react4.useLocation)();
|
721
730
|
const queryObject = Utilities3.queryStringToObject(location.search);
|
722
|
-
const windowUrl = `${
|
731
|
+
const windowUrl = `${PUBLIC_PRIMARY_DOMAIN}${location.pathname}${location.search}`;
|
723
732
|
const cart = (0, import_hydrogen_react.useCart)();
|
724
733
|
(0, import_react5.useEffect)(() => {
|
725
734
|
const initConfig = async () => {
|
726
|
-
const config = await getRebuyConfig(
|
735
|
+
const config = await getRebuyConfig(PUBLIC_REBUY_API_KEY, PUBLIC_STORE_DOMAIN);
|
727
736
|
setRebuyConfig(config);
|
728
737
|
};
|
729
738
|
if (!rebuyConfig?.shop) {
|
730
739
|
initConfig();
|
731
740
|
}
|
732
|
-
}, [rebuyConfig,
|
741
|
+
}, [rebuyConfig, PUBLIC_REBUY_API_KEY, PUBLIC_STORE_DOMAIN]);
|
733
742
|
const contextParameters = (0, import_react5.useMemo)(
|
734
743
|
() => createContextParameters({
|
735
744
|
cacheKey: rebuyConfig?.shop?.cache_key,
|
@@ -801,7 +810,7 @@ var RebuyHydrogenReactContextProvider = ({
|
|
801
810
|
{
|
802
811
|
countryIsoCode,
|
803
812
|
languageIsoCode,
|
804
|
-
storeDomain:
|
813
|
+
storeDomain: PUBLIC_STORE_DOMAIN,
|
805
814
|
storefrontApiVersion,
|
806
815
|
storefrontId: PUBLIC_STOREFRONT_ID,
|
807
816
|
storefrontToken: PUBLIC_STOREFRONT_API_TOKEN,
|
@@ -843,7 +852,7 @@ var Utilities4 = __toESM(require("@rebuy/rebuy/utilities"), 1);
|
|
843
852
|
var import_hydrogen = require("@shopify/hydrogen");
|
844
853
|
var import_react6 = __toESM(require("react"), 1);
|
845
854
|
var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
846
|
-
const { collection, collectionId, dataSource, limit, options, product, productId, variant, variantId } = props;
|
855
|
+
const { apiKey, collection, collectionId, dataSource, limit, options, product, productId, variant, variantId } = props;
|
847
856
|
const contextParameters = (0, import_react6.useContext)(RebuyContext);
|
848
857
|
const [Rebuy, setRebuy] = (0, import_react6.useState)(null);
|
849
858
|
const [initialized, setInitialized] = (0, import_react6.useState)(false);
|
@@ -852,10 +861,9 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
|
852
861
|
const shopifyCollectionId = collection?.id ?? collectionId ?? null;
|
853
862
|
const [products, setProducts] = (0, import_react6.useState)([]);
|
854
863
|
const [metadata, setMetadata] = (0, import_react6.useState)();
|
855
|
-
const REBUY_API_KEY = process.env.PUBLIC_REBUY_API_KEY;
|
856
864
|
(0, import_react6.useEffect)(() => {
|
857
865
|
if (!Rebuy) {
|
858
|
-
const client = new import_rebuy2.RebuyClient(
|
866
|
+
const client = new import_rebuy2.RebuyClient(apiKey);
|
859
867
|
client.setContextParameters(
|
860
868
|
contextParameters
|
861
869
|
// TODO: fix this type when @rebuy/rebuy is moved to typescript
|
@@ -866,7 +874,7 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
|
|
866
874
|
setRebuy(client);
|
867
875
|
setInitialized(true);
|
868
876
|
}
|
869
|
-
}, [
|
877
|
+
}, [apiKey, Rebuy, contextParameters, options]);
|
870
878
|
(0, import_react6.useEffect)(() => {
|
871
879
|
if (!Rebuy) return;
|
872
880
|
Rebuy.setContextParameters(
|