@nosto/nosto-react 0.4.3 → 1.0.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/README.md +1 -6
- package/dist/index.d.ts +1201 -0
- package/dist/index.es.js +872 -564
- package/dist/index.umd.js +18 -2
- package/package.json +8 -6
- package/src/components/Nosto404.tsx +1 -8
- package/src/components/NostoCategory.tsx +1 -11
- package/src/components/NostoCheckout.tsx +1 -9
- package/src/components/NostoHome.tsx +1 -8
- package/src/components/NostoOrder.tsx +3 -13
- package/src/components/NostoOther.tsx +1 -8
- package/src/components/NostoProduct.tsx +3 -95
- package/src/components/NostoSearch.tsx +1 -11
- package/src/components/NostoSession.tsx +2 -2
- package/src/components/context.ts +2 -2
- package/src/index.ts +1 -2
- package/src/types.ts +792 -101
- package/src/utils/hooks.ts +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(C,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client"],h):(C=typeof globalThis<"u"?globalThis:C||self,h(C["@nosto/nosto-react"]={},C.React,C.ReactDOM))})(this,function(C,h,He){"use strict";const ne=h.createContext({account:"",currentVariation:"",pageType:"",responseMode:"HTML",clientScriptLoaded:!1,useRenderCampaigns:()=>({renderCampaigns:()=>{},pageTypeUpdated:!1})});function x(){const n=h.useContext(ne);if(!n)throw new Error("No nosto context found");return n}const ge=n=>String(n)==="[object Object]";function ye(n){if(!ge(n))return!1;const o=n.constructor;if(o===void 0)return!0;const a=o.prototype;return!(!ge(a)||!a.hasOwnProperty("isPrototypeOf"))}function oe(n,o){if(n===o)return!0;if(n instanceof Date&&o instanceof Date)return n.getTime()===o.getTime();if(n instanceof Array&&o instanceof Array)return n.length!==o.length?!1:n.every((a,u)=>oe(a,o[u]));if(ye(n)&&ye(o)){const a=Object.entries(n);return a.length!==Object.keys(o).length?!1:a.every(([u,d])=>oe(d,o[u]))}return!1}function he(n,o){return h.useEffect(n,Je(o))}function Je(n){const o=h.useRef(n),a=h.useRef(0);return oe(n,o.current)||(o.current=n,a.current+=1),h.useMemo(()=>o.current,[a.current])}function L(n,o,a){const{clientScriptLoaded:u,currentVariation:d,responseMode:c}=x();(a!=null&&a.deep?he:h.useEffect)(()=>{u&&window.nostojs(p=>{p.defaultSession().setVariation(d).setResponseMode(c),n(p)})},[u,d,c,...o??[]])}function ze(n){const{recommendationComponent:o,useRenderCampaigns:a}=x(),{renderCampaigns:u,pageTypeUpdated:d}=a("404");return L(async c=>{const i=await c.defaultSession().viewNotFound().setPlacements(n.placements||c.placements.getPlacements()).load();u(i,c)},[o,d]),null}function Ge(n){const{recommendationComponent:o,useRenderCampaigns:a}=x(),{renderCampaigns:u,pageTypeUpdated:d}=a("other");return L(async c=>{const i=await c.defaultSession().viewOther().setPlacements(n.placements||c.placements.getPlacements()).load();u(i,c)},[o,d]),null}function Ke(n){const{recommendationComponent:o,useRenderCampaigns:a}=x(),{renderCampaigns:u,pageTypeUpdated:d}=a("checkout");return L(async c=>{const i=await c.defaultSession().viewCart().setPlacements(n.placements||c.placements.getPlacements()).load();u(i,c)},[o,d]),null}function Xe(n){const{product:o,tagging:a,placements:u}=n,{recommendationComponent:d,useRenderCampaigns:c}=x(),{renderCampaigns:i,pageTypeUpdated:p}=c("product");return L(async v=>{const N=await v.defaultSession().viewProduct(a??o).setPlacements(u||v.placements.getPlacements()).load();i(N,v)},[o,d,p],{deep:!0}),null}function Ze(n){const{category:o,placements:a}=n,{recommendationComponent:u,useRenderCampaigns:d}=x(),{renderCampaigns:c,pageTypeUpdated:i}=d("home");return L(async p=>{const v=await p.defaultSession().viewCategory(o).setPlacements(a||p.placements.getPlacements()).load();c(v,p)},[o,u,i]),null}function Qe(n){const{query:o,placements:a}=n,{recommendationComponent:u,useRenderCampaigns:d}=x(),{renderCampaigns:c,pageTypeUpdated:i}=d("search");return L(async p=>{const v=await p.defaultSession().viewSearch(o).setPlacements(a||p.placements.getPlacements()).load();c(v,p)},[o,u,i]),null}function M(n){return!n||typeof n!="object"||et(n)||tt(n)?n:Array.isArray(n)?n.map(M):Object.keys(n).reduce((o,a)=>{const u=a[0].toLowerCase()+a.slice(1).replace(/([A-Z]+)/g,(d,c)=>"_"+c.toLowerCase());return o[u]=M(n[a]),o},{})}function et(n){return Object.prototype.toString.call(n)==="[object Date]"}function tt(n){return Object.prototype.toString.call(n)==="[object RegExp]"}function rt(n){const{order:o,placements:a}=n,{recommendationComponent:u,useRenderCampaigns:d}=x(),{renderCampaigns:c,pageTypeUpdated:i}=d("order");return L(async p=>{const v=await p.defaultSession().addOrder(M(o)).setPlacements(a||p.placements.getPlacements()).load();c(v,p)},[u,i]),null}function nt(n){const{recommendationComponent:o,useRenderCampaigns:a}=x(),{renderCampaigns:u,pageTypeUpdated:d}=a("home");return L(async c=>{const i=await c.defaultSession().viewFrontPage().setPlacements(n.placements||c.placements.getPlacements()).load();u(i,c)},[o,d]),null}var ae={exports:{}},q={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,20 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var G=T.default,z=Symbol.for("react.element"),J=Symbol.for("react.fragment"),W=Object.prototype.hasOwnProperty,B=G.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Y={key:!0,ref:!0,__self:!0,__source:!0};function D(t,n,e){var a,i={},c=null,r=null;e!==void 0&&(c=""+e),n.key!==void 0&&(c=""+n.key),n.ref!==void 0&&(r=n.ref);for(a in n)W.call(n,a)&&!Y.hasOwnProperty(a)&&(i[a]=n[a]);if(t&&t.defaultProps)for(a in n=t.defaultProps,n)i[a]===void 0&&(i[a]=n[a]);return{$$typeof:z,type:t,key:c,ref:r,props:i,_owner:B.current}}b.Fragment=J,b.jsx=D,b.jsxs=D,R.exports=b;const s=R.exports.jsx,v=R.exports.jsxs,N=R.exports.Fragment;function Z(t){const{recommendationComponent:n,useRenderCampaigns:e}=f(),{renderCampaigns:a,pageTypeUpdated:i}=e("404");return C(async c=>{const r=await c.defaultSession().viewNotFound().setPlacements(t.placements||c.placements.getPlacements()).load();a(r,c)},[n,i]),s(N,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"notfound"})})}function K(t){const{recommendationComponent:n,useRenderCampaigns:e}=f(),{renderCampaigns:a,pageTypeUpdated:i}=e("other");return C(async c=>{const r=await c.defaultSession().viewOther().setPlacements(t.placements||c.placements.getPlacements()).load();a(r,c)},[n,i]),s(N,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"other"})})}function Q(t){const{recommendationComponent:n,useRenderCampaigns:e}=f(),{renderCampaigns:a,pageTypeUpdated:i}=e("checkout");return C(async c=>{const r=await c.defaultSession().viewCart().setPlacements(t.placements||c.placements.getPlacements()).load();a(r,c)},[n,i]),s(N,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"cart"})})}function X(t){const{product:n,tagging:e,placements:a}=t,{recommendationComponent:i,useRenderCampaigns:c}=f(),{renderCampaigns:r,pageTypeUpdated:d}=c("product");return C(async o=>{const u=await o.defaultSession().viewProduct(n).setPlacements(a||o.placements.getPlacements()).load();r(u,o)},[n,i,d],{deep:!0}),v(N,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"product"}),v("div",{className:"nosto_product",style:{display:"none"},children:[(e==null?void 0:e.variationId)&&s("span",{className:"variation_id",children:e.variationId}),n&&s("span",{className:"product_id",children:n}),(e==null?void 0:e.name)&&s("span",{className:"name",children:e.name}),(e==null?void 0:e.url)&&s("span",{className:"url",children:e.url.toString()}),(e==null?void 0:e.imageUrl)&&s("span",{className:"image_url",children:e.imageUrl.toString()}),(e==null?void 0:e.availability)&&s("span",{className:"availability",children:e.availability}),(e==null?void 0:e.price)&&s("span",{className:"price",children:e.price}),(e==null?void 0:e.listPrice)&&s("span",{className:"list_price",children:e.listPrice}),(e==null?void 0:e.priceCurrencyCode)&&s("span",{className:"price_currency_code",children:e.priceCurrencyCode}),(e==null?void 0:e.brand)&&s("span",{className:"brand",children:e.brand}),(e==null?void 0:e.description)&&s("span",{className:"description",children:e.description}),(e==null?void 0:e.googleCategory)&&s("span",{className:"description",children:e.googleCategory}),(e==null?void 0:e.condition)&&s("span",{className:"condition",children:e.condition}),(e==null?void 0:e.gender)&&s("span",{className:"gender",children:e.gender}),(e==null?void 0:e.ageGroup)&&s("span",{className:"age_group",children:e.ageGroup}),(e==null?void 0:e.gtin)&&s("span",{className:"gtin",children:e.gtin}),(e==null?void 0:e.category)&&(e==null?void 0:e.category.map((o,u)=>s("span",{className:"category",children:o},u))),(e==null?void 0:e.tags1)&&e.tags1.map((o,u)=>s("span",{className:"tag1",children:o},u)),(e==null?void 0:e.tags2)&&e.tags2.map((o,u)=>s("span",{className:"tag2",children:o},u)),(e==null?void 0:e.tags3)&&e.tags3.map((o,u)=>s("span",{className:"tag3",children:o},u)),(e==null?void 0:e.ratingValue)&&s("span",{className:"rating_value",children:e.ratingValue}),(e==null?void 0:e.reviewCount)&&s("span",{className:"review_count",children:e.reviewCount}),(e==null?void 0:e.alternateImageUrls)&&e.alternateImageUrls.map((o,u)=>s("span",{className:"alternate_image_url",children:o.toString()},u)),(e==null?void 0:e.customFields)&&Object.keys(e.customFields).map((o,u)=>e.customFields&&e.customFields[o]&&s("span",{className:o,children:e.customFields[o]},u)),(e==null?void 0:e.skus)&&e.skus.map((o,u)=>v("span",{className:"nosto_sku",children:[(o==null?void 0:o.id)&&s("span",{className:"product_id",children:o.id}),(o==null?void 0:o.name)&&s("span",{className:"name",children:o.name}),(o==null?void 0:o.price)&&s("span",{className:"price",children:o.price}),(o==null?void 0:o.listPrice)&&s("span",{className:"list_price",children:o.listPrice}),(o==null?void 0:o.url)&&s("span",{className:"url",children:o.url.toString()}),(o==null?void 0:o.imageUrl)&&s("span",{className:"image_url",children:o.imageUrl.toString()}),(o==null?void 0:o.gtin)&&s("span",{className:"gtin",children:o.gtin}),(o==null?void 0:o.availability)&&s("span",{className:"availability",children:o.availability}),(o==null?void 0:o.customFields)&&Object.keys(o.customFields).map((P,E)=>o.customFields&&o.customFields[P]&&s("span",{className:P,children:o.customFields[P]},E))]},u))]})]})}function g(t){const{category:n,placements:e}=t,{recommendationComponent:a,useRenderCampaigns:i}=f(),{renderCampaigns:c,pageTypeUpdated:r}=i("home");return C(async d=>{const o=await d.defaultSession().viewCategory(n).setPlacements(e||d.placements.getPlacements()).load();c(o,d)},[n,a,r]),v(N,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"category"}),s("div",{className:"nosto_category",style:{display:"none"},children:n})]})}function k(t){const{query:n,placements:e}=t,{recommendationComponent:a,useRenderCampaigns:i}=f(),{renderCampaigns:c,pageTypeUpdated:r}=i("search");return C(async d=>{const o=await d.defaultSession().viewSearch(n).setPlacements(e||d.placements.getPlacements()).load();c(o,d)},[n,a,r]),v(N,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"search"}),s("div",{className:"nosto_search",style:{display:"none"},children:n})]})}function S(t){return!t||typeof t!="object"||ee(t)||te(t)?t:Array.isArray(t)?t.map(S):Object.keys(t).reduce((n,e)=>{const a=e[0].toLowerCase()+e.slice(1).replace(/([A-Z]+)/g,(i,c)=>"_"+c.toLowerCase());return n[a]=S(t[e]),n},{})}function ee(t){return Object.prototype.toString.call(t)==="[object Date]"}function te(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function ne(t){const{order:n,placements:e}=t,{recommendationComponent:a,useRenderCampaigns:i}=f(),{renderCampaigns:c,pageTypeUpdated:r}=i("order");return C(async d=>{const o=await d.defaultSession().addOrder(S(n)).setPlacements(e||d.placements.getPlacements()).load();c(o,d)},[a,r]),v(N,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"order"}),s("div",{className:"nosto_order",style:{display:"none"},children:n.purchase.number})]})}function oe(t){const{recommendationComponent:n,useRenderCampaigns:e}=f(),{renderCampaigns:a,pageTypeUpdated:i}=e("home");return C(async c=>{const r=await c.defaultSession().viewFrontPage().setPlacements(t.placements||c.placements.getPlacements()).load();a(r,c)},[n,i]),s(N,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"front"})})}function se(t){const{id:n,pageType:e}=t;return s("div",{className:"nosto_element",id:n},n+(e||""))}function re(t){const{account:n,multiCurrency:e=!1,host:a,children:i,recommendationComponent:c,shopifyMarkets:r}=t,[d,o]=T.default.useState(!1),u=T.default.useMemo(()=>d,[d]),P=e?t.currentVariation:"",E=p.isValidElement(c)?"JSON_ORIGINAL":"HTML";function ce(_){return T.default.cloneElement(c,{nostoRecommendation:_.nostoRecommendation})}const[A,ie]=p.useState("");function le(_=""){const w=p.useRef({});p.useEffect(()=>{A!==_&&ie(_)},[]);const L=_===A;function l(y,h){if(E=="HTML")h.placements.injectCampaigns(y.recommendations);else{const O=y.campaigns.recommendations;for(const j in O){const de=O[j],me="#"+j,V=()=>document.querySelector(me);V()&&(w.current[j]||(w.current[j]=H.createRoot(V())),w.current[j].render(s(ce,{nostoRecommendation:de})))}}}return{renderCampaigns:l,pageTypeUpdated:L}}return p.useEffect(()=>{var _,w,L;if(window.nostojs||(window.nostojs=l=>{(window.nostojs.q=window.nostojs.q||[]).push(l)},window.nostojs(l=>l.setAutoLoad(!1))),!document.querySelectorAll("[nosto-client-script]").length&&!r){const l=document.createElement("script");l.type="text/javascript",l.src="//"+(a||"connect.nosto.com")+"/include/"+n,l.async=!0,l.setAttribute("nosto-client-script",""),l.onload=()=>{var y;typeof jest!="undefined"&&((y=window.nosto)==null||y.reload({site:"localhost"})),o(!0)},document.body.appendChild(l)}if(r){const l=document.querySelector("[nosto-client-script]"),y=document.querySelector("#nosto-sandbox");if(!l||(l==null?void 0:l.getAttribute("nosto-language"))!==(r==null?void 0:r.language)||(l==null?void 0:l.getAttribute("nosto-market-id"))!==(r==null?void 0:r.marketId)){d&&o(!1),(_=l==null?void 0:l.parentNode)==null||_.removeChild(l),(w=y==null?void 0:y.parentNode)==null||w.removeChild(y);const h=document.createElement("script");h.type="text/javascript",h.src="//"+(a||"connect.nosto.com")+`/script/shopify/market/nosto.js?merchant=${n}&market=${r.marketId||""}&locale=${((L=r==null?void 0:r.language)==null?void 0:L.toLowerCase())||""}`,h.async=!0,h.setAttribute("nosto-client-script",""),h.setAttribute("nosto-language",(r==null?void 0:r.language)||""),h.setAttribute("nosto-market-id",String(r==null?void 0:r.marketId)),h.onload=()=>{var O;typeof jest!="undefined"&&((O=window.nosto)==null||O.reload({site:"localhost"})),o(!0)},document.body.appendChild(h)}}},[d,r]),s(F.Provider,{value:{account:n,clientScriptLoaded:u,currentVariation:P,responseMode:E,recommendationComponent:c,useRenderCampaigns:le,pageType:A},children:i})}function ae(t){const{cart:n,customer:e}=t,{clientScriptLoaded:a}=f();return x(()=>{const i=n?S(n):void 0,c=e?S(e):void 0;a&&window.nostojs(r=>{r.defaultSession().setResponseMode("HTML").setCart(i).setCustomer(c).viewOther().load()})},[a,n,e]),s(N,{})}m.Nosto404=Z,m.NostoCategory=g,m.NostoCheckout=Q,m.NostoContext=F,m.NostoHome=oe,m.NostoOrder=ne,m.NostoOther=K,m.NostoPlacement=se,m.NostoProduct=X,m.NostoProvider=re,m.NostoSearch=k,m.NostoSession=ae,m.useNostoContext=f,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
9
|
+
*/var Ee;function ot(){if(Ee)return q;Ee=1;var n=h,o=Symbol.for("react.element"),a=Symbol.for("react.fragment"),u=Object.prototype.hasOwnProperty,d=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function i(p,v,N){var _,S={},k=null,I=null;N!==void 0&&(k=""+N),v.key!==void 0&&(k=""+v.key),v.ref!==void 0&&(I=v.ref);for(_ in v)u.call(v,_)&&!c.hasOwnProperty(_)&&(S[_]=v[_]);if(p&&p.defaultProps)for(_ in v=p.defaultProps,v)S[_]===void 0&&(S[_]=v[_]);return{$$typeof:o,type:p,key:k,ref:I,props:S,_owner:d.current}}return q.Fragment=a,q.jsx=i,q.jsxs=i,q}var B={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var Ce;function at(){return Ce||(Ce=1,process.env.NODE_ENV!=="production"&&function(){var n=h,o=Symbol.for("react.element"),a=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),p=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),N=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),S=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),I=Symbol.for("react.offscreen"),G=Symbol.iterator,se="@@iterator";function A(e){if(e===null||typeof e!="object")return null;var t=G&&e[G]||e[se];return typeof t=="function"?t:null}var T=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function R(e){{for(var t=arguments.length,r=new Array(t>1?t-1:0),s=1;s<t;s++)r[s-1]=arguments[s];y("error",e,r)}}function y(e,t,r){{var s=T.ReactDebugCurrentFrame,m=s.getStackAddendum();m!==""&&(t+="%s",r=r.concat([m]));var g=r.map(function(f){return String(f)});g.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,g)}}var P=!1,O=!1,$=!1,U=!1,ie=!1,K;K=Symbol.for("react.module.reference");function X(e){return!!(typeof e=="string"||typeof e=="function"||e===u||e===c||ie||e===d||e===N||e===_||U||e===I||P||O||$||typeof e=="object"&&e!==null&&(e.$$typeof===k||e.$$typeof===S||e.$$typeof===i||e.$$typeof===p||e.$$typeof===v||e.$$typeof===K||e.getModuleId!==void 0))}function be(e,t,r){var s=e.displayName;if(s)return s;var m=t.displayName||t.name||"";return m!==""?r+"("+m+")":r}function _e(e){return e.displayName||"Context"}function D(e){if(e==null)return null;if(typeof e.tag=="number"&&R("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case u:return"Fragment";case a:return"Portal";case c:return"Profiler";case d:return"StrictMode";case N:return"Suspense";case _:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case p:var t=e;return _e(t)+".Consumer";case i:var r=e;return _e(r._context)+".Provider";case v:return be(e,e.render,"ForwardRef");case S:var s=e.displayName||null;return s!==null?s:D(e.type)||"Memo";case k:{var m=e,g=m._payload,f=m._init;try{return D(f(g))}catch{return null}}}return null}var W=Object.assign,H=0,we,Te,Se,Pe,Oe,je,xe;function Ne(){}Ne.__reactDisabledLog=!0;function lt(){{if(H===0){we=console.log,Te=console.info,Se=console.warn,Pe=console.error,Oe=console.group,je=console.groupCollapsed,xe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ne,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}H++}}function ft(){{if(H--,H===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:W({},e,{value:we}),info:W({},e,{value:Te}),warn:W({},e,{value:Se}),error:W({},e,{value:Pe}),group:W({},e,{value:Oe}),groupCollapsed:W({},e,{value:je}),groupEnd:W({},e,{value:xe})})}H<0&&R("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ce=T.ReactCurrentDispatcher,ue;function Z(e,t,r){{if(ue===void 0)try{throw Error()}catch(m){var s=m.stack.trim().match(/\n( *(at )?)/);ue=s&&s[1]||""}return`
|
|
18
|
+
`+ue+e}}var le=!1,Q;{var dt=typeof WeakMap=="function"?WeakMap:Map;Q=new dt}function Ae(e,t){if(!e||le)return"";{var r=Q.get(e);if(r!==void 0)return r}var s;le=!0;var m=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var g;g=ce.current,ce.current=null,lt();try{if(t){var f=function(){throw Error()};if(Object.defineProperty(f.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(f,[])}catch(F){s=F}Reflect.construct(e,[],f)}else{try{f.call()}catch(F){s=F}e.call(f.prototype)}}else{try{throw Error()}catch(F){s=F}e()}}catch(F){if(F&&s&&typeof F.stack=="string"){for(var l=F.stack.split(`
|
|
19
|
+
`),w=s.stack.split(`
|
|
20
|
+
`),E=l.length-1,b=w.length-1;E>=1&&b>=0&&l[E]!==w[b];)b--;for(;E>=1&&b>=0;E--,b--)if(l[E]!==w[b]){if(E!==1||b!==1)do if(E--,b--,b<0||l[E]!==w[b]){var j=`
|
|
21
|
+
`+l[E].replace(" at new "," at ");return e.displayName&&j.includes("<anonymous>")&&(j=j.replace("<anonymous>",e.displayName)),typeof e=="function"&&Q.set(e,j),j}while(E>=1&&b>=0);break}}}finally{le=!1,ce.current=g,ft(),Error.prepareStackTrace=m}var Y=e?e.displayName||e.name:"",Be=Y?Z(Y):"";return typeof e=="function"&&Q.set(e,Be),Be}function mt(e,t,r){return Ae(e,!1)}function pt(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function ee(e,t,r){if(e==null)return"";if(typeof e=="function")return Ae(e,pt(e));if(typeof e=="string")return Z(e);switch(e){case N:return Z("Suspense");case _:return Z("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case v:return mt(e.render);case S:return ee(e.type,t,r);case k:{var s=e,m=s._payload,g=s._init;try{return ee(g(m),t,r)}catch{}}}return""}var te=Object.prototype.hasOwnProperty,ke={},De=T.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,r=ee(e.type,e._source,t?t.type:null);De.setExtraStackFrame(r)}else De.setExtraStackFrame(null)}function vt(e,t,r,s,m){{var g=Function.call.bind(te);for(var f in e)if(g(e,f)){var l=void 0;try{if(typeof e[f]!="function"){var w=Error((s||"React class")+": "+r+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw w.name="Invariant Violation",w}l=e[f](t,f,s,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(E){l=E}l&&!(l instanceof Error)&&(re(m),R("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",s||"React class",r,f,typeof l),re(null)),l instanceof Error&&!(l.message in ke)&&(ke[l.message]=!0,re(m),R("Failed %s type: %s",r,l.message),re(null))}}}var gt=Array.isArray;function fe(e){return gt(e)}function yt(e){{var t=typeof Symbol=="function"&&Symbol.toStringTag,r=t&&e[Symbol.toStringTag]||e.constructor.name||"Object";return r}}function ht(e){try{return Fe(e),!1}catch{return!0}}function Fe(e){return""+e}function Le(e){if(ht(e))return R("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",yt(e)),Fe(e)}var J=T.ReactCurrentOwner,Et={key:!0,ref:!0,__self:!0,__source:!0},Ie,$e,de;de={};function Ct(e){if(te.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function Rt(e){if(te.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function bt(e,t){if(typeof e.ref=="string"&&J.current&&t&&J.current.stateNode!==t){var r=D(J.current.type);de[r]||(R('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',D(J.current.type),e.ref),de[r]=!0)}}function _t(e,t){{var r=function(){Ie||(Ie=!0,R("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}}function wt(e,t){{var r=function(){$e||($e=!0,R("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}}var Tt=function(e,t,r,s,m,g,f){var l={$$typeof:o,type:e,key:t,ref:r,props:f,_owner:g};return l._store={},Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:m}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l};function St(e,t,r,s,m){{var g,f={},l=null,w=null;r!==void 0&&(Le(r),l=""+r),Rt(t)&&(Le(t.key),l=""+t.key),Ct(t)&&(w=t.ref,bt(t,m));for(g in t)te.call(t,g)&&!Et.hasOwnProperty(g)&&(f[g]=t[g]);if(e&&e.defaultProps){var E=e.defaultProps;for(g in E)f[g]===void 0&&(f[g]=E[g])}if(l||w){var b=typeof e=="function"?e.displayName||e.name||"Unknown":e;l&&_t(f,b),w&&wt(f,b)}return Tt(e,l,w,m,s,J.current,f)}}var me=T.ReactCurrentOwner,Ue=T.ReactDebugCurrentFrame;function V(e){if(e){var t=e._owner,r=ee(e.type,e._source,t?t.type:null);Ue.setExtraStackFrame(r)}else Ue.setExtraStackFrame(null)}var pe;pe=!1;function ve(e){return typeof e=="object"&&e!==null&&e.$$typeof===o}function We(){{if(me.current){var e=D(me.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function Pt(e){return""}var Ve={};function Ot(e){{var t=We();if(!t){var r=typeof e=="string"?e:e.displayName||e.name;r&&(t=`
|
|
24
|
+
|
|
25
|
+
Check the top-level render call using <`+r+">.")}return t}}function Ye(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var r=Ot(t);if(Ve[r])return;Ve[r]=!0;var s="";e&&e._owner&&e._owner!==me.current&&(s=" It was passed a child from "+D(e._owner.type)+"."),V(e),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,s),V(null)}}function Me(e,t){{if(typeof e!="object")return;if(fe(e))for(var r=0;r<e.length;r++){var s=e[r];ve(s)&&Ye(s,t)}else if(ve(e))e._store&&(e._store.validated=!0);else if(e){var m=A(e);if(typeof m=="function"&&m!==e.entries)for(var g=m.call(e),f;!(f=g.next()).done;)ve(f.value)&&Ye(f.value,t)}}}function jt(e){{var t=e.type;if(t==null||typeof t=="string")return;var r;if(typeof t=="function")r=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===v||t.$$typeof===S))r=t.propTypes;else return;if(r){var s=D(t);vt(r,e.props,"prop",s,e)}else if(t.PropTypes!==void 0&&!pe){pe=!0;var m=D(t);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",m||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function xt(e){{for(var t=Object.keys(e.props),r=0;r<t.length;r++){var s=t[r];if(s!=="children"&&s!=="key"){V(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",s),V(null);break}}e.ref!==null&&(V(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),V(null))}}function qe(e,t,r,s,m,g){{var f=X(e);if(!f){var l="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(l+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var w=Pt();w?l+=w:l+=We();var E;e===null?E="null":fe(e)?E="array":e!==void 0&&e.$$typeof===o?(E="<"+(D(e.type)||"Unknown")+" />",l=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,l)}var b=St(e,t,r,m,g);if(b==null)return b;if(f){var j=t.children;if(j!==void 0)if(s)if(fe(j)){for(var Y=0;Y<j.length;Y++)Me(j[Y],e);Object.freeze&&Object.freeze(j)}else R("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Me(j,e)}return e===u?xt(b):jt(b),b}}function Nt(e,t,r){return qe(e,t,r,!0)}function At(e,t,r){return qe(e,t,r,!1)}var kt=At,Dt=Nt;B.Fragment=u,B.jsx=kt,B.jsxs=Dt}()),B}process.env.NODE_ENV==="production"?ae.exports=ot():ae.exports=at();var Re=ae.exports;const z=Re.jsx,st=Re.Fragment;function it(n){const{id:o,pageType:a}=n;return z("div",{className:"nosto_element",id:o},o+(a||""))}function ct(n){const{account:o,multiCurrency:a=!1,host:u,children:d,recommendationComponent:c,shopifyMarkets:i}=n,[p,v]=h.useState(!1),N=h.useMemo(()=>p,[p]),_=a?n.currentVariation:"",S=h.isValidElement(c)?"JSON_ORIGINAL":"HTML";function k(A){return h.cloneElement(c,{nostoRecommendation:A.nostoRecommendation})}const[I,G]=h.useState("");function se(A=""){const T=h.useRef({});h.useEffect(()=>{I!==A&&G(A)},[]);const R=A===I;function y(P,O){if(S=="HTML")O.placements.injectCampaigns(P.recommendations);else{const $=P.campaigns.recommendations;for(const U in $){const ie=$[U],K="#"+U,X=()=>document.querySelector(K);X()&&(T.current[U]||(T.current[U]=He.createRoot(X())),T.current[U].render(z(k,{nostoRecommendation:ie})))}}}return{renderCampaigns:y,pageTypeUpdated:R}}return h.useEffect(()=>{var A,T,R;if(window.nostojs||(window.nostojs=y=>{(window.nostojs.q=window.nostojs.q||[]).push(y)},window.nostojs(y=>y.setAutoLoad(!1))),!document.querySelectorAll("[nosto-client-script]").length&&!i){const y=document.createElement("script");y.type="text/javascript",y.src="//"+(u||"connect.nosto.com")+"/include/"+o,y.async=!0,y.setAttribute("nosto-client-script",""),y.onload=()=>{var P;typeof jest<"u"&&((P=window.nosto)==null||P.reload({site:"localhost"})),v(!0)},document.body.appendChild(y)}if(i){const y=document.querySelector("[nosto-client-script]"),P=document.querySelector("#nosto-sandbox");if(!y||(y==null?void 0:y.getAttribute("nosto-language"))!==(i==null?void 0:i.language)||(y==null?void 0:y.getAttribute("nosto-market-id"))!==(i==null?void 0:i.marketId)){p&&v(!1),(A=y==null?void 0:y.parentNode)==null||A.removeChild(y),(T=P==null?void 0:P.parentNode)==null||T.removeChild(P);const O=document.createElement("script");O.type="text/javascript",O.src="//"+(u||"connect.nosto.com")+`/script/shopify/market/nosto.js?merchant=${o}&market=${i.marketId||""}&locale=${((R=i==null?void 0:i.language)==null?void 0:R.toLowerCase())||""}`,O.async=!0,O.setAttribute("nosto-client-script",""),O.setAttribute("nosto-language",(i==null?void 0:i.language)||""),O.setAttribute("nosto-market-id",String(i==null?void 0:i.marketId)),O.onload=()=>{var $;typeof jest<"u"&&(($=window.nosto)==null||$.reload({site:"localhost"})),v(!0)},document.body.appendChild(O)}}},[p,i]),z(ne.Provider,{value:{account:o,clientScriptLoaded:N,currentVariation:_,responseMode:S,recommendationComponent:c,useRenderCampaigns:se,pageType:I},children:d})}function ut(n){const{cart:o,customer:a}=n??{},{clientScriptLoaded:u}=x();return he(()=>{const d=o?M(o):void 0,c=a?M(a):void 0;u&&window.nostojs(i=>{i.defaultSession().setResponseMode("HTML").setCart(d).setCustomer(c).viewOther().load()})},[u,o,a]),z(st,{})}C.Nosto404=ze,C.NostoCategory=Ze,C.NostoCheckout=Ke,C.NostoContext=ne,C.NostoHome=nt,C.NostoOrder=rt,C.NostoOther=Ge,C.NostoPlacement=it,C.NostoProduct=Xe,C.NostoProvider=ct,C.NostoSearch=Qe,C.NostoSession=ut,C.useNostoContext=x,Object.defineProperty(C,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": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"author": "Mridang Agarwalla, Dominik Gilg",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "vite",
|
|
17
|
-
"build": "tsc && npm run lint && vite build && typedoc
|
|
17
|
+
"build": "tsc && npm run lint && vite build && npm run typedoc",
|
|
18
18
|
"preview": "vite preview",
|
|
19
19
|
"prepare": "vite build",
|
|
20
20
|
"typecheck": "tsc",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"clean": "rimraf dist",
|
|
23
23
|
"prettier": "prettier '{src,spec}/**' --list-different",
|
|
24
24
|
"prettier:fix": "prettier '{src,spec}/**' --write",
|
|
25
|
-
"test": "jest spec"
|
|
25
|
+
"test": "jest spec",
|
|
26
|
+
"typedoc": "typedoc src/index.ts"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
29
|
"dist",
|
|
@@ -40,8 +41,8 @@
|
|
|
40
41
|
"@typescript-eslint/parser": "^6.11.0",
|
|
41
42
|
"@vitejs/plugin-react": "^1.3.0",
|
|
42
43
|
"eslint": "^8.53.0",
|
|
43
|
-
"eslint-plugin-react": "^7.33.2",
|
|
44
44
|
"eslint-plugin-promise": "^6.1.1",
|
|
45
|
+
"eslint-plugin-react": "^7.33.2",
|
|
45
46
|
"jest": "^29.5.0",
|
|
46
47
|
"jest-environment-jsdom": "^29.5.0",
|
|
47
48
|
"prettier": "^2.0.5",
|
|
@@ -51,11 +52,12 @@
|
|
|
51
52
|
"ts-jest": "^29.1.0",
|
|
52
53
|
"typedoc": "^0.24.1",
|
|
53
54
|
"typescript": "^4.6.3",
|
|
54
|
-
"vite": "^2.
|
|
55
|
+
"vite": "^5.2.10",
|
|
56
|
+
"vite-plugin-dts": "^3.9.1"
|
|
55
57
|
},
|
|
56
58
|
"main": "./dist/index.umd.js",
|
|
57
59
|
"module": "./dist/index.es.js",
|
|
58
|
-
"types": "./
|
|
60
|
+
"types": "./dist/index.d.ts",
|
|
59
61
|
"exports": {
|
|
60
62
|
".": {
|
|
61
63
|
"import": "./dist/index.es.js",
|
|
@@ -36,12 +36,5 @@ export default function Nosto404(props: { placements?: string[] }) {
|
|
|
36
36
|
},
|
|
37
37
|
[recommendationComponent, pageTypeUpdated]
|
|
38
38
|
)
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<>
|
|
42
|
-
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
43
|
-
notfound
|
|
44
|
-
</div>
|
|
45
|
-
</>
|
|
46
|
-
)
|
|
39
|
+
return null
|
|
47
40
|
}
|
|
@@ -39,15 +39,5 @@ export default function NostoCategory(props: { category: string; placements?: st
|
|
|
39
39
|
},
|
|
40
40
|
[category, recommendationComponent, pageTypeUpdated]
|
|
41
41
|
)
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<>
|
|
45
|
-
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
46
|
-
category
|
|
47
|
-
</div>
|
|
48
|
-
<div className="nosto_category" style={{ display: "none" }}>
|
|
49
|
-
{category}
|
|
50
|
-
</div>
|
|
51
|
-
</>
|
|
52
|
-
)
|
|
42
|
+
return null
|
|
53
43
|
}
|
|
@@ -20,7 +20,6 @@ import { useNostoApi } from "../utils/hooks"
|
|
|
20
20
|
*
|
|
21
21
|
* @group Components
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
23
|
export default function NostoCheckout(props: { placements?: string[] }) {
|
|
25
24
|
const { recommendationComponent, useRenderCampaigns } = useNostoContext()
|
|
26
25
|
|
|
@@ -36,12 +35,5 @@ export default function NostoCheckout(props: { placements?: string[] }) {
|
|
|
36
35
|
},
|
|
37
36
|
[recommendationComponent, pageTypeUpdated]
|
|
38
37
|
)
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<>
|
|
42
|
-
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
43
|
-
cart
|
|
44
|
-
</div>
|
|
45
|
-
</>
|
|
46
|
-
)
|
|
38
|
+
return null
|
|
47
39
|
}
|
|
@@ -39,12 +39,5 @@ export default function NostoHome(props: { placements?: string[] }) {
|
|
|
39
39
|
},
|
|
40
40
|
[recommendationComponent, pageTypeUpdated]
|
|
41
41
|
)
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<>
|
|
45
|
-
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
46
|
-
front
|
|
47
|
-
</div>
|
|
48
|
-
</>
|
|
49
|
-
)
|
|
42
|
+
return null
|
|
50
43
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Order } from "../types"
|
|
2
2
|
import { useNostoContext } from "./context"
|
|
3
3
|
import { snakeize } from "../utils/snakeize"
|
|
4
4
|
import { useNostoApi } from "../utils/hooks"
|
|
@@ -23,7 +23,7 @@ import { useNostoApi } from "../utils/hooks"
|
|
|
23
23
|
* @group Components
|
|
24
24
|
*/
|
|
25
25
|
export default function NostoOrder(props: {
|
|
26
|
-
order:
|
|
26
|
+
order: Order,
|
|
27
27
|
placements?: string[]
|
|
28
28
|
}) {
|
|
29
29
|
const { order, placements } = props
|
|
@@ -41,15 +41,5 @@ export default function NostoOrder(props: {
|
|
|
41
41
|
},
|
|
42
42
|
[recommendationComponent, pageTypeUpdated]
|
|
43
43
|
)
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<>
|
|
47
|
-
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
48
|
-
order
|
|
49
|
-
</div>
|
|
50
|
-
<div className="nosto_order" style={{ display: "none" }}>
|
|
51
|
-
{order.purchase.number}
|
|
52
|
-
</div>
|
|
53
|
-
</>
|
|
54
|
-
)
|
|
44
|
+
return null
|
|
55
45
|
}
|
|
@@ -35,12 +35,5 @@ export default function NostoOther(props: { placements?: string[] }) {
|
|
|
35
35
|
},
|
|
36
36
|
[recommendationComponent, pageTypeUpdated]
|
|
37
37
|
)
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<>
|
|
41
|
-
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
42
|
-
other
|
|
43
|
-
</div>
|
|
44
|
-
</>
|
|
45
|
-
)
|
|
38
|
+
return null
|
|
46
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Product } from "../types"
|
|
2
1
|
import { useNostoContext } from "./context"
|
|
3
2
|
import { useNostoApi } from "../utils/hooks"
|
|
3
|
+
import { Product } from "../types"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The NostoProduct component must be used to personalise the product page.
|
|
@@ -39,7 +39,7 @@ export default function NostoProduct(props: {
|
|
|
39
39
|
useNostoApi(
|
|
40
40
|
async (api) => {
|
|
41
41
|
const data = await api.defaultSession()
|
|
42
|
-
.viewProduct(product)
|
|
42
|
+
.viewProduct(tagging ?? product)
|
|
43
43
|
.setPlacements(placements || api.placements.getPlacements())
|
|
44
44
|
.load()
|
|
45
45
|
renderCampaigns(data, api)
|
|
@@ -47,97 +47,5 @@ export default function NostoProduct(props: {
|
|
|
47
47
|
[product, recommendationComponent, pageTypeUpdated],
|
|
48
48
|
{ deep: true }
|
|
49
49
|
)
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<>
|
|
53
|
-
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
54
|
-
product
|
|
55
|
-
</div>
|
|
56
|
-
<div className="nosto_product" style={{ display: "none" }}>
|
|
57
|
-
{tagging?.variationId && <span className="variation_id">{tagging.variationId}</span>}
|
|
58
|
-
{product && <span className="product_id">{product}</span>}
|
|
59
|
-
{tagging?.name && <span className="name">{tagging.name}</span>}
|
|
60
|
-
{tagging?.url && <span className="url">{tagging.url.toString()}</span>}
|
|
61
|
-
{tagging?.imageUrl && <span className="image_url">{tagging.imageUrl.toString()}</span>}
|
|
62
|
-
{tagging?.availability && <span className="availability">{tagging.availability}</span>}
|
|
63
|
-
{tagging?.price && <span className="price">{tagging.price}</span>}
|
|
64
|
-
{tagging?.listPrice && <span className="list_price">{tagging.listPrice}</span>}
|
|
65
|
-
{tagging?.priceCurrencyCode && (
|
|
66
|
-
<span className="price_currency_code">{tagging.priceCurrencyCode}</span>
|
|
67
|
-
)}
|
|
68
|
-
{tagging?.brand && <span className="brand">{tagging.brand}</span>}
|
|
69
|
-
{tagging?.description && <span className="description">{tagging.description}</span>}
|
|
70
|
-
{tagging?.googleCategory && <span className="description">{tagging.googleCategory}</span>}
|
|
71
|
-
{tagging?.condition && <span className="condition">{tagging.condition}</span>}
|
|
72
|
-
{tagging?.gender && <span className="gender">{tagging.gender}</span>}
|
|
73
|
-
{tagging?.ageGroup && <span className="age_group">{tagging.ageGroup}</span>}
|
|
74
|
-
{tagging?.gtin && <span className="gtin">{tagging.gtin}</span>}
|
|
75
|
-
{tagging?.category &&
|
|
76
|
-
tagging?.category.map((category, index) => (
|
|
77
|
-
<span className="category" key={index}>
|
|
78
|
-
{category}
|
|
79
|
-
</span>
|
|
80
|
-
))}
|
|
81
|
-
{tagging?.tags1 &&
|
|
82
|
-
tagging.tags1.map((tag, index) => (
|
|
83
|
-
<span className="tag1" key={index}>
|
|
84
|
-
{tag}
|
|
85
|
-
</span>
|
|
86
|
-
))}
|
|
87
|
-
{tagging?.tags2 &&
|
|
88
|
-
tagging.tags2.map((tag, index) => (
|
|
89
|
-
<span className="tag2" key={index}>
|
|
90
|
-
{tag}
|
|
91
|
-
</span>
|
|
92
|
-
))}
|
|
93
|
-
{tagging?.tags3 &&
|
|
94
|
-
tagging.tags3.map((tag, index) => (
|
|
95
|
-
<span className="tag3" key={index}>
|
|
96
|
-
{tag}
|
|
97
|
-
</span>
|
|
98
|
-
))}
|
|
99
|
-
{tagging?.ratingValue && <span className="rating_value">{tagging.ratingValue}</span>}
|
|
100
|
-
{tagging?.reviewCount && <span className="review_count">{tagging.reviewCount}</span>}
|
|
101
|
-
{tagging?.alternateImageUrls &&
|
|
102
|
-
tagging.alternateImageUrls.map((url, index) => (
|
|
103
|
-
<span className="alternate_image_url" key={index}>
|
|
104
|
-
{url.toString()}
|
|
105
|
-
</span>
|
|
106
|
-
))}
|
|
107
|
-
{tagging?.customFields &&
|
|
108
|
-
Object.keys(tagging.customFields).map(
|
|
109
|
-
(field, index) =>
|
|
110
|
-
tagging.customFields &&
|
|
111
|
-
tagging.customFields[field] && (
|
|
112
|
-
<span className={field} key={index}>
|
|
113
|
-
{tagging.customFields[field]}
|
|
114
|
-
</span>
|
|
115
|
-
)
|
|
116
|
-
)}
|
|
117
|
-
{tagging?.skus &&
|
|
118
|
-
tagging.skus.map((sku, index) => (
|
|
119
|
-
<span className="nosto_sku" key={index}>
|
|
120
|
-
{sku?.id && <span className="product_id">{sku.id}</span>}
|
|
121
|
-
{sku?.name && <span className="name">{sku.name}</span>}
|
|
122
|
-
{sku?.price && <span className="price">{sku.price}</span>}
|
|
123
|
-
{sku?.listPrice && <span className="list_price">{sku.listPrice}</span>}
|
|
124
|
-
{sku?.url && <span className="url">{sku.url.toString()}</span>}
|
|
125
|
-
{sku?.imageUrl && <span className="image_url">{sku.imageUrl.toString()}</span>}
|
|
126
|
-
{sku?.gtin && <span className="gtin">{sku.gtin}</span>}
|
|
127
|
-
{sku?.availability && <span className="availability">{sku.availability}</span>}
|
|
128
|
-
{sku?.customFields &&
|
|
129
|
-
Object.keys(sku.customFields).map(
|
|
130
|
-
(field, index) =>
|
|
131
|
-
sku.customFields &&
|
|
132
|
-
sku.customFields[field] && (
|
|
133
|
-
<span className={field} key={index}>
|
|
134
|
-
{sku.customFields[field]}
|
|
135
|
-
</span>
|
|
136
|
-
)
|
|
137
|
-
)}
|
|
138
|
-
</span>
|
|
139
|
-
))}
|
|
140
|
-
</div>
|
|
141
|
-
</>
|
|
142
|
-
)
|
|
50
|
+
return null
|
|
143
51
|
}
|
|
@@ -40,15 +40,5 @@ export default function NostoSearch(props: { query: string; placements?: string[
|
|
|
40
40
|
},
|
|
41
41
|
[query, recommendationComponent, pageTypeUpdated]
|
|
42
42
|
)
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<>
|
|
46
|
-
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
47
|
-
search
|
|
48
|
-
</div>
|
|
49
|
-
<div className="nosto_search" style={{ display: "none" }}>
|
|
50
|
-
{query}
|
|
51
|
-
</div>
|
|
52
|
-
</>
|
|
53
|
-
)
|
|
43
|
+
return null
|
|
54
44
|
}
|
|
@@ -13,8 +13,8 @@ import { useDeepCompareEffect } from "../utils/hooks"
|
|
|
13
13
|
*
|
|
14
14
|
* @group Essential Functions
|
|
15
15
|
*/
|
|
16
|
-
export default function NostoSession(props
|
|
17
|
-
const { cart, customer } = props
|
|
16
|
+
export default function NostoSession(props?: { cart?: Cart; customer?: Customer }) {
|
|
17
|
+
const { cart, customer } = props ?? {}
|
|
18
18
|
const { clientScriptLoaded } = useNostoContext()
|
|
19
19
|
|
|
20
20
|
useDeepCompareEffect(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useContext } from "react"
|
|
2
|
-
import { NostoClient, Recommendation } from "../types"
|
|
2
|
+
import { NostoClient, Recommendation, RenderMode } from "../types"
|
|
3
3
|
|
|
4
4
|
type AnyFunction = (...args: unknown[]) => unknown
|
|
5
5
|
|
|
@@ -11,7 +11,7 @@ export interface NostoContextType {
|
|
|
11
11
|
clientScriptLoaded: boolean
|
|
12
12
|
currentVariation?: string
|
|
13
13
|
renderFunction?: AnyFunction
|
|
14
|
-
responseMode:
|
|
14
|
+
responseMode: RenderMode
|
|
15
15
|
recommendationComponent?: React.ReactElement<{
|
|
16
16
|
nostoRecommendation: Recommendation
|
|
17
17
|
}>
|
package/src/index.ts
CHANGED