mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(core): Make enterprise trial requests via the backend (no-changelog) (#9784)
This commit is contained in:
parent
f7d7404907
commit
876bcbb04c
|
@ -1,5 +1,5 @@
|
||||||
import { Get, Post, RestController, GlobalScope } from '@/decorators';
|
import { Get, Post, RestController, GlobalScope } from '@/decorators';
|
||||||
import { LicenseRequest } from '@/requests';
|
import { AuthenticatedRequest, LicenseRequest } from '@/requests';
|
||||||
import { LicenseService } from './license.service';
|
import { LicenseService } from './license.service';
|
||||||
|
|
||||||
@RestController('/license')
|
@RestController('/license')
|
||||||
|
@ -11,6 +11,12 @@ export class LicenseController {
|
||||||
return await this.licenseService.getLicenseData();
|
return await this.licenseService.getLicenseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('/enterprise/request_trial')
|
||||||
|
@GlobalScope('license:manage')
|
||||||
|
async requestEnterpriseTrial(req: AuthenticatedRequest) {
|
||||||
|
await this.licenseService.requestEnterpriseTrial(req.user);
|
||||||
|
}
|
||||||
|
|
||||||
@Post('/activate')
|
@Post('/activate')
|
||||||
@GlobalScope('license:manage')
|
@GlobalScope('license:manage')
|
||||||
async activateLicense(req: LicenseRequest.Activate) {
|
async activateLicense(req: LicenseRequest.Activate) {
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
import { Logger } from '@/Logger';
|
import { Logger } from '@/Logger';
|
||||||
import { License } from '@/License';
|
import { License } from '@/License';
|
||||||
import { InternalHooks } from '@/InternalHooks';
|
import { InternalHooks } from '@/InternalHooks';
|
||||||
|
import type { User } from '@db/entities/User';
|
||||||
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
||||||
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||||
|
import { UrlService } from '@/services/url.service';
|
||||||
|
|
||||||
type LicenseError = Error & { errorId?: keyof typeof LicenseErrors };
|
type LicenseError = Error & { errorId?: keyof typeof LicenseErrors };
|
||||||
|
|
||||||
|
@ -24,6 +28,7 @@ export class LicenseService {
|
||||||
private readonly license: License,
|
private readonly license: License,
|
||||||
private readonly internalHooks: InternalHooks,
|
private readonly internalHooks: InternalHooks,
|
||||||
private readonly workflowRepository: WorkflowRepository,
|
private readonly workflowRepository: WorkflowRepository,
|
||||||
|
private readonly urlService: UrlService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async getLicenseData() {
|
async getLicenseData() {
|
||||||
|
@ -45,6 +50,16 @@ export class LicenseService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async requestEnterpriseTrial(user: User) {
|
||||||
|
await axios.post('https://enterprise.n8n.io/enterprise-trial', {
|
||||||
|
licenseType: 'enterprise',
|
||||||
|
firstName: user.firstName,
|
||||||
|
lastName: user.lastName,
|
||||||
|
email: user.email,
|
||||||
|
instanceUrl: this.urlService.getWebhookBaseUrl(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getManagementJwt(): string {
|
getManagementJwt(): string {
|
||||||
return this.license.getManagementJwt();
|
return this.license.getManagementJwt();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import nock from 'nock';
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import { RESPONSE_ERROR_MESSAGES } from '@/constants';
|
import { RESPONSE_ERROR_MESSAGES } from '@/constants';
|
||||||
import type { User } from '@db/entities/User';
|
import type { User } from '@db/entities/User';
|
||||||
|
@ -47,6 +48,20 @@ describe('GET /license', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('POST /license/enterprise/request_trial', () => {
|
||||||
|
nock('https://enterprise.n8n.io').post('/enterprise-trial').reply(200);
|
||||||
|
|
||||||
|
test('should work for instance owner', async () => {
|
||||||
|
await authOwnerAgent.post('/license/enterprise/request_trial').expect(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not work for regular users', async () => {
|
||||||
|
await authMemberAgent
|
||||||
|
.post('/license/enterprise/request_trial')
|
||||||
|
.expect(403, { status: 'error', message: RESPONSE_ERROR_MESSAGES.MISSING_SCOPE });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('POST /license/activate', () => {
|
describe('POST /license/activate', () => {
|
||||||
test('should work for instance owner', async () => {
|
test('should work for instance owner', async () => {
|
||||||
await authOwnerAgent
|
await authOwnerAgent
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { makeRestApiRequest, request } from '@/utils/apiUtils';
|
import { makeRestApiRequest } from '@/utils/apiUtils';
|
||||||
import type { IRestApiContext, UsageState } from '@/Interface';
|
import type { IRestApiContext, UsageState } from '@/Interface';
|
||||||
|
|
||||||
export const getLicense = async (context: IRestApiContext): Promise<UsageState['data']> => {
|
export const getLicense = async (context: IRestApiContext): Promise<UsageState['data']> => {
|
||||||
|
@ -16,21 +16,8 @@ export const renewLicense = async (context: IRestApiContext): Promise<UsageState
|
||||||
return await makeRestApiRequest(context, 'POST', '/license/renew');
|
return await makeRestApiRequest(context, 'POST', '/license/renew');
|
||||||
};
|
};
|
||||||
|
|
||||||
export const requestLicenseTrial = async (data: {
|
export const requestLicenseTrial = async (
|
||||||
licenseType: 'enterprise';
|
context: IRestApiContext,
|
||||||
firstName: string;
|
): Promise<UsageState['data']> => {
|
||||||
lastName: string;
|
return await makeRestApiRequest(context, 'POST', '/license/enterprise/request_trial');
|
||||||
email: string;
|
|
||||||
instanceUrl: string;
|
|
||||||
}): Promise<UsageState['data']> => {
|
|
||||||
return await request({
|
|
||||||
method: 'POST',
|
|
||||||
baseURL: 'https://enterprise.n8n.io',
|
|
||||||
endpoint: '/enterprise-trial',
|
|
||||||
data,
|
|
||||||
withCredentials: false,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -85,19 +85,7 @@ export const useUsageStore = defineStore('usage', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestEnterpriseLicenseTrial = async () => {
|
const requestEnterpriseLicenseTrial = async () => {
|
||||||
if (!usersStore.currentUser) {
|
await requestLicenseTrial(rootStore.getRestApiContext);
|
||||||
throw new Error('User is not logged in');
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await requestLicenseTrial({
|
|
||||||
licenseType: 'enterprise',
|
|
||||||
firstName: usersStore.currentUser.firstName ?? '',
|
|
||||||
lastName: usersStore.currentUser.lastName ?? '',
|
|
||||||
email: usersStore.currentUser.email ?? '',
|
|
||||||
instanceUrl: window.location.origin,
|
|
||||||
});
|
|
||||||
|
|
||||||
return data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue