@authup/core-kit

中文文档
1.0.0-beta.73发布于 2026/11/02Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 4174

Domain types, enums and validators for every Authup entity, shared by server and clients.

原始使用文档
文档目录10 节
  1. Where it fits
  2. Installation
  3. Usage
  4. Entity types
  5. Names and enums
  6. Validators
  7. Name checks
  8. API
  9. Notes
  10. License

Authup logo

@authup/core-kit

Domain types, enums and validators for every Authup entity, shared by server and clients.
The shapes of users, clients, roles, permissions and realms, and the rules their fields follow.

npm version CI License: Apache-2.0

Installation · Usage · API · Documentation


Where it fits

@authup/core-kit is the domain layer every other Authup workspace builds on: the server validates incoming payloads with its validators, @authup/core-http-kit types its responses with its entities, and the Vue kit renders its forms against the same rules. You install it directly when you write TypeScript against Authup and need the entity types or the permission and scope names, for example to type your own API layer or to check permission.name === PermissionName.USER_UPDATE without a string literal. If you already use @authup/core-http-kit, it is installed with it.

Installation

npm install @authup/core-kit

ESM only. Node.js >=26.0.0, or a browser bundler. There are no peer dependencies.

Usage

Entity types

Every entity is a plain type with camelCase fields:

import type { Role, User } from '@authup/core-kit';

function label(user: User) : string {
    return user.displayName ?? user.name;
}

const role: Pick<Role, 'name' | 'realmId'> = { name: 'editor', realmId: null };

EntityType names every entity (EntityType.USER === 'user', EntityType.ROLE_PERMISSION === 'rolePermission'), and EntityTypeMap maps each name to its type.

Names and enums

import {
    IdentityType,
    PermissionName,
    REALM_MASTER_NAME,
    ROLE_ADMIN_NAME,
    ScopeName,
} from '@authup/core-kit';

PermissionName.USER_UPDATE; // 'user_update'
ScopeName.GLOBAL; // 'global'
IdentityType.CLIENT; // 'client'
REALM_MASTER_NAME; // 'master'
ROLE_ADMIN_NAME; // 'admin'

PermissionName lists the built-in permissions the server provisions; ScopeName the built-in scopes (global, openid, email, roles, identity).

Validators

Each writable entity has a validator, a validup container. run() returns the validated and normalized data, or throws a ValidupError listing the issues:

import { RoleValidator } from '@authup/core-kit';
import { ValidatorGroup } from '@authup/kit';

const validator = new RoleValidator();
const data = await validator.run(
    { name: '  Editor ', description: 'Edits content' },
    { group: ValidatorGroup.CREATE },
);
// data.name === 'editor'
  • The group decides which fields are mounted. CREATE mounts identifiers such as name and realmId; UPDATE does not mount realmId, so a realm cannot change after creation. ValidatorGroup comes from @authup/kit.
  • Fields a group does not mount are stripped from the output, not rejected.
  • Names are canonicalized: name is trimmed and lower-cased before the format check, so mixed case is accepted and stored lower case.

Name checks

import { isNameValid, isUserNameValid } from '@authup/core-kit';

isNameValid('my-app_1'); // true
isNameValid('My App'); // false
isNameValid('My App', { throwOnFailure: true }); // throws
isUserNameValid('alice');

isNameValid accepts [a-z0-9-_.] only. Each entity adds its own variant (isRoleNameValid, isClientNameValid, isRealmNameValid, ...) with its own reserved names and length bounds.

API

The barrel exports one family per entity. Each family carries the entity type and, where the entity is writable, a validator, a name check and its constants.

FamilyMain exports
UsersUser, UserValidator, isUserNameValid, isValidUserEmail, USER_PASSWORD_MIN_LENGTH, USER_PASSWORD_MAX_LENGTH
User relationsUserAttribute, UserAttributeName, UserAuthenticator, UserAuthenticatorKind, UserPermission, UserRole and their validators
ClientsClient, ClientValidator, ClientSecretRotateValidator, ClientAuthMethod, ClientSecretMode, ClientTokenBindingMethod, CLIENT_SYSTEM_NAME, CLIENT_ADMIN_CONSOLE_NAME, CLIENT_ACCOUNT_CONSOLE_NAME, CLIENT_RESERVED_NAMES, isClientPublic, getClientSecretMode
Client relationsClientPermission, ClientRole, ClientScope and their validators
RolesRole, RoleValidator, RoleAttribute, RolePermission, ROLE_ADMIN_NAME, ROLE_REALM_ADMIN_NAME
Permissions and policiesPermission, PermissionName, PermissionValidator, PermissionPolicy, Policy, PolicyValidator, PolicyAttribute, REALM_SCOPE
ScopesScope, ScopeName, ScopeValidator
RealmsRealm, RealmValidator, REALM_MASTER_NAME, isRealmNameValid
PathsPath, PathValidator, splitPath, joinPath, isPathValid, PATH_MAX_DEPTH
Identity providersIdentityProvider, IdentityProviderProtocol, IdentityProviderPreset, IdentityProviderValidator, the OAuth2, OIDC and LDAP attribute validators, IdentityProviderAccount, the attribute, role and permission mappings
Sessions and consentSession, SessionAuthMethod, SessionToken, Consent, OAuth2AuthorizationCode
KeysKey, KeyStatus, KeyValidator, TrustAnchor, TrustAnchorValidator
EventsEvent, EventName, EventScope, EventRefType, EventAggregate
IdentitiesIdentity, UserIdentity, ClientIdentity, IdentityType
Cross-entityEntityType, EntityTypeMap, EntityDefaultEventName, isNameValid, buildEntityChannelName, buildEntityNamespaceName

The full reference is at authup.org.

Notes

  • Types describe the API shape, not the database. Fields the server never returns (a password, a secret in hashed mode) may still appear on the type as optional or nullable.
  • EntityTypeMap is not every EntityType. A few types (the identity-provider attribute and permission mappings, the user authenticator) have no entry, since no flat entity API serves them.

License

Made with 💚

Published under the Apache 2.0 License.

版本与发布记录

@authup/core-kit 共发布 58 个版本,首次发布于 2024/05/08;过去 12 个月发布了 44 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0-beta.73latest2026/11/025 天前
1.0.0-beta.722026/10/2711 天前
1.0.0-beta.712026/10/2018 天前
1.0.0-beta.702026/10/1919 天前
1.0.0-beta.692026/10/1424 天前
1.0.0-beta.682026/09/251 个月前

关于 @authup/core-kit 的常见问题

@authup/core-kit 是什么?

Domain types, enums and validators for every Authup entity, shared by server and clients.

如何安装 @authup/core-kit?

在项目目录运行 npm install @authup/core-kit,或使用 pnpm add / yarn add / bun add。

@authup/core-kit 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@authup/core-kit 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@authup/core-kit 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=26.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@authup/core-kit 可以商用吗?

@authup/core-kit 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@authup/core-kit 的下载量有多少?

根据 npm 官方下载统计,@authup/core-kit 在 2026/10/07 – 2026/11/05 这 30 天内被下载 4,174 次,日均约 139 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@authup/core-kit 还在维护吗?

最新版本 1.0.0-beta.73 发布于 2026/11/02(5 天前);至今共发布 58 个版本,其中过去 12 个月发布了 44 个;首次发布于 2024/05/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。