HEX
Server: LiteSpeed
System: Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: swifizcd (1555)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/swifizcd/doxaorganix.com/wp-content/plugins/extendify/src/AutoLaunch/fetchers/get-pages.js
import { getPagesShape, pageTemplateShape } from '@auto-launch/fetchers/shape';
import {
	fetchWithTimeout,
	retryTwice,
	setStatus,
} from '@auto-launch/functions/helpers';
import { PATTERNS_HOST } from '@constants';
import { reqDataBasics } from '@shared/lib/data';
import { __ } from '@wordpress/i18n';
import { z } from 'zod';

const url = `${PATTERNS_HOST}/api/page-templates`;
const method = 'POST';
const headers = { 'Content-Type': 'application/json' };

const shapeLocal = z.looseObject({
	recommended: z.array(pageTemplateShape),
});

export const handlePages = async ({
	siteProfile,
	sitePlugins,
	siteStyle,
	siteImages,
}) => {
	// Pages are only needed for multi-page sites
	if (siteProfile.structure !== 'multi-page') {
		return { pages: [] };
	}

	// translators: this is for a action log UI. Keep it short
	setStatus(__('Preparing your pages', 'extendify-local'));

	const body = JSON.stringify({
		...reqDataBasics,
		siteProfile,
		siteStyle,
		siteImages: { siteImages }, // route expects this shape
		sitePlugins,
		includeOptional: false,
	});

	const response = await retryTwice(() =>
		fetchWithTimeout(url, { method, headers, body }),
	);
	const template = shapeLocal.parse(await response.json());

	return getPagesShape.parse({ pages: [...template.recommended] });
};