Skip to content

The open alternative to Salesforce, designed for AI.

chore(billing): remove unused billingMeter table (#28381)

Etienne536f4bd99933
diff --git a/packages/twenty-oxlint-rules/rules/prefer-workspace-scoped-repository.exemptions.ts b/packages/twenty-oxlint-rules/rules/prefer-workspace-scoped-repository.exemptions.ts
index 364fbf19f8f..f1980d35b20 100644
--- a/packages/twenty-oxlint-rules/rules/prefer-workspace-scoped-repository.exemptions.ts
+++ b/packages/twenty-oxlint-rules/rules/prefer-workspace-scoped-repository.exemptions.ts
@@ -15,7 +15,6 @@ export const STRUCTURAL_EXEMPTIONS = [
'ApplicationRegistrationVariableEntity',
'ApplicationRegistrationVersionEntity',
- 'BillingMeterEntity',
'BillingPriceEntity',
'BillingProductEntity',
'BillingSubscriptionItemEntity',
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792480059403-drop-billing-meter-table.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792480059403-drop-billing-meter-table.ts
new file mode 100644
index 00000000000..f4d1d4c1d29
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792480059403-drop-billing-meter-table.ts
@@ -0,0 +1,37 @@
+import { QueryRunner } from 'typeorm';
+
+import { RegisteredInstanceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-instance-command.decorator';
+import { FastInstanceCommand } from 'src/engine/core-modules/upgrade/interfaces/fast-instance-command.interface';
+
+@RegisteredInstanceCommand('2.50.0', 1792480059403)
+export class DropBillingMeterTableFastInstanceCommand implements FastInstanceCommand {
+ public async up(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(`DROP TABLE IF EXISTS "core"."billingMeter"`);
+ await queryRunner.query(
+ `DROP TYPE IF EXISTS "core"."billingMeter_eventtimewindow_enum"`,
+ );
+ await queryRunner.query(
+ `DROP TYPE IF EXISTS "core"."billingMeter_status_enum"`,
+ );
+ }
+
+ public async down(queryRunner: QueryRunner): Promise<void> {
+ const billingPriceTables = await queryRunner.query(
+ `SELECT 1 FROM pg_tables WHERE schemaname = 'core' AND tablename = 'billingPrice'`,
+ );
+
+ if (billingPriceTables.length === 0) {
+ return;
+ }
+
+ await queryRunner.query(
+ `CREATE TYPE "core"."billingMeter_status_enum" AS ENUM('ACTIVE', 'INACTIVE')`,
+ );
+ await queryRunner.query(
+ `CREATE TYPE "core"."billingMeter_eventtimewindow_enum" AS ENUM('DAY', 'HOUR')`,
+ );
+ await queryRunner.query(
+ `CREATE TABLE "core"."billingMeter" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "deletedAt" TIMESTAMP WITH TIME ZONE, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "stripeMeterId" character varying NOT NULL, "displayName" character varying NOT NULL, "eventName" character varying NOT NULL, "status" "core"."billingMeter_status_enum" NOT NULL, "customerMapping" jsonb NOT NULL, "eventTimeWindow" "core"."billingMeter_eventtimewindow_enum", "valueSettings" jsonb NOT NULL, CONSTRAINT "UQ_340c08c4e5dd33cf963cbb133ae" UNIQUE ("stripeMeterId"), CONSTRAINT "PK_0bba5f7d2e3713332a0138ea1b3" PRIMARY KEY ("id"))`,
+ );
+ }
+}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts
index 72eeed1f72b..d4a85354b0e 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts
@@ -249,6 +249,7 @@ import { AddConnectionProviderScopeFastInstanceCommand } from 'src/database/comm
import { AddConnectedAccountScopeFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-49/2-49-instance-command-fast-1792170228100-add-connected-account-scope';
import { AddExcludePrivateEventsToCalendarChannelFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-49/2-49-instance-command-fast-1792319637000-add-exclude-private-events-to-calendar-channel';
import { AddPeriodMaxSeatsToBillingSubscriptionFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792410699010-add-period-max-seats-to-billing-subscription';
+import { DropBillingMeterTableFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792480059403-drop-billing-meter-table';
export const INSTANCE_COMMANDS = [
AddViewFieldGroupIdIndexOnViewFieldFastInstanceCommand,
@@ -500,4 +501,5 @@ export const INSTANCE_COMMANDS = [
AddConnectedAccountScopeFastInstanceCommand,
AddExcludePrivateEventsToCalendarChannelFastInstanceCommand,
AddPeriodMaxSeatsToBillingSubscriptionFastInstanceCommand,
+ DropBillingMeterTableFastInstanceCommand,
];
diff --git a/packages/twenty-server/src/engine/core-modules/billing-webhook/billing-webhook.module.ts b/packages/twenty-server/src/engine/core-modules/billing-webhook/billing-webhook.module.ts
index 04fc09e1f78..c0b70dda5e4 100644
--- a/packages/twenty-server/src/engine/core-modules/billing-webhook/billing-webhook.module.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing-webhook/billing-webhook.module.ts
@@ -18,7 +18,6 @@ import { UsageLimitModule } from 'src/engine/core-modules/usage-limit/usage-limi
import { WorkspaceIteratorModule } from 'src/database/commands/command-runners/workspace-iterator.module';
import { BillingCustomerEntity } from 'src/engine/core-modules/billing/entities/billing-customer.entity';
import { BillingEntitlementEntity } from 'src/engine/core-modules/billing/entities/billing-entitlement.entity';
-import { BillingMeterEntity } from 'src/engine/core-modules/billing/entities/billing-meter.entity';
import { BillingPriceEntity } from 'src/engine/core-modules/billing/entities/billing-price.entity';
import { BillingProductEntity } from 'src/engine/core-modules/billing/entities/billing-product.entity';
import { BillingSubscriptionItemEntity } from 'src/engine/core-modules/billing/entities/billing-subscription-item.entity';
@@ -46,7 +45,6 @@ import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache
BillingCustomerEntity,
BillingProductEntity,
BillingPriceEntity,
- BillingMeterEntity,
BillingEntitlementEntity,
WorkspaceEntity,
]),
diff --git a/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-webhook-price.service.ts b/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-webhook-price.service.ts
index f49380d6c2a..9ec4a0c5cca 100644
--- a/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-webhook-price.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-webhook-price.service.ts
@@ -12,23 +12,17 @@ import {
BillingException,
BillingExceptionCode,
} from 'src/engine/core-modules/billing/billing.exception';
-import { BillingMeterEntity } from 'src/engine/core-modules/billing/entities/billing-meter.entity';
import { BillingPriceEntity } from 'src/engine/core-modules/billing/entities/billing-price.entity';
import { BillingProductEntity } from 'src/engine/core-modules/billing/entities/billing-product.entity';
-import { StripeBillingMeterService } from 'src/engine/core-modules/billing/stripe/services/stripe-billing-meter.service';
-import { transformStripeMeterToDatabaseMeter } from 'src/engine/core-modules/billing/utils/transform-stripe-meter-to-database-meter.util';
import { StripePriceService } from 'src/engine/core-modules/billing/stripe/services/stripe-price.service';
@Injectable()
export class BillingWebhookPriceService {
protected readonly logger = new Logger(BillingWebhookPriceService.name);
constructor(
- private readonly stripeBillingMeterService: StripeBillingMeterService,
private readonly stripePriceService: StripePriceService,
@InjectRepository(BillingPriceEntity)
private readonly billingPriceRepository: Repository<BillingPriceEntity>,
- @InjectRepository(BillingMeterEntity)
- private readonly billingMeterRepository: Repository<BillingMeterEntity>,
@InjectRepository(BillingProductEntity)
private readonly billingProductRepository: Repository<BillingProductEntity>,
) {}
@@ -48,20 +42,6 @@ export class BillingWebhookPriceService {
);
}
- const meterId = data.object.recurring?.meter;
-
- if (meterId) {
- const meterData = await this.stripeBillingMeterService.getMeter(meterId);
-
- await this.billingMeterRepository.upsert(
- transformStripeMeterToDatabaseMeter(meterData),
- {
- conflictPaths: ['stripeMeterId'],
- skipUpdateIfNoValuesChanged: true,
- },
- );
- }
-
await this.billingPriceRepository.upsert(
transformStripePriceEventToDatabasePrice(
await this.stripePriceService.getPriceByPriceId(data.object.id),
@@ -74,7 +54,6 @@ export class BillingWebhookPriceService {
return {
stripePriceId: data.object.id,
- stripeMeterId: meterId,
};
}
}
diff --git a/packages/twenty-server/src/engine/core-modules/billing/billing.module.ts b/packages/twenty-server/src/engine/core-modules/billing/billing.module.ts
index a01b9170e5c..f72877d504d 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/billing.module.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/billing.module.ts
@@ -14,7 +14,6 @@ import { BillingSyncPlansDataCommand } from 'src/engine/core-modules/billing/com
import { BillingUpdateSubscriptionPriceCommand } from 'src/engine/core-modules/billing/commands/billing-update-subscription-price.command';
import { BillingCreditGrantEntity } from 'src/engine/core-modules/billing/entities/billing-credit-grant.entity';
import { BillingCustomerEntity } from 'src/engine/core-modules/billing/entities/billing-customer.entity';
-import { BillingMeterEntity } from 'src/engine/core-modules/billing/entities/billing-meter.entity';
import { BillingPriceEntity } from 'src/engine/core-modules/billing/entities/billing-price.entity';
import { BillingProductEntity } from 'src/engine/core-modules/billing/entities/billing-product.entity';
import { BillingSubscriptionItemEntity } from 'src/engine/core-modules/billing/entities/billing-subscription-item.entity';
@@ -64,7 +63,6 @@ import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache
BillingCustomerEntity,
BillingProductEntity,
BillingPriceEntity,
- BillingMeterEntity,
BillingCreditGrantEntity,
WorkspaceEntity,
UserWorkspaceEntity,
diff --git a/packages/twenty-server/src/engine/core-modules/billing/commands/billing-sync-plans-data.command.ts b/packages/twenty-server/src/engine/core-modules/billing/commands/billing-sync-plans-data.command.ts
index 7aaa8785cb9..b34dbe8cfb1 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/commands/billing-sync-plans-data.command.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/commands/billing-sync-plans-data.command.ts
@@ -11,20 +11,17 @@ import {
type MigrationCommandOptions,
MigrationCommandRunner,
} from 'src/database/commands/command-runners/migration.command-runner';
-import { BillingMeterEntity } from 'src/engine/core-modules/billing/entities/billing-meter.entity';
import { BillingPriceEntity } from 'src/engine/core-modules/billing/entities/billing-price.entity';
import { BillingProductEntity } from 'src/engine/core-modules/billing/entities/billing-product.entity';
-import { StripeBillingMeterService } from 'src/engine/core-modules/billing/stripe/services/stripe-billing-meter.service';
import { StripePriceService } from 'src/engine/core-modules/billing/stripe/services/stripe-price.service';
import { StripeProductService } from 'src/engine/core-modules/billing/stripe/services/stripe-product.service';
import { isStripeValidProductMetadata } from 'src/engine/core-modules/billing/utils/is-stripe-valid-product-metadata.util';
-import { transformStripeMeterToDatabaseMeter } from 'src/engine/core-modules/billing/utils/transform-stripe-meter-to-database-meter.util';
import { transformStripePriceToDatabasePrice } from 'src/engine/core-modules/billing/utils/transform-stripe-price-to-database-price.util';
import { transformStripeProductToDatabaseProduct } from 'src/engine/core-modules/billing/utils/transform-stripe-product-to-database-product.util';
@Command({
name: 'billing:sync-plans-data',
description:
- 'Fetches from stripe the plans data (meter, product and price) and upserts it into the database',
+ 'Fetches from stripe the plans data (product and price) and upserts it into the database',
})
export class BillingSyncPlansDataCommand extends MigrationCommandRunner {
private readonly batchSize = 5;
@@ -33,38 +30,12 @@ export class BillingSyncPlansDataCommand extends MigrationCommandRunner {
private readonly billingPriceRepository: Repository<BillingPriceEntity>,
@InjectRepository(BillingProductEntity)
private readonly billingProductRepository: Repository<BillingProductEntity>,
- @InjectRepository(BillingMeterEntity)
- private readonly billingMeterRepository: Repository<BillingMeterEntity>,
- private readonly stripeBillingMeterService: StripeBillingMeterService,
private readonly stripeProductService: StripeProductService,
private readonly stripePriceService: StripePriceService,
) {
super();
}
- private async upsertMetersRepositoryData(
- meters: Stripe.Billing.Meter[],
- options: MigrationCommandOptions,
- ) {
- await Promise.all(
- meters.map(async (meter) => {
- try {
- if (!options.dryRun) {
- await this.billingMeterRepository.upsert(
- transformStripeMeterToDatabaseMeter(meter),
- {
- conflictPaths: ['stripeMeterId'],
- },
- );
- }
- this.logger.log(`Upserted meter: ${meter.id}`);
- } catch (error) {
- this.logger.error(`Error upserting meter ${meter.id}: ${error}`);
- }
- }),
- );
- }
-
private async upsertProductRepositoryData(
product: Stripe.Product,
options: MigrationCommandOptions,
@@ -142,10 +113,6 @@ export class BillingSyncPlansDataCommand extends MigrationCommandRunner {
_passedParams: string[],
options: MigrationCommandOptions,
): Promise<void> {
- const billingMeters = await this.stripeBillingMeterService.getAllMeters();
-
- await this.upsertMetersRepositoryData(billingMeters, options);
-
const billingProducts = await this.stripeProductService.getAllProducts();
const billingPrices = await this.processBillingPricesByProductBatches(
diff --git a/packages/twenty-server/src/engine/core-modules/billing/entities/billing-meter.entity.ts b/packages/twenty-server/src/engine/core-modules/billing/entities/billing-meter.entity.ts
deleted file mode 100644
index a31675d5075..00000000000
--- a/packages/twenty-server/src/engine/core-modules/billing/entities/billing-meter.entity.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-/* @license Enterprise */
-
-import Stripe from 'stripe';
-import {
- Column,
- CreateDateColumn,
- Entity,
- OneToMany,
- PrimaryGeneratedColumn,
- Relation,
- UpdateDateColumn,
-} from 'typeorm';
-
-import { BillingPriceEntity } from 'src/engine/core-modules/billing/entities/billing-price.entity';
-import { BillingMeterEventTimeWindow } from 'src/engine/core-modules/billing/enums/billing-meter-event-time-window.enum';
-import { BillingMeterStatus } from 'src/engine/core-modules/billing/enums/billing-meter-status.enum';
-
-@Entity({ name: 'billingMeter', schema: 'core' })
-export class BillingMeterEntity {
- @PrimaryGeneratedColumn('uuid')
- id: string;
-
- @Column({ nullable: true, type: 'timestamptz' })
- deletedAt?: Date;
-
- @CreateDateColumn({ type: 'timestamptz' })
- createdAt: Date;
-
- @UpdateDateColumn({ type: 'timestamptz' })
- updatedAt: Date;
-
- @Column({ nullable: false, unique: true })
- stripeMeterId: string;
-
- @Column({ nullable: false })
- displayName: string;
-
- @Column({ nullable: false })
- eventName: string;
-
- @Column({
- nullable: false,
- type: 'enum',
- enum: Object.values(BillingMeterStatus),
- })
- status: BillingMeterStatus;
-
- @Column({ nullable: false, type: 'jsonb' })
- customerMapping: Stripe.Billing.Meter.CustomerMapping;
-
- @Column({
- nullable: true,
- type: 'enum',
- enum: Object.values(BillingMeterEventTimeWindow),
- })
- eventTimeWindow: BillingMeterEventTimeWindow | null;
-
- @OneToMany(
- () => BillingPriceEntity,
- (billingPrice) => billingPrice.billingMeter,
- )
- billingPrices: Relation<BillingPriceEntity[]>;
-
- @Column({ nullable: false, type: 'jsonb' })
- valueSettings: Stripe.Billing.Meter.ValueSettings;
-}
diff --git a/packages/twenty-server/src/engine/core-modules/billing/entities/billing-price.entity.ts b/packages/twenty-server/src/engine/core-modules/billing/entities/billing-price.entity.ts
index ca1d36724f1..5f848ae18c6 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/entities/billing-price.entity.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/entities/billing-price.entity.ts
@@ -15,7 +15,6 @@ import {
import type Stripe from 'stripe';
-import { BillingMeterEntity } from 'src/engine/core-modules/billing/entities/billing-meter.entity';
import { BillingProductEntity } from 'src/engine/core-modules/billing/entities/billing-product.entity';
import { BillingPriceBillingScheme } from 'src/engine/core-modules/billing/enums/billing-price-billing-scheme.enum';
import { BillingPriceTaxBehavior } from 'src/engine/core-modules/billing/enums/billing-price-tax-behavior.enum';
@@ -126,17 +125,4 @@ export class BillingPriceEntity {
name: 'stripeProductId',
})
billingProduct: Relation<BillingProductEntity> | null;
-
- @ManyToOne(
- () => BillingMeterEntity,
- (billingMeter) => billingMeter.billingPrices,
- {
- nullable: true,
- },
- )
- @JoinColumn({
- referencedColumnName: 'stripeMeterId',
- name: 'stripeMeterId',
- })
- billingMeter: Relation<BillingMeterEntity> | null;
}
diff --git a/packages/twenty-server/src/engine/core-modules/billing/enums/billing-meter-event-time-window.enum.ts b/packages/twenty-server/src/engine/core-modules/billing/enums/billing-meter-event-time-window.enum.ts
deleted file mode 100644
index 5d4e4e3be11..00000000000
--- a/packages/twenty-server/src/engine/core-modules/billing/enums/billing-meter-event-time-window.enum.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-/* @license Enterprise */
-
-export enum BillingMeterEventTimeWindow {
- DAY = 'DAY',
- HOUR = 'HOUR',
-}
diff --git a/packages/twenty-server/src/engine/core-modules/billing/enums/billing-meter-status.enum.ts b/packages/twenty-server/src/engine/core-modules/billing/enums/billing-meter-status.enum.ts
deleted file mode 100644
index 27b1df35099..00000000000
--- a/packages/twenty-server/src/engine/core-modules/billing/enums/billing-meter-status.enum.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-/* @license Enterprise */
-
-export enum BillingMeterStatus {
- ACTIVE = 'ACTIVE',
- INACTIVE = 'INACTIVE',
-}
diff --git a/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-billing-meter.service.ts b/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-billing-meter.service.ts
deleted file mode 100644
index 2df41706d20..00000000000
--- a/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-billing-meter.service.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-/* @license Enterprise */
-
-import { Injectable, Logger } from '@nestjs/common';
-
-import type Stripe from 'stripe';
-
-import { StripeSDKService } from 'src/engine/core-modules/billing/stripe/stripe-sdk/services/stripe-sdk.service';
-import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
-
-@Injectable()
-export class StripeBillingMeterService {
- protected readonly logger = new Logger(StripeBillingMeterService.name);
- private readonly stripe: Stripe;
-
- constructor(
- private readonly twentyConfigService: TwentyConfigService,
- private readonly stripeSDKService: StripeSDKService,
- ) {
- if (!this.twentyConfigService.get('IS_BILLING_ENABLED')) {
- return;
- }
- this.stripe = this.stripeSDKService.getStripe(
- this.twentyConfigService.get('BILLING_STRIPE_API_KEY'),
- );
- }
-
- async getMeter(stripeMeterId: string) {
- return await this.stripe.billing.meters.retrieve(stripeMeterId);
- }
-
- async getAllMeters() {
- const meters = await this.stripe.billing.meters.list();
-
- return meters.data;
- }
-}
diff --git a/packages/twenty-server/src/engine/core-modules/billing/stripe/stripe.module.ts b/packages/twenty-server/src/engine/core-modules/billing/stripe/stripe.module.ts
index 1e703ac0c1a..7486056258d 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/stripe/stripe.module.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/stripe/stripe.module.ts
@@ -3,7 +3,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
-import { StripeBillingMeterService } from 'src/engine/core-modules/billing/stripe/services/stripe-billing-meter.service';
import { StripeBillingPortalService } from 'src/engine/core-modules/billing/stripe/services/stripe-billing-portal.service';
import { StripeCheckoutService } from 'src/engine/core-modules/billing/stripe/services/stripe-checkout.service';
import { StripeCustomerService } from 'src/engine/core-modules/billing/stripe/services/stripe-customer.service';
@@ -32,7 +31,6 @@ import { provideWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspac
StripeSubscriptionService,
StripeSubscriptionScheduleService,
StripeBillingPortalService,
- StripeBillingMeterService,
StripeCustomerService,
StripeEntitlementService,
StripePriceService,
@@ -43,7 +41,6 @@ import { provideWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspac
exports: [
StripeWebhookService,
StripeBillingPortalService,
- StripeBillingMeterService,
StripeCustomerService,
StripeEntitlementService,
StripePriceService,
diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/transform-stripe-meter-to-database-meter.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/transform-stripe-meter-to-database-meter.util.spec.ts
deleted file mode 100644
index d15c28d4192..00000000000
--- a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/transform-stripe-meter-to-database-meter.util.spec.ts
+++ /dev/null
@@ -1,96 +0,0 @@
-/* @license Enterprise */
-
-import type Stripe from 'stripe';
-
-import { BillingMeterEventTimeWindow } from 'src/engine/core-modules/billing/enums/billing-meter-event-time-window.enum';
-import { BillingMeterStatus } from 'src/engine/core-modules/billing/enums/billing-meter-status.enum';
-import { transformStripeMeterToDatabaseMeter } from 'src/engine/core-modules/billing/utils/transform-stripe-meter-to-database-meter.util';
-
-describe('transformStripeMeterDataToMeterRepositoryData', () => {
- it('should return the correct data with customer mapping', () => {
- const data: Stripe.Billing.Meter = {
- id: 'met_123',
- object: 'billing.meter',
- created: 1719859200,
- display_name: 'Meter 1',
- event_name: 'event_1',
- status: 'active',
- customer_mapping: {
- event_payload_key: 'event_payload_key_1',
- type: 'by_id',
- },
- default_aggregation: {
- formula: 'count',
- },
- event_time_window: 'day',
- livemode: false,
- status_transitions: {
- deactivated_at: null,
- },
- updated: 1719859200,
- value_settings: {
- event_payload_key: 'event_payload_key_1',
- },
- };
-
- const result = transformStripeMeterToDatabaseMeter(data);
-
- expect(result).toEqual({
- stripeMeterId: 'met_123',
- displayName: 'Meter 1',
- eventName: 'event_1',
- status: BillingMeterStatus.ACTIVE,
- customerMapping: {
- event_payload_key: 'event_payload_key_1',
- type: 'by_id',
- },
- eventTimeWindow: BillingMeterEventTimeWindow.DAY,
- valueSettings: {
- event_payload_key: 'event_payload_key_1',
- },
- });
- });
- it('should return the correct data with null values', () => {
- const data: Stripe.Billing.Meter = {
- id: 'met_1234',
- object: 'billing.meter',
- created: 1719859200,
- display_name: 'Meter 2',
- event_name: 'event_2',
- status: 'inactive',
- customer_mapping: {
- event_payload_key: 'event_payload_key_2',
- type: 'by_id',
- },
- default_aggregation: {
- formula: 'sum',
- },
- event_time_window: null,
- livemode: false,
- status_transitions: {
- deactivated_at: 1719859200,
- },
- updated: 1719859200,
- value_settings: {
- event_payload_key: 'event_payload_key_2',
- },
- };
-
- const result = transformStripeMeterToDatabaseMeter(data);
-
- expect(result).toEqual({
- stripeMeterId: 'met_1234',
- displayName: 'Meter 2',
- eventName: 'event_2',
- status: BillingMeterStatus.INACTIVE,
- customerMapping: {
- event_payload_key: 'event_payload_key_2',
- type: 'by_id',
- },
- eventTimeWindow: undefined,
- valueSettings: {
- event_payload_key: 'event_payload_key_2',
- },
- });
- });
-});
diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/transform-stripe-meter-to-database-meter.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/transform-stripe-meter-to-database-meter.util.ts
deleted file mode 100644
index 4762f3caa48..00000000000
--- a/packages/twenty-server/src/engine/core-modules/billing/utils/transform-stripe-meter-to-database-meter.util.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-/* @license Enterprise */
-
-import type Stripe from 'stripe';
-
-import { BillingMeterEventTimeWindow } from 'src/engine/core-modules/billing/enums/billing-meter-event-time-window.enum';
-import { BillingMeterStatus } from 'src/engine/core-modules/billing/enums/billing-meter-status.enum';
-
-export const transformStripeMeterToDatabaseMeter = (
- data: Stripe.Billing.Meter,
-) => {
- return {
- stripeMeterId: data.id,
- displayName: data.display_name,
- eventName: data.event_name,
- status: getBillingMeterStatus(data.status),
- customerMapping: data.customer_mapping,
- eventTimeWindow: data.event_time_window
- ? getBillingMeterEventTimeWindow(data.event_time_window)
- : undefined,
- valueSettings: data.value_settings,
- };
-};
-
-const getBillingMeterStatus = (data: Stripe.Billing.Meter.Status) => {
- switch (data) {
- case 'active':
- return BillingMeterStatus.ACTIVE;
- case 'inactive':
- return BillingMeterStatus.INACTIVE;
- }
-};
-
-const getBillingMeterEventTimeWindow = (
- data: Stripe.Billing.Meter.EventTimeWindow,
-) => {
- switch (data) {
- case 'day':
- return BillingMeterEventTimeWindow.DAY;
- case 'hour':
- return BillingMeterEventTimeWindow.HOUR;
- }
-};
diff --git a/packages/twenty-server/src/engine/workspace-manager/types/all-non-workspace-related-entity.type.ts b/packages/twenty-server/src/engine/workspace-manager/types/all-non-workspace-related-entity.type.ts
index 3c5e8f51f10..f4907b62663 100644
--- a/packages/twenty-server/src/engine/workspace-manager/types/all-non-workspace-related-entity.type.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/types/all-non-workspace-related-entity.type.ts
@@ -3,7 +3,6 @@ import { type Equal, type Expect } from 'twenty-shared/testing';
import { type ApplicationRegistrationEntity } from 'src/engine/core-modules/application/application-registration/application-registration.entity';
import { type ApplicationRegistrationVariableEntity } from 'src/engine/core-modules/application/application-registration-variable/application-registration-variable.entity';
import { type ApplicationRegistrationVersionEntity } from 'src/engine/core-modules/application/application-registration-version/application-registration-version.entity';
-import { type BillingMeterEntity } from 'src/engine/core-modules/billing/entities/billing-meter.entity';
import { type BillingPriceEntity } from 'src/engine/core-modules/billing/entities/billing-price.entity';
import { type BillingProductEntity } from 'src/engine/core-modules/billing/entities/billing-product.entity';
import { type BillingSubscriptionItemEntity } from 'src/engine/core-modules/billing/entities/billing-subscription-item.entity';
@@ -23,7 +22,6 @@ export type AllNonWorkspaceRelatedEntity =
| ApplicationRegistrationEntity
| ApplicationRegistrationVariableEntity
| ApplicationRegistrationVersionEntity
- | BillingMeterEntity
| BillingPriceEntity
| BillingProductEntity
| BillingSubscriptionItemEntity