@nosto/nosto-react 2.7.1 → 2.9.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.
- package/dist/index.es.js +158 -160
- package/dist/index.umd.js +1 -1
- package/package.json +19 -11
package/dist/index.es.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { createContext as k, useContext as
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { createRoot as
|
|
4
|
-
const
|
|
1
|
+
import { createContext as k, useContext as b, useEffect as g, useRef as h, useMemo as A, cloneElement as x, useState as I, isValidElement as M } from "react";
|
|
2
|
+
import { jsx as C } from "react/jsx-runtime";
|
|
3
|
+
import { createRoot as _ } from "react-dom/client";
|
|
4
|
+
const v = k({
|
|
5
5
|
account: "",
|
|
6
6
|
currentVariation: "",
|
|
7
7
|
responseMode: "HTML",
|
|
8
8
|
clientScriptLoaded: !1
|
|
9
9
|
});
|
|
10
|
-
function
|
|
11
|
-
return
|
|
10
|
+
function y() {
|
|
11
|
+
return b(v);
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
function
|
|
15
|
-
if (!
|
|
13
|
+
const P = (e) => String(e) === "[object Object]";
|
|
14
|
+
function N(e) {
|
|
15
|
+
if (!P(e)) return !1;
|
|
16
16
|
const t = e.constructor;
|
|
17
17
|
if (t === void 0) return !0;
|
|
18
18
|
const n = t.prototype;
|
|
19
|
-
return !(!
|
|
19
|
+
return !(!P(n) || !n.hasOwnProperty("isPrototypeOf"));
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function w(e, t) {
|
|
22
22
|
if (e === t)
|
|
23
23
|
return !0;
|
|
24
24
|
if (e instanceof Date && t instanceof Date)
|
|
25
25
|
return e.getTime() === t.getTime();
|
|
26
26
|
if (e instanceof Array && t instanceof Array)
|
|
27
|
-
return e.length !== t.length ? !1 : e.every((n, o) =>
|
|
28
|
-
if (
|
|
27
|
+
return e.length !== t.length ? !1 : e.every((n, o) => w(n, t[o]));
|
|
28
|
+
if (N(e) && N(t)) {
|
|
29
29
|
const n = Object.entries(e);
|
|
30
|
-
return n.length !== Object.keys(t).length ? !1 : n.every(([o, r]) =>
|
|
30
|
+
return n.length !== Object.keys(t).length ? !1 : n.every(([o, r]) => w(r, t[o]));
|
|
31
31
|
}
|
|
32
32
|
return !1;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
34
|
+
function L(e, t) {
|
|
35
|
+
return g(e, T(t));
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function T(e) {
|
|
38
38
|
const t = h(e), n = h(0);
|
|
39
|
-
return
|
|
39
|
+
return w(e, t.current) || (t.current = e, n.current += 1), A(() => t.current, [n.current]);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function S() {
|
|
42
42
|
window.nostojs = window.nostojs ?? function(e) {
|
|
43
43
|
(window.nostojs.q = window.nostojs.q ?? []).push(e);
|
|
44
44
|
};
|
|
@@ -46,88 +46,86 @@ function N() {
|
|
|
46
46
|
async function m(e) {
|
|
47
47
|
return window.nostojs(e);
|
|
48
48
|
}
|
|
49
|
-
typeof window < "u" && (
|
|
49
|
+
typeof window < "u" && (S(), m((e) => {
|
|
50
50
|
e.internal.getSettings();
|
|
51
51
|
}));
|
|
52
|
-
function
|
|
52
|
+
function D() {
|
|
53
53
|
return typeof window.nosto < "u";
|
|
54
54
|
}
|
|
55
|
-
const
|
|
55
|
+
const V = {
|
|
56
56
|
production: "https://connect.nosto.com/",
|
|
57
57
|
staging: "https://connect.staging.nosto.com/",
|
|
58
58
|
local: "https://connect.nosto.com/"
|
|
59
59
|
};
|
|
60
|
-
function
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"nosto-
|
|
74
|
-
"nosto-market-id": a
|
|
60
|
+
function O(e) {
|
|
61
|
+
return V[e ?? "production"];
|
|
62
|
+
}
|
|
63
|
+
function q({ merchantId: e, env: t, options: n, shopifyInternational: o, scriptLoader: r }) {
|
|
64
|
+
const s = document.querySelector("script[nosto-language], script[nosto-market-id]"), c = String(o?.marketId || ""), i = o?.language || "", a = s?.getAttribute("nosto-language") !== i || s?.getAttribute("nosto-market-id") !== c;
|
|
65
|
+
if (!s || a) {
|
|
66
|
+
const u = document.querySelector("#nosto-sandbox");
|
|
67
|
+
s?.parentNode?.removeChild(s), u?.parentNode?.removeChild(u);
|
|
68
|
+
const f = new URL("/script/shopify/market/nosto.js", O(t));
|
|
69
|
+
f.searchParams.append("merchant", e), f.searchParams.append("market", c), f.searchParams.append("locale", i.toLowerCase());
|
|
70
|
+
const E = {
|
|
71
|
+
...n?.attributes,
|
|
72
|
+
"nosto-language": i,
|
|
73
|
+
"nosto-market-id": c
|
|
75
74
|
};
|
|
76
|
-
return (r ??
|
|
75
|
+
return (r ?? j)(f.toString(), { ...n, attributes: E });
|
|
77
76
|
}
|
|
78
77
|
return Promise.resolve();
|
|
79
78
|
}
|
|
80
|
-
function
|
|
79
|
+
function H(e) {
|
|
81
80
|
if (e.shopifyInternational)
|
|
82
|
-
return
|
|
83
|
-
const { merchantId: t, env: n, options: o, scriptLoader: r } = e,
|
|
84
|
-
return c
|
|
81
|
+
return q(e);
|
|
82
|
+
const { merchantId: t, env: n, options: o, scriptLoader: r } = e, s = r ?? j, c = new URL(`/include/${t}`, O(n));
|
|
83
|
+
return s(c.toString(), o);
|
|
85
84
|
}
|
|
86
|
-
function
|
|
85
|
+
function j(e, t) {
|
|
87
86
|
return new Promise((n, o) => {
|
|
88
87
|
const r = document.createElement("script");
|
|
89
|
-
r.src = e, r.async = !0, r.type = "text/javascript", r.onload = () => n(), r.onerror = () => o(), Object.entries(
|
|
88
|
+
r.src = e, r.async = !0, r.type = "text/javascript", r.onload = () => n(), r.onerror = () => o(), Object.entries(t?.attributes ?? {}).forEach(([s, c]) => r.setAttribute(s, c)), t?.position === "head" ? document.head.appendChild(r) : document.body.appendChild(r);
|
|
90
89
|
});
|
|
91
90
|
}
|
|
92
|
-
typeof window < "u" &&
|
|
91
|
+
typeof window < "u" && S();
|
|
93
92
|
function d(e, t, n) {
|
|
94
|
-
const { clientScriptLoaded: o } =
|
|
95
|
-
(n
|
|
93
|
+
const { clientScriptLoaded: o } = y();
|
|
94
|
+
(n?.deep ? L : g)(() => {
|
|
96
95
|
o && m(e);
|
|
97
96
|
}, [o, ...t ?? []]);
|
|
98
97
|
}
|
|
99
|
-
function
|
|
100
|
-
return
|
|
98
|
+
function F(e) {
|
|
99
|
+
return x(e.recommendationComponent, {
|
|
101
100
|
// eslint-disable-next-line react/prop-types
|
|
102
101
|
nostoRecommendation: e.nostoRecommendation
|
|
103
102
|
});
|
|
104
103
|
}
|
|
105
|
-
function
|
|
104
|
+
function R(e) {
|
|
106
105
|
m((t) => t.placements.injectCampaigns(e));
|
|
107
106
|
}
|
|
108
|
-
function
|
|
107
|
+
function z(e) {
|
|
109
108
|
if (!window.nostojs)
|
|
110
109
|
throw new Error("Nosto has not yet been initialized");
|
|
111
|
-
|
|
110
|
+
R(e.recommendations);
|
|
112
111
|
}
|
|
113
112
|
function l() {
|
|
114
|
-
const { responseMode: e, recommendationComponent: t } =
|
|
113
|
+
const { responseMode: e, recommendationComponent: t } = y(), n = h({});
|
|
115
114
|
if (e == "HTML")
|
|
116
|
-
return { renderCampaigns:
|
|
115
|
+
return { renderCampaigns: z };
|
|
117
116
|
if (!t)
|
|
118
117
|
throw new Error("recommendationComponent is required for client-side rendering using hook");
|
|
119
118
|
function o(r) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const c
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
U,
|
|
119
|
+
R(r.campaigns?.content ?? {});
|
|
120
|
+
const s = r.campaigns?.recommendations ?? {};
|
|
121
|
+
for (const c in s) {
|
|
122
|
+
const i = s[c], a = "#" + c, u = document.querySelector(a);
|
|
123
|
+
u && (n.current[c] || (n.current[c] = _(u)), n.current[c].render(
|
|
124
|
+
/* @__PURE__ */ C(
|
|
125
|
+
F,
|
|
128
126
|
{
|
|
129
127
|
recommendationComponent: t,
|
|
130
|
-
nostoRecommendation:
|
|
128
|
+
nostoRecommendation: i
|
|
131
129
|
}
|
|
132
130
|
)
|
|
133
131
|
));
|
|
@@ -135,17 +133,17 @@ function l() {
|
|
|
135
133
|
}
|
|
136
134
|
return { renderCampaigns: o };
|
|
137
135
|
}
|
|
138
|
-
function
|
|
136
|
+
function U(e) {
|
|
139
137
|
const { renderCampaigns: t } = l();
|
|
140
138
|
d(async (n) => {
|
|
141
|
-
const o = await n.defaultSession().viewNotFound().setPlacements(
|
|
139
|
+
const o = await n.defaultSession().viewNotFound().setPlacements(e?.placements || n.placements.getPlacements()).load();
|
|
142
140
|
t(o);
|
|
143
141
|
});
|
|
144
142
|
}
|
|
145
|
-
function
|
|
146
|
-
return
|
|
143
|
+
function ce(e) {
|
|
144
|
+
return U(e), null;
|
|
147
145
|
}
|
|
148
|
-
function
|
|
146
|
+
function $({ category: e, placements: t }) {
|
|
149
147
|
const { renderCampaigns: n } = l();
|
|
150
148
|
d(
|
|
151
149
|
async (o) => {
|
|
@@ -155,145 +153,145 @@ function J({ category: e, placements: t }) {
|
|
|
155
153
|
[e]
|
|
156
154
|
);
|
|
157
155
|
}
|
|
158
|
-
function
|
|
159
|
-
return
|
|
156
|
+
function ie(e) {
|
|
157
|
+
return $(e), null;
|
|
160
158
|
}
|
|
161
|
-
function
|
|
159
|
+
function G(e) {
|
|
162
160
|
const { renderCampaigns: t } = l();
|
|
163
161
|
d(async (n) => {
|
|
164
|
-
const o = await n.defaultSession().viewCart().setPlacements(
|
|
162
|
+
const o = await n.defaultSession().viewCart().setPlacements(e?.placements || n.placements.getPlacements()).load();
|
|
165
163
|
t(o);
|
|
166
164
|
});
|
|
167
165
|
}
|
|
168
|
-
function
|
|
169
|
-
return
|
|
166
|
+
function ae(e) {
|
|
167
|
+
return G(e), null;
|
|
170
168
|
}
|
|
171
|
-
function
|
|
169
|
+
function J(e) {
|
|
172
170
|
const { renderCampaigns: t } = l();
|
|
173
171
|
d(async (n) => {
|
|
174
|
-
const o = await n.defaultSession().viewFrontPage().setPlacements(
|
|
172
|
+
const o = await n.defaultSession().viewFrontPage().setPlacements(e?.placements || n.placements.getPlacements()).load();
|
|
175
173
|
t(o);
|
|
176
174
|
});
|
|
177
175
|
}
|
|
178
|
-
function
|
|
179
|
-
return
|
|
176
|
+
function ue(e) {
|
|
177
|
+
return J(e), null;
|
|
180
178
|
}
|
|
181
|
-
function
|
|
182
|
-
return !e || typeof e != "object" ||
|
|
183
|
-
const o = n[0].toLowerCase() + n.slice(1).replace(/([A-Z]+)/g, (r,
|
|
184
|
-
return t[o] =
|
|
179
|
+
function p(e) {
|
|
180
|
+
return !e || typeof e != "object" || W(e) || Z(e) ? e : Array.isArray(e) ? e.map(p) : Object.keys(e).reduce((t, n) => {
|
|
181
|
+
const o = n[0].toLowerCase() + n.slice(1).replace(/([A-Z]+)/g, (r, s) => "_" + s.toLowerCase());
|
|
182
|
+
return t[o] = p(e[n]), t;
|
|
185
183
|
}, {});
|
|
186
184
|
}
|
|
187
|
-
function
|
|
185
|
+
function W(e) {
|
|
188
186
|
return Object.prototype.toString.call(e) === "[object Date]";
|
|
189
187
|
}
|
|
190
|
-
function
|
|
188
|
+
function Z(e) {
|
|
191
189
|
return Object.prototype.toString.call(e) === "[object RegExp]";
|
|
192
190
|
}
|
|
193
|
-
function
|
|
191
|
+
function B({ order: e, placements: t }) {
|
|
194
192
|
const { renderCampaigns: n } = l();
|
|
195
193
|
d(
|
|
196
194
|
async (o) => {
|
|
197
|
-
const r = await o.defaultSession().addOrder(
|
|
195
|
+
const r = await o.defaultSession().addOrder(p(e)).setPlacements(t || o.placements.getPlacements()).load();
|
|
198
196
|
n(r);
|
|
199
197
|
},
|
|
200
198
|
[e],
|
|
201
199
|
{ deep: !0 }
|
|
202
200
|
);
|
|
203
201
|
}
|
|
204
|
-
function
|
|
205
|
-
return
|
|
202
|
+
function de(e) {
|
|
203
|
+
return B(e), null;
|
|
206
204
|
}
|
|
207
|
-
function
|
|
205
|
+
function K(e) {
|
|
208
206
|
const { renderCampaigns: t } = l();
|
|
209
207
|
d(async (n) => {
|
|
210
|
-
const o = await n.defaultSession().viewOther().setPlacements(
|
|
208
|
+
const o = await n.defaultSession().viewOther().setPlacements(e?.placements || n.placements.getPlacements()).load();
|
|
211
209
|
t(o);
|
|
212
210
|
});
|
|
213
211
|
}
|
|
214
|
-
function
|
|
215
|
-
return
|
|
212
|
+
function le(e) {
|
|
213
|
+
return K(e), null;
|
|
216
214
|
}
|
|
217
|
-
function
|
|
218
|
-
return /* @__PURE__ */
|
|
215
|
+
function me({ id: e, pageType: t, children: n }) {
|
|
216
|
+
return /* @__PURE__ */ C("div", { className: "nosto_element", id: e, children: n }, e + (t || ""));
|
|
219
217
|
}
|
|
220
|
-
function
|
|
218
|
+
function Q({ product: e, tagging: t, placements: n, reference: o }) {
|
|
221
219
|
const { renderCampaigns: r } = l();
|
|
222
220
|
if (t && !t.product_id)
|
|
223
221
|
throw new Error("The product object must contain a product_id property");
|
|
224
|
-
const
|
|
222
|
+
const s = t?.product_id ?? e;
|
|
225
223
|
d(
|
|
226
|
-
async (
|
|
227
|
-
const
|
|
228
|
-
o &&
|
|
229
|
-
const a = await
|
|
224
|
+
async (c) => {
|
|
225
|
+
const i = c.defaultSession().viewProduct(t ?? e).setPlacements(n || c.placements.getPlacements());
|
|
226
|
+
o && i.setRef(s, o);
|
|
227
|
+
const a = await i.load();
|
|
230
228
|
r(a);
|
|
231
229
|
},
|
|
232
|
-
[
|
|
230
|
+
[s, t?.selected_sku_id]
|
|
233
231
|
);
|
|
234
232
|
}
|
|
235
|
-
function
|
|
236
|
-
return
|
|
233
|
+
function fe(e) {
|
|
234
|
+
return Q(e), null;
|
|
237
235
|
}
|
|
238
|
-
function
|
|
236
|
+
function X(e, t) {
|
|
239
237
|
return new Promise((n, o) => {
|
|
240
238
|
const r = document.createElement("script");
|
|
241
|
-
r.type = "text/javascript", r.src = e, r.async = !0, r.onload = () => n(), r.onerror = () => o(), Object.entries(
|
|
239
|
+
r.type = "text/javascript", r.src = e, r.async = !0, r.onload = () => n(), r.onerror = () => o(), Object.entries(t?.attributes ?? {}).forEach(([s, c]) => r.setAttribute(s, c)), t?.position === "head" ? document.head.appendChild(r) : document.body.appendChild(r);
|
|
242
240
|
});
|
|
243
241
|
}
|
|
244
|
-
const
|
|
245
|
-
function
|
|
242
|
+
const Y = { "nosto-client-script": "" };
|
|
243
|
+
function ee(e) {
|
|
246
244
|
const {
|
|
247
|
-
scriptLoader: t =
|
|
245
|
+
scriptLoader: t = X,
|
|
248
246
|
account: n,
|
|
249
247
|
shopifyMarkets: o,
|
|
250
248
|
loadScript: r = !0
|
|
251
|
-
} = e, [
|
|
252
|
-
return
|
|
253
|
-
function
|
|
254
|
-
|
|
249
|
+
} = e, [s, c] = I(!1);
|
|
250
|
+
return g(() => {
|
|
251
|
+
function i() {
|
|
252
|
+
c(!0);
|
|
255
253
|
}
|
|
256
|
-
if (
|
|
257
|
-
m(
|
|
254
|
+
if (S(), m((u) => u.setAutoLoad(!1)), !r) {
|
|
255
|
+
m(i);
|
|
258
256
|
return;
|
|
259
257
|
}
|
|
260
258
|
async function a() {
|
|
261
|
-
await
|
|
259
|
+
await H({
|
|
262
260
|
merchantId: n,
|
|
263
261
|
shopifyInternational: o,
|
|
264
262
|
options: {
|
|
265
|
-
attributes:
|
|
263
|
+
attributes: Y
|
|
266
264
|
},
|
|
267
265
|
scriptLoader: t
|
|
268
|
-
}),
|
|
266
|
+
}), i();
|
|
269
267
|
}
|
|
270
|
-
(!
|
|
271
|
-
}, [o
|
|
268
|
+
(!D() || o) && a();
|
|
269
|
+
}, [o?.marketId, o?.language]), { clientScriptLoaded: s };
|
|
272
270
|
}
|
|
273
|
-
function
|
|
274
|
-
const { account: t, multiCurrency: n = !1, children: o, recommendationComponent: r, renderMode:
|
|
275
|
-
if (r && !
|
|
271
|
+
function pe(e) {
|
|
272
|
+
const { account: t, multiCurrency: n = !1, children: o, recommendationComponent: r, renderMode: s } = e, c = n ? e.currentVariation : "";
|
|
273
|
+
if (r && !M(r))
|
|
276
274
|
throw new Error(
|
|
277
275
|
"The recommendationComponent prop must be a valid React element. Please provide a valid React element."
|
|
278
276
|
);
|
|
279
|
-
const
|
|
277
|
+
const i = s || (r ? "JSON_ORIGINAL" : "HTML"), { clientScriptLoaded: a } = ee(e);
|
|
280
278
|
return a && m((u) => {
|
|
281
|
-
u.defaultSession().setVariation(
|
|
282
|
-
}), /* @__PURE__ */
|
|
283
|
-
|
|
279
|
+
u.defaultSession().setVariation(c).setResponseMode(i);
|
|
280
|
+
}), /* @__PURE__ */ C(
|
|
281
|
+
v.Provider,
|
|
284
282
|
{
|
|
285
283
|
value: {
|
|
286
284
|
account: t,
|
|
287
285
|
clientScriptLoaded: a,
|
|
288
|
-
currentVariation:
|
|
289
|
-
responseMode:
|
|
286
|
+
currentVariation: c,
|
|
287
|
+
responseMode: i,
|
|
290
288
|
recommendationComponent: r
|
|
291
289
|
},
|
|
292
290
|
children: o
|
|
293
291
|
}
|
|
294
292
|
);
|
|
295
293
|
}
|
|
296
|
-
function
|
|
294
|
+
function te({ query: e, placements: t }) {
|
|
297
295
|
const { renderCampaigns: n } = l();
|
|
298
296
|
d(
|
|
299
297
|
async (o) => {
|
|
@@ -304,41 +302,41 @@ function oe({ query: e, placements: t }) {
|
|
|
304
302
|
);
|
|
305
303
|
}
|
|
306
304
|
function he(e) {
|
|
307
|
-
return
|
|
308
|
-
}
|
|
309
|
-
function
|
|
310
|
-
const { clientScriptLoaded: n } =
|
|
311
|
-
|
|
312
|
-
const o = e ?
|
|
313
|
-
n && m((
|
|
314
|
-
|
|
305
|
+
return te(e), null;
|
|
306
|
+
}
|
|
307
|
+
function ne({ cart: e, customer: t } = {}) {
|
|
308
|
+
const { clientScriptLoaded: n } = y();
|
|
309
|
+
L(() => {
|
|
310
|
+
const o = e ? p(e) : void 0, r = t ? p(t) : void 0;
|
|
311
|
+
n && m((s) => {
|
|
312
|
+
s.defaultSession().setCart(o).setCustomer(r).viewOther().load({ skipPageViews: !0 });
|
|
315
313
|
});
|
|
316
314
|
}, [n, e, t]);
|
|
317
315
|
}
|
|
318
|
-
function
|
|
319
|
-
return
|
|
316
|
+
function we(e) {
|
|
317
|
+
return ne(e), null;
|
|
320
318
|
}
|
|
321
319
|
export {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
320
|
+
ce as Nosto404,
|
|
321
|
+
ie as NostoCategory,
|
|
322
|
+
ae as NostoCheckout,
|
|
323
|
+
v as NostoContext,
|
|
324
|
+
ue as NostoHome,
|
|
325
|
+
de as NostoOrder,
|
|
326
|
+
le as NostoOther,
|
|
327
|
+
me as NostoPlacement,
|
|
328
|
+
fe as NostoProduct,
|
|
329
|
+
pe as NostoProvider,
|
|
332
330
|
he as NostoSearch,
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
331
|
+
we as NostoSession,
|
|
332
|
+
U as useNosto404,
|
|
333
|
+
$ as useNostoCategory,
|
|
334
|
+
G as useNostoCheckout,
|
|
335
|
+
y as useNostoContext,
|
|
336
|
+
J as useNostoHome,
|
|
337
|
+
B as useNostoOrder,
|
|
338
|
+
K as useNostoOther,
|
|
339
|
+
Q as useNostoProduct,
|
|
340
|
+
te as useNostoSearch,
|
|
341
|
+
ne as useNostoSession
|
|
344
342
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react"),require("react/jsx-runtime"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime","react-dom/client"],a):(r=typeof globalThis<"u"?globalThis:r||self,a(r["@nosto/nosto-react"]={},r.React,r["react/jsx-runtime"],r.client))})(this,function(r,a,w,H){"use strict";const y=a.createContext({account:"",currentVariation:"",responseMode:"HTML",clientScriptLoaded:!1});function g(){return a.useContext(y)}const P=e=>String(e)==="[object Object]";function O(e){if(!P(e))return!1;const t=e.constructor;if(t===void 0)return!0;const n=t.prototype;return!(!P(n)||!n.hasOwnProperty("isPrototypeOf"))}function N(e,t){if(e===t)return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof Array&&t instanceof Array)return e.length!==t.length?!1:e.every((n,o)=>N(n,t[o]));if(O(e)&&O(t)){const n=Object.entries(e);return n.length!==Object.keys(t).length?!1:n.every(([o,s])=>N(s,t[o]))}return!1}function v(e,t){return a.useEffect(e,D(t))}function D(e){const t=a.useRef(e),n=a.useRef(0);return N(e,t.current)||(t.current=e,n.current+=1),a.useMemo(()=>t.current,[n.current])}function S(){window.nostojs=window.nostojs??function(e){(window.nostojs.q=window.nostojs.q??[]).push(e)}}async function p(e){return window.nostojs(e)}typeof window<"u"&&(S(),p(e=>{e.internal.getSettings()}));function V(){return typeof window.nosto<"u"}const F={production:"https://connect.nosto.com/",staging:"https://connect.staging.nosto.com/",local:"https://connect.nosto.com/"};function j(e){return F[e??"production"]}function z({merchantId:e,env:t,options:n,shopifyInternational:o,scriptLoader:s}){const c=document.querySelector("script[nosto-language], script[nosto-market-id]"),i=String(o?.marketId||""),u=o?.language||"",d=c?.getAttribute("nosto-language")!==u||c?.getAttribute("nosto-market-id")!==i;if(!c||d){const l=document.querySelector("#nosto-sandbox");c?.parentNode?.removeChild(c),l?.parentNode?.removeChild(l);const C=new URL("/script/shopify/market/nosto.js",j(t));C.searchParams.append("merchant",e),C.searchParams.append("market",i),C.searchParams.append("locale",u.toLowerCase());const ie={...n?.attributes,"nosto-language":u,"nosto-market-id":i};return(s??L)(C.toString(),{...n,attributes:ie})}return Promise.resolve()}function U(e){if(e.shopifyInternational)return z(e);const{merchantId:t,env:n,options:o,scriptLoader:s}=e,c=s??L,i=new URL(`/include/${t}`,j(n));return c(i.toString(),o)}function L(e,t){return new Promise((n,o)=>{const s=document.createElement("script");s.src=e,s.async=!0,s.type="text/javascript",s.onload=()=>n(),s.onerror=()=>o(),Object.entries(t?.attributes??{}).forEach(([c,i])=>s.setAttribute(c,i)),t?.position==="head"?document.head.appendChild(s):document.body.appendChild(s)})}typeof window<"u"&&S();function f(e,t,n){const{clientScriptLoaded:o}=g();(n?.deep?v:a.useEffect)(()=>{o&&p(e)},[o,...t??[]])}function $(e){return a.cloneElement(e.recommendationComponent,{nostoRecommendation:e.nostoRecommendation})}function R(e){p(t=>t.placements.injectCampaigns(e))}function G(e){if(!window.nostojs)throw new Error("Nosto has not yet been initialized");R(e.recommendations)}function m(){const{responseMode:e,recommendationComponent:t}=g(),n=a.useRef({});if(e=="HTML")return{renderCampaigns:G};if(!t)throw new Error("recommendationComponent is required for client-side rendering using hook");function o(s){R(s.campaigns?.content??{});const c=s.campaigns?.recommendations??{};for(const i in c){const u=c[i],d="#"+i,l=document.querySelector(d);l&&(n.current[i]||(n.current[i]=H.createRoot(l)),n.current[i].render(w.jsx($,{recommendationComponent:t,nostoRecommendation:u})))}}return{renderCampaigns:o}}function E(e){const{renderCampaigns:t}=m();f(async n=>{const o=await n.defaultSession().viewNotFound().setPlacements(e?.placements||n.placements.getPlacements()).load();t(o)})}function J(e){return E(e),null}function k({category:e,placements:t}){const{renderCampaigns:n}=m();f(async o=>{const s=await o.defaultSession().viewCategory(e).setPlacements(t||o.placements.getPlacements()).load();n(s)},[e])}function W(e){return k(e),null}function b(e){const{renderCampaigns:t}=m();f(async n=>{const o=await n.defaultSession().viewCart().setPlacements(e?.placements||n.placements.getPlacements()).load();t(o)})}function Z(e){return b(e),null}function A(e){const{renderCampaigns:t}=m();f(async n=>{const o=await n.defaultSession().viewFrontPage().setPlacements(e?.placements||n.placements.getPlacements()).load();t(o)})}function B(e){return A(e),null}function h(e){return!e||typeof e!="object"||K(e)||Q(e)?e:Array.isArray(e)?e.map(h):Object.keys(e).reduce((t,n)=>{const o=n[0].toLowerCase()+n.slice(1).replace(/([A-Z]+)/g,(s,c)=>"_"+c.toLowerCase());return t[o]=h(e[n]),t},{})}function K(e){return Object.prototype.toString.call(e)==="[object Date]"}function Q(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function M({order:e,placements:t}){const{renderCampaigns:n}=m();f(async o=>{const s=await o.defaultSession().addOrder(h(e)).setPlacements(t||o.placements.getPlacements()).load();n(s)},[e],{deep:!0})}function X(e){return M(e),null}function I(e){const{renderCampaigns:t}=m();f(async n=>{const o=await n.defaultSession().viewOther().setPlacements(e?.placements||n.placements.getPlacements()).load();t(o)})}function Y(e){return I(e),null}function x({id:e,pageType:t,children:n}){return w.jsx("div",{className:"nosto_element",id:e,children:n},e+(t||""))}function T({product:e,tagging:t,placements:n,reference:o}){const{renderCampaigns:s}=m();if(t&&!t.product_id)throw new Error("The product object must contain a product_id property");const c=t?.product_id??e;f(async i=>{const u=i.defaultSession().viewProduct(t??e).setPlacements(n||i.placements.getPlacements());o&&u.setRef(c,o);const d=await u.load();s(d)},[c,t?.selected_sku_id])}function ee(e){return T(e),null}function te(e,t){return new Promise((n,o)=>{const s=document.createElement("script");s.type="text/javascript",s.src=e,s.async=!0,s.onload=()=>n(),s.onerror=()=>o(),Object.entries(t?.attributes??{}).forEach(([c,i])=>s.setAttribute(c,i)),t?.position==="head"?document.head.appendChild(s):document.body.appendChild(s)})}const ne={"nosto-client-script":""};function oe(e){const{scriptLoader:t=te,account:n,shopifyMarkets:o,loadScript:s=!0}=e,[c,i]=a.useState(!1);return a.useEffect(()=>{function u(){i(!0)}if(S(),p(l=>l.setAutoLoad(!1)),!s){p(u);return}async function d(){await U({merchantId:n,shopifyInternational:o,options:{attributes:ne},scriptLoader:t}),u()}(!V()||o)&&d()},[o?.marketId,o?.language]),{clientScriptLoaded:c}}function se(e){const{account:t,multiCurrency:n=!1,children:o,recommendationComponent:s,renderMode:c}=e,i=n?e.currentVariation:"";if(s&&!a.isValidElement(s))throw new Error("The recommendationComponent prop must be a valid React element. Please provide a valid React element.");const u=c||(s?"JSON_ORIGINAL":"HTML"),{clientScriptLoaded:d}=oe(e);return d&&p(l=>{l.defaultSession().setVariation(i).setResponseMode(u)}),w.jsx(y.Provider,{value:{account:t,clientScriptLoaded:d,currentVariation:i,responseMode:u,recommendationComponent:s},children:o})}function _({query:e,placements:t}){const{renderCampaigns:n}=m();f(async o=>{const s=await o.defaultSession().viewSearch(e).setPlacements(t||o.placements.getPlacements()).load();n(s)},[e])}function re(e){return _(e),null}function q({cart:e,customer:t}={}){const{clientScriptLoaded:n}=g();v(()=>{const o=e?h(e):void 0,s=t?h(t):void 0;n&&p(c=>{c.defaultSession().setCart(o).setCustomer(s).viewOther().load({skipPageViews:!0})})},[n,e,t])}function ce(e){return q(e),null}r.Nosto404=J,r.NostoCategory=W,r.NostoCheckout=Z,r.NostoContext=y,r.NostoHome=B,r.NostoOrder=X,r.NostoOther=Y,r.NostoPlacement=x,r.NostoProduct=ee,r.NostoProvider=se,r.NostoSearch=re,r.NostoSession=ce,r.useNosto404=E,r.useNostoCategory=k,r.useNostoCheckout=b,r.useNostoContext=g,r.useNostoHome=A,r.useNostoOrder=M,r.useNostoOther=I,r.useNostoProduct=T,r.useNostoSearch=_,r.useNostoSession=q,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/nosto-react",
|
|
3
3
|
"description": "Component library to simply implementing Nosto on React.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.9.0",
|
|
5
5
|
"author": "Mridang Agarwalla, Dominik Gilg",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"repository": {
|
|
@@ -12,19 +12,23 @@
|
|
|
12
12
|
"nosto",
|
|
13
13
|
"personalisation"
|
|
14
14
|
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.0.0"
|
|
17
|
+
},
|
|
15
18
|
"scripts": {
|
|
16
19
|
"dev": "vite",
|
|
17
20
|
"build": "tsc && npm run lint && vite build && npm run typedoc",
|
|
18
21
|
"preview": "vite preview",
|
|
19
|
-
"prepare": "vite build",
|
|
22
|
+
"prepare": "husky && vite build",
|
|
20
23
|
"typecheck": "tsc",
|
|
21
24
|
"lint": "eslint 'src/**/*.{ts,tsx}' --cache",
|
|
22
25
|
"clean": "rimraf dist",
|
|
23
26
|
"prettier": "prettier '{src,spec}/**' --list-different",
|
|
24
27
|
"prettier:fix": "prettier '{src,spec}/**' --write",
|
|
25
|
-
"test": "vitest run --silent",
|
|
28
|
+
"test": "vitest run --silent --coverage",
|
|
26
29
|
"test-loud": "vitest run",
|
|
27
|
-
"typedoc": "typedoc --treatWarningsAsErrors src/index.ts"
|
|
30
|
+
"typedoc": "typedoc --treatWarningsAsErrors src/index.ts",
|
|
31
|
+
"typedoc-json": "typedoc --treatWarningsAsErrors --json dist/typedoc.json src/index.ts"
|
|
28
32
|
},
|
|
29
33
|
"files": [
|
|
30
34
|
"dist",
|
|
@@ -35,29 +39,33 @@
|
|
|
35
39
|
"react-dom": "^18.3.1 || ^19.0.0"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
|
-
"@nosto/nosto-js": "^
|
|
42
|
+
"@nosto/nosto-js": "^2.0.0",
|
|
43
|
+
"@commitlint/cli": "^20.0.0",
|
|
44
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
39
45
|
"@testing-library/jest-dom": "^6.4.8",
|
|
40
46
|
"@testing-library/react": "^16.0.0",
|
|
41
47
|
"@testing-library/user-event": "^14.4.3",
|
|
42
48
|
"@types/react": "^19.0.2",
|
|
43
49
|
"@types/react-dom": "^19.0.0",
|
|
44
50
|
"@types/user-event": "^4.1.1",
|
|
45
|
-
"@vitejs/plugin-react": "^
|
|
51
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
52
|
+
"@vitest/coverage-v8": "^3.0.9",
|
|
46
53
|
"eslint": "^9.13.0",
|
|
47
54
|
"eslint-plugin-barrel-files": "^3.0.1",
|
|
48
55
|
"eslint-plugin-promise": "^7.1.0",
|
|
49
56
|
"eslint-plugin-react": "^7.33.2",
|
|
57
|
+
"husky": "^9.1.7",
|
|
50
58
|
"prettier": "^3.3.3",
|
|
51
59
|
"react": "^19.0.0",
|
|
52
60
|
"react-dom": "^19.0.0",
|
|
53
61
|
"react-router": "^7.0.1",
|
|
54
62
|
"react-router-dom": "^7.0.1",
|
|
55
63
|
"rimraf": "^6.0.1",
|
|
56
|
-
"rollup-plugin-visualizer": "^
|
|
57
|
-
"typedoc": "^0.28.
|
|
58
|
-
"typescript": "^5.
|
|
59
|
-
"typescript-eslint": "^8.
|
|
60
|
-
"vite": "^
|
|
64
|
+
"rollup-plugin-visualizer": "^6.0.0",
|
|
65
|
+
"typedoc": "^0.28.9",
|
|
66
|
+
"typescript": "^5.9.2",
|
|
67
|
+
"typescript-eslint": "^8.39.0",
|
|
68
|
+
"vite": "^7.0.2",
|
|
61
69
|
"vite-plugin-dts": "^4.2.2",
|
|
62
70
|
"vitest": "^3.0.2"
|
|
63
71
|
},
|