@@ -20,14 +20,6 @@ const eeLicenseKeyPayloadSchema = z.object({
2020
2121type LicenseKeyPayload = z . infer < typeof eeLicenseKeyPayloadSchema > ;
2222
23- // eslint-disable-next-line @typescript-eslint/no-unused-vars
24- const planLabels = {
25- oss : "OSS" ,
26- "self-hosted:enterprise" : "Enterprise (Self-Hosted)" ,
27- "self-hosted:enterprise-unlimited" : "Enterprise (Self-Hosted) Unlimited" ,
28- } as const ;
29- export type Plan = keyof typeof planLabels ;
30-
3123// eslint-disable-next-line @typescript-eslint/no-unused-vars
3224const entitlements = [
3325 "search-contexts" ,
@@ -44,45 +36,10 @@ const entitlements = [
4436] as const ;
4537export type Entitlement = ( typeof entitlements ) [ number ] ;
4638
47- const entitlementsByPlan : Record < Plan , Entitlement [ ] > = {
48- oss : [
49- "anonymous-access" ,
50- ] ,
51- "self-hosted:enterprise" : [
52- "search-contexts" ,
53- "sso" ,
54- "code-nav" ,
55- "audit" ,
56- "analytics" ,
57- "permission-syncing" ,
58- "github-app" ,
59- "chat-sharing" ,
60- "org-management" ,
61- "oauth" ,
62- ] ,
63- "self-hosted:enterprise-unlimited" : [
64- "anonymous-access" ,
65- "search-contexts" ,
66- "sso" ,
67- "code-nav" ,
68- "audit" ,
69- "analytics" ,
70- "permission-syncing" ,
71- "github-app" ,
72- "chat-sharing" ,
73- "org-management" ,
74- "oauth" ,
75- ] ,
76- } as const ;
77-
78- const isValidPlan = ( plan : string ) : plan is Plan => {
79- return plan in entitlementsByPlan ;
80- }
81-
8239const ACTIVE_LICENSE_STATUSES = [ 'active' , 'trialing' , 'past_due' ] as const ;
8340
84- const isLicenseActive = ( license : License | null ) : boolean => {
85- if ( ! license ? .status ) {
41+ const isLicenseActive = ( license : License ) : boolean => {
42+ if ( ! license . status ) {
8643 return false ;
8744 }
8845 return ACTIVE_LICENSE_STATUSES . includes ( license . status as typeof ACTIVE_LICENSE_STATUSES [ number ] ) ;
@@ -122,25 +79,6 @@ export const getOfflineLicenseKey = (): LicenseKeyPayload | null => {
12279 return null ;
12380}
12481
125- export const getPlan = ( license : License | null ) : Plan => {
126- const licenseKey = getOfflineLicenseKey ( ) ;
127- if ( licenseKey ) {
128- const expiryDate = new Date ( licenseKey . expiryDate ) ;
129- if ( expiryDate . getTime ( ) < new Date ( ) . getTime ( ) ) {
130- logger . error ( `The provided license key has expired (${ expiryDate . toLocaleString ( ) } ). Please contact ${ SOURCEBOT_SUPPORT_EMAIL } for support.` ) ;
131- process . exit ( 1 ) ;
132- }
133-
134- return licenseKey . seats === SOURCEBOT_UNLIMITED_SEATS ? "self-hosted:enterprise-unlimited" : "self-hosted:enterprise" ;
135- }
136- else if ( license ?. plan && isValidPlan ( license . plan ) && isLicenseActive ( license ) ) {
137- return license . plan ;
138- }
139- else {
140- return "oss" ;
141- }
142- }
143-
14482export const getSeats = ( license : License | null ) : number => {
14583 const licenseKey = getOfflineLicenseKey ( ) ;
14684 if ( licenseKey ) {
@@ -160,6 +98,20 @@ export const hasEntitlement = (entitlement: Entitlement, license: License | null
16098}
16199
162100export const getEntitlements = ( license : License | null ) : Entitlement [ ] => {
163- const plan = getPlan ( license ) ;
164- return entitlementsByPlan [ plan ] ;
101+ const licenseKey = getOfflineLicenseKey ( ) ;
102+ if ( licenseKey ) {
103+ const expiryDate = new Date ( licenseKey . expiryDate ) ;
104+ if ( expiryDate . getTime ( ) < new Date ( ) . getTime ( ) ) {
105+ logger . error ( `The provided license key has expired (${ expiryDate . toLocaleString ( ) } ). Please contact ${ SOURCEBOT_SUPPORT_EMAIL } for support.` ) ;
106+ process . exit ( 1 ) ;
107+ }
108+
109+ return entitlements as unknown as Entitlement [ ] ;
110+ }
111+ else if ( license && isLicenseActive ( license ) ) {
112+ return license . entitlements as unknown as Entitlement [ ] ;
113+ }
114+ else {
115+ return [ ] ;
116+ }
165117}
0 commit comments