nextjs-seo-manager
Version:
2 lines (1 loc) • 8.6 kB
JavaScript
import{getApps as e,initializeApp as r,getApp as o}from"firebase/app";import{getAuth as t}from"firebase/auth";import n from"axios";const s=()=>{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},i=e=>{process.env.SEO_MANAGER_MODULE_PROJECT=JSON.stringify(e)},a=()=>{const e=process.env.SEO_MANAGER_MODULE_PROJECT;return e?JSON.parse(e):null},l=e=>{process.env.SEO_MANAGER_MODULE_PROJECTPLAN=JSON.stringify(e)},d=()=>{const e=process.env.SEO_MANAGER_MODULE_PROJECTPLAN;return e?JSON.parse(e):null};function u(e,r,o,t){return new(o||(o=Promise))(function(n,s){function i(e){try{l(t.next(e))}catch(e){s(e)}}function a(e){try{l(t.throw(e))}catch(e){s(e)}}function l(e){var r;e.done?n(e.value):(r=e.value,r instanceof o?r:new o(function(e){e(r)})).then(i,a)}l((t=t.apply(e,r||[])).next())})}var c;"function"==typeof SuppressedError&&SuppressedError;const v="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 p;p=(null===(c=e())||void 0===c?void 0:c.findIndex(e=>"seo-manager"===(null==e?void 0:e.name)))<0?r(v,"seo-manager"):o("seo-manager");const E=(e,r="put",o,t,i)=>new Promise((a,l)=>u(void 0,void 0,void 0,function*(){var d,u,c,v,p,E,m,_,O,f,y,h;try{const v=s();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 p=g(e),E=t||("Test"!==process.env.NEXT_PUBLIC_NODE_ENV_MANAGER&&"Development"!==process.env.NEXT_PUBLIC_NODE_ENV_MANAGER?`https://v1.seomanager.dev/${p}`:"Test"===process.env.NEXT_PUBLIC_NODE_ENV_MANAGER?`http://localhost:3002/${p}`:`https://v1-testing.seomanager.dev/${p}`);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)||""};i&&(m=Object.assign(Object.assign({},m),i));const _={method:r,url:E,headers:m};"get"===r?_.params=o||{}:_.data=o||{};const O=yield n(_);return a(Object.assign(Object.assign({},(null==O?void 0:O.data)||{}),{results:null===(d=null==O?void 0:O.data)||void 0===d?void 0:d.results,error:(null===(u=null==O?void 0:O.data)||void 0===u?void 0:u.error)||!1,message:(null===(c=null==O?void 0:O.data)||void 0===c?void 0:c.message)||"Successful",statusCode:O.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===(E=null===(p=null==e?void 0:e.response)||void 0===p?void 0:p.data)||void 0===E?void 0:E.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===(f=null===(O=null==e?void 0:e.response)||void 0===O?void 0:O.data)||void 0===f?void 0:f.message)||(null===(y=null==e?void 0:e.response)||void 0===y?void 0:y.data)||"There was an error on our end! Please try again in a few minutes!",statusCode:null===(h=null==e?void 0:e.response)||void 0===h?void 0:h.status}))}})),g=e=>{let r=e;return"/"===r[0]&&(r=r.replace("/","")),r};t(p);const m=(e,r={})=>new Promise(r=>u(void 0,void 0,void 0,function*(){const o=yield(e=>new Promise(r=>u(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=s(),{results:t,error:n}=yield E("/seo/server_get","get",{projectId:null==o?void 0:o.projectId,pagePath:e});return r(t?{results:t,error:"",message:"Successful"}:{results:!1,error:n,message:"No SEO data for this page found"})}catch(e){return r({results:!1,error:e.error,message:"Not Successful"})}})))(e);return r((null==o?void 0:o.results)||{})})),_=e=>new Promise(r=>u(void 0,void 0,void 0,function*(){var o,t;try{O();const t=yield E("/backend_api/validate","put",{encrypted:(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.encrypted)||{}});return r(t)}catch(e){return r({results:!1,message:(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.error)||(null==e?void 0:e.error)||"Something went wrong",error:!0})}})),O=()=>{const e=A();if(!(null==e?void 0:e.secretKey))throw{error:"Please add a secretKey by calling the SEOInit function SEOInit({secretKey: <<Add Value Here>>. Make sure you initialize this in your Api, not _app.js!"};if(!(null==e?void 0:e.projectId))throw{error:"Please add a projectId by calling the SEOInit function SEOInit({projectId: <<Add Value Here>>. Make sure you initialize this in your Api, not _app.js!"}};function f(e){return new Promise(r=>u(this,void 0,void 0,function*(){var o,t;try{if((null==e?void 0:e.length)>50)return r({results:!1,message:"You are limited to 50 inserts at the same time!",error:!0});O();const o=yield E("backend_api/seo/insert","post",{pageSEO:e});return r(o)}catch(e){return console.error(e),r({results:!1,message:(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.message)||(null==e?void 0:e.message)||"Something went wrong",error:(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.error)||(null==e?void 0:e.error)||"Something went wrong"})}}))}const y=(e,r,o)=>new Promise(t=>u(void 0,void 0,void 0,function*(){var n;try{if((null==e?void 0:e.length)>50)return t({results:!1,message:"You are limited to 50 updates at the same time!",error:!0});O();const n=yield E("backend_api/seo/update","put",{pageIdentifiers:e,pageSEO:r,options:o});return t(n)}catch(e){return console.log("Error:",e),t({results:!1,message:(null===(n=null==e?void 0:e.data)||void 0===n?void 0:n.error)||(null==e?void 0:e.error)||"Something went wrong",error:!0})}})),h=e=>new Promise(r=>u(void 0,void 0,void 0,function*(){var o;try{if((null==e?void 0:e.length)>50)return r({results:!1,message:"You are limited to 50 deletes at the same time!",error:!0});O();const o=yield E("backend_api/seo/delete","post",{pageIdentifiers:e});return r(o)}catch(e){return r({results:!1,message:(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.error)||(null==e?void 0:e.error)||"Something went wrong",error:!0})}})),S=e=>new Promise(r=>u(void 0,void 0,void 0,function*(){var o;try{O();const o=yield E("backend_api/seo/getSeoPages","post",{pageIdentifiers:e});return r(o)}catch(e){return r({results:!1,error:!0,message:(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.error)||(null==e?void 0:e.error)||"Something went wrong"})}})),A=()=>{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};function R(e,r){var o;if(void 0!==(null==r?void 0:r.path))return"function"==typeof r.path?r.path(e):r.path;const t=null===(o=e.resolvedUrl)||void 0===o?void 0:o.split("?")[0],n=e.pathname;return t||n||"/"}function N(e,r){return o=>u(this,void 0,void 0,function*(){var t;const n=null!==(t=yield null==e?void 0:e(o))&&void 0!==t?t:{props:{}},s=R(o,r),i=yield m(s);return Object.assign(Object.assign({},n),{props:Object.assign(Object.assign({},n.props||{}),{seo:i||{}})})})}function I(e,r){return o=>u(this,void 0,void 0,function*(){var t;const n=null!==(t=yield null==e?void 0:e(o))&&void 0!==t?t:{props:{}},s=R(o,r),i=yield m(s);return Object.assign(Object.assign({},n),{props:Object.assign(Object.assign({},n.props||{}),{seo:i||{}})})})}export{_ as backendValidation,O as checkBackendKeys,h as deleteSeoPage,m as fetchSEO,S as getSeoPages,f as insertSeoPage,s as returnKey,a as returnProject,d as returnProjectPlan,i as setProject,l as setProjectPlan,y as updateSeoPage,N as withSEO,I as withSEOStatic};