File size: 2,889 Bytes
1e92f2d |
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 |
import wpcom from 'calypso/lib/wp';
export const SITE_FIELDS = [
'ID',
'slug',
'URL',
'name',
'icon',
'subscribers_count',
'plan',
'capabilities',
'is_a4a_dev_site',
'is_a8c',
'is_deleted',
'is_coming_soon',
'is_private',
'is_wpcom_atomic',
'is_wpcom_staging_site',
'hosting_provider_guess',
'lang',
'launch_status',
'site_migration',
'site_owner',
'options',
'jetpack',
'jetpack_connection',
'jetpack_modules',
];
export const JOINED_SITE_FIELDS = SITE_FIELDS.join( ',' );
export const SITE_OPTIONS = [
'admin_url',
'created_at',
'is_difm_lite_in_progress',
'is_domain_only',
'is_redirect',
'is_wpforteams_site',
'p2_hub_blog_id',
'site_creation_flow',
'site_intent',
'software_version',
'updated_at',
'wpcom_production_blog_id',
];
export const JOINED_SITE_OPTIONS = SITE_OPTIONS.join( ',' );
export interface SitePlan {
product_id: number;
product_slug: string;
product_name: string;
product_name_short: string;
expired: boolean;
is_free: boolean;
billing_period: 'Yearly' | 'Monthly';
features: {
active: string[];
};
}
export interface SiteCapabilities {
manage_options: boolean;
}
export interface SiteOptions {
admin_url: string;
created_at?: string;
is_difm_lite_in_progress?: boolean;
is_wpforteams_site?: boolean;
p2_hub_blog_id?: number;
site_creation_flow?: string;
site_intent?: string;
software_version: string;
updated_at?: string;
wpcom_production_blog_id?: number;
wpcom_staging_blog_ids?: number[];
}
export interface Site {
ID: number;
slug: string;
name: string;
URL: string;
icon?: {
ico: string;
};
plan?: SitePlan;
capabilities: SiteCapabilities;
subscribers_count: number;
options?: SiteOptions; // Can be undefined for deleted sites.
is_a4a_dev_site: boolean;
is_a8c: boolean;
is_deleted: boolean;
is_coming_soon: boolean;
is_private: boolean;
is_wpcom_atomic: boolean;
is_wpcom_staging_site: boolean;
is_vip: boolean;
lang: string;
launch_status: string | boolean;
site_migration: {
migration_status?: string;
in_progress: boolean;
is_complete: boolean;
};
site_owner: number;
jetpack: boolean;
jetpack_connection: boolean;
jetpack_modules: string[] | null;
hosting_provider_guess?: string;
}
export async function fetchSite( siteIdOrSlug: number | string ): Promise< Site > {
return await wpcom.req.get(
{ path: `/sites/${ siteIdOrSlug }` },
{ fields: JOINED_SITE_FIELDS, options: JOINED_SITE_OPTIONS }
);
}
export async function deleteSite( siteId: number ) {
return wpcom.req.post( {
path: `/sites/${ siteId }/delete`,
} );
}
export async function launchSite( siteId: number ) {
return wpcom.req.post( {
path: `/sites/${ siteId }/launch`,
} );
}
export async function restoreSite( siteId: number ) {
return wpcom.req.post(
{
path: '/restore-site',
apiNamespace: 'wpcom/v2',
method: 'put',
},
{
site_id: siteId,
}
);
}
|