mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-04 22:21:21 +09:00
Phase B batch 1 — roadmap #16, #19, #20. #16 Passwordless "Auto Login" into wp-admin (the signature managed-WP feature), no heavy plugin. New WordPressService.create_login_url uses the Docker-aware wp_cli bridge to install the wp-cli-login package (idempotent) and mint a one-time magic URL (wp login create --url-only); login slug resolved via wp eval rather than hardcoding /wp-admin. New POST /sites/<id>/login (admin-gated) resolves or provisions a managed admin tied to the operator's panel email (create_user role=administrator), persists admin_user, writes a 'wordpress.admin_login' AuditLog, and returns the URL. A prominent primary "Auto Login" button in the site topbar opens it; Dashboard remains as fallback. #19 Multisite is now detected for real via `wp core is-multisite` (new is_multisite helper): surfaced in get_wordpress_info, set at create_site, and refreshed+persisted on the single-site detail load (never on the hot list endpoint). #20 Site tags/labels for agency organization. New JSON-in-TEXT tags column on WordPressSite (auto-added on boot by _fix_missing_columns; plus an idempotent 009 Alembic revision for determinism), exposed via to_dict, set via PATCH /sites/<id>/tags (normalized/deduped). Frontend: tag chips on each site card and a client-side tag filter bar on the WordPress list. Verified: backend boots (009 migration applies, tags column live, routes + methods present); frontend builds; changed JS lints with 0 errors. No frontend or backend regressions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
322 lines
11 KiB
JavaScript
322 lines
11 KiB
JavaScript
import api from './api';
|
|
|
|
const BASE_PATH = '/wordpress/sites';
|
|
|
|
const wordpressApi = {
|
|
// Site Management
|
|
getSites: () => api.request(BASE_PATH),
|
|
|
|
createSite: (data) => api.request(BASE_PATH, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
getSite: (id) => api.request(`${BASE_PATH}/${id}`),
|
|
|
|
// Replace the tag list for a site (agency organization labels)
|
|
setTags: (id, tags) => api.request(`${BASE_PATH}/${id}/tags`, {
|
|
method: 'PATCH',
|
|
body: { tags }
|
|
}),
|
|
|
|
// Deletes the site and all environments. A final files+DB backup is taken
|
|
// by default (pass { createBackup: false } to skip).
|
|
deleteSite: (id, { createBackup = true } = {}) => api.request(
|
|
`${BASE_PATH}/${id}?create_backup=${createBackup}`,
|
|
{ method: 'DELETE' }
|
|
),
|
|
|
|
// Stop the stack but keep data + files (reversible via unarchiveSite).
|
|
archiveSite: (id) => api.request(`${BASE_PATH}/${id}/archive`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
unarchiveSite: (id) => api.request(`${BASE_PATH}/${id}/unarchive`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
// Environment Management
|
|
getEnvironments: (siteId) => api.request(`${BASE_PATH}/${siteId}/environments`),
|
|
|
|
createEnvironment: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/environments`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
deleteEnvironment: (siteId, envId) => api.request(`${BASE_PATH}/${siteId}/environments/${envId}`, {
|
|
method: 'DELETE'
|
|
}),
|
|
|
|
syncEnvironment: (siteId, data = {}) => api.request(`${BASE_PATH}/${siteId}/sync`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
// Database Snapshots
|
|
getSnapshots: (siteId) => api.request(`${BASE_PATH}/${siteId}/snapshots`),
|
|
|
|
createSnapshot: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/snapshots`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
restoreSnapshot: (siteId, snapId) => api.request(`${BASE_PATH}/${siteId}/snapshots/${snapId}/restore`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
deleteSnapshot: (siteId, snapId) => api.request(`${BASE_PATH}/${siteId}/snapshots/${snapId}`, {
|
|
method: 'DELETE'
|
|
}),
|
|
|
|
// Git Integration
|
|
getGitStatus: (siteId) => api.request(`${BASE_PATH}/${siteId}/git`),
|
|
|
|
connectRepo: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/git`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
disconnectRepo: (siteId) => api.request(`${BASE_PATH}/${siteId}/git`, {
|
|
method: 'DELETE'
|
|
}),
|
|
|
|
getCommits: (siteId, limit = 20) => api.request(`${BASE_PATH}/${siteId}/git/commits?limit=${limit}`),
|
|
|
|
deployCommit: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/git/deploy`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
createDevFromCommit: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/git/dev-from-commit`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
// Plugins
|
|
getPlugins: (siteId) => api.request(`${BASE_PATH}/${siteId}/plugins`),
|
|
|
|
installPlugin: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/plugins`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
// Themes
|
|
getThemes: (siteId) => api.request(`${BASE_PATH}/${siteId}/themes`),
|
|
|
|
installTheme: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/themes`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
// WordPress Core Update
|
|
updateCore: (siteId) => api.request(`${BASE_PATH}/${siteId}/update`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
// Live WP-CLI info (core version + update_available / latest_version)
|
|
getWordPressInfo: (siteId) => api.request(`${BASE_PATH}/${siteId}/info`),
|
|
|
|
// Update plugins. Pass an array of slugs to update specific ones, omit for all.
|
|
updatePlugins: (siteId, plugins) => api.request(`${BASE_PATH}/${siteId}/plugins/update`, {
|
|
method: 'POST',
|
|
body: plugins ? { plugins } : {}
|
|
}),
|
|
|
|
// Update themes. Pass an array of slugs to update specific ones, omit for all.
|
|
updateThemes: (siteId, themes) => api.request(`${BASE_PATH}/${siteId}/themes/update`, {
|
|
method: 'POST',
|
|
body: themes ? { themes } : {}
|
|
}),
|
|
|
|
// Maintenance & Security
|
|
flushCache: (siteId) => api.request(`${BASE_PATH}/${siteId}/flush-cache`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
searchReplace: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/search-replace`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
harden: (siteId) => api.request(`${BASE_PATH}/${siteId}/harden`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
// Mint a one-time passwordless wp-admin login URL for the current operator.
|
|
autoLogin: (siteId) => api.request(`${BASE_PATH}/${siteId}/login`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
// Clone Database (for advanced use)
|
|
cloneDatabase: (siteId, data) => api.request(`${BASE_PATH}/${siteId}/clone-db`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
// =========================================
|
|
// Pipeline API (Environment Management v2)
|
|
// =========================================
|
|
PIPELINE_PATH: '/wordpress/projects',
|
|
|
|
// Project listing
|
|
getProjects: () => api.request('/wordpress/projects'),
|
|
|
|
// Pipeline dashboard
|
|
getProjectPipeline: (prodId) => api.request(`/wordpress/projects/${prodId}/pipeline`),
|
|
|
|
// Environment CRUD
|
|
createProjectEnvironment: (prodId, data) => api.request(`/wordpress/projects/${prodId}/environments`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
getProjectEnvironment: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}`),
|
|
|
|
deleteProjectEnvironment: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}`, {
|
|
method: 'DELETE'
|
|
}),
|
|
|
|
// Container lifecycle
|
|
startEnvironment: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/start`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
stopEnvironment: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/stop`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
restartEnvironment: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/restart`, {
|
|
method: 'POST'
|
|
}),
|
|
|
|
// Promotion
|
|
promoteEnvironment: (prodId, data) => api.request(`/wordpress/projects/${prodId}/promote`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
// Sync from production
|
|
syncProjectEnvironment: (prodId, envId, data) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/sync`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
// Compare environments
|
|
compareEnvironments: (prodId, envAId, envBId) =>
|
|
api.request(`/wordpress/projects/${prodId}/compare?env_a=${envAId}&env_b=${envBId}`),
|
|
|
|
// Locking
|
|
lockEnvironment: (prodId, envId, data) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/lock`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
unlockEnvironment: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/lock`, {
|
|
method: 'DELETE'
|
|
}),
|
|
|
|
// Activity log
|
|
getProjectActivity: (prodId, params = {}) => {
|
|
const query = new URLSearchParams(params).toString();
|
|
return api.request(`/wordpress/projects/${prodId}/activity${query ? `?${query}` : ''}`);
|
|
},
|
|
|
|
// Container logs
|
|
getEnvironmentLogs: (prodId, envId, params = {}) => {
|
|
const query = new URLSearchParams(params).toString();
|
|
return api.request(`/wordpress/projects/${prodId}/environments/${envId}/logs${query ? `?${query}` : ''}`);
|
|
},
|
|
|
|
// Promotion history
|
|
getPromotionHistory: (prodId, params = {}) => {
|
|
const query = new URLSearchParams(params).toString();
|
|
return api.request(`/wordpress/projects/${prodId}/promotions${query ? `?${query}` : ''}`);
|
|
},
|
|
|
|
// Restore a promotion's pre-promotion snapshot into its target environment
|
|
rollbackPromotion: (prodId, promotionId) => api.request(
|
|
`/wordpress/projects/${prodId}/promotions/${promotionId}/rollback`,
|
|
{ method: 'POST' }
|
|
),
|
|
|
|
// Git branches (for multidev)
|
|
getBranches: (prodId) => api.request(`/wordpress/projects/${prodId}/git/branches`),
|
|
|
|
// Multidev cleanup
|
|
cleanupMultidevs: (prodId, dryRun = true) => api.request(`/wordpress/projects/${prodId}/multidev/cleanup`, {
|
|
method: 'POST',
|
|
body: { dry_run: dryRun }
|
|
}),
|
|
|
|
// Sanitization Profiles
|
|
getSanitizationProfiles: () => api.request('/wordpress/projects/sanitization-profiles'),
|
|
|
|
createSanitizationProfile: (data) => api.request('/wordpress/projects/sanitization-profiles', {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
updateSanitizationProfile: (profileId, data) => api.request(`/wordpress/projects/sanitization-profiles/${profileId}`, {
|
|
method: 'PUT',
|
|
body: data
|
|
}),
|
|
|
|
deleteSanitizationProfile: (profileId) => api.request(`/wordpress/projects/sanitization-profiles/${profileId}`, {
|
|
method: 'DELETE'
|
|
}),
|
|
|
|
// =========================================
|
|
// Phase 7: Advanced Features
|
|
// =========================================
|
|
|
|
// Resource Limits
|
|
updateResourceLimits: (prodId, envId, limits) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/resources`, {
|
|
method: 'PUT',
|
|
body: limits
|
|
}),
|
|
|
|
// Basic Auth
|
|
enableBasicAuth: (prodId, envId, data = {}) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/auth`, {
|
|
method: 'POST',
|
|
body: data
|
|
}),
|
|
|
|
disableBasicAuth: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/auth`, {
|
|
method: 'DELETE'
|
|
}),
|
|
|
|
getBasicAuthStatus: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/auth`),
|
|
|
|
// WP-CLI
|
|
executeWpCli: (prodId, envId, command) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/exec`, {
|
|
method: 'POST',
|
|
body: { command }
|
|
}),
|
|
|
|
// Health
|
|
getEnvironmentHealth: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/health`),
|
|
|
|
getProjectHealth: (prodId) => api.request(`/wordpress/projects/${prodId}/health`),
|
|
|
|
// Disk Usage
|
|
getEnvironmentDiskUsage: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/disk-usage`),
|
|
|
|
getProjectDiskUsage: (prodId) => api.request(`/wordpress/projects/${prodId}/disk-usage`),
|
|
|
|
// Bulk Operations
|
|
executeBulkOperation: (prodId, operations) => api.request(`/wordpress/projects/${prodId}/bulk`, {
|
|
method: 'POST',
|
|
body: { operations }
|
|
}),
|
|
|
|
// Auto-Sync
|
|
getAutoSyncSchedule: (prodId, envId) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/auto-sync`),
|
|
|
|
updateAutoSyncSchedule: (prodId, envId, config) => api.request(`/wordpress/projects/${prodId}/environments/${envId}/auto-sync`, {
|
|
method: 'PUT',
|
|
body: config
|
|
})
|
|
};
|
|
|
|
export default wordpressApi;
|