nextjs-seo-manager
Version:
2 lines (1 loc) • 6.63 kB
JavaScript
import{cache as e}from"react";import{getApps as t,initializeApp as o,getApp as r}from"firebase/app";import{getAuth as n}from"firebase/auth";import s from"axios";export{AppSEOHelper}from"./AppSEOHelper";function i(e,t,o,r){return new(o||(o=Promise))(function(n,s){function i(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(i,a)}l((r=r.apply(e,t||[])).next())})}var a;"function"==typeof SuppressedError&&SuppressedError;const l="Test"!==process.env.NEXT_PUBLIC_NODE_ENV_MANAGER&&"Development"!==process.env.NEXT_PUBLIC_NODE_ENV_MANAGER?{apiKey:"AIzaSyDPjpRmobrdUtIY3hIaNoyox7alxYJH_B8",authDomain:"seo-manager-live.firebaseapp.com",projectId:"seo-manager-live",storageBucket:"seo-manager-live.appspot.com",messagingSenderId:"510256510596",appId:"1:510256510596:web:eae1ccc42cb103b8a7f4d1",measurementId:"G-RED1HCM49W"}:{apiKey:"AIzaSyBD6KEJFm2SVguRDEiqufIlRo5HuHu0IZg",authDomain:"seo-manager-test.firebaseapp.com",projectId:"seo-manager-test",storageBucket:"seo-manager-test.appspot.com",messagingSenderId:"682714204028",appId:"1:682714204028:web:a782b9da96ce811ee606f9",measurementId:"G-PYZDK47B2M"};let d;d=(null===(a=t())||void 0===a?void 0:a.findIndex(e=>"seo-manager"===(null==e?void 0:e.name)))<0?o(l,"seo-manager"):r("seo-manager");const c=()=>{let e={};return process.env.SEO_MANAGER_MODULE_SECRETKEY&&(e.secretKey=process.env.SEO_MANAGER_MODULE_SECRETKEY),process.env.SEO_MANAGER_MODULE_PROJECTKEY&&(e.projectKey=process.env.SEO_MANAGER_MODULE_PROJECTKEY),process.env.SEO_MANAGER_MODULE_PROJECTID&&(e.projectId=process.env.SEO_MANAGER_MODULE_PROJECTID),e},u=e=>{let t=e;return"/"===t[0]&&(t=t.replace("/","")),t};n(d);const p=e=>new Promise(t=>i(void 0,void 0,void 0,function*(){try{if("undefined"!=typeof window)throw{error:"This function is only allowed to be called in a server environment, not in the client. If you are using NextJS this belong in getServerSideProps or getStaticProps."};if(!e)throw{error:"You must pass page path!"};const o=c(),{results:r,error:n}=yield((e,t="put",o,r,n)=>new Promise((a,l)=>i(void 0,void 0,void 0,function*(){var i,d,p,v,E,g,m,_,f,h,N,O;try{const v=c();if(!(null==v?void 0:v.projectId))return l({results:!1,error:"Project Id is required"});if(!(null==v?void 0:v.secretKey))return l({results:!1,error:"Project Secret Key is required"});const E=u(e),g=r||("Test"!==process.env.NEXT_PUBLIC_NODE_ENV_MANAGER&&"Development"!==process.env.NEXT_PUBLIC_NODE_ENV_MANAGER?`https://v1.seomanager.dev/${E}`:"Test"===process.env.NEXT_PUBLIC_NODE_ENV_MANAGER?`http://localhost:3002/${E}`:`https://v1-testing.seomanager.dev/${E}`);let m={X_ProjectId:null==v?void 0:v.projectId,X_ProjectKey:(null==v?void 0:v.projectKey)||"",X_ProjectSecretKey:(null==v?void 0:v.secretKey)||""};n&&(m=Object.assign(Object.assign({},m),n));const _={method:t,url:g,headers:m};"get"===t?_.params=o||{}:_.data=o||{};const f=yield s(_);return a(Object.assign(Object.assign({},(null==f?void 0:f.data)||{}),{results:null===(i=null==f?void 0:f.data)||void 0===i?void 0:i.results,error:(null===(d=null==f?void 0:f.data)||void 0===d?void 0:d.error)||!1,message:(null===(p=null==f?void 0:f.data)||void 0===p?void 0:p.message)||"Successful",statusCode:f.status}))}catch(e){return console.log("SERVER SECRET CALL ERROR:",e),a(Object.assign(Object.assign({},(null===(v=null==e?void 0:e.response)||void 0===v?void 0:v.data)||{}),{results:(null===(g=null===(E=null==e?void 0:e.response)||void 0===E?void 0:E.data)||void 0===g?void 0:g.results)||!1,error:(null===(_=null===(m=null==e?void 0:e.response)||void 0===m?void 0:m.data)||void 0===_?void 0:_.error)||!0,message:(null===(h=null===(f=null==e?void 0:e.response)||void 0===f?void 0:f.data)||void 0===h?void 0:h.message)||(null===(N=null==e?void 0:e.response)||void 0===N?void 0:N.data)||"There was an error on our end! Please try again in a few minutes!",statusCode:null===(O=null==e?void 0:e.response)||void 0===O?void 0:O.status}))}})))("/seo/server_get","get",{projectId:null==o?void 0:o.projectId,pagePath:e});return t(r?{results:r,error:"",message:"Successful"}:{results:!1,error:n,message:"No SEO data for this page found"})}catch(e){return t({results:!1,error:e.error,message:"Not Successful"})}}));function v(e,t={}){var o;const r=(null==e?void 0:e.page)||{},n=(null==e?void 0:e.global)||{},s=r.title||n.defaultTitle||t.title||"",i=r.description||n.defaultDescription||t.description||"",a=r.keywords||t.keywords,l=(null===(o=r.image)||void 0===o?void 0:o.url)||t.image||"",d=r.path||t.path||"",c=n.canonicalURL||"";return{title:s,description:i,keywords:a,imageUrl:l,canonical:c&&d?`${c.replace(/\/$/,"")}${d.startsWith("/")?d:`/${d}`}`:d?d.startsWith("/")?d:`/${d}`:t.canonical||"",index:"noindex"!==r.index,follow:"nofollow"!==r.follow,structuredData:r.ldJson||null}}function E(e,t={},o={}){var r;const{title:n,description:s,keywords:i,imageUrl:a,canonical:l,index:d,follow:c,structuredData:u}=v(e,t),p=null!==(r=o.robotsOverride)&&void 0!==r?r:{index:d,follow:c},E={title:n||t.title,description:s||t.description,keywords:i||t.keywords,openGraph:{title:n||t.title,description:s||t.description,images:[{url:a||t.image,width:1200,height:630,alt:n||t.title}],type:"website",locale:"en_US"},twitter:{card:"summary_large_image",title:n||t.title,description:s||t.description,images:[a||t.image]},alternates:{canonical:l||t.canonical},robots:p},g=o.structuredData||u;return g&&(E.structuredData=g),E}function g(t,o={},r={}){const n=e(()=>(e=>new Promise(t=>i(void 0,void 0,void 0,function*(){const o=yield p(e);return t((null==o?void 0:o.results)||{})})))(t,r.meta));return{generateMetadata:()=>i(this,void 0,void 0,function*(){try{return E(yield n(),o,r.metadataOptions)}catch(e){return console.error("Error fetching SEO data:",e),E({},o,r.metadataOptions)}}),getSEOData:()=>i(this,void 0,void 0,function*(){var e,t,o;try{const r=yield n(),s=c(),i="Test"!==process.env.NEXT_PUBLIC_NODE_ENV_MANAGER&&"Development"!==process.env.NEXT_PUBLIC_NODE_ENV_MANAGER?"https://v1.seomanager.dev":"Test"===process.env.NEXT_PUBLIC_NODE_ENV_MANAGER?"http://localhost:3002":"https://v1-testing.seomanager.dev";return Object.assign(Object.assign({},r),{_ping:{url:`${i}/seo/ping`,projectId:s.projectId||(null===(e=null==r?void 0:r.global)||void 0===e?void 0:e.projectId)||"",projectKey:s.projectKey||"",pageId:(null===(t=null==r?void 0:r.page)||void 0===t?void 0:t.pageId)||"",path:(null===(o=null==r?void 0:r.page)||void 0===o?void 0:o.path)||""}})}catch(e){return null}})}}export{E as buildMetadataFromSEO,g as createPageSEO,v as mapFetchSEOToMetadata};