nextjs-seo-manager
Version:
2 lines (1 loc) • 7.95 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("firebase/app"),r=require("firebase/auth");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=o(require("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};function n(e,r,o,t){return new(o||(o=Promise))(function(s,n){function i(e){try{d(t.next(e))}catch(e){n(e)}}function a(e){try{d(t.throw(e))}catch(e){n(e)}}function d(e){var r;e.done?s(e.value):(r=e.value,r instanceof o?r:new o(function(e){e(r)})).then(i,a)}d((t=t.apply(e,r||[])).next())})}var i;"function"==typeof SuppressedError&&SuppressedError;const a="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===(i=e.getApps())||void 0===i?void 0:i.findIndex(e=>"seo-manager"===(null==e?void 0:e.name)))<0?e.initializeApp(a,"seo-manager"):e.getApp("seo-manager");var l=d;const u=(e,r="put",o,i,a)=>new Promise((d,l)=>n(void 0,void 0,void 0,function*(){var n,u,v,p,E,g,_,m,O,S,f;try{const p=s();if(!(null==p?void 0:p.projectId))return l({results:!1,error:"Project Id is required"});if(!(null==p?void 0:p.secretKey))return l({results:!1,error:"Project Secret Key is required"});const E=c(e),g=i||("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 _={X_ProjectId:null==p?void 0:p.projectId,X_ProjectKey:(null==p?void 0:p.projectKey)||"",X_ProjectSecretKey:(null==p?void 0:p.secretKey)||""};a&&(_=Object.assign(Object.assign({},_),a));const m=yield t.default(g,{method:r,url:g,data:o||{},headers:_});return d(Object.assign(Object.assign({},(null==m?void 0:m.data)||{}),{results:null===(n=null==m?void 0:m.data)||void 0===n?void 0:n.results,error:(null===(u=null==m?void 0:m.data)||void 0===u?void 0:u.error)||!1,message:(null===(v=null==m?void 0:m.data)||void 0===v?void 0:v.message)||"Successful",statusCode:m.status}))}catch(e){return console.log("SERVER SECRET CALL ERROR:",e),d(Object.assign(Object.assign({},(null===(p=null==e?void 0:e.response)||void 0===p?void 0:p.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===(m=null===(_=null==e?void 0:e.response)||void 0===_?void 0:_.data)||void 0===m?void 0:m.error)||!0,message:(null===(S=null===(O=null==e?void 0:e.response)||void 0===O?void 0:O.data)||void 0===S?void 0:S.message)||(null===(f=null==e?void 0:e.response)||void 0===f?void 0:f.data)||"There was an error on our end! Please try again in a few minutes!",statusCode:e.response.status}))}})),c=e=>{let r=e;return"/"===r[0]&&(r=r.replace("/","")),r};r.getAuth(l);const v=()=>{const e=p();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!"}};const p=()=>{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};exports.backendValidation=e=>new Promise(r=>n(void 0,void 0,void 0,function*(){var o,t;try{v();const t=yield u("/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})}})),exports.checkBackendKeys=v,exports.deleteSeoPage=e=>new Promise(r=>n(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});v();const o=yield u("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})}})),exports.fetchSEO=(e,r={})=>new Promise(o=>n(void 0,void 0,void 0,function*(){var t;const s=yield((e,r={})=>new Promise(o=>n(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{results:t,error:s}=yield u("/seo/server_get","put",{path:e,headers:r||{}});return o(t?{results:t,error:"",message:"Successful"}:{results:!1,error:s,message:"No SEO data for this page found"})}catch(e){return o({results:!1,error:e.error,message:"Not Successful"})}})))(e,(null===(t=null==r?void 0:r.request)||void 0===t?void 0:t.headers)||{});return o((null==s?void 0:s.results)||{})})),exports.getSeoPages=e=>new Promise(r=>n(void 0,void 0,void 0,function*(){var o;try{v();const o=yield u("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"})}})),exports.insertSeoPage=function(e){return new Promise(r=>n(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});v();const o=yield u("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"})}}))},exports.returnKey=s,exports.returnProject=()=>{const e=process.env.SEO_MANAGER_MODULE_PROJECT;return e?JSON.parse(e):null},exports.returnProjectPlan=()=>{const e=process.env.SEO_MANAGER_MODULE_PROJECTPLAN;return e?JSON.parse(e):null},exports.setProject=e=>{process.env.SEO_MANAGER_MODULE_PROJECT=JSON.stringify(e)},exports.setProjectPlan=e=>{process.env.SEO_MANAGER_MODULE_PROJECTPLAN=JSON.stringify(e)},exports.updateSeoPage=(e,r,o)=>new Promise(t=>n(void 0,void 0,void 0,function*(){var s;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});v();const s=yield u("backend_api/seo/update","put",{pageIdentifiers:e,pageSEO:r,options:o});return t(s)}catch(e){return console.log("Error:",e),t({results:!1,message:(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.error)||(null==e?void 0:e.error)||"Something went wrong",error:!0})}}));