mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(schemas,cli): seed default scope for management api (#2869)
Co-authored-by: Gao Sun <gao@silverhand.io>
This commit is contained in:
parent
8f809da308
commit
385966625e
5 changed files with 26 additions and 2 deletions
|
@ -10,6 +10,8 @@ import {
|
|||
createDefaultSetting,
|
||||
createDemoAppApplication,
|
||||
defaultRole,
|
||||
managementResourceScope,
|
||||
defaultRoleScopeRelation,
|
||||
} from '@logto/schemas';
|
||||
import { Hooks } from '@logto/schemas/models';
|
||||
import chalk from 'chalk';
|
||||
|
@ -57,10 +59,12 @@ const createTables = async (connection: DatabaseTransactionConnection) => {
|
|||
const seedTables = async (connection: DatabaseTransactionConnection, latestTimestamp: number) => {
|
||||
await Promise.all([
|
||||
connection.query(insertInto(managementResource, 'resources')),
|
||||
connection.query(insertInto(managementResourceScope, 'scopes')),
|
||||
connection.query(insertInto(createDefaultSetting(), 'settings')),
|
||||
connection.query(insertInto(defaultSignInExperience, 'sign_in_experiences')),
|
||||
connection.query(insertInto(createDemoAppApplication(generateStandardId()), 'applications')),
|
||||
connection.query(insertInto(defaultRole, 'roles')),
|
||||
connection.query(insertInto(defaultRoleScopeRelation, 'roles_scopes')),
|
||||
updateDatabaseTimestamp(connection, latestTimestamp),
|
||||
]);
|
||||
};
|
||||
|
|
|
@ -3,3 +3,4 @@ export * from './resource.js';
|
|||
export * from './setting.js';
|
||||
export * from './sign-in-experience.js';
|
||||
export * from './roles.js';
|
||||
export * from './scope.js';
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import type { CreateResource } from '../db-entries/index.js';
|
||||
|
||||
export const managementResourceId = 'management-api';
|
||||
|
||||
export const managementResource: Readonly<CreateResource> = Object.freeze({
|
||||
id: 'management-api',
|
||||
id: managementResourceId,
|
||||
/**
|
||||
* The fixed resource indicator for Management APIs.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import type { CreateRole } from '../db-entries/index.js';
|
||||
import type { CreateRole, CreateRolesScope } from '../db-entries/index.js';
|
||||
import { UserRole } from '../types/index.js';
|
||||
import { managementResourceScopeId } from './scope.js';
|
||||
|
||||
export const adminConsoleAdminRoleId = 'ac-admin-id';
|
||||
|
||||
|
@ -11,3 +12,8 @@ export const defaultRole: Readonly<CreateRole> = {
|
|||
name: UserRole.Admin,
|
||||
description: 'Admin role for Logto.',
|
||||
};
|
||||
|
||||
export const defaultRoleScopeRelation: Readonly<CreateRolesScope> = {
|
||||
roleId: adminConsoleAdminRoleId,
|
||||
scopeId: managementResourceScopeId,
|
||||
};
|
||||
|
|
11
packages/schemas/src/seeds/scope.ts
Normal file
11
packages/schemas/src/seeds/scope.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import type { CreateScope } from '../db-entries/index.js';
|
||||
import { managementResourceId } from './resource.js';
|
||||
|
||||
export const managementResourceScopeId = 'management-api-scope';
|
||||
|
||||
export const managementResourceScope: Readonly<CreateScope> = Object.freeze({
|
||||
id: managementResourceScopeId,
|
||||
name: 'default',
|
||||
description: 'Default scope for management API',
|
||||
resourceId: managementResourceId,
|
||||
});
|
Loading…
Reference in a new issue