@nosto/nosto-react 0.1.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.
@@ -0,0 +1,505 @@
1
+ import * as React from "react";
2
+ import React__default, { useEffect, createContext } from "react";
3
+ var jsxRuntime = { exports: {} };
4
+ var reactJsxRuntime_production_min = {};
5
+ /**
6
+ * @license React
7
+ * react-jsx-runtime.production.min.js
8
+ *
9
+ * Copyright (c) Facebook, Inc. and its affiliates.
10
+ *
11
+ * This source code is licensed under the MIT license found in the
12
+ * LICENSE file in the root directory of this source tree.
13
+ */
14
+ 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 };
15
+ function q(c, a, g) {
16
+ var b, d = {}, e = null, h = null;
17
+ g !== void 0 && (e = "" + g);
18
+ a.key !== void 0 && (e = "" + a.key);
19
+ a.ref !== void 0 && (h = a.ref);
20
+ for (b in a)
21
+ m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
22
+ if (c && c.defaultProps)
23
+ for (b in a = c.defaultProps, a)
24
+ d[b] === void 0 && (d[b] = a[b]);
25
+ return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
26
+ }
27
+ reactJsxRuntime_production_min.Fragment = l;
28
+ reactJsxRuntime_production_min.jsx = q;
29
+ reactJsxRuntime_production_min.jsxs = q;
30
+ {
31
+ jsxRuntime.exports = reactJsxRuntime_production_min;
32
+ }
33
+ const jsx = jsxRuntime.exports.jsx;
34
+ const jsxs = jsxRuntime.exports.jsxs;
35
+ const Fragment = jsxRuntime.exports.Fragment;
36
+ const NostoFohofo = () => {
37
+ useEffect(() => {
38
+ window.nostojs((api) => {
39
+ api.defaultSession().setResponseMode("HTML").viewNotFound().setPlacements(api.placements.getPlacements()).load().then((data) => {
40
+ api.placements.injectCampaigns(data.recommendations);
41
+ });
42
+ });
43
+ }, []);
44
+ return /* @__PURE__ */ jsx(Fragment, {
45
+ children: /* @__PURE__ */ jsx("div", {
46
+ className: "nosto_page_type",
47
+ style: {
48
+ display: "none"
49
+ },
50
+ children: "notfound"
51
+ })
52
+ });
53
+ };
54
+ const NostoOther = () => {
55
+ useEffect(() => {
56
+ window.nostojs((api) => {
57
+ api.defaultSession().setResponseMode("HTML").viewOther().setPlacements(api.placements.getPlacements()).load().then((data) => {
58
+ api.placements.injectCampaigns(data.recommendations);
59
+ });
60
+ });
61
+ }, []);
62
+ return /* @__PURE__ */ jsx(Fragment, {
63
+ children: /* @__PURE__ */ jsx("div", {
64
+ className: "nosto_page_type",
65
+ style: {
66
+ display: "none"
67
+ },
68
+ children: "other"
69
+ })
70
+ });
71
+ };
72
+ const NostoCheckout = () => {
73
+ useEffect(() => {
74
+ window.nostojs((api) => {
75
+ api.defaultSession().setResponseMode("HTML").viewCart().setPlacements(api.placements.getPlacements()).load().then((data) => {
76
+ api.placements.injectCampaigns(data.recommendations);
77
+ });
78
+ });
79
+ }, []);
80
+ return /* @__PURE__ */ jsx(Fragment, {
81
+ children: /* @__PURE__ */ jsx("div", {
82
+ className: "nosto_page_type",
83
+ style: {
84
+ display: "none"
85
+ },
86
+ children: "cart"
87
+ })
88
+ });
89
+ };
90
+ function stringinate(obj) {
91
+ Object.keys(obj).forEach((property) => {
92
+ if (obj[property] instanceof URL) {
93
+ obj[property] = obj[property].toString();
94
+ }
95
+ if (typeof obj[property] === "object") {
96
+ stringinate(obj[property]);
97
+ }
98
+ obj[property] = obj[property];
99
+ });
100
+ return obj;
101
+ }
102
+ var snakeize = function walk(obj) {
103
+ if (!obj || typeof obj !== "object")
104
+ return obj;
105
+ if (isDate(obj) || isRegex(obj))
106
+ return obj;
107
+ if (Array.isArray(obj))
108
+ return obj.map(walk);
109
+ return Object.keys(obj).reduce(function(acc, key) {
110
+ var camel = key[0].toLowerCase() + key.slice(1).replace(/([A-Z]+)/g, function(m2, x) {
111
+ return "_" + x.toLowerCase();
112
+ });
113
+ acc[camel] = walk(obj[key]);
114
+ return acc;
115
+ }, {});
116
+ };
117
+ var isDate = function(obj) {
118
+ return Object.prototype.toString.call(obj) === "[object Date]";
119
+ };
120
+ var isRegex = function(obj) {
121
+ return Object.prototype.toString.call(obj) === "[object RegExp]";
122
+ };
123
+ const NostoProduct = ({
124
+ product,
125
+ tagging
126
+ }) => {
127
+ useEffect(() => {
128
+ window.nostojs((api) => {
129
+ api.defaultSession().setResponseMode("HTML").viewProduct(snakeize(stringinate(tagging))).setPlacements(api.placements.getPlacements()).load().then((data) => {
130
+ api.placements.injectCampaigns(data.recommendations);
131
+ });
132
+ });
133
+ }, []);
134
+ return /* @__PURE__ */ jsxs(Fragment, {
135
+ children: [/* @__PURE__ */ jsx("div", {
136
+ className: "nosto_page_type",
137
+ style: {
138
+ display: "none"
139
+ },
140
+ children: "product"
141
+ }), /* @__PURE__ */ jsxs("div", {
142
+ className: "nosto_product",
143
+ style: {
144
+ display: "none"
145
+ },
146
+ children: [tagging.variationId && /* @__PURE__ */ jsx("span", {
147
+ className: "variation_id",
148
+ children: tagging.variationId
149
+ }), tagging.productId && /* @__PURE__ */ jsx("span", {
150
+ className: "product_id",
151
+ children: tagging.productId
152
+ }), tagging.name && /* @__PURE__ */ jsx("span", {
153
+ className: "name",
154
+ children: tagging.name
155
+ }), tagging.url && /* @__PURE__ */ jsx("span", {
156
+ className: "url",
157
+ children: tagging.url.toString()
158
+ }), tagging.imageUrl && /* @__PURE__ */ jsx("span", {
159
+ className: "image_url",
160
+ children: tagging.imageUrl.toString()
161
+ }), tagging.availability && /* @__PURE__ */ jsx("span", {
162
+ className: "availability",
163
+ children: tagging.availability
164
+ }), tagging.price && /* @__PURE__ */ jsx("span", {
165
+ className: "price",
166
+ children: tagging.price
167
+ }), tagging.listPrice && /* @__PURE__ */ jsx("span", {
168
+ className: "list_price",
169
+ children: tagging.listPrice
170
+ }), tagging.priceCurrencyCode && /* @__PURE__ */ jsx("span", {
171
+ className: "price_currency_code",
172
+ children: tagging.priceCurrencyCode
173
+ }), tagging.brand && /* @__PURE__ */ jsx("span", {
174
+ className: "brand",
175
+ children: tagging.brand
176
+ }), tagging.description && /* @__PURE__ */ jsx("span", {
177
+ className: "description",
178
+ children: tagging.description
179
+ }), tagging.googleCategory && /* @__PURE__ */ jsx("span", {
180
+ className: "description",
181
+ children: tagging.googleCategory
182
+ }), tagging.condition && /* @__PURE__ */ jsx("span", {
183
+ className: "condition",
184
+ children: tagging.condition
185
+ }), tagging.gender && /* @__PURE__ */ jsx("span", {
186
+ className: "gender",
187
+ children: tagging.gender
188
+ }), tagging.ageGroup && /* @__PURE__ */ jsx("span", {
189
+ className: "age_group",
190
+ children: tagging.ageGroup
191
+ }), tagging.gtin && /* @__PURE__ */ jsx("span", {
192
+ className: "gtin",
193
+ children: tagging.gtin
194
+ }), tagging.category && tagging.category.map((category, index) => /* @__PURE__ */ jsx("span", {
195
+ className: "category",
196
+ children: category
197
+ }, index)), tagging.tags1 && tagging.tags1.map((tag, index) => /* @__PURE__ */ jsx("span", {
198
+ className: "tag1",
199
+ children: tag
200
+ }, index)), tagging.tags2 && tagging.tags2.map((tag, index) => /* @__PURE__ */ jsx("span", {
201
+ className: "tag2",
202
+ children: tag
203
+ }, index)), tagging.tags3 && tagging.tags3.map((tag, index) => /* @__PURE__ */ jsx("span", {
204
+ className: "tag3",
205
+ children: tag
206
+ }, index)), tagging.ratingValue && /* @__PURE__ */ jsx("span", {
207
+ className: "rating_value",
208
+ children: tagging.ratingValue
209
+ }), tagging.reviewCount && /* @__PURE__ */ jsx("span", {
210
+ className: "review_count",
211
+ children: tagging.reviewCount
212
+ }), tagging.alternateImageUrls && tagging.alternateImageUrls.map((url, index) => /* @__PURE__ */ jsx("span", {
213
+ className: "alternate_image_url",
214
+ children: url.toString()
215
+ }, index)), tagging.customFields && Object.keys(tagging.customFields).map((field, index) => tagging.customFields && tagging.customFields[field] && /* @__PURE__ */ jsx("span", {
216
+ className: field,
217
+ children: tagging.customFields[field]
218
+ }, index)), tagging.skus && tagging.skus.map((sku, index) => /* @__PURE__ */ jsxs("span", {
219
+ className: "nosto_sku",
220
+ children: [sku.id && /* @__PURE__ */ jsx("span", {
221
+ className: "product_id",
222
+ children: sku.id
223
+ }), sku.name && /* @__PURE__ */ jsx("span", {
224
+ className: "name",
225
+ children: sku.name
226
+ }), sku.price && /* @__PURE__ */ jsx("span", {
227
+ className: "price",
228
+ children: sku.price
229
+ }), sku.listPrice && /* @__PURE__ */ jsx("span", {
230
+ className: "list_price",
231
+ children: sku.listPrice
232
+ }), sku.url && /* @__PURE__ */ jsx("span", {
233
+ className: "url",
234
+ children: sku.url.toString()
235
+ }), sku.imageUrl && /* @__PURE__ */ jsx("span", {
236
+ className: "image_url",
237
+ children: sku.imageUrl.toString()
238
+ }), sku.gtin && /* @__PURE__ */ jsx("span", {
239
+ className: "gtin",
240
+ children: sku.gtin
241
+ }), sku.availability && /* @__PURE__ */ jsx("span", {
242
+ className: "availability",
243
+ children: sku.availability
244
+ }), sku.customFields && Object.keys(sku.customFields).map((field, index2) => sku.customFields && sku.customFields[field] && /* @__PURE__ */ jsx("span", {
245
+ className: field,
246
+ children: sku.customFields[field]
247
+ }, index2))]
248
+ }, index))]
249
+ })]
250
+ });
251
+ };
252
+ const NostoCategory = ({
253
+ category
254
+ }) => {
255
+ useEffect(() => {
256
+ window.nostojs((api) => {
257
+ api.defaultSession().setResponseMode("HTML").viewCategory(category).setPlacements(api.placements.getPlacements()).load().then((data) => {
258
+ api.placements.injectCampaigns(data.recommendations);
259
+ });
260
+ });
261
+ }, []);
262
+ return /* @__PURE__ */ jsxs(Fragment, {
263
+ children: [/* @__PURE__ */ jsx("div", {
264
+ className: "nosto_page_type",
265
+ style: {
266
+ display: "none"
267
+ },
268
+ children: "category"
269
+ }), /* @__PURE__ */ jsx("div", {
270
+ className: "nosto_category",
271
+ style: {
272
+ display: "none"
273
+ },
274
+ children: category
275
+ })]
276
+ });
277
+ };
278
+ const NostoSearch = ({
279
+ query
280
+ }) => {
281
+ useEffect(() => {
282
+ window.nostojs((api) => {
283
+ api.defaultSession().setResponseMode("HTML").viewSearch(query).setPlacements(api.placements.getPlacements()).load().then((data) => {
284
+ api.placements.injectCampaigns(data.recommendations);
285
+ });
286
+ });
287
+ }, []);
288
+ return /* @__PURE__ */ jsxs(Fragment, {
289
+ children: [/* @__PURE__ */ jsx("div", {
290
+ className: "nosto_page_type",
291
+ style: {
292
+ display: "none"
293
+ },
294
+ children: "search"
295
+ }), /* @__PURE__ */ jsx("div", {
296
+ className: "nosto_search",
297
+ style: {
298
+ display: "none"
299
+ },
300
+ children: query
301
+ })]
302
+ });
303
+ };
304
+ const NostoOrder = ({
305
+ order
306
+ }) => {
307
+ useEffect(() => {
308
+ window.nostojs((api) => {
309
+ api.defaultSession().setResponseMode("HTML").addOrder(snakeize(order)).setPlacements(api.placements.getPlacements()).load().then((data) => {
310
+ api.placements.injectCampaigns(data.recommendations);
311
+ });
312
+ });
313
+ }, []);
314
+ return /* @__PURE__ */ jsxs(Fragment, {
315
+ children: [/* @__PURE__ */ jsx("div", {
316
+ className: "nosto_page_type",
317
+ style: {
318
+ display: "none"
319
+ },
320
+ children: "order"
321
+ }), /* @__PURE__ */ jsx("div", {
322
+ className: "nosto_order",
323
+ style: {
324
+ display: "none"
325
+ },
326
+ children: order.purchase.number
327
+ })]
328
+ });
329
+ };
330
+ const NostoHome = () => {
331
+ useEffect(() => {
332
+ window.nostojs((api) => {
333
+ api.defaultSession().setResponseMode("HTML").viewFrontPage().setPlacements(api.placements.getPlacements()).load().then((data) => {
334
+ api.placements.injectCampaigns(data.recommendations);
335
+ });
336
+ });
337
+ }, []);
338
+ return /* @__PURE__ */ jsx(Fragment, {
339
+ children: /* @__PURE__ */ jsx("div", {
340
+ className: "nosto_page_type",
341
+ style: {
342
+ display: "none"
343
+ },
344
+ children: "front"
345
+ })
346
+ });
347
+ };
348
+ const NostoPlacement = ({
349
+ id
350
+ }) => {
351
+ const handleClick = (e) => {
352
+ const targetLink = e.target.closest("a");
353
+ if (!targetLink) {
354
+ return;
355
+ } else {
356
+ e.preventDefault();
357
+ location.href = targetLink.href.toString().replace(new URL(targetLink.href).origin, "");
358
+ }
359
+ };
360
+ return /* @__PURE__ */ jsx("div", {
361
+ className: "nosto_element",
362
+ onClick: handleClick,
363
+ id
364
+ });
365
+ };
366
+ const NostoContext = createContext({
367
+ account: void 0
368
+ });
369
+ const NostoProvider = ({
370
+ account,
371
+ host,
372
+ children
373
+ }) => {
374
+ useEffect(() => {
375
+ const script = document.createElement("script");
376
+ script.type = "text/javascript";
377
+ script.src = "//" + (host || "connect.nosto.com") + "/include/" + account;
378
+ script.async = true;
379
+ document.head.appendChild(script);
380
+ window.nostojs = (cb) => (window.nostojs.q = window.nostojs.q || []).push(cb);
381
+ window.nostojs((api) => api.setAutoLoad(false));
382
+ }, []);
383
+ return /* @__PURE__ */ jsx(NostoContext.Provider, {
384
+ value: {
385
+ account
386
+ },
387
+ children
388
+ });
389
+ };
390
+ var has = Object.prototype.hasOwnProperty;
391
+ function find(iter, tar, key) {
392
+ for (key of iter.keys()) {
393
+ if (dequal(key, tar))
394
+ return key;
395
+ }
396
+ }
397
+ function dequal(foo, bar) {
398
+ var ctor, len, tmp;
399
+ if (foo === bar)
400
+ return true;
401
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
402
+ if (ctor === Date)
403
+ return foo.getTime() === bar.getTime();
404
+ if (ctor === RegExp)
405
+ return foo.toString() === bar.toString();
406
+ if (ctor === Array) {
407
+ if ((len = foo.length) === bar.length) {
408
+ while (len-- && dequal(foo[len], bar[len]))
409
+ ;
410
+ }
411
+ return len === -1;
412
+ }
413
+ if (ctor === Set) {
414
+ if (foo.size !== bar.size) {
415
+ return false;
416
+ }
417
+ for (len of foo) {
418
+ tmp = len;
419
+ if (tmp && typeof tmp === "object") {
420
+ tmp = find(bar, tmp);
421
+ if (!tmp)
422
+ return false;
423
+ }
424
+ if (!bar.has(tmp))
425
+ return false;
426
+ }
427
+ return true;
428
+ }
429
+ if (ctor === Map) {
430
+ if (foo.size !== bar.size) {
431
+ return false;
432
+ }
433
+ for (len of foo) {
434
+ tmp = len[0];
435
+ if (tmp && typeof tmp === "object") {
436
+ tmp = find(bar, tmp);
437
+ if (!tmp)
438
+ return false;
439
+ }
440
+ if (!dequal(len[1], bar.get(tmp))) {
441
+ return false;
442
+ }
443
+ }
444
+ return true;
445
+ }
446
+ if (ctor === ArrayBuffer) {
447
+ foo = new Uint8Array(foo);
448
+ bar = new Uint8Array(bar);
449
+ } else if (ctor === DataView) {
450
+ if ((len = foo.byteLength) === bar.byteLength) {
451
+ while (len-- && foo.getInt8(len) === bar.getInt8(len))
452
+ ;
453
+ }
454
+ return len === -1;
455
+ }
456
+ if (ArrayBuffer.isView(foo)) {
457
+ if ((len = foo.byteLength) === bar.byteLength) {
458
+ while (len-- && foo[len] === bar[len])
459
+ ;
460
+ }
461
+ return len === -1;
462
+ }
463
+ if (!ctor || typeof foo === "object") {
464
+ len = 0;
465
+ for (ctor in foo) {
466
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
467
+ return false;
468
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
469
+ return false;
470
+ }
471
+ return Object.keys(bar).length === len;
472
+ }
473
+ }
474
+ return foo !== foo && bar !== bar;
475
+ }
476
+ function useDeepCompareMemoize(value) {
477
+ var ref = React.useRef(value);
478
+ var signalRef = React.useRef(0);
479
+ if (!dequal(value, ref.current)) {
480
+ ref.current = value;
481
+ signalRef.current += 1;
482
+ }
483
+ return React.useMemo(function() {
484
+ return ref.current;
485
+ }, [signalRef.current]);
486
+ }
487
+ function useDeepCompareEffect(callback, dependencies) {
488
+ return React.useEffect(callback, useDeepCompareMemoize(dependencies));
489
+ }
490
+ const NostoSession = ({
491
+ cart,
492
+ customer
493
+ }) => {
494
+ useDeepCompareEffect(() => {
495
+ const currentUser = customer ? customer : void 0;
496
+ console.debug(currentUser);
497
+ const currentCart = cart ? cart : void 0;
498
+ console.debug(currentCart);
499
+ window.nostojs((api) => {
500
+ api.defaultSession().setResponseMode("HTML").setCart(snakeize(currentCart)).viewOther().load();
501
+ });
502
+ }, [cart || [], customer || {}]);
503
+ return /* @__PURE__ */ jsx("div", {});
504
+ };
505
+ export { NostoFohofo as Nosto404, NostoCategory, NostoCheckout, NostoHome, NostoOrder, NostoOther, NostoPlacement, NostoProduct, NostoProvider, NostoSearch, NostoSession };
@@ -0,0 +1,9 @@
1
+ (function(c,a){typeof exports=="object"&&typeof module!="undefined"?a(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],a):(c=typeof globalThis!="undefined"?globalThis:c||self,a(c["@nosto/nosto-react"]={},c.React))})(this,function(c,a){"use strict";function P(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}function j(t){if(t&&t.__esModule)return t;var e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return t&&Object.keys(t).forEach(function(s){if(s!=="default"){var n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:function(){return t[s]}})}}),e.default=t,Object.freeze(e)}var C=P(a),m=j(a),p={exports:{}},f={};/**
2
+ * @license React
3
+ * react-jsx-runtime.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var S=C.default,O=Symbol.for("react.element"),M=Symbol.for("react.fragment"),L=Object.prototype.hasOwnProperty,E=S.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,T={key:!0,ref:!0,__self:!0,__source:!0};function N(t,e,s){var n,o={},d=null,h=null;s!==void 0&&(d=""+s),e.key!==void 0&&(d=""+e.key),e.ref!==void 0&&(h=e.ref);for(n in e)L.call(e,n)&&!T.hasOwnProperty(n)&&(o[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)o[n]===void 0&&(o[n]=e[n]);return{$$typeof:O,type:t,key:d,ref:h,props:o,_owner:E.current}}f.Fragment=M,f.jsx=N,f.jsxs=N,p.exports=f;const r=p.exports.jsx,i=p.exports.jsxs,l=p.exports.Fragment,F=()=>(a.useEffect(()=>{window.nostojs(t=>{t.defaultSession().setResponseMode("HTML").viewNotFound().setPlacements(t.placements.getPlacements()).load().then(e=>{t.placements.injectCampaigns(e.recommendations)})})},[]),r(l,{children:r("div",{className:"nosto_page_type",style:{display:"none"},children:"notfound"})})),R=()=>(a.useEffect(()=>{window.nostojs(t=>{t.defaultSession().setResponseMode("HTML").viewOther().setPlacements(t.placements.getPlacements()).load().then(e=>{t.placements.injectCampaigns(e.recommendations)})})},[]),r(l,{children:r("div",{className:"nosto_page_type",style:{display:"none"},children:"other"})})),U=()=>(a.useEffect(()=>{window.nostojs(t=>{t.defaultSession().setResponseMode("HTML").viewCart().setPlacements(t.placements.getPlacements()).load().then(e=>{t.placements.injectCampaigns(e.recommendations)})})},[]),r(l,{children:r("div",{className:"nosto_page_type",style:{display:"none"},children:"cart"})}));function v(t){return Object.keys(t).forEach(e=>{t[e]instanceof URL&&(t[e]=t[e].toString()),typeof t[e]=="object"&&v(t[e]),t[e]=t[e]}),t}var y=function t(e){return!e||typeof e!="object"||x(e)||D(e)?e:Array.isArray(e)?e.map(t):Object.keys(e).reduce(function(s,n){var o=n[0].toLowerCase()+n.slice(1).replace(/([A-Z]+)/g,function(d,h){return"_"+h.toLowerCase()});return s[o]=t(e[n]),s},{})},x=function(t){return Object.prototype.toString.call(t)==="[object Date]"},D=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"};const H=({product:t,tagging:e})=>(a.useEffect(()=>{window.nostojs(s=>{s.defaultSession().setResponseMode("HTML").viewProduct(y(v(e))).setPlacements(s.placements.getPlacements()).load().then(n=>{s.placements.injectCampaigns(n.recommendations)})})},[]),i(l,{children:[r("div",{className:"nosto_page_type",style:{display:"none"},children:"product"}),i("div",{className:"nosto_product",style:{display:"none"},children:[e.variationId&&r("span",{className:"variation_id",children:e.variationId}),e.productId&&r("span",{className:"product_id",children:e.productId}),e.name&&r("span",{className:"name",children:e.name}),e.url&&r("span",{className:"url",children:e.url.toString()}),e.imageUrl&&r("span",{className:"image_url",children:e.imageUrl.toString()}),e.availability&&r("span",{className:"availability",children:e.availability}),e.price&&r("span",{className:"price",children:e.price}),e.listPrice&&r("span",{className:"list_price",children:e.listPrice}),e.priceCurrencyCode&&r("span",{className:"price_currency_code",children:e.priceCurrencyCode}),e.brand&&r("span",{className:"brand",children:e.brand}),e.description&&r("span",{className:"description",children:e.description}),e.googleCategory&&r("span",{className:"description",children:e.googleCategory}),e.condition&&r("span",{className:"condition",children:e.condition}),e.gender&&r("span",{className:"gender",children:e.gender}),e.ageGroup&&r("span",{className:"age_group",children:e.ageGroup}),e.gtin&&r("span",{className:"gtin",children:e.gtin}),e.category&&e.category.map((s,n)=>r("span",{className:"category",children:s},n)),e.tags1&&e.tags1.map((s,n)=>r("span",{className:"tag1",children:s},n)),e.tags2&&e.tags2.map((s,n)=>r("span",{className:"tag2",children:s},n)),e.tags3&&e.tags3.map((s,n)=>r("span",{className:"tag3",children:s},n)),e.ratingValue&&r("span",{className:"rating_value",children:e.ratingValue}),e.reviewCount&&r("span",{className:"review_count",children:e.reviewCount}),e.alternateImageUrls&&e.alternateImageUrls.map((s,n)=>r("span",{className:"alternate_image_url",children:s.toString()},n)),e.customFields&&Object.keys(e.customFields).map((s,n)=>e.customFields&&e.customFields[s]&&r("span",{className:s,children:e.customFields[s]},n)),e.skus&&e.skus.map((s,n)=>i("span",{className:"nosto_sku",children:[s.id&&r("span",{className:"product_id",children:s.id}),s.name&&r("span",{className:"name",children:s.name}),s.price&&r("span",{className:"price",children:s.price}),s.listPrice&&r("span",{className:"list_price",children:s.listPrice}),s.url&&r("span",{className:"url",children:s.url.toString()}),s.imageUrl&&r("span",{className:"image_url",children:s.imageUrl.toString()}),s.gtin&&r("span",{className:"gtin",children:s.gtin}),s.availability&&r("span",{className:"availability",children:s.availability}),s.customFields&&Object.keys(s.customFields).map((o,d)=>s.customFields&&s.customFields[o]&&r("span",{className:o,children:s.customFields[o]},d))]},n))]})]})),I=({category:t})=>(a.useEffect(()=>{window.nostojs(e=>{e.defaultSession().setResponseMode("HTML").viewCategory(t).setPlacements(e.placements.getPlacements()).load().then(s=>{e.placements.injectCampaigns(s.recommendations)})})},[]),i(l,{children:[r("div",{className:"nosto_page_type",style:{display:"none"},children:"category"}),r("div",{className:"nosto_category",style:{display:"none"},children:t})]})),A=({query:t})=>(a.useEffect(()=>{window.nostojs(e=>{e.defaultSession().setResponseMode("HTML").viewSearch(t).setPlacements(e.placements.getPlacements()).load().then(s=>{e.placements.injectCampaigns(s.recommendations)})})},[]),i(l,{children:[r("div",{className:"nosto_page_type",style:{display:"none"},children:"search"}),r("div",{className:"nosto_search",style:{display:"none"},children:t})]})),z=({order:t})=>(a.useEffect(()=>{window.nostojs(e=>{e.defaultSession().setResponseMode("HTML").addOrder(y(t)).setPlacements(e.placements.getPlacements()).load().then(s=>{e.placements.injectCampaigns(s.recommendations)})})},[]),i(l,{children:[r("div",{className:"nosto_page_type",style:{display:"none"},children:"order"}),r("div",{className:"nosto_order",style:{display:"none"},children:t.purchase.number})]})),b=()=>(a.useEffect(()=>{window.nostojs(t=>{t.defaultSession().setResponseMode("HTML").viewFrontPage().setPlacements(t.placements.getPlacements()).load().then(e=>{t.placements.injectCampaigns(e.recommendations)})})},[]),r(l,{children:r("div",{className:"nosto_page_type",style:{display:"none"},children:"front"})})),q=({id:t})=>r("div",{className:"nosto_element",onClick:s=>{const n=s.target.closest("a");if(n)s.preventDefault(),location.href=n.href.toString().replace(new URL(n.href).origin,"");else return},id:t}),V=a.createContext({account:void 0}),B=({account:t,host:e,children:s})=>(a.useEffect(()=>{const n=document.createElement("script");n.type="text/javascript",n.src="//"+(e||"connect.nosto.com")+"/include/"+t,n.async=!0,document.head.appendChild(n),window.nostojs=o=>(window.nostojs.q=window.nostojs.q||[]).push(o),window.nostojs(o=>o.setAutoLoad(!1))},[]),r(V.Provider,{value:{account:t},children:s}));var _=Object.prototype.hasOwnProperty;function w(t,e,s){for(s of t.keys())if(u(s,e))return s}function u(t,e){var s,n,o;if(t===e)return!0;if(t&&e&&(s=t.constructor)===e.constructor){if(s===Date)return t.getTime()===e.getTime();if(s===RegExp)return t.toString()===e.toString();if(s===Array){if((n=t.length)===e.length)for(;n--&&u(t[n],e[n]););return n===-1}if(s===Set){if(t.size!==e.size)return!1;for(n of t)if(o=n,o&&typeof o=="object"&&(o=w(e,o),!o)||!e.has(o))return!1;return!0}if(s===Map){if(t.size!==e.size)return!1;for(n of t)if(o=n[0],o&&typeof o=="object"&&(o=w(e,o),!o)||!u(n[1],e.get(o)))return!1;return!0}if(s===ArrayBuffer)t=new Uint8Array(t),e=new Uint8Array(e);else if(s===DataView){if((n=t.byteLength)===e.byteLength)for(;n--&&t.getInt8(n)===e.getInt8(n););return n===-1}if(ArrayBuffer.isView(t)){if((n=t.byteLength)===e.byteLength)for(;n--&&t[n]===e[n];);return n===-1}if(!s||typeof t=="object"){n=0;for(s in t)if(_.call(t,s)&&++n&&!_.call(e,s)||!(s in e)||!u(t[s],e[s]))return!1;return Object.keys(e).length===n}}return t!==t&&e!==e}function G(t){var e=m.useRef(t),s=m.useRef(0);return u(t,e.current)||(e.current=t,s.current+=1),m.useMemo(function(){return e.current},[s.current])}function $(t,e){return m.useEffect(t,G(e))}const J=({cart:t,customer:e})=>($(()=>{console.debug(e||void 0);const n=t||void 0;console.debug(n),window.nostojs(o=>{o.defaultSession().setResponseMode("HTML").setCart(y(n)).viewOther().load()})},[t||[],e||{}]),r("div",{}));c.Nosto404=F,c.NostoCategory=I,c.NostoCheckout=U,c.NostoHome=b,c.NostoOrder=z,c.NostoOther=R,c.NostoPlacement=q,c.NostoProduct=H,c.NostoProvider=B,c.NostoSearch=A,c.NostoSession=J,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@nosto/nosto-react",
3
+ "description": "Component library to simply implementing Nosto on React.",
4
+ "version": "0.1.0",
5
+ "author": "Mridang Agarwalla, Dominik Gilg",
6
+ "license": "ISC",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Nosto/nosto-react.git"
10
+ },
11
+ "keywords": [
12
+ "nosto",
13
+ "personalisation"
14
+ ],
15
+ "scripts": {
16
+ "dev": "vite",
17
+ "build": "tsc && vite build",
18
+ "preview": "vite preview",
19
+ "prepare": "vite build",
20
+ "typecheck": "tsc",
21
+ "tslint": "tslint 'src/**/*.ts?(x)'",
22
+ "clean": "rimraf dist",
23
+ "prettier": "prettier '*/**/*.{ts,tsx,js,jsx,html,css,less}' --list-different",
24
+ "prettier:fix": "prettier '*/**/*.{ts,tsx,js,jsx,html,css,less}' --write"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "src"
29
+ ],
30
+ "dependencies": {
31
+ "react": "^18.0.0",
32
+ "react-dom": "^18.0.0",
33
+ "snakeize": "^0.1.0",
34
+ "use-deep-compare-effect": "^1.3.1",
35
+ "react-router": "^6.3.0",
36
+ "react-router-dom": "^6.3.0",
37
+ "@vitejs/plugin-react": "^1.3.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/react": "^18.0.0",
41
+ "@types/react-dom": "^18.0.0",
42
+ "vite": "^2.9.9",
43
+ "typescript": "^4.6.3",
44
+ "prettier": "^2.0.5",
45
+ "rimraf": "^3.0.2"
46
+ },
47
+ "main": "./dist/index.es.client.js",
48
+ "module": "./dist/index.es.client.js",
49
+ "types": "./src/types.ts",
50
+ "exports": {
51
+ ".": {
52
+ "import": "./dist/index.es.client.js",
53
+ "require": "./dist/index.umd.client.js"
54
+ }
55
+ },
56
+ "bugs": {
57
+ "url": "https://github.com/Nosto/nosto-react/issues"
58
+ },
59
+ "homepage": "https://github.com/Nosto/nosto-react#readme"
60
+ }
@@ -0,0 +1,32 @@
1
+ import React, { useEffect } from "react";
2
+
3
+ const NostoCategory: React.FC<{ category: string }> = ({ category }) => {
4
+ useEffect(() => {
5
+ // @ts-ignore
6
+ window.nostojs((api) => {
7
+ api
8
+ .defaultSession()
9
+ .setResponseMode("HTML")
10
+ .viewCategory(category)
11
+ .setPlacements(api.placements.getPlacements())
12
+ .load()
13
+ .then((data: object) => {
14
+ // @ts-ignore
15
+ api.placements.injectCampaigns(data.recommendations);
16
+ });
17
+ });
18
+ }, []);
19
+
20
+ return (
21
+ <>
22
+ <div className="nosto_page_type" style={{ display: "none" }}>
23
+ category
24
+ </div>
25
+ <div className="nosto_category" style={{ display: "none" }}>
26
+ {category}
27
+ </div>
28
+ </>
29
+ );
30
+ };
31
+
32
+ export default NostoCategory;
@@ -0,0 +1,29 @@
1
+ import React, { useEffect } from "react";
2
+
3
+ const NostoCheckout: React.FC = () => {
4
+ useEffect(() => {
5
+ // @ts-ignore
6
+ window.nostojs((api) => {
7
+ api
8
+ .defaultSession()
9
+ .setResponseMode("HTML")
10
+ .viewCart()
11
+ .setPlacements(api.placements.getPlacements())
12
+ .load()
13
+ .then((data: object) => {
14
+ // @ts-ignore
15
+ api.placements.injectCampaigns(data.recommendations);
16
+ });
17
+ });
18
+ }, []);
19
+
20
+ return (
21
+ <>
22
+ <div className="nosto_page_type" style={{ display: "none" }}>
23
+ cart
24
+ </div>
25
+ </>
26
+ );
27
+ };
28
+
29
+ export default NostoCheckout;
@@ -0,0 +1,29 @@
1
+ import React, { useEffect } from "react";
2
+
3
+ const NostoFohofo: React.FC = () => {
4
+ useEffect(() => {
5
+ // @ts-ignore
6
+ window.nostojs((api) => {
7
+ api
8
+ .defaultSession()
9
+ .setResponseMode("HTML")
10
+ .viewNotFound()
11
+ .setPlacements(api.placements.getPlacements())
12
+ .load()
13
+ .then((data: object) => {
14
+ // @ts-ignore
15
+ api.placements.injectCampaigns(data.recommendations);
16
+ });
17
+ });
18
+ }, []);
19
+
20
+ return (
21
+ <>
22
+ <div className="nosto_page_type" style={{ display: "none" }}>
23
+ notfound
24
+ </div>
25
+ </>
26
+ );
27
+ };
28
+
29
+ export default NostoFohofo;