1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 05:13:29 +00:00

Refactor StaticStore Plans and consuming logic (#6136)

* staticstore factoring changes

* Refactoring code changes

* fix the free org issue

* remove a depreciated endpoint

* Resolve the issue of secrets manager sub

* Fix the ui product sorting
This commit is contained in:
cyprain-okeke
2023-10-17 15:56:59 +01:00
committed by GitHub
parent d4e6793871
commit 5cacd79d8c
12 changed files with 313 additions and 195 deletions

View File

@@ -13,7 +13,6 @@ export class OrganizationResponse extends BaseResponse {
businessTaxNumber: string;
billingEmail: string;
plan: PlanResponse;
secretsManagerPlan: PlanResponse;
planType: PlanType;
seats: number;
maxAutoscaleSeats: number;
@@ -49,10 +48,6 @@ export class OrganizationResponse extends BaseResponse {
const plan = this.getResponseProperty("Plan");
this.plan = plan == null ? null : new PlanResponse(plan);
const secretsManagerPlan = this.getResponseProperty("SecretsManagerPlan");
this.secretsManagerPlan =
secretsManagerPlan == null ? null : new PlanResponse(secretsManagerPlan);
this.planType = this.getResponseProperty("PlanType");
this.seats = this.getResponseProperty("Seats");
this.maxAutoscaleSeats = this.getResponseProperty("MaxAutoscaleSeats");

View File

@@ -1,28 +1,16 @@
import { ProductType } from "../../../enums";
import { BaseResponse } from "../../../models/response/base.response";
import { BitwardenProductType, PlanType } from "../../enums";
import { PlanType } from "../../enums";
export class PlanResponse extends BaseResponse {
type: PlanType;
product: ProductType;
bitwardenProduct: BitwardenProductType;
name: string;
isAnnual: boolean;
nameLocalizationKey: string;
descriptionLocalizationKey: string;
canBeUsedByBusiness: boolean;
baseSeats: number;
baseStorageGb: number;
maxCollections: number;
maxUsers: number;
hasAdditionalSeatsOption: boolean;
maxAdditionalSeats: number;
hasAdditionalStorageOption: boolean;
maxAdditionalStorage: number;
hasPremiumAccessOption: boolean;
trialPeriodDays: number;
hasSelfHost: boolean;
hasPolicies: boolean;
hasGroups: boolean;
@@ -34,29 +22,12 @@ export class PlanResponse extends BaseResponse {
hasSso: boolean;
hasResetPassword: boolean;
usersGetPremium: boolean;
upgradeSortOrder: number;
displaySortOrder: number;
legacyYear: number;
disabled: boolean;
stripePlanId: string;
stripeSeatPlanId: string;
stripeStoragePlanId: string;
stripePremiumAccessPlanId: string;
basePrice: number;
seatPrice: number;
additionalStoragePricePerGb: number;
premiumAccessOptionPrice: number;
// SM only
additionalPricePerServiceAccount: number;
baseServiceAccount: number;
maxServiceAccount: number;
hasAdditionalServiceAccountOption: boolean;
maxProjects: number;
maxAdditionalServiceAccounts: number;
stripeServiceAccountPlanId: string;
PasswordManager: PasswordManagerPlanFeaturesResponse;
SecretsManager: SecretsManagerPlanFeaturesResponse;
constructor(response: any) {
super(response);
@@ -67,15 +38,6 @@ export class PlanResponse extends BaseResponse {
this.nameLocalizationKey = this.getResponseProperty("NameLocalizationKey");
this.descriptionLocalizationKey = this.getResponseProperty("DescriptionLocalizationKey");
this.canBeUsedByBusiness = this.getResponseProperty("CanBeUsedByBusiness");
this.baseSeats = this.getResponseProperty("BaseSeats");
this.baseStorageGb = this.getResponseProperty("BaseStorageGb");
this.maxCollections = this.getResponseProperty("MaxCollections");
this.maxUsers = this.getResponseProperty("MaxUsers");
this.hasAdditionalSeatsOption = this.getResponseProperty("HasAdditionalSeatsOption");
this.maxAdditionalSeats = this.getResponseProperty("MaxAdditionalSeats");
this.hasAdditionalStorageOption = this.getResponseProperty("HasAdditionalStorageOption");
this.maxAdditionalStorage = this.getResponseProperty("MaxAdditionalStorage");
this.hasPremiumAccessOption = this.getResponseProperty("HasPremiumAccessOption");
this.trialPeriodDays = this.getResponseProperty("TrialPeriodDays");
this.hasSelfHost = this.getResponseProperty("HasSelfHost");
this.hasPolicies = this.getResponseProperty("HasPolicies");
@@ -92,16 +54,46 @@ export class PlanResponse extends BaseResponse {
this.displaySortOrder = this.getResponseProperty("SortOrder");
this.legacyYear = this.getResponseProperty("LegacyYear");
this.disabled = this.getResponseProperty("Disabled");
this.stripePlanId = this.getResponseProperty("StripePlanId");
const passwordManager = this.getResponseProperty("PasswordManager");
const secretsManager = this.getResponseProperty("SecretsManager");
this.PasswordManager =
passwordManager == null ? null : new PasswordManagerPlanFeaturesResponse(passwordManager);
this.SecretsManager =
secretsManager == null ? null : new SecretsManagerPlanFeaturesResponse(secretsManager);
}
}
export class SecretsManagerPlanFeaturesResponse extends BaseResponse {
// Seats
stripeSeatPlanId: string;
baseSeats: number;
basePrice: number;
seatPrice: number;
hasAdditionalSeatsOption: boolean;
maxAdditionalSeats: number;
maxSeats: number;
// Service accounts
stripeServiceAccountPlanId: string;
additionalPricePerServiceAccount: number;
baseServiceAccount: number;
maxServiceAccount: number;
hasAdditionalServiceAccountOption: boolean;
maxAdditionalServiceAccounts: number;
// Features
maxProjects: number;
constructor(response: any) {
super(response);
this.stripeSeatPlanId = this.getResponseProperty("StripeSeatPlanId");
this.stripeStoragePlanId = this.getResponseProperty("StripeStoragePlanId");
this.stripePremiumAccessPlanId = this.getResponseProperty("StripePremiumAccessPlanId");
this.baseSeats = this.getResponseProperty("BaseSeats");
this.basePrice = this.getResponseProperty("BasePrice");
this.seatPrice = this.getResponseProperty("SeatPrice");
this.additionalStoragePricePerGb = this.getResponseProperty("AdditionalStoragePricePerGb");
this.premiumAccessOptionPrice = this.getResponseProperty("PremiumAccessOptionPrice");
this.bitwardenProduct = this.getResponseProperty("BitwardenProduct");
this.hasAdditionalSeatsOption = this.getResponseProperty("HasAdditionalSeatsOption");
this.maxAdditionalSeats = this.getResponseProperty("MaxAdditionalSeats");
this.maxSeats = this.getResponseProperty("MaxSeats");
this.stripeServiceAccountPlanId = this.getResponseProperty("StripeServiceAccountPlanId");
this.additionalPricePerServiceAccount = this.getResponseProperty(
"AdditionalPricePerServiceAccount"
);
@@ -110,8 +102,53 @@ export class PlanResponse extends BaseResponse {
this.hasAdditionalServiceAccountOption = this.getResponseProperty(
"HasAdditionalServiceAccountOption"
);
this.maxProjects = this.getResponseProperty("MaxProjects");
this.maxAdditionalServiceAccounts = this.getResponseProperty("MaxAdditionalServiceAccounts");
this.stripeServiceAccountPlanId = this.getResponseProperty("StripeServiceAccountPlanId");
this.maxProjects = this.getResponseProperty("MaxProjects");
}
}
export class PasswordManagerPlanFeaturesResponse extends BaseResponse {
// Seats
stripePlanId: string;
stripeSeatPlanId: string;
stripePremiumAccessPlanId: string;
basePrice: number;
seatPrice: number;
premiumAccessOptionPrice: number;
baseSeats: number;
maxAdditionalSeats: number;
maxSeats: number;
hasPremiumAccessOption: boolean;
// Storage
additionalStoragePricePerGb: number;
stripeStoragePlanId: string;
baseStorageGb: number;
hasAdditionalStorageOption: boolean;
maxAdditionalStorage: number;
hasAdditionalSeatsOption: boolean;
// Feature
maxCollections: number;
constructor(response: any) {
super(response);
this.stripePlanId = this.getResponseProperty("StripePlanId");
this.stripeSeatPlanId = this.getResponseProperty("StripeSeatPlanId");
this.stripeStoragePlanId = this.getResponseProperty("StripeStoragePlanId");
this.stripePremiumAccessPlanId = this.getResponseProperty("StripePremiumAccessPlanId");
this.basePrice = this.getResponseProperty("BasePrice");
this.seatPrice = this.getResponseProperty("SeatPrice");
this.baseSeats = this.getResponseProperty("BaseSeats");
this.maxAdditionalSeats = this.getResponseProperty("MaxAdditionalSeats");
this.premiumAccessOptionPrice = this.getResponseProperty("PremiumAccessOptionPrice");
this.maxSeats = this.getResponseProperty("MaxSeats");
this.additionalStoragePricePerGb = this.getResponseProperty("AdditionalStoragePricePerGb");
this.hasAdditionalSeatsOption = this.getResponseProperty("HasAdditionalSeatsOption");
this.baseStorageGb = this.getResponseProperty("BaseStorageGb");
this.maxCollections = this.getResponseProperty("MaxCollections");
this.hasAdditionalStorageOption = this.getResponseProperty("HasAdditionalStorageOption");
this.maxAdditionalStorage = this.getResponseProperty("MaxAdditionalStorage");
this.hasPremiumAccessOption = this.getResponseProperty("HasPremiumAccessOption");
}
}

View File

@@ -1,5 +1,4 @@
import { BaseResponse } from "../../../models/response/base.response";
import { BitwardenProductType } from "../../enums";
export class SubscriptionResponse extends BaseResponse {
storageName: string;
@@ -67,7 +66,7 @@ export class BillingSubscriptionItemResponse extends BaseResponse {
interval: string;
sponsoredSubscriptionItem: boolean;
addonSubscriptionItem: boolean;
bitwardenProduct: BitwardenProductType;
productName: string;
constructor(response: any) {
super(response);
@@ -77,7 +76,6 @@ export class BillingSubscriptionItemResponse extends BaseResponse {
this.interval = this.getResponseProperty("Interval");
this.sponsoredSubscriptionItem = this.getResponseProperty("SponsoredSubscriptionItem");
this.addonSubscriptionItem = this.getResponseProperty("AddonSubscriptionItem");
this.bitwardenProduct = this.getResponseProperty("BitwardenProduct");
}
}

View File

@@ -894,7 +894,7 @@ export class ApiService implements ApiServiceAbstraction {
// Plan APIs
async getPlans(): Promise<ListResponse<PlanResponse>> {
const r = await this.send("GET", "/plans/all", null, false, true);
const r = await this.send("GET", "/plans", null, false, true);
return new ListResponse(r, PlanResponse);
}