feat(billing): refacto billing (#14243)

… prices for metered billing

---------

Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
Antoine Moreaux
2025-09-19 11:25:53 +02:00
committed by GitHub
parent 163890f6c8
commit 43e0cd5d05
351 changed files with 16091 additions and 6101 deletions
@@ -0,0 +1,41 @@
import { assertIsDefinedOrThrow } from '@/utils';
describe('assertIsDefinedOrThrow', () => {
it('does not throw when value is defined (number)', () => {
expect(() => assertIsDefinedOrThrow(42)).not.toThrow();
});
it('does not throw when value is defined (false)', () => {
const v: boolean | undefined | null = false;
expect(() => assertIsDefinedOrThrow(v)).not.toThrow();
});
it('does not throw when value is defined (empty string)', () => {
const v: string | undefined | null = '';
expect(() => assertIsDefinedOrThrow(v)).not.toThrow();
});
it('throws the default error when value is undefined', () => {
expect(() => assertIsDefinedOrThrow(undefined)).toThrow('Value not defined');
});
it('throws the default error when value is null', () => {
expect(() => assertIsDefinedOrThrow(null)).toThrow('Value not defined');
});
it('throws the custom error instance when provided', () => {
const err = new TypeError('Custom');
expect(() => assertIsDefinedOrThrow(undefined, err)).toThrow(err);
});
it('narrows the type after assertion (compile-time check)', () => {
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
function expectString(s: string) {
expect(typeof s).toBe('string');
}
let maybe: string | undefined | null = 'ok';
assertIsDefinedOrThrow(maybe);
// After the assertion, TypeScript should treat `maybe` as `string`.
expectString(maybe);
});
});
@@ -0,0 +1,12 @@
import { isDefined } from '@/utils';
// https://github.com/microsoft/TypeScript/issues/34523
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function assertIsDefinedOrThrow<T>(
value: T | undefined | null,
exceptionToThrow: Error = new Error(
'Value not defined',
),
): asserts value is T {
if (!isDefined(value)) throw exceptionToThrow;
}
@@ -1,4 +1,5 @@
export * from './isDefined';
export * from './assertIsDefinedOrThrow';
export * from './isValidLocale';
export * from './isValidUuid';
export * from './normalizeLocale';