This repository has been archived by the owner on Feb 5, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from event-catalog/adding-check-for-license
chore(plugin): added checks for license
- Loading branch information
Showing
7 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@eventcatalog/generator-federation": patch | ||
--- | ||
|
||
chore(plugin): added checks for license |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
import chalk from 'chalk'; | ||
import pkg from '../../package.json'; | ||
|
||
export default () => { | ||
console.log(chalk.bgBlue(`\nYou are using the open source license for this plugin`)); | ||
console.log( | ||
chalk.blueBright( | ||
`This plugin is governed and published under a dual-license. \nIf using for internal, commercial or proprietary software, you can purchase a license at https://dashboard.eventcatalog.dev/ or contact us hello@eventcatalog.dev.` | ||
) | ||
); | ||
type LicenseResponse = { | ||
is_trial: boolean; | ||
plugin: string; | ||
state: string; | ||
}; | ||
|
||
export default async (licenseKey?: string) => { | ||
const LICENSE_KEY = process.env.EVENTCATALOG_LICENSE_KEY_FEDERATION || licenseKey || null; | ||
|
||
if (!LICENSE_KEY) { | ||
console.log(chalk.bgRed(`\nThis plugin requires a license key to use`)); | ||
console.log(chalk.redBright(`\nVisit https://eventcatalog.cloud/ to get a 14 day trial or purchase a license`)); | ||
process.exit(1); | ||
} | ||
|
||
// Verify the license key | ||
const response = await fetch('https://api.eventcatalog.cloud/functions/v1/license', { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${LICENSE_KEY}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
if (response.status !== 200) { | ||
console.log(chalk.bgRed(`\nInvalid license key`)); | ||
console.log(chalk.redBright('Please check your plugin license key or purchase a license at https://eventcatalog.cloud/')); | ||
process.exit(1); | ||
} | ||
|
||
if (response.status === 200) { | ||
const data = (await response.json()) as LicenseResponse; | ||
|
||
if (pkg.name !== data.plugin) { | ||
console.log(chalk.bgRed(`\nInvalid license key for this plugin`)); | ||
console.log(chalk.redBright('Please check your plugin license key or purchase a license at https://eventcatalog.cloud/')); | ||
process.exit(1); | ||
} | ||
|
||
if (data.is_trial) { | ||
console.log(chalk.bgBlue(`\nYou are using a trial license for this plugin`)); | ||
} | ||
} | ||
|
||
return Promise.resolve(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters