0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(core): fix the subscription api response type (#6834)

fix the subscription api response type all dates value should be converted to ISO 8601 string
This commit is contained in:
simeng-li 2024-12-10 13:37:23 +08:00 committed by GitHub
parent 2178589507
commit 8a15a60c37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -16,7 +16,15 @@ export const getTenantSubscription = async (
const client = await cloudConnection.getClient();
const subscription = await client.get('/api/tenants/my/subscription');
return subscription;
// All the dates will be converted to the ISO 8601 format after json serialization.
// Convert the dates to ISO 8601 format to match the exact type of the response.
const { currentPeriodStart, currentPeriodEnd, ...rest } = subscription;
return {
...rest,
currentPeriodStart: new Date(currentPeriodStart).toISOString(),
currentPeriodEnd: new Date(currentPeriodEnd).toISOString(),
};
};
export const getTenantSubscriptionData = async (

View file

@ -10,7 +10,17 @@ type RouteResponseType<T extends { search?: unknown; body?: unknown; response?:
type RouteRequestBodyType<T extends { search?: unknown; body?: ZodType; response?: unknown }> =
z.infer<NonNullable<T['body']>>;
export type Subscription = RouteResponseType<GetRoutes['/api/tenants/my/subscription']>;
/**
* The subscription data is fetched from the Cloud API.
* All the dates are in ISO 8601 format, we need to manually fix the type to string here.
*/
export type Subscription = Omit<
RouteResponseType<GetRoutes['/api/tenants/my/subscription']>,
'currentPeriodStart' | 'currentPeriodEnd'
> & {
currentPeriodStart: string;
currentPeriodEnd: string;
};
type CompleteSubscriptionUsage = RouteResponseType<GetRoutes['/api/tenants/my/subscription-usage']>;