Skip to content

Commit 1e2c0f5

Browse files
committed
Replaces SubscriptionPlanIds enum with union type
1 parent 519a85b commit 1e2c0f5

20 files changed

+149
-175
lines changed

src/commands/quickWizard.base.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Disposable, InputBox, QuickInputButton, QuickPick, QuickPickItem } from 'vscode';
22
import { InputBoxValidationSeverity, QuickInputButtons, window } from 'vscode';
33
import type { GlCommands } from '../constants.commands';
4-
import { SubscriptionPlanId } from '../constants.subscription';
54
import { Container } from '../container';
65
import { Directive, isDirective, isDirectiveQuickPickItem } from '../quickpicks/items/directive';
76
import { configuration } from '../system/-webview/configuration';
@@ -736,7 +735,7 @@ export abstract class QuickWizardCommandBase extends GlCommandBase {
736735
}
737736

738737
case Directive.RequiresPaidSubscription:
739-
void Container.instance.subscription.upgrade(SubscriptionPlanId.Pro, {
738+
void Container.instance.subscription.upgrade('pro', {
740739
source: 'quick-wizard',
741740
detail: {
742741
action: rootStep.command?.key,

src/constants.context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { Uri } from 'vscode';
22
import type { AnnotationStatus, Keys } from './constants';
3-
import type { SubscriptionPlanId, SubscriptionState } from './constants.subscription';
3+
import type { SubscriptionState } from './constants.subscription';
44
import type { CustomEditorTypes, GroupableTreeViewTypes, WebviewTypes, WebviewViewTypes } from './constants.views';
55
import type { Features } from './features';
66
import type { PromoKeys } from './plus/gk/models/promo';
7+
import type { SubscriptionPlanIds } from './plus/gk/models/subscription';
78
import type { WalkthroughContextKeys } from './telemetry/walkthroughStateProvider';
89

910
export type ContextKeys = {
@@ -21,7 +22,7 @@ export type ContextKeys = {
2122
'gitlens:install:new': boolean;
2223
/** Indicates that this is the first run after an upgrade of GitLens */
2324
'gitlens:install:upgradedFrom': string;
24-
'gitlens:plus': Exclude<SubscriptionPlanId, SubscriptionPlanId.Community>;
25+
'gitlens:plus': Exclude<SubscriptionPlanIds, 'community'>;
2526
'gitlens:plus:disabled': boolean;
2627
'gitlens:plus:disallowedRepos': string[];
2728
'gitlens:plus:required': boolean;

src/constants.subscription.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@ export const proFeaturePreviewUsages = 3;
22
export const proFeaturePreviewUsageDurationInDays = 1;
33
export const proTrialLengthInDays = 14;
44

5-
export const enum SubscriptionPlanId {
6-
Community = 'community',
7-
CommunityWithAccount = 'community-with-account',
8-
Pro = 'pro',
9-
Advanced = 'advanced',
10-
Business = 'teams', // teams is the old name for Business; do not change
11-
Enterprise = 'enterprise',
12-
}
13-
145
// NOTE: Pay attention to gitlens:plus:state in the `package.json` when modifying this enum
156
// NOTE: This is reported in telemetry so we should NOT change the values
167
export const enum SubscriptionState {
@@ -31,12 +22,3 @@ export const enum SubscriptionState {
3122
/** Indicates a paid user */
3223
Paid = 6,
3324
}
34-
35-
export type SubscriptionStateString =
36-
| 'verification'
37-
| 'free'
38-
| 'trial'
39-
| 'trial-expired'
40-
| 'trial-reactivation-eligible'
41-
| 'paid'
42-
| 'unknown';

src/constants.telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type { WalkthroughSteps } from './constants';
33
import type { AIProviders } from './constants.ai';
44
import type { GlCommands, GlCommandsDeprecated } from './constants.commands';
55
import type { IntegrationId, SupportedCloudIntegrationIds } from './constants.integrations';
6-
import type { SubscriptionState, SubscriptionStateString } from './constants.subscription';
6+
import type { SubscriptionState } from './constants.subscription';
77
import type { CustomEditorTypes, TreeViewTypes, WebviewTypes, WebviewViewTypes } from './constants.views';
88
import type { FeaturePreviews, FeaturePreviewStatus } from './features';
99
import type { GitContributionTiers } from './git/models/contributor';
10-
import type { Subscription, SubscriptionAccount } from './plus/gk/models/subscription';
10+
import type { Subscription, SubscriptionAccount, SubscriptionStateString } from './plus/gk/models/subscription';
1111
import type { Flatten } from './system/object';
1212
import type { WalkthroughContextKeys } from './telemetry/walkthroughStateProvider';
1313
import type { GraphColumnConfig } from './webviews/plus/graph/protocol';

src/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import type { Uri } from 'vscode';
22
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
33
import { CancellationError as _CancellationError } from 'vscode';
44
import type { Response } from '@env/fetch';
5-
import type { RequiredSubscriptionPlans, Subscription } from './plus/gk/models/subscription';
5+
import type { RequiredSubscriptionPlanIds, Subscription } from './plus/gk/models/subscription';
66
import { isSubscriptionPaidPlan } from './plus/gk/utils/subscription.utils';
77

88
export class AccessDeniedError extends Error {
99
public readonly subscription: Subscription;
10-
public readonly required: RequiredSubscriptionPlans | undefined;
10+
public readonly required: RequiredSubscriptionPlanIds | undefined;
1111

12-
constructor(subscription: Subscription, required: RequiredSubscriptionPlans | undefined) {
12+
constructor(subscription: Subscription, required: RequiredSubscriptionPlanIds | undefined) {
1313
let message;
1414
if (subscription.account?.verified === false) {
1515
message = 'Email verification required';

src/features.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { StoredFeaturePreviewUsagePeriod } from './constants.storage';
22
import { proFeaturePreviewUsageDurationInDays, proFeaturePreviewUsages } from './constants.subscription';
33
import type { RepositoryVisibility } from './git/gitProvider';
4-
import type { RequiredSubscriptionPlans, Subscription } from './plus/gk/models/subscription';
4+
import type { RequiredSubscriptionPlanIds, Subscription } from './plus/gk/models/subscription';
55
import { capitalize } from './system/string';
66

77
// GitFeature's must start with `git:` to be recognized in all usages
@@ -53,7 +53,7 @@ export type FeatureAccess =
5353
}
5454
| {
5555
allowed: false | 'mixed';
56-
subscription: { current: Subscription; required?: RequiredSubscriptionPlans };
56+
subscription: { current: Subscription; required?: RequiredSubscriptionPlanIds };
5757
visibility?: RepositoryVisibility;
5858
};
5959

@@ -65,7 +65,7 @@ export type RepoFeatureAccess =
6565
}
6666
| {
6767
allowed: false;
68-
subscription: { current: Subscription; required?: RequiredSubscriptionPlans };
68+
subscription: { current: Subscription; required?: RequiredSubscriptionPlanIds };
6969
visibility?: RepositoryVisibility;
7070
};
7171

src/git/gitProviderService.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { Disposable, EventEmitter, FileType, ProgressLocation, Uri, window, work
1313
import { isWeb } from '@env/platform';
1414
import { resetAvatarCache } from '../avatars';
1515
import { GlyphChars, Schemes } from '../constants';
16-
import { SubscriptionPlanId } from '../constants.subscription';
1716
import type { Container } from '../container';
1817
import { AccessDeniedError, ProviderNotFoundError, ProviderNotSupportedError } from '../errors';
1918
import type { FeatureAccess, PlusFeatures, RepoFeatureAccess } from '../features';
@@ -738,7 +737,7 @@ export class GitProviderService implements Disposable {
738737
}
739738

740739
if (feature != null && (isProFeatureOnAllRepos(feature) || isAdvancedFeature(feature))) {
741-
return { allowed: false, subscription: { current: subscription, required: SubscriptionPlanId.Pro } };
740+
return { allowed: false, subscription: { current: subscription, required: 'pro' } };
742741
}
743742

744743
function getRepoAccess(
@@ -755,7 +754,7 @@ export class GitProviderService implements Disposable {
755754
if (visibility === 'private') {
756755
return {
757756
allowed: false,
758-
subscription: { current: subscription, required: SubscriptionPlanId.Pro },
757+
subscription: { current: subscription, required: 'pro' },
759758
visibility: visibility,
760759
};
761760
}
@@ -791,13 +790,13 @@ export class GitProviderService implements Disposable {
791790
case 'private':
792791
return {
793792
allowed: false,
794-
subscription: { current: subscription, required: SubscriptionPlanId.Pro },
793+
subscription: { current: subscription, required: 'pro' },
795794
visibility: 'private',
796795
};
797796
case 'mixed':
798797
return {
799798
allowed: 'mixed',
800-
subscription: { current: subscription, required: SubscriptionPlanId.Pro },
799+
subscription: { current: subscription, required: 'pro' },
801800
};
802801
default:
803802
return {

src/plus/ai/aiProviderService.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
vscodeProviderDescriptor,
1717
xAIProviderDescriptor,
1818
} from '../../constants.ai';
19-
import { SubscriptionPlanId } from '../../constants.subscription';
2019
import type { AIGenerateDraftEventData, Source, TelemetryEvents } from '../../constants.telemetry';
2120
import type { Container } from '../../container';
2221
import {
@@ -990,9 +989,7 @@ export class AIProviderService implements Disposable {
990989

991990
if (isSubscriptionPaid(sub)) {
992991
const plan =
993-
compareSubscriptionPlans(sub.plan.actual.id, SubscriptionPlanId.Advanced) <= 0
994-
? SubscriptionPlanId.Business
995-
: SubscriptionPlanId.Advanced;
992+
compareSubscriptionPlans(sub.plan.actual.id, 'advanced') <= 0 ? 'teams' : 'advanced';
996993

997994
const upgrade = { title: `Upgrade to ${getSubscriptionPlanName(plan)}` };
998995
const result = await window.showErrorMessage(
@@ -1012,7 +1009,7 @@ export class AIProviderService implements Disposable {
10121009
);
10131010

10141011
if (result === upgrade) {
1015-
void this.container.subscription.upgrade(SubscriptionPlanId.Pro, source);
1012+
void this.container.subscription.upgrade('pro', source);
10161013
}
10171014
}
10181015

src/plus/gk/__debug__accountDebug.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import type { Disposable } from 'vscode';
22
import { ThemeIcon, window } from 'vscode';
3-
import {
4-
proFeaturePreviewUsages,
5-
proTrialLengthInDays,
6-
SubscriptionPlanId,
7-
SubscriptionState,
8-
} from '../../constants.subscription';
3+
import { proFeaturePreviewUsages, proTrialLengthInDays, SubscriptionState } from '../../constants.subscription';
94
import type { Container } from '../../container';
105
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
116
import { createQuickPickSeparator } from '../../quickpicks/items/common';
127
import { registerCommand } from '../../system/-webview/command';
138
import type { GKCheckInResponse, GKLicenses, GKLicenseType, GKUser } from './models/checkin';
9+
import type { PaidSubscriptionPlanIds, SubscriptionPlanIds } from './models/subscription';
1410
import type { SubscriptionService } from './subscriptionService';
1511
import { getConfiguredActiveOrganizationId } from './utils/-webview/subscription.utils';
1612
import { getSubscriptionFromCheckIn } from './utils/checkin.utils';
@@ -55,18 +51,14 @@ type SimulateQuickPickItem = QuickPickItemOfT<
5551
state: SubscriptionState.Trial;
5652
reactivatedTrial?: boolean;
5753
expiredPaid?: never;
58-
planId?: SubscriptionPlanId.Advanced;
54+
planId?: Extract<'advanced', SubscriptionPlanIds>;
5955
featurePreviews?: never;
6056
}
6157
| {
6258
state: SubscriptionState.Paid;
6359
reactivatedTrial?: never;
6460
expiredPaid?: boolean;
65-
planId?:
66-
| SubscriptionPlanId.Pro
67-
| SubscriptionPlanId.Advanced
68-
| SubscriptionPlanId.Business
69-
| SubscriptionPlanId.Enterprise;
61+
planId?: PaidSubscriptionPlanIds;
7062
featurePreviews?: never;
7163
}
7264
>;
@@ -156,15 +148,15 @@ class AccountDebug {
156148
label: 'Pro Trial (Advanced)',
157149
description: 'Pro trial (advanced plan), account',
158150
iconPath: new ThemeIcon('blank'),
159-
item: { state: SubscriptionState.Trial, planId: SubscriptionPlanId.Advanced },
151+
item: { state: SubscriptionState.Trial, planId: 'advanced' },
160152
},
161153
{
162154
label: 'Pro Trial (Advanced, Reactivated)',
163155
description: 'Pro trial (advanced plan), account',
164156
iconPath: new ThemeIcon('blank'),
165157
item: {
166158
state: SubscriptionState.Trial,
167-
planId: SubscriptionPlanId.Advanced,
159+
planId: 'advanced',
168160
reactivatedTrial: true,
169161
},
170162
},
@@ -185,25 +177,25 @@ class AccountDebug {
185177
label: 'Pro',
186178
description: 'Pro, account',
187179
iconPath: new ThemeIcon('blank'),
188-
item: { state: SubscriptionState.Paid, planId: SubscriptionPlanId.Pro },
180+
item: { state: SubscriptionState.Paid, planId: 'pro' },
189181
},
190182
{
191183
label: 'Advanced',
192184
description: 'Advanced plan, account',
193185
iconPath: new ThemeIcon('blank'),
194-
item: { state: SubscriptionState.Paid, planId: SubscriptionPlanId.Advanced },
186+
item: { state: SubscriptionState.Paid, planId: 'advanced' },
195187
},
196188
{
197189
label: 'Business',
198190
description: 'Business plan, account',
199191
iconPath: new ThemeIcon('blank'),
200-
item: { state: SubscriptionState.Paid, planId: SubscriptionPlanId.Business },
192+
item: { state: SubscriptionState.Paid, planId: 'teams' },
201193
},
202194
{
203195
label: 'Enterprise',
204196
description: 'Enterprise plan, account',
205197
iconPath: new ThemeIcon('blank'),
206-
item: { state: SubscriptionState.Paid, planId: SubscriptionPlanId.Enterprise },
198+
item: { state: SubscriptionState.Paid, planId: 'enterprise' },
207199
},
208200
// TODO: Update this subscription state once we have a "paid expired" state availale
209201
{

src/plus/gk/models/subscription.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import type { SubscriptionPlanId, SubscriptionState } from '../../../constants.subscription';
1+
import type { SubscriptionState } from '../../../constants.subscription';
22
import type { Source } from '../../../constants.telemetry';
33
import type { Organization } from './organization';
44

5-
export type FreeSubscriptionPlans = Extract<
6-
SubscriptionPlanId,
7-
SubscriptionPlanId.Community | SubscriptionPlanId.CommunityWithAccount
8-
>;
9-
export type PaidSubscriptionPlans = Exclude<
10-
SubscriptionPlanId,
11-
SubscriptionPlanId.Community | SubscriptionPlanId.CommunityWithAccount
12-
>;
13-
export type RequiredSubscriptionPlans = Exclude<SubscriptionPlanId, SubscriptionPlanId.Community>;
5+
export type SubscriptionPlanIds =
6+
| 'community'
7+
| 'community-with-account'
8+
| 'pro'
9+
| 'advanced'
10+
| 'teams' /* the old name for Business; do not change */
11+
| 'enterprise';
12+
13+
export type FreeSubscriptionPlanIds = Extract<SubscriptionPlanIds, 'community' | 'community-with-account'>;
14+
export type PaidSubscriptionPlanIds = Exclude<SubscriptionPlanIds, FreeSubscriptionPlanIds>;
15+
export type RequiredSubscriptionPlanIds = Exclude<SubscriptionPlanIds, 'community'>;
1416

1517
export interface Subscription {
1618
readonly plan: {
@@ -27,7 +29,7 @@ export interface Subscription {
2729
}
2830

2931
export interface SubscriptionPlan {
30-
readonly id: SubscriptionPlanId;
32+
readonly id: SubscriptionPlanIds;
3133
readonly name: string;
3234
readonly bundle: boolean;
3335
readonly trialReactivationCount: number;
@@ -47,5 +49,14 @@ export interface SubscriptionAccount {
4749
}
4850

4951
export interface SubscriptionUpgradeCommandArgs extends Source {
50-
plan?: SubscriptionPlanId;
52+
plan?: SubscriptionPlanIds;
5153
}
54+
55+
export type SubscriptionStateString =
56+
| 'verification'
57+
| 'free'
58+
| 'trial'
59+
| 'trial-expired'
60+
| 'trial-reactivation-eligible'
61+
| 'paid'
62+
| 'unknown';

0 commit comments

Comments
 (0)