Skip to content

Commit

Permalink
fix: remove entitlements remove based on plan (PL-1101) [bugfix] (#827)
Browse files Browse the repository at this point in the history
Do not remove entitlements based on plan, trust the billing service.

Also adds error logging if we don't get entitlements back.

Co-authored-by: Tyler Stewart <git@tylerstewart.ca>
  • Loading branch information
trs and trs committed May 23, 2024
1 parent 6ac0996 commit 9123719
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/services/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import _ from 'lodash';

import { BillingClient } from '@/lib/clients/billing-client';
import { FrameType } from '@/lib/services/runtime/types';
import logger from '@/logger';
import { PartialContext, State, SubscriptionEntitlements } from '@/runtime';
import { Context, InitContextHandler } from '@/types';

Expand All @@ -27,11 +28,13 @@ const getSubscriptionEntitlements = async (billingClientFactory: BillingClient,
if (billingClient) {
const subscriptionResponse = await billingClient.resourcesPrivate
.getResourceSubscription('workspace', workspaceID)
.catch(() => null);
.catch((error) => {
logger.error(`Failed to get subscription entitlements for workspace ${workspaceID}: ${logger.vars({ error })}`);
return undefined;
});

if (subscriptionResponse) {
return !['active', 'in_trial'].includes(subscriptionResponse.subscription.status)
? []
: subscriptionResponse.subscription?.subscription_entitlements;
return subscriptionResponse.subscription?.subscription_entitlements;
}
}
return undefined;
Expand Down

0 comments on commit 9123719

Please sign in to comment.