File size: 602 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 |
import wpcom from 'calypso/lib/wp';
export interface Plan {
id?: string | null;
current_plan?: boolean;
expiry?: string;
has_domain_credit?: boolean;
product_slug?: string;
subscribed_date?: string;
user_facing_expiry?: string;
}
export async function fetchCurrentSitePlan( siteId: number ): Promise< Plan > {
const plans: Record< string, Plan > = await wpcom.req.get( {
path: `/sites/${ siteId }/plans`,
apiVersion: '1.3',
} );
const plan = Object.values( plans ).find( ( plan ) => plan.current_plan );
if ( ! plan ) {
throw new Error( 'No current plan found' );
}
return plan;
}
|