Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
Merge pull request #6 from event-catalog/adding-check-for-license
Browse files Browse the repository at this point in the history
chore(plugin): added checks for license
  • Loading branch information
boyney123 authored Feb 5, 2025
2 parents 1ab6097 + b9c50ce commit e2d490e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-actors-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/generator-federation": patch
---

chore(plugin): added checks for license
2 changes: 1 addition & 1 deletion LICENSE-COMMERCIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ You will need a Commercial License in the following cases:
- You are building proprietary software or SaaS platforms where you do not want to share the source code with customers or the public.
- You are creating a closed-source product that incorporates this software.

If you would like to obtain a Commercial License, you can purchase a license at https://dashboard.eventcatalog.dev or email us at `hello@eventcatalog.dev`
If you would like to obtain a Commercial License, you can purchase a license at https://eventcatalog.cloud or email us at `hello@eventcatalog.dev`
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ You can find the [contributing guidelines here](https://eventcatalog.dev/docs/co

This project is governed by a [dual-license](./LICENSE.md). To ensure the sustainability of the project, you can freely make use of this software if your projects are Open Source. Otherwise for internal systems you must obtain a [commercial license](./LICENSE-COMMERCIAL.md).

If you would like to obtain a Commercial License, you can purchase a license at https://dashboard.eventcatalog.dev or email us at `hello@eventcatalog.dev`
If you would like to obtain a Commercial License, you can purchase a license at https://eventcatalog.cloud or email us at `hello@eventcatalog.dev`
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type CopyProps = {

// Configuration the users give your catalog
type GeneratorProps = {
licenseKey?: string;
source: string;
branch?: string;
copy: CopyProps[];
Expand Down Expand Up @@ -110,6 +111,8 @@ export default async (_: EventCatalogConfig, options: GeneratorProps) => {
throw new Error('Please provide catalog url (env variable PROJECT_DIR)');
}

await checkLicense(options.licenseKey);

// Remove the tmpDir if it exists
if (fsExtra.existsSync(tmpDir)) {
await fsExtra.remove(tmpDir);
Expand Down Expand Up @@ -155,6 +158,4 @@ export default async (_: EventCatalogConfig, options: GeneratorProps) => {

// Remove the tmpDir
await fs.rm(tmpDir, { recursive: true });

await checkLicense();
};
7 changes: 6 additions & 1 deletion src/test/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, it, describe, beforeEach, afterEach } from 'vitest';
import { expect, it, describe, beforeEach, afterEach, vi } from 'vitest';
import utils from '@eventcatalog/sdk';
import plugin from '../index';
import path, { join } from 'node:path';
Expand All @@ -11,6 +11,11 @@ const eventCatalogConfig = {

let catalogDir: string;

// Add mock for the local checkLicense module
vi.mock('../utils/checkLicense', () => ({
default: () => Promise.resolve(),
}));

describe('generator-federation', () => {
beforeEach(async () => {
catalogDir = join(__dirname, 'catalog') || '';
Expand Down
53 changes: 46 additions & 7 deletions src/utils/checkLicense.ts
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();
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": false /* Skip type checking all .d.ts files. */
"skipLibCheck": false /* Skip type checking all .d.ts files. */,
"resolveJsonModule": true
},
"module": "ESNext",
"moduleResolution": "node"
Expand Down

0 comments on commit e2d490e

Please sign in to comment.