mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(server): support selfhost licenses (#8947)
This commit is contained in:
@@ -607,4 +607,38 @@ export const USER_FRIENDLY_ERRORS = {
|
||||
type: 'bad_request',
|
||||
message: 'Captcha verification failed.',
|
||||
},
|
||||
|
||||
// license errors
|
||||
invalid_license_session_id: {
|
||||
type: 'invalid_input',
|
||||
message: 'Invalid session id to generate license key.',
|
||||
},
|
||||
license_revealed: {
|
||||
type: 'action_forbidden',
|
||||
message:
|
||||
'License key has been revealed. Please check your mail box of the one provided during checkout.',
|
||||
},
|
||||
workspace_license_already_exists: {
|
||||
type: 'action_forbidden',
|
||||
message: 'Workspace already has a license applied.',
|
||||
},
|
||||
license_not_found: {
|
||||
type: 'resource_not_found',
|
||||
message: 'License not found.',
|
||||
},
|
||||
invalid_license_to_activate: {
|
||||
type: 'bad_request',
|
||||
message: 'Invalid license to activate.',
|
||||
},
|
||||
invalid_license_update_params: {
|
||||
type: 'invalid_input',
|
||||
args: { reason: 'string' },
|
||||
message: ({ reason }) => `Invalid license update params. ${reason}`,
|
||||
},
|
||||
workspace_members_exceed_limit_to_downgrade: {
|
||||
type: 'bad_request',
|
||||
args: { limit: 'number' },
|
||||
message: ({ limit }) =>
|
||||
`You cannot downgrade the workspace from team workspace because there are more than ${limit} members that are currently active.`,
|
||||
},
|
||||
} satisfies Record<string, UserFriendlyErrorOptions>;
|
||||
|
||||
@@ -591,6 +591,56 @@ export class CaptchaVerificationFailed extends UserFriendlyError {
|
||||
super('bad_request', 'captcha_verification_failed', message);
|
||||
}
|
||||
}
|
||||
|
||||
export class InvalidLicenseSessionId extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('invalid_input', 'invalid_license_session_id', message);
|
||||
}
|
||||
}
|
||||
|
||||
export class LicenseRevealed extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('action_forbidden', 'license_revealed', message);
|
||||
}
|
||||
}
|
||||
|
||||
export class WorkspaceLicenseAlreadyExists extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('action_forbidden', 'workspace_license_already_exists', message);
|
||||
}
|
||||
}
|
||||
|
||||
export class LicenseNotFound extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('resource_not_found', 'license_not_found', message);
|
||||
}
|
||||
}
|
||||
|
||||
export class InvalidLicenseToActivate extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('bad_request', 'invalid_license_to_activate', message);
|
||||
}
|
||||
}
|
||||
@ObjectType()
|
||||
class InvalidLicenseUpdateParamsDataType {
|
||||
@Field() reason!: string
|
||||
}
|
||||
|
||||
export class InvalidLicenseUpdateParams extends UserFriendlyError {
|
||||
constructor(args: InvalidLicenseUpdateParamsDataType, message?: string | ((args: InvalidLicenseUpdateParamsDataType) => string)) {
|
||||
super('invalid_input', 'invalid_license_update_params', message, args);
|
||||
}
|
||||
}
|
||||
@ObjectType()
|
||||
class WorkspaceMembersExceedLimitToDowngradeDataType {
|
||||
@Field() limit!: number
|
||||
}
|
||||
|
||||
export class WorkspaceMembersExceedLimitToDowngrade extends UserFriendlyError {
|
||||
constructor(args: WorkspaceMembersExceedLimitToDowngradeDataType, message?: string | ((args: WorkspaceMembersExceedLimitToDowngradeDataType) => string)) {
|
||||
super('bad_request', 'workspace_members_exceed_limit_to_downgrade', message, args);
|
||||
}
|
||||
}
|
||||
export enum ErrorNames {
|
||||
INTERNAL_SERVER_ERROR,
|
||||
TOO_MANY_REQUEST,
|
||||
@@ -669,7 +719,14 @@ export enum ErrorNames {
|
||||
MAILER_SERVICE_IS_NOT_CONFIGURED,
|
||||
CANNOT_DELETE_ALL_ADMIN_ACCOUNT,
|
||||
CANNOT_DELETE_OWN_ACCOUNT,
|
||||
CAPTCHA_VERIFICATION_FAILED
|
||||
CAPTCHA_VERIFICATION_FAILED,
|
||||
INVALID_LICENSE_SESSION_ID,
|
||||
LICENSE_REVEALED,
|
||||
WORKSPACE_LICENSE_ALREADY_EXISTS,
|
||||
LICENSE_NOT_FOUND,
|
||||
INVALID_LICENSE_TO_ACTIVATE,
|
||||
INVALID_LICENSE_UPDATE_PARAMS,
|
||||
WORKSPACE_MEMBERS_EXCEED_LIMIT_TO_DOWNGRADE
|
||||
}
|
||||
registerEnumType(ErrorNames, {
|
||||
name: 'ErrorNames'
|
||||
@@ -678,5 +735,5 @@ registerEnumType(ErrorNames, {
|
||||
export const ErrorDataUnionType = createUnionType({
|
||||
name: 'ErrorDataUnion',
|
||||
types: () =>
|
||||
[WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, SpaceNotFoundDataType, MemberNotFoundInSpaceDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType] as const,
|
||||
[WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, SpaceNotFoundDataType, MemberNotFoundInSpaceDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType, InvalidLicenseUpdateParamsDataType, WorkspaceMembersExceedLimitToDowngradeDataType] as const,
|
||||
});
|
||||
|
||||
@@ -46,6 +46,24 @@ export class URLHelper {
|
||||
return new URLSearchParams(query).toString();
|
||||
}
|
||||
|
||||
addSimpleQuery(
|
||||
url: string,
|
||||
key: string,
|
||||
value: string | number | boolean,
|
||||
escape = true
|
||||
) {
|
||||
const urlObj = new URL(url);
|
||||
if (escape) {
|
||||
urlObj.searchParams.set(key, encodeURIComponent(value));
|
||||
return urlObj.toString();
|
||||
} else {
|
||||
const query =
|
||||
(urlObj.search ? urlObj.search + '&' : '?') + `${key}=${value}`;
|
||||
|
||||
return urlObj.origin + urlObj.pathname + query;
|
||||
}
|
||||
}
|
||||
|
||||
url(path: string, query: Record<string, any> = {}) {
|
||||
const url = new URL(path, this.origin);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
renderTeamBecomeCollaboratorMail,
|
||||
renderTeamDeleteIn1MonthMail,
|
||||
renderTeamDeleteIn24HoursMail,
|
||||
renderTeamLicenseMail,
|
||||
renderTeamWorkspaceDeletedMail,
|
||||
renderTeamWorkspaceExpiredMail,
|
||||
renderTeamWorkspaceExpireSoonMail,
|
||||
@@ -188,4 +189,5 @@ export class MailService {
|
||||
renderTeamWorkspaceExpireSoonMail
|
||||
);
|
||||
sendTeamExpiredMail = this.makeWorkspace(renderTeamWorkspaceExpiredMail);
|
||||
sendTeamLicenseMail = this.make(renderTeamLicenseMail);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user