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

refactor: remove TenantInfo type (#5891)

This commit is contained in:
Gao Sun 2024-05-17 20:06:09 +08:00 committed by GitHub
parent f1d5f724d5
commit e715049bae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 15 additions and 18 deletions

View file

@ -1,4 +1,4 @@
import { createTenantMetadata } from '@logto/core-kit'; import { createTenantDatabaseMetadata } from '@logto/core-kit';
import { import {
type AdminData, type AdminData,
type UpdateAdminData, type UpdateAdminData,
@ -26,7 +26,7 @@ import { consoleLog } from '../../../utils.js';
export const createTenant = async (pool: CommonQueryMethods, tenantId: string) => { export const createTenant = async (pool: CommonQueryMethods, tenantId: string) => {
const database = await getDatabaseName(pool, true); const database = await getDatabaseName(pool, true);
const { parentRole, role, password } = createTenantMetadata(database, tenantId); const { parentRole, role, password } = createTenantDatabaseMetadata(database, tenantId);
const createTenant = { const createTenant = {
id: tenantId, id: tenantId,
dbUser: role, dbUser: role,

View file

@ -16,7 +16,7 @@ import * as modalStyles from '@/scss/modal.module.scss';
import { type SubscriptionPlan } from '@/types/subscriptions'; import { type SubscriptionPlan } from '@/types/subscriptions';
import { pickupFeaturedPlans } from '@/utils/subscription'; import { pickupFeaturedPlans } from '@/utils/subscription';
import { type CreateTenantData } from '../type'; import { type CreateTenantData } from '../types';
import PlanCardItem from './PlanCardItem'; import PlanCardItem from './PlanCardItem';
import * as styles from './index.module.scss'; import * as styles from './index.module.scss';

View file

@ -20,7 +20,7 @@ import * as modalStyles from '@/scss/modal.module.scss';
import EnvTagOptionContent from './EnvTagOptionContent'; import EnvTagOptionContent from './EnvTagOptionContent';
import SelectTenantPlanModal from './SelectTenantPlanModal'; import SelectTenantPlanModal from './SelectTenantPlanModal';
import * as styles from './index.module.scss'; import * as styles from './index.module.scss';
import { type CreateTenantData } from './type'; import { type CreateTenantData } from './types';
type Props = { type Props = {
readonly isOpen: boolean; readonly isOpen: boolean;

View file

@ -1,3 +0,0 @@
import { type TenantInfo } from '@logto/schemas/models';
export type CreateTenantData = Pick<TenantInfo, 'name' | 'tag'>;

View file

@ -0,0 +1,3 @@
import { type TenantModel } from '@logto/schemas';
export type CreateTenantData = Pick<TenantModel, 'name' | 'tag'>;

View file

@ -6,7 +6,7 @@ import { toast } from 'react-hot-toast';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { toastResponseError, useCloudApi } from '@/cloud/hooks/use-cloud-api'; import { toastResponseError, useCloudApi } from '@/cloud/hooks/use-cloud-api';
import { type CreateTenantData } from '@/components/CreateTenantModal/type'; import { type CreateTenantData } from '@/components/CreateTenantModal/types';
import { checkoutStateQueryKey } from '@/consts/subscriptions'; import { checkoutStateQueryKey } from '@/consts/subscriptions';
import { GlobalRoute, TenantsContext } from '@/contexts/TenantsProvider'; import { GlobalRoute, TenantsContext } from '@/contexts/TenantsProvider';
import { createLocalCheckoutSession } from '@/utils/checkout'; import { createLocalCheckoutSession } from '@/utils/checkout';

View file

@ -1,8 +1,11 @@
import { type TenantTag } from '@logto/schemas'; import { type TenantTag } from '@logto/schemas';
import type { TenantInfo } from '@logto/schemas/models'; import type { TenantModel } from '@logto/schemas/models';
import { cloudApi } from './api.js'; import { cloudApi } from './api.js';
// TODO: Import from cloud package after it's created
type TenantInfo = Pick<TenantModel, 'id' | 'name' | 'tag' | 'isSuspended' | 'createdAt'>;
export const createTenant = async ( export const createTenant = async (
accessToken: string, accessToken: string,
payload: { name: string; tag: TenantTag } payload: { name: string; tag: TenantTag }

View file

@ -27,9 +27,3 @@ export const Tenants = createModel(
.extend('createdAt', { readonly: true }); .extend('createdAt', { readonly: true });
export type TenantModel = InferModelType<typeof Tenants>; export type TenantModel = InferModelType<typeof Tenants>;
export const tenantInfoGuard = Tenants.guard('model')
.pick({ id: true, name: true, tag: true, isSuspended: true })
.extend({ indicator: z.string() });
export type TenantInfo = z.infer<typeof tenantInfoGuard>;

View file

@ -3,17 +3,17 @@ import { generateStandardId } from '@logto/shared/universal';
// Use lowercase letters for tenant IDs to improve compatibility // Use lowercase letters for tenant IDs to improve compatibility
const generateTenantId = () => generateStandardId(6); const generateTenantId = () => generateStandardId(6);
export type TenantMetadata = { export type TenantDatabaseMetadata = {
id: string; id: string;
parentRole: string; parentRole: string;
role: string; role: string;
password: string; password: string;
}; };
export const createTenantMetadata = ( export const createTenantDatabaseMetadata = (
databaseName: string, databaseName: string,
tenantId = generateTenantId() tenantId = generateTenantId()
): TenantMetadata => { ): TenantDatabaseMetadata => {
const parentRole = `logto_tenant_${databaseName}`; const parentRole = `logto_tenant_${databaseName}`;
const role = `logto_tenant_${databaseName}_${tenantId}`; const role = `logto_tenant_${databaseName}_${tenantId}`;
const password = generateStandardId(32); const password = generateStandardId(32);