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:
parent
f1d5f724d5
commit
e715049bae
9 changed files with 15 additions and 18 deletions
|
@ -1,4 +1,4 @@
|
|||
import { createTenantMetadata } from '@logto/core-kit';
|
||||
import { createTenantDatabaseMetadata } from '@logto/core-kit';
|
||||
import {
|
||||
type AdminData,
|
||||
type UpdateAdminData,
|
||||
|
@ -26,7 +26,7 @@ import { consoleLog } from '../../../utils.js';
|
|||
|
||||
export const createTenant = async (pool: CommonQueryMethods, tenantId: string) => {
|
||||
const database = await getDatabaseName(pool, true);
|
||||
const { parentRole, role, password } = createTenantMetadata(database, tenantId);
|
||||
const { parentRole, role, password } = createTenantDatabaseMetadata(database, tenantId);
|
||||
const createTenant = {
|
||||
id: tenantId,
|
||||
dbUser: role,
|
||||
|
|
|
@ -16,7 +16,7 @@ import * as modalStyles from '@/scss/modal.module.scss';
|
|||
import { type SubscriptionPlan } from '@/types/subscriptions';
|
||||
import { pickupFeaturedPlans } from '@/utils/subscription';
|
||||
|
||||
import { type CreateTenantData } from '../type';
|
||||
import { type CreateTenantData } from '../types';
|
||||
|
||||
import PlanCardItem from './PlanCardItem';
|
||||
import * as styles from './index.module.scss';
|
||||
|
|
|
@ -20,7 +20,7 @@ import * as modalStyles from '@/scss/modal.module.scss';
|
|||
import EnvTagOptionContent from './EnvTagOptionContent';
|
||||
import SelectTenantPlanModal from './SelectTenantPlanModal';
|
||||
import * as styles from './index.module.scss';
|
||||
import { type CreateTenantData } from './type';
|
||||
import { type CreateTenantData } from './types';
|
||||
|
||||
type Props = {
|
||||
readonly isOpen: boolean;
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
import { type TenantInfo } from '@logto/schemas/models';
|
||||
|
||||
export type CreateTenantData = Pick<TenantInfo, 'name' | 'tag'>;
|
|
@ -0,0 +1,3 @@
|
|||
import { type TenantModel } from '@logto/schemas';
|
||||
|
||||
export type CreateTenantData = Pick<TenantModel, 'name' | 'tag'>;
|
|
@ -6,7 +6,7 @@ import { toast } from 'react-hot-toast';
|
|||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
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 { GlobalRoute, TenantsContext } from '@/contexts/TenantsProvider';
|
||||
import { createLocalCheckoutSession } from '@/utils/checkout';
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
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';
|
||||
|
||||
// TODO: Import from cloud package after it's created
|
||||
type TenantInfo = Pick<TenantModel, 'id' | 'name' | 'tag' | 'isSuspended' | 'createdAt'>;
|
||||
|
||||
export const createTenant = async (
|
||||
accessToken: string,
|
||||
payload: { name: string; tag: TenantTag }
|
||||
|
|
|
@ -27,9 +27,3 @@ export const Tenants = createModel(
|
|||
.extend('createdAt', { readonly: true });
|
||||
|
||||
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>;
|
||||
|
|
|
@ -3,17 +3,17 @@ import { generateStandardId } from '@logto/shared/universal';
|
|||
// Use lowercase letters for tenant IDs to improve compatibility
|
||||
const generateTenantId = () => generateStandardId(6);
|
||||
|
||||
export type TenantMetadata = {
|
||||
export type TenantDatabaseMetadata = {
|
||||
id: string;
|
||||
parentRole: string;
|
||||
role: string;
|
||||
password: string;
|
||||
};
|
||||
|
||||
export const createTenantMetadata = (
|
||||
export const createTenantDatabaseMetadata = (
|
||||
databaseName: string,
|
||||
tenantId = generateTenantId()
|
||||
): TenantMetadata => {
|
||||
): TenantDatabaseMetadata => {
|
||||
const parentRole = `logto_tenant_${databaseName}`;
|
||||
const role = `logto_tenant_${databaseName}_${tenantId}`;
|
||||
const password = generateStandardId(32);
|
||||
|
|
Loading…
Reference in a new issue