PluginProbe
Extendify / 3.1.3
Extendify v3.1.3
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / AutoLaunch / fetchers / get-pages.js

get-pages.js in Extendify 3.1.3, at src/AutoLaunch/fetchers/get-pages.js

55 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { applyDesignBuildOrder } from '@auto-launch/fetchers/get-design-build';
2 import { getPagesShape, pageTemplateShape } from '@auto-launch/fetchers/shape';
3 import {
4 fetchWithTimeout,
5 retryTwice,
6 setStatus,
7 } from '@auto-launch/functions/helpers';
8 import { PATTERNS_HOST } from '@constants';
9 import { reqDataBasics } from '@shared/lib/data';
10 import { __ } from '@wordpress/i18n';
11 import { z } from 'zod';
12
13 const url = `${PATTERNS_HOST}/api/page-templates`;
14 const method = 'POST';
15 const headers = { 'Content-Type': 'application/json' };
16
17 const shapeLocal = z.looseObject({
18 recommended: z.array(pageTemplateShape),
19 });
20
21 export const handlePages = async ({
22 siteProfile,
23 sitePlugins,
24 siteStyle,
25 siteImages,
26 designBuild,
27 }) => {
28 if (siteProfile.structure !== 'multi-page') {
29 return { pages: [] };
30 }
31
32 // translators: this is for a action log UI. Keep it short
33 setStatus(__('Preparing your pages', 'extendify-local'));
34
35 const body = JSON.stringify({
36 ...reqDataBasics,
37 siteProfile,
38 siteStyle,
39 siteImages: { siteImages },
40 sitePlugins,
41 includeOptional: false,
42 // If pages are passed in they may be used
43 pages: designBuild?.pages ?? [],
44 buildId: designBuild?.buildId,
45 });
46
47 const response = await retryTwice(() =>
48 fetchWithTimeout(url, { method, headers, body }),
49 );
50 const template = shapeLocal.parse(await response.json());
51 const pages = applyDesignBuildOrder(template.recommended, designBuild);
52
53 return getPagesShape.parse({ pages });
54 };
55