Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | 93x 2x 2x 2x 2x 2x 2x 1x 2x 2x 1x 2x 2x 3x 3x 2x 2x 1x 2x 2x 1x 2x 2x 1x 2x 2x 1x 2x 2x 1x | // Website API - Pro website management
import { request } from "../base";
// Types
export interface WebsiteTemplate {
id: string;
name: string;
description: string | null;
thumbnailUrl: string | null;
defaultForBusinessTypes: string[] | null;
isActive: boolean;
sortOrder: number;
}
export interface WebsiteCustomizations {
primaryColor?: string;
secondaryColor?: string;
fontFamily?: string;
logoUrl?: string;
faviconUrl?: string;
headerStyle?: string;
footerStyle?: string;
}
export interface ProWebsite {
id: number;
proId: string;
templateId: string;
status: "draft" | "preview" | "published";
customDomain: string | null;
customDomainVerified: boolean;
pagesProjectName: string | null;
lastPublishedAt: Date | null;
publishedVersion: number;
hasUnpublishedChanges: boolean;
contentLastModifiedAt: Date | null;
customizations: WebsiteCustomizations | null;
seoTitle: string | null;
seoDescription: string | null;
ogImage: string | null;
analyticsId: string | null;
dateCreated: Date;
dateUpdated: Date;
}
export interface WebsiteBuildJob {
id: number;
proWebsiteId: number;
status:
| "pending"
| "queued"
| "building"
| "deploying"
| "deployed"
| "failed"
| "cancelled";
version: number;
triggeredBy: string | null;
triggerType: "manual" | "template_update" | "scheduled";
startedAt: Date | null;
completedAt: Date | null;
buildLogs: string | null;
errorMessage: string | null;
deploymentUrl: string | null;
deploymentId: string | null;
retryCount: number;
maxRetries: number;
dateCreated: Date;
dateUpdated: Date;
}
export interface WebsiteSettingsResponse {
website: ProWebsite | null;
template: WebsiteTemplate | null;
latestBuild: WebsiteBuildJob | null;
previewUrl: string | null;
publishedUrl: string | null;
customDomainUrl: string | null;
cnameTarget: string | null;
}
export interface SetCustomDomainResponse {
website: ProWebsite;
cnameTarget: string;
}
export interface VerifyDomainResponse {
verified: boolean;
domain: string;
expectedCname: string;
resolvedCname?: string;
error?: string;
}
export interface BuildStatusResponse {
latestBuild: WebsiteBuildJob | null;
websiteStatus: string;
hasUnpublishedChanges: boolean;
}
export interface PreviewTokenResponse {
token: string;
expiresAt: string;
previewUrl: string;
}
export interface UpdateWebsiteInput {
templateId?: string;
seoTitle?: string | null;
seoDescription?: string | null;
ogImage?: string | null;
analyticsId?: string | null;
customizations?: WebsiteCustomizations;
}
// API Functions
export const websiteApi = {
// Get available templates
async getTemplates(proId: string): Promise<WebsiteTemplate[]> {
const response = await request<WebsiteTemplate[]>(`/api/pro/${proId}/website/templates`);
return response.data ?? [];
},
// Get website settings and status
async getSettings(proId: string): Promise<WebsiteSettingsResponse> {
const response = await request<WebsiteSettingsResponse>(`/api/pro/${proId}/website`);
return response.data ?? { website: null, template: null, latestBuild: null, previewUrl: null, publishedUrl: null, customDomainUrl: null, cnameTarget: null };
},
// Update website settings
async updateSettings(
proId: string,
data: UpdateWebsiteInput,
): Promise<ProWebsite> {
const response = await request<ProWebsite>(`/api/pro/${proId}/website`, {
method: "PUT",
body: data,
});
if (!response.data) throw new Error("Failed to update website settings");
return response.data;
},
// Trigger publish
async publish(proId: string): Promise<{ buildJob: WebsiteBuildJob; message: string }> {
const response = await request<{ buildJob: WebsiteBuildJob; message: string }>(
`/api/pro/${proId}/website/publish`,
{ method: "POST" },
);
if (!response.data) throw new Error("Failed to publish website");
return response.data;
},
// Get build status (for polling)
async getBuildStatus(proId: string): Promise<BuildStatusResponse> {
const response = await request<BuildStatusResponse>(`/api/pro/${proId}/website/build-status`);
return response.data ?? { latestBuild: null, websiteStatus: "draft", hasUnpublishedChanges: false };
},
// Get build history
async getBuildHistory(
proId: string,
offset = 0,
limit = 10,
): Promise<WebsiteBuildJob[]> {
const response = await request<WebsiteBuildJob[]>(
`/api/pro/${proId}/website/builds?offset=${offset}&limit=${limit}`,
);
return response.data ?? [];
},
// Cancel active build
async cancelBuild(proId: string): Promise<{ cancelled: number; message: string }> {
const response = await request<{ cancelled: number; message: string }>(
`/api/pro/${proId}/website/cancel-build`,
{ method: "POST" },
);
if (!response.data) throw new Error("Failed to cancel build");
return response.data;
},
// Get preview token
async getPreviewToken(proId: string): Promise<PreviewTokenResponse> {
const response = await request<PreviewTokenResponse>(`/api/pro/${proId}/website/preview-token`);
if (!response.data) throw new Error("Failed to get preview token");
return response.data;
},
// Set custom domain
async setCustomDomain(proId: string, domain: string): Promise<SetCustomDomainResponse> {
const response = await request<SetCustomDomainResponse>(
`/api/pro/${proId}/website/custom-domain`,
{ method: "PUT", body: { domain } },
);
if (!response.data) throw new Error("Failed to set custom domain");
return response.data;
},
// Remove custom domain
async removeCustomDomain(proId: string): Promise<{ website: ProWebsite }> {
const response = await request<{ website: ProWebsite }>(
`/api/pro/${proId}/website/custom-domain`,
{ method: "DELETE" },
);
if (!response.data) throw new Error("Failed to remove custom domain");
return response.data;
},
// Verify custom domain DNS
async verifyDomain(proId: string): Promise<VerifyDomainResponse> {
const response = await request<VerifyDomainResponse>(
`/api/pro/${proId}/website/verify-domain`,
{ method: "POST" },
);
if (!response.data) throw new Error("Failed to verify domain");
return response.data;
},
};
|