@nosto/nosto-react 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +519 -0
- package/dist/index.es.js +947 -449
- package/dist/index.umd.js +18 -2
- package/package.json +8 -6
- package/src/types.ts +6 -6
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(R,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client"],b):(R=typeof globalThis<"u"?globalThis:R||self,b(R["@nosto/nosto-react"]={},R.React,R.ReactDOM))})(this,function(R,b,ze){"use strict";const oe=b.createContext({account:"",currentVariation:"",pageType:"",responseMode:"HTML",clientScriptLoaded:!1,useRenderCampaigns:()=>({renderCampaigns:()=>{},pageTypeUpdated:!1})});function F(){const o=b.useContext(oe);if(!o)throw new Error("No nosto context found");return o}const Ce=o=>String(o)==="[object Object]";function be(o){if(!Ce(o))return!1;const s=o.constructor;if(s===void 0)return!0;const r=s.prototype;return!(!Ce(r)||!r.hasOwnProperty("isPrototypeOf"))}function se(o,s){if(o===s)return!0;if(o instanceof Date&&s instanceof Date)return o.getTime()===s.getTime();if(o instanceof Array&&s instanceof Array)return o.length!==s.length?!1:o.every((r,d)=>se(r,s[d]));if(be(o)&&be(s)){const r=Object.entries(o);return r.length!==Object.keys(s).length?!1:r.every(([d,m])=>se(m,s[d]))}return!1}function Ee(o,s){return b.useEffect(o,Ke(s))}function Ke(o){const s=b.useRef(o),r=b.useRef(0);return se(o,s.current)||(s.current=o,r.current+=1),b.useMemo(()=>s.current,[r.current])}function $(o,s,r){const{clientScriptLoaded:d,currentVariation:m,responseMode:u}=F();(r!=null&&r.deep?Ee:b.useEffect)(()=>{d&&window.nostojs(y=>{y.defaultSession().setVariation(m).setResponseMode(u),o(y)})},[d,m,u,...s??[]])}var ie={exports:{}},H={};/**
|
|
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 Re;function Xe(){if(Re)return H;Re=1;var o=b,s=Symbol.for("react.element"),r=Symbol.for("react.fragment"),d=Object.prototype.hasOwnProperty,m=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,u={key:!0,ref:!0,__self:!0,__source:!0};function l(y,n,C){var N,P={},I=null,V=null;C!==void 0&&(I=""+C),n.key!==void 0&&(I=""+n.key),n.ref!==void 0&&(V=n.ref);for(N in n)d.call(n,N)&&!u.hasOwnProperty(N)&&(P[N]=n[N]);if(y&&y.defaultProps)for(N in n=y.defaultProps,n)P[N]===void 0&&(P[N]=n[N]);return{$$typeof:s,type:y,key:I,ref:V,props:P,_owner:m.current}}return H.Fragment=r,H.jsx=l,H.jsxs=l,H}var J={};/**
|
|
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 we;function Ze(){return we||(we=1,process.env.NODE_ENV!=="production"&&function(){var o=b,s=Symbol.for("react.element"),r=Symbol.for("react.portal"),d=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),u=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),y=Symbol.for("react.context"),n=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),N=Symbol.for("react.suspense_list"),P=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),V=Symbol.for("react.offscreen"),Z=Symbol.iterator,le="@@iterator";function A(e){if(e===null||typeof e!="object")return null;var t=Z&&e[Z]||e[le];return typeof t=="function"?t:null}var g=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(e){{for(var t=arguments.length,a=new Array(t>1?t-1:0),c=1;c<t;c++)a[c-1]=arguments[c];_("error",e,a)}}function _(e,t,a){{var c=g.ReactDebugCurrentFrame,v=c.getStackAddendum();v!==""&&(t+="%s",a=a.concat([v]));var h=a.map(function(p){return String(p)});h.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,h)}}var O=!1,j=!1,W=!1,Y=!1,ue=!1,Q;Q=Symbol.for("react.module.reference");function k(e){return!!(typeof e=="string"||typeof e=="function"||e===d||e===u||ue||e===m||e===C||e===N||Y||e===V||O||j||W||typeof e=="object"&&e!==null&&(e.$$typeof===I||e.$$typeof===P||e.$$typeof===l||e.$$typeof===y||e.$$typeof===n||e.$$typeof===Q||e.getModuleId!==void 0))}function Se(e,t,a){var c=e.displayName;if(c)return c;var v=t.displayName||t.name||"";return v!==""?a+"("+v+")":a}function Ne(e){return e.displayName||"Context"}function L(e){if(e==null)return null;if(typeof e.tag=="number"&&w("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 d:return"Fragment";case r:return"Portal";case u:return"Profiler";case m:return"StrictMode";case C:return"Suspense";case N:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case y:var t=e;return Ne(t)+".Consumer";case l:var a=e;return Ne(a._context)+".Provider";case n:return Se(e,e.render,"ForwardRef");case P:var c=e.displayName||null;return c!==null?c:L(e.type)||"Memo";case I:{var v=e,h=v._payload,p=v._init;try{return L(p(h))}catch{return null}}}return null}var M=Object.assign,K=0,Te,Pe,ge,Oe,je,xe,Fe;function Ae(){}Ae.__reactDisabledLog=!0;function dr(){{if(K===0){Te=console.log,Pe=console.info,ge=console.warn,Oe=console.error,je=console.group,xe=console.groupCollapsed,Fe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ae,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}K++}}function fr(){{if(K--,K===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:M({},e,{value:Te}),info:M({},e,{value:Pe}),warn:M({},e,{value:ge}),error:M({},e,{value:Oe}),group:M({},e,{value:je}),groupCollapsed:M({},e,{value:xe}),groupEnd:M({},e,{value:Fe})})}K<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var de=g.ReactCurrentDispatcher,fe;function ee(e,t,a){{if(fe===void 0)try{throw Error()}catch(v){var c=v.stack.trim().match(/\n( *(at )?)/);fe=c&&c[1]||""}return`
|
|
18
|
+
`+fe+e}}var pe=!1,re;{var pr=typeof WeakMap=="function"?WeakMap:Map;re=new pr}function De(e,t){if(!e||pe)return"";{var a=re.get(e);if(a!==void 0)return a}var c;pe=!0;var v=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var h;h=de.current,de.current=null,dr();try{if(t){var p=function(){throw Error()};if(Object.defineProperty(p.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(p,[])}catch(U){c=U}Reflect.construct(e,[],p)}else{try{p.call()}catch(U){c=U}e.call(p.prototype)}}else{try{throw Error()}catch(U){c=U}e()}}catch(U){if(U&&c&&typeof U.stack=="string"){for(var f=U.stack.split(`
|
|
19
|
+
`),T=c.stack.split(`
|
|
20
|
+
`),E=f.length-1,S=T.length-1;E>=1&&S>=0&&f[E]!==T[S];)S--;for(;E>=1&&S>=0;E--,S--)if(f[E]!==T[S]){if(E!==1||S!==1)do if(E--,S--,S<0||f[E]!==T[S]){var x=`
|
|
21
|
+
`+f[E].replace(" at new "," at ");return e.displayName&&x.includes("<anonymous>")&&(x=x.replace("<anonymous>",e.displayName)),typeof e=="function"&&re.set(e,x),x}while(E>=1&&S>=0);break}}}finally{pe=!1,de.current=h,fr(),Error.prepareStackTrace=v}var G=e?e.displayName||e.name:"",Je=G?ee(G):"";return typeof e=="function"&&re.set(e,Je),Je}function mr(e,t,a){return De(e,!1)}function vr(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function te(e,t,a){if(e==null)return"";if(typeof e=="function")return De(e,vr(e));if(typeof e=="string")return ee(e);switch(e){case C:return ee("Suspense");case N:return ee("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case n:return mr(e.render);case P:return te(e.type,t,a);case I:{var c=e,v=c._payload,h=c._init;try{return te(h(v),t,a)}catch{}}}return""}var ne=Object.prototype.hasOwnProperty,Ie={},Le=g.ReactDebugCurrentFrame;function ae(e){if(e){var t=e._owner,a=te(e.type,e._source,t?t.type:null);Le.setExtraStackFrame(a)}else Le.setExtraStackFrame(null)}function yr(e,t,a,c,v){{var h=Function.call.bind(ne);for(var p in e)if(h(e,p)){var f=void 0;try{if(typeof e[p]!="function"){var T=Error((c||"React class")+": "+a+" type `"+p+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[p]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw T.name="Invariant Violation",T}f=e[p](t,p,c,a,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(E){f=E}f&&!(f instanceof Error)&&(ae(v),w("%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).",c||"React class",a,p,typeof f),ae(null)),f instanceof Error&&!(f.message in Ie)&&(Ie[f.message]=!0,ae(v),w("Failed %s type: %s",a,f.message),ae(null))}}}var hr=Array.isArray;function me(e){return hr(e)}function _r(e){{var t=typeof Symbol=="function"&&Symbol.toStringTag,a=t&&e[Symbol.toStringTag]||e.constructor.name||"Object";return a}}function Cr(e){try{return Ue(e),!1}catch{return!0}}function Ue(e){return""+e}function $e(e){if(Cr(e))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",_r(e)),Ue(e)}var X=g.ReactCurrentOwner,br={key:!0,ref:!0,__self:!0,__source:!0},Ve,We,ve;ve={};function Er(e){if(ne.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function Rr(e){if(ne.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function wr(e,t){if(typeof e.ref=="string"&&X.current&&t&&X.current.stateNode!==t){var a=L(X.current.type);ve[a]||(w('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',L(X.current.type),e.ref),ve[a]=!0)}}function Sr(e,t){{var a=function(){Ve||(Ve=!0,w("%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))};a.isReactWarning=!0,Object.defineProperty(e,"key",{get:a,configurable:!0})}}function Nr(e,t){{var a=function(){We||(We=!0,w("%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))};a.isReactWarning=!0,Object.defineProperty(e,"ref",{get:a,configurable:!0})}}var Tr=function(e,t,a,c,v,h,p){var f={$$typeof:s,type:e,key:t,ref:a,props:p,_owner:h};return f._store={},Object.defineProperty(f._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(f,"_self",{configurable:!1,enumerable:!1,writable:!1,value:c}),Object.defineProperty(f,"_source",{configurable:!1,enumerable:!1,writable:!1,value:v}),Object.freeze&&(Object.freeze(f.props),Object.freeze(f)),f};function Pr(e,t,a,c,v){{var h,p={},f=null,T=null;a!==void 0&&($e(a),f=""+a),Rr(t)&&($e(t.key),f=""+t.key),Er(t)&&(T=t.ref,wr(t,v));for(h in t)ne.call(t,h)&&!br.hasOwnProperty(h)&&(p[h]=t[h]);if(e&&e.defaultProps){var E=e.defaultProps;for(h in E)p[h]===void 0&&(p[h]=E[h])}if(f||T){var S=typeof e=="function"?e.displayName||e.name||"Unknown":e;f&&Sr(p,S),T&&Nr(p,S)}return Tr(e,f,T,v,c,X.current,p)}}var ye=g.ReactCurrentOwner,Ye=g.ReactDebugCurrentFrame;function B(e){if(e){var t=e._owner,a=te(e.type,e._source,t?t.type:null);Ye.setExtraStackFrame(a)}else Ye.setExtraStackFrame(null)}var he;he=!1;function _e(e){return typeof e=="object"&&e!==null&&e.$$typeof===s}function Me(){{if(ye.current){var e=L(ye.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function gr(e){return""}var qe={};function Or(e){{var t=Me();if(!t){var a=typeof e=="string"?e:e.displayName||e.name;a&&(t=`
|
|
24
|
+
|
|
25
|
+
Check the top-level render call using <`+a+">.")}return t}}function Be(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var a=Or(t);if(qe[a])return;qe[a]=!0;var c="";e&&e._owner&&e._owner!==ye.current&&(c=" It was passed a child from "+L(e._owner.type)+"."),B(e),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',a,c),B(null)}}function Ge(e,t){{if(typeof e!="object")return;if(me(e))for(var a=0;a<e.length;a++){var c=e[a];_e(c)&&Be(c,t)}else if(_e(e))e._store&&(e._store.validated=!0);else if(e){var v=A(e);if(typeof v=="function"&&v!==e.entries)for(var h=v.call(e),p;!(p=h.next()).done;)_e(p.value)&&Be(p.value,t)}}}function jr(e){{var t=e.type;if(t==null||typeof t=="string")return;var a;if(typeof t=="function")a=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===n||t.$$typeof===P))a=t.propTypes;else return;if(a){var c=L(t);yr(a,e.props,"prop",c,e)}else if(t.PropTypes!==void 0&&!he){he=!0;var v=L(t);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function xr(e){{for(var t=Object.keys(e.props),a=0;a<t.length;a++){var c=t[a];if(c!=="children"&&c!=="key"){B(e),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",c),B(null);break}}e.ref!==null&&(B(e),w("Invalid attribute `ref` supplied to `React.Fragment`."),B(null))}}function He(e,t,a,c,v,h){{var p=k(e);if(!p){var f="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(f+=" 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 T=gr();T?f+=T:f+=Me();var E;e===null?E="null":me(e)?E="array":e!==void 0&&e.$$typeof===s?(E="<"+(L(e.type)||"Unknown")+" />",f=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,f)}var S=Pr(e,t,a,v,h);if(S==null)return S;if(p){var x=t.children;if(x!==void 0)if(c)if(me(x)){for(var G=0;G<x.length;G++)Ge(x[G],e);Object.freeze&&Object.freeze(x)}else w("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 Ge(x,e)}return e===d?xr(S):jr(S),S}}function Fr(e,t,a){return He(e,t,a,!0)}function Ar(e,t,a){return He(e,t,a,!1)}var Dr=Ar,Ir=Fr;J.Fragment=d,J.jsx=Dr,J.jsxs=Ir}()),J}process.env.NODE_ENV==="production"?ie.exports=Xe():ie.exports=Ze();var ce=ie.exports;const i=ce.jsx,q=ce.jsxs,D=ce.Fragment;function Qe(o){const{recommendationComponent:s,useRenderCampaigns:r}=F(),{renderCampaigns:d,pageTypeUpdated:m}=r("404");return $(async u=>{const l=await u.defaultSession().viewNotFound().setPlacements(o.placements||u.placements.getPlacements()).load();d(l,u)},[s,m]),i(D,{children:i("div",{className:"nosto_page_type",style:{display:"none"},children:"notfound"})})}function ke(o){const{recommendationComponent:s,useRenderCampaigns:r}=F(),{renderCampaigns:d,pageTypeUpdated:m}=r("other");return $(async u=>{const l=await u.defaultSession().viewOther().setPlacements(o.placements||u.placements.getPlacements()).load();d(l,u)},[s,m]),i(D,{children:i("div",{className:"nosto_page_type",style:{display:"none"},children:"other"})})}function er(o){const{recommendationComponent:s,useRenderCampaigns:r}=F(),{renderCampaigns:d,pageTypeUpdated:m}=r("checkout");return $(async u=>{const l=await u.defaultSession().viewCart().setPlacements(o.placements||u.placements.getPlacements()).load();d(l,u)},[s,m]),i(D,{children:i("div",{className:"nosto_page_type",style:{display:"none"},children:"cart"})})}function rr(o){const{product:s,tagging:r,placements:d}=o,{recommendationComponent:m,useRenderCampaigns:u}=F(),{renderCampaigns:l,pageTypeUpdated:y}=u("product");return $(async n=>{const C=await n.defaultSession().viewProduct(s).setPlacements(d||n.placements.getPlacements()).load();l(C,n)},[s,m,y],{deep:!0}),q(D,{children:[i("div",{className:"nosto_page_type",style:{display:"none"},children:"product"}),q("div",{className:"nosto_product",style:{display:"none"},children:[(r==null?void 0:r.variationId)&&i("span",{className:"variation_id",children:r.variationId}),s&&i("span",{className:"product_id",children:s}),(r==null?void 0:r.name)&&i("span",{className:"name",children:r.name}),(r==null?void 0:r.url)&&i("span",{className:"url",children:r.url.toString()}),(r==null?void 0:r.imageUrl)&&i("span",{className:"image_url",children:r.imageUrl.toString()}),(r==null?void 0:r.availability)&&i("span",{className:"availability",children:r.availability}),(r==null?void 0:r.price)&&i("span",{className:"price",children:r.price}),(r==null?void 0:r.listPrice)&&i("span",{className:"list_price",children:r.listPrice}),(r==null?void 0:r.priceCurrencyCode)&&i("span",{className:"price_currency_code",children:r.priceCurrencyCode}),(r==null?void 0:r.brand)&&i("span",{className:"brand",children:r.brand}),(r==null?void 0:r.description)&&i("span",{className:"description",children:r.description}),(r==null?void 0:r.googleCategory)&&i("span",{className:"description",children:r.googleCategory}),(r==null?void 0:r.condition)&&i("span",{className:"condition",children:r.condition}),(r==null?void 0:r.gender)&&i("span",{className:"gender",children:r.gender}),(r==null?void 0:r.ageGroup)&&i("span",{className:"age_group",children:r.ageGroup}),(r==null?void 0:r.gtin)&&i("span",{className:"gtin",children:r.gtin}),(r==null?void 0:r.category)&&(r==null?void 0:r.category.map((n,C)=>i("span",{className:"category",children:n},C))),(r==null?void 0:r.tags1)&&r.tags1.map((n,C)=>i("span",{className:"tag1",children:n},C)),(r==null?void 0:r.tags2)&&r.tags2.map((n,C)=>i("span",{className:"tag2",children:n},C)),(r==null?void 0:r.tags3)&&r.tags3.map((n,C)=>i("span",{className:"tag3",children:n},C)),(r==null?void 0:r.ratingValue)&&i("span",{className:"rating_value",children:r.ratingValue}),(r==null?void 0:r.reviewCount)&&i("span",{className:"review_count",children:r.reviewCount}),(r==null?void 0:r.alternateImageUrls)&&r.alternateImageUrls.map((n,C)=>i("span",{className:"alternate_image_url",children:n.toString()},C)),(r==null?void 0:r.customFields)&&Object.keys(r.customFields).map((n,C)=>r.customFields&&r.customFields[n]&&i("span",{className:n,children:r.customFields[n]},C)),(r==null?void 0:r.skus)&&r.skus.map((n,C)=>q("span",{className:"nosto_sku",children:[(n==null?void 0:n.id)&&i("span",{className:"product_id",children:n.id}),(n==null?void 0:n.name)&&i("span",{className:"name",children:n.name}),(n==null?void 0:n.price)&&i("span",{className:"price",children:n.price}),(n==null?void 0:n.listPrice)&&i("span",{className:"list_price",children:n.listPrice}),(n==null?void 0:n.url)&&i("span",{className:"url",children:n.url.toString()}),(n==null?void 0:n.imageUrl)&&i("span",{className:"image_url",children:n.imageUrl.toString()}),(n==null?void 0:n.gtin)&&i("span",{className:"gtin",children:n.gtin}),(n==null?void 0:n.availability)&&i("span",{className:"availability",children:n.availability}),(n==null?void 0:n.customFields)&&Object.keys(n.customFields).map((N,P)=>n.customFields&&n.customFields[N]&&i("span",{className:N,children:n.customFields[N]},P))]},C))]})]})}function tr(o){const{category:s,placements:r}=o,{recommendationComponent:d,useRenderCampaigns:m}=F(),{renderCampaigns:u,pageTypeUpdated:l}=m("home");return $(async y=>{const n=await y.defaultSession().viewCategory(s).setPlacements(r||y.placements.getPlacements()).load();u(n,y)},[s,d,l]),q(D,{children:[i("div",{className:"nosto_page_type",style:{display:"none"},children:"category"}),i("div",{className:"nosto_category",style:{display:"none"},children:s})]})}function nr(o){const{query:s,placements:r}=o,{recommendationComponent:d,useRenderCampaigns:m}=F(),{renderCampaigns:u,pageTypeUpdated:l}=m("search");return $(async y=>{const n=await y.defaultSession().viewSearch(s).setPlacements(r||y.placements.getPlacements()).load();u(n,y)},[s,d,l]),q(D,{children:[i("div",{className:"nosto_page_type",style:{display:"none"},children:"search"}),i("div",{className:"nosto_search",style:{display:"none"},children:s})]})}function z(o){return!o||typeof o!="object"||ar(o)||or(o)?o:Array.isArray(o)?o.map(z):Object.keys(o).reduce((s,r)=>{const d=r[0].toLowerCase()+r.slice(1).replace(/([A-Z]+)/g,(m,u)=>"_"+u.toLowerCase());return s[d]=z(o[r]),s},{})}function ar(o){return Object.prototype.toString.call(o)==="[object Date]"}function or(o){return Object.prototype.toString.call(o)==="[object RegExp]"}function sr(o){const{order:s,placements:r}=o,{recommendationComponent:d,useRenderCampaigns:m}=F(),{renderCampaigns:u,pageTypeUpdated:l}=m("order");return $(async y=>{const n=await y.defaultSession().addOrder(z(s)).setPlacements(r||y.placements.getPlacements()).load();u(n,y)},[d,l]),q(D,{children:[i("div",{className:"nosto_page_type",style:{display:"none"},children:"order"}),i("div",{className:"nosto_order",style:{display:"none"},children:s.purchase.number})]})}function ir(o){const{recommendationComponent:s,useRenderCampaigns:r}=F(),{renderCampaigns:d,pageTypeUpdated:m}=r("home");return $(async u=>{const l=await u.defaultSession().viewFrontPage().setPlacements(o.placements||u.placements.getPlacements()).load();d(l,u)},[s,m]),i(D,{children:i("div",{className:"nosto_page_type",style:{display:"none"},children:"front"})})}function cr(o){const{id:s,pageType:r}=o;return i("div",{className:"nosto_element",id:s},s+(r||""))}function lr(o){const{account:s,multiCurrency:r=!1,host:d,children:m,recommendationComponent:u,shopifyMarkets:l}=o,[y,n]=b.useState(!1),C=b.useMemo(()=>y,[y]),N=r?o.currentVariation:"",P=b.isValidElement(u)?"JSON_ORIGINAL":"HTML";function I(A){return b.cloneElement(u,{nostoRecommendation:A.nostoRecommendation})}const[V,Z]=b.useState("");function le(A=""){const g=b.useRef({});b.useEffect(()=>{V!==A&&Z(A)},[]);const w=A===V;function _(O,j){if(P=="HTML")j.placements.injectCampaigns(O.recommendations);else{const W=O.campaigns.recommendations;for(const Y in W){const ue=W[Y],Q="#"+Y,k=()=>document.querySelector(Q);k()&&(g.current[Y]||(g.current[Y]=ze.createRoot(k())),g.current[Y].render(i(I,{nostoRecommendation:ue})))}}}return{renderCampaigns:_,pageTypeUpdated:w}}return b.useEffect(()=>{var A,g,w;if(window.nostojs||(window.nostojs=_=>{(window.nostojs.q=window.nostojs.q||[]).push(_)},window.nostojs(_=>_.setAutoLoad(!1))),!document.querySelectorAll("[nosto-client-script]").length&&!l){const _=document.createElement("script");_.type="text/javascript",_.src="//"+(d||"connect.nosto.com")+"/include/"+s,_.async=!0,_.setAttribute("nosto-client-script",""),_.onload=()=>{var O;typeof jest<"u"&&((O=window.nosto)==null||O.reload({site:"localhost"})),n(!0)},document.body.appendChild(_)}if(l){const _=document.querySelector("[nosto-client-script]"),O=document.querySelector("#nosto-sandbox");if(!_||(_==null?void 0:_.getAttribute("nosto-language"))!==(l==null?void 0:l.language)||(_==null?void 0:_.getAttribute("nosto-market-id"))!==(l==null?void 0:l.marketId)){y&&n(!1),(A=_==null?void 0:_.parentNode)==null||A.removeChild(_),(g=O==null?void 0:O.parentNode)==null||g.removeChild(O);const j=document.createElement("script");j.type="text/javascript",j.src="//"+(d||"connect.nosto.com")+`/script/shopify/market/nosto.js?merchant=${s}&market=${l.marketId||""}&locale=${((w=l==null?void 0:l.language)==null?void 0:w.toLowerCase())||""}`,j.async=!0,j.setAttribute("nosto-client-script",""),j.setAttribute("nosto-language",(l==null?void 0:l.language)||""),j.setAttribute("nosto-market-id",String(l==null?void 0:l.marketId)),j.onload=()=>{var W;typeof jest<"u"&&((W=window.nosto)==null||W.reload({site:"localhost"})),n(!0)},document.body.appendChild(j)}}},[y,l]),i(oe.Provider,{value:{account:s,clientScriptLoaded:C,currentVariation:N,responseMode:P,recommendationComponent:u,useRenderCampaigns:le,pageType:V},children:m})}function ur(o){const{cart:s,customer:r}=o,{clientScriptLoaded:d}=F();return Ee(()=>{const m=s?z(s):void 0,u=r?z(r):void 0;d&&window.nostojs(l=>{l.defaultSession().setResponseMode("HTML").setCart(m).setCustomer(u).viewOther().load()})},[d,s,r]),i(D,{})}R.Nosto404=Qe,R.NostoCategory=tr,R.NostoCheckout=er,R.NostoContext=oe,R.NostoHome=ir,R.NostoOrder=sr,R.NostoOther=ke,R.NostoPlacement=cr,R.NostoProduct=rr,R.NostoProvider=lr,R.NostoSearch=nr,R.NostoSession=ur,R.useNostoContext=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": "0.
|
|
4
|
+
"version": "0.5.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",
|
package/src/types.ts
CHANGED
|
@@ -34,11 +34,11 @@ export interface SessionAction {
|
|
|
34
34
|
/**
|
|
35
35
|
* @group Types
|
|
36
36
|
*/
|
|
37
|
-
export interface
|
|
38
|
-
setCart(cart?: Cart):
|
|
39
|
-
setCustomer(customer?: Customer):
|
|
40
|
-
setResponseMode(mode: string):
|
|
41
|
-
setVariation(variation?: string):
|
|
37
|
+
export interface NostoClientSession {
|
|
38
|
+
setCart(cart?: Cart): NostoClientSession
|
|
39
|
+
setCustomer(customer?: Customer): NostoClientSession
|
|
40
|
+
setResponseMode(mode: string): NostoClientSession
|
|
41
|
+
setVariation(variation?: string): NostoClientSession
|
|
42
42
|
addOrder(order: { purchase: Purchase }): SessionAction
|
|
43
43
|
viewCategory(category: string): SessionAction
|
|
44
44
|
viewProduct(product: string): SessionAction
|
|
@@ -54,7 +54,7 @@ export interface NostoSession {
|
|
|
54
54
|
*/
|
|
55
55
|
export interface NostoClient {
|
|
56
56
|
setAutoLoad(autoload: boolean): NostoClient
|
|
57
|
-
defaultSession():
|
|
57
|
+
defaultSession(): NostoClientSession
|
|
58
58
|
placements: {
|
|
59
59
|
getPlacements(): string[]
|
|
60
60
|
injectCampaigns(recommendations: Record<string, Recommendation>): void
|