import { FetchError, ofetch } from 'ofetch' import {consola} from 'consola' export async function validateLicense (opts: { key: string, dir: string, theme: { env: string, link: string } }) { if (!opts.key) { throw _createError(`Missing \`${opts.theme.env}\` license key.\nPurchase Bloggrify Epoxia at \`${opts.theme.link}\` to build your app in production.`) } try { await ofetch('https://license.bloggrify.com/api/epoxia/check', { headers: { Accept: 'application/json', }, params: { license_key: opts.key } }) consola.success('Bloggrify Epoxia License is valid.') } catch (error) { const statusType = Math.round((error as FetchError).status as number / 100) if (statusType === 4) { throw _createError(`Invalid \`${opts.theme.env}\` license key.\nPurchase Bloggrify Epoxia at \`${opts.theme.link}\` to build your app in production.`) } throw _createError('Cannot validate Bloggrify Epoxia License: ' + error) } } function _createError (message: string) { const error = new Error(message) try {error.stack = ''} catch { /* runtime not supports */ } return error }