PluginProbe
Extendify / 3.1.6
Extendify v3.1.6
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.6, at src/AutoLaunch/fetchers/get-pages.js

57 lines 1.6 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 { siteImageUrls } from '@shared/lib/site-images';
11 import { __ } from '@wordpress/i18n';
12 import { z } from 'zod';
13
14 const url = `${PATTERNS_HOST}/api/page-templates`;
15 const method = 'POST';
16 const headers = { 'Content-Type': 'application/json' };
17
18 const shapeLocal = z.looseObject({
19 recommended: z.array(pageTemplateShape),
20 });
21
22 export const handlePages = async ({
23 siteProfile,
24 sitePlugins,
25 siteStyle,
26 siteImages,
27 designBuild,
28 }) => {
29 if (siteProfile.structure !== 'multi-page') {
30 return { pages: [] };
31 }
32
33 // translators: this is for a action log UI. Keep it short
34 setStatus(__('Preparing your pages', 'extendify-local'));
35
36 const body = JSON.stringify({
37 ...reqDataBasics,
38 siteProfile,
39 siteStyle,
40 // This route reads urls only; the keyed shape silently drops every image.
41 siteImages: { siteImages: siteImageUrls(siteImages) },
42 sitePlugins,
43 includeOptional: false,
44 // If pages are passed in they may be used
45 pages: designBuild?.pages ?? [],
46 buildId: designBuild?.buildId,
47 });
48
49 const response = await retryTwice(() =>
50 fetchWithTimeout(url, { method, headers, body }),
51 );
52 const template = shapeLocal.parse(await response.json());
53 const pages = applyDesignBuildOrder(template.recommended, designBuild);
54
55 return getPagesShape.parse({ pages });
56 };
57