@nosto/nosto-react 0.2.1 → 0.4.0

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.
@@ -1,9 +1,12 @@
1
- import * as React from "react";
2
- import React__default, { createContext, useContext, useEffect } from "react";
1
+ import React, { createContext, useContext, useEffect, useRef, useMemo, isValidElement, useState } from "react";
2
+ import { createRoot } from "react-dom/client";
3
3
  const NostoContext = createContext({
4
- account: void 0,
4
+ account: "",
5
5
  currentVariation: "",
6
- renderFunction: void 0
6
+ pageType: "",
7
+ responseMode: "HTML",
8
+ clientScriptLoaded: false,
9
+ useRenderCampaigns: () => void 0
7
10
  });
8
11
  function useNostoContext() {
9
12
  const context = useContext(NostoContext);
@@ -23,7 +26,7 @@ var reactJsxRuntime_production_min = {};
23
26
  * This source code is licensed under the MIT license found in the
24
27
  * LICENSE file in the root directory of this source tree.
25
28
  */
26
- var f = React__default, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
29
+ var f = React, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
27
30
  function q(c, a, g) {
28
31
  var b, d = {}, e = null, h = null;
29
32
  void 0 !== g && (e = "" + g);
@@ -45,26 +48,27 @@ reactJsxRuntime_production_min.jsxs = q;
45
48
  const jsx = jsxRuntime.exports.jsx;
46
49
  const jsxs = jsxRuntime.exports.jsxs;
47
50
  const Fragment = jsxRuntime.exports.Fragment;
48
- const NostoFohofo = () => {
51
+ function Nosto404() {
49
52
  const {
50
53
  clientScriptLoaded,
51
54
  currentVariation,
52
- renderFunction,
53
- responseMode
55
+ responseMode,
56
+ recommendationComponent,
57
+ useRenderCampaigns
54
58
  } = useNostoContext();
59
+ const {
60
+ renderCampaigns,
61
+ pageTypeUpdated
62
+ } = useRenderCampaigns("404");
55
63
  useEffect(() => {
56
- if (clientScriptLoaded) {
64
+ if (clientScriptLoaded && pageTypeUpdated) {
57
65
  window.nostojs((api) => {
58
66
  api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewNotFound().setPlacements(api.placements.getPlacements()).load().then((data) => {
59
- if (responseMode == "HTML") {
60
- api.placements.injectCampaigns(data.recommendations);
61
- } else {
62
- renderFunction(data.campaigns);
63
- }
67
+ renderCampaigns(data, api);
64
68
  });
65
69
  });
66
70
  }
67
- }, [clientScriptLoaded, currentVariation, renderFunction]);
71
+ }, [clientScriptLoaded, currentVariation, recommendationComponent, pageTypeUpdated]);
68
72
  return /* @__PURE__ */ jsx(Fragment, {
69
73
  children: /* @__PURE__ */ jsx("div", {
70
74
  className: "nosto_page_type",
@@ -74,27 +78,28 @@ const NostoFohofo = () => {
74
78
  children: "notfound"
75
79
  })
76
80
  });
77
- };
78
- const NostoOther = () => {
81
+ }
82
+ function NostoOther() {
79
83
  const {
80
84
  clientScriptLoaded,
81
85
  currentVariation,
82
- renderFunction,
83
- responseMode
86
+ responseMode,
87
+ recommendationComponent,
88
+ useRenderCampaigns
84
89
  } = useNostoContext();
90
+ const {
91
+ renderCampaigns,
92
+ pageTypeUpdated
93
+ } = useRenderCampaigns("other");
85
94
  useEffect(() => {
86
- if (clientScriptLoaded) {
95
+ if (clientScriptLoaded && pageTypeUpdated) {
87
96
  window.nostojs((api) => {
88
97
  api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewOther().setPlacements(api.placements.getPlacements()).load().then((data) => {
89
- if (responseMode == "HTML") {
90
- api.placements.injectCampaigns(data.recommendations);
91
- } else {
92
- renderFunction(data.campaigns);
93
- }
98
+ renderCampaigns(data, api);
94
99
  });
95
100
  });
96
101
  }
97
- }, [clientScriptLoaded, currentVariation, renderFunction]);
102
+ }, [clientScriptLoaded, currentVariation, recommendationComponent, pageTypeUpdated]);
98
103
  return /* @__PURE__ */ jsx(Fragment, {
99
104
  children: /* @__PURE__ */ jsx("div", {
100
105
  className: "nosto_page_type",
@@ -104,27 +109,28 @@ const NostoOther = () => {
104
109
  children: "other"
105
110
  })
106
111
  });
107
- };
108
- const NostoCheckout = () => {
112
+ }
113
+ function NostoCheckout() {
109
114
  const {
110
115
  clientScriptLoaded,
111
116
  currentVariation,
112
- renderFunction,
113
- responseMode
117
+ responseMode,
118
+ recommendationComponent,
119
+ useRenderCampaigns
114
120
  } = useNostoContext();
121
+ const {
122
+ renderCampaigns,
123
+ pageTypeUpdated
124
+ } = useRenderCampaigns("checkout");
115
125
  useEffect(() => {
116
- if (clientScriptLoaded) {
126
+ if (clientScriptLoaded && pageTypeUpdated) {
117
127
  window.nostojs((api) => {
118
128
  api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCart().setPlacements(api.placements.getPlacements()).load().then((data) => {
119
- if (responseMode == "HTML") {
120
- api.placements.injectCampaigns(data.recommendations);
121
- } else {
122
- renderFunction(data.campaigns);
123
- }
129
+ renderCampaigns(data, api);
124
130
  });
125
131
  });
126
132
  }
127
- }, [clientScriptLoaded, currentVariation, renderFunction]);
133
+ }, [clientScriptLoaded, currentVariation, recommendationComponent, pageTypeUpdated]);
128
134
  return /* @__PURE__ */ jsx(Fragment, {
129
135
  children: /* @__PURE__ */ jsx("div", {
130
136
  className: "nosto_page_type",
@@ -134,30 +140,81 @@ const NostoCheckout = () => {
134
140
  children: "cart"
135
141
  })
136
142
  });
137
- };
138
- const NostoProduct = ({
139
- product,
140
- tagging
141
- }) => {
143
+ }
144
+ function isPlainObject(value) {
145
+ const isObject = (v) => String(v) === "[object Object]";
146
+ if (!isObject(value))
147
+ return false;
148
+ const constructor = value.constructor;
149
+ if (constructor === void 0)
150
+ return true;
151
+ const prototype = constructor.prototype;
152
+ if (!isObject(prototype))
153
+ return false;
154
+ if (!prototype.hasOwnProperty("isPrototypeOf")) {
155
+ return false;
156
+ }
157
+ return true;
158
+ }
159
+ function deepCompare(a, b) {
160
+ if (a === b) {
161
+ return true;
162
+ }
163
+ if (a instanceof Date && b instanceof Date) {
164
+ return a.getTime() === b.getTime();
165
+ }
166
+ if (a instanceof Array && b instanceof Array) {
167
+ if (a.length !== b.length) {
168
+ return false;
169
+ }
170
+ return a.every((v, i) => deepCompare(v, b[i]));
171
+ }
172
+ if (isPlainObject(a) && isPlainObject(b)) {
173
+ const entriesA = Object.entries(a);
174
+ if (entriesA.length !== Object.keys(b).length) {
175
+ return false;
176
+ }
177
+ return entriesA.every(([k2, v]) => deepCompare(v, b[k2]));
178
+ }
179
+ return false;
180
+ }
181
+ function useDeepCompareEffect(callback, dependencies) {
182
+ return useEffect(callback, useDeepCompareMemoize(dependencies));
183
+ }
184
+ function useDeepCompareMemoize(value) {
185
+ const ref = useRef(value);
186
+ const signalRef = useRef(0);
187
+ if (!deepCompare(value, ref.current)) {
188
+ ref.current = value;
189
+ signalRef.current += 1;
190
+ }
191
+ return useMemo(() => ref.current, [signalRef.current]);
192
+ }
193
+ function NostoProduct(props) {
194
+ const {
195
+ product,
196
+ tagging
197
+ } = props;
142
198
  const {
143
199
  clientScriptLoaded,
144
200
  currentVariation,
145
- renderFunction,
146
- responseMode
201
+ responseMode,
202
+ recommendationComponent,
203
+ useRenderCampaigns
147
204
  } = useNostoContext();
148
- useEffect(() => {
149
- if (clientScriptLoaded) {
205
+ const {
206
+ renderCampaigns,
207
+ pageTypeUpdated
208
+ } = useRenderCampaigns("product");
209
+ useDeepCompareEffect(() => {
210
+ if (clientScriptLoaded && pageTypeUpdated) {
150
211
  window.nostojs((api) => {
151
212
  api.defaultSession().setResponseMode(responseMode).viewProduct(product).setPlacements(api.placements.getPlacements()).load().then((data) => {
152
- if (responseMode == "HTML") {
153
- api.placements.injectCampaigns(data.recommendations);
154
- } else {
155
- renderFunction(data.campaigns);
156
- }
213
+ renderCampaigns(data, api);
157
214
  });
158
- }, [clientScriptLoaded, currentVariation, product, renderFunction]);
215
+ });
159
216
  }
160
- });
217
+ }, [clientScriptLoaded, currentVariation, product, recommendationComponent, pageTypeUpdated]);
161
218
  return /* @__PURE__ */ jsxs(Fragment, {
162
219
  children: [/* @__PURE__ */ jsx("div", {
163
220
  className: "nosto_page_type",
@@ -275,29 +332,31 @@ const NostoProduct = ({
275
332
  }, index))]
276
333
  })]
277
334
  });
278
- };
279
- const NostoCategory = ({
280
- category
281
- }) => {
335
+ }
336
+ function NostoCategory(props) {
337
+ const {
338
+ category
339
+ } = props;
282
340
  const {
283
341
  clientScriptLoaded,
284
342
  currentVariation,
285
- renderFunction,
286
- responseMode
343
+ responseMode,
344
+ recommendationComponent,
345
+ useRenderCampaigns
287
346
  } = useNostoContext();
347
+ const {
348
+ renderCampaigns,
349
+ pageTypeUpdated
350
+ } = useRenderCampaigns("home");
288
351
  useEffect(() => {
289
- if (clientScriptLoaded) {
352
+ if (clientScriptLoaded && pageTypeUpdated) {
290
353
  window.nostojs((api) => {
291
354
  api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCategory(category).setPlacements(api.placements.getPlacements()).load().then((data) => {
292
- if (responseMode == "HTML") {
293
- api.placements.injectCampaigns(data.recommendations);
294
- } else {
295
- renderFunction(data.campaigns);
296
- }
355
+ renderCampaigns(data, api);
297
356
  });
298
357
  });
299
358
  }
300
- }, [clientScriptLoaded, category, currentVariation, renderFunction]);
359
+ }, [clientScriptLoaded, category, currentVariation, recommendationComponent, pageTypeUpdated]);
301
360
  return /* @__PURE__ */ jsxs(Fragment, {
302
361
  children: [/* @__PURE__ */ jsx("div", {
303
362
  className: "nosto_page_type",
@@ -313,29 +372,31 @@ const NostoCategory = ({
313
372
  children: category
314
373
  })]
315
374
  });
316
- };
317
- const NostoSearch = ({
318
- query
319
- }) => {
375
+ }
376
+ function NostoSearch(props) {
377
+ const {
378
+ query
379
+ } = props;
320
380
  const {
321
381
  clientScriptLoaded,
322
382
  currentVariation,
323
- renderFunction,
324
- responseMode
383
+ responseMode,
384
+ recommendationComponent,
385
+ useRenderCampaigns
325
386
  } = useNostoContext();
387
+ const {
388
+ renderCampaigns,
389
+ pageTypeUpdated
390
+ } = useRenderCampaigns("search");
326
391
  useEffect(() => {
327
- if (clientScriptLoaded) {
392
+ if (clientScriptLoaded && pageTypeUpdated) {
328
393
  window.nostojs((api) => {
329
394
  api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewSearch(query).setPlacements(api.placements.getPlacements()).load().then((data) => {
330
- if (responseMode == "HTML") {
331
- api.placements.injectCampaigns(data.recommendations);
332
- } else {
333
- renderFunction(data.campaigns);
334
- }
395
+ renderCampaigns(data, api);
335
396
  });
336
397
  });
337
398
  }
338
- }, [clientScriptLoaded, currentVariation, query, renderFunction]);
399
+ }, [clientScriptLoaded, currentVariation, query, recommendationComponent, pageTypeUpdated]);
339
400
  return /* @__PURE__ */ jsxs(Fragment, {
340
401
  children: [/* @__PURE__ */ jsx("div", {
341
402
  className: "nosto_page_type",
@@ -351,50 +412,55 @@ const NostoSearch = ({
351
412
  children: query
352
413
  })]
353
414
  });
354
- };
355
- var snakeize = function walk(obj) {
356
- if (!obj || typeof obj !== "object")
415
+ }
416
+ function snakeize(obj) {
417
+ if (!obj || typeof obj !== "object") {
357
418
  return obj;
358
- if (isDate(obj) || isRegex(obj))
419
+ }
420
+ if (isDate(obj) || isRegex(obj)) {
359
421
  return obj;
360
- if (Array.isArray(obj))
361
- return obj.map(walk);
362
- return Object.keys(obj).reduce(function(acc, key) {
363
- var camel = key[0].toLowerCase() + key.slice(1).replace(/([A-Z]+)/g, function(m2, x) {
422
+ }
423
+ if (Array.isArray(obj)) {
424
+ return obj.map(snakeize);
425
+ }
426
+ return Object.keys(obj).reduce((acc, key) => {
427
+ var camel = key[0].toLowerCase() + key.slice(1).replace(/([A-Z]+)/g, (_, x) => {
364
428
  return "_" + x.toLowerCase();
365
429
  });
366
- acc[camel] = walk(obj[key]);
430
+ acc[camel] = snakeize(obj[key]);
367
431
  return acc;
368
432
  }, {});
369
- };
370
- var isDate = function(obj) {
433
+ }
434
+ function isDate(obj) {
371
435
  return Object.prototype.toString.call(obj) === "[object Date]";
372
- };
373
- var isRegex = function(obj) {
436
+ }
437
+ function isRegex(obj) {
374
438
  return Object.prototype.toString.call(obj) === "[object RegExp]";
375
- };
376
- const NostoOrder = ({
377
- order
378
- }) => {
439
+ }
440
+ function NostoOrder(props) {
441
+ const {
442
+ order
443
+ } = props;
379
444
  const {
380
445
  clientScriptLoaded,
381
446
  currentVariation,
382
- renderFunction,
383
- responseMode
447
+ responseMode,
448
+ recommendationComponent,
449
+ useRenderCampaigns
384
450
  } = useNostoContext();
451
+ const {
452
+ renderCampaigns,
453
+ pageTypeUpdated
454
+ } = useRenderCampaigns("order");
385
455
  useEffect(() => {
386
- if (clientScriptLoaded) {
456
+ if (clientScriptLoaded && pageTypeUpdated) {
387
457
  window.nostojs((api) => {
388
458
  api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).addOrder(snakeize(order)).setPlacements(api.placements.getPlacements()).load().then((data) => {
389
- if (responseMode == "HTML") {
390
- api.placements.injectCampaigns(data.recommendations);
391
- } else {
392
- renderFunction(data.campaigns);
393
- }
459
+ renderCampaigns(data, api);
394
460
  });
395
461
  });
396
462
  }
397
- }, [clientScriptLoaded, currentVariation, renderFunction]);
463
+ }, [clientScriptLoaded, currentVariation, recommendationComponent, pageTypeUpdated]);
398
464
  return /* @__PURE__ */ jsxs(Fragment, {
399
465
  children: [/* @__PURE__ */ jsx("div", {
400
466
  className: "nosto_page_type",
@@ -410,27 +476,28 @@ const NostoOrder = ({
410
476
  children: order.purchase.number
411
477
  })]
412
478
  });
413
- };
414
- const NostoHome = () => {
479
+ }
480
+ function NostoHome() {
415
481
  const {
416
482
  clientScriptLoaded,
417
483
  currentVariation,
418
- renderFunction,
419
- responseMode
484
+ responseMode,
485
+ recommendationComponent,
486
+ useRenderCampaigns
420
487
  } = useNostoContext();
488
+ const {
489
+ renderCampaigns,
490
+ pageTypeUpdated
491
+ } = useRenderCampaigns("home");
421
492
  useEffect(() => {
422
- if (clientScriptLoaded) {
493
+ if (clientScriptLoaded && pageTypeUpdated) {
423
494
  window.nostojs((api) => {
424
495
  api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewFrontPage().setPlacements(api.placements.getPlacements()).load().then((data) => {
425
- if (responseMode == "HTML") {
426
- api.placements.injectCampaigns(data.recommendations);
427
- } else {
428
- renderFunction(data.campaigns);
429
- }
496
+ renderCampaigns(data, api);
430
497
  });
431
498
  });
432
499
  }
433
- }, [clientScriptLoaded, currentVariation, renderFunction]);
500
+ }, [clientScriptLoaded, currentVariation, recommendationComponent, pageTypeUpdated]);
434
501
  return /* @__PURE__ */ jsx(Fragment, {
435
502
  children: /* @__PURE__ */ jsx("div", {
436
503
  className: "nosto_page_type",
@@ -440,158 +507,142 @@ const NostoHome = () => {
440
507
  children: "front"
441
508
  })
442
509
  });
443
- };
444
- const NostoPlacement = ({
445
- id
446
- }) => {
510
+ }
511
+ function NostoPlacement(props) {
512
+ const {
513
+ id,
514
+ pageType
515
+ } = props;
447
516
  return /* @__PURE__ */ jsx("div", {
448
517
  className: "nosto_element",
449
518
  id
450
- });
451
- };
452
- const NostoProvider = ({
453
- account,
454
- currentVariation = "",
455
- multiCurrency = false,
456
- host,
457
- children,
458
- renderFunction
459
- }) => {
460
- const [clientScriptLoadedState, setClientScriptLoadedState] = React__default.useState(false);
461
- const clientScriptLoaded = React__default.useMemo(() => clientScriptLoadedState, [clientScriptLoadedState]);
462
- const responseMode = typeof renderFunction == "function" ? "JSON_ORIGINAL" : "HTML";
519
+ }, id + (pageType || ""));
520
+ }
521
+ function NostoProvider(props) {
522
+ let {
523
+ account,
524
+ currentVariation = "",
525
+ multiCurrency = false,
526
+ host,
527
+ children,
528
+ recommendationComponent,
529
+ shopifyMarkets
530
+ } = props;
531
+ const [clientScriptLoadedState, setClientScriptLoadedState] = React.useState(false);
532
+ const clientScriptLoaded = React.useMemo(() => clientScriptLoadedState, [clientScriptLoadedState]);
463
533
  currentVariation = multiCurrency ? currentVariation : "";
534
+ const responseMode = isValidElement(recommendationComponent) ? "JSON_ORIGINAL" : "HTML";
535
+ function RecommendationComponentWrapper(props2) {
536
+ return React.cloneElement(recommendationComponent, {
537
+ nostoRecommendation: props2.nostoRecommendation
538
+ });
539
+ }
540
+ const [pageType, setPageType] = useState("");
541
+ const useRenderCampaigns = function(type = "") {
542
+ const placementRefs = useRef({});
543
+ useEffect(() => {
544
+ if (pageType != type) {
545
+ setPageType(type);
546
+ }
547
+ }, []);
548
+ const pageTypeUpdated = type == pageType;
549
+ function renderCampaigns(data, api) {
550
+ if (responseMode == "HTML") {
551
+ api.placements.injectCampaigns(data.recommendations);
552
+ } else {
553
+ const recommendations = data.campaigns.recommendations;
554
+ for (const key in recommendations) {
555
+ let recommendation = recommendations[key];
556
+ let placementSelector = "#" + key;
557
+ let placement = () => document.querySelector(placementSelector);
558
+ if (!!placement()) {
559
+ if (!placementRefs.current[key])
560
+ placementRefs.current[key] = createRoot(placement());
561
+ const root = placementRefs.current[key];
562
+ root.render(/* @__PURE__ */ jsx(RecommendationComponentWrapper, {
563
+ nostoRecommendation: recommendation
564
+ }));
565
+ }
566
+ }
567
+ }
568
+ }
569
+ return {
570
+ renderCampaigns,
571
+ pageTypeUpdated
572
+ };
573
+ };
464
574
  useEffect(() => {
465
- if (!document.querySelectorAll("[nosto-client-script]").length) {
575
+ var _a, _b, _c;
576
+ if (!window.nostojs) {
577
+ window.nostojs = (cb) => {
578
+ (window.nostojs.q = window.nostojs.q || []).push(cb);
579
+ };
580
+ window.nostojs((api) => api.setAutoLoad(false));
581
+ }
582
+ if (!document.querySelectorAll("[nosto-client-script]").length && !shopifyMarkets) {
466
583
  const script = document.createElement("script");
467
584
  script.type = "text/javascript";
468
585
  script.src = "//" + (host || "connect.nosto.com") + "/include/" + account;
469
586
  script.async = true;
470
587
  script.setAttribute("nosto-client-script", "");
471
588
  script.onload = () => {
472
- console.log("Nosto client script loaded");
589
+ var _a2;
590
+ if (typeof jest !== "undefined") {
591
+ (_a2 = window.nosto) == null ? void 0 : _a2.reload({
592
+ site: "localhost"
593
+ });
594
+ }
473
595
  setClientScriptLoadedState(true);
474
596
  };
475
- document.head.appendChild(script);
597
+ document.body.appendChild(script);
476
598
  }
477
- window.nostojs = (cb) => (window.nostojs.q = window.nostojs.q || []).push(cb);
478
- window.nostojs((api) => api.setAutoLoad(false));
479
- }, []);
599
+ if (!!shopifyMarkets) {
600
+ const existingScript = document.querySelector("[nosto-client-script]");
601
+ const nostoSandbox = document.querySelector("#nosto-sandbox");
602
+ if (!existingScript || (existingScript == null ? void 0 : existingScript.getAttribute("nosto-language")) != (shopifyMarkets == null ? void 0 : shopifyMarkets.language) || (existingScript == null ? void 0 : existingScript.getAttribute("nosto-market-id")) != (shopifyMarkets == null ? void 0 : shopifyMarkets.marketId)) {
603
+ if (clientScriptLoadedState) {
604
+ setClientScriptLoadedState(false);
605
+ }
606
+ (_a = existingScript == null ? void 0 : existingScript.parentNode) == null ? void 0 : _a.removeChild(existingScript);
607
+ (_b = nostoSandbox == null ? void 0 : nostoSandbox.parentNode) == null ? void 0 : _b.removeChild(nostoSandbox);
608
+ const script = document.createElement("script");
609
+ script.type = "text/javascript";
610
+ script.src = "//" + (host || "connect.nosto.com") + `/script/shopify/market/nosto.js?merchant=${account}&market=${shopifyMarkets.marketId || ""}&locale=${((_c = shopifyMarkets == null ? void 0 : shopifyMarkets.language) == null ? void 0 : _c.toLowerCase()) || ""}`;
611
+ script.async = true;
612
+ script.setAttribute("nosto-client-script", "");
613
+ script.setAttribute("nosto-language", (shopifyMarkets == null ? void 0 : shopifyMarkets.language) || "");
614
+ script.setAttribute("nosto-market-id", String(shopifyMarkets == null ? void 0 : shopifyMarkets.marketId));
615
+ script.onload = () => {
616
+ var _a2;
617
+ if (typeof jest !== "undefined") {
618
+ (_a2 = window.nosto) == null ? void 0 : _a2.reload({
619
+ site: "localhost"
620
+ });
621
+ }
622
+ setClientScriptLoadedState(true);
623
+ };
624
+ document.body.appendChild(script);
625
+ }
626
+ }
627
+ }, [clientScriptLoadedState, shopifyMarkets]);
480
628
  return /* @__PURE__ */ jsx(NostoContext.Provider, {
481
629
  value: {
482
630
  account,
483
631
  clientScriptLoaded,
484
632
  currentVariation,
485
- renderFunction,
486
- responseMode
633
+ responseMode,
634
+ recommendationComponent,
635
+ useRenderCampaigns,
636
+ pageType
487
637
  },
488
638
  children
489
639
  });
490
- };
491
- var has = Object.prototype.hasOwnProperty;
492
- function find(iter, tar, key) {
493
- for (key of iter.keys()) {
494
- if (dequal(key, tar))
495
- return key;
496
- }
497
640
  }
498
- function dequal(foo, bar) {
499
- var ctor, len, tmp;
500
- if (foo === bar)
501
- return true;
502
- if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
503
- if (ctor === Date)
504
- return foo.getTime() === bar.getTime();
505
- if (ctor === RegExp)
506
- return foo.toString() === bar.toString();
507
- if (ctor === Array) {
508
- if ((len = foo.length) === bar.length) {
509
- while (len-- && dequal(foo[len], bar[len]))
510
- ;
511
- }
512
- return len === -1;
513
- }
514
- if (ctor === Set) {
515
- if (foo.size !== bar.size) {
516
- return false;
517
- }
518
- for (len of foo) {
519
- tmp = len;
520
- if (tmp && typeof tmp === "object") {
521
- tmp = find(bar, tmp);
522
- if (!tmp)
523
- return false;
524
- }
525
- if (!bar.has(tmp))
526
- return false;
527
- }
528
- return true;
529
- }
530
- if (ctor === Map) {
531
- if (foo.size !== bar.size) {
532
- return false;
533
- }
534
- for (len of foo) {
535
- tmp = len[0];
536
- if (tmp && typeof tmp === "object") {
537
- tmp = find(bar, tmp);
538
- if (!tmp)
539
- return false;
540
- }
541
- if (!dequal(len[1], bar.get(tmp))) {
542
- return false;
543
- }
544
- }
545
- return true;
546
- }
547
- if (ctor === ArrayBuffer) {
548
- foo = new Uint8Array(foo);
549
- bar = new Uint8Array(bar);
550
- } else if (ctor === DataView) {
551
- if ((len = foo.byteLength) === bar.byteLength) {
552
- while (len-- && foo.getInt8(len) === bar.getInt8(len))
553
- ;
554
- }
555
- return len === -1;
556
- }
557
- if (ArrayBuffer.isView(foo)) {
558
- if ((len = foo.byteLength) === bar.byteLength) {
559
- while (len-- && foo[len] === bar[len])
560
- ;
561
- }
562
- return len === -1;
563
- }
564
- if (!ctor || typeof foo === "object") {
565
- len = 0;
566
- for (ctor in foo) {
567
- if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
568
- return false;
569
- if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
570
- return false;
571
- }
572
- return Object.keys(bar).length === len;
573
- }
574
- }
575
- return foo !== foo && bar !== bar;
576
- }
577
- function useDeepCompareMemoize(value) {
578
- var ref = React.useRef(value);
579
- var signalRef = React.useRef(0);
580
- if (!dequal(value, ref.current)) {
581
- ref.current = value;
582
- signalRef.current += 1;
583
- }
584
- return React.useMemo(function() {
585
- return ref.current;
586
- }, [signalRef.current]);
587
- }
588
- function useDeepCompareEffect(callback, dependencies) {
589
- return React.useEffect(callback, useDeepCompareMemoize(dependencies));
590
- }
591
- const NostoSession = ({
592
- cart,
593
- customer
594
- }) => {
641
+ function NostoSession(props) {
642
+ const {
643
+ cart,
644
+ customer
645
+ } = props;
595
646
  const {
596
647
  clientScriptLoaded
597
648
  } = useNostoContext();
@@ -603,7 +654,7 @@ const NostoSession = ({
603
654
  api.defaultSession().setResponseMode("HTML").setCart(currentCart).setCustomer(currentCustomer).viewOther().load();
604
655
  });
605
656
  }
606
- }, [clientScriptLoaded, cart || [], customer || {}]);
657
+ }, [clientScriptLoaded, cart, customer]);
607
658
  return /* @__PURE__ */ jsx(Fragment, {});
608
- };
609
- export { NostoFohofo as Nosto404, NostoCategory, NostoCheckout, NostoContext, NostoHome, NostoOrder, NostoOther, NostoPlacement, NostoProduct, NostoProvider, NostoSearch, NostoSession, useNostoContext };
659
+ }
660
+ export { Nosto404, NostoCategory, NostoCheckout, NostoContext, NostoHome, NostoOrder, NostoOther, NostoPlacement, NostoProduct, NostoProvider, NostoSearch, NostoSession, useNostoContext };