@nosto/nosto-react 0.4.1 → 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/README.md +5 -2
- package/dist/index.d.ts +519 -0
- package/dist/index.es.js +1117 -0
- package/dist/index.umd.js +25 -0
- package/package.json +20 -13
- package/src/components/Nosto404.tsx +47 -0
- package/src/components/{Category/index.client.tsx → NostoCategory.tsx} +18 -39
- package/src/components/NostoCheckout.tsx +47 -0
- package/src/components/{Home/index.client.tsx → NostoHome.tsx} +17 -36
- package/src/components/NostoOrder.tsx +55 -0
- package/src/components/NostoOther.tsx +46 -0
- package/src/components/{Placement/index.client.tsx → NostoPlacement.tsx} +5 -8
- package/src/components/{Product/index.client.tsx → NostoProduct.tsx} +37 -81
- package/src/components/NostoProvider.tsx +220 -0
- package/src/components/{Search/index.client.tsx → NostoSearch.tsx} +18 -39
- package/src/components/{Session/index.client.tsx → NostoSession.tsx} +14 -17
- package/src/components/context.ts +55 -0
- package/src/components/index.ts +14 -0
- package/src/index.ts +3 -0
- package/src/types.ts +112 -97
- package/src/utils/compare.ts +9 -9
- package/src/utils/hooks.ts +28 -8
- package/src/utils/object.ts +10 -11
- package/src/utils/snakeize.ts +11 -11
- package/dist/index.es.client.js +0 -660
- package/dist/index.umd.client.js +0 -9
- package/src/components/Checkout/index.client.tsx +0 -66
- package/src/components/Fohofo/index.client.tsx +0 -66
- package/src/components/Order/index.client.tsx +0 -72
- package/src/components/Other/index.client.tsx +0 -64
- package/src/components/Provider/context.client.ts +0 -45
- package/src/components/Provider/index.client.tsx +0 -222
- package/src/index.client.ts +0 -33
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
* @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 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,15 +14,16 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "vite",
|
|
17
|
-
"build": "tsc && 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",
|
|
21
|
-
"
|
|
21
|
+
"lint": "eslint 'src/**/*.{ts,tsx}' --cache",
|
|
22
22
|
"clean": "rimraf dist",
|
|
23
|
-
"prettier": "prettier '{src,spec}
|
|
24
|
-
"prettier:fix": "prettier '{src,spec}
|
|
25
|
-
"test": "jest spec"
|
|
23
|
+
"prettier": "prettier '{src,spec}/**' --list-different",
|
|
24
|
+
"prettier:fix": "prettier '{src,spec}/**' --write",
|
|
25
|
+
"test": "jest spec",
|
|
26
|
+
"typedoc": "typedoc src/index.ts"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
29
|
"dist",
|
|
@@ -36,7 +37,12 @@
|
|
|
36
37
|
"@types/react": "^18.0.0",
|
|
37
38
|
"@types/react-dom": "^18.0.0",
|
|
38
39
|
"@types/user-event": "^4.1.1",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
41
|
+
"@typescript-eslint/parser": "^6.11.0",
|
|
39
42
|
"@vitejs/plugin-react": "^1.3.0",
|
|
43
|
+
"eslint": "^8.53.0",
|
|
44
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
45
|
+
"eslint-plugin-react": "^7.33.2",
|
|
40
46
|
"jest": "^29.5.0",
|
|
41
47
|
"jest-environment-jsdom": "^29.5.0",
|
|
42
48
|
"prettier": "^2.0.5",
|
|
@@ -46,17 +52,18 @@
|
|
|
46
52
|
"ts-jest": "^29.1.0",
|
|
47
53
|
"typedoc": "^0.24.1",
|
|
48
54
|
"typescript": "^4.6.3",
|
|
49
|
-
"vite": "^2.
|
|
55
|
+
"vite": "^5.2.10",
|
|
56
|
+
"vite-plugin-dts": "^3.9.1"
|
|
50
57
|
},
|
|
51
|
-
"main": "./dist/index.umd.
|
|
52
|
-
"module": "./dist/index.es.
|
|
53
|
-
"types": "./
|
|
58
|
+
"main": "./dist/index.umd.js",
|
|
59
|
+
"module": "./dist/index.es.js",
|
|
60
|
+
"types": "./dist/index.d.ts",
|
|
54
61
|
"exports": {
|
|
55
62
|
".": {
|
|
56
|
-
"import": "./dist/index.es.
|
|
57
|
-
"require": "./dist/index.umd.
|
|
63
|
+
"import": "./dist/index.es.js",
|
|
64
|
+
"require": "./dist/index.umd.js"
|
|
58
65
|
},
|
|
59
|
-
"./shopify-hydrogen": "./dist/index.es.
|
|
66
|
+
"./shopify-hydrogen": "./dist/index.es.js"
|
|
60
67
|
},
|
|
61
68
|
"bugs": {
|
|
62
69
|
"url": "https://github.com/Nosto/nosto-react/issues"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useNostoContext } from "./context"
|
|
2
|
+
import { useNostoApi } from "../utils/hooks"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* You can personalise your cart and checkout pages by using the `Nosto404` component.
|
|
6
|
+
* The component does not require any props.
|
|
7
|
+
*
|
|
8
|
+
* By default, your account, when created, has three 404-page placements named `notfound-nosto-1`, `notfound-nosto-2` and `notfound-nosto-3`.
|
|
9
|
+
* You may omit these and use any identifier you need.
|
|
10
|
+
* The identifiers used here are simply provided to illustrate the example.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* <div className="notfound-page">
|
|
15
|
+
* <NostoPlacement id="notfound-nosto-1" />
|
|
16
|
+
* <NostoPlacement id="notfound-nosto-2" />
|
|
17
|
+
* <NostoPlacement id="notfound-nosto-3" />
|
|
18
|
+
* <Nosto404 />
|
|
19
|
+
* </div>
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @group Components
|
|
23
|
+
*/
|
|
24
|
+
export default function Nosto404(props: { placements?: string[] }) {
|
|
25
|
+
const { recommendationComponent, useRenderCampaigns } = useNostoContext()
|
|
26
|
+
|
|
27
|
+
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("404")
|
|
28
|
+
|
|
29
|
+
useNostoApi(
|
|
30
|
+
async (api) => {
|
|
31
|
+
const data = await api.defaultSession()
|
|
32
|
+
.viewNotFound()
|
|
33
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
34
|
+
.load()
|
|
35
|
+
renderCampaigns(data, api)
|
|
36
|
+
},
|
|
37
|
+
[recommendationComponent, pageTypeUpdated]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
43
|
+
notfound
|
|
44
|
+
</div>
|
|
45
|
+
</>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useNostoContext } from "./context"
|
|
2
|
+
import { useNostoApi } from "../utils/hooks"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* You can personalise your category and collection pages by using the NostoCategory component.
|
|
@@ -21,45 +21,24 @@ import { useNostoContext } from "../Provider/context.client";
|
|
|
21
21
|
* If the category being viewed is `Mens >> Jackets`, you must provide the name as `/Mens/Jackets`.
|
|
22
22
|
* You must ensure that the category path provided here matches that of the categories tagged in your products.
|
|
23
23
|
*
|
|
24
|
-
* @group
|
|
24
|
+
* @group Components
|
|
25
25
|
*/
|
|
26
|
-
export default function NostoCategory(props: {
|
|
27
|
-
category
|
|
28
|
-
|
|
29
|
-
}): JSX.Element {
|
|
30
|
-
const { category } = props;
|
|
31
|
-
const {
|
|
32
|
-
clientScriptLoaded,
|
|
33
|
-
currentVariation,
|
|
34
|
-
responseMode,
|
|
35
|
-
recommendationComponent,
|
|
36
|
-
useRenderCampaigns,
|
|
37
|
-
} = useNostoContext();
|
|
26
|
+
export default function NostoCategory(props: { category: string; placements?: string[] }) {
|
|
27
|
+
const { category, placements } = props
|
|
28
|
+
const { recommendationComponent, useRenderCampaigns } = useNostoContext()
|
|
38
29
|
|
|
39
|
-
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("home")
|
|
30
|
+
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("home")
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.then((data) => {
|
|
52
|
-
renderCampaigns(data, api);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}, [
|
|
57
|
-
clientScriptLoaded,
|
|
58
|
-
category,
|
|
59
|
-
currentVariation,
|
|
60
|
-
recommendationComponent,
|
|
61
|
-
pageTypeUpdated,
|
|
62
|
-
]);
|
|
32
|
+
useNostoApi(
|
|
33
|
+
async (api) => {
|
|
34
|
+
const data = await api.defaultSession()
|
|
35
|
+
.viewCategory(category)
|
|
36
|
+
.setPlacements(placements || api.placements.getPlacements())
|
|
37
|
+
.load()
|
|
38
|
+
renderCampaigns(data, api)
|
|
39
|
+
},
|
|
40
|
+
[category, recommendationComponent, pageTypeUpdated]
|
|
41
|
+
)
|
|
63
42
|
|
|
64
43
|
return (
|
|
65
44
|
<>
|
|
@@ -70,5 +49,5 @@ export default function NostoCategory(props: {
|
|
|
70
49
|
{category}
|
|
71
50
|
</div>
|
|
72
51
|
</>
|
|
73
|
-
)
|
|
52
|
+
)
|
|
74
53
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useNostoContext } from "./context"
|
|
2
|
+
import { useNostoApi } from "../utils/hooks"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* You can personalise your cart and checkout pages by using the NostoCheckout component.
|
|
6
|
+
* The component does not require any props.
|
|
7
|
+
*
|
|
8
|
+
* By default, your account, when created, has two cart-page placements named `categorypage-nosto-1` and `categorypage-nosto-2`.
|
|
9
|
+
* You may omit these and use any identifier you need.
|
|
10
|
+
* The identifiers used here are simply provided to illustrate the example.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* <div className="checkout-page">
|
|
15
|
+
* <NostoPlacement id="checkout-nosto-1" />
|
|
16
|
+
* <NostoPlacement id="checkout-nosto-2" />
|
|
17
|
+
* <NostoCheckout />
|
|
18
|
+
* </div>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @group Components
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export default function NostoCheckout(props: { placements?: string[] }) {
|
|
25
|
+
const { recommendationComponent, useRenderCampaigns } = useNostoContext()
|
|
26
|
+
|
|
27
|
+
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("checkout")
|
|
28
|
+
|
|
29
|
+
useNostoApi(
|
|
30
|
+
async (api) => {
|
|
31
|
+
const data = await api.defaultSession()
|
|
32
|
+
.viewCart()
|
|
33
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
34
|
+
.load()
|
|
35
|
+
renderCampaigns(data, api)
|
|
36
|
+
},
|
|
37
|
+
[recommendationComponent, pageTypeUpdated]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
43
|
+
cart
|
|
44
|
+
</div>
|
|
45
|
+
</>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useNostoContext } from "./context"
|
|
2
|
+
import { useNostoApi } from "../utils/hooks"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The `NostoHome` component must be used to personalise the home page. The component does not require any props.
|
|
@@ -22,42 +22,23 @@ import { useNostoContext } from "../Provider/context.client";
|
|
|
22
22
|
* </div>
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
25
|
-
* @group
|
|
25
|
+
* @group Components
|
|
26
26
|
*/
|
|
27
|
-
export default function NostoHome(props: {
|
|
28
|
-
|
|
29
|
-
}): JSX.Element {
|
|
30
|
-
const {
|
|
31
|
-
clientScriptLoaded,
|
|
32
|
-
currentVariation,
|
|
33
|
-
responseMode,
|
|
34
|
-
recommendationComponent,
|
|
35
|
-
useRenderCampaigns,
|
|
36
|
-
} = useNostoContext();
|
|
27
|
+
export default function NostoHome(props: { placements?: string[] }) {
|
|
28
|
+
const { recommendationComponent, useRenderCampaigns } = useNostoContext()
|
|
37
29
|
|
|
38
|
-
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("home")
|
|
30
|
+
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("home")
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.then((data) => {
|
|
51
|
-
renderCampaigns(data, api);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}, [
|
|
56
|
-
clientScriptLoaded,
|
|
57
|
-
currentVariation,
|
|
58
|
-
recommendationComponent,
|
|
59
|
-
pageTypeUpdated,
|
|
60
|
-
]);
|
|
32
|
+
useNostoApi(
|
|
33
|
+
async (api) => {
|
|
34
|
+
const data = await api.defaultSession()
|
|
35
|
+
.viewFrontPage()
|
|
36
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
37
|
+
.load()
|
|
38
|
+
renderCampaigns(data, api)
|
|
39
|
+
},
|
|
40
|
+
[recommendationComponent, pageTypeUpdated]
|
|
41
|
+
)
|
|
61
42
|
|
|
62
43
|
return (
|
|
63
44
|
<>
|
|
@@ -65,5 +46,5 @@ export default function NostoHome(props: {
|
|
|
65
46
|
front
|
|
66
47
|
</div>
|
|
67
48
|
</>
|
|
68
|
-
)
|
|
49
|
+
)
|
|
69
50
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Purchase } from "../types"
|
|
2
|
+
import { useNostoContext } from "./context"
|
|
3
|
+
import { snakeize } from "../utils/snakeize"
|
|
4
|
+
import { useNostoApi } from "../utils/hooks"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* You can personalise your order-confirmation/thank-you page by using the `NostoOrder` component.
|
|
8
|
+
* The component requires that you provide it with the details of the order.
|
|
9
|
+
*
|
|
10
|
+
* By default, your account, when created, has one other-page placement named `thankyou-nosto-1`.
|
|
11
|
+
* You may omit this and use any identifier you need. The identifier used here is simply provided to illustrate the example.
|
|
12
|
+
*
|
|
13
|
+
* The order prop requires a value that adheres to the type `Purchase`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```
|
|
17
|
+
* <div className="thankyou-page">
|
|
18
|
+
* <NostoPlacement id="thankyou-nosto-1" />
|
|
19
|
+
* <NostoOrder order={{ purchase: toOrder(order) }} />
|
|
20
|
+
* </div>
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @group Components
|
|
24
|
+
*/
|
|
25
|
+
export default function NostoOrder(props: {
|
|
26
|
+
order: { purchase: Purchase }
|
|
27
|
+
placements?: string[]
|
|
28
|
+
}) {
|
|
29
|
+
const { order, placements } = props
|
|
30
|
+
const { recommendationComponent, useRenderCampaigns } = useNostoContext()
|
|
31
|
+
|
|
32
|
+
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("order")
|
|
33
|
+
|
|
34
|
+
useNostoApi(
|
|
35
|
+
async (api) => {
|
|
36
|
+
const data = await api.defaultSession()
|
|
37
|
+
.addOrder(snakeize(order))
|
|
38
|
+
.setPlacements(placements || api.placements.getPlacements())
|
|
39
|
+
.load()
|
|
40
|
+
renderCampaigns(data, api)
|
|
41
|
+
},
|
|
42
|
+
[recommendationComponent, pageTypeUpdated]
|
|
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
|
+
)
|
|
55
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useNostoContext } from "./context"
|
|
2
|
+
import { useNostoApi } from "../utils/hooks"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* You can personalise your miscellaneous pages by using the NostoOther component.
|
|
6
|
+
* The component does not require any props.
|
|
7
|
+
*
|
|
8
|
+
* By default, your account, when created, has two other-page placements named `other-nosto-1` and `other-nosto-2`.
|
|
9
|
+
* You may omit these and use any identifier you need.
|
|
10
|
+
* The identifiers used here are simply provided to illustrate the example.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* <div className="other-page">
|
|
15
|
+
* <NostoPlacement id="other-nosto-1" />
|
|
16
|
+
* <NostoPlacement id="other-nosto-2" />
|
|
17
|
+
* <NostoOther />
|
|
18
|
+
* </div>;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @group Components
|
|
22
|
+
*/
|
|
23
|
+
export default function NostoOther(props: { placements?: string[] }) {
|
|
24
|
+
const { recommendationComponent, useRenderCampaigns } = useNostoContext()
|
|
25
|
+
|
|
26
|
+
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("other")
|
|
27
|
+
|
|
28
|
+
useNostoApi(
|
|
29
|
+
async (api) => {
|
|
30
|
+
const data = await api.defaultSession()
|
|
31
|
+
.viewOther()
|
|
32
|
+
.setPlacements(props.placements || api.placements.getPlacements())
|
|
33
|
+
.load()
|
|
34
|
+
renderCampaigns(data, api)
|
|
35
|
+
},
|
|
36
|
+
[recommendationComponent, pageTypeUpdated]
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
<div className="nosto_page_type" style={{ display: "none" }}>
|
|
42
|
+
other
|
|
43
|
+
</div>
|
|
44
|
+
</>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react"
|
|
1
|
+
import React from "react"
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Nosto React has a special component called NostoPlacement.
|
|
@@ -11,12 +11,9 @@ import React from "react";
|
|
|
11
11
|
* <NostoPlacement id="frontpage-nosto-1" />
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* @group
|
|
14
|
+
* @group Components
|
|
15
15
|
*/
|
|
16
|
-
export default function NostoPlacement(props: {
|
|
17
|
-
id
|
|
18
|
-
pageType
|
|
19
|
-
}): JSX.Element {
|
|
20
|
-
const { id, pageType } = props;
|
|
21
|
-
return <div className="nosto_element" id={id} key={id + (pageType || "")} />;
|
|
16
|
+
export default function NostoPlacement(props: { id: string; pageType?: string }) {
|
|
17
|
+
const { id, pageType } = props
|
|
18
|
+
return <div className="nosto_element" id={id} key={id + (pageType || "")} />
|
|
22
19
|
}
|