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