catalyst-core 0.1.0-beta.6 → 0.1.0-beta.7

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.
@@ -4,7 +4,7 @@ const _getMatchRoutes=(routes,req,res,store,context,fetcherData,basePath="",webE
4
4
  renderToStringWithObservability(webExtractor,store,context,req,fetcherData);}const wc=route.component;matches.push({route,match,serverSideFunction:wc&&wc.serverSideFunction||(()=>Promise.resolve())});}if(!match&&route.children){// recursively try to match nested routes
5
5
  const nested=_getMatchRoutes(route.children,req,res,store,context,fetcherData,`${basePath}/${path}`,webExtractor);if(nested.length){matches=matches.concat(nested);}}return matches;},[]);};const getMatchRoutes=(0,_otel.withSyncObservability)(SSR_SERVICE,_getMatchRoutes,"getMatchRoutes");const tracedResWriteFirstFoldCss=(0,_otel.withSyncObservability)(SSR_SERVICE,(res,chunk)=>res.write(chunk),"res.write.firstFoldCss");const tracedResWriteFirstFoldJS=(0,_otel.withSyncObservability)(SSR_SERVICE,(res,chunk)=>res.write(chunk),"res.write.firstFoldJS");const tracedResEnd=(0,_otel.withSyncObservability)(SSR_SERVICE,res=>res.end(),"res.end");// Preloads chunks required for rendering document
6
6
  const getComponent=(store,context,req,fetcherData)=>{return/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{id:"app",children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactRedux.Provider,{store:store,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_server.StaticRouter,{context:context,location:req.originalUrl,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_ServerRouter.default,{store:store,intialData:fetcherData})})})});};// sends document after rendering
7
- const renderMarkUp=async(errorCode,req,res,metaTags,fetcherData,store,matches,context,webExtractor)=>{const deviceDetails=(0,_userAgentUtil.getUserAgentDetails)(req.headers["user-agent"]||"");const isBot=deviceDetails.googleBot?true:false;const safeArea=parseSafeAreaFromHeaders(req)||{...DEFAULT_SAFE_AREA_INSETS};// Set in globalThis for hooks to access during SSR
7
+ const renderMarkUp=async(errorCode,req,res,metaTags,fetcherData,store,matches,context,webExtractor)=>{const deviceDetails=(0,_userAgentUtil.getUserAgentDetails)(req.headers["user-agent"]||"");const isBot=deviceDetails.googleBot||deviceDetails.aiBot?true:false;const safeArea=parseSafeAreaFromHeaders(req)||{...DEFAULT_SAFE_AREA_INSETS};// Set in globalThis for hooks to access during SSR
8
8
  /* eslint-disable no-undef */const previousSafeArea=globalThis.__SAFE_AREA_INITIAL__;globalThis.__SAFE_AREA_INITIAL__=safeArea;/* eslint-enable no-undef */let state=store.getState();const jsx=webExtractor.collectChunks(getComponent(store,context,req,fetcherData));const{IS_DEV_COMMAND,WEBPACK_DEV_SERVER_HOSTNAME,WEBPACK_DEV_SERVER_PORT}=process.env;let publicAssetPath=`${process.env.PUBLIC_STATIC_ASSET_URL}${process.env.PUBLIC_STATIC_ASSET_PATH}`;// serves assets from localhost on running devBuild and devServe command
9
9
  if(IS_DEV_COMMAND==="true"){publicAssetPath=`http://${WEBPACK_DEV_SERVER_HOSTNAME}:${WEBPACK_DEV_SERVER_PORT}/assets/`;}const finalProps={req,res,lang:"en",pageCss:res.locals.pageCss,preloadJSLinks:res.locals.preloadJSLinks,metaTags,isBot,publicAssetPath,jsx,initialState:state,fetcherData,safeArea};let CompleteDocument=()=>{if((0,_validator.validateCustomDocument)(_document2.default)){return(0,_document2.default)(finalProps);}else{return/*#__PURE__*/(0,_jsxRuntime.jsxs)("html",{lang:finalProps.lang,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)(_document.Head,{isBot:finalProps.isBot,pageCss:finalProps.pageCss,metaTags:finalProps.metaTags,preloadJSLinks:finalProps.preloadJSLinks,publicAssetPath:finalProps.publicAssetPath}),/*#__PURE__*/(0,_jsxRuntime.jsx)(_document.Body,{jsx:finalProps.jsx,fetcherData:finalProps.fetcherData,initialState:finalProps.initialState,safeArea:finalProps.safeArea})]});}};// Helper to cleanup globalThis after rendering completes
10
10
  const cleanupGlobalThis=()=>{/* eslint-disable no-undef */if(previousSafeArea===undefined){delete globalThis.__SAFE_AREA_INITIAL__;}else{globalThis.__SAFE_AREA_INITIAL__=previousSafeArea;}/* eslint-enable no-undef */};try{let status=matches.length&&matches[0].match.path==="*"?404:200;res.set({"content-type":"text/html; charset=utf-8"});res.status(status);return new Promise((resolve,reject)=>{const{pipe}=(0,_server3.renderToPipeableStream)(/*#__PURE__*/(0,_jsxRuntime.jsx)(CompleteDocument,{}),{onShellReady(){res.setHeader("content-type","text/html");pipe(res);},onAllReady(){const{firstFoldCss,firstFoldJS}=(0,_extract.cacheAndFetchAssets)({webExtractor,res,isBot});tracedResWriteFirstFoldCss(res,firstFoldCss);tracedResWriteFirstFoldJS(res,firstFoldJS);tracedResEnd(res);cleanupGlobalThis();resolve();},onError(error){logger.error({message:`\n Error while renderToPipeableStream : ${error.toString()}`});// function defined by user which needs to run if rendering fails
@@ -1,9 +1,15 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getUserAgentDetails=void 0;var _uaParserJs=_interopRequireDefault(require("ua-parser-js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}const googleBots={"APIs-Google":"APIs-Google",AdSense:"Mediapartners-Google","AdsBot Mobile Web Android":"AdsBot-Google-Mobile","AdsBot Mobile Web":"AdsBot-Google-Mobile",AdsBot:"AdsBot-Google","Mobile AdSense":"Mediapartners-Google","Mobile Apps Android":"AdsBot-Google-Mobile-Apps",Feedfetcher:"FeedFetcher-Google","Google Read Aloud":"Google-Read-Aloud","Duplex on the Web":"DuplexWeb-Google","Google Favicon":"Google Favicon","Web Light":"googleweblight","Amp crawler":"Google-AMPHTM",Googlebot:"Googlebot"};/**
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getUserAgentDetails=void 0;var _uaParserJs=_interopRequireDefault(require("ua-parser-js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}const googleBots={"APIs-Google":"APIs-Google",AdSense:"Mediapartners-Google","AdsBot Mobile Web Android":"AdsBot-Google-Mobile","AdsBot Mobile Web":"AdsBot-Google-Mobile",AdsBot:"AdsBot-Google","Mobile AdSense":"Mediapartners-Google","Mobile Apps Android":"AdsBot-Google-Mobile-Apps",Feedfetcher:"FeedFetcher-Google","Google Read Aloud":"Google-Read-Aloud","Duplex on the Web":"DuplexWeb-Google","Google Favicon":"Google Favicon","Web Light":"googleweblight","Amp crawler":"Google-AMPHTM",Googlebot:"Googlebot","Google Inspection Tool":"Google-InspectionTool","Google Agent":"Google-Agent"};// AI Crawler bots - for improved SEO with AI search engines
2
+ const aiCrawlerBots={// OpenAI/ChatGPT bots
3
+ GPTBot:"GPTBot","ChatGPT-User":"ChatGPT-User","OAI-SearchBot":"OAI-SearchBot",// Anthropic/Claude bots
4
+ ClaudeBot:"ClaudeBot","Claude-User":"Claude-User","Claude-SearchBot":"Claude-SearchBot",// Perplexity bots
5
+ PerplexityBot:"PerplexityBot","Perplexity-User":"Perplexity-User",// Microsoft Bing bot (also powers Bing Chat/Copilot)
6
+ Bingbot:"bingbot",// Meta Crawler bot
7
+ MetaBot:"meta-externalagent"};/**
2
8
  * check if user agent contains bot data
3
9
  * @param {string} ua - user agent
4
10
  * @return {string|null}
5
- */const getGoogleBot=ua=>{for(let key in googleBots){if(ua.includes(googleBots[key]))return key;}return null;};/**
11
+ */const getGoogleBot=ua=>{for(let key in googleBots){if(ua.includes(googleBots[key]))return key;}return null;};const getAICrawlerBot=ua=>{for(let key in aiCrawlerBots){if(ua.includes(aiCrawlerBots[key]))return key;}return null;};/**
6
12
  * returns object which contains google bot and user-agent info
7
13
  * @param {string} ua - user agent
8
14
  * @return {object} - returns user agent
9
- */const getUserAgentDetails=ua=>{const agentDetails=(0,_uaParserJs.default)(ua);const googleBot=getGoogleBot(ua);return{...agentDetails,googleBot};};exports.getUserAgentDetails=getUserAgentDetails;
15
+ */const getUserAgentDetails=ua=>{const agentDetails=(0,_uaParserJs.default)(ua);const googleBot=getGoogleBot(ua);const aiBot=getAICrawlerBot(ua);return{...agentDetails,googleBot,aiBot};};exports.getUserAgentDetails=getUserAgentDetails;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catalyst-core",
3
- "version": "0.1.0-beta.6",
3
+ "version": "0.1.0-beta.7",
4
4
  "main": "dist/index.js",
5
5
  "description": "Web framework that provides great performance out of the box",
6
6
  "bin": {